Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:45

0001 #include "DQMOffline/PFTau/interface/Matchers.h"
0002 #include "DQMOffline/PFTau/interface/PFJetMonitor.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 PFJetMonitor::PFJetMonitor(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   delta_frac_VS_frac_muon_ = nullptr;
0020   delta_frac_VS_frac_photon_ = nullptr;
0021   delta_frac_VS_frac_electron_ = nullptr;
0022   delta_frac_VS_frac_charged_hadron_ = nullptr;
0023   delta_frac_VS_frac_neutral_hadron_ = nullptr;
0024 
0025   deltaR_ = nullptr;
0026 
0027   createPFractionHistos_ = false;
0028   histogramBooked_ = false;
0029 }
0030 
0031 //
0032 // -- Destructor
0033 //
0034 PFJetMonitor::~PFJetMonitor() {}
0035 
0036 //
0037 // -- Set Parameters accessing them from ParameterSet
0038 //
0039 void PFJetMonitor::setParameters(const edm::ParameterSet &parameterSet) {
0040   dRMax_ = parameterSet.getParameter<double>("deltaRMax");
0041   onlyTwoJets_ = parameterSet.getParameter<bool>("onlyTwoJets");
0042   matchCharge_ = parameterSet.getParameter<bool>("matchCharge");
0043   mode_ = (Benchmark::Mode)parameterSet.getParameter<int>("mode");
0044   createPFractionHistos_ = parameterSet.getParameter<bool>("CreatePFractionHistos");
0045 
0046   setRange(parameterSet.getParameter<double>("ptMin"),
0047            parameterSet.getParameter<double>("ptMax"),
0048            parameterSet.getParameter<double>("etaMin"),
0049            parameterSet.getParameter<double>("etaMax"),
0050            parameterSet.getParameter<double>("phiMin"),
0051            parameterSet.getParameter<double>("phiMax"));
0052 
0053   candBench_.setParameters(mode_);
0054   candBench_.setRange(parameterSet.getParameter<double>("ptMin"),
0055                       parameterSet.getParameter<double>("ptMax"),
0056                       parameterSet.getParameter<double>("etaMin"),
0057                       parameterSet.getParameter<double>("etaMax"),
0058                       parameterSet.getParameter<double>("phiMin"),
0059                       parameterSet.getParameter<double>("phiMax"));
0060 
0061   matchCandBench_.setParameters(mode_);
0062   matchCandBench_.setRange(parameterSet.getParameter<double>("ptMin"),
0063                            parameterSet.getParameter<double>("ptMax"),
0064                            parameterSet.getParameter<double>("etaMin"),
0065                            parameterSet.getParameter<double>("etaMax"),
0066                            parameterSet.getParameter<double>("phiMin"),
0067                            parameterSet.getParameter<double>("phiMax"));
0068 }
0069 
0070 //
0071 // -- Create histograms accessing parameters from ParameterSet
0072 //
0073 void PFJetMonitor::setup(DQMStore::IBooker &b, const edm::ParameterSet &parameterSet) {
0074   candBench_.setup(b, parameterSet);
0075   matchCandBench_.setup(b, parameterSet);
0076 
0077   edm::ParameterSet dR = parameterSet.getParameter<edm::ParameterSet>("DeltaRHistoParameter");
0078   if (dR.getParameter<bool>("switchOn")) {
0079     deltaR_ = book1D(b,
0080                      "deltaR_",
0081                      "#DeltaR;#DeltaR",
0082                      dR.getParameter<int32_t>("nBin"),
0083                      dR.getParameter<double>("xMin"),
0084                      dR.getParameter<double>("xMax"));
0085   }
0086   if (createPFractionHistos_ && !histogramBooked_) {
0087     delta_frac_VS_frac_muon_ =
0088         book2D(b, "delta_frac_VS_frac_muon_", "#DeltaFraction_Vs_Fraction(muon)", 100, 0.0, 1.0, 100, -1.0, 1.0);
0089     delta_frac_VS_frac_photon_ =
0090         book2D(b, "delta_frac_VS_frac_photon_", "#DeltaFraction_Vs_Fraction(photon)", 100, 0.0, 1.0, 100, -1.0, 1.0);
0091     delta_frac_VS_frac_electron_ = book2D(
0092         b, "delta_frac_VS_frac_electron_", "#DeltaFraction_Vs_Fraction(electron)", 100, 0.0, 1.0, 100, -1.0, 1.0);
0093     delta_frac_VS_frac_charged_hadron_ = book2D(b,
0094                                                 "delta_frac_VS_frac_charged_hadron_",
0095                                                 "#DeltaFraction_Vs_Fraction(charged hadron)",
0096                                                 100,
0097                                                 0.0,
0098                                                 1.0,
0099                                                 100,
0100                                                 -1.0,
0101                                                 1.0);
0102     delta_frac_VS_frac_neutral_hadron_ = book2D(b,
0103                                                 "delta_frac_VS_frac_neutral_hadron_",
0104                                                 "#DeltaFraction_Vs_Fraction(neutral hadron)",
0105                                                 100,
0106                                                 0.0,
0107                                                 1.0,
0108                                                 100,
0109                                                 -1.0,
0110                                                 1.0);
0111 
0112     histogramBooked_ = true;
0113   }
0114 }
0115 
0116 //
0117 // -- Create histograms using local parameters
0118 //
0119 void PFJetMonitor::setup(DQMStore::IBooker &b) {
0120   candBench_.setup(b);
0121   matchCandBench_.setup(b);
0122 
0123   if (createPFractionHistos_ && !histogramBooked_) {
0124     delta_frac_VS_frac_muon_ =
0125         book2D(b, "delta_frac_VS_frac_muon_", "#DeltaFraction_Vs_Fraction(muon)", 100, 0.0, 1.0, 100, -1.0, 1.0);
0126     delta_frac_VS_frac_photon_ =
0127         book2D(b, "delta_frac_VS_frac_photon_", "#DeltaFraction_Vs_Fraction(photon)", 100, 0.0, 1.0, 100, -1.0, 1.0);
0128     delta_frac_VS_frac_electron_ = book2D(
0129         b, "delta_frac_VS_frac_electron_", "#DeltaFraction_Vs_Fraction(electron)", 100, 0.0, 1.0, 100, -1.0, 1.0);
0130     delta_frac_VS_frac_charged_hadron_ = book2D(b,
0131                                                 "delta_frac_VS_frac_charged_hadron_",
0132                                                 "#DeltaFraction_Vs_Fraction(charged hadron)",
0133                                                 100,
0134                                                 0.0,
0135                                                 1.0,
0136                                                 100,
0137                                                 -1.0,
0138                                                 1.0);
0139     delta_frac_VS_frac_neutral_hadron_ = book2D(b,
0140                                                 "delta_frac_VS_frac_neutral_hadron_",
0141                                                 "#DeltaFraction_Vs_Fraction(neutral hadron)",
0142                                                 100,
0143                                                 0.0,
0144                                                 1.0,
0145                                                 100,
0146                                                 -1.0,
0147                                                 1.0);
0148 
0149     histogramBooked_ = true;
0150   }
0151 }
0152 
0153 //
0154 // -- Set directory to book histograms using ROOT
0155 //
0156 
0157 void PFJetMonitor::setDirectory(TDirectory *dir) {
0158   Benchmark::setDirectory(dir);
0159 
0160   candBench_.setDirectory(dir);
0161   matchCandBench_.setDirectory(dir);
0162 }
0163 
0164 //
0165 // -- fill histograms for a given Jet pair
0166 //
0167 void PFJetMonitor::fillOne(const reco::Jet &jet, const reco::Jet &matchedJet) {
0168   const reco::PFJet *pfJet = dynamic_cast<const reco::PFJet *>(&jet);
0169   const reco::PFJet *pfMatchedJet = dynamic_cast<const reco::PFJet *>(&matchedJet);
0170   if (pfJet && pfMatchedJet && createPFractionHistos_) {
0171     float del_frac_muon = -99.9;
0172     float del_frac_elec = -99.9;
0173     float del_frac_phot = -99.9;
0174     float del_frac_ch_had = -99.9;
0175     float del_frac_neu_had = -99.9;
0176 
0177     int mult_muon = pfMatchedJet->muonMultiplicity();
0178     int mult_elec = pfMatchedJet->electronMultiplicity();
0179     int mult_phot = pfMatchedJet->photonMultiplicity();
0180     int mult_ch_had = pfMatchedJet->chargedHadronMultiplicity();
0181     int mult_neu_had = pfMatchedJet->neutralHadronMultiplicity();
0182 
0183     if (mult_muon > 0)
0184       del_frac_muon = (pfJet->muonMultiplicity() - mult_muon) * 1.0 / mult_muon;
0185     if (mult_elec > 0)
0186       del_frac_elec = (pfJet->electronMultiplicity() - mult_elec) * 1.0 / mult_elec;
0187     if (mult_phot > 0)
0188       del_frac_phot = (pfJet->photonMultiplicity() - mult_phot) * 1.0 / mult_phot;
0189     if (mult_ch_had > 0)
0190       del_frac_ch_had = (pfJet->chargedHadronMultiplicity() - mult_ch_had) * 1.0 / mult_ch_had;
0191     if (mult_neu_had > 0)
0192       del_frac_neu_had = (pfJet->neutralHadronMultiplicity() - mult_neu_had) * 1.0 / mult_neu_had;
0193 
0194     delta_frac_VS_frac_muon_->Fill(mult_muon, del_frac_muon);
0195     delta_frac_VS_frac_electron_->Fill(mult_elec, del_frac_elec);
0196     delta_frac_VS_frac_photon_->Fill(mult_phot, del_frac_phot);
0197     delta_frac_VS_frac_charged_hadron_->Fill(mult_ch_had, del_frac_ch_had);
0198     delta_frac_VS_frac_neutral_hadron_->Fill(mult_neu_had, del_frac_neu_had);
0199   }
0200 }