ATLAS Offline Software
UnassociatedHitsGetterTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
11 #include "TrkTrack/Track.h"
15 
17 
18 namespace DerivationFramework {
19 
21  const std::string& name,
22  const IInterface* parent) :
24 {
25  declareInterface<IUnassociatedHitsGetterTool>(this);
26 }
27 
29 
31 
33 
34  // retrieve PRD association tool
36  ATH_CHECK( m_assoTool.retrieve(DisableTool{!m_prdToTrackMapKey.key().empty()} ) );
37  ATH_CHECK( m_trackCollection.initialize());
40  // Read Cond Handle Key
42 
44 
45  return StatusCode::SUCCESS;
46 }
47 
48 const MinBiasPRDAssociation* UnassociatedHitsGetterTool::get (bool /*allowMissing*/) const {
49  const EventContext& ctx = Gaudi::Hive::currentContext();
50 
51  // If we fail to find something we need in SG on the first call,
52  // issue a warning and don't try again (this can happen if we're
53  // reading an AOD). But consider it an ERROR if it happens
54  // after the first call.
55 
56  // retrieve track collection
58  if(!trackCollection.isValid()) {
59  ATH_MSG_FATAL("Track collection " << m_trackCollection.key() << " not found in StoreGate");
60  return nullptr;
61  }
62 
63  // Get empty state for PRD association tool.
64  const Trk::PRDtoTrackMap *prd_to_track_map;
65  std::unique_ptr<Trk::PRDtoTrackMap> prd_to_track_map_cleanup;
66  if (!m_prdToTrackMapKey.key().empty()) {
67  SG::ReadHandle<Trk::PRDtoTrackMap> prd_to_track_map_handle(m_prdToTrackMapKey,ctx);
68  if (!prd_to_track_map_handle.isValid()) {
69  ATH_MSG_ERROR( "Failed to get PRDs to track map " << m_prdToTrackMapKey.key());
70  return nullptr;
71  }
72  prd_to_track_map=prd_to_track_map_handle.cptr();
73  }
74  else {
75  prd_to_track_map_cleanup = m_assoTool->createPRDtoTrackMap();
76  // Loop over tracks and add PRDs to the PRD association tool
77  for (const Trk::Track* track : *trackCollection) {
78  StatusCode sc = m_assoTool->addPRDs(*prd_to_track_map_cleanup, *track);
79  if(sc.isFailure()){
80  ATH_MSG_FATAL( "Could not add PRDs to track");
81  return nullptr;
82  }
83  }
84  prd_to_track_map = prd_to_track_map_cleanup.get();
85  }
86 
87  std::unique_ptr<MinBiasPRDAssociation> PRDAssociation(std::make_unique<MinBiasPRDAssociation>());
88  if (!m_pixelClusterContainer.key().empty()) {
89  // retrieve pixel clusters
91  if(!pixelClusters.isValid()) {
92  ATH_MSG_FATAL("Pixel cluster container '" << m_pixelClusterContainer.key() << "' not found in StoreGate");
93  return nullptr;
94  }
95  // Loop on pixel clusters
96  InDet::PixelClusterContainer::const_iterator pixCollItr = pixelClusters->begin();
97  InDet::PixelClusterContainer::const_iterator pixCollEnd = pixelClusters->end();
98  for(; pixCollItr!=pixCollEnd; ++pixCollItr){
99 
100  InDet::PixelClusterCollection::const_iterator pixItr = (*pixCollItr)->begin();
101  InDet::PixelClusterCollection::const_iterator pixEnd = (*pixCollItr)->end();
102  for(; pixItr!=pixEnd; ++pixItr){
103 
104  // ask the association tool if the hit was associated
105  if(prd_to_track_map->isUsed(*(*pixItr))) continue;
106 
107  // count number of unassociated pixel hits
108  PRDAssociation->nPixelUA++;
109 
110  // find out which detector element the hit belongs to
111  const InDetDD::SiDetectorElement *det = (*pixItr)->detectorElement();
112 
113  // count pixel barrel unassociated hits
114  if(det->isBarrel()) PRDAssociation->nPixelBarrelUA++;
115 
116  // count pixel endcap unassociated hits: use hit Z position to determin A/C side
117  if(det->isEndcap()){
118  if((*pixItr)->globalPosition().z()<0){
119  PRDAssociation->nPixelEndCapCUA++;
120  }else{
121  PRDAssociation->nPixelEndCapAUA++;
122  }
123  }
124 
125  // count B-Layer unassociated hits
126  if(det->isBlayer()) PRDAssociation->nBlayerUA++;
127  }
128  }
129  }
130 
131  // retrieve SCT clusters
132  if (!m_SCTClusterContainer.key().empty()) {
134  if(!SCTClusters.isValid()) {
135  ATH_MSG_FATAL("SCT cluster container '" << m_SCTClusterContainer.key() << "' not found in StoreGate");
136  return nullptr;
137  }
138  // Loop on SCT clusters
139  InDet::SCT_ClusterContainer::const_iterator sctCollItr = SCTClusters->begin();
140  InDet::SCT_ClusterContainer::const_iterator sctCollEnd = SCTClusters->end();
141  for(; sctCollItr!=sctCollEnd; ++sctCollItr){
142 
143  InDet::SCT_ClusterCollection::const_iterator sctItr = (*sctCollItr)->begin();
144  InDet::SCT_ClusterCollection::const_iterator sctEnd = (*sctCollItr)->end();
145  for(; sctItr!=sctEnd; ++sctItr){
146 
147  // ask the association tool if the hit was associated
148  if(prd_to_track_map->isUsed(*(*sctItr))) continue;
149 
150  // count number of unassociated SCT hits
151  PRDAssociation->nSCTUA++;
152 
153  // find out which detector element the hit belongs to
154  const InDetDD::SiDetectorElement *det = (*sctItr)->detectorElement();
155 
156  // count SCT barrel unassociated hits
157  if(det->isBarrel()) PRDAssociation->nSCTBarrelUA++;
158 
159  // count SCT endcap unassociated hits: use hit Z position to determin A/C side
160  if(det->isEndcap()){
161  if((*sctItr)->globalPosition().z()<0){
162  PRDAssociation->nSCTEndCapCUA++;
163  }else{
164  PRDAssociation->nSCTEndCapAUA++;
165  }
166  }
167  }
168  }
169  }
170 
171  // retrieve TRT drift circles
172  if (!m_TRTDriftCircleContainer.key().empty()) {
174  if(!TRTDriftCircles.isValid()) {
175  ATH_MSG_FATAL("TRT drift circle container '" << m_TRTDriftCircleContainer << "' not found in StoreGate");
176  return nullptr;
177  }
178  // Loop on TRT clusters
179  InDet::TRT_DriftCircleContainer::const_iterator trtCollItr = TRTDriftCircles->begin();
180  InDet::TRT_DriftCircleContainer::const_iterator trtCollEnd = TRTDriftCircles->end();
181  for(; trtCollItr!=trtCollEnd; ++trtCollItr){
182 
183  InDet::TRT_DriftCircleCollection::const_iterator trtItr = (*trtCollItr)->begin();
184  InDet::TRT_DriftCircleCollection::const_iterator trtEnd = (*trtCollItr)->end();
185  for(; trtItr!=trtEnd; ++trtItr){
186 
187  // ask the association tool if the hit was associated
188  if(prd_to_track_map->isUsed(*(*trtItr))) continue;
189 
190  // count number of unassociated TRT hits
191  PRDAssociation->nTRTUA++;
192 
193  // find out which detector element the hit belongs to
194  const InDetDD::TRT_BaseElement *det = (*trtItr)->detectorElement();
195 
197 
198  // count TRT barrel unassociated hits
199  if(type == InDetDD::TRT_BaseElement::BARREL) PRDAssociation->nTRTBarrelUA++;
200 
201  // count TRT endcap unassociated hits: use hit Z position to determin A/C side
203  if(det->center().z()<0){
204  PRDAssociation->nTRTEndCapCUA++;
205  }else{
206  PRDAssociation->nTRTEndCapAUA++;
207  }
208  }
209  }
210  }
211  }
212 
213  return PRDAssociation.release();
214 }
215 
217  if(p) delete p;
218 }
219 
220 } // namespace DerivationFramework
PRDtoTrackMap.h
DerivationFramework::UnassociatedHitsGetterTool::initialize
StatusCode initialize()
Definition: UnassociatedHitsGetterTool.cxx:30
DerivationFramework::UnassociatedHitsGetterTool::m_trackCollection
SG::ReadHandleKey< TrackCollection > m_trackCollection
Definition: UnassociatedHitsGetterTool.h:57
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DerivationFramework::UnassociatedHitsGetterTool::m_assoTool
ToolHandle< Trk::IPRDtoTrackMapTool > m_assoTool
Definition: UnassociatedHitsGetterTool.h:69
AthMsgStreamMacros.h
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
MinBiasPRDAssociation::nPixelBarrelUA
int nPixelBarrelUA
Definition: MinBiasPRDAssociation.h:20
MinBiasPRDAssociation::nPixelUA
int nPixelUA
Definition: MinBiasPRDAssociation.h:18
MinBiasPRDAssociation::nPixelEndCapAUA
int nPixelEndCapAUA
Definition: MinBiasPRDAssociation.h:21
TRTCalib_Extractor.det
det
Definition: TRTCalib_Extractor.py:36
PixelCluster.h
Trk::PRDtoTrackMap
Definition: PRDtoTrackMap.h:17
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
DerivationFramework::UnassociatedHitsGetterTool::UnassociatedHitsGetterTool
UnassociatedHitsGetterTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: UnassociatedHitsGetterTool.cxx:20
initialize
void initialize()
Definition: run_EoverP.cxx:894
MinBiasPRDAssociation::nSCTEndCapCUA
int nSCTEndCapCUA
Definition: MinBiasPRDAssociation.h:27
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SCT_Cluster.h
MinBiasPRDAssociation::nSCTUA
int nSCTUA
Definition: MinBiasPRDAssociation.h:24
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
DerivationFramework::UnassociatedHitsGetterTool::releaseObject
virtual void releaseObject(const MinBiasPRDAssociation *p) const
delete the pointer created by get
Definition: UnassociatedHitsGetterTool.cxx:216
Track.h
DerivationFramework::UnassociatedHitsGetterTool::m_pixelClusterContainer
SG::ReadHandleKey< InDet::PixelClusterContainer > m_pixelClusterContainer
Definition: UnassociatedHitsGetterTool.h:59
DerivationFramework::UnassociatedHitsGetterTool::m_SCTDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
Definition: UnassociatedHitsGetterTool.h:66
MinBiasPRDAssociation::nTRTEndCapCUA
int nTRTEndCapCUA
Definition: MinBiasPRDAssociation.h:32
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
MinBiasPRDAssociation::nTRTEndCapAUA
int nTRTEndCapAUA
Definition: MinBiasPRDAssociation.h:31
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DerivationFramework::UnassociatedHitsGetterTool::m_prdToTrackMapKey
SG::ReadHandleKey< Trk::PRDtoTrackMap > m_prdToTrackMapKey
Definition: UnassociatedHitsGetterTool.h:71
InDetDD::TRT_BaseElement::ENDCAP
@ ENDCAP
Definition: TRT_BaseElement.h:61
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MinBiasPRDAssociation::nSCTBarrelUA
int nSCTBarrelUA
Definition: MinBiasPRDAssociation.h:25
InDetDD::TRT_BaseElement::BARREL
@ BARREL
Definition: TRT_BaseElement.h:61
test_pyathena.parent
parent
Definition: test_pyathena.py:15
UnassociatedHitsGetterTool.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::UnassociatedHitsGetterTool::get
virtual const MinBiasPRDAssociation * get(bool allowMissing=false) const
get method: compute the number of unassociated his wrap the info in a MinBiasPRDAssociation object
Definition: UnassociatedHitsGetterTool.cxx:48
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
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
MinBiasPRDAssociation::nSCTEndCapAUA
int nSCTEndCapAUA
Definition: MinBiasPRDAssociation.h:26
Trk::PRDtoTrackMap::isUsed
bool isUsed(const PrepRawData &prd) const
does this PRD belong to at least one track?
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TRT_DriftCircle.h
InDetDD::TRT_BaseElement::Type
Type
Definition: TRT_BaseElement.h:61
MinBiasPRDAssociation
Definition: MinBiasPRDAssociation.h:11
TRT_BaseElement.h
DerivationFramework::UnassociatedHitsGetterTool::m_SCTClusterContainer
SG::ReadHandleKey< InDet::SCT_ClusterContainer > m_SCTClusterContainer
Definition: UnassociatedHitsGetterTool.h:61
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
errorcheck.h
Helpers for checking error return status codes and reporting errors.
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
DerivationFramework::UnassociatedHitsGetterTool::m_TRTDriftCircleContainer
SG::ReadHandleKey< InDet::TRT_DriftCircleContainer > m_TRTDriftCircleContainer
Definition: UnassociatedHitsGetterTool.h:63
SiDetectorElement.h
MinBiasPRDAssociation::nTRTBarrelUA
int nTRTBarrelUA
Definition: MinBiasPRDAssociation.h:30
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DerivationFramework::UnassociatedHitsGetterTool::~UnassociatedHitsGetterTool
virtual ~UnassociatedHitsGetterTool()
MinBiasPRDAssociation::nPixelEndCapCUA
int nPixelEndCapCUA
Definition: MinBiasPRDAssociation.h:22
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
AthAlgTool
Definition: AthAlgTool.h:26
MinBiasPRDAssociation::nBlayerUA
int nBlayerUA
Definition: MinBiasPRDAssociation.h:19
MinBiasPRDAssociation::nTRTUA
int nTRTUA
Definition: MinBiasPRDAssociation.h:29
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57