StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSvtCoordinateTransform.cc
1 /***********************************************************************
2  *
3  * $Id: StSvtCoordinateTransform.cc,v 1.44 2018/10/17 20:45:24 fisyak Exp $
4  *
5  * Author: Helen Caines April 2000
6  *
7  ***********************************************************************
8  * Description:
9  *
10  * Geometrical transformation Routines for:
11  * Raw Wafer Coordinate <--> Local Coordinate
12  * Local Coordinate <--> Global Coordinate
13  *
14  * These Routines deal positions ONLY!
15  *
16  *
17  ***********************************************************************/
18 #include "StTpcDb/StTpcDb.h" //Final transformation to mag. coords
19 #include "StSvtCoordinateTransform.hh"
20 #include "StCoordinates.hh" // coordinate definitions
21 #include "StGlobals.hh"
22 #include "StMessMgr.h"
23 #include "StSvtClassLibrary/StSvtConfig.hh"
24 #include "StSvtClassLibrary/StSvtGeometry.hh"
25 #include "StSvtClassLibrary/StSvtWaferGeometry.hh"
26 #include "StSvtClassLibrary/StSvtHybridCollection.hh"
27 #include "StSvtClassLibrary/StSvtHybridDriftVelocity.hh"
28 #include "StSvtClassLibrary/StSvtHybridDriftCurve.hh"
29 #include "StSvtClassLibrary/StSvtT0.hh"
30 #include <unistd.h>
31 #include "TF1.h"
32 #include "TString.h"
33 #include "TMath.h"
34 #include "St_svtCorrectionC.h"
35 #include "St_svtHybridDriftVelocityC.h"
36 #if defined (__SUNPRO_CC) && __SUNPRO_CC >= 0x500
37 using namespace units;
38 #endif
39 static Int_t _debug = 0;
40 
41 //_____________________________________________________________________________
42 StSvtCoordinateTransform::StSvtCoordinateTransform() {
43 
44  mFlag=0;
45  mDeltaDriftVelocity = 1;
46  mPoly9 = new TF1("mPoly9","pol9(0)",0.0,6.0);
47 }
48 
49 //_____________________________________________________________________________
50 
51 StSvtCoordinateTransform::StSvtCoordinateTransform(StTpcDb* /* gStTpcDb */) {
52  mFlag=0;
53  mPoly9=0;
54 }
55 //_____________________________________________________________________________
56 
57 StSvtCoordinateTransform::~StSvtCoordinateTransform()
58 {
59  SafeDelete(mPoly9);
60  if (mFlag&1) delete mgeom; mgeom=0;
61 }
62 
63 //_____________________________________________________________________________
64 void StSvtCoordinateTransform::setParamPointers( srs_srspar_st* param,
65  svg_geom_st* geom,
66  svg_shape_st* shape,
67  StSvtConfig* config,
68  StSvtHybridCollection* driftVeloc,
69  StSvtT0* T0){
70  mFlag=0;
71  mgeom = new StSvtGeometry(param, geom, shape);
72  mFlag |=1;
73  mconfig = config;
74  mDriftVelocity = 0;//YF driftVeloc;
75  mDriftCurve = NULL;
76  mT0 = T0;
77  mdriftVelCorr = 0;
78 }
79 //_____________________________________________________________________________
80 void StSvtCoordinateTransform::setParamPointers( srs_srspar_st* param,
81  svg_geom_st* geom,
82  svg_shape_st* shape,
83  StSvtConfig* config,
84  StSvtHybridCollection* driftVeloc,
85  StSvtHybridCollection* driftCurve,
86  StSvtT0* T0){
87 
88 
89  mFlag=0;
90  mgeom = new StSvtGeometry(param, geom, shape);
91  mFlag |=1;
92  mconfig = config;
93  mDriftVelocity = 0;//YF driftVeloc;
94  mDriftCurve = 0;//YF driftCurve;
95  mT0 = T0;
96  mdriftVelCorr = 0;
97 }
98 //_____________________________________________________________________________
99 void StSvtCoordinateTransform::setVelocityScale( double deltaV){
100 
101  mDeltaDriftVelocity = deltaV;
102 }
103 //____________________________________________________________________________
104 void StSvtCoordinateTransform::setParamPointers( StSvtGeometry* geom,
105  StSvtConfig* config,
106  StSvtHybridCollection* driftVeloc,
107  StSvtT0* T0){
108  mgeom = geom;
109  mconfig = config;
110  mDriftVelocity = 0; //driftVeloc;
111  mDriftCurve = NULL;
112  mT0 = T0;
113  mdriftVelCorr = 0;
114 
115 }
116 //____________________________________________________________________________
117 void StSvtCoordinateTransform::setParamPointers( StSvtGeometry* geom,
118  StSvtConfig* config,
119  StSvtHybridCollection* driftVeloc,
120  StSvtHybridCollection* driftCurve,
121  StSvtT0* T0){
122  mgeom = geom;
123  mconfig = config;
124  mDriftVelocity = 0;//YF driftVeloc;
125  mDriftCurve = 0;//YF driftCurve;
126  mT0 = T0;
127  mdriftVelCorr = 0;
128 
129 }
130 
131 //____________________________________________________________________________
132 void StSvtCoordinateTransform::setParamPointers( StSvtGeometry* geom,
133  StSvtConfig* config,
134  StSvtHybridCollection* driftVeloc,
135  StSvtHybridCollection* driftCurve,
136  StSvtT0* T0,
137  St_svtCorrectionC* driftVelCorr){
138  mgeom = geom;
139  mconfig = config;
140  mDriftVelocity = 0;//YF driftVeloc;
141  mDriftCurve = 0;//YF driftCurve;
142  mT0 = T0;
143  mdriftVelCorr = driftVelCorr;
144 
145 }
146 
147 //_____________________________________________________________________________
148 // Raw Data --> Global Coordinate
149 
150 void StSvtCoordinateTransform::operator()(const StSvtWaferCoordinate& a, StGlobalCoordinate& c)
151 {
153 
154 
155  this->operator()(a,b);
156  this->operator()(b,c);
157 
158  return;
159 
160 }
161 //_____________________________________________________________________________
162 
163 // Global Coordinate --> Raw data
164 
165 void StSvtCoordinateTransform::operator()(const StGlobalCoordinate& a, StSvtWaferCoordinate& c, Int_t Id)
166 {
167 
169 
170 
171  this->operator()(a,b, Id);
172 
173  this->operator()(b,c);
174  return;
175 
176 }
177 //_____________________________________________________________________________
178 
179 // Raw Data --> SVT Local Coordinate
180 void StSvtCoordinateTransform::operator()(const StSvtWaferCoordinate& a, StSvtLocalCoordinate& b)
181 
182 {
183  b.setLayer(a.layer());
184  b.setLadder(a.ladder());
185  b.setWafer(a.wafer());
186  b.setHybrid(a.hybrid());
187 
188  St_svtHybridDriftVelocityC *d = St_svtHybridDriftVelocityC::instance();
189  b.setPosition(StThreeVector<double>(d->CalcU(a.barrel(),a.ladder(),a.wafer(),a.hybrid(),a.timebucket(),a.anode()),
190  d->CalcV(a.hybrid(),a.anode()),
191  0.0));
192  return;
193 }
194 //_____________________________________________________________________________
195 
196 
197 // SVT Local Coordinate --> Raw coordinate
198 
199 void StSvtCoordinateTransform::operator()(const StSvtLocalCoordinate& a, StSvtWaferCoordinate& b)
200 {
201  //StThreeVector<double> pos(0,0,0);
202 
203  b.setLayer(a.layer());
204  b.setLadder(a.ladder());
205  b.setWafer(a.wafer());
206  b.setHybrid(a.hybrid());
207 
208  // int idShape = 0;
209  St_svtHybridDriftVelocityC *d = St_svtHybridDriftVelocityC::instance();
210  b.setTimeBucket(-99);
211  b.setAnode(-99);
212  if (d) {
213  b.setTimeBucket(d->UnCalcU(b.barrel(),b.ladder(),b.wafer(),b.hybrid(),a.position().x()));
214  b.setAnode(d->UnCalcV(b.hybrid(),a.position().y()));
215  }
216  return;
217 
218 }
219 
220 //_____________________________________________________________________________
221 // Svt Local --> Global
222 
223 void StSvtCoordinateTransform::operator()(const StSvtLocalCoordinate& a, StGlobalCoordinate& b)
224 {
225 
226  StThreeVector<double> x(0,0,0);
227 
228  LocaltoGlobal(a, x, -1);
229 
230  b.setPosition(x);
231 
232 
233 }
234 
235 //_____________________________________________________________________________
236 
237 // Svt Global --> Local
238 
239 void StSvtCoordinateTransform::operator()(const StGlobalCoordinate& a, StSvtLocalCoordinate& b, Int_t Id)
240 {
241  // Id = 10000*shell + 1000*layer + 100*wafer + ladder;
242  Int_t id = Id%10000;
243  Int_t layer = (id/1000);
244  // Int_t barrel = (layer - 1)/2 + 1;
245  Int_t ladder = id%100;
246  Int_t wafer = (id - 1000*layer)/100;
247  b.setLayer(layer);
248  b.setLadder(ladder);
249  b.setWafer(wafer);
250  GlobaltoLocal( a.position(), b, Id, -1);
251  b.setHybrid(2);
252  if( b.position().x() < 0) b.setHybrid(1);
253 }
254 
255 //_____________________________________________________________________________
256 
257 int StSvtCoordinateTransform::LocaltoGlobal(const StSvtLocalCoordinate& a, StThreeVector<double>& x, int index){
258 /***********************************************************************/
259 /* TRANSFORMATION ROUTINES */
260 
261 
262  // DESCRIPTION: local to global mapping for svt points
263 
264  // Input Arguments:
265  // xp : local coordinate
266  // geom->x : wafer origin
267  // geom->d : wafer drift direction
268  // geom->t : wafer transverse direction
269  // geom->n : wafer normal
270 
271  // Output Arguments:
272  // x : global coordinate
273 
274  // Functional Description:
275  // Make a local to global mapping by using the origin of the wafer coordinate and the
276  // 3 vectors defining the normal to the plane, the drift direction, and the transverse direction.
277  // xp[0] : component in the drift direction
278  // xp[1] : component in the transverse direction
279  // xp[2] : component in the direction normal to the wafer; should be small ...
280 
281  // Error Conditions: none
282 
283 
284  if( index < 0){
285  index = mgeom->getWaferIndex(mgeom->getBarrelID(a.layer(),a.ladder()),(int)a.ladder(),(int)a.wafer());
286 
287  }
288  StSvtWaferGeometry *waferGeom = 0;
289  if (index >= 0 && index < 216)
290  waferGeom = (StSvtWaferGeometry*)mgeom->at(index);
291  if (!waferGeom) {
292  x.setX(-999);
293  x.setY(-999);
294  x.setZ(-999);
295  return 0;
296  }
297  if (_debug) waferGeom->print();
298 
299  Double_t xl[3] = {a.position().x(), a.position().y(), a.position().z()};
300  if (_debug) cout << "xl \t" << xl[0] << "\t" << xl[1] << "\t" << xl[2] << endl;
301  Double_t xg[3];
302  waferGeom->LocalToMaster(xl,xg);
303  if (_debug) cout << "xg \t" << xg[0] << "\t" << xg[1] << "\t" << xg[2] << endl;
304  x.setX(xg[0]); x.setY(xg[1]); x.setZ(xg[2]);
305  if (_debug) cout << "x \t" << x.x() << "\t" << x.y() << "\t" << x.z() << endl;
306 
307  return index;
308 }
309 
310 //___________________________________________________________________________
311 
312 int StSvtCoordinateTransform::GlobaltoLocal( const StThreeVector<double>& x, StSvtLocalCoordinate& b , int HardWarePos, int index )
313 {
314 
315 /* DESCRIPTION: global to local mapping for svt points
316  c Input Arguments:
317  c x : global coordinate
318  c geom->x : wafer origin
319  c geom->d : wafer drift direction
320  c geom->t : wafer transverse direction
321  c geom->n : wafer normal
322  c
323  c Output Arguments:
324  c xp : local coordinate
325  c
326  c Functional Description:
327  c Make a global to local mapping by using the origin of the wafer coordinate and the
328  c 3 vectors defining the normal to the plane, the drift direction, and the transverse direction.
329  c xp.x : component in the drift direction
330  c xp.y : component in the transverse direction
331  c xp.z : component in the direction normal to the wafer; should be small ...
332  c
333  c Created 1-Nov-93 C. Pruneau, WSU
334  c
335  c Error Conditions: none
336  c
337 */
338 
339  // Executable Code
340  // ===============
341 
342 
343  StSvtWaferGeometry* waferGeom = NULL;
344 
345  if( index < 0){
346  index = mgeom->getWaferIndex(HardWarePos%10000);
347  }
348 
349  if (index >= 0 && index<216)
350  waferGeom = (StSvtWaferGeometry*)mgeom->at(index);
351  //cout << "HardWarePos = " << HardWarePos << ", index = " << index << ", waferGeom = " << waferGeom << endl;
352 
353  if (!waferGeom) {
354  b.position().setX(-999);
355  b.position().setY(-999);
356  b.position().setZ(-999);
357  return 0;
358  }
359 
360 
361  // xl[0] = x.x() - mgeom[index].x[0];
362  // xl[1] = x.y() - mgeom[index].x[1];
363  // xl[2] = x.z() - mgeom[index].x[2];
364 
365  // b.position().setX(xl[0]*mgeom[index].d[0] + xl[1]*mgeom[index].d[1] + xl[2]*mgeom[index].d[2]);
366  // b.position().setY(xl[0]*mgeom[index].t[0] + xl[1]*mgeom[index].t[1] + xl[2]*mgeom[index].t[2]);
367  // b.position().setZ(xl[0]*mgeom[index].n[0] + xl[1]*mgeom[index].n[1] + xl[2]*mgeom[index].n[2]);
368 
369  Double_t xg[3] = {x.x(), x.y(), x.z()};
370  Double_t xl[3];
371  if (_debug) waferGeom->print();
372  if (_debug) cout << "xg \t" << xg[0] << "\t" << xg[1] << "\t" << xg[2] << endl;
373 
374  waferGeom->MasterToLocal(xg,xl);
375  if (_debug) cout << "xl \t" << xl[0] << "\t" << xl[1] << "\t" << xl[2] << endl;
376  b.position().setX(xl[0]); b.position().setY(xl[1]); b.position().setZ(xl[2]);
377  if (_debug) cout << "x \t" << b.position().x() << "\t" << b.position().y() << "\t" << b.position().z() << endl;
378 
379  // cout << index << " " << b.position() << " " << waferGeom->x(0) << " " << waferGeom->x(1) << " " << waferGeom->x(2) << " " << x.x() << " "
380 // << x.y() << " " << x.z() << endl;
381  return index;
382 
383 }
384 
385 //_____________________________________________________________________________
386 //_____________________________________________________________________________
387 
388 int StSvtCoordinateTransform::IsOnWaferZ( const StThreeVector<double>& GlobalPosition,
389  int HardWarePos){
390 
391  //Find out for a given z coord and Hardware pos is it on the wafer
392 
393  StSvtLocalCoordinate LocalPosition;
394 
395 
396  GlobaltoLocal(GlobalPosition, LocalPosition, HardWarePos, -1);
397 
398  return (fabs(LocalPosition.position().y()) <3.1525)? 1:0;
399 }
400 
401 //_____________________________________________________________________________
402 
403 int StSvtCoordinateTransform::IsOnWaferR( const StThreeVector<double>& GlobalPosition,
404  int HardWarePos){
405 
406  //Find out for a given z coord and Hardware pos is it on the wafer
407 
408  StSvtLocalCoordinate LocalPosition;
409 
410  GlobaltoLocal(GlobalPosition, LocalPosition, HardWarePos, -1);
411 
412 
413  if( fabs(LocalPosition.position().x()) < 3.1525 &&
414  fabs(LocalPosition.position().z()) < 0.15 ) return 1;
415  return 0;
416 }
417