194 bus_.clear_outputs();
201 bus_.set(
"weight", 1.);
202 bus_.set(
"run", eh.getRunNumber());
203 bus_.set(
"event", eh.getEventNumber());
204 bus_.set(
"n_signal", 0);
205 bus_.set(
"truth_signal_found",
false);
206 bus_.set(
"true_ap_p", TVector3(0., 0., 0.));
207 bus_.set(
"true_ele_p", TVector3(0., 0., 0.));
208 bus_.set(
"true_pos_p", TVector3(0., 0., 0.));
209 for (
const auto& name : {
"true_ap_E",
"true_ap_mass",
"true_betagamma",
"true_decay_len",
210 "true_vtx_x",
"true_vtx_y",
"true_vtx_z",
211 "true_prod_x",
"true_prod_y",
"true_prod_z",
212 "true_ele_E",
"true_pos_E",
"true_vertex_invM",
"true_vertex_psum",
213 "true_ele_pt",
"true_ele_pz",
"true_ele_theta",
"true_ele_slopeX",
"true_ele_slopeY",
214 "true_pos_pt",
"true_pos_pz",
"true_pos_theta",
"true_pos_slopeX",
"true_pos_slopeY"}) {
215 bus_.set<
double>(name, -9999.);
217 bus_.set(
"n_trk_pos", 0);
218 bus_.set(
"n_trk_ele", 0);
220 bus_.set(
"has_v0",
false);
221 bus_.set(
"matched_z",
false);
222 for (
const auto& name : {
"best_dz",
"best_vtx_x",
"best_vtx_y",
"best_vtx_z",
"best_vtx_chi2"}) {
223 bus_.set<
double>(name, -9999.);
225 bus_.set(
"n_v0_trk_matched", 0);
226 bus_.set(
"matched_trk",
false);
227 bus_.set(
"matched_z_or_trk",
false);
228 bus_.set(
"matched_z_and_trk",
false);
229 bus_.set<
double>(
"best_trk_dz", -9999.);
230 bus_.set(
"matched_trk_ele",
false);
231 bus_.set(
"matched_trk_pos",
false);
233 bus_.set<
int>(
"n_truth_hits_ele", -1);
234 bus_.set<
int>(
"n_truth_hits_pos", -1);
235 bus_.set<
int>(
"n_truth_layers_ele", -1);
236 bus_.set<
int>(
"n_truth_layers_pos", -1);
237 bus_.set(
"has_ele_clus",
false);
238 bus_.set(
"has_pos_clus",
false);
239 for (
const auto& name : {
"ele_clus_E",
"ele_clus_x",
"ele_clus_y",
"ele_clus_z",
"ele_clus_t",
240 "pos_clus_E",
"pos_clus_x",
"pos_clus_y",
"pos_clus_z",
"pos_clus_t",
241 "ele_trk_p",
"pos_trk_p"}) {
242 bus_.set<
double>(name, -9999.);
244 bus_.set<
int>(
"ele_trk_nhits", 0);
245 bus_.set<
int>(
"pos_trk_nhits", 0);
246 bus_.set(
"matched_trk_ele_clus",
false);
247 bus_.set(
"matched_trk_pos_clus",
false);
248 bus_.set(
"matched_trk_clus_both",
false);
249 bus_.set(
"matched_trk_clus_pos_only",
false);
250 bus_.set(
"matched_trk_clus_ele_only",
false);
262 const auto& mcParticles{
bus_.get<std::vector<MCParticle*>>(
mcColl_)};
265 double true_vtx_z = -9999.;
266 ROOT::Math::PxPyPzEVector trueEleP, truePosP;
267 bool foundEle{
false}, foundPos{
false};
269 int trueEleID{-1}, truePosID{-1};
271 std::vector<double> lP = ptr->getMomentum();
275 }
else if (ptr->getPDG() == 11 && ptr->getMomPDG() ==
signalMomPDG_) {
276 trueEleP = ROOT::Math::PxPyPzEVector(lP.at(0), lP.at(1), lP.at(2), ptr->getEnergy());
277 trueEleID = ptr->getID();
279 }
else if (ptr->getPDG() == -11 && ptr->getMomPDG() ==
signalMomPDG_) {
280 truePosP = ROOT::Math::PxPyPzEVector(lP.at(0), lP.at(1), lP.at(2), ptr->getEnergy());
281 truePosID = ptr->getID();
293 const auto& truthHits{
bus_.get<std::vector<TrackerHit*>>(
hitColl_)};
294 std::map<int, int> nHitsByMcpID;
295 std::map<int, std::set<int>> layersByMcpID;
297 for (
int mcpID : hit->getMCPartIDs()) {
298 nHitsByMcpID[mcpID]++;
299 layersByMcpID[mcpID].insert(hit->getLayer());
302 if (trueEleID >= 0) {
303 bus_.set<
int>(
"n_truth_hits_ele", nHitsByMcpID[trueEleID]);
304 bus_.set<
int>(
"n_truth_layers_ele",
static_cast<int>(layersByMcpID[trueEleID].size()));
306 if (truePosID >= 0) {
307 bus_.set<
int>(
"n_truth_hits_pos", nHitsByMcpID[truePosID]);
308 bus_.set<
int>(
"n_truth_layers_pos",
static_cast<int>(layersByMcpID[truePosID].size()));
316 double invM = (foundEle && foundPos) ? (trueEleP + truePosP).M() : -1.;
327 bool truth_signal_found = (n_signal > 0) && mass_ok && zfid_ok;
328 bus_.set(
"n_signal", n_signal);
329 bus_.set(
"truth_signal_found", truth_signal_found);
331 event_cf_.apply(
"truth_signal_found", truth_signal_found);
332 event_cf_.fill_nm1(
"truth_signal_found", truth_signal_found ? 1 : 0);
333 event_cf_.apply(
"single_truth_signal", n_signal == 1);
334 event_cf_.fill_nm1(
"single_truth_signal", n_signal);
337 bus_.set(
"true_ele_p", TVector3(trueEleP.Px(), trueEleP.Py(), trueEleP.Pz()));
338 bus_.set<
double>(
"true_ele_E", trueEleP.E());
339 bus_.set<
double>(
"true_ele_pt", trueEleP.Pt());
340 bus_.set<
double>(
"true_ele_pz", trueEleP.Pz());
341 bus_.set<
double>(
"true_ele_theta", trueEleP.Theta());
342 bus_.set<
double>(
"true_ele_slopeX", trueEleP.Pz() != 0 ? trueEleP.Px() / trueEleP.Pz() : -9999.);
343 bus_.set<
double>(
"true_ele_slopeY", trueEleP.Pz() != 0 ? trueEleP.Py() / trueEleP.Pz() : -9999.);
346 bus_.set(
"true_pos_p", TVector3(truePosP.Px(), truePosP.Py(), truePosP.Pz()));
347 bus_.set<
double>(
"true_pos_E", truePosP.E());
348 bus_.set<
double>(
"true_pos_pt", truePosP.Pt());
349 bus_.set<
double>(
"true_pos_pz", truePosP.Pz());
350 bus_.set<
double>(
"true_pos_theta", truePosP.Theta());
351 bus_.set<
double>(
"true_pos_slopeX", truePosP.Pz() != 0 ? truePosP.Px() / truePosP.Pz() : -9999.);
352 bus_.set<
double>(
"true_pos_slopeY", truePosP.Pz() != 0 ? truePosP.Py() / truePosP.Pz() : -9999.);
354 if (foundEle && foundPos) {
355 bus_.set<
double>(
"true_vertex_invM", (trueEleP + truePosP).M());
356 bus_.set<
double>(
"true_vertex_psum", trueEleP.P() + truePosP.P());
361 std::vector<double> endPos = mother->
getEndPoint();
362 bus_.set<
double>(
"true_prod_x", prodPos[0]);
363 bus_.set<
double>(
"true_prod_y", prodPos[1]);
364 bus_.set<
double>(
"true_prod_z", prodPos[2]);
365 bus_.set<
double>(
"true_vtx_x", endPos[0]);
366 bus_.set<
double>(
"true_vtx_y", endPos[1]);
367 bus_.set<
double>(
"true_vtx_z", endPos[2]);
368 true_vtx_z = endPos[2];
374 bus_.set<
double>(
"true_decay_len",
375 std::sqrt(endPos[0] * endPos[0] + endPos[1] * endPos[1] + endPos[2] * endPos[2]));
378 double mp = std::sqrt(mMom[0] * mMom[0] + mMom[1] * mMom[1] + mMom[2] * mMom[2]);
379 bus_.set(
"true_ap_p", TVector3(mMom[0], mMom[1], mMom[2]));
381 bus_.set<
double>(
"true_ap_mass", mother->
getMass());
382 if (mother->
getMass() > 0)
bus_.set<
double>(
"true_betagamma", mp / mother->
getMass());
387 const auto& vtxs{
bus_.get<std::vector<Vertex*>>(
vtxColl_)};
388 int n_v0 =
static_cast<int>(vtxs.size());
389 bool has_v0 = (n_v0 >= 1);
393 auto majorityMcpID = [](
Track& trk) ->
int {
394 std::map<int, int> count_per_id;
395 for (
const auto& hit : trk.getMcpHits()) count_per_id[hit.second]++;
396 int best_id{-1}, best_n{0};
397 for (
const auto& [
id, n] : count_per_id) {
406 double best_abs_dz = 1e9, best_dz = -9999.;
407 Vertex* best_vtx =
nullptr;
408 int n_v0_trk_matched = 0;
409 int n_v0_ele_trk_matched = 0, n_v0_pos_trk_matched = 0;
410 int n_v0_ele_trk_matched_clus = 0, n_v0_pos_trk_matched_clus = 0;
411 int n_v0_trk_matched_clus_both = 0, n_v0_trk_matched_clus_pos_only = 0;
412 int n_v0_trk_matched_clus_ele_only = 0;
413 double best_trk_abs_dz = 1e9, best_trk_dz = -9999.;
419 int best_clus_tier = -1;
420 double best_clus_abs_dz = 1e9;
422 double best_ele_trk_p = -9999., best_pos_trk_p = -9999.;
423 int best_ele_trk_nhits = 0, best_pos_trk_nhits = 0;
424 bool have_best_trk_clus =
false;
425 bool matched_z_and_trk =
false;
426 for (
Vertex* vtx : vtxs) {
427 double dz = vtx->getZ() - true_vtx_z;
428 if (std::fabs(dz) < best_abs_dz) {
429 best_abs_dz = std::fabs(dz);
438 bool this_ele_matched =
false, this_pos_matched =
false;
439 bool this_ele_has_clus =
false, this_pos_has_clus =
false;
440 Particle *eleP{
nullptr}, *posP{
nullptr};
441 TRefArray parts = vtx->getParticles();
442 if (parts.GetEntries() >= 2) {
448 Track *eleT{
nullptr}, *posT{
nullptr};
460 if (eleT && trueEleID >= 0) this_ele_matched = (majorityMcpID(*eleT) == trueEleID);
461 if (posT && truePosID >= 0) this_pos_matched = (majorityMcpID(*posT) == truePosID);
467 if (posP) this_pos_has_clus = (posP->getCluster().getEnergy() > -9000.);
469 if (this_ele_matched && this_ele_has_clus) n_v0_ele_trk_matched_clus++;
470 if (this_pos_matched && this_pos_has_clus) n_v0_pos_trk_matched_clus++;
471 if (this_ele_matched && this_pos_matched) {
472 if (this_ele_has_clus && this_pos_has_clus) n_v0_trk_matched_clus_both++;
473 if (this_pos_has_clus) n_v0_trk_matched_clus_pos_only++;
474 if (this_ele_has_clus) n_v0_trk_matched_clus_ele_only++;
478 bool this_trk_matched = this_ele_matched && this_pos_matched;
479 if (this_ele_matched) n_v0_ele_trk_matched++;
480 if (this_pos_matched) n_v0_pos_trk_matched++;
481 if (this_trk_matched) {
483 if (std::fabs(dz) < best_trk_abs_dz) {
484 best_trk_abs_dz = std::fabs(dz);
488 int this_tier = this_pos_has_clus ? (this_ele_has_clus ? 2 : 1) : 0;
489 bool better = (this_tier > best_clus_tier) ||
490 (this_tier == best_clus_tier && std::fabs(dz) < best_clus_abs_dz);
492 best_clus_tier = this_tier;
493 best_clus_abs_dz = std::fabs(dz);
495 best_pos_clus = posP->getCluster();
497 best_pos_trk_p = posP->getTrack().getP();
499 best_pos_trk_nhits = posP->getTrack().getTrackerHitCount();
500 have_best_trk_clus =
true;
506 bool matched_z = has_v0 && (true_vtx_z > -9000.) && (best_abs_dz <
vertexMatchZ_);
507 bool matched_trk = (n_v0_trk_matched >= 1);
508 bool matched_trk_ele = (n_v0_ele_trk_matched >= 1);
509 bool matched_trk_pos = (n_v0_pos_trk_matched >= 1);
510 bool matched_z_or_trk = matched_z || matched_trk;
511 bool matched_trk_ele_clus = (n_v0_ele_trk_matched_clus >= 1);
512 bool matched_trk_pos_clus = (n_v0_pos_trk_matched_clus >= 1);
513 bool matched_trk_clus_both = (n_v0_trk_matched_clus_both >= 1);
514 bool matched_trk_clus_pos_only = (n_v0_trk_matched_clus_pos_only >= 1);
515 bool matched_trk_clus_ele_only = (n_v0_trk_matched_clus_ele_only >= 1);
517 bus_.set(
"n_v0", n_v0);
518 bus_.set(
"has_v0", has_v0);
519 bus_.set(
"matched_z", matched_z);
521 bus_.set<
double>(
"best_dz", best_dz);
522 bus_.set<
double>(
"best_vtx_x", best_vtx->
getX());
523 bus_.set<
double>(
"best_vtx_y", best_vtx->
getY());
524 bus_.set<
double>(
"best_vtx_z", best_vtx->
getZ());
525 bus_.set<
double>(
"best_vtx_chi2", best_vtx->
getChi2());
527 bus_.set(
"n_v0_trk_matched", n_v0_trk_matched);
528 bus_.set(
"matched_trk", matched_trk);
529 bus_.set(
"matched_z_or_trk", matched_z_or_trk);
530 bus_.set(
"matched_z_and_trk", matched_z_and_trk);
531 if (n_v0_trk_matched > 0)
bus_.set<
double>(
"best_trk_dz", best_trk_dz);
532 bus_.set(
"matched_trk_ele", matched_trk_ele);
533 bus_.set(
"matched_trk_pos", matched_trk_pos);
534 bus_.set(
"matched_trk_ele_clus", matched_trk_ele_clus);
535 bus_.set(
"matched_trk_pos_clus", matched_trk_pos_clus);
536 bus_.set(
"matched_trk_clus_both", matched_trk_clus_both);
537 bus_.set(
"matched_trk_clus_pos_only", matched_trk_clus_pos_only);
538 bus_.set(
"matched_trk_clus_ele_only", matched_trk_clus_ele_only);
539 if (have_best_trk_clus) {
541 bool pos_has_clus = best_pos_clus.
getEnergy() > -9000.;
542 bus_.set(
"has_ele_clus", ele_has_clus);
543 bus_.set(
"has_pos_clus", pos_has_clus);
544 bus_.set<
double>(
"ele_trk_p", best_ele_trk_p);
545 bus_.set<
double>(
"pos_trk_p", best_pos_trk_p);
546 bus_.set<
int>(
"ele_trk_nhits", best_ele_trk_nhits);
547 bus_.set<
int>(
"pos_trk_nhits", best_pos_trk_nhits);
549 std::vector<double> xyz = best_ele_clus.
getPosition();
551 bus_.set<
double>(
"ele_clus_x", xyz[0]);
552 bus_.set<
double>(
"ele_clus_y", xyz[1]);
553 bus_.set<
double>(
"ele_clus_z", xyz[2]);
554 bus_.set<
double>(
"ele_clus_t", best_ele_clus.
getTime());
557 std::vector<double> xyz = best_pos_clus.
getPosition();
559 bus_.set<
double>(
"pos_clus_x", xyz[0]);
560 bus_.set<
double>(
"pos_clus_y", xyz[1]);
561 bus_.set<
double>(
"pos_clus_z", xyz[2]);
562 bus_.set<
double>(
"pos_clus_t", best_pos_clus.
getTime());
566 event_cf_.apply(
"at_least_one_v0", has_v0);
567 event_cf_.fill_nm1(
"at_least_one_v0", n_v0);
568 event_cf_.apply(
"v0_within_z", matched_z);
569 event_cf_.fill_nm1(
"v0_within_z", best_abs_dz < 1e8 ? best_abs_dz : 49.999);
574 int n_trk_pos = 0, n_trk_ele = 0;
576 const auto& tracks{
bus_.get<std::vector<Track*>>(
trkColl_)};
577 for (
Track* trk : tracks) {
578 if (trk->getCharge() > 0) n_trk_pos++;
579 else if (trk->getCharge() < 0) n_trk_ele++;
582 bus_.set(
"n_trk_pos", n_trk_pos);
583 bus_.set(
"n_trk_ele", n_trk_ele);
585 if (truth_signal_found) {
599 bool hp = (n_trk_pos > 0), he = (n_trk_ele > 0);