CMS 3D CMS Logo

CSCTFAnalyzer.cc
Go to the documentation of this file.
7 
8 //consumes
14 
15 #include <TTree.h>
16 #include <TFile.h>
17 
19 private:
21  TTree *tree;
22  TFile *file;
23  int dtPhi[12][2];
24 
29 
30 public:
31  void analyze(const edm::Event &e, const edm::EventSetup &c) override;
32 
33  explicit CSCTFAnalyzer(const edm::ParameterSet &conf);
34  ~CSCTFAnalyzer(void) override {
35  file->cd();
36  tree->Write();
37  file->Close();
38  }
39 };
40 
43 
44 #include <strings.h>
45 #include <cerrno>
46 #include <iostream>
47 #include <iomanip>
48 
49 CSCTFAnalyzer::CSCTFAnalyzer(const edm::ParameterSet &conf) : edm::one::EDAnalyzer<>() {
50  mbProducer = conf.getUntrackedParameter<edm::InputTag>("mbProducer", edm::InputTag("csctfunpacker"));
51  lctProducer = conf.getUntrackedParameter<edm::InputTag>("lctProducer", edm::InputTag("csctfunpacker"));
52  trackProducer = conf.getUntrackedParameter<edm::InputTag>("trackProducer", edm::InputTag("csctfunpacker"));
53  statusProducer = conf.getUntrackedParameter<edm::InputTag>("statusProducer", edm::InputTag("csctfunpacker"));
54  file = new TFile("ewq.root", "RECREATE");
55  tree = new TTree("dy", "QWE");
56  tree->Branch("dtPhi_1_plus", &dtPhi[0][0], "dtPhi_1_plus/I");
57  tree->Branch("dtPhi_2_plus", &dtPhi[1][0], "dtPhi_2_plus/I");
58  tree->Branch("dtPhi_3_plus", &dtPhi[2][0], "dtPhi_3_plus/I");
59  tree->Branch("dtPhi_4_plus", &dtPhi[3][0], "dtPhi_4_plus/I");
60  tree->Branch("dtPhi_5_plus", &dtPhi[4][0], "dtPhi_5_plus/I");
61  tree->Branch("dtPhi_6_plus", &dtPhi[5][0], "dtPhi_6_plus/I");
62  tree->Branch("dtPhi_7_plus", &dtPhi[6][0], "dtPhi_7_plus/I");
63  tree->Branch("dtPhi_8_plus", &dtPhi[7][0], "dtPhi_8_plus/I");
64  tree->Branch("dtPhi_9_plus", &dtPhi[8][0], "dtPhi_9_plus/I");
65  tree->Branch("dtPhi_10_plus", &dtPhi[9][0], "dtPhi_10_plus/I");
66  tree->Branch("dtPhi_11_plus", &dtPhi[10][0], "dtPhi_11_plus/I");
67  tree->Branch("dtPhi_12_plus", &dtPhi[11][0], "dtPhi_12_plus/I");
68  tree->Branch("dtPhi_1_minus", &dtPhi[0][1], "dtPhi_1_minus/I");
69  tree->Branch("dtPhi_2_minus", &dtPhi[1][1], "dtPhi_2_minus/I");
70  tree->Branch("dtPhi_3_minus", &dtPhi[2][1], "dtPhi_3_minus/I");
71  tree->Branch("dtPhi_4_minus", &dtPhi[3][1], "dtPhi_4_minus/I");
72  tree->Branch("dtPhi_5_minus", &dtPhi[4][1], "dtPhi_5_minus/I");
73  tree->Branch("dtPhi_6_minus", &dtPhi[5][1], "dtPhi_6_minus/I");
74  tree->Branch("dtPhi_7_minus", &dtPhi[6][1], "dtPhi_7_minus/I");
75  tree->Branch("dtPhi_8_minus", &dtPhi[7][1], "dtPhi_8_minus/I");
76  tree->Branch("dtPhi_9_minus", &dtPhi[8][1], "dtPhi_9_minus/I");
77  tree->Branch("dtPhi_10_minus", &dtPhi[9][1], "dtPhi_10_minus/I");
78  tree->Branch("dtPhi_11_minus", &dtPhi[10][1], "dtPhi_11_minus/I");
79  tree->Branch("dtPhi_12_minus", &dtPhi[11][1], "dtPhi_12_minus/I");
80 
81  L1CSCS_Tok = consumes<L1CSCStatusDigiCollection>(edm::InputTag(statusProducer.label(), statusProducer.instance()));
82  CSCTC_Tok =
83  consumes<CSCTriggerContainer<csctf::TrackStub> >(edm::InputTag(mbProducer.label(), mbProducer.instance()));
84  CSCCDC_Tok = consumes<CSCCorrelatedLCTDigiCollection>(edm::InputTag(lctProducer.label(), lctProducer.instance()));
85  L1CST_Tok = consumes<L1CSCTrackCollection>(edm::InputTag(trackProducer.label(), trackProducer.instance()));
86 }
87 
89  /* edm::Handle<FEDRawDataCollection> rawdata;
90  e.getByToken("source","",rawdata);
91 
92  const FEDRawData& fedData = rawdata->FEDData(750);
93  if( fedData.size()==0 ) return;
94  unsigned short *data = (unsigned short *)fedData.data();
95  unsigned int size = fedData.size()/2;
96  std::cout<<"New event:"<<std::endl;
97  for(unsigned i=0; i<size/4; i++)
98  std::cout<<std::hex<<" "<<std::setw(6)<<data[i*4+0]<<" "<<std::setw(6)<<data[i*4+1]<<" "<<std::setw(6)<<data[i*4+2]<<" "<<std::setw(6)<<data[i*4+3]<<std::dec<<std::endl;
99  std::cout<<"End of event"<<std::endl;
100  return;
101 */
102  if (statusProducer.label() != "null") {
104  e.getByToken(L1CSCS_Tok, status);
105  if (status.isValid()) {
106  edm::LogInfo("CSCTFAnalyzer") << " Unpacking Errors: " << status->first;
107  for (std::vector<L1CSCSPStatusDigi>::const_iterator stat = status->second.begin(); stat != status->second.end();
108  stat++) {
109  //edm::LogInfo("CSCTFAnalyzer") << " Status: SP in slot "<<stat->slot()<<" FMM: "<<stat->FMM()<<" SE: 0x"<<std::hex<<stat->SEs()<<" VP: 0x"<<stat->VPs()<<std::dec;
110  }
111  } else
112  edm::LogInfo("CSCTFAnalyzer") << " No valid L1CSCStatusDigiCollection products found";
113  }
114 
115  if (mbProducer.label() != "null") {
116  bzero(dtPhi, sizeof(dtPhi));
118  e.getByToken(CSCTC_Tok, dtStubs);
119  if (dtStubs.isValid()) {
120  std::vector<csctf::TrackStub> vstubs = dtStubs->get();
121  std::cout << "DT size=" << vstubs.end() - vstubs.begin() << std::endl;
122  for (std::vector<csctf::TrackStub>::const_iterator stub = vstubs.begin(); stub != vstubs.end(); stub++) {
123  int dtSector = (stub->sector() - 1) * 2 + stub->subsector() - 1;
124  int dtEndcap = stub->endcap() - 1;
125  if (dtSector >= 0 && dtSector < 12 && dtEndcap >= 0 && dtEndcap < 2) {
126  dtPhi[dtSector][dtEndcap] = stub->phiPacked();
127  } else {
128  edm::LogInfo("CSCTFAnalyzer: DT digi are out of range: ")
129  << " dtSector=" << dtSector << " dtEndcap=" << dtEndcap;
130  }
131  edm::LogInfo("CSCTFAnalyzer") << " DT data: tbin=" << stub->BX() << " CSC sector=" << stub->sector()
132  << " CSC subsector=" << stub->subsector() << " station=" << stub->station()
133  << " endcap=" << stub->endcap() << " phi=" << stub->phiPacked()
134  << " phiBend=" << stub->getBend() << " quality=" << stub->getQuality()
135  << " mb_bxn=" << stub->cscid();
136  }
137  } else
138  edm::LogInfo("CSCTFAnalyzer") << " No valid CSCTriggerContainer<csctf::TrackStub> products found";
139  tree->Fill();
140  }
141 
142  if (lctProducer.label() != "null") {
144  e.getByToken(CSCCDC_Tok, corrlcts);
145  if (corrlcts.isValid()) {
147  csc != corrlcts.product()->end();
148  csc++) {
149  int lctId = 0;
150  CSCCorrelatedLCTDigiCollection::Range range1 = corrlcts.product()->get((*csc).first);
151  for (CSCCorrelatedLCTDigiCollection::const_iterator lct = range1.first; lct != range1.second; lct++, lctId++) {
152  int station = (*csc).first.station() - 1;
153  int cscId = (*csc).first.triggerCscId() - 1;
154  int sector = (*csc).first.triggerSector() - 1; // + ( (*csc).first.endcap()==1 ? 0 : 6 );
155  int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
156  int tbin = lct->getBX();
157  int fpga = (subSector ? subSector - 1 : station + 1);
158  // If Det Id is within range
159  if (sector < 0 || sector > 11 || station < 0 || station > 3 || cscId < 0 || cscId > 8 || lctId < 0 ||
160  lctId > 1) {
161  edm::LogInfo("CSCTFAnalyzer: CSC digi are out of range: ");
162  continue;
163  }
164  edm::LogInfo("CSCTFAnalyzer") << " Front data endcap: " << (*csc).first.endcap()
165  << " station: " << (station + 1) << " sector: " << (sector + 1)
166  << " subSector: " << subSector << " tbin: " << tbin
167  << " cscId: " << (cscId + 1) << " fpga: " << (fpga + 1) << " "
168  << "LCT(vp=" << lct->isValid() << ",qual=" << lct->getQuality()
169  << ",wg=" << lct->getKeyWG() << ",strip=" << lct->getStrip()
170  << ",link=" << lct->getMPCLink() << ")";
171  }
172  }
173  } else
174  edm::LogInfo("CSCTFAnalyzer") << " No valid CSCCorrelatedLCTDigiCollection products found";
175  }
176 
177  if (trackProducer.label() != "null") {
179  e.getByToken(L1CST_Tok, tracks);
180  if (tracks.isValid()) {
181  int nTrk = 0;
182  for (L1CSCTrackCollection::const_iterator trk = tracks->begin(); trk < tracks->end(); trk++, nTrk++) {
183  int sector = 6 * (trk->first.endcap() - 1) + trk->first.sector() - 1;
184  int tbin = trk->first.BX();
185  edm::LogInfo("CSCTFAnalyzer") << " Track sector: " << (sector + 1) << " tbin: " << tbin << " "
186  << "TRK(mode=" << ((trk->first.ptLUTAddress() >> 16) & 0xF)
187  << ",eta=" << trk->first.eta_packed() << ",phi=" << trk->first.localPhi()
188  << ") IDs:"
189  << " me1D=" << trk->first.me1ID() << " t1=" << trk->first.me1Tbin()
190  << " me2D=" << trk->first.me2ID() << " t2=" << trk->first.me2Tbin()
191  << " me3D=" << trk->first.me3ID() << " t3=" << trk->first.me3Tbin()
192  << " me4D=" << trk->first.me4ID() << " t4=" << trk->first.me4Tbin()
193  << " mb1D=" << trk->first.mb1ID() << " tb=" << trk->first.mb1Tbin();
194 
195  for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator csc = trk->second.begin(); csc != trk->second.end();
196  csc++) {
197  int lctId = 0;
198  CSCCorrelatedLCTDigiCollection::Range range1 = trk->second.get((*csc).first);
199  for (CSCCorrelatedLCTDigiCollection::const_iterator lct = range1.first; lct != range1.second;
200  lct++, lctId++) {
201  int station = (*csc).first.station() - 1;
202  int cscId = (*csc).first.triggerCscId() - 1;
203  int sector = (*csc).first.triggerSector() - 1; // + ( (*csc).first.endcap()==1 ? 0 : 6 );
204  int subSector = CSCTriggerNumbering::triggerSubSectorFromLabels((*csc).first);
205  int tbin = lct->getBX();
206  int fpga = (subSector ? subSector - 1 : station + 1);
207  // If Det Id is within range
208  if (sector < 0 || sector > 11 || station < 0 || station > 3 || cscId < 0 || cscId > 8 || lctId < 0 ||
209  lctId > 1) {
210  edm::LogInfo("CSCTFAnalyzer: Digi are out of range: ");
211  continue;
212  }
213  if (lct->getQuality() < 100)
214  edm::LogInfo("CSCTFAnalyzer")
215  << " Linked LCT: " << (*csc).first.endcap() << " station: " << (station + 1)
216  << " sector: " << (sector + 1) << " subSector: " << subSector << " tbin: " << tbin
217  << " cscId: " << (cscId + 1) << " fpga: " << (fpga + 1) << " LCT(vp=" << lct->isValid()
218  << ",qual=" << lct->getQuality() << ",wg=" << lct->getKeyWG() << ",strip=" << lct->getStrip() << ")";
219  else
220  edm::LogInfo("CSCTFAnalyzer")
221  << " Linked MB stub: " << (*csc).first.endcap() << " sector: " << (sector + 1)
222  << " subSector: " << subSector << " tbin: " << tbin << " MB(vp=" << lct->isValid()
223  << ",qual=" << (lct->getQuality() - 100) << ",cal=" << lct->getKeyWG() << ",flag=" << lct->getStrip()
224  << ",bc0=" << lct->getPattern() << ",phiBend=" << lct->getBend() << ",tbin=" << lct->getBX()
225  << ",id=" << lct->getMPCLink() << ",bx0=" << lct->getBX0() << ",se=" << lct->getSyncErr()
226  << ",bxn=" << lct->getCSCID() << ",phi=" << lct->getTrknmb() << ")";
227  }
228  }
229  }
230  } else
231  edm::LogInfo("CSCTFAnalyzer") << " No valid L1CSCTrackCollection products found";
232  }
233 }
234 
edm::EDGetTokenT< CSCTriggerContainer< csctf::TrackStub > > CSCTC_Tok
std::string const & instance() const
Definition: InputTag.h:37
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T const * product() const
Definition: Handle.h:70
edm::InputTag mbProducer
CSCTFAnalyzer(const edm::ParameterSet &conf)
std::string const & label() const
Definition: InputTag.h:36
edm::InputTag lctProducer
T getUntrackedParameter(std::string const &, T const &) const
edm::InputTag statusProducer
Definition: L1Track.h:19
~CSCTFAnalyzer(void) override
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Log< level::Info, false > LogInfo
edm::InputTag trackProducer
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > CSCCDC_Tok
auto const & tracks
cannot be loose
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
static int triggerSubSectorFromLabels(int station, int chamber)
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
int dtPhi[12][2]
Definition: tree.py:1
edm::EDGetTokenT< L1CSCTrackCollection > L1CST_Tok
edm::EDGetTokenT< L1CSCStatusDigiCollection > L1CSCS_Tok