ATLAS Offline Software
FPTracker/src/Magnet.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "FPTracker/Magnet.h"
6 #include "FPTracker/Particle.h"
8 #include "FPTracker/IBender.h"
9 #include <sstream>
10 #include <cmath>
11 //#include <iostream>
12 #include <cassert>
13 
14 namespace FPTracker{
15 
16  std::string Magnet::label() const{
17  return m_label+":"+m_bender->label();
18  }
19 
21  double x,
22  double y,
23  double center,
24  double strength,
25  double length,
26  int apertype,
27  double aper_A1,
28  double aper_A2,
29  double aper_A3,
30  double aper_A4,
31  double xb,
32  Side side,
33  IBender::ConstPtr_t bender,
34  const std::string& label):
35  m_center(x, y, center),
36  m_frontFace(center>0 ? center-0.5*length:center+0.5*length),
37  m_rearFace(center>0 ? center+0.5*length:center-0.5*length),
38  m_strength(strength),
39  m_apertype(apertype),
40  m_aper_A1(aper_A1),
41  m_aper_A2(aper_A2),
42  m_aper_A3(aper_A3),
43  m_aper_A4(aper_A4),
44  m_xb(xb),
45  m_side(side),
46  m_bender(bender),
47  m_label(label){
48  if (m_apertype == 1){ assert(m_aper_A1 != 0.);}
49  if (m_apertype == 2 || m_apertype == 3){ assert(m_aper_A3 != 0. and m_aper_A4 != 0.);}
50  }
52  IBeamElement::ConstPtr_t pm(new Magnet(*this));
53  return pm;
54  }
55 
56  double Magnet::frontFace() const {return m_frontFace;}
57  double Magnet::rearFace() const {return m_rearFace;}
58  double Magnet::zsignedpos() const {return m_center.z();}
59  double Magnet::zabspos() const {return std::fabs(m_center.z());}
60  Point Magnet::position() const {return m_center;}
61  Side Magnet::side() const {return m_side;}
62 
63  bool Magnet::isEndElement() const{return false;}
64 
66 
67  particle.setBeamCoordinateShift(this);
68  if ( particle.isOutOfAperture() ){return;}
69 
70 
71  // check if particle x,y coordinates wrt to the magnet are in the aperture.
72  if( this->isOutOfAperture( particle ) ){
73  //std::cout<<"lost at front face "<<std::endl;
74  particle.setOutOfAperture(true);
75  return;
76  }
77 
78  // update the particle position and direction affected by the bending of the magnet.
79  m_bender->bend(particle);
80  particle.z() = m_rearFace;
81 
82  /*
83  std::cout<<"Magnet::track after bend "<<this->m_frontFace<<" "<<this->label()<<'\n'
84  <<"\n position "<<particle.position()
85  <<"\n p dir "<<particle.direction()
86  <<"\n m pos "<<this->position()<<'\n'<<std::endl;
87 
88 
89  std::cout<<particle<<'\n';
90  */
91 
92  if ( this->isOutOfAperture( particle ) )
93  {
94  particle.setOutOfAperture(true);
95  }
96 
97  }
98 
100  {
101  return this->track(particle);
102  }
103 
105 
106  TransversePoint offCenter = particle.displacement();
107  if(m_apertype == 1)
108  {
109 
110  double radius = m_aper_A1;
111  bool out = offCenter.mag2() > radius*radius;
112 
113  if(out)
114  {
115  std::ostringstream ost;
116  ost<<"pos "<<offCenter.mag2()<<" radiusSq "<<radius*radius<<'\n';
117  particle.addMsg( ost.str() );
118  return true;
119  }
120 
121  return false;
122  }
123 
124  if(m_apertype == 2)
125  {
126  double part_x = offCenter.x();
127  double part_y = offCenter.y();
128 
129  double xx = part_x/m_aper_A3;
130  double yy = part_y/m_aper_A4;
131 
132  bool out = xx*xx + yy*yy >1.;
133  if(out)
134  {
135  std::ostringstream ost;
136  ost<<"outside for aperture type 2 x xx, xaper "<<part_x<<" "<<xx<<" "<<m_aper_A3<<" y yy yaper "<<part_y<<" "<<yy<<" "<<m_aper_A4<<'\n';
137  particle.addMsg( ost.str() );
138  return true;
139  }
140 
141 
142  if ( m_aper_A1>0.)
143  {
144  if( std::fabs(part_x)>m_aper_A1 )
145  {
146  std::ostringstream ost;
147  ost<<"outside for aperture type 2 x test: particle x "<<part_x<<" m_aper_A1 "<<m_aper_A1<<"\n";
148  particle.addMsg( ost.str() );
149  return true;
150  }
151  }
152  if ( m_aper_A2>0.)
153  {
154  if( std::fabs(part_y)>m_aper_A2)
155  {
156  std::ostringstream ost;
157  ost<<"outside for aperture type 2 y test: particle y "<<part_y<<" m_aper_A2 "<<m_aper_A2<<"\n";
158  particle.addMsg( ost.str() );
159  return true;
160  }
161  }
162 
163  return false;
164  }
165  if(m_apertype == 3)
166  {
167  double part_x = offCenter.x();
168  double part_y = offCenter.y();
169 
170  if ( m_aper_A1 > 0. )
171  {
172  if( std::fabs(part_x)>m_aper_A1 )
173  {
174  std::ostringstream ost;
175  ost<<"outside for aperture type 3 x test: particle x "<<part_x<<" m_aper_A1 "<<m_aper_A1<<"\n";
176  particle.addMsg( ost.str() );
177  return true;
178  }
179  }
180  if ( m_aper_A2 > 0. )
181  {
182  if( std::fabs(part_y)>m_aper_A2)
183  {
184  std::ostringstream ost;
185  ost<<"outside for aperture type 3 y test: particle y "<<part_y<<" m_aper_A2 "<<m_aper_A2<<"\n";
186  particle.addMsg( ost.str() );
187  return true;
188  }
189  }
190  if ( m_aper_A3 > 0. && m_aper_A4 > 0. )
191  {
192  float B3=std::tan(m_aper_A3)*m_aper_A1;
193  float B4=m_aper_A2/std::tan(m_aper_A4);
194  float d=(m_aper_A1-std::fabs(part_x))/(m_aper_A1-B4)+(m_aper_A2-std::fabs(part_y))/(m_aper_A2-B3);
195 
196  if(d<1.)
197  {
198  std::ostringstream ost;
199  ost<<"outside for aperture type 3 test: particle x "<<part_x<<" particle y "<<part_y<<"; m_aper_A1 "<<m_aper_A1<<" m_aper_A2 "<<m_aper_A2<<" m_aper_A3 "<<m_aper_A3<<" m_aper_A4 "<<m_aper_A4<<"\n";
200  particle.addMsg( ost.str() );
201  return true;
202  }
203  }
204 
205  return false;
206  }
207 
208  // aperture is checked anly if aperture type i s 1, 2, or 3
209  return false;
210  }
211 
212 
213  std::string Magnet::str() const {
214  std::ostringstream ost;
215  ost <<" \n\n-- Magnet --\n"
216  << "label " << m_label <<'\n'
217  << "center " << m_center <<'\n'
218  << "frontFace " << m_frontFace <<'\n'
219  << "rearFace " << m_rearFace <<'\n'
220  << "m_strength " << m_strength <<'\n'
221  << "m_apertyp " << m_apertype <<'\n'
222  << "m_aper_A1 " << m_aper_A1 <<'\n'
223  << "m_aper_A2 " << m_aper_A2 <<'\n'
224  << "m_aper_A3 " << m_aper_A3 <<'\n'
225  << "m_aper_A4 " << m_aper_A4 <<'\n'
226  << "m_xb " << m_xb <<'\n'
227  << "m_side " << m_side <<'\n';
228  return ost.str();
229  }
230  std::ostream& operator<<(std::ostream& os, const Magnet& mag){
231  os << mag.str();
232  return os;
233  }
234 }
235 
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
FPTracker::operator<<
std::ostream & operator<<(std::ostream &os, const Beamline &bl)
Definition: FPTracker/src/Beamline.cxx:163
FPTracker::TransversePoint::mag2
double mag2() const
Definition: FPTracker/src/TransversePoint.cxx:25
PlotCalibFromCool.yy
yy
Definition: PlotCalibFromCool.py:714
FPTracker::Magnet::rearFace
double rearFace() const
Definition: FPTracker/src/Magnet.cxx:57
FPTracker::Magnet
Definition: FPTracker/FPTracker/Magnet.h:20
FPTracker::IBender::ConstPtr_t
std::shared_ptr< IBender > ConstPtr_t
Definition: FPTracker/FPTracker/IBender.h:18
hist_file_dump.d
d
Definition: hist_file_dump.py:137
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
FPTracker::Magnet::clone
IBeamElement::ConstPtr_t clone() const
Definition: FPTracker/src/Magnet.cxx:51
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
TransversePoint.h
FPTracker::Magnet::side
Side side() const
Definition: FPTracker/src/Magnet.cxx:61
x
#define x
FPTracker::Magnet::m_label
std::string m_label
Definition: FPTracker/FPTracker/Magnet.h:83
FPTracker::Magnet::m_xb
double m_xb
Definition: FPTracker/FPTracker/Magnet.h:80
TRT::Hit::side
@ side
Definition: HitInfo.h:83
IBender.h
FPTracker::Magnet::m_center
Point m_center
Definition: FPTracker/FPTracker/Magnet.h:71
FPTracker::Magnet::m_strength
double m_strength
Definition: FPTracker/FPTracker/Magnet.h:74
FPTracker::Magnet::m_rearFace
double m_rearFace
Definition: FPTracker/FPTracker/Magnet.h:73
FPTracker::Magnet::position
Point position() const
Definition: FPTracker/src/Magnet.cxx:60
FPTracker::IBeamElement::ConstPtr_t
std::shared_ptr< const IBeamElement > ConstPtr_t
Definition: FPTracker/FPTracker/IBeamElement.h:40
Side
Definition: WaferTree.h:36
FPTracker::Magnet::zsignedpos
double zsignedpos() const
Definition: FPTracker/src/Magnet.cxx:58
FPTracker::Magnet::isOutOfAperture
bool isOutOfAperture(IParticle &) const
Definition: FPTracker/src/Magnet.cxx:104
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
FPTracker::Magnet::m_aper_A1
double m_aper_A1
Definition: FPTracker/FPTracker/Magnet.h:76
FPTracker::Point::z
double z() const
Definition: FPTracker/src/Point.cxx:19
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
FPTracker::Magnet::track
void track(IParticle &) const
Definition: FPTracker/src/Magnet.cxx:65
FPTracker::Point
Definition: FPTracker/FPTracker/Point.h:14
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
FPTracker::Magnet::zabspos
double zabspos() const
Definition: FPTracker/src/Magnet.cxx:59
DataModelTestDataCommonDict::xb
DMTest::CView::Pers_t xb
Definition: DataModelTestDataCommonDict.h:44
FPTracker::Magnet::label
std::string label() const
Definition: FPTracker/src/Magnet.cxx:16
FPTracker::Magnet::m_aper_A2
double m_aper_A2
Definition: FPTracker/FPTracker/Magnet.h:77
FPTracker::TransversePoint::x
double x() const
Definition: FPTracker/src/TransversePoint.cxx:16
FPTracker::Magnet::m_aper_A3
double m_aper_A3
Definition: FPTracker/FPTracker/Magnet.h:78
FPTracker::Magnet::m_apertype
int m_apertype
Definition: FPTracker/FPTracker/Magnet.h:75
y
#define y
FPTracker::Magnet::m_frontFace
double m_frontFace
Definition: FPTracker/FPTracker/Magnet.h:72
FPTracker::Magnet::m_side
Side m_side
Definition: FPTracker/FPTracker/Magnet.h:81
Particle.h
FPTracker::Magnet::m_aper_A4
double m_aper_A4
Definition: FPTracker/FPTracker/Magnet.h:79
FPTracker
Definition: FPTracker/FPTracker/Beamline.h:12
Magnet.h
FPTracker::Magnet::str
std::string str() const
Definition: FPTracker/src/Magnet.cxx:213
FPTracker::Magnet::frontFace
double frontFace() const
Definition: FPTracker/src/Magnet.cxx:56
FPTracker::Magnet::Magnet
Magnet(double x, double y, double center, double strength, double length, int apertype, double aper_A1, double aper_A2, double aper_A3, double aper_A4, double xb, Side side, IBender::ConstPtr_t bender, const std::string &label)
Definition: FPTracker/src/Magnet.cxx:20
FPTracker::TransversePoint::y
double y() const
Definition: FPTracker/src/TransversePoint.cxx:17
FPTracker::IParticle
Definition: ForwardDetectors/FPTracker/FPTracker/IParticle.h:17
FPTracker::Magnet::isEndElement
bool isEndElement() const
Definition: FPTracker/src/Magnet.cxx:63
FPTracker::TransversePoint
Definition: FPTracker/FPTracker/TransversePoint.h:12
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
mag
Scalar mag() const
mag method
Definition: AmgMatrixBasePlugin.h:25
FPTracker::Magnet::calibrate
void calibrate(IParticle &)
Definition: FPTracker/src/Magnet.cxx:99
FPTracker::Magnet::m_bender
IBender::ConstPtr_t m_bender
Definition: FPTracker/FPTracker/Magnet.h:82