@@ -109,7 +109,7 @@ class TrackMCStudy : public Task
109109 void updateTimeDependentParams (ProcessingContext& pc);
110110 float getDCAYCut (float pt) const ;
111111
112- gsl::span< const MCTrack> mCurrMCTracks ;
112+ const std::vector<o2:: MCTrack>* mCurrMCTracks = nullptr ;
113113 TVector3 mCurrMCVertex ;
114114 o2::tpc::VDriftHelper mTPCVDriftHelper {};
115115 o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader {};
@@ -122,8 +122,9 @@ class TrackMCStudy : public Task
122122 std::vector<float > mTPCOcc ; // /< TPC occupancy for this interaction time
123123 std::vector<int > mITSOcc ; // < N ITS clusters in the ROF containing collision
124124 bool mCheckSV = false ; // < check SV binding (apart from prongs availability)
125+ bool mRecProcStage = false ; // < flag that the MC particle was added only at the stage of reco tracks processing
125126 int mNTPCOccBinLength = 0 ; // /< TPC occ. histo bin length in TBs
126- float mNTPCOccBinLengthInv ;
127+ float mNTPCOccBinLengthInv = - 1 .f ;
127128 int mVerbose = 0 ;
128129 float mITSTimeBiasMUS = 0 .f;
129130 float mITSROFrameLengthMUS = 0 .f; // /< ITS RO frame in mus
@@ -181,10 +182,11 @@ void TrackMCStudy::run(ProcessingContext& pc)
181182 }
182183 mDecProdLblPool .clear ();
183184 mMCVtVec .clear ();
184- mCurrMCTracks = {} ;
185+ mCurrMCTracks = nullptr ;
185186
186187 recoData.collectData (pc, *mDataRequest .get ()); // select tracks of needed type, with minimal cuts, the real selected will be done in the vertexer
187188 updateTimeDependentParams (pc); // Make sure this is called after recoData.collectData, which may load some conditions
189+ mRecProcStage = false ;
188190 process (recoData);
189191}
190192
@@ -278,15 +280,21 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
278280 return patt;
279281 };
280282
281- auto getLowestPadrow = [&recoData](const o2::tpc::TrackTPC& trc) {
283+ auto getLowestPadrow = [&recoData](const o2::tpc::TrackTPC& trc, RecTrack& tref ) {
282284 if (recoData.inputsTPCclusters ) {
283285 uint8_t clSect = 0 , clRow = 0 ;
284286 uint32_t clIdx = 0 ;
285287 const auto clRefs = recoData.getTPCTracksClusterRefs ();
288+ const auto tpcClusAcc = recoData.getTPCClusters ();
286289 trc.getClusterReference (clRefs, trc.getNClusterReferences () - 1 , clSect, clRow, clIdx);
287- return int (clRow);
290+ const auto & clus = tpcClusAcc.clusters [clSect][clRow][clIdx];
291+ int padFromEdge = int (clus.getPad ()), npads = o2::gpu::GPUTPCGeometry::NPads (clRow);
292+ if (padFromEdge > npads / 2 ) {
293+ padFromEdge = npads - 1 - padFromEdge;
294+ }
295+ tref.padFromEdge = uint8_t (padFromEdge);
296+ tref.lowestPadRow = clRow;
288297 }
289- return -1 ;
290298 };
291299
292300 auto flagTPCClusters = [&recoData](const o2::tpc::TrackTPC& trc, o2::MCCompLabel lbTrc) {
@@ -338,6 +346,21 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
338346 }
339347 break ;
340348 }
349+ if (mNTPCOccBinLengthInv > 0 .f ) {
350+ mcVtx.occTPCV .resize (params.nOccBinsDrift );
351+ int grp = TMath::Max (1 , TMath::Nint (params.nTBPerOccBin * mNTPCOccBinLengthInv ));
352+ for (int ib = 0 ; ib < params.nOccBinsDrift ; ib++) {
353+ float smb = 0 ;
354+ int tbs = occBin + TMath::Nint (ib * params.nTBPerOccBin * mNTPCOccBinLengthInv );
355+ for (int ig = 0 ; ig < grp; ig++) {
356+ if (tbs >= 0 && tbs < int (mTBinClOccHist .size ())) {
357+ smb += mTBinClOccHist [tbs];
358+ }
359+ tbs++;
360+ }
361+ mcVtx.occTPCV [ib] = smb;
362+ }
363+ }
341364 if (rofCount >= ITSClusROFRec.size ()) {
342365 mITSOcc .push_back (0 ); // IR after the last ROF
343366 }
@@ -352,15 +375,17 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
352375 int nev = mcReader.getNEvents (curSrcMC);
353376 bool okAccVtx = true ;
354377 if (nev != (int )mMCVtVec .size ()) {
355- LOGP (error , " source {} has {} events while {} MC vertices were booked" , curSrcMC, nev, mMCVtVec .size ());
378+ LOGP (debug , " source {} has {} events while {} MC vertices were booked" , curSrcMC, nev, mMCVtVec .size ());
356379 okAccVtx = false ;
380+ if (nev > (int )mMCVtVec .size ()) { // QED
381+ continue ;
382+ }
357383 }
358384 for (curEvMC = 0 ; curEvMC < nev; curEvMC++) {
359385 if (mVerbose > 1 ) {
360386 LOGP (info, " Event {}" , curEvMC);
361387 }
362- const auto & mt = mcReader.getTracks (curSrcMC, curEvMC);
363- mCurrMCTracks = gsl::span<const MCTrack>(mt.data (), mt.size ());
388+ mCurrMCTracks = &mcReader.getTracks (curSrcMC, curEvMC);
364389 const_cast <o2::dataformats::MCEventHeader&>(mcReader.getMCEventHeader (curSrcMC, curEvMC)).GetVertex (mCurrMCVertex );
365390 if (okAccVtx) {
366391 auto & pos = mMCVtVec [curEvMC].pos ;
@@ -370,7 +395,7 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
370395 pos[2 ] = mCurrMCVertex .Z ();
371396 }
372397 }
373- for (int itr = 0 ; itr < mCurrMCTracks . size (); itr++) {
398+ for (int itr = 0 ; itr < mCurrMCTracks -> size (); itr++) {
374399 processMCParticle (curSrcMC, curEvMC, itr);
375400 }
376401 }
@@ -382,6 +407,7 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
382407 }
383408
384409 // add reconstruction info to MC particles. If MC particle was not selected before but was reconstrected, account MC info
410+ mRecProcStage = true ; // MC particles accepted only at this stage will be flagged
385411 for (int iv = 0 ; iv < nv; iv++) {
386412 if (mVerbose > 1 ) {
387413 LOGP (info, " processing PV {} of {}" , iv, nv);
@@ -416,11 +442,10 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
416442 if (lbl.getSourceID () != curSrcMC || lbl.getEventID () != curEvMC) {
417443 curSrcMC = lbl.getSourceID ();
418444 curEvMC = lbl.getEventID ();
419- const auto & mt = mcReader.getTracks (curSrcMC, curEvMC);
420- mCurrMCTracks = gsl::span<const MCTrack>(mt.data (), mt.size ());
445+ mCurrMCTracks = &mcReader.getTracks (curSrcMC, curEvMC);
421446 const_cast <o2::dataformats::MCEventHeader&>(mcReader.getMCEventHeader (curSrcMC, curEvMC)).GetVertex (mCurrMCVertex );
422447 }
423- if (!acceptMCCharged (mCurrMCTracks [lbl.getTrackID ()], lbl)) {
448+ if (!acceptMCCharged ((* mCurrMCTracks ) [lbl.getTrackID ()], lbl)) {
424449 continue ;
425450 }
426451 entry = mSelMCTracks .find (lbl);
@@ -532,7 +557,7 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
532557 if (msk[DetID::TPC]) {
533558 const auto & trtpc = recoData.getTPCTrack (gidSet[GTrackID::TPC]);
534559 tref.nClTPC = trtpc.getNClusters ();
535- tref. lowestPadRow = getLowestPadrow (trtpc);
560+ getLowestPadrow (trtpc, tref );
536561 flagTPCClusters (trtpc, entry.first );
537562 if (trackFam.entTPC < 0 ) {
538563 trackFam.entTPC = tcnt;
@@ -968,7 +993,7 @@ float TrackMCStudy::getDCAYCut(float pt) const
968993
969994bool TrackMCStudy::processMCParticle (int src, int ev, int trid)
970995{
971- const auto & mcPart = mCurrMCTracks [trid];
996+ const auto & mcPart = (* mCurrMCTracks ) [trid];
972997 int pdg = mcPart.GetPdgCode ();
973998 bool res = false ;
974999 while (true ) {
@@ -990,7 +1015,7 @@ bool TrackMCStudy::processMCParticle(int src, int ev, int trid)
9901015 break ;
9911016 }
9921017 for (int idd = idd0; idd <= idd1; idd++) {
993- const auto & product = mCurrMCTracks [idd];
1018+ const auto & product = (* mCurrMCTracks ) [idd];
9941019 auto lbld = o2::MCCompLabel (idd, ev, src);
9951020 if (!acceptMCCharged (product, lbld, decay)) {
9961021 decay = -1 ; // discard decay
@@ -1088,10 +1113,17 @@ bool TrackMCStudy::addMCParticle(const MCTrack& mcPart, const o2::MCCompLabel& l
10881113 mcEntry.mcTrackInfo .bcInTF = mIntBC [lb.getEventID ()];
10891114 mcEntry.mcTrackInfo .occTPC = mTPCOcc [lb.getEventID ()];
10901115 mcEntry.mcTrackInfo .occITS = mITSOcc [lb.getEventID ()];
1116+ mcEntry.mcTrackInfo .occTPCV = mMCVtVec [lb.getEventID ()].occTPCV ;
1117+ if (mRecProcStage ) {
1118+ mcEntry.mcTrackInfo .setAddedAtRecStage ();
1119+ }
1120+ if (o2::mcutils::MCTrackNavigator::isPhysicalPrimary (mcPart, *mCurrMCTracks )) {
1121+ mcEntry.mcTrackInfo .setPrimary ();
1122+ }
10911123 int moth = -1 ;
10921124 o2::MCCompLabel mclbPar;
10931125 if ((moth = mcPart.getMotherTrackId ()) >= 0 ) {
1094- const auto & mcPartPar = mCurrMCTracks [moth];
1126+ const auto & mcPartPar = (* mCurrMCTracks ) [moth];
10951127 mcEntry.mcTrackInfo .pdgParent = mcPartPar.GetPdgCode ();
10961128 }
10971129 if (mcPart.isPrimary () && mcReader.getNEvents (lb.getSourceID ()) == mMCVtVec .size ()) {
0 commit comments