Skip to content

Commit 7d6e3e4

Browse files
authored
[PWGJE] Adding a cut on IP for TreeCreator and SV reconstruction (#11182)
1 parent fd24ceb commit 7d6e3e4

File tree

6 files changed

+164
-128
lines changed

6 files changed

+164
-128
lines changed

PWGJE/Core/JetTaggingUtilities.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ int jetTrackFromHFShower(T const& jet, U const& /*tracks*/, V const& particles,
211211
hasMcParticle = true;
212212
auto const& particle = track.template mcParticle_as<V>();
213213
origin = RecoDecay::getParticleOrigin(particles, particle, searchUpToQuark);
214-
if (origin == 1 || origin == 2) { // 1=charm , 2=beauty
214+
if (origin == RecoDecay::OriginType::Prompt || origin == RecoDecay::OriginType::NonPrompt) { // 1=charm , 2=beauty
215215
hftrack = track;
216-
if (origin == 1) {
216+
if (origin == RecoDecay::OriginType::Prompt) {
217217
return JetTaggingSpecies::charm;
218218
}
219-
if (origin == 2) {
219+
if (origin == RecoDecay::OriginType::NonPrompt) {
220220
return JetTaggingSpecies::beauty;
221221
}
222222
}
@@ -244,12 +244,12 @@ int jetParticleFromHFShower(T const& jet, U const& particles, typename U::iterat
244244
for (const auto& particle : jet.template tracks_as<U>()) {
245245
hfparticle = particle; // for init if origin is 1 or 2, the particle is not hfparticle
246246
origin = RecoDecay::getParticleOrigin(particles, particle, searchUpToQuark);
247-
if (origin == 1 || origin == 2) { // 1=charm , 2=beauty
247+
if (origin == RecoDecay::OriginType::Prompt || origin == RecoDecay::OriginType::NonPrompt) { // 1=charm , 2=beauty
248248
hfparticle = particle;
249-
if (origin == 1) {
249+
if (origin == RecoDecay::OriginType::Prompt) {
250250
return JetTaggingSpecies::charm;
251251
}
252-
if (origin == 2) {
252+
if (origin == RecoDecay::OriginType::NonPrompt) {
253253
return JetTaggingSpecies::beauty;
254254
}
255255
}
@@ -993,11 +993,11 @@ void analyzeJetSVInfo4ML(AnalysisJet const& myJet, AnyTracks const& /*allTracks*
993993

994994
// Looping over the track info and putting them in the input vector
995995
template <typename AnalysisJet, typename AnyTracks, typename SecondaryVertices>
996-
void analyzeJetTrackInfo4ML(AnalysisJet const& analysisJet, AnyTracks const& /*allTracks*/, SecondaryVertices const& /*allSVs*/, std::vector<BJetTrackParams>& tracksParams, float trackPtMin = 0.5)
996+
void analyzeJetTrackInfo4ML(AnalysisJet const& analysisJet, AnyTracks const& /*allTracks*/, SecondaryVertices const& /*allSVs*/, std::vector<BJetTrackParams>& tracksParams, float trackPtMin = 0.5, float trackDcaXYMax = 10.0, float trackDcaZMax = 10.0)
997997
{
998998
for (const auto& constituent : analysisJet.template tracks_as<AnyTracks>()) {
999999

1000-
if (constituent.pt() < trackPtMin) {
1000+
if (constituent.pt() < trackPtMin || !trackAcceptanceWithDca(constituent, trackDcaXYMax, trackDcaZMax)) {
10011001
continue;
10021002
}
10031003

@@ -1026,11 +1026,11 @@ void analyzeJetTrackInfo4ML(AnalysisJet const& analysisJet, AnyTracks const& /*a
10261026

10271027
// Looping over the track info and putting them in the input vector without using any SV info
10281028
template <typename AnalysisJet, typename AnyTracks>
1029-
void analyzeJetTrackInfo4MLnoSV(AnalysisJet const& analysisJet, AnyTracks const& /*allTracks*/, std::vector<BJetTrackParams>& tracksParams, float trackPtMin = 0.5)
1029+
void analyzeJetTrackInfo4MLnoSV(AnalysisJet const& analysisJet, AnyTracks const& /*allTracks*/, std::vector<BJetTrackParams>& tracksParams, float trackPtMin = 0.5, float trackDcaXYMax = 10.0, float trackDcaZMax = 10.0)
10301030
{
10311031
for (const auto& constituent : analysisJet.template tracks_as<AnyTracks>()) {
10321032

1033-
if (constituent.pt() < trackPtMin) {
1033+
if (constituent.pt() < trackPtMin || !trackAcceptanceWithDca(constituent, trackDcaXYMax, trackDcaZMax)) {
10341034
continue;
10351035
}
10361036

PWGJE/Core/MlResponseHfTagging.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ class MlResponseHfTagging : public MlResponse<TypeOutputScore>
113113
/// @return A vector of input shapes
114114
std::vector<std::vector<int64_t>> getInputShape() const { return this->mModels[0].getInputShapes(); }
115115

116+
/// @brief Method to get the output shape of a model
117+
/// \param imod is the index of the model
118+
/// @return number of output nodes
119+
int getOutputNodes(int imod = 0) const { return this->mModels[imod].getNumOutputNodes(); }
120+
116121
/// Method to fill the inputs of jet, tracks and secondary vertices
117122
/// \param jet is the b-jet candidate
118123
/// \param tracks is the vector of tracks associated to the jet

PWGJE/TableProducer/jetTaggerHF.cxx

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct JetTaggerHFTask {
9494
Configurable<LabeledArray<double>> cutsMl{"cutsMl", {DefaultCutsMl[0], 1, 2, {"pT bin 0"}, {"score for default b-jet tagging", "uncer 1"}}, "ML selections per pT bin"};
9595
Configurable<int> nClassesMl{"nClassesMl", 2, "Number of classes in ML model"};
9696
Configurable<std::vector<std::string>> namesInputFeatures{"namesInputFeatures", std::vector<std::string>{"feature1", "feature2"}, "Names of ML model input features"};
97+
Configurable<bool> useDb{"useDb", false, "Flag to use DB for ML model instead of the score"};
9798

9899
Configurable<std::string> ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
99100
Configurable<std::vector<std::string>> modelPathsCCDB{"modelPathsCCDB", std::vector<std::string>{"Users/h/hahassan"}, "Paths of models on CCDB"};
@@ -297,16 +298,16 @@ struct JetTaggerHFTask {
297298
std::map<std::string, std::string> metadata;
298299
resoFuncMatch = resoFuncMatching;
299300

300-
const int IPmethodResolutionFunctionSize = 7;
301+
const int mIPmethodResolutionFunctionSize = 7;
301302

302303
auto loadCCDBforIP = [&](const std::vector<std::string>& paths, std::vector<TF1*>& targetVec, const std::string& name) {
303-
if (paths.size() != IPmethodResolutionFunctionSize) {
304+
if (paths.size() != mIPmethodResolutionFunctionSize) {
304305
usepTcategorize.value = false;
305306
LOG(info) << name << " does not have 7 entries. Disabling pT categorization (usepTcategorize = false).";
306307
resoFuncMatch = 0;
307308
return;
308309
}
309-
for (int i = 0; i < IPmethodResolutionFunctionSize; i++) {
310+
for (int i = 0; i < mIPmethodResolutionFunctionSize; i++) {
310311
targetVec.push_back(ccdbApi.retrieveFromTFileAny<TF1>(paths[i], metadata, -1));
311312
}
312313
};
@@ -335,7 +336,7 @@ struct JetTaggerHFTask {
335336
}
336337

337338
maxOrder = numCount + 1; // 0: untagged, >1 : N ordering
338-
const int IPmethodNumOfParameters = 9;
339+
const int mIPmethodNumOfParameters = 9;
339340

340341
// Set up the resolution function
341342
switch (resoFuncMatch) {
@@ -383,7 +384,7 @@ struct JetTaggerHFTask {
383384
for (size_t j = 0; j < resoFuncIncCCDB.size(); j++) {
384385
std::vector<float> params;
385386
if (resoFuncIncCCDB[j]) {
386-
for (int i = 0; i < IPmethodNumOfParameters; i++) {
387+
for (int i = 0; i < mIPmethodNumOfParameters; i++) {
387388
params.emplace_back(resoFuncIncCCDB[j]->GetParameter(i));
388389
}
389390
}
@@ -397,7 +398,7 @@ struct JetTaggerHFTask {
397398
for (size_t j = 0; j < resoFuncBeautyCCDB.size(); j++) {
398399
std::vector<float> params;
399400
if (resoFuncBeautyCCDB[j]) {
400-
for (int i = 0; i < IPmethodNumOfParameters; i++) {
401+
for (int i = 0; i < mIPmethodNumOfParameters; i++) {
401402
params.emplace_back(resoFuncBeautyCCDB[j]->GetParameter(i));
402403
}
403404
}
@@ -406,7 +407,7 @@ struct JetTaggerHFTask {
406407
for (size_t j = 0; j < resoFuncCharmCCDB.size(); j++) {
407408
std::vector<float> params;
408409
if (resoFuncCharmCCDB[j]) {
409-
for (int i = 0; i < IPmethodNumOfParameters; i++) {
410+
for (int i = 0; i < mIPmethodNumOfParameters; i++) {
410411
params.emplace_back(resoFuncCharmCCDB[j]->GetParameter(i));
411412
}
412413
}
@@ -415,7 +416,7 @@ struct JetTaggerHFTask {
415416
for (size_t j = 0; j < resoFuncLfCCDB.size(); j++) {
416417
std::vector<float> params;
417418
if (resoFuncLfCCDB[j]) {
418-
for (int i = 0; i < IPmethodNumOfParameters; i++) {
419+
for (int i = 0; i < mIPmethodNumOfParameters; i++) {
419420
params.emplace_back(resoFuncLfCCDB[j]->GetParameter(i));
420421
}
421422
}
@@ -427,7 +428,7 @@ struct JetTaggerHFTask {
427428
for (size_t j = 0; j < resoFuncDataCCDB.size(); j++) {
428429
std::vector<float> params;
429430
if (resoFuncDataCCDB[j]) {
430-
for (int i = 0; i < IPmethodNumOfParameters; i++) {
431+
for (int i = 0; i < mIPmethodNumOfParameters; i++) {
431432
params.emplace_back(resoFuncDataCCDB[j]->GetParameter(i));
432433
}
433434
}
@@ -507,7 +508,7 @@ struct JetTaggerHFTask {
507508
std::vector<jettaggingutilities::BJetSVParams> svsParams;
508509

509510
jettaggingutilities::analyzeJetSVInfo4ML(analysisJet, allTracks, allSVs, svsParams, svPtMin, svReductionFactor);
510-
jettaggingutilities::analyzeJetTrackInfo4ML(analysisJet, allTracks, allSVs, tracksParams, trackPtMin);
511+
jettaggingutilities::analyzeJetTrackInfo4ML(analysisJet, allTracks, allSVs, tracksParams, trackPtMin, trackDcaXYMax, trackDcaZMax);
511512

512513
int nSVs = analysisJet.template secondaryVertices_as<SecondaryVertices>().size();
513514

@@ -525,7 +526,15 @@ struct JetTaggerHFTask {
525526
bMlResponse.isSelectedMl(inputML, analysisJet.pt(), output);
526527
}
527528

528-
scoreML[analysisJet.globalIndex()] = output[0];
529+
if (bMlResponse.getOutputNodes() > 1) {
530+
auto mDb = [](std::vector<float> scores, float fC) {
531+
return std::log(scores[2] / (fC * scores[1] + (1 - fC) * scores[0]));
532+
};
533+
534+
scoreML[analysisJet.globalIndex()] = useDb ? mDb(output, fC) : output[2]; // 2 is the b-jet index
535+
} else {
536+
scoreML[analysisJet.globalIndex()] = output[0];
537+
}
529538
}
530539
}
531540

@@ -537,7 +546,7 @@ struct JetTaggerHFTask {
537546
std::vector<jettaggingutilities::BJetTrackParams> tracksParams;
538547
std::vector<jettaggingutilities::BJetSVParams> svsParams;
539548

540-
jettaggingutilities::analyzeJetTrackInfo4MLnoSV(analysisJet, allTracks, tracksParams, trackPtMin);
549+
jettaggingutilities::analyzeJetTrackInfo4MLnoSV(analysisJet, allTracks, tracksParams, trackPtMin, trackDcaXYMax, trackDcaZMax);
541550

542551
jettaggingutilities::BJetParams jetparam = {analysisJet.pt(), analysisJet.eta(), analysisJet.phi(), static_cast<int>(tracksParams.size()), 0, analysisJet.mass()};
543552
tracksParams.resize(nJetConst); // resize to the number of inputs of the ML

PWGJE/TableProducer/secondaryVertexReconstruction.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ struct SecondaryVertexReconstruction {
7272
Configurable<float> ptMinTrack{"ptMinTrack", -1., "min. track pT"};
7373
Configurable<float> etaMinTrack{"etaMinTrack", -99999., "min. pseudorapidity"};
7474
Configurable<float> etaMaxTrack{"etaMaxTrack", 4., "max. pseudorapidity"};
75+
Configurable<float> maxIPxy{"maxIPxy", 10, "maximum track DCA in xy plane"};
76+
Configurable<float> maxIPz{"maxIPz", 10, "maximum track DCA in z direction"};
7577
Configurable<bool> fillHistograms{"fillHistograms", true, "do validation plots"};
7678

7779
Configurable<std::string> ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
@@ -288,7 +290,7 @@ struct SecondaryVertexReconstruction {
288290
for (size_t iprong = prongIndex; iprong < particles.size(); ++iprong) {
289291

290292
const auto& testTrack = particles[iprong].template track_as<OriginalTracks>();
291-
if (testTrack.pt() < ptMinTrack || testTrack.eta() < etaMinTrack || testTrack.eta() > etaMaxTrack) {
293+
if (testTrack.pt() < ptMinTrack || testTrack.eta() < etaMinTrack || testTrack.eta() > etaMaxTrack || std::abs(testTrack.dcaXY()) > maxIPxy || std::abs(testTrack.dcaZ()) > maxIPz) {
292294
continue;
293295
}
294296

0 commit comments

Comments
 (0)