4141#include " DataFormatsMCH/ROFRecord.h"
4242#include " DataFormatsMCH/TrackMCH.h"
4343#include " DataFormatsMCH/Cluster.h"
44+ #include " DataFormatsMCH/Digit.h"
4445#include " MCHTracking/TrackParam.h"
4546#include " MCHTracking/Track.h"
4647#include " MCHTracking/TrackFinder.h"
@@ -57,6 +58,9 @@ using namespace o2::framework;
5758class TrackFinderTask
5859{
5960 public:
61+ // _________________________________________________________________________________________________
62+ TrackFinderTask (bool digits = false ) : mDigits (digits) {}
63+
6064 // _________________________________________________________________________________________________
6165 void init (framework::InitContext& ic)
6266 {
@@ -105,18 +109,22 @@ class TrackFinderTask
105109 auto clusterROFs = pc.inputs ().get <gsl::span<ROFRecord>>(" clusterrofs" );
106110 auto clustersIn = pc.inputs ().get <gsl::span<Cluster>>(" clusters" );
107111
108- // LOG(info) << "received time frame with " << clusterROFs.size() << " interactions";
109-
110112 // create the output messages for tracks and attached clusters
111113 auto & trackROFs = pc.outputs ().make <std::vector<ROFRecord>>(OutputRef{" trackrofs" });
112114 auto & mchTracks = pc.outputs ().make <std::vector<TrackMCH>>(OutputRef{" tracks" });
113115 auto & usedClusters = pc.outputs ().make <std::vector<Cluster>>(OutputRef{" trackclusters" });
114116
117+ // prepare to send the associated digits if requested
118+ gsl::span<const Digit> digitsIn{};
119+ std::vector<Digit, o2::pmr::polymorphic_allocator<Digit>>* usedDigits (nullptr );
120+ if (mDigits ) {
121+ digitsIn = pc.inputs ().get <gsl::span<Digit>>(" clusterdigits" );
122+ usedDigits = &pc.outputs ().make <std::vector<Digit>>(OutputRef{" trackdigits" });
123+ }
124+
115125 trackROFs.reserve (clusterROFs.size ());
116126 for (const auto & clusterROF : clusterROFs) {
117127
118- // LOG(info) << "processing interaction: " << clusterROF.getBCData() << "...";
119-
120128 // sort the input clusters of the current event per DE
121129 std::unordered_map<int , std::list<const Cluster*>> clusters{};
122130 for (const auto & cluster : clustersIn.subspan (clusterROF.getFirstIdx (), clusterROF.getNEntries ())) {
@@ -131,7 +139,7 @@ class TrackFinderTask
131139
132140 // fill the ouput messages
133141 int trackOffset (mchTracks.size ());
134- writeTracks (tracks, mchTracks, usedClusters);
142+ writeTracks (tracks, mchTracks, usedClusters, digitsIn, usedDigits );
135143 trackROFs.emplace_back (clusterROF.getBCData (), trackOffset, mchTracks.size () - trackOffset,
136144 clusterROF.getBCWidth ());
137145 }
@@ -144,9 +152,14 @@ class TrackFinderTask
144152 // _________________________________________________________________________________________________
145153 void writeTracks (const std::list<Track>& tracks,
146154 std::vector<TrackMCH, o2::pmr::polymorphic_allocator<TrackMCH>>& mchTracks,
147- std::vector<Cluster, o2::pmr::polymorphic_allocator<Cluster>>& usedClusters) const
155+ std::vector<Cluster, o2::pmr::polymorphic_allocator<Cluster>>& usedClusters,
156+ const gsl::span<const Digit>& digitsIn,
157+ std::vector<Digit, o2::pmr::polymorphic_allocator<Digit>>* usedDigits) const
148158 {
149- // / fill the output messages with tracks and attached clusters
159+ // / fill the output messages with tracks and attached clusters and digits if requested
160+
161+ // map the location of the attached digits between the digitsIn and the usedDigits lists
162+ std::unordered_map<uint32_t , uint32_t > digitLocMap{};
150163
151164 for (const auto & track : tracks) {
152165
@@ -162,26 +175,55 @@ class TrackFinderTask
162175 paramAtMID.getZ (), paramAtMID.getParameters (), paramAtMID.getCovariances ());
163176
164177 for (const auto & param : track) {
178+
165179 usedClusters.emplace_back (*param.getClusterPtr ());
180+
181+ if (mDigits ) {
182+
183+ // map the location of the digits associated to this cluster in the usedDigits list, if not already done
184+ auto & cluster = usedClusters.back ();
185+ auto digitLoc = digitLocMap.emplace (cluster.firstDigit , usedDigits->size ());
186+
187+ // add the digits associated to this cluster if not already there
188+ if (digitLoc.second ) {
189+ auto itFirstDigit = digitsIn.begin () + cluster.firstDigit ;
190+ usedDigits->insert (usedDigits->end (), itFirstDigit, itFirstDigit + cluster.nDigits );
191+ }
192+
193+ // make the cluster point to the associated digits in the usedDigits list
194+ cluster.firstDigit = digitLoc.first ->second ;
195+ }
166196 }
167197 }
168198 }
169199
200+ bool mDigits = false ; // /< send to associated digits
170201 TrackFinder mTrackFinder {}; // /< track finder
171202 std::chrono::duration<double > mElapsedTime {}; // /< timer
172203};
173204
174205// _________________________________________________________________________________________________
175- o2::framework::DataProcessorSpec getTrackFinderSpec (const char * specName)
206+ o2::framework::DataProcessorSpec getTrackFinderSpec (const char * specName, bool digits )
176207{
208+ std::vector<InputSpec> inputSpecs{};
209+ inputSpecs.emplace_back (InputSpec{" clusterrofs" , " MCH" , " CLUSTERROFS" , 0 , Lifetime::Timeframe});
210+ inputSpecs.emplace_back (InputSpec{" clusters" , " MCH" , " GLOBALCLUSTERS" , 0 , Lifetime::Timeframe});
211+
212+ std::vector<OutputSpec> outputSpecs{};
213+ outputSpecs.emplace_back (OutputSpec{{" trackrofs" }, " MCH" , " TRACKROFS" , 0 , Lifetime::Timeframe});
214+ outputSpecs.emplace_back (OutputSpec{{" tracks" }, " MCH" , " TRACKS" , 0 , Lifetime::Timeframe});
215+ outputSpecs.emplace_back (OutputSpec{{" trackclusters" }, " MCH" , " TRACKCLUSTERS" , 0 , Lifetime::Timeframe});
216+
217+ if (digits) {
218+ inputSpecs.emplace_back (InputSpec{" clusterdigits" , " MCH" , " CLUSTERDIGITS" , 0 , Lifetime::Timeframe});
219+ outputSpecs.emplace_back (OutputSpec{{" trackdigits" }, " MCH" , " TRACKDIGITS" , 0 , Lifetime::Timeframe});
220+ }
221+
177222 return DataProcessorSpec{
178223 specName,
179- Inputs{InputSpec{" clusterrofs" , " MCH" , " CLUSTERROFS" , 0 , Lifetime::Timeframe},
180- InputSpec{" clusters" , " MCH" , " GLOBALCLUSTERS" , 0 , Lifetime::Timeframe}},
181- Outputs{OutputSpec{{" trackrofs" }, " MCH" , " TRACKROFS" , 0 , Lifetime::Timeframe},
182- OutputSpec{{" tracks" }, " MCH" , " TRACKS" , 0 , Lifetime::Timeframe},
183- OutputSpec{{" trackclusters" }, " MCH" , " TRACKCLUSTERS" , 0 , Lifetime::Timeframe}},
184- AlgorithmSpec{adaptFromTask<TrackFinderTask>()},
224+ inputSpecs,
225+ outputSpecs,
226+ AlgorithmSpec{adaptFromTask<TrackFinderTask>(digits)},
185227 Options{{" l3Current" , VariantType::Float, -30000 .0f , {" L3 current" }},
186228 {" dipoleCurrent" , VariantType::Float, -6000 .0f , {" Dipole current" }},
187229 {" grp-file" , VariantType::String, o2::base::NameConf::getGRPFileName (), {" Name of the grp file" }},
0 commit comments