ATLAS Offline Software
Loading...
Searching...
No Matches
MeasurementToTruthAssociationAlg.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ACTSTRKFINDING_MEASUREMENTTOTRUTHASSOCIATIONALG_H
6#define ACTSTRKFINDING_MEASUREMENTTOTRUTHASSOCIATIONALG_H 1
7
8// Base Class
10
11// Gaudi includes
12#include "Gaudi/Property.h"
13
14// Handle Keys
17
18#include "Identifier/Identifier.h"
20
21#include <string>
22#include <memory>
23#include <array>
24#include <atomic>
25#include <type_traits>
26
27#include <cmath>
28#include <iomanip>
29#include <ostream>
30#include <string>
31#include <sstream>
32#include <vector>
33
35
36namespace Dbg {
37using ActsUtils::Stat;
39using ActsUtils::operator<<;
40
41struct HistTemp {
42 mutable Dbg::StatHist m_depositedEnergy ATLAS_THREAD_SAFE {20, -6., 14.};
43 mutable Dbg::StatHist m_particlesPerMeasurement ATLAS_THREAD_SAFE {20, -.5, 20.-.5};
44 mutable Dbg::StatHist m_measurementsPerParticle ATLAS_THREAD_SAFE {20, -0.5, 20.-0.5};
45 HistTemp() = default;
47 : m_depositedEnergy(a.m_depositedEnergy.createEmptyClone()),
48 m_particlesPerMeasurement( a.m_particlesPerMeasurement.createEmptyClone()),
49 m_measurementsPerParticle( a.m_measurementsPerParticle.createEmptyClone())
50 {
51 }
52};
53struct Hist : public HistTemp {
55 mutable std::mutex m_mutex;
56};
57
58struct Empty {
59 Empty() =default;
60 Empty(const Empty &) =default;
61};
62
63}
64
65namespace ActsTrk
66{
67
68 // Helper class to emulate an RDO list for a type which provides a single RDO
69 template<class T>
71 private:
72 const T *m_ptr;
73 public:
74 DummyRDOList(const T &a) : m_ptr(&a) {}
76 const T *m_ptr;
77 const_iterator(const T *a_ptr) : m_ptr(a_ptr) {}
78 Identifier operator*() const { return m_ptr->identifier(); }
79 bool operator!=(const const_iterator &other) const {
80 return m_ptr != other.m_ptr;
81 }
82 const_iterator &operator++() { ++m_ptr; return *this;}
83 };
85 return const_iterator(m_ptr);
86 }
88 return const_iterator(m_ptr+1);
89 }
90 };
91
92 // helper templates to detect whether a type has the method rdoList
93 template <typename Object>
94 using rdoListFunc_t = decltype(std::declval<Object>().rdoList());
95
96 // template being used for types that do not have a member function called rdoList
97 template <typename Object, typename = std::void_t<> >
98 struct has_rdoList : std::false_type{};
99
100 // template being used for types that have the member function rdoList
101 template <typename Object >
102 struct has_rdoList<Object, std::void_t<rdoListFunc_t<Object> > > : std::true_type{};
103
104 // helper template to get a list of RDOs associated to the given measurement
105 // if the measurement does not provide an RDO list but only is composed of a single measurement
106 // return something which behaves like a RDO list but contains only a single identifier.
107 // the optimizer (with O2) should take care of eliminating the bogus loop.
108 template <class T>
109 auto getRDOList(const T &a) {
110 if constexpr(has_rdoList<T>::value) {
111 return a.rdoList();
112 }
113 else {
114 return DummyRDOList(a);
115 }
116 }
117
118 // specialisations need to be implemented for each T_TruthEventCollection used for the MeasurementToTruthAssociationAlg
119 // @return helper class to get TruthParticles from a deposit, and test whether a truth particle is from the hard scatter event
120 // The helper class has to implement getTruthParticle, isHardScatter which are functions from Deposits, where deposits are
121 // elements from the collection returned by getSimDataDeposits, which is a function of the sim data collection
122 template <class T_TruthEventCollection>
123 auto makeDepositToTruthParticleMap(const T_TruthEventCollection *truth_particle_links);
124
125 // specialisation need to be implemented for each T_TruthEventCollection used for the MeasurementToTruthAssociationAlg
126 template <class T_TruthEventCollection>
127 inline const char *getInTruthPropertyName();
128
129 // specialisations need to be implemented for each T_SimDataCollection/T_SimDataIterator used for the MeasurementToTruthAssociationAlg
130 template <class T_SimDataCollection, class T_SimDataIterator>
131 auto getSimDataDeposits(const T_SimDataCollection &sim_data_collection, T_SimDataIterator sim_data_iter_for_identifier);
132
133 // specialisations need to be implemented for each T_SimDataCollection used for the MeasurementToTruthAssociationAlg
134 template <class T_Deposit>
135 float getDepositedEnergy(const T_Deposit &);
136
139 template <class T_MeasurementCollection, class T_SimDataCollection, class T_TruthEventCollection, bool IsDebug=false >
141 {
142 public:
143 MeasurementToTruthAssociationAlg(const std::string &name,
144 ISvcLocator *pSvcLocator);
145
146 virtual StatusCode initialize() override;
147 virtual StatusCode finalize() override;
148 virtual StatusCode execute(const EventContext &ctx) const override;
149
150 private:
152 {this, "Measurements",{}, "List of input measurement keys." };
154 {this, "SimData",{}, "List of input simulated data keys." };
156 {this,getInTruthPropertyName<T_TruthEventCollection>(),"","The key for the truth event collection e.g. McEventCollectionWrap if one is required."};
157
159 {this, "AssociationMapOut","", "Output association map from measurements to generator particles." };
160
161 Gaudi::Property<float> m_depositedEnergyMin
162 {this, "DepositedEnergyMin", 0., "Only consider gnerator particles which"
163 " deposed more than this amount of energy (in MeV)" };
164
173 // statistics counter
174 mutable std::array<std::atomic<std::size_t>,kNCategories> m_statRDO ATLAS_THREAD_SAFE;
175 // counter of deposits from truth particles of the hard scatter and pileup with or without
176 // associated xAOD truth particle.
177 mutable std::array<std::atomic<std::size_t>,4> m_depositCounts ATLAS_THREAD_SAFE {0u, 0u, 0u, 0u};
178 // optional histograms of deposits per particle, particles per measurement, and measurements per particle
179 typename std::conditional<IsDebug, Dbg::Hist, Dbg::Empty>::type m_stat;
180 };
181
182} // namespace
183
184#endif
static Double_t a
Property holding a SG store/key/clid from which a ReadHandle is made.
Property holding a SG store/key/clid from which a WriteHandle is made.
MeasurementToTruthAssociationAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &ctx) const override
virtual StatusCode initialize() override
SG::WriteHandleKey< MeasurementToTruthParticleAssociation > m_associationOutKey
SG::ReadHandleKey< T_TruthEventCollection > m_truthEventCollectionKey
SG::ReadHandleKey< T_SimDataCollection > m_simDataKey
SG::ReadHandleKey< T_MeasurementCollection > m_measurementKey
std::conditional< IsDebug, Dbg::Hist, Dbg::Empty >::type m_stat
std::array< std::atomic< std::size_t >, kNCategories > m_statRDO ATLAS_THREAD_SAFE
virtual StatusCode finalize() override
Extend Stat helper by an equidistant binned histogram.
Definition StatUtils.h:81
Simple class to gather statistics : min, max, mean, rms.
Definition StatUtils.h:17
An algorithm that can be simultaneously executed in multiple threads.
Property holding a SG store/key/clid from which a ReadHandle is made.
Property holding a SG store/key/clid from which a WriteHandle is made.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
auto getRDOList(const T &a)
float getDepositedEnergy(const T_Deposit &)
auto getSimDataDeposits(const T_SimDataCollection &sim_data_collection, T_SimDataIterator sim_data_iter_for_identifier)
const char * getInTruthPropertyName()
auto makeDepositToTruthParticleMap(const T_TruthEventCollection *truth_particle_links)
decltype(std::declval< Object >().rdoList()) rdoListFunc_t
STL namespace.
bool operator!=(const const_iterator &other) const
Empty(const Empty &)=default
Empty()=default
HistTemp()=default
Dbg::StatHist m_depositedEnergy ATLAS_THREAD_SAFE
HistTemp()=default