Skip to content

Commit 40a7845

Browse files
author
zjxiongOvO
committed
add weighted method
1 parent 8ec221c commit 40a7845

4 files changed

Lines changed: 83 additions & 1 deletion

File tree

PWGDQ/Core/HistogramsLibrary.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,7 @@ void o2::aod::dqhistograms::DefineHistograms(HistogramManager* hm, const char* h
13701370
hm->AddHistogram(histClass, "CosThetaStarFT0A", "", false, 100, -1.0, 1.0, VarManager::kCosThetaStarFT0A);
13711371
hm->AddHistogram(histClass, "CosThetaStarFT0C", "", false, 100, -1.0, 1.0, VarManager::kCosThetaStarFT0C);
13721372
hm->AddHistogram(histClass, "Cos2ThetaStarFT0C_Mass", "", true, 50, 2.0, 4.0, VarManager::kMass, 100, -1.0, 1.0, VarManager::kCos2ThetaStarFT0C);
1373+
hm->AddHistogram(histClass, "Cos2ThetaStarFT0C_Mass_Weight", "", true, 50, 2.0, 4.0, VarManager::kMass, 100, -1.0, 1.0, VarManager::kCos2ThetaStarFT0C, 1, 0, 1, VarManager::kNothing, "", "", "", -1, VarManager::kPairWeight, false, false);
13731374
}
13741375
if (subGroupStr.Contains("mc")) {
13751376
hm->AddHistogram(histClass, "EventPlaneAngle", "", false, 100, -TMath::Pi(), TMath::Pi(), VarManager::kMCEventPlaneAngle);

PWGDQ/Core/VarManager.cxx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ std::map<VarManager::CalibObjects, TObject*> VarManager::fgCalibs;
7474
bool VarManager::fgRunTPCPostCalibration[4] = {false, false, false, false};
7575
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
7676
bool VarManager::fgUseInterpolatedCalibration = true; // use interpolated calibration histograms (default: true)
77+
int VarManager::fgEfficiencyType = 0; // type of efficiency to be applied, default is no efficiency
78+
TObject* VarManager::fgEfficiencyHist = nullptr; // histogram for efficiency
7779

7880
//__________________________________________________________________
7981
VarManager::VarManager() : TObject()
@@ -380,6 +382,58 @@ double VarManager::ComputePIDcalibration(int species, double nSigmaValue)
380382
}
381383
}
382384

385+
//__________________________________________________________________
386+
void VarManager::SetEfficiencyObject(int efficiencyType, TObject* obj)
387+
{
388+
// check the type of the efficiency object and set it accordingly
389+
if (efficiencyType >= kNEfficiencyTypes || efficiencyType < 0) {
390+
LOG(warning) << "SetEfficiencyObject: unknown efficiency type " << efficiencyType;
391+
return;
392+
}
393+
394+
// set the efficiency type
395+
fgEfficiencyType = efficiencyType;
396+
// set the efficiency object
397+
fgEfficiencyHist = obj;
398+
}
399+
400+
void VarManager::FillEfficiency(float* values)
401+
{
402+
// depending on the efficiency type, we use different types of efficiency histograms and different variables to get the efficiency value
403+
if (!values) {
404+
values = fgValues;
405+
}
406+
407+
if (fgEfficiencyType == kNone) {
408+
values[kPairEfficiency] = 1.0; // if no efficiency is to be applied, set the efficiency value to 1
409+
values[kPairWeight] = 1.0; // set the weight to 1
410+
} else if (fgEfficiencyType == kPairPtCentFT0cCosThetaStarFT0c) {
411+
if (!fgEfficiencyHist) {
412+
LOG(fatal) << "efficiency histogram not set";
413+
return;
414+
}
415+
TH3F* efficiencyHist = reinterpret_cast<TH3F*>(fgEfficiencyHist);
416+
// Get the bin indices for the efficiency histogram
417+
int binPt = efficiencyHist->GetXaxis()->FindBin(values[kPairPt]);
418+
binPt = (binPt == 0 ? 1 : binPt);
419+
binPt = (binPt > efficiencyHist->GetXaxis()->GetNbins() ? efficiencyHist->GetXaxis()->GetNbins() : binPt);
420+
int binCent = efficiencyHist->GetYaxis()->FindBin(values[kCentFT0C]);
421+
binCent = (binCent == 0 ? 1 : binCent);
422+
binCent = (binCent > efficiencyHist->GetYaxis()->GetNbins() ? efficiencyHist->GetYaxis()->GetNbins() : binCent);
423+
int binCosThetaStarFT0c = efficiencyHist->GetZaxis()->FindBin(values[kCosThetaStarFT0C]);
424+
binCosThetaStarFT0c = (binCosThetaStarFT0c == 0 ? 1 : binCosThetaStarFT0c);
425+
binCosThetaStarFT0c = (binCosThetaStarFT0c > efficiencyHist->GetZaxis()->GetNbins() ? efficiencyHist->GetZaxis()->GetNbins() : binCosThetaStarFT0c);
426+
427+
// get the efficiency value from the histogram
428+
values[kPairEfficiency] = efficiencyHist->GetBinContent(binPt, binCent, binCosThetaStarFT0c);
429+
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
430+
} else {
431+
LOG(warning) << "FillEfficiency: unknown efficiency type " << fgEfficiencyType << ", using default efficiency = 1";
432+
values[kPairEfficiency] = 1;
433+
values[kPairWeight] = 1;
434+
}
435+
}
436+
383437
//__________________________________________________________________
384438
std::tuple<float, float, float, float, float> VarManager::BimodalityCoefficientUnbinned(const std::vector<float>& data)
385439
{

PWGDQ/Core/VarManager.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
#include <KFPTrack.h>
6969
#include <KFPVertex.h>
7070
#include <KFParticle.h>
71+
#include <rapidjson/document.h>
72+
#include <rapidjson/error/error.h>
7173

7274
#include <GPUROOTCartesianFwd.h>
7375
#include <Rtypes.h>
@@ -926,6 +928,8 @@ class VarManager : public TObject
926928
kS12,
927929
kS13,
928930
kS23,
931+
kPairEfficiency,
932+
kPairWeight,
929933
kNPairVariables,
930934

931935
// Candidate-track correlation variables
@@ -1111,6 +1115,13 @@ class VarManager : public TObject
11111115
kNCalibObjects
11121116
};
11131117

1118+
enum EfficiencyType {
1119+
kNone = 0,
1120+
kPairPtCentFT0cCosThetaStarFT0c,
1121+
// Add more efficiency types as needed
1122+
kNEfficiencyTypes
1123+
};
1124+
11141125
enum DileptonCharmHadronTypes {
11151126
kJPsi = 0,
11161127
kD0ToPiK,
@@ -1461,7 +1472,8 @@ class VarManager : public TObject
14611472
fgUseInterpolatedCalibration = useInterpolation;
14621473
}
14631474
static double ComputePIDcalibration(int species, double nSigmaValue);
1464-
1475+
static void SetEfficiencyObject(int type, TObject* obj);
1476+
static void FillEfficiency(float* values = nullptr);
14651477
static TObject* GetCalibrationObject(CalibObjects calib)
14661478
{
14671479
auto obj = fgCalibs.find(calib);
@@ -1519,6 +1531,7 @@ class VarManager : public TObject
15191531

15201532
// static void FillEventDerived(float* values = nullptr);
15211533
static void FillTrackDerived(float* values = nullptr);
1534+
// static void FillPairDerived(float* values = nullptr);
15221535
template <typename T, typename U, typename V>
15231536
static auto getRotatedCovMatrixXX(const T& matrix, U phi, V theta);
15241537
template <typename T>
@@ -1545,6 +1558,9 @@ class VarManager : public TObject
15451558
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
15461559
static bool fgUseInterpolatedCalibration; // use interpolated calibration histograms (default: true)
15471560

1561+
static int fgEfficiencyType; // type of efficiency correction to apply
1562+
static TObject* fgEfficiencyHist; // histogram for efficiency correction
1563+
15481564
VarManager& operator=(const VarManager& c);
15491565
VarManager(const VarManager& c);
15501566

PWGDQ/Tasks/tableReader_withAssoc.cxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@ struct AnalysisSameEventPairing {
12871287
Configurable<std::string> lutPath{"lutPath", "GLO/Param/MatLUT", "Path of the Lut parametrization"};
12881288
Configurable<std::string> geoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"};
12891289
Configurable<std::string> GrpLhcIfPath{"grplhcif", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"};
1290+
Configurable<std::string> efficiencyPath{"effHistPath", "Users/z/zhxiong/efficiency", "Path on the CCDB for the efficiency histograms"};
12901291
} fConfigCCDB;
12911292

12921293
struct : ConfigurableGroup {
@@ -1303,6 +1304,8 @@ struct AnalysisSameEventPairing {
13031304
Configurable<float> centerMassEnergy{"energy", 13600, "Center of mass energy in GeV"};
13041305
Configurable<bool> propTrack{"cfgPropTrack", true, "Propgate tracks to associated collision to recalculate DCA and momentum vector"};
13051306
Configurable<bool> useRemoteCollisionInfo{"cfgUseRemoteCollisionInfo", false, "Use remote collision information from CCDB"};
1307+
Configurable<bool> useEfficiencyWeighting{"cfgUseEfficiencyWeighting", false, "Apply efficiency weighting to the pairs from CCDB"};
1308+
Configurable<int> efficiencyType{"cfgEfficiencyType", 0, "Type of efficiency to apply from CCDB: 0 no efficiency, 1 pt-cent-costhetastar"};
13061309
} fConfigOptions;
13071310
struct : ConfigurableGroup {
13081311
Configurable<bool> applyBDT{"applyBDT", false, "Flag to apply ML selections"};
@@ -1716,6 +1719,11 @@ struct AnalysisSameEventPairing {
17161719
o2::parameters::GRPLHCIFData* grpo = fCCDB->getForTimeStamp<o2::parameters::GRPLHCIFData>(fConfigCCDB.GrpLhcIfPath, timestamp);
17171720
VarManager::SetCollisionSystem(grpo);
17181721
}
1722+
1723+
if (fConfigOptions.useEfficiencyWeighting) {
1724+
auto effList = fCCDB->getForTimeStamp<TList>(fConfigCCDB.efficiencyPath.value, timestamp);
1725+
VarManager::SetEfficiencyObject(fConfigOptions.efficiencyType.value, effList->FindObject("efficiency"));
1726+
}
17191727
}
17201728

17211729
// Template function to run same event pairing (barrel-barrel, muon-muon, barrel-muon)
@@ -1837,6 +1845,9 @@ struct AnalysisSameEventPairing {
18371845
if constexpr (eventHasQvectorCentr) {
18381846
VarManager::FillPairVn<TEventFillMap, TPairType>(t1, t2);
18391847
}
1848+
// if (fConfigOptions.useEfficiencyWeighting) {
1849+
VarManager::FillEfficiency();
1850+
// }
18401851

18411852
dielectronList(event.globalIndex(), VarManager::fgValues[VarManager::kMass],
18421853
VarManager::fgValues[VarManager::kPt], VarManager::fgValues[VarManager::kEta], VarManager::fgValues[VarManager::kPhi],

0 commit comments

Comments
 (0)