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//
23//ONNX Runtime include(s)
24#include <onnxruntime_cxx_api.h>
26
27// STL includes
28#include <string>
29#include <tuple>
30#include <vector>
31#include <cstdint> //uint64_t
32#include <memory>
33#include <cmath> //M_PI etc
34
36 const double M_TWOPI = 2.0 * M_PI;
37 // Calculate constants only once for feature scaling
38 const float px_diff = 0.00029734736; // (1/3363.07) px_max: 1893.19; px_min: -1.46988e+03
39 const float py_diff = 0.000335; //(1/2979.65) py_max: 1628.23; py_min: -1.35142e+03
40 const float pz_diff = 0.00025; //(1/3924.99) pz_max: 2420.35 pz_min: -1.50464e+03
41 const float pt_diff = 0.0005283; //(1/1892.74) pt_max: 1893.24 pt_min: 5.00006e-01
42 const float e_diff = 0.000372; //(1/2689.63) e_max: 2690.14 e_min: 5.08307e-01
43 const float pu_diff = 0.01449; //(1/69) pu_max: 84.5 pu_min: 15.5
44 const float multi_diff = 0.00342; //(1/292) multiplicity_max:310.0 min:1.80000000e+01
45 const float eventPt_diff = 0.0004798; //(1/2084.2) eventPt_max: 2084.61 min:3.42359395e-01
46 const float area0p2 = 127.388535032;//(1.0 / (M_PI * 0.05 * 0.05)) for R=0.05
47 const float area0p05 = 7.961783; // 1.0 / (M_PI * 0.2 * 0.2); for R=0.2
48 const float constant1 = 0.000417; //(1.0 / 2395.2); 1/max_of_multiplicity_0p2
49 const float constant2 = 0.00002626749; //(1.0 / 38069.86); 1/max_of_multiplicity_0p05
50 const float constant3 = 0.014797; //(1.0 / 67.58); 1/max_of_sum_0p2
51 const float constant4 = 0.006934; //(1.0 / 144.21); 1/max_of_sum_0p05
52 const float constant5 = 0.0004086; //(1.0 / 2447.24); 1/max_of_sumPtAroundTrack for R=0.2
53 const float constant6 = 0.0004186; //(1.0 / 2388.55); 1/max_of_sumPtAroundTrack for R=0.05
54
56 public:
58 TrackOverlayDecisionAlg( const std::string& name, ISvcLocator* pSvcLocator );
60 virtual ~TrackOverlayDecisionAlg() = default;
62 virtual StatusCode initialize() override final;
63 virtual StatusCode execute(const EventContext& ctx) const override final;
65 virtual StatusCode finalize() override final;
66 private:
67 ToolHandle<IAthSelectionTool> m_truthSelectionTool{this, "TruthSelectionTool","AthTruthSelectionTool", "Truth selection tool (for efficiencies and resolutions)"};
70 //set the "selectedByPileupSwitch" decoration for all particles in the passed vector
71 void markSelectedByPileupSwitch(const std::vector<const xAOD::TruthParticle*> & truthParticles) const;
72 BooleanProperty m_useTrackSelection {this, "useTrackSelection", false, "plot only tracks accepted by selection tool"};
73 StringProperty m_pileupSwitch {this, "PileupSwitch", "HardScatter", "Pileup truth strategy to use. May be \"All\", \"HardScatter\", or \"PileUp\""};
74 FloatProperty m_lowProb{this,"LowProb",0.5,"Truth match prob. cutoff for efficiency (lower bound) and fake (upper bound) classification."};
75 //EventInfo container name
76 SG::ReadHandleKey<xAOD::EventInfo> m_eventInfoContainerName{this,"EventInfoContainerName", "EventInfo", ""};
77 //TruthParticle container's name
78 SG::ReadHandleKey<xAOD::TruthPileupEventContainer> m_truthPileUpEventName{this, "TruthPileupEvents", "TruthPileupEvents","Name of the truth pileup events container probably TruthPileupEvent(s)"};
79 SG::ReadHandleKey<xAOD::TruthParticleContainer> m_truthParticleName{this, "TruthParticleContainerName", "TruthParticles", ""};
80 SG::ReadHandleKey<xAOD::TruthEventContainer> m_truthEventName{this, "TruthEvents", "TruthEvents","Name of the truth events container probably either TruthEvent or TruthEvents"};
81 // Get truth particles into a vector, possibly using the pileup from the event
82 const std::vector<const xAOD::TruthParticle *> getTruthParticles() const;
83 FilterReporterParams m_filterParams {this, "TrackOverlayDecisionAlg", "Decides whether events should be reconstructed in track-overlay workflow or MC-overlay."};
84 Gaudi::Property<bool> m_invertfilter{this, "InvertFilter", false, "Invert filter decision."};
85 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."};
86 // Set up the ONNX Runtime session
87 ServiceHandle<AthOnnx::IOnnxRuntimeSvc> m_svc{this, "ONNXRuntimeSvc", "AthOnnx::OnnxRuntimeSvc", "CaloMuonScoreTool ONNXRuntimeSvc"};
88 std::tuple<std::vector<int64_t>, std::vector<char*>> m_inputInfo;
89 std::tuple<std::vector<int64_t>, std::vector<char*>> m_outputInfo;
90 std::unique_ptr<Ort::Session> m_session;
91 inline std::tuple<std::vector<int64_t>, std::vector<char*> > GetInputNodeInfo(const std::unique_ptr< Ort::Session >& session) {
92 std::vector<int64_t> input_node_dims;
93 size_t num_input_nodes = session->GetInputCount();
94 std::vector<char*> input_node_names(num_input_nodes);
95 Ort::AllocatorWithDefaultOptions allocator;
96 for( std::size_t i = 0; i < num_input_nodes; i++ ) {
97 char* input_name = session->GetInputNameAllocated(i, allocator).release();
98 input_node_names[i] = input_name;
99 Ort::TypeInfo type_info = session->GetInputTypeInfo(i);
100 auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
101 input_node_dims = tensor_info.GetShape();
102 }
103 return std::make_tuple(input_node_dims, input_node_names);
104 }
105
106 inline std::tuple<std::vector<int64_t>, std::vector<char*> > GetOutputNodeInfo(const std::unique_ptr< Ort::Session >& session){
107 std::vector<int64_t> output_node_dims;
108 size_t num_output_nodes = session->GetOutputCount();
109 std::vector<char*> output_node_names(num_output_nodes);
110 Ort::AllocatorWithDefaultOptions allocator;
111 for( std::size_t i = 0; i < num_output_nodes; i++ ) {
112 char* output_name = session->GetOutputNameAllocated(i, allocator).release();
113 output_node_names[i] = output_name;
114 Ort::TypeInfo type_info = session->GetOutputTypeInfo(i);
115 auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
116 output_node_dims = tensor_info.GetShape();
117 }
118 return std::make_tuple(output_node_dims, output_node_names);
119 }
120 };
121
122}
123#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.
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.
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:576
Property holding a SG store/key/clid from which a ReadHandle is made.
SG::AuxElement::Decorator< bool > m_dec_selectedByPileupSwitch
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
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
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
void initialize()
#define private