16#include "GaudiKernel/PhysicalConstants.h"
18#include "TDatabasePDG.h"
19#include "TParticlePDG.h"
62 return StatusCode::SUCCESS;
70 return StatusCode::SUCCESS;
77 return StatusCode::FAILURE;
80 std::size_t ptruth_size=ptruth->size();
82 std::vector<unsigned int> truthIndexMap;
85 unsigned int max_size=0;
86 assert( ptruth_size < std::numeric_limits<unsigned int>::max());
88 max_size = std::max( max_size, decor_index(*truth_particle) );
90 if (max_size>=std::numeric_limits<unsigned int>::max()) {
92 return StatusCode::FAILURE;
95 truthIndexMap.resize( max_size, std::numeric_limits<unsigned int>::max());
96 unsigned int new_index=0;
98 truthIndexMap.at( decor_index(*truth_particle) ) = new_index;
103 truthIndexMap.reserve(ptruth_size);
104 for (
unsigned int i=0; i<ptruth_size; ++i) {
105 truthIndexMap.push_back(i);
109 std::vector< IDPVM::OptionalDecoration<xAOD::TruthParticleContainer,float> >
113 std::vector< std::array<uint16_t, kNClusterTypes> > tp_clustercount;
114 tp_clustercount.resize(ptruth_size,std::array<uint16_t,kNClusterTypes>{});
115 unsigned int missing_truth_particle=0u;
121 for (
const auto *
const sct : *sctClusters) {
123 static const SG::AuxElement::ConstAccessor< std::vector<unsigned int> > truthIndexAcc(
"truth_index");
124 if (truthIndexAcc.isAvailable(*sctCluster)) {
125 const std::vector<unsigned int> &truth_indices = truthIndexAcc(*sctCluster);
126 for (
auto index : truth_indices) {
127 if (
index != std::numeric_limits<unsigned int>::max()) {
128 if (
index < truthIndexMap.size() && truthIndexMap[
index] != std::numeric_limits<unsigned int>::max()) {
129 ++tp_clustercount.at(truthIndexMap[
index])[
kSCT];
132 ++missing_truth_particle;
139 for (
const auto *
const pix : *pixelClusters) {
141 static const SG::AuxElement::ConstAccessor< std::vector<unsigned int> > truthIndexAcc(
"truth_index");
142 if (truthIndexAcc.isAvailable(*pixCluster)) {
143 const std::vector<unsigned int> &truth_indices = truthIndexAcc(*pixCluster);
144 for (
auto index : truth_indices) {
145 if (
index != std::numeric_limits<unsigned int>::max()) {
146 if (
index < truthIndexMap.size() && truthIndexMap[
index] != std::numeric_limits<unsigned int>::max()) {
147 ++tp_clustercount.at(truthIndexMap[
index])[
kPixel];
150 ++missing_truth_particle;
159 if (not float_decor.empty()) {
165 decorateTruth(*truth_particle, float_decor, beamPos, tp_clustercount);
168 return StatusCode::FAILURE;
172 return StatusCode::SUCCESS;
179 const std::vector<std::array<uint16_t,kNClusterTypes> > &counts)
const {
181 if (particle.isNeutral()) {
184 const EventContext& ctx = Gaudi::Hive::currentContext();
185 const Amg::Vector3D momentum(particle.px(), particle.py(), particle.pz());
186 const int pid(particle.pdgId());
187 double charge = particle.charge();
190 ATH_MSG_DEBUG(
"charge not found on particle with pid " << pid);
195 float nSiHits = std::accumulate(counts.at(particle.index()).begin(), counts[particle.index()].end(), 0u);
201 ptruthVertex = particle.prodVtx();
202 }
catch (
const std::exception& e) {
204 ATH_MSG_WARNING(
"A non existent production vertex was requested in calculating the track parameters d0 etc");
210 ATH_MSG_DEBUG(
"A production vertex pointer was retrieved, but it is NULL");
213 const auto xPos = ptruthVertex->
x();
214 const auto yPos = ptruthVertex->
y();
215 const auto z_truth = ptruthVertex->
z();
217 const float prodR_truth = std::sqrt(xPos * xPos + yPos * yPos);
223 std::unique_ptr<const Trk::TrackParameters> tP (
m_extrapolator->extrapolate(ctx,
227 float d0_truth = tP->parameters()[
Trk::d0];
228 float theta_truth = tP->parameters()[
Trk::theta];
229 float z0_truth = tP->parameters()[
Trk::z0];
230 float phi_truth = tP->parameters()[
Trk::phi];
231 float qOverP_truth = tP->parameters()[
Trk::qOverP];
232 float z0st_truth = z0_truth * std::sin(theta_truth);
247 ATH_MSG_DEBUG(
"The TrackParameters pointer for this TruthParticle is NULL");
255 const EventContext& ctx = Gaudi::Hive::currentContext();
265 ATH_MSG_WARNING(
"TruthEventContainer name was specified, but no container is present");
270 truthVtx =
event->signalProcessVertex();
271 truthTime = (truthVtx) ? truthVtx->
t() / Gaudi::Units::c_light : -9999.;
272 for (
const auto& link : event->truthParticleLinks()) {
273 if (link.isValid()) {
288 if (!truthPileupEventContainer.
isPresent()) {
289 ATH_MSG_WARNING(
"TruthPileupEventContainer name was specified, but no container is present");
292 if (truthPileupEventContainer.
isValid()) {
293 for (
const auto event : *truthPileupEventContainer) {
295 for (std::size_t i = 0; i <
event->nTruthVertices(); i++) {
296 truthVtx =
event->truthVertex(i);
301 truthTime = (truthVtx) ? truthVtx->
t() / Gaudi::Units::c_light: -9999.;
302 for (
const auto& link : event->truthParticleLinks()) {
303 if (link.isValid()) {
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
double charge(const T &p)
header file for class of same name
Handle class for reading a decoration on an object.
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventName
virtual StatusCode finalize()
std::atomic< bool > m_errorEmitted
virtual ~InDetPhysValTruthDecoratorAlg()
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_truthParticleIndexDecor
PublicToolHandle< Trk::IExtrapolator > m_extrapolator
std::vector< std::pair< SG::WriteDecorHandleKey< xAOD::TruthParticleContainer >, SG::AuxElement::ConstAccessor< float > > > m_decor
virtual StatusCode initialize()
virtual StatusCode execute(const EventContext &ctx) const
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_truthPixelClusterName
TruthPixelClusterContainer and TruthSCTClusterContainer needed for truth silicon hit cut.
std::atomic< std::size_t > m_nMissingTruthParticles
InDetPhysValTruthDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::TrackMeasurementValidationContainer > m_truthSCTClusterName
SG::ReadDecorHandleKeyArray< xAOD::EventInfo > m_beamSpotDecoKey
Gaudi::Property< std::string > m_prefix
SG::ReadHandleKey< xAOD::TruthPileupEventContainer > m_truthPileupEventName
bool decorateTruthTime(std::vector< std::pair< SG::WriteDecorHandle< xAOD::TruthParticleContainer, float >, bool > > &float_decor) const
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleName
TruthParticle container's name needed to create decorators.
bool decorateTruth(const xAOD::TruthParticle &particle, std::vector< std::pair< SG::WriteDecorHandle< xAOD::TruthParticleContainer, float >, bool > > &float_decor, const Amg::Vector3D &beamPos, const std::vector< std::array< uint16_t, kNClusterTypes > > &counts) const
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
bool isPresent() const
Is the referenced object present in SG?
Class describing the Line to which the Perigee refers to.
float z() const
Vertex longitudinal distance along the beam line form the origin.
float y() const
Vertex y displacement.
float t() const
Vertex time.
float x() const
Vertex x displacement.
Eigen::Matrix< double, 3, 1 > Vector3D
void createDecoratorKeysAndAccessor(T_Parent &parent, const SG::ReadHandleKey< T_Cont > &container_key, const std::string &prefix, const std::vector< std::string > &decor_names, std::vector< WriteKeyAccessorPair< T_Cont, T > > &decor_out)
void decorateOrRejectQuietly(const T_Cont_Elm &particle, OptionalDecoration< T_Cont, T > &decorator, const T &value)
std::vector< OptionalDecoration< T_Cont, T > > createDecoratorsIfNeeded(const T_Cont &container, const std::vector< WriteKeyAccessorPair< T_Cont, T > > &keys, const EventContext &ctx, bool verbose=false)
std::pair< SG::WriteDecorHandle< ContainerType, VariableType >, bool > OptionalDecoration
CurvilinearParametersT< TrackParametersDim, Charged, PlaneSurface > CurvilinearParameters
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
TruthVertex_v1 TruthVertex
Typedef to implementation.
TruthEvent_v1 TruthEvent
Typedef to implementation.
TruthParticle_v1 TruthParticle
Typedef to implementation.
implementation file for function of same name