Skip to content

Commit 3b7bb2a

Browse files
committed
Feat: use double for intermediate computations
1 parent 501f144 commit 3b7bb2a

File tree

4 files changed

+58
-66
lines changed

4 files changed

+58
-66
lines changed

PWGCF/Femto/Core/closePairRejection.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ class CloseTrackRejection
214214
mDeta = track1.eta() - track2.eta();
215215

216216
for (size_t i = 0; i < TpcRadii.size(); i++) {
217-
auto phistar1 = utils::dphistar(mMagField, TpcRadii[i], mChargeAbsTrack1 * track1.signedPt(), track1.phi());
218-
auto phistar2 = utils::dphistar(mMagField, TpcRadii[i], mChargeAbsTrack2 * track2.signedPt(), track2.phi());
217+
auto phistar1 = phistar(mMagField, TpcRadii[i], mChargeAbsTrack1 * track1.signedPt(), track1.phi());
218+
auto phistar2 = phistar(mMagField, TpcRadii[i], mChargeAbsTrack2 * track2.signedPt(), track2.phi());
219219
if (phistar1 && phistar2) {
220220
mDphistar.at(i) = RecoDecay::constrainAngle(phistar1.value() - phistar2.value(), -o2::constants::math::PI); // constrain angular difference between -pi and pi
221221
mDphistarMask.at(i) = true;
@@ -309,6 +309,16 @@ class CloseTrackRejection
309309
bool isActivated() const { return mIsActivated; }
310310

311311
private:
312+
std::optional<float> phistar(float magfield, float radius, float signedPt, float phi)
313+
{
314+
double arg = 0.3 * (0.1 * magfield) * (0.01 * radius) / (2. * signedPt);
315+
if (std::fabs(arg) <= 1.) {
316+
double phistar = phi - std::asin(arg);
317+
return static_cast<float>(RecoDecay::constrainAngle(phistar));
318+
}
319+
return std::nullopt;
320+
}
321+
312322
o2::framework::HistogramRegistry* mHistogramRegistry = nullptr;
313323
bool mPlotAllRadii = false;
314324
bool mPlotAverage = false;

PWGCF/Femto/Core/collisionBuilder.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class CollisionSelection : public BaseSelection<float, o2::aod::femtodatatypes::
225225
template <typename T>
226226
void setSphericity(T tracks)
227227
{
228-
mSphericity = utils::sphericity(tracks);
228+
mSphericity = computeSphericity(tracks);
229229
}
230230

231231
float getSphericity() const { return mSphericity; }
@@ -312,6 +312,39 @@ class CollisionSelection : public BaseSelection<float, o2::aod::femtodatatypes::
312312
};
313313

314314
protected:
315+
template <typename T>
316+
float computeSphericity(T const& tracks)
317+
{
318+
int minNumberTracks = 2;
319+
double maxSphericity = 2.f;
320+
if (tracks.size() <= minNumberTracks) {
321+
return maxSphericity;
322+
}
323+
// Initialize the transverse momentum tensor components
324+
double sxx = 0.;
325+
double syy = 0.;
326+
double sxy = 0.;
327+
double sumPt = 0.;
328+
// Loop over the tracks to compute the tensor components
329+
for (const auto& track : tracks) {
330+
sxx += (track.px() * track.px()) / track.pt();
331+
syy += (track.py() * track.py()) / track.pt();
332+
sxy += (track.px() * track.py()) / track.pt();
333+
sumPt += track.pt();
334+
}
335+
sxx /= sumPt;
336+
syy /= sumPt;
337+
sxy /= sumPt;
338+
// Compute the eigenvalues (real values)
339+
double lambda1 = ((sxx + syy) + std::sqrt((sxx + syy) * (sxx + syy) - 4. * (sxx * syy - sxy * sxy))) / 2.;
340+
double lambda2 = ((sxx + syy) - std::sqrt((sxx + syy) * (sxx + syy) - 4. * (sxx * syy - sxy * sxy))) / 2.;
341+
if (lambda1 <= 0. || lambda2 <= 0.) {
342+
return maxSphericity;
343+
}
344+
// Compute sphericity
345+
return static_cast<float>(2. * lambda2 / (lambda1 + lambda2));
346+
}
347+
315348
// filter cuts
316349
float mVtxZMin = -12.f;
317350
float mVtxZMax = -12.f;

PWGCF/Femto/Core/femtoUtils.h

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
#ifndef PWGCF_FEMTO_CORE_FEMTOUTILS_H_
1717
#define PWGCF_FEMTO_CORE_FEMTOUTILS_H_
1818

19-
#include "RecoDecay.h"
20-
2119
#include "Common/Core/TableHelper.h"
2220

23-
#include "CommonConstants/MathConstants.h"
2421
#include "CommonConstants/PhysicsConstants.h"
2522
#include "Framework/InitContext.h"
2623

@@ -63,55 +60,16 @@ float itsSignal(T const& track)
6360
auto clSizeLayer6 = (clsizeflag >> (6 * 4)) & 0xf;
6461
int numLayers = 7;
6562
int sumClusterSizes = clSizeLayer0 + clSizeLayer1 + clSizeLayer2 + clSizeLayer3 + clSizeLayer4 + clSizeLayer5 + clSizeLayer6;
66-
float cosLamnda = 1. / std::cosh(track.eta());
67-
return (static_cast<float>(sumClusterSizes) / numLayers) * cosLamnda;
63+
double cosLamnda = 1. / std::cosh(track.eta());
64+
double signal = (static_cast<double>(sumClusterSizes) / numLayers) * cosLamnda;
65+
return static_cast<float>(signal);
6866
};
6967

70-
template <typename T>
71-
float sphericity(T const& tracks)
72-
{
73-
74-
int minNumberTracks = 2;
75-
float maxSphericity = 2.f;
76-
77-
if (tracks.size() <= minNumberTracks) {
78-
return maxSphericity;
79-
}
80-
81-
// Initialize the transverse momentum tensor components
82-
float sxx = 0.f;
83-
float syy = 0.f;
84-
float sxy = 0.f;
85-
float sumPt = 0.f;
86-
87-
// Loop over the tracks to compute the tensor components
88-
for (const auto& track : tracks) {
89-
sxx += (track.px() * track.px()) / track.pt();
90-
syy += (track.py() * track.py()) / track.pt();
91-
sxy += (track.px() * track.py()) / track.pt();
92-
sumPt += track.pt();
93-
}
94-
sxx /= sumPt;
95-
syy /= sumPt;
96-
sxy /= sumPt;
97-
98-
// Compute the eigenvalues (real values)
99-
float lambda1 = ((sxx + syy) + std::sqrt((sxx + syy) * (sxx + syy) - 4 * (sxx * syy - sxy * sxy))) / 2;
100-
float lambda2 = ((sxx + syy) - std::sqrt((sxx + syy) * (sxx + syy) - 4 * (sxx * syy - sxy * sxy))) / 2;
101-
102-
if (lambda1 <= 0.f || lambda2 <= 0.f) {
103-
return maxSphericity;
104-
}
105-
106-
// Compute sphericity
107-
return 2.f * lambda2 / (lambda1 + lambda2);
108-
}
109-
110-
inline float getMass(int pdgCode)
68+
inline double getMass(int pdgCode)
11169
{
11270
// use this function instead of TDatabasePDG to return masses defined in the PhysicsConstants.h header
11371
// this approach saves a lot of memory and important partilces like deuteron are missing in TDatabasePDG anyway
114-
float mass = 0.f;
72+
double mass = 0.f;
11573
// add new particles if necessary here
11674
switch (std::abs(pdgCode)) {
11775
case kPiPlus:
@@ -175,15 +133,6 @@ float qn(T const& col)
175133
return qn;
176134
}
177135

178-
inline std::optional<float> dphistar(float magfield, float radius, float signedPt, float phi)
179-
{
180-
float arg = 0.3f * (0.1f * magfield) * (0.01 * radius) / (2.f * signedPt);
181-
if (std::fabs(arg) <= 1.f) {
182-
return RecoDecay::constrainAngle(phi - std::asin(arg));
183-
}
184-
return std::nullopt;
185-
}
186-
187136
inline bool enableTable(const char* tableName, int userSetting, o2::framework::InitContext& initContext)
188137
{
189138
if (userSetting == 1) {

PWGCF/Femto/Core/pairHistManager.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,14 @@ class PairHistManager
596596

597597
float getKt(ROOT::Math::PtEtaPhiMVector const& part1, ROOT::Math::PtEtaPhiMVector const& part2)
598598
{
599-
auto sum = part1 + part2;
600-
return 0.5 * sum.Pt();
599+
double kt = 0.5 * (part1 + part2).Pt();
600+
return static_cast<float>(kt);
601601
}
602602

603603
float getMt(ROOT::Math::PtEtaPhiMVector const& part1, ROOT::Math::PtEtaPhiMVector const& part2)
604604
{
605605
auto sum = part1 + part2;
606-
float mt = 0;
606+
double mt = 0;
607607
switch (mMtType) {
608608
case modes::TransverseMassType::kAveragePdgMass:
609609
mt = std::hypot(0.5 * sum.Pt(), mAverageMass);
@@ -617,7 +617,7 @@ class PairHistManager
617617
default:
618618
LOG(fatal) << "Invalid transverse mass type, breaking...";
619619
}
620-
return mt;
620+
return static_cast<float>(mt);
621621
}
622622

623623
float getKstar(ROOT::Math::PtEtaPhiMVector const& part1, ROOT::Math::PtEtaPhiMVector const& part2)
@@ -630,16 +630,16 @@ class PairHistManager
630630
// get lorentz boost into pair rest frame
631631
ROOT::Math::Boost boostPrf(sum.BoostToCM());
632632
// boost particle 1 into pair rest frame and calculate its momentum, which has the same value as k*
633-
return boostPrf(particle1Prf).P();
633+
return static_cast<float>(boostPrf(particle1Prf).P());
634634
}
635635

636636
o2::framework::HistogramRegistry* mHistogramRegistry = nullptr;
637637
float mPdgMass1 = 0.f;
638638
float mPdgMass2 = 0.f;
639639

640640
modes::TransverseMassType mMtType = modes::TransverseMassType::kAveragePdgMass;
641-
float mAverageMass = 0.f;
642-
float mReducedMass = 0.f;
641+
double mAverageMass = 0.f;
642+
double mReducedMass = 0.f;
643643

644644
int mAbsCharge1 = 1;
645645
int mAbsCharge2 = 1;

0 commit comments

Comments
 (0)