Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions PWGDQ/Core/VarManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
bool VarManager::fgRunTPCPostCalibration[4] = {false, false, false, false};
int VarManager::fgCalibrationType = 0; // 0 - no calibration, 1 - calibration vs (TPCncls,pIN,eta) typically for pp, 2 - calibration vs (eta,nPV,nLong,tLong) typically for PbPb
bool VarManager::fgUseInterpolatedCalibration = true; // use interpolated calibration histograms (default: true)
int VarManager::fgEfficiencyType = 0; // type of efficiency to be applied, default is no efficiency
TObject* VarManager::fgEfficiencyHist = nullptr; // histogram for efficiency

//__________________________________________________________________
VarManager::VarManager() : TObject()
Expand Down Expand Up @@ -191,8 +193,8 @@
// TO Do: add more systems

// set the beam 4-momentum vectors
float beamAEnergy = energy / 2.0 * sqrt(NumberOfProtonsA * NumberOfProtonsC / NumberOfProtonsC / NumberOfProtonsA); // GeV

Check failure on line 196 in PWGDQ/Core/VarManager.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[std-prefix]

Use std:: prefix for names from the std namespace.
float beamCEnergy = energy / 2.0 * sqrt(NumberOfProtonsC * NumberOfProtonsA / NumberOfProtonsA / NumberOfProtonsC); // GeV

Check failure on line 197 in PWGDQ/Core/VarManager.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[std-prefix]

Use std:: prefix for names from the std namespace.
float beamAMomentum = std::sqrt(beamAEnergy * beamAEnergy - NumberOfNucleonsA * NumberOfNucleonsA * MassProton * MassProton);
float beamCMomentum = std::sqrt(beamCEnergy * beamCEnergy - NumberOfNucleonsC * NumberOfNucleonsC * MassProton * MassProton);
fgBeamA.SetPxPyPzE(0, 0, beamAMomentum, beamAEnergy);
Expand Down Expand Up @@ -291,7 +293,7 @@
double mean = calibMeanHist->GetBinContent(binTPCncls, binPin, binEta);
double sigma = calibSigmaHist->GetBinContent(binTPCncls, binPin, binEta);
return (nSigmaValue - mean) / sigma; // Return the calibrated nSigma value
} else if (fgCalibrationType == 2) {

Check failure on line 296 in PWGDQ/Core/VarManager.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
// get the calibration histograms
CalibObjects calibMean, calibSigma, calibStatus;
switch (species) {
Expand Down Expand Up @@ -380,20 +382,72 @@
}
}

//__________________________________________________________________
void VarManager::SetEfficiencyObject(int efficiencyType, TObject* obj)
{
// check the type of the efficiency object and set it accordingly
if (efficiencyType >= kNEfficiencyTypes || efficiencyType < 0) {
LOG(warning) << "SetEfficiencyObject: unknown efficiency type " << efficiencyType;
return;
}

// set the efficiency type
fgEfficiencyType = efficiencyType;
// set the efficiency object
fgEfficiencyHist = obj;
}

void VarManager::FillEfficiency(float* values)
{
// depending on the efficiency type, we use different types of efficiency histograms and different variables to get the efficiency value
if (!values) {
values = fgValues;
}

if (fgEfficiencyType == kNone) {
values[kPairEfficiency] = 1.0; // if no efficiency is to be applied, set the efficiency value to 1
values[kPairWeight] = 1.0; // set the weight to 1
} else if (fgEfficiencyType == kPairPtCentFT0cCosThetaStarFT0c) {
if (!fgEfficiencyHist) {
LOG(fatal) << "efficiency histogram not set";
return;
}
TH3F* efficiencyHist = reinterpret_cast<TH3F*>(fgEfficiencyHist);
// Get the bin indices for the efficiency histogram
int binPt = efficiencyHist->GetXaxis()->FindBin(values[kPairPt]);
binPt = (binPt == 0 ? 1 : binPt);
binPt = (binPt > efficiencyHist->GetXaxis()->GetNbins() ? efficiencyHist->GetXaxis()->GetNbins() : binPt);
int binCent = efficiencyHist->GetYaxis()->FindBin(values[kCentFT0C]);
binCent = (binCent == 0 ? 1 : binCent);
binCent = (binCent > efficiencyHist->GetYaxis()->GetNbins() ? efficiencyHist->GetYaxis()->GetNbins() : binCent);
int binCosThetaStarFT0c = efficiencyHist->GetZaxis()->FindBin(values[kCosThetaStarFT0C]);
binCosThetaStarFT0c = (binCosThetaStarFT0c == 0 ? 1 : binCosThetaStarFT0c);
binCosThetaStarFT0c = (binCosThetaStarFT0c > efficiencyHist->GetZaxis()->GetNbins() ? efficiencyHist->GetZaxis()->GetNbins() : binCosThetaStarFT0c);

// get the efficiency value from the histogram
values[kPairEfficiency] = efficiencyHist->GetBinContent(binPt, binCent, binCosThetaStarFT0c);
values[kPairWeight] = 1.0 / (values[kPairEfficiency] > 0 ? values[kPairEfficiency] : 1.0); // set the weight as the inverse of the efficiency, but avoid division by zero
} else {
LOG(warning) << "FillEfficiency: unknown efficiency type " << fgEfficiencyType << ", using default efficiency = 1";
values[kPairEfficiency] = 1;
values[kPairWeight] = 1;
}
}

//__________________________________________________________________
std::tuple<float, float, float, float, float> VarManager::BimodalityCoefficientUnbinned(const std::vector<float>& data)
{
// Bimodality coefficient = (skewness^2 + 1) / kurtosis
// return a tuple including the coefficient, mean, RMS, skewness, and kurtosis
size_t n = data.size();
if (n < 3) {

Check failure on line 443 in PWGDQ/Core/VarManager.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
return std::make_tuple(-1.0, -1.0, -1.0, -1.0, -1.0);
}
float mean = std::accumulate(data.begin(), data.end(), 0.0) / n;

float m2 = 0.0, m3 = 0.0, m4 = 0.0;
float diff, diff2;
for (float x : data) {

Check failure on line 450 in PWGDQ/Core/VarManager.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[const-ref-in-for-loop]

Use constant references for non-modified iterators in range-based for loops.
diff = x - mean;
diff2 = diff * diff;
m2 += diff2;
Expand Down Expand Up @@ -432,7 +486,7 @@
int nBins = static_cast<int>((max - min) / binWidth);
std::vector<int> counts(nBins, 0.0);

for (float x : data) {

Check failure on line 489 in PWGDQ/Core/VarManager.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[const-ref-in-for-loop]

Use constant references for non-modified iterators in range-based for loops.
if (x < min || x >= max) {
continue; // skip out-of-range values
}
Expand Down Expand Up @@ -1535,6 +1589,8 @@
fgVariableUnits[kCos2ThetaStarRandom] = "";
fgVariableNames[kMCCosThetaStar] = "cos#it{#theta}^{*}_{MC}";
fgVariableUnits[kMCCosThetaStar] = "";
fgVariableNames[kPairWeight] = "weight";
fgVariableUnits[kPairWeight] = "";
fgVariableNames[kCosPhiVP] = "cos#it{#varphi}_{VP}";
fgVariableUnits[kCosPhiVP] = "";
fgVariableNames[kPhiVP] = "#varphi_{VP} - #Psi_{2}";
Expand Down Expand Up @@ -2364,6 +2420,7 @@
fgVarNamesMap["kCosThetaStarRandom"] = kCosThetaStarRandom;
fgVarNamesMap["kCos2ThetaStarRandom"] = kCos2ThetaStarRandom;
fgVarNamesMap["kMCCosThetaStar"] = kMCCosThetaStar;
fgVarNamesMap["kPairWeight"] = kPairWeight;
fgVarNamesMap["kCosPhiVP"] = kCosPhiVP;
fgVarNamesMap["kPhiVP"] = kPhiVP;
fgVarNamesMap["kDeltaPhiPair2"] = kDeltaPhiPair2;
Expand Down
14 changes: 14 additions & 0 deletions PWGDQ/Core/VarManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,8 @@
kS12,
kS13,
kS23,
kPairEfficiency,
kPairWeight,
kNPairVariables,

// Candidate-track correlation variables
Expand Down Expand Up @@ -1113,6 +1115,13 @@
kNCalibObjects
};

enum EfficiencyType {
kNone = 0,
kPairPtCentFT0cCosThetaStarFT0c,
// Add more efficiency types as needed
kNEfficiencyTypes
};

enum DileptonCharmHadronTypes {
kJPsi = 0,
kD0ToPiK,
Expand Down Expand Up @@ -1464,6 +1473,8 @@
}
static double ComputePIDcalibration(int species, double nSigmaValue);

static void SetEfficiencyObject(int type, TObject* obj);
static void FillEfficiency(float* values = nullptr);
static TObject* GetCalibrationObject(CalibObjects calib)
{
auto obj = fgCalibs.find(calib);
Expand Down Expand Up @@ -1547,6 +1558,9 @@
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
static bool fgUseInterpolatedCalibration; // use interpolated calibration histograms (default: true)

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

VarManager& operator=(const VarManager& c);
VarManager(const VarManager& c);

Expand Down Expand Up @@ -1814,9 +1828,9 @@
}
if constexpr ((fillMap & MuonCov) > 0 || (fillMap & ReducedMuonCov) > 0) {
o2::dataformats::GlobalFwdTrack propmuon = PropagateMuon(muontrack, collision);
double px = propmuon.getP() * sin(M_PI / 2 - atan(mfttrack.tgl())) * cos(mfttrack.phi());

Check failure on line 1831 in PWGDQ/Core/VarManager.h

View workflow job for this annotation

GitHub Actions / O2 linter

[std-prefix]

Use std:: prefix for names from the std namespace.
double py = propmuon.getP() * sin(M_PI / 2 - atan(mfttrack.tgl())) * sin(mfttrack.phi());

Check failure on line 1832 in PWGDQ/Core/VarManager.h

View workflow job for this annotation

GitHub Actions / O2 linter

[std-prefix]

Use std:: prefix for names from the std namespace.
double pz = propmuon.getP() * cos(M_PI / 2 - atan(mfttrack.tgl()));

Check failure on line 1833 in PWGDQ/Core/VarManager.h

View workflow job for this annotation

GitHub Actions / O2 linter

[std-prefix]

Use std:: prefix for names from the std namespace.
double pt = std::sqrt(std::pow(px, 2) + std::pow(py, 2));
auto mftprop = o2::aod::fwdtrackutils::getTrackParCovFwdShift(mfttrack, fgzShiftFwd);
values[kX] = mftprop.getX();
Expand Down Expand Up @@ -4655,7 +4669,7 @@
values[kVertexingLxyErr] = (KFPV.GetCovariance(0) + KFGeoTwoProng.GetCovariance(0)) * dxPair2PV * dxPair2PV + (KFPV.GetCovariance(2) + KFGeoTwoProng.GetCovariance(2)) * dyPair2PV * dyPair2PV + 2 * ((KFPV.GetCovariance(1) + KFGeoTwoProng.GetCovariance(1)) * dxPair2PV * dyPair2PV);
values[kVertexingLzErr] = (KFPV.GetCovariance(5) + KFGeoTwoProng.GetCovariance(5)) * dzPair2PV * dzPair2PV;
values[kVertexingLxyzErr] = (KFPV.GetCovariance(0) + KFGeoTwoProng.GetCovariance(0)) * dxPair2PV * dxPair2PV + (KFPV.GetCovariance(2) + KFGeoTwoProng.GetCovariance(2)) * dyPair2PV * dyPair2PV + (KFPV.GetCovariance(5) + KFGeoTwoProng.GetCovariance(5)) * dzPair2PV * dzPair2PV + 2 * ((KFPV.GetCovariance(1) + KFGeoTwoProng.GetCovariance(1)) * dxPair2PV * dyPair2PV + (KFPV.GetCovariance(3) + KFGeoTwoProng.GetCovariance(3)) * dxPair2PV * dzPair2PV + (KFPV.GetCovariance(4) + KFGeoTwoProng.GetCovariance(4)) * dyPair2PV * dzPair2PV);
if (fabs(values[kVertexingLxy]) < 1.e-8f)

Check failure on line 4672 in PWGDQ/Core/VarManager.h

View workflow job for this annotation

GitHub Actions / O2 linter

[std-prefix]

Use std:: prefix for names from the std namespace.
values[kVertexingLxy] = 1.e-8f;
values[kVertexingLxyErr] = values[kVertexingLxyErr] < 0. ? 1.e8f : std::sqrt(values[kVertexingLxyErr]) / values[kVertexingLxy];
if (fabs(values[kVertexingLz]) < 1.e-8f)
Expand Down
12 changes: 12 additions & 0 deletions PWGDQ/Tasks/tableReader_withAssoc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,7 @@ struct AnalysisSameEventPairing {
Configurable<std::string> lutPath{"lutPath", "GLO/Param/MatLUT", "Path of the Lut parametrization"};
Configurable<std::string> geoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"};
Configurable<std::string> GrpLhcIfPath{"grplhcif", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"};
Configurable<std::string> efficiencyPath{"effHistPath", "Users/z/zhxiong/efficiency", "Path on the CCDB for the efficiency histograms"};
} fConfigCCDB;

struct : ConfigurableGroup {
Expand All @@ -1318,6 +1319,8 @@ struct AnalysisSameEventPairing {
Configurable<float> centerMassEnergy{"energy", 13600, "Center of mass energy in GeV"};
Configurable<bool> propTrack{"cfgPropTrack", true, "Propgate tracks to associated collision to recalculate DCA and momentum vector"};
Configurable<bool> useRemoteCollisionInfo{"cfgUseRemoteCollisionInfo", false, "Use remote collision information from CCDB"};
Configurable<bool> useEfficiencyWeighting{"cfgUseEfficiencyWeighting", false, "Apply efficiency weighting to the pairs from CCDB"};
Configurable<int> efficiencyType{"cfgEfficiencyType", 0, "Type of efficiency to apply from CCDB: 0 no efficiency, 1 pt-cent-costhetastar"};
} fConfigOptions;
struct : ConfigurableGroup {
Configurable<bool> applyBDT{"applyBDT", false, "Flag to apply ML selections"};
Expand Down Expand Up @@ -1731,6 +1734,11 @@ struct AnalysisSameEventPairing {
o2::parameters::GRPLHCIFData* grpo = fCCDB->getForTimeStamp<o2::parameters::GRPLHCIFData>(fConfigCCDB.GrpLhcIfPath, timestamp);
VarManager::SetCollisionSystem(grpo);
}

if (fConfigOptions.useEfficiencyWeighting) {
auto effList = fCCDB->getForTimeStamp<TList>(fConfigCCDB.efficiencyPath.value, timestamp);
VarManager::SetEfficiencyObject(fConfigOptions.efficiencyType.value, effList->FindObject("efficiency"));
}
}

// Template function to run same event pairing (barrel-barrel, muon-muon, barrel-muon)
Expand Down Expand Up @@ -1853,6 +1861,10 @@ struct AnalysisSameEventPairing {
VarManager::FillPairVn<TEventFillMap, TPairType>(t1, t2);
}

if (fConfigOptions.useEfficiencyWeighting) {
VarManager::FillEfficiency();
}
Comment thread
iarsene marked this conversation as resolved.

dielectronList(event.globalIndex(), VarManager::fgValues[VarManager::kMass],
VarManager::fgValues[VarManager::kPt], VarManager::fgValues[VarManager::kEta], VarManager::fgValues[VarManager::kPhi],
t1.sign() + t2.sign(), twoTrackFilter, 0);
Expand Down
Loading