Skip to content

Commit 06d9740

Browse files
author
Chiara De Martin
committed
add centrality weight on the fly
1 parent f73ec0b commit 06d9740

File tree

1 file changed

+58
-22
lines changed

1 file changed

+58
-22
lines changed

PWGLF/TableProducer/Strangeness/cascadeflow.cxx

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

280+
struct : ConfigurableGroup {
280281
Configurable<std::string> ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
281282
Configurable<std::vector<std::string>> modelPathsCCDBXi{"modelPathsCCDBXi", std::vector<std::string>{"Users/c/chdemart/CascadesFlow"}, "Paths of models on CCDB"};
282283
Configurable<std::vector<std::string>> modelPathsCCDBOmega{"modelPathsCCDBOmega", std::vector<std::string>{"Users/c/chdemart/CascadesFlow"}, "Paths of models on CCDB"};
@@ -293,7 +294,10 @@ struct cascadeFlow {
293294
Configurable<std::string> acceptanceHistoNamePrimaryLambda{"acceptanceHistoNamePrimaryLambda", "histoCos2ThetaLambdaFromCNoFit2D", "Histo name of acceptance on CCDB"};
294295
Configurable<std::string> resoPaths{"resoPath", "Users/c/chdemart/Resolution/", "Paths of resolution"};
295296
Configurable<std::string> resoHistoName{"resoHistoName", "hResoPerCentBinsV0A", "Histo name of resolution"};
296-
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;
300+
297301
// ML inference
298302
Configurable<bool> isApplyML{"isApplyML", 1, "Flag to apply ML selections"};
299303
Configurable<std::vector<double>> binsPtMl{"binsPtMl", std::vector<double>{cascade_flow_cuts_ml::vecBinsPt}, "pT bin limits for ML application"};
@@ -304,6 +308,7 @@ struct cascadeFlow {
304308
// acceptance crrection
305309
Configurable<bool> applyAcceptanceCorrection{"applyAcceptanceCorrection", false, "apply acceptance correction"};
306310
Configurable<bool> applyResoCorrection{"applyResoCorrection", false, "apply resolution correction"};
311+
Configurable<bool> applyCentWeightCorrection{"applyCentWeightCorrection", false, "apply centrality weight correction"};
307312

308313
o2::ccdb::CcdbApi ccdbApi;
309314
Service<o2::ccdb::BasicCCDBManager> ccdb;
@@ -577,6 +582,9 @@ struct cascadeFlow {
577582
//objects to use for resolution correction
578583
TH1F* hReso;
579584

585+
//objects to use for centrality weight
586+
TH1F* hCentWeight;
587+
580588
HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject, false, true};
581589
HistogramRegistry histosMCGen{"histosMCGen", {}, OutputObjHandlingPolicy::AnalysisObject, false, true};
582590
HistogramRegistry resolution{"resolution", {}, OutputObjHandlingPolicy::AnalysisObject, false, true};
@@ -716,35 +724,35 @@ struct cascadeFlow {
716724
void initAcceptanceFromCCDB()
717725
{
718726
LOG(info) << "Loading acceptance from CCDB ";
719-
TList* listAcceptanceXi = ccdb->get<TList>(acceptancePathsCCDBXi);
727+
TList* listAcceptanceXi = ccdb->get<TList>(ccdbConfigs.acceptancePathsCCDBXi);
720728
if (!listAcceptanceXi)
721729
LOG(fatal) << "Problem getting TList object with acceptance for Xi!";
722-
TList* listAcceptanceOmega = ccdb->get<TList>(acceptancePathsCCDBOmega);
730+
TList* listAcceptanceOmega = ccdb->get<TList>(ccdbConfigs.acceptancePathsCCDBOmega);
723731
if (!listAcceptanceOmega)
724732
LOG(fatal) << "Problem getting TList object with acceptance for Omega!";
725-
TList* listAcceptanceLambda = ccdb->get<TList>(acceptancePathsCCDBLambda);
733+
TList* listAcceptanceLambda = ccdb->get<TList>(ccdbConfigs.acceptancePathsCCDBLambda);
726734
if (!listAcceptanceLambda)
727735
LOG(fatal) << "Problem getting TList object with acceptance for Lambda!";
728-
TList* listAcceptancePrimaryLambda = ccdb->get<TList>(acceptancePathsCCDBPrimaryLambda);
736+
TList* listAcceptancePrimaryLambda = ccdb->get<TList>(ccdbConfigs.acceptancePathsCCDBPrimaryLambda);
729737
if (!listAcceptancePrimaryLambda)
730738
LOG(fatal) << "Problem getting TList object with acceptance for Primary Lambda!";
731739

732-
hAcceptanceXi = static_cast<TH2F*>(listAcceptanceXi->FindObject(Form("%s", acceptanceHistoNameCasc->data())));
740+
hAcceptanceXi = static_cast<TH2F*>(listAcceptanceXi->FindObject(Form("%s", ccdbConfigs.acceptanceHistoNameCasc->data())));
733741
if (!hAcceptanceXi) {
734742
LOG(fatal) << "The histogram for Xi is not there!";
735743
}
736744
hAcceptanceXi->SetName("hAcceptanceXi");
737-
hAcceptanceOmega = static_cast<TH2F*>(listAcceptanceOmega->FindObject(Form("%s", acceptanceHistoNameCasc->data())));
745+
hAcceptanceOmega = static_cast<TH2F*>(listAcceptanceOmega->FindObject(Form("%s", ccdbConfigs.acceptanceHistoNameCasc->data())));
738746
if (!hAcceptanceOmega) {
739747
LOG(fatal) << "The histogram for omega is not there!";
740748
}
741749
hAcceptanceOmega->SetName("hAcceptanceOmega");
742-
hAcceptanceLambda = static_cast<TH2F*>(listAcceptanceLambda->FindObject(Form("%s", acceptanceHistoNameLambda->data())));
750+
hAcceptanceLambda = static_cast<TH2F*>(listAcceptanceLambda->FindObject(Form("%s", ccdbConfigs.acceptanceHistoNameLambda->data())));
743751
if (!hAcceptanceLambda) {
744752
LOG(fatal) << "The histogram for Lambda is not there!";
745753
}
746754
hAcceptanceLambda->SetName("hAcceptanceLambda");
747-
hAcceptancePrimaryLambda = static_cast<TH2F*>(listAcceptancePrimaryLambda->FindObject(Form("%s", acceptanceHistoNamePrimaryLambda->data())));
755+
hAcceptancePrimaryLambda = static_cast<TH2F*>(listAcceptancePrimaryLambda->FindObject(Form("%s", ccdbConfigs.acceptanceHistoNamePrimaryLambda->data())));
748756
if (!hAcceptancePrimaryLambda) {
749757
LOG(fatal) << "The histogram for Primary Lambda is not there!";
750758
}
@@ -754,18 +762,33 @@ struct cascadeFlow {
754762
void initResoFromCCDB()
755763
{
756764
LOG(info) << "Loading resolution from CCDB ";
757-
TList* listReso = ccdb->get<TList>(resoPaths);
765+
TList* listReso = ccdb->get<TList>(ccdbConfigs.resoPaths);
758766
if (!listReso)
759767
LOG(fatal) << "Problem getting TList object with resolution!";
760768

761-
hReso = static_cast<TH1F*>(listReso->FindObject(Form("%s", resoHistoName->data())));
769+
hReso = static_cast<TH1F*>(listReso->FindObject(Form("%s", ccdbConfigs.resoHistoName->data())));
762770
if (!hReso) {
763771
LOG(fatal) << "The histogram for resolution is not there";
764772
}
765773
hReso->SetName("hReso");
766774
LOG(info) << "Resolution now loaded";
767775
}
768776

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+
}
791+
769792
void init(InitContext const&)
770793
{
771794

@@ -1009,31 +1032,38 @@ struct cascadeFlow {
10091032
mlResponseXi.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl);
10101033
mlResponseOmega.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl);
10111034
// Bonus: retrieve the model from CCDB (needed for ML application on the GRID)
1012-
if (loadModelsFromCCDB) {
1013-
ccdbApi.init(ccdbUrl);
1014-
mlResponseXi.setModelPathsCCDB(onnxFileNamesXi, ccdbApi, modelPathsCCDBXi, timestampCCDB);
1015-
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
10161039
} else {
1017-
mlResponseXi.setModelPathsLocal(onnxFileNamesXi);
1018-
mlResponseOmega.setModelPathsLocal(onnxFileNamesOmega);
1040+
mlResponseXi.setModelPathsLocal(ccdbConfigs.onnxFileNamesXi);
1041+
mlResponseOmega.setModelPathsLocal(ccdbConfigs.onnxFileNamesOmega);
10191042
}
10201043
mlResponseXi.init();
10211044
mlResponseOmega.init();
10221045
}
10231046
if (applyAcceptanceCorrection) {
1024-
ccdb->setURL(ccdbUrl);
1047+
ccdb->setURL(ccdbConfigs.ccdbUrl);
10251048
ccdb->setCaching(true);
10261049
ccdb->setLocalObjectValidityChecking();
10271050
ccdb->setFatalWhenNull(false);
10281051
initAcceptanceFromCCDB();
10291052
}
10301053
if (applyResoCorrection) {
1031-
ccdb->setURL(ccdbUrl);
1054+
ccdb->setURL(ccdbConfigs.ccdbUrl);
10321055
ccdb->setCaching(true);
10331056
ccdb->setLocalObjectValidityChecking();
10341057
ccdb->setFatalWhenNull(false);
10351058
initResoFromCCDB();
10361059
}
1060+
if (applyCentWeightCorrection) {
1061+
ccdb->setURL(ccdbConfigs.ccdbUrl);
1062+
ccdb->setCaching(true);
1063+
ccdb->setLocalObjectValidityChecking();
1064+
ccdb->setFatalWhenNull(false);
1065+
initCentWeightFromCCDB();
1066+
}
10371067
}
10381068

10391069
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&)
@@ -1900,7 +1930,12 @@ struct cascadeFlow {
19001930
int centBin = hReso->FindBin(collisionCentrality);
19011931
EPresolution = hReso->GetBinContent(centBin);
19021932
}
1903-
1933+
double centWeight = 1;
1934+
if (applyCentWeightCorrection){
1935+
int centBin = hCentWeight->FindBin(collisionCentrality);
1936+
centWeight = hCentWeight->GetBinContent(centBin);
1937+
}
1938+
19041939
std::vector<float> bdtScore[nParticles];
19051940
for (auto const& v0 : V0s) {
19061941

@@ -2015,14 +2050,15 @@ struct cascadeFlow {
20152050
if (fillingConfigs.isFillTHN_V2)
20162051
histos.get<THn>(HIST("hLambdaV2"))->Fill(collisionCentrality, chargeIndex, v0.pt(), v0.mLambda(), v2CEP);
20172052
if (fillingConfigs.isFillTHN_Pz) {
2018-
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);
20192055
}
20202056
if (fillingConfigs.isFillTHN_Acc)
20212057
histos.get<THn>(HIST("hLambdaCos2Theta"))->Fill(collisionCentrality, chargeIndex, v0.eta(), v0.pt(), v0.mLambda(), cos2ThetaLambda);
20222058
}
20232059
if (fillingConfigs.isFillTHNLambda_PzVsPsi) {
20242060
if (fillingConfigs.isFillTHN_Pz)
2025-
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);
20262062
if (fillingConfigs.isFillTHN_Acc)
20272063
histos.get<THn>(HIST("hLambdaCos2ThetaVsPsi"))->Fill(collisionCentrality, chargeIndex, v0.eta(), v0.pt(), v0.mLambda(), cos2ThetaLambda, 2 * lambdaminuspsiT0C);
20282064
}

0 commit comments

Comments
 (0)