Skip to content

Commit 73b8dc1

Browse files
authored
Merge branch 'AliceO2Group:master' into master
2 parents f80040b + ef10e98 commit 73b8dc1

File tree

146 files changed

+13446
-7682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+13446
-7682
lines changed

ALICE3/Tasks/alice3-multicharm.cxx

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ struct alice3multicharm {
8484
std::string prefix = "bdt"; // JSON group name
8585
Configurable<std::string> ccdbUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
8686
Configurable<std::string> localPath{"localPath", "MCharm_BDTModel.onnx", "(std::string) Path to the local .onnx file."};
87-
Configurable<std::string> pathCCDB{"btdPathCCDB", "Users/j/jekarlss/MLModels2", "Path on CCDB"};
88-
Configurable<int64_t> timestampCCDB{"timestampCCDB", -1, "timestamp of the ONNX file for ML model used to query in CCDB. Exceptions: > 0 for the specific timestamp, 0 gets the run dependent timestamp"};
87+
Configurable<std::string> pathCCDB{"btdPathCCDB", "Users/j/jekarlss/MLModels", "Path on CCDB"};
88+
Configurable<int64_t> timestampCCDB{"timestampCCDB", 1695750420200, "timestamp of the ONNX file for ML model used to query in CCDB. Please use 1695750420200"};
8989
Configurable<bool> loadModelsFromCCDB{"loadModelsFromCCDB", false, "Flag to enable or disable the loading of models from CCDB"};
9090
Configurable<bool> enableOptimizations{"enableOptimizations", false, "Enables the ONNX extended model-optimization: sessionOptions.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_EXTENDED)"};
9191
Configurable<bool> enableML{"enableML", false, "Enables bdt model"};
9292
Configurable<std::vector<float>> requiredScores{"requiredScores", {0.5, 0.75, 0.85, 0.9, 0.95, 0.99}, "Vector of different scores to try"};
9393
} bdt;
9494

9595
ConfigurableAxis axisEta{"axisEta", {80, -4.0f, +4.0f}, "#eta"};
96-
ConfigurableAxis axisXicMass{"axisXicMass", {200, 2.368f, 2.568f}, "XiC Inv Mass (GeV/c^{2})"};
96+
ConfigurableAxis axisXicMass{"axisXicMass", {200, 2.368f, 2.568f}, "Xic Inv Mass (GeV/c^{2})"};
9797
ConfigurableAxis axisXiccMass{"axisXiccMass", {200, 3.521f, 3.721f}, "Xicc Inv Mass (GeV/c^{2})"};
9898
ConfigurableAxis axisDCA{"axisDCA", {400, 0, 400}, "DCA (#mum)"};
9999
ConfigurableAxis axisRadiusLarge{"axisRadiusLarge", {1000, 0, 20}, "Decay radius (cm)"};
@@ -102,6 +102,7 @@ struct alice3multicharm {
102102
ConfigurableAxis axisNSigma{"axisNSigma", {21, -10, 10}, "nsigma"};
103103
ConfigurableAxis axisDecayLength{"axisDecayLength", {2000, 0, 2000}, "Decay lenght (#mum)"};
104104
ConfigurableAxis axisDcaDaughters{"axisDcaDaughters", {200, 0, 100}, "DCA (mum)"};
105+
ConfigurableAxis axisBDTScore{"axisBDTScore", {100, 0, 1}, "BDT Score"};
105106
ConfigurableAxis axisPt{"axisPt", {VARIABLE_WIDTH, 0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.2f, 2.4f, 2.6f, 2.8f, 3.0f, 3.2f, 3.4f, 3.6f, 3.8f, 4.0f, 4.4f, 4.8f, 5.2f, 5.6f, 6.0f, 6.5f, 7.0f, 7.5f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 17.0f, 19.0f, 21.0f, 23.0f, 25.0f, 30.0f, 35.0f, 40.0f, 50.0f}, "pt axis for QA histograms"};
106107

107108
Configurable<float> xiMinDCAxy{"xiMinDCAxy", -1, "[0] in |DCAxy| > [0]+[1]/pT"};
@@ -133,21 +134,6 @@ struct alice3multicharm {
133134

134135
void init(InitContext&)
135136
{
136-
ccdb->setURL(bdt.ccdbUrl.value);
137-
if (bdt.loadModelsFromCCDB) {
138-
ccdbApi.init(bdt.ccdbUrl);
139-
LOG(info) << "Fetching model for timestamp: " << bdt.timestampCCDB.value;
140-
bool retrieveSuccessMCharm = ccdbApi.retrieveBlob(bdt.pathCCDB.value, ".", metadata, bdt.timestampCCDB.value, false, bdt.localPath.value);
141-
142-
if (retrieveSuccessMCharm) {
143-
bdtMCharm.initModel(bdt.localPath.value, bdt.enableOptimizations.value);
144-
} else {
145-
LOG(fatal) << "Error encountered while fetching/loading the MCharm model from CCDB! Maybe the model doesn't exist yet for this runnumber/timestamp?";
146-
}
147-
} else {
148-
bdtMCharm.initModel(bdt.localPath.value, bdt.enableOptimizations.value);
149-
}
150-
151137
histos.add("SelectionQA/hDCAXicDaughters", "hDCAXicDaughters; DCA between Xic daughters (#mum)", kTH1D, {axisDcaDaughters});
152138
histos.add("SelectionQA/hDCAXiccDaughters", "hDCAXiccDaughters; DCA between Xicc daughters (#mum)", kTH1D, {axisDcaDaughters});
153139
histos.add("SelectionQA/hDCAxyXi", "hDCAxyXi; Xi DCAxy to PV (#mum)", kTH1D, {axisDCA});
@@ -249,6 +235,24 @@ struct alice3multicharm {
249235
histos.add("h3dXicc", "h3dXicc; Xicc pT (GeV/#it(c)); Xicc #eta; Xicc mass (GeV/#it(c)^{2})", kTH3D, {axisPt, axisEta, axisXiccMass});
250236

251237
if (bdt.enableML) {
238+
ccdb->setURL(bdt.ccdbUrl.value);
239+
if (bdt.loadModelsFromCCDB) {
240+
ccdbApi.init(bdt.ccdbUrl);
241+
LOG(info) << "Fetching model for timestamp: " << bdt.timestampCCDB.value;
242+
bool retrieveSuccessMCharm = ccdbApi.retrieveBlob(bdt.pathCCDB.value, ".", metadata, bdt.timestampCCDB.value, false, bdt.localPath.value);
243+
244+
if (retrieveSuccessMCharm) {
245+
bdtMCharm.initModel(bdt.localPath.value, bdt.enableOptimizations.value);
246+
} else {
247+
LOG(fatal) << "Error encountered while fetching/loading the MCharm model from CCDB! Maybe the model doesn't exist yet for this runnumber/timestamp?";
248+
}
249+
} else {
250+
bdtMCharm.initModel(bdt.localPath.value, bdt.enableOptimizations.value);
251+
}
252+
253+
histos.add("hBDTScore", "hBDTScore", kTH1D, {axisBDTScore});
254+
histos.add("hBDTScoreVsXiccMass", "hBDTScoreVsXiccMass", kTH2D, {axisXiccMass, axisBDTScore});
255+
histos.add("hBDTScoreVsXiccPt", "hBDTScoreVsXiccPt", kTH2D, {axisXiccMass, axisPt});
252256
for (const auto& score : bdt.requiredScores.value) {
253257
histPath = std::format("MLQA/RequiredBDTScore_{}/", static_cast<int>(score * 100));
254258
histPointers.insert({histPath + "hDCAXicDaughters", histos.add((histPath + "hDCAXicDaughters").c_str(), "hDCAXicDaughters", {kTH1D, {{axisDcaDaughters}}})});
@@ -292,7 +296,6 @@ struct alice3multicharm {
292296
void genericProcessXicc(TMCharmCands xiccCands)
293297
{
294298
for (const auto& xiccCand : xiccCands) {
295-
296299
if (bdt.enableML) {
297300
std::vector<float> inputFeatures{
298301
xiccCand.xicDauDCA(),
@@ -318,6 +321,10 @@ struct alice3multicharm {
318321
float* probabilityMCharm = bdtMCharm.evalModel(inputFeatures);
319322
float bdtScore = probabilityMCharm[1];
320323

324+
histos.fill(HIST("hBDTScore"), bdtScore);
325+
histos.fill(HIST("hBDTScoreVsXiccMass"), xiccCand.xiccMass(), bdtScore);
326+
histos.fill(HIST("hBDTScoreVsXiccPt"), xiccCand.xiccPt(), bdtScore);
327+
321328
for (const auto& requiredScore : bdt.requiredScores.value) {
322329
if (bdtScore > requiredScore) {
323330
histPath = std::format("MLQA/RequiredBDTScore_{}/", static_cast<int>(requiredScore * 100));

Common/CCDB/ctpRateFetcher.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ double ctpRateFetcher::fetchCTPratesClasses(o2::ccdb::BasicCCDBManager* /*ccdb*/
6969
LOG(warn) << "Trigger class " << className << " not found in CTPConfiguration";
7070
return -1.;
7171
}
72-
auto rate{mScalers->getRateGivenT(timeStamp * 1.e-3, classIndex, inputType)};
72+
auto rate{mScalers->getRateGivenT(timeStamp * 1.e-3, classIndex, inputType, 1)};
7373
return pileUpCorrection(rate.second);
7474
}
7575

7676
double ctpRateFetcher::fetchCTPratesInputs(o2::ccdb::BasicCCDBManager* /*ccdb*/, uint64_t timeStamp, int /*runNumber*/, int input)
7777
{
7878
std::vector<ctp::CTPScalerRecordO2> recs = mScalers->getScalerRecordO2();
7979
if (recs[0].scalersInps.size() == 48) {
80-
return pileUpCorrection(mScalers->getRateGivenT(timeStamp * 1.e-3, input, 7).second);
80+
return pileUpCorrection(mScalers->getRateGivenT(timeStamp * 1.e-3, input, 7, 1).second);
8181
} else {
8282
LOG(error) << "Inputs not available";
8383
return -1.;

Common/Core/MetadataHelper.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11-
12-
///
1311
/// \file TableHelper.h
1412
/// \author Nicolò Jacazio nicolo.jacazio@cern.ch
1513
/// \brief Utility to handle the metadata from the AOD
@@ -70,6 +68,4 @@ struct MetadataHelper {
7068

7169
} // namespace o2::common::core
7270

73-
using MetadataHelper = o2::common::core::MetadataHelper; // Alias for the MetadataHelper
74-
7571
#endif // COMMON_CORE_METADATAHELPER_H_

Common/Core/PID/TPCPIDResponse.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,18 @@ class Response
7474
/// Gets the expected resolution of the track
7575
template <typename CollisionType, typename TrackType>
7676
float GetExpectedSigma(const CollisionType& collision, const TrackType& trk, const o2::track::PID::ID id) const;
77+
/// Gets the expected resolution of the track with multTPC explicitly provided
78+
template <typename TrackType>
79+
float GetExpectedSigmaAtMultiplicity(const long multTPC, const TrackType& trk, const o2::track::PID::ID id) const;
7780
/// Gets the number of sigmas with respect the expected value
7881
template <typename CollisionType, typename TrackType>
7982
float GetNumberOfSigma(const CollisionType& collision, const TrackType& trk, const o2::track::PID::ID id) const;
8083
// Number of sigmas with respect to expected for MC, defining a tune-on-data signal value
8184
template <typename CollisionType, typename TrackType>
8285
float GetNumberOfSigmaMCTuned(const CollisionType& collision, const TrackType& trk, const o2::track::PID::ID id, float mcTunedTPCSignal) const;
86+
// Number of sigmas with respect to expected for MC, defining a tune-on-data signal value, explicit multTPC
87+
template <typename TrackType>
88+
float GetNumberOfSigmaMCTunedAtMultiplicity(const long multTPC, const TrackType& trk, const o2::track::PID::ID id, float mcTunedTPCSignal) const;
8389
/// Gets the deviation to the expected signal
8490
template <typename TrackType>
8591
float GetSignalDelta(const TrackType& trk, const o2::track::PID::ID id) const;
@@ -116,6 +122,14 @@ inline float Response::GetExpectedSignal(const TrackType& track, const o2::track
116122
/// Gets the expected resolution of the measurement
117123
template <typename CollisionType, typename TrackType>
118124
inline float Response::GetExpectedSigma(const CollisionType& collision, const TrackType& track, const o2::track::PID::ID id) const
125+
{
126+
// use multTPC (legacy behaviour) if multTPC not provided
127+
return Response::GetExpectedSigmaAtMultiplicity(collision.multTPC(), track, id);
128+
}
129+
130+
/// Gets the expected resolution of the measurement
131+
template <typename TrackType>
132+
inline float Response::GetExpectedSigmaAtMultiplicity(const long multTPC, const TrackType& track, const o2::track::PID::ID id) const
119133
{
120134
if (!track.hasTPC()) {
121135
return -999.f;
@@ -133,7 +147,7 @@ inline float Response::GetExpectedSigma(const CollisionType& collision, const Tr
133147
const double dEdx = o2::tpc::BetheBlochAleph(static_cast<float>(bg), mBetheBlochParams[0], mBetheBlochParams[1], mBetheBlochParams[2], mBetheBlochParams[3], mBetheBlochParams[4]) * std::pow(static_cast<float>(o2::track::pid_constants::sCharges[id]), mChargeFactor);
134148
const double relReso = GetRelativeResolutiondEdx(p, mass, o2::track::pid_constants::sCharges[id], mResolutionParams[3]);
135149

136-
const std::vector<double> values{1.f / dEdx, track.tgl(), std::sqrt(ncl), relReso, track.signed1Pt(), collision.multTPC() / mMultNormalization};
150+
const std::vector<double> values{1.f / dEdx, track.tgl(), std::sqrt(ncl), relReso, track.signed1Pt(), multTPC / mMultNormalization};
137151

138152
const float reso = sqrt(pow(mResolutionParams[0], 2) * values[0] + pow(mResolutionParams[1], 2) * (values[2] * mResolutionParams[5]) * pow(values[0] / sqrt(1 + pow(values[1], 2)), mResolutionParams[2]) + values[2] * pow(values[3], 2) + pow(mResolutionParams[4] * values[4], 2) + pow(values[5] * mResolutionParams[6], 2) + pow(values[5] * (values[0] / sqrt(1 + pow(values[1], 2))) * mResolutionParams[7], 2)) * dEdx * mMIP;
139153
reso >= 0.f ? resolution = reso : resolution = -999.f;
@@ -160,7 +174,13 @@ inline float Response::GetNumberOfSigma(const CollisionType& collision, const Tr
160174
template <typename CollisionType, typename TrackType>
161175
inline float Response::GetNumberOfSigmaMCTuned(const CollisionType& collision, const TrackType& trk, const o2::track::PID::ID id, float mcTunedTPCSignal) const
162176
{
163-
if (GetExpectedSigma(collision, trk, id) < 0.) {
177+
return Response::GetNumberOfSigmaMCTunedAtMultiplicity(collision.multTPC(), trk, id, mcTunedTPCSignal);
178+
}
179+
180+
template <typename TrackType>
181+
inline float Response::GetNumberOfSigmaMCTunedAtMultiplicity(const long multTPC, const TrackType& trk, const o2::track::PID::ID id, float mcTunedTPCSignal) const
182+
{
183+
if (GetExpectedSigmaAtMultiplicity(multTPC, trk, id) < 0.) {
164184
return -999.f;
165185
}
166186
if (GetExpectedSignal(trk, id) < 0.) {
@@ -169,7 +189,7 @@ inline float Response::GetNumberOfSigmaMCTuned(const CollisionType& collision, c
169189
if (!trk.hasTPC()) {
170190
return -999.f;
171191
}
172-
return ((mcTunedTPCSignal - GetExpectedSignal(trk, id)) / GetExpectedSigma(collision, trk, id));
192+
return ((mcTunedTPCSignal - GetExpectedSignal(trk, id)) / GetExpectedSigmaAtMultiplicity(multTPC, trk, id));
173193
}
174194

175195
/// Gets the deviation between the actual signal and the expected signal

Common/TableProducer/PID/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ o2physics_add_dpl_workflow(pid-tof-full
4343

4444
# TPC
4545

46+
o2physics_add_dpl_workflow(pid-tpc-service
47+
SOURCES pidTPCService.cxx
48+
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2Physics::MLCore O2Physics::AnalysisCCDB
49+
COMPONENT_NAME Analysis)
50+
4651
o2physics_add_dpl_workflow(pid-tpc-base
4752
SOURCES pidTPCBase.cxx
4853
PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2Physics::AnalysisCCDB

Common/TableProducer/PID/pidTPC.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ struct tpcPid {
447447
}
448448

449449
float nSigma = -999.f;
450+
int multTPC = 0;
451+
if (trk.has_collision()) {
452+
auto collision = collisions.rawIteratorAt(trk.collisionId());
453+
multTPC = collision.multTPC();
454+
}
450455
float bg = trk.tpcInnerParam() / o2::track::pid_constants::sMasses[pid]; // estimated beta-gamma for network cutoff
451456
if (useNetworkCorrection && speciesNetworkFlags[pid] && trk.has_collision() && bg > networkBetaGammaCutoff) {
452457

@@ -469,7 +474,7 @@ struct tpcPid {
469474
LOGF(fatal, "Network output-dimensions incompatible!");
470475
}
471476
} else {
472-
nSigma = response->GetNumberOfSigmaMCTuned(collisions.iteratorAt(trk.collisionId()), trk, pid, tpcSignal);
477+
nSigma = response->GetNumberOfSigmaMCTunedAtMultiplicity(multTPC, trk, pid, tpcSignal);
473478
}
474479
if (flagFull)
475480
tableFull(expSigma, nSigma);

0 commit comments

Comments
 (0)