Skip to content

Commit dc12526

Browse files
authored
[PWGCF] Add custom event selection to energyFlowGfw.cxx (#18371)
1 parent 228c8e6 commit dc12526

2 files changed

Lines changed: 81 additions & 42 deletions

File tree

‎PWGCF/GenericFramework/Tasks/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ o2physics_add_dpl_workflow(flow-gfw-nonflow
3131

3232
o2physics_add_dpl_workflow(energy-flow-gfw
3333
SOURCES energyFlowGfw.cxx
34-
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::GFWCore
34+
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCCDB O2Physics::AnalysisCore O2Physics::GFWCore
3535
COMPONENT_NAME Analysis)

‎PWGCF/GenericFramework/Tasks/energyFlowGfw.cxx‎

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "PWGCF/GenericFramework/Core/GFWConfig.h"
1919
#include "PWGCF/GenericFramework/Core/GFWWeights.h"
2020

21+
#include "Common/CCDB/EventSelectionParams.h"
2122
#include "Common/CCDB/TriggerAliases.h"
2223
#include "Common/DataModel/Centrality.h"
2324
#include "Common/DataModel/EventSelection.h"
@@ -39,7 +40,6 @@
3940
#include <Framework/O2DatabasePDGPlugin.h>
4041
#include <Framework/runDataProcessing.h>
4142

42-
#include <TFile.h>
4343
#include <TH1.h>
4444
#include <THn.h>
4545
#include <TNamed.h>
@@ -136,6 +136,7 @@ struct EnergyFlowGfw {
136136
Configurable<float> cfgMaxCentrality{"cfgMaxCentrality", 100.f, "Maximum accepted centrality percentile"};
137137
Configurable<bool> cfgFillEfficiency{"fillEfficiency", false, "Fill MC tracking efficiency; ignored by data processes"};
138138
Configurable<bool> cfgFillAcceptance{"fillAcceptance", false, "Fill GFW acceptance weights instead of running the reconstructed analysis"};
139+
Configurable<bool> cfgUseRun2EventSelectionWithoutZdc{"cfgUseRun2EventSelectionWithoutZdc", false, "For Run 2 data, require kINT7 and every CCDB-enabled barrel sel7 criterion except the ZDC beam-beam criteria; retain the ZDC beam-gas vetoes"};
139140

140141
Configurable<float> cfgSpectatorEnergyPerNucleon{"cfgSpectatorEnergyPerNucleon", 1.f, "ZDC energy corresponding to one spectator nucleon"};
141142
Configurable<float> cfgMaxTotalSpectators{"cfgMaxTotalSpectators", 500.f, "Maximum accepted spectator count from ZNA+ZNC+ZPA+ZPC"};
@@ -145,8 +146,10 @@ struct EnergyFlowGfw {
145146
Configurable<float> cfgZdcResponseZPC{"cfgZdcResponseZPC", 1.f, "ZPC efficiency/acceptance response factor alpha; corrected energy is E_ZPC/alpha_ZPC"};
146147
Configurable<float> cfgZdcMaxAbsTimeForQa{"cfgZdcMaxAbsTimeForQa", 100.f, "Maximum absolute ZDC time considered available in QA; excludes missing-time sentinels"};
147148

148-
Configurable<std::string> efficiencyPath{"efficiencyPath", "", "CCDB path or local ROOT file containing a 4D efficiency-correction THn"};
149-
Configurable<bool> efficiencyFromLocalFile{"efficiencyFromLocalFile", false, "Load efficiencyPath from a local ROOT file"};
149+
struct : ConfigurableGroup {
150+
Configurable<std::string> cfgEfficiencyPath{"cfgEfficiencyPath", "", "CCDB path to efficiency object"};
151+
Configurable<bool> cfgUsePIDEfficiencies{"cfgUsePIDEfficiencies", false, "Use separate charged, pion, kaon, and proton efficiencies"};
152+
} cfgEfficiency;
150153
Configurable<std::string> acceptancePath{"acceptancePath", "", "CCDB path to GFW acceptance weights"};
151154
Configurable<bool> acceptanceRunByRun{"acceptanceRunByRun", false, "Load acceptance weights from the RunByRun subdirectory"};
152155

@@ -197,8 +200,9 @@ struct EnergyFlowGfw {
197200
std::vector<bool> zeroHarmonicConfigs;
198201
int gfwMask = 0;
199202

200-
std::unique_ptr<THn> localEfficiency;
201-
THn* efficiency = nullptr;
203+
TH1* efficiency = nullptr;
204+
std::vector<TH1*> pidEfficiencies;
205+
bool efficiencyLoaded = false;
202206
GFWWeights* acceptance = nullptr;
203207
int acceptanceRunNumber = -1;
204208

@@ -601,39 +605,70 @@ struct EnergyFlowGfw {
601605
return true;
602606
}
603607

604-
void loadEfficiency(uint64_t timestamp)
608+
static bool isZdcBeamBeamSelectionFlag(int flag)
605609
{
606-
if (efficiencyPath.value.empty()) {
607-
efficiency = nullptr;
608-
return;
610+
return flag == aod::evsel::kIsBBZNA || flag == aod::evsel::kIsBBZNC || flag == aod::evsel::kIsBBZAC;
611+
}
612+
613+
template <typename TBCs, typename TCollision>
614+
bool run2EventSelected(TCollision const& collision)
615+
{
616+
if (!collision.alias_bit(kINT7)) {
617+
return false;
609618
}
610-
if (efficiencyFromLocalFile) {
611-
if (localEfficiency) {
612-
efficiency = localEfficiency.get();
613-
return;
614-
}
615-
std::unique_ptr<TFile> input(TFile::Open(efficiencyPath.value.c_str(), "READ"));
616-
if (!input || input->IsZombie()) {
617-
LOGF(fatal, "Could not open efficiency file %s", efficiencyPath.value.c_str());
618-
return;
619-
}
620-
auto* source = dynamic_cast<THn*>(input->Get("ccdb_object"));
621-
if (!source || source->GetNdimensions() != 4) {
622-
LOGF(fatal, "Efficiency object must be a 4D THn with axes eta, pT, centrality, z-vtx");
619+
if (!cfgUseRun2EventSelectionWithoutZdc) {
620+
return collision.sel7();
621+
}
622+
if (!collision.has_foundBC()) {
623+
return false;
624+
}
625+
626+
const auto& bc = collision.template foundBC_as<TBCs>();
627+
auto* selectionParameters = ccdb->getForTimeStamp<EventSelectionParams>("EventSelection/EventSelectionParams", bc.timestamp());
628+
if (!selectionParameters) {
629+
LOGF(fatal, "Could not load the Run 2 event-selection parameters");
630+
}
631+
const bool* enabledSelections = selectionParameters->getSelection(0);
632+
for (int flag = 0; flag < aod::evsel::kNsel; ++flag) {
633+
if (isZdcBeamBeamSelectionFlag(flag)) {
634+
continue;
623635
}
624-
localEfficiency.reset(dynamic_cast<THn*>(source->Clone("eecEfficiency")));
625-
if (!localEfficiency) {
626-
LOGF(fatal, "Could not clone the efficiency object from %s", efficiencyPath.value.c_str());
636+
if (enabledSelections[flag] && !collision.selection_bit(flag)) {
637+
return false;
627638
}
628-
efficiency = localEfficiency.get();
639+
}
640+
return true;
641+
}
642+
643+
void loadEfficiency(uint64_t timestamp)
644+
{
645+
if (efficiencyLoaded) {
629646
return;
630647
}
631-
if (!efficiency || !ccdb->isCachedObjectValid(efficiencyPath.value, timestamp)) {
632-
efficiency = ccdb->getForTimeStamp<THnT<float>>(efficiencyPath.value, timestamp);
633-
if (!efficiency || efficiency->GetNdimensions() != 4) {
634-
LOGF(fatal, "Could not load a 4D efficiency correction from %s", efficiencyPath.value.c_str());
648+
if (cfgEfficiency.cfgEfficiencyPath.value.empty()) {
649+
efficiencyLoaded = true;
650+
return;
651+
}
652+
653+
if (!cfgEfficiency.cfgUsePIDEfficiencies) {
654+
efficiency = ccdb->getForTimeStamp<TH1D>(cfgEfficiency.cfgEfficiencyPath.value, timestamp);
655+
if (!efficiency) {
656+
LOGF(fatal, "Could not load efficiency histogram from %s", cfgEfficiency.cfgEfficiencyPath.value.c_str());
657+
}
658+
LOGF(info, "Loaded efficiency histogram from %s", cfgEfficiency.cfgEfficiencyPath.value.c_str());
659+
} else {
660+
static constexpr std::array<const char*, EfficiencySpeciesCount> EfficiencySpeciesNames{"ch", "pi", "ka", "pr"};
661+
pidEfficiencies.reserve(EfficiencySpeciesNames.size());
662+
for (const auto& speciesName : EfficiencySpeciesNames) {
663+
const std::string path = cfgEfficiency.cfgEfficiencyPath.value + "/" + speciesName;
664+
pidEfficiencies.push_back(ccdb->getForTimeStamp<TH1D>(path, timestamp));
665+
if (!pidEfficiencies.back()) {
666+
LOGF(fatal, "Could not load PID efficiency histogram from %s", path.c_str());
667+
}
668+
LOGF(info, "Loaded PID efficiency histogram from %s", path.c_str());
635669
}
636670
}
671+
efficiencyLoaded = true;
637672
}
638673

639674
void loadAcceptance(uint64_t timestamp, int runNumber)
@@ -659,17 +694,20 @@ struct EnergyFlowGfw {
659694
acceptanceRunNumber = runNumber;
660695
}
661696

662-
double efficiencyWeight(float eta, float pt, float centrality, float posZ) const
697+
double getEfficiency(float pt, int pid) const
663698
{
664-
if (!efficiency) {
699+
TH1* efficiencyHistogram = efficiency;
700+
if (cfgEfficiency.cfgUsePIDEfficiencies.value) {
701+
if (pidEfficiencies.empty()) {
702+
return 1.;
703+
}
704+
efficiencyHistogram = pidEfficiencies[pid];
705+
} else if (!efficiencyHistogram) {
665706
return 1.;
666707
}
667-
std::array<int, 4> bins{
668-
efficiency->GetAxis(0)->FindBin(eta),
669-
efficiency->GetAxis(1)->FindBin(pt),
670-
efficiency->GetAxis(2)->FindBin(centrality),
671-
efficiency->GetAxis(3)->FindBin(posZ)};
672-
return efficiency->GetBinContent(bins.data());
708+
709+
const double value = efficiencyHistogram->GetBinContent(efficiencyHistogram->FindBin(pt));
710+
return value == 0. ? -1. : 1. / value;
673711
}
674712

675713
template <typename TTrack>
@@ -816,9 +854,10 @@ struct EnergyFlowGfw {
816854

817855
gfw->Clear();
818856
for (const auto& track : tracks) {
819-
const int pid = energy.weightMode.value == PtWeight ? Unidentified : particleId(track);
857+
const bool needsParticleId = energy.weightMode.value != PtWeight || cfgEfficiency.cfgUsePIDEfficiencies;
858+
const int pid = needsParticleId ? particleId(track) : Unidentified;
820859
const double et = transverseEnergy(track, pid);
821-
const double weff = efficiencyWeight(track.eta(), track.pt(), centrality, collision.posZ());
860+
const double weff = getEfficiency(track.pt(), pid);
822861
const double wacc = acceptance ? acceptance->getNUA(track.phi(), track.eta(), collision.posZ()) : 1.;
823862
if (!std::isfinite(et) || !std::isfinite(weff) || !std::isfinite(wacc) || et <= 0. || weff <= 0. || wacc <= 0.) {
824863
continue;
@@ -868,7 +907,7 @@ struct EnergyFlowGfw {
868907
void processRun2(CollisionsRun2::iterator const& collision, Tracks const& tracks, BCsRun2 const&, aod::Zdcs const&)
869908
{
870909
float spectators = -1.f;
871-
if (!eventSelected<BCsRun2>(collision, collision.alias_bit(kINT7) && collision.sel7(), static_cast<float>(tracks.size()), collision.centRun2V0M(), spectators)) {
910+
if (!eventSelected<BCsRun2>(collision, run2EventSelected<BCsRun2>(collision), static_cast<float>(tracks.size()), collision.centRun2V0M(), spectators)) {
872911
return;
873912
}
874913
if (cfgFillAcceptance) {

0 commit comments

Comments
 (0)