Skip to content

Commit f390c5c

Browse files
authored
[Common] TPC interface: skipTPCOnly auto mode, fix Run 2 bug (#13604)
Co-authored-by: David Dobrigkeit Chinellato <david.dobrigkeit.chinellato.cern.ch>
1 parent 80095e0 commit f390c5c

File tree

1 file changed

+103
-20
lines changed

1 file changed

+103
-20
lines changed

Common/Tools/PID/pidTPCModule.h

Lines changed: 103 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <Framework/AnalysisDataModel.h>
3434
#include <Framework/AnalysisHelpers.h>
3535
#include <Framework/Configurable.h>
36+
#include <Framework/RunningWorkflowInfo.h>
3637
#include <Framework/runDataProcessing.h>
3738
#include <ReconstructionDataFormats/PID.h>
3839

@@ -91,7 +92,8 @@ struct pidTPCConfigurables : o2::framework::ConfigurableGroup {
9192
// Parameters for loading network from a file / downloading the file
9293
o2::framework::Configurable<bool> useNetworkCorrection{"useNetworkCorrection", 0, "(bool) Wether or not to use the network correction for the TPC dE/dx signal"};
9394
o2::framework::Configurable<bool> autofetchNetworks{"autofetchNetworks", 1, "(bool) Automatically fetches networks from CCDB for the correct run number"};
94-
o2::framework::Configurable<bool> skipTPCOnly{"skipTPCOnly", false, "Flag to skip TPC only tracks (faster but affects the analyses that use TPC only tracks)"};
95+
o2::framework::Configurable<int> skipTPCOnly{"skipTPCOnly", -1, "Flag to skip TPC only tracks (faster but affects the analyses that use TPC only tracks). 0: do not skip, 1: skip, -1: check if needed by specific tasks"};
96+
o2::framework::Configurable<std::vector<std::string>> devicesRequiringTPCOnlyPID{"devicesRequiringTPCOnlyPID", std::vector<std::string>{"photon-conversion-builder"}, "List of device names of tasks requiring TPC-only tracks to have TPC PID calculated"};
9597
o2::framework::Configurable<std::string> networkPathLocally{"networkPathLocally", "network.onnx", "(std::string) Path to the local .onnx file. If autofetching is enabled, then this is where the files will be downloaded"};
9698
o2::framework::Configurable<std::string> networkPathCCDB{"networkPathCCDB", "Analysis/PID/TPC/ML", "Path on CCDB"};
9799
o2::framework::Configurable<bool> enableNetworkOptimizations{"enableNetworkOptimizations", 1, "(bool) If the neural network correction is used, this enables GraphOptimizationLevel::ORT_ENABLE_EXTENDED in the ONNX session"};
@@ -244,6 +246,59 @@ class pidTPCModule
244246
LOGF(info, "***************************************************");
245247
}
246248

249+
if (pidTPCopts.skipTPCOnly.value == -1) {
250+
LOGF(info, "***************************************************");
251+
LOGF(info, " the skipTPConly flag has a value of -1! ");
252+
LOGF(info, " ---> autodetecting TPC-only track necessity now ");
253+
LOGF(info, "***************************************************");
254+
// print list of devices that are being checked for
255+
for (std::size_t devIdx{0}; devIdx < pidTPCopts.devicesRequiringTPCOnlyPID->size(); devIdx++) {
256+
LOGF(info, "Will search for #%i device requiring TPC PID for TPC only: %s", devIdx, pidTPCopts.devicesRequiringTPCOnlyPID->at(devIdx));
257+
}
258+
LOGF(info, "***************************************************");
259+
260+
// assume that TPC tracks are not needed, but check if tasks
261+
// requiring them are present in the chain
262+
pidTPCopts.skipTPCOnly.value = 1;
263+
264+
// loop over devices in this execution
265+
auto& workflows = context.services().template get<o2::framework::RunningWorkflowInfo const>();
266+
for (o2::framework::DeviceSpec const& device : workflows.devices) {
267+
// Look for propagation service
268+
if (device.name.compare("propagation-service") == 0) {
269+
LOGF(info, " ---> propagation service detected, checking if photons enabled...");
270+
for (auto const& option : device.options) {
271+
// check for photon generation enabled or not
272+
if (option.name.compare("v0BuilderOpts.generatePhotonCandidates") == 0) {
273+
if (option.defaultValue.get<bool>()) {
274+
LOGF(info, " ---> propagation service: photons enabled, will calculate TPC PID for TPC only tracks.");
275+
pidTPCopts.skipTPCOnly.value = 0;
276+
} else {
277+
LOGF(info, " ---> propagation service: photons disabled, TPC PID not required for TPC-only tracks");
278+
}
279+
}
280+
}
281+
}
282+
283+
// Check 2: specific tasks that require TPC PID based on configurable
284+
for (std::size_t devIdx{0}; devIdx < pidTPCopts.devicesRequiringTPCOnlyPID->size(); devIdx++) {
285+
if (device.name.compare(pidTPCopts.devicesRequiringTPCOnlyPID->at(devIdx)) == 0) {
286+
LOGF(info, " ---> %s detected! ", pidTPCopts.devicesRequiringTPCOnlyPID->at(devIdx));
287+
LOGF(info, " ---> enabling TPC only track TPC PID calculations now.");
288+
pidTPCopts.skipTPCOnly.value = 0;
289+
}
290+
}
291+
}
292+
293+
if (pidTPCopts.skipTPCOnly.value == 1) {
294+
LOGF(info, "***************************************************");
295+
LOGF(info, "No need for TPC only information detected. Will not generate Nsigma for TPC only tracks");
296+
LOGF(info, "If this is unexpected behaviour and a necessity was not identified, please add the");
297+
LOGF(info, "corresponding task to the list 'devicesRequiringTPCOnlyPID' in pidTPCModule::Init()");
298+
}
299+
LOGF(info, "***************************************************");
300+
}
301+
247302
// initialize PID response
248303
response = new o2::pid::tpc::Response();
249304

@@ -330,12 +385,16 @@ class pidTPCModule
330385
LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << time << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"];
331386
metadata["RecoPassName"] = headers["RecoPassName"]; // Force pass number for NN request to match retrieved BB
332387
o2::parameters::GRPLHCIFData* grpo = ccdb->template getForTimeStamp<o2::parameters::GRPLHCIFData>(pidTPCopts.cfgPathGrpLhcIf.value, time);
333-
LOG(info) << " collision type::" << CollisionSystemType::getCollisionTypeFromGrp(grpo);
334-
collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
335-
if (collsys == CollisionSystemType::kCollSyspp) {
336-
irSource = std::string("T0VTX");
388+
if (grpo) {
389+
LOG(info) << " collision type::" << CollisionSystemType::getCollisionTypeFromGrp(grpo);
390+
collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
391+
if (collsys == CollisionSystemType::kCollSyspp) {
392+
irSource = std::string("T0VTX");
393+
} else {
394+
irSource = std::string("ZNC hadronic");
395+
}
337396
} else {
338-
irSource = std::string("ZNC hadronic");
397+
LOGF(info, "No grpo object found. irSource will remain undefined.");
339398
}
340399
response->PrintAll();
341400
}
@@ -412,12 +471,16 @@ class pidTPCModule
412471
LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << bc.timestamp() << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"];
413472
metadata["RecoPassName"] = headers["RecoPassName"]; // Force pass number for NN request to match retrieved BB
414473
o2::parameters::GRPLHCIFData* grpo = ccdb->template getForTimeStamp<o2::parameters::GRPLHCIFData>(pidTPCopts.cfgPathGrpLhcIf.value, bc.timestamp());
415-
LOG(info) << "Collision type::" << CollisionSystemType::getCollisionTypeFromGrp(grpo);
416-
collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
417-
if (collsys == CollisionSystemType::kCollSyspp) {
418-
irSource = std::string("T0VTX");
474+
if (grpo) {
475+
LOG(info) << "Collision type::" << CollisionSystemType::getCollisionTypeFromGrp(grpo);
476+
collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
477+
if (collsys == CollisionSystemType::kCollSyspp) {
478+
irSource = std::string("T0VTX");
479+
} else {
480+
irSource = std::string("ZNC hadronic");
481+
}
419482
} else {
420-
irSource = std::string("ZNC hadronic");
483+
LOGF(info, "No grpo object found. irSource will remain undefined.");
421484
}
422485
response->PrintAll();
423486
}
@@ -458,11 +521,19 @@ class pidTPCModule
458521
size_t i = 0;
459522
for (const auto& collision : collisions) {
460523
const auto& bc = collision.template bc_as<B>();
461-
hadronicRateForCollision[i] = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3;
524+
if (irSource.compare("") != 0) {
525+
hadronicRateForCollision[i] = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3;
526+
} else {
527+
hadronicRateForCollision[i] = 0.0f;
528+
}
462529
i++;
463530
}
464531
auto bc = bcs.begin();
465-
hadronicRateBegin = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3; // kHz
532+
if (irSource.compare("") != 0) {
533+
hadronicRateBegin = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3; // kHz
534+
} else {
535+
hadronicRateBegin = 0.0f;
536+
}
466537

467538
// Filling a std::vector<float> to be evaluated by the network
468539
// Evaluation on single tracks brings huge overhead: Thus evaluation is done on one large vector
@@ -685,11 +756,19 @@ class pidTPCModule
685756
size_t i = 0;
686757
for (const auto& collision : cols) {
687758
const auto& bc = collision.template bc_as<aod::BCsWithTimestamps>();
688-
hadronicRateForCollision[i] = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3;
759+
if (irSource.compare("") != 0) {
760+
hadronicRateForCollision[i] = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3;
761+
} else {
762+
hadronicRateForCollision[i] = 0.0f;
763+
}
689764
i++;
690765
}
691766
auto bc = bcs.begin();
692-
hadronicRateBegin = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3; // kHz
767+
if (irSource.compare("") != 0) {
768+
hadronicRateBegin = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3; // kHz
769+
} else {
770+
hadronicRateBegin = 0.0f;
771+
}
693772
}
694773

695774
for (auto const& trk : tracks) {
@@ -797,12 +876,16 @@ class pidTPCModule
797876
}
798877
LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << bc.timestamp() << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"];
799878
o2::parameters::GRPLHCIFData* grpo = ccdb->template getForTimeStamp<o2::parameters::GRPLHCIFData>(pidTPCopts.cfgPathGrpLhcIf.value, bc.timestamp());
800-
LOG(info) << "Collisions type::" << CollisionSystemType::getCollisionTypeFromGrp(grpo);
801-
collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
802-
if (collsys == CollisionSystemType::kCollSyspp) {
803-
irSource = std::string("T0VTX");
879+
if (grpo) {
880+
LOG(info) << "Collisions type::" << CollisionSystemType::getCollisionTypeFromGrp(grpo);
881+
collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
882+
if (collsys == CollisionSystemType::kCollSyspp) {
883+
irSource = std::string("T0VTX");
884+
} else {
885+
irSource = std::string("ZNC hadronic");
886+
}
804887
} else {
805-
irSource = std::string("ZNC hadronic");
888+
LOGF(info, "No grpo object found. irSource will remain undefined.");
806889
}
807890
response->PrintAll();
808891
}

0 commit comments

Comments
 (0)