File indexing completed on 2024-10-08 05:12:06
0001 #include "Validation/CaloTowers/interface/CaloTowersClient.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003
0004 #include "FWCore/Framework/interface/Run.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008
0009 #include "DQMServices/Core/interface/DQMStore.h"
0010
0011 CaloTowersClient::CaloTowersClient(const edm::ParameterSet& iConfig) : conf_(iConfig) {
0012 outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile", "myfile.root");
0013
0014 debug_ = false;
0015 verbose_ = false;
0016 dirName_ = iConfig.getParameter<std::string>("DQMDirName");
0017 }
0018
0019 CaloTowersClient::~CaloTowersClient() {}
0020
0021 void CaloTowersClient::beginJob() {}
0022
0023 void CaloTowersClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0024 igetter.setCurrentFolder(dirName_);
0025
0026 if (verbose_)
0027 std::cout << "\nrunClient" << std::endl;
0028
0029 std::vector<MonitorElement*> hcalMEs;
0030
0031
0032
0033 std::vector<std::string> fullPathHLTFolders = igetter.getSubdirs();
0034 for (unsigned int i = 0; i < fullPathHLTFolders.size(); i++) {
0035 if (verbose_)
0036 std::cout << "\nfullPath: " << fullPathHLTFolders[i] << std::endl;
0037 igetter.setCurrentFolder(fullPathHLTFolders[i]);
0038
0039 std::vector<std::string> fullSubPathHLTFolders = igetter.getSubdirs();
0040 for (unsigned int j = 0; j < fullSubPathHLTFolders.size(); j++) {
0041 if (verbose_)
0042 std::cout << "fullSub: " << fullSubPathHLTFolders[j] << std::endl;
0043
0044 if (strcmp(fullSubPathHLTFolders[j].c_str(), "CaloTowersV/CaloTowersTask") == 0) {
0045 hcalMEs = igetter.getContents(fullSubPathHLTFolders[j]);
0046 if (verbose_)
0047 std::cout << "hltMES size : " << hcalMEs.size() << std::endl;
0048 if (!CaloTowersEndjob(hcalMEs))
0049 std::cout << "\nError in CaloTowersEndjob!" << std::endl << std::endl;
0050 }
0051 }
0052 }
0053 }
0054
0055
0056
0057 int CaloTowersClient::CaloTowersEndjob(const std::vector<MonitorElement*>& hcalMEs) {
0058 int useAllHistos = 0;
0059 MonitorElement* Ntowers_vs_ieta = nullptr;
0060 MonitorElement *mapEnergy_N = nullptr, *mapEnergy_E = nullptr, *mapEnergy_H = nullptr, *mapEnergy_EH = nullptr;
0061 MonitorElement *occupancy_map = nullptr, *occupancy_vs_ieta = nullptr;
0062 for (unsigned int ih = 0; ih < hcalMEs.size(); ih++) {
0063 if (strcmp(hcalMEs[ih]->getName().c_str(), "Ntowers_per_event_vs_ieta") == 0) {
0064 Ntowers_vs_ieta = hcalMEs[ih];
0065 }
0066 if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_Nentries") == 0) {
0067 mapEnergy_N = hcalMEs[ih];
0068 }
0069 if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_energy_H") == 0) {
0070 useAllHistos++;
0071 mapEnergy_H = hcalMEs[ih];
0072 }
0073 if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_energy_E") == 0) {
0074 useAllHistos++;
0075 mapEnergy_E = hcalMEs[ih];
0076 }
0077 if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_energy_EH") == 0) {
0078 useAllHistos++;
0079 mapEnergy_EH = hcalMEs[ih];
0080 }
0081 if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_map_occupancy") == 0) {
0082 occupancy_map = hcalMEs[ih];
0083 }
0084 if (strcmp(hcalMEs[ih]->getName().c_str(), "CaloTowersTask_occupancy_vs_ieta") == 0) {
0085 occupancy_vs_ieta = hcalMEs[ih];
0086 }
0087 }
0088 if (useAllHistos != 0 && useAllHistos != 3)
0089 return 0;
0090
0091 assert(mapEnergy_N);
0092 double nevent = mapEnergy_N->getEntries();
0093 if (verbose_)
0094 std::cout << "nevent : " << nevent << std::endl;
0095
0096
0097 assert(Ntowers_vs_ieta);
0098 int nx = Ntowers_vs_ieta->getNbinsX();
0099 float cont;
0100 float econt;
0101 float fev = float(nevent);
0102
0103 for (int i = 1; i <= nx; i++) {
0104 cont = Ntowers_vs_ieta->getBinContent(i) / fev;
0105 econt = Ntowers_vs_ieta->getBinError(i) / fev;
0106 Ntowers_vs_ieta->setBinContent(i, cont);
0107 Ntowers_vs_ieta->setBinError(i, econt);
0108 }
0109
0110
0111
0112 nx = mapEnergy_N->getNbinsX();
0113 int ny = mapEnergy_N->getNbinsY();
0114 float cnorm;
0115 float enorm;
0116 float phi_factor;
0117
0118 for (int i = 1; i <= nx; i++) {
0119 float sumphi = 0.;
0120 float sumphie = 0.;
0121
0122 for (int j = 1; j <= ny; j++) {
0123
0124 cnorm = mapEnergy_N->getBinContent(i, j);
0125
0126 if (cnorm > 0.000001 && useAllHistos) {
0127 cont = mapEnergy_E->getBinContent(i, j) / cnorm;
0128 econt = mapEnergy_E->getBinError(i, j) / cnorm;
0129 mapEnergy_E->setBinContent(i, j, cont);
0130 mapEnergy_E->setBinError(i, j, econt);
0131
0132 cont = mapEnergy_H->getBinContent(i, j) / cnorm;
0133 econt = mapEnergy_H->getBinError(i, j) / cnorm;
0134 mapEnergy_H->setBinContent(i, j, cont);
0135 mapEnergy_H->setBinError(i, j, econt);
0136
0137 cont = mapEnergy_EH->getBinContent(i, j) / cnorm;
0138 econt = mapEnergy_EH->getBinError(i, j) / cnorm;
0139 mapEnergy_EH->setBinContent(i, j, cont);
0140 mapEnergy_EH->setBinError(i, j, econt);
0141 }
0142
0143
0144 assert(occupancy_map);
0145 cnorm = occupancy_map->getBinContent(i, j) / fev;
0146 enorm = occupancy_map->getBinError(i, j) / fev;
0147 if (cnorm > 1.e-30)
0148 occupancy_map->setBinContent(i, j, cnorm);
0149
0150 sumphi += cnorm;
0151 sumphie += enorm * enorm;
0152
0153 }
0154
0155
0156
0157 int ieta = i - 42;
0158 if (ieta >= -20 && ieta <= 20) {
0159 phi_factor = 72.;
0160 } else {
0161 if (ieta >= 40 || ieta <= -40) {
0162 phi_factor = 18.;
0163 } else
0164 phi_factor = 36.;
0165 }
0166
0167 cnorm = sumphi / phi_factor;
0168 enorm = sqrt(sumphie) / phi_factor;
0169 assert(occupancy_vs_ieta);
0170 occupancy_vs_ieta->setBinContent(i, cnorm);
0171 occupancy_vs_ieta->setBinError(i, enorm);
0172
0173 }
0174
0175 return 1;
0176 }
0177
0178 DEFINE_FWK_MODULE(CaloTowersClient);