1818#include " Framework/runDataProcessing.h"
1919#include " Common/Core/TrackSelection.h"
2020#include " Common/DataModel/TrackSelectionTables.h"
21+ #include " Common/DataModel/Multiplicity.h"
2122#include " Common/Core/trackUtilities.h"
23+ #include " ReconstructionDataFormats/DCA.h"
24+ #include " DetectorsBase/Propagator.h"
25+ #include " DetectorsBase/GeometryManager.h"
26+ #include " DetectorsCommonDataFormats/NameConf.h"
27+ #include " DataFormatsParameters/GRPObject.h"
28+ #include < CCDB/BasicCCDBManager.h>
2229
2330using namespace o2 ;
2431using namespace o2 ::framework;
@@ -31,22 +38,111 @@ using namespace o2::framework::expressions;
3138 * FIXME: computing overhead and errors in calculations
3239 */
3340// ****************************************************************************************
34- struct TrackExtension {
41+ namespace o2
42+ {
43+ namespace analysis
44+ {
45+ namespace trackextension
46+ {
47+ constexpr long run3grp_timestamp = (1619781650000 + 1619781529000 ) / 2 ;
48+ const char * ccdbpath_lut = " GLO/Param/MatLUT" ;
49+ const char * ccdbpath_geo = " GLO/Config/Geometry" ;
50+ const char * ccdbpath_grp = " GLO/GRP/GRP" ;
51+ const char * ccdburl = " https://alice-ccdb.cern.ch" ; /* test "http://alice-ccdb.cern.ch:8080"; */
52+ } // namespace trackextension
53+ } // namespace analysis
54+ } // namespace o2
3555
56+ struct TrackExtension {
3657 Produces<aod::TracksExtended> extendedTrackQuantities;
58+ Service<o2::ccdb::BasicCCDBManager> ccdb;
59+
60+ int mRunNumber ;
61+ float mMagField ;
3762
38- void process (aod::FullTracks const & tracks, aod::Collisions const & )
63+ void init (InitContext& context )
3964 {
65+ using namespace analysis ::trackextension;
66+
67+ ccdb->setURL (ccdburl);
68+ ccdb->setCaching (true );
69+ ccdb->setLocalObjectValidityChecking ();
70+
71+ auto lut = o2::base::MatLayerCylSet::rectifyPtrFromFile (ccdb->get <o2::base::MatLayerCylSet>(ccdbpath_lut));
72+
73+ if (!o2::base::GeometryManager::isGeometryLoaded ()) {
74+ auto * gm = ccdb->get <TGeoManager>(ccdbpath_geo);
75+ /* it seems this is needed at this level for the material LUT to work properly */
76+ /* but what happens if the run changes while doing the processing? */
77+ o2::parameters::GRPObject* grpo = ccdb->getForTimeStamp <o2::parameters::GRPObject>(ccdbpath_grp, analysis::trackextension::run3grp_timestamp);
78+ o2::base::Propagator::initFieldFromGRP (grpo);
79+ o2::base::Propagator::Instance ()->setMatLUT (lut);
80+ }
81+ mRunNumber = 0 ;
82+ mMagField = 0 .0f ;
83+ }
84+
85+ void processRun2 (aod::FullTracks const & tracks, aod::Collisions const &, aod::BCsWithTimestamps const &)
86+ {
87+ using namespace analysis ::trackextension;
88+
89+ int lastCollId = -1 ;
4090 for (auto & track : tracks) {
91+ std::array<float , 2 > dca{1e10f, 1e10f};
92+ if (track.has_collision ()) {
93+ if (track.trackType () == o2::aod::track::TrackTypeEnum::Run2Track && track.itsChi2NCl () != 0 .f && track.tpcChi2NCl () != 0 .f && std::abs (track.x ()) < 10 .f ) {
94+ if (lastCollId != track.collisionId ()) {
95+ auto bc = track.collision_as <aod::Collisions>().bc_as <aod::BCsWithTimestamps>();
96+ if (mRunNumber != bc.runNumber ()) {
97+ o2::parameters::GRPObject* grpo = ccdb->getForTimeStamp <o2::parameters::GRPObject>(ccdbpath_grp, bc.timestamp ());
98+ if (grpo != nullptr ) {
99+ float l3current = grpo->getL3Current ();
100+ mMagField = l3current / 30000 .0f * 5 .0f ;
101+ LOGF (info, " Setting magnetic field to %f from an L3 current %f for run %d" , mMagField , l3current, bc.runNumber ());
102+ } else {
103+ LOGF (fatal, " GRP object is not available in CCDB for run=%d at timestamp=%llu" , bc.runNumber (), bc.timestamp ());
104+ }
105+ mRunNumber = bc.runNumber ();
106+ }
107+ lastCollId = track.collisionId ();
108+ }
109+ auto trackPar = getTrackPar (track);
110+ auto const & collision = track.collision ();
111+ trackPar.propagateParamToDCA ({collision.posX (), collision.posY (), collision.posZ ()}, mMagField , &dca);
112+ }
113+ }
114+ extendedTrackQuantities (dca[0 ], dca[1 ]);
41115
116+ // TODO: add realtive pt resolution sigma(pt)/pt \approx pt * sigma(1/pt)
117+ // TODO: add geometrical length / fiducial volume
118+ }
119+ }
120+ PROCESS_SWITCH (TrackExtension, processRun2, " Process Run2 track extension task" , true );
121+
122+ void processRun3 (aod::FullTracks const & tracks, aod::Collisions const &)
123+ {
124+ using namespace analysis ::trackextension;
125+
126+ /* it is not clear yet if we will the GRP object per run number */
127+ /* if that is the case something similar to what has been */
128+ /* done for Run2 needs to be implemented */
129+ /* but incorporating here only the GRP object makes appear */
130+ /* the double peak in the DCAxy distribution again */
131+ /* so probaly the whole initalization sequence is needed */
132+ /* when a new run (Run3) is processed */
133+ o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT;
134+
135+ for (auto & track : tracks) {
42136 std::array<float , 2 > dca{1e10f, 1e10f};
43137 if (track.has_collision ()) {
44- if ((track.trackType () == o2::aod::track::TrackTypeEnum::Track) ||
45- (track.trackType () == o2::aod::track::TrackTypeEnum::Run2Track && track.itsChi2NCl () != 0 .f && track.tpcChi2NCl () != 0 .f && std::abs (track.x ()) < 10 .f )) {
46- float magField = 5.0 ; // in kG (FIXME: get this from CCDB)
138+ if (track.trackType () == o2::aod::track::TrackTypeEnum::Track) {
47139 auto trackPar = getTrackPar (track);
48140 auto const & collision = track.collision ();
49- trackPar.propagateParamToDCA ({collision.posX (), collision.posY (), collision.posZ ()}, magField, &dca);
141+ gpu::gpustd::array<float , 2 > dcaInfo;
142+ if (o2::base::Propagator::Instance ()->propagateToDCABxByBz ({collision.posX (), collision.posY (), collision.posZ ()}, trackPar, 2 .f , matCorr, &dcaInfo)) {
143+ dca[0 ] = dcaInfo[0 ];
144+ dca[1 ] = dcaInfo[1 ];
145+ }
50146 }
51147 }
52148 extendedTrackQuantities (dca[0 ], dca[1 ]);
@@ -55,6 +151,7 @@ struct TrackExtension {
55151 // TODO: add geometrical length / fiducial volume
56152 }
57153 }
154+ PROCESS_SWITCH (TrackExtension, processRun3, " Process Run3 track extension task" , false );
58155};
59156
60157// ****************************************************************************************
0 commit comments