CMS 3D CMS Logo

PFJetMonitor.h
Go to the documentation of this file.
1 #ifndef DQMOffline_PFTau_PFJetMonitor_h
2 #define DQMOffline_PFTau_PFJetMonitor_h
3 
8 
10 
11 #include <vector>
12 #include <numeric> // std::iota
13 #include <algorithm> // std::sort
14 
15 #include <TH1.h> //needed by the deltaR->Fill() call
16 
17 class PFJetMonitor : public Benchmark {
18 public:
20 
21  ~PFJetMonitor() override;
22 
25 
27  void setDirectory(TDirectory *dir) override;
28 
30  void setup(DQMStore::IBooker &b);
32 
34  template <class T, class C>
35  void fill(const T &candidateCollection,
36  const C &matchedCandCollection,
37  float &minVal,
38  float &maxVal,
39  float &jetpT,
41 
42  void fillOne(const reco::Jet &jet, const reco::Jet &matchedJet);
43 
44 protected:
47 
53 
54  TH1F *deltaR_;
55  float dRMax_;
60 };
61 
63 
64 template <class T, class C>
66  const C &matchedJetCollection,
67  float &minVal,
68  float &maxVal,
69  float &jetpT,
71  std::vector<int> matchIndices;
72  PFB::match(jetCollection, matchedJetCollection, matchIndices, matchCharge_, dRMax_);
73  // now matchIndices[i] stores the j-th closest matched jet
74 
75  std::vector<uint32_t> sorted_pt_indices(jetCollection.size());
76  std::iota(std::begin(sorted_pt_indices), std::end(sorted_pt_indices), 0);
77  // Sort the vector of indices using the pt() as ordering variable
78  std::sort(std::begin(sorted_pt_indices), std::end(sorted_pt_indices), [&](uint32_t i, uint32_t j) {
79  return jetCollection[i].pt() < jetCollection[j].pt();
80  });
81  for (uint32_t i = 0; i < sorted_pt_indices.size(); ++i) {
82  // If we want only the 2 pt-leading jets, now that they are orderd, simply
83  // check if the index is either in the first or second location of the
84  // sorted indices: if not, bail out.
85  if (onlyTwoJets_ && i > 1)
86  break;
87 
88  const reco::Jet &jet = jetCollection[i];
89 
90  if (!isInRange(jet.pt(), jet.eta(), jet.phi()))
91  continue;
92 
93  int iMatch = matchIndices[i];
94  assert(iMatch < static_cast<int>(matchedJetCollection.size()));
95 
96  if (iMatch != -1) {
97  const reco::Jet &matchedJet = matchedJetCollection[iMatch];
98  if (!isInRange(matchedJet.pt(), matchedJet.eta(), matchedJet.phi()))
99  continue;
100 
101  float ptRes = (jet.pt() - matchedJet.pt()) / matchedJet.pt();
102 
103  jetpT = jet.pt();
104  if (ptRes > maxVal)
105  maxVal = ptRes;
106  if (ptRes < minVal)
107  minVal = ptRes;
108 
109  candBench_.fillOne(jet); // fill pt eta phi and charge histos for MATCHED candidate jet
110  matchCandBench_.fillOne(jet, matchedJet, parameterSet); // fill delta_x_VS_y histos for matched couple
112  fillOne(jet, matchedJet); // book and fill delta_frac_VS_frac histos for matched couple
113  }
114 
115  for (unsigned j = 0; j < matchedJetCollection.size(); ++j) // for DeltaR spectrum
116  if (deltaR_)
117  deltaR_->Fill(reco::deltaR(jetCollection[i], matchedJetCollection[j]));
118  } // end loop on jetCollection
119 }
120 #endif
void setDirectory(TDirectory *dir) override
set directory (to use in ROOT)
void fill(const T &candidateCollection, const C &matchedCandCollection, float &minVal, float &maxVal, float &jetpT, const edm::ParameterSet &parameterSet)
fill histograms with all particle
Definition: PFJetMonitor.h:65
bool histogramBooked_
Definition: PFJetMonitor.h:59
To plot Candidate quantities.
void fillOne(const reco::Candidate &candidate, const reco::Candidate &matchedCandidate)
fill histograms with a given particle
To plot Candidate quantities.
double pt() const final
transverse momentum
CandidateBenchmark candBench_
Definition: PFJetMonitor.h:45
void match(const C &candCollection, const M &matchedCandCollection, std::vector< int > &matchIndices, bool matchCharge=false, float dRMax=-1)
Definition: Matchers.h:17
void fillOne(const reco::Candidate &candidate)
fill histograms with a given particle
Base class for all types of Jets.
Definition: Jet.h:20
abstract base class
Definition: Benchmark.h:19
bool createPFractionHistos_
Definition: PFJetMonitor.h:58
TH2F * delta_frac_VS_frac_muon_
Definition: PFJetMonitor.h:48
MatchCandidateBenchmark matchCandBench_
Definition: PFJetMonitor.h:46
assert(be >=bs)
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
void setup(DQMStore::IBooker &b)
book histograms
TH2F * delta_frac_VS_frac_neutral_hadron_
Definition: PFJetMonitor.h:52
bool onlyTwoJets_
Definition: PFJetMonitor.h:56
PFJetMonitor(float dRMax=0.3, bool matchCharge=true, Benchmark::Mode mode=Benchmark::DEFAULT)
Definition: PFJetMonitor.cc:15
bool isInRange(float pt, float eta, float phi) const
Definition: Benchmark.h:50
void setParameters(const edm::ParameterSet &parameterSet)
set the parameters accessing them from ParameterSet
Definition: PFJetMonitor.cc:39
void fillOne(const reco::Jet &jet, const reco::Jet &matchedJet)
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
TH2F * delta_frac_VS_frac_photon_
Definition: PFJetMonitor.h:49
TH2F * delta_frac_VS_frac_electron_
Definition: PFJetMonitor.h:50
TH1F * deltaR_
Definition: PFJetMonitor.h:54
double b
Definition: hdecay.h:120
TH2F * delta_frac_VS_frac_charged_hadron_
Definition: PFJetMonitor.h:51
long double T
double phi() const final
momentum azimuthal angle
~PFJetMonitor() override
Definition: PFJetMonitor.cc:34
bool matchCharge_
Definition: PFJetMonitor.h:57
double eta() const final
momentum pseudorapidity