CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TdeGCT.cc
Go to the documentation of this file.
2 #include <bitset>
3 
4 using namespace dedefs;
5 
7 
8  verbose_ = iConfig.getUntrackedParameter<int>("VerboseFlag",0);
9 
10  if(verbose())
11  std::cout << "L1TdeGCT::L1TdeGCT()...\n" << std::flush;
12 
13  DEsource_ = consumes<L1DataEmulRecord>(iConfig.getParameter<edm::InputTag>("DataEmulCompareSource"));
14  histFolder_ = iConfig.getUntrackedParameter<std::string>("HistFolder", "L1TEMU/GCTexpert");
15 
16  dbe = NULL;
17  if (iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
18  dbe = edm::Service<DQMStore>().operator->();
19  dbe->setVerbose(0);
20  }
21 
22  histFile_ = iConfig.getUntrackedParameter<std::string>("HistFile", "");
23  if(iConfig.getUntrackedParameter<bool> ("disableROOToutput", true))
24  histFile_ = "";
25 
26  if (histFile_.size()!=0) {
27  edm::LogInfo("OutputRootFile")
28  << "L1TEmulator GCT specific histograms will be saved to "
29  << histFile_.c_str()
30  << std::endl;
31  }
32 
33  if(dbe!=NULL)
34  dbe->setCurrentFolder(histFolder_);
35 
36  hasRecord_=true;
37 
38  if(verbose())
39  std::cout << "L1TdeGCT::L1TdeGCT()...done.\n" << std::flush;
40 }
41 
43 
44 void L1TdeGCT::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
45 
46  if(verbose())
47  std::cout << "L1TdeGCT::beginRun() start\n" << std::flush;
48 
49  if(dbe) {
50  dbe->setCurrentFolder(histFolder_);
51  dbe->rmdir(histFolder_);
52  }
53 
54  if(dbe) {
55  dbe->setCurrentFolder(histFolder_);
56 
57  // book histograms here
58  sysrates = dbe->book1D("sysrates","RATE OF COMPARISON FAILURES",nGctColl_, 0, nGctColl_ );
59 
60  for(int j=0; j<2; j++) {
61  std::string lbl("sysncand");
62  lbl += (j==0?"Data":"Emul");
63  std::string title("GCT OBJECT MULTIPLICITY ");
64  title += (j==0?"(DATA)":"(EMULATOR)");
65  sysncand[j] = dbe->book1D(lbl.data(),title.data(),nGctColl_, 0, nGctColl_ );
66  }
67 
68  for(int j=0; j<nGctColl_; j++) {
69 
70  dbe->setCurrentFolder(std::string(histFolder_+"/"+cLabel[j]));
71 
72  std::string lbl("");
73  std::string title("");
74  lbl.clear();
75  title.clear();
76  lbl+=cLabel[j];lbl+="ErrorFlag";
77  title+=cLabel[j];title+=" ErrorFlag";
78  errortype[j] = dbe->book1D(lbl.data(),title.data(), nerr, 0, nerr);
79 
80  lbl.clear();
81  title.clear();
82  lbl+=cLabel[j];lbl+="Eta";
83  title+=cLabel[j];title+=" ETA OF COMPARISON FAILURES";
84  eta[j] = dbe->book1D(lbl.data(),title.data(),
85  etaNBins, etaMinim, etaMaxim);
86  lbl.clear();
87  title.clear();
88  lbl+=cLabel[j];lbl+="Phi";
89  title+=cLabel[j];title+=" PHI OF COMPARISON FAILURES";
90  phi[j] = dbe->book1D(lbl.data(),title.data(),
91  phiNBins, phiMinim, phiMaxim);
92 
93  lbl.clear();
94  title.clear();
95  lbl+=cLabel[j];lbl+="Etaphi";
96  title+=cLabel[j];title+=" ETA PHI OF COMPARISON FAILURES";
97  etaphi[j] = dbe->book2D(lbl.data(),title.data(),
98  etaNBins, etaMinim, etaMaxim,
99  phiNBins, phiMinim, phiMaxim
100  );
101  lbl.clear();
102  title.clear();
103  lbl+=cLabel[j];lbl+="Rank";
104  title+=cLabel[j];title+=" RANK OF COMPARISON FAILURES";
105  rnk[j] = dbe->book1D(lbl.data(),title.data(),
106  rnkNBins, rnkMinim, rnkMaxim);
107  //
108  lbl.clear();
109  title.clear();
110  lbl+=cLabel[j];lbl+="Eta"; lbl+="Data";
111  title+=cLabel[j];title+=" ETA (DATA)";
112  etaData[j] = dbe->book1D(lbl.data(),title.data(),
113  etaNBins, etaMinim, etaMaxim);
114  lbl.clear();
115  title.clear();
116  lbl+=cLabel[j];lbl+="Phi"; lbl+="Data";
117  title+=cLabel[j];title+=" PHI (DATA)";
118  phiData[j] = dbe->book1D(lbl.data(),title.data(),
119  phiNBins, phiMinim, phiMaxim);
120 
121  lbl.clear();
122  title.clear();
123  lbl+=cLabel[j];lbl+="Rank"; lbl+="Data";
124  title+=cLabel[j];title+=" RANK (DATA)";
125  rnkData[j] = dbe->book1D(lbl.data(),title.data(),
126  rnkNBins, rnkMinim, rnkMaxim);
127  lbl.clear();
128  lbl+=cLabel[j];lbl+="Dword";
129  dword[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
130  lbl.clear();
131  lbl+=cLabel[j];lbl+="Eword";
132  eword[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
133  lbl.clear();
134  lbl+=cLabel[j];lbl+="DEword";
135  deword[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
136  //lbl.clear();
137  //lbl+=cLabel[j];lbl+="Masked";
138  //masked[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
139  }
140 
141  }
142 
143  for(int i=0; i<nGctColl_; i++) {
144  sysrates ->setBinLabel(i+1,cLabel[i]);
145  sysncand[0]->setBinLabel(i+1,cLabel[i]);
146  sysncand[1]->setBinLabel(i+1,cLabel[i]);
147  }
148 
149  for(int i=0; i<nGctColl_; i++) {
150  for(int j=0; j<nerr; j++) {
151  errortype[i]->setBinLabel(j+1,errLabel[j]);
152  }
153  }
154 
155  for(int i=0; i<nGctColl_; i++) {
156  etaphi [i]->setAxisTitle("GCT #eta",1);
157  etaphi [i]->setAxisTitle("GCT #phi",2);
158  eta [i]->setAxisTitle("GCT #eta");
159  phi [i]->setAxisTitle("GCT #phi");
160  rnk [i]->setAxisTitle("Rank");
161  etaData[i]->setAxisTitle("GCT #eta");
162  phiData[i]->setAxisTitle("GCT #phi");
163  rnkData[i]->setAxisTitle("Rank");
164  dword [i]->setAxisTitle("trigger data word bit");
165  eword [i]->setAxisTitle("trigger data word bit");
166  deword [i]->setAxisTitle("trigger data word bit");
167  //masked [i]->setAxisTitle("trigger data word bit");
168  }
169 
170  for(int i=0; i<nGctColl_; i++) {
171  colCount[i]=0;
172  nWithCol[i]=0;
173  }
174 
175  if(verbose())
176  std::cout << "L1TdeGCT::beginJob() end.\n" << std::flush;
177 }
178 
179 void
181 }
182 
183 void
185  if(verbose())
186  std::cout << "L1TdeGCT::endJob()...\n" << std::flush;
187 
188  if(histFile_.size()!=0 && dbe)
189  dbe->save(histFile_);
190 
191  if(verbose())
192  std::cout << "L1TdeGCT::endJob() end.\n" << std::flush;
193 }
194 
195 
196 // ------------ method called to for each event ------------
197 void
199 
200  if(!hasRecord_)
201  return;
202 
203  if(verbose())
204  std::cout << "L1TdeGCT::analyze() start\n" << std::flush;
205 
208  iEvent.getByToken(DEsource_, deRecord);
209 
210  if (!deRecord.isValid()) {
211  edm::LogInfo("DataNotFound")
212  << "Cannot find L1DataEmulRecord"
213  << " Please verify that comparator was successfully executed."
214  << " Emulator DQM for GCT will be skipped!"
215  << std::endl;
216  hasRecord_=false;
217  return;
218  }
219 
220  bool isComp = deRecord->get_isComp(GCT);
221  if(!isComp) {
222  if(verbose())
223  std::cout << "[L1TdeGCT] Gct information not generated in de-record."
224  << " Skiping event!\n" << std::flush;
225  return;
226  }
227 
228  int DEncand[2]={0};
229  for(int j=0; j<2; j++)
230  DEncand[j] = deRecord->getNCand(GCT,j);
231 
232  if(verbose())
233  std::cout << "[L1TdeGCT] ncands"
234  << " data: " << DEncand[0]
235  << " emul: " << DEncand[1]
236  << std::endl;
237 
238 
240  L1DEDigiCollection deColl;
241  deColl = deRecord->getColl();
242 
243  // extract the GCT comparison digis
244  L1DEDigiCollection gctColl;
245 
246  gctColl.reserve(20);
247  gctColl.clear();
248 
249 
250  for(L1DEDigiCollection::const_iterator it=deColl.begin();
251  it!=deColl.end(); it++)
252  if(!it->empty())
253  if(it->sid()==GCT)
254  gctColl.push_back(*it);
255 
256  if(verbose()) {
257  std::cout << "[L1TdeGCT] record has " << gctColl.size()
258  << " gct de digis\n" << std::flush;
259  for(L1DEDigiCollection::const_iterator it=gctColl.begin();
260  it!=gctColl.end(); it++)
261  std::cout << "\t" << *it << std::endl;
262  }
263 
264  const int nullVal = L1DataEmulDigi().reset();
265 
267 
268  // d|e candidate loop
269  for(L1DEDigiCollection::const_iterator it=gctColl.begin();
270  it!=gctColl.end(); it++) {
271 
272  // sid should be GCT
273  int sid = it->sid();
274  // cid: GCTisolaem, GCTnoisoem, GCTcenjets, GCTforjets, GCTtaujets
275  int cid = it->cid();
277 
278  if(verbose())
279  std::cout << "[L1TdeGCT] processing digi "
280  << " sys:" << sid
281  << " type:" << cid
282  << " \n\t"
283  << *it << "\n"
284  << std::flush;
285 
286  //assert(cid==GCT);
287  if(sid!=GCT || it->empty()) {
288  LogDebug("L1TdeGCT") << "consistency check failure, non-gct digis!";
289  continue;
290  }
291 
292  int type = it->type();
293  double phiv = it->x1();
294  double etav = it->x2();
295  float rankarr[2];
296  it->rank(rankarr);
297  float rnkv = rankarr[0];
298 
299  double wei = 1.;
300 
301  unsigned int mask = (~0x0);
302 
303  // shift coll type for starting at zero
304  int ccid = cid - dedefs::GCTisolaem;
305  if(ccid<0 || ccid >= nGctColl_) {
306  LogDebug("L1TdeGCT") << "consistency check failure, col type outbounds:"
307  << ccid << "\n";
308  ccid=0;
309  }
310 
311  //type: 0:agree 1:loc.agree, 2:loc.disagree, 3:data.only, 4:emul.only
312  if(it->type()<4)
313  sysncand[0]->Fill(ccid);
314  if(it->type()<5&&it->type()!=3)
315  sysncand[1]->Fill(ccid);
316 
317  errortype[ccid]->Fill(type);
318 
319  wei=1.; if(!type) wei=0.;
320  if(etav!=nullVal && phiv!=nullVal)
321  etaphi[ccid]->Fill(etav,phiv,wei);
322  if(etav!=nullVal)
323  eta [ccid]->Fill(etav,wei);
324  if(phiv!=nullVal)
325  phi [ccid]->Fill(phiv,wei);
326  rnk[ccid]->Fill(rnkv,wei);
327 
328  //exclude e-only cands (only data)
329  wei=1.;if(type==4) wei=0.;
330  if(etav!=nullVal)
331  etaData[ccid]->Fill(etav,wei);
332  if(phiv!=nullVal)
333  phiData[ccid]->Fill(phiv,wei);
334  rnkData[ccid]->Fill(rnkv,wei);
335  wei=1;
336 
337  // GCT trigger bits
338  unsigned int word[2];
339  it->data(word);
340  std::bitset<32> dbits(word[0]);
341  std::bitset<32> ebits(word[1]);
342  unsigned int dexor = ( (word[0]) ^ (word[1]) );
343  //disagreeing bits
344  std::bitset<32> debits(dexor);
345  //disagreeing bits after masking
346  std::bitset<32> dembits( ( (dexor) & (mask) ) );
347 
348  if(verbose())
349  std::cout << "l1degct"
350  << " sid:" << sid << " cid:" << cid << "\n"
351  << " data:0x" << std::hex << word[0] << std::dec
352  << " bitset:" << dbits
353  << "\n"
354  << " emul:0x" << std::hex << word[1] << std::dec
355  << " bitset:" << ebits
356  << "\n"
357  << " xor:0x" << std::hex << dexor << std::dec
358  << " bitset:" << debits
359  << " bitset:" << ( (dbits) ^ (ebits) )
360  << "\n" << std::flush;
361 
363  for(int ibit=0; ibit<32; ibit++) {
364  wei=1.;
365  //comparison gives no info if there's only 1 candidate
366  if(type==3 || type==4) wei=0.;
367  if(dbits [ibit]) dword[sid]->Fill(ibit,wei);
368  if(ebits [ibit]) eword[sid]->Fill(ibit,wei);
369  if(debits [ibit])deword[sid]->Fill(ibit,wei);
370  //if(dembits[ibit])masked[sid]->Fill(ibit,wei);
371  }
372  wei=1;
373 
374  }
375 
376  //error rates per GCT trigger object type
377  int hasCol[nGctColl_]={0};
378  int nagree[nGctColl_]={0};
379  for(L1DEDigiCollection::const_iterator it=gctColl.begin();
380  it!=gctColl.end(); it++) {
381  int ccid = it->cid()-dedefs::GCTisolaem;
382  ccid = (ccid<0 || ccid >= nGctColl_) ? 0:ccid;
383  hasCol[ccid]++;
384  if(!it->type())
385  nagree[ccid]++;
386  }
387  for(int i=0; i<nGctColl_; i++) {
388  if(!hasCol[i]) continue;
390  //nWithCol[i]++;
391  //if(nagree[i]<hasCol[i]) colCount[i]++;
393  nWithCol[i]+=hasCol[i];//#of objects
394  colCount[i]+=nagree[i];//#of agreements
395  }
396  for(int i=0; i<nGctColl_; i++) {
397  int ibin = i+1;
398  double rate = nWithCol[i] ? 1.-1.*colCount[i]/nWithCol[i]: 0.;
399  sysrates->setBinContent(ibin,rate);
400  if(verbose()) {
401  std::cout << "[L1TDEMON] analyze rate computation\t\n"
402  << " colid:" << i
403  << "(so far)"
404  << " nWithCol: " << nWithCol[i]
405  << " colCount: " << colCount[i]
406  << "(this event)"
407  << "hasCol: " << hasCol[i]
408  << " nagree: " << nagree[i]
409  << " rate:" << sysrates->getBinContent(ibin)
410  << "\n" << std::flush;
411  if(rate>1. || rate<0.)
412  std::cout << "problem, error rate for " << SystLabel[i]
413  <<" is "<<sysrates->getBinContent(ibin)
414  << "\n" << std::flush;
415  }
416  }
417 
418 
419  if(verbose())
420  std::cout << "L1TdeGCT::analyze() end.\n" << std::flush;
421 
422 }
423 
#define LogDebug(id)
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
~L1TdeGCT()
Definition: L1TdeGCT.cc:42
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual void beginRun(edm::Run const &iRun, edm::EventSetup const &iSetup)
Definition: L1TdeGCT.cc:44
#define NULL
Definition: scimark2.h:8
T eta() const
std::vector< L1DataEmulDigi > L1DEDigiCollection
Definition: DEtrait.h:79
virtual void endJob()
Definition: L1TdeGCT.cc:184
L1TdeGCT(const edm::ParameterSet &)
Definition: L1TdeGCT.cc:6
int iEvent
Definition: GenABIO.cc:243
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: L1TdeGCT.cc:198
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
std::pair< T, T > etaphi(T x, T y, T z)
Definition: FastMath.h:128
int j
Definition: DBlmapReader.cc:9
bool isValid() const
Definition: HandleBase.h:76
const std::string SystLabel[DEnsys]
Definition: DEtrait.h:45
double rate(double x)
Definition: Constants.cc:3
tuple cout
Definition: gather_cfg.py:121
Definition: Run.h:41
Definition: DDAxes.h:10
virtual void beginJob(void)
Definition: L1TdeGCT.cc:180