Skip to content

Commit 27b9cf7

Browse files
nstrangmNicolas Strangmann
andauthored
[PWGEM/PhotonMeson] Add MC functionality to BC wise pi0 task (#11012)
Co-authored-by: Nicolas Strangmann <nicolas.strangmann@.cern.ch>
1 parent 22f76f4 commit 27b9cf7

File tree

3 files changed

+189
-80
lines changed

3 files changed

+189
-80
lines changed

PWGEM/PhotonMeson/DataModel/bcWiseTables.h

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ enum Observables {
3737
kFT0MCent,
3838
kZVtx,
3939
kFT0Amp,
40-
kCellAmpSum,
4140
kpT,
4241
nObservables
4342
};
@@ -53,25 +52,24 @@ const float downscalingFactors[nObservables]{
5352
1E2, // Cluster time
5453
2E0, // FT0M centrality
5554
1E3, // Z-vertex position
56-
1E0, // FT0M amplitude
57-
1E0, // Cell energy
55+
1E-1, // FT0M amplitude
5856
1E3}; // MC pi0 pt
5957
} // namespace emdownscaling
6058

6159
namespace bcwisebc
6260
{
63-
DECLARE_SOA_COLUMN(HasFT0, hasFT0, bool); //! has_foundFT0()
64-
DECLARE_SOA_COLUMN(HasTVX, hasTVX, bool); //! has the TVX trigger flag
65-
DECLARE_SOA_COLUMN(HaskTVXinEMC, haskTVXinEMC, bool); //! kTVXinEMC
66-
DECLARE_SOA_COLUMN(HasEMCCell, hasEMCCell, bool); //! at least one EMCal cell in the BC
67-
DECLARE_SOA_COLUMN(HasNoTFROFBorder, hasNoTFROFBorder, bool); //! not in the TF border or ITS ROF border region
68-
DECLARE_SOA_COLUMN(StoredFT0MAmplitude, storedFT0MAmplitude, unsigned int); //! ft0a+c amplitude
69-
DECLARE_SOA_COLUMN(StoredEMCalnCells, storedEMCalnCells, unsigned int); //! number of emcal cells
70-
DECLARE_SOA_COLUMN(StoredEMCalCellEnergy, storedEMCalCellEnergy, float); //! sum of energy in emcal cells
61+
DECLARE_SOA_COLUMN(HasFT0, hasFT0, bool); //! has_foundFT0()
62+
DECLARE_SOA_COLUMN(HasTVX, hasTVX, bool); //! has the TVX trigger flag
63+
DECLARE_SOA_COLUMN(HaskTVXinEMC, haskTVXinEMC, bool); //! kTVXinEMC
64+
DECLARE_SOA_COLUMN(HasEMCCell, hasEMCCell, bool); //! at least one EMCal cell in the BC
65+
DECLARE_SOA_COLUMN(HasNoTFROFBorder, hasNoTFROFBorder, bool); //! not in the TF border or ITS ROF border region
66+
DECLARE_SOA_COLUMN(StoredFT0MAmplitude, storedFT0MAmplitude, uint16_t); //! ft0a+c amplitude
67+
68+
DECLARE_SOA_DYNAMIC_COLUMN(FT0MAmplitude, ft0Amplitude, [](uint16_t storedFT0MAmplitude) -> float { return storedFT0MAmplitude / emdownscaling::downscalingFactors[emdownscaling::kFT0Amp]; }); //! FT0M amplitude
7169
} // namespace bcwisebc
7270
DECLARE_SOA_TABLE(BCWiseBCs, "AOD", "BCWISEBC", //! table of bc wise centrality estimation and event selection input
7371
o2::soa::Index<>, bcwisebc::HasFT0, bcwisebc::HasTVX, bcwisebc::HaskTVXinEMC, bcwisebc::HasEMCCell, bcwisebc::HasNoTFROFBorder,
74-
bcwisebc::StoredFT0MAmplitude, bcwisebc::StoredEMCalnCells, bcwisebc::StoredEMCalCellEnergy);
72+
bcwisebc::StoredFT0MAmplitude, bcwisebc::FT0MAmplitude<bcwisebc::StoredFT0MAmplitude>);
7573

7674
DECLARE_SOA_INDEX_COLUMN(BCWiseBC, bcWiseBC); //! bunch crossing ID used as index
7775

@@ -117,29 +115,29 @@ DECLARE_SOA_TABLE(BCWiseClusters, "AOD", "BCWISECLUSTER", //! table of skimmed E
117115

118116
namespace bcwisemcpi0s
119117
{
120-
DECLARE_SOA_COLUMN(ParticleIdPi0, particleIdPi0, int); //! ID of the pi0 in the MC stack
121-
DECLARE_SOA_COLUMN(StoredPt, storedPt, uint16_t); //! Transverse momentum of generated pi0 (10 MeV)
122-
DECLARE_SOA_COLUMN(IsAccepted, isAccepted, bool); //! Both decay photons are within the EMCal acceptance
123-
DECLARE_SOA_COLUMN(IsPrimary, isPrimary, bool); //! mcParticle.isPhysicalPrimary() || mcParticle.producedByGenerator()
124-
DECLARE_SOA_COLUMN(IsFromWD, isFromWD, bool); //! Pi0 from a weak decay according to pwgem::photonmeson::utils::mcutil::IsFromWD
118+
DECLARE_SOA_COLUMN(StoredPt, storedPt, uint16_t); //! Transverse momentum of generated pi0 (1 MeV -> Maximum pi0 pT of ~65 GeV)
119+
DECLARE_SOA_COLUMN(IsAccepted, isAccepted, bool); //! Both decay photons are within the EMCal acceptance
120+
DECLARE_SOA_COLUMN(IsPrimary, isPrimary, bool); //! mcParticle.isPhysicalPrimary() || mcParticle.producedByGenerator()
121+
DECLARE_SOA_COLUMN(IsFromWD, isFromWD, bool); //! Pi0 from a weak decay according to pwgem::photonmeson::utils::mcutil::IsFromWD
125122

126123
DECLARE_SOA_DYNAMIC_COLUMN(Pt, pt, [](uint16_t storedpt) -> float { return storedpt / emdownscaling::downscalingFactors[emdownscaling::kpT]; }); //! pT of pi0 (GeV)
127124
} // namespace bcwisemcpi0s
128125

129126
DECLARE_SOA_TABLE(BCWiseMCPi0s, "AOD", "BCWISEMCPI0", //! table of pi0s on MC level
130-
o2::soa::Index<>, BCWiseBCId, bcwisemcpi0s::ParticleIdPi0, bcwisemcpi0s::StoredPt, bcwisemcpi0s::IsAccepted, bcwisemcpi0s::IsPrimary, bcwisemcpi0s::IsFromWD,
127+
o2::soa::Index<>, BCWiseBCId, bcwisemcpi0s::StoredPt, bcwisemcpi0s::IsAccepted, bcwisemcpi0s::IsPrimary, bcwisemcpi0s::IsFromWD,
131128
bcwisemcpi0s::Pt<bcwisemcpi0s::StoredPt>);
132129

133130
namespace bcwisemccluster
134131
{
135-
DECLARE_SOA_COLUMN(StoredE, storedE, uint16_t); //! energy of cluster inducing particle (1 MeV precision)
132+
DECLARE_SOA_COLUMN(Pi0ID, pi0ID, int32_t); //! Index of the mother pi0 (-1 if not from pi0)
133+
DECLARE_SOA_COLUMN(StoredTrueE, storedTrueE, uint16_t); //! energy of cluster inducing particle (1 MeV -> Maximum cluster energy of ~65 GeV)
136134

137-
DECLARE_SOA_DYNAMIC_COLUMN(E, e, [](uint16_t storedE) -> float { return storedE / emdownscaling::downscalingFactors[emdownscaling::kEnergy]; }); //! energy of cluster inducing particle (GeV)
135+
DECLARE_SOA_DYNAMIC_COLUMN(TrueE, trueE, [](uint16_t storedTrueE) -> float { return storedTrueE / emdownscaling::downscalingFactors[emdownscaling::kEnergy]; }); //! energy of cluster inducing particle (GeV)
138136
} // namespace bcwisemccluster
139137

140138
DECLARE_SOA_TABLE(BCWiseMCClusters, "AOD", "BCWISEMCCLS", //! table of MC information for clusters -> To be joined with the cluster table
141-
o2::soa::Index<>, BCWiseBCId, bcwisemccluster::StoredE, bcwisemcpi0s::ParticleIdPi0,
142-
bcwisemccluster::E<bcwisemccluster::StoredE>);
139+
o2::soa::Index<>, BCWiseBCId, bcwisemccluster::Pi0ID, bcwisemccluster::StoredTrueE,
140+
bcwisemccluster::TrueE<bcwisemccluster::StoredTrueE>);
143141

144142
} // namespace o2::aod
145143

PWGEM/PhotonMeson/TableProducer/bcWiseClusterSkimmer.cxx

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <limits>
2020
#include <vector>
21+
#include <map>
2122

2223
#include "Framework/runDataProcessing.h"
2324
#include "Framework/AnalysisTask.h"
@@ -63,6 +64,12 @@ struct bcWiseClusterSkimmer {
6364
Configurable<float> cfgMinTime{"cfgMinTime", -25, "Minimum time of selected clusters (ns)"};
6465
Configurable<float> cfgMaxTime{"cfgMaxTime", 25, "Maximum time of selected clusters (ns)"};
6566
Configurable<float> cfgRapidityCut{"cfgRapidityCut", 0.8f, "Maximum absolute rapidity of counted generated particles"};
67+
// Configurable<float> cfgMinPtGenPi0{"cfgMinPtGenPi0", 0., "Minimum pT for stored generated pi0s (reduce disk space of derived data)"};
68+
69+
Configurable<bool> cfgRequirekTVXinEMC{"cfgRequirekTVXinEMC", false, "Only store kTVXinEMC triggered BCs"};
70+
Configurable<bool> cfgRequireGoodRCTQuality{"cfgRequireGoodRCTQuality", false, "Only store BCs with good quality of T0 and EMC in RCT"};
71+
72+
aod::rctsel::RCTFlagsChecker isFT0EMCGoodRCTChecker{aod::rctsel::kFT0Bad, aod::rctsel::kEMCBad};
6673

6774
expressions::Filter energyFilter = aod::emcalcluster::energy > cfgMinClusterEnergy;
6875
expressions::Filter m02Filter = (aod::emcalcluster::nCells == 1 || (aod::emcalcluster::m02 > cfgMinM02 && aod::emcalcluster::m02 < cfgMaxM02));
@@ -71,6 +78,8 @@ struct bcWiseClusterSkimmer {
7178

7279
HistogramRegistry mHistManager{"output", {}, OutputObjHandlingPolicy::AnalysisObject, false, false};
7380

81+
std::map<int32_t, int32_t> fMapPi0Index; // Map to connect the MC index of the pi0 to the one saved in the derived table
82+
7483
void init(framework::InitContext&)
7584
{
7685
const int nEventBins = 6;
@@ -79,15 +88,13 @@ struct bcWiseClusterSkimmer {
7988
for (int iBin = 0; iBin < nEventBins; iBin++)
8089
mHistManager.get<TH1>(HIST("nBCs"))->GetXaxis()->SetBinLabel(iBin + 1, binLabels[iBin]);
8190

82-
mHistManager.add("hAmplitudeVsCentrality", "FT0M AmplitudeVsCentrality;FT0M Centrality;FT0M Amplitude", HistType::kTH2F, {{105, 0, 105}, {400, 0, 200000}});
83-
mHistManager.add("sumAmp", "Sum Amplitude", HistType::kTH1F, {{1000, 0., 10.}});
84-
mHistManager.add("nCells", "Number of EMCal cells", HistType::kTH1F, {{5000, -0.5, 5000.5}});
85-
8691
LOG(info) << "| Timing cut: " << cfgMinTime << " < t < " << cfgMaxTime;
8792
LOG(info) << "| M02 cut: " << cfgMinM02 << " < M02 < " << cfgMaxM02;
8893
LOG(info) << "| E cut: E > " << cfgMinClusterEnergy;
8994

9095
o2::emcal::Geometry::GetInstanceFromRunNumber(300000);
96+
if (cfgRequireGoodRCTQuality)
97+
isFT0EMCGoodRCTChecker.init({aod::rctsel::kFT0Bad, aod::rctsel::kEMCBad});
9198
}
9299

93100
/// \brief Process EMCAL clusters (either ambigous or unique)
@@ -129,28 +136,32 @@ struct bcWiseClusterSkimmer {
129136
{
130137
for (const auto& cluster : clusters) {
131138
float clusterInducerEnergy = 0.;
132-
int pi0MCIndex = -1;
139+
int32_t pi0MCIndex = -1;
133140
if (cluster.amplitudeA().size() > 0) {
134141
int clusterInducerId = cluster.mcParticleIds()[0];
135142
auto clusterInducer = mcParticles.iteratorAt(clusterInducerId);
136143
clusterInducerEnergy = clusterInducer.e();
137144
int daughterId = aod::pwgem::photonmeson::utils::mcutil::FindMotherInChain(clusterInducer, mcParticles, std::vector<int>{111});
138-
if (daughterId > 0) {
145+
if (daughterId > 0)
139146
pi0MCIndex = mcParticles.iteratorAt(daughterId).mothersIds()[0];
140-
}
141147
}
142-
mcclusterTable(bcID, convertForStorage<uint16_t>(clusterInducerEnergy, kEnergy), pi0MCIndex);
148+
if (pi0MCIndex > 0)
149+
pi0MCIndex = fMapPi0Index[pi0MCIndex];
150+
mcclusterTable(bcID, pi0MCIndex, convertForStorage<uint16_t>(clusterInducerEnergy, kEnergy));
143151
}
144152
}
145153

146-
void processEventProperties(const auto& bc, const auto& collisionsInBC, const auto& cellsInBC)
154+
bool isBCSelected(const auto& bc)
147155
{
148-
float sumAmp = 0.;
149-
for (const auto& cell : cellsInBC)
150-
sumAmp += cell.amplitude();
151-
mHistManager.fill(HIST("sumAmp"), sumAmp);
152-
mHistManager.fill(HIST("nCells"), cellsInBC.size());
156+
if (cfgRequirekTVXinEMC && !bc.selection_bit(aod::evsel::kIsTriggerTVX))
157+
return false;
158+
if (cfgRequireGoodRCTQuality && !isFT0EMCGoodRCTChecker(bc))
159+
return false;
160+
return true;
161+
}
153162

163+
void processEventProperties(const auto& bc, const auto& collisionsInBC, const auto& cellsInBC)
164+
{
154165
bool hasFT0 = bc.has_foundFT0();
155166
bool hasTVX = bc.selection_bit(aod::evsel::kIsTriggerTVX);
156167
bool haskTVXinEMC = bc.alias_bit(kTVXinEMC);
@@ -170,15 +181,11 @@ struct bcWiseClusterSkimmer {
170181

171182
float ft0Amp = hasFT0 ? bc.foundFT0().sumAmpA() + bc.foundFT0().sumAmpC() : 0.;
172183

173-
bcTable(hasFT0, hasTVX, haskTVXinEMC, hasEMCCell, hasNoTFROFBorder, convertForStorage<unsigned int>(ft0Amp, kFT0Amp), convertForStorage<unsigned int>(cellsInBC.size(), kNCells), convertForStorage<float>(sumAmp, kCellAmpSum));
184+
bcTable(hasFT0, hasTVX, haskTVXinEMC, hasEMCCell, hasNoTFROFBorder, convertForStorage<uint16_t>(ft0Amp, kFT0Amp));
174185

175186
for (const auto& collision : collisionsInBC) {
176187
collisionTable(bcTable.lastIndex(), convertForStorage<uint8_t>(collision.centFT0M(), kFT0MCent), convertForStorage<int16_t>(collision.posZ(), kZVtx));
177-
mHistManager.fill(HIST("hAmplitudeVsCentrality"), collision.centFT0M(), ft0Amp);
178188
}
179-
180-
if (collisionsInBC.size() == 0)
181-
mHistManager.fill(HIST("hAmplitudeVsCentrality"), 103, ft0Amp);
182189
}
183190

184191
template <typename TMCParticle, typename TMCParticles>
@@ -218,6 +225,8 @@ struct bcWiseClusterSkimmer {
218225
void processData(MyBCs const& bcs, MyCollisions const& collisions, aod::FT0s const&, SelectedCells const& cells, SelectedUniqueClusters const& uClusters, SelectedAmbiguousClusters const& aClusters)
219226
{
220227
for (const auto& bc : bcs) {
228+
if (!isBCSelected(bc))
229+
continue;
221230
auto collisionsInBC = collisions.sliceBy(perFoundBC, bc.globalIndex());
222231
auto cellsInBC = cells.sliceBy(cellsPerBC, bc.globalIndex());
223232

@@ -240,6 +249,8 @@ struct bcWiseClusterSkimmer {
240249
void processMC(MyBCs const& bcs, MyMCCollisions const& collisions, aod::McCollisions const& mcCollisions, aod::FT0s const&, SelectedCells const& cells, SelectedUniqueMCClusters const& uClusters, SelectedAmbiguousMCClusters const& aClusters, aod::McParticles const& mcParticles)
241250
{
242251
for (const auto& bc : bcs) {
252+
if (!isBCSelected(bc))
253+
continue;
243254
auto collisionsInBC = collisions.sliceBy(perFoundBC, bc.globalIndex());
244255
auto cellsInBC = cells.sliceBy(cellsPerBC, bc.globalIndex());
245256

@@ -249,11 +260,12 @@ struct bcWiseClusterSkimmer {
249260
for (const auto& mcCollision : mcCollisionsBC) {
250261
auto mcParticlesInColl = mcParticles.sliceBy(perMcCollision, mcCollision.globalIndex());
251262
for (const auto& mcParticle : mcParticlesInColl) {
252-
if (mcParticle.pdgCode() != 111 || fabs(mcParticle.y()) > cfgRapidityCut || !isGammaGammaDecay(mcParticle, mcParticles))
263+
if (mcParticle.pdgCode() != 111 || std::abs(mcParticle.y()) > cfgRapidityCut || !isGammaGammaDecay(mcParticle, mcParticles))
253264
continue;
254265
bool isPrimary = mcParticle.isPhysicalPrimary() || mcParticle.producedByGenerator();
255266
bool isFromWD = (aod::pwgem::photonmeson::utils::mcutil::IsFromWD(mcCollision, mcParticle, mcParticles)) > 0;
256-
mcpi0Table(bc.globalIndex(), mcParticle.globalIndex(), convertForStorage<uint16_t>(mcParticle.pt(), kpT), isAccepted(mcParticle, mcParticles), isPrimary, isFromWD);
267+
mcpi0Table(bc.globalIndex(), convertForStorage<uint16_t>(mcParticle.pt(), kpT), isAccepted(mcParticle, mcParticles), isPrimary, isFromWD);
268+
fMapPi0Index[mcParticle.globalIndex()] = static_cast<int32_t>(mcpi0Table.lastIndex());
257269
}
258270
}
259271

@@ -266,6 +278,7 @@ struct bcWiseClusterSkimmer {
266278
processClusters(clustersInBC, bcTable.lastIndex());
267279
processClusterMCInfo(clustersInBC, bc.globalIndex(), mcParticles);
268280
}
281+
fMapPi0Index.clear();
269282
}
270283
}
271284
PROCESS_SWITCH(bcWiseClusterSkimmer, processMC, "Run skimming for MC", false);

0 commit comments

Comments
 (0)