ATLAS Offline Software
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"
25 #include "AtlasHepMC/GenParticle.h"
28 
30 
31 #include "CLHEP/Random/RandFlat.h"
32 
33 #include <TMath.h>
34 
35 namespace 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 
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 
160  std::vector<Amg::Vector2D> TruthClusterizationFactory::estimatePositions(const InDet::PixelCluster& ) const
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
InDet::TruthClusterizationFactory::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition: TruthClusterizationFactory.h:73
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
PixelCluster.h
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
Trk::PrepRawData::rdoList
const std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
InDet::TruthClusterizationFactory::m_rndmEngine
ATHRNG::RNGWrapper * m_rndmEngine
Definition: TruthClusterizationFactory.h:75
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ParamDefs.h
GenParticle.h
InDet::TruthClusterizationFactory::m_simDataCollectionName
SG::ReadHandleKey< InDetSimDataCollection > m_simDataCollectionName
IncidentSvc to catch begining of event and end of event.
Definition: TruthClusterizationFactory.h:70
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
InDetSimData.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TruthClusterizationFactory.h
InDet::TruthClusterizationFactory::TruthClusterizationFactory
TruthClusterizationFactory(const std::string &name, const std::string &n, const IInterface *p)
Definition: TruthClusterizationFactory.cxx:37
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
InDet::TruthClusterizationFactory::initialize
virtual StatusCode initialize()
Definition: TruthClusterizationFactory.cxx:44
InDet::TruthClusterizationFactory::m_discardPUHits
Gaudi::Property< bool > m_discardPUHits
Definition: TruthClusterizationFactory.h:76
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
InDet::TruthClusterizationFactory::m_truthClusterSplittingEff
Gaudi::Property< float > m_truthClusterSplittingEff
Definition: TruthClusterizationFactory.h:77
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
InDet::TruthClusterizationFactory::estimateNumberOfParticles
std::vector< double > estimateNumberOfParticles(const InDet::PixelCluster &pCluster) const
Definition: TruthClusterizationFactory.cxx:69
InDet::TruthClusterizationFactory::m_rndmEngineName
Gaudi::Property< std::string > m_rndmEngineName
Definition: TruthClusterizationFactory.h:74
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
simData
constexpr bool simData
Definition: constants.h:36
AthAlgTool
Definition: AthAlgTool.h:26
checker_macros.h
Define macros for attributes used to control the static checker.
ATHRNG::RNGWrapper::evtSeeded
EventContext::ContextEvt_t evtSeeded() const
Return the event count at which the current slot was last seeded.
Definition: RNGWrapper.h:139
InDet::TruthClusterizationFactory::estimatePositions
std::vector< Amg::Vector2D > estimatePositions(const InDet::PixelCluster &) const
Definition: TruthClusterizationFactory.cxx:160