Skip to content

Commit e1801f4

Browse files
ChiaraDeMartin95Chiara De Martinalibuild
authored
[PWGLF] Add possibility to apply resolution and centraliwy weight on the fly (#14176)
Co-authored-by: Chiara De Martin <chdemart@alicecerno2.cern.ch> Co-authored-by: ALICE Action Bot <alibuild@cern.ch>
1 parent f9bb80b commit e1801f4

File tree

1 file changed

+107
-38
lines changed

1 file changed

+107
-38
lines changed

PWGLF/TableProducer/Strangeness/cascadeflow.cxx

Lines changed: 107 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,26 @@ struct cascadeFlow {
277277
Configurable<float> etaCascMCGen{"etaCascMCGen", 0.8, "etaCascMCGen"};
278278
Configurable<float> yCascMCGen{"yCascMCGen", 0.5, "yCascMCGen"};
279279

280-
Configurable<std::string> ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
281-
Configurable<std::vector<std::string>> modelPathsCCDBXi{"modelPathsCCDBXi", std::vector<std::string>{"Users/c/chdemart/CascadesFlow"}, "Paths of models on CCDB"};
282-
Configurable<std::vector<std::string>> modelPathsCCDBOmega{"modelPathsCCDBOmega", std::vector<std::string>{"Users/c/chdemart/CascadesFlow"}, "Paths of models on CCDB"};
283-
Configurable<std::vector<std::string>> onnxFileNamesXi{"onnxFileNamesXi", std::vector<std::string>{"model_onnx.onnx"}, "ONNX file names for each pT bin (if not from CCDB full path)"};
284-
Configurable<std::vector<std::string>> onnxFileNamesOmega{"onnxFileNamesOmega", std::vector<std::string>{"model_onnx.onnx"}, "ONNX file names for each pT bin (if not from CCDB full path)"};
285-
Configurable<int64_t> timestampCCDB{"timestampCCDB", -1, "timestamp of the ONNX file for ML model used to query in CCDB"};
286-
Configurable<bool> loadModelsFromCCDB{"loadModelsFromCCDB", true, "Flag to enable or disable the loading of models from CCDB"};
287-
Configurable<std::string> acceptancePathsCCDBXi{"acceptancePathsCCDBXi", "Users/c/chdemart/AcceptanceXi", "Paths of Xi acceptance on CCDB"};
288-
Configurable<std::string> acceptancePathsCCDBOmega{"acceptancePathsCCDBOmega", "Users/c/chdemart/AcceptanceOmega", "Paths of Omega acceptance on CCDB"};
289-
Configurable<std::string> acceptancePathsCCDBLambda{"acceptancePathsCCDBLambda", "Users/c/chdemart/AcceptanceLambda", "Paths of Lambda acceptance on CCDB"};
290-
Configurable<std::string> acceptancePathsCCDBPrimaryLambda{"acceptancePathsCCDBPrimaryLambda", "Users/c/chdemart/AcceptanceLambda", "Paths of PrimaryLambda acceptance on CCDB"};
291-
Configurable<std::string> acceptanceHistoNameCasc{"acceptanceHistoNameCasc", "histoCos2ThetaNoFit2D", "Histo name of acceptance on CCDB"};
292-
Configurable<std::string> acceptanceHistoNameLambda{"acceptanceHistoNameLambda", "histoCos2ThetaLambdaFromCNoFit2D", "Histo name of acceptance on CCDB"};
293-
Configurable<std::string> acceptanceHistoNamePrimaryLambda{"acceptanceHistoNamePrimaryLambda", "histoCos2ThetaLambdaFromCNoFit2D", "Histo name of acceptance on CCDB"};
280+
struct : ConfigurableGroup {
281+
Configurable<std::string> ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
282+
Configurable<std::vector<std::string>> modelPathsCCDBXi{"modelPathsCCDBXi", std::vector<std::string>{"Users/c/chdemart/CascadesFlow"}, "Paths of models on CCDB"};
283+
Configurable<std::vector<std::string>> modelPathsCCDBOmega{"modelPathsCCDBOmega", std::vector<std::string>{"Users/c/chdemart/CascadesFlow"}, "Paths of models on CCDB"};
284+
Configurable<std::vector<std::string>> onnxFileNamesXi{"onnxFileNamesXi", std::vector<std::string>{"model_onnx.onnx"}, "ONNX file names for each pT bin (if not from CCDB full path)"};
285+
Configurable<std::vector<std::string>> onnxFileNamesOmega{"onnxFileNamesOmega", std::vector<std::string>{"model_onnx.onnx"}, "ONNX file names for each pT bin (if not from CCDB full path)"};
286+
Configurable<int64_t> timestampCCDB{"timestampCCDB", -1, "timestamp of the ONNX file for ML model used to query in CCDB"};
287+
Configurable<bool> loadModelsFromCCDB{"loadModelsFromCCDB", true, "Flag to enable or disable the loading of models from CCDB"};
288+
Configurable<std::string> acceptancePathsCCDBXi{"acceptancePathsCCDBXi", "Users/c/chdemart/AcceptanceXi", "Paths of Xi acceptance on CCDB"};
289+
Configurable<std::string> acceptancePathsCCDBOmega{"acceptancePathsCCDBOmega", "Users/c/chdemart/AcceptanceOmega", "Paths of Omega acceptance on CCDB"};
290+
Configurable<std::string> acceptancePathsCCDBLambda{"acceptancePathsCCDBLambda", "Users/c/chdemart/AcceptanceLambda", "Paths of Lambda acceptance on CCDB"};
291+
Configurable<std::string> acceptancePathsCCDBPrimaryLambda{"acceptancePathsCCDBPrimaryLambda", "Users/c/chdemart/AcceptanceLambda", "Paths of PrimaryLambda acceptance on CCDB"};
292+
Configurable<std::string> acceptanceHistoNameCasc{"acceptanceHistoNameCasc", "histoCos2ThetaNoFit2D", "Histo name of acceptance on CCDB"};
293+
Configurable<std::string> acceptanceHistoNameLambda{"acceptanceHistoNameLambda", "histoCos2ThetaLambdaFromCNoFit2D", "Histo name of acceptance on CCDB"};
294+
Configurable<std::string> acceptanceHistoNamePrimaryLambda{"acceptanceHistoNamePrimaryLambda", "histoCos2ThetaLambdaFromCNoFit2D", "Histo name of acceptance on CCDB"};
295+
Configurable<std::string> resoPaths{"resoPath", "Users/c/chdemart/Resolution/", "Paths of resolution"};
296+
Configurable<std::string> resoHistoName{"resoHistoName", "hResoPerCentBinsV0A", "Histo name of resolution"};
297+
Configurable<std::string> centWeightPaths{"centWeightPath", "Users/c/chdemart/CentralityWeight/", "Paths of centrality weight"};
298+
Configurable<std::string> centWeightHistoName{"centWeightHistoName", "hCentWeight", "Histo name of centrality weight"};
299+
} ccdbConfigs;
294300

295301
// ML inference
296302
Configurable<bool> isApplyML{"isApplyML", 1, "Flag to apply ML selections"};
@@ -301,6 +307,8 @@ struct cascadeFlow {
301307

302308
// acceptance crrection
303309
Configurable<bool> applyAcceptanceCorrection{"applyAcceptanceCorrection", false, "apply acceptance correction"};
310+
Configurable<bool> applyResoCorrection{"applyResoCorrection", false, "apply resolution correction"};
311+
Configurable<bool> applyCentWeightCorrection{"applyCentWeightCorrection", false, "apply centrality weight correction"};
304312

305313
o2::ccdb::CcdbApi ccdbApi;
306314
Service<o2::ccdb::BasicCCDBManager> ccdb;
@@ -571,6 +579,12 @@ struct cascadeFlow {
571579
TH2F* hAcceptanceLambda;
572580
TH2F* hAcceptancePrimaryLambda;
573581

582+
// objects to use for resolution correction
583+
TH1F* hReso;
584+
585+
// objects to use for centrality weight
586+
TH1F* hCentWeight;
587+
574588
HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject, false, true};
575589
HistogramRegistry histosMCGen{"histosMCGen", {}, OutputObjHandlingPolicy::AnalysisObject, false, true};
576590
HistogramRegistry resolution{"resolution", {}, OutputObjHandlingPolicy::AnalysisObject, false, true};
@@ -710,41 +724,70 @@ struct cascadeFlow {
710724
void initAcceptanceFromCCDB()
711725
{
712726
LOG(info) << "Loading acceptance from CCDB ";
713-
TList* listAcceptanceXi = ccdb->get<TList>(acceptancePathsCCDBXi);
727+
TList* listAcceptanceXi = ccdb->get<TList>(ccdbConfigs.acceptancePathsCCDBXi);
714728
if (!listAcceptanceXi)
715729
LOG(fatal) << "Problem getting TList object with acceptance for Xi!";
716-
TList* listAcceptanceOmega = ccdb->get<TList>(acceptancePathsCCDBOmega);
730+
TList* listAcceptanceOmega = ccdb->get<TList>(ccdbConfigs.acceptancePathsCCDBOmega);
717731
if (!listAcceptanceOmega)
718732
LOG(fatal) << "Problem getting TList object with acceptance for Omega!";
719-
TList* listAcceptanceLambda = ccdb->get<TList>(acceptancePathsCCDBLambda);
733+
TList* listAcceptanceLambda = ccdb->get<TList>(ccdbConfigs.acceptancePathsCCDBLambda);
720734
if (!listAcceptanceLambda)
721735
LOG(fatal) << "Problem getting TList object with acceptance for Lambda!";
722-
TList* listAcceptancePrimaryLambda = ccdb->get<TList>(acceptancePathsCCDBPrimaryLambda);
736+
TList* listAcceptancePrimaryLambda = ccdb->get<TList>(ccdbConfigs.acceptancePathsCCDBPrimaryLambda);
723737
if (!listAcceptancePrimaryLambda)
724738
LOG(fatal) << "Problem getting TList object with acceptance for Primary Lambda!";
725739

726-
hAcceptanceXi = static_cast<TH2F*>(listAcceptanceXi->FindObject(Form("%s", acceptanceHistoNameCasc->data())));
740+
hAcceptanceXi = static_cast<TH2F*>(listAcceptanceXi->FindObject(Form("%s", ccdbConfigs.acceptanceHistoNameCasc->data())));
727741
if (!hAcceptanceXi) {
728742
LOG(fatal) << "The histogram for Xi is not there!";
729743
}
730744
hAcceptanceXi->SetName("hAcceptanceXi");
731-
hAcceptanceOmega = static_cast<TH2F*>(listAcceptanceOmega->FindObject(Form("%s", acceptanceHistoNameCasc->data())));
745+
hAcceptanceOmega = static_cast<TH2F*>(listAcceptanceOmega->FindObject(Form("%s", ccdbConfigs.acceptanceHistoNameCasc->data())));
732746
if (!hAcceptanceOmega) {
733747
LOG(fatal) << "The histogram for omega is not there!";
734748
}
735749
hAcceptanceOmega->SetName("hAcceptanceOmega");
736-
hAcceptanceLambda = static_cast<TH2F*>(listAcceptanceLambda->FindObject(Form("%s", acceptanceHistoNameLambda->data())));
750+
hAcceptanceLambda = static_cast<TH2F*>(listAcceptanceLambda->FindObject(Form("%s", ccdbConfigs.acceptanceHistoNameLambda->data())));
737751
if (!hAcceptanceLambda) {
738752
LOG(fatal) << "The histogram for Lambda is not there!";
739753
}
740754
hAcceptanceLambda->SetName("hAcceptanceLambda");
741-
hAcceptancePrimaryLambda = static_cast<TH2F*>(listAcceptancePrimaryLambda->FindObject(Form("%s", acceptanceHistoNamePrimaryLambda->data())));
755+
hAcceptancePrimaryLambda = static_cast<TH2F*>(listAcceptancePrimaryLambda->FindObject(Form("%s", ccdbConfigs.acceptanceHistoNamePrimaryLambda->data())));
742756
if (!hAcceptancePrimaryLambda) {
743757
LOG(fatal) << "The histogram for Primary Lambda is not there!";
744758
}
745759
hAcceptancePrimaryLambda->SetName("hAcceptancePrimaryLambda");
746760
LOG(info) << "Acceptance now loaded";
747761
}
762+
void initResoFromCCDB()
763+
{
764+
LOG(info) << "Loading resolution from CCDB ";
765+
TList* listReso = ccdb->get<TList>(ccdbConfigs.resoPaths);
766+
if (!listReso)
767+
LOG(fatal) << "Problem getting TList object with resolution!";
768+
769+
hReso = static_cast<TH1F*>(listReso->FindObject(Form("%s", ccdbConfigs.resoHistoName->data())));
770+
if (!hReso) {
771+
LOG(fatal) << "The histogram for resolution is not there";
772+
}
773+
hReso->SetName("hReso");
774+
LOG(info) << "Resolution now loaded";
775+
}
776+
777+
void initCentWeightFromCCDB()
778+
{
779+
LOG(info) << "Loading resolution from CCDB ";
780+
TList* listCentWeight = ccdb->get<TList>(ccdbConfigs.centWeightPaths);
781+
if (!listCentWeight)
782+
LOG(fatal) << "Problem getting TList object with resolution!";
783+
784+
hCentWeight = static_cast<TH1F*>(listCentWeight->FindObject(Form("%s", ccdbConfigs.centWeightHistoName->data())));
785+
if (!hCentWeight) {
786+
LOG(fatal) << "The histogram for resolution is not there";
787+
}
788+
hCentWeight->SetName("hCentWeight");
789+
LOG(info) << "Centrality weight now loaded";
790+
}
748791

749792
void init(InitContext const&)
750793
{
@@ -989,24 +1032,38 @@ struct cascadeFlow {
9891032
mlResponseXi.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl);
9901033
mlResponseOmega.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl);
9911034
// Bonus: retrieve the model from CCDB (needed for ML application on the GRID)
992-
if (loadModelsFromCCDB) {
993-
ccdbApi.init(ccdbUrl);
994-
mlResponseXi.setModelPathsCCDB(onnxFileNamesXi, ccdbApi, modelPathsCCDBXi, timestampCCDB);
995-
mlResponseOmega.setModelPathsCCDB(onnxFileNamesOmega, ccdbApi, modelPathsCCDBOmega, timestampCCDB); // TODO: use different model for Xi and Omega
1035+
if (ccdbConfigs.loadModelsFromCCDB) {
1036+
ccdbApi.init(ccdbConfigs.ccdbUrl);
1037+
mlResponseXi.setModelPathsCCDB(ccdbConfigs.onnxFileNamesXi, ccdbApi, ccdbConfigs.modelPathsCCDBXi, ccdbConfigs.timestampCCDB);
1038+
mlResponseOmega.setModelPathsCCDB(ccdbConfigs.onnxFileNamesOmega, ccdbApi, ccdbConfigs.modelPathsCCDBOmega, ccdbConfigs.timestampCCDB); // TODO: use different model for Xi and Omega
9961039
} else {
997-
mlResponseXi.setModelPathsLocal(onnxFileNamesXi);
998-
mlResponseOmega.setModelPathsLocal(onnxFileNamesOmega);
1040+
mlResponseXi.setModelPathsLocal(ccdbConfigs.onnxFileNamesXi);
1041+
mlResponseOmega.setModelPathsLocal(ccdbConfigs.onnxFileNamesOmega);
9991042
}
10001043
mlResponseXi.init();
10011044
mlResponseOmega.init();
10021045
}
10031046
if (applyAcceptanceCorrection) {
1004-
ccdb->setURL(ccdbUrl);
1047+
ccdb->setURL(ccdbConfigs.ccdbUrl);
10051048
ccdb->setCaching(true);
10061049
ccdb->setLocalObjectValidityChecking();
10071050
ccdb->setFatalWhenNull(false);
10081051
initAcceptanceFromCCDB();
10091052
}
1053+
if (applyResoCorrection) {
1054+
ccdb->setURL(ccdbConfigs.ccdbUrl);
1055+
ccdb->setCaching(true);
1056+
ccdb->setLocalObjectValidityChecking();
1057+
ccdb->setFatalWhenNull(false);
1058+
initResoFromCCDB();
1059+
}
1060+
if (applyCentWeightCorrection) {
1061+
ccdb->setURL(ccdbConfigs.ccdbUrl);
1062+
ccdb->setCaching(true);
1063+
ccdb->setLocalObjectValidityChecking();
1064+
ccdb->setFatalWhenNull(false);
1065+
initCentWeightFromCCDB();
1066+
}
10101067
}
10111068

10121069
void processTrainingBackground(soa::Join<aod::StraCollisions, aod::StraCents, aod::StraEvSels>::iterator const& coll, soa::Join<aod::CascCollRefs, aod::CascCores, aod::CascExtras, aod::CascBBs> const& Cascades, DauTracks const&)
@@ -1868,6 +1925,17 @@ struct cascadeFlow {
18681925
resolution.fill(HIST("QVectorsNormT0ATPCC"), eventplaneVecT0A.Dot(eventplaneVecTPCC) / (coll.qTPCL() * coll.sumAmplFT0A()), collisionCentrality);
18691926
resolution.fill(HIST("QVectorsNormT0ATPCA"), eventplaneVecT0A.Dot(eventplaneVecTPCA) / (coll.qTPCR() * coll.sumAmplFT0A()), collisionCentrality);
18701927

1928+
double EPresolution = 1;
1929+
if (applyResoCorrection) {
1930+
int centBin = hReso->FindBin(collisionCentrality);
1931+
EPresolution = hReso->GetBinContent(centBin);
1932+
}
1933+
double centWeight = 1;
1934+
if (applyCentWeightCorrection) {
1935+
int centBin = hCentWeight->FindBin(collisionCentrality);
1936+
centWeight = hCentWeight->GetBinContent(centBin);
1937+
}
1938+
18711939
std::vector<float> bdtScore[nParticles];
18721940
for (auto const& v0 : V0s) {
18731941

@@ -1952,25 +2020,25 @@ struct cascadeFlow {
19522020
// acceptance values if requested
19532021
double meanCos2ThetaProtonFromLambda = 1;
19542022
if (applyAcceptanceCorrection) {
1955-
int bin2DLambda = hAcceptanceLambda->FindBin(v0.pt(), v0.eta());
2023+
int bin2DLambda = hAcceptancePrimaryLambda->FindBin(v0.pt(), v0.eta());
19562024
meanCos2ThetaProtonFromLambda = hAcceptancePrimaryLambda->GetBinContent(bin2DLambda);
19572025
}
19582026

19592027
double pzs2Lambda = 0;
19602028
double cos2ThetaLambda = 0;
19612029
double cosThetaLambda = 0;
19622030
if (chargeIndex == 0) {
1963-
pzs2Lambda = cosThetaStarProton[0] * std::sin(2 * (v0.phi() - psiT0CCorr)) / lambdav2::AlphaLambda[0] / meanCos2ThetaProtonFromLambda;
2031+
pzs2Lambda = cosThetaStarProton[0] * std::sin(2 * (v0.phi() - psiT0CCorr)) / lambdav2::AlphaLambda[0] / meanCos2ThetaProtonFromLambda / EPresolution;
19642032
cos2ThetaLambda = cosThetaStarProton[0] * cosThetaStarProton[0];
1965-
cosThetaLambda = cosThetaStarProton[0] / cascadev2::AlphaLambda[0] / meanCos2ThetaProtonFromLambda;
2033+
cosThetaLambda = cosThetaStarProton[0] / cascadev2::AlphaLambda[0] / meanCos2ThetaProtonFromLambda / EPresolution;
19662034
} else if (chargeIndex == 1) {
1967-
pzs2Lambda = cosThetaStarProton[1] * std::sin(2 * (v0.phi() - psiT0CCorr)) / lambdav2::AlphaLambda[1] / meanCos2ThetaProtonFromLambda;
2035+
pzs2Lambda = cosThetaStarProton[1] * std::sin(2 * (v0.phi() - psiT0CCorr)) / lambdav2::AlphaLambda[1] / meanCos2ThetaProtonFromLambda / EPresolution;
19682036
cos2ThetaLambda = cosThetaStarProton[1] * cosThetaStarProton[1];
1969-
cosThetaLambda = cosThetaStarProton[1] / cascadev2::AlphaLambda[1] / meanCos2ThetaProtonFromLambda;
2037+
cosThetaLambda = cosThetaStarProton[1] / cascadev2::AlphaLambda[1] / meanCos2ThetaProtonFromLambda / EPresolution;
19702038
} else { // I treat these bkg candidates as Lambdas for the purpose of calculating Pz
1971-
pzs2Lambda = cosThetaStarProton[0] * std::sin(2 * (v0.phi() - psiT0CCorr)) / lambdav2::AlphaLambda[0] / meanCos2ThetaProtonFromLambda;
2039+
pzs2Lambda = cosThetaStarProton[0] * std::sin(2 * (v0.phi() - psiT0CCorr)) / lambdav2::AlphaLambda[0] / meanCos2ThetaProtonFromLambda / EPresolution;
19722040
cos2ThetaLambda = cosThetaStarProton[0] * cosThetaStarProton[0];
1973-
cosThetaLambda = cosThetaStarProton[0] / cascadev2::AlphaLambda[0] / meanCos2ThetaProtonFromLambda;
2041+
cosThetaLambda = cosThetaStarProton[0] / cascadev2::AlphaLambda[0] / meanCos2ThetaProtonFromLambda / EPresolution;
19742042
}
19752043

19762044
histos.fill(HIST("hv2CEPvsFT0C"), collisionCentrality, v2CEP);
@@ -1982,14 +2050,15 @@ struct cascadeFlow {
19822050
if (fillingConfigs.isFillTHN_V2)
19832051
histos.get<THn>(HIST("hLambdaV2"))->Fill(collisionCentrality, chargeIndex, v0.pt(), v0.mLambda(), v2CEP);
19842052
if (fillingConfigs.isFillTHN_Pz) {
1985-
histos.get<THn>(HIST("hLambdaPzs2"))->Fill(collisionCentrality, chargeIndex, v0.pt(), v0.mLambda(), pzs2Lambda);
2053+
// histos.get<THn>(HIST("hLambdaPzs2"))->Fill(collisionCentrality, chargeIndex, v0.pt(), v0.mLambda(), pzs2Lambda);
2054+
histos.get<THn>(HIST("hLambdaPzs2"))->Fill(collisionCentrality, chargeIndex, v0.pt(), v0.mLambda(), pzs2Lambda, centWeight);
19862055
}
19872056
if (fillingConfigs.isFillTHN_Acc)
19882057
histos.get<THn>(HIST("hLambdaCos2Theta"))->Fill(collisionCentrality, chargeIndex, v0.eta(), v0.pt(), v0.mLambda(), cos2ThetaLambda);
19892058
}
19902059
if (fillingConfigs.isFillTHNLambda_PzVsPsi) {
19912060
if (fillingConfigs.isFillTHN_Pz)
1992-
histos.get<THn>(HIST("hLambdaPzVsPsi"))->Fill(collisionCentrality, chargeIndex, v0.pt(), v0.mLambda(), cosThetaLambda, 2 * lambdaminuspsiT0C);
2061+
histos.get<THn>(HIST("hLambdaPzVsPsi"))->Fill(collisionCentrality, chargeIndex, v0.pt(), v0.mLambda(), cosThetaLambda, 2 * lambdaminuspsiT0C, centWeight);
19932062
if (fillingConfigs.isFillTHN_Acc)
19942063
histos.get<THn>(HIST("hLambdaCos2ThetaVsPsi"))->Fill(collisionCentrality, chargeIndex, v0.eta(), v0.pt(), v0.mLambda(), cos2ThetaLambda, 2 * lambdaminuspsiT0C);
19952064
}

0 commit comments

Comments
 (0)