ATLAS Offline Software
ForwardTracker/src/Magnet.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
10 namespace ForwardTracker {
11 
12  Magnet::Magnet(double x,
13  double y,
14  double z,
15  double length,
16  const std::string& aperType,
17  double aper1,
18  double aper2,
19  double aper3,
20  double aper4,
21  Side side,
22  IBender::ConstPtr_t bender,
23  const std::string& label):
24  m_label (label),
25  m_side (side),
26  m_frontFace(z>0 ? z - 0.5*length : z + 0.5*length),
27  m_rearFace (z>0 ? z + 0.5*length : z - 0.5*length),
28  m_position (x, y, z),
29  m_aperType (aperType),
30  m_A1 (aper1),
31  m_A2 (aper2),
32  m_A3 (aper3),
33  m_A4 (aper4),
34  m_bender (bender)
35  {}
36 
38 
39  particle.setBeamCoordinateShift(this);
40 
41  if (particle.isOutOfAperture()) return;
42 
43  m_bender->bend(particle);
44 
45  particle.z() = m_rearFace;
46 
47  if (this->isOutOfAperture(particle)) particle.setOutOfAperture(true);
48  }
49 
51 
52  TransversePoint offCenter = particle.displacement();
53 
54  if (m_aperType == "\"NONE\"") return false;
55  else if (m_aperType == "\"CIRCLE\"") {
56 
57  if (m_A1 == 0) return false;
58 
59  if (offCenter.mag2() > m_A1*m_A1) {
60 
61  std::ostringstream ost; ost << m_label << " isOutOfAperture ";
62 
63  ost << "radius: " << offCenter.mag2() << " > A1*A1: " << m_A1*m_A1;
64  particle.addMsg(ost.str());
65 
66  return true;
67  }
68 
69  return false;
70  }
71  else if (m_aperType == "\"RECTELLIPSE\"") {
72 
73  double xx = (m_A3) ? offCenter.x()/m_A3 : throw std::runtime_error("ERROR: m_A3 == 0");
74  double yy = (m_A4) ? offCenter.y()/m_A4 : throw std::runtime_error("ERROR: m_A4 == 0");
75  double rr = xx*xx + yy*yy;
76 
77  if (rr > 1) {
78 
79  std::ostringstream ost; ost << m_label << " isOutOfAperture ";
80 
81  ost << " x/A3: " << xx << " y/A4: " << yy << " (Squared sum: " << rr << " > 1)";
82  particle.addMsg(ost.str());
83 
84  return true;
85  }
86 
87  if (m_A1 > 0) {
88 
89  if (std::fabs(offCenter.x()) > m_A1) {
90 
91  std::ostringstream ost; ost << m_label << " isOutOfAperture ";
92 
93  ost << " |x|: " << std::fabs(offCenter.x()) << " > A1: " << m_A1;
94  particle.addMsg(ost.str());
95 
96  return true;
97  }
98  }
99 
100  if (m_A2 > 0) {
101 
102  if (std::fabs(offCenter.y()) > m_A2) {
103 
104  std::ostringstream ost; ost << m_label << " isOutOfAperture ";
105 
106  ost << " |y|: " << std::fabs(offCenter.y()) << " > A2: " << m_A2;
107  particle.addMsg(ost.str());
108 
109  return true;
110  }
111  }
112 
113  return false;
114  }
115  else if (m_aperType == "\"OCTAGON\"") {
116 
117  if ( m_A1 > 0. ) {
118  if( std::fabs(offCenter.x())>m_A1 ) {
119 
120  std::ostringstream ost; ost << m_label << " isOutOfAperture ";
121 
122  ost << " |x|: " << std::fabs(offCenter.x()) << " > A1: " << m_A1;
123  particle.addMsg(ost.str());
124  return true;
125  }
126  }
127  if ( m_A2 > 0. ) {
128  if( std::fabs(offCenter.y())>m_A2) {
129 
130  std::ostringstream ost; ost << m_label << " isOutOfAperture ";
131 
132  ost << " |y|: " << std::fabs(offCenter.y()) << " > A2: " << m_A2;
133  particle.addMsg(ost.str());
134  return true;
135  }
136  }
137  if ( m_A3 > 0. && m_A4 > 0. ) {
138 
139  float B3=std::tan(m_A3)*m_A1;
140  float B4=m_A2/std::tan(m_A4);
141  float d=(m_A1-std::fabs(offCenter.x()))/(m_A1-B4)+(m_A2-std::fabs(offCenter.y()))/(m_A2-B3);
142 
143  if(d<1.) {
144  std::ostringstream ost; ost << m_label << " isOutOfAperture ";
145 
146  ost<<" x: "<<offCenter.x()<<" y: "<<offCenter.y()<<" m_A1 "<<m_A1<<" m_A2 "<<m_A2<<" m_A3 "<<m_A3<<" m_A4 "<<m_A4<<" d: "<<d;
147  particle.addMsg( ost.str() );
148  return true;
149  }
150  }
151 
152  return false;
153  }
154  else {
155 
156  std::stringstream sstr; sstr << " Unknown magnet aperture type " << m_aperType << "\n";
157  throw std::runtime_error(sstr.str().c_str());
158  }
159 
160  return false;
161  }
162 
163  std::string Magnet::str() const {
164 
165  std::ostringstream ost;
166 
167  ost << "m_label " << m_label << "\n"
168  << "m_side " << m_side << "\n"
169  << "m_frontFace " << m_frontFace << "\n"
170  << "m_rearFace " << m_rearFace << "\n"
171  << "m_position " << m_position << "\n"
172  << "m_aperType " << m_aperType << "\n"
173  << "m_A1 " << m_A1 << "\n"
174  << "m_A2 " << m_A2 << "\n"
175  << "m_A3 " << m_A3 << "\n"
176  << "m_A4 " << m_A4 << "\n";
177 
178  return ost.str();
179  }
180 
181  std::ostream& operator<<(std::ostream& os, const Magnet& mag) { os << mag.str(); return os; }
182 }
ForwardTracker::Magnet::Magnet
Magnet(double x, double y, double z, double length, const std::string &aperType, double A1, double A2, double A3, double A4, Side side, IBender::ConstPtr_t bender, const std::string &label)
Definition: ForwardTracker/src/Magnet.cxx:12
ForwardTracker::Magnet::m_frontFace
double m_frontFace
Definition: ForwardTracker/ForwardTracker/Magnet.h:58
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
python.trigbs_prescaleL1.ost
ost
Definition: trigbs_prescaleL1.py:104
PlotCalibFromCool.yy
yy
Definition: PlotCalibFromCool.py:714
ForwardTracker::TransversePoint::y
double y() const
Definition: ForwardTracker/ForwardTracker/TransversePoint.h:21
ForwardTracker::Magnet::m_A2
double m_A2
Definition: ForwardTracker/ForwardTracker/Magnet.h:63
hist_file_dump.d
d
Definition: hist_file_dump.py:137
ForwardTracker::TransversePoint::mag2
double mag2() const
Definition: ForwardTracker/ForwardTracker/TransversePoint.h:22
Particle.h
ForwardTracker::Magnet::m_rearFace
double m_rearFace
Definition: ForwardTracker/ForwardTracker/Magnet.h:59
x
#define x
ForwardTracker::Magnet::m_A1
double m_A1
Definition: ForwardTracker/ForwardTracker/Magnet.h:62
ForwardTracker::operator<<
std::ostream & operator<<(std::ostream &, const Beamline &)
Definition: ForwardTracker/src/Beamline.cxx:105
TRT::Hit::side
@ side
Definition: HitInfo.h:83
TransversePoint.h
z
#define z
ForwardTracker::Magnet
Definition: ForwardTracker/ForwardTracker/Magnet.h:19
ForwardTracker::Magnet::m_aperType
std::string m_aperType
Definition: ForwardTracker/ForwardTracker/Magnet.h:61
ForwardTracker::Magnet::m_A4
double m_A4
Definition: ForwardTracker/ForwardTracker/Magnet.h:65
Magnet.h
Side
Definition: WaferTree.h:36
ForwardTracker::TransversePoint
Definition: ForwardTracker/ForwardTracker/TransversePoint.h:13
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
ForwardTracker::Magnet::m_bender
IBender::ConstPtr_t m_bender
Definition: ForwardTracker/ForwardTracker/Magnet.h:66
ForwardTracker::IParticle
Definition: ForwardDetectors/ForwardTracker/ForwardTracker/IParticle.h:16
ForwardTracker::Magnet::m_label
std::string m_label
Definition: ForwardTracker/ForwardTracker/Magnet.h:56
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
ForwardTracker::label
std::string label(Magnet::Type type)
Definition: MagnetFactory.cxx:15
ForwardTracker::Magnet::m_position
Point m_position
Definition: ForwardTracker/ForwardTracker/Magnet.h:60
IBender.h
ForwardTracker::Magnet::m_side
Side m_side
Definition: ForwardTracker/ForwardTracker/Magnet.h:57
y
#define y
ForwardTracker::TransversePoint::x
double x() const
Definition: ForwardTracker/ForwardTracker/TransversePoint.h:20
ForwardTracker::Magnet::m_A3
double m_A3
Definition: ForwardTracker/ForwardTracker/Magnet.h:64
ForwardTracker::IBender::ConstPtr_t
std::shared_ptr< IBender > ConstPtr_t
Definition: ForwardTracker/ForwardTracker/IBender.h:21
rr
const boost::regex rr(r_r)
ForwardTracker::Magnet::isOutOfAperture
bool isOutOfAperture(IParticle &) const
Definition: ForwardTracker/src/Magnet.cxx:50
ForwardTracker
Definition: ForwardTracker/ForwardTracker/Beamline.h:12
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
mag
Scalar mag() const
mag method
Definition: AmgMatrixBasePlugin.h:26
ForwardTracker::Magnet::str
std::string str() const
Definition: ForwardTracker/src/Magnet.cxx:163
ForwardTracker::Magnet::track
void track(IParticle &) const
Definition: ForwardTracker/src/Magnet.cxx:37