hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
Loading...
Searching...
No Matches
ClusterEfficiency2021.cxx
Go to the documentation of this file.
1/*
2 * @file ClusterEfficiency2021.cxx
3 * @brief Standalone study of positron-cluster (and v0) reconstruction efficiency
4 * for 2021 displaced A'/SIMP signal MC.
5 * @author Matthew Gignac
6 * @date May 2026
7 */
8
10
11#include <cmath>
12#include <cstdio>
13
15 isData_ = parameters.getInteger("isData", 0) != 0;
16 isApSignal_ = parameters.getInteger("isApSignal", 0) != 0;
17 isSimpSignal_ = parameters.getInteger("isSimpSignal", 0) != 0;
18 apPDG_ = parameters.getInteger("apPDG", apPDG_);
19 calTimeOffset_ = parameters.getDouble("calTimeOffset", 0.0);
20 clusterEnergyThresh_ = parameters.getDouble("clusterEnergyThresh", 0.0);
21 eventClusterThresh_ = parameters.getDouble("eventClusterThresh", 0.2);
22 drMatch_ = parameters.getDouble("drMatch", 30.0);
23 debug_ = parameters.getInteger("debug", 0) != 0;
24
25 auto vtxColl = parameters.getString("vtxCollection", "");
26 if (not vtxColl.empty()) vtxColl_ = vtxColl;
27
28 // mother PDG of the signal e+/e-: 625 for SIMP vector decay, apPDG_ for A'
30
31 std::cout << "[ClusterEfficiency2021] isData=" << isData_ << " isApSignal=" << isApSignal_
32 << " isSimpSignal=" << isSimpSignal_ << " signalMomPDG=" << signalMomPDG_
33 << " vtxColl=" << vtxColl_ << " eventClusterThresh=" << eventClusterThresh_ << std::endl;
34}
35
37 _ah = std::make_shared<AnaHelpers>();
38
39 bus_.board_input<EventHeader>(tree, "EventHeader");
40 bus_.board_input<TSData>(tree, "TSBank");
41 if (not trkColl_.empty()) bus_.board_input<std::vector<Track*>>(tree, trkColl_);
42 bus_.board_input<std::vector<Vertex*>>(tree, vtxColl_);
43 bus_.board_input<std::vector<CalCluster*>>(tree, "RecoEcalClusters");
44 if (not isData_ and not mcColl_.empty()) bus_.board_input<std::vector<MCParticle*>>(tree, mcColl_);
45
46 // efficiency chain (quick at-a-glance, in addition to the tree)
47 event_cf_.add("single_trigger", 2, -0.5, 1.5);
48 event_cf_.add("truth_epem_found", 2, -0.5, 1.5);
49 event_cf_.add("has_v0", 2, -0.5, 1.5);
50 event_cf_.add("both_tracks_fiducial", 2, -0.5, 1.5);
51 event_cf_.add("pos_has_cluster", 2, -0.5, 1.5);
52 event_cf_.init();
53 event_cf_.set_label_names({"readout", "single2 or 3 trigger", "truth e^{+}e^{-} found",
54 "N_{vtx} #geq 1", "both tracks fiducial", "e^{+} has cluster"});
55}
56
57void ClusterEfficiency2021::setFile(TFile* out_file) {
58 Processor::setFile(out_file);
59
60 output_tree_ = std::make_unique<TTree>("cluster_eff", "Positron-cluster efficiency study", 99, out_file);
61
62 bus_.board_output<double>(output_tree_.get(), "weight");
63 bus_.board_output<int>(output_tree_.get(), "run");
64 bus_.board_output<int>(output_tree_.get(), "event");
65
66 // trigger
67 bus_.board_output<bool>(output_tree_.get(), "single2");
68 bus_.board_output<bool>(output_tree_.get(), "single3");
69
70 // flags
71 for (const auto& name : {"truth_epem_found", "has_v0", "ele_fiducial", "pos_fiducial",
72 "both_tracks_fiducial", "ele_has_cluster", "pos_has_cluster"}) {
73 bus_.board_output<bool>(output_tree_.get(), name);
74 }
75
76 // truth quantities
77 bus_.board_output<TVector3>(output_tree_.get(), "ele_truth_p");
78 bus_.board_output<TVector3>(output_tree_.get(), "pos_truth_p");
79 for (const auto& name : {"ele_truth_E", "pos_truth_E", "true_vertex_invM", "true_vertex_psum",
80 "true_decay_len", "true_betagamma"}) {
81 bus_.board_output<double>(output_tree_.get(), name);
82 }
83 // reco track quantities
84 bus_.board_output<TVector3>(output_tree_.get(), "ele_track_p");
85 bus_.board_output<TVector3>(output_tree_.get(), "pos_track_p");
86 for (const auto& name : {"ele_ecal_x", "ele_ecal_y", "ele_ecal_z",
87 "pos_ecal_x", "pos_ecal_y", "pos_ecal_z"}) {
88 bus_.board_output<double>(output_tree_.get(), name);
89 }
90
91 // reco cluster quantities (associated to the v0 particles)
92 for (const auto& name : {"ele_clu_E", "ele_clu_x", "ele_clu_y", "ele_clu_time",
93 "pos_clu_E", "pos_clu_x", "pos_clu_y", "pos_clu_time"}) {
94 bus_.board_output<double>(output_tree_.get(), name);
95 }
96 bus_.board_output<int>(output_tree_.get(), "ele_clu_nhits");
97 bus_.board_output<int>(output_tree_.get(), "pos_clu_nhits");
98
99 // standalone-cluster cross-check near the positron track projection
100 for (const auto& name : {"pos_nearest_clu_dr", "pos_nearest_clu_E", "pos_nearest_clu_time"}) {
101 bus_.board_output<double>(output_tree_.get(), name);
102 }
103
104 // track-level match flags (KalmanFullTracks, no v0 required) + n_v0 multiplicity
105 bus_.board_output<bool>(output_tree_.get(), "trk_pos_matched");
106 bus_.board_output<bool>(output_tree_.get(), "trk_ele_matched");
107 bus_.board_output<int>(output_tree_.get(), "n_v0");
108
109 // tracking/acceptance-loss scenario: energetic cluster(s) present but no positron track on
110 // one of them. "orphan" = energetic cluster with NO reconstructed track (any charge) within
111 // drMatch_ -> the positron's lost cluster; map its x,y to see WHERE acceptance/tracking fails.
112 bus_.board_output<bool>(output_tree_.get(), "pos_acceptance_loss");
113 bus_.board_output<bool>(output_tree_.get(), "has_orphan_cluster");
114 for (const auto& name : {"orphan_clu_x", "orphan_clu_y", "orphan_clu_E"}) {
115 bus_.board_output<double>(output_tree_.get(), name);
116 }
117}
118
120 // Reset output branches so conditionally-filled ones do not carry over the
121 // previous event's value into this event's entry.
122 bus_.clear_outputs();
123
124 const auto& tsbank{bus_.get<TSData>("TSBank")};
125 const auto& eh{bus_.get<EventHeader>("EventHeader")};
126
127 event_cf_.begin_event();
128
129 // Re-apply trigger decision: data contains other triggers; MC is produced with only
130 // this trigger but the event header is not updated, so the bits are still meaningful.
131 bool single2 = tsbank.isSingle2Trigger() == 1;
132 bool single3 = tsbank.isSingle3Trigger() == 1;
133 bool single_trigger = single2 || single3;
134 event_cf_.apply("single_trigger", single_trigger);
135 event_cf_.fill_nm1("single_trigger", single_trigger ? 1 : 0);
136 if (not event_cf_.keep()) return true;
137
138 // ===== Q1: after the singles2/3 trigger, is there an energetic cluster ANYWHERE? =====
139 // Loop over ALL RecoEcalClusters, independent of any v0. By definition a singles
140 // trigger requires an energetic cluster, so this should be ~100%.
141 const auto& allClusters{bus_.get<std::vector<CalCluster*>>("RecoEcalClusters")};
142 int n_clusters = static_cast<int>(allClusters.size());
143 double event_max_clu_E = -9999.;
144 for (const auto* cl : allClusters) {
145 if (cl->getEnergy() > event_max_clu_E) event_max_clu_E = cl->getEnergy();
146 }
147 bool event_has_cluster = event_max_clu_E > eventClusterThresh_;
148 n_triggered_++;
149 if (event_has_cluster) n_event_has_cluster_++;
150
151 // nearest ENERGETIC cluster (E > eventClusterThresh_) to a track's ECal projection.
152 // A track is "dr-matched" to a trigger-quality cluster if the nearest such cluster is
153 // within drMatch_. Used to score/pick the best v0 and to fill the per-track dbg below.
154 auto nearest_energetic = [&](const std::vector<double>& ecal,
155 double& out_dr, double& out_E, double& out_t) {
156 out_dr = 9999.0; out_E = -9999.0; out_t = -9999.0;
157 for (const auto* cl : allClusters) {
158 if (cl->getEnergy() <= eventClusterThresh_) continue;
159 auto cp = cl->getPosition();
160 double dr = std::sqrt((cp[0] - ecal[0]) * (cp[0] - ecal[0]) +
161 (cp[1] - ecal[1]) * (cp[1] - ecal[1]));
162 if (dr < out_dr) { out_dr = dr; out_E = cl->getEnergy(); out_t = cl->getTime() - calTimeOffset_; }
163 }
164 };
165
166 // ----- defaults (sentinels) -----
167 bus_.set("weight", 1.);
168 bus_.set("run", eh.getRunNumber());
169 bus_.set("event", eh.getEventNumber());
170 bus_.set("single2", single2);
171 bus_.set("single3", single3);
172
173 bus_.set("ele_truth_p", TVector3(0., 0., 0.));
174 bus_.set("pos_truth_p", TVector3(0., 0., 0.));
175 bus_.set("ele_truth_E", -9999.);
176 bus_.set("pos_truth_E", -9999.);
177 bus_.set("true_vertex_invM", -9999.);
178 bus_.set("true_vertex_psum", -9999.);
179 bus_.set("true_decay_len", -9999.);
180 bus_.set("true_betagamma", -9999.);
181
182 bus_.set("ele_track_p", TVector3(0., 0., 0.));
183 bus_.set("pos_track_p", TVector3(0., 0., 0.));
184 for (const auto& name : {"ele_ecal_x", "ele_ecal_y", "ele_ecal_z",
185 "pos_ecal_x", "pos_ecal_y", "pos_ecal_z",
186 "ele_clu_E", "ele_clu_x", "ele_clu_y", "ele_clu_time",
187 "pos_clu_E", "pos_clu_x", "pos_clu_y", "pos_clu_time",
188 "pos_nearest_clu_dr", "pos_nearest_clu_E", "pos_nearest_clu_time"}) {
189 bus_.set<double>(name, -9999.);
190 }
191 bus_.set("ele_clu_nhits", -1);
192 bus_.set("pos_clu_nhits", -1);
193
194 bool truth_epem_found = false, has_v0 = false;
195 bool ele_fiducial = false, pos_fiducial = false, both_tracks_fiducial = false;
196 bool ele_has_cluster = false, pos_has_cluster = false;
197 // Q2: is an energetic cluster matched to the v0 positron track?
198 bool pos_matched_cluster = false; // associated cluster with E > eventClusterThresh_
199 double pos_clu_E_dbg = -9999.; // associated-cluster energy (sentinel if none)
200 double pos_nearest_dr_dbg = -9999.; // dr to nearest standalone cluster at ECal
201 // Q3: dr-based track->cluster match (did the e-/e+ make an energetic trigger cluster?)
202 bool ele_dr_matched = false, pos_dr_matched = false;
203 double ele_nearest_dr_dbg = -9999., ele_dr_E_dbg = -9999.;
204 double pos_dr_E_dbg = -9999.;
205
206 // ===================== truth block =====================
207 const std::vector<MCParticle*>* mcParticles = nullptr;
208 if (bus_.has(mcColl_)) {
209 mcParticles = &bus_.get<std::vector<MCParticle*>>(mcColl_);
210 MCParticle* mother{nullptr};
211 ROOT::Math::PxPyPzEVector trueEleP, truePosP;
212 bool foundEle = false, foundPos = false;
213 for (MCParticle* ptr : *mcParticles) {
214 std::vector<double> lP = ptr->getMomentum();
215 if (ptr->getPDG() == apPDG_ || (isSimpSignal_ && ptr->getPDG() == 625)) {
216 mother = ptr;
217 } else if (ptr->getPDG() == 11 && ptr->getMomPDG() == signalMomPDG_) {
218 trueEleP = ROOT::Math::PxPyPzEVector(lP.at(0), lP.at(1), lP.at(2), ptr->getEnergy());
219 foundEle = true;
220 } else if (ptr->getPDG() == -11 && ptr->getMomPDG() == signalMomPDG_) {
221 truePosP = ROOT::Math::PxPyPzEVector(lP.at(0), lP.at(1), lP.at(2), ptr->getEnergy());
222 foundPos = true;
223 }
224 }
225 truth_epem_found = foundEle && foundPos;
226
227 if (foundEle) {
228 bus_.set("ele_truth_p", TVector3(trueEleP.Px(), trueEleP.Py(), trueEleP.Pz()));
229 bus_.set("ele_truth_E", trueEleP.E());
230 }
231 if (foundPos) {
232 bus_.set("pos_truth_p", TVector3(truePosP.Px(), truePosP.Py(), truePosP.Pz()));
233 bus_.set("pos_truth_E", truePosP.E());
234 }
235 if (foundEle && foundPos) {
236 bus_.set("true_vertex_invM", (trueEleP + truePosP).M());
237 bus_.set("true_vertex_psum", trueEleP.P() + truePosP.P());
238 }
239
240 if (mother) {
241 std::vector<double> vtxPos = mother->getVertexPosition();
242 std::vector<double> endPos = mother->getEndPoint();
243 double dx = endPos[0] - vtxPos[0];
244 double dy = endPos[1] - vtxPos[1];
245 double dz = endPos[2] - vtxPos[2];
246 bus_.set("true_decay_len", std::sqrt(dx * dx + dy * dy + dz * dz));
247
248 std::vector<double> mMom = mother->getMomentum();
249 double mp = std::sqrt(mMom[0] * mMom[0] + mMom[1] * mMom[1] + mMom[2] * mMom[2]);
250 if (mother->getMass() > 0) bus_.set("true_betagamma", mp / mother->getMass());
251 }
252 }
253 event_cf_.apply("truth_epem_found", isData_ ? true : truth_epem_found);
254 event_cf_.fill_nm1("truth_epem_found", truth_epem_found ? 1 : 0);
255
256 // ===================== reco block =====================
257 const auto& vtxs{bus_.get<std::vector<Vertex*>>(vtxColl_)};
258
259 // Evaluate EVERY e-/e+ v0 and choose the BEST one = the v0 whose positron points closest
260 // to an energetic cluster (smallest e+ dr). Also record whether ANY v0 has a matched
261 // e+/e- (best-case efficiency) and what the FIRST v0 alone would have given.
262 Vertex* chosen{nullptr};
263 int chosen_i_ele{-1}, chosen_i_pos{-1};
264 int n_v0 = 0;
265 double best_pos_dr = 1e9;
266 bool any_pos_matched = false, any_ele_matched = false;
267 bool first_pos_matched = false, first_ele_matched = false, first_v0_seen = false;
268 for (Vertex* vtx : vtxs) {
269 int i_ele{-1}, i_pos{-1};
270 for (int ipart = 0; ipart < vtx->getParticles().GetEntries(); ++ipart) {
271 int pdg_id = ((Particle*)vtx->getParticles().At(ipart))->getPDG();
272 if (pdg_id == 11)
273 i_ele = ipart;
274 else if (pdg_id == -11)
275 i_pos = ipart;
276 }
277 if (i_ele < 0 || i_pos < 0) continue;
278 n_v0++;
279
280 Particle* e = dynamic_cast<Particle*>(vtx->getParticles().At(i_ele));
281 Particle* p = dynamic_cast<Particle*>(vtx->getParticles().At(i_pos));
282 auto eEcal = e->getTrack().getPositionAtEcal();
283 auto pEcal = p->getTrack().getPositionAtEcal();
284 double pdr, pE, pt, edr, eE, et;
285 nearest_energetic(pEcal, pdr, pE, pt);
286 nearest_energetic(eEcal, edr, eE, et);
287 bool pmatch = (pdr < drMatch_);
288 bool ematch = (edr < drMatch_);
289 any_pos_matched = any_pos_matched || pmatch;
290 any_ele_matched = any_ele_matched || ematch;
291 if (not first_v0_seen) {
292 first_v0_seen = true;
293 first_pos_matched = pmatch;
294 first_ele_matched = ematch;
295 }
296 if (pdr < best_pos_dr) { // best v0 = positron closest to an energetic cluster
297 best_pos_dr = pdr;
298 chosen = vtx;
299 chosen_i_ele = i_ele;
300 chosen_i_pos = i_pos;
301 }
302 }
303 has_v0 = (chosen != nullptr);
304
305 // ---- track-level cluster match (decouple tracking vs vertexing) ----
306 // Independent of any v0: does a standalone track (KalmanFullTracks) point at an energetic
307 // cluster? If a positron TRACK matches but no v0 positron does, the loss is VERTEXING; if
308 // no track matches either, the loss is TRACKING/acceptance.
309 bool trk_pos_matched = false, trk_ele_matched = false;
310 bool has_orphan_cluster = false;
311 double orphan_clu_x = -9999., orphan_clu_y = -9999., orphan_clu_E = -9999.;
312 if (bus_.has(trkColl_)) {
313 const auto& tracks{bus_.get<std::vector<Track*>>(trkColl_)};
314 for (Track* trk : tracks) {
315 auto tEcal = trk->getPositionAtEcal();
316 if (tEcal.size() < 2) continue;
317 double dr, E, t;
318 nearest_energetic(tEcal, dr, E, t);
319 if (dr < drMatch_) {
320 if (trk->getCharge() > 0) trk_pos_matched = true;
321 else if (trk->getCharge() < 0) trk_ele_matched = true;
322 }
323 }
324
325 // orphan energetic clusters: energetic cluster with NO track (any charge) within
326 // drMatch_. Keep the highest-E orphan -> the lost (positron) cluster for the x,y map.
327 for (const auto* cl : allClusters) {
328 if (cl->getEnergy() <= eventClusterThresh_) continue;
329 auto cp = cl->getPosition();
330 double min_trk_dr = 9999.;
331 for (Track* trk : tracks) {
332 auto tE = trk->getPositionAtEcal();
333 if (tE.size() < 2) continue;
334 double dr = std::sqrt((tE[0] - cp[0]) * (tE[0] - cp[0]) +
335 (tE[1] - cp[1]) * (tE[1] - cp[1]));
336 if (dr < min_trk_dr) min_trk_dr = dr;
337 }
338 if (min_trk_dr > drMatch_) { // no track points at this energetic cluster
339 has_orphan_cluster = true;
340 if (cl->getEnergy() > orphan_clu_E) {
341 orphan_clu_E = cl->getEnergy();
342 orphan_clu_x = cp[0];
343 orphan_clu_y = cp[1];
344 }
345 }
346 }
347 }
348 // "tracking/acceptance" scenario for the positron: an energetic cluster exists but no
349 // positron track points at any energetic cluster.
350 bool pos_acceptance_loss = event_has_cluster && not trk_pos_matched;
351
352 bus_.set("trk_pos_matched", trk_pos_matched);
353 bus_.set("trk_ele_matched", trk_ele_matched);
354 bus_.set("n_v0", n_v0);
355 bus_.set("pos_acceptance_loss", pos_acceptance_loss);
356 bus_.set("has_orphan_cluster", has_orphan_cluster);
357 bus_.set<double>("orphan_clu_x", orphan_clu_x);
358 bus_.set<double>("orphan_clu_y", orphan_clu_y);
359 bus_.set<double>("orphan_clu_E", orphan_clu_E);
360
361 if (has_v0) {
362 Particle ele = *dynamic_cast<Particle*>(chosen->getParticles().At(chosen_i_ele));
363 Particle pos = *dynamic_cast<Particle*>(chosen->getParticles().At(chosen_i_pos));
364 Track ele_trk = ele.getTrack();
365 Track pos_trk = pos.getTrack();
366
367 TVector3 ele_p(ele_trk.getMomentum()[0], ele_trk.getMomentum()[1], ele_trk.getMomentum()[2]);
368 TVector3 pos_p(pos_trk.getMomentum()[0], pos_trk.getMomentum()[1], pos_trk.getMomentum()[2]);
369 bus_.set("ele_track_p", ele_p);
370 bus_.set("pos_track_p", pos_p);
371
372 auto eleEcal = ele_trk.getPositionAtEcal();
373 auto posEcal = pos_trk.getPositionAtEcal();
374 bus_.set<double>("ele_ecal_x", eleEcal[0]);
375 bus_.set<double>("ele_ecal_y", eleEcal[1]);
376 bus_.set<double>("ele_ecal_z", eleEcal[2]);
377 bus_.set<double>("pos_ecal_x", posEcal[0]);
378 bus_.set<double>("pos_ecal_y", posEcal[1]);
379 bus_.set<double>("pos_ecal_z", posEcal[2]);
380
381 // fiducial: use AnaHelpers::IsECalFiducial on the track projection at ECal
382 auto fiducial_at = [&](const std::vector<double>& xyz) -> bool {
383 float p[3] = {(float)xyz[0], (float)xyz[1], (float)xyz[2]};
384 CalCluster c;
385 c.setPosition(p);
386 return _ah->IsECalFiducial(&c);
387 };
388 ele_fiducial = fiducial_at(eleEcal);
389 pos_fiducial = fiducial_at(posEcal);
390 both_tracks_fiducial = ele_fiducial && pos_fiducial;
391
392 // associated clusters: a missing cluster has the sentinel energy (-9999)
393 CalCluster ele_clu = ele.getCluster();
394 CalCluster pos_clu = pos.getCluster();
395 ele_has_cluster = ele_clu.getEnergy() > clusterEnergyThresh_;
396 pos_has_cluster = pos_clu.getEnergy() > clusterEnergyThresh_;
397 pos_matched_cluster = pos_clu.getEnergy() > eventClusterThresh_;
398 pos_clu_E_dbg = pos_clu.getEnergy();
399 if (ele_has_cluster) {
400 bus_.set<double>("ele_clu_E", ele_clu.getEnergy());
401 bus_.set<double>("ele_clu_x", ele_clu.getPosition()[0]);
402 bus_.set<double>("ele_clu_y", ele_clu.getPosition()[1]);
403 bus_.set<double>("ele_clu_time", ele_clu.getTime() - calTimeOffset_);
404 bus_.set("ele_clu_nhits", ele_clu.getNHits());
405 }
406 if (pos_has_cluster) {
407 bus_.set<double>("pos_clu_E", pos_clu.getEnergy());
408 bus_.set<double>("pos_clu_x", pos_clu.getPosition()[0]);
409 bus_.set<double>("pos_clu_y", pos_clu.getPosition()[1]);
410 bus_.set<double>("pos_clu_time", pos_clu.getTime() - calTimeOffset_);
411 bus_.set("pos_clu_nhits", pos_clu.getNHits());
412 }
413
414 // dr-match of the BEST v0's tracks to the nearest energetic cluster (for dbg/printout)
415 double pos_dr, pos_dr_E, pos_dr_t;
416 double ele_dr, ele_dr_E, ele_dr_t;
417 nearest_energetic(posEcal, pos_dr, pos_dr_E, pos_dr_t);
418 nearest_energetic(eleEcal, ele_dr, ele_dr_E, ele_dr_t);
419 bus_.set<double>("pos_nearest_clu_dr", pos_dr);
420 bus_.set<double>("pos_nearest_clu_E", pos_dr_E);
421 bus_.set<double>("pos_nearest_clu_time", pos_dr_t);
422 pos_dr_matched = (pos_dr < drMatch_);
423 ele_dr_matched = (ele_dr < drMatch_);
424 pos_nearest_dr_dbg = pos_dr;
425 pos_dr_E_dbg = pos_dr_E;
426 ele_nearest_dr_dbg = ele_dr;
427 ele_dr_E_dbg = ele_dr_E;
428 }
429
430 bus_.set("truth_epem_found", truth_epem_found);
431 bus_.set("has_v0", has_v0);
432 bus_.set("ele_fiducial", ele_fiducial);
433 bus_.set("pos_fiducial", pos_fiducial);
434 bus_.set("both_tracks_fiducial", both_tracks_fiducial);
435 bus_.set("ele_has_cluster", ele_has_cluster);
436 bus_.set("pos_has_cluster", pos_has_cluster);
437
438 event_cf_.apply("has_v0", has_v0);
439 event_cf_.fill_nm1("has_v0", has_v0 ? 1 : 0);
440 event_cf_.apply("both_tracks_fiducial", both_tracks_fiducial);
441 event_cf_.fill_nm1("both_tracks_fiducial", both_tracks_fiducial ? 1 : 0);
442 event_cf_.apply("pos_has_cluster", pos_has_cluster);
443 event_cf_.fill_nm1("pos_has_cluster", pos_has_cluster ? 1 : 0);
444
445 if (has_v0) n_has_v0_++;
446 if (n_v0 > 1) n_multi_v0_++;
447 if (first_pos_matched) n_first_pos_matched_++;
448 if (first_ele_matched) n_first_ele_matched_++;
449 if (any_pos_matched) n_any_pos_matched_++;
450 if (any_ele_matched) n_any_ele_matched_++;
451 if (trk_pos_matched) n_trk_pos_matched_++;
452 if (trk_ele_matched) n_trk_ele_matched_++;
453 if (trk_pos_matched && not any_pos_matched) n_trkpos_no_v0pos_++;
454
455 // per-event terminal dump (first 40 triggered events) so we can inspect by eye.
456 // Compares v0-level vs track-level cluster match to separate tracking from vertexing.
457 if (n_printed_ < 40) {
458 printf("[cluseff] run %d evt %d | nClu=%2d || nV0=%d hasV0=%d "
459 "|| v0: pos=%d ele=%d || trk: pos=%d ele=%d%s\n",
460 eh.getRunNumber(), eh.getEventNumber(), n_clusters,
461 n_v0, has_v0 ? 1 : 0,
462 any_pos_matched ? 1 : 0, any_ele_matched ? 1 : 0,
463 trk_pos_matched ? 1 : 0, trk_ele_matched ? 1 : 0,
464 (trk_pos_matched && not any_pos_matched) ? " <-- e+ track but no v0!" : "");
465 n_printed_++;
466 }
467
468 // one row per triggered signal event (sentinels where reco objects are absent)
469 output_tree_->Fill();
470 return true;
471}
472
474 auto pct = [](long num, long den) { return den > 0 ? 100.0 * num / den : 0.0; };
475 std::cout << "\n================ ClusterEfficiency2021 summary ================\n"
476 << " energetic-cluster threshold : " << eventClusterThresh_ << " GeV\n"
477 << " singles2/3 triggered events : " << n_triggered_ << "\n"
478 << " Q1: cluster > thr ANYWHERE : " << n_event_has_cluster_
479 << " (" << pct(n_event_has_cluster_, n_triggered_) << "% of triggered)\n"
480 << " events with >=1 e+e- v0 : " << n_has_v0_
481 << " (" << pct(n_has_v0_, n_triggered_) << "% of triggered)\n"
482 << " ... of which have >1 v0 : " << n_multi_v0_
483 << " (" << pct(n_multi_v0_, n_has_v0_) << "% of v0 events)\n"
484 << " dr match radius : " << drMatch_ << " mm\n"
485 << " --- FIRST v0 only (old behavior) ---\n"
486 << " e+ dr-matched cluster > thr : " << n_first_pos_matched_
487 << " (" << pct(n_first_pos_matched_, n_has_v0_) << "% of v0)\n"
488 << " e- dr-matched cluster > thr : " << n_first_ele_matched_
489 << " (" << pct(n_first_ele_matched_, n_has_v0_) << "% of v0)\n"
490 << " --- ANY v0 (best case), as % of TRIGGERED ---\n"
491 << " e+ dr-matched in some v0 : " << n_any_pos_matched_
492 << " (" << pct(n_any_pos_matched_, n_triggered_) << "% of triggered, "
493 << pct(n_any_pos_matched_, n_has_v0_) << "% of v0)\n"
494 << " e- dr-matched in some v0 : " << n_any_ele_matched_
495 << " (" << pct(n_any_ele_matched_, n_triggered_) << "% of triggered, "
496 << pct(n_any_ele_matched_, n_has_v0_) << "% of v0)\n"
497 << " --- TRACK level (KalmanFullTracks, NO v0 required), % of TRIGGERED ---\n"
498 << " e+ track dr-matched cluster : " << n_trk_pos_matched_
499 << " (" << pct(n_trk_pos_matched_, n_triggered_) << "% of triggered)\n"
500 << " e- track dr-matched cluster : " << n_trk_ele_matched_
501 << " (" << pct(n_trk_ele_matched_, n_triggered_) << "% of triggered)\n"
502 << " e+ track matched but NO v0 e+ : " << n_trkpos_no_v0pos_
503 << " (" << pct(n_trkpos_no_v0pos_, n_triggered_) << "% of triggered)"
504 << " <- VERTEXING loss\n"
505 << "===============================================================\n" << std::endl;
506
507 outF_->cd();
508 output_tree_->Write();
509 event_cf_.save();
510 outF_->Close();
511}
512
#define DECLARE_PROCESSOR(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Definition Processor.h:139
void setPosition(const float *position)
double getEnergy() const
Definition CalCluster.h:73
std::vector< double > getPosition() const
Definition CalCluster.h:63
int getNHits() const
Definition CalCluster.h:53
double getTime() const
Definition CalCluster.h:83
virtual void setFile(TFile *out_file) final
Set output TFile for AnaProcessors.
std::shared_ptr< AnaHelpers > _ah
virtual void initialize(TTree *tree) final
Callback for the Processor to take any necessary action when the processing of events starts,...
virtual void finalize() final
Callback for the Processor to take any necessary action when the processing of events finishes,...
virtual void configure(const ParameterSet &parameters) final
Callback for the Processor to configure itself from the given set of parameters.
std::unique_ptr< TTree > output_tree_
Definition IEvent.h:7
description
Track getTrack() const
Definition Particle.h:48
CalCluster getCluster() const
Definition Particle.h:62
TFile * outF_
Definition Processor.h:125
virtual bool process()
Process the histograms and generate analysis output.
Definition Processor.h:95
virtual void setFile(TFile *outFile)
Set output TFile for AnaProcessors.
Definition Processor.h:88
Definition Track.h:32
std::vector< double > getPositionAtEcal()
Definition Track.cxx:53
std::vector< double > getMomentum()
Definition Track.h:287
TRefArray getParticles()
Definition Vertex.h:94