1 |
#include "UserCode/L1RpcTriggerAnalysis/interface/DetHitDigiGrabber.h"
|
2 |
|
3 |
#include "FWCore/Framework/interface/Event.h"
|
4 |
#include "FWCore/Framework/interface/EventSetup.h"
|
5 |
#include "FWCore/Framework/interface/ESHandle.h"
|
6 |
#include "DataFormats/Common/interface/Handle.h"
|
7 |
|
8 |
#include "Geometry/RPCGeometry/interface/RPCGeometry.h"
|
9 |
#include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
|
10 |
|
11 |
|
12 |
#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
|
13 |
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"
|
14 |
#include "DataFormats/GeometryVector/interface/LocalPoint.h"
|
15 |
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
|
16 |
|
17 |
#include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
|
18 |
#include "DataFormats/DetId/interface/DetIdCollection.h"
|
19 |
#include "UserCode/L1RpcTriggerAnalysis/interface/RPCDetIdUtil.h"
|
20 |
#include "DataFormats/MuonDetId/interface/RPCDetId.h"
|
21 |
|
22 |
#include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
|
23 |
#include "DataFormats/MuonDetId/interface/CSCTriggerNumbering.h"
|
24 |
#include "DataFormats/MuonDetId/interface/CSCDetId.h"
|
25 |
#include "DataFormats/L1CSCTrackFinder/interface/CSCTriggerContainer.h"
|
26 |
|
27 |
#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h"
|
28 |
#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h"
|
29 |
#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhDigi.h"
|
30 |
#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThDigi.h"
|
31 |
|
32 |
#include "DataFormats/Math/interface/deltaPhi.h"
|
33 |
#include "UserCode/L1RpcTriggerAnalysis/interface/TrackObj.h"
|
34 |
#include "UserCode/L1RpcTriggerAnalysis/interface/RPCDigiSpec.h"
|
35 |
#include "TObjArray.h"
|
36 |
#include "TH1D.h"
|
37 |
#include "TH2D.h"
|
38 |
#include <sstream>
|
39 |
#include <bitset>
|
40 |
|
41 |
namespace {
|
42 |
TH2D* hDetHitDigiGrabber_DphiVsPt_Bar;
|
43 |
TH2D* hDetHitDigiGrabber_DphiVsPt_End;
|
44 |
}
|
45 |
|
46 |
DetHitDigiGrabber::DetHitDigiGrabber(const edm::ParameterSet& cfg)
|
47 |
: theConfig(cfg) { }
|
48 |
|
49 |
DetHitDigiGrabber::~DetHitDigiGrabber() {}
|
50 |
|
51 |
HitSpecObj DetHitDigiGrabber::rpcDetHits(const edm::Event &ev,
|
52 |
const edm::EventSetup &es,
|
53 |
const TrackObj * simu,
|
54 |
int station) const
|
55 |
{
|
56 |
HitSpecObj result;
|
57 |
std::vector<uint32_t> simuHits;
|
58 |
edm::Handle< edm::PSimHitContainer > simHits;
|
59 |
static std::string rpcHitsCollName = theConfig.getParameter<std::string>("rpcHitsCollName");
|
60 |
ev.getByLabel("g4SimHits", rpcHitsCollName, simHits);
|
61 |
static bool warnNoColl = theConfig.getUntrackedParameter<bool>("warnNoColl" , true);
|
62 |
if (!simHits.isValid()) {
|
63 |
if (warnNoColl) std::cout <<"** WARNING: not collection: "<< rpcHitsCollName << std::endl;
|
64 |
return result;
|
65 |
}
|
66 |
|
67 |
edm::ESHandle<RPCGeometry> rpcGeometry;
|
68 |
es.get<MuonGeometryRecord>().get(rpcGeometry);
|
69 |
|
70 |
for (edm::PSimHitContainer::const_iterator hitItr = simHits->begin(); hitItr != simHits->end(); ++hitItr) {
|
71 |
if ( !(13 == abs(hitItr->particleType()) ) ) continue;
|
72 |
uint32_t rpcRawId = hitItr->detUnitId();
|
73 |
RPCDetId rpcDet(rpcRawId);
|
74 |
RPCDetIdUtil u(rpcDet);
|
75 |
if((station==2 && ((u.isBarrel() && u.barrelLayer()==4) || (!u.isBarrel() && u.endcapLayer()==2))) ||
|
76 |
(station==1 && u.isBarrel() && u.barrelLayer()==1)){
|
77 |
|
78 |
GlobalPoint hitPoint = rpcGeometry->idToDet(rpcDet)->toGlobal(hitItr->entryPoint());
|
79 |
GlobalVector glbMom = rpcGeometry->idToDet(rpcDet)->toGlobal(hitItr->momentumAtEntry());
|
80 |
|
81 |
if (u.isBarrel() || result.rawId()==0) result = HitSpecObj(rpcRawId, hitPoint, glbMom);
|
82 |
|
83 |
TH2D* h = u.isBarrel() ? hDetHitDigiGrabber_DphiVsPt_Bar : hDetHitDigiGrabber_DphiVsPt_End;
|
84 |
h->Fill( simu->pt(), deltaPhi(simu->phi(),hitPoint.phi())*simu->charge());
|
85 |
/*
|
86 |
std::cout <<"Det: "<< rpcRawId
|
87 |
<<" glbMom: pt:" << glbMom.perp() <<" pz: "<<glbMom.z()<<" phi: "<<glbMom.phi()
|
88 |
<<" globalPosition: r:"<<hitPoint.perp()<<" z:"<<hitPoint.z()<<" phi: "<<hitPoint.phi()
|
89 |
<<std::endl;
|
90 |
*/
|
91 |
}
|
92 |
}
|
93 |
return result;
|
94 |
}
|
95 |
|
96 |
std::vector< std::pair<uint32_t,uint32_t> > DetHitDigiGrabber::digiCollector(const edm::Event &ev, const edm::EventSetup &es) const
|
97 |
{
|
98 |
std::vector< std::pair<uint32_t,uint32_t> > result;
|
99 |
|
100 |
std::vector<RPCDigiSpec> rpc = rpcDetDigis(ev,es);
|
101 |
for (std::vector<RPCDigiSpec>::const_iterator it = rpc.begin(); it!= rpc.end(); ++it) {
|
102 |
result.push_back( std::make_pair( it->rawId(), it->codedDigi()) );
|
103 |
}
|
104 |
|
105 |
std::vector<CSCDigiSpec> csc = cscDetDigis(ev,es);
|
106 |
for (std::vector<CSCDigiSpec>::const_iterator it = csc.begin(); it!= csc.end(); ++it) {
|
107 |
result.push_back( std::make_pair( it->rawId(), it->codedDigi()) );
|
108 |
}
|
109 |
|
110 |
std::vector<DTphDigiSpec> dt = dtPhiDetDigis(ev,es);
|
111 |
for (std::vector<DTphDigiSpec>::const_iterator it = dt.begin(); it!= dt.end(); ++it) {
|
112 |
result.push_back( std::make_pair( it->rawId(), it->codedDigi()) );
|
113 |
}
|
114 |
|
115 |
return result;
|
116 |
}
|
117 |
|
118 |
std::vector<RPCDigiSpec> DetHitDigiGrabber::rpcDetDigis(const edm::Event &ev, const edm::EventSetup &es) const
|
119 |
{
|
120 |
std::vector<RPCDigiSpec> result;
|
121 |
edm::Handle<RPCDigiCollection> rpcDigis;
|
122 |
static std::string rpcDigisCollName = theConfig.getParameter<std::string>("rpcDigisCollName");
|
123 |
ev.getByLabel( rpcDigisCollName, rpcDigis);
|
124 |
static bool warnNoColl = theConfig.getUntrackedParameter<bool>("warnNoColl" , true);
|
125 |
if (!rpcDigis.isValid()) {
|
126 |
if (warnNoColl) std::cout <<"** WARNING: not collection: "<< rpcDigisCollName << std::endl;
|
127 |
return result;
|
128 |
}
|
129 |
|
130 |
for (RPCDigiCollection::DigiRangeIterator ic=rpcDigis->begin(); ic != rpcDigis->end(); ++ic) {
|
131 |
RPCDetId rpcDetId = (*ic).first;
|
132 |
std::vector<unsigned int> strips;
|
133 |
for (RPCDigiCollection::const_iterator it = (*ic).second.first; it != (*ic).second.second; ++it) strips.push_back(it->strip());
|
134 |
std::sort(strips.begin(), strips.end());
|
135 |
for (std::vector<unsigned int>::const_iterator it=strips.begin(); it!=strips.end(); ++it) {
|
136 |
unsigned int s = *it;
|
137 |
if (result.empty() || (result.back().rawId() != rpcDetId.rawId()) ) result.push_back( RPCDigiSpec( rpcDetId.rawId(), s, s ) );
|
138 |
else if (s - result.back().toStrip() == 1) result.back().setToStrip(s);
|
139 |
else if (s - result.back().toStrip() > 1) result.push_back( RPCDigiSpec( rpcDetId.rawId(), s, s ) );
|
140 |
}
|
141 |
}
|
142 |
|
143 |
// for (std::vector<RPCDigiSpec>::const_iterator id=result.begin(); id != result.end(); ++id) {
|
144 |
// std::cout <<" DET: "<< id->rawId() <<" from: "<< id->fromStrip()<<" to:"<< id->toStrip() << std::endl;
|
145 |
// }
|
146 |
|
147 |
// edm::ESHandle<RPCGeometry> rpcGeometry;
|
148 |
// es.get<MuonGeometryRecord>().get(rpcGeometry);
|
149 |
// const TrackingGeometry::DetIdContainer & detIds = rpcGeometry->detIds();
|
150 |
// for (TrackingGeometry::DetIdContainer::const_iterator it = detIds.begin(); it != detIds.end(); ++it) {
|
151 |
// const RPCDigiCollection::Range range = rpcDigis->get(*it);
|
152 |
// if (range.first != range.second) {
|
153 |
// RPCDetId rpcDet(*it);
|
154 |
// RPCDetIdUtil rpcDetUtil( rpcDet );
|
155 |
// std::cout <<"DET: "<< rpcDetUtil << std::endl;
|
156 |
// for (RPCDigiCollection::const_iterator id = range.first; id != range.second; ++id) id->print() ;
|
157 |
// }
|
158 |
// }
|
159 |
return result;
|
160 |
}
|
161 |
|
162 |
std::vector<CSCDigiSpec> DetHitDigiGrabber::cscDetDigis(const edm::Event &ev, const edm::EventSetup &es) const
|
163 |
{
|
164 |
std::vector<CSCDigiSpec> result;
|
165 |
|
166 |
edm::Handle<CSCCorrelatedLCTDigiCollection> lctDigiColls;
|
167 |
static std::string cscDigisCollName = theConfig.getParameter<std::string>("cscCorrelatedLCTDigisCollName");
|
168 |
ev.getByLabel(cscDigisCollName,lctDigiColls);
|
169 |
static bool warnNoColl = theConfig.getUntrackedParameter<bool>("warnNoColl" , true);
|
170 |
if (!lctDigiColls.isValid()) {
|
171 |
if (warnNoColl) std::cout <<"** WARNING: not collection: "<< cscDigisCollName<< std::endl;
|
172 |
return result;
|
173 |
}
|
174 |
typedef CSCCorrelatedLCTDigiCollection::DigiRangeIterator DRI;
|
175 |
for (DRI lctDigiColl = lctDigiColls->begin(); lctDigiColl != lctDigiColls->end(); lctDigiColl++) {
|
176 |
typedef CSCCorrelatedLCTDigiCollection::const_iterator DI;
|
177 |
for (DI lctDigi = (*lctDigiColl).second.first; lctDigi != (*lctDigiColl).second.second; lctDigi++) {
|
178 |
if (lctDigi->isValid()) {
|
179 |
result.push_back( CSCDigiSpec((*lctDigiColl).first, *lctDigi));
|
180 |
// std::cout << CSCDigiSpec((*lctDigiColl).first, *lctDigi) << std::endl;
|
181 |
// (*lctDigi).print();
|
182 |
}
|
183 |
}
|
184 |
}
|
185 |
return result;
|
186 |
}
|
187 |
|
188 |
std::vector<DTphDigiSpec> DetHitDigiGrabber::dtPhiDetDigis(const edm::Event &ev, const edm::EventSetup &es) const
|
189 |
{
|
190 |
std::vector<DTphDigiSpec> result;
|
191 |
edm::Handle<L1MuDTChambPhContainer> dtPhiDigiColls;
|
192 |
static std::string dtDigisCollName = theConfig.getParameter<std::string>("dtDigiCollName");
|
193 |
static bool warnNoColl = theConfig.getUntrackedParameter<bool>("warnNoColl" , true);
|
194 |
ev.getByLabel(dtDigisCollName,dtPhiDigiColls);
|
195 |
if (!dtPhiDigiColls.isValid()) {
|
196 |
if (warnNoColl) std::cout <<"** WARNING: not collection: "<< dtDigisCollName<< std::endl;
|
197 |
return result;
|
198 |
}
|
199 |
L1MuDTChambPhContainer::Phi_Container * phi_Container = dtPhiDigiColls->getContainer();
|
200 |
typedef L1MuDTChambPhContainer::Phi_iterator IP;
|
201 |
|
202 |
for (IP ip = phi_Container->begin(); ip < phi_Container->end(); ip++){
|
203 |
const L1MuDTChambPhDigi& phDigi = (*ip);
|
204 |
result.push_back( DTphDigiSpec(phDigi));
|
205 |
/*
|
206 |
DTphDigiSpec d(phDigi);
|
207 |
if ( (d.phi() != phDigi.phi())
|
208 |
|| (d.phiB() != phDigi.phiB())
|
209 |
|| (d.code() != phDigi.code())
|
210 |
|| (d.bxNum() != phDigi.bxNum())
|
211 |
|| (d.bxCnt() != phDigi.BxCnt())
|
212 |
|| (d.ts2() != phDigi.Ts2Tag()) ) {
|
213 |
std::cout <<" ************* WARNING: " << std::endl;
|
214 |
std::cout <<"DT_PH: wheel: "<<phDigi.whNum()
|
215 |
<<", station: "<<phDigi.stNum()
|
216 |
<<", sector: "<<phDigi.scNum()
|
217 |
<<", phi: "<<phDigi.phi()
|
218 |
<<", phiB: "<<phDigi.phiB()
|
219 |
<<", q,bx,bxCnt,ts2: "<<phDigi.code()<<" "<<phDigi.bxNum()<<" "<<phDigi.BxCnt()<<" "<<phDigi.Ts2Tag()
|
220 |
<<std::endl;
|
221 |
std::cout << result.back() <<std::endl;
|
222 |
}
|
223 |
*/
|
224 |
}
|
225 |
return result;
|
226 |
}
|
227 |
/*
|
228 |
void DetHitDigiGrabber::dtEtaDetDigis(const edm::Event &ev, const edm::EventSetup &es) co
|
229 |
{
|
230 |
edm::Handle<L1MuDTChambThContainer> dtThetaDigiColls;
|
231 |
static std::string dtDigisCollName = theConfig.getParameter<std::string>("dtDigiCollName");
|
232 |
static bool warnNoColl = theConfig.getUntrackedParameter<bool>("warnNoColl" , true);
|
233 |
ev.getByLabel(dtDigisCollName,dtThetaDigiColls);
|
234 |
if (!dtThetaDigiColls.isValid()) {
|
235 |
if (warnNoColl) std::cout <<"** WARNING: not collection: "<< dtDigisCollName<< std::endl;
|
236 |
return;
|
237 |
}
|
238 |
L1MuDTChambThContainer::The_Container * theta_Container = dtThetaDigiColls->getContainer();
|
239 |
typedef L1MuDTChambThContainer::The_iterator IT;
|
240 |
for (IT it = theta_Container->begin(); it < theta_Container->end(); it++){
|
241 |
const L1MuDTChambThDigi& thDigi = (*it);
|
242 |
std::cout <<"DT_TH: wheel: "<<thDigi.whNum()
|
243 |
<<", station: "<<thDigi.stNum()
|
244 |
<<", sector: "<<thDigi.scNum()
|
245 |
<<std::endl;
|
246 |
}
|
247 |
}
|
248 |
*/
|
249 |
|
250 |
void DetHitDigiGrabber::initHistos(TObjArray & histos)
|
251 |
{
|
252 |
|
253 |
hDetHitDigiGrabber_DphiVsPt_Bar = new TH2D("hDetHitDigiGrabber_DphiVsPt_Bar","hDetHitDigiGrabber_DphiVsPt_Bar",100,1.,20.,150.,0.,1.5);
|
254 |
histos.Add(hDetHitDigiGrabber_DphiVsPt_Bar);
|
255 |
hDetHitDigiGrabber_DphiVsPt_End = new TH2D("hDetHitDigiGrabber_DphiVsPt_End","hDetHitDigiGrabber_DphiVsPt_End",100,1.,20.,150.,0.,1.5);
|
256 |
histos.Add(hDetHitDigiGrabber_DphiVsPt_End);
|
257 |
}
|
258 |
|