@@ -75,7 +75,8 @@ int VarManager::fgCalibrationType = 0; // 0 - no calibration, 1 -
7575bool VarManager::fgUseInterpolatedCalibration = true ; // use interpolated calibration histograms (default: true)
7676int VarManager::fgEfficiencyType = 0 ; // type of efficiency to be applied, default is no efficiency
7777TObject* VarManager::fgEfficiencyHist = nullptr ; // histogram for efficiency
78-
78+ TH3D * VarManager::fgPosiPhiMap = nullptr ;
79+ TH3D * VarManager::fgNegaPhiMap = nullptr ;
7980// __________________________________________________________________
8081VarManager::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// __________________________________________________________________
457581std::tuple<float , float , float , float , float > VarManager::BimodalityCoefficientUnbinned (const std::vector<float >& data)
458582{
0 commit comments