Skip to content

Commit 0688089

Browse files
authored
[PWGEM] PhotonMeson: Add second iteration of NonLin for PCM (#15073)
1 parent f5c6baf commit 0688089

File tree

7 files changed

+448
-231
lines changed

7 files changed

+448
-231
lines changed

PWGEM/PhotonMeson/Core/EMCPhotonCut.h

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ static constexpr bool HasPrimaries = !std::is_same_v<TPrimaries, std::nullptr_t>
4141
template <typename TSecondaries>
4242
static constexpr bool HasSecondaries = !std::is_same_v<TSecondaries, std::nullptr_t>;
4343

44+
template <typename T>
45+
concept IsNonLinIterator = o2::soa::is_iterator<T> && requires(T t) {
46+
// Check that the *elements* of the container have the required methods:
47+
{ t.corrE() } -> std::same_as<float>;
48+
{ t.corrPt() } -> std::same_as<float>;
49+
};
50+
51+
template <typename T>
52+
concept IsNonLinContainer = o2::soa::is_table<T> && requires(T t) {
53+
// Check that the *elements* of the container have the required methods:
54+
{ t.begin().corrE() } -> std::same_as<float>;
55+
{ t.begin().corrPt() } -> std::same_as<float>;
56+
};
57+
4458
template <typename T>
4559
concept IsTrackIterator = o2::soa::is_iterator<T> && requires(T t) {
4660
// Check that the *elements* of the container have the required methods:
@@ -114,7 +128,7 @@ class EMCPhotonCut : public TNamed
114128

115129
static const char* mCutNames[static_cast<int>(EMCPhotonCuts::kNCuts)];
116130

117-
constexpr auto getClusterId(o2::soa::is_iterator auto const& t) const
131+
static constexpr auto getClusterId(o2::soa::is_iterator auto const& t)
118132
{
119133
if constexpr (requires { t.emEmcClusterId(); }) {
120134
return t.emEmcClusterId();
@@ -384,7 +398,11 @@ class EMCPhotonCut : public TNamed
384398
return cluster.definition() == mDefinition;
385399

386400
case EMCPhotonCuts::kEnergy:
387-
return cluster.e() > mMinE;
401+
if constexpr (IsNonLinIterator<std::decay_t<decltype(cluster)>>) {
402+
return cluster.corrE() > mMinE;
403+
} else {
404+
return cluster.e() > mMinE;
405+
}
388406

389407
case EMCPhotonCuts::kNCell:
390408
return cluster.nCells() >= mMinNCell;
@@ -478,7 +496,11 @@ class EMCPhotonCut : public TNamed
478496
return cluster.definition() == mDefinition;
479497

480498
case EMCPhotonCuts::kEnergy:
481-
return cluster.e() > mMinE;
499+
if constexpr (IsNonLinIterator<Cluster>) {
500+
return cluster.corrE() > mMinE;
501+
} else {
502+
return cluster.e() > mMinE;
503+
}
482504

483505
case EMCPhotonCuts::kNCell:
484506
return cluster.nCells() >= mMinNCell;
@@ -496,7 +518,9 @@ class EMCPhotonCut : public TNamed
496518
auto dPhi = std::fabs(emcmatchedtrack.deltaPhi());
497519
auto trackpt = emcmatchedtrack.trackPt();
498520
auto trackp = emcmatchedtrack.trackP();
499-
bool result = (dEta > GetTrackMatchingEta(trackpt)) || (dPhi > GetTrackMatchingPhi(trackpt)) || (cluster.e() / trackp >= mMinEoverP);
521+
bool result = (dEta > GetTrackMatchingEta(trackpt)) ||
522+
(dPhi > GetTrackMatchingPhi(trackpt)) ||
523+
(cluster.e() / trackp >= mMinEoverP);
500524
if (!result) {
501525
return false;
502526
}
@@ -506,7 +530,7 @@ class EMCPhotonCut : public TNamed
506530
auto dPhis = cluster.deltaPhi(); // std:vector<float>
507531
auto trackspt = cluster.trackpt(); // std:vector<float>
508532
auto tracksp = cluster.trackp(); // std:vector<float>
509-
int ntrack = tracksp.size();
533+
int ntrack = trackspt.size();
510534
for (int itr = 0; itr < ntrack; itr++) {
511535
float dEta = std::fabs(dEtas[itr]);
512536
float dPhi = std::fabs(dPhis[itr]);
@@ -526,8 +550,8 @@ class EMCPhotonCut : public TNamed
526550
auto dEta = std::fabs(emcmatchedtrack.deltaEta());
527551
auto dPhi = std::fabs(emcmatchedtrack.deltaPhi());
528552
auto trackpt = emcmatchedtrack.trackPt();
529-
auto trackp = emcmatchedtrack.trackP();
530-
bool result = (dEta > GetSecTrackMatchingEta(trackpt)) || (dPhi > GetSecTrackMatchingPhi(trackpt)) || (cluster.e() / trackp >= mMinEoverP);
553+
bool result = (dEta > GetSecTrackMatchingEta(trackpt)) ||
554+
(dPhi > GetSecTrackMatchingPhi(trackpt));
531555
if (!result) {
532556
return false;
533557
}
@@ -536,8 +560,7 @@ class EMCPhotonCut : public TNamed
536560
auto dEtas = cluster.deltaEtaSec(); // std:vector<float>
537561
auto dPhis = cluster.deltaPhiSec(); // std:vector<float>
538562
auto trackspt = cluster.trackptSec(); // std:vector<float>
539-
auto tracksp = cluster.trackpSec(); // std:vector<float>
540-
int ntrack = tracksp.size();
563+
int ntrack = trackspt.size();
541564
for (int itr = 0; itr < ntrack; itr++) {
542565
float dEta = std::fabs(dEtas[itr]);
543566
float dPhi = std::fabs(dPhis[itr]);

PWGEM/PhotonMeson/Core/EMNonLin.cxx

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,52 @@
1515

1616
#include "EMNonLin.h"
1717

18-
#include <cmath>
18+
#include <algorithm>
1919

2020
using namespace o2::pwgem::nonlin;
2121

22-
float EMNonLin::getCorrectionFactor(float inputCalibValue, PhotonType photonType, float cent)
22+
float EMNonLin::getCorrectionFactor(float x, const Context& ctx)
2323
{
24-
float param0 = 0, param1 = 0, param2 = 0, val = 1.f;
25-
switch (photonType) {
26-
case PhotonType::kEMC:
27-
if (cent >= 30 && cent <= 40) {
28-
param0 = -5.33426e-01f;
29-
param1 = 1.40144e-02f;
30-
param2 = -5.24434e-01f;
31-
} else {
32-
param0 = 0.f;
33-
param1 = 0.f;
34-
param2 = 0.f;
35-
}
36-
break;
37-
case PhotonType::kPCM:
38-
if (cent >= 0 && cent <= 100) {
39-
param0 = 10.7203f;
40-
param1 = 0.0383968f;
41-
param2 = 10.6025f;
42-
} else {
43-
param0 = 0.f;
44-
param1 = 0.f;
45-
param2 = 0.f;
46-
}
47-
break;
48-
case PhotonType::kPHOS:
49-
param0 = 0.f;
50-
param1 = 0.f;
51-
param2 = 0.f;
24+
if (!ctx.params || x == 0.f) [[unlikely]] {
25+
return x;
26+
}
27+
28+
float val = x;
29+
// safety measure
30+
int maxIter = std::min(ctx.nIter, MaxIter - 1);
31+
32+
for (int i = 0; i <= maxIter; ++i) {
33+
if (val == 0.f) {
5234
break;
35+
}
36+
37+
float inv = 1.f / val;
38+
val *= (1.f + ctx.params[i].par0 * inv +
39+
ctx.params[i].par1 * inv * inv) /
40+
(1.f + ctx.params[i].par2 * inv);
5341
}
5442

55-
val = (1.f + param0 / inputCalibValue + param1 / std::pow(inputCalibValue, 2.f)) / (1.f + param2 / inputCalibValue);
5643
return val;
5744
}
45+
46+
const EMNonLin::NonLinParams* EMNonLin::resolveParams(PhotonType type, float cent)
47+
{
48+
int centBin = static_cast<int>(cent / 10.f);
49+
if (centBin < 0)
50+
centBin = 0;
51+
if (centBin >= CentBins)
52+
centBin = CentBins - 1;
53+
54+
return &kNonLinTable[static_cast<int>(type)][centBin][0];
55+
}
56+
57+
const EMNonLin::NonLinParams* EMNonLin::resolveParamsMC(PhotonType type, float cent)
58+
{
59+
int centBin = static_cast<int>(cent / 10.f);
60+
if (centBin < 0)
61+
centBin = 0;
62+
if (centBin >= CentBins)
63+
centBin = CentBins - 1;
64+
65+
return &kNonLinTableMC[static_cast<int>(type)][centBin][0];
66+
}

0 commit comments

Comments
 (0)