ATLAS Offline Software
Loading...
Searching...
No Matches
TrackOverlayDecisionAlg.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 * */
4
5#ifndef TRACKOVERLAYREC_TRACKOVERLAYDECISIONALG_H
6#define TRACKOVERLAYREC_TRACKOVERLAYDECISIONALG_H
7
8
9// FrameWork includes
11
13#include "GaudiKernel/ToolHandle.h"
14#include "Gaudi/Property.h"
16// local includes
18
19//
24
25//ONNX Runtime include(s)
26#include <onnxruntime_cxx_api.h>
28
29// STL includes
30#include <string>
31#include <tuple>
32#include <vector>
33#include <cstdint> //uint64_t
34#include <memory>
35#include <cmath> //M_PI etc
36
38
39 const double M_TWOPI = 2.0 * M_PI;
40 // Calculate constants only once for feature scaling
41 const float px_diff = 0.00029734736; // (1/3363.07) px_max: 1893.19; px_min: -1.46988e+03
42 const float py_diff = 0.000335; //(1/2979.65) py_max: 1628.23; py_min: -1.35142e+03
43 const float pz_diff = 0.00025; //(1/3924.99) pz_max: 2420.35 pz_min: -1.50464e+03
44 const float pt_diff = 0.0005283; //(1/1892.74) pt_max: 1893.24 pt_min: 5.00006e-01
45 const float e_diff = 0.000372; //(1/2689.63) e_max: 2690.14 e_min: 5.08307e-01
46 const float pu_diff = 0.01449; //(1/69) pu_max: 84.5 pu_min: 15.5
47 const float multi_diff = 0.00342; //(1/292) multiplicity_max:310.0 min:1.80000000e+01
48 const float eventPt_diff = 0.0004798; //(1/2084.2) eventPt_max: 2084.61 min:3.42359395e-01
49 const float area0p2 = 127.388535032;//(1.0 / (M_PI * 0.05 * 0.05)) for R=0.05
50 const float area0p05 = 7.961783; // 1.0 / (M_PI * 0.2 * 0.2); for R=0.2
51 const float constant1 = 0.000417; //(1.0 / 2395.2); 1/max_of_multiplicity_0p2
52 const float constant2 = 0.00002626749; //(1.0 / 38069.86); 1/max_of_multiplicity_0p05
53 const float constant3 = 0.014797; //(1.0 / 67.58); 1/max_of_sum_0p2
54 const float constant4 = 0.006934; //(1.0 / 144.21); 1/max_of_sum_0p05
55 const float constant5 = 0.0004086; //(1.0 / 2447.24); 1/max_of_sumPtAroundTrack for R=0.2
56 const float constant6 = 0.0004186; //(1.0 / 2388.55); 1/max_of_sumPtAroundTrack for R=0.05
57
59 public:
61 TrackOverlayDecisionAlg( const std::string& name, ISvcLocator* pSvcLocator );
63 virtual ~TrackOverlayDecisionAlg() = default;
65 virtual StatusCode initialize() override final;
66 virtual StatusCode execute(const EventContext& ctx) const override final;
68 virtual StatusCode finalize() override final;
69 private:
70 ToolHandle<IAthSelectionTool> m_truthSelectionTool{this, "TruthSelectionTool","AthTruthSelectionTool", "Truth selection tool (for efficiencies and resolutions)"};
73 //set the "selectedByPileupSwitch" decoration for all particles in the passed vector
74 void markSelectedByPileupSwitch(const std::vector<const xAOD::TruthParticle*> & truthParticles) const;
75 BooleanProperty m_useTrackSelection {this, "useTrackSelection", false, "plot only tracks accepted by selection tool"};
76 StringProperty m_pileupSwitch {this, "PileupSwitch", "HardScatter", "Pileup truth strategy to use. May be \"All\", \"HardScatter\", or \"PileUp\""};
77 FloatProperty m_lowProb{this,"LowProb",0.5,"Truth match prob. cutoff for efficiency (lower bound) and fake (upper bound) classification."};
78 //EventInfo container name
79 SG::ReadHandleKey<xAOD::EventInfo> m_eventInfoContainerName{this,"EventInfoContainerName", "EventInfo", ""};
80 //TruthParticle container's name
81 SG::ReadHandleKey<xAOD::TruthPileupEventContainer> m_truthPileUpEventName{this, "TruthPileupEvents", "TruthPileupEvents","Name of the truth pileup events container probably TruthPileupEvent(s)"};
82 SG::ReadHandleKey<xAOD::TruthParticleContainer> m_truthParticleName{this, "TruthParticleContainerName", "TruthParticles", ""};
83 SG::ReadHandleKey<xAOD::TruthEventContainer> m_truthEventName{this, "TruthEvents", "TruthEvents","Name of the truth events container probably either TruthEvent or TruthEvents"};
84 // Get truth particles into a vector, possibly using the pileup from the event
85 const std::vector<const xAOD::TruthParticle *> getTruthParticles() const;
86 FilterReporterParams m_filterParams {this, "TrackOverlayDecisionAlg", "Decides whether events should be reconstructed in track-overlay workflow or MC-overlay."};
87 Gaudi::Property<bool> m_invertfilter{this, "InvertFilter", false, "Invert filter decision."};
88 Gaudi::Property<float> m_MLthreshold{this, "MLThreshold", 0.74201, "ML threshold for bad/good tracks decision. ML scores larger than this threshold are considered as bad tracks."};
89 SG::WriteDecorHandleKey<xAOD::EventInfo> m_decIsMCOverlayKey{this, "IsMCOverlayDecor", m_eventInfoContainerName, "TrackOverlayIsMCOverlay", "1 if the event is reconstructed in the MC-overlay workflow"};
90 // Set up the ONNX Runtime session
91 ServiceHandle<AthOnnx::IOnnxRuntimeSvc> m_svc{this, "ONNXRuntimeSvc", "AthOnnx::OnnxRuntimeSvc", "CaloMuonScoreTool ONNXRuntimeSvc"};
92 std::tuple<std::vector<int64_t>, std::vector<char*>> m_inputInfo;
93 std::tuple<std::vector<int64_t>, std::vector<char*>> m_outputInfo;
94 std::unique_ptr<Ort::Session> m_session;
95 inline std::tuple<std::vector<int64_t>, std::vector<char*> > GetInputNodeInfo(const std::unique_ptr< Ort::Session >& session) {
96 std::vector<int64_t> input_node_dims;
97 size_t num_input_nodes = session->GetInputCount();
98 std::vector<char*> input_node_names(num_input_nodes);
99 Ort::AllocatorWithDefaultOptions allocator;
100 for( std::size_t i = 0; i < num_input_nodes; i++ ) {
101 char* input_name = session->GetInputNameAllocated(i, allocator).release();
102 input_node_names[i] = input_name;
103 Ort::TypeInfo type_info = session->GetInputTypeInfo(i);
104 auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
105 input_node_dims = tensor_info.GetShape();
106 }
107 return std::make_tuple(input_node_dims, input_node_names);
108 }
109
110 inline std::tuple<std::vector<int64_t>, std::vector<char*> > GetOutputNodeInfo(const std::unique_ptr< Ort::Session >& session){
111 std::vector<int64_t> output_node_dims;
112 size_t num_output_nodes = session->GetOutputCount();
113 std::vector<char*> output_node_names(num_output_nodes);
114 Ort::AllocatorWithDefaultOptions allocator;
115 for( std::size_t i = 0; i < num_output_nodes; i++ ) {
116 char* output_name = session->GetOutputNameAllocated(i, allocator).release();
117 output_node_names[i] = output_name;
118 Ort::TypeInfo type_info = session->GetOutputTypeInfo(i);
119 auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
120 output_node_dims = tensor_info.GetShape();
121 }
122 return std::make_tuple(output_node_dims, output_node_names);
123 }
124 };
125
126} // namespace TrackOverlay
127#endif
#define M_PI
header file for interface of selection tools in this package
Property holding a SG store/key/clid from which a ReadHandle is made.
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
An algorithm that can be simultaneously executed in multiple threads.
a handle for applying algorithm filter decisions
IAthSelectionTool is a virtual baseclass for selection methods.
Property holding a SG store/key/clid from which a ReadHandle is made.
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoContainerName
std::tuple< std::vector< int64_t >, std::vector< char * > > GetInputNodeInfo(const std::unique_ptr< Ort::Session > &session)
Gaudi::Property< bool > m_invertfilter
invert filter decision at the end
SG::WriteDecorHandleKey< xAOD::EventInfo > m_decIsMCOverlayKey
virtual StatusCode execute(const EventContext &ctx) const override final
Athena algorithm's interface method execute().
virtual ~TrackOverlayDecisionAlg()=default
Destructor.
std::tuple< std::vector< int64_t >, std::vector< char * > > m_outputInfo
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventName
std::tuple< std::vector< int64_t >, std::vector< char * > > GetOutputNodeInfo(const std::unique_ptr< Ort::Session > &session)
std::tuple< std::vector< int64_t >, std::vector< char * > > m_inputInfo
virtual StatusCode finalize() override final
Athena algorithm's interface method finalize().
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleName
SG::ReadHandleKey< xAOD::TruthPileupEventContainer > m_truthPileUpEventName
ServiceHandle< AthOnnx::IOnnxRuntimeSvc > m_svc
void markSelectedByPileupSwitch(const std::vector< const xAOD::TruthParticle * > &truthParticles) const
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
Definition AuxElement.h:576
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
void initialize()
#define private
Definition testRead.cxx:27