Skip to content

Commit 3f5c239

Browse files
ayatsujiringoayatsuji
andauthored
[PWGDQ] Apply phi-dependent correction to track rotation (#17245)
Co-authored-by: ayatsuji <13807650+asakuratou@user.noreply.gitee.com>
1 parent fc680f6 commit 3f5c239

3 files changed

Lines changed: 95 additions & 3 deletions

File tree

PWGDQ/Core/VarManager.cxx

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <Rtypes.h>
3434
#include <RtypesCore.h>
3535

36+
#include <algorithm>
3637
#include <array>
3738
#include <cmath>
3839
#include <cstddef>
@@ -75,7 +76,9 @@ int VarManager::fgCalibrationType = 0; // 0 - no calibration, 1 -
7576
bool VarManager::fgUseInterpolatedCalibration = true; // use interpolated calibration histograms (default: true)
7677
int VarManager::fgEfficiencyType = 0; // type of efficiency to be applied, default is no efficiency
7778
TObject* VarManager::fgEfficiencyHist = nullptr; // histogram for efficiency
78-
79+
TObject* VarManager::fgPosiPhiMap = nullptr;
80+
TObject* VarManager::fgNegaPhiMap = nullptr;
81+
bool VarManager::fgUsePhiCorrection = false;
7982
//__________________________________________________________________
8083
VarManager::VarManager() : TObject()
8184
{
@@ -453,6 +456,76 @@ void VarManager::FillEfficiency(float* values)
453456
}
454457
}
455458

459+
void VarManager::SetPhiMap(TObject* hposi, TObject* hnega, bool option)
460+
{
461+
fgPosiPhiMap = hposi;
462+
fgNegaPhiMap = hnega;
463+
fgUsePhiCorrection = option;
464+
}
465+
466+
double VarManager::SampleRotationPhi(double pt, double eta, int charge)
467+
{
468+
// each type only alarm once
469+
static bool warnedEmptyPhi = false;
470+
471+
if (!fgUsePhiCorrection) {
472+
return gRandom->Uniform(0., o2::constants::math::TwoPI);
473+
} else {
474+
475+
TH3D* hMap = nullptr;
476+
if (charge > 0) {
477+
hMap = dynamic_cast<TH3D*>(fgPosiPhiMap);
478+
} else {
479+
hMap = dynamic_cast<TH3D*>(fgNegaPhiMap);
480+
}
481+
482+
if (!hMap) {
483+
LOGF(fatal, "Phi map is not a TH3D");
484+
}
485+
// TH3 axes: X=pT, Y=phi, Z=eta
486+
int ptBin = hMap->GetXaxis()->FindBin(pt);
487+
int etaBin = hMap->GetZaxis()->FindBin(eta);
488+
489+
ptBin = std::clamp(ptBin, 1, hMap->GetNbinsX());
490+
etaBin = std::clamp(etaBin, 1, hMap->GetNbinsZ());
491+
492+
TH1D* hPhi = hMap->ProjectionY(
493+
Form("hTRPhi_tmp_charge%d_ptbin%d_etabin%d",
494+
charge, ptBin, etaBin),
495+
ptBin,
496+
ptBin,
497+
etaBin,
498+
etaBin);
499+
500+
if (!hPhi || hPhi->Integral(1, hPhi->GetNbinsX()) <= 0.) {
501+
if (!warnedEmptyPhi) {
502+
LOGF(warn,
503+
"Empty phi distribution for "
504+
"pt=%f, eta=%f, charge=%d, ptBin=%d, etaBin=%d. "
505+
"Falling back to uniform phi sampling.",
506+
pt,
507+
eta,
508+
charge,
509+
ptBin,
510+
etaBin);
511+
512+
warnedEmptyPhi = true;
513+
}
514+
515+
delete hPhi;
516+
517+
return gRandom->Uniform(
518+
0., o2::constants::math::TwoPI);
519+
}
520+
521+
const double phi =
522+
RecoDecay::constrainAngle(hPhi->GetRandom());
523+
524+
delete hPhi;
525+
return phi;
526+
}
527+
}
528+
456529
//__________________________________________________________________
457530
std::tuple<float, float, float, float, float> VarManager::BimodalityCoefficientUnbinned(const std::vector<float>& data)
458531
{

PWGDQ/Core/VarManager.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,8 @@ class VarManager : public TObject
15341534

15351535
static void SetEfficiencyObject(int type, TObject* obj);
15361536
static void FillEfficiency(float* values = nullptr);
1537+
static void SetPhiMap(TObject* h1, TObject* h2, bool option);
1538+
static double SampleRotationPhi(double pT, double eta, int charge);
15371539
static TObject* GetCalibrationObject(CalibObjects calib)
15381540
{
15391541
auto obj = fgCalibs.find(calib);
@@ -1618,6 +1620,10 @@ class VarManager : public TObject
16181620
static int fgEfficiencyType; // type of efficiency correction to apply
16191621
static TObject* fgEfficiencyHist; // histogram for efficiency correction
16201622

1623+
static TObject* fgPosiPhiMap; // phi map to correct track rotation
1624+
static TObject* fgNegaPhiMap;
1625+
static bool fgUsePhiCorrection;
1626+
16211627
VarManager& operator=(const VarManager& c);
16221628
VarManager(const VarManager& c);
16231629
};
@@ -3960,8 +3966,7 @@ void VarManager::FillPairRotation(T1 const& t1, T2 const& t2, float* values)
39603966
m2 = o2::constants::physics::MassMuon;
39613967
}
39623968

3963-
double dphi = gRandom->Uniform(0., o2::constants::math::TwoPI);
3964-
double rotationphi2 = RecoDecay::constrainAngle(t2.phi() + dphi);
3969+
double rotationphi2 = SampleRotationPhi(t2.pt(), t2.eta(), t2.sign());
39653970

39663971
values[kCharge] = t1.sign() + t2.sign();
39673972
values[kCharge1] = t1.sign();

PWGDQ/Tasks/tableReader_withAssoc.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,7 @@ struct AnalysisSameEventPairing {
13621362
Configurable<std::string> GrpLhcIfPath{"grplhcif", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"};
13631363
Configurable<std::string> efficiencyPath{"effHistPath", "Users/z/zhxiong/efficiency", "Path on the CCDB for the efficiency histograms"};
13641364
Configurable<std::string> flowPath{"flowPath", "Users/y/yiping/FlowResolution", "Path to the flow resolution object"};
1365+
Configurable<std::string> phiPath{"phiPath", "Users/h/hxiaoyu/TrackPhi/LHC23", "Path to load phi distribution for track rotation"};
13651366
} fConfigCCDB;
13661367

13671368
struct : ConfigurableGroup {
@@ -1381,6 +1382,7 @@ struct AnalysisSameEventPairing {
13811382
Configurable<bool> useEfficiencyWeighting{"cfgUseEfficiencyWeighting", false, "Apply efficiency weighting to the pairs from CCDB"};
13821383
Configurable<int> efficiencyType{"cfgEfficiencyType", 0, "Type of efficiency to apply from CCDB: 0 no efficiency, 1 pt-cent-costhetastar"};
13831384
Configurable<bool> useFlowReso{"cfgUseFlowReso", false, "Use remote flow information from CCDB"};
1385+
Configurable<bool> usePhiDistribution{"cfgUsePhiDistribution", false, "Use phi distribution to correct track rotation"};
13841386
} fConfigOptions;
13851387
struct : ConfigurableGroup {
13861388
Configurable<bool> applyBDT{"applyBDT", false, "Flag to apply ML selections"};
@@ -1855,6 +1857,18 @@ struct AnalysisSameEventPairing {
18551857
LOGF(fatal, "Flow resolution histograms not available in CCDB at timestamp=%llu", timestamp);
18561858
}
18571859
}
1860+
1861+
if (fConfigOptions.usePhiDistribution) {
1862+
TString PathPhi = fConfigCCDB.phiPath.value;
1863+
TString ccdbPathPhiPosi = Form("%s/hPtPhiPositive", PathPhi.Data());
1864+
TString ccdbPathPhiNega = Form("%s/hPtPhiNegative", PathPhi.Data());
1865+
auto phiPosi = fCCDB->getForTimeStamp<TH3D>(ccdbPathPhiPosi.Data(), timestamp);
1866+
auto phiNega = fCCDB->getForTimeStamp<TH3D>(ccdbPathPhiNega.Data(), timestamp);
1867+
if (phiPosi == nullptr || phiNega == nullptr) {
1868+
LOGF(fatal, "Phi distribution histograms not available in CCDB at timestamp=%llu", timestamp);
1869+
}
1870+
VarManager::SetPhiMap(phiPosi, phiNega, fConfigOptions.usePhiDistribution.value);
1871+
}
18581872
}
18591873

18601874
// Template function to run same event pairing (barrel-barrel, muon-muon, barrel-muon)

0 commit comments

Comments
 (0)