File indexing completed on 2023-03-17 11:26:58
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 double nevent = mapEnergy_N->getEntries();
0092 if (verbose_)
0093 std::cout << "nevent : " << nevent << std::endl;
0094
0095
0096 int nx = Ntowers_vs_ieta->getNbinsX();
0097 float cont;
0098 float econt;
0099 float fev = float(nevent);
0100
0101 for (int i = 1; i <= nx; i++) {
0102 cont = Ntowers_vs_ieta->getBinContent(i) / fev;
0103 econt = Ntowers_vs_ieta->getBinError(i) / fev;
0104 Ntowers_vs_ieta->setBinContent(i, cont);
0105 Ntowers_vs_ieta->setBinError(i, econt);
0106 }
0107
0108
0109
0110 nx = mapEnergy_N->getNbinsX();
0111 int ny = mapEnergy_N->getNbinsY();
0112 float cnorm;
0113 float enorm;
0114 float phi_factor;
0115
0116 for (int i = 1; i <= nx; i++) {
0117 float sumphi = 0.;
0118 float sumphie = 0.;
0119
0120 for (int j = 1; j <= ny; j++) {
0121
0122 cnorm = mapEnergy_N->getBinContent(i, j);
0123
0124 if (cnorm > 0.000001 && useAllHistos) {
0125 cont = mapEnergy_E->getBinContent(i, j) / cnorm;
0126 econt = mapEnergy_E->getBinError(i, j) / cnorm;
0127 mapEnergy_E->setBinContent(i, j, cont);
0128 mapEnergy_E->setBinError(i, j, econt);
0129
0130 cont = mapEnergy_H->getBinContent(i, j) / cnorm;
0131 econt = mapEnergy_H->getBinError(i, j) / cnorm;
0132 mapEnergy_H->setBinContent(i, j, cont);
0133 mapEnergy_H->setBinError(i, j, econt);
0134
0135 cont = mapEnergy_EH->getBinContent(i, j) / cnorm;
0136 econt = mapEnergy_EH->getBinError(i, j) / cnorm;
0137 mapEnergy_EH->setBinContent(i, j, cont);
0138 mapEnergy_EH->setBinError(i, j, econt);
0139 }
0140
0141
0142 cnorm = occupancy_map->getBinContent(i, j) / fev;
0143 enorm = occupancy_map->getBinError(i, j) / fev;
0144 if (cnorm > 1.e-30)
0145 occupancy_map->setBinContent(i, j, cnorm);
0146
0147 sumphi += cnorm;
0148 sumphie += enorm * enorm;
0149
0150 }
0151
0152
0153
0154 int ieta = i - 42;
0155 if (ieta >= -20 && ieta <= 20) {
0156 phi_factor = 72.;
0157 } else {
0158 if (ieta >= 40 || ieta <= -40) {
0159 phi_factor = 18.;
0160 } else
0161 phi_factor = 36.;
0162 }
0163
0164 cnorm = sumphi / phi_factor;
0165 enorm = sqrt(sumphie) / phi_factor;
0166 occupancy_vs_ieta->setBinContent(i, cnorm);
0167 occupancy_vs_ieta->setBinError(i, enorm);
0168
0169 }
0170
0171 return 1;
0172 }
0173
0174 DEFINE_FWK_MODULE(CaloTowersClient);