00001
00002
00003
00004
00005
00006
00007
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( const char* nameext,
00149 const char* folder,
00150 bool emulated ) {
00151
00152 array1* meEtMap = &meEtMapReal_;
00153 array1* meVeto = &meVetoReal_;
00154
00155 if ( emulated ) {
00156 meEtMap = &meEtMapEmul_;
00157 meVeto = &meVetoEmul_;
00158 }
00159
00160 dqmStore_->setCurrentFolder(folder);
00161
00162 char histo[200];
00163
00164 if (!emulated) {
00165 sprintf(histo, "EBTTT Et spectrum %s", nameext);
00166 meEtSpectrumReal_ = dqmStore_->book1D(histo, histo, 256, 0., 256.);
00167 meEtSpectrumReal_->setAxisTitle("energy (ADC)", 1);
00168
00169 sprintf(histo, "EBTTT TP matching index");
00170 meEmulMatchIndex1D_ = dqmStore_->book1D(histo, histo, 7, -1., 6.);
00171 meEmulMatchIndex1D_->setAxisTitle("TP data matching emulator", 1);
00172
00173 sprintf(histo, "EBTTT max TP matching index");
00174 meEmulMatchMaxIndex1D_ = dqmStore_->book1D(histo, histo, 7, -1., 6.);
00175 meEmulMatchMaxIndex1D_->setAxisTitle("Max TP data matching emulator", 1);
00176
00177 double xbins[51];
00178 for ( int i=0; i<=11; i++ ) xbins[i] = i-1;
00179
00180
00181
00182 for ( int i=12; i<=22; i++) xbins[i] = 3371+i-12;
00183
00184 for ( int i=23; i<=50; i++) xbins[i] = 3382+(i-23)*6;
00185
00186 sprintf(histo, "EBTTT Et vs bx %s", nameext);
00187 meEtBxReal_ = dqmStore_->bookProfile(histo, histo, 50, xbins, 256, 0, 256);
00188 meEtBxReal_->setAxisTitle("bunch crossing", 1);
00189 meEtBxReal_->setAxisTitle("energy (ADC)", 2);
00190
00191 sprintf(histo, "EBTTT TP occupancy vs bx %s", nameext);
00192 meOccupancyBxReal_ = dqmStore_->bookProfile(histo, histo, 50, xbins, 2448, 0, 2448);
00193 meOccupancyBxReal_->setAxisTitle("bunch crossing", 1);
00194 meOccupancyBxReal_->setAxisTitle("TP number", 2);
00195
00196 if ( HLTCaloHLTBit_ != "" ) {
00197 sprintf(histo, "EBTTT TCC timing calo triggers %s", nameext);
00198 meTCCTimingCalo_ = dqmStore_->book2D(histo, histo, 36, 37, 73, 7, -1., 6.);
00199 meTCCTimingCalo_->setAxisTitle("nTCC", 1);
00200 meTCCTimingCalo_->setAxisTitle("TP data matching emulator", 2);
00201 }
00202
00203 if ( HLTMuonHLTBit_ != "" ) {
00204 sprintf(histo, "EBTTT TCC timing muon triggers %s", nameext);
00205 meTCCTimingMuon_ = dqmStore_->book2D(histo, histo, 36, 37, 73, 7, -1., 6.);
00206 meTCCTimingMuon_->setAxisTitle("nTCC", 1);
00207 meTCCTimingMuon_->setAxisTitle("TP data matching emulator", 2);
00208 }
00209
00210 } else {
00211 sprintf(histo, "EBTTT Et spectrum %s", nameext);
00212 meEtSpectrumEmul_ = dqmStore_->book1D(histo, histo, 256, 0., 256.);
00213 meEtSpectrumEmul_->setAxisTitle("energy (ADC)", 1);
00214
00215 sprintf(histo, "EBTTT Et spectrum %s max", nameext);
00216 meEtSpectrumEmulMax_ = dqmStore_->book1D(histo, histo, 256, 0., 256.);
00217 meEtSpectrumEmulMax_->setAxisTitle("energy (ADC)", 1);
00218 }
00219
00220 for (int i = 0; i < 36; i++) {
00221
00222 sprintf(histo, "EBTTT Et map %s %s", nameext, Numbers::sEB(i+1).c_str());
00223 (*meEtMap)[i] = dqmStore_->bookProfile2D(histo, histo, nTTEta, 0, nTTEta, nTTPhi, 0, nTTPhi, 256, 0, 256.);
00224 (*meEtMap)[i]->setAxisTitle("ieta'", 1);
00225 (*meEtMap)[i]->setAxisTitle("iphi'", 2);
00226 dqmStore_->tag((*meEtMap)[i], i+1);
00227
00228 if (!emulated) {
00229
00230 sprintf(histo, "EBTTT EmulError %s", Numbers::sEB(i+1).c_str());
00231 meEmulError_[i] = dqmStore_->book2D(histo, histo, nTTEta, 0., nTTEta, nTTPhi, 0., nTTPhi );
00232 meEmulError_[i]->setAxisTitle("ieta'", 1);
00233 meEmulError_[i]->setAxisTitle("iphi'", 2);
00234 dqmStore_->tag(meEmulError_[i], i+1);
00235
00236 sprintf(histo, "EBTTT EmulMatch %s", Numbers::sEB(i+1).c_str());
00237 meEmulMatch_[i] = dqmStore_->book3D(histo, histo, nTTEta, 0., nTTEta, nTTPhi, 0., nTTPhi, 6, 0., 6.);
00238 meEmulMatch_[i]->setAxisTitle("ieta'", 1);
00239 meEmulMatch_[i]->setAxisTitle("iphi'", 2);
00240 meEmulMatch_[i]->setAxisTitle("TP timing", 3);
00241 dqmStore_->tag(meEmulMatch_[i], i+1);
00242
00243 sprintf(histo, "EBTTT EmulFineGrainVetoError %s", Numbers::sEB(i+1).c_str());
00244 meVetoEmulError_[i] = dqmStore_->book2D(histo, histo, nTTEta, 0., nTTEta, nTTPhi, 0., nTTPhi);
00245 meVetoEmulError_[i]->setAxisTitle("ieta'", 1);
00246 meVetoEmulError_[i]->setAxisTitle("iphi'", 2);
00247 dqmStore_->tag(meVetoEmulError_[i], i+1);
00248
00249 }
00250 }
00251
00252 }
00253
00254 void EBTriggerTowerTask::cleanup(void) {
00255
00256 if ( ! init_ ) return;
00257
00258 if ( dqmStore_ ) {
00259
00260 if ( !outputFile_.empty() ) dqmStore_->save( outputFile_.c_str() );
00261
00262 dqmStore_->rmdir( prefixME_ + "/EBTriggerTowerTask" );
00263
00264 }
00265
00266 init_ = false;
00267
00268 }
00269
00270 void EBTriggerTowerTask::endJob(void){
00271
00272 edm::LogInfo("EBTriggerTowerTask") << "analyzed " << ievt_ << " events";
00273
00274 if ( enableCleanup_ ) this->cleanup();
00275
00276 }
00277
00278 void EBTriggerTowerTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00279
00280 if ( ! init_ ) this->setup();
00281
00282 ievt_++;
00283
00284 edm::Handle<EcalTrigPrimDigiCollection> realDigis;
00285
00286 if ( e.getByLabel(realCollection_, realDigis) ) {
00287
00288 int nebtpd = realDigis->size();
00289 LogDebug("EBTriggerTowerTask") << "event " << ievt_ <<" trigger primitive digi collection size: " << nebtpd;
00290
00291 processDigis( e,
00292 realDigis,
00293 meEtMapReal_,
00294 meVetoReal_);
00295
00296 } else {
00297 edm::LogWarning("EBTriggerTowerTask") << realCollection_ << " not available";
00298 }
00299
00300 edm::Handle<EcalTrigPrimDigiCollection> emulDigis;
00301
00302 if ( e.getByLabel(emulCollection_, emulDigis) ) {
00303
00304 edm::Handle<edm::TriggerResults> hltResults;
00305
00306 if ( !e.getByLabel(HLTResultsCollection_, hltResults) ) {
00307 HLTResultsCollection_ = edm::InputTag(HLTResultsCollection_.label(), HLTResultsCollection_.instance(), "HLT");
00308 }
00309
00310 if ( !e.getByLabel(HLTResultsCollection_, hltResults) ) {
00311 HLTResultsCollection_ = edm::InputTag(HLTResultsCollection_.label(), HLTResultsCollection_.instance(), "FU");
00312 }
00313
00314 if ( e.getByLabel(HLTResultsCollection_, hltResults) ) {
00315
00316 processDigis( e,
00317 emulDigis,
00318 meEtMapEmul_,
00319 meVetoEmul_,
00320 realDigis,
00321 hltResults);
00322
00323 } else {
00324 edm::LogWarning("EBTriggerTowerTask") << HLTResultsCollection_ << " not available";
00325 }
00326
00327 } else {
00328 edm::LogInfo("EBTriggerTowerTask") << emulCollection_ << " not available";
00329 }
00330
00331 }
00332
00333 void
00334 EBTriggerTowerTask::processDigis( const edm::Event& e, const edm::Handle<EcalTrigPrimDigiCollection>& digis,
00335 array1& meEtMap,
00336 array1& meVeto,
00337 const edm::Handle<EcalTrigPrimDigiCollection>& compDigis,
00338 const edm::Handle<edm::TriggerResults> & hltResults) {
00339
00340 int bx = e.bunchCrossing();
00341 int nTP = 0;
00342
00343
00344 int readoutCrystalsInTower[108][68];
00345 for (int itcc = 0; itcc < 108; itcc++) {
00346 for (int itt = 0; itt < 68; itt++) readoutCrystalsInTower[itcc][itt] = 0;
00347 }
00348
00349 if ( compDigis.isValid() ) {
00350
00351 edm::Handle<EBDigiCollection> crystalDigis;
00352
00353 if ( e.getByLabel(EBDigiCollection_, crystalDigis) ) {
00354
00355 for ( EBDigiCollection::const_iterator cDigiItr = crystalDigis->begin(); cDigiItr != crystalDigis->end(); ++cDigiItr ) {
00356
00357 EBDetId id = cDigiItr->id();
00358 EcalTrigTowerDetId towid = id.tower();
00359
00360 int itcc = Numbers::iTCC( towid );
00361 int itt = Numbers::iTT( towid );
00362
00363 readoutCrystalsInTower[itcc-1][itt-1]++;
00364
00365 }
00366
00367 } else {
00368 edm::LogWarning("EBTriggerTowerTask") << EBDigiCollection_ << " not available";
00369 }
00370
00371 }
00372
00373 bool caloTrg = false;
00374 bool muonTrg = false;
00375
00376 if ( hltResults.isValid() ) {
00377
00378 int ntrigs = hltResults->size();
00379 if ( ntrigs!=0 ) {
00380
00381 const edm::TriggerNames & triggerNames = e.triggerNames(*hltResults);
00382
00383 for ( int itrig = 0; itrig != ntrigs; ++itrig ) {
00384 std::string trigName = triggerNames.triggerName(itrig);
00385 bool accept = hltResults->accept(itrig);
00386
00387 if ( trigName == HLTCaloHLTBit_ ) caloTrg = accept;
00388
00389 if ( trigName == HLTMuonHLTBit_ ) muonTrg = accept;
00390
00391 }
00392
00393 } else {
00394 edm::LogWarning("EBTriggerTowerTask") << " zero size trigger names in input TriggerResults";
00395 }
00396
00397 }
00398
00399 for ( EcalTrigPrimDigiCollection::const_iterator tpdigiItr = digis->begin(); tpdigiItr != digis->end(); ++tpdigiItr ) {
00400
00401 if ( Numbers::subDet( tpdigiItr->id() ) != EcalBarrel ) continue;
00402
00403 int ismt = Numbers::iSM( tpdigiItr->id() );
00404
00405 int iet = std::abs(tpdigiItr->id().ieta());
00406 int ipt = tpdigiItr->id().iphi();
00407
00408
00409
00410 ipt = ipt + 2;
00411 if ( ipt > 72 ) ipt = ipt - 72;
00412 ipt = (ipt-1)%4 + 1;
00413
00414
00415 if ( tpdigiItr->id().zside() > 0 ) ipt = 5 - ipt;
00416
00417 float xiet = iet-0.5;
00418 float xipt = ipt-0.5;
00419
00420 int itt = Numbers::iTT( tpdigiItr->id() );
00421 int itcc = Numbers::iTCC( tpdigiItr->id() );
00422
00423 float xvalEt = tpdigiItr->compressedEt();
00424 float xvalVeto = 0.5 + tpdigiItr->fineGrain();
00425
00426 bool good = true;
00427 bool goodVeto = true;
00428
00429 int compDigiInterest = -1;
00430
00431 bool matchSample[6];
00432 for (int j=0; j<6; j++) matchSample[j]=false;
00433
00434 if ( compDigis.isValid() ) {
00435
00436 if ( meEtSpectrumEmul_ ) meEtSpectrumEmul_->Fill( xvalEt );
00437
00438 float maxEt = 0;
00439 int maxTPIndex = -1;
00440 for (int j=0; j<5; j++) {
00441 float EtTP = (*tpdigiItr)[j].compressedEt();
00442 if ( EtTP > maxEt ) {
00443 maxEt = EtTP;
00444 maxTPIndex = j+1;
00445 }
00446 }
00447
00448 if ( meEtSpectrumEmulMax_ ) meEtSpectrumEmulMax_->Fill( maxEt );
00449 if ( meEmulMatchMaxIndex1D_ && maxEt > 0 ) meEmulMatchMaxIndex1D_->Fill( maxTPIndex );
00450
00451 EcalTrigPrimDigiCollection::const_iterator compDigiItr = compDigis->find( tpdigiItr->id().rawId() );
00452 if ( compDigiItr != compDigis->end() ) {
00453 int compDigiEt = compDigiItr->compressedEt();
00454 compDigiInterest = (compDigiItr->ttFlag() & 0x3);
00455
00456 if ( compDigiEt > 0 ) nTP++;
00457 if ( meEtSpectrumReal_ ) meEtSpectrumReal_->Fill( compDigiEt );
00458 if ( meEtBxReal_ && compDigiEt > 0 ) meEtBxReal_->Fill( bx, compDigiEt );
00459
00460
00461
00462 matchSample[0]=false;
00463 bool matchedAny=false;
00464
00465 for (int j=0; j<5; j++) {
00466 if ((*tpdigiItr)[j].compressedEt() == compDigiEt ) {
00467 matchSample[j+1]=true;
00468 matchedAny=true;
00469 } else {
00470 matchSample[j+1]=false;
00471 }
00472 }
00473
00474 if (!matchedAny) matchSample[0]=true;
00475
00476
00477 if (readoutCrystalsInTower[itcc-1][itt-1] == 25 &&
00478 (compDigiInterest == 1 || compDigiInterest == 3) && compDigiEt > 0) {
00479
00480 if ( tpdigiItr->compressedEt() != compDigiEt ) {
00481 good = false;
00482 }
00483 if ( tpdigiItr->fineGrain() != compDigiItr->fineGrain() ) {
00484 goodVeto = false;
00485 }
00486
00487 for (int j=0; j<6; j++) {
00488 if (matchSample[j]) {
00489
00490 int index = ( j==0 ) ? -1 : j;
00491
00492 meEmulMatchIndex1D_->Fill(index+0.5);
00493
00494 meEmulMatch_[ismt-1]->Fill(xiet, xipt, j+0.5);
00495 if ( meTCCTimingCalo_ && caloTrg ) meTCCTimingCalo_->Fill( itcc, index+0.5 );
00496 if ( meTCCTimingMuon_ && muonTrg ) meTCCTimingMuon_->Fill( itcc, index+0.5 );
00497
00498 }
00499 }
00500
00501 }
00502
00503 } else {
00504 good = false;
00505 goodVeto = false;
00506 }
00507
00508 if (!good ) {
00509 if ( meEmulError_[ismt-1] ) meEmulError_[ismt-1]->Fill(xiet, xipt);
00510 }
00511 if (!goodVeto) {
00512 if ( meVetoEmulError_[ismt-1] ) meVetoEmulError_[ismt-1]->Fill(xiet, xipt);
00513 }
00514
00515 }
00516
00517 if ( meEtMap[ismt-1] ) meEtMap[ismt-1]->Fill(xiet, xipt, xvalEt);
00518 if ( meVeto[ismt-1] ) meVeto[ismt-1]->Fill(xiet, xipt, xvalVeto);
00519
00520 }
00521
00522 if ( meOccupancyBxReal_ ) meOccupancyBxReal_->Fill( bx, nTP );
00523
00524 }
00525