CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PFCandidateMonitor.h
Go to the documentation of this file.
1 #ifndef DQMOffline_PFTau_PFCandidateMonitor_h
2 #define DQMOffline_PFTau_PFCandidateMonitor_h
3 
8 
11 
12 #include <vector>
13 
14 #include <TH1.h> //needed by the deltaR->Fill() call
15 
16 class PFCandidateMonitor : public Benchmark {
17 public:
18  PFCandidateMonitor(float dRMax = 0.3, bool matchCharge = true, Benchmark::Mode mode = Benchmark::DEFAULT);
19 
20  ~PFCandidateMonitor() override;
21 
23  void setParameters(float dRMax,
24  bool matchCharge,
26  float ptmin,
27  float ptmax,
28  float etamin,
29  float etamax,
30  float phimin,
31  float phimax,
32  bool refHistoFlag);
33 
36 
38  void setDirectory(TDirectory *dir) override;
39 
41  void setup(DQMStore::IBooker &b);
42  void setup(DQMStore::IBooker &b, const edm::ParameterSet &parameterSet);
43 
45  template <class T, class C>
46  /*void fill(const T& candidateCollection,
47  const C& matchedCandCollection, float& minVal, float& maxVal) ;*/
48  void fill(const T &candidateCollection,
49  const C &matchedCandCollection,
50  float &minVal,
51  float &maxVal,
52  const edm::ParameterSet &parameterSet);
53  template <class T, class C, class M>
54  void fill(const T &candidateCollection,
55  const C &matchedCandCollection,
56  float &minVal,
57  float &maxVal,
58  const edm::ParameterSet &parameterSet,
59  const M &muonMatchedCandCollection);
60 
61  void fillOne(const reco::Candidate &cand);
62 
63 protected:
66 
67  TH1F *pt_gen_;
68  TH1F *eta_gen_;
69  TH1F *phi_gen_;
70 
71  TH1F *pt_ref_;
72  TH1F *eta_ref_;
73  TH1F *phi_ref_;
74 
75  TH1F *deltaR_;
76  float dRMax_;
80 
83 };
84 
86 template <class T, class C>
87 void PFCandidateMonitor::fill(const T &candCollection,
88  const C &matchedCandCollection,
89  float &minVal,
90  float &maxVal,
92  matching_done_ = false;
94  for (unsigned i = 0; i < candCollection.size(); ++i) {
95  if (!isInRange(candCollection[i].pt(), candCollection[i].eta(), candCollection[i].phi()))
96  continue;
97  fillOne(candCollection[i]); // fill pt_gen, eta_gen and phi_gen histos for
98  // UNMATCHED generated candidate
99 
100  for (unsigned j = 0; j < matchedCandCollection.size(); ++j) // for DeltaR spectrum
101  if (deltaR_)
102  deltaR_->Fill(reco::deltaR(candCollection[i], matchedCandCollection[j]));
103  }
104  }
105 
106  std::vector<int> matchIndices;
107  PFB::match(candCollection, matchedCandCollection, matchIndices, matchCharge_, dRMax_);
108  // PFB::match( candCollection, matchedCandCollection, matchIndices,
109  // parameterSet, matchCharge_, dRMax_ );
110  // now matchIndices[i] stores the j-th closest matched jet
111  matching_done_ = true;
112 
113  for (unsigned int i = 0; i < (candCollection).size(); i++) {
114  const reco::Candidate &cand = candCollection[i];
115 
116  if (!isInRange(cand.pt(), cand.eta(), cand.phi()))
117  continue;
118 
119  int iMatch = matchIndices[i];
120  assert(iMatch < static_cast<int>(matchedCandCollection.size()));
121 
122  if (iMatch != -1) {
123  const reco::Candidate &matchedCand = matchedCandCollection[iMatch];
124  if (!isInRange(matchedCand.pt(), matchedCand.eta(), matchedCand.phi()))
125  continue;
126  // std::cout <<"PFJet pT " <<cand.pt() <<" eta " <<cand.eta() <<" phi "
127  // <<cand.phi() ; std::cout <<"\nmatched genJet pT " <<matchedCand.pt()
128  // <<" eta " <<matchedCand.eta() <<" phi " <<matchedCand.phi() <<"\n"
129  // <<std::endl ;
130  float ptRes = (cand.pt() - matchedCand.pt()) / matchedCand.pt();
131 
132  if (ptRes > maxVal)
133  maxVal = ptRes;
134  if (ptRes < minVal)
135  minVal = ptRes;
136 
138  candBench_.fillOne(cand); // fill pt, eta phi and charge histos for MATCHED candidate
139  // matchCandBench_.fillOne(cand, matchedCand); // fill delta_x_VS_y
140  // histos for matched couple
141  matchCandBench_.fillOne(cand, matchedCand,
142  parameterSet); // fill delta_x_VS_y histos for matched couple
144  fillOne(matchedCand); // fill pt_ref, eta_ref and phi_ref histos for
145  // MATCHED reference candidate
146  } else {
147  candBench_.fillOne(matchedCand); // fill pt, eta phi and charge histos
148  // for MATCHED candidate
149  // matchCandBench_.fillOne(matchedCand, cand); // fill delta_x_VS_y
150  // histos for matched couple
151  matchCandBench_.fillOne(cand, matchedCand,
152  parameterSet); // fill delta_x_VS_y histos for matched couple
154  fillOne(cand); // fill pt_ref, eta_ref and phi_ref histos for MATCHED
155  // reference candidate
156  }
157  }
158  }
159 }
160 
161 template <class T, class C, class M>
162 /*void PFCandidateMonitor::fill(const T& candCollection,
163  const C& matchedCandCollection, float& minVal, float& maxVal) {*/
164 void PFCandidateMonitor::fill(const T &candCollection,
165  const C &matchedCandCollection,
166  float &minVal,
167  float &maxVal,
169  const M &muonMatchedCandCollection) {
170  matching_done_ = false;
172  for (unsigned i = 0; i < candCollection.size(); ++i) {
173  if (!isInRange(candCollection[i].pt(), candCollection[i].eta(), candCollection[i].phi()))
174  continue;
175  fillOne(candCollection[i]); // fill pt_gen, eta_gen and phi_gen histos for
176  // UNMATCHED generated candidate
177 
178  for (unsigned j = 0; j < matchedCandCollection.size(); ++j) // for DeltaR spectrum
179  if (deltaR_)
180  deltaR_->Fill(reco::deltaR(candCollection[i], matchedCandCollection[j]));
181  }
182  }
183 
184  std::vector<int> matchIndices;
185  // PFB::match( candCollection, matchedCandCollection, matchIndices,
186  // matchCharge_, dRMax_ ); PFB::match( candCollection, matchedCandCollection,
187  // matchIndices, parameterSet, matchCharge_, dRMax_ );
188  PFB::match(candCollection,
189  matchedCandCollection,
190  matchIndices,
191  parameterSet,
192  muonMatchedCandCollection,
193  matchCharge_,
194  dRMax_);
195  // now matchIndices[i] stores the j-th closest matched jet
196  matching_done_ = true;
197 
198  for (unsigned int i = 0; i < (candCollection).size(); i++) {
199  const reco::Candidate &cand = candCollection[i];
200 
201  if (!isInRange(cand.pt(), cand.eta(), cand.phi()))
202  continue;
203 
204  int iMatch = matchIndices[i];
205  assert(iMatch < static_cast<int>(matchedCandCollection.size()));
206 
207  if (iMatch != -1) {
208  const reco::Candidate &matchedCand = matchedCandCollection[iMatch];
209  if (!isInRange(matchedCand.pt(), matchedCand.eta(), matchedCand.phi()))
210  continue;
211  // std::cout <<"PFJet pT " <<cand.pt() <<" eta " <<cand.eta() <<" phi "
212  // <<cand.phi() ; std::cout <<"\nmatched genJet pT " <<matchedCand.pt()
213  // <<" eta " <<matchedCand.eta() <<" phi " <<matchedCand.phi() <<"\n"
214  // <<std::endl ;
215  float ptRes = (cand.pt() - matchedCand.pt()) / matchedCand.pt();
216 
217  if (ptRes > maxVal)
218  maxVal = ptRes;
219  if (ptRes < minVal)
220  minVal = ptRes;
221 
223  candBench_.fillOne(cand); // fill pt, eta phi and charge histos for MATCHED candidate
224  matchCandBench_.fillOne(cand, matchedCand,
225  parameterSet); // fill delta_x_VS_y histos for matched couple
227  fillOne(matchedCand); // fill pt_ref, eta_ref and phi_ref histos for
228  // MATCHED reference candidate
229  } else {
230  candBench_.fillOne(matchedCand); // fill pt, eta phi and charge histos
231  // for MATCHED candidate
232  matchCandBench_.fillOne(cand, matchedCand,
233  parameterSet); // fill delta_x_VS_y histos for matched couple
235  fillOne(cand); // fill pt_ref, eta_ref and phi_ref histos for MATCHED
236  // reference candidate
237  }
238  }
239  }
240 }
241 #endif
To plot Candidate quantities.
void fillOne(const reco::Candidate &candidate, const reco::Candidate &matchedCandidate)
fill histograms with a given particle
To plot Candidate quantities.
void match(const C &candCollection, const M &matchedCandCollection, std::vector< int > &matchIndices, bool matchCharge=false, float dRMax=-1)
Definition: Matchers.h:17
virtual double pt() const =0
transverse momentum
void fillOne(const reco::Candidate &candidate)
fill histograms with a given particle
abstract base class
Definition: Benchmark.h:19
void setDirectory(TDirectory *dir) override
set directory (to use in ROOT)
void setup(DQMStore::IBooker &b)
book histograms
assert(be >=bs)
void setParameters(float dRMax, bool matchCharge, Benchmark::Mode mode, float ptmin, float ptmax, float etamin, float etamax, float phimin, float phimax, bool refHistoFlag)
set the parameters locally
void fill(const T &candidateCollection, const C &matchedCandCollection, float &minVal, float &maxVal, const edm::ParameterSet &parameterSet)
fill histograms with all particle
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
~PFCandidateMonitor() override
CandidateBenchmark candBench_
void fillOne(const reco::Candidate &cand)
double b
Definition: hdecay.h:118
double ptmin
Definition: HydjetWrapper.h:84
MatchCandidateBenchmark matchCandBench_
bool isInRange(float pt, float eta, float phi) const
Definition: Benchmark.h:50
long double T
tuple size
Write out results.
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
PFCandidateMonitor(float dRMax=0.3, bool matchCharge=true, Benchmark::Mode mode=Benchmark::DEFAULT)