Skip to content

Commit a23529e

Browse files
authored
use float pi constants (#266)
1 parent a821bc1 commit a23529e

4 files changed

Lines changed: 52 additions & 45 deletions

File tree

PWGCF/Core/CorrelationContainer.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
#include "TF1.h"
2929
#include "THn.h"
3030
#include "Framework/HistogramSpec.h"
31+
#include "CommonConstants/MathConstants.h"
3132

33+
using namespace o2;
3234
using namespace o2::framework;
35+
using namespace o2::constants::math;
3336

3437
ClassImp(CorrelationContainer);
3538

@@ -486,9 +489,6 @@ TH2* CorrelationContainer::getPerTriggerYield(CorrelationContainer::CFStep step,
486489
THnBase* trackSameAll = nullptr;
487490
TH2* eventSameAll = nullptr;
488491

489-
Long64_t totalEvents = 0;
490-
Int_t nCorrelationFunctions = 0;
491-
492492
getHistsZVtxMult(step, ptTriggerMin, ptTriggerMax, &trackSameAll, &eventSameAll);
493493

494494
TAxis* multAxis = trackSameAll->GetAxis(3);
@@ -1498,8 +1498,8 @@ void CorrelationContainer::symmetrizepTBins()
14981498
for (Int_t i4 = 1; i4 <= target->GetAxis(4)->GetNbins(); i4++) {
14991499
Int_t binEta = target->GetAxis(0)->FindBin(-target->GetAxis(0)->GetBinCenter(i0));
15001500
Double_t phi = -target->GetAxis(4)->GetBinCenter(i4);
1501-
if (phi < -M_PI / 2) {
1502-
phi += M_PI * 2;
1501+
if (phi < -PIHalf) {
1502+
phi += TwoPI;
15031503
}
15041504
Int_t binPhi = target->GetAxis(4)->FindBin(phi);
15051505

PWGCF/Core/PairCuts.h

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
#include "Framework/Logger.h"
1818
#include "Framework/HistogramRegistry.h"
19+
#include "CommonConstants/MathConstants.h"
1920

2021
// Functions which cut on particle pairs (decays, conversions, two-track cuts)
2122
//
2223
// Author: Jan Fiete Grosse-Oetringhaus
2324

2425
using namespace o2;
2526
using namespace o2::framework;
27+
using namespace constants::math;
2628

2729
class PairCuts
2830
{
@@ -266,41 +268,41 @@ double PairCuts::getInvMassSquaredFast(T const& track1, double m0_1, T const& tr
266268
const float pt1 = track1.pt();
267269
const float pt2 = track2.pt();
268270

269-
float tantheta1 = 1e10;
271+
float tantheta1 = 1e10f;
270272

271-
if (eta1 < -1e-10 || eta1 > 1e-10) {
272-
float expTmp = 1.0 - eta1 + eta1 * eta1 / 2 - eta1 * eta1 * eta1 / 6 + eta1 * eta1 * eta1 * eta1 / 24;
273-
tantheta1 = 2.0 * expTmp / (1.0 - expTmp * expTmp);
273+
if (eta1 < -1e-10f || eta1 > 1e-10f) {
274+
float expTmp = 1.0f - eta1 + eta1 * eta1 / 2.0f - eta1 * eta1 * eta1 / 6.0f + eta1 * eta1 * eta1 * eta1 / 24.0f;
275+
tantheta1 = 2.0f * expTmp / (1.0f - expTmp * expTmp);
274276
}
275277

276-
float tantheta2 = 1e10;
277-
if (eta2 < -1e-10 || eta2 > 1e-10) {
278-
float expTmp = 1.0 - eta2 + eta2 * eta2 / 2 - eta2 * eta2 * eta2 / 6 + eta2 * eta2 * eta2 * eta2 / 24;
279-
tantheta2 = 2.0 * expTmp / (1.0 - expTmp * expTmp);
278+
float tantheta2 = 1e10f;
279+
if (eta2 < -1e-10f || eta2 > 1e-10f) {
280+
float expTmp = 1.0f - eta2 + eta2 * eta2 / 2.0f - eta2 * eta2 * eta2 / 6.0f + eta2 * eta2 * eta2 * eta2 / 24.0f;
281+
tantheta2 = 2.0f * expTmp / (1.0f - expTmp * expTmp);
280282
}
281283

282-
float e1squ = m0_1 * m0_1 + pt1 * pt1 * (1.0 + 1.0 / tantheta1 / tantheta1);
283-
float e2squ = m0_2 * m0_2 + pt2 * pt2 * (1.0 + 1.0 / tantheta2 / tantheta2);
284+
float e1squ = m0_1 * m0_1 + pt1 * pt1 * (1.0f + 1.0f / tantheta1 / tantheta1);
285+
float e2squ = m0_2 * m0_2 + pt2 * pt2 * (1.0f + 1.0f / tantheta2 / tantheta2);
284286

285287
// fold onto 0...pi
286288
float deltaPhi = std::fabs(phi1 - phi2);
287-
while (deltaPhi > M_PI * 2) {
288-
deltaPhi -= M_PI * 2;
289+
while (deltaPhi > TwoPI) {
290+
deltaPhi -= TwoPI;
289291
}
290-
if (deltaPhi > M_PI) {
291-
deltaPhi = M_PI * 2 - deltaPhi;
292+
if (deltaPhi > PI) {
293+
deltaPhi = TwoPI - deltaPhi;
292294
}
293295

294296
float cosDeltaPhi = 0;
295-
if (deltaPhi < M_PI / 3) {
297+
if (deltaPhi < PI / 3.0f) {
296298
cosDeltaPhi = 1.0 - deltaPhi * deltaPhi / 2 + deltaPhi * deltaPhi * deltaPhi * deltaPhi / 24;
297-
} else if (deltaPhi < 2 * M_PI / 3) {
298-
cosDeltaPhi = -(deltaPhi - M_PI / 2) + 1.0 / 6 * std::pow((deltaPhi - M_PI / 2), 3);
299+
} else if (deltaPhi < 2.0f * PI / 3.0f) {
300+
cosDeltaPhi = -(deltaPhi - PI / 2) + 1.0 / 6 * std::pow((deltaPhi - PI / 2), 3);
299301
} else {
300-
cosDeltaPhi = -1.0 + 1.0 / 2.0 * (deltaPhi - M_PI) * (deltaPhi - M_PI) - 1.0 / 24.0 * std::pow(deltaPhi - M_PI, 4);
302+
cosDeltaPhi = -1.0f + 1.0f / 2.0f * (deltaPhi - PI) * (deltaPhi - PI) - 1.0f / 24.0f * std::pow(deltaPhi - PI, 4.0f);
301303
}
302304

303-
double mass2 = m0_1 * m0_1 + m0_2 * m0_2 + 2 * (std::sqrt(e1squ * e2squ) - (pt1 * pt2 * (cosDeltaPhi + 1.0 / tantheta1 / tantheta2)));
305+
double mass2 = m0_1 * m0_1 + m0_2 * m0_2 + 2.0f * (std::sqrt(e1squ * e2squ) - (pt1 * pt2 * (cosDeltaPhi + 1.0f / tantheta1 / tantheta2)));
304306

305307
//LOGF(debug, "%f %f %f %f %f %f %f %f %f", pt1, eta1, phi1, pt2, eta2, phi2, m0_1, m0_2, mass2);
306308

@@ -324,14 +326,14 @@ float PairCuts::getDPhiStar(T const& track1, T const& track2, float radius, int
324326

325327
float dphistar = phi1 - phi2 - charge1 * std::asin(0.015 * magField * radius / pt1) + charge2 * std::asin(0.015 * magField * radius / pt2);
326328

327-
if (dphistar > M_PI) {
328-
dphistar = M_PI * 2 - dphistar;
329+
if (dphistar > PI) {
330+
dphistar = TwoPI - dphistar;
329331
}
330-
if (dphistar < -M_PI) {
331-
dphistar = -M_PI * 2 - dphistar;
332+
if (dphistar < -PI) {
333+
dphistar = -TwoPI - dphistar;
332334
}
333-
if (dphistar > M_PI) { // might look funny but is needed
334-
dphistar = M_PI * 2 - dphistar;
335+
if (dphistar > PI) { // might look funny but is needed
336+
dphistar = TwoPI - dphistar;
335337
}
336338

337339
return dphistar;

PWGCF/Tasks/correlations.cxx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "Framework/StepTHn.h"
1717
#include "Framework/HistogramRegistry.h"
1818
#include "Framework/RunningWorkflowInfo.h"
19+
#include "CommonConstants/MathConstants.h"
1920

2021
#include "Common/DataModel/EventSelection.h"
2122
#include "Common/DataModel/TrackSelectionTables.h"
@@ -44,6 +45,7 @@ using Hash = Hashes::iterator;
4445
using namespace o2;
4546
using namespace o2::framework;
4647
using namespace o2::framework::expressions;
48+
using namespace constants::math;
4749

4850
#define O2_DEFINE_CONFIGURABLE(NAME, TYPE, DEFAULT, HELP) Configurable<TYPE> NAME{#NAME, DEFAULT, HELP};
4951

@@ -73,7 +75,7 @@ struct CorrelationTask {
7375
O2_DEFINE_CONFIGURABLE(cfgNoMixedEvents, int, 5, "Number of mixed events per event")
7476

7577
ConfigurableAxis axisVertex{"axisVertex", {7, -7, 7}, "vertex axis for histograms"};
76-
ConfigurableAxis axisDeltaPhi{"axisDeltaPhi", {72, -M_PI / 2, M_PI / 2 * 3}, "delta phi axis for histograms"};
78+
ConfigurableAxis axisDeltaPhi{"axisDeltaPhi", {72, -PIHalf, PIHalf * 3}, "delta phi axis for histograms"};
7779
ConfigurableAxis axisDeltaEta{"axisDeltaEta", {40, -2, 2}, "delta eta axis for histograms"};
7880
ConfigurableAxis axisPtTrigger{"axisPtTrigger", {VARIABLE_WIDTH, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, 10.0}, "pt trigger axis for histograms"};
7981
ConfigurableAxis axisPtAssoc{"axisPtAssoc", {VARIABLE_WIDTH, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0}, "pt associated axis for histograms"};
@@ -254,11 +256,11 @@ struct CorrelationTask {
254256
}
255257

256258
float deltaPhi = track1.phi() - track2.phi();
257-
if (deltaPhi > 1.5 * M_PI) {
258-
deltaPhi -= M_PI * 2;
259+
if (deltaPhi > 1.5f * PI) {
260+
deltaPhi -= TwoPI;
259261
}
260-
if (deltaPhi < -0.5 * M_PI) {
261-
deltaPhi += M_PI * 2;
262+
if (deltaPhi < -PIHalf) {
263+
deltaPhi += TwoPI;
262264
}
263265

264266
target->getPairHist()->Fill(CorrelationContainer::kCFStepReconstructed,
@@ -454,11 +456,11 @@ struct CorrelationTask {
454456
}
455457

456458
float deltaPhi = track1.phi() - track2.phi();
457-
if (deltaPhi > 1.5 * M_PI) {
458-
deltaPhi -= M_PI * 2;
459+
if (deltaPhi > 1.5f * PI) {
460+
deltaPhi -= TwoPI;
459461
}
460-
if (deltaPhi < -0.5 * M_PI) {
461-
deltaPhi += M_PI * 2;
462+
if (deltaPhi < -PIHalf) {
463+
deltaPhi += TwoPI;
462464
}
463465

464466
same->getPairHist()->Fill(CorrelationContainer::kCFStepReconstructed,

Tutorials/src/mcHistograms.cxx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515

1616
#include "Framework/runDataProcessing.h"
1717
#include "Framework/AnalysisTask.h"
18+
#include "CommonConstants/MathConstants.h"
19+
1820
#include "Common/Core/MC.h"
1921

2022
using namespace o2;
2123
using namespace o2::framework;
24+
using namespace constants::math;
2225

2326
// Simple access to collision
2427
struct VertexDistribution {
@@ -34,7 +37,7 @@ struct VertexDistribution {
3437

3538
// Grouping between MC particles and collisions
3639
struct AccessMcData {
37-
OutputObj<TH1F> phiH{TH1F("phi", "phi", 100, 0., 2. * M_PI)};
40+
OutputObj<TH1F> phiH{TH1F("phi", "phi", 100, 0., TwoPI)};
3841
OutputObj<TH1F> etaH{TH1F("eta", "eta", 102, -2.01, 2.01)};
3942

4043
// group according to McCollisions
@@ -58,7 +61,7 @@ struct AccessMcData {
5861
// Access from tracks to MC particle
5962
struct AccessMcTruth {
6063
OutputObj<TH1F> etaDiff{TH1F("etaDiff", ";eta_{MC} - eta_{Rec}", 100, -2, 2)};
61-
OutputObj<TH1F> phiDiff{TH1F("phiDiff", ";phi_{MC} - phi_{Rec}", 100, -M_PI, M_PI)};
64+
OutputObj<TH1F> phiDiff{TH1F("phiDiff", ";phi_{MC} - phi_{Rec}", 100, -PI, PI)};
6265

6366
// group according to reconstructed Collisions
6467
void process(soa::Join<aod::Collisions, aod::McCollisionLabels>::iterator const& collision, soa::Join<aod::Tracks, aod::McTrackLabels> const& tracks,
@@ -75,11 +78,11 @@ struct AccessMcTruth {
7578
if (MC::isPhysicalPrimary(particle)) {
7679
etaDiff->Fill(particle.eta() - track.eta());
7780
auto delta = particle.phi() - track.phi();
78-
if (delta > M_PI) {
79-
delta -= 2 * M_PI;
81+
if (delta > PI) {
82+
delta -= TwoPI;
8083
}
81-
if (delta < -M_PI) {
82-
delta += 2 * M_PI;
84+
if (delta < -PI) {
85+
delta += TwoPI;
8386
}
8487
phiDiff->Fill(delta);
8588
}

0 commit comments

Comments
 (0)