ATLAS Offline Software
Loading...
Searching...
No Matches
CSC_RegSelCondAlg.cxx
Go to the documentation of this file.
1
13
14
15#include "GaudiKernel/EventIDRange.h"
17
18#include "CLHEP/Units/SystemOfUnits.h"
20
21#include <iostream>
22#include <fstream>
23#include <string>
24#include <cmath>
25
28
32
33
34#include "CSC_RegSelCondAlg.h"
35
36
37CSC_RegSelCondAlg::CSC_RegSelCondAlg(const std::string& name, ISvcLocator* pSvcLocator):
38 MuonRegSelCondAlg( name, pSvcLocator )
39{
40 ATH_MSG_DEBUG( "CSC_RegSelCondAlg::CSC_RegSelCondAlg() " << name );
41}
42
43
44
45
46std::unique_ptr<RegSelSiLUT> CSC_RegSelCondAlg::createTable( const EventContext& ctx, EventIDRange& id_range ) const {
47
49
50 if( !manager.range( id_range ) ) {
51 ATH_MSG_ERROR("Failed to retrieve validity range for " << manager.key());
52 return {nullptr};
53 }
54
55
57
58 ServiceHandle<CSCcablingSvc> cabling("CSCcablingSvc", name());
59 ATH_CHECK( cabling.retrieve(), {} );
60
61 const CscIdHelper* helper = manager->cscIdHelper();
62
63 std::vector<Identifier>::const_iterator idfirst = helper->module_begin();
64 std::vector<Identifier>::const_iterator idlast = helper->module_end();
65
66 const IdContext ModuleContext = helper->module_context();
67
68 ATH_MSG_DEBUG("createTable()");
69
70 std::unique_ptr<RegSelSiLUT> lut = std::make_unique<RegSelSiLUT>();
71
72
73
74 for ( std::vector<Identifier>::const_iterator itr=idfirst ; itr!=idlast ; ++itr ) {
75 Identifier Id = *itr;
76 IdentifierHash Idhash;
77
78 helper->get_hash(Id, Idhash, &ModuleContext);
79
80 ExpandedIdentifier exp_id;
81 if (helper->get_expanded_id( Id, exp_id, &ModuleContext)) {
82 ATH_MSG_DEBUG("Failed retrieving ExpandedIdentifier for PRD Identifier = " << Id.getString() << ". Skipping to the next PRD.");
83 continue;
84 }
85
86 int detid = ( exp_id[2]<0 ? -1 : 1 );
87 int layerid = exp_id[1]+1;
88
89
90 // retrieve CscReadoutElement
91
92 Identifier Id2ndLayer;
93 int chamberLayer = 2;
94 const MuonGM::CscReadoutElement *csc = manager->getCscReadoutElement(Id);
95 if (csc == nullptr) {
96
97 // std::cout << "Csc Readout Element not found for this Id ---- try 2nd layer"<<std::endl;
98 Id2ndLayer = helper->parentID(Id);
99 Id2ndLayer = helper->channelID(Id2ndLayer, chamberLayer, 1, 0, 1);
100 csc = manager->getCscReadoutElement(Id2ndLayer);
101 if (csc == nullptr)
102 {
103 // std::cout << "Csc Readout Element not found for 2nd layer too ---- skip"<<std::endl;
104 continue;
105 }
106 }
107
108 double eta_min = 99999999.;
109 double eta_max = -99999999.;
110 double phi_min = 999999.;
111 double phi_max = -999999.;
112
113 double zmin = 999999999;
114 double zmax = -999999999;
115
116 double rmin = 0;
117 double rmax = 0;
118
119 double phi_test = 0.;
120 Identifier Id_phi_max;
121 Identifier Id_phi_min;
122 Identifier Id_eta_max;
123 Identifier Id_eta_min;
124
125 // only use the extreme chamber layers and wirelayers
126
127 int chlayer_inc = helper->chamberLayerMax(Id)-1;
128 if ( chlayer_inc<1 ) chlayer_inc = 1;
129 for ( int chlayer=1 ; chlayer<=helper->chamberLayerMax(Id) ; chlayer+=chlayer_inc ) {
130
131
132 int wlayer_inc = helper->wireLayerMax(Id)-1;
133 if ( wlayer_inc<1 ) wlayer_inc = 1;
134 for ( int wlayer=1 ; wlayer<=helper->wireLayerMax(Id) ; wlayer+=wlayer_inc ){
135
136 for ( int phis=1 ; phis<=csc->NphiStrips(wlayer) ; phis++ ) {
137
138
139 Identifier phis_id = helper->channelID(Id, chlayer, wlayer, 1, phis);
140 Amg::Vector3D phis_x = csc->localStripPos(phis_id);
141 double phis_lenght = csc->stripLength(phis_id);
142
143 // positions of the strip endpoints
144
145 Amg::Vector3D phis_x1 = phis_x;
146 Amg::Vector3D phis_x2 = phis_x;
147
148 //phis_x1.setZ(phis_x.z()-phis_lenght/2.0);
149 //phis_x2.setZ(phis_x.z()+phis_lenght/2.0);
150 phis_x1[2] = phis_x.z()-phis_lenght/2.0;
151 phis_x2[2] = phis_x.z()+phis_lenght/2.0;
152
153 Amg::Vector3D gphis_x1 = csc->globalPos(phis_x1);
154 Amg::Vector3D gphis_x2 = csc->globalPos(phis_x2);
155
156 phi_test=gphis_x1.phi();
157 // for detector in (-0.25,0.25) phi interval use +-3,14 phi interval
158 // if(!(aux1==51 && aux3==1))if (phi_test < 0) phi_test += 2.*M_PI;
159 if(exp_id[1]!=51 || exp_id[3]!=1)if (phi_test < 0) phi_test += 2.*M_PI;
160
161
162 if ( zmin>gphis_x1.z() ) zmin = gphis_x1.z();
163 if ( zmax<gphis_x1.z() ) zmax = gphis_x1.z();
164
165 if ( rmin==0 || rmin>gphis_x1.perp() ) rmin = gphis_x1.perp();
166 if ( rmax==0 || rmax<gphis_x1.perp() ) rmax = gphis_x1.perp();
167
168 if ( zmin>gphis_x2.z() ) zmin = gphis_x2.z();
169 if ( zmax<gphis_x2.z() ) zmax = gphis_x2.z();
170
171 if ( rmin==0 || rmin>gphis_x2.perp() ) rmin = gphis_x2.perp();
172 if ( rmax==0 || rmax<gphis_x2.perp() ) rmax = gphis_x2.perp();
173
174 // position of the strip centre
175
176
177 Amg::Vector3D gphis_x = csc->globalPos(phis_x);
178
179 if ( rmin==0 || rmin>gphis_x.perp() ) rmin = gphis_x.perp();
180 if ( rmax==0 || rmax<gphis_x.perp() ) rmax = gphis_x.perp();
181
182 // phi
183 if(phi_test > phi_max){
184 Id_phi_max=phis_id;
185 phi_max=phi_test;
186 }
187 if(phi_test < phi_min){
188 Id_phi_min=phis_id;
189 phi_min=phi_test;
190 }
191 // eta
192 if(gphis_x1.eta() > eta_max) {
193 Id_eta_max=phis_id;
194 eta_max=gphis_x1.eta();
195 }
196 if(gphis_x1.eta() < eta_min) {
197 Id_eta_min=phis_id;
198 eta_min=gphis_x1.eta();
199 }
200
201 phi_test=gphis_x2.phi();
202 // for detector in (-0.25,0.25) phi interval use +-3,14 phi interval
203 // if(!(aux1==51 && aux3==1)) if (phi_test < 0) phi_test += 2.*M_PI;
204 if(exp_id[1]!=51 || exp_id[3]!=1) if (phi_test < 0) phi_test += 2.*M_PI;
205
206 // phi
207 if(phi_test > phi_max) {
208 Id_phi_max=phis_id;
209 phi_max=phi_test;
210 }
211 if(phi_test < phi_min) {
212 Id_phi_min=phis_id;
213 phi_min=phi_test;
214 }
215 // eta
216 if(gphis_x2.eta() > eta_max) {
217 Id_eta_max=phis_id;
218 eta_max=gphis_x2.eta();
219 }
220 if(gphis_x2.eta() < eta_min) {
221 Id_eta_min=phis_id;
222 eta_min=gphis_x2.eta();
223 }
224
225 }
226
227 // only use the extreme and middle strips
228
229 int eta_inc = csc->NetaStrips(wlayer)/2;
230 if ( eta_inc<1 ) eta_inc = 1;
231 for ( int etas=1 ; etas<=csc->NetaStrips(wlayer) ; etas+=eta_inc ) {
232
233
234 Identifier etas_id = helper->channelID(Id, chlayer, wlayer, 0, etas);
235 Amg::Vector3D etas_x = csc->localStripPos(etas_id);
236 double etas_lenght = csc->stripLength(etas_id);
237
238 // strip endpoints
239
240 Amg::Vector3D etas_x1 = etas_x;
241 Amg::Vector3D etas_x2 = etas_x;
242
243 //etas_x1.setY(etas_x.y()-etas_lenght/2.0);
244 //etas_x2.setY(etas_x.y()+etas_lenght/2.0);
245 etas_x1[1] = etas_x.y()-etas_lenght/2.0;
246 etas_x2[1] = etas_x.y()+etas_lenght/2.0;
247
248 Amg::Vector3D getas_x1 = csc->globalPos(etas_x1);
249 Amg::Vector3D getas_x2 = csc->globalPos(etas_x2);
250
251 if ( zmin>getas_x1.z() ) zmin = getas_x1.z();
252 if ( zmax<getas_x1.z() ) zmax = getas_x1.z();
253
254 if ( zmin>getas_x2.z() ) zmin = getas_x2.z();
255 if ( zmax<getas_x2.z() ) zmax = getas_x2.z();
256
257 if ( rmin==0 || rmin>getas_x1.perp() ) rmin = getas_x1.perp();
258 if ( rmax==0 || rmax<getas_x1.perp() ) rmax = getas_x1.perp();
259
260 if ( rmin==0 || rmin>getas_x2.perp() ) rmin = getas_x2.perp();
261 if ( rmax==0 || rmax<getas_x2.perp() ) rmax = getas_x2.perp();
262
263 // position of the strip centre
264
265 Amg::Vector3D getas_x = csc->globalPos(etas_x);
266
267 if ( rmin==0 || rmin>getas_x.perp() ) rmin = getas_x.perp();
268 if ( rmax==0 || rmax<getas_x.perp() ) rmax = getas_x.perp();
269
270 phi_test = getas_x1.phi();
271 // for detector in (-0.25,0.25) phi interval use +-3,14 phi interval
272 // if(!(aux1==51 && aux3==1)) if (phi_test < 0) phi_test += 2.*M_PI;
273 if(exp_id[1]!=51 || exp_id[3]!=1) if (phi_test < 0) phi_test += 2.*M_PI;
274 // phi
275 if(phi_test > phi_max){
276 Id_phi_max=etas_id;
277 phi_max=phi_test;
278 }
279 if(phi_test < phi_min){
280 Id_phi_min=etas_id;
281 phi_min=phi_test;
282 }
283 // eta
284 if(getas_x1.eta() > eta_max) {
285 Id_eta_max=etas_id;
286 eta_max=getas_x1.eta();
287 }
288 if(getas_x1.eta() < eta_min) {
289 Id_eta_min=etas_id;
290 eta_min=getas_x1.eta();
291 }
292
293 phi_test = getas_x2.phi();
294 // for detector in (-0.25,0.25) phi interval use +-3,14 phi interval
295 // if (!(aux1==51 && aux3==1)) if (phi_test < 0) phi_test += 2.*M_PI;
296 if (exp_id[1]!=51 || exp_id[3]!=1) if (phi_test < 0) phi_test += 2.*M_PI;
297 // phi
298 if(phi_test > phi_max){
299 Id_phi_max=etas_id;
300 phi_max=phi_test;
301 }
302 if(phi_test < phi_min){
303 Id_phi_min=etas_id;
304 phi_min=phi_test;
305 }
306 // eta
307 if(getas_x2.eta() > eta_max) {
308 Id_eta_max=etas_id;
309 eta_max=getas_x2.eta();
310 }
311 if(getas_x2.eta() < eta_min) {
312 Id_eta_min=etas_id;
313 eta_min=getas_x2.eta();
314 }
315
316 }
317 } //gas gaps
318 } // chamber layers
319
320 // if(aux1==51 && aux3==1)if (phi_min < 0) phi_min += 2.*M_PI;
321 // if(aux1==51 && aux3==1)if (phi_max < 0) phi_max += 2.*M_PI;
322 if(exp_id[1]==51 && exp_id[3]==1) {
323 if (phi_max < 0) phi_max += 2.*M_PI;
324 if (phi_min < 0) phi_min += 2.*M_PI;
325 }
326
327 uint16_t subDetectorId = (detid == -1) ? 0x6a : 0x69;
328 uint32_t cscrob = 0x0;
329 cabling->hash2Rob(Idhash.value(),cscrob);
330 cscrob = ((subDetectorId << 16) | cscrob);
331 RegSelModule m( zmin, zmax, rmin, rmax, phi_min, phi_max, layerid, detid, cscrob, Idhash );
332 lut->addModule( m );
333
334
335 } // modules
336
337
338 lut->initialise();
339
340 return lut;
341
342}
343
344
345
346
347
348
349
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
emacs: this is -*- c++ -*-
CSC_RegSelCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
std::unique_ptr< RegSelSiLUT > createTable(const EventContext &ctx, EventIDRange &id_range) const override
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
This is a "hash" representation of an Identifier.
value_type value() const
std::string getString() const
Provide a string form of the identifier - hexadecimal.
Amg::Vector3D localStripPos(const Identifier &id) const
takes into account internal alignment parameters, hence gives generally accurate answer (local here i...
double stripLength(int chamberLayer, int measuresPhi, int stripNumber, double &epsilon) const
Amg::Vector3D globalPos(const Amg::Vector3D &localP) const
station-level method: does not depend on the strip view/layer, hence it cannot account for internal a...
int NphiStrips(int gasgaplayer) const
int NetaStrips(int gasgaplayer) const
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_detMgrKey
MuonDetectorManager from the conditions store.
MuonRegSelCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Eigen::Matrix< double, 3, 1 > Vector3D