AuxDetSensitiveGeo.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file AuxDetSensitiveGeo.cxx
3 /// \brief Encapsulate the geometry of the sensitive portion of an auxilary detector
4 ///
5 /// \author brebel@fnal.gov
6 ////////////////////////////////////////////////////////////////////////
7 
8 #include <iostream>
9 
10 #include "Geometry/AuxDetSensitiveGeo.h"
11 
12 #include "TGeoManager.h"
13 #include "TGeoTube.h"
14 #include "TGeoTrd1.h"
15 #include "TGeoTrd2.h"
16 #include "TGeoMatrix.h"
17 #include "TGeoNode.h"
18 #include "TMath.h"
19 #include "TVector3.h"
20 
21 // Framework includes
23 #include "cetlib_except/exception.h"
24 
25 namespace gar {
26  namespace geo{
27 
28  //-----------------------------------------
29  AuxDetSensitiveGeo::AuxDetSensitiveGeo(std::vector<const TGeoNode*>& path, int depth)
30  : fTotalVolume(0)
31  {
32 
33  TGeoVolume *vc = path[depth]->GetVolume();
34  if(vc){
35  fTotalVolume = vc;
36  if(!fTotalVolume)
37  throw cet::exception("AuxDetSensitiveGeo") << "cannot find AuxDetSensitive volume\n";
38 
39  }// end if found volume
40 
41  MF_LOG_DEBUG("Geometry") << "detector sensitive total volume is " << fTotalVolume->GetName();
42 
43  // Build the matrix that takes us to the top world frame
44  // build a matrix to take us from the local to the world coordinates
45  // in one step
46  fGeoMatrix = new TGeoHMatrix(*path[0]->GetMatrix());
47  for(int i = 1; i <= depth; ++i){
48  fGeoMatrix->Multiply(path[i]->GetMatrix());
49  }
50 
51  // set the ends depending on whether the shape is a box or trapezoid
52  std::string volName(fTotalVolume->GetName());
53  if( volName.find("Trap") != std::string::npos ) {
54 
55  // Small Width
56  // ____ Height is the thickness
57  // / \ T of the trapezoid
58  // / \ |
59  // / \ | Length
60  // /__________\ _
61  // Width
62  fHalfHeight = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDy1(); // same as Dy2()
63  fLength = 2.0*((TGeoTrd2*)fTotalVolume->GetShape())->GetDz();
64  fHalfWidth1 = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDx1(); // at -Dz
65  fHalfWidth2 = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDx2(); // at +Dz
66  }
67  else {
68  fHalfWidth1 = ((TGeoBBox*)fTotalVolume->GetShape())->GetDX();
69  fHalfHeight = ((TGeoBBox*)fTotalVolume->GetShape())->GetDY();
70  fLength = 2.0*((TGeoBBox*)fTotalVolume->GetShape())->GetDZ();
72  }
73 
74  }
75 
76  //-----------------------------------------
78  TGeoHMatrix* rotation)
79  : fGeoMatrix(rotation)
80  , fTotalVolume(volume)
81  {
82 
83  MF_LOG_DEBUG("Geometry") << "detector sensitive total volume is " << fTotalVolume->GetName();
84 
85  // set the ends depending on whether the shape is a box or trapezoid
86  std::string volName(fTotalVolume->GetName());
87  if( volName.find("Trap") != std::string::npos ) {
88 
89  // Small Width
90  // ____ Height is the thickness
91  // / \ T of the trapezoid
92  // / \ |
93  // / \ | Length
94  // /__________\ _
95  // Width
96  fHalfHeight = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDy1(); // same as Dy2()
97  fLength = 2.0*((TGeoTrd2*)fTotalVolume->GetShape())->GetDz();
98  fHalfWidth1 = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDx1(); // at -Dz
99  fHalfWidth2 = ((TGeoTrd2*)fTotalVolume->GetShape())->GetDx2(); // at +Dz
100  }
101  else {
102  fHalfWidth1 = ((TGeoBBox*)fTotalVolume->GetShape())->GetDX();
103  fHalfHeight = ((TGeoBBox*)fTotalVolume->GetShape())->GetDY();
104  fLength = 2.0*((TGeoBBox*)fTotalVolume->GetShape())->GetDZ();
106  }
107 
108  }
109 
110  //......................................................................
112  {
113  if(fGeoMatrix) delete fGeoMatrix;
114  return;
115  }
116 
117  //......................................................................
118  /// Transform a position from local frame to world frame
119  /// \param local : 3D array. Position in the local frame Input.
120  /// \param world : 3D array. Position in the world frame. Returned.
121  void AuxDetSensitiveGeo::LocalToWorld(const double* local, double* world) const
122  {
123  fGeoMatrix->LocalToMaster(local,world);
124  }
125 
126  //......................................................................
127  /// Transform a 3-vector from local frame to world frame
128  /// \param local : 3D array. Position in the local frame Input.
129  /// \param world : 3D array. Position in the world frame. Returned.
130  void AuxDetSensitiveGeo::LocalToWorldVect(const double* local, double* world) const
131  {
132  fGeoMatrix->LocalToMasterVect(local,world);
133  }
134 
135  //......................................................................
136  /// Transform a position from world frame to local frame
137  /// \param world : 3D array. Position in the world frame. Input.
138  /// \param local : 3D array. Position in the local frame Returned.
139  void AuxDetSensitiveGeo::WorldToLocal(const double* world, double* local) const
140  {
141  fGeoMatrix->MasterToLocal(world,local);
142  }
143 
144  //......................................................................
145  /// Transform a 3-vector from world frame to local frame
146  /// \param world : 3D array. Position in the world frame. Input.
147  /// \param local : 3D array. Position in the local frame Returned.
148  void AuxDetSensitiveGeo::WorldToLocalVect(const double* world, double* local) const
149  {
150  fGeoMatrix->MasterToLocalVect(world,local);
151  }
152 
153  //......................................................................
154  /// Return the center position of an AuxDet
155  /// \param xyz : 3-D array. The returned location.
156  /// \param localz : Distance along the length of the volume (z)
157  /// (cm). Default is 0.
158  void AuxDetSensitiveGeo::GetCenter(double* xyz, double localz) const
159  {
160  double xyzLocal[3] = {0.,0.,localz};
161  this->LocalToWorld(xyzLocal, xyz);
162  }
163 
164  //......................................................................
165  // Return the unit normal vector (0,0,1) in local coordinates to global coordinates
166  void AuxDetSensitiveGeo::GetNormalVector(double* xyzDir) const
167  {
168  double normal[3]={0.,0.,1.};
169  this->LocalToWorldVect(normal,xyzDir);
170  }
171 
172  //......................................................................
173  // Get the distance from some point to this detector, xyz in global coordinates
174  double AuxDetSensitiveGeo::DistanceToPoint(double * xyz) const
175  {
176  double Center[3];
177  GetCenter(Center);
178  return std::sqrt((Center[0]-xyz[0])*(Center[0]-xyz[0]) +
179  (Center[1]-xyz[1])*(Center[1]-xyz[1]) +
180  (Center[2]-xyz[2])*(Center[2]-xyz[2]));
181  }
182  }
183 } // gar
184 ////////////////////////////////////////////////////////////////////////
TGeoHMatrix * fGeoMatrix
Transformation matrix to world frame.
void GetCenter(double *xyz, double localz=0.0) const
std::string string
Definition: nybbler.cc:12
static const std::string volume[nvol]
double fHalfHeight
half height of volume
AuxDetSensitiveGeo(std::vector< const TGeoNode * > &path, int depth)
void WorldToLocal(const double *world, double *local) const
const TGeoVolume * fTotalVolume
Total volume of AuxDet, called vol*.
void LocalToWorld(const double *local, double *world) const
void LocalToWorldVect(const double *local, double *world) const
double fHalfWidth2
2nd half width (width1==width2 for boxes), at +z/2
General GArSoft Utilities.
#define MF_LOG_DEBUG(id)
double DistanceToPoint(double *xyz) const
void WorldToLocalVect(const double *world, double *local) const
LArSoft geometry interface.
Definition: ChannelGeo.h:16
double fLength
length of volume, along z direction in local
double fHalfWidth1
1st half width of volume, at -z/2 in local coordinates
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void GetNormalVector(double *xyzDir) const