CMS 3D CMS Logo

CSCTFanalyzer.cc
Go to the documentation of this file.
1 #include "CSCTFanalyzer.h"
8 
10  verbose = pset.getUntrackedParameter<unsigned int>("verbose",0);
11  dataTrackProducer = pset.getUntrackedParameter<edm::InputTag>("dataTrackProducer",edm::InputTag("csctfDigis"));
12  emulTrackProducer = pset.getUntrackedParameter<edm::InputTag>("emulTrackProducer",edm::InputTag("csctfTrackDigis"));
13  lctProducer = pset.getUntrackedParameter<edm::InputTag>("lctProducer",edm::InputTag("csctfDigis"));
14  mbProducer = pset.getUntrackedParameter<edm::InputTag>("mbProducer", edm::InputTag("csctfDigis"));
15  file = new TFile("qwe.root","RECREATE");
16  tree = new TTree("dy","QWE");
17  tree->Branch("nDataMuons", &nDataMuons, "nDataMuons/I");
18  tree->Branch("dphi1", &dphi1, "dphi1/D");
19  tree->Branch("dphi2", &dphi2, "dphi2/D");
20  tree->Branch("dphi3", &dphi3, "dphi3/D");
21  tree->Branch("deta1", &deta1, "deta1/D");
22  tree->Branch("deta2", &deta2, "deta2/D");
23  tree->Branch("deta3", &deta3, "deta3/D");
24  tree->Branch("dpt1", &dpt1, "dpt1/I");
25  tree->Branch("dpt2", &dpt2, "dpt2/I");
26  tree->Branch("dpt3", &dpt3, "dpt3/I");
27  tree->Branch("dch1", &dch1, "dch1/I");
28  tree->Branch("dch2", &dch2, "dch2/I");
29  tree->Branch("dch3", &dch3, "dch3/I");
30  tree->Branch("dbx1", &dbx1, "dbx1/I");
31  tree->Branch("dbx2", &dbx2, "dbx2/I");
32  tree->Branch("dbx3", &dbx3, "dbx3/I");
33  tree->Branch("drank1",&drank1,"drank1/I");
34  tree->Branch("drank2",&drank2,"drank2/I");
35  tree->Branch("drank3",&drank3,"drank3/I");
36  tree->Branch("dmode1",&dmode1,"dmode1/I");
37  tree->Branch("dmode2",&dmode2,"dmode2/I");
38  tree->Branch("dmode3",&dmode3,"dmode3/I");
39  tree->Branch("dlcts1",&dlcts1,"dlcts1/I");
40  tree->Branch("dlcts2",&dlcts2,"dlcts2/I");
41  tree->Branch("dlcts3",&dlcts3,"dlcts3/I");
42 
43  tree->Branch("nEmulMuons", &nEmulMuons, "nEmulMuons/I");
44  tree->Branch("ephi1", &ephi1, "ephi1/D");
45  tree->Branch("ephi2", &ephi2, "ephi2/D");
46  tree->Branch("ephi3", &ephi3, "ephi3/D");
47  tree->Branch("eeta1", &eeta1, "eeta1/D");
48  tree->Branch("eeta2", &eeta2, "eeta2/D");
49  tree->Branch("eeta3", &eeta3, "eeta3/D");
50  tree->Branch("ept1", &ept1, "ept1/I");
51  tree->Branch("ept2", &ept2, "ept2/I");
52  tree->Branch("ept3", &ept3, "ept3/I");
53  tree->Branch("ech1", &ech1, "ech1/I");
54  tree->Branch("ech2", &ech2, "ech2/I");
55  tree->Branch("ech3", &ech3, "ech3/I");
56  tree->Branch("ebx1", &ebx1, "ebx1/I");
57  tree->Branch("ebx2", &ebx2, "ebx2/I");
58  tree->Branch("ebx3", &ebx3, "ebx3/I");
59  tree->Branch("erank1",&erank1,"erank1/I");
60  tree->Branch("erank2",&erank2,"erank2/I");
61  tree->Branch("erank3",&erank3,"erank3/I");
62  tree->Branch("emode1",&emode1,"emode1/I");
63  tree->Branch("emode2",&emode2,"emode2/I");
64  tree->Branch("emode3",&emode3,"emode3/I");
65 
66  ts=nullptr;
67 }
68 
70  tree->Write();
71  file->Write();
72  file->Close();
73 }
74 
76  if(!ts){
78  es.get< L1MuTriggerScalesRcd >().get(scales);
79  ts = scales.product();
80  }
81 
82  if( lctProducer.label() != "null" ){
85 
86  for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc=LCTs.product()->begin(); csc!=LCTs.product()->end(); csc++){
87  int lctId=0;
88 
89  CSCCorrelatedLCTDigiCollection::Range range1 = LCTs.product()->get((*csc).first);
90  for(CSCCorrelatedLCTDigiCollection::const_iterator lct=range1.first; lct!=range1.second; lct++,lctId++){
91  int station = (*csc).first.station()-1;
92  int cscId = (*csc).first.triggerCscId()-1;
93  int sector = (*csc).first.triggerSector()-1 + ( (*csc).first.endcap()==1 ? 0 : 6 );
94  //int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
95  int tbin = lct->getBX();
96  //int fpga = ( subSector ? subSector-1 : station+1 );
97  if((verbose&1)==1)
98  std::cout<<"LCT in station="<<(station+1)<<" sector="<<(sector+1)<<" cscId="<<(cscId+1)<<" bx="<<tbin<<std::endl;
99  }
100  }
101  }
102 
103  if( mbProducer.label() != "null" ){
106  if( dtStubs.isValid() ){
107  std::vector<csctf::TrackStub> vstubs = dtStubs->get();
108  for(std::vector<csctf::TrackStub>::const_iterator stub=vstubs.begin(); stub!=vstubs.end(); stub++){
109  //int dtSector =(stub->sector()-1)*2 + stub->subsector()-1;
110  //int dtEndcap = stub->endcap()-1;
111  std::cout<<" DT data: tbin="<<stub->BX()<<" (CSC) sector="<<stub->sector()<<" (CSC) subsector="<<stub->subsector()<<" station="<<stub->station()<<" endcap="<<stub->endcap()
112  <<" phi="<<stub->phiPacked()<<" phiBend="<<stub->getBend()<<" quality="<<stub->getQuality()<<" id="<<stub->getMPCLink()<<" mb_bxn="<<stub->cscid()<<std::endl;
113  }
114 
115  } else edm::LogInfo("CSCTFAnalyzer")<<" No valid CSCTriggerContainer<csctf::TrackStub> products found";
116  }
117 
118  nDataMuons = 0; nEmulMuons = 0;
119  dphi1=-1; deta1=-1; dpt1=-1; dch1=-1, dbx1=-10;
120  dphi2=-1; deta2=-1; dpt2=-1; dch2=-1, dbx2=-10;
121  dphi3=-1; deta3=-1; dpt3=-1; dch3=-1, dbx3=-10;
122  drank1=-1;drank2=-1;drank3=-1;
123  dmode1=-1;dmode2=-1;dmode3=-1;
124  dlcts1= 0;dlcts2= 0;dlcts3= 0;
125  ephi1=-1; eeta1=-1; ept1=-1; ech1=-1, ebx1=-10;
126  ephi2=-1; eeta2=-1; ept2=-1; ech2=-1, ebx2=-10;
127  ephi3=-1; eeta3=-1; ept3=-1; ech3=-1, ebx3=-10;
128  erank1=-1;erank2=-1;erank3=-1;
129  emode1=-1;emode2=-1;emode3=-1;
130 
131  if( dataTrackProducer.label() != "null" ){
134  // Muon sorter emulation:
135  std::vector<csc::L1Track> result;
136  CSCTriggerContainer<csc::L1Track> stripped_tracks;
137  for(L1CSCTrackCollection::const_iterator tmp_trk=tracks->begin(); tmp_trk!=tracks->end(); tmp_trk++){
138  csc::L1Track qqq(tmp_trk->first);
139  qqq.setOutputLink(0);
140  CSCCorrelatedLCTDigiCollection qwe = tmp_trk->second;
141  for(CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc=qwe.begin(); csc!=qwe.end(); csc++){
142  CSCCorrelatedLCTDigiCollection::Range range1 = qwe.get((*csc).first);
143  for(CSCCorrelatedLCTDigiCollection::const_iterator lct=range1.first; lct!=range1.second; lct++)
144  qqq.setOutputLink( qqq.outputLink()|(1<<(*csc).first.station()) );
145  }
146  stripped_tracks.push_back(qqq);
147  }
148  // First we sort and crop the incoming tracks based on their rank.
149  for(int bx = -3; bx <= 3; ++bx){ // switch back into signed BX
150  std::vector<csc::L1Track> tks = stripped_tracks.get(bx);
151  std::sort(tks.begin(),tks.end(),std::greater<csc::L1Track>());
152  if(tks.size() > 4) tks.resize(4); // resize to max number of muons the MS can output
153  for(std::vector<csc::L1Track>::iterator itr=tks.begin(); itr!=tks.end(); itr++){
154  unsigned gbl_phi = itr->localPhi() + ((itr->sector() - 1)*24) + 6; // for now, convert using this.. LUT in the future
155  if(gbl_phi > 143) gbl_phi -= 143;
156  itr->setPhiPacked(gbl_phi & 0xff);
157  unsigned eta_sign = (itr->endcap() == 1 ? 0 : 1);
158  int gbl_eta = itr->eta_packed() | eta_sign << (L1MuRegionalCand::ETA_LENGTH - 1);
159  itr->setEtaPacked(gbl_eta & 0x3f);
160  itr->setQualityPacked((itr->rank()>>4) & 0x3);
161  itr->setPtPacked(itr->rank() & 0x1f);
162  if(!itr->empty()) result.push_back(*itr);
163  }
164  }
165 // for(std::vector<csc::L1Track>::const_iterator trk=result.begin(); trk!=result.end(); trk++){
166  for(L1CSCTrackCollection::const_iterator _trk=tracks->begin(); _trk!=tracks->end(); _trk++){ const csc::L1Track *trk = &(_trk->first);
167  switch(nDataMuons){
168  case 0:
169  dphi1 = ts->getPhiScale()->getLowEdge( trk->phi_packed() );
171  dpt1 = trk->pt_packed();
172  dch1 = trk->charge_packed();
173  dbx1 = trk->BX();
174  dmode1= trk->mode();
175  drank1= trk->rank();
176  dlcts1= trk->outputLink();
177  break;
178  case 1:
179  dphi2 = ts->getPhiScale()->getLowEdge( trk->phi_packed() );
181  dpt2 = trk->pt_packed();
182  dch2 = trk->charge_packed();
183  dbx2 = trk->BX();
184  dmode2= trk->mode();
185  drank2= trk->rank();
186  dlcts2= trk->outputLink();
187  break;
188  case 2:
189  dphi3 = ts->getPhiScale()->getLowEdge( trk->phi_packed() );
191  dpt3 = trk->pt_packed();
192  dch3 = trk->charge_packed();
193  dbx3 = trk->BX();
194  dmode3= trk->mode();
195  drank3= trk->rank();
196  dlcts3= trk->outputLink();
197  break;
198  default: break;
199  }
200  if( (verbose&2)==2 )
201  std::cout<<"Data: TRK in endcap="<<trk->endcap()<<" sector="<<trk->sector()<<" bx="<<trk->BX()
202  <<" (rank="<<trk->rank()
203  <<" localPhi="<<trk->localPhi()
204  <<" etaPacked="<<trk->eta_packed()
205  <<" me1D="<<trk->me1ID()
206  <<" me2D="<<trk->me2ID()
207  <<" me3D="<<trk->me3ID()
208  <<" me4D="<<trk->me4ID()
209  <<" mb1D="<<trk->mb1ID()
210  <<" pTaddr="<<std::hex<<trk->ptLUTAddress()<<std::dec
211  <<")"<<std::endl;
212  nDataMuons++;
213  }
214  }
215 
216  if( emulTrackProducer.label() != "null" ){
219  for(L1CSCTrackCollection::const_iterator trk=tracks.product()->begin(); trk!=tracks.product()->end(); trk++){
220  switch(nEmulMuons){
221  case 0:
222  ephi1 = trk->first.localPhi();
223  eeta1 = trk->first.eta_packed();
224  ept1 = trk->first.pt_packed();
225  ech1 = trk->first.charge_packed();
226  ebx1 = trk->first.BX();
227  break;
228  case 1:
229  ephi2 = trk->first.localPhi();
230  eeta2 = trk->first.eta_packed();
231  ept2 = trk->first.pt_packed();
232  ech2 = trk->first.charge_packed();
233  ebx2 = trk->first.BX();
234  break;
235  case 2:
236  ephi3 = trk->first.localPhi();
237  eeta3 = trk->first.eta_packed();
238  ept3 = trk->first.pt_packed();
239  ech3 = trk->first.charge_packed();
240  ebx3 = trk->first.BX();
241  break;
242  default: break;
243  }
244  if( (verbose&2)==2 )
245  std::cout<<"Emulator: TRK in endcap="<<trk->first.endcap()<<" sector="<<trk->first.sector()<<" bx="<<trk->first.BX()
246  <<" (rank="<<trk->first.rank()
247  <<" localPhi="<<trk->first.localPhi()
248  <<" etaPacked="<<trk->first.eta_packed()
249  <<" me1D="<<trk->first.me1ID()
250  <<" me2D="<<trk->first.me2ID()
251  <<" me3D="<<trk->first.me3ID()
252  <<" me4D="<<trk->first.me4ID()
253  <<" mb1D="<<trk->first.mb1ID()
254  <<" pTaddr="<<std::hex<<trk->first.ptLUTAddress()<<std::dec
255  <<")"<<std::endl;
256  nEmulMuons++;
257  }
258  }
259 
260  tree->Fill();
261 }
unsigned mode(void) const
Definition: L1Track.h:88
T getUntrackedParameter(std::string const &, T const &) const
std::vector< T > get() const
void analyze(edm::Event const &e, edm::EventSetup const &iSetup) override
unsigned me1ID() const
Definition: L1Track.h:38
unsigned me2ID() const
Definition: L1Track.h:39
unsigned charge_packed() const
return charge packed as in hardware (0=pos, 1=neg)
edm::InputTag mbProducer
Definition: CSCTFanalyzer.h:18
virtual float getCenter(unsigned packed) const =0
get the center of bin represented by packed
void push_back(const T &data)
void endJob(void) override
edm::InputTag lctProducer
Definition: CSCTFanalyzer.h:18
unsigned mb1ID() const
Definition: L1Track.h:42
const L1MuScale * getPhiScale() const
get the phi scale
unsigned ptLUTAddress() const
Definition: L1Track.h:56
unsigned eta_packed() const
return eta packed as in hardware
unsigned sector() const
Definition: L1Track.h:45
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:475
Definition: L1Track.h:19
unsigned rank() const
Definition: L1Track.cc:118
unsigned localPhi() const
Definition: L1Track.h:35
unsigned outputLink() const
Definition: L1Track.h:61
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:59
void setOutputLink(unsigned oPL)
Definition: L1Track.h:62
std::vector< CSCCorrelatedLCTDigi >::const_iterator const_iterator
std::string const & label() const
Definition: InputTag.h:36
const L1MuScale * getRegionalEtaScale(int isys) const
get the regioanl muon trigger eta scale, isys = 0(DT), 1(bRPC), 2(CSC), 3(fwdRPC) ...
const L1MuTriggerScales * ts
Definition: CSCTFanalyzer.h:34
HLT enums.
unsigned endcap() const
Definition: L1Track.h:44
virtual float getLowEdge(unsigned packed) const =0
get the low edge of bin represented by packed
CSCTFanalyzer(edm::ParameterSet const &pset)
Definition: CSCTFanalyzer.cc:9
edm::InputTag emulTrackProducer
Definition: CSCTFanalyzer.h:18
unsigned me4ID() const
Definition: L1Track.h:41
std::pair< const_iterator, const_iterator > Range
Definition: tree.py:1
unsigned pt_packed() const
return pt packed as in hardware
T const * product() const
Definition: ESHandle.h:86
std::string const & instance() const
Definition: InputTag.h:37
edm::InputTag dataTrackProducer
Definition: CSCTFanalyzer.h:18
int BX() const
Definition: L1Track.h:51
unsigned me3ID() const
Definition: L1Track.h:40
unsigned phi_packed() const
return phi packed as in hardware