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