Skip to content

Commit

Permalink
Support for track identification tracking (AliceO2Group#5995)
Browse files Browse the repository at this point in the history
Co-authored-by: Victor <[email protected]>
  • Loading branch information
victor-gonzalez and Victor authored May 4, 2024
1 parent 85f2294 commit 93a0a1f
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 24 deletions.
65 changes: 42 additions & 23 deletions PWGCF/TableProducer/dptdptfilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ struct DptDptFilterTracks {
std::string cfgCCDBDate{"20220307"};
std::string cfgCCDBPeriod{"LHC22o"};

Configurable<bool> cfgOutDebugInfo{"outdebuginfo", false, "Out detailed debug information per track into a text file. Default false"};
Configurable<bool> cfgFullDerivedData{"fullderiveddata", false, "Produce the full derived data for external storage. Default false"};
Configurable<int> cfgTrackType{"trktype", 4, "Type of selected tracks: 0 = no selection;1 = Run2 global tracks FB96;3 = Run3 tracks;4 = Run3 tracks MM sel;5 = Run2 TPC only tracks;7 = Run 3 TPC only tracks;30-33 = any/two on 3 ITS,any/all in 7 ITS;40-43 same as 30-33 w tighter DCAxy;50-53 w tighter pT DCAz. Default 4"};
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}"};
Expand Down Expand Up @@ -811,6 +812,12 @@ struct DptDptFilterTracks {
ccdb->setURL(cfgCCDBUrl);
ccdb->setCaching(true);
ccdb->setLocalObjectValidityChecking();
/* the debug info output file if required */
if (cfgOutDebugInfo) {
debugstream.open("tracings.csv");
debugstream << "p,piw,pt,hastof,dEdx,beta,tpcnEl,tpcnMu,tpcnPi,tpcnKa,tpcnPr,tofnEl,tofnMu,tofnPi,tofnKa,tofnPr,tpcnElSft,tpcnMuSft,tpcnPiSft,tpcnKaSft,tpcnPrSft,tofnElSft,tofnMuSft,tofnPiSft,tofnKaSft,tofnPrSft,idcode,pid,pid2,truepid,phprim,process\n";
debugstream.close();
}
}

void getCCDBInformation()
Expand All @@ -828,11 +835,11 @@ struct DptDptFilterTracks {
}
}

template <typename TrackObject>
template <StrongDebugging outdebug, typename TrackObject>
int8_t trackIdentification(TrackObject const& track);
template <typename TrackObject>
template <StrongDebugging outdebug, typename TrackObject>
int8_t selectTrack(TrackObject const& track);
template <typename CollisionObjects, typename TrackObject>
template <StrongDebugging outdebug, typename CollisionObjects, typename TrackObject>
int8_t selectTrackAmbiguousCheck(CollisionObjects const& collisions, TrackObject const& track);
template <typename ParticleObject>
int8_t identifyParticle(ParticleObject const& particle);
Expand Down Expand Up @@ -862,7 +869,7 @@ struct DptDptFilterTracks {

/* TODO: as it is now when the derived data is stored (fullDerivedData = true) */
/* the collision index stored with the track is wrong. This has to be fixed */
template <typename passedtracks>
template <StrongDebugging outdebug, typename passedtracks>
void filterTracks(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo> const& collisions,
passedtracks const& tracks)
{
Expand All @@ -882,7 +889,7 @@ struct DptDptFilterTracks {
for (auto track : tracks) {
int8_t pid = -1;
if (track.has_collision() && (track.template collision_as<soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo>>()).collisionaccepted()) {
pid = selectTrackAmbiguousCheck(collisions, track);
pid = selectTrackAmbiguousCheck<outdebug>(collisions, track);
if (!(pid < 0)) {
naccepted++;
if (fullDerivedData) {
Expand Down Expand Up @@ -961,75 +968,87 @@ struct DptDptFilterTracks {
particles.size());
}

template <typename passedtracks>
void doFilterTracks(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo> const& collisions, passedtracks const& tracks)
{
if (cfgOutDebugInfo) {
debugstream.open("tracings.csv", std::ios::app);
filterTracks<kDEBUG>(collisions, tracks);
debugstream.close();
} else {
filterTracks<kNODEBUG>(collisions, tracks);
}
}

void filterRecoWithPID(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo>& collisions, DptDptFullTracksPID const& tracks)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterRecoWithPID, "Not stored derived data track filtering", false)

void filterRecoWithFullPID(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo>& collisions, DptDptFullTracksFullPID const& tracks)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterRecoWithFullPID, "Not stored derived data track filtering", false)

void filterRecoWithPIDAmbiguous(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo>& collisions, DptDptFullTracksPIDAmbiguous const& tracks)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterRecoWithPIDAmbiguous, "Not stored derived data track filtering with ambiguous tracks check", false)

void filterRecoWithFullPIDAmbiguous(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo>& collisions, DptDptFullTracksFullPIDAmbiguous const& tracks)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterRecoWithFullPIDAmbiguous, "Not stored derived data track filtering with ambiguous tracks check", false)

void filterDetectorLevelWithPID(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo>& collisions, DptDptFullTracksPIDDetLevel const& tracks, aod::McParticles const&)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterDetectorLevelWithPID, "Not stored derived data detector level track filtering", false)

void filterDetectorLevelWithFullPID(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo>& collisions, DptDptFullTracksFullPIDDetLevel const& tracks, aod::McParticles const&)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterDetectorLevelWithFullPID, "Not stored derived data detector level track filtering", false)

void filterDetectorLevelWithPIDAmbiguous(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo>& collisions, DptDptFullTracksPIDDetLevelAmbiguous const& tracks, aod::McParticles const&)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterDetectorLevelWithPIDAmbiguous, "Not stored derived data detector level track filtering with ambiguous tracks check", false)

void filterDetectorLevelWithFullPIDAmbiguous(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo>& collisions, DptDptFullTracksFullPIDDetLevelAmbiguous const& tracks, aod::McParticles const&)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterDetectorLevelWithFullPIDAmbiguous, "Not stored derived data detector level track filtering with ambiguous tracks check", false)

void filterRecoWithoutPID(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo> const& collisions, DptDptFullTracks const& tracks)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterRecoWithoutPID, "Track filtering without PID information", true)

void filterRecoWithoutPIDAmbiguous(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo> const& collisions, DptDptFullTracksAmbiguous const& tracks)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterRecoWithoutPIDAmbiguous, "Track filtering without PID information with ambiguous tracks check", false)

void filterDetectorLevelWithoutPID(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo> const& collisions, DptDptFullTracksDetLevel const& tracks, aod::McParticles const&)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterDetectorLevelWithoutPID, "Detector level track filtering without PID information", false)

void filterDetectorLevelWithoutPIDAmbiguous(soa::Join<aod::Collisions, aod::DptDptCFCollisionsInfo> const& collisions, DptDptFullTracksDetLevelAmbiguous const& tracks, aod::McParticles const&)
{
filterTracks(collisions, tracks);
doFilterTracks(collisions, tracks);
}
PROCESS_SWITCH(DptDptFilterTracks, filterDetectorLevelWithoutPIDAmbiguous, "Detector level track filtering without PID information with ambiguous tracks check", false)

Expand All @@ -1040,7 +1059,7 @@ struct DptDptFilterTracks {
PROCESS_SWITCH(DptDptFilterTracks, filterGenerated, "Generated particles filtering", true)
};

template <typename TrackObject>
template <StrongDebugging outdebug, typename TrackObject>
int8_t DptDptFilterTracks::trackIdentification(TrackObject const& track)
{
using namespace dptdptfilter;
Expand All @@ -1050,7 +1069,7 @@ int8_t DptDptFilterTracks::trackIdentification(TrackObject const& track)
sp = 0;
} else if (recoIdMethod == 1) {
if constexpr (framework::has_type_v<aod::pidtpc_tiny::TPCNSigmaStorePi, typename TrackObject::all_columns> || framework::has_type_v<aod::pidtpc::TPCNSigmaPi, typename TrackObject::all_columns>) {
sp = pidselector.whichSpecies(track);
sp = pidselector.whichSpecies<outdebug>(track);
} else {
LOGF(fatal, "Track identification required but PID information not present");
}
Expand Down Expand Up @@ -1082,7 +1101,7 @@ int8_t DptDptFilterTracks::trackIdentification(TrackObject const& track)
return sp;
}

template <typename TrackObject>
template <StrongDebugging outdebug, typename TrackObject>
int8_t DptDptFilterTracks::selectTrack(TrackObject const& track)
{
using namespace dptdptfilter;
Expand All @@ -1095,7 +1114,7 @@ int8_t DptDptFilterTracks::selectTrack(TrackObject const& track)
if (AcceptTrack(track)) {
/* the track has been accepted */
/* let's identify it */
sp = trackIdentification(track);
sp = trackIdentification<outdebug>(track);
if (!(sp < 0)) {
/* fill the species histograms */
fillTrackHistosAfterSelection(track, sp);
Expand All @@ -1114,7 +1133,7 @@ int8_t DptDptFilterTracks::selectTrack(TrackObject const& track)
return sp;
}

template <typename CollisionObjects, typename TrackObject>
template <StrongDebugging outdebug, typename CollisionObjects, typename TrackObject>
int8_t DptDptFilterTracks::selectTrackAmbiguousCheck(CollisionObjects const& collisions, TrackObject const& track)
{
bool ambiguoustrack = false;
Expand Down Expand Up @@ -1164,7 +1183,7 @@ int8_t DptDptFilterTracks::selectTrackAmbiguousCheck(CollisionObjects const& col
/* feedback of no ambiguous tracks only if checks required */
fhAmbiguousTrackType->Fill(ambtracktype, multiplicityclass);
}
return selectTrack(track);
return selectTrack<outdebug>(track);
}
}

Expand Down
70 changes: 69 additions & 1 deletion PWGCF/TableProducer/dptdptfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <string>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <locale>
#include <sstream>
#include <functional>
Expand Down Expand Up @@ -101,6 +102,18 @@ enum TriggerSelectionType {
knEventSelection ///< number of triggers for event selection
};

/// \enum StrongDebugging
/// \brief Enable a per track information debugging. Only for local analyses
enum StrongDebugging {
kNODEBUG = 0, ///< do not debug
kDEBUG ///< output debugging information on a per track basis to a text file
};

//============================================================================================
// The debug output stream
//============================================================================================
std::ofstream debugstream;

//============================================================================================
// The overall minimum momentum
//============================================================================================
Expand Down Expand Up @@ -992,12 +1005,34 @@ struct PIDSpeciesSelection {
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>
template <StrongDebugging outdebug, typename TrackObject>
int8_t whichSpecies(TrackObject const& track)
{
TString debuginfo;
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 outmomentumdebug = [&]() {
if constexpr (outdebug != 0) {
debuginfo += TString::Format("%.5f,%.5f,%.5f,%d,%.2f,%.4f,", track.p(), track.tpcInnerParam(), track.pt(), track.hasTOF() ? 1 : 0, track.tpcSignal(), track.beta());
}
};
auto outnsigmasdebug = [&]() {
if constexpr (outdebug != 0) {
for (auto tpcn : tpcnsigmas) {
debuginfo += TString::Format("%.4f,", tpcn);
}
for (auto tofn : tofnsigmas) {
debuginfo += TString::Format("%.4f,", tofn);
}
}
};

/* out debug if needed */
outmomentumdebug();
/* out debug if needed */
outnsigmasdebug();

auto closeTo = [](auto& values, auto& mindet, auto& maxdet, uint8_t sp) {
if (mindet[sp] <= values[sp] && values[sp] < maxdet[sp]) {
return true;
Expand Down Expand Up @@ -1097,12 +1132,34 @@ struct PIDSpeciesSelection {
}
};

auto outpiddebug = [&](int code, int pid, int pid2) {
if constexpr (outdebug != 0) {
int truepid = -1;
int isphysicalprimary = -1;
int process = -1;
if constexpr (framework::has_type_v<aod::mctracklabel::McParticleId, typename TrackObject::all_columns>) {
if (!(track.mcParticleId() < 0)) {
auto particle = track.template mcParticle_as<aod::McParticles>();
truepid = particle.pdgCode();
isphysicalprimary = particle.isPhysicalPrimary() ? 1 : 0;
process = particle.getProcess();
}
}
debuginfo += TString::Format("%d,%d,%d,%d,%d,%d\n", code, pid, pid2, truepid, isphysicalprimary, process);
debugstream << debuginfo;
}
};

/* adjust the nsigmas values if appropriate */
adjustnsigmas();
/* out debug info if needed */
outnsigmasdebug();

/* let's first check the exclusion from the analysis */
for (uint8_t ix = 0; ix < configexclude.size(); ++ix) {
if (isA(configexclude[ix], speciesexclude[ix])) {
/* out debug info if needed */
outpiddebug(1, speciesexclude[ix], -1);
return -(ix + 1);
}
}
Expand All @@ -1114,13 +1171,24 @@ struct PIDSpeciesSelection {
if (id < 0) {
id = ix;
} else {
/* out debug info if needed */
outpiddebug(2, species[id], species[ix]);
/* already identified once */
return -127;
}
}
}
/* out debug info if needed */
if (id < 0) {
/* not identified */
outpiddebug(3, -1, -1);
} else {
/* identified */
outpiddebug(0, species[id], -1);
}
return id;
} else {
outpiddebug(0, 0, -1);
/* charged hadron */
return 0;
}
Expand Down

0 comments on commit 93a0a1f

Please sign in to comment.