CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DQM/L1TMonitor/src/L1TdeGCT.cc

Go to the documentation of this file.
00001 #include "DQM/L1TMonitor/interface/L1TdeGCT.h"
00002 #include <bitset>
00003 
00004 using namespace dedefs;
00005 
00006 L1TdeGCT::L1TdeGCT(const edm::ParameterSet& iConfig) {
00007 
00008   verbose_ = iConfig.getUntrackedParameter<int>("VerboseFlag",0);
00009 
00010   if(verbose())
00011     std::cout << "L1TdeGCT::L1TdeGCT()...\n" << std::flush;
00012   
00013   DEsource_ = iConfig.getParameter<edm::InputTag>("DataEmulCompareSource");
00014   histFolder_ = iConfig.getUntrackedParameter<std::string>("HistFolder", "L1TEMU/GCTexpert/");
00015   
00016   dbe = NULL;
00017   if (iConfig.getUntrackedParameter<bool>("DQMStore", false)) { 
00018     dbe = edm::Service<DQMStore>().operator->();
00019     dbe->setVerbose(0);
00020   }
00021   
00022   histFile_ = iConfig.getUntrackedParameter<std::string>("HistFile", "");
00023   if(iConfig.getUntrackedParameter<bool> ("disableROOToutput", true))
00024     histFile_ = "";
00025 
00026   if (histFile_.size()!=0) {
00027     edm::LogInfo("OutputRootFile") 
00028       << "L1TEmulator GCT specific histograms will be saved to " 
00029       << histFile_.c_str() 
00030       << std::endl;
00031   }
00032 
00033   if(dbe!=NULL)
00034     dbe->setCurrentFolder(histFolder_);
00035 
00036   hasRecord_=true;
00037   
00038   if(verbose())
00039     std::cout << "L1TdeGCT::L1TdeGCT()...done.\n" << std::flush;
00040 }
00041 
00042 L1TdeGCT::~L1TdeGCT() {}
00043 
00044 void 
00045 L1TdeGCT::beginJob(void) {
00046 
00047   if(verbose())
00048     std::cout << "L1TdeGCT::beginJob()  start\n" << std::flush;
00049 
00050   DQMStore* dbe = 0;
00051   dbe = edm::Service<DQMStore>().operator->();
00052   if(dbe) {
00053     dbe->setCurrentFolder(histFolder_);
00054     dbe->rmdir(histFolder_);
00055   }
00056 
00057   // (em) iso, no-iso, (jets) cen, for, tau
00058   std::string cLabel[nGctColl_]= 
00059     {"IsoEM", "NoisoEM", "CenJet", "ForJet", "TauJet", "HT", "MET", "ET", "MHT", "HFSums", "HFCnts"};
00060   const int nerr  = 5; 
00061   const int nbit = 32;
00062   
00063   if(dbe) {
00064     dbe->setCurrentFolder(histFolder_);
00065 
00066     // book histograms here 
00067 
00068     const int    phiNBins = 18  ;
00069     const double phiMinim = -0.5;
00070     const double phiMaxim = 17.5;
00071     const int    etaNBins = 22  ;
00072     const double etaMinim = -0.5;
00073     const double etaMaxim = 21.5;
00074     const int    rnkNBins = 63;
00075     const double rnkMinim = 0.5;
00076     const double rnkMaxim = 63.5;
00077 
00078     sysrates = dbe->book1D("sysrates","RATE OF COMPARISON FAILURES",nGctColl_, 0, nGctColl_ );
00079 
00080     for(int j=0; j<2; j++) {
00081       std::string lbl("sysncand"); 
00082       lbl += (j==0?"Data":"Emul");
00083       std::string title("GCT OBJECT MULTIPLICITY ");
00084       title += (j==0?"(DATA)":"(EMULATOR)");
00085       sysncand[j] = dbe->book1D(lbl.data(),title.data(),nGctColl_, 0, nGctColl_ );
00086     }
00087     
00088     for(int j=0; j<nGctColl_; j++) {
00089       
00090       dbe->setCurrentFolder(std::string(histFolder_+cLabel[j]));
00091       
00092       std::string lbl("");
00093       std::string title("");
00094       lbl.clear();
00095       title.clear();
00096       lbl+=cLabel[j];lbl+="ErrorFlag"; 
00097       title+=cLabel[j];title+=" ErrorFlag"; 
00098       errortype[j] = dbe->book1D(lbl.data(),title.data(), nerr, 0, nerr);
00099       
00100       lbl.clear();
00101       title.clear();
00102       lbl+=cLabel[j];lbl+="Eta"; 
00103       title+=cLabel[j];title+=" ETA OF COMPARISON FAILURES"; 
00104       eta[j] = dbe->book1D(lbl.data(),title.data(),
00105                            etaNBins, etaMinim, etaMaxim);
00106       lbl.clear();
00107       title.clear();
00108       lbl+=cLabel[j];lbl+="Phi"; 
00109       title+=cLabel[j];title+=" PHI OF COMPARISON FAILURES"; 
00110       phi[j] = dbe->book1D(lbl.data(),title.data(),
00111                            phiNBins, phiMinim, phiMaxim);
00112 
00113       lbl.clear();
00114       title.clear();
00115       lbl+=cLabel[j];lbl+="Etaphi"; 
00116       title+=cLabel[j];title+=" ETA PHI OF COMPARISON FAILURES"; 
00117       etaphi[j] = dbe->book2D(lbl.data(),title.data(), 
00118                               etaNBins, etaMinim, etaMaxim,
00119                               phiNBins, phiMinim, phiMaxim
00120                               );
00121       lbl.clear();
00122       title.clear();
00123       lbl+=cLabel[j];lbl+="Rank";
00124       title+=cLabel[j];title+=" RANK OF COMPARISON FAILURES"; 
00125       rnk[j] = dbe->book1D(lbl.data(),title.data(),
00126                                rnkNBins, rnkMinim, rnkMaxim);
00127       //
00128       lbl.clear();
00129       title.clear();
00130       lbl+=cLabel[j];lbl+="Eta"; lbl+="Data";
00131       title+=cLabel[j];title+=" ETA (DATA)"; 
00132       etaData[j] = dbe->book1D(lbl.data(),title.data(),
00133                                etaNBins, etaMinim, etaMaxim);
00134       lbl.clear();
00135       title.clear();
00136       lbl+=cLabel[j];lbl+="Phi";  lbl+="Data";
00137       title+=cLabel[j];title+=" PHI (DATA)"; 
00138       phiData[j] = dbe->book1D(lbl.data(),title.data(),
00139                                phiNBins, phiMinim, phiMaxim);
00140 
00141       lbl.clear();
00142       title.clear();
00143       lbl+=cLabel[j];lbl+="Rank";  lbl+="Data";
00144       title+=cLabel[j];title+=" RANK (DATA)"; 
00145       rnkData[j] = dbe->book1D(lbl.data(),title.data(),
00146                                rnkNBins, rnkMinim, rnkMaxim);
00147       lbl.clear();
00148       lbl+=cLabel[j];lbl+="Dword"; 
00149       dword[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
00150       lbl.clear();
00151       lbl+=cLabel[j];lbl+="Eword"; 
00152       eword[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
00153       lbl.clear();
00154       lbl+=cLabel[j];lbl+="DEword"; 
00155       deword[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
00156       //lbl.clear();
00157       //lbl+=cLabel[j];lbl+="Masked"; 
00158       //masked[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
00159     }
00160 
00161   }
00162   
00164   std::string errLabel[nerr]= {
00165     "Agree", "Loc. Agree", "L.Disagree", "Data only", "Emul only"
00166   };
00167   
00168   for(int i=0; i<nGctColl_; i++) {
00169     sysrates   ->setBinLabel(i+1,cLabel[i]);
00170     sysncand[0]->setBinLabel(i+1,cLabel[i]);
00171     sysncand[1]->setBinLabel(i+1,cLabel[i]);
00172   }
00173 
00174   for(int i=0; i<nGctColl_; i++) {
00175     for(int j=0; j<nerr; j++) {
00176       errortype[i]->setBinLabel(j+1,errLabel[j]);
00177     }
00178   }
00179   
00180   for(int i=0; i<nGctColl_; i++) {
00181     etaphi [i]->setAxisTitle("GCT #eta",1);
00182     etaphi [i]->setAxisTitle("GCT #phi",2);
00183     eta    [i]->setAxisTitle("GCT #eta");
00184     phi    [i]->setAxisTitle("GCT #phi");
00185     rnk    [i]->setAxisTitle("Rank");
00186     etaData[i]->setAxisTitle("GCT #eta");
00187     phiData[i]->setAxisTitle("GCT #phi");
00188     rnkData[i]->setAxisTitle("Rank");
00189     dword  [i]->setAxisTitle("trigger data word bit");
00190     eword  [i]->setAxisTitle("trigger data word bit");
00191     deword [i]->setAxisTitle("trigger data word bit");
00192     //masked [i]->setAxisTitle("trigger data word bit");
00193   }
00194 
00195   for(int i=0; i<nGctColl_; i++) {
00196     colCount[i]=0;
00197     nWithCol[i]=0;
00198   }
00199   
00200   if(verbose())
00201     std::cout << "L1TdeGCT::beginJob()  end.\n" << std::flush;
00202 }
00203 
00204 void 
00205 L1TdeGCT::endJob() {
00206   if(verbose())
00207     std::cout << "L1TdeGCT::endJob()...\n" << std::flush;
00208 
00209   if(histFile_.size()!=0  && dbe) 
00210     dbe->save(histFile_);
00211 
00212   if(verbose())
00213     std::cout << "L1TdeGCT::endJob()  end.\n" << std::flush;
00214 }
00215 
00216  
00217 // ------------ method called to for each event  ------------
00218 void
00219   L1TdeGCT::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00220   
00221   if(!hasRecord_)
00222     return;
00223   
00224   if(verbose())
00225     std::cout << "L1TdeGCT::analyze()  start\n" << std::flush;
00226 
00228   edm::Handle<L1DataEmulRecord> deRecord;
00229   iEvent.getByLabel(DEsource_, deRecord);
00230 
00231   if (!deRecord.isValid()) {
00232     edm::LogInfo("DataNotFound") 
00233       << "Cannot find L1DataEmulRecord with label "
00234       << DEsource_.label() 
00235       << " Please verify that comparator was successfully executed."
00236       << " Emulator DQM for GCT will be skipped!"
00237       << std::endl;
00238     hasRecord_=false;
00239     return;
00240   }
00241 
00242   bool isComp = deRecord->get_isComp(GCT);
00243   if(!isComp) {
00244     if(verbose()) 
00245       std::cout << "[L1TdeGCT] Gct information not generated in de-record."
00246                 << " Skiping event!\n" << std::flush;
00247     return;
00248   }
00249 
00250   int DEncand[2]={0};
00251   for(int j=0; j<2; j++) 
00252     DEncand[j] = deRecord->getNCand(GCT,j);
00253   
00254   if(verbose()) 
00255     std::cout << "[L1TdeGCT] ncands" 
00256               << " data: " << DEncand[0]
00257               << " emul: " << DEncand[1]
00258               << std::endl;
00259 
00260 
00262   L1DEDigiCollection deColl;
00263   deColl = deRecord->getColl();
00264 
00265   // extract the GCT comparison digis
00266   L1DEDigiCollection gctColl;
00267 
00268   gctColl.reserve(20);
00269   gctColl.clear();
00270 
00271 
00272   for(L1DEDigiCollection::const_iterator it=deColl.begin(); 
00273       it!=deColl.end(); it++) 
00274     if(!it->empty()) 
00275       if(it->sid()==GCT)
00276         gctColl.push_back(*it);
00277   
00278   if(verbose()) {
00279     std::cout << "[L1TdeGCT] record has " << gctColl.size() 
00280               << " gct de digis\n" << std::flush;
00281     for(L1DEDigiCollection::const_iterator it=gctColl.begin(); 
00282         it!=gctColl.end(); it++)
00283       std::cout << "\t" << *it << std::endl;
00284   }
00285 
00286   const int nullVal = L1DataEmulDigi().reset();
00287 
00289   
00290   // d|e candidate loop
00291   for(L1DEDigiCollection::const_iterator it=gctColl.begin(); 
00292       it!=gctColl.end(); it++) {
00293     
00294     // sid should be GCT
00295     int sid = it->sid();
00296     // cid: GCTisolaem, GCTnoisoem, GCTcenjets, GCTforjets, GCTtaujets
00297     int cid = it->cid();
00299 
00300     if(verbose()) 
00301       std::cout << "[L1TdeGCT] processing digi "
00302                 << " sys:"  << sid
00303                 << " type:" << cid
00304                 << " \n\t"
00305                 << *it << "\n" 
00306                 << std::flush;
00307     
00308     //assert(cid==GCT);
00309     if(sid!=GCT || it->empty()) {
00310       LogDebug("L1TdeGCT") << "consistency check failure, non-gct digis!";
00311       continue;
00312     }
00313     
00314     int type    = it->type();
00315     double phiv = it->x1();
00316     double etav = it->x2();
00317     float rankarr[2]; 
00318     it->rank(rankarr);
00319     float rnkv = rankarr[0];
00320 
00321     double wei = 1.;
00322 
00323     unsigned int mask = (~0x0);
00324 
00325     // shift coll type for starting at zero
00326     int ccid = cid - dedefs::GCTisolaem; 
00327     if(ccid<0 || ccid >= nGctColl_) {
00328       LogDebug("L1TdeGCT") << "consistency check failure, col type outbounds:"
00329                            << ccid << "\n";
00330       ccid=0;
00331     }
00332     
00333     //type: 0:agree 1:loc.agree, 2:loc.disagree, 3:data.only, 4:emul.only
00334     if(it->type()<4) 
00335       sysncand[0]->Fill(ccid); 
00336     if(it->type()<5&&it->type()!=3) 
00337       sysncand[1]->Fill(ccid);
00338     
00339     errortype[ccid]->Fill(type);
00340 
00341     wei=1.; if(!type) wei=0.;
00342     if(etav!=nullVal && phiv!=nullVal)
00343       etaphi[ccid]->Fill(etav,phiv,wei);
00344     if(etav!=nullVal)
00345       eta   [ccid]->Fill(etav,wei);
00346     if(phiv!=nullVal)
00347       phi   [ccid]->Fill(phiv,wei);
00348     rnk[ccid]->Fill(rnkv,wei);    
00349 
00350     //exclude e-only cands (only data)
00351     wei=1.;if(type==4) wei=0.;
00352     if(etav!=nullVal)
00353       etaData[ccid]->Fill(etav,wei);
00354     if(phiv!=nullVal)
00355       phiData[ccid]->Fill(phiv,wei);
00356     rnkData[ccid]->Fill(rnkv,wei);
00357     wei=1;
00358 
00359     // GCT trigger bits
00360     unsigned int word[2];
00361     it->data(word);
00362     std::bitset<32> dbits(word[0]);
00363     std::bitset<32> ebits(word[1]);
00364     unsigned int dexor = ( (word[0]) ^ (word[1]) );
00365     //disagreeing bits
00366     std::bitset<32> debits(dexor);
00367     //disagreeing bits after masking
00368     std::bitset<32> dembits( ( (dexor) & (mask) ) );
00369     
00370     if(verbose())
00371       std::cout << "l1degct" 
00372                 << " sid:" << sid << " cid:" << cid << "\n"
00373                 << " data:0x" << std::hex << word[0] << std::dec
00374                 << " bitset:" << dbits
00375                 << "\n"
00376                 << " emul:0x" << std::hex << word[1] << std::dec
00377                 << " bitset:" << ebits
00378                 << "\n"
00379                 << "  xor:0x" << std::hex << dexor << std::dec
00380                 << " bitset:" << debits
00381                 << " bitset:" << ( (dbits) ^ (ebits) )
00382                 << "\n" << std::flush;
00383 
00385     for(int ibit=0; ibit<32; ibit++) {
00386       wei=1.;
00387       //comparison gives no info if there's only 1 candidate
00388       if(type==3 || type==4) wei=0.; 
00389       if(dbits  [ibit]) dword[sid]->Fill(ibit,wei);
00390       if(ebits  [ibit]) eword[sid]->Fill(ibit,wei);
00391       if(debits [ibit])deword[sid]->Fill(ibit,wei);
00392       //if(dembits[ibit])masked[sid]->Fill(ibit,wei);
00393     }
00394     wei=1;
00395     
00396   }
00397 
00398   //error rates per GCT trigger object type
00399   int hasCol[nGctColl_]={0};
00400   int nagree[nGctColl_]={0};
00401   for(L1DEDigiCollection::const_iterator it=gctColl.begin(); 
00402       it!=gctColl.end(); it++) {
00403     int ccid = it->cid()-dedefs::GCTisolaem;
00404     ccid = (ccid<0 || ccid >= nGctColl_) ? 0:ccid;
00405     hasCol[ccid]++;
00406     if(!it->type()) 
00407       nagree[ccid]++;
00408   }
00409   for(int i=0; i<nGctColl_; i++) {
00410     if(!hasCol[i]) continue;
00412     //nWithCol[i]++;
00413     //if(nagree[i]<hasCol[i]) colCount[i]++;
00415     nWithCol[i]+=hasCol[i];//#of objects
00416     colCount[i]+=nagree[i];//#of agreements
00417   }
00418   for(int i=0; i<nGctColl_; i++) {
00419     int ibin = i+1;
00420     double rate = nWithCol[i] ? 1.-1.*colCount[i]/nWithCol[i]: 0.;
00421     sysrates->setBinContent(ibin,rate);
00422     if(verbose()) {
00423       std::cout << "[L1TDEMON] analyze rate computation\t\n"
00424                 << " colid:"   << i
00425                 << "(so far)"
00426                 << " nWithCol: " << nWithCol[i]
00427                 << " colCount: " << colCount[i]
00428                 << "(this event)"
00429                 << "hasCol: "    << hasCol[i] 
00430                 << " nagree: "   << nagree[i]
00431                 << " rate:"    << sysrates->getBinContent(ibin) 
00432                 << "\n" << std::flush;
00433       if(rate>1. || rate<0.)
00434         std::cout << "problem, error rate for " << SystLabel[i] 
00435                   <<" is "<<sysrates->getBinContent(ibin)
00436                   << "\n" << std::flush;
00437     }
00438   }
00439 
00440     
00441   if(verbose())
00442     std::cout << "L1TdeGCT::analyze() end.\n" << std::flush;
00443   
00444 }
00445