ATLAS Offline Software
Loading...
Searching...
No Matches
TBCaloCoordinate.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ***************************************************************************
6// Liquid Argon detector description package
7// -----------------------------------------
8//
9//****************************************************************************
10
12
13#include "GaudiKernel/Bootstrap.h"
14#include "Gaudi/Property.h"
15#include "GaudiKernel/IService.h"
16#include "GaudiKernel/IToolSvc.h"
17#include "GaudiKernel/ISvcLocator.h"
18#include "GaudiKernel/IMessageSvc.h"
19#include <vector>
20
23
27
28//#include "CLHEP/Geometry/Transform3D.h"
30#include "GaudiKernel/ThreadLocalContext.h"
31#include <iostream>
32#include <iomanip>
33
34
35using Amg::Vector3D;
37using Amg::Rotation3D;
40
41
43 const std::string& name,
44 const IInterface* parent) :
45 base_class(type, name, parent),
48 m_table_eta(0.),
55{
56
57 // by default, assume Atlas : m_DBRead=-1, m_PoolRead=-1
58 // other clients need to include the jobOpt fragment and set
59 // what they want via the properties :
60
61 declareProperty("DBRead",m_DBRead);
62 declareProperty("PoolRead",m_PoolRead);
63
64 declareProperty("calo_phi_shift",m_calo_phi_shift);
65 declareProperty("calo_theta_shift",m_calo_theta_shift);
66 declareProperty("calo_psi_shift",m_calo_psi_shift);
67 declareProperty("calo_x_shift",m_calo_x_shift);
68 declareProperty("calo_y_shift",m_calo_y_shift);
69 declareProperty("calo_z_shift",m_calo_z_shift);
70
71 declareProperty("table_eta",m_table_eta);
72
73 // default values for MC, will be overwritten by Pool numbers
74 m_table_axis_MC = 6062.;
75 m_table_proj_MC = 1276. - 6062.;
76
77 // number taken from the note ATC-TT-IN-0001, Feb 12, 2005:
78 m_table_axis_data = 6208.;
79
80 // number extracted from the Tiles table rotation program, S. Solodkov, Nov 2004
81 m_table_proj_data = -3910. ;
82
83 // this will be calculated
86
89 //m_table_rotate = new Rotate3D();
90 m_table_rotate = new RotationMatrix3D(); // uninitialized, but always assigned before use
91 m_table_shift = new Translation3D(0.,0.,0.);
92 m_postool=0;
93 m_MCmgr=0;
95}
96
97StatusCode
99{
100 float eta = -1.*std::log(tan( (float)
101 ((m_calo_theta_shift+m_range->twopi()/4.)/2.)));
102
104 ( " Numbers used for Calo geometry : "
105 << "phi=" << m_calo_phi_shift << " theta="
106 << m_calo_theta_shift << " (=> deta=" << eta << ") psi="
107 << m_calo_psi_shift << " x,y,z= "
108 << m_calo_x_shift << " "
109 << m_calo_y_shift << " "
110 << m_calo_z_shift );
111
112 // For global Calo position build HepTransforms according to
113 // jobOpt parameters :
114
119
120 StatusCode sc = StatusCode::SUCCESS;
121 return sc;
122}
123
132
133StatusCode
135{
136 StatusCode sc = StatusCode::SUCCESS;
137 return sc;
138}
139
140void
142 Vector3D& pt_local)
143{
145 pt_local = (*m_transform_ctb_to_calo)*pt_ctb;
146}
147
148void
150 Vector3D& pt_ctb)
151{
153 pt_ctb = (*m_transform_calo_to_ctb)*pt_local;
154}
155
156void
157TBCaloCoordinate::ctb_to_local( double& x_ctb, double& y_ctb, double& z_ctb,
158 double& x_local, double& y_local, double& z_local)
159{
160 Vector3D pt_ctb(x_ctb,y_ctb,z_ctb);
161 Vector3D pt_local(0.,0.,0.);
162
163 ctb_to_local(pt_ctb,pt_local);
164
165 x_local = pt_local.x();
166 y_local = pt_local.y();
167 z_local = pt_local.z();
168
169 //log << MSG::DEBUG << "ctb : " << x_ctb << " " << y_ctb << " "
170 // << z_ctb << " " << endmsg;
171 //log << MSG::DEBUG << " ==> local : " << x_local << " " << y_local << " "
172 // << z_local << " " << endmsg;
173}
174
175void
176TBCaloCoordinate::local_to_ctb(double& x_local,double& y_local,double& z_local,
177 double& x_ctb, double& y_ctb, double& z_ctb)
178{
179 Vector3D pt_local(x_local,y_local,z_local);
180 Vector3D pt_ctb(0.,0.,0.);
181
182 local_to_ctb(pt_local,pt_ctb);
183
184 x_ctb = pt_ctb.x();
185 y_ctb = pt_ctb.y();
186 z_ctb = pt_ctb.z();
187
188 //log << MSG::DEBUG << " local : " << x_local << " " << y_local << " "
189 // << z_local << " " << endmsg;
190 //log << MSG::DEBUG << " ==> ctb : " << x_ctb << " " << y_ctb << " "
191 // << z_ctb << " " << endmsg;
192}
193
194double
200
201double
207
208// This is where the work is done :
209
210void
212{
213 if ( m_firstevt == 0 ) {
214 const EventContext& ctx = Gaudi::Hive::currentContext();
215 m_runNumber = ctx.eventID().run_number();
216 m_firstevt = 1;
217 }
218
219 if ( m_DBRead >= 0 ) {
220 bool result = read_data_position();
222 }
223 else if ( m_PoolRead >= 0 ) {
224 bool result = read_MC_position();
226 }
227 else
229
230}
231void
233{
234 if ( m_firstevt == 0 ) m_firstevt = 1;
235
236 if ( m_DBRead >= 0 || m_PoolRead >= 0) {
238 }
239 else
241}
242
248
254
255void
257{
258 RotationMatrix3D junkrot = htrans.rotation();
259 double alpha = Eigen::AngleAxisd(junkrot).angle();
260 Eigen::Vector3d junkaxis = Eigen::AngleAxisd(junkrot).axis();
261
262 ATH_MSG_INFO ("");
263
264 ATH_MSG_INFO ( " -> Rotation : axis x,y,z = " << junkaxis[Amg::x]
265 << " " << junkaxis[Amg::y] << " " << junkaxis[Amg::z]);
266 ATH_MSG_INFO ( " angle = " << alpha );
267
268 Amg::Vector3D junktransl = htrans.translation();
269
270 ATH_MSG_INFO ( " -> Translation : x,y,z = " <<
271 junktransl[Amg::x] << " " << junktransl[Amg::y] << " " << junktransl[Amg::z] );
272
273 ATH_MSG_INFO ("");
274
275}
276
277bool
279{
280 // -------- Access to DB tool : will try once, if fails will use the default (user)
281
282 if ( m_DBRead == 0 ) {
283
284 // Horrible hack : DCS update were missing for the end of the data-taking
285 if ( m_runNumber >= 2102455 ) {
286 m_DBRead = -1;
287 return false;
288 }
289 // Horrible hack : DCS indicated infinite eta value for some runs
290 if ( m_runNumber > 2102164 && m_runNumber <= 2102208 ) {
291 m_DBRead = -1;
292 return false;
293 }
294
295 if (!toolSvc()) {
296 ATH_MSG_ERROR ( "Cannot find ToolSvc ??? " );
297 m_DBRead = -1;
298 return false;
299 }
300 else {
301 StatusCode sc = toolSvc()->retrieveTool("TBCaloPosTool", m_postool);
302 if(sc.isFailure()) {
304 ( "Cannot get Calo table position from DB : keep default" );
305 m_DBRead = -1;
306 return false;
307 }
308 else {
309 ATH_MSG_DEBUG ( "Did get Calo table position from DB !" );
310 m_DBRead = 1;
311 }
312 }
313 }
314
315 if ( m_DBRead > 0 ) {
316 m_table_eta = m_postool->eta();
317 m_table_theta = m_postool->theta();
318 m_table_z = m_postool->z();
319 m_table_delta = m_postool->delta();
320
321 // Protection : if result is crasy, switch to handcoded default
323 ATH_MSG_INFO ( " ==> Calorimeter table position read from DB makes no sense, DB updates will be overwitten " );
324 ATH_MSG_INFO ( " " );
325 m_DBRead = 1;
326 return false;
327 }
328
329 if (m_firstevt == 1 ) {
330 ATH_MSG_INFO ( " --------------------------------------------------------------------- " );
331 ATH_MSG_INFO ( " " );
332 ATH_MSG_INFO ( " Calorimeter table position is read from DB : for run " << m_runNumber
333 << " eta is = " << m_table_eta );
334 ATH_MSG_INFO ( " " );
335
336
337 ATH_MSG_INFO ( " If it does not match the LAr logbook, inform LAr people " );
338 ATH_MSG_INFO ( " " );
339 ATH_MSG_INFO ( " " );
340 ATH_MSG_INFO ( " Other (unused) table numbers are : theta=" << m_table_theta
341 << " z=" << m_table_z << " delta=" << m_table_delta );
342 ATH_MSG_INFO ( " --------------------------------------------------------------------- " );
343
344 m_firstevt = 2;
345 }
346 }
347
348 // ------- OK, it worked : now do the work
349
350 // in Atlas, theta is the angle with the z axis, and it is
351 // given by the formula atan(exp(-m_table_eta))*2.
352 // but here, we want the angle against the y axis :
353 m_table_calc_theta= m_range->twopi()/4. - atan(exp(-m_table_eta))*2.;
355
357 //*m_table_shift = TranslateX3D(m_table_calc_x);
359
361
362 //print_transform( *m_transform_calo_to_ctb );
363
365
366 ATH_MSG_DEBUG ( "Calculated table position is : " );
367 ATH_MSG_DEBUG ( " angle against y axis = "
369 ATH_MSG_DEBUG ( " x shift = " << m_table_calc_x );
370
371 ATH_MSG_DEBUG ( " Final corresponding Moovement : " );
372 //print_transform( *m_transform_calo_to_ctb );
373
374 return true;
375}
376
377bool
379{
380 if (!m_MCmgr) {
381 ATH_MSG_INFO ( "Retreiving TBDetDescrManager" );
382
383 // get the manager used for simulation :
384
385 ATH_CHECK( detStore()->retrieve( m_MCmgr ), false );
386 }
387
388 ATH_MSG_DEBUG ( " found TBDetDescrManager " );
389
390 TBElement LArTileMother = m_MCmgr->getElement(TBElementID::CALO);
391 if (LArTileMother.id() == TBElementID::Unknown ) return false;
392
393 ATH_MSG_DEBUG ( " found CALO envelope " );
394
395 // ------- OK, now do the work :
396
397 Vector3D pos = LArTileMother.position();
398 *m_table_shift = Translation3D(pos.x(),pos.y(),pos.z());
399
400 // FIXME : rotation has the wrong sign !
401 *m_table_rotate = (LArTileMother.rotation()).inverse();
402
403 *m_transform_calo_to_ctb = (*m_table_shift)*(*m_table_rotate);
404
405 // Extract m_table_eta
406 // Not completely satisfactory : it's wrong if the calorimeter is rotated
407 // around z and/or x in addition to y (it's not supposed
408 // to be the case in MC but still ...)
409 //float angle = m_transform_calo_to_ctb->getRotation().delta();
410 float angle = Eigen::AngleAxisd(m_transform_calo_to_ctb->rotation()).angle();
411 m_table_eta = -1.*std::log(tan((float) (m_range->twopi()/4. - angle)/2.));
412
414 ATH_MSG_INFO ( " m_table_eta is not in [0,1.5] -> will set it to 0. " );
415 m_table_eta = 0.;
416 }
417
418 //log << MSG::DEBUG << " Enveloppe position is read from Pool, and is : "
419 // << endmsg;
420 //print_transform( *m_transform_calo_to_ctb );
421
423
424 return true;
425}
426
427void
429{
430 // This is a fall back solution if numbers are not found anywhere else
431 // Note that the hypothesis is that it is DATA
432
433 // do the work once :
434 //if (m_firstevt > 1 ) return;
435
436 // default :
437 m_table_eta = 0.45;
438
439 // Horrible hack : DCS indicated infinite eta for some periods
440 if ( m_runNumber >= 2102181 && m_runNumber < 2102208 ) m_table_eta = 0.55;
441 if ( m_runNumber == 2102208 ) m_table_eta = 0.42;
442
443 // Horrible hack : DCS update were missing for the end of the data-taking
444 if ( m_runNumber >= 2102455 && m_runNumber < 2102470 ) m_table_eta = 0.1;
445 if ( m_runNumber >= 2102470 && m_runNumber < 2102478 ) m_table_eta = 0.2;
446 if ( m_runNumber >= 2102478 && m_runNumber < 2102488 ) m_table_eta = 0.3;
447 if ( m_runNumber >= 2102488 && m_runNumber < 2102498 ) m_table_eta = 0.4;
448 if ( m_runNumber >= 2102498 && m_runNumber < 2102512 ) m_table_eta = 0.5;
449 if ( m_runNumber >= 2102512 && m_runNumber < 2102530 ) m_table_eta = 0.7;
450 if ( m_runNumber >= 2102530 && m_runNumber < 2102758 ) m_table_eta = 0.6;
451
452 if ( m_runNumber >= 2102758 && m_runNumber < 2102903 ) m_table_eta = 0.55;
453 if ( m_runNumber >= 2102903 && m_runNumber < 2102936 ) m_table_eta = 0.5;
454 if ( m_runNumber >= 2102936 && m_runNumber < 2102953 ) m_table_eta = 0.3;
455 if ( m_runNumber >= 2102953 && m_runNumber < 2102980 ) m_table_eta = 0.4;
456 if ( m_runNumber >= 2102980 ) m_table_eta = 0.3;
457
458 ATH_MSG_DEBUG ( " --------------------------------------------------------------------- " );
459 ATH_MSG_DEBUG ( " " );
460 ATH_MSG_DEBUG ( " Calorimeter table DCS either OFF of not used, position is hardcoded : for run "
461 << m_runNumber << " eta is = " << m_table_eta );
462 ATH_MSG_DEBUG ( " " );
463 ATH_MSG_DEBUG ( " If it does not match the LAr logbook, inform LAr people " );
464 ATH_MSG_DEBUG ( " " );
465 ATH_MSG_DEBUG ( " --------------------------------------------------------------------- " );
466
467 m_table_calc_theta= m_range->twopi()/4. - atan(exp(-m_table_eta))*2.;
468
469 if(m_DBRead >= 0)
471 else
473
475 //*m_table_shift = TranslateX3D(m_table_calc_x);
477
479
480 //print_transform( *m_transform_calo_to_ctb );
481
483
484 ATH_MSG_DEBUG ( " Moovement defined by hardcoded numbers : eta was set to "
485 << m_table_eta);
486
487 ATH_MSG_DEBUG ( "Calculated table position is : " );
488 ATH_MSG_DEBUG ( " angle against y axis = "
490
491 m_firstevt = 2;
492
493 //log << MSG::DEBUG << " x shift = " << m_table_calc_x << endmsg;
494 //print_transform( *m_transform_calo_to_ctb );
495
496}
497
498void
500{
501 // do the work once :
502 if (m_firstevt > 1 ) return;
503
506
508 //*m_table_shift = TranslateX3D(m_table_calc_x);
510 *m_transform_calo_to_ctb = (*m_table_shift)*(*m_table_rotate);
512
513 m_firstevt = 2;
514
515 ATH_MSG_DEBUG ( " Neutral Moovement : " );
516 //print_transform( *m_transform_calo_to_ctb );
517
518}
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
CaloPhiRange class declaration.
static Double_t sc
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
This class defines the phi convention for Calorimeters.
Amg::RotationMatrix3D * m_table_rotate
void print_transform(Amg::Transform3D &htrans)
Amg::Transform3D m_translxyz_extra_calo_to_ctb
StatusCode initialize()
Amg::Transform3D * m_transform_calo_to_ctb
void ctb_to_local(Amg::Vector3D &pt_ctb, Amg::Vector3D &pt_local)
Amg::Transform3D * transform_ctb_to_calo()
ITBCaloPosTool * m_postool
Amg::Transform3D m_roty_extra_calo_to_ctb
virtual void read_table_position()
Amg::Translation3D * m_table_shift
virtual void read_fake_table_position()
Amg::Transform3D * transform_calo_to_ctb()
void local_to_ctb(Amg::Vector3D &pt_local, Amg::Vector3D &pt_ctb)
CaloPhiRange * m_range
TBCaloCoordinate(const std::string &type, const std::string &name, const IInterface *parent)
Amg::Transform3D m_rotx_extra_calo_to_ctb
Amg::Transform3D m_rotz_extra_calo_to_ctb
Amg::Transform3D * m_transform_ctb_to_calo
const TBDetDescrManager * m_MCmgr
TBElementID::TBElementID id() const
Definition TBElement.h:33
Amg::Vector3D position() const
Definition TBElement.h:35
Amg::RotationMatrix3D rotation() const
Definition TBElement.h:36
Eigen::AngleAxisd AngleAxis3D
Eigen::Quaternion< double > Rotation3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Translation< double, 3 > Translation3D