@@ -166,6 +166,8 @@ class CosmicsClusterCollectorSpec : public Task
166166 };
167167
168168 void updateTimeDependentParams (ProcessingContext& pc);
169+ void fillTPCOccupancy (gsl::span<const unsigned int > occupancyMap);
170+ float tpcOccupancy (float timeTB, bool after) const ;
169171 void buildUsedMap (const RecoContainer& data, std::vector<std::pair<float , float >>& time0Windows);
170172 void addTPCAttached (const RecoContainer& data, const o2::tpc::TrackTPC& trk, std::vector<o2::dataformats::CosmicTPCCluster>& out, std::unordered_set<uint32_t >& taken) const ;
171173 // / time frame of a TPC road: the leg's z is shifted by dz and its clusters are transformed with vertexTime
@@ -221,6 +223,10 @@ class CosmicsClusterCollectorSpec : public Task
221223 float mRoadITS = 1 .5f ; // /< road half-width in the ITS [cm]
222224 std::vector<o2::math_utils::Point3D<float >> mITSChipCentres ; // /< global positions of the ITS chip centres (aligned geometry)
223225 float mTPCTBinMUS = 0 .2f ; // /< TPC time bin [mus]
226+ std::vector<uint64_t > mTPCOccCumul ; // /< TPC occupancy map of the TF summed up: [i] = clusters in the bins before bin i
227+ float mTPCOccBinTB = 16 .f; // /< time bins per bin of the TPC occupancy map
228+ int mTPCOccBinsPerOrbit = 1 ; // /< bins of the TPC occupancy map per orbit
229+ float mTPCOccTF = -1 .f; // /< TPC clusters per orbit, average of the TF (< 0: no occupancy map)
224230 float mBz = 0 .f;
225231 bool mUseMC = false ;
226232 mutable bool mStaggeredWarned = false ;
@@ -305,6 +311,8 @@ void CosmicsClusterCollectorSpec::run(ProcessingContext& pc)
305311 o2::dataformats::CosmicsTFInfo tfInfo;
306312 tfInfo.vDrift = mCorrMap ->getVDrift ();
307313 tfInfo.t0 = mCorrMap ->getT0 ();
314+ fillTPCOccupancy (recoData.occupancyMapTPC );
315+ tfInfo.tpcOcc = mTPCOccTF ;
308316
309317 std::vector<o2::dataformats::TrackCosmicsExtended> cosmicsOut;
310318 const auto cosmics = recoData.getCosmicTracks ();
@@ -391,6 +399,8 @@ void CosmicsClusterCollectorSpec::run(ProcessingContext& pc)
391399 roadTime.known = true ;
392400 }
393401 mDbgTauC = roadTime.tb ;
402+ out.tpcOccBef = tpcOccupancy (roadTime.tb , false );
403+ out.tpcOccAft = tpcOccupancy (roadTime.tb , true );
394404 std::unordered_set<uint32_t > taken;
395405 for (int leg = 0 ; leg < 2 ; leg++) { // attached clusters of both legs first, so that a road never takes the other leg's clusters
396406 if (tpcLegs[leg]) {
@@ -488,6 +498,40 @@ void CosmicsClusterCollectorSpec::buildUsedMap(const RecoContainer& data, std::v
488498 }
489499}
490500
501+ void CosmicsClusterCollectorSpec::fillTPCOccupancy (gsl::span<const unsigned int > occupancyMap)
502+ {
503+ // TPC occupancy map (GPUChainTrackingSectorTracker): [0] clusters per orbit (average of the TF), [1] time bins per bin << 16 | averaging,
504+ // [2...] clusters per bin (all clusters, by their time)
505+ mTPCOccCumul .clear ();
506+ mTPCOccTF = occupancyMap.empty () ? -1 .f : occupancyMap[0 ];
507+ if (occupancyMap.size () < 3 || (occupancyMap[1 ] >> 16 ) == 0 ) { // no time bins in the map
508+ return ;
509+ }
510+ mTPCOccBinTB = occupancyMap[1 ] >> 16 ;
511+ mTPCOccBinsPerOrbit = std::max (1 , static_cast <int >(o2::constants::lhc::LHCMaxBunches / 8 / mTPCOccBinTB ));
512+ mTPCOccCumul .resize (occupancyMap.size () - 1 , 0 );
513+ for (size_t bin = 2 ; bin < occupancyMap.size (); bin++) {
514+ mTPCOccCumul [bin - 1 ] = mTPCOccCumul [bin - 2 ] + occupancyMap[bin];
515+ }
516+ }
517+
518+ float CosmicsClusterCollectorSpec::tpcOccupancy (float timeTB, bool after) const
519+ {
520+ // TPC clusters in the map bins of one orbit before the bin of timeTB (after: from the bin of timeTB on); -1 if the window is not
521+ // fully inside the TF, where the map would understate the occupancy
522+ if (mTPCOccCumul .empty ()) {
523+ return -1 .f ;
524+ }
525+ const int nBins = static_cast <int >(mTPCOccCumul .size ()) - 1 ;
526+ const int bin = static_cast <int >(std::floor (timeTB / mTPCOccBinTB ));
527+ const int first = after ? bin : bin - mTPCOccBinsPerOrbit ;
528+ const int last = after ? bin + mTPCOccBinsPerOrbit : bin;
529+ if (first < 0 || last > nBins) {
530+ return -1 .f ;
531+ }
532+ return static_cast <float >(mTPCOccCumul [last] - mTPCOccCumul [first]);
533+ }
534+
491535void CosmicsClusterCollectorSpec::addTPCAttached (const RecoContainer& data, const o2::tpc::TrackTPC& trk, std::vector<o2::dataformats::CosmicTPCCluster>& out, std::unordered_set<uint32_t >& taken) const
492536{
493537 const auto & clusters = data.getTPCClusters ();
0 commit comments