StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTpcCoordinateTransform.hh
1 /***********************************************************************
2  *
3  * $Id: StTpcCoordinateTransform.hh,v 1.29 2018/10/17 20:45:24 fisyak Exp $
4  *
5  * Author: brian made this on Feb 6, 1998
6  *
7  ***********************************************************************
8  * Description:
9  *
10  * Geometrical transformation Routines for:
11  * Raw Pad Coordinate <--> Local Coordinate
12  * Local Coordinate <--> Global Coordinate
13  *
14  * These Routines deal positions ONLY!
15  *
16  ***********************************************************************
17  *
18  * $Log: StTpcCoordinateTransform.hh,v $
19  * Revision 1.29 2018/10/17 20:45:24 fisyak
20  * Restore update for Run XVIII dE/dx calibration removed by Gene on 08/07/2018
21  *
22  * Revision 1.27 2018/08/07 03:43:37 fisyak
23  * iTPC corrections
24  *
25  * Revision 1.25 2018/06/21 01:46:56 perev
26  * iTPCheckIn
27  *
28  * Revision 1.22.10.1 2018/02/16 22:14:56 perev
29  * iTPC
30  * Revision 1.24 2018/06/07 04:28:42 genevb
31  * Explicit include for TMath needed
32  *
33  * Revision 1.23 2018/04/11 02:43:44 smirnovd
34  * StTpcCoordinateTransform: Extend interface to accept TPC sector + use padConfig
35  *
36  * Revision 1.22 2014/06/26 21:29:27 fisyak
37  * New Tpc Alignment, v632
38  *
39  * Revision 1.21 2012/10/23 20:13:17 fisyak
40  * Move xFromPad from h- to cxx-file
41  *
42  * Revision 1.20 2012/09/13 20:57:28 fisyak
43  * Corrections for iTpx
44  *
45  * Revision 1.19 2012/05/07 14:38:41 fisyak
46  * Remvoe hardcoded separation between Inner and Outer Sectors
47  *
48  * Revision 1.18 2011/01/18 14:34:28 fisyak
49  * Clean up TpcDb interfaces and Tpc coordinate transformation
50  *
51  * Revision 1.17 2009/11/02 17:32:25 fisyak
52  * remove defaults in Tpc Coordinate transformations
53  *
54  * Revision 1.16 2009/09/23 23:30:14 fisyak
55  * Follow up Valery's corrections
56  *
57  * Revision 1.15 2009/09/22 22:39:38 fine
58  * fix the StThreeVector invocation
59  *
60  * Revision 1.14 2009/05/20 02:49:51 genevb
61  * Introduce tpcPadrowT0 time offsets
62  *
63  * Revision 1.13 2008/05/27 14:26:40 fisyak
64  * Use TChairs, absorb shift tau shift, introduce sector to sector time offset
65  *
66  * Revision 1.12 2007/07/12 19:22:01 fisyak
67  * Tpc Drift Velocity depends on West/East half
68  *
69  * Revision 1.11 2007/03/21 16:39:05 fisyak
70  * TpcCoordinate transformation via TGeoHMatrix
71  *
72  * Revision 1.10 2005/07/06 19:10:34 fisyak
73  * Add TpcCoordinate transormation classes to dictionary, use templated StThreeVector
74  *
75  * Revision 1.9 2004/06/05 23:31:09 fisyak
76  * Add (sector,row) for Tpc Coordinate/Direction transformations; Change sign of t0zoffset correction (to be synch. with fcf)
77  *
78  * Revision 1.8 2004/03/05 17:22:54 fisyak
79  * Add TPC transformations for direction, aligned sectors, protection in order to stay in the same sector when moving from/to Pad coordinates
80  *
81  * Revision 1.7 2001/05/22 22:32:14 hardtke
82  * Add tpc global to local transformations
83  *
84  * Revision 1.6 2000/07/27 23:06:50 hardtke
85  * Hui requested that all member functions be public -- probably bad programming, but TRS needs to be speeded up
86  *
87  * Revision 1.5 2000/05/25 20:51:31 hardtke
88  * make z-to-time functions public, use correct t0s, get rid of spurious 0.5
89  *
90  * Revision 1.4 2000/04/13 22:57:53 calderon
91  * use lookup table of sines and cosines instead of calculating them
92  * each time
93  *
94  * Revision 1.3 2000/02/10 01:19:37 calderon
95  * Tpc Local Sector Coordinate definitions where
96  * y is up,
97  * z points toward central membrane,
98  * x is such that everything is righthanded
99  * There are still some parameters that need to be taken from
100  * database.
101  *
102  * Revision 1.2 2000/02/02 23:01:38 calderon
103  * Changes for CC5
104  * Tests withs StTpcDb still going.
105  *
106  * Revision 1.1 1999/11/19 19:01:08 calderon
107  * First version of files for StDbUtilities.
108  * Note: this package uses StTpcDb.
109  * There are some parameters
110  * that are not yet kept in StTpcDb. When StTpcDb has them, the code
111  * will be changed to use them from StTpcDb.
112  * There are no Ftpc or Svt Coordinate transformations in here yet.
113  *
114  * Revision 1.5 1999/10/04 16:00:46 long
115  * new coordinate system in the trs
116  *
117  * Revision 1.5 1999/10/01 17:15:00 Hui Long
118  * New definition of the coordinate system according to Brian nad Thomas's
119  * proposal
120  * Revision 1.4 1999/02/18 21:17:42 lasiuk
121  * instantiate with electronics db
122  *
123  * Revision 1.3 1999/02/16 23:28:46 lasiuk
124  * matrix(3) is a data member to avoid constructor calls
125  * protection against pad<1
126  * const removed from several functions (because of matrix)
127  *
128  * Revision 1.2 1999/01/28 02:51:40 lasiuk
129  * add ()localSector --> Raw
130  * add ()localSector --> Local
131  *
132  * Revision 1.1 1998/11/10 17:12:05 fisyak
133  * Put Brian trs versin into StRoot
134  *
135  * Revision 1.5 1998/11/01 16:21:05 lasiuk
136  * remove 'St' from variable declarations
137  * add set functions in local Coordinates
138  *
139  * Revision 1.4 1998/10/22 00:23:17 lasiuk
140  * Oct 22
141  *
142  * Revision 1.3 1998/06/04 23:13:18 lasiuk
143  * add sector12 coordinate transform as public member
144  *
145  * Revision 1.2 1998/05/25 17:00:31 lasiuk
146  * pass databases instead of filenames
147  * do not use hardcoded numbers
148  *
149  * Revision 1.1 1998/05/21 21:27:37 lasiuk
150  * Initial revision
151  *
152  *
153  ***********************************************************************/
154 #ifndef ST_COORDINATE_TRANSFORM_HH
155 #define ST_COORDINATE_TRANSFORM_HH
156 
157 #include <stdlib.h>
158 #include "TMath.h"
159 // SCL
160 #include "StGlobals.hh"
161 #include "SystemOfUnits.h"
162 #include "StThreeVector.hh"
163 #include "StTpcDb/StTpcDb.h"
164 #include "StObject.h"
165 
166 //#define DEBUG_TPC 0
167 //#define idb if(DEBUG_TPC) cout
168 #include "StTpcPadCoordinate.hh"
169 #include "StTpcLocalCoordinate.hh"
170 #include "StTpcLocalSectorCoordinate.hh"
171 #include "StTpcLocalSectorAlignedCoordinate.hh"
172 #include "StGlobalCoordinate.hh"
173 
174 #include "StTpcLocalDirection.hh"
175 #include "StTpcLocalSectorDirection.hh"
176 #include "StTpcLocalSectorAlignedDirection.hh"
177 #include "StGlobalDirection.hh"
178  // pad => sector12 => subsector => sector => tpc => global
179  // TpcPadCoordinate => TpcSectL => TpcSectLAligned => TpcLocal => Global
180 class StTpcCoordinateTransform {//: public StObject {
181 public:
182  StTpcCoordinateTransform(StTpcDb* globalDbPointer=0);
184  // Raw Data <--> Tpc Local Sector Coordinates
185  void operator()(const StTpcLocalSectorCoordinate& a, StTpcPadCoordinate& b,Bool_t useT0=kFALSE, Bool_t useTau=kTRUE);
186  void operator()(const StTpcPadCoordinate& a, StTpcLocalSectorCoordinate& b,Bool_t useT0=kFALSE, Bool_t useTau=kTRUE);
187  // Raw Data <--> Tpc Local Coordinates
188  void operator()(const StTpcLocalCoordinate& a, StTpcPadCoordinate& b,Bool_t useT0=kFALSE, Bool_t useTau=kTRUE)
189  {StTpcLocalSectorCoordinate c; this->operator()(a,c); this->operator()(c,b,useT0,useTau);}
190  void operator()(const StTpcPadCoordinate& a, StTpcLocalCoordinate& b,Bool_t useT0=kFALSE, Bool_t useTau=kTRUE)
191  {StTpcLocalSectorCoordinate c; this->operator()(a,c,useT0,useTau); this->operator()(c,b);}
192  // Tpc Local Sector <--> TPC Local
193  void operator()(const StTpcLocalSectorCoordinate& a, StTpcLocalCoordinate& b );
194 // { Double_t xyzS[3] = {a.position().x(), a.position().y(), 0.};
195 // StTpcDb::instance()->Pad2Tpc(a.sector(),a.row()).LocalToMaster(xyzS,b.position().xyz());
196 // b.position().setZ(b.position().z() + a.position().z());
197 // b.setSector(a.sector()); b.setRow(a.row());}
198  void operator()(const StTpcLocalSectorCoordinate& a, StTpcLocalSectorAlignedCoordinate& b) {b = a;}
199  void operator()(const StTpcLocalSectorDirection& a, StTpcLocalDirection& b)
200  {StTpcDb::instance()->Pad2Tpc(a.sector(),a.row()).LocalToMasterVect(a.position().xyz(),b.position().xyz()); b.setSector(a.sector()); b.setRow(a.row());}
201  void operator()(const StTpcLocalSectorDirection& a, StTpcLocalSectorAlignedDirection& b) {b = a;}
202  void operator()(const StTpcLocalSectorCoordinate& a, StGlobalCoordinate& b)
203  { StTpcLocalCoordinate c; this->operator()(a,c); this->operator()(c,b); }
204  void operator()(const StTpcLocalSectorDirection& a, StGlobalDirection& b)
205  {StTpcDb::instance()->Pad2Glob(a.sector(),a.row()).LocalToMasterVect(a.position().xyz(),b.position().xyz());}
206  void operator()(const StTpcLocalCoordinate& a, StTpcLocalSectorCoordinate& b );
207 // { Double_t xyzS[3] = {a.position().x(), a.position().y(), 0.};
208 // StTpcDb::instance()->Pad2Tpc(a.sector(),a.row()).MasterToLocal(xyzS,b.position().xyz()); b.setSector(a.sector()); b.setRow(a.row());
209 // b.position().setZ(b.position().z() + a.position().z());
210 // }
211  void operator()(const StTpcLocalDirection& a, StTpcLocalSectorDirection& b )
212  {StTpcDb::instance()->Pad2Tpc(a.sector(),a.row()).MasterToLocalVect(a.position().xyz(),b.position().xyz()); b.setSector(a.sector()); b.setRow(a.row());}
213  void operator()(const StGlobalCoordinate& a,StTpcLocalSectorCoordinate& b,Int_t sector, Int_t row)
215  this->operator()(a,c,sector,row);
216  this->operator()(c,b);
217  }
218  void operator()(const StGlobalDirection& a,StTpcLocalSectorDirection& b,Int_t sector, Int_t row)
219  {StTpcDb::instance()->Pad2Glob(sector,row).MasterToLocalVect(a.position().xyz(),b.position().xyz()); b.setSector(sector); b.setRow(row);}
220  // Internal TpcCoordinate <--> Global Coordinate
221  void operator()(const StTpcLocalCoordinate& a, StGlobalCoordinate& b)
222  {StTpcDb::instance()->Tpc2GlobalMatrix().LocalToMaster(a.position().xyz(),b.position().xyz());}
223  void operator()(const StGlobalCoordinate& a, StTpcLocalCoordinate& b,Int_t sector, Int_t row)
224  {StTpcDb::instance()->Tpc2GlobalMatrix().MasterToLocal(a.position().xyz(),b.position().xyz()); b.setSector(sector); b.setRow(row);}
225  void operator()(const StTpcLocalDirection& a, StGlobalDirection& b)
226  {StTpcDb::instance()->Tpc2GlobalMatrix().LocalToMasterVect(a.position().xyz(),b.position().xyz());}
227  void operator()(const StGlobalDirection& a, StTpcLocalDirection& b,Int_t sector, Int_t row)
228  {StTpcDb::instance()->Tpc2GlobalMatrix().MasterToLocalVect(a.position().xyz(),b.position().xyz()); b.setSector(sector); b.setRow(row);}
229  // Raw Data <--> Global Coordinate
230  void operator()(const StTpcPadCoordinate& a, StGlobalCoordinate& b,Bool_t useT0=kFALSE, Bool_t useTau=kTRUE)
231  {StTpcLocalCoordinate c; this->operator()(a,c,useT0,useTau); this->operator()(c,b);}
232  void operator()(const StGlobalCoordinate& a, StTpcPadCoordinate& b,Int_t sector, Int_t row, Bool_t useT0=kFALSE, Bool_t useTau=kTRUE)
233  {StTpcLocalCoordinate c; this->operator()(a,c,sector,row); this->operator()(c,b,useT0,useTau);}
234  Double_t tBFromZ(Double_t z, Int_t sector, Int_t row, Int_t pad = 0) const;
235  Double_t zFromTB(Double_t tb, Int_t sector, Int_t row, Int_t pad = 0) const;
236  // Transformation Routines!!
237  // Raw Data (pad row timebin or drift L From tpc local sector Coordinates
238  static Int_t rowFromLocalY(Double_t y, Int_t sector);
239  static Int_t rowFromLocal(const StThreeVector<Double_t>& a, Int_t sector) {return rowFromLocalY(a.y(), sector);}
240  Double_t padFromLocal(const StThreeVector<Double_t>& a, Int_t sector, Int_t row) const {return padFromX(a.x(), sector, row);}
241  Double_t padFromX(Double_t x, Int_t sector, Int_t row) const;
242  Int_t rowFromLocal(const StTpcLocalSectorCoordinate& a) const {return rowFromLocal(a.position(),a.sector());}
243  Double_t padFromLocal(const StTpcLocalSectorCoordinate& a) const {return padFromLocal(a.position(),a.sector(),a.row());}
244  // tpc local sector Coordinates from Raw Data
245  StThreeVector<Double_t> xyFromRow(const StTpcPadCoordinate& a) {return StThreeVector<Double_t> (xFromPad(a.sector(),a.row(),a.pad()),yFromRow(a.sector(),a.row()),0);}
246  Double_t yFromRow(Int_t sector, Int_t row) const {return (St_tpcPadConfigC::instance()->radialDistanceAtRow(sector,row));}
247  Double_t xFromPad(Int_t sector, Int_t row, Double_t pad) const;
248 // sector from Tpc local coordinates
249  Int_t sectorFromCoordinate(const StThreeVector<double>& a) const{
250  Double_t angle = TMath::RadToDeg()*TMath::ATan2(a.y(),a.x());
251  if(angle<0) angle+= 360;
252  Int_t sectorNumber= (int)( (angle+15)/30);
253  if(a.z()>0){sectorNumber=15-sectorNumber; if(sectorNumber> 12)sectorNumber-=12;}
254  else {sectorNumber+=9; if(sectorNumber<=12)sectorNumber+=12;}
255  return sectorNumber;
256  }
257 private:
258  Double_t mTimeBinWidth;
259  Double_t mInnerSectorzOffset;
260  Double_t mOuterSectorzOffset;
261 #if 0
262  Double_t mInnerSectorzOffset_West;
263  Double_t mOuterSectorzOffset_West;
264 #endif
265  Int_t mNoOfInnerRows;
266  Int_t mNoOfRows;
267 
268  // ClassDef(StTpcCoordinateTransform,0) //
269 };
270 
271 #endif
272 
273 
274