3838#include < TTree.h>
3939
4040#include < string>
41+ #include < unordered_set>
4142
4243using namespace o2 ;
4344using namespace o2 ::framework;
@@ -57,24 +58,28 @@ struct HmpidTableProducer {
5758
5859 Produces<aod::HmpidAnalysis> hmpidAnalysis;
5960
60- // using TrackCandidates = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksDCA, aod::TrackSelection>;
61+ // configurable for quality requirements
62+ Configurable<bool > requireITS{" requireITS" , true , " Require ITS track" };
63+ Configurable<bool > requireTPC{" requireTPC" , true , " Require TPC track" };
64+ Configurable<bool > requireTOF{" requireTOF" , true , " Require TOF track" };
6165
62- using CollisionCandidates = o2::soa::Join<o2:: aod::Collisions, o2:: aod::EvSels >;
66+ using CollisionCandidates = o2::soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::CentFV0As >;
6367
6468 using TrackCandidates = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksDCA, aod::TrackSelection,
6569 aod::pidTPCFullPi, aod::pidTPCFullKa, aod::pidTPCFullPr, aod::pidTPCFullDe,
6670 aod::pidTOFFullPi, aod::pidTOFFullKa, aod::pidTOFFullPr, aod::pidTOFFullDe>;
6771
68- // using CentralityClass = o2::soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::CentFV0As>;
69-
7072 void init (o2::framework::InitContext&)
7173 {
7274 // Configure CCDB
7375 ccdb->setURL (ccdbConfig.ccdbUrl );
7476 ccdb->setCaching (true );
7577 ccdb->setLocalObjectValidityChecking ();
78+ ccdb->setFatalWhenNull (false );
7679
7780 histos.add (" eventCounter" , " eventCounter" , kTH1F , {axisEvtCounter});
81+ histos.add (" goodEventCounter" , " goodEventCounter" , kTH1F , {axisEvtCounter});
82+ histos.add (" eventsHmpid" , " eventsWithHmpid" , kTH1F , {axisEvtCounter});
7883 }
7984
8085 // function to manage ccdb
@@ -87,50 +92,75 @@ struct HmpidTableProducer {
8792 mCCDBRunNumber = bc.runNumber ();
8893 }
8994
90- void process (soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::CentFV0As>::iterator const & col,
91- const aod::HMPIDs& hmpids,
92- TrackCandidates const &,
93- aod::BCsWithTimestamps const &)
95+ void processEvent (CollisionCandidates::iterator const & col,
96+ aod::BCsWithTimestamps const &)
9497 {
9598 histos.fill (HIST (" eventCounter" ), 0.5 );
99+ if (col.sel8 ()) {
100+ histos.fill (HIST (" goodEventCounter" ), 0.5 );
101+ }
96102
103+ // initialize CCDB for current BC
97104 initCCDB (col.bc_as <aod::BCsWithTimestamps>());
105+ }
106+ PROCESS_SWITCH (HmpidTableProducer, processEvent, " Process event level - collisions" , true );
107+
108+ void processHmpid (
109+ aod::HMPIDs const & hmpids,
110+ TrackCandidates const &,
111+ CollisionCandidates const &,
112+ aod::BCsWithTimestamps const &)
113+ {
114+ // --- Static set to track unique collisions with HMPID tracks ---
115+ static std::unordered_set<uint32_t > collisionsWithHmpid;
98116
99- for (const auto & t : hmpids) {
117+ for (auto const & t : hmpids) {
100118
101- // global tracks associated to hmpid tracks
119+ // Access the global track associated to the HMPID track
102120 const auto & globalTrack = t.track_as <TrackCandidates>();
103- if (!globalTrack.isGlobalTrack ())
104- continue ;
105- if (!globalTrack.hasITS () || !globalTrack.hasTPC () || !globalTrack.hasTOF ())
121+
122+ if (!globalTrack.has_collision ())
106123 continue ;
107124
108- // verify accessible collision
109- if (!globalTrack.has_collision ()) {
125+ // Access the associated collision
126+ const auto & col = globalTrack.collision_as <CollisionCandidates>();
127+ initCCDB (col.bc_as <aod::BCsWithTimestamps>());
128+ uint32_t collId = col.globalIndex ();
129+
130+ // --- Track quality selection ---
131+ if ((requireITS && !globalTrack.hasITS ()) ||
132+ (requireTPC && !globalTrack.hasTPC ()) ||
133+ (requireTOF && !globalTrack.hasTOF ())) {
110134 continue ;
111135 }
112136
137+ // Count collisions with at least one valid HMPID track
138+ if (collisionsWithHmpid.insert (collId).second ) {
139+ histos.fill (HIST (" eventsHmpid" ), 0.5 );
140+ }
141+
142+ float centrality = col.centFV0A ();
143+
113144 float hmpidPhotsCharge2[o2::aod::kDimPhotonsCharge ];
114145
115146 for (int i = 0 ; i < o2::aod::kDimPhotonsCharge ; i++) {
116147 hmpidPhotsCharge2[i] = t.hmpidPhotsCharge ()[i];
117148 }
118149
119- float centrality = col.centFV0A ();
120-
121- // ///FILL TABLE
122- hmpidAnalysis (
123- t.hmpidSignal (), globalTrack.phi (), globalTrack.eta (), t.hmpidMom (),
124- globalTrack.p (), t.hmpidXTrack (), t.hmpidYTrack (), t.hmpidXMip (),
125- t.hmpidYMip (), t.hmpidNPhotons (), t.hmpidQMip (), (t.hmpidClusSize () % 1000000 ) / 1000 ,
126- t.hmpidClusSize () / 1000000 , hmpidPhotsCharge2, globalTrack.eta (), globalTrack.phi (),
127- globalTrack.px (), globalTrack.py (), globalTrack.pz (), globalTrack.itsNCls (),
128- globalTrack.tpcNClsFound (), globalTrack.tpcNClsCrossedRows (), globalTrack.tpcChi2NCl (), globalTrack.itsChi2NCl (),
129- globalTrack.dcaXY (), globalTrack.dcaZ (), globalTrack.tpcNSigmaPi (), globalTrack.tofNSigmaPi (),
130- globalTrack.tpcNSigmaKa (), globalTrack.tofNSigmaKa (), globalTrack.tpcNSigmaPr (), globalTrack.tofNSigmaPr (),
131- globalTrack.tpcNSigmaDe (), globalTrack.tofNSigmaDe (), centrality);
132- }
150+ // ///FILL HMPID CUSTOM TABLE
151+ hmpidAnalysis (t.hmpidSignal (), t.hmpidMom (),
152+ globalTrack.p (), t.hmpidXTrack (), t.hmpidYTrack (), t.hmpidXMip (),
153+ t.hmpidYMip (), t.hmpidNPhotons (), t.hmpidQMip (), (t.hmpidClusSize () % 1000000 ) / 1000 ,
154+ t.hmpidClusSize () / 1000000 , hmpidPhotsCharge2, globalTrack.eta (), globalTrack.phi (),
155+ globalTrack.px (), globalTrack.py (), globalTrack.pz (), globalTrack.itsNCls (),
156+ globalTrack.tpcNClsFound (), globalTrack.tpcNClsCrossedRows (), globalTrack.tpcChi2NCl (), globalTrack.itsChi2NCl (),
157+ globalTrack.dcaXY (), globalTrack.dcaZ (), globalTrack.tpcNSigmaPi (), globalTrack.tofNSigmaPi (),
158+ globalTrack.tpcNSigmaKa (), globalTrack.tofNSigmaKa (), globalTrack.tpcNSigmaPr (), globalTrack.tofNSigmaPr (),
159+ globalTrack.tpcNSigmaDe (), globalTrack.tofNSigmaDe (), centrality);
160+ } // end loop on hmpid table entries
133161 }
162+
163+ PROCESS_SWITCH (HmpidTableProducer, processHmpid, " Process hmpid entries - tracks" , true );
134164};
135165
136166WorkflowSpec defineDataProcessing (ConfigContext const & cfg) { return WorkflowSpec{adaptAnalysisTask<HmpidTableProducer>(cfg)}; }
0 commit comments