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