Skip to content

Commit ec8659b

Browse files
author
ayatsuji
committed
Add phi-map correction for track rotation
1 parent 38ef137 commit ec8659b

3 files changed

Lines changed: 142 additions & 2 deletions

File tree

PWGDQ/Core/VarManager.cxx

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ int VarManager::fgCalibrationType = 0; // 0 - no calibration, 1 -
7575
bool VarManager::fgUseInterpolatedCalibration = true; // use interpolated calibration histograms (default: true)
7676
int VarManager::fgEfficiencyType = 0; // type of efficiency to be applied, default is no efficiency
7777
TObject* VarManager::fgEfficiencyHist = nullptr; // histogram for efficiency
78-
78+
TH3D* VarManager::fgPosiPhiMap = nullptr;
79+
TH3D* VarManager::fgNegaPhiMap = nullptr;
7980
//__________________________________________________________________
8081
VarManager::VarManager() : TObject()
8182
{
@@ -453,6 +454,129 @@ void VarManager::FillEfficiency(float* values)
453454
}
454455
}
455456

457+
void VarManager::SetPhiMap(TH3D* hposi, TH3D* hnega)
458+
{
459+
fgPosiPhiMap = hposi;
460+
fgNegaPhiMap = hnega;
461+
}
462+
463+
double VarManager::SampleRotationPhi(double pt, double eta, int charge)
464+
{
465+
// 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;
470+
static bool warnedEmptyPhi = false;
471+
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+
}
484+
485+
return gRandom->Uniform(
486+
0., o2::constants::math::TwoPI);
487+
}
488+
} else if (charge < 0) {
489+
hMap = fgNegaPhiMap;
490+
491+
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;
537+
}
538+
539+
return gRandom->Uniform(
540+
0., o2::constants::math::TwoPI);
541+
}
542+
543+
TH1D* hPhi = hMap->ProjectionY(
544+
Form("hTRPhi_tmp_charge%d_ptbin%d_etabin%d",
545+
charge, ptBin, etaBin),
546+
ptBin,
547+
ptBin,
548+
etaBin,
549+
etaBin);
550+
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+
}
566+
567+
delete hPhi;
568+
569+
return gRandom->Uniform(
570+
0., o2::constants::math::TwoPI);
571+
}
572+
573+
const double phi =
574+
RecoDecay::constrainAngle(hPhi->GetRandom());
575+
576+
delete hPhi;
577+
return phi;
578+
}
579+
456580
//__________________________________________________________________
457581
std::tuple<float, float, float, float, float> VarManager::BimodalityCoefficientUnbinned(const std::vector<float>& data)
458582
{

PWGDQ/Core/VarManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,6 +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);
15331535
static TObject* GetCalibrationObject(CalibObjects calib)
15341536
{
15351537
auto obj = fgCalibs.find(calib);
@@ -3956,7 +3958,7 @@ void VarManager::FillPairRotation(T1 const& t1, T2 const& t2, float* values)
39563958
m2 = o2::constants::physics::MassMuon;
39573959
}
39583960

3959-
double dphi = gRandom->Uniform(0., o2::constants::math::TwoPI);
3961+
double dphi = SampleRotationPhi(t2.pt(),t2.eta(),t2.sign());
39603962
double rotationphi2 = RecoDecay::constrainAngle(t2.phi() + dphi);
39613963

39623964
values[kCharge] = t1.sign() + t2.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);
1871+
}
18581872
}
18591873

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

0 commit comments

Comments
 (0)