From 2315a92682332c3d797cda078a88684fee514790 Mon Sep 17 00:00:00 2001 From: chchoi Date: Tue, 14 Jan 2025 23:50:19 +0900 Subject: [PATCH] Resolved formatting issues --- PWGJE/Core/JetTaggingUtilities.h | 55 +++++++++++++++++------------ PWGJE/TableProducer/jetTaggerHF.cxx | 27 +++++++------- 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/PWGJE/Core/JetTaggingUtilities.h b/PWGJE/Core/JetTaggingUtilities.h index bce0faadbc9..d9bbf478397 100644 --- a/PWGJE/Core/JetTaggingUtilities.h +++ b/PWGJE/Core/JetTaggingUtilities.h @@ -109,20 +109,23 @@ struct BJetSVParams { }; // ONNX Runtime tensor (Ort::Value) allocator for using customized inputs of ML models. -class TensorAllocator { -protected: +class TensorAllocator +{ + protected: #if !__has_include() Ort::MemoryInfo mem_info; #endif -public: + public: TensorAllocator() #if !__has_include() : mem_info(Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtArenaAllocator, OrtMemType::OrtMemTypeDefault)) #endif - {} + { + } ~TensorAllocator() = default; template - Ort::Value createTensor(std::vector& input, std::vector& inputShape) { + Ort::Value createTensor(std::vector& input, std::vector& inputShape) + { #if __has_include() return Ort::Experimental::Value::CreateTensor(input.data(), input.size(), inputShape); #else @@ -132,8 +135,9 @@ class TensorAllocator { }; // TensorAllocator for GNN b-jet tagger -class GNNBjetAllocator : public TensorAllocator { -private: +class GNNBjetAllocator : public TensorAllocator +{ + private: int64_t nJetFeat; int64_t nTrkFeat; int64_t nFlav; @@ -144,23 +148,26 @@ class GNNBjetAllocator : public TensorAllocator { std::vector tfJetStdev; std::vector tfTrkMean; std::vector tfTrkStdev; - + std::vector> edgesList; // Jet feature normalization template - T jetFeatureTransform(T feat, int idx) const { + T jetFeatureTransform(T feat, int idx) const + { return (feat - tfJetMean[idx]) / tfJetStdev[idx]; } // Track feature normalization template - T trkFeatureTransform(T feat, int idx) const { + T trkFeatureTransform(T feat, int idx) const + { return (feat - tfTrkMean[idx]) / tfTrkStdev[idx]; } // Edge input of GNN (fully-connected graph) - void setEdgesList(void) { + void setEdgesList(void) + { for (int64_t nNodes = 0; nNodes <= maxNNodes; ++nNodes) { std::vector> edges; // Generate all permutations of (i, j) where i != j @@ -189,7 +196,8 @@ class GNNBjetAllocator : public TensorAllocator { // Replace NaN in a vector into value template - static int replaceNaN(std::vector& vec, T value) { + static int replaceNaN(std::vector& vec, T value) + { int numNaN = 0; for (auto& el : vec) { if (std::isnan(el)) { @@ -200,17 +208,18 @@ class GNNBjetAllocator : public TensorAllocator { return numNaN; } -public: + public: GNNBjetAllocator() : TensorAllocator(), nJetFeat(4), nTrkFeat(13), nFlav(3), nTrkOrigin(5), maxNNodes(40) {} - GNNBjetAllocator(int64_t nJetFeat, int64_t nTrkFeat, int64_t nFlav, int64_t nTrkOrigin, std::vector& tfJetMean, std::vector& tfJetStdev, std::vector& tfTrkMean, std::vector& tfTrkStdev, int64_t maxNNodes=40) - : TensorAllocator(), nJetFeat(nJetFeat), nTrkFeat(nTrkFeat), nFlav(nFlav), nTrkOrigin(nTrkOrigin), maxNNodes(maxNNodes), tfJetMean(tfJetMean), tfJetStdev(tfJetStdev), tfTrkMean(tfTrkMean), tfTrkStdev(tfTrkStdev) + GNNBjetAllocator(int64_t nJetFeat, int64_t nTrkFeat, int64_t nFlav, int64_t nTrkOrigin, std::vector& tfJetMean, std::vector& tfJetStdev, std::vector& tfTrkMean, std::vector& tfTrkStdev, int64_t maxNNodes = 40) + : TensorAllocator(), nJetFeat(nJetFeat), nTrkFeat(nTrkFeat), nFlav(nFlav), nTrkOrigin(nTrkOrigin), maxNNodes(maxNNodes), tfJetMean(tfJetMean), tfJetStdev(tfJetStdev), tfTrkMean(tfTrkMean), tfTrkStdev(tfTrkStdev) { setEdgesList(); } ~GNNBjetAllocator() = default; // Copy operator for initializing GNNBjetAllocator using Configurable values - GNNBjetAllocator& operator=(const GNNBjetAllocator& other) { + GNNBjetAllocator& operator=(const GNNBjetAllocator& other) + { nJetFeat = other.nJetFeat; nTrkFeat = other.nTrkFeat; nFlav = other.nFlav; @@ -226,12 +235,13 @@ class GNNBjetAllocator : public TensorAllocator { // Allocate & Return GNN input tensors (std::vector) template - void getGNNInput(std::vector& jetFeat, std::vector>& trkFeat, std::vector& feat, std::vector& gnnInput) { + void getGNNInput(std::vector& jetFeat, std::vector>& trkFeat, std::vector& feat, std::vector& gnnInput) + { int64_t nNodes = trkFeat.size(); std::vector edgesShape{2, nNodes * nNodes}; gnnInput.emplace_back(createTensor(edgesList[nNodes], edgesShape)); - + std::vector featShape{nNodes, nJetFeat + nTrkFeat}; int numNaN = replaceNaN(jetFeat, 0.f); @@ -242,7 +252,7 @@ class GNNBjetAllocator : public TensorAllocator { for (size_t i = 0; i < aTrkFeat.size(); ++i) feat.push_back(trkFeatureTransform(aTrkFeat[i], i)); } - + gnnInput.emplace_back(createTensor(feat, featShape)); if (numNaN > 0) { @@ -1164,16 +1174,15 @@ void analyzeJetTrackInfo4GNN(AnalysisJet const& analysisJet, AnyTracks const& /* if (constituent.pt() < trackPtMin) { continue; } - + int sign = jettaggingutilities::getGeoSign(analysisJet, constituent); auto origConstit = constituent.template track_as(); if (static_cast(tracksParams.size()) < nMaxConstit) { tracksParams.emplace_back(std::vector{constituent.pt(), origConstit.phi(), constituent.eta(), static_cast(constituent.sign()), std::abs(constituent.dcaXY()) * sign, constituent.sigmadcaXY(), std::abs(constituent.dcaXYZ()) * sign, constituent.sigmadcaXYZ(), static_cast(origConstit.itsNCls()), static_cast(origConstit.tpcNClsFound()), static_cast(origConstit.tpcNClsCrossedRows()), origConstit.itsChi2NCl(), origConstit.tpcChi2NCl()}); - } - else { - // If there are more than nMaxConstit constituents in the jet, select only 40 constituents with the highest DCA_XY significance. + } else { + // If there are more than nMaxConstit constituents in the jet, select only nMaxConstit constituents with the highest DCA_XY significance. size_t minIdx = 0; for (size_t i = 0; i < tracksParams.size(); ++i) { if (tracksParams[i][4] / tracksParams[i][5] < tracksParams[minIdx][4] / tracksParams[minIdx][5]) diff --git a/PWGJE/TableProducer/jetTaggerHF.cxx b/PWGJE/TableProducer/jetTaggerHF.cxx index a19194bc815..bf3eca2752f 100644 --- a/PWGJE/TableProducer/jetTaggerHF.cxx +++ b/PWGJE/TableProducer/jetTaggerHF.cxx @@ -218,18 +218,18 @@ struct JetTaggerHFTask { if (doprocessAlgorithmGNN) { if constexpr (isMC) { switch (origin) { - case 2: - registry.fill(HIST("h_db_b"), scoreML[jet.globalIndex()]); - break; - case 1: - registry.fill(HIST("h_db_c"), scoreML[jet.globalIndex()]); - break; - case 0: - case 3: - registry.fill(HIST("h_db_lf"), scoreML[jet.globalIndex()]); - break; - default: - LOGF(debug, "doprocessAlgorithmGNN, Unexpected origin value: %d (%d)", origin, jet.globalIndex()); + case 2: + registry.fill(HIST("h_db_b"), scoreML[jet.globalIndex()]); + break; + case 1: + registry.fill(HIST("h_db_c"), scoreML[jet.globalIndex()]); + break; + case 0: + case 3: + registry.fill(HIST("h_db_lf"), scoreML[jet.globalIndex()]); + break; + default: + LOGF(debug, "doprocessAlgorithmGNN, Unexpected origin value: %d (%d)", origin, jet.globalIndex()); } } registry.fill(HIST("h2_pt_db"), jet.pt(), scoreML[jet.globalIndex()]); @@ -380,8 +380,7 @@ struct JetTaggerHFTask { auto modelOutput = bMlResponse.getModelOutput(gnnInput, 0); scoreML[jet.globalIndex()] = jettaggingutilities::Db(modelOutput, fC); - } - else { + } else { scoreML[jet.globalIndex()] = -999.; LOGF(debug, "doprocessAlgorithmGNN, trkFeat.size() <= 0 (%d)", jet.globalIndex()); }