CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DQMOffline/Hcal/src/CaloTowersDQMClient.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Hcal/interface/CaloTowersDQMClient.h"
00002 #include "FWCore/Framework/interface/MakerMacros.h"
00003 
00004 #include "FWCore/Framework/interface/Run.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 
00012 CaloTowersDQMClient::CaloTowersDQMClient(const edm::ParameterSet& iConfig):conf_(iConfig)
00013 {
00014 
00015   outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile", "myfile.root");
00016 
00017   dbe_ = edm::Service<DQMStore>().operator->();
00018   if (!dbe_) {
00019     edm::LogError("CaloTowersDQMClient") << "unable to get DQMStore service, upshot is no client histograms will be made";
00020   }
00021   if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00022     if(dbe_) dbe_->setVerbose(0);
00023   }
00024  
00025   debug_ = false;
00026   verbose_ = false;
00027 
00028   dirName_=iConfig.getParameter<std::string>("DQMDirName");
00029   if(dbe_) dbe_->setCurrentFolder(dirName_);
00030  
00031 }
00032 
00033 
00034 CaloTowersDQMClient::~CaloTowersDQMClient()
00035 { 
00036   
00037 }
00038 
00039 void CaloTowersDQMClient::beginJob()
00040 {
00041  
00042 
00043 }
00044 
00045 void CaloTowersDQMClient::endJob() 
00046 {
00047    if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
00048 }
00049 
00050 void CaloTowersDQMClient::beginRun(const edm::Run& run, const edm::EventSetup& c)
00051 {
00052  
00053 }
00054 
00055 
00056 void CaloTowersDQMClient::endRun(const edm::Run& run, const edm::EventSetup& c)
00057 {
00058   runClient_();
00059 }
00060 
00061 //dummy analysis function
00062 void CaloTowersDQMClient::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00063 {
00064   
00065 }
00066 
00067 void CaloTowersDQMClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c)
00068 { 
00069 //  runClient_();
00070 }
00071 
00072 void CaloTowersDQMClient::runClient_()
00073 {
00074   if(!dbe_) return; //we dont have the DQMStore so we cant do anything
00075   dbe_->setCurrentFolder(dirName_);
00076 
00077   if (verbose_) std::cout << "\nrunClient" << std::endl; 
00078 
00079   std::vector<MonitorElement*> hcalMEs;
00080 
00081   // Since out folders are fixed to three, we can just go over these three folders
00082   // i.e., CaloTowersV/CaloTowersTask, HcalRecHitsV/HcalRecHitTask, NoiseRatesV/NoiseRatesTask.
00083   std::vector<std::string> fullPathHLTFolders = dbe_->getSubdirs();
00084   for(unsigned int i=0;i<fullPathHLTFolders.size();i++) {
00085 
00086     if (verbose_) std::cout <<"\nfullPath: "<< fullPathHLTFolders[i] << std::endl;
00087     dbe_->setCurrentFolder(fullPathHLTFolders[i]);
00088 
00089     std::vector<std::string> fullSubPathHLTFolders = dbe_->getSubdirs();
00090     for(unsigned int j=0;j<fullSubPathHLTFolders.size();j++) {
00091 
00092       if (verbose_) std::cout <<"fullSub: "<<fullSubPathHLTFolders[j] << std::endl;
00093 
00094       if( strcmp(fullSubPathHLTFolders[j].c_str(), "CaloTowersV/CaloTowersTask") ==0  ){
00095          hcalMEs = dbe_->getContents(fullSubPathHLTFolders[j]);
00096          if (verbose_) std::cout <<"hltMES size : "<<hcalMEs.size()<<std::endl;
00097          if( !CaloTowersEndjob(hcalMEs) ) std::cout<<"\nError in CaloTowersEndjob!"<<std::endl<<std::endl;
00098       }
00099 
00100     }    
00101 
00102   }
00103 
00104 }
00105 
00106 // called after entering the CaloTowersV/CaloTowersTask directory
00107 // hcalMEs are within that directory
00108 int CaloTowersDQMClient::CaloTowersEndjob(const std::vector<MonitorElement*> &hcalMEs){
00109 
00110    int useAllHistos = 0;
00111    MonitorElement* Ntowers_vs_ieta =0;
00112    MonitorElement* mapEnergy_N =0, *mapEnergy_E =0, *mapEnergy_H =0, *mapEnergy_EH =0;
00113    MonitorElement* occupancy_map =0, *occupancy_vs_ieta =0;
00114    for(unsigned int ih=0; ih<hcalMEs.size(); ih++){
00115       if( strcmp(hcalMEs[ih]->getName().c_str(), "Ntowers_per_event_vs_ieta") ==0  ){
00116          Ntowers_vs_ieta = hcalMEs[ih];
00117       } 
00118       if( strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_Nentries") ==0  ){
00119          mapEnergy_N = hcalMEs[ih];
00120       }
00121       if( strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_energy_H") ==0  ){
00122          useAllHistos++; mapEnergy_H = hcalMEs[ih];
00123       }
00124       if( strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_energy_E") ==0  ){
00125          useAllHistos++; mapEnergy_E = hcalMEs[ih];
00126       }
00127       if( strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_energy_EH") ==0  ){
00128          useAllHistos++; mapEnergy_EH = hcalMEs[ih];
00129       }
00130       if( strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_occupancy") ==0  ){
00131          occupancy_map = hcalMEs[ih];
00132       }
00133       if( strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_occupancy_vs_ieta") ==0  ){
00134          occupancy_vs_ieta = hcalMEs[ih];
00135       }
00136   
00137    } 
00138    if( useAllHistos !=0 && useAllHistos !=3 ) return 0;
00139 
00140    double nevent = mapEnergy_N->getEntries();
00141    if(verbose_) std::cout<<"nevent : "<<nevent<<std::endl;
00142 
00143    // mean number of towers per ieta
00144    int nx = Ntowers_vs_ieta->getNbinsX();
00145    float cont;
00146    float fev = float(nevent);
00147 
00148    for (int i = 1; i <= nx; i++) {
00149       cont = Ntowers_vs_ieta -> getBinContent(i) / fev ;
00150       Ntowers_vs_ieta -> setBinContent(i,cont);
00151    }
00152 
00153    // mean energies & occupancies evaluation
00154 
00155    nx = mapEnergy_N->getNbinsX();
00156    int ny = mapEnergy_N->getNbinsY();
00157    float cnorm;
00158    float phi_factor;
00159 
00160    for (int i = 1; i <= nx; i++) {
00161       float sumphi = 0.;
00162 
00163       for (int j = 1; j <= ny; j++) {
00164 
00165          // Emean
00166          cnorm   = mapEnergy_N -> getBinContent(i,j);
00167          //Phi histos are not used in the macros
00168          if(cnorm > 0.000001 && useAllHistos) {
00169 
00170             cont = mapEnergy_E -> getBinContent(i,j) / cnorm ;
00171             mapEnergy_E -> setBinContent(i,j,cont);
00172 
00173             cont = mapEnergy_H -> getBinContent(i,j) / cnorm ;
00174             mapEnergy_H -> setBinContent(i,j,cont);
00175 
00176             cont = mapEnergy_EH -> getBinContent(i,j) / cnorm ;
00177             mapEnergy_EH -> setBinContent(i,j,cont);
00178          }
00179 
00180          // Occupancy (needed for occupancy vs ieta)
00181          cnorm   = occupancy_map -> getBinContent(i,j) / fev;
00182          if(cnorm > 1.e-30) occupancy_map -> setBinContent(i,j,cnorm);
00183 
00184          sumphi += cnorm;
00185 
00186       } // end of iphy cycle (j)
00187 
00188       //Occupancy vs ieta histo is drawn
00189       // phi-factor evaluation for occupancy_vs_ieta calculation
00190       int ieta = i - 42;        // -41 -1, 0 40 
00191       if(ieta >=0 ) ieta +=1;   // -41 -1, 1 41  - to make it detector-like
00192 
00193       if(ieta >= -20 && ieta <= 20 )
00194          {phi_factor = 72.;}
00195          else {
00196             if(ieta >= 40 || ieta <= -40 ) {phi_factor = 18.;}
00197          else
00198             phi_factor = 36.;
00199        }
00200        if(ieta >= 0) ieta -= 1; // -41 -1, 0 40  - to bring back to histo num
00201 
00202        cnorm = sumphi / phi_factor;
00203        occupancy_vs_ieta->Fill(double(ieta), cnorm);
00204 
00205    } // end of ieta cycle (i)
00206    
00207    return 1;
00208 
00209 }
00210 
00211 DEFINE_FWK_MODULE(CaloTowersDQMClient);