StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StGmtGeom.h
1 /* StGmtGeom.h
2  *
3  * GMT geometry class declaration.
4  *
5  * \authors K.S. Engle and Richard Witt (witt@usna.edu)
6  * based on StFgtGeom
7  */
8 
9 #ifndef _ST_GMT_GEOM_H_
10 #define _ST_GMT_GEOM_H_
11 
12 #include <TVector3.h>
13 #include <string>
14 #include <sstream>
15 #include <cstdlib>
16 #include <cmath>
17 #include <iostream>
18 #include <algorithm>
19 #include "StRoot/StGmtUtil/StGmtConsts.h"
20 
21 
22 // StGmtGeom is a "singleton" class. Only one of it needs to exist in any
23 // program. However, because the data contained in this class is entirely
24 // static, the class itself is also entirely static.
25 class StGmtGeom {
26 
27  public:
28  // For all functions where they appear: Disc can be >= 0 (in theory,
29  // although only values 0-5 work at the moment, I believe). Quadrant
30  // is 0-3. Layer is 'P' or 'R'. Strip is 0-720
31 
32  // Location of modules in Z.
33  static Double_t getModuleZ(int iModule = -999);
34 
35  // Location of modules in phi.
36  static Double_t getModulePhi(int iModule = -999);
37 
38  static Int_t getNaiveMapping(Int_t idx) { return mNaiveMapping[ idx ]; }
39 
40  // geoId is a unique number used to identify a specific strip
41  // on a specific disk/quadrant/layer/strip. Please NOTE:
42  // The set of geoIds IS NOT CONTINUOUS simply becuase strip
43  // number is not continuous. On the R plane strips 280-399
44  // are not implemented.
45  // static Int_t encodeGeoId( Int_t module, Char_t layer, Int_t strip );
46  static Int_t encodeGeoId(Int_t rdo = -999, Int_t arm = -999, Int_t apv = -999, Int_t channel = -999);
47  // static Int_t decodeGeoId( Int_t geoId, Short_t & module, Char_t & layer, Short_t & strip );
48  static Int_t decodeGeoId(Int_t geoId, Short_t &module, Int_t &layer, Short_t &strip);
49 
50 
51  // Geoname is human readable form of geoId
52  static std::string encodeGeoName(Int_t module = -999, Char_t layer = -120, Int_t strip = -999);
53  // static Int_t decodeGeoName( const std::string & geoName, Short_t & module, Char_t & layer, Short_t & strip );
54  static Int_t decodeGeoName(const std::string &geoName, Short_t &module, Int_t &layer, Short_t &strip);
55  static std::string translateGeoIdToGeoName(Int_t geoId = -999);
56 
57  // Returns range upper and lower range of R or Phi valus depending on geoId.
58  // NOTE phi values are only local - that is they are the same for each quadrant
59  // The ordinate, lowerSpan and upperSpan are all in centimeters or radians
60  // static Int_t getPhysicalCoordinate( Int_t geoId, Short_t & module, Char_t & layer);
61  static Int_t getPhysicalCoordinate(Int_t geoId, Short_t &module, Int_t &layer);
62 
63 
64 
65  // Returns range upper and lower range of R or Phi valus depending on geoName.
66  // NOTE phi values are only local - that is they are the same for each quadrant
67  // The ordinate, lowerSpan and upperSpan are all in centimeters or radians
68  // static Int_t getPhysicalCoordinate( const std::string & geoName, Short_t & module, Char_t & layer);
69  static Int_t getPhysicalCoordinate(const std::string &geoName, Short_t &module, Int_t &layer);
70 
71 
72  // Similar to getPhysicalCoordinate but returns phi in STAR coordinate system
73  // static Int_t getGlobalPhysicalCoordinate( Int_t geoId, Short_t & module, Char_t & layer);
74  static Int_t getGlobalPhysicalCoordinate(Int_t geoId, Short_t &module, Int_t &layer);
75 
76  //Similar to getPhysicalCoordinate but returns phi in STAR coordinate system
77  // static Int_t getGlobalPhysicalCoordinate( const std::string & geoName,
78  // Short_t & module,
79  // Char_t & layer);
80  static Int_t getGlobalPhysicalCoordinate(const std::string &geoName, Short_t &module, Int_t &layer);
81 
82  static Int_t getCoordNumFromElecCoord(Int_t rdo = -999, Int_t arm = -999, Int_t apv = -999, Int_t channel = -999);
83  static Double_t getPositionFromElecCoord(Int_t rdo = -999, Int_t arm = -999, Int_t apv = -999, Int_t channel = -999);
84 
85  // Please note that the following functions do NOT access the STAR
86  // database to find mapping information. They assume the most
87  // straight-forward mapping scheme and use that.
88  // For those functions that have them, currently rdo can be 1-2, arm
89  // can be 0-5, apv can be 0-23 (although 10, 11, 22, and 23 are not
90  // technically valid) and channel is 0-127. To access database
91  // functions please use functions in StGmtDb.h
92 
93  // Electronic Id is determined from the electronic devices
94  // rdo/arm/apv/channel and does form a continuous set of integers.
95  // The mapping from geoId to electronicId is accessible via the
96  // database or from "naive" functions below
97 
98  static Int_t encodeElectronicId(Int_t rdo = -999, Int_t arm = -999, Int_t apv = -999, Int_t channel = -999);
99 
100  static Int_t decodeElectronicId(Int_t elecId, Int_t &rdo, Int_t &arm, Int_t &apv, Int_t &channel);
101  static Int_t getElectIdFromElecCoord(Int_t rdo = -999, Int_t arm = -999, Int_t apv = -999, Int_t ch = -999) { return encodeElectronicId(rdo,arm,apv,ch); }
102  static Int_t getElecCoordFromElectId(Int_t eID, Int_t& rdo, Int_t& arm, Int_t& apv, Int_t& ch) { return decodeElectronicId(eID,rdo,arm,apv,ch); }
103 
104  static Short_t getModuleIdFromElecCoord(Int_t rdo = -999, Int_t arm = -999, Int_t apv = -999);
105 
106  // get the octant for a given layer and strip
107  static Char_t getOctant(Char_t layer = -120, Int_t strip = -999);
108 
109  // get the octant given the APV number
110  static Char_t getOctant(Int_t apv = -999);
111 
112  // get the octant given a phi in radians
113  // maps to i8: 0=A.L, 1=A.S, 2=B.L, .... 7=D.S
114  static Int_t getOctant(Double_t phi = 0.);
115 
116  static Int_t getNaiveGeoIdFromElecCoord(Int_t rdo = -999, Int_t arm = -999, Int_t apv = -999, Int_t channel = -999);
117  static Int_t getNaiveElecCoordFromGeoId(Int_t geoId, Int_t& rdo, Int_t& arm, Int_t& apv, Int_t& channel);
118  static std::string getNaiveGeoNameFromElecCoord(Int_t rdo = -999, Int_t arm = -999, Int_t apv = -999, Int_t channel = -999);
119  static Int_t getNaivePhysCoordFromElecCoord(Int_t rdo, Int_t arm, Int_t apv, Int_t channel, Short_t &module, Char_t &layer);
120 
121  // This is similar to the above functions, but it takes electronic
122  // coordinates and only returns the final ordinate. This is here
123  // primarily so that it can be used as a drop in replacement for
124  // older code that has similar functionality.
125  static Double_t getNaiveMapping(Int_t rdo = -999, Int_t arm = -999, Int_t apv = -999, Int_t channel = -999);
126  static bool isNaiveR(Int_t rdo = -999, Int_t arm = -999, Int_t apv = -999, Int_t channel = -999);
127 
128  // Jan's necessary functions start here. These were written by Jan,
129  // modified slightly by me.
130  // Jan: I have adjusted the dimensions to match GMT as build, September, 2011
131  // static double rIn() { return kGmtRin; }
132  // static double rMid() { return kGmtRmid; }
133  // static double rOut() { return kGmtRout; }
134  static double sFirst() { return kGmtSfirst; }
135  static double sLast() { return kGmtSlast; }
136  static double pFirst() { return kGmtPfirst; }
137  static double pLast() { return kGmtPlast; }
138 
139  // static double radStrip_pitch() { return kGmtRadPitch; } // cm
140  // static double phiStrip_pitch() { return kGmtPhiAnglePitch; } // rad
141  static double xStrip_pitch() { return kGmtXPitch; } // cm
142  static double yStrip_pitch() { return kGmtYPitch; } // cm
143 
144  // static double yLimit() { return kGmtRout; }
145 
146  // deadQuadEdge is in cm, local ref frame
147  // static double deadQuadEdge() { return kGmtDeadQuadEdge; }
148 
149  // static double radStripOff() { return mRadStripOff; }
150  // static double phiStripOff() { return mPhiStripOff; }
151  // static double StripOff() { return mStripOff; }
152  // static double PadOff() { return mPadOff; }
153 
154  // static double phiQuadXaxis(int iquad);
155  // static bool inDisc( TVector3 rLab );
156  // static bool belowFlat( TVector3 rLoc );
157  // static int getQuad( double phiLab );
158  static bool inModule( TVector3 rLab );
159 
160  // What follows are some functions to help with the
161  // localXYtoStripID function. These are also written by Jan, modified
162  // slightly by me.
163 
164  // These next two return -1 on error.
165  static int rad2LocalStripId(double rad = 0., double phi = 0., double *binFrac=0 );
166  static int phi2LocalStripId(double rad = 0., double phi = 0., double *binFrac=0 );
167 
168  // static double rStrip_Phi_High(int rindex);//return upper phi range for an r strip
169  // static double rStrip_Phi_Low(int rindex);//return lower phi range for an r strip
170  // static double pHistrip_R_Low(int pindex);//return lower r range for a phi strip
171  // static double pHistrip_R_High(int pindex);//return upper r range for a phi strip
172 
173  protected:
174 
175  // StGmtGeomData stores data on each ordinate associated with each
176  // global ID used to index individual geometry elements.
177  // struct StGmtGeomData
178  // {
179  // // Bool_t isPhi;
180  // // Double_t ordinate;
181  // // Double_t lowerSpan;
182  // // Double_t upperSpan;
183  // Bool_t isX;
184  // Double_t localX;
185  // Double_t localY;
186  // };
187 
189  {
190  Int_t apv; // apv number (arm channel 0-3 or 12-15)
191  Int_t channel; // apv channel (0-127)
192  Bool_t isY; // is it a pad (true) or strip (false)
193  Int_t coordinate; // coordinate number
194  Double_t location; // in cm
195  TString signal; // label string
196  Int_t readout; // number in readout order
197  };
198 
199  friend class StGmtDbFileMaker;
200 
201 
202  // Various constants used in Jan's conversion functions.
203  static double mPi;
204  static double mHalfPi;
205 
206 
207  // ---Private member variables---
208  // static StGmtGeomData mStrips[ 2*kGmtNumStrips ];
209  static StGmtGeomData mStrips[ kGmtNumStripsPerModule ]; // 128 X strip and 128 Y strips
210 
211  // maps from (apv*128 + channel) to ((layer=='P')*kGmtNumStrips + stripID)
212  // static Int_t mNaiveMapping[ kGmtNumChannels*kGmtApvsPerQuad ];
213  static Int_t mNaiveMapping[ kGmtNumStripsPerModule ];
214 
215  // reverse mapping: ((layer=='P')*kGmtNumStrips + stripID) to (apv*128 + channel)
216  static Bool_t mReverseNaiveMappingValid;
217  static Int_t mReverseNaiveMapping[ kGmtNumStripsPerModule ];
218  static void makeReverseNaiveMappingValid();
219 
220  private:
221 
222  // Calculates coordinates of strip in global coordinate system
223  // Units are in cm andradians, depending on the layer.
224  // static Int_t computeGlobalPhysicalCoordinate(Char_t & layer,
225  static Int_t computeGlobalPhysicalCoordinate(Int_t &layer, Short_t &strip);
226 };
227 
228 //________________
229 // get the octant given the phi in radians
230 inline Int_t StGmtGeom::getOctant( Double_t phi ) {
231  double phiDeg= 75 - ((phi*180)/mPi);
232  while ( phiDeg < 0 ) phiDeg+=360;
233  while ( phiDeg > 360 ) phiDeg-=360;
234  int i8=phiDeg/45;
235  return i8;
236 }
237 
238 #endif
239