Skip to content

Commit 217c639

Browse files
author
Ana Marin
committed
Follow coding rules
1 parent 4488ea1 commit 217c639

File tree

1 file changed

+50
-25
lines changed

1 file changed

+50
-25
lines changed

Common/Tools/PID/pidTPCModule.h

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
#include <ratio>
5050
#include <string>
5151
#include <vector>
52-
std::string irSource = "-1";
53-
int collsys = -1;
5452

5553
namespace o2::aod
5654
{
@@ -218,6 +216,10 @@ class pidTPCModule
218216
std::vector<int> speciesNetworkFlags = std::vector<int>(9);
219217
std::string networkVersion;
220218

219+
// To get automatically the proper Hadronic Rate
220+
std::string irSource = "";
221+
o2::common::core::CollisionSystemType::collType collsys = o2::common::core::CollisionSystemType::kCollSysUndef;
222+
221223
// Parametrization configuration
222224
bool useCCDBParam = false;
223225

@@ -331,9 +333,9 @@ class pidTPCModule
331333
LOG(info) << " collision type::" << CollisionSystemType::getCollisionTypeFromGrp(grpo);
332334
collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
333335
if (collsys == CollisionSystemType::kCollSyspp) {
334-
irSource = "T0VTX";
336+
irSource = std::string("T0VTX");
335337
} else {
336-
irSource = "ZNC hadronic";
338+
irSource = std::string("ZNC hadronic");
337339
}
338340
response->PrintAll();
339341
}
@@ -411,11 +413,11 @@ class pidTPCModule
411413
metadata["RecoPassName"] = headers["RecoPassName"]; // Force pass number for NN request to match retrieved BB
412414
o2::parameters::GRPLHCIFData* grpo = ccdb->template getForTimeStamp<o2::parameters::GRPLHCIFData>(pidTPCopts.cfgPathGrpLhcIf.value, bc.timestamp());
413415
LOG(info) << "Collision type::" << CollisionSystemType::getCollisionTypeFromGrp(grpo);
414-
int collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
416+
collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
415417
if (collsys == CollisionSystemType::kCollSyspp) {
416-
irSource = "T0VTX";
418+
irSource = std::string("T0VTX");
417419
} else {
418-
irSource = "ZNC hadronic";
420+
irSource = std::string("ZNC hadronic");
419421
}
420422
response->PrintAll();
421423
}
@@ -450,11 +452,21 @@ class pidTPCModule
450452
uint64_t counter_track_props = 0;
451453
int loop_counter = 0;
452454

455+
// To load the Hadronic rate once for each collision
456+
float hadronicRateBegin = 0.;
457+
std::vector<float> hadronicRateForCollision(collisions.size(), 0.0f);
458+
size_t i = 0;
459+
for (const auto& collision : collisions) {
460+
const auto& bc = collision.template bc_as<B>();
461+
hadronicRateForCollision[i] = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3;
462+
i++;
463+
}
464+
auto bc = bcs.begin();
465+
hadronicRateBegin = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3; // kHz
466+
453467
// Filling a std::vector<float> to be evaluated by the network
454468
// Evaluation on single tracks brings huge overhead: Thus evaluation is done on one large vector
455469
for (int i = 0; i < 9; i++) { // Loop over particle number for which network correction is used
456-
float hadronicRate = 0.;
457-
uint64_t timeStamp_bcOld = 0;
458470
for (auto const& trk : tracks) {
459471
if (!trk.hasTPC()) {
460472
continue;
@@ -476,18 +488,19 @@ class pidTPCModule
476488
if (input_dimensions == 8 && networkVersion == "3") {
477489
track_properties[counter_track_props + 6] = trk.has_collision() ? collisions.iteratorAt(trk.collisionId()).ft0cOccupancyInTimeRange() / 60000. : 1.;
478490
if (trk.has_collision()) {
479-
auto trk_bc = (collisions.iteratorAt(trk.collisionId())).template bc_as<B>();
480-
if (trk_bc.timestamp() != timeStamp_bcOld) {
481-
hadronicRate = mRateFetcher.fetch(ccdb.service, trk_bc.timestamp(), trk_bc.runNumber(), irSource) * 1.e-3;
482-
}
483-
timeStamp_bcOld = trk_bc.timestamp();
484491
if (collsys == CollisionSystemType::kCollSyspp) {
485-
track_properties[counter_track_props + 7] = hadronicRate / 1500.;
492+
track_properties[counter_track_props + 7] = hadronicRateForCollision[trk.collisionId()] / 1500.;
486493
} else {
487-
track_properties[counter_track_props + 7] = hadronicRate / 50.;
494+
track_properties[counter_track_props + 7] = hadronicRateForCollision[trk.collisionId()] / 50.;
488495
}
489496
} else {
490-
track_properties[counter_track_props + 7] = 1;
497+
// asign Hadronic Rate at beginning of run if track does not belong to a collision
498+
if (collsys == CollisionSystemType::kCollSyspp) {
499+
track_properties[counter_track_props + 7] = hadronicRateBegin / 1500.;
500+
} else {
501+
track_properties[counter_track_props + 7] = hadronicRateBegin / 50.;
502+
}
503+
491504
}
492505
}
493506
counter_track_props += input_dimensions;
@@ -659,6 +672,21 @@ class pidTPCModule
659672
}
660673
//_______________________________________
661674

675+
// Fill Hadronic rate per collision in case CorrectedDEdx is requested
676+
std::vector<float> hadronicRateForCollision(cols.size(), 0.0f);
677+
float hadronicRateBegin = 0.0f;
678+
if (pidTPCopts.useCorrecteddEdx) {
679+
size_t i = 0;
680+
for (const auto& collision : cols) {
681+
const auto& bc = collision.template bc_as<aod::BCsWithTimestamps>();;
682+
hadronicRateForCollision[i] = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3;
683+
i++;
684+
}
685+
auto bc = bcs.begin();
686+
hadronicRateBegin = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * 1.e-3; // kHz
687+
}
688+
689+
662690
for (auto const& trk : tracks) {
663691
// get the TPC signal to be used in the PID
664692
float tpcSignalToEvaluatePID = trk.tpcSignal();
@@ -687,13 +715,10 @@ class pidTPCModule
687715
if (trk.has_collision()) {
688716
auto collision = cols.iteratorAt(trk.collisionId());
689717
auto bc = collision.template bc_as<aod::BCsWithTimestamps>();
690-
const int runnumber = bc.runNumber();
691-
hadronicRate = mRateFetcher.fetch(ccdb.service, bc.timestamp(), runnumber, "ZNC hadronic") * 1.e-3; // kHz
718+
hadronicRate = hadronicRateForCollision[trk.collisionId()];
692719
occupancy = collision.trackOccupancyInTimeRange();
693720
} else {
694-
auto bc = bcs.begin();
695-
const int runnumber = bc.runNumber();
696-
hadronicRate = mRateFetcher.fetch(ccdb.service, bc.timestamp(), runnumber, "ZNC hadronic") * 1.e-3; // kHz
721+
hadronicRate = hadronicRateBegin;
697722
occupancy = 0;
698723
}
699724

@@ -764,11 +789,11 @@ class pidTPCModule
764789
LOG(info) << "Successfully retrieved TPC PID object from CCDB for timestamp " << bc.timestamp() << ", period " << headers["LPMProductionTag"] << ", recoPass " << headers["RecoPassName"];
765790
o2::parameters::GRPLHCIFData* grpo = ccdb->template getForTimeStamp<o2::parameters::GRPLHCIFData>(pidTPCopts.cfgPathGrpLhcIf.value, bc.timestamp());
766791
LOG(info) << "Collisions type::" << CollisionSystemType::getCollisionTypeFromGrp(grpo);
767-
int collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
792+
collsys = CollisionSystemType::getCollisionTypeFromGrp(grpo);
768793
if (collsys == CollisionSystemType::kCollSyspp) {
769-
irSource = "T0VTX";
794+
irSource = std::string("T0VTX");
770795
} else {
771-
irSource = "ZNC hadronic";
796+
irSource = std::string("ZNC hadronic");
772797
}
773798
response->PrintAll();
774799
}

0 commit comments

Comments
 (0)