CMS 3D CMS Logo

EBSelectiveReadoutTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBSelectiveReadoutTask.cc
00003  *
00004  * $Date: 2008/12/04 15:19:28 $
00005  * $Revision: 1.24 $
00006  * \author P. Gras
00007  * \author E. Di Marco
00008  *
00009 */
00010 
00011 #include <iostream>
00012 #include <fstream>
00013 #include <vector>
00014 #include <math.h>
00015 
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 
00019 #include "DQMServices/Core/interface/MonitorElement.h"
00020 
00021 #include "DQMServices/Core/interface/DQMStore.h"
00022 
00023 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00024 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00025 
00026 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00027 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00028 
00029 #include <DQM/EcalCommon/interface/UtilsClient.h>
00030 #include <DQM/EcalCommon/interface/Numbers.h>
00031 
00032 #include <DQM/EcalBarrelMonitorTasks/interface/EBSelectiveReadoutTask.h>
00033 
00034 using namespace cms;
00035 using namespace edm;
00036 using namespace std;
00037 
00038 EBSelectiveReadoutTask::EBSelectiveReadoutTask(const ParameterSet& ps){
00039 
00040   init_ = false;
00041 
00042   dqmStore_ = Service<DQMStore>().operator->();
00043 
00044   prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
00045 
00046   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00047 
00048   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00049 
00050   // parameters...
00051   EBDigiCollection_ = ps.getParameter<edm::InputTag>("EBDigiCollection");
00052   EBUnsuppressedDigiCollection_ = ps.getParameter<edm::InputTag>("EBUsuppressedDigiCollection");
00053   EBSRFlagCollection_ = ps.getParameter<edm::InputTag>("EBSRFlagCollection");
00054   EcalTrigPrimDigiCollection_ = ps.getParameter<edm::InputTag>("EcalTrigPrimDigiCollection");
00055   FEDRawDataCollection_ = ps.getParameter<edm::InputTag>("FEDRawDataCollection");
00056 
00057   // histograms...
00058   EBDccEventSize_ = 0;
00059   EBReadoutUnitForcedBitMap_ = 0;
00060   EBFullReadoutSRFlagMap_ = 0;
00061   EBHighInterestTriggerTowerFlagMap_ = 0;
00062   EBLowInterestTriggerTowerFlagMap_ = 0;
00063   EBEventSize_ = 0;
00064   EBHighInterestPayload_ = 0;
00065   EBLowInterestPayload_ = 0;
00066 
00067 }
00068 
00069 EBSelectiveReadoutTask::~EBSelectiveReadoutTask() {
00070 
00071 }
00072 
00073 void EBSelectiveReadoutTask::beginJob(const EventSetup& c) {
00074 
00075   ievt_ = 0;
00076 
00077   if ( dqmStore_ ) {
00078     dqmStore_->setCurrentFolder(prefixME_ + "/EBSelectiveReadoutTask");
00079     dqmStore_->rmdir(prefixME_ + "/EBSelectiveReadoutTask");
00080   }
00081 
00082   Numbers::initGeometry(c, false);
00083 
00084 }
00085 
00086 void EBSelectiveReadoutTask::setup(void) {
00087 
00088   init_ = true;
00089 
00090   char histo[200];
00091 
00092   if ( dqmStore_ ) {
00093     dqmStore_->setCurrentFolder(prefixME_ + "/EBSelectiveReadoutTask");
00094 
00095     sprintf(histo, "EBSRT DCC event size");
00096     EBDccEventSize_ = dqmStore_->bookProfile(histo, histo, 36, 1, 37, 100, 0., 200., "s");
00097     for (int i = 0; i < 36; i++) {
00098       EBDccEventSize_->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
00099     }
00100 
00101     sprintf(histo, "EBSRT readout unit with SR forced");
00102     EBReadoutUnitForcedBitMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00103     EBReadoutUnitForcedBitMap_->setAxisTitle("jphi", 1);
00104     EBReadoutUnitForcedBitMap_->setAxisTitle("jeta", 2);
00105 
00106     sprintf(histo, "EBSRT full readout SR flags");
00107     EBFullReadoutSRFlagMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00108     EBFullReadoutSRFlagMap_->setAxisTitle("jphi", 1);
00109     EBFullReadoutSRFlagMap_->setAxisTitle("jeta", 2);
00110 
00111     sprintf(histo, "EBSRT high interest TT Flags");
00112     EBHighInterestTriggerTowerFlagMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00113     EBHighInterestTriggerTowerFlagMap_->setAxisTitle("jphi", 1);
00114     EBHighInterestTriggerTowerFlagMap_->setAxisTitle("jeta", 2);
00115 
00116     sprintf(histo, "EBSRT low interest TT Flags");
00117     EBLowInterestTriggerTowerFlagMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00118     EBLowInterestTriggerTowerFlagMap_->setAxisTitle("jphi", 1);
00119     EBLowInterestTriggerTowerFlagMap_->setAxisTitle("jeta", 2);
00120 
00121     sprintf(histo, "EBSRT event size");
00122     EBEventSize_ = dqmStore_->book1D(histo, histo, 100, 0, 200);
00123     EBEventSize_->setAxisTitle("event size (kB)",1);
00124 
00125     sprintf(histo, "EBSRT high interest payload");
00126     EBHighInterestPayload_ =  dqmStore_->book1D(histo, histo, 100, 0, 200);
00127     EBHighInterestPayload_->setAxisTitle("event size (kB)",1);
00128 
00129     sprintf(histo, "EBSRT low interest payload");
00130     EBLowInterestPayload_ =  dqmStore_->book1D(histo, histo, 100, 0, 200);
00131     EBLowInterestPayload_->setAxisTitle("event size (kB)",1);
00132 
00133   }
00134 
00135 }
00136 
00137 void EBSelectiveReadoutTask::cleanup(void){
00138 
00139   if ( ! init_ ) return;
00140 
00141   if ( dqmStore_ ) {
00142     dqmStore_->setCurrentFolder(prefixME_ + "/EBSelectiveReadoutTask");
00143 
00144     if ( EBDccEventSize_ ) dqmStore_->removeElement( EBDccEventSize_->getName() );
00145     EBDccEventSize_ = 0;
00146 
00147     if ( EBReadoutUnitForcedBitMap_ ) dqmStore_->removeElement( EBReadoutUnitForcedBitMap_->getName() );
00148     EBReadoutUnitForcedBitMap_ = 0;
00149 
00150     if ( EBFullReadoutSRFlagMap_ ) dqmStore_->removeElement( EBFullReadoutSRFlagMap_->getName() );
00151     EBFullReadoutSRFlagMap_ = 0;
00152 
00153     if ( EBHighInterestTriggerTowerFlagMap_ ) dqmStore_->removeElement( EBHighInterestTriggerTowerFlagMap_->getName() );
00154     EBHighInterestTriggerTowerFlagMap_ = 0;
00155 
00156     if ( EBLowInterestTriggerTowerFlagMap_ ) dqmStore_->removeElement( EBLowInterestTriggerTowerFlagMap_->getName() );
00157     EBLowInterestTriggerTowerFlagMap_ = 0;
00158 
00159     if ( EBEventSize_ ) dqmStore_->removeElement( EBEventSize_->getName() );
00160     EBEventSize_ = 0;
00161 
00162     if ( EBHighInterestPayload_ ) dqmStore_->removeElement( EBHighInterestPayload_->getName() );
00163     EBHighInterestPayload_ = 0;
00164 
00165     if ( EBLowInterestPayload_ ) dqmStore_->removeElement( EBLowInterestPayload_->getName() );
00166     EBLowInterestPayload_ = 0;
00167 
00168   }
00169 
00170   init_ = false;
00171 
00172 }
00173 
00174 void EBSelectiveReadoutTask::endJob(void){
00175 
00176   LogInfo("EBSelectiveReadoutTask") << "analyzed " << ievt_ << " events";
00177 
00178   if ( enableCleanup_ ) this->cleanup();
00179 
00180 }
00181 
00182 void EBSelectiveReadoutTask::beginRun(const Run& r, const EventSetup& c) {
00183 
00184   if ( ! mergeRuns_ ) this->reset();
00185 
00186 }
00187 
00188 void EBSelectiveReadoutTask::endRun(const Run& r, const EventSetup& c) {
00189 
00190 }
00191 
00192 void EBSelectiveReadoutTask::reset(void) {
00193 
00194   if ( EBDccEventSize_ ) EBDccEventSize_->Reset();
00195 
00196   if ( EBReadoutUnitForcedBitMap_ ) EBReadoutUnitForcedBitMap_->Reset();
00197 
00198   if ( EBFullReadoutSRFlagMap_ ) EBFullReadoutSRFlagMap_->Reset();
00199 
00200   if ( EBHighInterestTriggerTowerFlagMap_ ) EBHighInterestTriggerTowerFlagMap_->Reset();
00201 
00202   if ( EBLowInterestTriggerTowerFlagMap_ ) EBLowInterestTriggerTowerFlagMap_->Reset();
00203 
00204   if ( EBEventSize_ ) EBEventSize_->Reset();
00205 
00206   if ( EBHighInterestPayload_ ) EBHighInterestPayload_->Reset();
00207 
00208   if ( EBLowInterestPayload_ ) EBLowInterestPayload_->Reset();
00209 
00210 }
00211 
00212 void EBSelectiveReadoutTask::analyze(const Event& e, const EventSetup& c){
00213 
00214   if ( ! init_ ) this->setup();
00215 
00216   ievt_++;
00217 
00218   Handle<FEDRawDataCollection> raw;
00219   if ( e.getByLabel(FEDRawDataCollection_, raw) ) {
00220 
00221     for ( int iDcc = 0; iDcc < nEBDcc; ++iDcc ) {
00222 
00223       EBDccEventSize_->Fill(iDcc+1, ((double)raw->FEDData(610+iDcc).size())/kByte );
00224 
00225     }
00226 
00227   } else {
00228     LogWarning("EBSelectiveReadoutTask") << FEDRawDataCollection_ << " not available";
00229   }
00230   
00231   TH2F *h01 = UtilsClient::getHisto<TH2F*>( EBFullReadoutSRFlagMap_ );
00232   float integral01 = h01->GetEntries();
00233   if( integral01 != 0 ) h01->Scale( integral01 );
00234 
00235   TH2F *h02 = UtilsClient::getHisto<TH2F*>( EBReadoutUnitForcedBitMap_ );
00236   float integral02 = h02->GetEntries();
00237   if( integral02 != 0 ) h02->Scale( integral02 );
00238 
00239   // Selective Readout Flags
00240   Handle<EBSrFlagCollection> ebSrFlags;
00241   if ( e.getByLabel(EBSRFlagCollection_,ebSrFlags) ) {
00242 
00243     for ( EBSrFlagCollection::const_iterator it = ebSrFlags->begin(); it != ebSrFlags->end(); ++it ) {
00244 
00245       int iet = it->id().ieta();
00246       int ipt = it->id().iphi();
00247 
00248       float xiet = (iet>0) ? iet-0.5 : iet+0.5 ;
00249       float xipt = ipt-0.5;
00250 
00251       int flag = it->value() & ~EcalSrFlag::SRF_FORCED_MASK;
00252 
00253       if(flag == EcalSrFlag::SRF_FULL){
00254         EBFullReadoutSRFlagMap_->Fill(xipt,xiet);
00255       } else {
00256         EBFullReadoutSRFlagMap_->Fill(-1,-18);
00257       }
00258 
00259       if(it->value() & EcalSrFlag::SRF_FORCED_MASK){
00260         EBReadoutUnitForcedBitMap_->Fill(xipt,xiet);
00261       } else {
00262         EBReadoutUnitForcedBitMap_->Fill(-1,-18);
00263       }
00264       
00265     }
00266   } else {
00267     LogWarning("EBSelectiveReadoutTask") << EBSRFlagCollection_ << " not available";
00268   }
00269 
00270   integral01 = h01->GetEntries();
00271   if( integral01 != 0 ) h01->Scale( 1.0/integral01 );
00272   integral02 = h02->GetEntries();
00273   if( integral02 != 0 ) h02->Scale( 1.0/integral02 );
00274 
00275   TH2F *h03 = UtilsClient::getHisto<TH2F*>( EBLowInterestTriggerTowerFlagMap_ );
00276   float integral03 = h03->GetEntries();
00277   if( integral03 != 0 ) h03->Scale( integral03 );
00278 
00279   TH2F *h04 = UtilsClient::getHisto<TH2F*>( EBHighInterestTriggerTowerFlagMap_ );
00280   float integral04 = h04->GetEntries();
00281   if( integral04 != 0 ) h04->Scale( integral04 );
00282 
00283   Handle<EcalTrigPrimDigiCollection> TPCollection;
00284   if ( e.getByLabel(EcalTrigPrimDigiCollection_, TPCollection) ) {
00285 
00286     // Trigger Primitives
00287     EcalTrigPrimDigiCollection::const_iterator TPdigi;
00288     for (TPdigi = TPCollection->begin(); TPdigi != TPCollection->end(); ++TPdigi ) {
00289 
00290       if ( Numbers::subDet( TPdigi->id() ) != EcalBarrel ) continue;
00291 
00292       int iet = TPdigi->id().ieta();
00293       int ipt = TPdigi->id().iphi();
00294 
00295       float xiet = (iet>0) ? iet-0.5 : iet+0.5 ;
00296       float xipt = ipt-0.5;
00297 
00298       if ( (TPdigi->ttFlag() & 0x3) == 0 ) {
00299         EBLowInterestTriggerTowerFlagMap_->Fill(xipt,xiet);
00300       } else {
00301         EBLowInterestTriggerTowerFlagMap_->Fill(-1,-18);
00302       }
00303 
00304       if ( (TPdigi->ttFlag() & 0x3) == 3 ) {
00305         EBHighInterestTriggerTowerFlagMap_->Fill(xipt,xiet);
00306       } else {
00307         EBHighInterestTriggerTowerFlagMap_->Fill(-1,-18);
00308       }
00309 
00310     }
00311   } else {
00312     LogWarning("EBSelectiveReadoutTask") << EcalTrigPrimDigiCollection_ << " not available";
00313   }
00314 
00315   integral03 = h03->GetEntries();
00316   if( integral03 != 0 ) h03->Scale( 1.0/integral03 );
00317   integral04 = h04->GetEntries();
00318   if( integral04 != 0 ) h04->Scale( 1.0/integral04 );
00319 
00320   if (!ebSrFlags.isValid()) return;
00321 
00322   // Data Volume
00323   double aLowInterest=0;
00324   double aHighInterest=0;
00325   double aAnyInterest=0;
00326 
00327   Handle<EBDigiCollection> ebDigis;
00328   if ( e.getByLabel(EBDigiCollection_ , ebDigis) ) {
00329 
00330     anaDigiInit();
00331 
00332     for (unsigned int digis=0; digis<ebDigis->size(); ++digis){
00333       EBDataFrame ebdf = (*ebDigis)[digis];
00334       anaDigi(ebdf, *ebSrFlags);
00335     }
00336 
00337     //low interest channels:
00338     aLowInterest = nEbLI_*bytesPerCrystal/kByte;
00339     EBLowInterestPayload_->Fill(aLowInterest);
00340 
00341     //low interest channels:
00342     aHighInterest = nEbHI_*bytesPerCrystal/kByte;
00343     EBHighInterestPayload_->Fill(aHighInterest);
00344 
00345     //any-interest channels:
00346     aAnyInterest = getEbEventSize(nEb_)/kByte;
00347     EBEventSize_->Fill(aAnyInterest);
00348 
00349   } else {
00350     LogWarning("EBSelectiveReadoutTask") << EBDigiCollection_ << " not available";
00351   }
00352 
00353 }
00354 
00355 void EBSelectiveReadoutTask::anaDigi(const EBDataFrame& frame, const EBSrFlagCollection& srFlagColl){
00356 
00357   EBDetId id = frame.id();
00358   EBSrFlagCollection::const_iterator srf = srFlagColl.find(readOutUnitOf(id));
00359 
00360   if(srf == srFlagColl.end()){
00361     // LogWarning("EBSelectiveReadoutTask") << "SR flag not found";
00362     return;
00363   }
00364 
00365   bool highInterest = ((srf->value() & ~EcalSrFlag::SRF_FORCED_MASK)
00366                        == EcalSrFlag::SRF_FULL);
00367 
00368   bool barrel = (id.subdetId()==EcalBarrel);
00369 
00370   if(barrel){
00371     ++nEb_;
00372     if(highInterest){
00373       ++nEbHI_;
00374     } else{//low interest
00375       ++nEbLI_;
00376     }
00377     int iEta0 = iEta2cIndex(id.ieta());
00378     int iPhi0 = iPhi2cIndex(id.iphi());
00379     if(!ebRuActive_[iEta0/ebTtEdge][iPhi0/ebTtEdge]){
00380       ++nRuPerDcc_[dccNum(id)-1];
00381       ebRuActive_[iEta0/ebTtEdge][iPhi0/ebTtEdge] = true;
00382     }
00383   }
00384 
00385   ++nPerDcc_[dccNum(id)-1];
00386 }
00387 
00388 void EBSelectiveReadoutTask::anaDigiInit(){
00389   nEb_ = 0;
00390   nEbLI_ = 0;
00391   nEbHI_ = 0;
00392   bzero(nPerDcc_, sizeof(nPerDcc_));
00393   bzero(nRuPerDcc_, sizeof(nRuPerDcc_));
00394   bzero(ebRuActive_, sizeof(ebRuActive_));
00395 }
00396 
00397 EcalTrigTowerDetId
00398 EBSelectiveReadoutTask::readOutUnitOf(const EBDetId& xtalId) const{
00399   return xtalId.tower();
00400 }
00401 
00402 unsigned EBSelectiveReadoutTask::dccNum(const DetId& xtalId) const{
00403   int j;
00404   int k;
00405 
00406   if ( xtalId.det()!=DetId::Ecal ) {
00407     throw cms::Exception("EBSelectiveReadoutTask") << "Crystal does not belong to ECAL";
00408   }
00409 
00410   if(xtalId.subdetId()==EcalBarrel){
00411     EBDetId ebDetId(xtalId);
00412     j = iEta2cIndex(ebDetId.ieta());
00413     k = iPhi2cIndex(ebDetId.iphi());
00414   } else {
00415     throw cms::Exception("EBSelectiveReadoutTask")
00416       <<"Not ECAL barrel.";
00417   }
00418   int iDcc0 = dccIndex(j,k);
00419   assert(iDcc0>=0 && iDcc0<nECALDcc);
00420   return iDcc0+1;
00421 }
00422 
00423 double EBSelectiveReadoutTask::getEbEventSize(double nReadXtals) const{
00424   double ruHeaderPayload = 0.;
00425   const int nEEDcc = 18;
00426   const int firstEbDcc0 = nEEDcc/2;
00427   for (int iDcc0 = firstEbDcc0; iDcc0 < firstEbDcc0 + nEBDcc; ++iDcc0 ) {
00428     ruHeaderPayload += nRuPerDcc_[iDcc0]*8.;
00429   }
00430   return getDccOverhead(EB)*nEBDcc + nReadXtals*bytesPerCrystal
00431     + ruHeaderPayload;
00432 }
00433 
00434 int EBSelectiveReadoutTask::dccPhiIndexOfRU(int i, int j) const {
00435   //iEta=i, iPhi=j
00436   //phi edge of a SM is 4 TT
00437   return j/4;
00438 }
00439 
00440 int EBSelectiveReadoutTask::dccIndex(int i, int j) const {
00441     //a SM is 85 crystal long:
00442     int iEtaSM = i/85;
00443     //a SM is 20 crystal wide:
00444     int iPhiSM = j/20;
00445     //DCC numbers start at 9 in the barrel and there 18 DCC/SM
00446     return 9+18*iEtaSM+iPhiSM;
00447 }
00448 

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