1919#include " Framework/AnalysisDataModel.h"
2020#include " Framework/ASoAHelpers.h"
2121#include " ReconstructionDataFormats/Track.h"
22+
23+ #include " DetectorsBase/GeometryManager.h"
24+ #include " DataFormatsParameters/GRPObject.h"
25+ #include " DataFormatsParameters/GRPMagField.h"
26+ #include " CCDB/BasicCCDBManager.h"
27+
2228#include " PWGEM/PhotonMeson/DataModel/gammaTables.h"
2329
2430using namespace o2 ;
2531using namespace o2 ::framework;
2632using namespace o2 ::framework::expressions;
2733using namespace o2 ::soa;
2834
29- using MyBCs = soa::Join<aod::BCs , aod::BcSels>;
35+ using MyBCs = soa::Join<aod::BCsWithTimestamps , aod::BcSels>;
3036
3137using MyCollisions = soa::Join<aod::Collisions, aod::EvSels, aod::Mults>;
3238using MyCollisions_Cent = soa::Join<MyCollisions, aod::CentFT0Ms, aod::CentFT0As, aod::CentFT0Cs, aod::CentNTPVs>; // centrality table has dependency on multiplicity table.
@@ -48,6 +54,13 @@ struct CreateEMEvent {
4854 kEvent_Cent_Qvec = 2 ,
4955 };
5056
57+ // CCDB options
58+ Configurable<std::string> ccdburl{" ccdb-url" , " http://alice-ccdb.cern.ch" , " url of the ccdb repository" };
59+ Configurable<std::string> grpPath{" grpPath" , " GLO/GRP/GRP" , " Path of the grp file" };
60+ Configurable<std::string> grpmagPath{" grpmagPath" , " GLO/Config/GRPMagField" , " CCDB path of the GRPMagField object" };
61+ Configurable<bool > skipGRPOquery{" skipGRPOquery" , true , " skip grpo query" };
62+ Configurable<double > d_bz_input{" d_bz" , -999 , " bz field, -999 is automatic" };
63+
5164 HistogramRegistry registry{" registry" };
5265 void init (o2::framework::InitContext&)
5366 {
@@ -56,6 +69,49 @@ struct CreateEMEvent {
5669 hEventCounter->GetXaxis ()->SetBinLabel (2 , " sel8" );
5770 }
5871
72+ int mRunNumber ;
73+ float d_bz;
74+ Service<o2::ccdb::BasicCCDBManager> ccdb;
75+
76+ template <typename TBC>
77+ void initCCDB (TBC const & bc)
78+ {
79+ if (mRunNumber == bc.runNumber ()) {
80+ return ;
81+ }
82+
83+ // In case override, don't proceed, please - no CCDB access required
84+ if (d_bz_input > -990 ) {
85+ d_bz = d_bz_input;
86+ o2::parameters::GRPMagField grpmag;
87+ if (fabs (d_bz) > 1e-5 ) {
88+ grpmag.setL3Current (30000 .f / (d_bz / 5 .0f ));
89+ }
90+ mRunNumber = bc.runNumber ();
91+ return ;
92+ }
93+
94+ auto run3grp_timestamp = bc.timestamp ();
95+ o2::parameters::GRPObject* grpo = 0x0 ;
96+ o2::parameters::GRPMagField* grpmag = 0x0 ;
97+ if (!skipGRPOquery)
98+ grpo = ccdb->getForTimeStamp <o2::parameters::GRPObject>(grpPath, run3grp_timestamp);
99+ if (grpo) {
100+ // Fetch magnetic field from ccdb for current collision
101+ d_bz = grpo->getNominalL3Field ();
102+ LOG (info) << " Retrieved GRP for timestamp " << run3grp_timestamp << " with magnetic field of " << d_bz << " kZG" ;
103+ } else {
104+ grpmag = ccdb->getForTimeStamp <o2::parameters::GRPMagField>(grpmagPath, run3grp_timestamp);
105+ if (!grpmag) {
106+ LOG (fatal) << " Got nullptr from CCDB for path " << grpmagPath << " of object GRPMagField and " << grpPath << " of object GRPObject for timestamp " << run3grp_timestamp;
107+ }
108+ // Fetch magnetic field from ccdb for current collision
109+ d_bz = std::lround (5 .f * grpmag->getL3Current () / 30000 .f );
110+ LOG (info) << " Retrieved GRP for timestamp " << run3grp_timestamp << " with magnetic field of " << d_bz << " kZG" ;
111+ }
112+ mRunNumber = bc.runNumber ();
113+ }
114+
59115 PresliceUnsorted<MyCollisions> preslice_collisions_per_bc = o2::aod::evsel::foundBCId;
60116 std::unordered_map<uint64_t , int > map_ncolls_per_bc;
61117
@@ -76,7 +132,9 @@ struct CreateEMEvent {
76132 continue ;
77133 }
78134 }
135+
79136 auto bc = collision.template foundBC_as <TBCs>();
137+ initCCDB (bc);
80138
81139 // LOGF(info, "collision-loop | bc.globalIndex() = %d, ncolls_per_bc = %d", bc.globalIndex(), map_ncolls_per_bc[bc.globalIndex()]);
82140 registry.fill (HIST (" hEventCounter" ), 1 );
@@ -88,7 +146,7 @@ struct CreateEMEvent {
88146 // uint64_t tag = collision.selection_raw();
89147 event (collision.globalIndex (), bc.globalBC (), bc.runNumber (), collision.sel8 (), collision.alias_raw (), collision.selection_raw (), map_ncolls_per_bc[bc.globalIndex ()],
90148 collision.posX (), collision.posY (), collision.posZ (),
91- collision.numContrib (), collision.collisionTime (), collision.collisionTimeRes ());
149+ collision.numContrib (), collision.collisionTime (), collision.collisionTimeRes (), d_bz );
92150
93151 event_mult (collision.multFV0A (), collision.multFV0C (), collision.multFT0A (), collision.multFT0C (), collision.multFDDA (), collision.multFDDC (),
94152 collision.multZNA (), collision.multZNC (),
0 commit comments