ATLAS Offline Software
SiDetElementsRoadCondAlg_xk.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 
11 
12 #include <memory>
13 #include <utility>
14 
16 // Constructor
18 
19 InDet::SiDetElementsRoadCondAlg_xk::SiDetElementsRoadCondAlg_xk(const std::string& name, ISvcLocator* pSvcLocator)
20  : ::AthReentrantAlgorithm(name, pSvcLocator)
21 {
22 }
23 
25 // Initialisation
27 
29 {
30  if ((not m_usePIX) and (not m_useSCT)) {
31  ATH_MSG_FATAL("Please don't call this tool if usePixel and useSCT are false");
32  return StatusCode::FAILURE;
33  }
34 
37 
39 
40  return StatusCode::SUCCESS;
41 }
42 
44 // Finalize
46 
48 {
49  return StatusCode::SUCCESS;
50 }
51 
53 // Map of detector elements production
54 // Taken from InDet::SiDetElementsRoadMaker_xk::mapDetectorElementsProduction()
56 
58 {
59  const double pi2=2.*M_PI;
60  const double pi=M_PI;
61 
63  if (writeHandle.isValid()) {
64  ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
65  << ". In theory this should not be called, but may happen"
66  << " if multiple concurrent events are being processed out of order.");
67  return StatusCode::SUCCESS;
68  }
69 
70  std::unique_ptr<SiDetElementsLayerVectors_xk> writeCdo{std::make_unique<SiDetElementsLayerVectors_xk>(3)};
71 
72  std::vector<const InDetDD::SiDetectorElement*> pW[3];
73 
74  if (m_usePIX) {
75  // Loop over each wafer of pixels
77  const InDetDD::SiDetectorElementCollection* pixelDetEle{*pixelDetEleHandle};
78  if (not pixelDetEleHandle.isValid() or pixelDetEle==nullptr) {
79  ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
80  return StatusCode::FAILURE;
81  }
82  for (const InDetDD::SiDetectorElement* s: *pixelDetEle) {
83  if (s->isBarrel() ) pW[1].push_back(s); // Barrel
84  else if (s->center().z() > 0.) pW[2].push_back(s); // Right endcap
85  else pW[0].push_back(s); // Left endcap
86  }
87 
88  writeHandle.addDependency(pixelDetEleHandle);
89  }
90 
91  if (m_useSCT) {
92  // Loop over each wafer of sct
94  const InDetDD::SiDetectorElementCollection* sctDetEle{*sctDetEleHandle};
95  if (not sctDetEleHandle.isValid() or sctDetEle==nullptr) {
96  ATH_MSG_FATAL(m_SCTDetEleCollKey.fullKey() << " is not available.");
97  return StatusCode::FAILURE;
98  }
99  for (const InDetDD::SiDetectorElement* s: *sctDetEle) {
100  if (s->isBarrel() ) pW[1].push_back(s); // Barrel
101  else if (s->center().z() > 0.) pW[2].push_back(s); // Right endcap
102  else pW[0].push_back(s); // Left endcap
103  }
104 
105  writeHandle.addDependency(sctDetEleHandle);
106  }
107 
108  int nel = pW[0].size()+pW[1].size()+pW[2].size();
109  if (nel==0) {
110  ATH_MSG_WARNING("The number of elements is zero.");
111  return StatusCode::SUCCESS;
112  }
113 
114  std::sort(pW[1].begin(), pW[1].end(), InDet::compDetElements_RAZ());
115  std::sort(pW[0].begin(), pW[0].end(), InDet::compDetElements_ZRA());
116  std::sort(pW[2].begin(), pW[2].end(), InDet::compDetElements_ZRA());
117 
118  for(int N=0; N<3; ++N) {
119 
120  double P[40];
121  int im = static_cast<int>(pW[N].size())-1;
122  int If = 0 ;
123  double z0 = 0. ;
124  double r0 = 0. ;
125 
126  for (int i = 0; i<= im; ++i) {
127 
129 
130  double r = P[0];
131  double z = P[1];
132  bool newl = false;
133  if (N==1) {
134  if (fabs(r-r0) > 10.) {
135  newl=true;
136  r0=r;
137  }
138  } else {
139  if (fabs(z-z0) > 10.) {
140  newl=true;
141  r0=r;
142  z0=z;
143  }
144  }
145 
146  if (newl || i==im) {
147 
148  int Il = i-1;
149  if (i==im) ++Il;
150 
151  if (If<=Il) {
152 
153  double rmin = 100000., rmax =-100000.;
154  double zmin = 100000., zmax =-100000.;
155  double dfm = 0.;
156 
157  std::vector<const InDetDD::SiDetectorElement*> pE;
158  for (int j=If; j<=Il; ++j) pE.push_back(pW[N][j]);
159  std::sort(pE.begin(), pE.end(), InDet::compDetElements_A());
160 
162 
163  for (auto & j : pE) {
164 
165  if (j) {
166 
168 
169  if ( P[ 9] < rmin ) rmin = P[ 9];
170  if ( P[10] > rmax ) rmax = P[10];
171  if ( P[11] < zmin ) zmin = P[11];
172  if ( P[12] > zmax ) zmax = P[12];
173 
174  double df1 = fabs(P[13]-P[2]);
175  if (df1>pi) df1 = fabs(df1-pi2);
176  double df2 = fabs(P[14]-P[2]);
177  if (df2>pi) df2 = fabs(df2-pi2);
178  if (df1>dfm) dfm = df1;
179  if (df2>dfm) dfm = df2;
180 
182  layer.add(link);
183  }
184  }
185  layer.sortDetectorElements();
186  double r =(rmax+rmin)*.5;
187  double dr =(rmax-rmin)*.5;
188  double z =(zmax+zmin)*.5;
189  double dz =(zmax-zmin)*.5;
190  layer.set(r, dr, z, dz, dfm);
191  (writeCdo->at(N)).push_back(layer);
192  }
193  If = i;
194  }
195  }
196  }
197 
198  if (writeHandle.record(std::move(writeCdo)).isFailure()) {
199  ATH_MSG_FATAL("Could not record " << writeHandle.key()
200  << " with EventRange " << writeHandle.getRange()
201  << " into Conditions Store");
202  return StatusCode::FAILURE;
203  }
204  ATH_MSG_DEBUG("recorded new CDO " << writeHandle.key() << " with range " << writeHandle.getRange() << " into Conditions Store");
205 
206  return StatusCode::SUCCESS;
207 }
beamspotman.r
def r
Definition: beamspotman.py:676
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
InDet::SiDetElementsRoadCondAlg_xk::m_usePIX
BooleanProperty m_usePIX
Definition: SiDetElementsRoadCondAlg_xk.h:67
SiDetElementsRoadUtils_xk.h
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
PixelAthClusterMonAlgCfg.zmin
zmin
Definition: PixelAthClusterMonAlgCfg.py:169
DMTest::P
P_v1 P
Definition: P.h:23
InDet::SiDetElementsRoadCondAlg_xk::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: SiDetElementsRoadCondAlg_xk.cxx:57
SiDetElementsLayer_xk.h
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
python.PhysicalConstants.pi2
float pi2
Definition: PhysicalConstants.py:52
M_PI
#define M_PI
Definition: ActiveFraction.h:11
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
python.atlas_oh.im
im
Definition: atlas_oh.py:167
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
InDet::SiDetElementsLayer_xk
Definition: SiDetElementsLayer_xk.h:28
pi
#define pi
Definition: TileMuonFitter.cxx:65
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
InDet::SiDetElementsRoadCondAlg_xk::initialize
virtual StatusCode initialize() override
Definition: SiDetElementsRoadCondAlg_xk.cxx:28
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
InDet::compDetElements_ZRA
Definition: SiDetElementsComparison.h:62
lumiFormat.i
int i
Definition: lumiFormat.py:85
z
#define z
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
InDet::SiDetElementsRoadCondAlg_xk::SiDetElementsRoadCondAlg_xk
SiDetElementsRoadCondAlg_xk(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SiDetElementsRoadCondAlg_xk.cxx:19
PixelAthClusterMonAlgCfg.zmax
zmax
Definition: PixelAthClusterMonAlgCfg.py:169
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
InDet::SiDetElementsRoadCondAlg_xk::m_writeKey
SG::WriteCondHandleKey< SiDetElementsLayerVectors_xk > m_writeKey
Definition: SiDetElementsRoadCondAlg_xk.h:79
TRT::Track::z0
@ z0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:63
InDet::SiDetElementsRoadUtils_xk::detElementInformation
void detElementInformation(const InDetDD::SiDetectorElement &Si, double *P)
Definition: SiDetElementsRoadUtils_xk.cxx:42
SiDetElementsComparison.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
InDet::SiDetElementsRoadCondAlg_xk::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Definition: SiDetElementsRoadCondAlg_xk.h:77
SiDetElementsRoadCondAlg_xk.h
InDet::SiDetElementsRoadCondAlg_xk::m_useSCT
BooleanProperty m_useSCT
Definition: SiDetElementsRoadCondAlg_xk.h:68
InDet::SiDetElementsRoadCondAlg_xk::m_SCTDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
Definition: SiDetElementsRoadCondAlg_xk.h:78
InDet::SiDetElementsRoadCondAlg_xk::m_ITkGeometry
BooleanProperty m_ITkGeometry
Definition: SiDetElementsRoadCondAlg_xk.h:69
InDet::compDetElements_A
Definition: SiDetElementsComparison.h:16
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
InDet::SiDetElementsRoadCondAlg_xk::finalize
virtual StatusCode finalize() override
Definition: SiDetElementsRoadCondAlg_xk.cxx:47
InDet::compDetElements_RAZ
Definition: SiDetElementsComparison.h:37
SG::WriteCondHandle
Definition: WriteCondHandle.h:26