KaliVeda
Toolkit for HIC analysis
KVPosition.h
1 /***************************************************************************
2  kvposition.h - description
3  -------------------
4  begin : Sun May 19 2002
5  copyright : (C) 2002 by J.D. Frankland
6  email : frankland@ganil.fr
7 
8 $Id: KVPosition.h,v 1.20 2009/01/19 14:36:57 ebonnet Exp $
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 #ifndef KVPOSITION_H
21 #define KVPOSITION_H
22 #include "TMath.h"
23 #include "KVBase.h"
24 #include "TVector3.h"
25 #include "TRotation.h"
26 #include "TGeoMatrix.h"
27 #include "TGeoBBox.h"
28 
92 {
93 private:
94  Double_t fTheta = -1; // polar angle in degrees with respect to beam axis, corresponds to centre of telescope
95  mutable Double_t fPhi = -1; // azimuthal angle in degrees with respect to 12 o'clock (=0 deg.), corresponds to centre of telescope
96  Double_t fTheta_min = 0; // polar angle in degrees corresponding to edge of telescope closest to beam axis
97  Double_t fTheta_max= 0; // polar angle in degrees of the edge furthest from the beam axis
98  Double_t fPhi_min = 0; // azimuthal angle in degrees corresponding to most anticlockwise edge of telescope
99  Double_t fPhi_max = 0; // azimuthal angle in degrees corresponding to most clockwise edge of telescope
100  Double_t fDistance = 0; // distance in cm from centre of solid angle element to coordinate system origin (target)
101 
102  /* ROOT Geometry */
103  std::unique_ptr<TGeoHMatrix> fMatrix;
104  TGeoBBox* fShape = nullptr; // shape of detector volume
105  mutable Double_t fSolidAngle = 0; // solid angle = area of entrance window / distance**2
109  Double_t fMaxMisalignment=-1.; // maximum angle [deg] between the normal & all vectors which pass through the surface
110 
112  {
114  }
116  {
120  }
121 
122  void initialize_root_geo();
123  void set_volume_centre();
124  void set_surface_centre();
125 
126  public:
127  KVPosition() = default;
128  KVPosition(Double_t thmin, Double_t thmax, Double_t phmin, Double_t phmax, Double_t dist = 0.0);
129  virtual ~KVPosition() = default;
133  fMatrix(o.GetMatrix() ? new TGeoHMatrix(*o.GetMatrix()) : nullptr),
137  fNormal(o.fNormal) {}
139  : KVPosition()
140  {
141  swap(*this,other);
142  }
143 
144  friend void swap(KVPosition& p1, KVPosition& p2)
145  {
146  using std::swap;
147  swap(p1.fTheta,p2.fTheta);
148  swap(p1.fPhi,p2.fPhi);
149  swap(p1.fTheta_min,p2.fTheta_min);
150  swap(p1.fTheta_max,p2.fTheta_max);
151  swap(p1.fPhi_min,p2.fPhi_min);
152  swap(p1.fPhi_max,p2.fPhi_max);
153  swap(p1.fDistance,p2.fDistance);
154  swap(p1.fMatrix,p2.fMatrix);
155  swap(p1.fShape,p2.fShape);
159  swap(p1.fNormal,p2.fNormal);
160  }
162  {
163  swap(*this, other);
164  return *this;
165  }
166 
167  virtual void SetAzimuthalAngle(Double_t ph);
168  virtual void SetPolarAngle(Double_t th);
169  virtual void SetPolarWidth(Double_t pw);
170  virtual void SetPolarMinMax(Double_t min, Double_t max);
171  virtual void SetAzimuthalWidth(Double_t aw);
172  virtual void SetAzimuthalMinMax(Double_t min, Double_t max);
174  {
176  }
177  virtual TVector3 GetRandomDirection(Option_t* t = "isotropic");
179  virtual void GetRandomAngles(Double_t& th, Double_t& ph, Option_t* t = "isotropic");
180  void CalculateEstimatedAngularLimits(int N=10000);
181  virtual TVector3 GetDirection();
182 
183  Bool_t IsInPolarRange(const Double_t theta);
184  Bool_t IsInPhiRange(const Double_t phi);
189 
191  {
192  if(ROOTGeo() && fPhi_min==fPhi_max)
193  const_cast<KVPosition*>(this)->CalculateEstimatedAngularLimits();
194  return fPhi_min;
195  }
197  {
198  if(ROOTGeo() && fPhi_min==fPhi_max)
199  const_cast<KVPosition*>(this)->CalculateEstimatedAngularLimits();
200  return fPhi_max;
201  }
203  {
204  if(ROOTGeo() && fTheta_min==fTheta_max)
205  const_cast<KVPosition*>(this)->CalculateEstimatedAngularLimits();
206  return fTheta_min;
207  }
209  {
210  if(ROOTGeo() && fTheta_min==fTheta_max)
211  const_cast<KVPosition*>(this)->CalculateEstimatedAngularLimits();
212  return fTheta_max;
213  }
214  Double_t GetAzimuthalWidth(Double_t phmin = -1., Double_t phimax =
215  -1.) const;
216  virtual Double_t GetTheta() const
217  {
218  return fTheta;
219  }
220  virtual Double_t GetSinTheta() const
221  {
222  return TMath::Sin(fTheta * TMath::DegToRad());
223  }
224  virtual Double_t GetCosTheta() const
225  {
226  return TMath::Cos(fTheta * TMath::DegToRad());
227  }
228  virtual Double_t GetPhi() const
229  {
230  if (fPhi >= 360.0)
231  fPhi -= 360.;
232  return fPhi;
233  }
235  {
236  SetPolarAngle(t);
237  }
238  void SetPhi(Double_t p)
239  {
241  }
243  {
244  fDistance = d;
245  }
246  virtual Double_t GetDistance(void) const
247  {
248  return fDistance;
249  }
250  void GetCornerCoordinates(TVector3*, Double_t /*depth*/ = 0);
251  void GetCornerCoordinatesInOwnFrame(TVector3*, Double_t /*depth*/ = 0);
252  void GetWidthsFromDimension(Double_t lin_dim);
253 
254  virtual Double_t GetSolidAngle(void) const;
255 
256  /* ROOT Geometry */
257  virtual Bool_t ROOTGeo() const
258  {
260  return (fMatrix && fShape);
261  }
262  virtual void SetMatrix(const TGeoHMatrix*);
263  virtual void SetShape(TGeoBBox*);
264  virtual TGeoHMatrix* GetMatrix() const;
265  virtual TGeoBBox* GetShape() const;
266  virtual TVector3 GetRandomPointOnSurface() const;
267  virtual TVector3 GetSurfaceCentre() const
268  {
269  return fSurfaceCentre;
270  }
271  virtual TVector3 GetVolumeCentre() const
272  {
273  return fVolumeCentre;
274  }
275  virtual TVector3 GetNormalIntoShape() const
276  {
279  return fNormal;
280  }
281  virtual Double_t GetSurfaceArea(int npoints = 100000) const;
283  {
286 
287  if(fMaxMisalignment<0)
288  const_cast<KVPosition*>(this)->CalculateEstimatedAngularLimits();
289  return fMaxMisalignment;
290  }
292  {
297 
299  }
300 
301  ClassDef(KVPosition, 2)//Class handling geometry of detectors in a multidetector array
302 };
303 
304 
305 
306 #endif
#define d(i)
bool Bool_t
double Double_t
const char Option_t
#define ClassDef(name, id)
winID h TVirtualViewer3D TVirtualGLPainter p
Base class used for handling geometry in a multidetector array.
Definition: KVPosition.h:92
virtual void GetRandomAngles(Double_t &th, Double_t &ph, Option_t *t="isotropic")
Definition: KVPosition.cpp:238
Bool_t IsInPhiRange(const Double_t phi)
Definition: KVPosition.cpp:323
void set_surface_centre()
Definition: KVPosition.cpp:855
virtual void SetAzimuthalWidth(Double_t aw)
Definition: KVPosition.cpp:147
virtual TVector3 GetRandomDirection(Option_t *t="isotropic")
Definition: KVPosition.cpp:200
Bool_t IsAzimuthallyWiderThan(KVPosition *pos)
Definition: KVPosition.cpp:433
virtual void SetShape(TGeoBBox *)
Definition: KVPosition.cpp:729
virtual void SetAzimuthalMinMax(Double_t min, Double_t max)
Set min and max azimuthal angles and calculate (mean) phi.
Definition: KVPosition.cpp:174
virtual void SetAzimuthalAngle(Double_t ph)
Definition: KVPosition.cpp:75
virtual Double_t GetSolidAngle(void) const
Definition: KVPosition.cpp:554
virtual Double_t GetTheta() const
Definition: KVPosition.h:216
void GetCornerCoordinates(TVector3 *, Double_t=0)
Definition: KVPosition.cpp:483
void initialize_root_geo()
Definition: KVPosition.cpp:680
Double_t fTheta
Definition: KVPosition.h:94
TVector3 fNormal
unit normal to volume i.e. axis of shape, pointing away from the origin
Definition: KVPosition.h:108
virtual TGeoHMatrix * GetMatrix() const
Definition: KVPosition.cpp:746
virtual TVector3 GetSurfaceCentre() const
Definition: KVPosition.h:267
void GetWidthsFromDimension(Double_t lin_dim)
Definition: KVPosition.cpp:617
void SetDistance(Double_t d)
Definition: KVPosition.h:242
TRotation GetRandomIsotropicRotation()
Definition: KVPosition.cpp:643
virtual TVector3 GetVolumeCentre() const
Definition: KVPosition.h:271
virtual void SetPolarAngle(Double_t th)
Definition: KVPosition.cpp:54
virtual Double_t GetPhi() const
Definition: KVPosition.h:228
Double_t GetPhiMax() const
Definition: KVPosition.h:196
virtual Double_t GetDistance(void) const
Definition: KVPosition.h:246
Double_t fSolidAngle
Definition: KVPosition.h:105
Double_t GetPhiMin() const
Definition: KVPosition.h:190
Bool_t IsSmallerThan(KVPosition *pos)
kTRUE if "this" is entirely contained within "pos"
Definition: KVPosition.cpp:366
Double_t fMaxMisalignment
Definition: KVPosition.h:109
std::unique_ptr< TGeoHMatrix > fMatrix
transform world<->detector coordinates
Definition: KVPosition.h:103
virtual Double_t GetSurfaceArea(int npoints=100000) const
Definition: KVPosition.cpp:902
Double_t GetThetaMin() const
Definition: KVPosition.h:202
void set_volume_centre()
Definition: KVPosition.cpp:879
virtual Double_t GetSinTheta() const
Definition: KVPosition.h:220
TVector3 fVolumeCentre
vector position of volume centre
Definition: KVPosition.h:106
Double_t GetOC_SC_CosAngle() const
Definition: KVPosition.h:111
KVPosition(const KVPosition &o)
Definition: KVPosition.h:130
Double_t GetMisalignmentAngle() const
Definition: KVPosition.h:115
virtual TVector3 GetNormalIntoShape() const
Definition: KVPosition.h:275
Double_t fTheta_min
Definition: KVPosition.h:96
Double_t GetAzimuthalWidth(Double_t phmin=-1., Double_t phimax=-1.) const
Definition: KVPosition.cpp:590
Bool_t IsInPolarRange(const Double_t theta)
kTRUE if given angle theta is within the polar range of this solid angle element
Definition: KVPosition.cpp:349
virtual void SetPolarWidth(Double_t pw)
Definition: KVPosition.cpp:105
Bool_t IsAlignedWith(KVPosition *pos)
kTRUE if one of the two solid angle elements is completely contained within the other.
Definition: KVPosition.cpp:382
Double_t fTheta_max
Definition: KVPosition.h:97
friend void swap(KVPosition &p1, KVPosition &p2)
Definition: KVPosition.h:144
void SetTheta(Double_t t)
Definition: KVPosition.h:234
KVPosition & operator=(KVPosition other)
Definition: KVPosition.h:161
void CalculateEstimatedAngularLimits(int N=10000)
Definition: KVPosition.cpp:294
Double_t fPhi
Definition: KVPosition.h:95
TGeoBBox * fShape
Definition: KVPosition.h:104
TVector3 fSurfaceCentre
vector position of surface centre
Definition: KVPosition.h:107
void SetPhi(Double_t p)
Definition: KVPosition.h:238
virtual ~KVPosition()=default
void SetPhiMinMax(Double_t min, Double_t max)
Definition: KVPosition.h:173
virtual void SetPolarMinMax(Double_t min, Double_t max)
Set min and max polar angles and calculate (mean) theta.
Definition: KVPosition.cpp:129
virtual void SetMatrix(const TGeoHMatrix *)
Set the global transformation matrix for this volume.
Definition: KVPosition.cpp:713
virtual Double_t GetCosineMaximumMisalignmentAngle() const
Definition: KVPosition.h:291
KVPosition()=default
virtual TGeoBBox * GetShape() const
Definition: KVPosition.cpp:759
Double_t fPhi_max
Definition: KVPosition.h:99
virtual Double_t GetCosTheta() const
Definition: KVPosition.h:224
Double_t fPhi_min
Definition: KVPosition.h:98
KVPosition(KVPosition &&other)
Definition: KVPosition.h:138
virtual Double_t GetMaximumMisalignmentAngle() const
Definition: KVPosition.h:282
Bool_t IsOverlappingWith(KVPosition *pos)
kTRUE if there is at least partial overlap between two solid angle elements
Definition: KVPosition.cpp:395
virtual Bool_t ROOTGeo() const
Definition: KVPosition.h:257
Double_t fDistance
Definition: KVPosition.h:100
void GetCornerCoordinatesInOwnFrame(TVector3 *, Double_t=0)
Definition: KVPosition.cpp:531
Double_t GetThetaMax() const
Definition: KVPosition.h:208
virtual TVector3 GetDirection()
Definition: KVPosition.cpp:450
virtual TVector3 GetRandomPointOnSurface() const
Definition: KVPosition.cpp:782
Double_t Dot(const TVector3 &) const
TVector3 Unit() const
void swap(RVec< T > &lhs, RVec< T > &rhs)
double min(double x, double y)
double max(double x, double y)
Double_t ACos(Double_t)
constexpr Double_t DegToRad()
Double_t Cos(Double_t)
Double_t Sin(Double_t)
constexpr Double_t RadToDeg()