ATLAS Offline Software
TRT_DetElementsLayer_xk.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // Implementation file for class TRT_DetElemenstLayerLxk
8 // (c) ATLAS Detector software
10 //
12 // Version 1.0 21/04/2004 I.Gavrilenko
14 
15 #include <cmath>
16 
17 #include <iostream>
18 #include <iomanip>
19 #include <utility>
21 #include "CxxUtils/trapping_fp.h"
22 
24 // Set detector elements layer
26 
28 (double r,double dr,double z,double dz,double df,double wf,double wz)
29 {
30  m_r = float(r ) ;
31  m_dr = float(dr) ;
32  m_z = float(z ) ;
33  m_dz = float(dz) ;
34  m_dfe = float(df) ;
35  m_wf = float(wf) ;
36  m_wz = float(wz) ;
37  m_f0 = m_elements[0].phi();
38  m_sfi = 0. ;
39  if(m_elements.size()<=1) return;
40  m_sfi = m_elements[1].phi()-m_elements[0].phi();
41  if(m_sfi < .001) m_sfi = m_elements[2].phi()-m_elements[0].phi();
42  m_sfi = 1./m_sfi;
43 }
44 
46 // Get barrel detector elements for Atlas geometry
47 // Input parameters: P[0] - X A[0] - Ax
48 // P[1] - Y A[1] - Ay
49 // P[2] - Z A[2] - Az
50 // P[3] - R
51 // P[4] - width
52 // P[5] - step
54 
56 (const float* P ,
57  const float* A,
58  std::vector<std::pair<const InDet::TRT_DetElementLink_xk*, float> >& lDE,
59  std::vector<InDet::TRT_DetElementLink_xk::Used_t> &used) const
60 {
61  // Tell clang to optimize assuming that FP exceptions can trap.
62  // Otherwise, it can vectorize the division, which can lead to
63  // spurious division-by-zero traps from unused vector lanes.
65  float a = (A[0]*P[0]+A[1]*P[1])*2.;
66  float s = 0. ;
67  if(a!=0.) {
68  float d = (m_r-P[0]-P[1])*(m_r+P[0]+P[1])+2.*P[0]*P[1];
69  float b = 2.*(A[0]*A[0]+A[1]*A[1]);
70  float sq = a*a+2.*d*b; sq>0. ? sq=std::sqrt(sq) : sq=0.;
71  float s1 =-(a+sq)/b;
72  float s2 =-(a-sq)/b;
73 
74  if((s1*s2) > 0.) {std::abs(s1) < std::abs(s2) ? s = s1 : s = s2;}
75  else { s1 > 0. ? s = s1 : s = s2;}
76 
77  }
78  float zc = P[2]+A[2]*s ; if(std::abs(zc-m_z)>(m_dz+P[4])) return;
79  float zc0 = zc-P[4]-m_z ;
80  float zc1 = zc+P[4]-m_z ;
81  float yc = P[1]+A[1]*s ;
82  float xc = P[0]+A[0]*s ; s+=P[5];
83  float fc = std::atan2(yc,xc);
84  int m = m_elements.size()-2;
85  int n = int((fc-m_f0)*m_sfi)*2; if(n<0) n=0; else if(n>m) n=m;
86 
87  float dF = fc-m_elements[n].phi();
88  float dx = std::abs(yc*m_elements[n].cos()-xc*m_elements[n].sin()-m_elements[n].centerf());
89  if((dx-m_wf-P[4]) <= 0.) {
90 
91  assert( used.size() > static_cast<unsigned int>(n));
92  if(zc0 <= 0 && !used[n].used()) {
93  lDE.emplace_back(&m_elements[n],s); used[n].setUsed();
94  }
95 
96  int k = n+1;
97  assert( used.size() > static_cast<unsigned int>(k));
98  if(zc1 >= 0. && !used[k].used() ) {
99  lDE.emplace_back(&m_elements[k],s); used[k].setUsed();
100  }
101  }
102  if(dF>0.) { n!=62 ? n+=2 : n=0 ;}
103  else { n!= 0 ? n-=2 : n=62;}
104 
105  dx = std::abs(yc*m_elements[n].cos()-xc*m_elements[n].sin()-m_elements[n].centerf());
106  if((dx-m_wf-P[4]) <= 0.) {
107 
108  assert( used.size() > static_cast<unsigned int>(n));
109  if(zc0 <= 0. && !used[n].used()) {
110  lDE.emplace_back(&m_elements[n],s); used[n].setUsed();
111  }
112 
113  int k = n+1;
114  assert( used.size() > static_cast<unsigned int>(k));
115  if(zc1 >= 0. && !used[k].used()) {
116  lDE.emplace_back(&m_elements[k],s); used[k].setUsed();
117  }
118  }
119 }
120 
122 // Get barrel detector elements for CTB geometry
123 // Input parameters: P[0] - X A[0] - Ax
124 // P[1] - Y A[1] - Ay
125 // P[2] - Z A[2] - Az
126 // P[3] - R
127 // P[4] - width
128 // P[5] - step
130 
132 (const float* P ,
133  const float* A,
134  std::vector<std::pair<const InDet::TRT_DetElementLink_xk*,float> >& lDE,
135  std::vector<InDet::TRT_DetElementLink_xk::Used_t> &used) const
136 {
137  float a = (A[0]*P[0]+A[1]*P[1])*2.;
138  float s = 0. ;
139  if(a!=0.) {
140  float d = (m_r-P[0]-P[1])*(m_r+P[0]+P[1])+2.*P[0]*P[1];
141  float b = 2.*(A[0]*A[0]+A[1]*A[1]);
142  float sq = a*a+2.*d*b; sq>0. ? sq=std::sqrt(sq) : sq=0.;
143  float s1 =-(a+sq)/b;
144  float s2 =-(a-sq)/b;
145 
146  if((s1*s2) > 0.) {std::abs(s1) < std::abs(s2) ? s = s1 : s = s2;}
147  else { s1 > 0. ? s = s1 : s = s2;}
148 
149  }
150  float zc = P[2]+A[2]*s ; if(std::abs(zc-m_z)>(m_dz+P[4])) return;
151  float zc0 = zc-P[4]-m_z ;
152  float zc1 = zc+P[4]-m_z ;
153  float yc = P[1]+A[1]*s ;
154  float xc = P[0]+A[0]*s ; s+=P[5];
155 
156  for(size_t n = 0; n < m_elements.size(); n+=2) {
157 
158  float dx = std::abs(yc*m_elements[n].cos()-xc*m_elements[n].sin()-m_elements[n].centerf());
159  if((dx-m_wf-P[4]) <= 0.) {
160 
161  assert( used.size() > static_cast<unsigned int>(n));
162  if(zc0 <= 0. && !used[n].used()) {
163  lDE.emplace_back(&m_elements[n],s); used[n].setUsed();
164  }
165 
166  assert( used.size() > static_cast<unsigned int>(n+1));
167  if(zc1 >= 0. && !used[n+1].used()) {
168 
169  lDE.emplace_back(&m_elements[n+1],s); used[n+1].setUsed();
170  }
171  }
172  }
173 }
174 
176 // Get endcap detector elements
177 // Input parameters: P[0] - X A[0] - Ax
178 // P[1] - Y A[1] - Ay
179 // P[2] - Z A[2] - Az
180 // P[3] - R
181 // P[4] - width
182 // P[5] - step
184 
186 (const float* P ,
187  const float* A,
188  std::vector<std::pair<const InDet::TRT_DetElementLink_xk*, float> >& lDE,
189  std::vector<InDet::TRT_DetElementLink_xk::Used_t> &used) const
190 {
191  const float pi2=2.*M_PI;
192 
193  float s = (m_z-P[2])/A[2];
194  float xc = P[0]+A[0]*s;
195  float yc = P[1]+A[1]*s; s+=P[5];
196  float rc = std::sqrt(xc*xc+yc*yc); if(std::abs(rc-m_r)>m_dr+P[4]) return;
197  float fc = std::atan2(yc,xc);
198  float sf = 0.09817477+P[4]/rc;
199 
200  int m = m_elements.size()-1;
201  int n = int((fc-m_f0)*m_sfi); if(n<0) n=0; else if(n>m) n=m;
202  float dF = fc-m_elements[n].phi();
203 
204  assert( used.size() > static_cast<unsigned int>(n));
205  if(std::abs(dF) < sf && !used[n].used()) {
206  lDE.emplace_back(&m_elements[n],s); used[n].setUsed();
207  }
208 
209  // if(dF>0.) {if(n!=63) ++n; else {n=0 ; fc-=pi2;}}
210  // else {if(n!=0 ) --n; else {n=63; fc+=pi2;}}
211  if(dF>0.) {if(n!=m) ++n; else {n=0 ; fc-=pi2;}}
212  else {if(n!=0) --n; else {n=m ; fc+=pi2;}}
213 
214  assert( used.size() > static_cast<size_t>(n));
215  if(std::abs(fc-m_elements[n].phi()) < sf && !used[n].used()) {
216  lDE.emplace_back(&m_elements[n],s); used[n].setUsed();
217  }
218 }
TRT_DetElementsLayer_xk.h
used
beamspotman.r
def r
Definition: beamspotman.py:676
CXXUTILS_TRAPPING_FP
#define CXXUTILS_TRAPPING_FP
Definition: trapping_fp.h:24
InDet::TRT_DetElementsLayer_xk::m_f0
float m_f0
Definition: TRT_DetElementsLayer_xk.h:110
InDet::TRT_DetElementsLayer_xk::getEndcapDetElements
void getEndcapDetElements(const float *, const float *, std::vector< std::pair< const InDet::TRT_DetElementLink_xk *, float > > &, std::vector< InDet::TRT_DetElementLink_xk::Used_t > &used) const
Definition: TRT_DetElementsLayer_xk.cxx:186
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
InDet::TRT_DetElementsLayer_xk::r
const float & r() const
Definition: TRT_DetElementsLayer_xk.h:50
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
hist_file_dump.d
d
Definition: hist_file_dump.py:137
python.PhysicalConstants.pi2
float pi2
Definition: PhysicalConstants.py:52
M_PI
#define M_PI
Definition: ActiveFraction.h:11
InDet::TRT_DetElementsLayer_xk::m_sfi
float m_sfi
Definition: TRT_DetElementsLayer_xk.h:111
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
z
#define z
beamspotman.n
n
Definition: beamspotman.py:731
sq
#define sq(x)
Definition: CurvedSegmentFinder.cxx:6
InDet::TRT_DetElementsLayer_xk::m_r
float m_r
Definition: TRT_DetElementsLayer_xk.h:107
InDet::TRT_DetElementsLayer_xk::getBarrelDetElementsCTB
void getBarrelDetElementsCTB(const float *, const float *, std::vector< std::pair< const InDet::TRT_DetElementLink_xk *, float > > &, std::vector< InDet::TRT_DetElementLink_xk::Used_t > &used) const
Definition: TRT_DetElementsLayer_xk.cxx:132
trapping_fp.h
Tell the compiler to optimize assuming that FP may trap.
InDet::TRT_DetElementsLayer_xk::m_z
float m_z
Definition: TRT_DetElementsLayer_xk.h:105
InDet::TRT_DetElementsLayer_xk::m_dr
float m_dr
Definition: TRT_DetElementsLayer_xk.h:108
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
InDet::TRT_DetElementsLayer_xk::m_dz
float m_dz
Definition: TRT_DetElementsLayer_xk.h:106
InDet::TRT_DetElementsLayer_xk::m_wf
float m_wf
Definition: TRT_DetElementsLayer_xk.h:112
InDet::TRT_DetElementsLayer_xk::m_elements
std::vector< TRT_DetElementLink_xk > m_elements
Definition: TRT_DetElementsLayer_xk.h:114
InDet::TRT_DetElementsLayer_xk::getBarrelDetElementsATL
void getBarrelDetElementsATL(const float *, const float *, std::vector< std::pair< const InDet::TRT_DetElementLink_xk *, float > > &, std::vector< InDet::TRT_DetElementLink_xk::Used_t > &used) const
Definition: TRT_DetElementsLayer_xk.cxx:56
a
TList * a
Definition: liststreamerinfos.cxx:10
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
InDet::TRT_DetElementsLayer_xk::m_wz
float m_wz
Definition: TRT_DetElementsLayer_xk.h:113
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
InDet::TRT_DetElementsLayer_xk::set
void set(double, double, double, double, double, double, double)
Definition: TRT_DetElementsLayer_xk.cxx:28
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
python.TriggerAPI.TriggerAPISession.df
df
Definition: TriggerAPISession.py:359
InDet::TRT_DetElementsLayer_xk::dz
const float & dz() const
Definition: TRT_DetElementsLayer_xk.h:53
readCCLHist.float
float
Definition: readCCLHist.py:83
InDet::TRT_DetElementsLayer_xk::m_dfe
float m_dfe
Definition: TRT_DetElementsLayer_xk.h:109
InDet::TRT_DetElementsLayer_xk::dr
const float & dr() const
Definition: TRT_DetElementsLayer_xk.h:51
InDet::TRT_DetElementsLayer_xk::z
const float & z() const
Definition: TRT_DetElementsLayer_xk.h:52
fitman.k
k
Definition: fitman.py:528