GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
FTDLayerLayoutImpl.cc
1 #include "gear/GEAR.h"
2 #include "gearimpl/FTDLayerLayoutImpl.h"
3 #include <math.h>
4 #include <iostream>
5 #include <stdlib.h>
6 #include <sstream>
7 
8 namespace gear
9 {
10  void FTDLayerLayoutImpl::addLayer(int nPetals, int nSensors, bool isDoubleSided, int sensorType, double petalOpAngle, double phi0, double alpha,
11  // common for support and sensitive
12  double zposition, double zoffset, double zsignpetal0,
13  // support
14  //double supportZposlayer,
15  double supportRinner, double supportThickness,
16  double supportLengthMin, double supportLengthMax,
17  double supportWidth,
18  double supportRadLength,
19  // sensitive
20  //double sensitiveZposlayer,
21  double sensitiveRinner, double sensitiveThickness,
22  double sensitiveLengthMin, double sensitiveLengthMax,
23  double sensitiveWidth,
24  double sensitiveRadLength )
25 {
26  Layer lL, sL ;
27 
28  lL.nPetals = nPetals ;
29  lL.nSensors = nSensors;
30  lL.isDoubleSided = isDoubleSided;
31  lL.sensorType = sensorType;
32  //lL.phi = phi ;
33  lL.petalOpenningAngle= petalOpAngle;
34  lL.phi0 = phi0;
35  lL.alpha = alpha;
36  lL.zposition = zposition; //supportZposlayer ;
37  lL.zoffset = zoffset;
38  lL.zsign0 = zsignpetal0;
39  lL.rInner = supportRinner;
40  lL.lengthMin = supportLengthMin;
41  lL.lengthMax = supportLengthMax;
42  lL.thickness = supportThickness;
43  lL.width = supportWidth ;
44  lL.radLength = supportRadLength ;
45 
46  sL.nPetals = nPetals ;
47  sL.nSensors = nSensors;
48  sL.isDoubleSided = isDoubleSided;
49  sL.sensorType = sensorType;
50  //sL.phi = phi ;
51  sL.petalOpenningAngle= petalOpAngle;
52  sL.phi0 = phi0;
53  sL.alpha = alpha;
54  sL.zposition = zposition; //sensitiveZposlayer;
55  sL.zoffset = zoffset;
56  sL.zsign0 = zsignpetal0;
57  sL.rInner = sensitiveRinner;
58  sL.thickness = sensitiveThickness;
59  sL.lengthMin = sensitiveLengthMin;
60  sL.lengthMax = sensitiveLengthMax;
61  sL.width = sensitiveWidth ;
62  sL.radLength = sensitiveRadLength ;
63 
64  _lVec.push_back( lL ) ;
65  _sVec.push_back( sL ) ;
66 
67  // Get the references frames defining the trapezoid
68  //FIXME: TO BE DEPRECATED
69  _eL = getframe( lL );
70  _eS = getframe( sL );
71 }
72 
73 
74 // Correct the index of the layer in order to return a value < 7
75 // (layers symmetric in z)
76 int FTDLayerLayoutImpl::getEquivLayer(const int & layerIndex) const
77 {
78 //FIXME: TO DEBUG!!
79  int correctedId = -1;
80  // Using the index of the vectors 0->2N-1
81  if( layerIndex > 6)
82  {
83  correctedId = layerIndex-getNLayers();
84  }
85  else
86  {
87  correctedId = layerIndex;
88  }
89 
90  if( correctedId < 0 )
91  {
92  std::cout << "The disk layer introduced is not in the right format. Use the description:\n " <<
93  "Z-Positives disks: 0,1,...,N-1\n " <<
94  "Z-negatives disks: 7,8,...,2N-1\n" << std::endl;
95  }
96 
97  return correctedId;
98 
99 }
100 
101 // Return the Z position defined in the centroid of the sensitive
102 double FTDLayerLayoutImpl::getSupportZposition(const int & layerIndex, const int & petalIndex) const
103 {
104  int layerId = getEquivLayer(layerIndex);
105 
106  Layer petal = _lVec.at(layerId);
107  // Extract if the zoffset is positive or negative: id=0 -> zsign0, id=1--> -zsign0, and so on
108  int offsetsign = petal.zsign0*(int)pow((double)-1,(double)petalIndex);
109 
110  double zpos = petal.zposition+offsetsign*petal.zoffset;
111  // Taking into account the negative disks
112  // RECALL: all the z-position are positives (by definition we used for
113  // the z-negative disks (-1)*zposition
114  int finalsign = 1;
115  if( layerId != layerIndex )
116  {
117  finalsign = -1;
118  }
119 
120  return finalsign*zpos;
121 }
122 
123 // Return the Z position defined in the centroid of the sensitive
124 double FTDLayerLayoutImpl::getSensitiveZposition(const int & layerIndex, const int & petalIndex,
125  const int & sensorIndex) const
126 {
127  double zsupport = getSupportZposition(layerIndex,petalIndex);
128  int layerId = getEquivLayer(layerIndex);
129 
130  // Extract if the sensor is back to IP or facing the IP
131  int zdisksign = (int)(zsupport/fabs(zsupport));
132  int sign = -zdisksign; // the direction of the sensor: we start with a value directed to the IP -> if disk is at +z , the direction is - and vice versa
133 
134  if( ( _lVec.at(layerId).isDoubleSided )&&( sensorIndex > _lVec.at(layerId).nSensors/2 ) ){ // If the sensor is on the back
135 
136  sign = zdisksign; //the it looks into the other direction
137 
138  }
139 
140  if( sensorIndex > _lVec.at(layerId).nSensors || sensorIndex < 1 )
141  {
142  std::stringstream ss ;
143  ss << "FTDLayerLayoutImpl::getSensitiveZposition Error!!"
144  << " The Sensor Index \'" << sensorIndex
145  << "\' is out of range. There are only sensors from 1 to " << _lVec.at(layerId).nSensors << " !"
146  << std::endl;
147 
148  throw gear::Exception( ss.str() ) ;
149  }
150  double petalthickness = _lVec.at(layerId).thickness;
151  double sensorthickness = _sVec.at(layerId).thickness;
152  double zpos = zsupport+sign*(petalthickness+sensorthickness)/2.0;
153 
154  return zpos;
155 }
156 
157 
158 
159 // Returns the phi of the petal centroid with respect to the x-axis
160 double FTDLayerLayoutImpl::getPhiPetalCd(const int & layerIndex, const int & petalIndex) const
161 {
162  int layerId = getEquivLayer(layerIndex);
163 
164  return _lVec.at(layerId).phi0+
165  (double)petalIndex*2.0*_lVec.at(layerId).petalOpenningAngle;
166 }
167 
168 // Returns the maximum radius for a given layer (No le veo utilidad aun)
169 double FTDLayerLayoutImpl::getMaxRadius(const int & layerIndex, const bool & sensitive ) const
170 {
171  Layer l ;
172  if(!sensitive)
173  {
174  l = _lVec.at( layerIndex );
175  }
176  else
177  {
178  l = _sVec.at( layerIndex );
179  }
180 
181  return l.rInner+l.width;
182 }
183 
184 
185 // returns starting phi for first petal in layer (on side to IP) (No le veo utilidad)
186  double FTDLayerLayoutImpl::getStartPhi(const int &layerIndex,const int &/*petalIndex*/,const bool &sensitive ) const
187 {
188  Layer l ;
189  if ( !sensitive )
190  {
191  l = _lVec.at( layerIndex ) ;
192  }
193  else {
194  l = _sVec.at( layerIndex ) ;
195  }
196 
197  const double endphi = 0.0; // FIXME: PROV getPhiPetalCd(layerIndex,petalIndex,sensitive);
198 
199  return endphi-2.0*l.phi0 ;
200 }
201 
202 // returns ending phi for first petal in layer (on side to IP). It corresponds with
203 // the phi where is defined the frame
204  double FTDLayerLayoutImpl::getEndPhi( const int & /*layerIndex*/ , const int & /*petalIndex*/, const bool & /*sensitive*/ ) const
205 {
206  //return getPhiPetalCd(layerIndex,petalIndex,sensitive);
207  return 0.0; //FIXME
208 }
209 
210 
211 // returns thickness under a certain incident angle
212 double FTDLayerLayoutImpl::getThicknessForAngle(const int & layerIndex,const double & theta,
213  const double & phi,const bool & sensitive ) const
214 {
215  Layer l ;
216  if (!sensitive) {
217  l = _lVec.at( layerIndex ) ;
218  }
219  else {
220  l = _sVec.at( layerIndex ) ;
221  }
222 
223  double angularThickness ;
224 
225  // Nota que falta comprobar:
226  // -si entra por el petalo
227  // -cual es la distancia que recorre antes de salir
228  // -para ello hay que controlar si sale antes de que
229  // acabe el petalo, en Y es fácil pero en x, al ser
230  // un petalo, la distancia es variable y dependera
231  // de la zona Y de salida del rayo
232  // -controlar y prohibir angulos que no esten en
233  // theta\in[0,PI/2) phi\in(0,PI/2]
234  angularThickness = l.thickness*sqrt(1.0/(sin(theta)*sin(theta))+tan(phi)*tan(phi));
235 
236  return angularThickness;
237 
238  // first check if layer is completely out of petal
239 /* if( phi < getStartInnerPhi( layerIndex , sensitive ) || phi > getEndInnerPhi( layerIndex, sensitive ) ) {
240  return -1 ;
241  }
242 
243  // check if angle is withhin outer boundaries - easy calculation then
244  if( phi >= getStartOuterPhi( layerIndex , sensitive ) && phi <= getEndOuterPhi( layerIndex , sensitive ) ) {
245  return ( l.Thickness / cos( phi ) ) ;
246  }*/
247 }
248 
249 // Return the reference frame defining a petal (sensitive)
250 std::vector<vframe> FTDLayerLayoutImpl::getframe( const Layer & l )
251 {
252  // The e1 corresponds directly with x-axis
253  vframe e1(1.0, 0.0, 0.0);
254  // the e2 corresponds directly with the z-axis with changed sign
255  // (this is done in order to keep the positive definition)
256  vframe e2(0.0,0.0,-1.0);
257  // the e3 corresponds with the y-axis with an inclination angle (sigma)
258  // defining the trapezoid
259  double sigma = atan( l.width/((l.lengthMax-l.lengthMin)/2.0) );
260  vframe e3(0.0,cos(sigma),sin(sigma));
261 
262  std::vector<vframe> fr;
263  fr.reserve(3);
264  fr[0] = e1;
265  fr[1] = e2;
266  fr[2] = e3;
267 
268  return fr;
269 }
270 
271 
272 
273 } //namespace
virtual double getThicknessForAngle(const int &layerIndex, const double &tetha, const double &phi, const bool &sensitive=false) const
returns thickness as viewed under the incidence angles phi and theta in layer layerIndex.
virtual int getNLayers() const
The total number of layers (z-positives and z-negatives disks).
virtual double getPhiPetalCd(const int &layerIndex, const int &petalIndex) const
Azimuthal angle of the petal petalIndex Centroid at layer layerIndex.
Base exception class for GEAR - all other exceptions extend this.
Definition: GEAR.h:41
virtual double getMaxRadius(const int &layerIndex, const bool &sensitive=false) const
returns maximum radius for a given layer
virtual double getSupportZposition(const int &layerIndex, const int &petalIndex) const
The position of the support in z direction in mm for the petalIndex petal in layer layerIndex - layer...
virtual double getEndPhi(const int &layerIndex, const int &petalInd, const bool &sensitive=false) const
returns ending phi for first petal in layer layerIndex (on side facing IP)
virtual double getSensitiveZposition(const int &layerIndex, const int &petalIndex, const int &sensorIndex) const
The position of the sensitive in z direction in mm for sensor sensorIndex of the petal support petalI...
virtual bool isDoubleSided(int layerIndex) const
Whether the petals on a layer have sensors in front and back.
Abstract description of layers in a FTD detector.
Helper class for layer properties.
virtual void addLayer(int nPetals, int nSensors, bool isDoubleSided, int sensorType, double petalOpAngle, double phi0, double alpha, double zposition, double zoffset, double zsign0, double supportRinner, double supportThickness, double supportLengthMin, double supportLengthMax, double supportWidth, double supportRadLength, double sensitiveRinner, double sensitiveThickness, double sensitiveLengthMin, double sensitiveLengthMax, double sensitiveWidth, double sensitiveRadLength)
Add a new layer at the given position.
virtual double getStartPhi(const int &layerIndex, const int &petalInd, const bool &sensitive=false) const
returns starting phi for first petal in layer layerIndex (on side facing IP)