Skip to content

Commit af1ff85

Browse files
sawenzelshahor02
authored andcommitted
Proposal to attach track statistics in MCHeader
https://alice.its.cern.ch/jira/browse/O2-2646
1 parent 5296a30 commit af1ff85

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

run/O2HitMerger.h

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include <csignal>
6666
#include <mutex>
6767
#include <filesystem>
68+
#include <functional>
6869

6970
#include "SimPublishChannelHelper.h"
7071

@@ -412,7 +413,7 @@ class O2HitMerger : public FairMQDevice
412413
std::copy(from.begin(), from.end(), std::back_inserter(to));
413414
}
414415

415-
void reorderAndMergeMCTracks(int eventID, TTree& target, const std::vector<int>& nprimaries, const std::vector<int>& nsubevents)
416+
void reorderAndMergeMCTracks(int eventID, TTree& target, const std::vector<int>& nprimaries, const std::vector<int>& nsubevents, std::function<void(std::vector<MCTrack> const&)> tracks_analysis_hook)
416417
{
417418
// avoid doing this for trivial cases
418419
std::vector<MCTrack>* mcTracksPerSubEvent = nullptr;
@@ -480,6 +481,11 @@ class O2HitMerger : public FairMQDevice
480481
//
481482
// write to output
482483
auto filladdr = (entries > 1) ? targetdata.get() : vectorOfSubEventMCTracks[0];
484+
485+
// we give the possibility to produce some MC track statistics
486+
// to be saved as part of the MCHeader structure
487+
tracks_analysis_hook(*filladdr);
488+
483489
auto targetbr = o2::base::getOrMakeBranch(target, "MCTrack", &filladdr);
484490
targetbr->SetAddress(&filladdr);
485491
targetbr->Fill();
@@ -650,9 +656,6 @@ class O2HitMerger : public FairMQDevice
650656

651657
// put the event headers into the new TTree
652658
auto headerbr = o2::base::getOrMakeBranch(*mOutTree, "MCEventHeader.", &eventheader);
653-
headerbr->SetAddress(&eventheader);
654-
headerbr->Fill();
655-
headerbr->ResetAddress();
656659

657660
// attention: We need to make sure that we write everything in the same event order
658661
// but iteration over keys of a standard map in C++ is ordered
@@ -667,9 +670,50 @@ class O2HitMerger : public FairMQDevice
667670
printf("HitMerger entry: %d nprimry: %5d trackoffset: %5d \n", entry, nprimaries[entry], trackoffsets[entry]);
668671
}
669672

670-
reorderAndMergeMCTracks(flusheventID, *mOutTree, nprimaries, subevOrdered);
673+
// This is a hook that collects some useful statistics/properties on the event
674+
// for use by other components;
675+
// Properties are attached making use of the extensible "Info" feature which is already
676+
// part of MCEventHeader. In such a way, one can also do this pass outside and attach arbitrary
677+
// metadata to MCEventHeader without needing to change the data layout or API of the class itself.
678+
// NOTE: This function might also be called directly in the primary server!?
679+
auto mcheaderhook = [eventheader](std::vector<MCTrack> const& tracks) {
680+
int eta1Point2Counter = 0;
681+
int eta1Point0Counter = 0;
682+
int eta0Point8Counter = 0;
683+
int prims = 0;
684+
for (auto& tr : tracks) {
685+
if (tr.isPrimary()) {
686+
prims++;
687+
const auto eta = tr.GetEta();
688+
if (eta < 1.2) {
689+
eta1Point2Counter++;
690+
}
691+
if (eta < 1.0) {
692+
eta1Point0Counter++;
693+
}
694+
if (eta < 0.8) {
695+
eta0Point8Counter++;
696+
}
697+
} else {
698+
break; // track layout is such that all prims are first anyway
699+
}
700+
}
701+
// attach these properties to eventheader
702+
// we only need to make the names standard
703+
eventheader->putInfo("prims_eta_1.2", eta1Point2Counter);
704+
eventheader->putInfo("prims_eta_1.0", eta1Point0Counter);
705+
eventheader->putInfo("prims_eta_0.8", eta0Point8Counter);
706+
eventheader->putInfo("prims_total", prims);
707+
};
708+
709+
reorderAndMergeMCTracks(flusheventID, *mOutTree, nprimaries, subevOrdered, mcheaderhook);
671710
remapTrackIdsAndMerge<std::vector<o2::TrackReference>>("TrackRefs", flusheventID, *mOutTree, trackoffsets, nprimaries, subevOrdered, mTrackRefBuffer);
672711

712+
// header can be written
713+
headerbr->SetAddress(&eventheader);
714+
headerbr->Fill();
715+
headerbr->ResetAddress();
716+
673717
// c) do the merge procedure for all hits ... delegate this to detector specific functions
674718
// since they know about types; number of branches; etc.
675719
// this will also fix the trackIDs inside the hits

0 commit comments

Comments
 (0)