CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/CastorMonitor/src/CastorRecHitMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/CastorMonitor/interface/CastorRecHitMonitor.h"
00002 #include "DQMServices/Core/interface/DQMStore.h"
00003 #include "DQMServices/Core/interface/MonitorElement.h"
00004 
00005 //***************************************************//
00006 //********** CastorRecHitMonitor: *******************//
00007 //********** Author: Dmytro Volyanskyy   ************//
00008 //********** Date  : 23.09.2008 (first version) ******// 
00009 //***************************************************//
00012 
00013 //==================================================================//
00014 //======================= Constructor ==============================//
00015 //==================================================================//
00016 CastorRecHitMonitor::CastorRecHitMonitor() {
00017   doPerChannel_ = true;
00018   //  occThresh_ = 1;
00019   ievt_=0; 
00020 }
00021 
00022 //==================================================================//
00023 //======================= Destructor ==============================//
00024 //==================================================================//
00025 CastorRecHitMonitor::~CastorRecHitMonitor(){
00026 }
00027 
00028 void CastorRecHitMonitor::reset(){
00029 }
00030 
00031 
00032 //==========================================================//
00033 //========================= setup ==========================//
00034 //==========================================================//
00035 
00036 void CastorRecHitMonitor::setup(const edm::ParameterSet& ps, DQMStore* dbe){
00037   
00038   CastorBaseMonitor::setup(ps,dbe);
00039   baseFolder_ = rootFolder_+"CastorRecHitMonitor";
00040 
00041    if(fVerbosity>0) std::cout << "CastorRecHitMonitor::setup (start)" << std::endl;
00042   
00043   if ( ps.getUntrackedParameter<bool>("RecHitsPerChannel", false) ){
00044     doPerChannel_ = true;
00045   }
00046     
00047   ievt_=0; module=0; sector=0; zside=0; totEnergy=0.;
00048 
00049   
00051    for (int mod=0; mod<14; mod++){
00052      for (int sec=0; sec<16; sec++){
00053           energyInEachChannel[mod][sec] = 0.;
00054           allEnergyModule[mod]=0;
00055           allEnergySector[sec]=0;
00056       }
00057     }
00058   
00059   if ( m_dbe !=NULL ) {    
00060  m_dbe->setCurrentFolder(baseFolder_);
00062 meEVT_ = m_dbe->bookInt("RecHit Event Number"); // meEVT_->Fill(ievt_);
00064 castorHists.meRECHIT_E_all = m_dbe->book1D("CastorRecHit Energies- above threshold on RecHitEnergy","CastorRecHit Energies- above threshold on RecHitEnergy",150,0,150);
00065 castorHists.meRECHIT_T_all = m_dbe->book1D("CastorRecHit Times- above threshold on RecHitEnergy","CastorRecHit Times- above threshold on RecHitEnergy",300,-100,100);    
00067 castorHists.meRECHIT_MAP_CHAN_E = m_dbe->book1D("CastorRecHit Energy in each channel- above threshold","CastorRecHit Energy in each channel- above threshold",224,0,224);
00069 castorHists.meRECHIT_E_modules = m_dbe->book1D("CastorRecHit Energy in modules- above threshold","CastorRecHit Energy in modules- above threshold", 14, 0, 14);
00071 castorHists.meRECHIT_E_sectors = m_dbe->book1D("CastorRecHit Energy in sectors- above threshold","CastorRecHit Energy in sectors- above threshold", 16, 0, 16);
00072 
00074 castorHists.meRECHIT_N_modules = m_dbe->book1D("Number of CastorRecHits in modules- above threshold","Number of CastorRecHits in modules- above threshold", 14, 0, 14);
00076 castorHists.meRECHIT_N_sectors = m_dbe->book1D("Number of CastorRecHits in sectors- above threshold","Number of CastorRecHits in sectors- above threshold", 16, 0, 16);
00078 castorHists.meCastorRecHitsOccupancy = m_dbe->book2D("CastorRecHits Occupancy Map", "CastorRecHits Occupancy Map", 14, 0,14, 16, 0,16);
00080 castorHists.meRECHIT_N_event = m_dbe->book1D("Number of CASTOR RecHits per event- above threshold","Number of CASTOR RecHits per event- above threshold", 23, 0, 230);
00081 
00082  m_dbe->setCurrentFolder(baseFolder_+"/EnergyFraction");
00084 castorHists.meRECHIT_E_relative_modules = m_dbe->book1D("Fraction of the total energy in CASTOR modules","Fraction of the total energy in CASTOR modules", 14, 0, 14);
00086 castorHists.meRECHIT_E_relative_sectors = m_dbe->book1D("Fraction of the total energy in CASTOR sectors","Fraction of the total energy in CASTOR sectors", 16, 0, 16);
00087 /*
00088 castorHists.meRECHIT_E_relative_modules->getTH1F()->GetYaxis()->SetTitle("fraction of the total energy");
00089 castorHists.meRECHIT_E_relative_sectors->getTH1F()->GetYaxis()->SetTitle("fraction of the total energy");
00090  
00091    char ibin1[1024];
00092     for(int i=0; i<14; i++){
00093      sprintf(ibin1,"%i", i+1);
00094      castorHists.meRECHIT_E_relative_modules->getTH1F()->GetXaxis()->SetBinLabel(i+1,ibin1);
00095     }
00096    char ibin2[1024];
00097     for(int i=0; i<16; i++){
00098      sprintf(ibin2,"%i", i+1);
00099      castorHists.meRECHIT_E_relative_sectors->getTH1F()->GetXaxis()->SetBinLabel(i+1,ibin2);
00100     }
00101 */
00102 
00103   } 
00104 
00105 
00106 
00107   else{
00108   if(fVerbosity>0) std::cout << "CastorRecHitMonitor::setup - NO DQMStore service" << std::endl; 
00109  }
00110 
00111   if(fVerbosity>0) std::cout << "CastorRecHitMonitor::setup (end)" << std::endl;
00112 
00113   return;
00114 }
00115 
00116 //==========================================================//
00117 //=============== do histograms for every channel ==========//
00118 //==========================================================//
00119 
00120 namespace CastorRecHitPerChan{
00121 
00122   template<class RecHit>
00123 
00124   inline void perChanHists(const RecHit& rhit, 
00125                            std::map<HcalCastorDetId, MonitorElement*> &toolE, 
00126                            std::map<HcalCastorDetId, MonitorElement*> &toolT,
00127                            DQMStore* dbe, std::string baseFolder) {
00128     
00129     std::map<HcalCastorDetId,MonitorElement*>::iterator _mei;
00130 
00131     std::string type = "CastorRecHitPerChannel";
00132     if(dbe) dbe->setCurrentFolder(baseFolder+"/"+type);
00133     
00135     _mei=toolE.find(rhit.id()); //-- look for a histogram with this hit's id !!!
00136     if (_mei!=toolE.end()){
00137       if (_mei->second==0) return;
00138       else _mei->second->Fill(rhit.energy()); //-- if it's there, fill it with energy
00139     }
00140     else{
00141        if(dbe){
00142          char name[1024];
00143          sprintf(name,"CastorRecHit Energy zside=%d module=%d sector=%d", rhit.id().zside(), rhit.id().module(), rhit.id().sector());
00144          toolE[rhit.id()] =  dbe->book1D(name,name,60,-10,20); 
00145          toolE[rhit.id()]->Fill(rhit.energy());
00146       }
00147     }
00148     
00150     _mei=toolT.find(rhit.id()); //-- look for a histogram with this hit's id
00151     if (_mei!=toolT.end()){
00152       if (_mei->second==0) return;
00153       else _mei->second->Fill(rhit.time()); //-- if it's there, fill it with time
00154     }
00155     else{
00156       if(dbe){
00157         char name[1024];
00158         sprintf(name,"CastorRecHit Time zside=%d module=%d sector=%d", rhit.id().zside(), rhit.id().module(), rhit.id().sector());
00159         toolT[rhit.id()] =  dbe->book1D(name,name,200,-100,100); 
00160         toolT[rhit.id()]->Fill(rhit.time());
00161       }
00162     }
00163     
00164     
00165   }
00166 }
00167 
00168 //==========================================================//
00169 //================== processEvent ==========================//
00170 //==========================================================//
00171 
00172 void CastorRecHitMonitor::processEvent(const CastorRecHitCollection& castorHits ){
00173 
00174   if(fVerbosity>0) std::cout << "==>CastorRecHitMonitor::processEvent !!!"<< std::endl;
00175        
00176 
00178   ievt_++; totEnergy=0.;
00179 
00181    meEVT_->Fill(ievt_);
00182 
00183 
00184 
00185   if(!m_dbe) { 
00186     if(fVerbosity>0) std::cout <<"CastorRecHitMonitor::processEvent => DQMStore is not instantiated !!!"<<std::endl;  
00187     return; 
00188   }
00189 
00190   CastorRecHitCollection::const_iterator CASTORiter;
00191   if (showTiming)  { cpu_timer.reset(); cpu_timer.start(); } 
00192 
00193   //castorHists.meRECHIT_N_event->Fill(castorHits.size());
00194    int iHit=0;
00195 
00196      if(castorHits.size()>0)
00197     {    
00198        if(fVerbosity>0) std::cout << "==>CastorRecHitMonitor::processEvent: castorHits.size()>0 !!!" << std::endl; 
00199 
00201       for (CASTORiter=castorHits.begin(); CASTORiter!=castorHits.end(); ++CASTORiter) { 
00202   
00204       energy = CASTORiter->energy();    
00205       time = CASTORiter->time();
00206       
00208       HcalCastorDetId id(CASTORiter->detid().rawId());
00209       //float zside  = id.zside(); 
00210       module = (int)id.module(); //-- get module
00211       sector = (int)id.sector(); //-- get sector 
00212       channel = 16*(module-1)+sector; //-- define channel
00213 
00214       if (energy>0.) { 
00216       castorHists.meRECHIT_E_all->Fill(energy);
00217       castorHists.meRECHIT_T_all->Fill(time);
00219       castorHists.meRECHIT_MAP_CHAN_E->Fill(channel,energy);
00221       castorHists.meRECHIT_E_modules->Fill(module-1, energy);
00223       castorHists.meRECHIT_E_sectors->Fill(sector-1, energy);
00225       castorHists.meRECHIT_N_modules->Fill(module-1);
00227       castorHists.meRECHIT_N_sectors->Fill(sector-1);     
00228       iHit++;
00229      }
00230 
00232       if(energy<0) energy=0;
00233 
00235       energyInEachChannel[module-1][sector-1] += energy; 
00236      
00238       castorHists.meCastorRecHitsOccupancy->Fill(module-1,sector-1, energy); 
00239 
00241         castorHists.meRECHIT_N_event->Fill(iHit);
00242 
00244       if( doPerChannel_) 
00245          CastorRecHitPerChan::perChanHists<CastorRecHit>(*CASTORiter, castorHists.meRECHIT_E, castorHists.meRECHIT_T, m_dbe, baseFolder_); 
00246      }
00247 
00249       for(int mod=0; mod<14;mod++)
00250         for(int sec=0; sec<16;sec++)
00251           totEnergy+=energyInEachChannel[mod][sec];
00252 
00254        for(int mod=0; mod<14;mod++)
00255        allEnergyModule[mod]= energyInEachChannel[mod][0]+energyInEachChannel[mod][1]+energyInEachChannel[mod][2]+energyInEachChannel[mod][3]+
00256                           energyInEachChannel[mod][4]+energyInEachChannel[mod][5]+energyInEachChannel[mod][6]+energyInEachChannel[mod][7]+
00257                           energyInEachChannel[mod][8]+energyInEachChannel[mod][9]+energyInEachChannel[mod][10]+energyInEachChannel[mod][11]+
00258                            energyInEachChannel[mod][12]+energyInEachChannel[mod][13]+energyInEachChannel[mod][14]+energyInEachChannel[mod][15];
00259                          
00261        for(int sec=0; sec<16;sec++)
00262        allEnergySector[sec]= energyInEachChannel[0][sec]+energyInEachChannel[1][sec]+energyInEachChannel[2][sec]+energyInEachChannel[3][sec]+
00263                           energyInEachChannel[4][sec]+energyInEachChannel[5][sec]+energyInEachChannel[6][sec]+energyInEachChannel[7][sec]+
00264                           energyInEachChannel[8][sec]+energyInEachChannel[9][sec]+energyInEachChannel[10][sec]+energyInEachChannel[11][sec]+
00265                           energyInEachChannel[12][sec]+energyInEachChannel[13][sec];
00266 
00267 
00269        for(int mod=0; mod<14;mod++)
00270       castorHists.meRECHIT_E_relative_modules->getTH1F()->SetBinContent(mod+1,allEnergyModule[mod]/totEnergy);
00271       for(int sec=0; sec<16;sec++)
00272         castorHists.meRECHIT_E_relative_sectors->getTH1F()->SetBinContent(sec+1,allEnergySector[sec]/totEnergy); 
00273 
00274   
00275 
00276    }
00277 
00278   else { if(fVerbosity>0) std::cout<<"CastorRecHitMonitor::processEvent NO Castor RecHits !!!"<<std::endl; }
00279 
00280   if (showTiming) { 
00281       cpu_timer.stop(); std::cout << " TIMER::CastorRecHit -> " << cpu_timer.cpuTime() << std::endl; 
00282       cpu_timer.reset(); cpu_timer.start();  
00283     }
00284     
00285  
00286   return;
00287 }
00288 
00289