diff --git a/PWGCF/TableProducer/dptdptfilter.cxx b/PWGCF/TableProducer/dptdptfilter.cxx index 924edaf13f6..ff5930aa9cc 100644 --- a/PWGCF/TableProducer/dptdptfilter.cxx +++ b/PWGCF/TableProducer/dptdptfilter.cxx @@ -514,6 +514,7 @@ struct DptDptFilterTracks { std::string cfgCCDBDate{"20220307"}; std::string cfgCCDBPeriod{"LHC22o"}; + Configurable cfgOutDebugInfo{"outdebuginfo", false, "Out detailed debug information per track into a text file. Default false"}; Configurable cfgFullDerivedData{"fullderiveddata", false, "Produce the full derived data for external storage. Default false"}; Configurable 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 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}"}; @@ -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() @@ -828,11 +835,11 @@ struct DptDptFilterTracks { } } - template + template int8_t trackIdentification(TrackObject const& track); - template + template int8_t selectTrack(TrackObject const& track); - template + template int8_t selectTrackAmbiguousCheck(CollisionObjects const& collisions, TrackObject const& track); template int8_t identifyParticle(ParticleObject const& particle); @@ -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 + template void filterTracks(soa::Join const& collisions, passedtracks const& tracks) { @@ -882,7 +889,7 @@ struct DptDptFilterTracks { for (auto track : tracks) { int8_t pid = -1; if (track.has_collision() && (track.template collision_as>()).collisionaccepted()) { - pid = selectTrackAmbiguousCheck(collisions, track); + pid = selectTrackAmbiguousCheck(collisions, track); if (!(pid < 0)) { naccepted++; if (fullDerivedData) { @@ -961,75 +968,87 @@ struct DptDptFilterTracks { particles.size()); } + template + void doFilterTracks(soa::Join const& collisions, passedtracks const& tracks) + { + if (cfgOutDebugInfo) { + debugstream.open("tracings.csv", std::ios::app); + filterTracks(collisions, tracks); + debugstream.close(); + } else { + filterTracks(collisions, tracks); + } + } + void filterRecoWithPID(soa::Join& 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& 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& 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& 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& 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& 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& 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& 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 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 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 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 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) @@ -1040,7 +1059,7 @@ struct DptDptFilterTracks { PROCESS_SWITCH(DptDptFilterTracks, filterGenerated, "Generated particles filtering", true) }; -template +template int8_t DptDptFilterTracks::trackIdentification(TrackObject const& track) { using namespace dptdptfilter; @@ -1050,7 +1069,7 @@ int8_t DptDptFilterTracks::trackIdentification(TrackObject const& track) sp = 0; } else if (recoIdMethod == 1) { if constexpr (framework::has_type_v || framework::has_type_v) { - sp = pidselector.whichSpecies(track); + sp = pidselector.whichSpecies(track); } else { LOGF(fatal, "Track identification required but PID information not present"); } @@ -1082,7 +1101,7 @@ int8_t DptDptFilterTracks::trackIdentification(TrackObject const& track) return sp; } -template +template int8_t DptDptFilterTracks::selectTrack(TrackObject const& track) { using namespace dptdptfilter; @@ -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(track); if (!(sp < 0)) { /* fill the species histograms */ fillTrackHistosAfterSelection(track, sp); @@ -1114,7 +1133,7 @@ int8_t DptDptFilterTracks::selectTrack(TrackObject const& track) return sp; } -template +template int8_t DptDptFilterTracks::selectTrackAmbiguousCheck(CollisionObjects const& collisions, TrackObject const& track) { bool ambiguoustrack = false; @@ -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(track); } } diff --git a/PWGCF/TableProducer/dptdptfilter.h b/PWGCF/TableProducer/dptdptfilter.h index afcd9f0df6c..a08c0c682c0 100644 --- a/PWGCF/TableProducer/dptdptfilter.h +++ b/PWGCF/TableProducer/dptdptfilter.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -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 //============================================================================================ @@ -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 + template int8_t whichSpecies(TrackObject const& track) { + TString debuginfo; std::vector tpcnsigmas = {track.tpcNSigmaEl(), track.tpcNSigmaMu(), track.tpcNSigmaPi(), track.tpcNSigmaKa(), track.tpcNSigmaPr()}; std::vector 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; @@ -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) { + if (!(track.mcParticleId() < 0)) { + auto particle = track.template mcParticle_as(); + 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); } } @@ -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; }