CMS 3D CMS Logo

TICLCandidateValidator.cc
Go to the documentation of this file.
1 #include <numeric>
2 #include <iomanip>
3 #include <sstream>
4 
7 
8 TICLCandidateValidator::TICLCandidateValidator(edm::EDGetTokenT<std::vector<TICLCandidate>> ticlCandidates,
9  edm::EDGetTokenT<std::vector<TICLCandidate>> simTICLCandidatesToken,
10  edm::EDGetTokenT<std::vector<reco::Track>> recoTracksToken,
11  edm::EDGetTokenT<std::vector<ticl::Trackster>> trackstersToken,
14  bool isTICLv5)
15  : TICLCandidatesToken_(ticlCandidates),
16  simTICLCandidatesToken_(simTICLCandidatesToken),
17  recoTracksToken_(recoTracksToken),
18  trackstersToken_(trackstersToken),
19  associatorMapRtSToken_(associatorMapRtSToken),
20  associatorMapStRToken_(associatorMapStRToken),
21  isTICLv5_(isTICLv5) {}
22 
24 
27  std::string baseDir) const {
28  // book CAND histos
29  histograms.h_tracksters_in_candidate =
30  ibook.book1D("N of tracksters in candidate", "N of tracksters in candidate", 100, 0, 99);
31  histograms.h_candidate_raw_energy =
32  ibook.book1D("Candidates raw energy", "Candidates raw energy;E (GeV)", 250, 0, 250);
33  histograms.h_candidate_regressed_energy =
34  ibook.book1D("Candidates regressed energy", "Candidates regressed energy;E (GeV)", 250, 0, 250);
35  histograms.h_candidate_pT = ibook.book1D("Candidates pT", "Candidates pT;p_{T}", 250, 0, 250);
36  histograms.h_candidate_charge = ibook.book1D("Candidates charge", "Candidates charge;Charge", 3, -1.5, 1.5);
37  histograms.h_candidate_pdgId = ibook.book1D("Candidates PDG Id", "Candidates PDG ID", 100, -220, 220);
38  histograms.h_candidate_partType = ibook.book1D("Candidates type", "Candidates type", 9, -0.5, 8.5);
39 
40  // neutral: photon, pion, hadron
41  const std::vector<std::string> neutrals{"photons", "neutral_pions", "neutral_hadrons"};
42  for (long unsigned int i = 0; i < neutrals.size(); i++) {
43  ibook.setCurrentFolder(baseDir + "/" + neutrals[i]);
44 
45  histograms.h_neut_tracksters_in_candidate.push_back(ibook.book1D("N of tracksters in candidate for " + neutrals[i],
46  "N of tracksters in candidate for " + neutrals[i],
47  100,
48  0,
49  99));
50  histograms.h_neut_candidate_regressed_energy.push_back(ibook.book1D(
51  neutrals[i] + "candidates regressed energy", neutrals[i] + " candidates regressed energy;E (GeV)", 250, 0, 250));
52  histograms.h_neut_candidate_charge.push_back(
53  ibook.book1D(neutrals[i] + " candidates charge", neutrals[i] + " candidates charge;Charge", 3, -1.5, 1.5));
54  histograms.h_neut_candidate_pdgId.push_back(
55  ibook.book1D(neutrals[i] + " candidates PDG Id", neutrals[i] + " candidates PDG ID", 100, -220, 220));
56  histograms.h_neut_candidate_partType.push_back(
57  ibook.book1D(neutrals[i] + " candidates type", neutrals[i] + " candidates type", 9, -0.5, 8.5));
58 
59  histograms.h_den_fake_neut_energy_candidate.push_back(
60  ibook.book1D("den_fake_cand_vs_energy_" + neutrals[i], neutrals[i] + " candidates energy;E (GeV)", 50, 0, 250));
61  histograms.h_num_fake_neut_energy_candidate_pdgId.push_back(ibook.book1D(
62  "num_fake_pid_cand_vs_energy_" + neutrals[i], neutrals[i] + " PID fake vs energy;E (GeV)", 50, 0, 250));
63  histograms.h_num_fake_neut_energy_candidate_energy.push_back(
64  ibook.book1D("num_fake_energy_cand_vs_energy_" + neutrals[i],
65  neutrals[i] + " PID and energy fake vs energy;E (GeV)",
66  50,
67  0,
68  250));
69  histograms.h_den_fake_neut_pt_candidate.push_back(
70  ibook.book1D("den_fake_cand_vs_pt_" + neutrals[i], neutrals[i] + " candidates pT;p_{T} (GeV)", 50, 0, 250));
71  histograms.h_num_fake_neut_pt_candidate_pdgId.push_back(ibook.book1D(
72  "num_fake_pid_cand_vs_pt_" + neutrals[i], neutrals[i] + " PID fake vs pT;p_{T} (GeV)", 50, 0, 250));
73  histograms.h_num_fake_neut_pt_candidate_energy.push_back(
74  ibook.book1D("num_fake_energy_cand_vs_pt_" + neutrals[i],
75  neutrals[i] + " PID and energy fake vs pT;p_{T} (GeV)",
76  50,
77  0,
78  250));
79  histograms.h_den_fake_neut_eta_candidate.push_back(
80  ibook.book1D("den_fake_cand_vs_eta_" + neutrals[i], neutrals[i] + " candidates eta;#eta (GeV)", 50, -3, 3));
81  histograms.h_num_fake_neut_eta_candidate_pdgId.push_back(ibook.book1D(
82  "num_fake_pid_cand_vs_eta_" + neutrals[i], neutrals[i] + " PID fake vs eta;#eta (GeV)", 50, -3, 3));
83  histograms.h_num_fake_neut_eta_candidate_energy.push_back(
84  ibook.book1D("num_fake_energy_cand_vs_eta_" + neutrals[i],
85  neutrals[i] + " PID and energy fake vs eta;#eta (GeV)",
86  50,
87  -3,
88  3));
89  histograms.h_den_fake_neut_phi_candidate.push_back(ibook.book1D(
90  "den_fake_cand_vs_phi_" + neutrals[i], neutrals[i] + " candidates phi;#phi (GeV)", 50, -3.14159, 3.14159));
91  histograms.h_num_fake_neut_phi_candidate_pdgId.push_back(ibook.book1D(
92  "num_fake_pid_cand_vs_phi_" + neutrals[i], neutrals[i] + " PID fake vs phi;#phi (GeV)", 50, -3.14159, 3.14159));
93  histograms.h_num_fake_neut_phi_candidate_energy.push_back(
94  ibook.book1D("num_fake_energy_cand_vs_phi_" + neutrals[i],
95  neutrals[i] + " PID and energy fake vs phi;#phi (GeV)",
96  50,
97  -3.14159,
98  3.14159));
99 
100  histograms.h_den_neut_energy_candidate.push_back(
101  ibook.book1D("den_cand_vs_energy_" + neutrals[i], neutrals[i] + " simCandidates energy;E (GeV)", 50, 0, 250));
102  histograms.h_num_neut_energy_candidate_pdgId.push_back(
103  ibook.book1D("num_pid_cand_vs_energy_" + neutrals[i],
104  neutrals[i] + " track and PID efficiency vs energy;E (GeV)",
105  50,
106  0,
107  250));
108  histograms.h_num_neut_energy_candidate_energy.push_back(
109  ibook.book1D("num_energy_cand_vs_energy_" + neutrals[i],
110  neutrals[i] + " track, PID and energy efficiency vs energy;E (GeV)",
111  50,
112  0,
113  250));
114  histograms.h_den_neut_pt_candidate.push_back(
115  ibook.book1D("den_cand_vs_pt_" + neutrals[i], neutrals[i] + " simCandidates pT;p_{T} (GeV)", 50, 0, 250));
116  histograms.h_num_neut_pt_candidate_pdgId.push_back(ibook.book1D(
117  "num_pid_cand_vs_pt_" + neutrals[i], neutrals[i] + " track and PID efficiency vs pT;p_{T} (GeV)", 50, 0, 250));
118  histograms.h_num_neut_pt_candidate_energy.push_back(
119  ibook.book1D("num_energy_cand_vs_pt_" + neutrals[i],
120  neutrals[i] + " track, PID and energy efficiency vs pT;p_{T} (GeV)",
121  50,
122  0,
123  250));
124  histograms.h_den_neut_eta_candidate.push_back(
125  ibook.book1D("den_cand_vs_eta_" + neutrals[i], neutrals[i] + " simCandidates eta;#eta (GeV)", 50, -3, 3));
126  histograms.h_num_neut_eta_candidate_pdgId.push_back(ibook.book1D(
127  "num_pid_cand_vs_eta_" + neutrals[i], neutrals[i] + " track and PID efficiency vs eta;#eta (GeV)", 50, -3, 3));
128  histograms.h_num_neut_eta_candidate_energy.push_back(
129  ibook.book1D("num_energy_cand_vs_eta_" + neutrals[i],
130  neutrals[i] + " track, PID and energy efficiency vs eta;#eta (GeV)",
131  50,
132  -3,
133  3));
134  histograms.h_den_neut_phi_candidate.push_back(ibook.book1D(
135  "den_cand_vs_phi_" + neutrals[i], neutrals[i] + " simCandidates phi;#phi (GeV)", 50, -3.14159, 3.14159));
136  histograms.h_num_neut_phi_candidate_pdgId.push_back(
137  ibook.book1D("num_pid_cand_vs_phi_" + neutrals[i],
138  neutrals[i] + " track and PID efficiency vs phi;#phi (GeV)",
139  50,
140  -3.14159,
141  3.14159));
142  histograms.h_num_neut_phi_candidate_energy.push_back(
143  ibook.book1D("num_energy_cand_vs_phi_" + neutrals[i],
144  neutrals[i] + " track, PID and energy efficiency vs phi;#phi (GeV)",
145  50,
146  -3.14159,
147  3.14159));
148  }
149  // charged: electron, muon, hadron
150  const std::vector<std::string> charged{"electrons", "muons", "charged_hadrons"};
151  for (long unsigned int i = 0; i < charged.size(); i++) {
152  ibook.setCurrentFolder(baseDir + "/" + charged[i]);
153 
154  histograms.h_chg_tracksters_in_candidate.push_back(ibook.book1D(
155  "N of tracksters in candidate for " + charged[i], "N of tracksters in candidate for " + charged[i], 100, 0, 99));
156  histograms.h_chg_candidate_regressed_energy.push_back(ibook.book1D(
157  charged[i] + "candidates regressed energy", charged[i] + " candidates regressed energy;E (GeV)", 250, 0, 250));
158  histograms.h_chg_candidate_charge.push_back(
159  ibook.book1D(charged[i] + " candidates charge", charged[i] + " candidates charge;Charge", 3, -1.5, 1.5));
160  histograms.h_chg_candidate_pdgId.push_back(
161  ibook.book1D(charged[i] + " candidates PDG Id", charged[i] + " candidates PDG ID", 100, -220, 220));
162  histograms.h_chg_candidate_partType.push_back(
163  ibook.book1D(charged[i] + " candidates type", charged[i] + " candidates type", 9, -0.5, 8.5));
164 
165  histograms.h_den_fake_chg_energy_candidate.push_back(
166  ibook.book1D("den_fake_cand_vs_energy_" + charged[i], charged[i] + " candidates energy;E (GeV)", 50, 0, 250));
167  histograms.h_num_fake_chg_energy_candidate_track.push_back(ibook.book1D(
168  "num_fake_track_cand_vs_energy_" + charged[i], charged[i] + " track fake vs energy;E (GeV)", 50, 0, 250));
169  histograms.h_num_fake_chg_energy_candidate_pdgId.push_back(ibook.book1D(
170  "num_fake_pid_cand_vs_energy_" + charged[i], charged[i] + " track and PID fake vs energy;E (GeV)", 50, 0, 250));
171  histograms.h_num_fake_chg_energy_candidate_energy.push_back(
172  ibook.book1D("num_fake_energy_cand_vs_energy_" + charged[i],
173  charged[i] + " track, PID and energy fake vs energy;E (GeV)",
174  50,
175  0,
176  250));
177  histograms.h_den_fake_chg_pt_candidate.push_back(
178  ibook.book1D("den_fake_cand_vs_pt_" + charged[i], charged[i] + " candidates pT;p_{T} (GeV)", 50, 0, 250));
179  histograms.h_num_fake_chg_pt_candidate_track.push_back(ibook.book1D(
180  "num_fake_track_cand_vs_pt_" + charged[i], charged[i] + " track fake vs pT;p_{T} (GeV)", 50, 0, 250));
181  histograms.h_num_fake_chg_pt_candidate_pdgId.push_back(ibook.book1D(
182  "num_fake_pid_cand_vs_pt_" + charged[i], charged[i] + " track and PID fake vs pT;p_{T} (GeV)", 50, 0, 250));
183  histograms.h_num_fake_chg_pt_candidate_energy.push_back(
184  ibook.book1D("num_fake_energy_cand_vs_pt_" + charged[i],
185  charged[i] + " track, PID and energy fake vs pT;p_{T} (GeV)",
186  50,
187  0,
188  250));
189  histograms.h_den_fake_chg_eta_candidate.push_back(
190  ibook.book1D("den_fake_cand_vs_eta_" + charged[i], charged[i] + " candidates eta;#eta (GeV)", 50, -3, 3));
191  histograms.h_num_fake_chg_eta_candidate_track.push_back(ibook.book1D(
192  "num_fake_track_cand_vs_eta_" + charged[i], charged[i] + " track fake vs eta;#eta (GeV)", 50, -3, 3));
193  histograms.h_num_fake_chg_eta_candidate_pdgId.push_back(ibook.book1D(
194  "num_fake_pid_cand_vs_eta_" + charged[i], charged[i] + " track and PID fake vs eta;#eta (GeV)", 50, -3, 3));
195  histograms.h_num_fake_chg_eta_candidate_energy.push_back(
196  ibook.book1D("num_fake_energy_cand_vs_eta_" + charged[i],
197  charged[i] + " track, PID and energy fake vs eta;#eta (GeV)",
198  50,
199  -3,
200  3));
201  histograms.h_den_fake_chg_phi_candidate.push_back(ibook.book1D(
202  "den_fake_cand_vs_phi_" + charged[i], charged[i] + " candidates phi;#phi (GeV)", 50, -3.14159, 3.14159));
203  histograms.h_num_fake_chg_phi_candidate_track.push_back(ibook.book1D("num_fake_track_cand_vs_phi_" + charged[i],
204  charged[i] + " track fake vs phi;#phi (GeV)",
205  50,
206  -3.14159,
207  3.14159));
208  histograms.h_num_fake_chg_phi_candidate_pdgId.push_back(
209  ibook.book1D("num_fake_pid_cand_vs_phi_" + charged[i],
210  charged[i] + " track and PID fake vs phi;#phi (GeV)",
211  50,
212  -3.14159,
213  3.14159));
214  histograms.h_num_fake_chg_phi_candidate_energy.push_back(
215  ibook.book1D("num_fake_energy_cand_vs_phi_" + charged[i],
216  charged[i] + " track, PID and energy fake vs phi;#phi (GeV)",
217  50,
218  -3.14159,
219  3.14159));
220 
221  histograms.h_den_chg_energy_candidate.push_back(
222  ibook.book1D("den_cand_vs_energy_" + charged[i], charged[i] + " simCandidates energy;E (GeV)", 50, 0, 250));
223  histograms.h_num_chg_energy_candidate_track.push_back(ibook.book1D(
224  "num_track_cand_vs_energy_" + charged[i], charged[i] + " track efficiency vs energy;E (GeV)", 50, 0, 250));
225  histograms.h_num_chg_energy_candidate_pdgId.push_back(ibook.book1D(
226  "num_pid_cand_vs_energy_" + charged[i], charged[i] + " track and PID efficiency vs energy;E (GeV)", 50, 0, 250));
227  histograms.h_num_chg_energy_candidate_energy.push_back(
228  ibook.book1D("num_energy_cand_vs_energy_" + charged[i],
229  charged[i] + " track, PID and energy efficiency vs energy;E (GeV)",
230  50,
231  0,
232  250));
233  histograms.h_den_chg_pt_candidate.push_back(
234  ibook.book1D("den_cand_vs_pt_" + charged[i], charged[i] + " simCandidates pT;p_{T} (GeV)", 50, 0, 250));
235  histograms.h_num_chg_pt_candidate_track.push_back(ibook.book1D(
236  "num_track_cand_vs_pt_" + charged[i], charged[i] + " track efficiency vs pT;p_{T} (GeV)", 50, 0, 250));
237  histograms.h_num_chg_pt_candidate_pdgId.push_back(ibook.book1D(
238  "num_pid_cand_vs_pt_" + charged[i], charged[i] + " track and PID efficiency vs pT;p_{T} (GeV)", 50, 0, 250));
239  histograms.h_num_chg_pt_candidate_energy.push_back(
240  ibook.book1D("num_energy_cand_vs_pt_" + charged[i],
241  charged[i] + " track, PID and energy efficiency vs pT;p_{T} (GeV)",
242  50,
243  0,
244  250));
245  histograms.h_den_chg_eta_candidate.push_back(
246  ibook.book1D("den_cand_vs_eta_" + charged[i], charged[i] + " simCandidates eta;#eta (GeV)", 50, -3, 3));
247  histograms.h_num_chg_eta_candidate_track.push_back(ibook.book1D(
248  "num_track_cand_vs_eta_" + charged[i], charged[i] + " track efficiency vs eta;#eta (GeV)", 50, -3, 3));
249  histograms.h_num_chg_eta_candidate_pdgId.push_back(ibook.book1D(
250  "num_pid_cand_vs_eta_" + charged[i], charged[i] + " track and PID efficiency vs eta;#eta (GeV)", 50, -3, 3));
251  histograms.h_num_chg_eta_candidate_energy.push_back(
252  ibook.book1D("num_energy_cand_vs_eta_" + charged[i],
253  charged[i] + " track, PID and energy efficiency vs eta;#eta (GeV)",
254  50,
255  -3,
256  3));
257  histograms.h_den_chg_phi_candidate.push_back(ibook.book1D(
258  "den_cand_vs_phi_" + charged[i], charged[i] + " simCandidates phi;#phi (GeV)", 50, -3.14159, 3.14159));
259  histograms.h_num_chg_phi_candidate_track.push_back(ibook.book1D("num_track_cand_vs_phi_" + charged[i],
260  charged[i] + " track efficiency vs phi;#phi (GeV)",
261  50,
262  -3.14159,
263  3.14159));
264  histograms.h_num_chg_phi_candidate_pdgId.push_back(
265  ibook.book1D("num_pid_cand_vs_phi_" + charged[i],
266  charged[i] + " track and PID efficiency vs phi;#phi (GeV)",
267  50,
268  -3.14159,
269  3.14159));
270  histograms.h_num_chg_phi_candidate_energy.push_back(
271  ibook.book1D("num_energy_cand_vs_phi_" + charged[i],
272  charged[i] + " track, PID and energy efficiency vs phi;#phi (GeV)",
273  50,
274  -3.14159,
275  3.14159));
276  }
277 }
278 
280  const Histograms& histograms,
281  edm::Handle<ticl::TracksterCollection> simTrackstersCP_h) const {
282  auto TICLCandidates = event.get(TICLCandidatesToken_);
283 
284  edm::Handle<std::vector<TICLCandidate>> simTICLCandidates_h;
285  event.getByToken(simTICLCandidatesToken_, simTICLCandidates_h);
286  auto simTICLCandidates = *simTICLCandidates_h;
287 
289  event.getByToken(recoTracksToken_, recoTracks_h);
290  auto recoTracks = *recoTracks_h;
291 
293  event.getByToken(trackstersToken_, Tracksters_h);
294  auto trackstersMerged = *Tracksters_h;
295 
297  event.getByToken(associatorMapRtSToken_, mergeTsRecoToSim_h);
298  auto const& mergeTsRecoToSimMap = *mergeTsRecoToSim_h;
299 
301  event.getByToken(associatorMapStRToken_, mergeTsSimToReco_h);
302  auto const& mergeTsSimToRecoMap = *mergeTsSimToReco_h;
303 
304  // candidates plots
305  for (const auto& cand : TICLCandidates) {
306  histograms.h_tracksters_in_candidate->Fill(cand.tracksters().size());
307  histograms.h_candidate_raw_energy->Fill(cand.rawEnergy());
308  histograms.h_candidate_regressed_energy->Fill(cand.energy());
309  histograms.h_candidate_pT->Fill(cand.pt());
310  histograms.h_candidate_charge->Fill(cand.charge());
311  histograms.h_candidate_pdgId->Fill(cand.pdgId());
312  const auto& arr = cand.idProbabilities();
313  histograms.h_candidate_partType->Fill(std::max_element(arr.begin(), arr.end()) - arr.begin());
314  }
315 
316  std::vector<int> chargedCandidates;
317  std::vector<int> neutralCandidates;
318  chargedCandidates.reserve(simTICLCandidates.size());
319  neutralCandidates.reserve(simTICLCandidates.size());
320 
321  for (size_t i = 0; i < simTICLCandidates.size(); ++i) {
322  const auto& simCand = simTICLCandidates[i];
323  const auto particleType = ticl::tracksterParticleTypeFromPdgId(simCand.pdgId(), simCand.charge());
327  chargedCandidates.emplace_back(i);
331  neutralCandidates.emplace_back(i);
332  // should consider also unknown ?
333  }
334 
335  chargedCandidates.shrink_to_fit();
336  neutralCandidates.shrink_to_fit();
337 
338  for (const auto i : chargedCandidates) {
339  const auto& simCand = simTICLCandidates[i];
340  auto index = std::log2(int(ticl::tracksterParticleTypeFromPdgId(simCand.pdgId(), 1)));
341  /* 11 (type 1) becomes 0
342  * 13 (type 2) becomes 1
343  * 211 (type 4) becomes 2
344  */
345  int32_t simCandTrackIdx = -1;
346  if (simCand.trackPtr().get() != nullptr)
347  simCandTrackIdx = simCand.trackPtr().get() - edm::Ptr<reco::Track>(recoTracks_h, 0).get();
348  else {
349  // no reco track, but simCand is charged
350  continue;
351  }
352  if (simCand.trackPtr().get()->pt() < 1 or simCand.trackPtr().get()->missingOuterHits() > 5 or
353  not simCand.trackPtr().get()->quality(reco::TrackBase::highPurity))
354  continue;
355 
356  // +1 to all denominators
357  histograms.h_den_chg_energy_candidate[index]->Fill(simCand.rawEnergy());
358  histograms.h_den_chg_pt_candidate[index]->Fill(simCand.pt());
359  histograms.h_den_chg_eta_candidate[index]->Fill(simCand.eta());
360  histograms.h_den_chg_phi_candidate[index]->Fill(simCand.phi());
361 
362  int32_t cand_idx = -1;
363  float shared_energy = 0.;
364  const auto ts_vec = mergeTsSimToRecoMap[i];
365  if (!ts_vec.empty()) {
366  auto min_elem =
367  std::min_element(ts_vec.begin(), ts_vec.end(), [](auto const& ts1_id_pair, auto const& ts2_id_pair) {
368  return ts1_id_pair.second.second < ts2_id_pair.second.second;
369  });
370  shared_energy = min_elem->second.first;
371  cand_idx = min_elem->first;
372  }
373  // no reco associated to sim
374  if (cand_idx == -1)
375  continue;
376 
377  auto& recoCand = TICLCandidates[cand_idx];
378  if (isTICLv5_) {
379  // cand_idx is the tsMerge index, find the ts in the candidates collection
380  auto const tsPtr = edm::Ptr<ticl::Trackster>(Tracksters_h, cand_idx);
381  auto cand_it = std::find_if(TICLCandidates.begin(), TICLCandidates.end(), [tsPtr](TICLCandidate const& cand) {
382  if (!cand.tracksters().empty())
383  return cand.tracksters()[0] == tsPtr;
384  else
385  return false;
386  });
387  if (cand_it != TICLCandidates.end())
388  recoCand = *cand_it;
389  else
390  continue;
391  }
392 
393  if (recoCand.trackPtr().get() != nullptr) {
394  const auto candTrackIdx = recoCand.trackPtr().get() - edm::Ptr<reco::Track>(recoTracks_h, 0).get();
395  if (simCandTrackIdx == candTrackIdx) {
396  // +1 to track num
397  histograms.h_num_chg_energy_candidate_track[index]->Fill(simCand.rawEnergy());
398  histograms.h_num_chg_pt_candidate_track[index]->Fill(simCand.pt());
399  histograms.h_num_chg_eta_candidate_track[index]->Fill(simCand.eta());
400  histograms.h_num_chg_phi_candidate_track[index]->Fill(simCand.phi());
401  } else {
402  continue;
403  }
404  } else {
405  continue;
406  }
407 
408  //step 2: PID
409  if (simCand.pdgId() == recoCand.pdgId()) {
410  // +1 to num pdg id
411  histograms.h_num_chg_energy_candidate_pdgId[index]->Fill(simCand.rawEnergy());
412  histograms.h_num_chg_pt_candidate_pdgId[index]->Fill(simCand.pt());
413  histograms.h_num_chg_eta_candidate_pdgId[index]->Fill(simCand.eta());
414  histograms.h_num_chg_phi_candidate_pdgId[index]->Fill(simCand.phi());
415 
416  //step 3: energy
417  if (shared_energy / simCand.rawEnergy() > 0.5) {
418  // +1 to ene num
419  histograms.h_num_chg_energy_candidate_energy[index]->Fill(simCand.rawEnergy());
420  histograms.h_num_chg_pt_candidate_energy[index]->Fill(simCand.pt());
421  histograms.h_num_chg_eta_candidate_energy[index]->Fill(simCand.eta());
422  histograms.h_num_chg_phi_candidate_energy[index]->Fill(simCand.phi());
423  }
424  }
425  }
426 
427  for (const auto i : neutralCandidates) {
428  const auto& simCand = simTICLCandidates[i];
429  auto index = int(ticl::tracksterParticleTypeFromPdgId(simCand.pdgId(), 0)) / 2;
430  /* 22 (type 0) becomes 0
431  * 111 (type 3) becomes 1
432  * 130 (type 5) becomes 2
433  */
434  histograms.h_den_neut_energy_candidate[index]->Fill(simCand.rawEnergy());
435  histograms.h_den_neut_pt_candidate[index]->Fill(simCand.pt());
436  histograms.h_den_neut_eta_candidate[index]->Fill(simCand.eta());
437  histograms.h_den_neut_phi_candidate[index]->Fill(simCand.phi());
438 
439  int32_t cand_idx = -1;
440  float shared_energy = 0.;
441  const auto ts_vec = mergeTsSimToRecoMap[i];
442  if (!ts_vec.empty()) {
443  auto min_elem =
444  std::min_element(ts_vec.begin(), ts_vec.end(), [](auto const& ts1_id_pair, auto const& ts2_id_pair) {
445  return ts1_id_pair.second.second < ts2_id_pair.second.second;
446  });
447  shared_energy = min_elem->second.first;
448  cand_idx = min_elem->first;
449  }
450 
451  // no reco associated to sim
452  if (cand_idx == -1)
453  continue;
454 
455  auto& recoCand = TICLCandidates[cand_idx];
456  if (isTICLv5_) {
457  // cand_idx is the tsMerge index, find the ts in the candidates collection
458  auto const tsPtr = edm::Ptr<ticl::Trackster>(Tracksters_h, cand_idx);
459  auto cand_it = std::find_if(TICLCandidates.begin(), TICLCandidates.end(), [tsPtr](TICLCandidate const& cand) {
460  if (!cand.tracksters().empty())
461  return cand.tracksters()[0] == tsPtr;
462  else
463  return false;
464  });
465  if (cand_it != TICLCandidates.end())
466  recoCand = *cand_it;
467  else
468  continue;
469  }
470 
471  if (recoCand.trackPtr().get() != nullptr)
472  continue;
473 
474  //step 2: PID
475  if (simCand.pdgId() == recoCand.pdgId()) {
476  // +1 to num pdg id
477  histograms.h_num_neut_energy_candidate_pdgId[index]->Fill(simCand.rawEnergy());
478  histograms.h_num_neut_pt_candidate_pdgId[index]->Fill(simCand.pt());
479  histograms.h_num_neut_eta_candidate_pdgId[index]->Fill(simCand.eta());
480  histograms.h_num_neut_phi_candidate_pdgId[index]->Fill(simCand.phi());
481 
482  //step 3: energy
483  if (shared_energy / simCand.rawEnergy() > 0.5) {
484  // +1 to ene num
485  histograms.h_num_neut_energy_candidate_energy[index]->Fill(simCand.rawEnergy());
486  histograms.h_num_neut_pt_candidate_energy[index]->Fill(simCand.pt());
487  histograms.h_num_neut_eta_candidate_energy[index]->Fill(simCand.eta());
488  histograms.h_num_neut_phi_candidate_energy[index]->Fill(simCand.phi());
489  }
490  }
491  }
492 
493  // FAKE rate
494  chargedCandidates.clear();
495  neutralCandidates.clear();
496  chargedCandidates.reserve(TICLCandidates.size());
497  neutralCandidates.reserve(TICLCandidates.size());
498 
499  auto isCharged = [](int pdgId) {
500  pdgId = std::abs(pdgId);
501  return (pdgId == 11 or pdgId == 211 or pdgId == 13);
502  };
503 
504  for (size_t i = 0; i < TICLCandidates.size(); ++i) {
505  const auto& cand = TICLCandidates[i];
506  const auto& charged = isCharged(cand.pdgId());
507  if (charged)
508  chargedCandidates.emplace_back(i);
509  else
510  neutralCandidates.emplace_back(i);
511 
512  // should consider also unknown ?
513  }
514 
515  chargedCandidates.shrink_to_fit();
516  neutralCandidates.shrink_to_fit();
517 
518  // loop on charged
519  for (const auto i : chargedCandidates) {
520  const auto& cand = TICLCandidates[i];
521  auto index = std::log2(int(ticl::tracksterParticleTypeFromPdgId(cand.pdgId(), 1)));
522  /* 11 (type 1) becomes 0
523  * 13 (type 2) becomes 1
524  * 211 (type 4) becomes 2
525  */
526  int32_t candTrackIdx = -1;
527  candTrackIdx = cand.trackPtr().get() - edm::Ptr<reco::Track>(recoTracks_h, 0).get();
528 
529  if (cand.tracksters().empty())
530  continue;
531 
532  // i is the candidate idx == ts idx only in v4, find ts_idx in v5
533  auto mergeTs_id = i;
534  if (isTICLv5_) {
535  mergeTs_id = cand.tracksters()[0].get() - edm::Ptr<ticl::Trackster>(Tracksters_h, 0).get();
536  }
537 
538  // +1 to all denominators
539  histograms.h_den_fake_chg_energy_candidate[index]->Fill(cand.rawEnergy());
540  histograms.h_den_fake_chg_pt_candidate[index]->Fill(cand.pt());
541  histograms.h_den_fake_chg_eta_candidate[index]->Fill(cand.eta());
542  histograms.h_den_fake_chg_phi_candidate[index]->Fill(cand.phi());
543 
544  histograms.h_chg_tracksters_in_candidate[index]->Fill(cand.tracksters().size());
545  histograms.h_chg_candidate_regressed_energy[index]->Fill(cand.energy());
546  histograms.h_chg_candidate_charge[index]->Fill(cand.charge());
547  histograms.h_chg_candidate_pdgId[index]->Fill(cand.pdgId());
548  const auto& arr = cand.idProbabilities();
549  histograms.h_chg_candidate_partType[index]->Fill(std::max_element(arr.begin(), arr.end()) - arr.begin());
550 
551  int32_t simCand_idx = -1;
552  const auto sts_vec = mergeTsRecoToSimMap[mergeTs_id];
553  float shared_energy = 0.;
554  // search for reco cand associated
555  if (!sts_vec.empty()) {
556  auto min_elem =
557  std::min_element(sts_vec.begin(), sts_vec.end(), [](auto const& sts1_id_pair, auto const& sts2_id_pair) {
558  return sts1_id_pair.second.second < sts2_id_pair.second.second;
559  });
560  shared_energy = min_elem->second.first;
561  simCand_idx = min_elem->first;
562  }
563 
564  if (simCand_idx == -1)
565  continue;
566 
567  const auto& simCand = simTICLCandidates[simCand_idx];
568  if (simCand.trackPtr().get() != nullptr) {
569  const auto simCandTrackIdx = simCand.trackPtr().get() - edm::Ptr<reco::Track>(recoTracks_h, 0).get();
570  if (simCandTrackIdx != candTrackIdx) {
571  // fake += 1
572  histograms.h_num_fake_chg_energy_candidate_track[index]->Fill(cand.rawEnergy());
573  histograms.h_num_fake_chg_pt_candidate_track[index]->Fill(cand.pt());
574  histograms.h_num_fake_chg_eta_candidate_track[index]->Fill(cand.eta());
575  histograms.h_num_fake_chg_phi_candidate_track[index]->Fill(cand.phi());
576  continue;
577  }
578  } else {
579  // fake += 1
580  histograms.h_num_fake_chg_energy_candidate_track[index]->Fill(cand.rawEnergy());
581  histograms.h_num_fake_chg_pt_candidate_track[index]->Fill(cand.pt());
582  histograms.h_num_fake_chg_eta_candidate_track[index]->Fill(cand.eta());
583  histograms.h_num_fake_chg_phi_candidate_track[index]->Fill(cand.phi());
584  continue;
585  }
586 
587  //step 2: PID
588  if (simCand.pdgId() != cand.pdgId()) {
589  // +1 to num fake pdg id
590  histograms.h_num_fake_chg_energy_candidate_pdgId[index]->Fill(cand.rawEnergy());
591  histograms.h_num_fake_chg_pt_candidate_pdgId[index]->Fill(cand.pt());
592  histograms.h_num_fake_chg_eta_candidate_pdgId[index]->Fill(cand.eta());
593  histograms.h_num_fake_chg_phi_candidate_pdgId[index]->Fill(cand.phi());
594  continue;
595  }
596 
597  //step 3: energy
598  if (shared_energy / simCand.rawEnergy() < 0.5) {
599  // +1 to ene num
600  histograms.h_num_fake_chg_energy_candidate_energy[index]->Fill(cand.rawEnergy());
601  histograms.h_num_fake_chg_pt_candidate_energy[index]->Fill(cand.pt());
602  histograms.h_num_fake_chg_eta_candidate_energy[index]->Fill(cand.eta());
603  histograms.h_num_fake_chg_phi_candidate_energy[index]->Fill(cand.phi());
604  }
605  }
606  // loop on neutrals
607  for (const auto i : neutralCandidates) {
608  const auto& cand = TICLCandidates[i];
609  auto index = int(ticl::tracksterParticleTypeFromPdgId(cand.pdgId(), 0)) / 2;
610  /* 22 (type 0) becomes 0
611  * 111 (type 3) becomes 1
612  * 130 (type 5) becomes 2
613  */
614 
615  if (cand.tracksters().empty())
616  continue;
617 
618  // i is the candidate idx == ts idx only in v4, find ts_idx in v5
619  auto mergeTs_id = i;
620  if (isTICLv5_) {
621  mergeTs_id = cand.tracksters()[0].get() - edm::Ptr<ticl::Trackster>(Tracksters_h, 0).get();
622  }
623 
624  // +1 to all denominators
625  histograms.h_den_fake_neut_energy_candidate[index]->Fill(cand.rawEnergy());
626  histograms.h_den_fake_neut_pt_candidate[index]->Fill(cand.pt());
627  histograms.h_den_fake_neut_eta_candidate[index]->Fill(cand.eta());
628  histograms.h_den_fake_neut_phi_candidate[index]->Fill(cand.phi());
629 
630  histograms.h_neut_tracksters_in_candidate[index]->Fill(cand.tracksters().size());
631  histograms.h_neut_candidate_regressed_energy[index]->Fill(cand.energy());
632  histograms.h_neut_candidate_charge[index]->Fill(cand.charge());
633  histograms.h_neut_candidate_pdgId[index]->Fill(cand.pdgId());
634  const auto& arr = cand.idProbabilities();
635  histograms.h_neut_candidate_partType[index]->Fill(std::max_element(arr.begin(), arr.end()) - arr.begin());
636 
637  int32_t simCand_idx = -1;
638  const auto sts_vec = mergeTsRecoToSimMap[mergeTs_id];
639  float shared_energy = 0.;
640  // search for reco cand associated
641  if (!sts_vec.empty()) {
642  auto min_elem =
643  std::min_element(sts_vec.begin(), sts_vec.end(), [](auto const& sts1_id_pair, auto const& sts2_id_pair) {
644  return sts1_id_pair.second.second < sts2_id_pair.second.second;
645  });
646  shared_energy = min_elem->second.first;
647  simCand_idx = min_elem->first;
648  }
649 
650  if (simCand_idx == -1)
651  continue;
652 
653  const auto& simCand = simTICLCandidates[simCand_idx];
654 
655  //step 2: PID
656  if (simCand.pdgId() != cand.pdgId()) {
657  // +1 to num fake pdg id
658  histograms.h_num_fake_neut_energy_candidate_pdgId[index]->Fill(cand.rawEnergy());
659  histograms.h_num_fake_neut_pt_candidate_pdgId[index]->Fill(cand.pt());
660  histograms.h_num_fake_neut_eta_candidate_pdgId[index]->Fill(cand.eta());
661  histograms.h_num_fake_neut_phi_candidate_pdgId[index]->Fill(cand.phi());
662  continue;
663  }
664 
665  //step 3: energy
666  if (shared_energy / simCand.rawEnergy() < 0.5) {
667  // +1 to ene num
668  histograms.h_num_fake_neut_energy_candidate_energy[index]->Fill(cand.rawEnergy());
669  histograms.h_num_fake_neut_pt_candidate_energy[index]->Fill(cand.pt());
670  histograms.h_num_fake_neut_eta_candidate_energy[index]->Fill(cand.eta());
671  histograms.h_num_fake_neut_phi_candidate_energy[index]->Fill(cand.phi());
672  }
673  }
674 }
edm::EDGetTokenT< std::vector< TICLCandidate > > simTICLCandidatesToken_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
edm::EDGetTokenT< std::vector< reco::Track > > recoTracksToken_
edm::EDGetTokenT< std::vector< TICLCandidate > > TICLCandidatesToken_
Trackster::ParticleType tracksterParticleTypeFromPdgId(int pdgId, int charge)
Definition: Common.h:44
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:141
edm::EDGetTokenT< ticl::TracksterToTracksterMap > associatorMapRtSToken_
edm::EDGetTokenT< std::vector< ticl::Trackster > > trackstersToken_
void bookCandidatesHistos(DQMStore::IBooker &ibook, Histograms &histograms, std::string baseDir) const
edm::EDGetTokenT< ticl::TracksterToTracksterMap > associatorMapStRToken_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void fillCandidateHistos(const edm::Event &event, const Histograms &histograms, edm::Handle< ticl::TracksterCollection > simTrackstersCP_h) const
Definition: event.py:1