1616// / First O2Physics task of the AliPhysics PWGLF/SPECTRA/MultEvShape analyses.
1717
1818#include " Common/CCDB/EventSelectionParams.h"
19+ #include " Common/CCDB/ctpRateFetcher.h"
1920#include " Common/DataModel/EventSelection.h"
2021#include " Common/DataModel/Multiplicity.h"
2122#include " Common/DataModel/TrackSelectionTables.h"
2223
24+ #include < CCDB/BasicCCDBManager.h>
2325#include < CommonConstants/MathConstants.h>
2426#include < Framework/ASoA.h>
2527#include < Framework/AnalysisDataModel.h>
@@ -109,6 +111,8 @@ struct Config {
109111};
110112constexpr int NConfigs = 13 ;
111113constexpr int INominal = 0 ;
114+ constexpr int IPairFirst = 1 ; // GAP02
115+ constexpr int IPairSecond = 4 ; // GAP05, same events and stratum count as GAP02
112116constexpr std::array<Config, NConfigs> Configs = {{{.name = " NOM" , .etaFirst = 1 , .ptEnd = 3 , .cond = kCondOwn , .validEtaFirst = 1 , .validPtEnd = 3 , .evVariant = kV1 },
113117 {.name = " GAP02" , .etaFirst = 1 , .ptEnd = 3 , .cond = kCondAll , .validEtaFirst = 4 , .validPtEnd = 3 , .evVariant = kV1 },
114118 {.name = " GAP03" , .etaFirst = 2 , .ptEnd = 3 , .cond = kCondAll , .validEtaFirst = 4 , .validPtEnd = 3 , .evVariant = kV1 },
@@ -126,6 +130,7 @@ constexpr std::array<Config, NConfigs> Configs = {{{.name = "NOM", .etaFirst = 1
126130constexpr int NCountBins = 64 ; // larger counts in the overflow bin
127131constexpr int NSubCountBins = 32 ; // per sub-event
128132constexpr int MinTracksValid = 2 ; // per sub-event
133+ constexpr int NCovariateQuantities = 7 ;
129134
130135// Data halves and subsample groups, defined on blocks of bunch crossings
131136constexpr int NHalves = 2 ;
@@ -134,6 +139,11 @@ constexpr int HalfBlockShift = 26; // 2^26 BC = 1.7 s
134139constexpr int GroupBlockShift = 20 ; // 2^20 BC = 26 ms
135140constexpr int NGroups = 20 ;
136141
142+ // MC only: nominal sums split by two hashes of the MC collision (run, globalBC)
143+ constexpr int NSplitBins = 8 ;
144+ constexpr int NSubsamples = 16 ;
145+ constexpr uint64_t SplitSalt = 0x6a09e667f3bcc909ULL ;
146+
137147// / splitmix64 finaliser
138148constexpr uint64_t mix64 (uint64_t z)
139149{
@@ -149,6 +159,12 @@ uint64_t blockHash(int run, uint64_t globalBC, int shift)
149159 return mix64 (mix64 (static_cast <uint64_t >(run)) ^ (globalBC >> shift));
150160}
151161
162+ // / Per-event hash, independent of the block hashes
163+ uint64_t eventHash (int run, uint64_t globalBC)
164+ {
165+ return mix64 (mix64 (static_cast <uint64_t >(run) ^ SplitSalt) ^ globalBC);
166+ }
167+
152168struct SubEvent {
153169 int n = 0 ;
154170 double sumPt = 0 .;
@@ -223,11 +239,13 @@ struct Sums {
223239 std::array<std::shared_ptr<TH3 >, NConfigs> config{}; // (N_fwd, stratum count, monomial)
224240 std::shared_ptr<THn> strata3; // (N_fwd, n_F, n_B, first-order monomial)
225241 std::shared_ptr<TH3 > occupancy; // (configuration, N_fwd, stratum count)
242+ std::shared_ptr<TH3 > paired; // (N_fwd, stratum count, GAP02 x GAP05 first-order monomials)
226243};
227244
228245// / Nominal-configuration observables of an event
229246struct Nominal {
230247 bool valid = false ;
248+ double nFwd = 0 .;
231249 int nMid = 0 ;
232250 double xF = 0 ., xB = 0 ., vF = 0 ., vB = 0 .;
233251};
@@ -239,13 +257,16 @@ enum EventFlowBin { kFlowAll = 0,
239257 kFlowNominalValid ,
240258 kFlowHalfA ,
241259 kFlowHalfB ,
260+ kFlowNoMcLabel ,
242261 NEventFlowBins };
243- constexpr std::array<const char *, NEventFlowBins> EventFlowLabels = {" all" , " sel8" , " |z|" , " pile-up V1" , " nominal valid" , " half A" , " half B" };
262+ constexpr std::array<const char *, NEventFlowBins> EventFlowLabels = {" all" , " sel8" , " |z|" , " pile-up V1" , " nominal valid" , " half A" , " half B" , " nominal valid, no MC label " };
244263} // namespace
245264
246265struct EventShapeCoex {
247266 HistogramRegistry registry{" registry" };
248267 Service<o2::framework::O2DatabasePDG> pdg{};
268+ Service<o2::ccdb::BasicCCDBManager> ccdb{};
269+ ctpRateFetcher rateFetcher;
249270
250271 Configurable<float > vtxZCut{" vtxZCut" , 10 .0f , " Max |PV z| (cm)" };
251272 Configurable<float > etaFwdAMin{" etaFwdAMin" , 3 .5f , " FT0-A proxy: lower eta edge (generator level)" };
@@ -255,6 +276,12 @@ struct EventShapeCoex {
255276 ConfigurableAxis axisNFwd{" axisNFwd" , {50 , 1 ., 30000 .}, " N_fwd = FT0A + FT0C amplitude (a fixed-width setting is made logarithmic)" };
256277 ConfigurableAxis axisNFwdGen{" axisNFwdGen" , {50 , 1 ., 1000 .}, " generator-level N_fwd = charged primaries in the FT0 acceptance (a fixed-width setting is made logarithmic)" };
257278 ConfigurableAxis axisRun{" axisRun" , {60000 , 519999.5 , 579999.5 }, " run number (QA)" };
279+ ConfigurableAxis axisOccupancy{" axisOccupancy" , {50 , 0 ., 1000 .}, " track occupancy in time range (QA; unset in underflow)" };
280+ ConfigurableAxis axisVtxZ{" axisVtxZ" , {40 , -10 ., 10 .}, " PV z (cm, QA)" };
281+ ConfigurableAxis axisRate{" axisRate" , {100 , 0 ., 1000 .}, " interaction rate (kHz, QA; unavailable in underflow)" };
282+ Configurable<std::string> irSource{" irSource" , " T0VTX" , " interaction-rate estimator for QA; empty = not fetched" };
283+ Configurable<std::string> ccdbUrl{" ccdbUrl" , " http://alice-ccdb.cern.ch" , " CCDB url" };
284+ Configurable<bool > doSplitSums{" doSplitSums" , true , " MC: nominal sums split by hashed event bins and subsamples" };
258285
259286 Filter trackFilter = (aod::track::pt > PtMin) && (nabs(aod::track::eta) < EtaMax) && requireGlobalTrackInFilter();
260287
@@ -263,9 +290,40 @@ struct EventShapeCoex {
263290 using MyTracks = soa::Filtered<soa::Join<aod::Tracks, aod::TracksExtra, aod::TrackSelection>>;
264291
265292 std::array<Sums, NHalves> sumsReco{};
266- std::array<std::shared_ptr<TH3 >, NHalves> designEffect {}; // (N_fwd, group, first-order monomial)
293+ std::array<std::shared_ptr<TH3 >, NHalves> groupSums {}; // (N_fwd, stratum count, group x first-order monomial)
267294 Sums sumsGen{};
268295
296+ // / Nominal sums of MC events split by hashed event bin (full) and by (subsample, event bin) (sub)
297+ struct SplitSums {
298+ std::shared_ptr<TH3 > full; // (N_fwd, stratum count, event bin x monomial)
299+ std::shared_ptr<TH3 > sub; // (N_fwd, stratum count, (subsample x event bin) x first-order monomial)
300+ };
301+ SplitSums splitReco{}, splitGen{};
302+
303+ void bookSplit (SplitSums& split, const std::string& dir, const AxisSpec& nFwdAxis)
304+ {
305+ const AxisSpec countAxis{NCountBins, -0.5 , NCountBins - 0.5 , " stratum count" };
306+ split.full = registry.add <TH3 >(dir + " /full" , " NOM sums per event bin" , HistType::kTH3D , {nFwdAxis, countAxis, {NSplitBins * NMono, -0.5 , NSplitBins * NMono - 0.5 , " event bin x monomial" }});
307+ split.sub = registry.add <TH3 >(dir + " /sub" , " NOM first-order sums per subsample and event bin" , HistType::kTH3D , {nFwdAxis, countAxis, {NSubsamples * NSplitBins * NMono1, -0.5 , NSubsamples * NSplitBins * NMono1 - 0.5 , " (subsample x event bin) x monomial" }});
308+ split.full ->SetBit (TH1 ::kIsNotW );
309+ split.sub ->SetBit (TH1 ::kIsNotW );
310+ }
311+
312+ void fillSplit (SplitSums& split, const Nominal& nominal, int run, uint64_t globalBC)
313+ {
314+ const uint64_t h = eventHash (run, globalBC);
315+ const int bin = static_cast <int >(h % NSplitBins);
316+ const int subsample = static_cast <int >((h >> 32 ) % NSubsamples);
317+ std::array<double , NMono> m{};
318+ monomials (nominal.xF , nominal.xB , nominal.vF , nominal.vB , NMono, m);
319+ for (int k = 0 ; k < NMono; ++k) {
320+ split.full ->Fill (nominal.nFwd , nominal.nMid , bin * NMono + k, m[k]);
321+ }
322+ for (int k = 0 ; k < NMono1; ++k) {
323+ split.sub ->Fill (nominal.nFwd , nominal.nMid , (subsample * NSplitBins + bin) * NMono1 + k, m[k]);
324+ }
325+ }
326+
269327 // / Books the moment sums of one level under dir/<configuration>/<half>
270328 void bookSums (Sums& sums, const std::string& dir, const std::string& half, const AxisSpec& nFwdAxis, int nConfigs)
271329 {
@@ -290,6 +348,17 @@ struct EventShapeCoex {
290348 }
291349 sums.strata3 = registry.add <THn>(dir + " /NOM3/" + half, (label + " NOM in (n_F, n_B) strata" ).c_str (), HistType::kTHnD , {nFwdAxis, subCountAxis, subCountAxis, mono1Axis});
292350 sums.occupancy = registry.add <TH3 >(dir + " /occupancy/" + half, " event counts per configuration" , HistType::kTH3D , {configAxis, nFwdAxis, countAxis});
351+ if (nConfigs > IPairSecond) {
352+ std::string pairName = dir;
353+ pairName += " /" ;
354+ pairName += Configs[IPairFirst].name ;
355+ pairName += " x" ;
356+ pairName += Configs[IPairSecond].name ;
357+ pairName += " /" ;
358+ pairName += half;
359+ sums.paired = registry.add <TH3 >(pairName, (label + " cross products of two configurations" ).c_str (), HistType::kTH3D , {nFwdAxis, countAxis, {NMono1 * NMono1, -0.5 , NMono1 * NMono1 - 0.5 , " monomial pair" }});
360+ sums.paired ->SetBit (TH1 ::kIsNotW );
361+ }
293362 }
294363
295364 void init (InitContext const &)
@@ -303,12 +372,15 @@ struct EventShapeCoex {
303372 if (nFwdAxis.nBins ) {
304373 nFwdAxis.makeLogarithmic ();
305374 }
306- const AxisSpec groupAxis{NGroups , -0.5 , NGroups - 0.5 , " group " };
307- const AxisSpec mono1Axis{ NMono1, -0.5 , NMono1 - 0.5 , " monomial" };
375+ const AxisSpec countAxis{NCountBins , -0.5 , NCountBins - 0.5 , " stratum count " };
376+ const AxisSpec groupMonoAxis{NGroups * NMono1, -0.5 , NGroups * NMono1 - 0.5 , " group x monomial" };
308377 for (int h = 0 ; h < NHalves; ++h) {
309378 bookSums (sumsReco[h], " accum" , HalfName[h], nFwdAxis, NConfigs);
310- designEffect[h] = registry.add <TH3 >(std::string (" designEffect/" ) + HalfName[h], " nominal first-order sums per block group" , HistType::kTH3D , {nFwdAxis, groupAxis, mono1Axis});
311- designEffect[h]->SetBit (TH1 ::kIsNotW );
379+ groupSums[h] = registry.add <TH3 >(std::string (" groups/" ) + HalfName[h], " nominal first-order sums per block group" , HistType::kTH3D , {nFwdAxis, countAxis, groupMonoAxis});
380+ groupSums[h]->SetBit (TH1 ::kIsNotW );
381+ }
382+ if (doprocessRecoMC && doSplitSums) {
383+ bookSplit (splitReco, " split" , nFwdAxis);
312384 }
313385
314386 // QA
@@ -328,6 +400,14 @@ struct EventShapeCoex {
328400 const AxisSpec quantityAxis{5 , -0.5 , 4.5 , " quantity" };
329401 registry.add <TH3 >(" qa/hMarginalSums" , " nominal single-side sums" , HistType::kTH3D , {nFwdAxis, {NCountBins, -0.5 , NCountBins - 0.5 , " n_{mid}" }, quantityAxis})->SetBit (TH1 ::kIsNotW );
330402 registry.add <TH2 >(" qa/hRunSums" , " nominal single-side sums per run" , HistType::kTH2D , {{axisRun, " run" }, quantityAxis})->SetBit (TH1 ::kIsNotW );
403+ // quantities: count, a_F, a_B, a_F^2, a_B^2, v_F, v_B
404+ const AxisSpec quantity2Axis{NCovariateQuantities, -0.5 , NCovariateQuantities - 0.5 , " quantity" };
405+ registry.add <TH2 >(" qa/hOccupancySums" , " nominal single-side sums vs occupancy" , HistType::kTH2D , {{axisOccupancy, " track occupancy" }, quantity2Axis})->SetBit (TH1 ::kIsNotW );
406+ registry.add <TH2 >(" qa/hVtxZSums" , " nominal single-side sums vs PV z" , HistType::kTH2D , {{axisVtxZ, " PV z (cm)" }, quantity2Axis})->SetBit (TH1 ::kIsNotW );
407+ registry.add <TH2 >(" qa/hRateSums" , " nominal single-side sums vs interaction rate" , HistType::kTH2D , {{axisRate, " IR (kHz)" }, quantity2Axis})->SetBit (TH1 ::kIsNotW );
408+ ccdb->setURL (ccdbUrl.value );
409+ ccdb->setCaching (true );
410+ ccdb->setFatalWhenNull (false );
331411 }
332412
333413 if (doprocessMC) {
@@ -337,6 +417,9 @@ struct EventShapeCoex {
337417 }
338418 bookSums (sumsGen, " gen" , " all" , nFwdGenAxis, 1 ); // nominal configuration only
339419 registry.add (" gen/hEvents" , " generated events" , HistType::kTH1D , {{1 , -0.5 , 0.5 }});
420+ if (doSplitSums) {
421+ bookSplit (splitGen, " gen/split" , nFwdGenAxis);
422+ }
340423 }
341424 }
342425
@@ -345,6 +428,8 @@ struct EventShapeCoex {
345428 {
346429 Nominal nominal;
347430 std::array<double , NMono> m{};
431+ std::array<double , NMono> mPairFirst {};
432+ bool pairFirstValid = false ;
348433 double xF = 0 ., xB = 0 ., vF = 0 ., vB = 0 .;
349434 for (int c = 0 ; c < nConfigs; ++c) {
350435 const auto & cfg = Configs[c];
@@ -370,8 +455,18 @@ struct EventShapeCoex {
370455 sums.config [c]->Fill (nFwd, nCond, k, m[k]);
371456 }
372457 sums.occupancy ->Fill (c, nFwd, nCond);
458+ if (c == IPairFirst) {
459+ mPairFirst = m;
460+ pairFirstValid = true ;
461+ } else if (c == IPairSecond && pairFirstValid) {
462+ for (int k = 0 ; k < NMono1; ++k) {
463+ for (int l = 0 ; l < NMono1; ++l) {
464+ sums.paired ->Fill (nFwd, nCond, k * NMono1 + l, mPairFirst [k] * m[l]);
465+ }
466+ }
467+ }
373468 if (c == INominal) {
374- nominal = {.valid = true , .nMid = nCond, .xF = xF, .xB = xB, .vF = vF, .vB = vB};
469+ nominal = {.valid = true , .nFwd = nFwd, . nMid = nCond, .xF = xF, .xB = xB, .vF = vF, .vB = vB};
375470 }
376471 }
377472
@@ -392,16 +487,17 @@ struct EventShapeCoex {
392487 return nominal;
393488 }
394489
490+ // / Fills the reconstructed-level sums; returns the nominal observables
395491 template <typename TCollision>
396- void fillReco (TCollision const & coll, MyTracks const & tracks)
492+ Nominal fillReco (TCollision const & coll, MyTracks const & tracks)
397493 {
398494 registry.fill (HIST (" qa/hEventFlow" ), kFlowAll );
399495 if (!coll.sel8 ()) {
400- return ;
496+ return {} ;
401497 }
402498 registry.fill (HIST (" qa/hEventFlow" ), kFlowSel8 );
403499 if (std::abs (coll.posZ ()) > vtxZCut) {
404- return ;
500+ return {} ;
405501 }
406502 registry.fill (HIST (" qa/hEventFlow" ), kFlowVtxZ );
407503
@@ -424,13 +520,13 @@ struct EventShapeCoex {
424520 registry.fill (HIST (" qa/hTrackPhi" ), track.phi ());
425521 }
426522
427- const auto & bc = coll.template bc_as <aod::BCs >();
523+ const auto & bc = coll.template bc_as <aod::BCsWithTimestamps >();
428524 const double nFwd = coll.multFT0A () + coll.multFT0C ();
429525 registry.fill (HIST (" qa/hNFwd" ), nFwd);
430526 const int half = static_cast <int >(blockHash (bc.runNumber (), bc.globalBC (), HalfBlockShift) & 1u );
431527 const Nominal nominal = fillSums (sumsReco[half], rings, nFwd, qaBits, NConfigs);
432528 if (!nominal.valid ) {
433- return ;
529+ return nominal ;
434530 }
435531 registry.fill (HIST (" qa/hEventFlow" ), kFlowNominalValid );
436532 registry.fill (HIST (" qa/hEventFlow" ), kFlowHalfA + half);
@@ -440,29 +536,46 @@ struct EventShapeCoex {
440536 std::array<double , NMono> m{};
441537 monomials (nominal.xF , nominal.xB , nominal.vF , nominal.vB , NMono1, m);
442538 for (int k = 0 ; k < NMono1; ++k) {
443- designEffect [half]->Fill (nFwd, group, k, m[k]);
539+ groupSums [half]->Fill (nFwd, nominal. nMid , group * NMono1 + k, m[k]);
444540 }
445541
446542 const std::array<double , 5 > quantities = {1 ., nominal.xF + MeanPtShift, nominal.xB + MeanPtShift, nominal.vF , nominal.vB };
447543 for (int q = 0 ; q < static_cast <int >(quantities.size ()); ++q) {
448544 registry.fill (HIST (" qa/hMarginalSums" ), nFwd, nominal.nMid , q, quantities[q]);
449545 registry.fill (HIST (" qa/hRunSums" ), bc.runNumber (), q, quantities[q]);
450546 }
547+ const double rate = irSource.value .empty () ? -1 . : rateFetcher.fetch (ccdb.service , bc.timestamp (), bc.runNumber (), irSource.value ) * 1 .e -3 ;
548+ const std::array<double , NCovariateQuantities> covariateQuantities = {1 ., quantities[1 ], quantities[2 ], quantities[1 ] * quantities[1 ], quantities[2 ] * quantities[2 ], nominal.vF , nominal.vB };
549+ for (int q = 0 ; q < NCovariateQuantities; ++q) {
550+ registry.fill (HIST (" qa/hOccupancySums" ), coll.trackOccupancyInTimeRange (), q, covariateQuantities[q]);
551+ registry.fill (HIST (" qa/hVtxZSums" ), coll.posZ (), q, covariateQuantities[q]);
552+ registry.fill (HIST (" qa/hRateSums" ), rate, q, covariateQuantities[q]);
553+ }
554+ return nominal;
451555 }
452556
453- void processReco (MyCollisions::iterator const & coll, MyTracks const & tracks, aod::BCs const &)
557+ void processReco (MyCollisions::iterator const & coll, MyTracks const & tracks, aod::BCsWithTimestamps const &)
454558 {
455559 fillReco (coll, tracks);
456560 }
457561 PROCESS_SWITCH (EventShapeCoex, processReco, " Reconstructed-level moment sums" , true );
458562
459- void processRecoMC (MyCollisionsMc::iterator const & coll, MyTracks const & tracks, aod::BCs const &)
563+ void processRecoMC (MyCollisionsMc::iterator const & coll, MyTracks const & tracks, aod::McCollisions const &, aod::BCsWithTimestamps const &)
460564 {
461- fillReco (coll, tracks);
565+ const Nominal nominal = fillReco (coll, tracks);
566+ if (!nominal.valid || !doSplitSums) {
567+ return ;
568+ }
569+ if (!coll.has_mcCollision ()) {
570+ registry.fill (HIST (" qa/hEventFlow" ), kFlowNoMcLabel );
571+ return ;
572+ }
573+ const auto & bc = coll.mcCollision ().bc_as <aod::BCsWithTimestamps>();
574+ fillSplit (splitReco, nominal, bc.runNumber (), bc.globalBC ());
462575 }
463576 PROCESS_SWITCH (EventShapeCoex, processRecoMC, " Reconstructed-level moment sums on MC (MC-labelled collisions)" , false );
464577
465- void processMC (aod::McCollision const &, aod::McParticles const & particles)
578+ void processMC (aod::McCollision const & mcCollision , aod::McParticles const & particles, aod::BCs const & )
466579 {
467580 static constexpr double ChargeTolerance = 1 .e -3 ;
468581
@@ -490,7 +603,11 @@ struct EventShapeCoex {
490603 }
491604 rings.add (eta, particle.pt ());
492605 }
493- fillSums (sumsGen, rings, nFwdA + nFwdC, AllQaBits, 1 );
606+ const Nominal nominal = fillSums (sumsGen, rings, nFwdA + nFwdC, AllQaBits, 1 );
607+ if (nominal.valid && doSplitSums) {
608+ const auto & bc = mcCollision.bc_as <aod::BCs>();
609+ fillSplit (splitGen, nominal, bc.runNumber (), bc.globalBC ());
610+ }
494611 }
495612 PROCESS_SWITCH (EventShapeCoex, processMC, " Generator-level moment sums (nominal configuration)" , false );
496613};
0 commit comments