@@ -263,6 +263,26 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
263263 return -1 ;
264264 };
265265
266+ auto flagTPCClusters = [&recoData](const o2::tpc::TrackTPC& trc, o2::MCCompLabel lbTrc) {
267+ if (recoData.inputsTPCclusters ) {
268+ const auto clRefs = recoData.getTPCTracksClusterRefs ();
269+ const auto * TPCClMClab = recoData.inputsTPCclusters ->clusterIndex .clustersMCTruth ;
270+ const auto & TPCClusterIdxStruct = recoData.inputsTPCclusters ->clusterIndex ;
271+ for (int ic = 0 ; ic < trc.getNClusterReferences (); ic++) {
272+ uint8_t clSect = 0 , clRow = 0 ;
273+ uint32_t clIdx = 0 ;
274+ trc.getClusterReference (clRefs, ic, clSect, clRow, clIdx);
275+ auto labels = TPCClMClab->getLabels (clIdx + TPCClusterIdxStruct.clusterOffset [clSect][clRow]);
276+ for (auto & lbl : labels) {
277+ if (lbl == lbTrc) {
278+ const_cast <o2::MCCompLabel&>(lbl).setFakeFlag (true ); // actually, in this way we are flagging that this cluster was correctly attached
279+ break ;
280+ }
281+ }
282+ }
283+ }
284+ };
285+
266286 {
267287 const auto * digconst = mcReader.getDigitizationContext ();
268288 const auto & mcEvRecords = digconst->getEventRecords (false );
@@ -421,13 +441,11 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
421441 }
422442 }
423443
424- // collect ITS/TPC cluster info for selected MC particles
425- if (params.minTPCRefsToExtractClRes > 0 ) {
444+ LOGP ( info, " collected {} MC tracks " , mSelMCTracks . size ());
445+ if (params.minTPCRefsToExtractClRes > 0 ) { // prepare MC trackrefs for TPC
426446 processTPCTrackRefs ();
427447 }
428- fillMCClusterInfo (recoData);
429448
430- LOGP (info, " collected {} MC tracks" , mSelMCTracks .size ());
431449 int mcnt = 0 ;
432450 for (auto & entry : mSelMCTracks ) {
433451 auto & trackFam = entry.second ;
@@ -489,6 +507,7 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
489507 const auto & trtpc = recoData.getTPCTrack (gidSet[GTrackID::TPC]);
490508 tref.nClTPC = trtpc.getNClusters ();
491509 tref.lowestPadRow = getLowestPadrow (trtpc);
510+ flagTPCClusters (trtpc, entry.first );
492511 if (trackFam.entTPC < 0 ) {
493512 trackFam.entTPC = tcnt;
494513 trackFam.tpcT0 = trtpc.getTime0 ();
@@ -533,6 +552,10 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
533552 auto & trackFam = entry.second ;
534553 (*mDBGOut ) << " tracks" << " tr=" << trackFam << " \n " ;
535554 }
555+
556+ // collect ITS/TPC cluster info for selected MC particles
557+ fillMCClusterInfo (recoData);
558+
536559 // decays
537560 std::vector<TrackFamily> decFam;
538561 for (int id = 0 ; id < mNCheckDecays ; id++) {
@@ -620,6 +643,8 @@ void TrackMCStudy::fillMCClusterInfo(const o2::globaltracking::RecoContainer& re
620643 const auto & TPCClusterIdxStruct = recoData.inputsTPCclusters ->clusterIndex ;
621644 const auto * TPCClMClab = recoData.inputsTPCclusters ->clusterIndex .clustersMCTruth ;
622645 const auto & params = o2::trackstudy::TrackMCStudyConfig::Instance ();
646+
647+ ClResTPC clRes{};
623648 for (uint8_t sector = 0 ; sector < 36 ; sector++) {
624649 for (uint8_t row = 0 ; row < 152 ; row++) {
625650 unsigned int offs = TPCClusterIdxStruct.clusterOffset [sector][row];
@@ -632,7 +657,12 @@ void TrackMCStudy::fillMCClusterInfo(const o2::globaltracking::RecoContainer& re
632657 }
633658 ncontLb++;
634659 }
635- for (const auto & lbl : labels) {
660+ const auto & clus = TPCClusterIdxStruct.clusters [sector][row][icl0];
661+ clRes.contTracks .clear ();
662+ bool doClusRes = (params.minTPCRefsToExtractClRes > 0 ) && (params.rejectClustersResStat <= 0 . || gRandom ->Rndm () < params.rejectClustersResStat );
663+ for (auto lbl : labels) {
664+ bool corrAttach = lbl.isFake (); // was this flagged in the flagTPCClusters called from process ?
665+ lbl.setFakeFlag (false );
636666 auto entry = mSelMCTracks .find (lbl);
637667 if (entry == mSelMCTracks .end ()) { // not selected
638668 continue ;
@@ -654,29 +684,29 @@ void TrackMCStudy::fillMCClusterInfo(const o2::globaltracking::RecoContainer& re
654684 mctr.nTPCClShared ++;
655685 }
656686 // try to extract ideal track position
657- if (params. minTPCRefsToExtractClRes > 0 ) {
687+ if (doClusRes ) {
658688 auto entTRefIDsIt = mSelTRefIdx .find (lbl);
659689 if (entTRefIDsIt == mSelTRefIdx .end ()) {
660690 continue ;
661691 }
692+ float xc, yc, zc;
693+ mTPCCorrMapsLoader .Transform (sector, row, clus.getPad (), clus.getTime (), xc, yc, zc, mctr.bcInTF / 8 .); // nominal time of the track
694+
662695 const auto & entTRefIDs = entTRefIDsIt->second ;
663696 // find bracketing TRef params
664697 int entIDBelow = -1 , entIDAbove = -1 ;
665698 float xBelow = -1e6 , xAbove = 1e6 ;
666- const auto & clus = TPCClusterIdxStruct.clusters [sector][row][icl0];
667- float xc, yc, zc;
668- mTPCCorrMapsLoader .Transform (sector, row, clus.getPad (), clus.getTime (), xc, yc, zc, mctr.bcInTF / 8 .); // nominal time of the track
669699
670700 for (int entID = entTRefIDs.first ; entID < entTRefIDs.second ; entID++) {
671701 const auto & refTr = mSelTRefs [entID];
672702 if (refTr.getUserField () != sector % 18 ) {
673703 continue ;
674704 }
675- if (refTr.getX () < xc && refTr.getX () > xBelow && refTr.getX () > xc - params.maxTPCRefExtrap ) {
705+ if (( refTr.getX () < xc) && ( refTr.getX () > xBelow) && ( refTr.getX () > xc - params.maxTPCRefExtrap ) ) {
676706 xBelow = refTr.getX ();
677707 entIDBelow = entID;
678708 }
679- if (refTr.getX () > xc && refTr.getX () < xAbove && refTr.getX () < xc + params.maxTPCRefExtrap ) {
709+ if (( refTr.getX () > xc) && ( refTr.getX () < xAbove) && ( refTr.getX () < xc + params.maxTPCRefExtrap ) ) {
680710 xAbove = refTr.getX ();
681711 entIDAbove = entID;
682712 }
@@ -688,42 +718,53 @@ void TrackMCStudy::fillMCClusterInfo(const o2::globaltracking::RecoContainer& re
688718 o2::track::TrackPar tparAbove, tparBelow;
689719 bool okBelow = entIDBelow >= 0 && prop->PropagateToXBxByBz ((tparBelow = mSelTRefs [entIDBelow]), xc, 0.99 , 2 .);
690720 bool okAbove = entIDAbove >= 0 && prop->PropagateToXBxByBz ((tparAbove = mSelTRefs [entIDAbove]), xc, 0.99 , 2 .);
691- if ((!okBelow && !okAbove) || (params.requireTopBottomRefs && (!okBelow || !okAbove)) || (params. rejectClustersResStat > 0 . && gRandom -> Rndm () < params. rejectClustersResStat ) ) {
721+ if ((!okBelow && !okAbove) || (params.requireTopBottomRefs && (!okBelow || !okAbove))) {
692722 continue ;
693723 }
694- ClResTPC clRes{};
695724
696725 int nmeas = 0 ;
726+ auto & clCont = clRes.contTracks .emplace_back ();
727+ clCont.corrAttach = corrAttach;
697728 if (okBelow) {
698- clRes.below = {mSelTRefs [entIDBelow].getX (), tparBelow.getY (), tparBelow.getZ ()};
699- clRes.snp += tparBelow.getSnp ();
700- clRes.tgl += tparBelow.getTgl ();
729+ clCont.below = {mSelTRefs [entIDBelow].getX (), tparBelow.getY (), tparBelow.getZ ()};
730+ clCont.snp += tparBelow.getSnp ();
731+ clCont.tgl += tparBelow.getTgl ();
732+ clCont.q2pt += tparBelow.getQ2Pt ();
701733 nmeas++;
702734 }
703735 if (okAbove) {
704- clRes.above = {mSelTRefs [entIDAbove].getX (), tparAbove.getY (), tparAbove.getZ ()};
705- clRes.snp += tparAbove.getSnp ();
706- clRes.tgl += tparBelow.getTgl ();
736+ clCont.above = {mSelTRefs [entIDAbove].getX (), tparAbove.getY (), tparAbove.getZ ()};
737+ clCont.snp += tparAbove.getSnp ();
738+ clCont.tgl += tparAbove.getTgl ();
739+ clCont.q2pt += tparAbove.getQ2Pt ();
707740 nmeas++;
708741 }
709742 if (nmeas) {
743+ if (clRes.contTracks .size () == 1 ) {
744+ int occBin = mctr.bcInTF / 8 * mNTPCOccBinLengthInv ;
745+ clRes.occ = occBin < 0 ? mTBinClOcc [0 ] : (occBin >= mTBinClOcc .size () ? mTBinClOcc .back () : mTBinClOcc [occBin]);
746+ }
747+ clCont.xyz = {xc, yc, zc};
710748 if (nmeas > 1 ) {
711- clRes.snp *= 0.5 ;
712- clRes.tgl *= 0.5 ;
749+ clCont.snp *= 0.5 ;
750+ clCont.tgl *= 0.5 ;
751+ clCont.q2pt *= 0.5 ;
713752 }
714- clRes.clPos = {xc, yc, zc};
715- clRes.sect = sector;
716- clRes.row = row;
717- clRes.qtot = clus.getQtot ();
718- clRes.qmax = clus.getQmax ();
719- clRes.flags = clus.getFlags ();
720- clRes.ncont = ncontLb;
721- int occBin = mctr.bcInTF / 8 * mNTPCOccBinLengthInv ;
722- clRes.occ = occBin < 0 ? mTBinClOcc [0 ] : (occBin >= mTBinClOcc .size () ? mTBinClOcc .back () : mTBinClOcc [occBin]);
723- (*mDBGOut ) << " clres" << " clr=" << clRes << " \n " ;
753+ } else {
754+ clRes.contTracks .pop_back ();
724755 }
725756 }
726757 }
758+ if (clRes.getNCont ()) {
759+ clRes.sect = sector;
760+ clRes.row = row;
761+ clRes.qtot = clus.getQtot ();
762+ clRes.qmax = clus.getQmax ();
763+ clRes.flags = clus.getFlags ();
764+ clRes.ncont = ncontLb;
765+ clRes.sortCont ();
766+ (*mDBGOut ) << " clres" << " clr=" << clRes << " \n " ;
767+ }
727768 }
728769 }
729770 }
0 commit comments