1818#include < CCDB/BasicCCDBManager.h>
1919#include < cmath>
2020#include < vector>
21+ #include < unordered_map>
2122#include < map>
2223#include < string>
2324#include < memory>
3334#include " Common/DataModel/TrackSelectionTables.h"
3435#include " Common/DataModel/Centrality.h"
3536#include " Common/DataModel/Multiplicity.h"
37+ #include " Common/CCDB/ctpRateFetcher.h"
3638
3739#include " GFWPowerArray.h"
3840#include " GFW.h"
@@ -64,8 +66,13 @@ struct FlowRunbyRun {
6466 O2_DEFINE_CONFIGURABLE (cfgCutDCAz, float , 2 .0f , " max DCA to vertex z" )
6567 O2_DEFINE_CONFIGURABLE (cfgUseNch, bool , false , " Use Nch for flow observables" )
6668 O2_DEFINE_CONFIGURABLE (cfgNbootstrap, int , 30 , " Number of subsamples" )
69+ O2_DEFINE_CONFIGURABLE (cfgOutputNUAWeights, bool , false , " NUA weights are filled in ref pt bins" )
6770 O2_DEFINE_CONFIGURABLE (cfgOutputNUAWeightsRefPt, bool , false , " NUA weights are filled in ref pt bins" )
6871 O2_DEFINE_CONFIGURABLE (cfgDynamicRunNumber, bool , false , " Add runNumber during runtime" )
72+ O2_DEFINE_CONFIGURABLE (cfgGetInteractionRate, bool , false , " Get interaction rate from CCDB" )
73+ O2_DEFINE_CONFIGURABLE (cfgUseInteractionRateCut, bool , false , " Use events with low interaction rate" )
74+ O2_DEFINE_CONFIGURABLE (cfgCutMaxIR, float , 50 .0f , " maximum interaction rate (kHz)" )
75+ O2_DEFINE_CONFIGURABLE (cfgCutMinIR, float , 0 .0f , " minimum interaction rate (kHz)" )
6976 Configurable<std::vector<int >> cfgRunNumbers{" cfgRunNumbers" , std::vector<int >{544095 , 544098 , 544116 , 544121 , 544122 , 544123 , 544124 }, " Preconfigured run numbers" };
7077 Configurable<std::vector<std::string>> cfgUserDefineGFWCorr{" cfgUserDefineGFWCorr" , std::vector<std::string>{" refN10 {2} refP10 {-2}" }, " User defined GFW CorrelatorConfig" };
7178 Configurable<std::vector<std::string>> cfgUserDefineGFWName{" cfgUserDefineGFWName" , std::vector<std::string>{" Ch10Gap22" }, " User defined GFW Name" };
@@ -113,6 +120,12 @@ struct FlowRunbyRun {
113120 c22_gap10,
114121 kCount_TProfileNames
115122 };
123+ int mRunNumber {-1 };
124+ uint64_t mSOR {0 };
125+ double mMinSeconds {-1 .};
126+ std::unordered_map<int , TH2*> gHadronicRate ;
127+ ctpRateFetcher mRateFetcher ;
128+ TH2* gCurrentHadronicRate ;
116129
117130 using AodCollisions = soa::Filtered<soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Cs, aod::Mults>>;
118131 using AodTracks = soa::Filtered<soa::Join<aod::Tracks, aod::TrackSelection, aod::TracksExtra, aod::TracksDCA>>;
@@ -225,11 +238,30 @@ struct FlowRunbyRun {
225238 profiles[c22_gap10] = registry.add <TProfile>(Form (" %d/c22_gap10" , runNumber), " " , {HistType::kTProfile , {axisIndependent}});
226239 profilesList.insert (std::make_pair (runNumber, profiles));
227240
228- // weightsList
229- o2::framework::AxisSpec axis = axisPt;
230- int nPtBins = axis.binEdges .size () - 1 ;
231- double * ptBins = &(axis.binEdges )[0 ];
232- fGFWWeightsList ->addGFWWeightsByRun (runNumber, nPtBins, ptBins, true , false );
241+ if (cfgOutputNUAWeights) {
242+ // weightsList
243+ o2::framework::AxisSpec axis = axisPt;
244+ int nPtBins = axis.binEdges .size () - 1 ;
245+ double * ptBins = &(axis.binEdges )[0 ];
246+ fGFWWeightsList ->addGFWWeightsByRun (runNumber, nPtBins, ptBins, true , false );
247+ }
248+ }
249+
250+ void initHadronicRate (aod::BCsWithTimestamps::iterator const & bc)
251+ {
252+ if (mRunNumber == bc.runNumber ()) {
253+ return ;
254+ }
255+ mRunNumber = bc.runNumber ();
256+ if (gHadronicRate .find (mRunNumber ) == gHadronicRate .end ()) {
257+ auto runDuration = ccdb->getRunDuration (mRunNumber );
258+ mSOR = runDuration.first ;
259+ mMinSeconds = std::floor (mSOR * 1 .e -3 ); // / round tsSOR to the highest integer lower than tsSOR
260+ double maxSec = std::ceil (runDuration.second * 1 .e -3 ); // / round tsEOR to the lowest integer higher than tsEOR
261+ const AxisSpec axisSeconds{static_cast <int >((maxSec - mMinSeconds ) / 20 .f ), 0 , maxSec - mMinSeconds , " Seconds since SOR" };
262+ gHadronicRate [mRunNumber ] = registry.add <TH2>(Form (" HadronicRate/%i" , mRunNumber ), " ;Time since SOR (s);Hadronic rate (kHz)" , kTH2D , {axisSeconds, {510 , 0 ., 51 .}}).get ();
263+ }
264+ gCurrentHadronicRate = gHadronicRate [mRunNumber ];
233265 }
234266
235267 void process (AodCollisions::iterator const & collision, aod::BCsWithTimestamps const &, AodTracks const & tracks)
@@ -240,6 +272,14 @@ struct FlowRunbyRun {
240272 return ;
241273 // detect run number
242274 auto bc = collision.bc_as <aod::BCsWithTimestamps>();
275+ if (cfgGetInteractionRate) {
276+ initHadronicRate (bc);
277+ double hadronicRate = mRateFetcher .fetch (ccdb.service , bc.timestamp (), mRunNumber , " ZNC hadronic" ) * 1 .e -3 ; //
278+ double seconds = bc.timestamp () * 1 .e -3 - mMinSeconds ;
279+ if (cfgUseInteractionRateCut && (hadronicRate < cfgCutMinIR || hadronicRate > cfgCutMaxIR)) // cut on hadronic rate
280+ return ;
281+ gCurrentHadronicRate ->Fill (seconds, hadronicRate);
282+ }
243283 int runNumber = bc.runNumber ();
244284 float lRandom = fRndm ->Rndm ();
245285 if (runNumber != lastRunNumer) {
@@ -271,22 +311,24 @@ struct FlowRunbyRun {
271311 if (withinPtRef) {
272312 fGFW ->Fill (track.eta (), 1 , track.phi (), wacc * weff, 1 );
273313 }
274- if (cfgOutputNUAWeightsRefPt) {
275- if (withinPtRef) {
314+ if (cfgOutputNUAWeights) {
315+ if (cfgOutputNUAWeightsRefPt) {
316+ if (withinPtRef) {
317+ GFWWeights* weight = fGFWWeightsList ->getGFWWeightsByRun (runNumber);
318+ if (!weight) {
319+ LOGF (fatal, " Could not find the weight for run %d" , runNumber);
320+ return ;
321+ }
322+ weight->Fill (track.phi (), track.eta (), collision.posZ (), track.pt (), cent, 0 );
323+ }
324+ } else {
276325 GFWWeights* weight = fGFWWeightsList ->getGFWWeightsByRun (runNumber);
277326 if (!weight) {
278327 LOGF (fatal, " Could not find the weight for run %d" , runNumber);
279328 return ;
280329 }
281330 weight->Fill (track.phi (), track.eta (), collision.posZ (), track.pt (), cent, 0 );
282331 }
283- } else {
284- GFWWeights* weight = fGFWWeightsList ->getGFWWeightsByRun (runNumber);
285- if (!weight) {
286- LOGF (fatal, " Could not find the weight for run %d" , runNumber);
287- return ;
288- }
289- weight->Fill (track.phi (), track.eta (), collision.posZ (), track.pt (), cent, 0 );
290332 }
291333 }
292334
0 commit comments