ATLAS Offline Software
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 
16 
17 
19  const std::string& name,
20  const IInterface* parent)
21  : base_class(type, name, parent)
22 {
23 }
24 
25 std::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() );
57  CHECK( m_rowColToLocalCSToolHandle.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 
75 StatusCode 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 
109 StatusCode 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 
118 StatusCode 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 
155 StatusCode 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 
164 StatusCode 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 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AFPSiClusterLayerBasicObj
Class representing basic silicon layer with pixels and their clusters to be used for creating the clu...
Definition: AFPSiClusterLayerBasicObj.h:30
AFPSiClusterTool::clearAllLayers
StatusCode clearAllLayers(std::vector< std::vector< AFPSiClusterLayerBasicObj > > &my_layers) const
Runs AFPSiClusterLayerBasicObj::clearHitsAndClusters() on all layers in #my_layers.
Definition: AFPSiClusterTool.cxx:109
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
json
nlohmann::json json
Definition: HistogramDef.cxx:9
xAOD::AFPSiHitsCluster_v1::pixelLayerID
int pixelLayerID() const
Index of the silicon layer with the cluster.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AFPSiClusterTool.h
Header file for AFPSiClusterTool used for clustering hits.
AFPSiClusterTool::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
@ brief Monitoring tool
Definition: AFPSiClusterTool.h:80
xAOD::AFPSiHit_v2
Class representing a hit in silicon detector.
Definition: AFPSiHit_v2.h:30
AFPSiClusterTool::initialize
virtual StatusCode initialize() override
Definition: AFPSiClusterTool.cxx:49
AFPSiClusterTool::AFPSiClusterTool
AFPSiClusterTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: AFPSiClusterTool.cxx:18
AFPSiClusterTool::clusterHits
StatusCode clusterHits(std::unique_ptr< xAOD::AFPSiHitsClusterContainer > &clustr, const EventContext &ctx) const override
Run clusters reconstruction.
Definition: AFPSiClusterTool.cxx:75
AFPSiClusterTool::fillLayersWithHits
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.
Definition: AFPSiClusterTool.cxx:118
AFPSiClusterBasicObj
Class representing basic silicon pixels cluster, designed to be used for creating the clusters.
Definition: AFPSiClusterBasicObj.h:28
AFPSiClusterTool::m_numberOfLayersInStations
Gaudi::Property< std::vector< int > > m_numberOfLayersInStations
Array defining number of stations and layers in each station.
Definition: AFPSiClusterTool.h:93
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
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
AFPSiClusterTool::saveToXAOD
StatusCode saveToXAOD(std::unique_ptr< xAOD::AFPSiHitsClusterContainer > &clustr, std::vector< std::vector< AFPSiClusterLayerBasicObj > > &my_layers, const EventContext &ctx) const
Save clusters in xAOD::AFPSiHitsClusterContainer.
Definition: AFPSiClusterTool.cxx:164
AFPSiClusterTool::m_siLocAlignDBTool
ToolHandle< AFP::ISiLocAlignDBTool > m_siLocAlignDBTool
@ brief Tool for accessing DB to get the local alignment constants
Definition: AFPSiClusterTool.h:84
AFPSiClusterTool::initLayers
std::vector< std::vector< AFPSiClusterLayerBasicObj > > initLayers(const std::vector< int > &layersInStations) const
Initialise size as well as station and layer ID for #my_layers.
Definition: AFPSiClusterTool.cxx:25
AFPSiClusterTool::m_AFPSiHitContainerKey
SG::ReadHandleKey< xAOD::AFPSiHitContainer > m_AFPSiHitContainerKey
Definition: AFPSiClusterTool.h:71
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Muon::nsw::STGTPSegments::moduleIDBits::stationID
constexpr uint8_t stationID
Large or Small wedge.
Definition: NSWSTGTPDecodeBitmaps.h:152
xAOD::AFPSiHitsCluster_v1::xLocal
float xLocal() const
Cluster position along X axis in station local coordinate system.
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AFPSiClusterTool::clusterEachLayer
StatusCode clusterEachLayer(std::vector< std::vector< AFPSiClusterLayerBasicObj > > &my_layers) const
Runs tool reconstructing clusters on each layer.
Definition: AFPSiClusterTool.cxx:155
AFP::SiGlobAlignData
Definition: SiGlobAlignData.h:23
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AFPSiClusterTool::finalize
virtual StatusCode finalize() override
does nothing
Definition: AFPSiClusterTool.cxx:70
AFPSiClusterTool::m_clusterAlgToolHandle
ToolHandle< IAFPSiClusterAlgTool > m_clusterAlgToolHandle
Tool that does the clustering on hits.
Definition: AFPSiClusterTool.h:74
xAOD::AFPSiHitsCluster_v1::addHitLink
void addHitLink(const AFPHitLink_t &newHit)
Add a link to a pixel in this cluster.
Definition: AFPSiHitsCluster_v1.cxx:40
AFPSiClusterTool::m_rowColToLocalCSToolHandle
ToolHandle< IAFPSiRowColToLocalCSTool > m_rowColToLocalCSToolHandle
Tool that creates xAOD and transforms rows and pixels to local coordinate system.
Definition: AFPSiClusterTool.h:77
AFP::SiLocAlignData
Class storing information about alignment.
Definition: SiLocAlignData.h:24
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::AFPSiHitsCluster_v1::nHits
int nHits() const
Number of fired pixels (hits) in cluster.
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
xAOD::AFPSiHitsCluster_v1
Class representing a cluster of AFP pixel hits.
Definition: AFPSiHitsCluster_v1.h:32
xAOD::AFPSiHitsCluster_v1::yLocal
float yLocal() const
Cluster position along Y axis in station local coordinate system.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
AFPSiClusterTool::m_siGlobAlignDBTool
ToolHandle< AFP::ISiGlobAlignDBTool > m_siGlobAlignDBTool
@ brief Tool for accessing DB to get the global alignment constants
Definition: AFPSiClusterTool.h:87
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::AFPSiHitsCluster_v1::zLocal
float zLocal() const
Cluster position along Z axis in station local coordinate system.