ATLAS Offline Software
Loading...
Searching...
No Matches
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
19InDet::SiDetElementsRoadCondAlg_xk::SiDetElementsRoadCondAlg_xk(const std::string& name, ISvcLocator* pSvcLocator)
20 : ::AthCondAlgorithm(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
38 ATH_CHECK(m_writeKey.initialize());
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
57StatusCode InDet::SiDetElementsRoadCondAlg_xk::execute(const EventContext& ctx) const
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}
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t P(Double_t *tt, Double_t *par)
#define pi
#define z
Base class for conditions algorithms.
Class to hold the SiDetectorElement objects to be put in the detector store.
Class to hold geometrical description of a silicon detector element.
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
SiDetElementsRoadCondAlg_xk(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteCondHandleKey< SiDetElementsLayerVectors_xk > m_writeKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
const std::string & key() const
void addDependency(const EventIDRange &range)
const EventIDRange & getRange() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
int r
Definition globals.cxx:22
void detElementInformation(const InDetDD::SiDetectorElement &Si, double *P)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.