Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-29 23:10:22

0001 #include "DQMOffline/Hcal/interface/CaloTowersDQMClient.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/Run.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 
0008 #include "DQMServices/Core/interface/DQMStore.h"
0009 
0010 CaloTowersDQMClient::CaloTowersDQMClient(const edm::ParameterSet &iConfig) : conf_(iConfig) {
0011   outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile", "myfile.root");
0012   debug_ = false;
0013   verbose_ = false;
0014   dirName_ = iConfig.getParameter<std::string>("DQMDirName");
0015 }
0016 
0017 CaloTowersDQMClient::~CaloTowersDQMClient() {}
0018 
0019 void CaloTowersDQMClient::beginJob() {}
0020 
0021 void CaloTowersDQMClient::beginRun(const edm::Run &run, const edm::EventSetup &c) {}
0022 
0023 // called after entering the CaloTowersD/CaloTowersTask directory
0024 // hcalMEs are within that directory
0025 int CaloTowersDQMClient::CaloTowersEndjob(const std::vector<MonitorElement *> &hcalMEs) {
0026   int useAllHistos = 0;
0027   MonitorElement *Ntowers_vs_ieta = nullptr;
0028   MonitorElement *mapEnergy_N = nullptr, *mapEnergy_E = nullptr, *mapEnergy_H = nullptr, *mapEnergy_EH = nullptr;
0029   MonitorElement *occupancy_map = nullptr, *occupancy_vs_ieta = nullptr;
0030   for (unsigned int ih = 0; ih < hcalMEs.size(); ih++) {
0031     if (strcmp(hcalMEs[ih]->getName().c_str(), "Ntowers_per_event_vs_ieta") == 0) {
0032       Ntowers_vs_ieta = hcalMEs[ih];
0033     }
0034     if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_Nentries") == 0) {
0035       mapEnergy_N = hcalMEs[ih];
0036     }
0037     if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_energy_H") == 0) {
0038       useAllHistos++;
0039       mapEnergy_H = hcalMEs[ih];
0040     }
0041     if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_energy_E") == 0) {
0042       useAllHistos++;
0043       mapEnergy_E = hcalMEs[ih];
0044     }
0045     if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_energy_EH") == 0) {
0046       useAllHistos++;
0047       mapEnergy_EH = hcalMEs[ih];
0048     }
0049     if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_occupancy") == 0) {
0050       occupancy_map = hcalMEs[ih];
0051     }
0052     if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_occupancy_vs_ieta") == 0) {
0053       occupancy_vs_ieta = hcalMEs[ih];
0054     }
0055   }
0056   if (useAllHistos != 0 && useAllHistos != 3)
0057     return 0;
0058 
0059   double nevent = mapEnergy_N->getEntries();
0060   if (verbose_)
0061     std::cout << "nevent : " << nevent << std::endl;
0062 
0063   // mean number of towers per ieta
0064   int nx = Ntowers_vs_ieta->getNbinsX();
0065   float cont;
0066   float conte;
0067   float fev = float(nevent);
0068 
0069   for (int i = 1; i <= nx; i++) {
0070     cont = Ntowers_vs_ieta->getBinContent(i) / fev;
0071     conte = pow(Ntowers_vs_ieta->getBinContent(i), 0.5) / fev;
0072     Ntowers_vs_ieta->setBinContent(i, cont);
0073     Ntowers_vs_ieta->setBinError(i, conte);
0074   }
0075 
0076   // mean energies & occupancies evaluation
0077 
0078   nx = mapEnergy_N->getNbinsX();
0079   int ny = mapEnergy_N->getNbinsY();
0080   float cnorm;
0081   float cnorme;
0082   float phi_factor;
0083 
0084   for (int i = 1; i <= nx; i++) {
0085     float sumphi = 0.;
0086 
0087     for (int j = 1; j <= ny; j++) {
0088       // Emean
0089       cnorm = mapEnergy_N->getBinContent(i, j);
0090       // Phi histos are not used in the macros
0091       if (cnorm > 0.000001 && useAllHistos) {
0092         cont = mapEnergy_E->getBinContent(i, j) / cnorm;
0093         conte = mapEnergy_E->getBinError(i, j) / cnorm;
0094         mapEnergy_E->setBinContent(i, j, cont);
0095         mapEnergy_E->setBinError(i, j, conte);
0096 
0097         cont = mapEnergy_H->getBinContent(i, j) / cnorm;
0098         conte = mapEnergy_H->getBinError(i, j) / cnorm;
0099         mapEnergy_H->setBinContent(i, j, cont);
0100         mapEnergy_H->setBinError(i, j, conte);
0101 
0102         cont = mapEnergy_EH->getBinContent(i, j) / cnorm;
0103         conte = mapEnergy_EH->getBinError(i, j) / cnorm;
0104         mapEnergy_EH->setBinContent(i, j, cont);
0105         mapEnergy_EH->setBinError(i, j, conte);
0106       }
0107 
0108       // Occupancy (needed for occupancy vs ieta)
0109       cont = occupancy_map->getBinContent(i, j);
0110       conte = occupancy_map->getBinError(i, j);
0111       if (fev > 0. && cnorm > 1.e-30) {
0112         occupancy_map->setBinContent(i, j, cont / fev);
0113         occupancy_map->setBinError(i, j, conte / fev);
0114       }
0115 
0116       sumphi += cont;
0117 
0118     }  // end of iphy cycle (j)
0119 
0120     // Occupancy vs ieta histo is drawn
0121     // phi-factor evaluation for occupancy_vs_ieta calculation
0122     int ieta = i - 43;  // should be the same as int ieta =
0123                         // int(occupancy_vs_ieta->getBinCenter(i));
0124 
0125     if (ieta >= -20 && ieta <= 20) {
0126       phi_factor = 72.;
0127     } else {
0128       if (ieta >= 40 || ieta <= -40) {
0129         phi_factor = 18.;
0130       } else
0131         phi_factor = 36.;
0132     }
0133 
0134     cnorm = sumphi / phi_factor;
0135     cnorme = pow(sumphi, 0.5) / phi_factor;
0136     if (fev > 0. && cnorm > 1.e-30) {
0137       occupancy_vs_ieta->setBinContent(i, cnorm / fev);
0138       occupancy_vs_ieta->setBinError(i, cnorme / fev);
0139     }
0140 
0141   }  // end of ieta cycle (i)
0142 
0143   return 1;
0144 }
0145 
0146 void CaloTowersDQMClient::dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) {
0147   igetter.setCurrentFolder(dirName_);
0148   if (verbose_)
0149     std::cout << "\nrunClient" << std::endl;
0150 
0151   std::vector<MonitorElement *> hcalMEs;
0152 
0153   // Since out folders are fixed to three, we can just go over these three
0154   // folders i.e., CaloTowersD/CaloTowersTask, HcalRecHitsD/HcalRecHitTask,
0155   // NoiseRatesV/NoiseRatesTask.
0156   std::vector<std::string> fullPathHLTFolders = igetter.getSubdirs();
0157   for (unsigned int i = 0; i < fullPathHLTFolders.size(); i++) {
0158     if (verbose_)
0159       std::cout << "\nfullPath: " << fullPathHLTFolders[i] << std::endl;
0160     igetter.setCurrentFolder(fullPathHLTFolders[i]);
0161 
0162     std::vector<std::string> fullSubPathHLTFolders = igetter.getSubdirs();
0163     for (unsigned int j = 0; j < fullSubPathHLTFolders.size(); j++) {
0164       if (verbose_)
0165         std::cout << "fullSub: " << fullSubPathHLTFolders[j] << std::endl;
0166 
0167       if (strcmp(fullSubPathHLTFolders[j].c_str(), "CaloTowersD/CaloTowersTask") == 0) {
0168         hcalMEs = igetter.getContents(fullSubPathHLTFolders[j]);
0169         if (verbose_)
0170           std::cout << "hltMES size : " << hcalMEs.size() << std::endl;
0171         if (!CaloTowersEndjob(hcalMEs))
0172           std::cout << "\nError in CaloTowersEndjob!" << std::endl << std::endl;
0173       }
0174     }
0175   }
0176 }
0177 
0178 DEFINE_FWK_MODULE(CaloTowersDQMClient);