StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtGeom.h
1 /* StFgtGeom.h
2  *
3  * FGT geometry class declaration.
4  *
5  * \author W. Witzke (wowitz0@uky.edu)
6  *
7  */
8 
9 #ifndef _ST_FGT_GEOM_H_
10 #define _ST_FGT_GEOM_H_
11 
12 //#include <assert.h>
13 #include <TVector3.h>
14 #include <string>
15 #include <sstream>
16 #include <cstdlib>
17 #include <cmath>
18 #include <iostream>
19 #include <algorithm>
20 #include "StRoot/StFgtUtil/StFgtConsts.h"
21 
22 
23 // StFgtGeom is a "singleton" class. Only one of it needs to exist in any
24 // program. However, because the data contained in this class is entirely
25 // static, the class itself is also entirely static.
26 class StFgtGeom
27 {
28  public:
29 
30  // For all functions where they appear: Disc can be >= 0 (in theory,
31  // although only values 0-5 work at the moment, I believe). Quadrant
32  // is 0-3. Layer is 'P' or 'R'. Strip is 0-720
33 
34  // Location of disks in Z. these values for now are copied from
35  // FgtdGeo3.xml, should come from vmc eventually
36  static Double_t getDiscZ(int iDisc);
37 
38  //geoId is a unique number used to identify a specific strip
39  //on a specific disk/quadrant/layer/strip. Please NOTE:
40  //The set of geoIds IS NOT CONTINUOUS simply becuase strip
41  //number is not continuous. On the R plane strips 280-399
42  //are not implemented.
43  static Int_t encodeGeoId( Int_t disc, Int_t quadrant,
44  Char_t layer, Int_t strip );
45  static Int_t decodeGeoId( Int_t geoId, Short_t & disc,
46  Short_t & quadrant, Char_t & layer,
47  Short_t & strip );
48 
49 
50  //Geoname is human readable form of geoId
51  static std::string encodeGeoName( Int_t disc, Int_t quadrant,
52  Char_t layer, Int_t strip );
53  static Int_t decodeGeoName( const std::string & geoName, Short_t & disc,
54  Short_t & quadrant, Char_t & layer,
55  Short_t & strip );
56  static std::string translateGeoIdToGeoName( Int_t geoId );
57  static Int_t translateGeoNameToGeoId( const std::string & geoName );
58 
59  //Returns range upper and lower range of R or Phi valus depending on geoId.
60  //NOTE phi values are only local - that is they are the same for each quadrant
61  //The ordinate, lowerSpan and upperSpan are all in centimeters or radians
62  static Int_t getPhysicalCoordinate( Int_t geoId, Short_t & disc,
63  Short_t & quadrant, Char_t & layer,
64  Double_t & ordinate,
65  Double_t & lowerSpan,
66  Double_t & upperSpan );
67 
68 
69 
70  //Returns range upper and lower range of R or Phi valus depending on geoName.
71  //NOTE phi values are only local - that is they are the same for each quadrant
72  //The ordinate, lowerSpan and upperSpan are all in centimeters or radians
73  static Int_t getPhysicalCoordinate( const std::string & geoName,
74  Short_t & disc, Short_t & quadrant,
75  Char_t & layer, Double_t & ordinate,
76  Double_t & lowerSpan,
77  Double_t & upperSpan );
78 
79 
80  //Similar to getPhysicalCoordinate but returns phi in STAR coordinate system
81  //This returns ideal position without alignments. Use StFgtDb::getStarXYZ() to get XYZ in STAR coordinate with alignment
82  static Int_t getGlobalPhysicalCoordinate( Int_t geoId, Short_t & disc,
83  Short_t & quadrant, Char_t & layer,
84  Double_t & ordinate,
85  Double_t & lowerSpan,
86  Double_t & upperSpan );
87 
88  //Similar to getPhysicalCoordinate but returns phi in STAR coordinate system
89  //This returns ideal position without alignments. Use StFgtDb::getStarXYZ() to get XYZ in STAR coordinate with alignment
90  static Int_t getGlobalPhysicalCoordinate( const std::string & geoName,
91  Short_t & disc, Short_t & quadrant,
92  Char_t & layer, Double_t & ordinate,
93  Double_t & lowerSpan,
94  Double_t & upperSpan );
95 
96  // This gives center of quadrant XYZ in STAR coordinate
97  // This does NOT get modified by alignment parameters.
98  static void getQuadCenterXYZ(Short_t disc, Short_t quad, TVector3 &xyz);
99 
100  // Please note that the following functions do NOT access the STAR
101  // database to find mapping information. They assume the most
102  // straight-forward mapping scheme and use that.
103  // For those functions that have them, currently rdo can be 1-2, arm
104  // can be 0-5, apv can be 0-23 (although 10, 11, 22, and 23 are not
105  // technically valid) and channel is 0-127. To access database
106  // functions please use functions in StFgtDb.h
107 
108  // Electronic Id is determined from the electronic devices
109  // rdo/arm/apv/channel and does form a continuous set of integers.
110  // The mapping from geoId to electronicId is accessible via the
111  // database or from "naive" functions below
112 
113  static Int_t encodeElectronicId( Int_t rdo, Int_t arm,
114  Int_t apv, Int_t channel );
115 
116  static Int_t decodeElectronicId( Int_t elecId, Int_t &rdo, Int_t &arm,
117  Int_t &apv, Int_t &channel );
118  static Int_t getElectIdFromElecCoord( Int_t rdo, Int_t arm,
119  Int_t apv, Int_t ch );
120  static Int_t getElecCoordFromElectId( Int_t eID, Int_t& rdo, Int_t& arm,
121  Int_t& apv, Int_t& ch );
122 
123  // get the octant for a given layer and strip
124  static Char_t getOctant( Char_t layer, Int_t strip );
125 
126  // get the octant given the APV number
127  static Char_t getOctant( Int_t apv );
128 
129  // get the octant given a phi in radians
130  // maps to i8: 0=A.L, 1=A.S, 2=B.L, .... 7=D.S
131  static Int_t getOctant( Double_t phi);
132 
133  static Int_t getNaiveGeoIdFromElecCoord( Int_t rdo, Int_t arm,
134  Int_t apv, Int_t channel );
135  static Int_t getNaiveElecCoordFromGeoId( Int_t geoId, Int_t& rdo,
136  Int_t& arm, Int_t& apv,
137  Int_t& channel );
138  static std::string getNaiveGeoNameFromElecCoord( Int_t rdo, Int_t arm,
139  Int_t apv,
140  Int_t channel );
141  static Int_t getNaivePhysCoordFromElecCoord( Int_t rdo, Int_t arm,
142  Int_t apv, Int_t channel,
143  Short_t & disc,
144  Short_t & quadrant,
145  Char_t & layer,
146  Double_t & ordinate,
147  Double_t & lowerSpan,
148  Double_t & upperSpan );
149 
150  // This is similar to the above functions, but it takes electronic
151  // coordinates and only returns the final ordinate. This is here
152  // primarily so that it can be used as a drop in replacement for
153  // older code that has similar functionality.
154  static Double_t getNaiveMapping( Int_t rdo, Int_t arm,
155  Int_t apv, Int_t channel );
156  static bool isNaiveR( Int_t rdo, Int_t arm, Int_t apv, Int_t channel );
157 
158  // Jan's necessary functions start here. These were written by Jan,
159  // modified slightly by me.
160  // Jan: I have adjusted the dimensions to match FGT as build, September, 2011
161  static double rIn() { return kFgtRin; }
162  static double rMid() { return kFgtRmid; }
163  static double rOut() { return kFgtRout; }
164  static double rFirst() { return kFgtRfirst; }
165  static double rLast() { return kFgtRlast;}
166  static double pFirst() { return kFgtPfirst; }
167  static double pLast() { return kFgtPlast;}
168 
169  static double radStrip_pitch() { return kFgtRadPitch; } // cm
170  static double phiStrip_pitch() { return kFgtPhiAnglePitch; } // rad
171 
172  static double yLimit() { return kFgtRout; }
173 
174  // deadQuadEdge is in cm, local ref frame
175  static double deadQuadEdge() { return kFgtDeadQuadEdge; }
176 
177  static double radStripOff() { return mRadStripOff; }
178  static double phiStripOff() { return mPhiStripOff; }
179 
180  static double phiQuadXaxis(int iquad);
181  static bool inDisc( TVector3 rLab );
182  static bool belowFlat( TVector3 rLoc );
183  static int getQuad( double phiLab );
184 
185  // What follows are some functions to help with the
186  // localXYtoStripID function. These are also written by Jan, modified
187  // slightly by me.
188 
189  // These next two return -1 on error.
190  static int rad2LocalStripId( double rad, double phi,
191  double *binFrac=0 );
192  static int phi2LocalStripId( double rad, double phi,
193  double *binFrac=0 );
194 
195  static double rStrip_Phi_High(int rindex);//return upper phi range for an r strip
196  static double rStrip_Phi_Low(int rindex);//return lower phi range for an r strip
197  static double pHistrip_R_Low(int pindex);//return lower r range for a phi strip
198  static double pHistrip_R_High(int pindex);//return upper r range for a phi strip
199 
200  protected:
201  // StFgtGeomData stores data on each ordinate associated with each
202  // global ID used to index individual geometry elements.
204  {
205  Bool_t isPhi;
206  Double_t ordinate;
207  Double_t lowerSpan;
208  Double_t upperSpan;
209  };
210 
211  friend class StFgtDbFileMaker;
212 
213 
214  // Various constants used in Jan's conversion functions.
215  static double mPi;
216  static double mHalfPi;
217  static double mRadStripOff;
218  static double mPhiStripOff;
219  static int mRadStripLOCId_number;
220  static int mPhiStripLOCId_number;
221 
222 
223  // ---Private member variables---
224  static StFgtGeomData mStrips[ 2*kFgtNumStrips ];
225 
226  // maps from (apv*128 + channel) to ((layer=='P')*kFgtNumStrips + stripID)
227  static Int_t mNaiveMapping[ kFgtNumChannels*kFgtApvsPerQuad ];
228 
229  // reverse mapping: ((layer=='P')*kFgtNumStrips + stripID) to (apv*128 + channel)
230  static Bool_t mReverseNaiveMappingValid;
231  static Int_t mReverseNaiveMapping[ 2*kFgtNumStrips ];
232  static void makeReverseNaiveMappingValid();
233 
234 
235  private:
236 
237  // Calculates coordinates of strip in global coordinate system
238  // Units are in cm andradians, depending on the layer.
239  static Int_t computeGlobalPhysicalCoordinate(Short_t & quadrant, Char_t & layer,
240  Double_t & ordinate, Double_t & lowerSpan,
241  Double_t & upperSpan, Short_t & strip);
242 };
243 
244 inline Int_t StFgtGeom::getElectIdFromElecCoord
245 (
246  Int_t rdo, Int_t arm, Int_t apv, Int_t ch
247 )
248 {
249  return encodeElectronicId(rdo,arm,apv,ch);
250 }
251 
252 inline Int_t StFgtGeom::getElecCoordFromElectId
253 (
254  Int_t eID,
255  Int_t& rdo, Int_t& arm, Int_t& apv, Int_t& ch
256 )
257 {
258  return decodeElectronicId(eID,rdo,arm,apv,ch);
259 }
260 
261 //get the octant given the phi in radians
262 inline Int_t StFgtGeom::getOctant( Double_t phi )
263 {
264  double phiDeg= 75 - ((phi*180)/mPi);
265  while ( phiDeg < 0 ) phiDeg+=360;
266  while ( phiDeg > 360 ) phiDeg-=360;
267  int i8=phiDeg/45;
268  return i8;
269 }
270 
271 inline std::string StFgtGeom::getNaiveGeoNameFromElecCoord
272 (
273  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
274 )
275 {
276  return
277  translateGeoIdToGeoName(
278  getNaiveGeoIdFromElecCoord( rdo, arm, apv, channel )
279  );
280 }
281 
282 inline Int_t StFgtGeom::getNaivePhysCoordFromElecCoord
283 (
284  Int_t rdo, Int_t arm, Int_t apv, Int_t channel,
285  Short_t & disc, Short_t & quadrant, Char_t & layer,
286  Double_t & ordinate, Double_t & lowerSpan, Double_t & upperSpan
287 )
288 {
289  return getPhysicalCoordinate(
290  getNaiveGeoIdFromElecCoord( rdo, arm, apv, channel ),
291  disc, quadrant, layer, ordinate, lowerSpan, upperSpan
292  );
293 }
294 
295 #endif
296 
297 
298 /*
299  * $Id: StFgtGeom.h,v 1.45 2013/01/31 15:44:27 akio Exp $
300  * $Log: StFgtGeom.h,v $
301  * Revision 1.45 2013/01/31 15:44:27 akio
302  * Adding getQuadCenterXYZ
303  *
304  * Revision 1.44 2012/08/15 18:02:59 rfatemi
305  * Bug fix in getGlobalPhysicalCoordinate by pnord, computation now done by computeGlobalPhysicalCoordinate
306  *
307  * Revision 1.43 2012/05/11 19:45:02 rfatemi
308  * added getGlobalPhysicalCoordinate
309  *
310  * Revision 1.42 2012/03/15 00:18:12 wwitzke
311  * Added boundary conditions to StFgtGeom.
312  *
313  * Revision 1.41 2012/03/14 02:05:48 rfatemi
314  * adding in getOctant from phi access function
315  *
316  * Revision 1.40 2012/03/14 00:58:56 rfatemi
317  * added documentation
318  *
319  * Revision 1.39 2012/03/07 20:31:43 avossen
320  * corrected z disc z position
321  *
322  * Revision 1.38 2012/02/09 18:23:24 wwitzke
323  * Fixed various minor issues, including nesting the StFgtGeomData, making the
324  * various "pi" variables use the TMath definions of pi, and removing the various
325  * asserts from the code.
326  *
327  * Revision 1.37 2012/02/09 17:52:03 wwitzke
328  * Changed organization of StFgtGeom to put inline functions after class body.
329  * Also moved getNaiveElecCoordFromGeoId to .cxx as a non-inline function.
330  *
331  * Revision 1.36 2012/02/09 17:05:58 wwitzke
332  * Fixed public/protected/private problems (moved some members from public to
333  * protected, consolidated public methods).
334  *
335  * Revision 1.35 2012/02/09 17:00:10 wwitzke
336  * Modified some variable names to conform to standard naming conventions.
337  *
338  * Revision 1.33 2012/01/31 15:34:23 rfatemi
339  * make it a friend of StFgtDbMaker which lives in StFgtPool
340  *
341  * Revision 1.32 2012/01/28 10:46:37 sgliske
342  * Forgot to include assert, and removing unneeded TObject include
343  *
344  * Revision 1.31 2012/01/28 10:29:47 sgliske
345  * static const doubles moved from StFgtGeom to StFgtConsts
346  * Also, geoName updated to more recent convention
347  * disc in 1-6, quad in A-D, strip in 0-719
348  *
349  * Revision 1.30 2012/01/27 13:21:25 rfatemi
350  * used only constants declared in enums in StFgtConsts.h
351  *
352  * Revision 1.29 2012/01/26 18:41:49 balewski
353  * fixing , new constants
354  *
355  * Revision 1.28 2012/01/26 13:13:12 sgliske
356  * Updated to use StFgtConsts, which
357  * replaces StFgtEnums and StFgtGeomDefs
358  *
359  * Revision 1.27 2012/01/19 16:27:27 rfatemi
360  * Move encode(decode) ElectronicId from StFgtDbImp.h
361  *
362  * Revision 1.26 2012/01/18 18:22:31 sgliske
363  * added function getElecCoordFromElectId
364  *
365  * Revision 1.25 2012/01/13 19:10:41 rfatemi
366  * included getElectIdfromElecCoord to calculate electronic id from RDO,ARM,APVmod,CH
367  *
368  * Revision 1.24 2011/11/06 22:34:34 rfatemi
369  * implement phi2LocalStripId
370  *
371  * Revision 1.23 2011/11/05 02:24:56 rfatemi
372  * add phi2LocalStripId
373  *
374  * Revision 1.22 2011/11/03 20:04:41 avossen
375  * added simple function to get disc z
376  *
377  * Revision 1.21 2011/10/13 21:02:15 balewski
378  * cleanup of not needed intermediate methods
379  *
380  * Revision 1.20 2011/10/11 15:56:15 rfatemi
381  * add in new access functions
382  *
383  * Revision 1.19 2011/10/09 13:36:44 rfatemi
384  * Update with Rlast and Rfirst for location of R strips
385  *
386  * Revision 1.18 2011/10/07 19:43:32 balewski
387  * make method public
388  *
389  * Revision 1.17 2011/10/07 03:42:38 rfatemi
390  * Updates to get strip Id from radius r
391  *
392  * Revision 1.16 2011/10/06 15:16:15 sgliske
393  * fixed spaces before Log: and Id:
394  *
395  *
396  */