1313// / \brief task for electrons from heavy-flavour hadron decays
1414// / \author Jonghan Park (Jeonbuk National University), Seul I Jeong (Pusan National University)
1515
16+ #include " PWGHF/DataModel/AliasTables.h"
17+ #include " PWGHF/Utils/utilsBfieldCCDB.h"
18+
19+ #include " Common/Core/trackUtilities.h"
1620#include " Common/DataModel/EventSelection.h"
1721#include " Common/DataModel/PIDResponseTOF.h"
1822#include " Common/DataModel/PIDResponseTPC.h"
1923#include " Common/DataModel/TrackSelectionTables.h"
2024
25+ #include < CCDB/BasicCCDBManager.h>
2126#include < CommonConstants/PhysicsConstants.h>
27+ #include < CommonUtils/ConfigurableParam.h>
28+ #include < DetectorsBase/MatLayerCylSet.h>
29+ #include < DetectorsBase/Propagator.h>
30+ #include < DetectorsVertexing/PVertexer.h>
2231#include < Framework/ASoA.h>
2332#include < Framework/AnalysisDataModel.h>
2433#include < Framework/AnalysisTask.h>
2938#include < Framework/InitContext.h>
3039#include < Framework/SliceCache.h>
3140#include < Framework/runDataProcessing.h>
41+ #include < ReconstructionDataFormats/Vertex.h>
3242
3343#include < TPDGCode.h>
3444
45+ #include < algorithm>
46+ #include < array>
47+ #include < cstdint>
3548#include < map>
49+ #include < string>
50+ #include < vector>
3651
3752using namespace o2 ;
3853using namespace o2 ::constants::math;
@@ -101,21 +116,37 @@ struct HfTaskSingleElectron {
101116 Configurable<int > nSigmaTpcHadronMax{" nSigmaTpcHadronMax" , -3 , " max of tpc hadron nsigma" };
102117 Configurable<int > nSigmaTpcHadronMin{" nSigmaTpcHadronMin" , -5 , " min of tpc hadron nsigma" };
103118
119+ Configurable<float > bFieldSign{" bFieldSign" , 1 .f , " sign of the L3 magnetic field (+1 or -1), used in DCA_xy x charge x sign(B)" };
120+
121+ // PV refit (processDataPvRefit)
122+ Configurable<std::string> ccdbUrl{" ccdbUrl" , " http://alice-ccdb.cern.ch" , " URL of the CCDB repository" };
123+ Configurable<std::string> ccdbPathLut{" ccdbPathLut" , " GLO/Param/MatLUT" , " CCDB path of the material LUT" };
124+ Configurable<std::string> ccdbPathGrpMag{" ccdbPathGrpMag" , " GLO/Config/GRPMagField" , " CCDB path of the GRPMagField object" };
125+
104126 // SliceCache
105127 SliceCache cache;
106128
129+ Service<o2::ccdb::BasicCCDBManager> ccdb{};
130+ o2::base::MatLayerCylSet* lut{};
131+ o2::vertexing::PVertexer vertexer;
132+ int runNumber{0 };
133+
107134 // using declarations
108135 using MyCollisions = soa::Join<aod::Collisions, aod::EvSels>;
109136 using TracksEl = soa::Join<aod::Tracks, aod::TrackSelection, aod::TrackSelectionExtension, aod::TracksExtra, aod::TracksDCA, aod::pidTOFFullEl, aod::pidTPCFullEl>;
110137 using McTracksEl = soa::Join<aod::Tracks, aod::TrackSelection, aod::TrackSelectionExtension, aod::TrackExtra, aod::TracksDCA, aod::pidTOFFullEl, aod::pidTPCFullEl, aod::McTrackLabels>;
138+ using AllTracks = aod::TracksWCovDcaExtra;
111139
112140 // Filter
113141 Filter collZFilter = nabs(aod::collision::posZ) < posZMax;
114142
115143 // Partition
144+ Partition<AllTracks> pvContributors = ((aod::track::flags & static_cast <uint32_t >(aod::track::PVContributor)) == static_cast <uint32_t >(aod::track::PVContributor));
116145
117146 // ConfigurableAxis
118147 ConfigurableAxis axisPtEl{" axisPtEl" , {VARIABLE_WIDTH , 0 .5f , 0 .6f , 0 .7f , 0 .8f , 0 .9f , 1 .f , 1 .1f , 1 .2f , 1 .3f , 1 .4f , 1 .5f , 1 .75f , 2 .0f , 2 .25f , 2 .5f , 2 .75f , 3 .f , 3 .5f , 4 .0f , 5 .0f , 6 .0f , 8 .0f , 10 .0f }, " electron pt bins" };
148+ ConfigurableAxis axisDcaSigned{" axisDcaSigned" , {4000 , -0.2 , 0.2 }, " DCA_xy x charge x sign(B) bins (cm)" };
149+ ConfigurableAxis axisNContrib{" axisNContrib" , {VARIABLE_WIDTH , 0 ., 5 ., 10 ., 15 ., 20 ., 25 ., 30 ., 40 ., 50 ., 60 ., 80 ., 100 ., 150 ., 250 .}, " number of PV contributors bins" };
119150
120151 // Histogram registry
121152 HistogramRegistry histos{" histos" };
@@ -191,6 +222,42 @@ struct HfTaskSingleElectron {
191222 histos.add (" hDcaConv" , " " , kTH2D , {{axisPtEl}, {axisTrackIp}});
192223 histos.add (" hDcaHadron" , " " , kTH2D , {{axisPtEl}, {axisTrackIp}});
193224
225+ // DCA_xy x q x sign(B)
226+ const AxisSpec axisDcaSig{axisDcaSigned, " DCA_{xy} #times #it{q} #times sign(#it{B}) (cm)" };
227+ const AxisSpec axisNContribEvt{axisNContrib, " #it{N}_{contrib}" };
228+ histos.add (" hDcaSignedTrack" , " after electron identification;#it{p}_{T} (GeV/#it{c});DCA_{xy} #times #it{q} #times sign(#it{B}) (cm);#it{N}_{contrib}" , kTH3D , {{axisPtEl}, {axisDcaSig}, {axisNContribEvt}});
229+ histos.add (" hDcaSignedHadron" , " TPC hadron band, before TOF selection;#it{p}_{T} (GeV/#it{c});DCA_{xy} #times #it{q} #times sign(#it{B}) (cm)" , kTH2D , {{axisPtEl}, {axisDcaSig}});
230+ histos.add (" hDcaSignedHadronAfterTofCut" , " TPC hadron band, after TOF selection;#it{p}_{T} (GeV/#it{c});DCA_{xy} #times #it{q} #times sign(#it{B}) (cm)" , kTH2D , {{axisPtEl}, {axisDcaSig}});
231+
232+ if (doprocessData && doprocessDataPvRefit) {
233+ LOGF (fatal, " processData and processDataPvRefit cannot be enabled together" );
234+ }
235+ if (doprocessDataPvRefit) {
236+ histos.add (" hDcaSignedTrackPvRefit" , " after electron identification, PV refit;#it{p}_{T} (GeV/#it{c});DCA_{xy} #times #it{q} #times sign(#it{B}) (cm);#it{N}_{contrib}" , kTH3D , {{axisPtEl}, {axisDcaSig}, {axisNContribEvt}});
237+ histos.add (" hDcaSignedHadronPvRefit" , " TPC hadron band, before TOF selection, PV refit;#it{p}_{T} (GeV/#it{c});DCA_{xy} #times #it{q} #times sign(#it{B}) (cm)" , kTH2D , {{axisPtEl}, {axisDcaSig}});
238+ histos.add (" hDcaSignedHadronAfterTofCutPvRefit" , " TPC hadron band, after TOF selection, PV refit;#it{p}_{T} (GeV/#it{c});DCA_{xy} #times #it{q} #times sign(#it{B}) (cm)" , kTH2D , {{axisPtEl}, {axisDcaSig}});
239+ // PV refit QA
240+ const AxisSpec axisCollisionNContrib{1000 , 0 , 1000 , " Number of contributors" };
241+ const AxisSpec axisPvRefitDeltaX{1000 , -0 .05f , 0 .05f , " #Delta x_{PV} (cm)" };
242+ const AxisSpec axisPvRefitDeltaY{1000 , -0 .05f , 0 .05f , " #Delta y_{PV} (cm)" };
243+ const AxisSpec axisPvRefitDeltaZ{1000 , -0 .05f , 0 .05f , " #Delta z_{PV} (cm)" };
244+ histos.add (" PvRefit/hVerticesPerTrack" , " " , kTH1D , {{3 , 0 .5f , 3 .5f , " " }});
245+ histos.add (" PvRefit/hPvDeltaXvsNContrib" , " " , kTH2D , {axisCollisionNContrib, axisPvRefitDeltaX});
246+ histos.add (" PvRefit/hPvDeltaYvsNContrib" , " " , kTH2D , {axisCollisionNContrib, axisPvRefitDeltaY});
247+ histos.add (" PvRefit/hPvDeltaZvsNContrib" , " " , kTH2D , {axisCollisionNContrib, axisPvRefitDeltaZ});
248+ histos.add (" PvRefit/hChi2vsNContrib" , " " , kTH2D , {axisCollisionNContrib, {102 , -1.5 , 100.5 , " #chi^{2} PV refit" }});
249+ histos.add (" PvRefit/hPvRefitXChi2Minus1" , " PV refit with #it{#chi}^{2}==#minus1" , kTH2D , {{100 , -20 .f , 20 .f }, {100 , -2 .f , 2 .f }});
250+ histos.add (" PvRefit/hPvRefitYChi2Minus1" , " PV refit with #it{#chi}^{2}==#minus1" , kTH2D , {{100 , -20 .f , 20 .f }, {100 , -2 .f , 2 .f }});
251+ histos.add (" PvRefit/hPvRefitZChi2Minus1" , " PV refit with #it{#chi}^{2}==#minus1" , kTH2D , {{100 , -20 .f , 20 .f }, {100 , -2 .f , 2 .f }});
252+ histos.add (" PvRefit/hNContribPvRefitNotDoable" , " N. contrib for PV refit not doable" , kTH1D , {axisCollisionNContrib});
253+ histos.add (" PvRefit/hNContribPvRefitChi2Minus1" , " N. contrib for PV refit #it{#chi}^{2}==#minus1" , kTH1D , {axisCollisionNContrib});
254+ ccdb->setURL (ccdbUrl);
255+ ccdb->setCaching (true );
256+ ccdb->setLocalObjectValidityChecking ();
257+ lut = o2::base::MatLayerCylSet::rectifyPtrFromFile (ccdb->get <o2::base::MatLayerCylSet>(ccdbPathLut));
258+ o2::conf::ConfigurableParam::updateFromString (" pvertexer.useMeanVertexConstraint=false" );
259+ }
260+
194261 // QA plots for MC
195262 histos.add (" hPdgC" , " " , kTH1D , {{10001 , -0.5 , 10000.5 }});
196263 histos.add (" hPdgB" , " " , kTH1D , {{10001 , -0.5 , 10000.5 }});
@@ -515,8 +582,8 @@ struct HfTaskSingleElectron {
515582 return Else;
516583 }
517584
518- void processData (soa::Filtered<MyCollisions>::iterator const & collision,
519- TracksEl const & tracks)
585+ template < bool DoPvRefit, typename TCollision, typename TTracks>
586+ void runData (TCollision const & collision, TTracks const & tracks)
520587 {
521588 float const flagAnalysedEvt = 0.5 ;
522589
@@ -531,6 +598,27 @@ struct HfTaskSingleElectron {
531598 histos.fill (HIST (" hVtxZ" ), collision.posZ ());
532599 histos.fill (HIST (" hNEvents" ), flagAnalysedEvt);
533600
601+ // PV refit: vertexer per collision
602+ std::vector<int64_t > pvContribGlobId{};
603+ std::vector<o2::track::TrackParCov> pvContribTrackParCov{};
604+ o2::dataformats::VertexBase primVtx;
605+ bool pvRefitDoable = false ;
606+ if constexpr (DoPvRefit) {
607+ initCCDB (collision.template bc_as <aod::BCsWithTimestamps>(), runNumber, ccdb, ccdbPathGrpMag, lut, false );
608+ auto pvContribColl = pvContributors->sliceByCached (aod::track::collisionId, collision.globalIndex (), cache);
609+ for (const auto & contributor : pvContribColl) {
610+ pvContribGlobId.push_back (contributor.globalIndex ());
611+ pvContribTrackParCov.push_back (getTrackParCov (contributor));
612+ }
613+ primVtx.setX (collision.posX ());
614+ primVtx.setY (collision.posY ());
615+ primVtx.setZ (collision.posZ ());
616+ primVtx.setCov (collision.covXX (), collision.covXY (), collision.covYY (), collision.covXZ (), collision.covYZ (), collision.covZZ ());
617+ vertexer.init ();
618+ pvRefitDoable = vertexer.prepareVertexRefit (pvContribTrackParCov, primVtx);
619+ }
620+ std::vector<bool > pvContribUsed (pvContribGlobId.size (), true );
621+
534622 for (const auto & track : tracks) {
535623
536624 fillTrackQaPreCut (track);
@@ -554,12 +642,64 @@ struct HfTaskSingleElectron {
554642 histos.fill (HIST (" hTpcNSigP" ), track.p (), track.tpcNSigmaEl ());
555643 histos.fill (HIST (" hTpcNSigPt" ), track.pt (), track.tpcNSigmaEl ());
556644
645+ double const dcaSigned = track.dcaXY () * track.sign () * bFieldSign;
646+ float dcaXYPvRefit = track.dcaXY ();
647+ bool pvRefitDone = false ;
648+ [[maybe_unused]] auto getDcaSignedPvRefit = [&]() -> double {
649+ if (!pvRefitDone) {
650+ pvRefitDone = true ;
651+ const auto it = std::find (pvContribGlobId.begin (), pvContribGlobId.end (), track.globalIndex ());
652+ if (track.isPVContributor () && it != pvContribGlobId.end ()) {
653+ histos.fill (HIST (" PvRefit/hVerticesPerTrack" ), 1 );
654+ if (!pvRefitDoable) {
655+ histos.fill (HIST (" PvRefit/hNContribPvRefitNotDoable" ), collision.numContrib ());
656+ } else {
657+ histos.fill (HIST (" PvRefit/hVerticesPerTrack" ), 2 );
658+ const auto entry = std::distance (pvContribGlobId.begin (), it);
659+ pvContribUsed[entry] = false ;
660+ const auto primVtxRefitted = vertexer.refitVertex (pvContribUsed, primVtx);
661+ pvContribUsed[entry] = true ;
662+ histos.fill (HIST (" PvRefit/hChi2vsNContrib" ), primVtxRefitted.getNContributors (), primVtxRefitted.getChi2 ());
663+ if (primVtxRefitted.getChi2 () < 0 ) {
664+ histos.fill (HIST (" PvRefit/hPvRefitXChi2Minus1" ), primVtxRefitted.getX (), collision.posX ());
665+ histos.fill (HIST (" PvRefit/hPvRefitYChi2Minus1" ), primVtxRefitted.getY (), collision.posY ());
666+ histos.fill (HIST (" PvRefit/hPvRefitZChi2Minus1" ), primVtxRefitted.getZ (), collision.posZ ());
667+ histos.fill (HIST (" PvRefit/hNContribPvRefitChi2Minus1" ), collision.numContrib ());
668+ } else {
669+ histos.fill (HIST (" PvRefit/hVerticesPerTrack" ), 3 );
670+ histos.fill (HIST (" PvRefit/hPvDeltaXvsNContrib" ), primVtxRefitted.getNContributors (), primVtx.getX () - primVtxRefitted.getX ());
671+ histos.fill (HIST (" PvRefit/hPvDeltaYvsNContrib" ), primVtxRefitted.getNContributors (), primVtx.getY () - primVtxRefitted.getY ());
672+ histos.fill (HIST (" PvRefit/hPvDeltaZvsNContrib" ), primVtxRefitted.getNContributors (), primVtx.getZ () - primVtxRefitted.getZ ());
673+ auto trackPar = getTrackPar (track);
674+ std::array<float , 2 > dcaInfo{-999 .f , -999 .f };
675+ if (o2::base::Propagator::Instance ()->propagateToDCABxByBz ({primVtxRefitted.getX (), primVtxRefitted.getY (), primVtxRefitted.getZ ()}, trackPar, 2 .f , o2::base::Propagator::MatCorrType::USEMatCorrNONE, &dcaInfo)) {
676+ dcaXYPvRefit = dcaInfo[0 ];
677+ }
678+ }
679+ }
680+ }
681+ }
682+ return dcaXYPvRefit * track.sign () * bFieldSign;
683+ };
684+ if (track.tpcNSigmaEl () < nSigmaTpcHadronMax && track.tpcNSigmaEl () > nSigmaTpcHadronMin) {
685+ histos.fill (HIST (" hDcaSignedHadron" ), track.pt (), dcaSigned);
686+ if constexpr (DoPvRefit) {
687+ histos.fill (HIST (" hDcaSignedHadronPvRefit" ), track.pt (), getDcaSignedPvRefit ());
688+ }
689+ }
690+
557691 if (std::abs (track.tofNSigmaEl ()) > nSigmaTofMax) {
558692 continue ;
559693 }
560694 histos.fill (HIST (" hTofNSigPtQA" ), track.pt (), track.tofNSigmaEl ());
561695 histos.fill (HIST (" hTpcNSigPAfterTofCut" ), track.p (), track.tpcNSigmaEl ());
562696 histos.fill (HIST (" hTpcNSigPtAfterTofCut" ), track.pt (), track.tpcNSigmaEl ());
697+ if (track.tpcNSigmaEl () < nSigmaTpcHadronMax && track.tpcNSigmaEl () > nSigmaTpcHadronMin) {
698+ histos.fill (HIST (" hDcaSignedHadronAfterTofCut" ), track.pt (), dcaSigned);
699+ if constexpr (DoPvRefit) {
700+ histos.fill (HIST (" hDcaSignedHadronAfterTofCutPvRefit" ), track.pt (), getDcaSignedPvRefit ());
701+ }
702+ }
563703
564704 if (track.tpcNSigmaEl () < nSigmaTpcMin || track.tpcNSigmaEl () > nSigmaTpcMax) {
565705 continue ;
@@ -573,10 +713,29 @@ struct HfTaskSingleElectron {
573713 histos.fill (HIST (" hTpcNSigPtQA" ), track.pt (), track.tpcNSigmaEl ());
574714
575715 histos.fill (HIST (" hDcaTrack" ), track.pt (), track.dcaXY ());
716+ histos.fill (HIST (" hDcaSignedTrack" ), track.pt (), dcaSigned, collision.numContrib ());
717+ if constexpr (DoPvRefit) {
718+ histos.fill (HIST (" hDcaSignedTrackPvRefit" ), track.pt (), getDcaSignedPvRefit (), collision.numContrib ());
719+ }
576720 }
577721 }
722+
723+ void processData (soa::Filtered<MyCollisions>::iterator const & collision,
724+ TracksEl const & tracks)
725+ {
726+ runData<false >(collision, tracks);
727+ }
578728 PROCESS_SWITCH (HfTaskSingleElectron, processData, " For real data" , true );
579729
730+ void processDataPvRefit (soa::Filtered<MyCollisions>::iterator const & collision,
731+ TracksEl const & tracks,
732+ AllTracks const &,
733+ aod::BCsWithTimestamps const &)
734+ {
735+ runData<true >(collision, tracks);
736+ }
737+ PROCESS_SWITCH (HfTaskSingleElectron, processDataPvRefit, " For real data, also with the DCA to the PV refitted without the track" , false );
738+
580739 void processMc (soa::Filtered<MyCollisions>::iterator const & collision,
581740 McTracksEl const & tracks,
582741 aod::McParticles const &)
0 commit comments