Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:57

0001 #include "HLTriggerOffline/SUSYBSM/interface/HltSusyExoPostProcessor.h"
0002 
0003 #include "DQMServices/Core/interface/DQMStore.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 
0008 #include "TH1.h"
0009 #include "TProfile.h"
0010 #include <cmath>
0011 #include <cstring>
0012 #include <fstream>
0013 #include <iomanip>
0014 #include <iostream>
0015 
0016 using namespace std;
0017 using namespace edm;
0018 
0019 HltSusyExoPostProcessor::HltSusyExoPostProcessor(const edm::ParameterSet &pset)
0020     : subDir_(pset.getUntrackedParameter<std::string>("subDir", std::string("HLT/SusyExo"))),
0021       mcFlag(pset.getUntrackedParameter<bool>("mc_flag", true)),
0022       reco_parametersets(pset.getParameter<VParameterSet>("reco_parametersets")),
0023       mc_parametersets(pset.getParameter<VParameterSet>("mc_parametersets")) {
0024   for (unsigned int i = 0; i < reco_parametersets.size(); ++i) {
0025     reco_dirs.push_back(reco_parametersets[i].getParameter<string>("name"));
0026   }
0027   for (unsigned int i = 0; i < mc_parametersets.size(); ++i) {
0028     mc_dirs.push_back(mc_parametersets[i].getParameter<string>("name"));
0029   }
0030 }
0031 
0032 void HltSusyExoPostProcessor::dqmEndJob(DQMStore::IBooker &iBooker_, DQMStore::IGetter &iGetter_) {
0033   LogDebug("HltSusyExoPostProcessor") << "Start dqmEndJob";
0034 
0035   // go to the directory to be processed
0036   if (iGetter_.dirExists(subDir_))
0037     iGetter_.cd(subDir_);
0038   else {
0039     edm::LogWarning("HltSusyExoPostProcessor") << "cannot find directory: " << subDir_ << " , skipping";
0040     return;
0041   }
0042 
0043   LogDebug("HltSusyExoPostProcessor") << "DQMStore cd";
0044 
0045   // --- set the names in the dbe folders ---
0046   std::string triggerBitsDir = "/TriggerBits";
0047   std::string recoSelBitsDir = "/RecoSelection";
0048   std::string mcSelBitsDir = "/McSelection";
0049   std::string byEventDir = "/By_Event";
0050   std::string byMuonDir = "/By_Muon";
0051 
0052   // get the number of bins of the MonitorElements (valid for all the
0053   // MonitorElements, independently of selection on the final state) we take the
0054   // number of bins from the MonitorElements of the source, and we subtract one
0055   // because the last bin was reserved for the Total number of events
0056   int nL1bins = (iGetter_.get(iBooker_.pwd() + triggerBitsDir + "/L1Bits")->getNbinsX());
0057   int nHltbins = (iGetter_.get(iBooker_.pwd() + triggerBitsDir + "/HltBits")->getNbinsX());
0058 
0059   std::vector<int> L1placement;
0060   L1placement.reserve(nL1bins - 1 * mcFlag);
0061   for (int i = 0; i < nL1bins - 1 * mcFlag; ++i)
0062     L1placement.push_back(6);
0063   std::vector<int> Hltplacement;
0064   Hltplacement.reserve(nHltbins - 1 * mcFlag);
0065   for (int i = 0; i < nHltbins - 1 * mcFlag; ++i)
0066     Hltplacement.push_back(7);
0067   int L1bins[7];
0068   for (unsigned int i = 0; i < sizeof(L1bins) / sizeof(L1bins[0]); ++i)
0069     L1bins[i] = 0;
0070   int Hltbins[8];
0071   for (unsigned int i = 0; i < sizeof(Hltbins) / sizeof(Hltbins[0]); ++i)
0072     Hltbins[i] = 0;
0073   string L1search[8] = {"Mu", "EG", "Jet", "ET", "TauJet", "X", ""};
0074   string L1search3 = "HTT", L1search6 = "Bias";
0075   string Hltsearch[8] = {"Mu", "Ele", "Jet", "Photon", "MET", "Tau", "X", ""};
0076   string Hltsearch4 = "HT", Hltsearch5 = "BTag", Hltsearch6_1 = "EG", Hltsearch6_2 = "ET", Hltsearch7_1 = "Bias",
0077          Hltsearch7_2 = "AlCa";
0078 
0079   LogDebug("HltSusyExoPostProcessor") << "number of L1 bins = " << nL1bins << " number of HLT bins = " << nHltbins;
0080   double value = 0;
0081   double error = 0;
0082 
0083   // Calculate the efficiencies for histos without any selection
0084   iGetter_.setCurrentFolder(subDir_ + triggerBitsDir);
0085   TH1F *hL1Paths = iGetter_.get(subDir_ + triggerBitsDir + "/L1Paths")->getTH1F();
0086   MonitorElement *hL1EffBeforeCuts = bookEffMEProfileFromTH1(hL1Paths, "Eff", iBooker_);
0087   TH1F *hHltPaths = iGetter_.get(subDir_ + triggerBitsDir + "/HltPaths")->getTH1F();
0088   MonitorElement *hHltEffBeforeCuts = bookEffMEProfileFromTH1(hHltPaths, "Eff", iBooker_);
0089 
0090   LogDebug("HltSusyExoPostProcessor") << "MonitorElements booked";
0091 
0092   // get the total number of events
0093   float nTotalBeforeCuts = -1;
0094   int reference_bin = -1;
0095   if (mcFlag) {
0096     nTotalBeforeCuts = iGetter_.get(subDir_ + triggerBitsDir + "/L1Bits")->getBinContent(nL1bins);
0097     reference_bin = nL1bins;
0098   } else {
0099     for (int i = 0; i < nHltbins; ++i) {
0100       string triggername = ((TProfile *)hHltEffBeforeCuts->getTProfile())->GetXaxis()->GetBinLabel(i + 1);
0101       string eff_search = "HLT_ZeroBias";
0102       if (triggername.find(eff_search) != string::npos && triggername.size() == eff_search.size()) {
0103         nTotalBeforeCuts = ((TProfile *)hHltEffBeforeCuts->getTProfile())->GetBinContent(i + 1);
0104         reference_bin = i + 1;
0105         break;
0106       }
0107     }
0108     if (nTotalBeforeCuts == -1) {
0109       nTotalBeforeCuts = iGetter_.get(subDir_ + triggerBitsDir + "/L1Bits")->getBinContent(nL1bins);
0110       reference_bin = nHltbins;
0111     }
0112   }
0113   LogDebug("HltSusyExoPostProcessor") << "Total number of events = " << nTotalBeforeCuts;
0114 
0115   // fill the eff histo
0116   for (int i = 0; i < nL1bins - 1 * mcFlag; i++) {
0117     value =
0118         (double)iGetter_.get(subDir_ + triggerBitsDir + "/L1Paths")->getBinContent(i + 1) / (double)nTotalBeforeCuts;
0119     error = sqrt(value * (1 - value) / (double)nTotalBeforeCuts);
0120     hL1EffBeforeCuts->setBinContent(i + 1, value);
0121     hL1EffBeforeCuts->setBinEntries(i + 1, 1);
0122     hL1EffBeforeCuts->setBinError(i + 1, error);
0123     // if(i!=nL1bins)
0124     // {
0125     string triggername = ((TProfile *)hL1EffBeforeCuts->getTProfile())->GetXaxis()->GetBinLabel(i + 1);
0126     if (triggername.find(L1search6) == string::npos) {
0127       for (unsigned int j = 0; j < sizeof(L1search) / sizeof(L1search[0]) - 2; ++j) {
0128         if (triggername.find(L1search[j]) != string::npos || (j == 3 && triggername.find(L1search3) != string::npos)) {
0129           if (L1placement[i] == 6)
0130             L1placement[i] = j;
0131           else if (L1placement[i] == 2 && j == 4)
0132             L1placement[i] = 4;
0133           else
0134             L1placement[i] = 5;
0135         } else if (triggername.empty() || triggername.find("Total") != string::npos)
0136           L1placement[i] = -1;
0137       }
0138     }
0139   }
0140 
0141   for (unsigned int i = 0; i < L1placement.size(); ++i)
0142     if (L1placement[i] != -1)
0143       ++L1bins[L1placement[i]];
0144 
0145   for (int i = 0; i < nHltbins - 1 * mcFlag; i++) {
0146     value =
0147         (double)iGetter_.get(subDir_ + triggerBitsDir + "/HltPaths")->getBinContent(i + 1) / (double)nTotalBeforeCuts;
0148     error = sqrt(value * (1 - value) / (double)nTotalBeforeCuts);
0149     hHltEffBeforeCuts->setBinContent(i + 1, value);
0150     hHltEffBeforeCuts->setBinEntries(i + 1, 1);
0151     hHltEffBeforeCuts->setBinError(i + 1, error);
0152     // if(i!=nHltbins)
0153     //  {
0154     string triggername = ((TProfile *)hHltEffBeforeCuts->getTProfile())->GetXaxis()->GetBinLabel(i + 1);
0155     if (triggername.find(Hltsearch7_1) == string::npos && triggername.find(Hltsearch7_2) == string::npos) {
0156       for (unsigned int j = 0; j < sizeof(Hltsearch) / sizeof(Hltsearch[0]) - 2; ++j) {
0157         if (triggername.find(Hltsearch[j]) != string::npos ||
0158             (j == 4 && triggername.find(Hltsearch4) != string::npos) ||
0159             (j == 5 && triggername.find(Hltsearch5) != string::npos)) {
0160           if (Hltplacement[i] == 7)
0161             Hltplacement[i] = j;
0162           else if (triggername.find(Hltsearch5) != string::npos)
0163             Hltplacement[i] = 5;
0164           else
0165             Hltplacement[i] = 6;
0166         } else if (triggername.empty() || triggername.find("Total") != string::npos)
0167           Hltplacement[i] = -1;
0168       }
0169       if (Hltplacement[i] >= 0 && Hltplacement[i] <= 5 &&
0170           (triggername.find(Hltsearch6_1) != string::npos ||
0171            (triggername.find(Hltsearch6_2) != string::npos && Hltplacement[i] != 4)))
0172         Hltplacement[i] = 6;
0173     }
0174   }
0175 
0176   for (unsigned int i = 0; i < Hltplacement.size(); ++i)
0177     if (Hltplacement[i] != -1)
0178       ++Hltbins[Hltplacement[i]];
0179 
0180   LogDebug("HltSusyExoPostProcessor") << "MonitorElements filled";
0181 
0182   // Create the sorted histograms
0183   iBooker_.setCurrentFolder(subDir_ + triggerBitsDir);
0184   MonitorElement *hL1EffSorted[7] = {
0185       iBooker_.bookProfile("L1_Mu", new TProfile("L1_Mu", "Efficiencies of L1 Muon Triggers", L1bins[0], 0, L1bins[0])),
0186       iBooker_.bookProfile("L1_EG", new TProfile("L1_EG", "Efficiencies of L1 EG Triggers", L1bins[1], 0, L1bins[1])),
0187       iBooker_.bookProfile("L1_Jet",
0188                            new TProfile("L1_Jet", "Efficiencies of L1 Jet Triggers", L1bins[2], 0, L1bins[2])),
0189       iBooker_.bookProfile(
0190           "L1_ETM_ETT_HTT",
0191           new TProfile("L1_ETM_ETT_HTT", "Efficiencies of L1 ETM, ETT, and HTT Triggers", L1bins[3], 0, L1bins[3])),
0192       iBooker_.bookProfile("L1_TauJet",
0193                            new TProfile("L1_TauJet", "Efficiencies of L1 TauJet Triggers", L1bins[4], 0, L1bins[4])),
0194       iBooker_.bookProfile("L1_XTrigger",
0195                            new TProfile("L1_XTrigger", "Efficiencies of L1 Cross Triggers", L1bins[5], 0, L1bins[5])),
0196       iBooker_.bookProfile(
0197           "L1_Overflow", new TProfile("L1_Overflow", "Efficiencies of L1 Unsorted Triggers", L1bins[6], 0, L1bins[6]))};
0198 
0199   MonitorElement *hHltEffSorted[8] = {
0200       iBooker_.bookProfile("Hlt_Mu",
0201                            new TProfile("Hlt_Mu", "Efficiencies of HL Muon Triggers", Hltbins[0], 0, Hltbins[0])),
0202       iBooker_.bookProfile("Hlt_Ele",
0203                            new TProfile("Hlt_Ele", "Efficiencies of HL Electron Triggers", Hltbins[1], 0, Hltbins[1])),
0204       iBooker_.bookProfile("Hlt_Jet",
0205                            new TProfile("Hlt_Jet", "Efficiencies of HL Jet Triggers", Hltbins[2], 0, Hltbins[2], "s")),
0206       iBooker_.bookProfile("Hlt_Photon",
0207                            new TProfile("Hlt_Photon", "Efficiencies of HL Photon Triggers", Hltbins[3], 0, Hltbins[3])),
0208       iBooker_.bookProfile(
0209           "Hlt_MET_HT",
0210           new TProfile("Hlt_MET_HT", "Efficiencies of HL MET and HT Triggers", Hltbins[4], 0, Hltbins[4])),
0211       iBooker_.bookProfile(
0212           "Hlt_Tau_BTag",
0213           new TProfile("Hlt_Tau_Btag", "Efficiencies of HL Tau and BTag Triggers", Hltbins[5], 0, Hltbins[5])),
0214       iBooker_.bookProfile(
0215           "Hlt_XTrigger", new TProfile("Hlt_XTrigger", "Efficiencies of HL Cross Triggers", Hltbins[6], 0, Hltbins[6])),
0216       iBooker_.bookProfile(
0217           "Hlt_Overflow",
0218           new TProfile("Hlt_Overflow", "Efficiencies of HL Unsorted Triggers", Hltbins[7], 0, Hltbins[7]))};
0219 
0220   int L1bincounter[8];
0221   for (unsigned int i = 0; i < sizeof(L1bincounter) / sizeof(L1bincounter[0]); ++i)
0222     L1bincounter[i] = 0;
0223   int Hltbincounter[8];
0224   for (unsigned int i = 0; i < sizeof(Hltbincounter) / sizeof(Hltbincounter[0]); ++i)
0225     Hltbincounter[i] = 0;
0226   TProfile *hL1_ = (TProfile *)hL1EffBeforeCuts->getTProfile();
0227   TProfile *hHlt_ = (TProfile *)hHltEffBeforeCuts->getTProfile();
0228   //  for(int i = 0; i<hHlt_->GetXaxis()->GetNbins(); i++) cout <<
0229   //  "hHLT_->GetBinError(" << i << ") = " << hHlt_->GetBinError(i+1) << endl;
0230   for (unsigned int i = 0; i < L1placement.size(); ++i) {
0231     if (L1placement[i] != -1) {
0232       hL1EffSorted[L1placement[i]]->setBinLabel(L1bincounter[L1placement[i]] + 1, hL1_->GetXaxis()->GetBinLabel(i + 1));
0233       hL1EffSorted[L1placement[i]]->setBinContent(L1bincounter[L1placement[i]] + 1, hL1_->GetBinContent(i + 1));
0234       hL1EffSorted[L1placement[i]]->setBinEntries(L1bincounter[L1placement[i]] + 1, 1);
0235       hL1EffSorted[L1placement[i]]->setBinError(L1bincounter[L1placement[i]] + 1, hL1_->GetBinError(i + 1));
0236       ++L1bincounter[L1placement[i]];
0237     }
0238   }
0239   for (unsigned int i = 0; i < Hltplacement.size(); ++i) {
0240     if (Hltplacement[i] != -1) {
0241       hHltEffSorted[Hltplacement[i]]->setBinLabel(Hltbincounter[Hltplacement[i]] + 1,
0242                                                   hHlt_->GetXaxis()->GetBinLabel(i + 1));
0243       hHltEffSorted[Hltplacement[i]]->setBinContent(Hltbincounter[Hltplacement[i]] + 1, hHlt_->GetBinContent(i + 1));
0244       hHltEffSorted[Hltplacement[i]]->setBinEntries(Hltbincounter[Hltplacement[i]] + 1, 1);
0245       hHltEffSorted[Hltplacement[i]]->setBinError(Hltbincounter[Hltplacement[i]] + 1, hHlt_->GetBinError(i + 1));
0246       ++Hltbincounter[Hltplacement[i]];
0247     }
0248   }
0249 
0250   for (unsigned int i = 0; i < mc_dirs.size(); ++i) {
0251     // Calculate the efficiencies for histos after MC selection
0252     iGetter_.setCurrentFolder(subDir_ + mcSelBitsDir + "/" + mc_dirs[i]);
0253     // book the MonitorElements for the efficiencies
0254     char set_name_L1[256], set_name_Hlt[256];
0255     sprintf(set_name_L1, "L1Eff_%s", mc_dirs[i].c_str());
0256     sprintf(set_name_Hlt, "HltEff_%s", mc_dirs[i].c_str());
0257     MonitorElement *hL1EffAfterMcCuts = bookEffMEProfileFromTH1(
0258         iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/L1Paths_" + mc_dirs[i])->getTH1F(),
0259         (std::string)set_name_L1,
0260         iBooker_);
0261     hL1EffAfterMcCuts->setTitle("L1 Efficiencies for " + mc_dirs[i] + " selection");
0262     MonitorElement *hHltEffAfterMcCuts = bookEffMEProfileFromTH1(
0263         iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/HltPaths_" + mc_dirs[i])->getTH1F(),
0264         (std::string)set_name_Hlt,
0265         iBooker_);
0266     hHltEffAfterMcCuts->setTitle("HLT Efficiencies for " + mc_dirs[i] + " selection");
0267 
0268     LogDebug("HltSusyExoPostProcessor") << "MonitorElements for " << mc_dirs[i] << " selection booked";
0269 
0270     // get the total number of events
0271     float nTotalAfterMcCuts;
0272     if (mcFlag)
0273       nTotalAfterMcCuts =
0274           iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/L1Bits_" + mc_dirs[i])->getBinContent(nL1bins);
0275     else
0276       nTotalAfterMcCuts = iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/HltBits_" + mc_dirs[i])
0277                               ->getBinContent(reference_bin);
0278 
0279     LogDebug("HltSusyExoPostProcessor") << "Total number of events = " << nTotalAfterMcCuts;
0280 
0281     MonitorElement *hL1EffSorted_mc[7];
0282     MonitorElement *hHltEffSorted_mc[8];
0283     char buffer1[256], buffer2[256];
0284     string L1_nametags[7] = {"Mu", "EG", "Jet", "ETM_ETT_HTT", "TauJet", "XTrigger", "Overflow"};
0285     string L1_titletags[7] = {"Muon", "EG", "Jet", "ETM, ETT, and HTT", "TauJet", "Cross", "Unsorted"};
0286     string Hlt_nametags[8] = {"Mu", "Ele", "Jet", "Photon", "MET_HT", "Tau_BTag", "XTrigger", "Overflow"};
0287     string Hlt_titletags[8] = {"Muon", "Electron", "Jet", "Photon", "MET and HT", "Tau and BTag", "Cross", "Unsorted"};
0288     for (unsigned int j = 0; j < sizeof(hL1EffSorted_mc) / sizeof(hL1EffSorted_mc[0]); ++j) {
0289       sprintf(buffer1, "L1_%s_%s", mc_dirs[i].c_str(), L1_nametags[j].c_str());
0290       sprintf(buffer2, "Efficiencies of L1 %s Triggers for %s Selection", L1_titletags[j].c_str(), mc_dirs[i].c_str());
0291       hL1EffSorted_mc[j] = iBooker_.bookProfile(buffer1, new TProfile(buffer1, buffer2, L1bins[j], 0, L1bins[j]));
0292     }
0293     for (unsigned int j = 0; j < sizeof(hHltEffSorted_mc) / sizeof(hHltEffSorted_mc[0]); ++j) {
0294       sprintf(buffer1, "Hlt_%s_%s", mc_dirs[i].c_str(), Hlt_nametags[j].c_str());
0295       sprintf(buffer2, "Efficiencies of HL %s Triggers for %s Selection", Hlt_titletags[j].c_str(), mc_dirs[i].c_str());
0296       hHltEffSorted_mc[j] = iBooker_.bookProfile(buffer1, new TProfile(buffer1, buffer2, Hltbins[j], 0, Hltbins[j]));
0297     }
0298 
0299     // fill the eff histo
0300     int L1bincounter_mc[8];
0301     for (unsigned int j = 0; j < sizeof(L1bincounter_mc) / sizeof(L1bincounter_mc[0]); ++j)
0302       L1bincounter_mc[j] = 0;
0303     int Hltbincounter_mc[8];
0304     for (unsigned int j = 0; j < sizeof(Hltbincounter_mc) / sizeof(Hltbincounter_mc[0]); ++j)
0305       Hltbincounter_mc[j] = 0;
0306     TProfile *hL1_mc = (TProfile *)hL1EffAfterMcCuts->getTProfile();
0307     TProfile *hHlt_mc = (TProfile *)hHltEffAfterMcCuts->getTProfile();
0308     for (unsigned int j = 0; j < L1placement.size(); j++) {
0309       value = nTotalAfterMcCuts
0310                   ? (float)iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/L1Paths_" + mc_dirs[i])
0311                             ->getBinContent(j + 1) /
0312                         nTotalAfterMcCuts
0313                   : 0;
0314       error = nTotalAfterMcCuts ? sqrt(value * (1 - value) / nTotalAfterMcCuts) : 0;
0315       hL1EffAfterMcCuts->setBinContent(j + 1, value);
0316       hL1EffAfterMcCuts->setBinEntries(j + 1, 1);
0317       hL1EffAfterMcCuts->setBinError(j + 1, error);
0318       if (L1placement[j] != -1) {
0319         hL1EffSorted_mc[L1placement[j]]->setBinLabel(L1bincounter_mc[L1placement[j]] + 1,
0320                                                      hL1_mc->GetXaxis()->GetBinLabel(j + 1));
0321         hL1EffSorted_mc[L1placement[j]]->setBinContent(L1bincounter_mc[L1placement[j]] + 1,
0322                                                        hL1_mc->GetBinContent(j + 1));
0323         hL1EffSorted_mc[L1placement[j]]->setBinEntries(L1bincounter_mc[L1placement[j]] + 1, 1);
0324         hL1EffSorted_mc[L1placement[j]]->setBinError(L1bincounter_mc[L1placement[j]] + 1, hL1_mc->GetBinError(j + 1));
0325         ++L1bincounter_mc[L1placement[j]];
0326       }
0327     }
0328     if (nL1bins != int(L1placement.size())) {
0329       value = nTotalAfterMcCuts
0330                   ? (float)iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/L1Paths_" + mc_dirs[i])
0331                             ->getBinContent(nL1bins) /
0332                         nTotalAfterMcCuts
0333                   : 0;
0334       error = nTotalAfterMcCuts ? sqrt(value * (1 - value) / nTotalAfterMcCuts) : 0;
0335       hL1EffAfterMcCuts->setBinContent(nL1bins, value);
0336       hL1EffAfterMcCuts->setBinEntries(nL1bins, 1);
0337       hL1EffAfterMcCuts->setBinError(nL1bins, error);
0338     }
0339     for (unsigned int j = 0; j < Hltplacement.size(); j++) {
0340       value = nTotalAfterMcCuts
0341                   ? (float)iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/HltPaths_" + mc_dirs[i])
0342                             ->getBinContent(j + 1) /
0343                         nTotalAfterMcCuts
0344                   : 0;
0345       error = nTotalAfterMcCuts ? sqrt(value * (1 - value) / nTotalAfterMcCuts) : 0;
0346       hHltEffAfterMcCuts->setBinContent(j + 1, value);
0347       hHltEffAfterMcCuts->setBinEntries(j + 1, 1);
0348       hHltEffAfterMcCuts->setBinError(j + 1, error);
0349       if (Hltplacement[j] != -1) {
0350         hHltEffSorted_mc[Hltplacement[j]]->setBinLabel(Hltbincounter_mc[Hltplacement[j]] + 1,
0351                                                        hHlt_mc->GetXaxis()->GetBinLabel(j + 1));
0352         hHltEffSorted_mc[Hltplacement[j]]->setBinContent(Hltbincounter_mc[Hltplacement[j]] + 1,
0353                                                          hHlt_mc->GetBinContent(j + 1));
0354         hHltEffSorted_mc[Hltplacement[j]]->setBinEntries(Hltbincounter_mc[Hltplacement[j]] + 1, 1);
0355         hHltEffSorted_mc[Hltplacement[j]]->setBinError(Hltbincounter_mc[Hltplacement[j]] + 1,
0356                                                        hHlt_mc->GetBinError(j + 1));
0357         ++Hltbincounter_mc[Hltplacement[j]];
0358       }
0359     }
0360     if (nHltbins != int(Hltplacement.size())) {
0361       value = nTotalAfterMcCuts
0362                   ? (float)iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/HltPaths_" + mc_dirs[i])
0363                             ->getBinContent(nHltbins) /
0364                         nTotalAfterMcCuts
0365                   : 0;
0366       error = nTotalAfterMcCuts ? sqrt(value * (1 - value) / nTotalAfterMcCuts) : 0;
0367       hHltEffAfterMcCuts->setBinContent(nHltbins, value);
0368       hHltEffAfterMcCuts->setBinEntries(nHltbins, 1);
0369       hHltEffAfterMcCuts->setBinError(nHltbins, error);
0370     }
0371     LogDebug("HltSusyExoPostProcessor") << "MonitorElements filled for " << mc_dirs[i] << " selection";
0372   }
0373 
0374   for (unsigned int i = 0; i < reco_dirs.size(); ++i) {
0375     // Calculate the efficiencies for histos after RECO selection
0376     iGetter_.setCurrentFolder(subDir_ + recoSelBitsDir + "/" + reco_dirs[i]);
0377     // book the MonitorElements for the efficiencies
0378     char set_name_L1[256], set_name_Hlt[256];
0379     sprintf(set_name_L1, "L1Eff_%s", reco_dirs[i].c_str());
0380     sprintf(set_name_Hlt, "HltEff_%s", reco_dirs[i].c_str());
0381     MonitorElement *hL1EffAfterRecoCuts = bookEffMEProfileFromTH1(
0382         iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/L1Paths_" + reco_dirs[i])->getTH1F(),
0383         (std::string)set_name_L1,
0384         iBooker_);
0385     hL1EffAfterRecoCuts->setTitle("L1 Efficiencies for " + reco_dirs[i] + " selection");
0386     MonitorElement *hHltEffAfterRecoCuts = bookEffMEProfileFromTH1(
0387         iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/HltPaths_" + reco_dirs[i])->getTH1F(),
0388         (std::string)set_name_Hlt,
0389         iBooker_);
0390     hHltEffAfterRecoCuts->setTitle("HLT Efficiencies for " + reco_dirs[i] + " selection");
0391 
0392     LogDebug("HltSusyExoPostProcessor") << "MonitorElements for " << reco_dirs[i] << " selection booked";
0393 
0394     // get the total number of events
0395     float nTotalAfterRecoCuts;
0396     if (mcFlag)
0397       nTotalAfterRecoCuts = iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/L1Bits_" + reco_dirs[i])
0398                                 ->getBinContent(nL1bins);
0399     else
0400       nTotalAfterRecoCuts = iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/HltBits_" + reco_dirs[i])
0401                                 ->getBinContent(reference_bin);
0402 
0403     LogDebug("HltSusyExoPostProcessor") << "Total number of events = " << nTotalAfterRecoCuts;
0404 
0405     MonitorElement *hL1EffSorted_reco[7];
0406     MonitorElement *hHltEffSorted_reco[8];
0407     char buffer1[256], buffer2[256];
0408     string L1_nametags[7] = {"Mu", "EG", "Jet", "ETM_ETT_HTT", "TauJet", "XTrigger", "Overflow"};
0409     string L1_titletags[7] = {"Muon", "EG", "Jet", "ETM, ETT, and HTT", "TauJet", "Cross", "Unsorted"};
0410     string Hlt_nametags[8] = {"Mu", "Ele", "Jet", "Photon", "MET_HT", "Tau_BTag", "XTrigger", "Overflow"};
0411     string Hlt_titletags[8] = {"Muon", "Electron", "Jet", "Photon", "MET and HT", "Tau and BTag", "Cross", "Unsorted"};
0412     for (unsigned int j = 0; j < sizeof(hL1EffSorted_reco) / sizeof(hL1EffSorted_reco[0]); ++j) {
0413       sprintf(buffer1, "L1_%s_%s", reco_dirs[i].c_str(), L1_nametags[j].c_str());
0414       sprintf(
0415           buffer2, "Efficiencies of L1 %s Triggers for %s Selection", L1_titletags[j].c_str(), reco_dirs[i].c_str());
0416       hL1EffSorted_reco[j] = iBooker_.bookProfile(buffer1, new TProfile(buffer1, buffer2, L1bins[j], 0, L1bins[j]));
0417     }
0418     for (unsigned int j = 0; j < sizeof(hHltEffSorted_reco) / sizeof(hHltEffSorted_reco[0]); ++j) {
0419       sprintf(buffer1, "Hlt_%s_%s", reco_dirs[i].c_str(), Hlt_nametags[j].c_str());
0420       sprintf(
0421           buffer2, "Efficiencies of HL %s Triggers for %s Selection", Hlt_titletags[j].c_str(), reco_dirs[i].c_str());
0422       hHltEffSorted_reco[j] = iBooker_.bookProfile(buffer1, new TProfile(buffer1, buffer2, Hltbins[j], 0, Hltbins[j]));
0423     }
0424 
0425     // fill the eff histo
0426     int L1bincounter_reco[8];
0427     for (unsigned int j = 0; j < sizeof(L1bincounter_reco) / sizeof(L1bincounter_reco[0]); ++j)
0428       L1bincounter_reco[j] = 0;
0429     int Hltbincounter_reco[8];
0430     for (unsigned int j = 0; j < sizeof(Hltbincounter_reco) / sizeof(Hltbincounter_reco[0]); ++j)
0431       Hltbincounter_reco[j] = 0;
0432     TProfile *hL1_reco = (TProfile *)hL1EffAfterRecoCuts->getTProfile();
0433     TProfile *hHlt_reco = (TProfile *)hHltEffAfterRecoCuts->getTProfile();
0434     for (unsigned int j = 0; j < L1placement.size(); j++) {
0435       value = nTotalAfterRecoCuts
0436                   ? (float)iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/L1Paths_" + reco_dirs[i])
0437                             ->getBinContent(j + 1) /
0438                         nTotalAfterRecoCuts
0439                   : 0;
0440       error = nTotalAfterRecoCuts ? sqrt(value * (1 - value) / nTotalAfterRecoCuts) : 0;
0441       hL1EffAfterRecoCuts->setBinContent(j + 1, value);
0442       hL1EffAfterRecoCuts->setBinEntries(j + 1, 1);
0443       hL1EffAfterRecoCuts->setBinError(j + 1, error);
0444       if (L1placement[j] != -1) {
0445         hL1EffSorted_reco[L1placement[j]]->setBinLabel(L1bincounter_reco[L1placement[j]] + 1,
0446                                                        hL1_reco->GetXaxis()->GetBinLabel(j + 1));
0447         hL1EffSorted_reco[L1placement[j]]->setBinContent(L1bincounter_reco[L1placement[j]] + 1,
0448                                                          hL1_reco->GetBinContent(j + 1));
0449         hL1EffSorted_reco[L1placement[j]]->setBinEntries(L1bincounter_reco[L1placement[j]] + 1, 1);
0450         hL1EffSorted_reco[L1placement[j]]->setBinError(L1bincounter_reco[L1placement[j]] + 1,
0451                                                        hL1_reco->GetBinError(j + 1));
0452         ++L1bincounter_reco[L1placement[j]];
0453       }
0454     }
0455     if (nL1bins != int(L1placement.size())) {
0456       value = nTotalAfterRecoCuts
0457                   ? (float)iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/L1Paths_" + reco_dirs[i])
0458                             ->getBinContent(nL1bins) /
0459                         nTotalAfterRecoCuts
0460                   : 0;
0461       error = nTotalAfterRecoCuts ? sqrt(value * (1 - value) / nTotalAfterRecoCuts) : 0;
0462       hL1EffAfterRecoCuts->setBinContent(nL1bins, value);
0463       hL1EffAfterRecoCuts->setBinEntries(nL1bins, 1);
0464       hL1EffAfterRecoCuts->setBinError(nL1bins, error);
0465     }
0466     for (unsigned int j = 0; j < Hltplacement.size(); j++) {
0467       value = nTotalAfterRecoCuts
0468                   ? (float)iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/HltPaths_" + reco_dirs[i])
0469                             ->getBinContent(j + 1) /
0470                         nTotalAfterRecoCuts
0471                   : 0;
0472       error = nTotalAfterRecoCuts ? sqrt(value * (1 - value) / nTotalAfterRecoCuts) : 0;
0473       hHltEffAfterRecoCuts->setBinContent(j + 1, value);
0474       hHltEffAfterRecoCuts->setBinEntries(j + 1, 1);
0475       hHltEffAfterRecoCuts->setBinError(j + 1, error);
0476       if (Hltplacement[j] != -1) {
0477         hHltEffSorted_reco[Hltplacement[j]]->setBinLabel(Hltbincounter_reco[Hltplacement[j]] + 1,
0478                                                          hHlt_reco->GetXaxis()->GetBinLabel(j + 1));
0479         hHltEffSorted_reco[Hltplacement[j]]->setBinContent(Hltbincounter_reco[Hltplacement[j]] + 1,
0480                                                            hHlt_reco->GetBinContent(j + 1));
0481         hHltEffSorted_reco[Hltplacement[j]]->setBinEntries(Hltbincounter_reco[Hltplacement[j]] + 1, 1);
0482         hHltEffSorted_reco[Hltplacement[j]]->setBinError(Hltbincounter_reco[Hltplacement[j]] + 1,
0483                                                          hHlt_reco->GetBinError(j + 1));
0484         ++Hltbincounter_reco[Hltplacement[j]];
0485       }
0486     }
0487     if (nHltbins != int(Hltplacement.size())) {
0488       value = nTotalAfterRecoCuts
0489                   ? (float)iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/HltPaths_" + reco_dirs[i])
0490                             ->getBinContent(nHltbins) /
0491                         nTotalAfterRecoCuts
0492                   : 0;
0493       error = nTotalAfterRecoCuts ? sqrt(value * (1 - value) / nTotalAfterRecoCuts) : 0;
0494       hHltEffAfterRecoCuts->setBinContent(nHltbins, value);
0495       hHltEffAfterRecoCuts->setBinEntries(nHltbins, 1);
0496       hHltEffAfterRecoCuts->setBinError(nHltbins, error);
0497     }
0498     LogDebug("HltSusyExoPostProcessor") << "MonitorElements filled";
0499   }
0500 
0501   int pt_bins = 100, eta_bins = 100;
0502   double pt_floor = 0., pt_ceiling = 200., eta_floor = -3.5, eta_ceiling = 3.5;
0503   iBooker_.setCurrentFolder(subDir_ + byEventDir);
0504   MonitorElement *hPt_1_ByEvent = iBooker_.book1D(
0505       "Pt_1_ByEvent", "Turn on as a Function of P_{t}, |Eta|<1.2, By Event", pt_bins, pt_floor, pt_ceiling);
0506   MonitorElement *hEta_1_ByEvent = iBooker_.book1D(
0507       "Eta_1_ByEvent", "Efficiency as a Function of Eta, P_{t}>0, By Event", eta_bins, eta_floor, eta_ceiling);
0508   MonitorElement *hPt_2_ByEvent = iBooker_.book1D(
0509       "Pt_2_ByEvent", "Turn on as a Function of P_{t}, 1.2<|Eta|<2.1, By Event", pt_bins, pt_floor, pt_ceiling);
0510   MonitorElement *hEta_2_ByEvent = iBooker_.book1D(
0511       "Eta_2_ByEvent", "Efficiency as a Function of Eta, P_{t}>10, By Event", eta_bins, eta_floor, eta_ceiling);
0512   MonitorElement *hPt_3_ByEvent = iBooker_.book1D(
0513       "Pt_3_ByEvent", "Turn on as a Function of P_{t}, |Eta|>2.1, By Event", pt_bins, pt_floor, pt_ceiling);
0514   MonitorElement *hEta_3_ByEvent = iBooker_.book1D(
0515       "Eta_3_ByEvent", "Efficiency as a Function of Eta, P_{t}>20, By Event", eta_bins, eta_floor, eta_ceiling);
0516   iBooker_.setCurrentFolder(subDir_ + byMuonDir);
0517   MonitorElement *hPt_1_ByMuon = iBooker_.book1D(
0518       "Pt_1_ByMuon", "Turn on as a Function of P_{t}, |Eta|<1.2, By Muon", pt_bins, pt_floor, pt_ceiling);
0519   MonitorElement *hEta_1_ByMuon = iBooker_.book1D(
0520       "Eta_1_ByMuon", "Efficiency as a Function of Eta, P_{t}>0, By Muon", eta_bins, eta_floor, eta_ceiling);
0521   MonitorElement *hPt_2_ByMuon = iBooker_.book1D(
0522       "Pt_2_ByMuon", "Turn on as a Function of P_{t}, 1.2<|Eta|<2.1, By Muon", pt_bins, pt_floor, pt_ceiling);
0523   MonitorElement *hEta_2_ByMuon = iBooker_.book1D(
0524       "Eta_2_ByMuon", "Efficiency as a Function of Eta, P_{t}>10, By Muon", eta_bins, eta_floor, eta_ceiling);
0525   MonitorElement *hPt_3_ByMuon = iBooker_.book1D(
0526       "Pt_3_ByMuon", "Turn on as a Function of P_{t}, |Eta|>2.1, By Muon", pt_bins, pt_floor, pt_ceiling);
0527   MonitorElement *hEta_3_ByMuon = iBooker_.book1D(
0528       "Eta_3_ByMuon", "Efficiency as a Function of Eta, P_{t}>20, By Muon", eta_bins, eta_floor, eta_ceiling);
0529 
0530   for (int i = 1; i <= hPt_1_ByEvent->getNbinsX(); ++i) {
0531     double n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonPt_1_ByEvent")->getBinContent(i);
0532     double n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonPt_1_ByEvent")->getBinContent(i);
0533     double value = (n2 != 0 ? n1 / n2 : 0);
0534     double error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0535     hPt_1_ByEvent->setBinContent(i, value);
0536     hPt_1_ByEvent->setBinError(i, error);
0537 
0538     n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonPt_2_ByEvent")->getBinContent(i);
0539     n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonPt_2_ByEvent")->getBinContent(i);
0540     value = (n2 != 0 ? n1 / n2 : 0);
0541     error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0542     hPt_2_ByEvent->setBinContent(i, value);
0543     hPt_2_ByEvent->setBinError(i, error);
0544 
0545     n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonPt_3_ByEvent")->getBinContent(i);
0546     n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonPt_3_ByEvent")->getBinContent(i);
0547     value = (n2 != 0 ? n1 / n2 : 0);
0548     error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0549     hPt_3_ByEvent->setBinContent(i, value);
0550     hPt_3_ByEvent->setBinError(i, error);
0551 
0552     n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonPt_1_ByMuon")->getBinContent(i);
0553     n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonPt_1_ByMuon")->getBinContent(i);
0554     value = (n2 != 0 ? n1 / n2 : 0);
0555     error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0556     hPt_1_ByMuon->setBinContent(i, value);
0557     hPt_1_ByMuon->setBinError(i, error);
0558 
0559     n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonPt_2_ByMuon")->getBinContent(i);
0560     n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonPt_2_ByMuon")->getBinContent(i);
0561     value = (n2 != 0 ? n1 / n2 : 0);
0562     error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0563     hPt_2_ByMuon->setBinContent(i, value);
0564     hPt_2_ByMuon->setBinError(i, error);
0565 
0566     n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonPt_3_ByMuon")->getBinContent(i);
0567     n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonPt_3_ByMuon")->getBinContent(i);
0568     value = (n2 != 0 ? n1 / n2 : 0);
0569     error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0570     hPt_3_ByMuon->setBinContent(i, value);
0571     hPt_3_ByMuon->setBinError(i, error);
0572   }
0573 
0574   for (int i = 1; i <= hEta_1_ByEvent->getNbinsX(); ++i) {
0575     double n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonEta_1_ByEvent")->getBinContent(i);
0576     double n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonEta_1_ByEvent")->getBinContent(i);
0577     double value = (n2 != 0 ? n1 / n2 : 0);
0578     double error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0579     hEta_1_ByEvent->setBinContent(i, value);
0580     hEta_1_ByEvent->setBinError(i, error);
0581 
0582     n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonEta_2_ByEvent")->getBinContent(i);
0583     n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonEta_2_ByEvent")->getBinContent(i);
0584     value = (n2 != 0 ? n1 / n2 : 0);
0585     error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0586     hEta_2_ByEvent->setBinContent(i, value);
0587     hEta_2_ByEvent->setBinError(i, error);
0588 
0589     n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonEta_3_ByEvent")->getBinContent(i);
0590     n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonEta_3_ByEvent")->getBinContent(i);
0591     value = (n2 != 0 ? n1 / n2 : 0);
0592     error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0593     hEta_3_ByEvent->setBinContent(i, value);
0594     hEta_3_ByEvent->setBinError(i, error);
0595 
0596     n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonEta_1_ByMuon")->getBinContent(i);
0597     n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonEta_1_ByMuon")->getBinContent(i);
0598     value = (n2 != 0 ? n1 / n2 : 0);
0599     error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0600     hEta_1_ByMuon->setBinContent(i, value);
0601     hEta_1_ByMuon->setBinError(i, error);
0602 
0603     n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonEta_2_ByMuon")->getBinContent(i);
0604     n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonEta_2_ByMuon")->getBinContent(i);
0605     value = (n2 != 0 ? n1 / n2 : 0);
0606     error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0607     hEta_2_ByMuon->setBinContent(i, value);
0608     hEta_2_ByMuon->setBinError(i, error);
0609 
0610     n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonEta_3_ByMuon")->getBinContent(i);
0611     n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonEta_3_ByMuon")->getBinContent(i);
0612     value = (n2 != 0 ? n1 / n2 : 0);
0613     error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
0614     hEta_3_ByMuon->setBinContent(i, value);
0615     hEta_3_ByMuon->setBinError(i, error);
0616   }
0617 }
0618 
0619 HltSusyExoPostProcessor::MonitorElement *HltSusyExoPostProcessor::bookEffMEProfileFromTH1(TH1F *histo,
0620                                                                                           std::string name,
0621                                                                                           DQMStore::IBooker &iBooker_) {
0622   MonitorElement *myEffME;
0623   if (name == "Eff") {
0624     myEffME = iBooker_.bookProfile((std::string)("Eff_" + ((std::string)histo->GetName())),
0625                                    ((std::string)histo->GetTitle()),
0626                                    histo->GetXaxis()->GetNbins(),
0627                                    histo->GetXaxis()->GetXmin(),
0628                                    histo->GetXaxis()->GetXmax(),
0629                                    100,
0630                                    0,
0631                                    1,
0632                                    "");
0633   } else {
0634     myEffME = iBooker_.bookProfile(name,
0635                                    new TProfile(name.c_str(),
0636                                                 histo->GetTitle(),
0637                                                 histo->GetXaxis()->GetNbins(),
0638                                                 histo->GetXaxis()->GetXmin(),
0639                                                 histo->GetXaxis()->GetXmax()));
0640   }
0641   for (int i = 0; i < histo->GetXaxis()->GetNbins(); i++) {
0642     myEffME->setBinLabel(i + 1, histo->GetXaxis()->GetBinLabel(i + 1), 1);
0643   }
0644   return myEffME;
0645 }
0646 
0647 DEFINE_FWK_MODULE(HltSusyExoPostProcessor);