ATLAS Offline Software
Loading...
Searching...
No Matches
AFPSiClusterTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
13
14
16
17
19 const std::string& name,
20 const IInterface* parent)
21 : base_class(type, name, parent)
22{
23}
24
25std::vector< std::vector<AFPSiClusterLayerBasicObj> > AFPSiClusterTool::initLayers (const std::vector<int>& layersInStations) const
26{
27 // set number of stations
28 std::vector< std::vector<AFPSiClusterLayerBasicObj> > my_layers;
29 my_layers.resize(layersInStations.size());
30
31 // initialise number of layers in each station
32 int stationID = 0;
33 std::vector<std::vector<AFPSiClusterLayerBasicObj> >::iterator layersIter = my_layers.begin();
34 for (const int layersN : layersInStations) {
35 int layerID = 0;
36 std::vector<AFPSiClusterLayerBasicObj>& layersVec = (*layersIter++);
37 layersVec.resize(layersN);
38 // set station and layer ID numbers
39 for (AFPSiClusterLayerBasicObj& theLayer : layersVec) {
40 theLayer.setStationID(stationID);
41 theLayer.setLayerID(layerID++);
42 }
43 stationID++;
44 } // close for over layersN
45
46 return my_layers;
47}
48
50{
51 ATH_MSG_DEBUG("Initializing " << name() << "...");
52
54
55 // retrieve tools
56 CHECK( m_clusterAlgToolHandle.retrieve() );
58 CHECK( m_siLocAlignDBTool.retrieve() );
59 CHECK( m_siGlobAlignDBTool.retrieve() );
60
61 // monitoring
62 if (!(m_monTool.name().empty())) {
63 CHECK( m_monTool.retrieve() );
64 ATH_MSG_DEBUG("m_monTool name: " << m_monTool);
65 }
66
67 return StatusCode::SUCCESS;
68}
69
71{
72 return StatusCode::SUCCESS;
73}
74
75StatusCode AFPSiClusterTool::clusterHits(std::unique_ptr<xAOD::AFPSiHitsClusterContainer>& clustr, const EventContext &ctx) const
76{
77 std::vector< std::vector<AFPSiClusterLayerBasicObj> > my_layers=initLayers(m_numberOfLayersInStations);
78
79 if(clearAllLayers(my_layers).isFailure())
80 {
81 ATH_MSG_WARNING("clearAllLayers failed");
82 return StatusCode::FAILURE;
83 }
84
85 if(fillLayersWithHits(my_layers, ctx).isFailure())
86 {
87 ATH_MSG_WARNING("fillLayersWithHits failed");
88 return StatusCode::FAILURE;
89 }
90
91 if(clusterEachLayer(my_layers).isFailure())
92 {
93 ATH_MSG_WARNING("clusterEachLayer failed");
94 return StatusCode::FAILURE;
95 }
96
97 if(saveToXAOD(clustr, my_layers, ctx).isFailure())
98 {
99 ATH_MSG_WARNING("saveToXAOD failed");
100 return StatusCode::FAILURE;
101 }
102
103 auto clusterSize = Monitored::Scalar("ClusterSize", clustr->size());
104 Monitored::Group( m_monTool, clusterSize);
105
106 return StatusCode::SUCCESS;
107}
108
109StatusCode AFPSiClusterTool::clearAllLayers(std::vector< std::vector<AFPSiClusterLayerBasicObj> > &my_layers) const
110{
111 for (std::vector<AFPSiClusterLayerBasicObj>& station : my_layers)
112 for (AFPSiClusterLayerBasicObj& layer : station)
113 layer.clearHitsAndClusters();
114
115 return StatusCode::SUCCESS;
116}
117
118StatusCode AFPSiClusterTool::fillLayersWithHits(std::vector< std::vector<AFPSiClusterLayerBasicObj> > &my_layers, const EventContext &ctx) const
119{
120 // retrieve hits
121 if (m_AFPSiHitContainerKey.empty()) {
122 ATH_MSG_DEBUG("AFPSiClusterTool, no input siHitContainer");
123 // this is allowed, there might be no AFP data in the input
124 return StatusCode::SUCCESS;
125 }
126
128 if(!siHitContainer.isValid()) {
129 ATH_MSG_WARNING("AFPSiClusterTool failed to retrieve siHitContainer, "<<m_AFPSiHitContainerKey<<", exiting gracefully");
130 // unexpected absence of Si hits ?
131 return StatusCode::SUCCESS;
132 }
133 else
134 {
135 ATH_MSG_DEBUG("AFPSiClusterTool::fillLayersWithHits(), successfully got siHitContainer, there are "<<siHitContainer->size()<<" hits");
136
137 auto hitsSize = Monitored::Scalar("HitsSize", siHitContainer->size());
138 Monitored::Group( m_monTool, hitsSize);
139
140 try {
141 // fill layers with hits
142 for(const auto *const theHit : *siHitContainer)
143 my_layers.at(theHit->stationID()).at(theHit->pixelLayerID()).hits().push_back(theHit);
144 }
145 catch (const std::out_of_range& outOfRange) {
146 ATH_MSG_WARNING("Hit with station or pixel ID outside expected range. Aborting pixels clustering.");
147 clearAllLayers(my_layers).ignore();
148 return StatusCode::FAILURE;
149 }
150 }
151
152 return StatusCode::SUCCESS;
153}
154
155StatusCode AFPSiClusterTool::clusterEachLayer(std::vector< std::vector<AFPSiClusterLayerBasicObj> > &my_layers) const
156{
157 for (std::vector<AFPSiClusterLayerBasicObj>& station : my_layers)
158 for (AFPSiClusterLayerBasicObj& layer : station)
159 m_clusterAlgToolHandle->doClustering(layer.hits(), layer.clusters()).ignore();
160
161 return StatusCode::SUCCESS;
162}
163
164StatusCode AFPSiClusterTool::saveToXAOD(std::unique_ptr<xAOD::AFPSiHitsClusterContainer>& clusterContainer, std::vector< std::vector<AFPSiClusterLayerBasicObj> > &my_layers, const EventContext &ctx) const
165{
166
167 if (m_AFPSiHitContainerKey.empty()) {
168 // this is allowed, there might be no AFP data in the input
169 return StatusCode::SUCCESS;
170 }
171
173 if(!siHitContainer.isValid())
174 {
175 // this is allowed, there might be no AFP data in the input
176 return StatusCode::SUCCESS;
177 }
178
179 // fill xAOD container
180
181 nlohmann::json dataLA, dataGA;
182 bool dataLA_init{false}, dataGA_init{false};
183
184 for (std::vector<AFPSiClusterLayerBasicObj>& station : my_layers)
185 for (AFPSiClusterLayerBasicObj& layer : station) {
186 if(layer.clusters().empty()) continue;
187
188 const int stationID = layer.stationID();
189 const int layerID = layer.layerID();
190
191 if(!dataLA_init)
192 {
193 // read from DB only if necessary
194 dataLA=m_siLocAlignDBTool->alignmentData(ctx);
195 dataLA_init=true;
196 }
197 if(!dataGA_init)
198 {
199 // read from DB only if necessary
200 dataGA=m_siGlobAlignDBTool->alignmentData(ctx);
201 dataGA_init=true;
202 }
203
204 const AFP::SiLocAlignData LA=m_siLocAlignDBTool->alignment(dataLA, stationID, layerID);
205 const AFP::SiGlobAlignData GA=m_siGlobAlignDBTool->alignment(dataGA, stationID);
206
207 for (const AFPSiClusterBasicObj& theCluster : layer.clusters()) {
208 // create xAOD object and set cluster coordinates and errors
209 xAOD::AFPSiHitsCluster* xAODCluster = m_rowColToLocalCSToolHandle->newXAODLocal(stationID, layerID, LA, GA, theCluster, clusterContainer);
210
211 ATH_MSG_DEBUG("have xAODCluster: pixelLayerID "<<xAODCluster->pixelLayerID()<<", xLocal "<<xAODCluster->xLocal()<<", yLocal "<<xAODCluster->yLocal()<<", zLocal "<<xAODCluster->zLocal()<<", nHits "<<xAODCluster->nHits());
212
213 // add links to hits
214 for (const xAOD::AFPSiHit* theHit : theCluster.hits()) {
216 hitLink.toContainedElement(*siHitContainer, theHit);
217 xAODCluster->addHitLink(hitLink);
218 }
219 } // end for over layers
220 } // end for over stations
221
222 return StatusCode::SUCCESS;
223}
224
Header file for AFPSiClusterTool used for clustering hits.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Class representing basic silicon pixels cluster, designed to be used for creating the clusters.
Class representing basic silicon layer with pixels and their clusters to be used for creating the clu...
ToolHandle< IAFPSiRowColToLocalCSTool > m_rowColToLocalCSToolHandle
Tool that creates xAOD and transforms rows and pixels to local coordinate system.
StatusCode clusterEachLayer(std::vector< std::vector< AFPSiClusterLayerBasicObj > > &my_layers) const
Runs tool reconstructing clusters on each layer.
AFPSiClusterTool(const std::string &type, const std::string &name, const IInterface *parent)
std::vector< std::vector< AFPSiClusterLayerBasicObj > > initLayers(const std::vector< int > &layersInStations) const
Initialise size as well as station and layer ID for my_layers.
ToolHandle< IAFPSiClusterAlgTool > m_clusterAlgToolHandle
Tool that does the clustering on hits.
ToolHandle< AFP::ISiLocAlignDBTool > m_siLocAlignDBTool
@ brief Tool for accessing DB to get the local alignment constants
StatusCode fillLayersWithHits(std::vector< std::vector< AFPSiClusterLayerBasicObj > > &my_layers, const EventContext &ctx) const
Reads hits from StoreGate and saves them to appropriate layers in my_layers.
StatusCode clusterHits(std::unique_ptr< xAOD::AFPSiHitsClusterContainer > &clustr, const EventContext &ctx) const override
Run clusters reconstruction.
ToolHandle< GenericMonitoringTool > m_monTool
@ brief Monitoring tool
ToolHandle< AFP::ISiGlobAlignDBTool > m_siGlobAlignDBTool
@ brief Tool for accessing DB to get the global alignment constants
virtual StatusCode finalize() override
does nothing
virtual StatusCode initialize() override
Gaudi::Property< std::vector< int > > m_numberOfLayersInStations
Array defining number of stations and layers in each station.
StatusCode saveToXAOD(std::unique_ptr< xAOD::AFPSiHitsClusterContainer > &clustr, std::vector< std::vector< AFPSiClusterLayerBasicObj > > &my_layers, const EventContext &ctx) const
Save clusters in xAOD::AFPSiHitsClusterContainer.
StatusCode clearAllLayers(std::vector< std::vector< AFPSiClusterLayerBasicObj > > &my_layers) const
Runs AFPSiClusterLayerBasicObj::clearHitsAndClusters() on all layers in my_layers.
SG::ReadHandleKey< xAOD::AFPSiHitContainer > m_AFPSiHitContainerKey
Class storing information about alignment.
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
void addHitLink(const AFPHitLink_t &newHit)
Add a link to a pixel in this cluster.
int pixelLayerID() const
Index of the silicon layer with the cluster.
int nHits() const
Number of fired pixels (hits) in cluster.
float zLocal() const
Cluster position along Z axis in station local coordinate system.
float xLocal() const
Cluster position along X axis in station local coordinate system.
float yLocal() const
Cluster position along Y axis in station local coordinate system.
AFPSiHit_v2 AFPSiHit
Definition AFPSiHit.h:12
AFPSiHitsCluster_v1 AFPSiHitsCluster