CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/DQM/EcalBarrelMonitorTasks/src/EBTriggerTowerTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBTriggerTowerTask.cc
00003  *
00004  * $Date: 2012/04/27 13:46:03 $
00005  * $Revision: 1.111 $
00006  * \author G. Della Ricca
00007  * \author E. Di Marco
00008  *
00009 */
00010 
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 
00014 #include "DataFormats/Common/interface/TriggerResults.h"
00015 #include "DQMServices/Core/interface/MonitorElement.h"
00016 #include "DQMServices/Core/interface/DQMStore.h"
00017 
00018 #include "DQM/EcalCommon/interface/Numbers.h"
00019 
00020 #include "DQM/EcalBarrelMonitorTasks/interface/EBTriggerTowerTask.h"
00021 #include "FWCore/Common/interface/TriggerNames.h"
00022 
00023 const int EBTriggerTowerTask::nTTEta = 17;
00024 const int EBTriggerTowerTask::nTTPhi = 4;
00025 const int EBTriggerTowerTask::nSM = 36;
00026 
00027 EBTriggerTowerTask::EBTriggerTowerTask(const edm::ParameterSet& ps) {
00028 
00029   init_ = false;
00030 
00031   dqmStore_ = edm::Service<DQMStore>().operator->();
00032 
00033   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00034 
00035   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00036 
00037   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00038 
00039   meEtSpectrumReal_ = 0;
00040   meEtSpectrumEmul_ = 0;
00041   meEtSpectrumEmulMax_ = 0;
00042   meEtBxReal_ = 0;
00043   meOccupancyBxReal_ = 0;
00044   meTCCTimingCalo_ = 0;
00045   meTCCTimingMuon_ = 0;
00046   meEmulMatchIndex1D_ = 0;
00047   meEmulMatchMaxIndex1D_ = 0;
00048 
00049   reserveArray(meEtMapReal_);
00050   reserveArray(meVetoReal_);
00051   reserveArray(meEtMapEmul_);
00052   reserveArray(meVetoEmul_);
00053   reserveArray(meEmulError_);
00054   reserveArray(meEmulMatch_);
00055   reserveArray(meVetoEmulError_);
00056 
00057   realCollection_ =  ps.getParameter<edm::InputTag>("EcalTrigPrimDigiCollectionReal");
00058   emulCollection_ =  ps.getParameter<edm::InputTag>("EcalTrigPrimDigiCollectionEmul");
00059   EBDigiCollection_ = ps.getParameter<edm::InputTag>("EBDigiCollection");
00060   HLTResultsCollection_ = ps.getParameter<edm::InputTag>("HLTResultsCollection");
00061 
00062   HLTCaloHLTBit_ = ps.getUntrackedParameter<std::string>("HLTCaloHLTBit", "");
00063   HLTMuonHLTBit_ = ps.getUntrackedParameter<std::string>("HLTMuonHLTBit", "");
00064 
00065   outputFile_ = ps.getUntrackedParameter<std::string>("OutputRootFile", "");
00066 
00067   LogDebug("EBTriggerTowerTask") << "REAL     digis: " << realCollection_;
00068   LogDebug("EBTriggerTowerTask") << "EMULATED digis: " << emulCollection_;
00069 
00070 }
00071 
00072 EBTriggerTowerTask::~EBTriggerTowerTask(){
00073 
00074 }
00075 
00076 void EBTriggerTowerTask::reserveArray( array1& array ) {
00077 
00078   array.reserve( nSM );
00079   array.resize( nSM, static_cast<MonitorElement*>(0) );
00080 
00081 }
00082 
00083 void EBTriggerTowerTask::beginJob(void){
00084 
00085   ievt_ = 0;
00086 
00087   if ( dqmStore_ ) {
00088     dqmStore_->setCurrentFolder(prefixME_ + "/EBTriggerTowerTask");
00089     dqmStore_->rmdir(prefixME_ + "/EBTriggerTowerTask");
00090   }
00091 
00092 }
00093 
00094 void EBTriggerTowerTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00095 
00096   Numbers::initGeometry(c, false);
00097 
00098   if ( ! mergeRuns_ ) this->reset();
00099 
00100 }
00101 
00102 void EBTriggerTowerTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00103 
00104 }
00105 
00106 void EBTriggerTowerTask::reset(void) {
00107 
00108   if ( meEtSpectrumReal_ ) meEtSpectrumReal_->Reset();
00109   if ( meEtSpectrumEmul_ ) meEtSpectrumEmul_->Reset();
00110   if ( meEtSpectrumEmulMax_ ) meEtSpectrumEmulMax_->Reset();
00111   if ( meEtBxReal_ ) meEtBxReal_->Reset();
00112   if ( meOccupancyBxReal_ ) meOccupancyBxReal_->Reset();
00113   if ( meTCCTimingCalo_ ) meTCCTimingCalo_->Reset();
00114   if ( meTCCTimingMuon_ ) meTCCTimingMuon_->Reset();
00115   if ( meEmulMatchIndex1D_ ) meEmulMatchIndex1D_->Reset();
00116   if ( meEmulMatchMaxIndex1D_ ) meEmulMatchMaxIndex1D_->Reset();
00117 
00118   for (int i = 0; i < 36; i++) {
00119 
00120     if ( meEtMapReal_[i] ) meEtMapReal_[i]->Reset();
00121     if ( meVetoReal_[i] ) meVetoReal_[i]->Reset();
00122     if ( meEtMapEmul_[i] ) meEtMapEmul_[i]->Reset();
00123     if ( meVetoEmul_[i] ) meVetoEmul_[i]->Reset();
00124     if ( meEmulError_[i] ) meEmulError_[i]->Reset();
00125     if ( meEmulMatch_[i] ) meEmulMatch_[i]->Reset();
00126     if ( meVetoEmulError_[i] ) meVetoEmulError_[i]->Reset();
00127 
00128   }
00129 
00130 }
00131 
00132 void EBTriggerTowerTask::setup(void){
00133 
00134   init_ = true;
00135 
00136   if ( dqmStore_ ) {
00137     setup( "Real Digis",
00138            (prefixME_ + "/EBTriggerTowerTask").c_str(), false );
00139 
00140     setup( "Emulated Digis",
00141            (prefixME_ + "/EBTriggerTowerTask/Emulated").c_str(), true);
00142   }
00143   else {
00144     edm::LogError("EBTriggerTowerTask") << "Bad DQMStore, cannot book MonitorElements.";
00145   }
00146 }
00147 
00148 void EBTriggerTowerTask::setup( std::string const &nameext,
00149                                 std::string const &folder,
00150                                 bool emulated ) {
00151 
00152   array1*  meEtMap = &meEtMapReal_;
00153 
00154   if ( emulated ) {
00155     meEtMap = &meEtMapEmul_;
00156   }
00157 
00158   dqmStore_->setCurrentFolder(folder);
00159 
00160   std::string name;
00161 
00162   if (!emulated) {
00163     name = "EBTTT Et spectrum " + nameext;
00164     meEtSpectrumReal_ = dqmStore_->book1D(name, name, 256, 0., 256.);
00165     meEtSpectrumReal_->setAxisTitle("energy (ADC)", 1);
00166 
00167     name = "EBTTT TP matching index";
00168     meEmulMatchIndex1D_ = dqmStore_->book1D(name, name, 7, -1., 6.);
00169     meEmulMatchIndex1D_->setAxisTitle("TP data matching emulator", 1);
00170 
00171     name = "EBTTT max TP matching index";
00172     meEmulMatchMaxIndex1D_ = dqmStore_->book1D(name, name, 7, -1., 6.);
00173     meEmulMatchMaxIndex1D_->setAxisTitle("Max TP data matching emulator", 1);
00174 
00175     double xbins[51];
00176     for ( int i=0; i<=11; i++ ) xbins[i] = i-1;  // begin of orbit
00177     // abort gap in presence of calibration: [3381-3500]
00178     // abort gap in absence of calibration: [3444-3500]
00179     // using the wider abort gap always, start finer binning at bx=3371
00180     for ( int i=12; i<=22; i++) xbins[i] = 3371+i-12;
00181     // use 29 bins for the abort gap
00182     for ( int i=23; i<=50; i++) xbins[i] = 3382+(i-23)*6;
00183 
00184     name = "EBTTT Et vs bx " + nameext;
00185     meEtBxReal_ = dqmStore_->bookProfile(name, name, 50, xbins, 256, 0, 256);
00186     meEtBxReal_->setAxisTitle("bunch crossing", 1);
00187     meEtBxReal_->setAxisTitle("energy (ADC)", 2);
00188 
00189     name = "EBTTT TP occupancy vs bx " + nameext;
00190     meOccupancyBxReal_ = dqmStore_->bookProfile(name, name, 50, xbins, 2448, 0, 2448);
00191     meOccupancyBxReal_->setAxisTitle("bunch crossing", 1);
00192     meOccupancyBxReal_->setAxisTitle("TP number", 2);
00193 
00194     if ( HLTCaloHLTBit_ != "" ) {
00195       name = "EBTTT TCC timing calo triggers " + nameext;
00196       meTCCTimingCalo_ = dqmStore_->book2D(name, name, 36, 37, 73, 7, -1., 6.);
00197       meTCCTimingCalo_->setAxisTitle("nTCC", 1);
00198       meTCCTimingCalo_->setAxisTitle("TP data matching emulator", 2);
00199     }
00200 
00201     if ( HLTMuonHLTBit_ != "" ) {
00202       name = "EBTTT TCC timing muon triggers " + nameext;
00203       meTCCTimingMuon_ = dqmStore_->book2D(name, name, 36, 37, 73, 7, -1., 6.);
00204       meTCCTimingMuon_->setAxisTitle("nTCC", 1);
00205       meTCCTimingMuon_->setAxisTitle("TP data matching emulator", 2);
00206     }
00207 
00208   } else {
00209     name = "EBTTT Et spectrum " + nameext;
00210     meEtSpectrumEmul_ = dqmStore_->book1D(name, name, 256, 0., 256.);
00211     meEtSpectrumEmul_->setAxisTitle("energy (ADC)", 1);
00212 
00213     name = "EBTTT Et spectrum " + nameext + " max";
00214     meEtSpectrumEmulMax_ = dqmStore_->book1D(name, name, 256, 0., 256.);
00215     meEtSpectrumEmulMax_->setAxisTitle("energy (ADC)", 1);
00216   }
00217 
00218   for (int i = 0; i < 36; i++) {
00219 
00220     name = "EBTTT Et map " + nameext + " " + Numbers::sEB(i+1);
00221     (*meEtMap)[i] = dqmStore_->bookProfile2D(name, name, nTTEta, 0, nTTEta, nTTPhi, 0, nTTPhi, 256, 0, 256.);
00222     (*meEtMap)[i]->setAxisTitle("ieta'", 1);
00223     (*meEtMap)[i]->setAxisTitle("iphi'", 2);
00224     dqmStore_->tag((*meEtMap)[i], i+1);
00225 
00226     if (!emulated) {
00227 
00228       name = "EBTTT EmulError " + Numbers::sEB(i+1);
00229       meEmulError_[i] = dqmStore_->book2D(name, name, nTTEta, 0., nTTEta, nTTPhi, 0., nTTPhi );
00230       meEmulError_[i]->setAxisTitle("ieta'", 1);
00231       meEmulError_[i]->setAxisTitle("iphi'", 2);
00232       dqmStore_->tag(meEmulError_[i], i+1);
00233 
00234       name = "EBTTT EmulMatch " + Numbers::sEB(i+1);
00235       meEmulMatch_[i] = dqmStore_->book3D(name, name, nTTEta, 0., nTTEta, nTTPhi, 0., nTTPhi, 6, 0., 6.);
00236       meEmulMatch_[i]->setAxisTitle("ieta'", 1);
00237       meEmulMatch_[i]->setAxisTitle("iphi'", 2);
00238       meEmulMatch_[i]->setAxisTitle("TP timing", 3);
00239       dqmStore_->tag(meEmulMatch_[i], i+1);
00240 
00241       name ="EBTTT EmulFineGrainVetoError " + Numbers::sEB(i+1);
00242       meVetoEmulError_[i] = dqmStore_->book2D(name, name, nTTEta, 0., nTTEta, nTTPhi, 0., nTTPhi);
00243       meVetoEmulError_[i]->setAxisTitle("ieta'", 1);
00244       meVetoEmulError_[i]->setAxisTitle("iphi'", 2);
00245       dqmStore_->tag(meVetoEmulError_[i], i+1);
00246 
00247     }
00248   }
00249 
00250 }
00251 
00252 void EBTriggerTowerTask::cleanup(void) {
00253 
00254   if ( ! init_ ) return;
00255 
00256   if ( dqmStore_ ) {
00257 
00258     if ( !outputFile_.empty() ) dqmStore_->save( outputFile_.c_str() );
00259 
00260     dqmStore_->rmdir( prefixME_ + "/EBTriggerTowerTask" );
00261 
00262   }
00263 
00264   init_ = false;
00265 
00266 }
00267 
00268 void EBTriggerTowerTask::endJob(void){
00269 
00270   edm::LogInfo("EBTriggerTowerTask") << "analyzed " << ievt_ << " events";
00271 
00272   if ( enableCleanup_ ) this->cleanup();
00273 
00274 }
00275 
00276 void EBTriggerTowerTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00277 
00278   if ( ! init_ ) this->setup();
00279 
00280   ievt_++;
00281 
00282   edm::Handle<EcalTrigPrimDigiCollection> realDigis;
00283 
00284   if ( e.getByLabel(realCollection_, realDigis) ) {
00285 
00286     int nebtpd = realDigis->size();
00287     LogDebug("EBTriggerTowerTask") << "event " << ievt_ <<" trigger primitive digi collection size: " << nebtpd;
00288 
00289     processDigis( e,
00290                   realDigis,
00291                   meEtMapReal_,
00292                   meVetoReal_);
00293 
00294   } else {
00295     edm::LogWarning("EBTriggerTowerTask") << realCollection_ << " not available";
00296   }
00297 
00298   edm::Handle<EcalTrigPrimDigiCollection> emulDigis;
00299 
00300   if ( e.getByLabel(emulCollection_, emulDigis) ) {
00301 
00302     edm::Handle<edm::TriggerResults> hltResults;
00303 
00304     if ( !e.getByLabel(HLTResultsCollection_, hltResults) ) {
00305       HLTResultsCollection_ = edm::InputTag(HLTResultsCollection_.label(), HLTResultsCollection_.instance(), "HLT");
00306     }
00307 
00308     if ( !e.getByLabel(HLTResultsCollection_, hltResults) ) {
00309       HLTResultsCollection_ = edm::InputTag(HLTResultsCollection_.label(), HLTResultsCollection_.instance(), "FU");
00310     }
00311 
00312     if ( e.getByLabel(HLTResultsCollection_, hltResults) ) {
00313 
00314       processDigis( e,
00315                     emulDigis,
00316                     meEtMapEmul_,
00317                     meVetoEmul_,
00318                     realDigis,
00319                     hltResults);
00320 
00321     } else {
00322       edm::LogWarning("EBTriggerTowerTask") << HLTResultsCollection_ << " not available";
00323     }
00324 
00325   } else {
00326     edm::LogInfo("EBTriggerTowerTask") << emulCollection_ << " not available";
00327   }
00328 
00329 }
00330 
00331 void
00332 EBTriggerTowerTask::processDigis( const edm::Event& e, const edm::Handle<EcalTrigPrimDigiCollection>& digis,
00333                                   array1& meEtMap,
00334                                   array1& meVeto,
00335                                   const edm::Handle<EcalTrigPrimDigiCollection>& compDigis,
00336                                   const edm::Handle<edm::TriggerResults> & hltResults) {
00337 
00338   int bx = e.bunchCrossing();
00339   int nTP = 0;
00340 
00341   //  map<EcalTrigTowerDetId, int> crystalsInTower;
00342   int readoutCrystalsInTower[108][68];
00343     for (int itcc = 0; itcc < 108; itcc++) {
00344     for (int itt = 0; itt < 68; itt++) readoutCrystalsInTower[itcc][itt] = 0;
00345   }
00346 
00347   if ( compDigis.isValid() ) {
00348 
00349     edm::Handle<EBDigiCollection> crystalDigis;
00350 
00351     if ( e.getByLabel(EBDigiCollection_, crystalDigis) ) {
00352 
00353       for ( EBDigiCollection::const_iterator cDigiItr = crystalDigis->begin(); cDigiItr != crystalDigis->end(); ++cDigiItr ) {
00354 
00355         EBDetId id = cDigiItr->id();
00356         EcalTrigTowerDetId towid = id.tower();
00357 
00358         int itcc = Numbers::iTCC( towid );
00359         int itt = Numbers::iTT( towid );
00360 
00361         readoutCrystalsInTower[itcc-1][itt-1]++;
00362 
00363       }
00364 
00365     } else {
00366       edm::LogWarning("EBTriggerTowerTask") << EBDigiCollection_ << " not available";
00367     }
00368 
00369   }
00370 
00371   bool caloTrg = false;
00372   bool muonTrg = false;
00373 
00374   if ( hltResults.isValid() ) {
00375 
00376     int ntrigs = hltResults->size();
00377     if ( ntrigs!=0 ) {
00378 
00379       const edm::TriggerNames & triggerNames = e.triggerNames(*hltResults);
00380 
00381       for ( int itrig = 0; itrig != ntrigs; ++itrig ) {
00382         std::string trigName = triggerNames.triggerName(itrig);
00383         bool accept = hltResults->accept(itrig);
00384 
00385         if ( trigName == HLTCaloHLTBit_ ) caloTrg = accept;
00386 
00387         if ( trigName == HLTMuonHLTBit_ ) muonTrg = accept;
00388 
00389       }
00390 
00391     } else {
00392       edm::LogWarning("EBTriggerTowerTask") << " zero size trigger names in input TriggerResults";
00393     }
00394 
00395   }
00396 
00397   for ( EcalTrigPrimDigiCollection::const_iterator tpdigiItr = digis->begin(); tpdigiItr != digis->end(); ++tpdigiItr ) {
00398 
00399     if ( Numbers::subDet( tpdigiItr->id() ) != EcalBarrel ) continue;
00400 
00401     int ismt = Numbers::iSM( tpdigiItr->id() );
00402 
00403     int iet = std::abs(tpdigiItr->id().ieta());
00404     int ipt = tpdigiItr->id().iphi();
00405 
00406     // phi_tower: change the range from global to SM-local
00407     // phi==0 is in the middle of a SM
00408     ipt = ipt + 2;
00409     if ( ipt > 72 ) ipt = ipt - 72;
00410     ipt = (ipt-1)%4 + 1;
00411 
00412     // phi_tower: SM-local phi runs opposite to global in EB+
00413     if ( tpdigiItr->id().zside() > 0 ) ipt = 5 - ipt;
00414 
00415     float xiet = iet-0.5;
00416     float xipt = ipt-0.5;
00417 
00418     int itt = Numbers::iTT( tpdigiItr->id() );
00419     int itcc = Numbers::iTCC( tpdigiItr->id() );
00420 
00421     float xvalEt = tpdigiItr->compressedEt();
00422     float xvalVeto = 0.5 + tpdigiItr->fineGrain();
00423 
00424     bool good = true;
00425     bool goodVeto = true;
00426 
00427     int compDigiInterest = -1;
00428 
00429     bool matchSample[6];
00430     for (int j=0; j<6; j++) matchSample[j]=false;
00431 
00432     if ( compDigis.isValid() ) {
00433 
00434       if ( meEtSpectrumEmul_ ) meEtSpectrumEmul_->Fill( xvalEt );
00435 
00436       float maxEt = 0;
00437       int maxTPIndex = -1;
00438       for (int j=0; j<5; j++) {
00439         float EtTP = (*tpdigiItr)[j].compressedEt();
00440         if ( EtTP > maxEt ) {
00441           maxEt = EtTP;
00442           maxTPIndex = j+1;
00443         }
00444       }
00445 
00446       if ( meEtSpectrumEmulMax_ ) meEtSpectrumEmulMax_->Fill( maxEt );
00447       if ( meEmulMatchMaxIndex1D_ && maxEt > 0 ) meEmulMatchMaxIndex1D_->Fill( maxTPIndex );
00448 
00449       EcalTrigPrimDigiCollection::const_iterator compDigiItr = compDigis->find( tpdigiItr->id().rawId() );
00450       if ( compDigiItr != compDigis->end() ) {
00451         int compDigiEt = compDigiItr->compressedEt();
00452         compDigiInterest = (compDigiItr->ttFlag() & 0x3);
00453 
00454         if ( compDigiEt > 0 ) nTP++;
00455         if ( meEtSpectrumReal_ ) meEtSpectrumReal_->Fill( compDigiEt );
00456         if ( meEtBxReal_ && compDigiEt > 0 ) meEtBxReal_->Fill( bx, compDigiEt );
00457 
00458         // compare the 5 TPs with different time-windows
00459         // sample 0 means no match, 1-5: sample of the TP that matches
00460         matchSample[0]=false;
00461         bool matchedAny=false;
00462 
00463         for (int j=0; j<5; j++) {
00464           if ((*tpdigiItr)[j].compressedEt() == compDigiEt ) {
00465             matchSample[j+1]=true;
00466             matchedAny=true;
00467           } else {
00468             matchSample[j+1]=false;
00469           }
00470         }
00471 
00472         if (!matchedAny) matchSample[0]=true;
00473 
00474         // check if the tower has been readout completely and if it is medium or high interest
00475         if (readoutCrystalsInTower[itcc-1][itt-1] == 25 &&
00476             (compDigiInterest == 1 || compDigiInterest == 3) && compDigiEt > 0) {
00477 
00478           if ( tpdigiItr->compressedEt() != compDigiEt ) {
00479             good = false;
00480           }
00481           if ( tpdigiItr->fineGrain() != compDigiItr->fineGrain() ) {
00482             goodVeto = false;
00483           }
00484 
00485           for (int j=0; j<6; j++) {
00486             if (matchSample[j]) {
00487 
00488               int index = ( j==0 ) ? -1 : j;
00489 
00490               meEmulMatchIndex1D_->Fill(index+0.5);
00491 
00492               meEmulMatch_[ismt-1]->Fill(xiet, xipt, j+0.5);
00493               if ( meTCCTimingCalo_ && caloTrg ) meTCCTimingCalo_->Fill( itcc, index+0.5 );
00494               if ( meTCCTimingMuon_ && muonTrg ) meTCCTimingMuon_->Fill( itcc, index+0.5 );
00495 
00496             }
00497           }
00498 
00499         } // check readout
00500 
00501       } else {
00502         good = false;
00503         goodVeto = false;
00504       }
00505 
00506       if (!good ) {
00507         if ( meEmulError_[ismt-1] ) meEmulError_[ismt-1]->Fill(xiet, xipt);
00508       }
00509       if (!goodVeto) {
00510         if ( meVetoEmulError_[ismt-1] ) meVetoEmulError_[ismt-1]->Fill(xiet, xipt);
00511       }
00512 
00513     } // compDigis.isValid
00514 
00515     if ( meEtMap[ismt-1] ) meEtMap[ismt-1]->Fill(xiet, xipt, xvalEt);
00516     if ( meVeto[ismt-1] ) meVeto[ismt-1]->Fill(xiet, xipt, xvalVeto);
00517 
00518   } // loop on TP
00519 
00520   if ( meOccupancyBxReal_ ) meOccupancyBxReal_->Fill( bx, nTP );
00521 
00522 }
00523