CMS 3D CMS Logo

performance.cc
Go to the documentation of this file.
1 #include "performance.h"
2 
3 enum { pT5 = 7, pT3 = 5, T5 = 4, pLS = 8 };
4 
5 //__________________________________________________________________________________________________________________________________________________________________________
6 int main(int argc, char** argv) {
7  // Parse arguments
9 
10  // Initialize input and output root files
12 
13  // Set of pdgids
14  std::vector<int> pdgids = {0, 11, 211, 13, 321};
15 
16  // Set of charges
17  std::vector<int> charges = {0, 1, -1};
18 
19  // Set of extra selections for efficiency plots
20  std::vector<TString> selnames = {
21  "base", // default baseline that is more inline with MTV
22  "loweta", // When the eta cut is restricted to 2.4
23  "xtr", // When the eta cut is restricted to transition regions
24  "vtr" // When the eta cut is vetoing transition regions
25  };
26  std::vector<std::function<bool(unsigned int)>> sels = {
27  [&](unsigned int isim) { return 1.; },
28  [&](unsigned int isim) { return abs(lstEff.sim_eta().at(isim)) < 2.4; },
29  [&](unsigned int isim) { return abs(lstEff.sim_eta().at(isim)) > 1.1 and abs(lstEff.sim_eta().at(isim)) < 1.7; },
30  [&](unsigned int isim) {
31  return (abs(lstEff.sim_eta().at(isim)) < 1.1 or abs(lstEff.sim_eta().at(isim)) > 1.7) and
32  abs(lstEff.sim_eta().at(isim)) < 2.4;
33  }};
34  pdgids.insert(pdgids.end(), ana.pdgids.begin(), ana.pdgids.end());
35 
36  std::vector<SimTrackSetDefinition> list_effSetDef;
37 
38  // creating a set of efficiency plots for each pdgids being considered
39  for (auto& pdgid : pdgids) {
40  for (auto& charge : charges) {
41  for (unsigned int isel = 0; isel < sels.size(); ++isel) {
42  list_effSetDef.push_back(
43  SimTrackSetDefinition(/* name */
44  TString("TC_") + selnames[isel],
45  /* pdgid */ pdgid,
46  /* q */ charge,
47  /* pass */ [&](unsigned int isim) { return lstEff.sim_TC_matched().at(isim) > 0; },
48  /* sel */ sels[isel]));
49  list_effSetDef.push_back(SimTrackSetDefinition(
50  /* name */
51  TString("pT5_") + selnames[isel],
52  /* pdgid */ pdgid,
53  /* q */ charge,
54  /* pass */ [&](unsigned int isim) { return lstEff.sim_TC_matched_mask().at(isim) & (1 << pT5); },
55  /* sel */ sels[isel]));
56  list_effSetDef.push_back(SimTrackSetDefinition(
57  /* name */
58  TString("pT3_") + selnames[isel],
59  /* pdgid */ pdgid,
60  /* q */ charge,
61  /* pass */ [&](unsigned int isim) { return lstEff.sim_TC_matched_mask().at(isim) & (1 << pT3); },
62  /* sel */ sels[isel]));
63  list_effSetDef.push_back(SimTrackSetDefinition(
64  /* name */
65  TString("T5_") + selnames[isel],
66  /* pdgid */ pdgid,
67  /* q */ charge,
68  /* pass */ [&](unsigned int isim) { return lstEff.sim_TC_matched_mask().at(isim) & (1 << T5); },
69  /* sel */ sels[isel]));
70  list_effSetDef.push_back(SimTrackSetDefinition(
71  /* name */
72  TString("pLS_") + selnames[isel],
73  /* pdgid */ pdgid,
74  /* q */ charge,
75  /* pass */ [&](unsigned int isim) { return lstEff.sim_TC_matched_mask().at(isim) & (1 << pLS); },
76  /* sel */ sels[isel]));
77 
78  if (ana.do_lower_level) {
79  //lower objects - name will have pT5_lower_, T5_lower_, pT3_lower_
80  list_effSetDef.push_back(SimTrackSetDefinition(
81  /* name */
82  TString("pT5_lower_") + selnames[isel],
83  /* pdgid */ pdgid,
84  /* q */ charge,
85  /* pass */ [&](unsigned int isim) { return lstEff.sim_pT5_matched().at(isim) > 0; },
86  /* sel */ sels[isel]));
87  list_effSetDef.push_back(
88  SimTrackSetDefinition(/* name */
89  TString("T5_lower_") + selnames[isel],
90  /* pdgid */ pdgid,
91  /* q */ charge,
92  /* pass */ [&](unsigned int isim) { return lstEff.sim_T5_matched().at(isim) > 0; },
93  /* sel */ sels[isel]));
94  list_effSetDef.push_back(SimTrackSetDefinition(
95  /* name */
96  TString("pT3_lower_") + selnames[isel],
97  /* pdgid */ pdgid,
98  /* q */ charge,
99  /* pass */ [&](unsigned int isim) { return lstEff.sim_pT3_matched().at(isim) > 0; },
100  /* sel */ sels[isel]));
101  }
102  }
103  }
104  }
105 
106  bookEfficiencySets(list_effSetDef);
107 
108  // creating a set of fake rate plots
109  std::vector<RecoTrackSetDefinition> list_FRSetDef;
110  list_FRSetDef.push_back(
111  RecoTrackSetDefinition(/* name */
112  "TC",
113  /* pass */ [&](unsigned int itc) { return lstEff.tc_isFake().at(itc) > 0; },
114  /* sel */ [&](unsigned int itc) { return 1; },
115  /* pt */ tas::tc_pt,
116  /* eta */ tas::tc_eta,
117  /* phi */ tas::tc_phi,
118  /* type */ tas::tc_type));
119  list_FRSetDef.push_back(
120  RecoTrackSetDefinition(/* name */
121  "pT5",
122  /* pass */ [&](unsigned int itc) { return lstEff.tc_isFake().at(itc) > 0; },
123  /* sel */ [&](unsigned int itc) { return lstEff.tc_type().at(itc) == pT5; },
124  /* pt */ tas::tc_pt,
125  /* eta */ tas::tc_eta,
126  /* phi */ tas::tc_phi,
127  /* type */ tas::tc_type));
128  list_FRSetDef.push_back(
129  RecoTrackSetDefinition(/* name */
130  "pT3",
131  /* pass */ [&](unsigned int itc) { return lstEff.tc_isFake().at(itc) > 0; },
132  /* sel */ [&](unsigned int itc) { return lstEff.tc_type().at(itc) == pT3; },
133  /* pt */ tas::tc_pt,
134  /* eta */ tas::tc_eta,
135  /* phi */ tas::tc_phi,
136  /* type */ tas::tc_type));
137  list_FRSetDef.push_back(
138  RecoTrackSetDefinition(/* name */
139  "T5",
140  /* pass */ [&](unsigned int itc) { return lstEff.tc_isFake().at(itc) > 0; },
141  /* sel */ [&](unsigned int itc) { return lstEff.tc_type().at(itc) == T5; },
142  /* pt */ tas::tc_pt,
143  /* eta */ tas::tc_eta,
144  /* phi */ tas::tc_phi,
145  /* type */ tas::tc_type));
146  list_FRSetDef.push_back(
147  RecoTrackSetDefinition(/* name */
148  "pLS",
149  /* pass */ [&](unsigned int itc) { return lstEff.tc_isFake().at(itc) > 0; },
150  /* sel */ [&](unsigned int itc) { return lstEff.tc_type().at(itc) == pLS; },
151  /* pt */ tas::tc_pt,
152  /* eta */ tas::tc_eta,
153  /* phi */ tas::tc_phi,
154  /* type */ tas::tc_type));
155 
156  if (ana.do_lower_level) {
157  list_FRSetDef.push_back(RecoTrackSetDefinition(
158  /* name */
159  "pT5_lower",
160  /* pass */ [&](unsigned int ipT5) { return lstEff.pT5_isFake().at(ipT5) > 0; },
161  /* sel */ [&](unsigned int ipT5) { return 1; },
162  /* pt */ tas::pT5_pt,
163  /* eta */ tas::pT5_eta,
164  /* phi */ tas::pT5_phi,
165  /* type */ [&]() { return static_cast<const std::vector<int>>(std::vector<int>(tas::pT5_pt().size(), 1)); }));
166  list_FRSetDef.push_back(RecoTrackSetDefinition(
167  /* name */
168  "T5_lower",
169  /* pass */ [&](unsigned int it5) { return lstEff.t5_isFake().at(it5) > 0; },
170  /* sel */ [&](unsigned int it5) { return 1; },
171  /* pt */ tas::t5_pt,
172  /* eta */ tas::t5_eta,
173  /* phi */ tas::t5_phi,
174  /* type */ [&]() { return static_cast<const std::vector<int>>(std::vector<int>(tas::t5_pt().size(), 1)); }));
175  list_FRSetDef.push_back(RecoTrackSetDefinition(
176  /* name */
177  "pT3_lower",
178  /* pass */ [&](unsigned int ipT3) { return lstEff.pT3_isFake().at(ipT3) > 0; },
179  /* sel */ [&](unsigned int ipT3) { return 1; },
180  /* pt */ tas::pT3_pt,
181  /* eta */ tas::pT3_eta,
182  /* phi */ tas::pT3_phi,
183  /* type */ [&]() { return static_cast<const std::vector<int>>(std::vector<int>(tas::pT3_pt().size(), 1)); }));
184  }
185 
186  bookFakeRateSets(list_FRSetDef);
187 
188  // creating a set of duplicate rate plots
189  std::vector<RecoTrackSetDefinition> list_DRSetDef;
190  list_DRSetDef.push_back(
191  RecoTrackSetDefinition(/* name */
192  "TC",
193  /* pass */ [&](unsigned int itc) { return lstEff.tc_isDuplicate().at(itc) > 0; },
194  /* sel */ [&](unsigned int itc) { return 1; },
195  /* pt */ tas::tc_pt,
196  /* eta */ tas::tc_eta,
197  /* phi */ tas::tc_phi,
198  /* type */ tas::tc_type));
199  list_DRSetDef.push_back(
200  RecoTrackSetDefinition(/* name */
201  "pT5",
202  /* pass */ [&](unsigned int itc) { return lstEff.tc_isDuplicate().at(itc) > 0; },
203  /* sel */ [&](unsigned int itc) { return lstEff.tc_type().at(itc) == pT5; },
204  /* pt */ tas::tc_pt,
205  /* eta */ tas::tc_eta,
206  /* phi */ tas::tc_phi,
207  /* type */ tas::tc_type));
208  list_DRSetDef.push_back(
209  RecoTrackSetDefinition(/* name */
210  "pT3",
211  /* pass */ [&](unsigned int itc) { return lstEff.tc_isDuplicate().at(itc) > 0; },
212  /* sel */ [&](unsigned int itc) { return lstEff.tc_type().at(itc) == pT3; },
213  /* pt */ tas::tc_pt,
214  /* eta */ tas::tc_eta,
215  /* phi */ tas::tc_phi,
216  /* type */ tas::tc_type));
217  list_DRSetDef.push_back(
218  RecoTrackSetDefinition(/* name */
219  "T5",
220  /* pass */ [&](unsigned int itc) { return lstEff.tc_isDuplicate().at(itc) > 0; },
221  /* sel */ [&](unsigned int itc) { return lstEff.tc_type().at(itc) == T5; },
222  /* pt */ tas::tc_pt,
223  /* eta */ tas::tc_eta,
224  /* phi */ tas::tc_phi,
225  /* type */ tas::tc_type));
226  list_DRSetDef.push_back(
227  RecoTrackSetDefinition(/* name */
228  "pLS",
229  /* pass */ [&](unsigned int itc) { return lstEff.tc_isDuplicate().at(itc) > 0; },
230  /* sel */ [&](unsigned int itc) { return lstEff.tc_type().at(itc) == pLS; },
231  /* pt */ tas::tc_pt,
232  /* eta */ tas::tc_eta,
233  /* phi */ tas::tc_phi,
234  /* type */ tas::tc_type));
235 
236  if (ana.do_lower_level) {
237  list_DRSetDef.push_back(RecoTrackSetDefinition(
238  /* name */
239  "pT5_lower",
240  /* pass */ [&](unsigned int ipT5) { return lstEff.pT5_isDuplicate().at(ipT5) > 0; },
241  /* sel */ [&](unsigned int ipT5) { return 1; },
242  /* pt */ tas::pT5_pt,
243  /* eta */ tas::pT5_eta,
244  /* phi */ tas::pT5_phi,
245  /* type */ [&]() { return static_cast<const std::vector<int>>(std::vector<int>(tas::pT5_pt().size(), 1)); }));
246  list_DRSetDef.push_back(RecoTrackSetDefinition(
247  /* name */
248  "T5_lower",
249  /* pass */ [&](unsigned int it5) { return lstEff.t5_isDuplicate().at(it5) > 0; },
250  /* sel */ [&](unsigned int it5) { return 1; },
251  /* pt */ tas::t5_pt,
252  /* eta */ tas::t5_eta,
253  /* phi */ tas::t5_phi,
254  /* type */ [&]() { return static_cast<const std::vector<int>>(std::vector<int>(tas::t5_pt().size(), 1)); }));
255  list_DRSetDef.push_back(RecoTrackSetDefinition(
256  /* name */
257  "pT3_lower",
258  /* pass */ [&](unsigned int ipT3) { return lstEff.pT3_isDuplicate().at(ipT3) > 0; },
259  /* sel */ [&](unsigned int ipT3) { return 1; },
260  /* pt */ tas::pT3_pt,
261  /* eta */ tas::pT3_eta,
262  /* phi */ tas::pT3_phi,
263  /* type */ [&]() { return static_cast<const std::vector<int>>(std::vector<int>(tas::pT3_pt().size(), 1)); }));
264  }
265 
266  bookDuplicateRateSets(list_DRSetDef);
267 
268  // Book Histograms
269  ana.cutflow.bookHistograms(ana.histograms); // if just want to book everywhere
270 
271  int nevts = 0;
272 
273  // Looping input file
274  while (ana.looper.nextEvent()) {
275  // If splitting jobs are requested then determine whether to process the event or not based on remainder
276  if (ana.job_index != -1 and ana.nsplit_jobs != -1) {
278  continue;
279  }
280 
281  // Reset all temporary variables necessary for histogramming
282  ana.tx.clear();
283 
284  // Compute all temporary variables and pack the vector quantities that will get filled to the histograms
285  fillEfficiencySets(list_effSetDef);
286  fillFakeRateSets(list_FRSetDef);
287  fillDuplicateRateSets(list_DRSetDef);
288 
289  // Reset all temporary variables necessary for histogramming
290  ana.cutflow.fill();
291 
292  // Counting number of events processed
293  nevts++;
294  }
295 
296  // Write number of events processed
297  ana.output_tfile->cd();
298  TH1F* h_nevts = new TH1F("nevts", "nevts", 1, 0, 1);
299  h_nevts->SetBinContent(1, nevts);
300  h_nevts->Write();
301 
302  // Writing output file
304 
305  // The below can be sometimes crucial
306  delete ana.output_tfile;
307 
308  // Done
309  return 0;
310 }
311 
312 // ---------------------------------------------------------=============================================-------------------------------------------------------------------
313 // ---------------------------------------------------------=============================================-------------------------------------------------------------------
314 // ---------------------------------------------------------=============================================-------------------------------------------------------------------
315 // ---------------------------------------------------------=============================================-------------------------------------------------------------------
316 // ---------------------------------------------------------=============================================-------------------------------------------------------------------
317 
318 //__________________________________________________________________________________________________________________________________________________________________________
319 void bookEfficiencySets(std::vector<SimTrackSetDefinition>& effsets) {
320  for (auto& effset : effsets)
321  bookEfficiencySet(effset);
322 }
323 
324 //__________________________________________________________________________________________________________________________________________________________________________
326  TString category_name = TString::Format("%s_%d_%d", effset.set_name.Data(), effset.pdgid, effset.q);
327 
328  // Denominator tracks' quantities
329  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_denom_pt");
330  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_denom_eta");
331  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_denom_dxy");
332  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_denom_vxy");
333  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_denom_dz");
334  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_denom_phi");
335 
336  // Numerator tracks' quantities
337  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_numer_pt");
338  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_numer_eta");
339  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_numer_dxy");
340  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_numer_vxy");
341  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_numer_dz");
342  ana.tx.createBranch<std::vector<float>>(category_name + "_ef_numer_phi");
343 
344  // Inefficiencies
345  ana.tx.createBranch<std::vector<float>>(category_name + "_ie_numer_pt");
346  ana.tx.createBranch<std::vector<float>>(category_name + "_ie_numer_eta");
347  ana.tx.createBranch<std::vector<float>>(category_name + "_ie_numer_dxy");
348  ana.tx.createBranch<std::vector<float>>(category_name + "_ie_numer_vxy");
349  ana.tx.createBranch<std::vector<float>>(category_name + "_ie_numer_dz");
350  ana.tx.createBranch<std::vector<float>>(category_name + "_ie_numer_phi");
351 
352  ana.histograms.addVecHistogram(category_name + "_ef_denom_pt", getPtBounds(0), [&, category_name]() {
353  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_denom_pt");
354  });
355  ana.histograms.addVecHistogram(category_name + "_ef_denom_ptlow", getPtBounds(4), [&, category_name]() {
356  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_denom_pt");
357  });
358  ana.histograms.addVecHistogram(category_name + "_ef_denom_ptmtv", getPtBounds(9), [&, category_name]() {
359  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_denom_pt");
360  });
361  ana.histograms.addVecHistogram(category_name + "_ef_denom_ptflatbin", 180, 0., 100, [&, category_name]() {
362  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_denom_pt");
363  });
364  ana.histograms.addVecHistogram(category_name + "_ef_denom_eta", 180, -4.5, 4.5, [&, category_name]() {
365  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_denom_eta");
366  });
367  ana.histograms.addVecHistogram(category_name + "_ef_denom_dxy", 180, -30., 30., [&, category_name]() {
368  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_denom_dxy");
369  });
370  ana.histograms.addVecHistogram(category_name + "_ef_denom_vxy", 180, -30., 30., [&, category_name]() {
371  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_denom_vxy");
372  });
373  ana.histograms.addVecHistogram(category_name + "_ef_denom_dz", 180, -30., 30., [&, category_name]() {
374  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_denom_dz");
375  });
376  ana.histograms.addVecHistogram(category_name + "_ef_denom_phi", 180, -M_PI, M_PI, [&, category_name]() {
377  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_denom_phi");
378  });
379 
380  ana.histograms.addVecHistogram(category_name + "_ef_numer_pt", getPtBounds(0), [&, category_name]() {
381  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_numer_pt");
382  });
383  ana.histograms.addVecHistogram(category_name + "_ef_numer_ptlow", getPtBounds(4), [&, category_name]() {
384  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_numer_pt");
385  });
386  ana.histograms.addVecHistogram(category_name + "_ef_numer_ptmtv", getPtBounds(9), [&, category_name]() {
387  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_numer_pt");
388  });
389  ana.histograms.addVecHistogram(category_name + "_ef_numer_ptflatbin", 180, 0., 100, [&, category_name]() {
390  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_numer_pt");
391  });
392  ana.histograms.addVecHistogram(category_name + "_ef_numer_eta", 180, -4.5, 4.5, [&, category_name]() {
393  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_numer_eta");
394  });
395  ana.histograms.addVecHistogram(category_name + "_ef_numer_dxy", 180, -30., 30., [&, category_name]() {
396  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_numer_dxy");
397  });
398  ana.histograms.addVecHistogram(category_name + "_ef_numer_vxy", 180, -30., 30., [&, category_name]() {
399  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_numer_vxy");
400  });
401  ana.histograms.addVecHistogram(category_name + "_ef_numer_dz", 180, -30., 30., [&, category_name]() {
402  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_numer_dz");
403  });
404  ana.histograms.addVecHistogram(category_name + "_ef_numer_phi", 180, -M_PI, M_PI, [&, category_name]() {
405  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ef_numer_phi");
406  });
407 
408  ana.histograms.addVecHistogram(category_name + "_ie_numer_pt", getPtBounds(0), [&, category_name]() {
409  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ie_numer_pt");
410  });
411  ana.histograms.addVecHistogram(category_name + "_ie_numer_ptlow", getPtBounds(4), [&, category_name]() {
412  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ie_numer_pt");
413  });
414  ana.histograms.addVecHistogram(category_name + "_ie_numer_ptmtv", getPtBounds(9), [&, category_name]() {
415  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ie_numer_pt");
416  });
417  ana.histograms.addVecHistogram(category_name + "_ie_numer_ptflatbin", 180, 0., 100, [&, category_name]() {
418  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ie_numer_pt");
419  });
420  ana.histograms.addVecHistogram(category_name + "_ie_numer_eta", 180, -4.5, 4.5, [&, category_name]() {
421  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ie_numer_eta");
422  });
423  ana.histograms.addVecHistogram(category_name + "_ie_numer_dxy", 180, -30., 30., [&, category_name]() {
424  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ie_numer_dxy");
425  });
426  ana.histograms.addVecHistogram(category_name + "_ie_numer_vxy", 180, -30., 30., [&, category_name]() {
427  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ie_numer_vxy");
428  });
429  ana.histograms.addVecHistogram(category_name + "_ie_numer_dz", 180, -30., 30., [&, category_name]() {
430  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ie_numer_dz");
431  });
432  ana.histograms.addVecHistogram(category_name + "_ie_numer_phi", 180, -M_PI, M_PI, [&, category_name]() {
433  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_ie_numer_phi");
434  });
435 }
436 
437 //__________________________________________________________________________________________________________________________________________________________________________
438 void bookDuplicateRateSets(std::vector<RecoTrackSetDefinition>& DRsets) {
439  for (auto& DRset : DRsets) {
440  bookDuplicateRateSet(DRset);
441  }
442 }
443 
444 //__________________________________________________________________________________________________________________________________________________________________________
446  TString category_name = DRset.set_name;
447 
448  // Denominator tracks' quantities
449  ana.tx.createBranch<std::vector<float>>(category_name + "_dr_denom_pt");
450  ana.tx.createBranch<std::vector<float>>(category_name + "_dr_denom_eta");
451  ana.tx.createBranch<std::vector<float>>(category_name + "_dr_denom_phi");
452 
453  // Numerator tracks' quantities
454  ana.tx.createBranch<std::vector<float>>(category_name + "_dr_numer_pt");
455  ana.tx.createBranch<std::vector<float>>(category_name + "_dr_numer_eta");
456  ana.tx.createBranch<std::vector<float>>(category_name + "_dr_numer_phi");
457 
458  // Histogram utility object that is used to define the histograms
459  ana.histograms.addVecHistogram(category_name + "_dr_denom_pt", getPtBounds(0), [&, category_name]() {
460  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_dr_denom_pt");
461  });
462  ana.histograms.addVecHistogram(category_name + "_dr_denom_ptlow", getPtBounds(4), [&, category_name]() {
463  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_dr_denom_pt");
464  });
465  ana.histograms.addVecHistogram(category_name + "_dr_denom_ptmtv", getPtBounds(9), [&, category_name]() {
466  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_dr_denom_pt");
467  });
468  ana.histograms.addVecHistogram(category_name + "_dr_denom_eta", 180, -4.5, 4.5, [&, category_name]() {
469  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_dr_denom_eta");
470  });
471  ana.histograms.addVecHistogram(category_name + "_dr_denom_phi", 180, -M_PI, M_PI, [&, category_name]() {
472  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_dr_denom_phi");
473  });
474  ana.histograms.addVecHistogram(category_name + "_dr_numer_pt", getPtBounds(0), [&, category_name]() {
475  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_dr_numer_pt");
476  });
477  ana.histograms.addVecHistogram(category_name + "_dr_numer_ptlow", getPtBounds(4), [&, category_name]() {
478  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_dr_numer_pt");
479  });
480  ana.histograms.addVecHistogram(category_name + "_dr_numer_ptmtv", getPtBounds(9), [&, category_name]() {
481  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_dr_numer_pt");
482  });
483  ana.histograms.addVecHistogram(category_name + "_dr_numer_eta", 180, -4.5, 4.5, [&, category_name]() {
484  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_dr_numer_eta");
485  });
486  ana.histograms.addVecHistogram(category_name + "_dr_numer_phi", 180, -M_PI, M_PI, [&, category_name]() {
487  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_dr_numer_phi");
488  });
489 }
490 
491 //__________________________________________________________________________________________________________________________________________________________________________
492 void bookFakeRateSets(std::vector<RecoTrackSetDefinition>& FRsets) {
493  for (auto& FRset : FRsets) {
494  bookFakeRateSet(FRset);
495  }
496 }
497 
498 //__________________________________________________________________________________________________________________________________________________________________________
500  TString category_name = FRset.set_name;
501 
502  // Denominator tracks' quantities
503  ana.tx.createBranch<std::vector<float>>(category_name + "_fr_denom_pt");
504  ana.tx.createBranch<std::vector<float>>(category_name + "_fr_denom_eta");
505  ana.tx.createBranch<std::vector<float>>(category_name + "_fr_denom_phi");
506 
507  // Numerator tracks' quantities
508  ana.tx.createBranch<std::vector<float>>(category_name + "_fr_numer_pt");
509  ana.tx.createBranch<std::vector<float>>(category_name + "_fr_numer_eta");
510  ana.tx.createBranch<std::vector<float>>(category_name + "_fr_numer_phi");
511 
512  // Histogram utility object that is used to define the histograms
513  ana.histograms.addVecHistogram(category_name + "_fr_denom_pt", getPtBounds(0), [&, category_name]() {
514  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_fr_denom_pt");
515  });
516  ana.histograms.addVecHistogram(category_name + "_fr_denom_ptlow", getPtBounds(4), [&, category_name]() {
517  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_fr_denom_pt");
518  });
519  ana.histograms.addVecHistogram(category_name + "_fr_denom_ptmtv", getPtBounds(9), [&, category_name]() {
520  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_fr_denom_pt");
521  });
522  ana.histograms.addVecHistogram(category_name + "_fr_denom_eta", 180, -4.5, 4.5, [&, category_name]() {
523  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_fr_denom_eta");
524  });
525  ana.histograms.addVecHistogram(category_name + "_fr_numer_phi", 180, -M_PI, M_PI, [&, category_name]() {
526  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_fr_numer_phi");
527  });
528  ana.histograms.addVecHistogram(category_name + "_fr_numer_pt", getPtBounds(0), [&, category_name]() {
529  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_fr_numer_pt");
530  });
531  ana.histograms.addVecHistogram(category_name + "_fr_numer_ptlow", getPtBounds(4), [&, category_name]() {
532  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_fr_numer_pt");
533  });
534  ana.histograms.addVecHistogram(category_name + "_fr_numer_ptmtv", getPtBounds(9), [&, category_name]() {
535  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_fr_numer_pt");
536  });
537  ana.histograms.addVecHistogram(category_name + "_fr_numer_eta", 180, -4.5, 4.5, [&, category_name]() {
538  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_fr_numer_eta");
539  });
540  ana.histograms.addVecHistogram(category_name + "_fr_denom_phi", 180, -M_PI, M_PI, [&, category_name]() {
541  return ana.tx.getBranchLazy<std::vector<float>>(category_name + "_fr_denom_phi");
542  });
543 }
544 
545 // ---------------------------------------------------------=============================================-------------------------------------------------------------------
546 // ---------------------------------------------------------=============================================-------------------------------------------------------------------
547 // ---------------------------------------------------------=============================================-------------------------------------------------------------------
548 // ---------------------------------------------------------=============================================-------------------------------------------------------------------
549 // ---------------------------------------------------------=============================================-------------------------------------------------------------------
550 
551 //__________________________________________________________________________________________________________________________________________________________________________
552 void fillEfficiencySets(std::vector<SimTrackSetDefinition>& effsets) {
553  for (auto& effset : effsets) {
554  for (unsigned int isimtrk = 0; isimtrk < lstEff.sim_pt().size(); ++isimtrk) {
555  fillEfficiencySet(isimtrk, effset);
556  }
557  }
558 }
559 
560 //__________________________________________________________________________________________________________________________________________________________________________
561 void fillEfficiencySet(int isimtrk, SimTrackSetDefinition& effset) {
562  //=========================================================
563  // NOTE: The following is not applied as the LSTNtuple no longer writes this.
564  // const int &bunch = lstEff.sim_bunchCrossing()[isimtrk];
565  // const int &event = lstEff.sim_event()[isimtrk];
566  // if (bunch != 0)
567  // return;
568  // if (event != 0)
569  // return;
570  //=========================================================
571 
572  const float& pt = lstEff.sim_pt()[isimtrk];
573  const float& eta = lstEff.sim_eta()[isimtrk];
574  const float& dz = lstEff.sim_pca_dz()[isimtrk];
575  const float& dxy = lstEff.sim_pca_dxy()[isimtrk];
576  const float& phi = lstEff.sim_phi()[isimtrk];
577  const int& pdgidtrk = lstEff.sim_pdgId()[isimtrk];
578  const int& q = lstEff.sim_q()[isimtrk];
579  const float& vtx_x = lstEff.sim_vx()[isimtrk];
580  const float& vtx_y = lstEff.sim_vy()[isimtrk];
581  const float& vtx_z = lstEff.sim_vz()[isimtrk];
582  const float& vtx_perp = sqrt(vtx_x * vtx_x + vtx_y * vtx_y);
583  bool pass = effset.pass(isimtrk);
584  bool sel = effset.sel(isimtrk);
585 
586  if (effset.pdgid != 0) {
587  if (abs(pdgidtrk) != abs(effset.pdgid))
588  return;
589  }
590 
591  if (effset.q != 0) {
592  if (q != effset.q)
593  return;
594  }
595 
596  if (effset.pdgid == 0 and q == 0)
597  return;
598 
599  if (not sel)
600  return;
601 
602  TString category_name = TString::Format("%s_%d_%d", effset.set_name.Data(), effset.pdgid, effset.q);
603 
604  // https://github.com/cms-sw/cmssw/blob/7cbdb18ec6d11d5fd17ca66c1153f0f4e869b6b0/SimTracker/Common/python/trackingParticleSelector_cfi.py
605  // https://github.com/cms-sw/cmssw/blob/7cbdb18ec6d11d5fd17ca66c1153f0f4e869b6b0/SimTracker/Common/interface/TrackingParticleSelector.h#L122-L124
606  const float vtx_z_thresh = 30;
607  const float vtx_perp_thresh = 2.5;
608 
609  // N minus eta cut
610  if (pt > ana.pt_cut and abs(vtx_z) < vtx_z_thresh and abs(vtx_perp) < vtx_perp_thresh) {
611  // vs. eta plot
612  ana.tx.pushbackToBranch<float>(category_name + "_ef_denom_eta", eta);
613  if (pass)
614  ana.tx.pushbackToBranch<float>(category_name + "_ef_numer_eta", eta);
615  else
616  ana.tx.pushbackToBranch<float>(category_name + "_ie_numer_eta", eta);
617  }
618 
619  // N minus pt cut
620  if (abs(eta) < ana.eta_cut and abs(vtx_z) < vtx_z_thresh and abs(vtx_perp) < vtx_perp_thresh) {
621  // vs. pt plot
622  ana.tx.pushbackToBranch<float>(category_name + "_ef_denom_pt", pt);
623  if (pass)
624  ana.tx.pushbackToBranch<float>(category_name + "_ef_numer_pt", pt);
625  else
626  ana.tx.pushbackToBranch<float>(category_name + "_ie_numer_pt", pt);
627  }
628 
629  // N minus dxy cut
630  if (abs(eta) < ana.eta_cut and pt > ana.pt_cut and abs(vtx_z) < vtx_z_thresh) {
631  // vs. dxy plot
632  ana.tx.pushbackToBranch<float>(category_name + "_ef_denom_dxy", dxy);
633  ana.tx.pushbackToBranch<float>(category_name + "_ef_denom_vxy", vtx_perp);
634  if (pass) {
635  ana.tx.pushbackToBranch<float>(category_name + "_ef_numer_dxy", dxy);
636  ana.tx.pushbackToBranch<float>(category_name + "_ef_numer_vxy", vtx_perp);
637  } else {
638  ana.tx.pushbackToBranch<float>(category_name + "_ie_numer_dxy", dxy);
639  ana.tx.pushbackToBranch<float>(category_name + "_ie_numer_vxy", vtx_perp);
640  }
641  }
642 
643  // N minus dz cut
644  if (abs(eta) < ana.eta_cut and pt > ana.pt_cut and abs(vtx_perp) < vtx_perp_thresh) {
645  // vs. dz plot
646  ana.tx.pushbackToBranch<float>(category_name + "_ef_denom_dz", dz);
647  if (pass)
648  ana.tx.pushbackToBranch<float>(category_name + "_ef_numer_dz", dz);
649  else
650  ana.tx.pushbackToBranch<float>(category_name + "_ie_numer_dz", dz);
651  }
652 
653  // All phase-space cuts
654  if (abs(eta) < ana.eta_cut and pt > ana.pt_cut and abs(vtx_z) < vtx_z_thresh and abs(vtx_perp) < vtx_perp_thresh) {
655  // vs. Phi plot
656  ana.tx.pushbackToBranch<float>(category_name + "_ef_denom_phi", phi);
657  if (pass)
658  ana.tx.pushbackToBranch<float>(category_name + "_ef_numer_phi", phi);
659  else
660  ana.tx.pushbackToBranch<float>(category_name + "_ie_numer_phi", phi);
661  }
662 }
663 
664 //__________________________________________________________________________________________________________________________________________________________________________
665 void fillFakeRateSets(std::vector<RecoTrackSetDefinition>& FRsets) {
666  for (auto& FRset : FRsets) {
667  for (unsigned int itc = 0; itc < FRset.pt().size(); ++itc) {
668  fillFakeRateSet(itc, FRset);
669  }
670  }
671 }
672 
673 //__________________________________________________________________________________________________________________________________________________________________________
675  float pt = FRset.pt().at(itc);
676  float eta = FRset.eta().at(itc);
677  float phi = FRset.phi().at(itc);
678  TString category_name = FRset.set_name;
679  bool pass = FRset.pass(itc);
680  bool sel = FRset.sel(itc);
681 
682  if (not sel)
683  return;
684 
685  if (pt > ana.pt_cut) {
686  ana.tx.pushbackToBranch<float>(category_name + "_fr_denom_eta", eta);
687  if (pass)
688  ana.tx.pushbackToBranch<float>(category_name + "_fr_numer_eta", eta);
689  }
690  if (abs(eta) < ana.eta_cut) {
691  ana.tx.pushbackToBranch<float>(category_name + "_fr_denom_pt", pt);
692  if (pass)
693  ana.tx.pushbackToBranch<float>(category_name + "_fr_numer_pt", pt);
694  }
695  if (abs(eta) < ana.eta_cut and pt > ana.pt_cut) {
696  ana.tx.pushbackToBranch<float>(category_name + "_fr_denom_phi", phi);
697  if (pass)
698  ana.tx.pushbackToBranch<float>(category_name + "_fr_numer_phi", phi);
699  }
700 }
701 
702 //__________________________________________________________________________________________________________________________________________________________________________
703 void fillDuplicateRateSets(std::vector<RecoTrackSetDefinition>& DRsets) {
704  for (auto& DRset : DRsets) {
705  for (unsigned int itc = 0; itc < DRset.pt().size(); ++itc) {
706  fillDuplicateRateSet(itc, DRset);
707  }
708  }
709 }
710 
711 //__________________________________________________________________________________________________________________________________________________________________________
713  float pt = DRset.pt().at(itc);
714  float eta = DRset.eta().at(itc);
715  float phi = DRset.phi().at(itc);
716  TString category_name = DRset.set_name;
717  bool pass = DRset.pass(itc);
718  bool sel = DRset.sel(itc);
719 
720  if (not sel)
721  return;
722 
723  if (pt > ana.pt_cut) {
724  ana.tx.pushbackToBranch<float>(category_name + "_dr_denom_eta", eta);
725  if (pass)
726  ana.tx.pushbackToBranch<float>(category_name + "_dr_numer_eta", eta);
727  }
728  if (abs(eta) < ana.eta_cut) {
729  ana.tx.pushbackToBranch<float>(category_name + "_dr_denom_pt", pt);
730  if (pass)
731  ana.tx.pushbackToBranch<float>(category_name + "_dr_numer_pt", pt);
732  }
733  if (abs(eta) < ana.eta_cut and pt > ana.pt_cut) {
734  ana.tx.pushbackToBranch<float>(category_name + "_dr_denom_phi", phi);
735  if (pass)
736  ana.tx.pushbackToBranch<float>(category_name + "_dr_numer_phi", phi);
737  }
738 }
const std::vector< int > & pT5_isFake()
Definition: LSTEff.cc:2481
const std::vector< float > & t5_phi()
Definition: LSTEff.cc:3299
void fillDuplicateRateSets(std::vector< RecoTrackSetDefinition > &DRsets)
Definition: performance.cc:703
const std::vector< float > & pT5_eta()
Definition: LSTEff.cc:3342
std::vector< float > getPtBounds(int mode)
Definition: helper.cc:242
const std::vector< int > & sim_TC_matched()
Definition: LSTEff.cc:2865
RooUtil::TTreeX * tx
const std::vector< float > & pT3_eta()
Definition: LSTEff.cc:3349
Definition: performance.cc:3
const std::vector< float > & tc_pt()
Definition: LSTEff.cc:3325
const std::vector< int > & t5_isFake()
Definition: LSTEff.cc:2025
const std::vector< int > & tc_type()
Definition: LSTEff.cc:3368
void saveOutput()
Definition: anautil.cc:308
const std::vector< float > & sim_vy()
Definition: LSTEff.cc:3069
void bookFakeRateSets(std::vector< RecoTrackSetDefinition > &FRsets)
Definition: performance.cc:492
void pushbackToBranch(TString, T)
AnalysisConfig ana
RooUtil::Cutflow cutflow
std::function< const std::vector< float >)> pt
Definition: helper.h:85
const std::vector< float > & sim_eta()
Definition: LSTEff.cc:1557
const std::vector< int > & tc_isDuplicate()
Definition: LSTEff.cc:1677
const std::vector< float > & tc_eta()
Definition: LSTEff.cc:3353
const std::vector< int > & tc_type()
Definition: LSTEff.cc:2925
void bookFakeRateSet(RecoTrackSetDefinition &FRset)
Definition: performance.cc:499
int main(int argc, char **argv)
Definition: performance.cc:6
const std::vector< int > & sim_pT3_matched()
Definition: LSTEff.cc:1701
unsigned int getNEventsProcessed()
Definition: looper.h:114
const std::vector< int > & pT3_isFake()
Definition: LSTEff.cc:2181
std::function< bool(unsigned int)> pass
Definition: helper.h:75
pdgids
Definition: ntuple.py:97
const std::vector< float > & sim_phi()
Definition: LSTEff.cc:2469
const std::vector< int > & t5_isDuplicate()
Definition: LSTEff.cc:2805
const std::vector< float > & sim_pca_dxy()
Definition: LSTEff.cc:2229
const std::vector< float > & sim_vx()
Definition: LSTEff.cc:3057
const std::vector< int > & sim_T5_matched()
Definition: LSTEff.cc:2769
const std::vector< float > & vtx_y()
Definition: Trktree.cc:6846
const std::vector< float > & tc_phi()
Definition: LSTEff.cc:3343
const T & getBranchLazy(TString)
void createBranch(TString, bool=true)
T sqrt(T t)
Definition: SSEVec.h:23
void fillEfficiencySets(std::vector< SimTrackSetDefinition > &effsets)
Definition: performance.cc:552
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void bookDuplicateRateSet(RecoTrackSetDefinition &DRset)
Definition: performance.cc:445
std::function< bool(unsigned int)> pass
Definition: helper.h:83
const std::vector< int > & sim_pT5_matched()
Definition: LSTEff.cc:3153
RooUtil::Looper< Trktree > looper
void fillEfficiencySet(int isimtrk, SimTrackSetDefinition &effset)
Definition: performance.cc:561
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::vector< int > & sim_q()
Definition: LSTEff.cc:1545
const std::vector< float > & sim_pt()
Definition: LSTEff.cc:1785
RooUtil::Histograms histograms
std::function< const std::vector< float >)> phi
Definition: helper.h:87
std::function< bool(unsigned int)> sel
Definition: helper.h:84
void bookEfficiencySets(std::vector< SimTrackSetDefinition > &effsets)
Definition: performance.cc:319
const std::vector< float > & vtx_x()
Definition: Trktree.cc:6944
#define M_PI
void fillFakeRateSet(int itc, RecoTrackSetDefinition &FRset)
Definition: performance.cc:674
const std::vector< float > & vtx_z()
Definition: Trktree.cc:6844
void addVecHistogram(TString, unsigned int, float, float, std::function< std::vector< float >()>, std::function< std::vector< float >()> wgt=nullptr)
Definition: anautil.cc:1114
const std::vector< float > & pT5_phi()
Definition: LSTEff.cc:3302
void fillDuplicateRateSet(int itc, RecoTrackSetDefinition &DRset)
Definition: performance.cc:712
void bookDuplicateRateSets(std::vector< RecoTrackSetDefinition > &DRsets)
Definition: performance.cc:438
LSTEff lstEff
Definition: LSTEff.cc:2
const std::vector< int > & sim_pdgId()
Definition: LSTEff.cc:1821
const std::vector< float > & sim_vz()
Definition: LSTEff.cc:3081
float pt_cut
Definition: helper.h:23
const std::vector< float > & t5_pt()
Definition: LSTEff.cc:3301
std::vector< int > pdgids
Definition: helper.h:60
TFile * output_tfile
const std::vector< float > & pT3_phi()
Definition: LSTEff.cc:3341
void initializeInputsAndOutputs()
Definition: helper.cc:194
TString set_name
Definition: helper.h:72
void bookEfficiencySet(SimTrackSetDefinition &effset)
Definition: performance.cc:325
std::function< const std::vector< float >)> eta
Definition: helper.h:86
const std::vector< int > & sim_TC_matched_mask()
Definition: LSTEff.cc:2877
const std::vector< float > & sim_pca_dz()
Definition: LSTEff.cc:2517
const std::vector< float > & pT3_pt()
Definition: LSTEff.cc:3324
charges
only generated particles of these IDs are considered
const std::vector< float > & pT5_pt()
Definition: LSTEff.cc:3327
void bookHistograms(Histograms &histograms)
Definition: anautil.cc:666
void fillFakeRateSets(std::vector< RecoTrackSetDefinition > &FRsets)
Definition: performance.cc:665
const std::vector< int > & pT3_isDuplicate()
Definition: LSTEff.cc:1665
const std::vector< int > & pT5_isDuplicate()
Definition: LSTEff.cc:1641
bool nextEvent()
Definition: looper.h:526
std::function< bool(unsigned int)> sel
Definition: helper.h:76
float eta_cut
Definition: helper.h:26
const std::vector< int > & tc_isFake()
Definition: LSTEff.cc:2169
const std::vector< float > & t5_eta()
Definition: LSTEff.cc:3259
void clear()
Definition: ttreex.cc:40