Skip to content

Commit

Permalink
Using inverse to speed up calculations
Browse files Browse the repository at this point in the history
- renaming variable
- changing std::pow(10, -9) -> 1.E-9
  • Loading branch information
matthias-kleiner committed Jan 22, 2023
1 parent 3d89a4d commit ab773d0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Detectors/TOF/workflow/src/TOFIntegrateClusterSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class TOFIntegrateClusters : public Task
const double orbitLength = o2::tof::Geo::BC_TIME_INPS * o2::constants::lhc::LHCMaxBunches;
const double maxTimeTF = orbitLength * nHBFPerTF; // maximum time if a TF in PS
const double sliceWidthPS = maxTimeTF / mNSlicesTF; // integration time
const int nSlices = maxTimeTF / sliceWidthPS; // number of slices a TF is divided into
const double sliceWidthMS = sliceWidthPS * 1.E-9;
const int nSlices = maxTimeTF / sliceWidthPS; // number of slices a TF is divided into
const double sliceWidthPSinv = 1. / sliceWidthPS;
const float sliceWidthMSinv = 1. / float(sliceWidthMS);

// storage for integrated currents
o2::pmr::vector<float> iTOFCNCl(nSlices);
Expand All @@ -56,7 +59,7 @@ class TOFIntegrateClusters : public Task
const auto clusters = pc.inputs().get<gsl::span<o2::tof::Cluster>>("tofcluster");
for (size_t iCl = 0; iCl < clusters.size(); ++iCl) {
const double timePS = clusters[iCl].getTime();
const unsigned int sliceInTF = timePS / sliceWidthPS;
const unsigned int sliceInTF = timePS * sliceWidthPSinv;
if (sliceInTF < mNSlicesTF) {
++iTOFCNCl[sliceInTF]; // count number of cluster
iTOFCqTot[sliceInTF] += clusters[iCl].getTot(); // integrated charge
Expand All @@ -66,10 +69,8 @@ class TOFIntegrateClusters : public Task
}

// normalize currents to integration time
const double sliceWidthMS = sliceWidthPS * std::pow(10, -9);
const float norm = 1. / float(sliceWidthMS);
std::transform(iTOFCNCl.begin(), iTOFCNCl.end(), iTOFCNCl.begin(), [norm](float& val) { return val * norm; });
std::transform(iTOFCqTot.begin(), iTOFCqTot.end(), iTOFCqTot.begin(), [norm](float& val) { return val * norm; });
std::transform(iTOFCNCl.begin(), iTOFCNCl.end(), iTOFCNCl.begin(), [sliceWidthMSinv](float& val) { return val * sliceWidthMSinv; });
std::transform(iTOFCqTot.begin(), iTOFCqTot.end(), iTOFCqTot.begin(), [sliceWidthMSinv](float& val) { return val * sliceWidthMSinv; });

sendOutput(pc.outputs(), std::move(iTOFCNCl), std::move(iTOFCqTot));
}
Expand Down

0 comments on commit ab773d0

Please sign in to comment.