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  //Initialize set for a list of UNIQUE barcodes for the cluster
82  std::set<int> barcodes;
84  //Loop over all elements (pixels/strips) in the cluster
85  if(pixSdoColl.isValid()){
86  for (auto rdoIter : rdos){
87  auto simDataIter = pixSdoColl->find(rdoIter);
88  if (simDataIter != pixSdoColl->end()){
89  // get the SimData and count the individual contributions
90  auto simData = (simDataIter->second);
91  for( const auto& deposit : simData.getdeposits() ){
92  //If deposit exists
93  if (!deposit.first){ATH_MSG_WARNING("No deposits found"); continue;}
94  // This should only be used for samples with pile-up
95  if (m_discardPUHits && deposit.first.eventIndex()!=0) continue;
96  int bc = deposit.first.barcode();
97  barcodes.insert(bc);
98  }
99  }
100  }
101  }
102  //Barcodes list of the total number of UNIQUE
103  //barcodes in the cluster, each corresponding to a truth particle
104  nPartContributing = barcodes.size();
105  ATH_MSG_VERBOSE("n Part Contributing: " << nPartContributing);
106  ATH_MSG_VERBOSE("Smearing TruthClusterizationFactory probability output for TIDE studies");
107  //If only 1 truth particles found
108  //For pure PU case nPartContributing=0, assume that there is a single particle contributing as well
109  if (nPartContributing<=1) {
110  //NN will always return 100% chance of there being only 1 particle
111  probabilities[0] = 1.0;
112  }
113  //If two unique truth particles found in cluster
114  else if (nPartContributing==2) {
115  //90% chance NN returns high probability of there being 2 particles
116  if (CLHEP::RandFlat::shoot( engine, 0, 1 ) < m_truthClusterSplittingEff) probabilities[1] = 1.0;
117  //Other 10% NN returns high probability of there being 1 particle
118  else probabilities[0] = 1.0;
119  }
120  //If greater than 2 unique truth particles in cluster
121  else if (nPartContributing>2) {
122  //90% chance NN returns high probability of there being >2 particles
123  if (CLHEP::RandFlat::shoot( engine, 0, 1 ) < m_truthClusterSplittingEff) probabilities[2] = 1.0;
124  //Other 10% NN returns high probability of there being 1 particle
125  else probabilities[0] = 1.0;
126  }
127 
128  return probabilities;
129 
130  }
131 
132  std::vector<Amg::Vector2D> TruthClusterizationFactory::estimatePositions(const InDet::PixelCluster& ) const
133  {
134  ATH_MSG_ERROR("TruthClusterizationFactory::estimatePositions called for ITk ambiguity setup, should never happen! Digital clustering should be run for positions & errors.");
135  return std::vector<Amg::Vector2D>(2,Amg::Vector2D (2,0.));
136  }
137 
138 }//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
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
PixelCluster.h
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
InDet
DUMMY 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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
python.Dumpers.barcodes
def barcodes(beg, end, sz)
Definition: Dumpers.py:2800
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:192
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
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
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:132