File indexing completed on 2024-10-25 05:06:29
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
0024
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
0057
0058 assert(Ntowers_vs_ieta);
0059 assert(mapEnergy_N);
0060 assert(occupancy_map);
0061 assert(occupancy_vs_ieta);
0062
0063 if (useAllHistos != 0 && useAllHistos != 3)
0064 return 0;
0065
0066 double nevent = mapEnergy_N->getEntries();
0067 if (verbose_)
0068 std::cout << "nevent : " << nevent << std::endl;
0069
0070
0071 int nx = Ntowers_vs_ieta->getNbinsX();
0072 float cont;
0073 float conte;
0074 float fev = float(nevent);
0075
0076 for (int i = 1; i <= nx; i++) {
0077 cont = Ntowers_vs_ieta->getBinContent(i) / fev;
0078 conte = pow(Ntowers_vs_ieta->getBinContent(i), 0.5) / fev;
0079 Ntowers_vs_ieta->setBinContent(i, cont);
0080 Ntowers_vs_ieta->setBinError(i, conte);
0081 }
0082
0083
0084
0085 nx = mapEnergy_N->getNbinsX();
0086 int ny = mapEnergy_N->getNbinsY();
0087 float cnorm;
0088 float cnorme;
0089 float phi_factor;
0090
0091 for (int i = 1; i <= nx; i++) {
0092 float sumphi = 0.;
0093
0094 for (int j = 1; j <= ny; j++) {
0095
0096 cnorm = mapEnergy_N->getBinContent(i, j);
0097
0098 if (cnorm > 0.000001 && useAllHistos) {
0099 cont = mapEnergy_E->getBinContent(i, j) / cnorm;
0100 conte = mapEnergy_E->getBinError(i, j) / cnorm;
0101 mapEnergy_E->setBinContent(i, j, cont);
0102 mapEnergy_E->setBinError(i, j, conte);
0103
0104 cont = mapEnergy_H->getBinContent(i, j) / cnorm;
0105 conte = mapEnergy_H->getBinError(i, j) / cnorm;
0106 mapEnergy_H->setBinContent(i, j, cont);
0107 mapEnergy_H->setBinError(i, j, conte);
0108
0109 cont = mapEnergy_EH->getBinContent(i, j) / cnorm;
0110 conte = mapEnergy_EH->getBinError(i, j) / cnorm;
0111 mapEnergy_EH->setBinContent(i, j, cont);
0112 mapEnergy_EH->setBinError(i, j, conte);
0113 }
0114
0115
0116 cont = occupancy_map->getBinContent(i, j);
0117 conte = occupancy_map->getBinError(i, j);
0118 if (fev > 0. && cnorm > 1.e-30) {
0119 occupancy_map->setBinContent(i, j, cont / fev);
0120 occupancy_map->setBinError(i, j, conte / fev);
0121 }
0122
0123 sumphi += cont;
0124
0125 }
0126
0127
0128
0129 int ieta = i - 43;
0130
0131
0132 if (ieta >= -20 && ieta <= 20) {
0133 phi_factor = 72.;
0134 } else {
0135 if (ieta >= 40 || ieta <= -40) {
0136 phi_factor = 18.;
0137 } else
0138 phi_factor = 36.;
0139 }
0140
0141 cnorm = sumphi / phi_factor;
0142 cnorme = pow(sumphi, 0.5) / phi_factor;
0143 if (fev > 0. && cnorm > 1.e-30) {
0144 occupancy_vs_ieta->setBinContent(i, cnorm / fev);
0145 occupancy_vs_ieta->setBinError(i, cnorme / fev);
0146 }
0147
0148 }
0149
0150 return 1;
0151 }
0152
0153 void CaloTowersDQMClient::dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) {
0154 igetter.setCurrentFolder(dirName_);
0155 if (verbose_)
0156 std::cout << "\nrunClient" << std::endl;
0157
0158 std::vector<MonitorElement *> hcalMEs;
0159
0160
0161
0162
0163 std::vector<std::string> fullPathHLTFolders = igetter.getSubdirs();
0164 for (unsigned int i = 0; i < fullPathHLTFolders.size(); i++) {
0165 if (verbose_)
0166 std::cout << "\nfullPath: " << fullPathHLTFolders[i] << std::endl;
0167 igetter.setCurrentFolder(fullPathHLTFolders[i]);
0168
0169 std::vector<std::string> fullSubPathHLTFolders = igetter.getSubdirs();
0170 for (unsigned int j = 0; j < fullSubPathHLTFolders.size(); j++) {
0171 if (verbose_)
0172 std::cout << "fullSub: " << fullSubPathHLTFolders[j] << std::endl;
0173
0174 if (strcmp(fullSubPathHLTFolders[j].c_str(), "CaloTowersD/CaloTowersTask") == 0) {
0175 hcalMEs = igetter.getContents(fullSubPathHLTFolders[j]);
0176 if (verbose_)
0177 std::cout << "hltMES size : " << hcalMEs.size() << std::endl;
0178 if (!CaloTowersEndjob(hcalMEs))
0179 std::cout << "\nError in CaloTowersEndjob!" << std::endl << std::endl;
0180 }
0181 }
0182 }
0183 }
0184
0185 DEFINE_FWK_MODULE(CaloTowersDQMClient);