Skip to content

Commit 4b3f0df

Browse files
author
ayatsuji
committed
edit phi distribution
1 parent ec8659b commit 4b3f0df

3 files changed

Lines changed: 57 additions & 105 deletions

File tree

PWGDQ/Core/VarManager.cxx

Lines changed: 42 additions & 93 deletions
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,8 +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-
TH3D* VarManager::fgPosiPhiMap = nullptr;
79-
TH3D* VarManager::fgNegaPhiMap = nullptr;
79+
TObject* VarManager::fgPosiPhiMap = nullptr;
80+
TObject* VarManager::fgNegaPhiMap = nullptr;
81+
bool VarManager::fgUsePhiCorrection = false;
8082
//__________________________________________________________________
8183
VarManager::VarManager() : TObject()
8284
{
@@ -454,127 +456,74 @@ void VarManager::FillEfficiency(float* values)
454456
}
455457
}
456458

457-
void VarManager::SetPhiMap(TH3D* hposi, TH3D* hnega)
459+
void VarManager::SetPhiMap(TObject* hposi, TObject* hnega, bool option)
458460
{
459461
fgPosiPhiMap = hposi;
460462
fgNegaPhiMap = hnega;
463+
fgUsePhiCorrection = option;
461464
}
462465

463466
double VarManager::SampleRotationPhi(double pt, double eta, int charge)
464467
{
465468
// each type only alarm once
466-
static bool warnedInvalidCharge = false;
467-
static bool warnedMissingPositiveMap = false;
468-
static bool warnedMissingNegativeMap = false;
469-
static bool warnedOutOfRange = false;
470469
static bool warnedEmptyPhi = false;
471470

472-
TH3D* hMap = nullptr;
473-
474-
if (charge > 0) {
475-
hMap = fgPosiPhiMap;
476-
477-
if (!hMap) {
478-
if (!warnedMissingPositiveMap) {
479-
LOGF(warn,
480-
"Positive phi correction map is not available. "
481-
"Falling back to uniform phi sampling.");
482-
warnedMissingPositiveMap = true;
483-
}
471+
if (!fgUsePhiCorrection) {
472+
return gRandom->Uniform(0., o2::constants::math::TwoPI);
473+
} else {
484474

485-
return gRandom->Uniform(
486-
0., o2::constants::math::TwoPI);
475+
TH3D* hMap = nullptr;
476+
if (charge > 0) {
477+
hMap = dynamic_cast<TH3D*>(fgPosiPhiMap);
478+
} else {
479+
hMap = dynamic_cast<TH3D*>(fgNegaPhiMap);
487480
}
488-
} else if (charge < 0) {
489-
hMap = fgNegaPhiMap;
490481

491482
if (!hMap) {
492-
if (!warnedMissingNegativeMap) {
493-
LOGF(warn,
494-
"Negative phi correction map is not available. "
495-
"Falling back to uniform phi sampling.");
496-
warnedMissingNegativeMap = true;
497-
}
498-
499-
return gRandom->Uniform(
500-
0., o2::constants::math::TwoPI);
501-
}
502-
} else {
503-
if (!warnedInvalidCharge) {
504-
LOGF(warn,
505-
"Track with charge=0 passed to SampleRotationPhi. "
506-
"Falling back to uniform phi sampling.");
507-
warnedInvalidCharge = true;
508-
}
509-
510-
return gRandom->Uniform(
511-
0., o2::constants::math::TwoPI);
512-
}
513-
514-
// TH3 axes: X=pT, Y=phi, Z=eta
515-
const int ptBin = hMap->GetXaxis()->FindBin(pt);
516-
const int etaBin = hMap->GetZaxis()->FindBin(eta);
517-
518-
if (ptBin < 1 || ptBin > hMap->GetNbinsX() ||
519-
etaBin < 1 || etaBin > hMap->GetNbinsZ()) {
520-
if (!warnedOutOfRange) {
521-
LOGF(warn,
522-
"Track outside phi correction map: "
523-
"pt=%f, eta=%f, charge=%d, ptBin=%d, etaBin=%d. "
524-
"Map ranges: pt=[%f,%f], eta=[%f,%f]. "
525-
"Falling back to uniform phi sampling.",
526-
pt,
527-
eta,
528-
charge,
529-
ptBin,
530-
etaBin,
531-
hMap->GetXaxis()->GetXmin(),
532-
hMap->GetXaxis()->GetXmax(),
533-
hMap->GetZaxis()->GetXmin(),
534-
hMap->GetZaxis()->GetXmax());
535-
536-
warnedOutOfRange = true;
483+
LOGF(fatal, "Phi map is not a TH3D");
537484
}
485+
// TH3 axes: X=pT, Y=phi, Z=eta
486+
int ptBin = hMap->GetXaxis()->FindBin(pt);
487+
int etaBin = hMap->GetZaxis()->FindBin(eta);
538488

539-
return gRandom->Uniform(
540-
0., o2::constants::math::TwoPI);
541-
}
489+
ptBin = std::clamp(ptBin, 1, hMap->GetNbinsX());
490+
etaBin = std::clamp(etaBin, 1, hMap->GetNbinsZ());
542491

543-
TH1D* hPhi = hMap->ProjectionY(
492+
TH1D* hPhi = hMap->ProjectionY(
544493
Form("hTRPhi_tmp_charge%d_ptbin%d_etabin%d",
545494
charge, ptBin, etaBin),
546495
ptBin,
547496
ptBin,
548497
etaBin,
549498
etaBin);
550499

551-
if (!hPhi ||
552-
hPhi->Integral(1, hPhi->GetNbinsX()) <= 0.) {
553-
if (!warnedEmptyPhi) {
554-
LOGF(warn,
555-
"Empty phi distribution for "
556-
"pt=%f, eta=%f, charge=%d, ptBin=%d, etaBin=%d. "
557-
"Falling back to uniform phi sampling.",
558-
pt,
559-
eta,
560-
charge,
561-
ptBin,
562-
etaBin);
563-
564-
warnedEmptyPhi = true;
565-
}
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+
}
566514

567-
delete hPhi;
515+
delete hPhi;
568516

569-
return gRandom->Uniform(
517+
return gRandom->Uniform(
570518
0., o2::constants::math::TwoPI);
571-
}
519+
}
572520

573-
const double phi =
521+
const double phi =
574522
RecoDecay::constrainAngle(hPhi->GetRandom());
575523

576-
delete hPhi;
577-
return phi;
524+
delete hPhi;
525+
return phi;
526+
}
578527
}
579528

580529
//__________________________________________________________________

PWGDQ/Core/VarManager.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,8 +1530,8 @@ class VarManager : public TObject
15301530

15311531
static void SetEfficiencyObject(int type, TObject* obj);
15321532
static void FillEfficiency(float* values = nullptr);
1533-
static void SetPhiMap(TH3D* h1, TH3D* h2);
1534-
static double SampleRotationPhi(double pT, int charge);
1533+
static void SetPhiMap(TObject* h1, TObject* h2, bool option);
1534+
static double SampleRotationPhi(double pT, double eta, int charge);
15351535
static TObject* GetCalibrationObject(CalibObjects calib)
15361536
{
15371537
auto obj = fgCalibs.find(calib);
@@ -1608,14 +1608,18 @@ class VarManager : public TObject
16081608
static o2::vertexing::FwdDCAFitterN<3> fgFitterThreeProngFwd;
16091609
static o2::globaltracking::MatchGlobalFwd mMatching;
16101610

1611-
static std::map<CalibObjects, TObject*> fgCalibs; // map of calibration histograms
1611+
static std::map<CalibObjects, TObject*> fgCalibs; // map of calibration histograms
16121612
static std::array<bool, 4> fgRunTPCPostCalibration; // 0-electron, 1-pion, 2-kaon, 3-proton
1613-
static int fgCalibrationType; // 0 - no calibration, 1 - calibration vs (TPCncls,pIN,eta) typically for pp, 2 - calibration vs (eta,nPV,nLong,tLong) typically for PbPb
1614-
static bool fgUseInterpolatedCalibration; // use interpolated calibration histograms (default: true)
1613+
static int fgCalibrationType; // 0 - no calibration, 1 - calibration vs (TPCncls,pIN,eta) typically for pp, 2 - calibration vs (eta,nPV,nLong,tLong) typically for PbPb
1614+
static bool fgUseInterpolatedCalibration; // use interpolated calibration histograms (default: true)
16151615

16161616
static int fgEfficiencyType; // type of efficiency correction to apply
16171617
static TObject* fgEfficiencyHist; // histogram for efficiency correction
16181618

1619+
static TObject* fgPosiPhiMap; // phi map to correct track rotation
1620+
static TObject* fgNegaPhiMap;
1621+
static bool fgUsePhiCorrection;
1622+
16191623
VarManager& operator=(const VarManager& c);
16201624
VarManager(const VarManager& c);
16211625
};
@@ -3958,8 +3962,7 @@ void VarManager::FillPairRotation(T1 const& t1, T2 const& t2, float* values)
39583962
m2 = o2::constants::physics::MassMuon;
39593963
}
39603964

3961-
double dphi = SampleRotationPhi(t2.pt(),t2.eta(),t2.sign());
3962-
double rotationphi2 = RecoDecay::constrainAngle(t2.phi() + dphi);
3965+
double rotationphi2 = SampleRotationPhi(t2.pt(), t2.eta(), t2.sign());
39633966

39643967
values[kCharge] = t1.sign() + t2.sign();
39653968
values[kCharge1] = t1.sign();

PWGDQ/Tasks/tableReader_withAssoc.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +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"};
1365+
Configurable<std::string> phiPath{"phiPath", "Users/h/hxiaoyu/TrackPhi/LHC23", "Path to load phi distribution for track rotation"};
13661366
} fConfigCCDB;
13671367

13681368
struct : ConfigurableGroup {
@@ -1382,7 +1382,7 @@ struct AnalysisSameEventPairing {
13821382
Configurable<bool> useEfficiencyWeighting{"cfgUseEfficiencyWeighting", false, "Apply efficiency weighting to the pairs from CCDB"};
13831383
Configurable<int> efficiencyType{"cfgEfficiencyType", 0, "Type of efficiency to apply from CCDB: 0 no efficiency, 1 pt-cent-costhetastar"};
13841384
Configurable<bool> useFlowReso{"cfgUseFlowReso", false, "Use remote flow information from CCDB"};
1385-
Configurable<bool> usePhiDistribution{"cfgUsePhiDistribution",false,"Use phi distribution to correct track rotation"};
1385+
Configurable<bool> usePhiDistribution{"cfgUsePhiDistribution", false, "Use phi distribution to correct track rotation"};
13861386
} fConfigOptions;
13871387
struct : ConfigurableGroup {
13881388
Configurable<bool> applyBDT{"applyBDT", false, "Flag to apply ML selections"};
@@ -1860,14 +1860,14 @@ struct AnalysisSameEventPairing {
18601860

18611861
if (fConfigOptions.usePhiDistribution) {
18621862
TString PathPhi = fConfigCCDB.phiPath.value;
1863-
TString ccdbPathPhiPosi = Form("%s/hPtPhiPositive",PathPhi.Data());
1864-
TString ccdbPathPhiNega = Form("%s/hPtPhiNegative",PathPhi.Data());
1863+
TString ccdbPathPhiPosi = Form("%s/hPtPhiPositive", PathPhi.Data());
1864+
TString ccdbPathPhiNega = Form("%s/hPtPhiNegative", PathPhi.Data());
18651865
auto phiPosi = fCCDB->getForTimeStamp<TH3D>(ccdbPathPhiPosi.Data(), timestamp);
18661866
auto phiNega = fCCDB->getForTimeStamp<TH3D>(ccdbPathPhiNega.Data(), timestamp);
18671867
if (phiPosi == nullptr || phiNega == nullptr) {
18681868
LOGF(fatal, "Phi distribution histograms not available in CCDB at timestamp=%llu", timestamp);
18691869
}
1870-
VarManager::SetPhiMap(phiPosi, phiNega);
1870+
VarManager::SetPhiMap(phiPosi, phiNega, fConfigOptions.usePhiDistribution.value);
18711871
}
18721872
}
18731873

0 commit comments

Comments
 (0)