ATLAS Offline Software
AFPSiClusterAllNeighbours.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
17 #include "xAODForward/AFPSiHit.h"
18 
19 // STL includes
20 #include <list>
21 
22 // FrameWork includes
23 #include "GaudiKernel/IToolSvc.h"
24 
26  const std::string &name,
27  const IInterface *parent)
28  : base_class(type, name, parent) {
29 }
30 
32 {
34  else if(m_neighbourhoodType=="xy" || m_neighbourhoodType=="XY") m_doOnlyHorz=false;
35  else
36  {
37  ATH_MSG_ERROR("neighbourhoodType is "<<m_neighbourhoodType<<" but allowed values are only \"X\" (only long-edge) or \"XY\" (both long- and short-edge); will abort");
38  return StatusCode::FAILURE;
39  }
40 
41  return StatusCode::SUCCESS;
42 }
43 
45  return StatusCode::SUCCESS;
46 }
47 
48 StatusCode AFPSiClusterAllNeighbours::doClustering (const std::list<const xAOD::AFPSiHit*>& hits, std::list<AFPSiClusterBasicObj>& outputClusters) const
49 {
50  std::list<const xAOD::AFPSiHit*> hitsAboveThreshold;
51 
52  // select only hits above charge threshold
53  for (const xAOD::AFPSiHit* theHit : hits)
54  if (theHit->depositedCharge() > m_chargeThreshold)
55  hitsAboveThreshold.push_back(theHit);
56 
57  while (!hitsAboveThreshold.empty())
58  {
59  // add the first hit to a new proto-cluster
60  std::list<const xAOD::AFPSiHit*> currentProtoCluster{hitsAboveThreshold.front()};
61  // and remove the hit from the list
62  hitsAboveThreshold.pop_front();
63 
64  // for each hit in the growing list of hits in the current proto-cluster
65  for(const xAOD::AFPSiHit* currHit : currentProtoCluster)
66  {
67  // loop over remaining hits
68  for(std::list<const xAOD::AFPSiHit*>::iterator remHit=hitsAboveThreshold.begin();remHit!=hitsAboveThreshold.end();)
69  {
70  if(abs(currHit->pixelVertID()-(*remHit)->pixelVertID())<=1 && abs(currHit->pixelHorizID()-(*remHit)->pixelHorizID())<=1)
71  {
72  if(m_doOnlyHorz && currHit->pixelVertID()!=(*remHit)->pixelVertID())
73  {
74  ++remHit;
75  }
76  else
77  {
78  // these hits are neighbours
79  currentProtoCluster.push_back(*remHit);
80  hitsAboveThreshold.erase(remHit++); // move iterator first, then erase the element
81  }
82  }
83  else
84  {
85  ++remHit;
86  }
87  }
88  // end loop over remaining hits, all neighbours of the current hit are added to currentProtoCluster
89  // let's continue with the next hit in currentProtoCluster, possible the one that has been just added
90  }
91  // reach end of currentProtoCluster, no more hits to be added
92 
93  // calculate positions on plane and save the cluster
94  outputClusters.emplace_back(0,0,0,xAOD::AFPClusterAlgID::allNeighbours);
95  AFPSiClusterBasicObj& newCluster = outputClusters.back();
96  double horizID = 0.;
97  double vertID = 0.;
98  double charge = 0.;
99  for (const xAOD::AFPSiHit* currHit : currentProtoCluster)
100  {
101  charge += currHit->depositedCharge();
102  horizID += currHit->pixelHorizID() * currHit->depositedCharge();
103  vertID += currHit->pixelVertID() * currHit->depositedCharge();
104 
105  newCluster.hits().push_back(currHit);
106  }
107 
108  newCluster.setHorizID(horizID/charge);
109  newCluster.setVertID(vertID/charge);
110  newCluster.setCharge(charge);
111  }
112 
113 
114  return StatusCode::SUCCESS;
115 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
AFPSiClusterAllNeighbours::doClustering
virtual StatusCode doClustering(const std::list< const xAOD::AFPSiHit * > &hits, std::list< AFPSiClusterBasicObj > &outputClusters) const override
Creates a cluster from the neighbouring pixels, joining only two pixels with charge above m_chargeThr...
Definition: AFPSiClusterAllNeighbours.cxx:48
AFPSiClusterBasicObj::setCharge
void setCharge(const double charge)
Definition: AFPSiClusterBasicObj.h:64
xAOD::AFPSiHit_v2
Class representing a hit in silicon detector.
Definition: AFPSiHit_v2.h:30
AFPSiClusterAllNeighbours::initialize
virtual StatusCode initialize() override
does nothing
Definition: AFPSiClusterAllNeighbours.cxx:31
AFPSiClusterAllNeighbours::finalize
virtual StatusCode finalize() override
does nothing
Definition: AFPSiClusterAllNeighbours.cxx:44
AFPSiClusterBasicObj.h
Full definition of AFPSiClusterBasicObj.
AFPSiClusterAllNeighbours::m_chargeThreshold
Gaudi::Property< float > m_chargeThreshold
Definition: AFPSiClusterAllNeighbours.h:54
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AFPSiClusterBasicObj
Class representing basic silicon pixels cluster, designed to be used for creating the clusters.
Definition: AFPSiClusterBasicObj.h:28
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AFPSiClusterAllNeighbours::m_doOnlyHorz
bool m_doOnlyHorz
Definition: AFPSiClusterAllNeighbours.h:58
test_pyathena.parent
parent
Definition: test_pyathena.py:15
AFPSiClusterAllNeighbours::AFPSiClusterAllNeighbours
AFPSiClusterAllNeighbours(const std::string &type, const std::string &name, const IInterface *parent)
Definition: AFPSiClusterAllNeighbours.cxx:25
AFPSiHit.h
AFPClusterAlgID.h
Definitions of identification numbers of pixel clustering algorithms.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
charge
double charge(const T &p)
Definition: AtlasPID.h:501
AFPSiClusterAllNeighbours.h
Header file for AFPSiClusterAllNeighbours used for clustering hits.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::AFPClusterAlgID::allNeighbours
static const int allNeighbours
All neighbours algorithm.
Definition: AFPClusterAlgID.h:50
AFPSiClusterBasicObj::setVertID
void setVertID(const float vertID)
Definition: AFPSiClusterBasicObj.h:54
AFPSiClusterBasicObj::setHorizID
void setHorizID(const float horizID)
Definition: AFPSiClusterBasicObj.h:44
AFPSiClusterBasicObj::hits
std::list< const xAOD::AFPSiHit * > & hits()
list of pixels used to form the cluster
Definition: AFPSiClusterBasicObj.h:72
AFPSiClusterAllNeighbours::m_neighbourhoodType
Gaudi::Property< std::string > m_neighbourhoodType
Definition: AFPSiClusterAllNeighbours.h:56