ATLAS Offline Software
Loading...
Searching...
No Matches
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
18namespace DerivationFramework {
19
21 const std::string& name,
22 const IInterface* parent) :
23 base_class(type, name, parent)
24{
25}
26
28
30
31 CHECK(AthAlgTool::initialize());
32
33 // retrieve PRD association tool
34 ATH_CHECK( m_prdToTrackMapKey.initialize(!m_prdToTrackMapKey.key().empty()));
35 ATH_CHECK( m_assoTool.retrieve(DisableTool{!m_prdToTrackMapKey.key().empty()} ) );
36 ATH_CHECK( m_trackCollection.initialize());
37 ATH_CHECK( m_pixelClusterContainer.initialize( !m_pixelClusterContainer.key().empty()) );
38 ATH_CHECK( m_SCTClusterContainer.initialize( !m_SCTClusterContainer.key().empty()) );
39 // Read Cond Handle Key
40 ATH_CHECK( m_SCTDetEleCollKey.initialize(!m_SCTClusterContainer.key().empty()) );
41
43
44 return StatusCode::SUCCESS;
45}
46
47const MinBiasPRDAssociation* UnassociatedHitsGetterTool::get (bool /*allowMissing*/) const {
48 const EventContext& ctx = Gaudi::Hive::currentContext();
49
50 // If we fail to find something we need in SG on the first call,
51 // issue a warning and don't try again (this can happen if we're
52 // reading an AOD). But consider it an ERROR if it happens
53 // after the first call.
54
55 // retrieve track collection
57 if(!trackCollection.isValid()) {
58 ATH_MSG_FATAL("Track collection " << m_trackCollection.key() << " not found in StoreGate");
59 return nullptr;
60 }
61
62 // Get empty state for PRD association tool.
63 const Trk::PRDtoTrackMap *prd_to_track_map;
64 std::unique_ptr<Trk::PRDtoTrackMap> prd_to_track_map_cleanup;
65 if (!m_prdToTrackMapKey.key().empty()) {
66 SG::ReadHandle<Trk::PRDtoTrackMap> prd_to_track_map_handle(m_prdToTrackMapKey,ctx);
67 if (!prd_to_track_map_handle.isValid()) {
68 ATH_MSG_ERROR( "Failed to get PRDs to track map " << m_prdToTrackMapKey.key());
69 return nullptr;
70 }
71 prd_to_track_map=prd_to_track_map_handle.cptr();
72 }
73 else {
74 prd_to_track_map_cleanup = m_assoTool->createPRDtoTrackMap();
75 // Loop over tracks and add PRDs to the PRD association tool
76 for (const Trk::Track* track : *trackCollection) {
77 StatusCode sc = m_assoTool->addPRDs(*prd_to_track_map_cleanup, *track);
78 if(sc.isFailure()){
79 ATH_MSG_FATAL( "Could not add PRDs to track");
80 return nullptr;
81 }
82 }
83 prd_to_track_map = prd_to_track_map_cleanup.get();
84 }
85
86 std::unique_ptr<MinBiasPRDAssociation> PRDAssociation(std::make_unique<MinBiasPRDAssociation>());
87 if (!m_pixelClusterContainer.key().empty()) {
88 // retrieve pixel clusters
90 if(!pixelClusters.isValid()) {
91 ATH_MSG_FATAL("Pixel cluster container '" << m_pixelClusterContainer.key() << "' not found in StoreGate");
92 return nullptr;
93 }
94 // Loop on pixel clusters
95 InDet::PixelClusterContainer::const_iterator pixCollItr = pixelClusters->begin();
96 InDet::PixelClusterContainer::const_iterator pixCollEnd = pixelClusters->end();
97 for(; pixCollItr!=pixCollEnd; ++pixCollItr){
98
99 InDet::PixelClusterCollection::const_iterator pixItr = (*pixCollItr)->begin();
100 InDet::PixelClusterCollection::const_iterator pixEnd = (*pixCollItr)->end();
101 for(; pixItr!=pixEnd; ++pixItr){
102
103 // ask the association tool if the hit was associated
104 if(prd_to_track_map->isUsed(*(*pixItr))) continue;
105
106 // count number of unassociated pixel hits
107 PRDAssociation->nPixelUA++;
108
109 // find out which detector element the hit belongs to
110 const InDetDD::SiDetectorElement *det = (*pixItr)->detectorElement();
111
112 // count pixel barrel unassociated hits
113 if(det->isBarrel()) PRDAssociation->nPixelBarrelUA++;
114
115 // count pixel endcap unassociated hits: use hit Z position to determin A/C side
116 if(det->isEndcap()){
117 if((*pixItr)->globalPosition().z()<0){
118 PRDAssociation->nPixelEndCapCUA++;
119 }else{
120 PRDAssociation->nPixelEndCapAUA++;
121 }
122 }
123
124 // count B-Layer unassociated hits
125 if(det->isBlayer()) PRDAssociation->nBlayerUA++;
126 }
127 }
128 }
129
130 // retrieve SCT clusters
131 if (!m_SCTClusterContainer.key().empty()) {
133 if(!SCTClusters.isValid()) {
134 ATH_MSG_FATAL("SCT cluster container '" << m_SCTClusterContainer.key() << "' not found in StoreGate");
135 return nullptr;
136 }
137 // Loop on SCT clusters
138 InDet::SCT_ClusterContainer::const_iterator sctCollItr = SCTClusters->begin();
139 InDet::SCT_ClusterContainer::const_iterator sctCollEnd = SCTClusters->end();
140 for(; sctCollItr!=sctCollEnd; ++sctCollItr){
141
142 InDet::SCT_ClusterCollection::const_iterator sctItr = (*sctCollItr)->begin();
143 InDet::SCT_ClusterCollection::const_iterator sctEnd = (*sctCollItr)->end();
144 for(; sctItr!=sctEnd; ++sctItr){
145
146 // ask the association tool if the hit was associated
147 if(prd_to_track_map->isUsed(*(*sctItr))) continue;
148
149 // count number of unassociated SCT hits
150 PRDAssociation->nSCTUA++;
151
152 // find out which detector element the hit belongs to
153 const InDetDD::SiDetectorElement *det = (*sctItr)->detectorElement();
154
155 // count SCT barrel unassociated hits
156 if(det->isBarrel()) PRDAssociation->nSCTBarrelUA++;
157
158 // count SCT endcap unassociated hits: use hit Z position to determin A/C side
159 if(det->isEndcap()){
160 if((*sctItr)->globalPosition().z()<0){
161 PRDAssociation->nSCTEndCapCUA++;
162 }else{
163 PRDAssociation->nSCTEndCapAUA++;
164 }
165 }
166 }
167 }
168 }
169
170 // retrieve TRT drift circles
171 if (!m_TRTDriftCircleContainer.key().empty()) {
173 if(!TRTDriftCircles.isValid()) {
174 ATH_MSG_FATAL("TRT drift circle container '" << m_TRTDriftCircleContainer << "' not found in StoreGate");
175 return nullptr;
176 }
177 // Loop on TRT clusters
178 InDet::TRT_DriftCircleContainer::const_iterator trtCollItr = TRTDriftCircles->begin();
179 InDet::TRT_DriftCircleContainer::const_iterator trtCollEnd = TRTDriftCircles->end();
180 for(; trtCollItr!=trtCollEnd; ++trtCollItr){
181
182 InDet::TRT_DriftCircleCollection::const_iterator trtItr = (*trtCollItr)->begin();
183 InDet::TRT_DriftCircleCollection::const_iterator trtEnd = (*trtCollItr)->end();
184 for(; trtItr!=trtEnd; ++trtItr){
185
186 // ask the association tool if the hit was associated
187 if(prd_to_track_map->isUsed(*(*trtItr))) continue;
188
189 // count number of unassociated TRT hits
190 PRDAssociation->nTRTUA++;
191
192 // find out which detector element the hit belongs to
193 const InDetDD::TRT_BaseElement *det = (*trtItr)->detectorElement();
194
196
197 // count TRT barrel unassociated hits
198 if(type == InDetDD::TRT_BaseElement::BARREL) PRDAssociation->nTRTBarrelUA++;
199
200 // count TRT endcap unassociated hits: use hit Z position to determin A/C side
202 if(det->center().z()<0){
203 PRDAssociation->nTRTEndCapCUA++;
204 }else{
205 PRDAssociation->nTRTEndCapAUA++;
206 }
207 }
208 }
209 }
210 }
211
212 return PRDAssociation.release();
213}
214
216 if(p) delete p;
217}
218
219} // namespace DerivationFramework
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
SG::ReadHandleKey< Trk::PRDtoTrackMap > m_prdToTrackMapKey
virtual const MinBiasPRDAssociation * get(bool allowMissing=false) const
get method: compute the number of unassociated his wrap the info in a MinBiasPRDAssociation object
virtual void releaseObject(const MinBiasPRDAssociation *p) const
delete the pointer created by get
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
UnassociatedHitsGetterTool(const std::string &type, const std::string &name, const IInterface *parent)
SG::ReadHandleKey< TrackCollection > m_trackCollection
SG::ReadHandleKey< InDet::PixelClusterContainer > m_pixelClusterContainer
SG::ReadHandleKey< InDet::SCT_ClusterContainer > m_SCTClusterContainer
SG::ReadHandleKey< InDet::TRT_DriftCircleContainer > m_TRTDriftCircleContainer
Class to hold geometrical description of a silicon detector element.
Virtual base class of TRT readout elements.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
bool isUsed(const PrepRawData &prd) const
does this PRD belong to at least one track?
THE reconstruction tool.