|
33 | 33 | #include <Framework/AnalysisDataModel.h> |
34 | 34 | #include <Framework/AnalysisHelpers.h> |
35 | 35 | #include <Framework/Configurable.h> |
| 36 | +#include <Framework/RunningWorkflowInfo.h> |
36 | 37 | #include <Framework/runDataProcessing.h> |
37 | 38 | #include <ReconstructionDataFormats/PID.h> |
38 | 39 |
|
@@ -91,7 +92,8 @@ struct pidTPCConfigurables : o2::framework::ConfigurableGroup { |
91 | 92 | // Parameters for loading network from a file / downloading the file |
92 | 93 | o2::framework::Configurable<bool> useNetworkCorrection{"useNetworkCorrection", 0, "(bool) Wether or not to use the network correction for the TPC dE/dx signal"}; |
93 | 94 | 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"}; |
95 | 97 | 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"}; |
96 | 98 | o2::framework::Configurable<std::string> networkPathCCDB{"networkPathCCDB", "Analysis/PID/TPC/ML", "Path on CCDB"}; |
97 | 99 | 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 |
244 | 246 | LOGF(info, "***************************************************"); |
245 | 247 | } |
246 | 248 |
|
| 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 | + |
247 | 302 | // initialize PID response |
248 | 303 | response = new o2::pid::tpc::Response(); |
249 | 304 |
|
@@ -330,12 +385,16 @@ class pidTPCModule |
330 | 385 | LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << time << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"]; |
331 | 386 | metadata["RecoPassName"] = headers["RecoPassName"]; // Force pass number for NN request to match retrieved BB |
332 | 387 | 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 | + } |
337 | 396 | } else { |
338 | | - irSource = std::string("ZNC hadronic"); |
| 397 | + LOGF(info, "No grpo object found. irSource will remain undefined."); |
339 | 398 | } |
340 | 399 | response->PrintAll(); |
341 | 400 | } |
@@ -412,12 +471,16 @@ class pidTPCModule |
412 | 471 | LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << bc.timestamp() << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"]; |
413 | 472 | metadata["RecoPassName"] = headers["RecoPassName"]; // Force pass number for NN request to match retrieved BB |
414 | 473 | 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 | + } |
419 | 482 | } else { |
420 | | - irSource = std::string("ZNC hadronic"); |
| 483 | + LOGF(info, "No grpo object found. irSource will remain undefined."); |
421 | 484 | } |
422 | 485 | response->PrintAll(); |
423 | 486 | } |
@@ -458,11 +521,19 @@ class pidTPCModule |
458 | 521 | size_t i = 0; |
459 | 522 | for (const auto& collision : collisions) { |
460 | 523 | 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 | + } |
462 | 529 | i++; |
463 | 530 | } |
464 | 531 | 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 | + } |
466 | 537 |
|
467 | 538 | // Filling a std::vector<float> to be evaluated by the network |
468 | 539 | // Evaluation on single tracks brings huge overhead: Thus evaluation is done on one large vector |
@@ -685,11 +756,19 @@ class pidTPCModule |
685 | 756 | size_t i = 0; |
686 | 757 | for (const auto& collision : cols) { |
687 | 758 | 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 | + } |
689 | 764 | i++; |
690 | 765 | } |
691 | 766 | 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 | + } |
693 | 772 | } |
694 | 773 |
|
695 | 774 | for (auto const& trk : tracks) { |
@@ -797,12 +876,16 @@ class pidTPCModule |
797 | 876 | } |
798 | 877 | LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << bc.timestamp() << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"]; |
799 | 878 | 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 | + } |
804 | 887 | } else { |
805 | | - irSource = std::string("ZNC hadronic"); |
| 888 | + LOGF(info, "No grpo object found. irSource will remain undefined."); |
806 | 889 | } |
807 | 890 | response->PrintAll(); |
808 | 891 | } |
|
0 commit comments