Skip to content

Commit 81c7bcd

Browse files
authored
[Common,DPG] PID: Add AO2D metadata handling for pass name in TPC CCDB calls (pull/6793), adding NN-version number , using nSigmaTOFdautrack in protons from Lambda decays (#8835)
1 parent 70f85cb commit 81c7bcd

File tree

2 files changed

+63
-21
lines changed

2 files changed

+63
-21
lines changed

Common/TableProducer/PID/pidTPC.cxx

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,32 @@
1818
/// \brief Task to produce PID tables for TPC split for each particle.
1919
/// Only the tables for the mass hypotheses requested are filled, and only for the requested table size ("Full" or "Tiny"). The others are sent empty.
2020
///
21-
21+
#include <utility>
22+
#include <map>
23+
#include <memory>
24+
#include <string>
25+
#include <vector>
2226
// ROOT includes
2327
#include "TFile.h"
2428
#include "TRandom.h"
2529
#include "TSystem.h"
2630

2731
// O2 includes
28-
#include <CCDB/BasicCCDBManager.h>
32+
#include "CCDB/BasicCCDBManager.h"
2933
#include "Framework/AnalysisTask.h"
34+
#include "Framework/runDataProcessing.h"
35+
#include "Framework/ASoAHelpers.h"
3036
#include "ReconstructionDataFormats/Track.h"
3137
#include "CCDB/CcdbApi.h"
3238
#include "Common/DataModel/PIDResponse.h"
3339
#include "Common/Core/PID/TPCPIDResponse.h"
3440
#include "Framework/AnalysisDataModel.h"
3541
#include "Common/DataModel/Multiplicity.h"
42+
#include "Common/DataModel/EventSelection.h"
3643
#include "TableHelper.h"
3744
#include "Tools/ML/model.h"
3845
#include "pidTPCBase.h"
46+
#include "MetadataHelper.h"
3947

4048
using namespace o2;
4149
using namespace o2::framework;
@@ -45,21 +53,21 @@ using namespace o2::framework::expressions;
4553
using namespace o2::track;
4654
using namespace o2::ml;
4755

56+
MetadataHelper metadataInfo; // Metadata helper
57+
4858
void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
4959
{
5060
std::vector<ConfigParamSpec> options{{"add-qa", VariantType::Int, 0, {"Legacy. No effect."}}};
5161
std::swap(workflowOptions, options);
5262
}
5363

54-
#include "Framework/runDataProcessing.h"
55-
5664
/// Task to produce the response table
5765
struct tpcPid {
5866
using Trks = soa::Join<aod::Tracks, aod::TracksExtra>;
59-
using Coll = soa::Join<aod::Collisions, aod::PIDMults>;
67+
using Coll = soa::Join<aod::Collisions, aod::PIDMults, aod::EvSels>;
6068

6169
using TrksMC = soa::Join<aod::Tracks, aod::TracksExtra, aod::McTrackLabels>;
62-
using CollMC = soa::Join<aod::Collisions, aod::PIDMults, aod::McCollisionLabels>;
70+
using CollMC = soa::Join<aod::Collisions, aod::PIDMults, aod::McCollisionLabels, aod::EvSels>;
6371

6472
// Tables to produce
6573
Produces<o2::aod::pidTPCFullEl> tablePIDFullEl;
@@ -90,8 +98,10 @@ struct tpcPid {
9098
OnnxModel network;
9199
o2::ccdb::CcdbApi ccdbApi;
92100
std::map<std::string, std::string> metadata;
101+
std::map<std::string, std::string> nullmetadata;
93102
std::map<std::string, std::string> headers;
94103
std::vector<int> speciesNetworkFlags = std::vector<int>(9);
104+
std::string networkVersion;
95105

96106
// Input parameters
97107
Service<o2::ccdb::BasicCCDBManager> ccdb;
@@ -187,11 +197,14 @@ struct tpcPid {
187197
speciesNetworkFlags[7] = useNetworkHe;
188198
speciesNetworkFlags[8] = useNetworkAl;
189199

190-
// Initialise metadata object for CCDB calls
200+
// Initialise metadata object for CCDB calls from AO2D metadata
191201
if (recoPass.value == "") {
192-
LOGP(info, "Reco pass not specified; CCDB will take latest available object");
202+
if (metadataInfo.isFullyDefined()) {
203+
metadata["RecoPassName"] = metadataInfo.get("RecoPassName");
204+
LOGP(info, "Automatically setting reco pass for TPC Response to {} from AO2D", metadata["RecoPassName"]);
205+
}
193206
} else {
194-
LOGP(info, "CCDB object will be requested for reconstruction pass {}", recoPass.value);
207+
LOGP(info, "Setting reco pass for TPC response to user-defined name {}", recoPass.value);
195208
metadata["RecoPassName"] = recoPass.value;
196209
}
197210

@@ -215,17 +228,23 @@ struct tpcPid {
215228
ccdb->setCaching(true);
216229
ccdb->setLocalObjectValidityChecking();
217230
ccdb->setCreatedNotAfter(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
231+
ccdbApi.init(url);
218232
if (time != 0) {
219233
LOGP(info, "Initialising TPC PID response for fixed timestamp {} and reco pass {}:", time, recoPass.value);
220234
ccdb->setTimestamp(time);
221235
response = ccdb->getSpecific<o2::pid::tpc::Response>(path, time, metadata);
236+
headers = ccdbApi.retrieveHeaders(path, metadata, time);
222237
if (!response) {
223238
LOGF(warning, "Unable to find TPC parametrisation for specified pass name - falling back to latest object");
224239
response = ccdb->getForTimeStamp<o2::pid::tpc::Response>(path, time);
240+
headers = ccdbApi.retrieveHeaders(path, metadata, time);
241+
networkVersion = headers["NN-Version"];
225242
if (!response) {
226243
LOGF(fatal, "Unable to find any TPC object corresponding to timestamp {}!", time);
227244
}
228245
}
246+
LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << time << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"];
247+
metadata["RecoPassName"] = headers["RecoPassName"]; // Force pass number for NN request to match retrieved BB
229248
response->PrintAll();
230249
}
231250
}
@@ -236,19 +255,21 @@ struct tpcPid {
236255
return;
237256
} else {
238257
/// CCDB and auto-fetching
239-
ccdbApi.init(url);
258+
240259
if (!autofetchNetworks) {
241260
if (ccdbTimestamp > 0) {
242261
/// Fetching network for specific timestamp
243262
LOG(info) << "Fetching network for timestamp: " << ccdbTimestamp.value;
244263
bool retrieveSuccess = ccdbApi.retrieveBlob(networkPathCCDB.value, ".", metadata, ccdbTimestamp.value, false, networkPathLocally.value);
245264
headers = ccdbApi.retrieveHeaders(networkPathCCDB.value, metadata, ccdbTimestamp.value);
265+
networkVersion = headers["NN-Version"];
246266
if (retrieveSuccess) {
247267
network.initModel(networkPathLocally.value, enableNetworkOptimizations.value, networkSetNumThreads.value, strtoul(headers["Valid-From"].c_str(), NULL, 0), strtoul(headers["Valid-Until"].c_str(), NULL, 0));
248268
std::vector<float> dummyInput(network.getNumInputNodes(), 1.);
249269
network.evalModel(dummyInput); /// Init the model evaluations
270+
LOGP(info, "Retrieved NN corrections for production tag {}, pass number {}, and NN-Version {}", headers["LPMProductionTag"], headers["RecoPassName"], headers["NN-Version"]);
250271
} else {
251-
LOG(fatal) << "Error encountered while fetching/loading the network from CCDB! Maybe the network doesn't exist yet for this runnumber/timestamp?";
272+
LOG(fatal) << "No valid NN object found matching retrieved Bethe-Bloch parametrisation for pass " << metadata["RecoPassName"] << ". Please ensure that the requested pass has dedicated NN corrections available";
252273
}
253274
} else {
254275
/// Taking the network from local file
@@ -266,7 +287,7 @@ struct tpcPid {
266287
}
267288
}
268289

269-
Partition<Trks> notTPCStandaloneTracks = (aod::track::tpcNClsFindable > (uint8_t)0) && ((aod::track::itsClusterSizes > (uint32_t)0) || (aod::track::trdPattern > (uint8_t)0) || (aod::track::tofExpMom > 0.f && aod::track::tofChi2 > 0.f)); // To count number of tracks for use in NN array
290+
Partition<Trks> notTPCStandaloneTracks = (aod::track::tpcNClsFindable > static_cast<uint8_t>(0)) && ((aod::track::itsClusterSizes > static_cast<uint32_t>(0)) || (aod::track::trdPattern > static_cast<uint8_t>(0)) || (aod::track::tofExpMom > 0.f && aod::track::tofChi2 > 0.f)); // To count number of tracks for use in NN array
270291
Partition<Trks> tracksWithTPC = (aod::track::tpcNClsFindable > (uint8_t)0);
271292

272293
template <typename C, typename T, typename B>
@@ -286,26 +307,33 @@ struct tpcPid {
286307
LOGP(info, "Retrieving TPC Response for timestamp {} and recoPass {}:", bc.timestamp(), recoPass.value);
287308
}
288309
response = ccdb->getSpecific<o2::pid::tpc::Response>(ccdbPath.value, bc.timestamp(), metadata);
310+
headers = ccdbApi.retrieveHeaders(ccdbPath.value, metadata, bc.timestamp());
311+
networkVersion = headers["NN-Version"];
289312
if (!response) {
290-
LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", recoPass.value);
313+
LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", metadata["RecoPassName"]);
314+
headers = ccdbApi.retrieveHeaders(ccdbPath.value, nullmetadata, bc.timestamp());
291315
response = ccdb->getForTimeStamp<o2::pid::tpc::Response>(ccdbPath.value, bc.timestamp());
292316
if (!response) {
293317
LOGP(fatal, "Could not find ANY TPC response object for the timestamp {}!", bc.timestamp());
294318
}
295319
}
320+
LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << bc.timestamp() << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"];
321+
metadata["RecoPassName"] = headers["RecoPassName"]; // Force pass number for NN request to match retrieved BB
296322
response->PrintAll();
297323
}
298324

299325
if (bc.timestamp() < network.getValidityFrom() || bc.timestamp() > network.getValidityUntil()) { // fetches network only if the runnumbers change
300326
LOG(info) << "Fetching network for timestamp: " << bc.timestamp();
301327
bool retrieveSuccess = ccdbApi.retrieveBlob(networkPathCCDB.value, ".", metadata, bc.timestamp(), false, networkPathLocally.value);
302328
headers = ccdbApi.retrieveHeaders(networkPathCCDB.value, metadata, bc.timestamp());
329+
networkVersion = headers["NN-Version"];
303330
if (retrieveSuccess) {
304331
network.initModel(networkPathLocally.value, enableNetworkOptimizations.value, networkSetNumThreads.value, strtoul(headers["Valid-From"].c_str(), NULL, 0), strtoul(headers["Valid-Until"].c_str(), NULL, 0));
305332
std::vector<float> dummyInput(network.getNumInputNodes(), 1.);
306333
network.evalModel(dummyInput);
334+
LOGP(info, "Retrieved NN corrections for production tag {}, pass number {}, NN-Version number{}", headers["LPMProductionTag"], headers["RecoPassName"], headers["NN-Version"]);
307335
} else {
308-
LOG(fatal) << "Error encountered while fetching/loading the network from CCDB! Maybe the network doesn't exist yet for this runnumber/timestamp?";
336+
LOG(fatal) << "No valid NN object found matching retrieved Bethe-Bloch parametrisation for pass " << metadata["RecoPassName"] << ". Please ensure that the requested pass has dedicated NN corrections available";
309337
}
310338
}
311339
}
@@ -342,6 +370,9 @@ struct tpcPid {
342370
track_properties[counter_track_props + 3] = o2::track::pid_constants::sMasses[i];
343371
track_properties[counter_track_props + 4] = trk.has_collision() ? collisions.iteratorAt(trk.collisionId()).multTPC() / 11000. : 1.;
344372
track_properties[counter_track_props + 5] = std::sqrt(nNclNormalization / trk.tpcNClsFound());
373+
if (input_dimensions == 7 && networkVersion == "2") {
374+
track_properties[counter_track_props + 6] = trk.has_collision() ? collisions.iteratorAt(trk.collisionId()).ft0cOccupancyInTimeRange() / 60000. : 1.;
375+
}
345376
counter_track_props += input_dimensions;
346377
}
347378

@@ -483,13 +514,16 @@ struct tpcPid {
483514
LOGP(info, "Retrieving TPC Response for timestamp {} and recoPass {}:", bc.timestamp(), recoPass.value);
484515
}
485516
response = ccdb->getSpecific<o2::pid::tpc::Response>(ccdbPath.value, bc.timestamp(), metadata);
517+
headers = ccdbApi.retrieveHeaders(ccdbPath.value, metadata, bc.timestamp());
486518
if (!response) {
487-
LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", recoPass.value);
519+
LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", metadata["RecoPassName"]);
488520
response = ccdb->getForTimeStamp<o2::pid::tpc::Response>(ccdbPath.value, bc.timestamp());
521+
headers = ccdbApi.retrieveHeaders(ccdbPath.value, nullmetadata, bc.timestamp());
489522
if (!response) {
490523
LOGP(fatal, "Could not find ANY TPC response object for the timestamp {}!", bc.timestamp());
491524
}
492525
}
526+
LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << bc.timestamp() << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"];
493527
response->PrintAll();
494528
}
495529

@@ -515,7 +549,7 @@ struct tpcPid {
515549

516550
PROCESS_SWITCH(tpcPid, processStandard, "Creating PID tables without MC TuneOnData", true);
517551

518-
Partition<TrksMC> mcnotTPCStandaloneTracks = (aod::track::tpcNClsFindable > (uint8_t)0) && ((aod::track::itsClusterSizes > (uint32_t)0) || (aod::track::trdPattern > (uint8_t)0) || (aod::track::tofExpMom > 0.f && aod::track::tofChi2 > 0.f)); // To count number of tracks for use in NN array
552+
Partition<TrksMC> mcnotTPCStandaloneTracks = (aod::track::tpcNClsFindable > static_cast<uint8_t>(0)) && ((aod::track::itsClusterSizes > static_cast<uint32_t>(0)) || (aod::track::trdPattern > static_cast<uint8_t>(0)) || (aod::track::tofExpMom > 0.f && aod::track::tofChi2 > 0.f)); // To count number of tracks for use in NN array
519553
Partition<TrksMC> mctracksWithTPC = (aod::track::tpcNClsFindable > (uint8_t)0);
520554

521555
void processMcTuneOnData(CollMC const& collisionsMc, TrksMC const& tracksMc, aod::BCsWithTimestamps const& bcs, aod::McParticles const&)
@@ -573,7 +607,7 @@ struct tpcPid {
573607
}
574608
response = ccdb->getSpecific<o2::pid::tpc::Response>(ccdbPath.value, bc.timestamp(), metadata);
575609
if (!response) {
576-
LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", recoPass.value);
610+
LOGP(warning, "!! Could not find a valid TPC response object for specific pass name {}! Falling back to latest uploaded object.", metadata["RecoPassName"]);
577611
response = ccdb->getForTimeStamp<o2::pid::tpc::Response>(ccdbPath.value, bc.timestamp());
578612
if (!response) {
579613
LOGP(fatal, "Could not find ANY TPC response object for the timestamp {}!", bc.timestamp());
@@ -641,4 +675,8 @@ struct tpcPid {
641675
PROCESS_SWITCH(tpcPid, processMcTuneOnData, "Creating PID tables with MC TuneOnData", false);
642676
};
643677

644-
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { return WorkflowSpec{adaptAnalysisTask<tpcPid>(cfgc)}; }
678+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
679+
{
680+
metadataInfo.initMetadata(cfgc); // Parse AO2D metadata
681+
return WorkflowSpec{adaptAnalysisTask<tpcPid>(cfgc)};
682+
}

DPG/Tasks/TPC/tpcSkimsTableCreator.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct TreeWriterTpcV0 {
5454
Produces<o2::aod::SkimmedTPCV0Tree> rowTPCTree;
5555

5656
/// Configurables
57-
Configurable<float> nSigmaTOFdautrack{"nSigmaTOFdautrack", 5., "n-sigma TOF cut on the daughter tracks. Set 0 to switch it off."};
57+
Configurable<float> nSigmaTOFdautrack{"nSigmaTOFdautrack", 999., "n-sigma TOF cut on the proton daughter tracks. Set 999 to switch it off."};
5858
Configurable<float> nClNorm{"nClNorm", 152., "Number of cluster normalization. Run 2: 159, Run 3 152"};
5959
Configurable<int> applyEvSel{"applyEvSel", 2, "Flag to apply rapidity cut: 0 -> no event selection, 1 -> Run 2 event selection, 2 -> Run 3 event selection"};
6060
Configurable<int> trackSelection{"trackSelection", 1, "Track selection: 0 -> No Cut, 1 -> kGlobalTrack, 2 -> kGlobalTrackWoPtEta, 3 -> kGlobalTrackWoDCA, 4 -> kQualityTracks, 5 -> kInAcceptanceTracks"};
@@ -222,7 +222,9 @@ struct TreeWriterTpcV0 {
222222
// Lambda
223223
if (static_cast<bool>(posTrack.pidbit() & (1 << 2)) && static_cast<bool>(negTrack.pidbit() & (1 << 2))) {
224224
if (downsampleTsalisCharged(posTrack.pt(), downsamplingTsalisProtons, sqrtSNN, o2::track::pid_constants::sMasses[o2::track::PID::Proton], maxPt4dwnsmplTsalisProtons)) {
225-
fillSkimmedV0Table(v0, posTrack, collision, posTrack.tpcNSigmaPr(), posTrack.tofNSigmaPr(), posTrack.tpcExpSignalPr(posTrack.tpcSignal()), o2::track::PID::Proton, runnumber, dwnSmplFactor_Pr, hadronicRate);
225+
if (TMath::Abs(posTrack.tofNSigmaPr()) <= nSigmaTOFdautrack) {
226+
fillSkimmedV0Table(v0, posTrack, collision, posTrack.tpcNSigmaPr(), posTrack.tofNSigmaPr(), posTrack.tpcExpSignalPr(posTrack.tpcSignal()), o2::track::PID::Proton, runnumber, dwnSmplFactor_Pr, hadronicRate);
227+
}
226228
}
227229
if (downsampleTsalisCharged(negTrack.pt(), downsamplingTsalisPions, sqrtSNN, o2::track::pid_constants::sMasses[o2::track::PID::Pion], maxPt4dwnsmplTsalisPions)) {
228230
fillSkimmedV0Table(v0, negTrack, collision, negTrack.tpcNSigmaPi(), negTrack.tofNSigmaPi(), negTrack.tpcExpSignalPi(negTrack.tpcSignal()), o2::track::PID::Pion, runnumber, dwnSmplFactor_Pi, hadronicRate);
@@ -234,7 +236,9 @@ struct TreeWriterTpcV0 {
234236
fillSkimmedV0Table(v0, posTrack, collision, posTrack.tpcNSigmaPi(), posTrack.tofNSigmaPi(), posTrack.tpcExpSignalPi(posTrack.tpcSignal()), o2::track::PID::Pion, runnumber, dwnSmplFactor_Pi, hadronicRate);
235237
}
236238
if (downsampleTsalisCharged(negTrack.pt(), downsamplingTsalisProtons, sqrtSNN, o2::track::pid_constants::sMasses[o2::track::PID::Proton], maxPt4dwnsmplTsalisProtons)) {
237-
fillSkimmedV0Table(v0, negTrack, collision, negTrack.tpcNSigmaPr(), negTrack.tofNSigmaPr(), negTrack.tpcExpSignalPr(negTrack.tpcSignal()), o2::track::PID::Proton, runnumber, dwnSmplFactor_Pr, hadronicRate);
239+
if (TMath::Abs(negTrack.tofNSigmaPr()) <= nSigmaTOFdautrack) {
240+
fillSkimmedV0Table(v0, negTrack, collision, negTrack.tpcNSigmaPr(), negTrack.tofNSigmaPr(), negTrack.tpcExpSignalPr(negTrack.tpcSignal()), o2::track::PID::Proton, runnumber, dwnSmplFactor_Pr, hadronicRate);
241+
}
238242
}
239243
}
240244
}

0 commit comments

Comments
 (0)