Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /** \file HLTExoticaPlotter.cc
0002  */
0003 
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 
0006 #include "HLTriggerOffline/Exotica/interface/HLTExoticaPlotter.h"
0007 #include "HLTriggerOffline/Exotica/interface/HLTExoticaSubAnalysis.h"
0008 #include "HLTriggerOffline/Exotica/src/EVTColContainer.cc"
0009 
0010 #include "TPRegexp.h"
0011 
0012 #include "HLTriggerOffline/Exotica/src/EVTColContainer.cc"
0013 
0014 #include <cctype>
0015 #include <set>
0016 
0017 HLTExoticaPlotter::HLTExoticaPlotter(const edm::ParameterSet &pset,
0018                                      const std::string &hltPath,
0019                                      const std::vector<unsigned int> &objectsType)
0020     : _hltPath(hltPath),
0021       _hltProcessName(pset.getParameter<std::string>("hltProcessName")),
0022       _objectsType(std::set<unsigned int>(objectsType.begin(), objectsType.end())),
0023       _nObjects(objectsType.size()),
0024       _parametersEta(pset.getParameter<std::vector<double>>("parametersEta")),
0025       _parametersPhi(pset.getParameter<std::vector<double>>("parametersPhi")),
0026       _parametersTurnOn(pset.getParameter<std::vector<double>>("parametersTurnOn")),
0027       _parametersTurnOnSumEt(pset.getParameter<std::vector<double>>("parametersTurnOnSumEt")),
0028       _parametersDxy(pset.getParameter<std::vector<double>>("parametersDxy")),
0029       _drop_pt2(false),
0030       _drop_pt3(false) {
0031   if (pset.exists("dropPt2")) {
0032     _drop_pt2 = pset.getParameter<bool>("dropPt2");
0033   }
0034   if (pset.exists("dropPt3")) {
0035     _drop_pt3 = pset.getParameter<bool>("dropPt3");
0036   }
0037   LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::constructor()";
0038 }
0039 
0040 HLTExoticaPlotter::~HLTExoticaPlotter() {}
0041 
0042 void HLTExoticaPlotter::beginJob() {}
0043 
0044 void HLTExoticaPlotter::plotterBookHistos(DQMStore::IBooker &iBooker,
0045                                           const edm::Run &iRun,
0046                                           const edm::EventSetup &iSetup) {
0047   LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::plotterBookHistos()";
0048   for (std::set<unsigned int>::iterator it = _objectsType.begin(); it != _objectsType.end(); ++it) {
0049     std::vector<std::string> sources(2);
0050     sources[0] = "gen";
0051     sources[1] = "rec";
0052 
0053     const std::string objTypeStr = EVTColContainer::getTypeString(*it);
0054 
0055     for (size_t i = 0; i < sources.size(); i++) {
0056       std::string source = sources[i];
0057 
0058       if (source == "gen") {
0059         if (TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT") ||
0060             TString(objTypeStr).Contains("Jet")) {
0061           continue;
0062         } else {
0063           bookHist(iBooker, source, objTypeStr, "MaxPt1");
0064           if (!_drop_pt2)
0065             bookHist(iBooker, source, objTypeStr, "MaxPt2");
0066           if (!_drop_pt3)
0067             bookHist(iBooker, source, objTypeStr, "MaxPt3");
0068           bookHist(iBooker, source, objTypeStr, "Eta");
0069           bookHist(iBooker, source, objTypeStr, "Phi");
0070 
0071           // If the target is electron or muon,
0072           // we will add Dxy plots.
0073           if (*it == EVTColContainer::ELEC || *it == EVTColContainer::MUON || *it == EVTColContainer::MUTRK) {
0074             bookHist(iBooker, source, objTypeStr, "Dxy");
0075           }
0076         }
0077       } else {  // reco
0078         if (TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT")) {
0079           bookHist(iBooker, source, objTypeStr, "MaxPt1");
0080           bookHist(iBooker, source, objTypeStr, "SumEt");
0081         } else {
0082           bookHist(iBooker, source, objTypeStr, "MaxPt1");
0083           if (!_drop_pt2)
0084             bookHist(iBooker, source, objTypeStr, "MaxPt2");
0085           if (!_drop_pt3)
0086             bookHist(iBooker, source, objTypeStr, "MaxPt3");
0087           bookHist(iBooker, source, objTypeStr, "Eta");
0088           bookHist(iBooker, source, objTypeStr, "Phi");
0089 
0090           // If the target is electron or muon,
0091           // we will add Dxy plots.
0092           if (*it == EVTColContainer::ELEC || *it == EVTColContainer::MUON || *it == EVTColContainer::MUTRK) {
0093             bookHist(iBooker, source, objTypeStr, "Dxy");
0094           }
0095         }
0096       }
0097     }
0098   }
0099 }
0100 
0101 void HLTExoticaPlotter::analyze(const bool &isPassTrigger,
0102                                 const std::string &source,
0103                                 const std::vector<reco::LeafCandidate> &matches,
0104                                 std::map<int, double> theSumEt,
0105                                 std::vector<float> &dxys) {
0106   LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::analyze()";
0107   if (!isPassTrigger) {
0108     return;
0109   }
0110 
0111   std::map<unsigned int, int> countobjects;
0112   // Initializing the count of the used object
0113   for (std::set<unsigned int>::iterator co = _objectsType.begin(); co != _objectsType.end(); ++co) {
0114     countobjects[*co] = 0;
0115   }
0116 
0117   int counttotal = 0;
0118 
0119   // 3 : pt1, pt2, pt3
0120   int totalobjectssize = 1;
0121   if (!_drop_pt2)
0122     totalobjectssize++;
0123   if (!_drop_pt3)
0124     totalobjectssize++;
0125   totalobjectssize *= countobjects.size();
0126   // Fill the histos if pass the trigger (just the two with higher pt)
0127   unsigned int jaux = 0;
0128   // jaux is being used as a dedicated counter to avoid getting
0129   // a non-existent element inside dxys
0130   // more information in the issue https://github.com/cms-sw/cmssw/issues/32550
0131   for (size_t j = 0; j < matches.size(); ++j) {
0132     // Is this object owned by this trigger? If not we are not interested...
0133     if (_objectsType.find(matches[j].pdgId()) == _objectsType.end()) {
0134       ++jaux;
0135       continue;
0136     }
0137 
0138     const unsigned int objType = matches[j].pdgId();
0139     const std::string objTypeStr = EVTColContainer::getTypeString(objType);
0140 
0141     float pt = matches[j].pt();
0142     float eta = matches[j].eta();
0143     float phi = matches[j].phi();
0144 
0145     if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
0146       this->fillHist(isPassTrigger, source, objTypeStr, "Eta", eta);
0147       this->fillHist(isPassTrigger, source, objTypeStr, "Phi", phi);
0148     } else if (source != "gen") {
0149       if (theSumEt[objType] >= 0 && countobjects[objType] == 0) {
0150         this->fillHist(isPassTrigger, source, objTypeStr, "SumEt", theSumEt[objType]);
0151       }
0152     }
0153 
0154     if (!dxys.empty() &&
0155         (objType == EVTColContainer::ELEC || objType == EVTColContainer::MUON || objType == EVTColContainer::MUTRK)) {
0156       this->fillHist(isPassTrigger, source, objTypeStr, "Dxy", dxys[jaux]);
0157       ++jaux;
0158     }
0159 
0160     if (countobjects[objType] == 0) {
0161       if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT")) || source != "gen") {
0162         this->fillHist(isPassTrigger, source, objTypeStr, "MaxPt1", pt);
0163       }
0164       // Filled the high pt ...
0165       ++(countobjects[objType]);
0166       ++counttotal;
0167     } else if (countobjects[objType] == 1 && !_drop_pt2) {
0168       if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
0169         this->fillHist(isPassTrigger, source, objTypeStr, "MaxPt2", pt);
0170       }
0171       // Filled the second high pt ...
0172       ++(countobjects[objType]);
0173       ++counttotal;
0174     } else if (countobjects[objType] == 2 && !_drop_pt3) {
0175       if (!(TString(objTypeStr).Contains("MET") || TString(objTypeStr).Contains("MHT"))) {
0176         this->fillHist(isPassTrigger, source, objTypeStr, "MaxPt3", pt);
0177       }
0178       // Filled the third highest pt ...
0179       ++(countobjects[objType]);
0180       ++counttotal;
0181     } else {
0182       if (counttotal == totalobjectssize) {
0183         break;
0184       }
0185     }
0186 
0187   }  // end loop over matches
0188 }
0189 
0190 void HLTExoticaPlotter::bookHist(DQMStore::IBooker &iBooker,
0191                                  const std::string &source,
0192                                  const std::string &objType,
0193                                  const std::string &variable) {
0194   LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::bookHist()";
0195   std::string sourceUpper = source;
0196   sourceUpper[0] = std::toupper(sourceUpper[0]);
0197   std::string name = source + objType + variable + "_" + _hltPath;
0198   TH1F *h = nullptr;
0199 
0200   if (variable.find("SumEt") != std::string::npos) {
0201     std::string title = "Sum ET of " + sourceUpper + " " + objType;
0202     const size_t nBins = _parametersTurnOnSumEt.size() - 1;
0203     float *edges = new float[nBins + 1];
0204     for (size_t i = 0; i < nBins + 1; i++) {
0205       edges[i] = _parametersTurnOnSumEt[i];
0206     }
0207     h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
0208     delete[] edges;
0209   } else if (variable.find("Dxy") != std::string::npos) {
0210     std::string title = "Dxy " + sourceUpper + " " + objType;
0211     int nBins = _parametersDxy[0];
0212     double min = _parametersDxy[1];
0213     double max = _parametersDxy[2];
0214     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
0215   } else if (variable.find("MaxPt") != std::string::npos) {
0216     std::string desc;  //=
0217     //        (variable == "MaxPt1") ? "Leading" : (variable == "MaxPt2") ? "Next-to-Leading" : "Next-to-next-to-Leading";
0218     if (variable == "MaxPt1") {
0219       desc = "Leading";
0220     } else if (variable == "MaxPt2") {
0221       desc = "Next-to-Leading";
0222     } else {
0223       desc = "Next-to-next-to-Leading";
0224     }
0225     std::string title = "pT of " + desc + " " + sourceUpper + " " + objType +
0226                         " "
0227                         "where event pass the " +
0228                         _hltPath;
0229     const size_t nBins = _parametersTurnOn.size() - 1;
0230     float *edges = new float[nBins + 1];
0231     for (size_t i = 0; i < nBins + 1; i++) {
0232       edges[i] = _parametersTurnOn[i];
0233     }
0234     h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
0235     delete[] edges;
0236   }
0237 
0238   else {
0239     std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
0240     std::string title = symbol + " of " + sourceUpper + " " + objType + " " + "where event pass the " + _hltPath;
0241     std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
0242 
0243     int nBins = (int)params[0];
0244     double min = params[1];
0245     double max = params[2];
0246     h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
0247   }
0248 
0249   h->Sumw2();
0250   _elements[name] = iBooker.book1D(name, h);
0251   //    LogDebug("ExoticaValidation") << "                        booked histo
0252   //    with name " << name << "\n"
0253   //                  << "                        at location " <<
0254   //(unsigned long int)_elements[name];
0255   delete h;
0256 }
0257 
0258 void HLTExoticaPlotter::fillHist(const bool &passTrigger,
0259                                  const std::string &source,
0260                                  const std::string &objType,
0261                                  const std::string &variable,
0262                                  const float &value) {
0263   std::string sourceUpper = source;
0264   sourceUpper[0] = toupper(sourceUpper[0]);
0265   std::string name = source + objType + variable + "_" + _hltPath;
0266 
0267   LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::fillHist()" << name << " " << value;
0268   _elements[name]->Fill(value);
0269   LogDebug("ExoticaValidation") << "In HLTExoticaPlotter::fillHist()" << name << " worked";
0270 }