CMS 3D CMS Logo

EETriggerTowerTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EETriggerTowerTask.cc
00003  *
00004  * $Date: 2008/12/04 15:49:43 $
00005  * $Revision: 1.45 $
00006  * \author C. Bernet
00007  * \author G. Della Ricca
00008  * \author E. Di Marco
00009  *
00010 */
00011 
00012 #include "FWCore/ServiceRegistry/interface/Service.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 #include "DQMServices/Core/interface/MonitorElement.h"
00016 
00017 #include "DQMServices/Core/interface/DQMStore.h"
00018 
00019 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00020 
00021 #include "DQM/EcalCommon/interface/Numbers.h"
00022 
00023 #include "DQM/EcalEndcapMonitorTasks/interface/EETriggerTowerTask.h"
00024 
00025 using namespace cms;
00026 using namespace edm;
00027 using namespace std;
00028 
00029 const int EETriggerTowerTask::nTTEta = 20;
00030 const int EETriggerTowerTask::nTTPhi = 20;
00031 const int EETriggerTowerTask::nSM = 18;
00032 
00033 EETriggerTowerTask::EETriggerTowerTask(const ParameterSet& ps) {
00034 
00035   init_ = false;
00036 
00037   dqmStore_ = Service<DQMStore>().operator->();
00038 
00039   prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
00040 
00041   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00042 
00043   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00044 
00045   meEtMapReal_ = 0;
00046   meEtMapEmul_ = 0;
00047 
00048   reserveArray(meVetoReal_);
00049   reserveArray(meFlagsReal_);
00050   reserveArray(meVetoEmul_);
00051   reserveArray(meFlagsEmul_);
00052   reserveArray(meEmulError_);
00053   reserveArray(meEmulMatch_);
00054   reserveArray(meVetoEmulError_);
00055   reserveArray(meFlagEmulError_);
00056 
00057   realCollection_ =  ps.getParameter<InputTag>("EcalTrigPrimDigiCollectionReal");
00058   emulCollection_ =  ps.getParameter<InputTag>("EcalTrigPrimDigiCollectionEmul");
00059   EEDigiCollection_ = ps.getParameter<InputTag>("EEDigiCollection");
00060 
00061   outputFile_ = ps.getUntrackedParameter<string>("OutputRootFile", "");
00062 
00063   ostringstream  str;
00064   str<<"Module label for producer of REAL     digis: "<<realCollection_<<endl;
00065   str<<"Module label for producer of EMULATED digis: "<<emulCollection_<<endl;
00066 
00067   LogDebug("EETriggerTowerTask")<<str.str()<<endl;
00068 
00069 }
00070 
00071 EETriggerTowerTask::~EETriggerTowerTask(){
00072 
00073 }
00074 
00075 void EETriggerTowerTask::reserveArray( array1& array ) {
00076 
00077   array.reserve( nSM );
00078   array.resize( nSM, static_cast<MonitorElement*>(0) );
00079 
00080 }
00081 
00082 void EETriggerTowerTask::beginJob(const EventSetup& c){
00083 
00084   ievt_ = 0;
00085 
00086   if ( dqmStore_ ) {
00087     dqmStore_->setCurrentFolder(prefixME_ + "/EETriggerTowerTask");
00088     dqmStore_->rmdir(prefixME_ + "/EETriggerTowerTask");
00089   }
00090 
00091   Numbers::initGeometry(c, false);
00092 
00093 }
00094 
00095 void EETriggerTowerTask::beginRun(const Run& r, const EventSetup& c) {
00096 
00097   if ( ! mergeRuns_ ) this->reset();
00098 
00099 }
00100 
00101 void EETriggerTowerTask::endRun(const Run& r, const EventSetup& c) {
00102 
00103 }
00104 
00105 void EETriggerTowerTask::reset(void) {
00106 
00107   if ( meEtMapReal_ ) meEtMapReal_->Reset();
00108   if ( meEtMapEmul_ ) meEtMapEmul_->Reset();
00109 
00110   for (int i = 0; i < 18; i++) {
00111 
00112     if ( meVetoReal_[i] ) meVetoReal_[i]->Reset();
00113     if ( meFlagsReal_[i] ) meFlagsReal_[i]->Reset();
00114     if ( meVetoEmul_[i] ) meVetoEmul_[i]->Reset();
00115     if ( meFlagsEmul_[i] ) meFlagsEmul_[i]->Reset();
00116     if ( meEmulError_[i] ) meEmulError_[i]->Reset();
00117     if ( meEmulMatch_[i] ) meEmulMatch_[i]->Reset();
00118     if ( meVetoEmulError_[i] ) meVetoEmulError_[i]->Reset();
00119     if ( meFlagEmulError_[i] ) meFlagEmulError_[i]->Reset();
00120 
00121   }
00122 
00123 }
00124 
00125 void EETriggerTowerTask::setup(void){
00126 
00127   init_ = true;
00128 
00129   if ( dqmStore_ ) {
00130     setup( "Real Digis",
00131            (prefixME_ + "/EETriggerTowerTask").c_str(), false );
00132 
00133     setup( "Emulated Digis",
00134            (prefixME_ + "/EETriggerTowerTask/Emulated").c_str(), true);
00135   }
00136   else {
00137     LogError("EETriggerTowerTask")<<"Bad DQMStore, "
00138                                   <<"cannot book MonitorElements."<<endl;
00139   }
00140 }
00141 
00142 void EETriggerTowerTask::setup( const char* nameext,
00143                                 const char* folder,
00144                                 bool emulated ) {
00145 
00146   array1*  meVeto = &meVetoReal_;
00147   array1*  meFlags = &meFlagsReal_;
00148 
00149   if( emulated ) {
00150     meVeto = &meVetoEmul_;
00151     meFlags= &meFlagsEmul_;
00152   }
00153 
00154   dqmStore_->setCurrentFolder(folder);
00155 
00156   static const unsigned namesize = 200;
00157 
00158   char histo[namesize];
00159   sprintf(histo, "EETTT Et map %s", nameext);
00160   string etMapName = histo;
00161   sprintf(histo, "EETTT FineGrainVeto %s", nameext);
00162   string fineGrainVetoName = histo;
00163   sprintf(histo, "EETTT Flags %s", nameext);
00164   string flagsName = histo;
00165   string emulErrorName = "EETTT EmulError";
00166   string emulMatchName = "EBTTT EmulMatch";
00167   string emulFineGrainVetoErrorName = "EETTT EmulFineGrainVetoError";
00168   string emulFlagErrorName = "EETTT EmulFlagError";
00169 
00170   if ( !emulated ) {
00171     meEtMapReal_ = dqmStore_->book2D(etMapName.c_str(), etMapName.c_str(),
00172                                      28*72, 0, 28*72, // 36 TCC/EE with max 28 TT/TCC
00173                                      256, 0, 256.);
00174     meEtMapReal_->setAxisTitle("iTT", 1);
00175     meEtMapReal_->setAxisTitle("compressed E_{T}", 2);
00176   }
00177 
00178   if ( emulated ) {
00179     meEtMapEmul_ = dqmStore_->book2D(etMapName.c_str(), etMapName.c_str(),
00180                                      28*72, 0, 28*72, // 36 TCC/EE with max 28 TT/TCC
00181                                      256, 0, 256.);
00182     meEtMapEmul_->setAxisTitle("iTT", 1);
00183     meEtMapEmul_->setAxisTitle("compressed E_{T}", 2);
00184   }
00185 
00186   for (int i = 0; i < 18; i++) {
00187 
00188     string  fineGrainVetoNameSM = fineGrainVetoName;
00189     fineGrainVetoNameSM += " " + Numbers::sEE(i+1);
00190 
00191     (*meVeto)[i] = dqmStore_->book3D(fineGrainVetoNameSM.c_str(),
00192                                fineGrainVetoNameSM.c_str(),
00193                                50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50.,
00194                                50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50.,
00195                                2, 0., 2.);
00196     (*meVeto)[i]->setAxisTitle("jx", 1);
00197     (*meVeto)[i]->setAxisTitle("jy", 2);
00198     dqmStore_->tag((*meVeto)[i], i+1);
00199 
00200     string  flagsNameSM = flagsName;
00201     flagsNameSM += " " + Numbers::sEE(i+1);
00202 
00203     (*meFlags)[i] = dqmStore_->book3D(flagsNameSM.c_str(), flagsNameSM.c_str(),
00204                                 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50.,
00205                                 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50.,
00206                                 8, 0., 8.);
00207     (*meFlags)[i]->setAxisTitle("jx", 1);
00208     (*meFlags)[i]->setAxisTitle("jy", 2);
00209     dqmStore_->tag((*meFlags)[i], i+1);
00210 
00211     if(!emulated) {
00212 
00213       string  emulErrorNameSM = emulErrorName;
00214       emulErrorNameSM += " " + Numbers::sEE(i+1);
00215 
00216       meEmulError_[i] = dqmStore_->book2D(emulErrorNameSM.c_str(),
00217                                     emulErrorNameSM.c_str(),
00218                                     50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50.,
00219                                     50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50. );
00220       meEmulError_[i]->setAxisTitle("jx", 1);
00221       meEmulError_[i]->setAxisTitle("jy", 2);
00222       dqmStore_->tag(meEmulError_[i], i+1);
00223 
00224       string  emulMatchNameSM = emulMatchName;
00225       emulMatchNameSM += " " + Numbers::sEB(i+1);
00226 
00227       meEmulMatch_[i] = dqmStore_->book3D(emulMatchNameSM.c_str(), emulMatchNameSM.c_str(),
00228                                           50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50.,
00229                                           50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50.,
00230                                           6, 0., 6.);
00231       meEmulMatch_[i]->setAxisTitle("jx'", 1);
00232       meEmulMatch_[i]->setAxisTitle("jy'", 2);
00233       dqmStore_->tag(meEmulMatch_[i], i+1);
00234 
00235       string  emulFineGrainVetoErrorNameSM = emulFineGrainVetoErrorName;
00236       emulFineGrainVetoErrorNameSM += " " + Numbers::sEE(i+1);
00237 
00238       meVetoEmulError_[i] = dqmStore_->book3D(emulFineGrainVetoErrorNameSM.c_str(),
00239                                           emulFineGrainVetoErrorNameSM.c_str(),
00240                                           50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50.,
00241                                           50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50.,
00242                                           8, 0., 8.);
00243       meVetoEmulError_[i]->setAxisTitle("jx", 1);
00244       meVetoEmulError_[i]->setAxisTitle("jy", 2);
00245       dqmStore_->tag(meVetoEmulError_[i], i+1);
00246 
00247       string  emulFlagErrorNameSM = emulFlagErrorName;
00248       emulFlagErrorNameSM += " " + Numbers::sEE(i+1);
00249 
00250       meFlagEmulError_[i] = dqmStore_->book3D(emulFlagErrorNameSM.c_str(),
00251                                           emulFlagErrorNameSM.c_str(),
00252                                           50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50.,
00253                                           50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50.,
00254                                           8, 0., 8.);
00255       meFlagEmulError_[i]->setAxisTitle("jx", 1);
00256       meFlagEmulError_[i]->setAxisTitle("jy", 2);
00257       dqmStore_->tag(meFlagEmulError_[i], i+1);
00258 
00259     }
00260   }
00261 
00262 }
00263 
00264 void EETriggerTowerTask::cleanup(void) {
00265 
00266   if ( ! init_ ) return;
00267 
00268   if ( dqmStore_ ) {
00269 
00270     if( !outputFile_.empty() ) dqmStore_->save( outputFile_.c_str() );
00271 
00272     dqmStore_->rmdir( prefixME_ + "/EETriggerTowerTask" );
00273 
00274   }
00275 
00276   init_ = false;
00277 
00278 }
00279 
00280 void EETriggerTowerTask::endJob(void){
00281 
00282   LogInfo("EETriggerTowerTask") << "analyzed " << ievt_ << " events";
00283 
00284   if ( enableCleanup_ ) this->cleanup();
00285 
00286 }
00287 
00288 void EETriggerTowerTask::analyze(const Event& e, const EventSetup& c){
00289 
00290   if ( ! init_ ) this->setup();
00291 
00292   ievt_++;
00293 
00294   Handle<EcalTrigPrimDigiCollection> realDigis;
00295 
00296   if ( e.getByLabel(realCollection_, realDigis) ) {
00297 
00298     int neetpd = realDigis->size();
00299     LogDebug("EETriggerTowerTask")
00300       <<"event "
00301       <<ievt_
00302       <<" trigger primitive digi collection size: "
00303       <<neetpd;
00304 
00305     processDigis( e,
00306                   realDigis,
00307                   meEtMapReal_,
00308                   meVetoReal_,
00309                   meFlagsReal_);
00310 
00311   } else {
00312     LogWarning("EETriggerTowerTask") << realCollection_ << " not available";
00313   }
00314 
00315   Handle<EcalTrigPrimDigiCollection> emulDigis;
00316 
00317   if ( e.getByLabel(emulCollection_, emulDigis) ) {
00318 
00319     processDigis( e,
00320                   emulDigis,
00321                   meEtMapEmul_,
00322                   meVetoEmul_,
00323                   meFlagsEmul_,
00324                   realDigis);
00325 
00326   } else {
00327     LogWarning("EETriggerTowerTask") << emulCollection_ << " not available";
00328   }
00329 
00330 }
00331 
00332 void
00333 EETriggerTowerTask::processDigis( const Event& e, const Handle<EcalTrigPrimDigiCollection>& digis,
00334                                   MonitorElement* meEtMap,
00335                                   array1& meVeto,
00336                                   array1& meFlags,
00337                                   const Handle<EcalTrigPrimDigiCollection>& compDigis ) {
00338 
00339   LogDebug("EETriggerTowerTask")<<"processing "<<meEtMap->getName()<<endl;
00340 
00341   map<int, int> crystalsInTower;
00342 
00343   Handle<EEDigiCollection> crystalDigis;
00344 
00345   if ( e.getByLabel(EEDigiCollection_, crystalDigis) ) {
00346 
00347     for ( EEDigiCollection::const_iterator cDigiItr = crystalDigis->begin(); cDigiItr != crystalDigis->end(); ++cDigiItr ) {
00348 
00349       EEDetId id = cDigiItr->id();
00350 
00351       int ix = id.ix();
00352       int iy = id.iy();
00353       int ism = Numbers::iSM( id );
00354       int itt = Numbers::iTT( ism, EcalEndcap, ix, iy );
00355 
00356       map<int, int>::const_iterator itrTower = crystalsInTower.find(itt);
00357 
00358       if( itrTower==crystalsInTower.end() ) crystalsInTower.insert(std::make_pair(itt,1));
00359       else crystalsInTower[itt]++;
00360 
00361     }
00362 
00363   } else {
00364     LogWarning("EETriggerTowerTask") << EEDigiCollection_ << " not available";
00365   }
00366 
00367   ostringstream  str;
00368 
00369   for ( EcalTrigPrimDigiCollection::const_iterator tpdigiItr = digis->begin(); tpdigiItr != digis->end(); ++tpdigiItr ) {
00370 
00371     if ( Numbers::subDet( tpdigiItr->id() ) != EcalEndcap ) continue;
00372 
00373     int ismt = Numbers::iSM( tpdigiItr->id() );
00374 
00375     int itt = Numbers::iTT( tpdigiItr->id() );
00376 
00377     vector<DetId> crystals = Numbers::crystals( tpdigiItr->id() );
00378 
00379     for ( unsigned int i=0; i<crystals.size(); i++ ) {
00380 
00381     EEDetId id = crystals[i];
00382 
00383     int ix = id.ix();
00384     int iy = id.iy();
00385 
00386     if ( ismt >= 1 && ismt <= 9 ) ix = 101 - ix;
00387 
00388     float xix = ix-0.5;
00389     float xiy = iy-0.5;
00390 
00391     str<<"det id = "<<tpdigiItr->id().rawId()<<" "
00392        <<"sm, tt, x, y "<<ismt<<" "<<itt<<" "<<ix<<" "<<iy<<endl;
00393 
00394     int ttindex = Numbers::iTT(tpdigiItr->id());
00395     int tccindex = Numbers::TCCid(tpdigiItr->id());
00396 
00397     int xttindex = -1;
00398     if ( tccindex <= 36 )
00399       xttindex = 28*tccindex+ttindex-1; // EE-
00400     else if ( tccindex >= 73 )
00401       xttindex = 28*(tccindex-36)+ttindex-1; // EE+ (skip EB TCCs)
00402 
00403     // count the number of readout crystals / TT
00404     // do do the match emul-real only if ncry/TT=25
00405     int nReadoutCrystals=crystalsInTower[itt];
00406 
00407     float xval;
00408 
00409     xval = tpdigiItr->compressedEt();
00410     if ( meEtMap && xttindex > -1 ) {
00411       meEtMap->Fill(xttindex, xval);
00412     }
00413     else {
00414       LogError("EETriggerTowerTask")<<"histo does not exist "<<endl;
00415     }
00416 
00417     xval = 0.5 + tpdigiItr->fineGrain();
00418     if ( meVeto[ismt-1] ) meVeto[ismt-1]->Fill(xix, xiy, xval);
00419 
00420     xval = 0.5 + tpdigiItr->ttFlag();
00421     if ( meFlags[ismt-1] ) meFlags[ismt-1]->Fill(xix, xiy, xval);
00422 
00423     if( compDigis.isValid() ) {
00424       bool good = true;
00425       bool goodFlag = true;
00426       bool goodVeto = true;
00427 
00428       EcalTrigPrimDigiCollection::const_iterator compDigiItr = compDigis->find( tpdigiItr->id().rawId() );
00429       if( compDigiItr != compDigis->end() ) {
00430         str<<"found corresponding digi! "<<*compDigiItr<<endl;
00431         if( tpdigiItr->compressedEt() != compDigiItr->compressedEt() ) {
00432           str<<"but it is different..."<<endl;
00433           good = false;
00434         }
00435 
00436         // compare the 5 TPs with different time-windows
00437         // sample 0 means no match, 1-5: sample of the TP that matches
00438         bool matchSample[6];
00439         for(int j=0; j<6; j++) matchSample[j] = false;
00440         bool matchedAny=false;
00441 
00442         for(int j=0; j<5; j++) {
00443           if((*tpdigiItr)[j].compressedEt() == compDigiItr->compressedEt() ) {
00444             matchSample[j+1]=true;
00445             matchedAny=true;
00446           }
00447         }
00448         if(!matchedAny) matchSample[0]=true;
00449 
00450         if(nReadoutCrystals==25 && compDigiItr->compressedEt()>0) {
00451           for(int j=0; j<6; j++) {
00452             if(matchSample[j]) meEmulMatch_[ismt-1]->Fill(xix, xiy, j+0.5);
00453           }
00454         }
00455 
00456         if( tpdigiItr->ttFlag() != compDigiItr->ttFlag() ) {
00457           str<<"but flag is different..."<<endl;
00458           goodFlag = false;
00459         }
00460         if( tpdigiItr->fineGrain() != compDigiItr->fineGrain() ) {
00461           str<<"but fine grain veto is different..."<<endl;
00462           goodVeto = false;
00463         }
00464       }
00465       else {
00466         good = false;
00467         goodFlag = false;
00468         goodVeto = false;
00469         str<<"could not find corresponding digi... "<<endl;
00470       }
00471       if(!good ) {
00472         if ( meEmulError_[ismt-1] ) meEmulError_[ismt-1]->Fill(xix, xiy);
00473       }
00474       if(!goodFlag) {
00475         float zval = tpdigiItr->ttFlag();
00476         if ( meFlagEmulError_[ismt-1] ) meFlagEmulError_[ismt-1]->Fill(xix, xiy, zval);
00477       }
00478       if(!goodVeto) {
00479         float zval = tpdigiItr->fineGrain();
00480         if ( meVetoEmulError_[ismt-1] ) meVetoEmulError_[ismt-1]->Fill(xix, xiy, zval);
00481       }
00482     }
00483     }
00484   }
00485   LogDebug("EETriggerTowerTask")<<str.str()<<endl;
00486 }
00487 

Generated on Tue Jun 9 17:32:54 2009 for CMSSW by  doxygen 1.5.4