CMS 3D CMS Logo

MatchCandidateBenchmark.cc
Go to the documentation of this file.
2 
4 
5 #include <TFile.h>
6 #include <TH1.h>
7 #include <TH2.h>
8 #include <TProfile.h>
9 #include <TROOT.h>
10 
11 using namespace std;
12 
14  delta_et_Over_et_VS_et_ = nullptr;
15  delta_et_VS_et_ = nullptr;
16  delta_eta_VS_et_ = nullptr;
17  delta_phi_VS_et_ = nullptr;
18 
19  BRdelta_et_Over_et_VS_et_ = nullptr;
20  ERdelta_et_Over_et_VS_et_ = nullptr;
21  // pTRes are initialzied in the setup since ptBinsPS.size() is needed
22 
23  histogramBooked_ = false;
24 }
25 
27 
29  if (!histogramBooked_) {
30  PhaseSpace ptPS;
31  PhaseSpace dptOvptPS;
32  PhaseSpace dptPS;
33  PhaseSpace detaPS;
34  PhaseSpace dphiPS;
35  switch (mode_) {
36  case VALIDATION:
37  ptPS = PhaseSpace(100, 0, 1000);
38  dptOvptPS = PhaseSpace(200, -1, 1);
39  dphiPS = PhaseSpace(200, -1, 1);
40  detaPS = PhaseSpace(200, -1, 1);
41  dptPS = PhaseSpace(100, -100, 100);
42  break;
43  case DQMOFFLINE:
44  default:
45  ptPS = PhaseSpace(50, 0, 100);
46  dptOvptPS = PhaseSpace(50, -1, 1);
47  dphiPS = PhaseSpace(50, -1, 1);
48  detaPS = PhaseSpace(50, -1, 1);
49  dptPS = PhaseSpace(50, -50, 50);
50  break;
51  }
52  float ptBins[11] = {0, 1, 2, 5, 10, 20, 50, 100, 200, 400, 1000};
53  int size = sizeof(ptBins) / sizeof(*ptBins);
54 
56  "delta_et_Over_et_VS_et_",
57  ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
58  size,
59  ptBins,
60  dptOvptPS.n,
61  dptOvptPS.m,
62  dptOvptPS.M);
63 
65  "BRdelta_et_Over_et_VS_et_",
66  ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
67  size,
68  ptBins,
69  dptOvptPS.n,
70  dptOvptPS.m,
71  dptOvptPS.M);
73  "ERdelta_et_Over_et_VS_et_",
74  ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
75  size,
76  ptBins,
77  dptOvptPS.n,
78  dptOvptPS.m,
79  dptOvptPS.M);
80 
82  book2D(b, "delta_et_VS_et_", ";E_{T, true} (GeV);#DeltaE_{T}", size, ptBins, dptPS.n, dptPS.m, dptPS.M);
83 
85  book2D(b, "delta_eta_VS_et_", ";#E_{T, true} (GeV);#Delta#eta", size, ptBins, detaPS.n, detaPS.m, detaPS.M);
86 
88  book2D(b, "delta_phi_VS_et_", ";E_{T, true} (GeV);#Delta#phi", size, ptBins, dphiPS.n, dphiPS.m, dphiPS.M);
89  /*
90  // TProfile
91  profile_delta_et_Over_et_VS_et_ =
92  bookProfile("profile_delta_et_Over_et_VS_et_", ";E_{T, true}
93  (GeV);#DeltaE_{T}/E_{T}", size, ptBins, dptOvptPS.m, dptOvptPS.M, "" );
94 
95  profile_delta_et_VS_et_ = bookProfile("profile_delta_et_VS_et_", ";E_{T,
96  true} (GeV);#DeltaE_{T}", size, ptBins, dptPS.m, dptPS.M, "" );
97 
98  profile_delta_eta_VS_et_ = bookProfile("profile_delta_eta_VS_et_", ";#E_{T,
99  true} (GeV);#Delta#eta", size, ptBins, detaPS.m, detaPS.M, "" );
100 
101  profile_delta_phi_VS_et_ = bookProfile("profile_delta_phi_VS_et_", ";E_{T,
102  true} (GeV);#Delta#phi", size, ptBins, dphiPS.m, dphiPS.M, "" );
103  // TProfile RMS
104  profileRMS_delta_et_Over_et_VS_et_ =
105  bookProfile("profileRMS_delta_et_Over_et_VS_et_", ";E_{T, true}
106  (GeV);#DeltaE_{T}/E_{T}", size, ptBins, dptOvptPS.m, dptOvptPS.M, "s" );
107 
108  profileRMS_delta_et_VS_et_ = bookProfile("profileRMS_delta_et_VS_et_",
109  ";E_{T, true} (GeV);#DeltaE_{T}", size, ptBins, dptPS.m, dptPS.M, "s" );
110 
111  profileRMS_delta_eta_VS_et_ = bookProfile("profileRMS_delta_eta_VS_et_",
112  ";#E_{T, true} (GeV);#Delta#eta", size, ptBins, detaPS.m, detaPS.M, "s" );
113 
114  profileRMS_delta_phi_VS_et_ = bookProfile("profileRMS_delta_phi_VS_et_",
115  ";E_{T, true} (GeV);#Delta#phi", size, ptBins, dphiPS.m, dphiPS.M, "s" );
116  */
117  pTRes_.resize(size);
118  BRpTRes_.resize(size);
119  ERpTRes_.resize(size);
120  for (size_t i = 0; i < pTRes_.size(); i++) {
121  pTRes_[i] = nullptr;
122  BRpTRes_[i] = nullptr;
123  ERpTRes_[i] = nullptr;
124  }
125 
126  histogramBooked_ = true;
127  }
128 }
129 
131  std::vector<double> ptBinsPS = parameterSet.getParameter<std::vector<double>>("VariablePtBins");
132  pTRes_.resize(ptBinsPS.size() - 1);
133  BRpTRes_.resize(ptBinsPS.size() - 1);
134  ERpTRes_.resize(ptBinsPS.size() - 1);
135  if (!pTRes_.empty())
136  for (size_t i = 0; i < pTRes_.size(); i++) {
137  pTRes_[i] = nullptr;
138  BRpTRes_[i] = nullptr;
139  ERpTRes_[i] = nullptr;
140  }
141 
142  if (!histogramBooked_) {
143  edm::ParameterSet ptPS = parameterSet.getParameter<edm::ParameterSet>("PtHistoParameter");
144  edm::ParameterSet dptPS = parameterSet.getParameter<edm::ParameterSet>("DeltaPtHistoParameter");
145  edm::ParameterSet dptOvptPS = parameterSet.getParameter<edm::ParameterSet>("DeltaPtOvPtHistoParameter");
146  edm::ParameterSet detaPS = parameterSet.getParameter<edm::ParameterSet>("DeltaEtaHistoParameter");
147  edm::ParameterSet dphiPS = parameterSet.getParameter<edm::ParameterSet>("DeltaPhiHistoParameter");
148 
149  std::vector<float> ptBins;
150  if (ptBinsPS.size() > 1) {
151  ptBins.reserve(ptBinsPS.size());
152  for (size_t i = 0; i < ptBinsPS.size(); i++)
153  ptBins.push_back(ptBinsPS[i]);
154  } else {
155  Int_t nFixedBins = ptPS.getParameter<int32_t>("nBin");
156  ptBins.reserve(nFixedBins + 1);
157  for (Int_t i = 0; i <= nFixedBins; i++)
158  ptBins.push_back(ptPS.getParameter<double>("xMin") +
159  i * ((ptPS.getParameter<double>("xMax") - ptPS.getParameter<double>("xMin")) / nFixedBins));
160  ptBinsPS.resize(nFixedBins);
161  }
162 
163  if (dptOvptPS.getParameter<bool>("switchOn")) {
165  "delta_et_Over_et_VS_et_",
166  ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
167  ptBinsPS.size() - 1,
168  &(ptBins.front()),
169  dptOvptPS.getParameter<int32_t>("nBin"),
170  dptOvptPS.getParameter<double>("xMin"),
171  dptOvptPS.getParameter<double>("xMax"));
172  }
173  if (dptOvptPS.getParameter<bool>("slicingOn")) {
174  for (size_t i = 0; i < pTRes_.size(); i++) {
175  pTRes_[i] = book1D(b,
176  TString::Format("Pt%d_%d", (int)ptBins[i], (int)ptBins[i + 1]),
177  ";#Deltap_{T}/p_{T};Entries",
178  dptOvptPS.getParameter<int32_t>("nBin"),
179  dptOvptPS.getParameter<double>("xMin"),
180  dptOvptPS.getParameter<double>("xMax"));
181  BRpTRes_[i] = book1D(b,
182  TString::Format("BRPt%d_%d", (int)ptBins[i], (int)ptBins[i + 1]),
183  ";#Deltap_{T}/p_{T};Entries",
184  dptOvptPS.getParameter<int32_t>("nBin"),
185  dptOvptPS.getParameter<double>("xMin"),
186  dptOvptPS.getParameter<double>("xMax"));
187  ERpTRes_[i] = book1D(b,
188  TString::Format("ERPt%d_%d", (int)ptBins[i], (int)ptBins[i + 1]),
189  ";#Deltap_{T}/p_{T};Entries",
190  dptOvptPS.getParameter<int32_t>("nBin"),
191  dptOvptPS.getParameter<double>("xMin"),
192  dptOvptPS.getParameter<double>("xMax"));
193  }
194  }
195  if (dptOvptPS.getParameter<bool>("BROn")) {
197  "BRdelta_et_Over_et_VS_et_",
198  ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
199  ptBinsPS.size() - 1,
200  &(ptBins.front()),
201  dptOvptPS.getParameter<int32_t>("nBin"),
202  dptOvptPS.getParameter<double>("xMin"),
203  dptOvptPS.getParameter<double>("xMax"));
204  }
205  if (dptOvptPS.getParameter<bool>("EROn")) {
207  "ERdelta_et_Over_et_VS_et_",
208  ";E_{T, true} (GeV);#DeltaE_{T}/E_{T}",
209  ptBinsPS.size() - 1,
210  &(ptBins.front()),
211  dptOvptPS.getParameter<int32_t>("nBin"),
212  dptOvptPS.getParameter<double>("xMin"),
213  dptOvptPS.getParameter<double>("xMax"));
214  }
215 
216  if (dptPS.getParameter<bool>("switchOn")) {
218  "delta_et_VS_et_",
219  ";E_{T, true} (GeV);#DeltaE_{T}",
220  ptBinsPS.size() - 1,
221  &(ptBins.front()),
222  dptPS.getParameter<int32_t>("nBin"),
223  dptPS.getParameter<double>("xMin"),
224  dptPS.getParameter<double>("xMax"));
225  }
226 
227  if (detaPS.getParameter<bool>("switchOn")) {
229  "delta_eta_VS_et_",
230  ";E_{T, true} (GeV);#Delta#eta",
231  ptBinsPS.size() - 1,
232  &(ptBins.front()),
233  detaPS.getParameter<int32_t>("nBin"),
234  detaPS.getParameter<double>("xMin"),
235  detaPS.getParameter<double>("xMax"));
236  }
237 
238  if (dphiPS.getParameter<bool>("switchOn")) {
240  "delta_phi_VS_et_",
241  ";E_{T, true} (GeV);#Delta#phi",
242  ptBinsPS.size() - 1,
243  &(ptBins.front()),
244  dphiPS.getParameter<int32_t>("nBin"),
245  dphiPS.getParameter<double>("xMin"),
246  dphiPS.getParameter<double>("xMax"));
247  }
248  /*
249  // TProfile
250  if (dptOvptPS.getParameter<bool>("switchOn")) {
251  profile_delta_et_Over_et_VS_et_ =
252  bookProfile("profile_delta_et_Over_et_VS_et_", ";E_{T, true}
253  (GeV);#DeltaE_{T}/E_{T}", ptBinsPS.size()-1, &(ptBins.front()),
254  dptOvptPS.getParameter<double>("xMin"),
255  dptOvptPS.getParameter<double>("xMax"),
256  "" ); profileRMS_delta_et_Over_et_VS_et_ =
257  bookProfile("profileRMS_delta_et_Over_et_VS_et_", ";E_{T, true}
258  (GeV);#DeltaE_{T}/E_{T}", ptBinsPS.size()-1, &(ptBins.front()),
259  dptOvptPS.getParameter<double>("xMin"),
260  dptOvptPS.getParameter<double>("xMax"),
261  "s" );
262  }
263 
264  if (dptPS.getParameter<bool>("switchOn")) {
265  profile_delta_et_VS_et_ = bookProfile("profile_delta_et_VS_et_", ";E_{T,
266  true} (GeV);#DeltaE_{T}", ptBinsPS.size()-1, &(ptBins.front()),
267  dptPS.getParameter<double>("xMin"),
268  dptPS.getParameter<double>("xMax"),
269  "" ); profileRMS_delta_et_VS_et_ = bookProfile("profileRMS_delta_et_VS_et_",
270  ";E_{T, true} (GeV);#DeltaE_{T}", ptBinsPS.size()-1, &(ptBins.front()),
271  dptPS.getParameter<double>("xMin"),
272  dptPS.getParameter<double>("xMax"),
273  "s" );
274  }
275 
276  if (detaPS.getParameter<bool>("switchOn")) {
277  profile_delta_eta_VS_et_ = bookProfile("profile_delta_eta_VS_et_", ";E_{T,
278  true} (GeV);#Delta#eta", ptBinsPS.size()-1, &(ptBins.front()),
279  detaPS.getParameter<double>("xMin"),
280  detaPS.getParameter<double>("xMax"),
281  "" ); profileRMS_delta_eta_VS_et_ =
282  bookProfile("profileRMS_delta_eta_VS_et_", ";E_{T, true} (GeV);#Delta#eta",
283  ptBinsPS.size()-1,
284  &(ptBins.front()), detaPS.getParameter<double>("xMin"),
285  detaPS.getParameter<double>("xMax"),
286  "s" );
287  }
288 
289  if (dphiPS.getParameter<bool>("switchOn")) {
290  profile_delta_phi_VS_et_ = bookProfile("profile_delta_phi_VS_et_", ";E_{T,
291  true} (GeV);#Delta#phi", ptBinsPS.size()-1, &(ptBins.front()),
292  dphiPS.getParameter<double>("xMin"),
293  dphiPS.getParameter<double>("xMax"),
294  "" ); profileRMS_delta_phi_VS_et_ =
295  bookProfile("profileRMS_delta_phi_VS_et_", ";E_{T, true} (GeV);#Delta#phi",
296  ptBinsPS.size()-1,
297  &(ptBins.front()), dphiPS.getParameter<double>("xMin"),
298  dphiPS.getParameter<double>("xMax"),
299  "s" );
300  }
301  */
302 
303  histogramBooked_ = true;
304  }
305 }
306 
308  if (!isInRange(cand.pt(), cand.eta(), cand.phi()))
309  return;
310 
311  if (histogramBooked_) {
313  delta_et_Over_et_VS_et_->Fill(matchedCand.pt(), (cand.pt() - matchedCand.pt()) / matchedCand.pt());
314  if (fabs(cand.eta()) <= 1.4)
316  BRdelta_et_Over_et_VS_et_->Fill(matchedCand.pt(), (cand.pt() - matchedCand.pt()) / matchedCand.pt());
317  if (fabs(cand.eta()) >= 1.6 && fabs(cand.eta()) <= 2.4)
319  ERdelta_et_Over_et_VS_et_->Fill(matchedCand.pt(), (cand.pt() - matchedCand.pt()) / matchedCand.pt());
320  if (delta_et_VS_et_)
321  delta_et_VS_et_->Fill(matchedCand.pt(), cand.pt() - matchedCand.pt());
322  if (delta_eta_VS_et_)
323  delta_eta_VS_et_->Fill(matchedCand.pt(), cand.eta() - matchedCand.eta());
324  if (delta_phi_VS_et_)
325  delta_phi_VS_et_->Fill(matchedCand.pt(), cand.phi() - matchedCand.phi());
326  /*
327  // TProfile
328  if (profile_delta_et_Over_et_VS_et_) {
329  profile_delta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() -
330  matchedCand.pt())/matchedCand.pt() );
331  profileRMS_delta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() -
332  matchedCand.pt())/matchedCand.pt() ); } if (profile_delta_et_VS_et_) {
333  profile_delta_et_VS_et_->Fill( matchedCand.pt(), cand.pt() -
334  matchedCand.pt() ); profileRMS_delta_et_VS_et_->Fill( matchedCand.pt(),
335  cand.pt() - matchedCand.pt() ); } if (profile_delta_eta_VS_et_) {
336  profile_delta_eta_VS_et_->Fill( matchedCand.pt(), cand.eta() -
337  matchedCand.eta() ); profileRMS_delta_eta_VS_et_->Fill( matchedCand.pt(),
338  cand.eta() - matchedCand.eta() ); } if (profile_delta_phi_VS_et_) {
339  profile_delta_phi_VS_et_->Fill( matchedCand.pt(), cand.phi() -
340  matchedCand.phi() ); profileRMS_delta_phi_VS_et_->Fill( matchedCand.pt(),
341  cand.phi() - matchedCand.phi() ); }
342  */
343  }
344 }
345 
347  const reco::Candidate &matchedCand,
349  if (!isInRange(cand.pt(), cand.eta(), cand.phi()))
350  return;
351 
352  if (histogramBooked_) {
353  std::vector<double> ptBinsPS = parameterSet.getParameter<std::vector<double>>("VariablePtBins");
354  edm::ParameterSet ptPS = parameterSet.getParameter<edm::ParameterSet>("PtHistoParameter");
355  std::vector<float> ptBins;
356  if (ptBinsPS.size() > 1) {
357  ptBins.reserve(ptBinsPS.size());
358  for (size_t i = 0; i < ptBinsPS.size(); i++) {
359  ptBins.push_back(ptBinsPS[i]);
360  }
361  } else {
362  Int_t nFixedBins = ptPS.getParameter<int32_t>("nBin");
363  ptBins.reserve(nFixedBins + 1);
364  for (Int_t i = 0; i <= nFixedBins; i++) {
365  ptBins.push_back(ptPS.getParameter<double>("xMin") +
366  i * ((ptPS.getParameter<double>("xMax") - ptPS.getParameter<double>("xMin")) / nFixedBins));
367  }
368  ptBinsPS.resize(nFixedBins);
369  }
370 
371  edm::ParameterSet dptOvptPS = parameterSet.getParameter<edm::ParameterSet>("DeltaPtOvPtHistoParameter");
372  if (matchedCand.pt() > ptBins.at(0)) { // underflow problem
374  delta_et_Over_et_VS_et_->Fill(matchedCand.pt(), (cand.pt() - matchedCand.pt()) / matchedCand.pt());
375  if (fabs(cand.eta()) >= dptOvptPS.getParameter<double>("BREtaMin") &&
376  fabs(cand.eta()) <= dptOvptPS.getParameter<double>("BREtaMax"))
378  BRdelta_et_Over_et_VS_et_->Fill(matchedCand.pt(), (cand.pt() - matchedCand.pt()) / matchedCand.pt());
379  if (fabs(cand.eta()) >= dptOvptPS.getParameter<double>("EREtaMin") &&
380  fabs(cand.eta()) <= dptOvptPS.getParameter<double>("EREtaMax"))
382  ERdelta_et_Over_et_VS_et_->Fill(matchedCand.pt(), (cand.pt() - matchedCand.pt()) / matchedCand.pt());
383  if (delta_et_VS_et_)
384  delta_et_VS_et_->Fill(matchedCand.pt(), cand.pt() - matchedCand.pt());
385  if (delta_eta_VS_et_)
386  delta_eta_VS_et_->Fill(matchedCand.pt(), cand.eta() - matchedCand.eta());
387  if (delta_phi_VS_et_)
388  delta_phi_VS_et_->Fill(matchedCand.pt(), cand.phi() - matchedCand.phi());
389  }
390  /*
391  // TProfile
392  if (profile_delta_et_Over_et_VS_et_) {
393  profile_delta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() -
394  matchedCand.pt())/matchedCand.pt() );
395  profileRMS_delta_et_Over_et_VS_et_->Fill( matchedCand.pt(), (cand.pt() -
396  matchedCand.pt())/matchedCand.pt() ); } if (profile_delta_et_VS_et_) {
397  profile_delta_et_VS_et_->Fill( matchedCand.pt(), cand.pt() -
398  matchedCand.pt() ); profileRMS_delta_et_VS_et_->Fill( matchedCand.pt(),
399  cand.pt() - matchedCand.pt() ); } if (profile_delta_eta_VS_et_) {
400  profile_delta_eta_VS_et_->Fill( matchedCand.pt(), cand.eta() -
401  matchedCand.eta() ); profileRMS_delta_eta_VS_et_->Fill( matchedCand.pt(),
402  cand.eta() - matchedCand.eta() ); } if (profile_delta_phi_VS_et_) {
403  profile_delta_phi_VS_et_->Fill( matchedCand.pt(), cand.phi() -
404  matchedCand.phi() ); profileRMS_delta_phi_VS_et_->Fill( matchedCand.pt(),
405  cand.phi() - matchedCand.phi() ); }
406  */
407 
408  for (size_t i = 0; i < pTRes_.size(); i++) {
409  if (matchedCand.pt() >= ptBins.at(i) && matchedCand.pt() < ptBins.at(i + 1)) {
410  if (pTRes_[i])
411  pTRes_[i]->Fill((cand.pt() - matchedCand.pt()) / matchedCand.pt());
412  if (fabs(cand.eta()) >= dptOvptPS.getParameter<double>("BREtaMin") &&
413  fabs(cand.eta()) <= dptOvptPS.getParameter<double>("BREtaMax"))
414  if (BRpTRes_[i])
415  BRpTRes_[i]->Fill((cand.pt() - matchedCand.pt()) / matchedCand.pt()); // Fill Barrel
416  if (fabs(cand.eta()) >= dptOvptPS.getParameter<double>("EREtaMin") &&
417  fabs(cand.eta()) <= dptOvptPS.getParameter<double>("EREtaMax"))
418  if (ERpTRes_[i])
419  ERpTRes_[i]->Fill((cand.pt() - matchedCand.pt()) / matchedCand.pt()); // Fill Endcap
420  }
421  }
422  }
423 }
size
Write out results.
T getParameter(std::string const &) const
TH1F * book1D(DQMStore::IBooker &b, const char *histname, const char *title, int nbins, float xmin, float xmax)
book a 1D histogram, either through IBooker or plain root
Definition: Benchmark.cc:16
void fillOne(const reco::Candidate &candidate, const reco::Candidate &matchedCandidate)
fill histograms with a given particle
std::vector< TH1F * > pTRes_
abstract base class
Definition: Benchmark.h:21
std::vector< TH1F * > BRpTRes_
void setup(DQMStore::IBooker &b)
book histograms
TH2F * book2D(DQMStore::IBooker &b, const char *histname, const char *title, int nbinsx, float xmin, float xmax, int nbinsy, float ymin, float ymax)
book a 2D histogram, either through IBooker or plain root
Definition: Benchmark.cc:23
virtual double eta() const =0
momentum pseudorapidity
virtual double pt() const =0
transverse momentum
double b
Definition: hdecay.h:120
std::vector< TH1F * > ERpTRes_
Mode mode_
Definition: Benchmark.h:124
bool isInRange(float pt, float eta, float phi) const
Definition: Benchmark.h:50
virtual double phi() const =0
momentum azimuthal angle
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11