ATLAS Offline Software
TrackTruthSelector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 TrackTruthSelector::TrackTruthSelector(const std::string &name,ISvcLocator *pSvcLocator) :
8  AthAlgorithm(name,pSvcLocator),
9  m_detailedTrackTruthName("DetailedTrackTruth"),
10  m_outputName("TrackTruthNew"),
11  m_subDetWeights(SubDetHitStatistics::NUM_SUBDETECTORS, 1.)
12 {
13  declareProperty("DetailedTrackTruthName", m_detailedTrackTruthName);
14  declareProperty("OutputName", m_outputName);
15 
25 }
26 
27 // -----------------------------------------------------------------------------------------------------
29 {
32  return StatusCode::SUCCESS;
33 }
34 
35 // -----------------------------------------------------------------------------------------------------
37  ATH_MSG_DEBUG ("TrackTruthSelector::execute()");
38 
39  //----------------------------------------------------------------
40  // Retrieve the input
41  const DetailedTrackTruthCollection *detailed = nullptr;
44  if(!rh_detailed.isValid()){
45  ATH_MSG_WARNING ("DetailedTrackTruthCollection "<<m_detailedTrackTruthName.key()<<" NOT found");
46  return StatusCode::SUCCESS;
47  } else {
48  detailed = rh_detailed.cptr();
49  ATH_MSG_DEBUG ("Got DetailedTrackTruthCollection "<<m_detailedTrackTruthName.key());
50  }
51 
52 
53  //----------------------------------------------------------------
54  // Produce and store the output.
55 
57 
58  fillOutput(out,detailed);
59 
60  ATH_CHECK(wh_output.record(std::unique_ptr<TrackTruthCollection>(out)));
61 
62  return StatusCode::SUCCESS;
63 
64 }
65 //================================================================
66 
69 {
70  using Iter = DetailedTrackTruthCollection::const_iterator;
71  Iter itrackData=in->begin();
72  while(itrackData!=in->end()) {
73  std::pair<Iter,Iter> range = in->equal_range(itrackData->first);
74 
75  // We KNOW that the range is not empty - no need to check that.
76  Iter selected = range.first;
77  double bestProb = getProbability(selected->second);
78  ATH_MSG_VERBOSE ("track=" << selected->first.index() << " prob=" << bestProb << " link: " << *(selected->second.trajectory().rbegin()));
79  for(Iter imatch = ++range.first; imatch != range.second; ++imatch) {
80  double prob = getProbability(imatch->second);
81  ATH_MSG_VERBOSE ("track=" << imatch->first.index() << " prob=" << prob << " link: " << *(imatch->second.trajectory().rbegin()));
82  if(prob>bestProb) {
83  bestProb = prob;
84  selected = imatch;
85  }
86  }
87 
88  // trajectory[0] is the LAST particle on the trajectory. The first
89  // is at trajectory.rbegin(), but different trajectories can have
90  // the same first particle.
91  // const HepMcParticleLink& particleLink = selected->second.trajectory()[0];
92  const HepMcParticleLink& particleLink = *(selected->second.trajectory().rbegin());
93 
94  ATH_MSG_DEBUG ("Truth selected for track=" << selected->first.index() << " prob=" << bestProb << " link: " << particleLink);
95  out->insert(std::make_pair(selected->first, TrackTruth(particleLink, bestProb, 0) ));
96  itrackData=range.second;
97  }
98 
99 }
100 
101 //================================================================
103 {
104  double prd_track=0, prd_common=0;
105  for(unsigned i=0; i<SubDetHitStatistics::NUM_SUBDETECTORS; i++) {
106  prd_common += m_subDetWeights[i] * dt.statsCommon()[SubDetHitStatistics::SubDetType(i)];
107  prd_track += m_subDetWeights[i] * dt.statsTrack()[SubDetHitStatistics::SubDetType(i)];
108  }
109  return (prd_track>0)? prd_common/prd_track : -1.;
110 }
111 
112 //================================================================
SubDetHitStatistics::SubDetType
SubDetType
Definition: SubDetHitStatistics.h:74
TrackTruthSelector::execute
virtual StatusCode execute() override
Definition: TrackTruthSelector.cxx:36
SubDetHitStatistics::SCT
@ SCT
Definition: SubDetHitStatistics.h:74
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
TrackTruthSelector::m_detailedTrackTruthName
SG::ReadHandleKey< DetailedTrackTruthCollection > m_detailedTrackTruthName
Definition: TrackTruthSelector.h:26
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SubDetHitStatistics::NUM_SUBDETECTORS
@ NUM_SUBDETECTORS
Definition: SubDetHitStatistics.h:74
SubDetHitStatistics
Definition: SubDetHitStatistics.h:34
TrackTruthSelector::TrackTruthSelector
TrackTruthSelector(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrackTruthSelector.cxx:7
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
TrackTruthSelector::m_subDetWeights
std::vector< double > m_subDetWeights
Definition: TrackTruthSelector.h:32
SubDetHitStatistics::MM
@ MM
Definition: SubDetHitStatistics.h:74
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
covarianceTool.prob
prob
Definition: covarianceTool.py:678
SubDetHitStatistics::CSC
@ CSC
Definition: SubDetHitStatistics.h:74
TrackTruthSelector::m_outputName
SG::WriteHandleKey< TrackTruthCollection > m_outputName
Definition: TrackTruthSelector.h:29
TrackTruthCollection
Definition: TrackTruthCollection.h:21
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
CaloNoise_fillDB.dt
dt
Definition: CaloNoise_fillDB.py:58
SubDetHitStatistics::MDT
@ MDT
Definition: SubDetHitStatistics.h:74
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrackTruthSelector::fillOutput
void fillOutput(TrackTruthCollection *out, const DetailedTrackTruthCollection *in)
Definition: TrackTruthSelector.cxx:67
TrackTruthSelector::getProbability
double getProbability(const DetailedTrackTruth &dt) const
Definition: TrackTruthSelector.cxx:102
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
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SubDetHitStatistics::TGC
@ TGC
Definition: SubDetHitStatistics.h:74
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DetailedTrackTruth
Definition: DetailedTrackTruth.h:16
TrackTruthSelector::initialize
virtual StatusCode initialize() override
Definition: TrackTruthSelector.cxx:28
SubDetHitStatistics::RPC
@ RPC
Definition: SubDetHitStatistics.h:74
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TrackTruth
MC particle associated with a reco track + the quality of match.
Definition: TrackTruth.h:14
SubDetHitStatistics::TRT
@ TRT
Definition: SubDetHitStatistics.h:74
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DetailedTrackTruthCollection::trackCollectionLink
DataLink< TrackCollection > trackCollectionLink() const
Definition: DetailedTrackTruthCollection.h:25
DetailedTrackTruthCollection
Definition: DetailedTrackTruthCollection.h:20
SubDetHitStatistics::Pixel
@ Pixel
Definition: SubDetHitStatistics.h:74
SubDetHitStatistics::STGC
@ STGC
Definition: SubDetHitStatistics.h:74
TrackTruthSelector.h