88// In applying this license CERN does not waive the privileges and immunities
99// granted to it by virtue of its status as an Intergovernmental Organization
1010// or submit itself to any jurisdiction.
11- // / \author Jasper Parkkila (jparkkil@cern.ch)
11+ // /
12+ // / \file jflucWeightsLoader.cxx
13+ // / \brief Task to load the NUA and NUE weights from local files or CCDB.
14+ // / \author Jasper Parkkila (jparkkil@cern.ch), Maxim Virta (maxim.virta@cern.ch)
1215// / \since May 2024
13- // o2-linter: disable='doc/file'
16+ // / The weights are loaded from the local files or CCDB and stored in the JWeights table.
1417
1518#include " PWGCF/DataModel/CorrelationsDerived.h"
1619#include " PWGCF/JCorran/DataModel/JCatalyst.h"
@@ -43,19 +46,22 @@ using namespace o2::framework::expressions;
4346// The standalone jfluc code expects the entire list of tracks for an event. At the same time, it expects weights together with other track attributes.
4447// This workflow creates a table of weights that can be joined with track tables.
4548struct JflucWeightsLoader {
46- O2_DEFINE_CONFIGURABLE (cfgPathPhiWeights, std::string, " http://alice-ccdb.cern.ch " , " Local (local://) or CCDB path for the phi acceptance correction histogram" );
47- O2_DEFINE_CONFIGURABLE (cfgPathEffWeights, std::string, " " , " Local (local://) or CCDB path for the efficiency correction histogram" );
49+ O2_DEFINE_CONFIGURABLE (cfgPathPhiWeights, std::string, " Users/m/mavirta/corrections/NUA/LHC23zzh " , " Local (local://) or CCDB path for the phi acceptance correction histogram" );
50+ O2_DEFINE_CONFIGURABLE (cfgPathEffWeights, std::string, " Users/m/mavirta/corrections/NUE/LHC23zzh " , " Local (local://) or CCDB path for the efficiency correction histogram" );
4851 O2_DEFINE_CONFIGURABLE (cfgForRunNumber, bool , false , " Get CCDB object by run" );
49- O2_DEFINE_CONFIGURABLE (cfgCCDBPath, std::string, " Users/m/mavirta/corrections/NUA/LHC23zzh" , " Internal path in CCDB" );
5052
5153 THnF* ph = 0 ;
5254 TFile* pf = 0 ;
5355 THnF* pheff = 0 ;
5456 TFile* pfeff = 0 ;
5557 int runNumber = 0 ;
5658 int timestamp = 0 ;
57- bool useCCDB = false ;
59+ bool useNUAFromCCDB = false ;
60+ bool useEffFromCCDB = false ;
5861 Service<o2::ccdb::BasicCCDBManager> ccdb;
62+ std::string ccdbURL = " http://alice-ccdb.cern.ch" ;
63+ enum { kNUA ,
64+ kEFF };
5965
6066 ~JflucWeightsLoader ()
6167 {
@@ -73,12 +79,20 @@ struct JflucWeightsLoader {
7379 }
7480 }
7581
76- void initCCDB (int runNum, int ts)
82+ void initCCDB (int runNum, int ts, int NUAorEFF = kNUA )
7783 {
7884 if (cfgForRunNumber) {
79- ph = ccdb->getForRun <THnF>(cfgCCDBPath, runNum);
85+ if (NUAorEFF == kNUA ) {
86+ ph = ccdb->getForRun <THnF>(cfgPathPhiWeights, runNum);
87+ } else {
88+ pheff = ccdb->getForRun <THnF>(cfgPathEffWeights, runNum);
89+ }
8090 } else {
81- ph = ccdb->getForTimeStamp <THnF>(cfgCCDBPath, ts);
91+ if (NUAorEFF == kNUA ) {
92+ ph = ccdb->getForTimeStamp <THnF>(cfgPathPhiWeights, ts);
93+ } else {
94+ pheff = ccdb->getForTimeStamp <THnF>(cfgPathEffWeights, ts);
95+ }
8296 }
8397 }
8498
@@ -90,40 +104,48 @@ struct JflucWeightsLoader {
90104
91105 if (doprocessLoadWeights && doprocessLoadWeightsCF)
92106 LOGF (fatal, " Only one of JTracks or CFTracks processing can be enabled at a time." );
93- if (cfgPathPhiWeights.value .find (" ccdb" ) != std::string::npos) {
94- LOGF (info, " Using corrections from: ccdb" );
95- useCCDB = true ;
96- ccdb->setURL (cfgPathPhiWeights);
97- ccdb->setCaching (true );
98- ccdb->setLocalObjectValidityChecking ();
99- ccdb->setFatalWhenNull (false );
100- } else if (cfgPathPhiWeights.value .substr (0 , 8 ) == " local://" ) {
101- LOGF (info, " Using non-uniform acceptance corrections from: %s" , cfgPathPhiWeights.value .substr (8 ).c_str ());
107+
108+ // NUA corrections from local file or CCDB
109+ if (cfgPathPhiWeights.value .substr (0 , 8 ) == " local://" ) {
110+ LOGF (info, " Using NUA corrections locally from: %s" , cfgPathPhiWeights.value .substr (8 ).c_str ());
102111 pf = new TFile (cfgPathPhiWeights.value .substr (8 ).c_str (), " read" );
103112 if (!pf->IsOpen ()) {
104113 delete pf;
105114 pf = 0 ;
106115 LOGF (fatal, " NUA correction weights file not found: %s" , cfgPathPhiWeights.value .substr (8 ).c_str ());
107116 }
108- useCCDB = false ;
117+ useNUAFromCCDB = false ;
109118 } else {
110- LOGF (info, " Didn't find \" local://\" or \" ccdb\" for non-uniform acceptance corrections." );
119+ LOGF (info, " Assuming NUA corrections from CCDB." );
120+ useNUAFromCCDB = true ;
121+ ccdb->setURL (ccdbURL.data ()); // default CCDB URL
122+ ccdb->setCaching (true );
123+ ccdb->setLocalObjectValidityChecking ();
124+ ccdb->setFatalWhenNull (false );
111125 }
112126
127+ // Efficiency corrections from local file or CCDB
113128 if (cfgPathEffWeights.value .substr (0 , 8 ) == " local://" ) {
114- LOGF (info, " Using efficiency corrections from: %s" , cfgPathEffWeights.value .substr (8 ).c_str ());
129+ LOGF (info, " Using efficiency corrections locally from: %s" , cfgPathEffWeights.value .substr (8 ).c_str ());
115130 pfeff = new TFile (cfgPathEffWeights.value .substr (8 ).c_str (), " read" );
116131 if (!pfeff->IsOpen ()) {
117132 delete pfeff;
118133 pfeff = 0 ;
119134 LOGF (fatal, " Efficiency correction weights file not found: %s" , cfgPathEffWeights.value .substr (8 ).c_str ());
120- } else if (!(pheff = pfeff->Get <THnF>(" ccdb_object" ))) {
121- LOGF (warning, " Efficiency correction histogram not found." );
122135 } else {
123136 LOGF (info, " Loaded efficiency correction histogram locally." );
124137 }
138+ useEffFromCCDB = false ;
125139 } else {
126- LOGF (info, " Didn't find \" local://\" or \" ccdb\" for efficiency corrections." );
140+ LOGF (info, " Assuming efficiency corrections from CCDB." );
141+ useEffFromCCDB = true ;
142+ // If NUA corrections are from CCDB, use the same CCDB URL for efficiency corrections
143+ if (!useNUAFromCCDB) {
144+ ccdb->setURL (ccdbURL.data ()); // default CCDB URL
145+ ccdb->setCaching (true );
146+ ccdb->setLocalObjectValidityChecking ();
147+ ccdb->setFatalWhenNull (false );
148+ }
127149 }
128150 }
129151
@@ -133,23 +155,39 @@ struct JflucWeightsLoader {
133155 template <class ProducesT , class CollisionT , class TrackT >
134156 void loadWeights (Produces<ProducesT>& outputT, CollisionT const & collision, TrackT const & tracks)
135157 {
136- if (pf || useCCDB ) {
158+ if (pf || useNUAFromCCDB ) {
137159 if (collision.runNumber () != runNumber) {
138160 if (ph)
139161 delete ph;
140- if (!useCCDB ) {
162+ if (!useNUAFromCCDB ) {
141163 // Check if NUA correction can be found from a local file and load it
142164 if (!(ph = pf->Get <THnF>(Form (" NUAWeights_%d" , collision.runNumber ()))))
143165 LOGF (warning, " NUA correction histogram not found for run %d." , collision.runNumber ());
144166 else
145167 LOGF (info, " Loaded NUA correction histogram locally for run %d." , collision.runNumber ());
146168 } else {
147- initCCDB (collision.runNumber (), timestamp);
169+ initCCDB (collision.runNumber (), timestamp, kNUA );
148170 LOGF (info, " Loaded NUA correction histogram from CCDB for run %d." , collision.runNumber ());
149171 }
150172 runNumber = collision.runNumber ();
151173 }
152174 }
175+ if (pfeff) {
176+ if (collision.runNumber () != runNumber) {
177+ if (pheff)
178+ delete pheff;
179+ if (!useEffFromCCDB) {
180+ if (!(pheff = pfeff->Get <THnF>(" ccdb_object" ))) {
181+ LOGF (warning, " Efficiency correction histogram not found." );
182+ } else {
183+ LOGF (info, " Loaded NUE correction histogram locally for run %d." , collision.runNumber ());
184+ }
185+ } else {
186+ initCCDB (collision.runNumber (), timestamp, kEFF );
187+ LOGF (info, " Loaded efficiency correction histogram from CCDB for run %d." , collision.runNumber ());
188+ }
189+ }
190+ }
153191 for (const auto & track : tracks) {
154192 float phiWeight, effWeight;
155193 if (ph) {
@@ -165,19 +203,18 @@ struct JflucWeightsLoader {
165203 break;
166204 }
167205 }*/
168- const double coords[] = {collision.multiplicity (), static_cast <double >(partType), track.phi (), track.eta (), collision.posZ ()};
169- phiWeight = ph->GetBinContent (ph->GetBin (coords));
206+ // NUA corrections are a function of multiplicity, partType, phi, eta, and z-vertex
207+ const double nuaCoords[] = {collision.multiplicity (), static_cast <double >(partType), track.phi (), track.eta (), collision.posZ ()};
208+ phiWeight = ph->GetBinContent (ph->GetBin (nuaCoords));
170209 } else {
171210 phiWeight = 1 .0f ;
172211 }
173212
174213 if (pheff) {
175- const int effVars[] = {
176- pheff->GetAxis (0 )->FindBin (track.eta ()),
177- pheff->GetAxis (1 )->FindBin (track.pt ()),
178- pheff->GetAxis (2 )->FindBin (collision.multiplicity ()),
179- pheff->GetAxis (3 )->FindBin (collision.posZ ())};
180- effWeight = pheff->GetBinContent (effVars);
214+ // Efficiency corrections are a function of eta, pT, multiplicity, and z-vertex
215+ const double nueCoords[] = {track.eta (), track.pt (), collision.multiplicity (), collision.posZ ()};
216+
217+ effWeight = pheff->GetBinContent (pheff->GetBin (nueCoords));
181218 } else {
182219 effWeight = 1 .0f ;
183220 }
0 commit comments