CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/L1TMonitor/src/L1TdeECAL.cc

Go to the documentation of this file.
00001 #include "DQM/L1TMonitor/interface/L1TdeECAL.h"
00002 #include <bitset>
00003 
00004 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00005 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00006 //#include "DQM/EcalCommon/interface/Numbers.h"
00007 #include "DQMServices/Core/interface/DQMStore.h"
00008 #include "DQMServices/Core/interface/MonitorElement.h"
00009 
00010 using namespace dedefs;
00011 
00012 L1TdeECAL::L1TdeECAL(const edm::ParameterSet& iConfig) {
00013 
00014   verbose_ = iConfig.getUntrackedParameter<int>("VerboseFlag",0);
00015 
00016   if(verbose())
00017     std::cout << "L1TdeECAL::L1TdeECAL()...\n" << std::flush;
00018   
00019   DEsource_ = iConfig.getParameter<edm::InputTag>("DataEmulCompareSource");
00020   histFolder_ = iConfig.getUntrackedParameter<std::string>("HistFolder", "L1TEMU//ECALexpert/");
00021   
00022   dbe = NULL;
00023   if (iConfig.getUntrackedParameter<bool>("DQMStore", false)) { 
00024     dbe = edm::Service<DQMStore>().operator->();
00025     dbe->setVerbose(0);
00026   }
00027   
00028   histFile_ = iConfig.getUntrackedParameter<std::string>("HistFile", "");
00029   if(iConfig.getUntrackedParameter<bool> ("disableROOToutput", true))
00030     histFile_ = "";
00031 
00032   if (histFile_.size()!=0) {
00033     edm::LogInfo("OutputRootFile") 
00034       << "L1TEmulator ECAL specific histograms will be saved to " 
00035       << histFile_.c_str() 
00036       << std::endl;
00037   }
00038 
00039   if(dbe!=NULL)
00040     dbe->setCurrentFolder(histFolder_);
00041   
00042   hasRecord_=true;
00043 
00044   if(verbose())
00045     std::cout << "L1TdeECAL::L1TdeECAL()...done.\n" << std::flush;
00046 }
00047 
00048 L1TdeECAL::~L1TdeECAL() {}
00049 
00050 void 
00051 L1TdeECAL::beginJob(void) {
00052 
00053   if(verbose())
00054     std::cout << "L1TdeECAL::beginJob()  start\n";
00055 
00056   DQMStore* dbe = 0;
00057   dbe = edm::Service<DQMStore>().operator->();
00058   if(dbe) {
00059     dbe->setCurrentFolder(histFolder_);
00060     dbe->rmdir(histFolder_);
00061   }
00062 
00063   if(dbe) {
00064     dbe->setCurrentFolder(histFolder_);
00065 
00066     etmapData.reserve(nSM);
00067     etmapEmul.reserve(nSM);
00068     etmapDiff.reserve(nSM);
00069     etmapData.resize( nSM, static_cast<MonitorElement*>(0) );
00070     etmapEmul.resize( nSM, static_cast<MonitorElement*>(0) );
00071     etmapDiff.resize( nSM, static_cast<MonitorElement*>(0) );
00072     
00073     
00074     std::string lbl("");
00075     char tmp[100];
00076     for(int j=0; j<nSM; j++) {
00077       lbl.clear();
00078       sprintf(tmp, "etmapDataSM%d", j+1);
00079       lbl+=tmp;
00080       etmapData[j] = dbe->book3D(lbl.c_str(),lbl.c_str(),
00081                                  nTTEta, 0, nTTEta,
00082                                  nTTPhi, 0, nTTPhi,
00083                                  256, 0, 256.);
00084       sprintf(tmp, "etmapEmulSM%d", j+1);
00085       lbl.clear(); lbl+=tmp;
00086       etmapEmul[j] = dbe->book3D(lbl.c_str(),lbl.c_str(),
00087                                  nTTEta, 0, nTTEta,
00088                                  nTTPhi, 0, nTTPhi,
00089                                  256, 0, 256.);
00090       sprintf(tmp, "etmapDiffSM%d", j+1);
00091       lbl.clear(); lbl+=tmp;
00092       etmapDiff[j] = dbe->book3D(lbl.c_str(),lbl.c_str(),
00093                                  nTTEta, 0, nTTEta,
00094                                  nTTPhi, 0, nTTPhi,
00095                                  256, 0, 256.);
00096     }   
00097     lbl= "EcalEtMapDiff" ;
00098     EcalEtMapDiff = dbe->bookProfile2D(lbl.c_str(),lbl.c_str(),
00099                                        35, -17.5, 17.5,
00100                                        72, -10., 350.,
00101                                        256, 0, 256.);
00102     lbl= "EcalFGMapDiff" ;
00103     EcalFGMapDiff = dbe->bookProfile2D(lbl.c_str(),lbl.c_str(),
00104                                        35, -17.5, 17.5,
00105                                        72, -10., 350.,
00106                                        2, 0, 2.);
00107   }
00108   
00109   if(verbose())
00110     std::cout << "L1TdeECAL::beginJob()  end.\n" << std::flush;
00111 }
00112 
00113 void 
00114 L1TdeECAL::endJob() {
00115   if(verbose())
00116     std::cout << "L1TdeECAL::endJob()...\n" << std::flush;
00117   if(histFile_.size()!=0  && dbe) 
00118     dbe->save(histFile_);
00119   //tbd delete emap;
00120 }
00121 
00122  
00123 // ------------ method called to for each event  ------------
00124 void
00125   L1TdeECAL::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00126   
00127   if(!hasRecord_)
00128     return;
00129 
00130   if(verbose())
00131     std::cout << "L1TdeECAL::analyze()  start\n" << std::flush;
00132 
00134   edm::Handle<L1DataEmulRecord> deRecord;
00135   iEvent.getByLabel(DEsource_, deRecord);
00136 
00137   if (!deRecord.isValid()) {
00138     edm::LogInfo("DataNotFound") 
00139       << "Cannot find L1DataEmulRecord with label "
00140       << DEsource_.label() 
00141       << " Please verify that comparator was successfully executed."
00142       << " Emulator DQM for ECAL will be skipped!"
00143       << std::endl;
00144     hasRecord_=false;
00145     return;
00146   }
00147 
00148   bool isComp = deRecord->get_isComp(ETP);
00149   if(!isComp) {
00150     if(verbose()) 
00151       std::cout << "[L1TdeECAL] Ecal information not generated in de-record."
00152                 << " Skiping event!\n";
00153     return;
00154   }
00155 
00156   int DEncand[2];
00157   for(int j=0; j<2; j++) 
00158     DEncand[j] = deRecord->getNCand(ETP,j);
00159   
00160   if(verbose()) 
00161     std::cout << "[L1TdeECAL] ncands" 
00162               << " data: " << DEncand[0]
00163               << " emul: " << DEncand[1]
00164               << std::endl;
00165 
00166   
00168   L1DEDigiCollection deColl;
00169   deColl = deRecord->getColl();
00170 
00171   if(verbose()) {
00172     std::cout << "[L1TdeECAL] digis: \n";
00173     for(L1DEDigiCollection::const_iterator it=deColl.begin(); it!=deColl.end(); it++)
00174       if(it->sid()==ETP)
00175         std::cout << "\t" << *it << std::endl;
00176   }
00177   
00178 
00180 
00181   EcalElectronicsMapping emap;
00182 
00183   // d|e candidate loop
00184   for(L1DEDigiCollection::const_iterator it=deColl.begin(); 
00185       it!=deColl.end(); it++) {
00186     
00187     int    sid = it->sid();
00188     int    cid = it->cid();
00189     
00190     if(sid!=ETP)
00191       continue;
00192 
00193     if(it->empty())
00194       continue;
00195 
00196     assert(cid==ECALtp);
00197     
00198     if(verbose()) 
00199       std::cout << "[L1TdeECAL] processing digi: \n\t"
00200                 << *it << "\n" << std::flush;
00201     
00202     //get (global) tt coordinates
00203     int iphi = (int)it->x1();
00204     int ieta = (int)it->x2();
00205     
00206     //get sm id
00207     int ism = iEtaiPhiToSMid(ieta,iphi); //1..36
00208 
00209     //get local indices
00210     int zside = (ieta>0?1:-1);
00211     int iet = abs(ieta);
00212     int ipt = iphi;
00213     ipt = ipt + 2;
00214     if ( ipt > 72 ) ipt = ipt - 72;
00215     ipt = (ipt-1)%4 + 1;
00216     if ( zside > 0 ) ipt = 5 - ipt;
00217 
00218 
00220     EcalTrigTowerDetId idt(zside, EcalBarrel, abs(ieta), iphi);
00221     // ... from EcalElectronicsMapping (needs addt'l lib)
00222     //int itt = map.iTT  (idt); //1..68
00223     int itcc = emap.TCCid(idt); //37..54(eb+) 55..72(eb-)
00224     // need here converter tcc->sm id
00225     int smid = TCCidToSMid(itcc);
00226     // ... or as in EBTriggerTowerTask (needs addt'l lib)
00227     //int ismt = Numbers::iSM( idt );
00228 
00229     if(verbose())
00230       std::cout << "L1TdeECAL \t"
00231                 << " smid:" << smid 
00232                 << " ism:"  << ism 
00233                 << " itcc:" << itcc 
00234                 << " local phi:" << ipt << " eta:" << iet 
00235                 << "\n" << std::flush
00236                 << *it
00237                 << "\n" << std::flush;
00238     if(ism!=smid)
00239       LogDebug("L1TdeECAL") << "consistency check failure\n\t"
00240                             << " smid:" << smid 
00241                             << " ism:"  << ism 
00242                             << " itcc:" << itcc 
00243                             << std::endl;
00244     
00245     float xiet = iet+0.5;
00246     float xipt = ipt+0.5;
00247     
00248     //get energy values
00249     float rankarr[2]; 
00250     it->rank(rankarr);
00251     // get FG values
00252     unsigned int raw[2] ;
00253     it->data(raw) ;
00254     int FG[2] = { (raw[0] & 0x1000000)!=0, (raw[1] & 0x1000000)!=0 } ;
00255 
00256     int type = it->type(); //3 data only, 4 emul only
00257     if(type!=4 && etmapData[ism-1])
00258       etmapData[ism-1]->Fill(xiet-1, xipt-1, rankarr[0]);
00259     if(type!=3 && etmapEmul[ism-1])
00260       etmapEmul[ism-1]->Fill(xiet-1, xipt-1, rankarr[1]);
00261     if(type<2 && etmapDiff[ism-1]) {
00262       float diff = fabs(rankarr[0]-rankarr[1]);
00263       etmapDiff[ism-1]->Fill(xiet-1, xipt-1, diff);
00264       float phi = iphi ;
00265       if (phi>70) phi -= 73 ;
00266       phi *= 5 ;
00267       if (phi>0) phi -= 5 ;
00268       EcalEtMapDiff->Fill(ieta, phi, diff) ;
00269       diff = fabs(FG[0]-FG[1]);
00270       EcalFGMapDiff->Fill(ieta, phi, diff) ;
00271     }
00272   }//close loop over dedigi-cands
00273 
00274 
00275   if(verbose())
00276     std::cout << "L1TdeECAL::analyze() end.\n" << std::flush;
00277 
00278 }
00279 
00280 // in  :: iphi    1..72 [71,72,1..70]
00281 //        ieta  -17..-1 (z-)   1..17 (z+)
00282 // out :: SMid   19..36 (z-)   1..18 (z+)
00283 int L1TdeECAL::iEtaiPhiToSMid(int ieta, int iphi) {
00284   // barrel
00285   int iz = (ieta<0)?-1:1;
00286   iphi += 2;
00287   if (iphi > 72) iphi -= 72;
00288   const int kEBTowersInPhi = 4; //EBDetId::kTowersInPhi
00289   int sm = ( iphi - 1 ) / kEBTowersInPhi;
00290   if ( iz < 0 ) 
00291     sm += 19;
00292   else
00293     sm += 1;
00294   return sm;
00295 }
00296 
00297 // in  :: TCCid  37..54 (z-) 55..72 (z+)
00298 // out :: SMid   19..36 (z-)  1..18 (z+)
00299 int L1TdeECAL::TCCidToSMid(int tccid) {
00300   // barrel
00301   if      ( tccid>37-1 && tccid<54+1) return tccid-37+19;
00302   else if ( tccid>55-1 && tccid<72+1) return tccid-55+ 1;
00303   else return 999;
00304 }