Skip to content

Commit fd87552

Browse files
NucleiTask - Change reco condition on MC
1 parent eb1a220 commit fd87552

1 file changed

Lines changed: 132 additions & 22 deletions

File tree

PWGLF/Tasks/Nuspex/lfNucleiBATask.cxx

Lines changed: 132 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ struct lfNucleiBATask {
7777

7878
// Efficiency configurator
7979
std::unordered_set<int> effEvtSet;
80-
bool effEvtSetReady = false;
81-
Configurable<bool> enableEffEvtSet{"enableEffEvtSet", true, "If true, MCGen uses the event-set built by MCReco; if false, MCGen runs stand-alone."};
80+
// bool effEvtSetReady = false;
81+
Configurable<bool> requireRecoEventForGen{"requireRecoEventForGen", true, "Require at least one reco collision passing the event selection in processMCGen"};
8282

8383
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
8484
HistogramRegistry spectraGen{"spectraGen", {}, OutputObjHandlingPolicy::AnalysisObject, false, true};
@@ -112,6 +112,7 @@ struct lfNucleiBATask {
112112
Configurable<bool> useINELgt0cut{"useINELgt0cut", false, "Apply INEL>0 Event Selection in processData o processMC"};
113113
Configurable<bool> useINELgt1cut{"useINELgt1cut", false, "Apply INEL>1 Event Selection in processData o processMC"};
114114
Configurable<bool> enableGenVzCut{"enableGenVzCut", true, "Apply cut in z-Vertex in the processGen function"};
115+
Configurable<bool> askGenFT0Coincidence{"askGenFT0Coincidence", false, "Require a generated charged-particle coincidence in FT0A and FT0C"};
115116
} evselOptions;
116117

117118
// Set the multiplity event limits
@@ -167,9 +168,9 @@ struct lfNucleiBATask {
167168
// Set the axis used in this task
168169
ConfigurableAxis binsPercentile{"binsPercentile", {100, 0, 100}, "Centrality FT0M"};
169170
ConfigurableAxis binsPt{"binsPt", {VARIABLE_WIDTH, 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.425, 0.45, 0.475, 0.5, 0.5125, 0.525, 0.5375, 0.55, 0.5625, 0.575, 0.5875, 0.6, 0.6125, 0.625, 0.6375, 0.65, 0.6625, 0.675, 0.6875, 0.7, 0.7125, 0.725, 0.7375, 0.75, 0.7625, 0.775, 0.7875, 0.8, 0.8125, 0.825, 0.8375, 0.85, 0.8625, 0.875, 0.8875, 0.9, 0.9125, 0.925, 0.9375, 0.95, 0.9625, 0.975, 0.9875, 1.0, 1.0125, 1.025, 1.0375, 1.05, 1.0625, 1.075, 1.0875, 1.1, 1.1125, 1.125, 1.1375, 1.15, 1.1625, 1.175, 1.1875, 1.2, 1.2125, 1.225, 1.2375, 1.25, 1.2625, 1.275, 1.2875, 1.3, 1.3125, 1.325, 1.3375, 1.35, 1.3625, 1.375, 1.3875, 1.4, 1.4125, 1.425, 1.4375, 1.45, 1.4625, 1.475, 1.4875, 1.5, 1.5125, 1.525, 1.5375, 1.55, 1.5625, 1.575, 1.5875, 1.6, 1.6125, 1.625, 1.6375, 1.65, 1.6625, 1.675, 1.6875, 1.7, 1.7125, 1.725, 1.7375, 1.75, 1.7625, 1.775, 1.7875, 1.8, 1.8125, 1.825, 1.8375, 1.85, 1.8625, 1.875, 1.8875, 1.9, 1.9125, 1.925, 1.9375, 1.95, 1.9625, 1.975, 1.9875, 2.0, 2.0625, 2.125, 2.1875, 2.25, 2.3125, 2.375, 2.4375, 2.5, 2.625, 2.75, 2.875, 3.0, 3.25, 3.5, 3.75, 4.0, 4.5, 5.0, 6.0, 7.0, 8.0}, ""};
170-
ConfigurableAxis binsPtHe{"binsPtHe", {VARIABLE_WIDTH, 1.0, 1.25, 1.50, 1.75, 2.0, 2.25, 2.50, 2.75, 3.0, 3.25, 3.50, 3.75, 4.0, 4.50, 5.0, 6.0, 7.0, 8.0}, ""};
171-
ConfigurableAxis binsPtZHe{"binsPtZHe", {VARIABLE_WIDTH, 0.5, 0.625, 0.75, 0.875, 1.0, 1.125, 1.25, 1.375, 1.5, 1.625, 1.75, 1.875, 2.0, 2.25, 2.5, 3.0, 3.5, 4.0}, ""};
172-
ConfigurableAxis binsPtHeMigration{"binsPtHeMigration", {VARIABLE_WIDTH, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 1.00, 1.10, 1.20, 1.30, 1.40, 1.50, 1.60, 1.70, 1.80, 1.90, 2.00, 2.10, 2.20, 2.30, 2.40, 2.50, 2.60, 2.70, 2.80, 2.90, 3.00, 3.25, 3.50, 3.75, 4.00, 4.50, 5.00, 6.00, 7.00, 8.00}, ""};
171+
ConfigurableAxis binsPtHe{"binsPtHe", {VARIABLE_WIDTH, 0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.50, 1.75, 2.0, 2.25, 2.50, 2.75, 3.0, 3.25, 3.50, 3.75, 4.0, 4.50, 5.0, 6.0, 7.0, 8.0}, ""};
172+
ConfigurableAxis binsPtZHe{"binsPtZHe", {VARIABLE_WIDTH, 0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0, 1.125, 1.25, 1.375, 1.5, 1.625, 1.75, 1.875, 2.0, 2.25, 2.5, 3.0, 3.5, 4.0}, ""};
173+
ConfigurableAxis binsPtHeMigration{"binsPtHeMigration", {VARIABLE_WIDTH, 0.0, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 1.00, 1.10, 1.20, 1.30, 1.40, 1.50, 1.60, 1.70, 1.80, 1.90, 2.00, 2.10, 2.20, 2.30, 2.40, 2.50, 2.60, 2.70, 2.80, 2.90, 3.00, 3.25, 3.50, 3.75, 4.00, 4.50, 5.00, 6.00, 7.00, 8.00}, ""};
173174

174175
ConfigurableAxis binsdEdx{"binsdEdx", {600, 0.f, 3000.f}, ""};
175176
ConfigurableAxis binsBeta{"binsBeta", {120, 0.0, 1.2}, ""};
@@ -323,6 +324,38 @@ struct lfNucleiBATask {
323324
return 0.5f * std::log((e + pz) / (e - pz));
324325
}
325326

327+
// Added TVX check on MC
328+
bool hasGenTVX(const aod::McParticles& particles, int mcCollisionIndex)
329+
{
330+
bool hasHitFT0A = false;
331+
bool hasHitFT0C = false;
332+
333+
for (const auto& particle : particles) {
334+
if (particle.mcCollisionId() != mcCollisionIndex)
335+
continue;
336+
337+
if (!particle.isPhysicalPrimary())
338+
continue;
339+
340+
auto* pdgInfo = pdgDB->GetParticle(particle.pdgCode());
341+
if (!pdgInfo || pdgInfo->Charge() == 0.)
342+
continue;
343+
344+
const float eta = particle.eta();
345+
346+
if (eta > 3.5f && eta < 4.9f)
347+
hasHitFT0A = true;
348+
349+
if (eta > -3.3f && eta < -2.1f)
350+
hasHitFT0C = true;
351+
352+
if (hasHitFT0A && hasHitFT0C)
353+
return true;
354+
}
355+
356+
return false;
357+
}
358+
326359
void init(o2::framework::InitContext& context)
327360
{
328361
if (initITSPID) {
@@ -333,7 +366,7 @@ struct lfNucleiBATask {
333366
}
334367

335368
effEvtSet.clear();
336-
effEvtSetReady = false;
369+
// effEvtSetReady = false;
337370

338371
const AxisSpec pAxis{binsPt, "#it{p} (GeV/#it{c})"};
339372
const AxisSpec ptAxis{binsPt, "#it{p}_{T} (GeV/#it{c})"};
@@ -2279,6 +2312,21 @@ struct lfNucleiBATask {
22792312
}
22802313
LOG(info) << " MC mode ";
22812314
// MC histograms - all, primary, sec. from weak decay, sec. from material
2315+
2316+
if (enableDebug) {
2317+
spectraGen.add("hEffEvtSetVsSG", "effEvtSet vs SmallGroups;in effEvtSet;has accepted reco collision", HistType::kTH2D, {{2, -0.5, 1.5}, {2, -0.5, 1.5}});
2318+
auto hEffCheck = spectraGen.get<TH2>(HIST("hEffEvtSetVsSG"));
2319+
hEffCheck->GetXaxis()->SetBinLabel(1, "Not in effEvtSet");
2320+
hEffCheck->GetXaxis()->SetBinLabel(2, "In effEvtSet");
2321+
hEffCheck->GetYaxis()->SetBinLabel(1, "No accepted reco");
2322+
hEffCheck->GetYaxis()->SetBinLabel(2, "Accepted reco");
2323+
2324+
spectraGen.add("hEffEvtSetFalsePositive", "False positives in effEvtSet", HistType::kTH1D, {{2, 0., 2.}});
2325+
auto hFalsePos = spectraGen.get<TH1>(HIST("hEffEvtSetFalsePositive"));
2326+
hFalsePos->GetXaxis()->SetBinLabel(1, "No associated reco");
2327+
hFalsePos->GetXaxis()->SetBinLabel(2, "Reco exists, fails cuts");
2328+
}
2329+
22822330
if (enableCentrality)
22832331
spectraGen.add("histGenVetxZ", "PosZ generated events", HistType::kTH2F, {{1500, -15.f, 15.f, "Vertex Z (cm)"}, {binsPercentile, "Centrality FT0M"}});
22842332
else
@@ -2415,7 +2463,6 @@ struct lfNucleiBATask {
24152463
}
24162464

24172465
LOG(info) << "MC Histograms defined";
2418-
// LOG(info) << "Histograms of lfNucleiBATask:";
24192466
LOG(info) << "Histograms of lfNucleiBATask:";
24202467
histos.print();
24212468
spectraGen.print();
@@ -6382,12 +6429,13 @@ struct lfNucleiBATask {
63826429
}
63836430

63846431
float mcCentFT0M = -1.f;
6432+
const bool passesRecoVertex = event.posZ() >= cfgVzCutLow && event.posZ() <= cfgVzCutHigh;
63856433

6386-
if (doRecoSep && event.has_mcCollision()) {
6434+
if (doRecoSep && passesRecoVertex && event.has_mcCollision()) {
63876435
const int mcIdx = event.mcCollisionId();
63886436
if (mcIdx >= 0) {
63896437
effEvtSet.insert(mcIdx);
6390-
effEvtSetReady = true;
6438+
// effEvtSetReady = true;
63916439

63926440
auto mcColIter = mcCollisions.iteratorAt(mcIdx);
63936441
mcCentFT0M = mcColIter.centFT0M();
@@ -6423,12 +6471,13 @@ struct lfNucleiBATask {
64236471
}
64246472

64256473
float mcCentFT0M = -1.f;
6474+
const bool passesRecoVertex = event.posZ() >= cfgVzCutLow && event.posZ() <= cfgVzCutHigh;
64266475

6427-
if (doRecoSep && event.has_mcCollision()) {
6476+
if (doRecoSep && passesRecoVertex && event.has_mcCollision()) {
64286477
const int mcIdx = event.mcCollisionId();
64296478
if (mcIdx >= 0) {
64306479
effEvtSet.insert(mcIdx);
6431-
effEvtSetReady = true;
6480+
// effEvtSetReady = true;
64326481

64336482
auto mcColIter = mcCollisions.iteratorAt(mcIdx);
64346483
mcCentFT0M = mcColIter.centFT0M();
@@ -6582,21 +6631,53 @@ struct lfNucleiBATask {
65826631
////////////
65836632

65846633
// LOOP OVER GENERATED MC PARTICLES
6585-
void processMCGen(soa::Join<aod::McCollisions, aod::McCentFT0Ms>::iterator const& mcCollision,
6586-
aod::McParticles const& mcParticles)
6634+
// void processMCGen(soa::Join<aod::McCollisions, aod::McCentFT0Ms>::iterator const& mcCollision,
6635+
// aod::McParticles const& mcParticles)
6636+
void processMCGen(
6637+
soa::Join<aod::McCollisions, aod::McCentFT0Ms>::iterator const& mcCollision,
6638+
const soa::SmallGroups<soa::Join<EventCandidatesMC, o2::aod::PVMults>>& collisions,
6639+
aod::McParticles const& mcParticles)
65876640
{
6588-
// Only events that are reconstructed
65896641
const int mcIdx = mcCollision.globalIndex();
6590-
if (enableEffEvtSet) {
6591-
if (!effEvtSetReady)
6642+
6643+
// Add GenTVX condition
6644+
if (evselOptions.askGenFT0Coincidence) {
6645+
if (!hasGenTVX(mcParticles, mcIdx))
65926646
return;
6593-
if (!effEvtSet.contains(mcIdx))
6647+
}
6648+
6649+
// Require Reco conditions (as in signal loss)
6650+
if (requireRecoEventForGen) {
6651+
bool hasAcceptedRecoCollision = false;
6652+
for (const auto& collision : collisions) {
6653+
const bool hasTVX = collision.selection_bit(aod::evsel::kIsTriggerTVX);
6654+
const bool hasNoTFB = collision.selection_bit(aod::evsel::kNoTimeFrameBorder);
6655+
const bool hasNoItsRofFB = collision.selection_bit(aod::evsel::kNoITSROFrameBorder);
6656+
if (evselOptions.useSel8 && !collision.sel8())
6657+
continue;
6658+
if (evselOptions.useTVXtrigger && !hasTVX)
6659+
continue;
6660+
if (evselOptions.removeTFBorder && !hasNoTFB)
6661+
continue;
6662+
if (evselOptions.removeITSROFBorder && !hasNoItsRofFB)
6663+
continue;
6664+
if (collision.posZ() < cfgVzCutLow || collision.posZ() > cfgVzCutHigh)
6665+
continue;
6666+
if (evselOptions.useINELgt0cut && !collision.isInelGt0())
6667+
continue;
6668+
if (evselOptions.useINELgt1cut && !collision.isInelGt1())
6669+
continue;
6670+
hasAcceptedRecoCollision = true;
6671+
break;
6672+
}
6673+
if (!hasAcceptedRecoCollision)
65946674
return;
65956675
}
65966676

65976677
if (enableCentrality && (mcCollision.centFT0M() < cfgMultCutLow || mcCollision.centFT0M() > cfgMultCutHigh))
65986678
return;
65996679

6680+
// Vz cut at Gen level
66006681
if (evselOptions.enableGenVzCut) {
66016682
if (mcCollision.posZ() < cfgVzCutLow || mcCollision.posZ() > cfgVzCutHigh)
66026683
return;
@@ -6607,9 +6688,6 @@ struct lfNucleiBATask {
66076688
else
66086689
spectraGen.fill(HIST("histGenVetxZ"), mcCollision.posZ());
66096690

6610-
// const auto& particlesInCollision = mcParticles.sliceByCached(aod::mcparticle::mcCollisionId, mcIdx, cache);
6611-
// const auto particlesInCollision = mcParticles.sliceBy(perMCCol, mcIdx);
6612-
66136691
for (const auto& mcParticleGen : mcParticles) {
66146692
if (mcParticleGen.mcCollisionId() != mcIdx)
66156693
continue;
@@ -6958,17 +7036,25 @@ struct lfNucleiBATask {
69587036
const soa::SmallGroups<soa::Join<EventCandidatesMC, o2::aod::PVMults>>& collisions,
69597037
aod::McParticles const& mcParticles)
69607038
{
7039+
const int mcIdx = mcCollision.globalIndex();
7040+
const bool genFT0Coincidence = hasGenTVX(mcParticles, mcIdx);
69617041
bool isINELgt0true = pwglf::isINELgtNmc(mcParticles, 0, pdgDB);
69627042

7043+
// GenFT0 coincidence
7044+
if (evselOptions.askGenFT0Coincidence && !genFT0Coincidence)
7045+
return;
7046+
69637047
// EVENT LOSS DENOMINATOR
69647048
// No cuts
69657049
histoGen.fill(HIST("events/hMCGen"), 0.5);
69667050
if (enableCentrality)
69677051
histoGen.fill(HIST("events/hMCGenVsMult"), 0.5, mcCollision.centFT0M());
69687052

69697053
// Vtz cut
6970-
if (mcCollision.posZ() < cfgVzCutLow || mcCollision.posZ() > cfgVzCutHigh)
6971-
return;
7054+
if (evselOptions.enableGenVzCut) {
7055+
if (mcCollision.posZ() < cfgVzCutLow || mcCollision.posZ() > cfgVzCutHigh)
7056+
return;
7057+
}
69727058

69737059
histoGen.fill(HIST("events/hMCGen"), 1.5);
69747060
if (enableCentrality)
@@ -7159,6 +7245,30 @@ struct lfNucleiBATask {
71597245
histoGen.fill(HIST("events/hNRecoCollPerMCCollVsMult_INEL"), recoIdxINEL, mcCollision.centFT0M());
71607246
histoGen.fill(HIST("events/hNRecoCollPerMCCollVsMult_INELgt0"), recoIdxINELgt0, mcCollision.centFT0M());
71617247
}
7248+
// Add checker for EffEvtSet
7249+
const int mcIdxCheck = mcCollision.globalIndex();
7250+
const bool inEffEvtSet = effEvtSet.contains(mcIdxCheck);
7251+
7252+
if (enableDebug) {
7253+
double effEvtSetValue = 0.0;
7254+
double inelValue = 0.0;
7255+
7256+
if (inEffEvtSet) {
7257+
effEvtSetValue = 1.0;
7258+
}
7259+
if (atLeastOneINEL) {
7260+
inelValue = 1.0;
7261+
}
7262+
7263+
spectraGen.fill(HIST("hEffEvtSetVsSG"), effEvtSetValue, inelValue);
7264+
7265+
if (inEffEvtSet && !atLeastOneINEL) {
7266+
if (collisions.size() == 0)
7267+
spectraGen.fill(HIST("hEffEvtSetFalsePositive"), 0.5);
7268+
else
7269+
spectraGen.fill(HIST("hEffEvtSetFalsePositive"), 1.5);
7270+
}
7271+
}
71627272

71637273
if (!atLeastOneINEL)
71647274
return;

0 commit comments

Comments
 (0)