ATLAS Offline Software
Loading...
Searching...
No Matches
TruthClusterizationFactory.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
13
14
15
17
18//for position estimate and clustering
21
22#include "GaudiKernel/ServiceHandle.h"
23#include "GaudiKernel/Incident.h"
28
30
31#include "CLHEP/Random/RandFlat.h"
32
33#include <TMath.h>
34
35namespace InDet {
36
38 const std::string& n, const IInterface* p):
39 AthAlgTool(name, n, p)
40 {
41 declareInterface<TruthClusterizationFactory>(this);
42 }
43
45
47
48 // random svc
49 CHECK(m_rndmSvc.retrieve());
50
51 // get the random stream
52 ATH_MSG_DEBUG ( "Getting random number engine : <" << m_rndmEngineName << ">" );
53 m_rndmEngine = m_rndmSvc->getEngine(this, m_rndmEngineName);
54 if (!m_rndmEngine) {
55 ATH_MSG_ERROR("Could not find RndmEngine : " << m_rndmEngineName);
56 return StatusCode::FAILURE;
57 }
58 else {
59 ATH_MSG_DEBUG("Found RndmEngine : " << m_rndmEngineName);
60 }
61
62 ATH_CHECK( m_simDataCollectionName.initialize() );
63
64 return StatusCode::SUCCESS;
65 }
66
67
68
70 {
71 const EventContext& ctx = Gaudi::Hive::currentContext();
72 if (ctx.evt() != m_rndmEngine->evtSeeded()) {
74 wrapper->setSeed (this->name(), ctx);
75 }
76 CLHEP::HepRandomEngine* engine = m_rndmEngine->getEngine (ctx);
77
78 std::vector<double> probabilities(3,0.);
79 const auto &rdos = pCluster.rdoList();
80 unsigned int nPartContributing = 0;
81 if (m_discardPUHits) {
82 // Initialize set for a list of distinct uniqueIDs for the cluster
83 std::set<int> uniqueIDs;
85 //Loop over all elements (pixels/strips) in the cluster
86 if(pixSdoColl.isValid()){
87 for (auto rdoIter : rdos){
88 auto simDataIter = pixSdoColl->find(rdoIter);
89 if (simDataIter != pixSdoColl->end()){
90 // get the SimData and count the individual contributions
91 auto simData = (simDataIter->second);
92 for( const auto& deposit : simData.getdeposits() ){
93 //If deposit exists
94 if (!deposit.first){ATH_MSG_DEBUG("No deposits found"); continue;}
95 // This should only be used for samples without pile-up
96 if (deposit.first.eventIndex() != 0) continue;
97 uniqueIDs.insert(deposit.first.id());
98 }
99 }
100 }
101 }
102 //uniqueIDs lists the unique truth particles contributing to the
103 //cluster
104 nPartContributing = uniqueIDs.size();
105 }
106 else {
107 //Initialize set for a list of distinct uniqueIDs for the cluster
108 //- if we are taking into account pile-up, then we need
109 //GenEvent::event_number() + GenParticle::id() to uniquely
110 //idenftify a GenParticle from a group of GenEvents.
111 std::set< std::pair<HepMcParticleLink::index_type, int> > uniqueIDs;
113 //Loop over all elements (pixels/strips) in the cluster
114 if(pixSdoColl.isValid()){
115 for (auto rdoIter : rdos){
116 auto simDataIter = pixSdoColl->find(rdoIter);
117 if (simDataIter != pixSdoColl->end()){
118 // get the SimData and count the individual contributions
119 auto simData = (simDataIter->second);
120 for( const auto& deposit : simData.getdeposits() ){
121 //If deposit exists
122 if (!deposit.first){ATH_MSG_DEBUG("No deposits found"); continue;}
123 // This should only be used for samples with pile-up
124 uniqueIDs.insert(std::make_pair(deposit.first.eventIndex(), deposit.first.id()));
125 }
126 }
127 }
128 }
129 //uniqueIDs lists the unique truth particles contributing to the
130 //cluster
131 nPartContributing = uniqueIDs.size();
132 }
133 ATH_MSG_VERBOSE("n Part Contributing: " << nPartContributing);
134 ATH_MSG_VERBOSE("Smearing TruthClusterizationFactory probability output for TIDE studies");
135 //If only 1 truth particles found
136 //For pure PU case nPartContributing=0, assume that there is a single particle contributing as well
137 if (nPartContributing<=1) {
138 //NN will always return 100% chance of there being only 1 particle
139 probabilities[0] = 1.0;
140 }
141 //If two unique truth particles found in cluster
142 else if (nPartContributing==2) {
143 //90% chance NN returns high probability of there being 2 particles
144 if (CLHEP::RandFlat::shoot( engine, 0, 1 ) < m_truthClusterSplittingEff) probabilities[1] = 1.0;
145 //Other 10% NN returns high probability of there being 1 particle
146 else probabilities[0] = 1.0;
147 }
148 //If greater than 2 unique truth particles in cluster
149 else if (nPartContributing>2) {
150 //90% chance NN returns high probability of there being >2 particles
151 if (CLHEP::RandFlat::shoot( engine, 0, 1 ) < m_truthClusterSplittingEff) probabilities[2] = 1.0;
152 //Other 10% NN returns high probability of there being 1 particle
153 else probabilities[0] = 1.0;
154 }
155
156 return probabilities;
157
158 }
159
161 {
162 ATH_MSG_ERROR("TruthClusterizationFactory::estimatePositions called for ITk ambiguity setup, should never happen! Digital clustering should be run for positions & errors.");
163 return std::vector<Amg::Vector2D>(2,Amg::Vector2D (2,0.));
164 }
165
166}//end InDet namespace
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
This is an Identifier helper class for the Pixel subdetector.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
A wrapper class for event-slot-local random engines.
Definition RNGWrapper.h:56
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Property< float > m_truthClusterSplittingEff
TruthClusterizationFactory(const std::string &name, const std::string &n, const IInterface *p)
Gaudi::Property< std::string > m_rndmEngineName
std::vector< Amg::Vector2D > estimatePositions(const InDet::PixelCluster &) const
std::vector< double > estimateNumberOfParticles(const InDet::PixelCluster &pCluster) const
SG::ReadHandleKey< InDetSimDataCollection > m_simDataCollectionName
IncidentSvc to catch begining of event and end of event.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
constexpr bool simData
Definition constants.h:36
Eigen::Matrix< double, 2, 1 > Vector2D
Primary Vertex Finder.