Skip to content

Commit 854dc38

Browse files
authored
Update
1 parent 69bfda3 commit 854dc38

File tree

1 file changed

+211
-3
lines changed

1 file changed

+211
-3
lines changed

Common/TableProducer/multPercentile.cxx

Lines changed: 211 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,14 @@ struct : ConfigurableGroup {
385385
}
386386
}
387387
isTableEnabled[i] = true;
388-
mEnabledTables.push_back(i);
388+
mEnabledCentralityTables.push_back(i);
389389
}
390390
}
391391

392-
if (mEnabledTables.size() == 0) {
392+
if (mEnabledCentralityTables.size() == 0) {
393393
LOGF(fatal, "No table enabled. Please enable at least one table.");
394394
}
395-
std::sort(mEnabledTables.begin(), mEnabledTables.end());
395+
std::sort(mEnabledCentralityTables.begin(), mEnabledCentralityTables.end());
396396

397397

398398

@@ -501,6 +501,40 @@ struct : ConfigurableGroup {
501501
}
502502

503503
// reserve memory for centrality tables
504+
for (auto const& table : mEnabledCentralityTables) {
505+
switch (table) {
506+
case centrality::kFV0As:
507+
centFV0A.reserve(collisions.size());
508+
break;
509+
case centrality::kFT0Ms:
510+
centFT0M.reserve(collisions.size());
511+
break;
512+
case centrality::kFT0As:
513+
centFT0A.reserve(collisions.size());
514+
break;
515+
case centrality::kFT0Cs:
516+
centFT0C.reserve(collisions.size());
517+
break;
518+
case centrality::kFT0CVariant1s:
519+
centFT0CVariant1.reserve(collisions.size());
520+
break;
521+
case centrality::kFDDMs:
522+
centFDDM.reserve(collisions.size());
523+
break;
524+
case centrality::kNTPVs:
525+
centNTPV.reserve(collisions.size());
526+
break;
527+
case centrality::kNGlobals:
528+
centNGlobals.reserve(collisions.size());
529+
break;
530+
case centrality::kMFTs:
531+
centMFTs.reserve(collisions.size());
532+
break;
533+
default:
534+
LOGF(fatal, "Table %d not supported in Run3", table);
535+
break;
536+
}
537+
}
504538

505539
// Initializing multiplicity values
506540
float multFV0A = 0.f;
@@ -575,6 +609,7 @@ struct : ConfigurableGroup {
575609
}
576610
}
577611

612+
// First we compute the multiplicity
578613
for (const auto& i : mEnabledMultiplicityTables) {
579614
switch (i) {
580615
case kFV0Mults: // FV0
@@ -788,6 +823,179 @@ struct : ConfigurableGroup {
788823
} break;
789824
}
790825
}
826+
827+
if (bc.runNumber() != mRunNumber) {
828+
mRunNumber = bc.runNumber(); // mark that this run has been attempted already regardless of outcome
829+
LOGF(info, "timestamp=%llu, run number=%d", bc.timestamp(), bc.runNumber());
830+
TList* callst = nullptr;
831+
// Check if the ccdb path is a root file
832+
if (ccdbConfig.ccdbPath.value.find(".root") != std::string::npos) {
833+
TFile f(ccdbConfig.ccdbPath.value.c_str(), "READ");
834+
f.GetObject(ccdbConfig.reconstructionPass.value.c_str(), callst);
835+
if (!callst) {
836+
f.ls();
837+
LOG(fatal) << "No calibration list " << ccdbConfig.reconstructionPass.value << " found in the file " << ccdbConfig.ccdbPath.value;
838+
}
839+
} else {
840+
if (ccdbConfig.reconstructionPass.value == "") {
841+
callst = ccdb->getForRun<TList>(ccdbConfig.ccdbPath, bc.runNumber());
842+
} else if (ccdbConfig.reconstructionPass.value == "metadata") {
843+
std::map<std::string, std::string> metadata;
844+
metadata["RecoPassName"] = metadataInfo.get("RecoPassName");
845+
LOGF(info, "Loading CCDB for reconstruction pass (from metadata): %s", metadataInfo.get("RecoPassName"));
846+
callst = ccdb->getSpecificForRun<TList>(ccdbConfig.ccdbPath, bc.runNumber(), metadata);
847+
} else {
848+
std::map<std::string, std::string> metadata;
849+
metadata["RecoPassName"] = ccdbConfig.reconstructionPass.value;
850+
LOGF(info, "Loading CCDB for reconstruction pass (from provided argument): %s", ccdbConfig.reconstructionPass.value);
851+
callst = ccdb->getSpecificForRun<TList>(ccdbConfig.ccdbPath, bc.runNumber(), metadata);
852+
}
853+
}
854+
855+
fv0aInfo.mCalibrationStored = false;
856+
ft0mInfo.mCalibrationStored = false;
857+
ft0aInfo.mCalibrationStored = false;
858+
ft0cInfo.mCalibrationStored = false;
859+
ft0cVariant1Info.mCalibrationStored = false;
860+
fddmInfo.mCalibrationStored = false;
861+
ntpvInfo.mCalibrationStored = false;
862+
nGlobalInfo.mCalibrationStored = false;
863+
mftInfo.mCalibrationStored = false;
864+
if (callst != nullptr) {
865+
if (produceHistograms) {
866+
listCalib->Add(callst->Clone(Form("%i", bc.runNumber())));
867+
}
868+
LOGF(info, "Getting new histograms with %d run number for %d run number", mRunNumber, bc.runNumber());
869+
auto getccdb = [callst, bc](struct CalibrationInfo& estimator, const Configurable<std::string> generatorName) { // TODO: to consider the name inside the estimator structure
870+
estimator.mhMultSelCalib = reinterpret_cast<TH1*>(callst->FindObject(TString::Format("hCalibZeq%s", estimator.name.c_str()).Data()));
871+
estimator.mMCScale = reinterpret_cast<TFormula*>(callst->FindObject(TString::Format("%s-%s", generatorName->c_str(), estimator.name.c_str()).Data()));
872+
if (estimator.mhMultSelCalib != nullptr) {
873+
if (generatorName->length() != 0) {
874+
LOGF(info, "Retrieving MC calibration for %d, generator name: %s", bc.runNumber(), generatorName->c_str());
875+
if (estimator.mMCScale != nullptr) {
876+
for (int ixpar = 0; ixpar < 6; ++ixpar) {
877+
estimator.mMCScalePars[ixpar] = estimator.mMCScale->GetParameter(ixpar);
878+
LOGF(info, "Parameter index %i value %.5f", ixpar, estimator.mMCScalePars[ixpar]);
879+
}
880+
} else {
881+
LOGF(warning, "MC Scale information from %s for run %d not available", estimator.name.c_str(), bc.runNumber());
882+
}
883+
}
884+
estimator.mCalibrationStored = true;
885+
estimator.isSane();
886+
} else {
887+
LOGF(info, "Calibration information from %s for run %d not available, will fill this estimator with invalid values and continue (no crash).", estimator.name.c_str(), bc.runNumber());
888+
}
889+
};
890+
891+
for (auto const& table : mEnabledCentralityTables) {
892+
switch (table) {
893+
case centrality::kFV0As:
894+
getccdb(fv0aInfo, ccdbConfig.genName);
895+
break;
896+
case centrality::kFT0Ms:
897+
getccdb(ft0mInfo, ccdbConfig.genName);
898+
break;
899+
case centrality::kFT0As:
900+
getccdb(ft0aInfo, ccdbConfig.genName);
901+
break;
902+
case centrality::kFT0Cs:
903+
getccdb(ft0cInfo, ccdbConfig.genName);
904+
break;
905+
case centrality::kFT0CVariant1s:
906+
getccdb(ft0cVariant1Info, ccdbConfig.genName);
907+
break;
908+
case centrality::kFDDMs:
909+
getccdb(fddmInfo, ccdbConfig.genName);
910+
break;
911+
case centrality::kNTPVs:
912+
getccdb(ntpvInfo, ccdbConfig.genName);
913+
break;
914+
case centrality::kNGlobals:
915+
getccdb(nGlobalInfo, ccdbConfig.genName);
916+
break;
917+
case centrality::kMFTs:
918+
getccdb(mftInfo, ccdbConfig.genName);
919+
break;
920+
default:
921+
LOGF(fatal, "Table %d not supported in Run3", table);
922+
break;
923+
}
924+
}
925+
} else {
926+
if (!ccdbConfig.doNotCrashOnNull) { // default behaviour: crash
927+
LOGF(fatal, "Centrality calibration is not available in CCDB for run=%d at timestamp=%llu", bc.runNumber(), bc.timestamp());
928+
} else { // only if asked: continue filling with non-valid values (105)
929+
LOGF(info, "Centrality calibration is not available in CCDB for run=%d at timestamp=%llu, will fill tables with dummy values", bc.runNumber(), bc.timestamp());
930+
}
931+
}
932+
}
933+
934+
/**
935+
* @brief Populates a table with data based on the given calibration information and multiplicity.
936+
*
937+
* @param table The table to populate.
938+
* @param estimator The calibration information.
939+
* @param multiplicity The multiplicity value.
940+
*/
941+
942+
auto populateTable = [&](auto& table, struct CalibrationInfo& estimator, float multiplicity) {
943+
const bool assignOutOfRange = embedINELgtZEROselection && !collision.isInelGt0();
944+
auto scaleMC = [](float x, float pars[6]) {
945+
return std::pow(((pars[0] + pars[1] * std::pow(x, pars[2])) - pars[3]) / pars[4], 1.0f / pars[5]);
946+
};
947+
948+
float percentile = 105.0f;
949+
float scaledMultiplicity = multiplicity;
950+
if (estimator.mCalibrationStored) {
951+
if (estimator.mMCScale != nullptr) {
952+
scaledMultiplicity = scaleMC(multiplicity, estimator.mMCScalePars);
953+
LOGF(debug, "Unscaled %s multiplicity: %f, scaled %s multiplicity: %f", estimator.name.c_str(), multiplicity, estimator.name.c_str(), scaledMultiplicity);
954+
}
955+
percentile = estimator.mhMultSelCalib->GetBinContent(estimator.mhMultSelCalib->FindFixBin(scaledMultiplicity));
956+
if (assignOutOfRange)
957+
percentile = 100.5f;
958+
}
959+
LOGF(debug, "%s centrality/multiplicity percentile = %.0f for a zvtx eq %s value %.0f", estimator.name.c_str(), percentile, estimator.name.c_str(), scaledMultiplicity);
960+
table(percentile);
961+
return percentile;
962+
};
963+
964+
for (auto const& table : mEnabledCentralityTables) {
965+
switch (table) {
966+
case centrality::kFV0As:
967+
populateTable(centFV0A, fv0aInfo, multZeqFV0A);
968+
break;
969+
case centrality::kFT0Ms:
970+
const float perC = populateTable(centFT0M, ft0mInfo, multZeqFT0A + multZeqFT0C);
971+
break;
972+
case centrality::kFT0As:
973+
const float perC = populateTable(centFT0A, ft0aInfo, multZeqFT0A);
974+
break;
975+
case centrality::kFT0Cs:
976+
const float perC = populateTable(centFT0C, ft0cInfo, multZeqFT0C);
977+
break;
978+
case centrality::kFT0CVariant1s:
979+
populateTable(centFT0CVariant1, ft0cVariant1Info, multZeqFT0C);
980+
break;
981+
case centrality::kFDDMs:
982+
populateTable(centFDDM, fddmInfo, multZeqFDDA + multZeqFDDC);
983+
break;
984+
case centrality::kNTPVs:
985+
populateTable(centNTPV, ntpvInfo, multZeqNTracksPV);
986+
break;
987+
case centrality::kNGlobals:
988+
populateTable(centNGlobals, nGlobalInfo, multNTracksGlobal);
989+
break;
990+
case centrality::kMFTs:
991+
populateTable(centMFTs, mftInfo, mftNtracks);
992+
break;
993+
default:
994+
LOGF(fatal, "Table %d not supported in Run3", table);
995+
break;
996+
}
997+
}
998+
791999
}
7921000
}
7931001

0 commit comments

Comments
 (0)