Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:11

0001 #include "DQMOffline/PFTau/interface/Matchers.h"
0002 #include "DQMOffline/PFTau/interface/PFCandidateMonitor.h"
0003 #include "DataFormats/JetReco/interface/Jet.h"
0004 #include "DataFormats/JetReco/interface/PFJet.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 
0007 #include <TFile.h>
0008 #include <TH1.h>
0009 #include <TH2.h>
0010 #include <TROOT.h>
0011 
0012 //
0013 // -- Constructor
0014 //
0015 PFCandidateMonitor::PFCandidateMonitor(float dRMax, bool matchCharge, Benchmark::Mode mode)
0016     : Benchmark(mode), candBench_(mode), matchCandBench_(mode), dRMax_(dRMax), matchCharge_(matchCharge) {
0017   setRange(0.0, 10e10, -10.0, 10.0, -3.14, 3.14);
0018 
0019   pt_gen_ = nullptr;
0020   eta_gen_ = nullptr;
0021   phi_gen_ = nullptr;
0022 
0023   pt_ref_ = nullptr;
0024   eta_ref_ = nullptr;
0025   phi_ref_ = nullptr;
0026 
0027   deltaR_ = nullptr;
0028 
0029   createReferenceHistos_ = false;
0030   histogramBooked_ = false;
0031 }
0032 
0033 //
0034 // -- Destructor
0035 //
0036 PFCandidateMonitor::~PFCandidateMonitor() {}
0037 
0038 //
0039 // -- Set Parameters accessing them from ParameterSet
0040 //
0041 void PFCandidateMonitor::setParameters(const edm::ParameterSet &parameterSet) {
0042   dRMax_ = parameterSet.getParameter<double>("deltaRMax");
0043   matchCharge_ = parameterSet.getParameter<bool>("matchCharge");
0044   mode_ = (Benchmark::Mode)parameterSet.getParameter<int>("mode");
0045   createReferenceHistos_ = parameterSet.getParameter<bool>("CreateReferenceHistos");
0046   createEfficiencyHistos_ = parameterSet.getParameter<bool>("CreateEfficiencyHistos");
0047 
0048   setRange(parameterSet.getParameter<double>("ptMin"),
0049            parameterSet.getParameter<double>("ptMax"),
0050            parameterSet.getParameter<double>("etaMin"),
0051            parameterSet.getParameter<double>("etaMax"),
0052            parameterSet.getParameter<double>("phiMin"),
0053            parameterSet.getParameter<double>("phiMax"));
0054 
0055   candBench_.setParameters(mode_);
0056   matchCandBench_.setParameters(mode_);
0057 }
0058 
0059 //
0060 // -- Set Parameters
0061 //
0062 void PFCandidateMonitor::setParameters(float dRMax,
0063                                        bool matchCharge,
0064                                        Benchmark::Mode mode,
0065                                        float ptmin,
0066                                        float ptmax,
0067                                        float etamin,
0068                                        float etamax,
0069                                        float phimin,
0070                                        float phimax,
0071                                        bool refHistoFlag) {
0072   dRMax_ = dRMax;
0073   matchCharge_ = matchCharge;
0074   mode_ = mode;
0075   createReferenceHistos_ = refHistoFlag;
0076 
0077   setRange(ptmin, ptmax, etamin, etamax, phimin, phimax);
0078 
0079   candBench_.setParameters(mode_);
0080   matchCandBench_.setParameters(mode_);
0081 }
0082 
0083 //
0084 // -- Create histograms accessing parameters from ParameterSet
0085 //
0086 void PFCandidateMonitor::setup(DQMStore::IBooker &b, const edm::ParameterSet &parameterSet) {
0087   candBench_.setup(b, parameterSet);
0088   matchCandBench_.setup(b, parameterSet);
0089 
0090   if (createReferenceHistos_ && !histogramBooked_) {
0091     edm::ParameterSet ptPS = parameterSet.getParameter<edm::ParameterSet>("PtHistoParameter");
0092     edm::ParameterSet etaPS = parameterSet.getParameter<edm::ParameterSet>("EtaHistoParameter");
0093     edm::ParameterSet phiPS = parameterSet.getParameter<edm::ParameterSet>("PhiHistoParameter");
0094 
0095     edm::ParameterSet dR = parameterSet.getParameter<edm::ParameterSet>("DeltaRHistoParameter");
0096 
0097     if (ptPS.getParameter<bool>("switchOn")) {
0098       pt_ref_ = book1D(b,
0099                        "pt_ref_",
0100                        "p_{T}_ref;p_{T} (GeV)",
0101                        ptPS.getParameter<int32_t>("nBin"),
0102                        ptPS.getParameter<double>("xMin"),
0103                        ptPS.getParameter<double>("xMax"));
0104       if (createEfficiencyHistos_) {
0105         pt_gen_ = book1D(b,
0106                          "pt_gen_",
0107                          "p_{T}_gen;p_{T} (GeV)",
0108                          ptPS.getParameter<int32_t>("nBin"),
0109                          ptPS.getParameter<double>("xMin"),
0110                          ptPS.getParameter<double>("xMax"));
0111       }
0112     }
0113 
0114     if (etaPS.getParameter<bool>("switchOn")) {
0115       eta_ref_ = book1D(b,
0116                         "eta_ref_",
0117                         "#eta_ref;#eta",
0118                         etaPS.getParameter<int32_t>("nBin"),
0119                         etaPS.getParameter<double>("xMin"),
0120                         etaPS.getParameter<double>("xMax"));
0121       if (createEfficiencyHistos_) {
0122         eta_gen_ = book1D(b,
0123                           "eta_gen_",
0124                           "#eta_gen;#eta",
0125                           etaPS.getParameter<int32_t>("nBin"),
0126                           etaPS.getParameter<double>("xMin"),
0127                           etaPS.getParameter<double>("xMax"));
0128       }
0129     }
0130 
0131     if (phiPS.getParameter<bool>("switchOn")) {
0132       phi_ref_ = book1D(b,
0133                         "phi_ref_",
0134                         "#phi_ref;#phi",
0135                         phiPS.getParameter<int32_t>("nBin"),
0136                         phiPS.getParameter<double>("xMin"),
0137                         phiPS.getParameter<double>("xMax"));
0138       if (createEfficiencyHistos_) {
0139         phi_gen_ = book1D(b,
0140                           "phi_gen_",
0141                           "#phi_gen;#phi",
0142                           phiPS.getParameter<int32_t>("nBin"),
0143                           phiPS.getParameter<double>("xMin"),
0144                           phiPS.getParameter<double>("xMax"));
0145       }
0146     }
0147 
0148     if (createEfficiencyHistos_ && dR.getParameter<bool>("switchOn")) {
0149       deltaR_ = book1D(b,
0150                        "deltaR_",
0151                        "#DeltaR;#DeltaR",
0152                        dR.getParameter<int32_t>("nBin"),
0153                        dR.getParameter<double>("xMin"),
0154                        dR.getParameter<double>("xMax"));
0155     }
0156 
0157     histogramBooked_ = true;
0158   }
0159 }
0160 
0161 //
0162 // -- Create histograms using local parameters
0163 //
0164 void PFCandidateMonitor::setup(DQMStore::IBooker &b) {
0165   candBench_.setup(b);
0166   matchCandBench_.setup(b);
0167 
0168   if (createReferenceHistos_ && !histogramBooked_) {
0169     PhaseSpace ptPS(100, 0, 100);
0170     PhaseSpace phiPS(360, -3.1416, 3.1416);
0171     PhaseSpace etaPS(100, -5, 5);
0172 
0173     pt_ref_ = book1D(b, "pt_ref_", "p_{T}_ref;p_{T} (GeV)", ptPS.n, ptPS.m, ptPS.M);
0174     if (createEfficiencyHistos_) {
0175       pt_gen_ = book1D(b, "pt_gen_", "p_{T}_gen;p_{T} (GeV)", ptPS.n, ptPS.m, ptPS.M);
0176     }
0177 
0178     eta_ref_ = book1D(b, "eta_ref_", "#eta_ref;#eta", etaPS.n, etaPS.m, etaPS.M);
0179     if (createEfficiencyHistos_) {
0180       eta_gen_ = book1D(b, "eta_gen_", "#eta_gen;#eta", etaPS.n, etaPS.m, etaPS.M);
0181     }
0182 
0183     phi_ref_ = book1D(b, "phi_ref_", "#phi_ref;#phi", phiPS.n, phiPS.m, phiPS.M);
0184     if (createEfficiencyHistos_) {
0185       phi_gen_ = book1D(b, "phi_gen_", "#phi_gen;#phi", phiPS.n, phiPS.m, phiPS.M);
0186     }
0187 
0188     histogramBooked_ = true;
0189   }
0190 }
0191 
0192 //
0193 // -- Set directory to book histograms using ROOT
0194 //
0195 void PFCandidateMonitor::setDirectory(TDirectory *dir) {
0196   Benchmark::setDirectory(dir);
0197 
0198   candBench_.setDirectory(dir);
0199   matchCandBench_.setDirectory(dir);
0200 }
0201 
0202 //
0203 // -- fill histograms for a single collection
0204 //
0205 void PFCandidateMonitor::fillOne(const reco::Candidate &cand) {
0206   if (matching_done_) {
0207     if (createReferenceHistos_ && histogramBooked_) {
0208       if (pt_ref_)
0209         pt_ref_->Fill(cand.pt());
0210       if (eta_ref_)
0211         eta_ref_->Fill(cand.eta());
0212       if (phi_ref_)
0213         phi_ref_->Fill(cand.phi());
0214     }
0215   } else if (createEfficiencyHistos_ && histogramBooked_) {
0216     if (pt_gen_)
0217       pt_gen_->Fill(cand.pt());
0218     if (eta_gen_)
0219       eta_gen_->Fill(cand.eta());
0220     if (phi_gen_)
0221       phi_gen_->Fill(cand.phi());
0222   }
0223 }