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_ = 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
46 
47  if(verbose())
48  std::cout << "L1TdeGCT::beginJob() start\n" << std::flush;
49 
50  DQMStore* dbe = 0;
51  dbe = edm::Service<DQMStore>().operator->();
52  if(dbe) {
53  dbe->setCurrentFolder(histFolder_);
54  dbe->rmdir(histFolder_);
55  }
56 
57  // (em) iso, no-iso, (jets) cen, for, tau
58  std::string cLabel[nGctColl_]=
59  {"IsoEM", "NoisoEM", "CenJet", "ForJet", "TauJet", "HT", "MET", "ET", "MHT", "HFSums", "HFCnts"};
60  const int nerr = 5;
61  const int nbit = 32;
62 
63  if(dbe) {
64  dbe->setCurrentFolder(histFolder_);
65 
66  // book histograms here
67 
68  const int phiNBins = 18 ;
69  const double phiMinim = -0.5;
70  const double phiMaxim = 17.5;
71  const int etaNBins = 22 ;
72  const double etaMinim = -0.5;
73  const double etaMaxim = 21.5;
74  const int rnkNBins = 63;
75  const double rnkMinim = 0.5;
76  const double rnkMaxim = 63.5;
77 
78  sysrates = dbe->book1D("sysrates","RATE OF COMPARISON FAILURES",nGctColl_, 0, nGctColl_ );
79 
80  for(int j=0; j<2; j++) {
81  std::string lbl("sysncand");
82  lbl += (j==0?"Data":"Emul");
83  std::string title("GCT OBJECT MULTIPLICITY ");
84  title += (j==0?"(DATA)":"(EMULATOR)");
85  sysncand[j] = dbe->book1D(lbl.data(),title.data(),nGctColl_, 0, nGctColl_ );
86  }
87 
88  for(int j=0; j<nGctColl_; j++) {
89 
90  dbe->setCurrentFolder(std::string(histFolder_+cLabel[j]));
91 
92  std::string lbl("");
93  std::string title("");
94  lbl.clear();
95  title.clear();
96  lbl+=cLabel[j];lbl+="ErrorFlag";
97  title+=cLabel[j];title+=" ErrorFlag";
98  errortype[j] = dbe->book1D(lbl.data(),title.data(), nerr, 0, nerr);
99 
100  lbl.clear();
101  title.clear();
102  lbl+=cLabel[j];lbl+="Eta";
103  title+=cLabel[j];title+=" ETA OF COMPARISON FAILURES";
104  eta[j] = dbe->book1D(lbl.data(),title.data(),
105  etaNBins, etaMinim, etaMaxim);
106  lbl.clear();
107  title.clear();
108  lbl+=cLabel[j];lbl+="Phi";
109  title+=cLabel[j];title+=" PHI OF COMPARISON FAILURES";
110  phi[j] = dbe->book1D(lbl.data(),title.data(),
111  phiNBins, phiMinim, phiMaxim);
112 
113  lbl.clear();
114  title.clear();
115  lbl+=cLabel[j];lbl+="Etaphi";
116  title+=cLabel[j];title+=" ETA PHI OF COMPARISON FAILURES";
117  etaphi[j] = dbe->book2D(lbl.data(),title.data(),
118  etaNBins, etaMinim, etaMaxim,
119  phiNBins, phiMinim, phiMaxim
120  );
121  lbl.clear();
122  title.clear();
123  lbl+=cLabel[j];lbl+="Rank";
124  title+=cLabel[j];title+=" RANK OF COMPARISON FAILURES";
125  rnk[j] = dbe->book1D(lbl.data(),title.data(),
126  rnkNBins, rnkMinim, rnkMaxim);
127  //
128  lbl.clear();
129  title.clear();
130  lbl+=cLabel[j];lbl+="Eta"; lbl+="Data";
131  title+=cLabel[j];title+=" ETA (DATA)";
132  etaData[j] = dbe->book1D(lbl.data(),title.data(),
133  etaNBins, etaMinim, etaMaxim);
134  lbl.clear();
135  title.clear();
136  lbl+=cLabel[j];lbl+="Phi"; lbl+="Data";
137  title+=cLabel[j];title+=" PHI (DATA)";
138  phiData[j] = dbe->book1D(lbl.data(),title.data(),
139  phiNBins, phiMinim, phiMaxim);
140 
141  lbl.clear();
142  title.clear();
143  lbl+=cLabel[j];lbl+="Rank"; lbl+="Data";
144  title+=cLabel[j];title+=" RANK (DATA)";
145  rnkData[j] = dbe->book1D(lbl.data(),title.data(),
146  rnkNBins, rnkMinim, rnkMaxim);
147  lbl.clear();
148  lbl+=cLabel[j];lbl+="Dword";
149  dword[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
150  lbl.clear();
151  lbl+=cLabel[j];lbl+="Eword";
152  eword[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
153  lbl.clear();
154  lbl+=cLabel[j];lbl+="DEword";
155  deword[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
156  //lbl.clear();
157  //lbl+=cLabel[j];lbl+="Masked";
158  //masked[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
159  }
160 
161  }
162 
164  std::string errLabel[nerr]= {
165  "Agree", "Loc. Agree", "L.Disagree", "Data only", "Emul only"
166  };
167 
168  for(int i=0; i<nGctColl_; i++) {
169  sysrates ->setBinLabel(i+1,cLabel[i]);
170  sysncand[0]->setBinLabel(i+1,cLabel[i]);
171  sysncand[1]->setBinLabel(i+1,cLabel[i]);
172  }
173 
174  for(int i=0; i<nGctColl_; i++) {
175  for(int j=0; j<nerr; j++) {
176  errortype[i]->setBinLabel(j+1,errLabel[j]);
177  }
178  }
179 
180  for(int i=0; i<nGctColl_; i++) {
181  etaphi [i]->setAxisTitle("GCT #eta",1);
182  etaphi [i]->setAxisTitle("GCT #phi",2);
183  eta [i]->setAxisTitle("GCT #eta");
184  phi [i]->setAxisTitle("GCT #phi");
185  rnk [i]->setAxisTitle("Rank");
186  etaData[i]->setAxisTitle("GCT #eta");
187  phiData[i]->setAxisTitle("GCT #phi");
188  rnkData[i]->setAxisTitle("Rank");
189  dword [i]->setAxisTitle("trigger data word bit");
190  eword [i]->setAxisTitle("trigger data word bit");
191  deword [i]->setAxisTitle("trigger data word bit");
192  //masked [i]->setAxisTitle("trigger data word bit");
193  }
194 
195  for(int i=0; i<nGctColl_; i++) {
196  colCount[i]=0;
197  nWithCol[i]=0;
198  }
199 
200  if(verbose())
201  std::cout << "L1TdeGCT::beginJob() end.\n" << std::flush;
202 }
203 
204 void
206  if(verbose())
207  std::cout << "L1TdeGCT::endJob()...\n" << std::flush;
208 
209  if(histFile_.size()!=0 && dbe)
210  dbe->save(histFile_);
211 
212  if(verbose())
213  std::cout << "L1TdeGCT::endJob() end.\n" << std::flush;
214 }
215 
216 
217 // ------------ method called to for each event ------------
218 void
220 
221  if(!hasRecord_)
222  return;
223 
224  if(verbose())
225  std::cout << "L1TdeGCT::analyze() start\n" << std::flush;
226 
229  iEvent.getByLabel(DEsource_, deRecord);
230 
231  if (!deRecord.isValid()) {
232  edm::LogInfo("DataNotFound")
233  << "Cannot find L1DataEmulRecord with label "
234  << DEsource_.label()
235  << " Please verify that comparator was successfully executed."
236  << " Emulator DQM for GCT will be skipped!"
237  << std::endl;
238  hasRecord_=false;
239  return;
240  }
241 
242  bool isComp = deRecord->get_isComp(GCT);
243  if(!isComp) {
244  if(verbose())
245  std::cout << "[L1TdeGCT] Gct information not generated in de-record."
246  << " Skiping event!\n" << std::flush;
247  return;
248  }
249 
250  int DEncand[2]={0};
251  for(int j=0; j<2; j++)
252  DEncand[j] = deRecord->getNCand(GCT,j);
253 
254  if(verbose())
255  std::cout << "[L1TdeGCT] ncands"
256  << " data: " << DEncand[0]
257  << " emul: " << DEncand[1]
258  << std::endl;
259 
260 
262  L1DEDigiCollection deColl;
263  deColl = deRecord->getColl();
264 
265  // extract the GCT comparison digis
266  L1DEDigiCollection gctColl;
267 
268  gctColl.reserve(20);
269  gctColl.clear();
270 
271 
272  for(L1DEDigiCollection::const_iterator it=deColl.begin();
273  it!=deColl.end(); it++)
274  if(!it->empty())
275  if(it->sid()==GCT)
276  gctColl.push_back(*it);
277 
278  if(verbose()) {
279  std::cout << "[L1TdeGCT] record has " << gctColl.size()
280  << " gct de digis\n" << std::flush;
281  for(L1DEDigiCollection::const_iterator it=gctColl.begin();
282  it!=gctColl.end(); it++)
283  std::cout << "\t" << *it << std::endl;
284  }
285 
286  const int nullVal = L1DataEmulDigi().reset();
287 
289 
290  // d|e candidate loop
291  for(L1DEDigiCollection::const_iterator it=gctColl.begin();
292  it!=gctColl.end(); it++) {
293 
294  // sid should be GCT
295  int sid = it->sid();
296  // cid: GCTisolaem, GCTnoisoem, GCTcenjets, GCTforjets, GCTtaujets
297  int cid = it->cid();
299 
300  if(verbose())
301  std::cout << "[L1TdeGCT] processing digi "
302  << " sys:" << sid
303  << " type:" << cid
304  << " \n\t"
305  << *it << "\n"
306  << std::flush;
307 
308  //assert(cid==GCT);
309  if(sid!=GCT || it->empty()) {
310  LogDebug("L1TdeGCT") << "consistency check failure, non-gct digis!";
311  continue;
312  }
313 
314  int type = it->type();
315  double phiv = it->x1();
316  double etav = it->x2();
317  float rankarr[2];
318  it->rank(rankarr);
319  float rnkv = rankarr[0];
320 
321  double wei = 1.;
322 
323  unsigned int mask = (~0x0);
324 
325  // shift coll type for starting at zero
326  int ccid = cid - dedefs::GCTisolaem;
327  if(ccid<0 || ccid >= nGctColl_) {
328  LogDebug("L1TdeGCT") << "consistency check failure, col type outbounds:"
329  << ccid << "\n";
330  ccid=0;
331  }
332 
333  //type: 0:agree 1:loc.agree, 2:loc.disagree, 3:data.only, 4:emul.only
334  if(it->type()<4)
335  sysncand[0]->Fill(ccid);
336  if(it->type()<5&&it->type()!=3)
337  sysncand[1]->Fill(ccid);
338 
339  errortype[ccid]->Fill(type);
340 
341  wei=1.; if(!type) wei=0.;
342  if(etav!=nullVal && phiv!=nullVal)
343  etaphi[ccid]->Fill(etav,phiv,wei);
344  if(etav!=nullVal)
345  eta [ccid]->Fill(etav,wei);
346  if(phiv!=nullVal)
347  phi [ccid]->Fill(phiv,wei);
348  rnk[ccid]->Fill(rnkv,wei);
349 
350  //exclude e-only cands (only data)
351  wei=1.;if(type==4) wei=0.;
352  if(etav!=nullVal)
353  etaData[ccid]->Fill(etav,wei);
354  if(phiv!=nullVal)
355  phiData[ccid]->Fill(phiv,wei);
356  rnkData[ccid]->Fill(rnkv,wei);
357  wei=1;
358 
359  // GCT trigger bits
360  unsigned int word[2];
361  it->data(word);
362  std::bitset<32> dbits(word[0]);
363  std::bitset<32> ebits(word[1]);
364  unsigned int dexor = ( (word[0]) ^ (word[1]) );
365  //disagreeing bits
366  std::bitset<32> debits(dexor);
367  //disagreeing bits after masking
368  std::bitset<32> dembits( ( (dexor) & (mask) ) );
369 
370  if(verbose())
371  std::cout << "l1degct"
372  << " sid:" << sid << " cid:" << cid << "\n"
373  << " data:0x" << std::hex << word[0] << std::dec
374  << " bitset:" << dbits
375  << "\n"
376  << " emul:0x" << std::hex << word[1] << std::dec
377  << " bitset:" << ebits
378  << "\n"
379  << " xor:0x" << std::hex << dexor << std::dec
380  << " bitset:" << debits
381  << " bitset:" << ( (dbits) ^ (ebits) )
382  << "\n" << std::flush;
383 
385  for(int ibit=0; ibit<32; ibit++) {
386  wei=1.;
387  //comparison gives no info if there's only 1 candidate
388  if(type==3 || type==4) wei=0.;
389  if(dbits [ibit]) dword[sid]->Fill(ibit,wei);
390  if(ebits [ibit]) eword[sid]->Fill(ibit,wei);
391  if(debits [ibit])deword[sid]->Fill(ibit,wei);
392  //if(dembits[ibit])masked[sid]->Fill(ibit,wei);
393  }
394  wei=1;
395 
396  }
397 
398  //error rates per GCT trigger object type
399  int hasCol[nGctColl_]={0};
400  int nagree[nGctColl_]={0};
401  for(L1DEDigiCollection::const_iterator it=gctColl.begin();
402  it!=gctColl.end(); it++) {
403  int ccid = it->cid()-dedefs::GCTisolaem;
404  ccid = (ccid<0 || ccid >= nGctColl_) ? 0:ccid;
405  hasCol[ccid]++;
406  if(!it->type())
407  nagree[ccid]++;
408  }
409  for(int i=0; i<nGctColl_; i++) {
410  if(!hasCol[i]) continue;
412  //nWithCol[i]++;
413  //if(nagree[i]<hasCol[i]) colCount[i]++;
415  nWithCol[i]+=hasCol[i];//#of objects
416  colCount[i]+=nagree[i];//#of agreements
417  }
418  for(int i=0; i<nGctColl_; i++) {
419  int ibin = i+1;
420  double rate = nWithCol[i] ? 1.-1.*colCount[i]/nWithCol[i]: 0.;
421  sysrates->setBinContent(ibin,rate);
422  if(verbose()) {
423  std::cout << "[L1TDEMON] analyze rate computation\t\n"
424  << " colid:" << i
425  << "(so far)"
426  << " nWithCol: " << nWithCol[i]
427  << " colCount: " << colCount[i]
428  << "(this event)"
429  << "hasCol: " << hasCol[i]
430  << " nagree: " << nagree[i]
431  << " rate:" << sysrates->getBinContent(ibin)
432  << "\n" << std::flush;
433  if(rate>1. || rate<0.)
434  std::cout << "problem, error rate for " << SystLabel[i]
435  <<" is "<<sysrates->getBinContent(ibin)
436  << "\n" << std::flush;
437  }
438  }
439 
440 
441  if(verbose())
442  std::cout << "L1TdeGCT::analyze() end.\n" << std::flush;
443 
444 }
445 
#define LogDebug(id)
type
Definition: HCALResponse.h:22
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
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:519
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2296
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
#define NULL
Definition: scimark2.h:8
std::vector< L1DataEmulDigi > L1DEDigiCollection
Definition: DEtrait.h:79
virtual void endJob()
Definition: L1TdeGCT.cc:205
T eta() const
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:219
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
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
const std::string SystLabel[DEnsys]
Definition: DEtrait.h:45
tuple cout
Definition: gather_cfg.py:41
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:647
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:237
Definition: DDAxes.h:10
virtual void beginJob(void)
Definition: L1TdeGCT.cc:45