ATLAS Offline Software
CaloMuonScoreTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef CALOTRKMUIDTOOLS_CALOMUONSCORETOOL_H
6 #define CALOTRKMUIDTOOLS_CALOMUONSCORETOOL_H
7 
8 #include <memory>
9 #include <vector>
10 
13 #include "GaudiKernel/ServiceHandle.h"
14 #include "GaudiKernel/ToolHandle.h"
17 
37 class CaloMuonScoreTool : public AthAlgTool, virtual public ICaloMuonScoreTool {
38 public:
39  CaloMuonScoreTool(const std::string &type, const std::string &name, const IInterface *parent);
40  virtual ~CaloMuonScoreTool() = default;
41 
42  virtual StatusCode initialize() override;
43 
44  // Compute the muon score given a track particle
45  float getMuonScore(const xAOD::TrackParticle *trk, const CaloCellContainer *cells = nullptr,
46  const CaloExtensionCollection *extensionCache = nullptr) const override;
47 
48 private:
49  // run the ONNX inference on the input tensor
50  float runOnnxInference(std::vector<float> &tensor) const;
51 
52  // unwrap phi values by mapping phi vectors that span the boundary
53  // between pi and -pi to their 2*pi complement
54  std::vector<float> unwrapPhiAngles(const std::vector<float> &v) const;
55 
56  // fill vectors from the particle cell association
57  void fillInputVectors(std::unique_ptr<const Rec::ParticleCellAssociation> &association, std::vector<float> &eta,
58  std::vector<float> &phi, std::vector<float> &energy, std::vector<int> &samplingId) const;
59 
60  // Compute the median of a vector of floats (can be even or odd in length)
63  float getMedian(std::vector<float> v) const;
64 
65  // Given a vector of bins, return the index of the matching bin
66  int getBin(const float low_edge, const float up_edge, const int n_bins, float val) const;
67 
68  // Given a calo sampling ID (as integer), return the corresponding "RGB"-like channel ID (0,1,2,3,4,5,6)
69  int channelForSamplingId(int &samplingId) const;
70 
71  // for a given particle, consume vectors for eta, phi, energy, sampling ID, and return the input tensor to be used in ONNX
72  std::vector<float> getInputTensor(std::vector<float> &eta, std::vector<float> &phi, std::vector<float> &energy,
73  std::vector<int> &sampling) const;
74 
75  Gaudi::Property<float> m_CaloCellAssociationConeSize{this, "CaloCellAssociationConeSize", 0.2,
76  "Size of the cone within which calo cells are associated with a track particle"};
77  Gaudi::Property<int> m_etaBins{this, "etaBins", 30, "Number of bins in eta"};
78  Gaudi::Property<int> m_phiBins{this, "phiBins", 30, "Number of bins in phi"};
79  Gaudi::Property<float> m_etaCut{
80  this, "etaCut", 0.25,
81  "Eta cut on the calorimeter cells associated with the track particle after centering of the calorimeter image"};
82  Gaudi::Property<float> m_phiCut{
83  this, "phiCut", 0.25,
84  "Phi cut on the calorimeter cells associated with the track particle after centering of the calorimeter image"};
85  Gaudi::Property<int> m_nChannels{this, "nChannels", 7, "Number of colour channels in the convolutional neural network"};
86 
87  ToolHandle<Rec::IParticleCaloCellAssociationTool> m_caloCellAssociationTool{this, "ParticleCaloCellAssociationTool", ""};
88 
90  ServiceHandle<AthOnnx::IOnnxRuntimeSvc> m_svc{this, "ONNXRuntimeSvc", "AthOnnx::OnnxRuntimeSvc", "CaloMuonScoreTool ONNXRuntimeSvc"};
91 
92  std::unique_ptr<Ort::Session> m_session;
93 
94  std::vector<const char *> m_input_node_names;
95 
96  std::vector<const char *> m_output_node_names;
97 
98  std::vector<int64_t> m_input_node_dims;
99 
100  // This path needs to point to the ATLAS calibration area (https://atlas-groupdata.web.cern.ch/atlas-groupdata/)
101  // It needs to be a full path relative to the root of the calibration area, e.g. `CaloTrkMuIdTools/nnBased_201022/CaloMuonCNN_1.onnx`
102  Gaudi::Property<std::string> m_modelFileName{this, "ModelFileName", "CaloTrkMuIdTools/nnBased_201022/CaloMuonCNN_1.onnx"};
103 
104  Gaudi::Property<double> m_CaloMuonEtaCut{this, "CaloMuonEtaCut", 1.0,
105  "Eta cut (absolute value) up to which a track particle's muon score will be calculated"};
106 };
107 
108 #endif
CaloMuonScoreTool::getInputTensor
std::vector< float > getInputTensor(std::vector< float > &eta, std::vector< float > &phi, std::vector< float > &energy, std::vector< int > &sampling) const
Definition: CaloMuonScoreTool.cxx:282
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
CaloMuonScoreTool::runOnnxInference
float runOnnxInference(std::vector< float > &tensor) const
Definition: CaloMuonScoreTool.cxx:207
ICaloMuonScoreTool.h
CaloMuonScoreTool::m_etaCut
Gaudi::Property< float > m_etaCut
Definition: CaloMuonScoreTool.h:79
CaloMuonScoreTool::channelForSamplingId
int channelForSamplingId(int &samplingId) const
Definition: CaloMuonScoreTool.cxx:238
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
CaloMuonScoreTool::unwrapPhiAngles
std::vector< float > unwrapPhiAngles(const std::vector< float > &v) const
Definition: CaloMuonScoreTool.cxx:118
CaloMuonScoreTool
Definition: CaloMuonScoreTool.h:37
CaloMuonScoreTool::m_input_node_dims
std::vector< int64_t > m_input_node_dims
Definition: CaloMuonScoreTool.h:98
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
CaloMuonScoreTool::m_caloCellAssociationTool
ToolHandle< Rec::IParticleCaloCellAssociationTool > m_caloCellAssociationTool
Definition: CaloMuonScoreTool.h:87
CaloMuonScoreTool::m_session
std::unique_ptr< Ort::Session > m_session
Definition: CaloMuonScoreTool.h:92
CaloMuonScoreTool::m_CaloCellAssociationConeSize
Gaudi::Property< float > m_CaloCellAssociationConeSize
Definition: CaloMuonScoreTool.h:75
ICaloMuonScoreTool
Definition: ICaloMuonScoreTool.h:17
CaloMuonScoreTool::m_phiBins
Gaudi::Property< int > m_phiBins
Definition: CaloMuonScoreTool.h:78
CaloMuonScoreTool::getBin
int getBin(const float low_edge, const float up_edge, const int n_bins, float val) const
Definition: CaloMuonScoreTool.cxx:269
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
CaloMuonScoreTool::getMuonScore
float getMuonScore(const xAOD::TrackParticle *trk, const CaloCellContainer *cells=nullptr, const CaloExtensionCollection *extensionCache=nullptr) const override
Definition: CaloMuonScoreTool.cxx:155
CaloMuonScoreTool::m_nChannels
Gaudi::Property< int > m_nChannels
Definition: CaloMuonScoreTool.h:85
CaloMuonScoreTool::m_etaBins
Gaudi::Property< int > m_etaBins
Definition: CaloMuonScoreTool.h:77
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloMuonScoreTool::m_output_node_names
std::vector< const char * > m_output_node_names
Definition: CaloMuonScoreTool.h:96
CaloMuonScoreTool::CaloMuonScoreTool
CaloMuonScoreTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CaloMuonScoreTool.cxx:24
AthAlgTool.h
Trk::association
@ association
Definition: TrackingGeometry.h:46
CaloMuonScoreTool::m_CaloMuonEtaCut
Gaudi::Property< double > m_CaloMuonEtaCut
Definition: CaloMuonScoreTool.h:104
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CaloMuonScoreTool::getMedian
float getMedian(std::vector< float > v) const
--> Copy is neccessary as the elements are reorded for the moment which would then break association ...
Definition: CaloMuonScoreTool.cxx:255
IParticleCaloCellAssociationTool.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
CaloMuonScoreTool::fillInputVectors
void fillInputVectors(std::unique_ptr< const Rec::ParticleCellAssociation > &association, std::vector< float > &eta, std::vector< float > &phi, std::vector< float > &energy, std::vector< int > &samplingId) const
Definition: CaloMuonScoreTool.cxx:134
CaloMuonScoreTool::initialize
virtual StatusCode initialize() override
Definition: CaloMuonScoreTool.cxx:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CaloMuonScoreTool::m_svc
ServiceHandle< AthOnnx::IOnnxRuntimeSvc > m_svc
Handle to AthOnnx::IOnnxRuntimeSvc.
Definition: CaloMuonScoreTool.h:90
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloMuonScoreTool::m_modelFileName
Gaudi::Property< std::string > m_modelFileName
Definition: CaloMuonScoreTool.h:102
IOnnxRuntimeSvc.h
CaloMuonScoreTool::m_input_node_names
std::vector< const char * > m_input_node_names
Definition: CaloMuonScoreTool.h:94
python.PyAthena.v
v
Definition: PyAthena.py:154
CaloMuonScoreTool::~CaloMuonScoreTool
virtual ~CaloMuonScoreTool()=default
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
AthAlgTool
Definition: AthAlgTool.h:26
CaloMuonScoreTool::m_phiCut
Gaudi::Property< float > m_phiCut
Definition: CaloMuonScoreTool.h:82
ServiceHandle< AthOnnx::IOnnxRuntimeSvc >