Skip to content

Commit

Permalink
Efficiency and QA task for identified analyses (AliceO2Group#4862)
Browse files Browse the repository at this point in the history
Also reorganized the PID configurable and the PID selector
Also standard use of the self configuration

Co-authored-by: Victor <[email protected]>
  • Loading branch information
victor-gonzalez and Victor authored Feb 24, 2024
1 parent f65ec24 commit de43ce9
Show file tree
Hide file tree
Showing 6 changed files with 794 additions and 251 deletions.
16 changes: 8 additions & 8 deletions PWGCF/Core/AnalysisConfigurableCuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ class TrackSelectionPIDCfg
{
public:
bool mUseIt = false;
float mMinNSigmasTPC[5] = {-3.0, -3.0, -3.0, -3.0, -3.0}; ///< nsigmas TPC lower limit for e, mu, pi, Ka, and p
float mMaxNSigmasTPC[5] = {3.0, 3.0, 3.0, 3.0, 3.0}; ///< nsigmas TPC upper limit for e, mu, pi, Ka, and p
float mPThreshold = 0.0; ///< momentum threshold for considering TOF information
bool mRequireTOF = true; ///< require or not the presence of TOF when the momentum threshold is passed
float mMinNSigmasTOF[5] = {-3.0, -3.0, -3.0, -3.0, -3.0}; ///< nsigmas TOF lower limit for e, mu, pi, Ka, and p
float mMaxNSigmasTOF[5] = {3.0, 3.0, 3.0, 3.0, 3.0}; ///< nsigmas TOF upper limit for e, mu, pi, Ka, and p
bool m2Dcut = true; ///< use an elliptic cut using TPC and TOF nsigmas
bool mExclude = false; ///< should the identified track be excluded for analysis?
std::vector<float> mMinNSigmasTPC = {-3.0f, -3.0f, -3.0f, -3.0f, -3.0f}; ///< nsigmas TPC lower limit for e, mu, pi, Ka, and p
std::vector<float> mMaxNSigmasTPC = {3.0f, 3.0f, 3.0f, 3.0f, 3.0f}; ///< nsigmas TPC upper limit for e, mu, pi, Ka, and p
float mPThreshold = 0.0; ///< momentum threshold for considering TOF information
bool mRequireTOF = true; ///< require or not the presence of TOF when the momentum threshold is passed
std::vector<float> mMinNSigmasTOF = {-3.0f, -3.0f, -3.0f, -3.0f, -3.0f}; ///< nsigmas TOF lower limit for e, mu, pi, Ka, and p
std::vector<float> mMaxNSigmasTOF = {3.0f, 3.0f, 3.0f, 3.0f, 3.0f}; ///< nsigmas TOF upper limit for e, mu, pi, Ka, and p
bool m2Dcut = true; ///< use an elliptic cut using TPC and TOF nsigmas
bool mExclude = false; ///< should the identified track be excluded for analysis?
private:
ClassDefNV(TrackSelectionPIDCfg, 1);
};
Expand Down
222 changes: 21 additions & 201 deletions PWGCF/TableProducer/dptdptfilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Framework/ASoAHelpers.h"
#include "Common/DataModel/EventSelection.h"
#include "Common/DataModel/Centrality.h"
#include "Common/Core/TableHelper.h"
#include "Common/Core/TrackSelection.h"
#include "Common/Core/TrackSelectionDefaults.h"
#include "Common/DataModel/PIDResponse.h"
Expand All @@ -25,6 +26,7 @@
#include "Common/DataModel/TrackSelectionTables.h"
#include "Common/DataModel/CollisionAssociationTables.h"
#include "Framework/runDataProcessing.h"
#include "Framework/RunningWorkflowInfo.h"
#include <TROOT.h>
#include <TDatabasePDG.h>
#include <TParameter.h>
Expand Down Expand Up @@ -162,6 +164,7 @@ struct DptDptFilter {
Configurable<std::string> cfgSystem{"syst", "PbPb", "System: pp, PbPb, Pbp, pPb, XeXe, ppRun3, PbPbRun3. Default PbPb"};
Configurable<std::string> cfgDataType{"datatype", "data", "Data type: data, datanoevsel, MC, FastMC, OnTheFlyMC. Default data"};
Configurable<std::string> cfgTriggSel{"triggsel", "MB", "Trigger selection: MB, None. Default MB"};
Configurable<std::string> cfgCentSpec{"centralities", "00-10,10-20,20-30,30-40,40-50,50-60,60-70,70-80", "Centrality/multiplicity ranges in min-max separated by commas"};
Configurable<o2::analysis::DptDptBinningCuts> cfgBinning{"binning",
{28, -7.0, 7.0, 18, 0.2, 2.0, 16, -0.8, 0.8, 72, 0.5},
"triplets - nbins, min, max - for z_vtx, pT, eta and phi, binning plus bin fraction of phi origin shift"};
Expand Down Expand Up @@ -530,193 +533,13 @@ T computeRMS(std::vector<T>& vec)

struct DptDptFilterTracks {

struct PIDSpeciesSelection {
static const std::vector<int> pdgcodes;
static const std::vector<std::string_view> spnames;
static const std::vector<std::string_view> sptitles;
static const std::vector<std::string_view> spfnames;
static const char hadname[];
static const char hadtitle[];
static const char hadfname[];
uint getNSpecies() { return config.size(); }
const char* getSpeciesName(uint8_t ix) { return spnames[species[ix]].data(); }
const char* getSpeciesTitle(uint8_t ix) { return sptitles[species[ix]].data(); }
const char* getSpeciesFName(uint8_t ix) { return spfnames[species[ix]].data(); }
static const char* getHadName() { return hadname; }
static const char* getHadTitle() { return hadtitle; }
static const char* getHadFName() { return hadfname; }
void Add(uint8_t sp, const o2::analysis::TrackSelectionPIDCfg* incfg)
{
o2::analysis::TrackSelectionPIDCfg* cfg = new o2::analysis::TrackSelectionPIDCfg(*incfg);
config.push_back(cfg);
species.push_back(sp);

auto last = config[config.size() - 1];
uint8_t lastsp = species[config.size() - 1];
LOGF(info, "Inserted species %d with", lastsp);
LOGF(info, " minTPC nsigmas: el: %.2f, mu: %.2f, pi: %.2f, ka: %.2f, pr: %.2f", last->mMinNSigmasTPC[0], last->mMinNSigmasTPC[1], last->mMinNSigmasTPC[2], last->mMinNSigmasTPC[3], last->mMinNSigmasTPC[4]);
LOGF(info, " maxTPC nsigmas: el: %.2f, mu: %.2f, pi: %.2f, ka: %.2f, pr: %.2f", last->mMaxNSigmasTPC[0], last->mMaxNSigmasTPC[1], last->mMaxNSigmasTPC[2], last->mMaxNSigmasTPC[3], last->mMaxNSigmasTPC[4]);
LOGF(info, " minTOF nsigmas: el: %.2f, mu: %.2f, pi: %.2f, ka: %.2f, pr: %.2f", last->mMinNSigmasTOF[0], last->mMinNSigmasTOF[1], last->mMinNSigmasTOF[2], last->mMinNSigmasTOF[3], last->mMinNSigmasTOF[4]);
LOGF(info, " maxTOF nsigmas: el: %.2f, mu: %.2f, pi: %.2f, ka: %.2f, pr: %.2f", last->mMaxNSigmasTOF[0], last->mMaxNSigmasTOF[1], last->mMaxNSigmasTOF[2], last->mMaxNSigmasTOF[3], last->mMaxNSigmasTOF[4]);
}
void AddExclude(uint8_t sp, const o2::analysis::TrackSelectionPIDCfg* incfg)
{
o2::analysis::TrackSelectionPIDCfg* cfg = new o2::analysis::TrackSelectionPIDCfg(*incfg);
configexclude.push_back(cfg);
speciesexclude.push_back(sp);
auto last = configexclude[configexclude.size() - 1];
uint8_t lastsp = speciesexclude[configexclude.size() - 1];

LOGF(info, "Inserted species %d for exclusion with", lastsp);
LOGF(info, " minTPC nsigmas: el: %.2f, mu: %.2f, pi: %.2f, ka: %.2f, pr: %.2f", last->mMinNSigmasTPC[0], last->mMinNSigmasTPC[1], last->mMinNSigmasTPC[2], last->mMinNSigmasTPC[3], last->mMinNSigmasTPC[4]);
LOGF(info, " maxTPC nsigmas: el: %.2f, mu: %.2f, pi: %.2f, ka: %.2f, pr: %.2f", last->mMaxNSigmasTPC[0], last->mMaxNSigmasTPC[1], last->mMaxNSigmasTPC[2], last->mMaxNSigmasTPC[3], last->mMaxNSigmasTPC[4]);
LOGF(info, " minTOF nsigmas: el: %.2f, mu: %.2f, pi: %.2f, ka: %.2f, pr: %.2f", last->mMinNSigmasTOF[0], last->mMinNSigmasTOF[1], last->mMinNSigmasTOF[2], last->mMinNSigmasTOF[3], last->mMinNSigmasTOF[4]);
LOGF(info, " maxTOF nsigmas: el: %.2f, mu: %.2f, pi: %.2f, ka: %.2f, pr: %.2f", last->mMaxNSigmasTOF[0], last->mMaxNSigmasTOF[1], last->mMaxNSigmasTOF[2], last->mMaxNSigmasTOF[3], last->mMaxNSigmasTOF[4]);
}
template <typename TrackObject>
int8_t whichSpecies(TrackObject const& track)
{
std::vector<float> tpcnsigmas = {track.tpcNSigmaEl(), track.tpcNSigmaMu(), track.tpcNSigmaPi(), track.tpcNSigmaKa(), track.tpcNSigmaPr()};
std::vector<float> tofnsigmas = {track.tofNSigmaEl(), track.tofNSigmaMu(), track.tofNSigmaPi(), track.tofNSigmaKa(), track.tofNSigmaPr()};

auto closeTo = [](auto& values, auto& mindet, auto& maxdet, uint8_t sp) {
if (mindet[sp] <= values[sp] && values[sp] < maxdet[sp]) {
return true;
} else {
return false;
}
};
auto awayFrom = [](auto& values, auto& mindet, auto& maxdet, uint8_t sp) {
for (int ix = 0; ix < 5; ix++) {
if (ix != sp) {
if (mindet[ix] <= values[ix] && values[ix] < maxdet[ix]) {
return false;
}
} else {
continue;
}
}
return true;
};
auto closeToTPC = [&](auto& config, uint8_t sp) {
return closeTo(tpcnsigmas, config->mMinNSigmasTPC, config->mMaxNSigmasTPC, sp);
};
auto awayFromTPC = [&](auto& config, uint8_t sp) {
return awayFrom(tpcnsigmas, config->mMinNSigmasTPC, config->mMaxNSigmasTPC, sp);
};
auto closeToTOF = [&](auto& config, uint8_t sp) {
return closeTo(tofnsigmas, config->mMinNSigmasTOF, config->mMaxNSigmasTOF, sp);
};
auto closeToTPCTOF = [&](auto& config, uint8_t sp) {
if (config->m2Dcut) {
float a = (config->mMaxNSigmasTPC[sp] - config->mMinNSigmasTPC[sp]) / 2.0;
float b = (config->mMaxNSigmasTOF[sp] - config->mMinNSigmasTOF[sp]) / 2.0;
float oa = (config->mMaxNSigmasTPC[sp] + config->mMinNSigmasTPC[sp]) / 2.0;
float ob = (config->mMaxNSigmasTOF[sp] + config->mMinNSigmasTOF[sp]) / 2.0;
float vtpc = tpcnsigmas[sp] - oa;
float vtof = tofnsigmas[sp] - ob;
return ((vtpc * vtpc / a / a + vtof * vtof / b / b) < 1);
} else {
return closeToTPC(config, sp) && closeToTOF(config, sp);
}
};
auto awayFromTPCTOF = [&](auto& config, uint8_t sp) {
for (uint8_t ix = 0; ix < 5; ++ix) {
if (ix != sp) {
if (closeToTPCTOF(config, ix)) {
return false;
}
} else {
continue;
}
}
return true;
};
auto aboveThreshold = [&](auto& config) {
return ((config->mPThreshold > 0.0) && (config->mPThreshold < track.p()));
};
auto isA = [&](auto& config, uint8_t sp) {
if (aboveThreshold(config)) {
if (track.hasTOF()) {
return closeToTPCTOF(config, sp) && awayFromTPCTOF(config, sp);
} else {
if (config->mRequireTOF) {
return false;
}
}
}
/* we are here */
/* - below the threshold */
/* - above the threshold without TOF and without requiring it */
/* so we check only the TPC information */
return closeToTPC(config, sp) && awayFromTPC(config, sp);
};

/* let's first check the exclusion from the analysis */
for (uint8_t ix = 0; ix < configexclude.size(); ++ix) {
if (isA(configexclude[ix], speciesexclude[ix])) {
return -ix;
}
}
/* we don't exclude it so check which species if any required */
if (config.size() > 0) {
int8_t id = -127;
for (uint8_t ix = 0; ix < config.size(); ++ix) {
if (isA(config[ix], species[ix])) {
if (id < 0) {
id = ix;
} else {
/* already identified once */
return -127;
}
}
}
return id;
} else {
/* charged hadron */
return 0;
}
}
template <typename ParticleObject>
int8_t whichTruthSpecies(ParticleObject part)
{
int pdgcode = std::abs(part.pdgCode());
/* let's first check the exclusion from the analysis */
for (uint8_t ix = 0; ix < configexclude.size(); ++ix) {
if (pdgcode == pdgcodes[speciesexclude[ix]]) {
return -ix;
}
}
/* we don't exclude it so check which species if any required */
if (config.size() > 0) {
for (uint8_t ix = 0; ix < config.size(); ++ix) {
if (pdgcode == pdgcodes[species[ix]]) {
return ix;
}
}
return -127;
} else {
return 0;
}
}
std::vector<const o2::analysis::TrackSelectionPIDCfg*> config; ///< the PID selection configuration of the species to include in the analysis
std::vector<uint8_t> species; ///< the species index of the species to include in the analysis
std::vector<const o2::analysis::TrackSelectionPIDCfg*> configexclude; ///< the PID selection configuration of the species to exclude from the analysis
std::vector<uint8_t> speciesexclude; ///< the species index of teh species to exclude from the analysis
};

Produces<aod::ScannedTracks> scannedtracks;
Produces<aod::DptDptCFTracksInfo> tracksinfo;
Produces<aod::ScannedTrueTracks> scannedgentracks;
Produces<aod::DptDptCFGenTracksInfo> gentracksinfo;

Configurable<bool> cfgFullDerivedData{"fullderiveddata", false, "Produce the full derived data for external storage. Default false"};
Configurable<int> cfgTrackType{"trktype", 1, "Type of selected tracks: 0 = no selection, 1 = Run2 global tracks FB96, 3 = Run3 tracks, 5 = Run2 TPC only tracks, 7 = Run 3 TPC only tracks. Default 1"};
Configurable<std::string> cfgSystem{"syst", "PbPb", "System: pp, PbPb, Pbp, pPb, XeXe, ppRun3, PbPbRun3. Default PbPb"};
Configurable<std::string> cfgDataType{"datatype", "data", "Data type: data, datanoevsel, MC, FastMC, OnTheFlyMC. Default data"};
Configurable<o2::analysis::DptDptBinningCuts> cfgBinning{"binning",
{28, -7.0, 7.0, 18, 0.2, 2.0, 16, -0.8, 0.8, 72, 0.5},
"triplets - nbins, min, max - for z_vtx, pT, eta and phi, binning plus bin fraction of phi origin shift"};
Configurable<o2::analysis::CheckRangeCfg> cfgTraceDCAOutliers{"trackdcaoutliers", {false, 0.0, 0.0}, "Track the generator level DCAxy outliers: false/true, low dcaxy, up dcaxy. Default {false,0.0,0.0}"};
Configurable<float> cfgTraceOutOfSpeciesParticles{"trackoutparticles", false, "Track the particles which are not e,mu,pi,K,p: false/true. Default false"};
Configurable<int> cfgRecoIdMethod{"recoidmethod", 0, "Method for identifying reconstructed tracks: 0 No PID, 1 PID, 2 mcparticle. Default 0"};
Expand All @@ -738,23 +561,24 @@ struct DptDptFilterTracks {
PIDSpeciesSelection pidselector;
bool checkAmbiguousTracks = false;

void init(InitContext&)
void init(InitContext& initContext)
{
LOGF(info, "DptDptFilterTracks::init()");

fullDerivedData = cfgFullDerivedData;

/* update with the configurable values */
/* the binning */
ptbins = cfgBinning->mPTbins;
ptlow = cfgBinning->mPTmin;
ptup = cfgBinning->mPTmax;
etabins = cfgBinning->mEtabins;
etalow = cfgBinning->mEtamin;
etaup = cfgBinning->mEtamax;
zvtxbins = cfgBinning->mZVtxbins;
zvtxlow = cfgBinning->mZVtxmin;
zvtxup = cfgBinning->mZVtxmax;
/* self configure the binning */
getTaskOptionValue(initContext, "dpt-dpt-filter", "binning.mZVtxbins", zvtxbins);
getTaskOptionValue(initContext, "dpt-dpt-filter", "binning.mZVtxmin", zvtxlow);
getTaskOptionValue(initContext, "dpt-dpt-filter", "binning.mZVtxmax", zvtxup);
getTaskOptionValue(initContext, "dpt-dpt-filter", "binning.mPTbins", ptbins);
getTaskOptionValue(initContext, "dpt-dpt-filter", "binning.mPTmin", ptlow);
getTaskOptionValue(initContext, "dpt-dpt-filter", "binning.mPTmax", ptup);
getTaskOptionValue(initContext, "dpt-dpt-filter", "binning.mEtabins", etabins);
getTaskOptionValue(initContext, "dpt-dpt-filter", "binning.mEtamin", etalow);
getTaskOptionValue(initContext, "dpt-dpt-filter", "binning.mEtamax", etaup);

/* the track types and combinations */
tracktype = cfgTrackType.value;
initializeTrackSelection();
Expand Down Expand Up @@ -791,9 +615,13 @@ struct DptDptFilterTracks {
useOwnTrackSelection = false;
}

/* self configure system type and data type */
/* if the system type is not known at this time, we have to put the initialization somewhere else */
fSystem = getSystemType(cfgSystem);
fDataType = getDataType(cfgDataType);
std::string tmpstr;
getTaskOptionValue(initContext, "dpt-dpt-filter", "syst", tmpstr);
fSystem = getSystemType(tmpstr);
getTaskOptionValue(initContext, "dpt-dpt-filter", "datatype", tmpstr);
fDataType = getDataType(tmpstr);
fPDG = TDatabasePDG::Instance();

/* required ambiguous tracks checks? */
Expand Down Expand Up @@ -1204,14 +1032,6 @@ struct DptDptFilterTracks {
PROCESS_SWITCH(DptDptFilterTracks, filterGenerated, "Generated particles filtering", true)
};

const std::vector<int> DptDptFilterTracks::PIDSpeciesSelection::pdgcodes = {11, 13, 211, 321, 2212};
const std::vector<std::string_view> DptDptFilterTracks::PIDSpeciesSelection::spnames = {"e", "mu", "pi", "ka", "p"};
const std::vector<std::string_view> DptDptFilterTracks::PIDSpeciesSelection::sptitles = {"e", "#mu", "#pi", "K", "p"};
const std::vector<std::string_view> DptDptFilterTracks::PIDSpeciesSelection::spfnames = {"E", "Mu", "Pi", "Ka", "Pr"};
const char DptDptFilterTracks::PIDSpeciesSelection::hadname[] = "h";
const char DptDptFilterTracks::PIDSpeciesSelection::hadtitle[] = "h";
const char DptDptFilterTracks::PIDSpeciesSelection::hadfname[] = "Ha";

template <typename TrackObject>
int8_t DptDptFilterTracks::trackIdentification(TrackObject const& track)
{
Expand Down
Loading

0 comments on commit de43ce9

Please sign in to comment.