Skip to content

Commit 9720ad0

Browse files
committed
DRY handronicRate, unfold cryptic variables
1 parent b1935ad commit 9720ad0

1 file changed

Lines changed: 14 additions & 20 deletions

File tree

Common/Tools/PID/pidTPCModule.h

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ class pidTPCModule
450450
{
451451
constexpr int NParticleTypes = 9;
452452
constexpr double OneToKilo = 1.e-3;
453+
constexpr int NanoToOne = 1000000000;
453454
constexpr double MultiplicityNorm = 11000.;
454455
constexpr double HadronicRateNormPp = 1500.;
455456
constexpr double HadronicRateNormAa = 50.;
@@ -566,28 +567,21 @@ class pidTPCModule
566567
int loopCounter = 0;
567568

568569
// To load the Hadronic rate once for each collision
569-
float hadronicRateBegin = 0.;
570570
std::vector<float> hadronicRateForCollision(collisions.size(), 0.0f);
571-
size_t i = 0;
571+
size_t iCollision = 0;
572572
for (const auto& collision : collisions) {
573573
const auto& bc = collision.template bc_as<B>();
574574
if (irSource.compare("") != 0) {
575-
hadronicRateForCollision[i] = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * OneToKilo;
576-
} else {
577-
hadronicRateForCollision[i] = 0.0f;
575+
hadronicRateForCollision[iCollision] = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * OneToKilo;
578576
}
579-
i++;
580-
}
581-
auto bc = bcs.begin();
582-
if (irSource.compare("") != 0) {
583-
hadronicRateBegin = mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * OneToKilo;
584-
} else {
585-
hadronicRateBegin = 0.0f;
577+
++iCollision;
586578
}
579+
const auto bc = bcs.begin();
580+
const float hadronicRateBegin = irSource.compare("") != 0 ? mRateFetcher.fetch(ccdb.service, bc.timestamp(), bc.runNumber(), irSource) * OneToKilo : 0.f;
587581

588582
// Filling a std::vector<float> to be evaluated by the network
589583
// Evaluation on single tracks brings huge overhead: Thus evaluation is done on one large vector
590-
for (int j = 0; j < NParticleTypes; j++) { // Loop over particle number for which network correction is used
584+
for (int jParticleType = 0; jParticleType < NParticleTypes; ++jParticleType) { // Loop over particle number for which network correction is used
591585
for (auto const& trk : tracks) {
592586
if (!trk.hasTPC()) {
593587
continue;
@@ -601,7 +595,7 @@ class pidTPCModule
601595
trackProperties[counterTrackProps + IdxTpcInnerParam] = trk.tpcInnerParam();
602596
trackProperties[counterTrackProps + IdxTgl] = trk.tgl();
603597
trackProperties[counterTrackProps + IdxSigned1Pt] = trk.signed1Pt();
604-
trackProperties[counterTrackProps + IdxMass] = o2::track::pid_constants::sMasses[j];
598+
trackProperties[counterTrackProps + IdxMass] = o2::track::pid_constants::sMasses[jParticleType];
605599
trackProperties[counterTrackProps + IdxMultiplicity] = isGoodTrack ? mults[trk.collisionId()] / MultiplicityNorm : 1.;
606600
trackProperties[counterTrackProps + IdxNClusters] = std::sqrt(nNclNormalization / trk.tpcNClsFound());
607601
if (nnVersion >= OldestNNVersionWithFt0c) {
@@ -620,10 +614,10 @@ class pidTPCModule
620614
const auto startNetworkEval = std::chrono::high_resolution_clock::now();
621615
const float* const outputNetwork = network.evalModel(trackProperties);
622616
const auto stopNetworkEval = std::chrono::high_resolution_clock::now();
623-
durationNetwork += std::chrono::duration<float, std::ratio<1, 1000000000>>(stopNetworkEval - startNetworkEval).count();
624-
for (uint64_t k = 0; k < predictionSize; k += outputDimensions) {
625-
for (int l = 0; l < outputDimensions; l++) {
626-
networkPrediction[k + l + predictionSize * loopCounter] = outputNetwork[k + l];
617+
durationNetwork += std::chrono::duration<float, std::ratio<1, NanoToOne>>(stopNetworkEval - startNetworkEval).count();
618+
for (uint64_t kPrediction = 0; kPrediction < predictionSize; kPrediction += outputDimensions) {
619+
for (int lOutputDim = 0; lOutputDim < outputDimensions; ++lOutputDim) {
620+
networkPrediction[kPrediction + lOutputDim + predictionSize * loopCounter] = outputNetwork[kPrediction + lOutputDim];
627621
}
628622
}
629623

@@ -633,8 +627,8 @@ class pidTPCModule
633627
trackProperties.clear();
634628

635629
const auto stopNetworkTotal = std::chrono::high_resolution_clock::now();
636-
LOG(debug) << "Neural Network for the TPC PID response correction: Time per track (eval ONNX): " << durationNetwork / (size * NParticleTypes) << "ns ; Total time (eval ONNX): " << durationNetwork / 1000000000 << " s";
637-
LOG(debug) << "Neural Network for the TPC PID response correction: Time per track (eval + overhead): " << std::chrono::duration<float, std::ratio<1, 1000000000>>(stopNetworkTotal - startNetworkTotal).count() / (size * NParticleTypes) << "ns ; Total time (eval + overhead): " << std::chrono::duration<float, std::ratio<1, 1000000000>>(stopNetworkTotal - startNetworkTotal).count() / 1000000000 << " s";
630+
LOG(debug) << "Neural Network for the TPC PID response correction: Time per track (eval ONNX): " << durationNetwork / (size * NParticleTypes) << "ns ; Total time (eval ONNX): " << durationNetwork / NanoToOne << " s";
631+
LOG(debug) << "Neural Network for the TPC PID response correction: Time per track (eval + overhead): " << std::chrono::duration<float, std::ratio<1, NanoToOne>>(stopNetworkTotal - startNetworkTotal).count() / (size * NParticleTypes) << "ns ; Total time (eval + overhead): " << std::chrono::duration<float, std::ratio<1, NanoToOne>>(stopNetworkTotal - startNetworkTotal).count() / NanoToOne << " s";
638632

639633
return networkPrediction;
640634
}

0 commit comments

Comments
 (0)