|
ATLAS Offline Software
|
#include <CaloMuonScoreTool.h>
|
| CaloMuonScoreTool (const std::string &type, const std::string &name, const IInterface *parent) |
|
virtual | ~CaloMuonScoreTool ()=default |
|
virtual StatusCode | initialize () override |
|
float | getMuonScore (const xAOD::TrackParticle *trk, const CaloCellContainer *cells=nullptr, const CaloExtensionCollection *extensionCache=nullptr) const override |
|
ServiceHandle< StoreGateSvc > & | evtStore () |
| The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc . More...
|
|
const ServiceHandle< StoreGateSvc > & | evtStore () const |
| The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc . More...
|
|
const ServiceHandle< StoreGateSvc > & | detStore () const |
| The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc . More...
|
|
virtual StatusCode | sysInitialize () override |
| Perform system initialization for an algorithm. More...
|
|
virtual StatusCode | sysStart () override |
| Handle START transition. More...
|
|
virtual std::vector< Gaudi::DataHandle * > | inputHandles () const override |
| Return this algorithm's input handles. More...
|
|
virtual std::vector< Gaudi::DataHandle * > | outputHandles () const override |
| Return this algorithm's output handles. More...
|
|
Gaudi::Details::PropertyBase & | declareProperty (Gaudi::Property< T > &t) |
|
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, SG::VarHandleKey &hndl, const std::string &doc, const SG::VarHandleKeyType &) |
| Declare a new Gaudi property. More...
|
|
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, SG::VarHandleBase &hndl, const std::string &doc, const SG::VarHandleType &) |
| Declare a new Gaudi property. More...
|
|
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, SG::VarHandleKeyArray &hndArr, const std::string &doc, const SG::VarHandleKeyArrayType &) |
|
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, T &property, const std::string &doc, const SG::NotHandleType &) |
| Declare a new Gaudi property. More...
|
|
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, T &property, const std::string &doc="none") |
| Declare a new Gaudi property. More...
|
|
void | updateVHKA (Gaudi::Details::PropertyBase &) |
|
MsgStream & | msg () const |
|
MsgStream & | msg (const MSG::Level lvl) const |
|
bool | msgLvl (const MSG::Level lvl) const |
|
|
float | runOnnxInference (std::vector< float > &tensor) const |
|
std::vector< float > | unwrapPhiAngles (const std::vector< float > &v) const |
|
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 |
|
float | getMedian (std::vector< float > v) const |
| --> Copy is neccessary as the elements are reorded for the moment which would then break association to the actual cell deposit More...
|
|
int | getBin (const float low_edge, const float up_edge, const int n_bins, float val) const |
|
int | channelForSamplingId (int &samplingId) const |
|
std::vector< float > | getInputTensor (std::vector< float > &eta, std::vector< float > &phi, std::vector< float > &energy, std::vector< int > &sampling) const |
|
Gaudi::Details::PropertyBase & | declareGaudiProperty (Gaudi::Property< T > &hndl, const SG::VarHandleKeyType &) |
| specialization for handling Gaudi::Property<SG::VarHandleKey> More...
|
|
Gaudi::Details::PropertyBase & | declareGaudiProperty (Gaudi::Property< T > &hndl, const SG::VarHandleKeyArrayType &) |
| specialization for handling Gaudi::Property<SG::VarHandleKeyArray> More...
|
|
Gaudi::Details::PropertyBase & | declareGaudiProperty (Gaudi::Property< T > &hndl, const SG::VarHandleType &) |
| specialization for handling Gaudi::Property<SG::VarHandleBase> More...
|
|
Gaudi::Details::PropertyBase & | declareGaudiProperty (Gaudi::Property< T > &t, const SG::NotHandleType &) |
| specialization for handling everything that's not a Gaudi::Property<SG::VarHandleKey> or a <SG::VarHandleKeyArray> More...
|
|
|
Gaudi::Property< float > | m_CaloCellAssociationConeSize |
|
Gaudi::Property< int > | m_etaBins {this, "etaBins", 30, "Number of bins in eta"} |
|
Gaudi::Property< int > | m_phiBins {this, "phiBins", 30, "Number of bins in phi"} |
|
Gaudi::Property< float > | m_etaCut |
|
Gaudi::Property< float > | m_phiCut |
|
Gaudi::Property< int > | m_nChannels {this, "nChannels", 7, "Number of colour channels in the convolutional neural network"} |
|
ToolHandle< Rec::IParticleCaloCellAssociationTool > | m_caloCellAssociationTool {this, "ParticleCaloCellAssociationTool", ""} |
|
ServiceHandle< AthOnnx::IOnnxRuntimeSvc > | m_svc {this, "ONNXRuntimeSvc", "AthOnnx::OnnxRuntimeSvc", "CaloMuonScoreTool ONNXRuntimeSvc"} |
| Handle to AthOnnx::IOnnxRuntimeSvc . More...
|
|
std::unique_ptr< Ort::Session > | m_session |
|
std::vector< const char * > | m_input_node_names |
|
std::vector< const char * > | m_output_node_names |
|
std::vector< int64_t > | m_input_node_dims |
|
Gaudi::Property< std::string > | m_modelFileName {this, "ModelFileName", "CaloTrkMuIdTools/nnBased_201022/CaloMuonCNN_1.onnx"} |
|
Gaudi::Property< double > | m_CaloMuonEtaCut |
|
StoreGateSvc_t | m_evtStore |
| Pointer to StoreGate (event store by default) More...
|
|
StoreGateSvc_t | m_detStore |
| Pointer to StoreGate (detector store by default) More...
|
|
std::vector< SG::VarHandleKeyArray * > | m_vhka |
|
bool | m_varHandleArraysDeclared |
|
Fetch the calorimeter cells around a track particle and compute the muon score.
The muon score is computed by doing inference on a 7-colour-channel convolutional neural network. The inputs to the convolutional neural network are the energy deposits in 30 eta and 30 phi bins around the track particle. Seven colour channels are considered, corresponding to the seven calorimeter layers (CaloSamplingIDs) in the low-eta region (eta < 0.1).
The convolutional neural network was trained using tensorflow. Inference on this model is done using ONNX (the tensorflow model having been converted to ONNX format).
- Author
- Ricardo Woelker ricar.nosp@m.do.w.nosp@m.oelke.nosp@m.r@ce.nosp@m.rn.ch
Definition at line 37 of file CaloMuonScoreTool.h.
◆ StoreGateSvc_t
◆ CaloMuonScoreTool()
CaloMuonScoreTool::CaloMuonScoreTool |
( |
const std::string & |
type, |
|
|
const std::string & |
name, |
|
|
const IInterface * |
parent |
|
) |
| |
◆ ~CaloMuonScoreTool()
virtual CaloMuonScoreTool::~CaloMuonScoreTool |
( |
| ) |
|
|
virtualdefault |
◆ channelForSamplingId()
int CaloMuonScoreTool::channelForSamplingId |
( |
int & |
samplingId | ) |
const |
|
private |
◆ declareGaudiProperty() [1/4]
specialization for handling Gaudi::Property<SG::VarHandleKeyArray>
Definition at line 170 of file AthCommonDataStore.h.
175 hndl.documentation());
◆ declareGaudiProperty() [2/4]
specialization for handling Gaudi::Property<SG::VarHandleKey>
Definition at line 156 of file AthCommonDataStore.h.
161 hndl.documentation());
◆ declareGaudiProperty() [3/4]
specialization for handling Gaudi::Property<SG::VarHandleBase>
Definition at line 184 of file AthCommonDataStore.h.
189 hndl.documentation());
◆ declareGaudiProperty() [4/4]
◆ declareProperty() [1/6]
Declare a new Gaudi property.
- Parameters
-
name | Name of the property. |
hndl | Object holding the property value. |
doc | Documentation string for the property. |
This is the version for types that derive from SG::VarHandleBase
. The property value object is put on the input and output lists as appropriate; then we forward to the base class.
Definition at line 245 of file AthCommonDataStore.h.
250 this->declare(hndl.
vhKey());
251 hndl.
vhKey().setOwner(
this);
253 return PBASE::declareProperty(
name,hndl,
doc);
◆ declareProperty() [2/6]
Declare a new Gaudi property.
- Parameters
-
name | Name of the property. |
hndl | Object holding the property value. |
doc | Documentation string for the property. |
This is the version for types that derive from SG::VarHandleKey
. The property value object is put on the input and output lists as appropriate; then we forward to the base class.
Definition at line 221 of file AthCommonDataStore.h.
229 return PBASE::declareProperty(
name,hndl,
doc);
◆ declareProperty() [3/6]
◆ declareProperty() [4/6]
Declare a new Gaudi property.
- Parameters
-
name | Name of the property. |
property | Object holding the property value. |
doc | Documentation string for the property. |
This is the generic version, for types that do not derive from SG::VarHandleKey
. It just forwards to the base class version of declareProperty
.
Definition at line 333 of file AthCommonDataStore.h.
338 return PBASE::declareProperty(
name, property,
doc);
◆ declareProperty() [5/6]
Declare a new Gaudi property.
- Parameters
-
name | Name of the property. |
property | Object holding the property value. |
doc | Documentation string for the property. |
This dispatches to either the generic declareProperty
or the one for VarHandle/Key/KeyArray.
Definition at line 352 of file AthCommonDataStore.h.
◆ declareProperty() [6/6]
◆ detStore()
◆ evtStore() [1/2]
◆ evtStore() [2/2]
◆ extraDeps_update_handler()
Add StoreName to extra input/output deps as needed.
use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given
◆ fillInputVectors()
void CaloMuonScoreTool::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 |
|
private |
Definition at line 134 of file CaloMuonScoreTool.cxx.
139 eta.push_back(cluster->eta());
140 phi.push_back(cluster->phi());
141 samplingId.push_back(cluster->caloDDE()->getSampling());
142 energy.push_back(cluster->energy());
147 ATH_MSG_DEBUG(
"Iterated over " << cell_count <<
" calo cells");
◆ getBin()
int CaloMuonScoreTool::getBin |
( |
const float |
low_edge, |
|
|
const float |
up_edge, |
|
|
const int |
n_bins, |
|
|
float |
val |
|
) |
| const |
|
private |
◆ getInputTensor()
std::vector< float > CaloMuonScoreTool::getInputTensor |
( |
std::vector< float > & |
eta, |
|
|
std::vector< float > & |
phi, |
|
|
std::vector< float > & |
energy, |
|
|
std::vector< int > & |
sampling |
|
) |
| const |
|
private |
Definition at line 282 of file CaloMuonScoreTool.cxx.
284 int n_cells =
eta.size();
291 float median_phi =
getMedian(unwrappedPhi);
296 int skipped_cells = 0;
298 for (
int i = 0;
i < n_cells;
i++) {
300 float shifted_eta =
eta[
i] - median_eta;
301 float shifted_phi = unwrappedPhi[
i] - median_phi;
317 ATH_MSG_DEBUG(
"Skipping cell because sampling ID does not correspond to low-eta layers. Sampling ID: " << sampling[
i]);
324 tensor[tensor_idx] +=
energy[
i];
327 ATH_MSG_DEBUG(
"Skipped " << skipped_cells <<
" out of " << n_cells <<
" cells");
◆ getMedian()
float CaloMuonScoreTool::getMedian |
( |
std::vector< float > |
v | ) |
const |
|
private |
--> Copy is neccessary as the elements are reorded for the moment which would then break association to the actual cell deposit
Definition at line 255 of file CaloMuonScoreTool.cxx.
256 if (
v.empty())
return 0.0;
258 int n =
v.size() / 2;
259 std::nth_element(
v.begin(),
v.begin() +
n,
v.end());
262 if (
v.size() % 2 == 1)
return med;
264 auto max_it = std::max_element(
v.begin(),
v.begin() +
n);
266 return (*max_it + med) / 2.0;
◆ getMuonScore()
Implements ICaloMuonScoreTool.
Definition at line 155 of file CaloMuonScoreTool.cxx.
159 double track_eta = trk->
eta();
164 <<
" (eta=" << track_eta <<
")");
168 ATH_MSG_DEBUG(
"Calculating muon score for track particle with eta=" << track_eta);
173 std::unique_ptr<const Rec::ParticleCellAssociation>
association =
183 std::vector<int> sampling;
◆ initialize()
StatusCode CaloMuonScoreTool::initialize |
( |
| ) |
|
|
overridevirtual |
Definition at line 32 of file CaloMuonScoreTool.cxx.
43 "Please make sure it exists in the ATLAS calibration area (https://atlas-groupdata.web.cern.ch/atlas-groupdata/), and provide "
44 "a model file name relative to the root of the calibration area.");
46 return StatusCode::FAILURE;
50 Ort::SessionOptions session_options;
51 Ort::AllocatorWithDefaultOptions allocator;
52 session_options.SetIntraOpNumThreads(1);
53 session_options.SetGraphOptimizationLevel(ORT_ENABLE_BASIC);
55 m_session = std::make_unique<Ort::Session>(
m_svc->env(), model_file_name.c_str(), session_options);
57 ATH_MSG_INFO(
"Created ONNX runtime session with model " << model_file_name);
59 size_t num_input_nodes =
m_session->GetInputCount();
62 for (std::size_t
i = 0;
i < num_input_nodes;
i++) {
64 char* input_name =
m_session->GetInputNameAllocated(
i, allocator).release();
66 <<
" name= " << input_name);
69 Ort::TypeInfo type_info =
m_session->GetInputTypeInfo(
i);
70 auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
71 ONNXTensorElementDataType
type = tensor_info.GetElementType();
73 <<
" type= " <<
type);
85 std::vector<int64_t> output_node_dims;
86 size_t num_output_nodes =
m_session->GetOutputCount();
90 for (std::size_t
i = 0;
i < num_output_nodes;
i++) {
92 char* output_name =
m_session->GetOutputNameAllocated(
i, allocator).release();
94 <<
" name= " << output_name);
97 Ort::TypeInfo type_info =
m_session->GetOutputTypeInfo(
i);
98 auto tensor_info = type_info.GetTensorTypeAndShapeInfo();
99 ONNXTensorElementDataType
type = tensor_info.GetElementType();
101 <<
" type= " <<
type);
104 output_node_dims = tensor_info.GetShape();
105 ATH_MSG_INFO(
"Output " <<
i <<
" : num_dims= " << output_node_dims.size());
106 for (std::size_t j = 0; j < output_node_dims.size(); j++) {
107 if (output_node_dims[j] < 0) output_node_dims[j] = 1;
108 ATH_MSG_INFO(
"Output" <<
i <<
" : dim " << j <<
"= " << output_node_dims[j]);
112 return StatusCode::SUCCESS;
◆ inputHandles()
Return this algorithm's input handles.
We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.
◆ interfaceID()
static const InterfaceID& ICaloMuonScoreTool::interfaceID |
( |
| ) |
|
|
inlinestaticinherited |
◆ msg() [1/2]
◆ msg() [2/2]
◆ msgLvl()
◆ outputHandles()
Return this algorithm's output handles.
We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.
◆ renounce()
◆ renounceArray()
◆ runOnnxInference()
float CaloMuonScoreTool::runOnnxInference |
( |
std::vector< float > & |
tensor | ) |
const |
|
private |
Definition at line 207 of file CaloMuonScoreTool.cxx.
211 auto memory_info = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault);
213 Ort::Value input_tensor =
227 float *output_score_array = output_tensors.front().GetTensorMutableData<
float>();
230 float output_score = output_score_array[0];
◆ sysInitialize()
◆ sysStart()
Handle START transition.
We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.
◆ unwrapPhiAngles()
std::vector< float > CaloMuonScoreTool::unwrapPhiAngles |
( |
const std::vector< float > & |
v | ) |
const |
|
private |
◆ updateVHKA()
◆ m_CaloCellAssociationConeSize
Gaudi::Property<float> CaloMuonScoreTool::m_CaloCellAssociationConeSize |
|
private |
Initial value:{this, "CaloCellAssociationConeSize", 0.2,
"Size of the cone within which calo cells are associated with a track particle"}
Definition at line 75 of file CaloMuonScoreTool.h.
◆ m_caloCellAssociationTool
◆ m_CaloMuonEtaCut
Gaudi::Property<double> CaloMuonScoreTool::m_CaloMuonEtaCut |
|
private |
Initial value:{this, "CaloMuonEtaCut", 1.0,
"Eta cut (absolute value) up to which a track particle's muon score will be calculated"}
Definition at line 104 of file CaloMuonScoreTool.h.
◆ m_detStore
◆ m_etaBins
Gaudi::Property<int> CaloMuonScoreTool::m_etaBins {this, "etaBins", 30, "Number of bins in eta"} |
|
private |
◆ m_etaCut
Gaudi::Property<float> CaloMuonScoreTool::m_etaCut |
|
private |
Initial value:{
this, "etaCut", 0.25,
"Eta cut on the calorimeter cells associated with the track particle after centering of the calorimeter image"}
Definition at line 79 of file CaloMuonScoreTool.h.
◆ m_evtStore
◆ m_input_node_dims
std::vector<int64_t> CaloMuonScoreTool::m_input_node_dims |
|
private |
◆ m_input_node_names
std::vector<const char *> CaloMuonScoreTool::m_input_node_names |
|
private |
◆ m_modelFileName
Gaudi::Property<std::string> CaloMuonScoreTool::m_modelFileName {this, "ModelFileName", "CaloTrkMuIdTools/nnBased_201022/CaloMuonCNN_1.onnx"} |
|
private |
◆ m_nChannels
Gaudi::Property<int> CaloMuonScoreTool::m_nChannels {this, "nChannels", 7, "Number of colour channels in the convolutional neural network"} |
|
private |
◆ m_output_node_names
std::vector<const char *> CaloMuonScoreTool::m_output_node_names |
|
private |
◆ m_phiBins
Gaudi::Property<int> CaloMuonScoreTool::m_phiBins {this, "phiBins", 30, "Number of bins in phi"} |
|
private |
◆ m_phiCut
Gaudi::Property<float> CaloMuonScoreTool::m_phiCut |
|
private |
Initial value:{
this, "phiCut", 0.25,
"Phi cut on the calorimeter cells associated with the track particle after centering of the calorimeter image"}
Definition at line 82 of file CaloMuonScoreTool.h.
◆ m_session
std::unique_ptr<Ort::Session> CaloMuonScoreTool::m_session |
|
private |
◆ m_svc
◆ m_varHandleArraysDeclared
◆ m_vhka
The documentation for this class was generated from the following files:
Scalar phi() const
phi method
Scalar eta() const
pseudorapidity method
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
StoreGateSvc_t m_evtStore
Pointer to StoreGate (event store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
#define ATH_MSG_VERBOSE(x)
virtual void setOwner(IDataHandleHolder *o)=0
StoreGateSvc_t m_detStore
Pointer to StoreGate (detector store by default)
virtual void renounce()=0
std::conditional< std::is_base_of< SG::VarHandleKeyArray, T >::value, VarHandleKeyArrayType, type2 >::type type
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
#define ATLAS_THREAD_SAFE
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>