StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFtpcPoint.cc
1 // $Id: StFtpcPoint.cc,v 1.22 2007/01/15 08:23:01 jcs Exp $
2 // $Log: StFtpcPoint.cc,v $
3 // Revision 1.22 2007/01/15 08:23:01 jcs
4 // replace printf, cout and gMesMgr with Logger commands
5 //
6 // Revision 1.21 2004/09/10 13:39:39 jcs
7 // correct bit allocation error for FTPC HardwarePosition
8 //
9 // Revision 1.20 2004/05/07 14:18:46 oldi
10 // const added to GedtDetectorId() and GetHardwarePosition().
11 // Creation of StEvent/StFtpcHit removed. This is done in a new constructor of StFtpcit itself, now.
12 //
13 // Revision 1.19 2004/04/06 18:36:13 oldi
14 // New data mebers for pad and time position and pad and time sigma added.
15 // Reference to StFtpcHit added.
16 // Possibility to update StFtpcHit coordinates directly included.
17 //
18 // Revision 1.18 2004/02/12 19:37:10 oldi
19 // *** empty log message ***
20 //
21 // Revision 1.17 2004/01/28 01:41:32 jeromel
22 // *** empty log message ***
23 //
24 // Revision 1.16 2003/09/23 23:25:35 oldi
25 // SetGlobalCoord() and SetUsage() moved to the end of the constructors to avoid
26 // them calling GetFlags() before mFlags is initialized.
27 //
28 // Revision 1.15 2003/09/16 15:27:02 jcs
29 // removed inline as it would leave a few undefined reference
30 //
31 // Revision 1.14 2003/01/16 18:04:33 oldi
32 // Bugs eliminated. Now it compiles on Solaris again.
33 // Split residuals for global and primary fit.
34 //
35 // Revision 1.13 2002/11/21 15:46:21 oldi
36 // Enabled rotation for FTPC west. If there is an observed shift of the vertex
37 // position in y-direction (in FTPC west), just fill this offset into the Db.
38 // Up to now this offset is set to 0., i.e. only FTPC east is rotated (because
39 // the offset is at 0.3427 cm).
40 //
41 // Revision 1.12 2002/11/19 12:45:07 oldi
42 // A new database entry (installationPointY[east/west]) was introduced. Now
43 // the rotation of FTPC east is done around the correct axis, which isn't
44 // measured but comes from the drawings. The measurements used before were true
45 // measurements but had nothing to do with the rotation axis, unfortunately.
46 // Anyway, the difference is rather small since a typical cluster is rotated
47 // by less than 0.1mm.
48 // Some code cleanup done.
49 //
50 // Revision 1.11 2002/10/31 13:39:09 oldi
51 // InstallationPointZ() changed to InstallationPointZ(i) where i specifies FTPC east or west.
52 //
53 // Revision 1.10 2002/10/11 15:45:12 oldi
54 // Get FTPC geometry and dimensions from database.
55 // No field fit activated: Returns momentum = 0 but fits a helix.
56 // Bug in TrackMaker fixed (events with z_vertex > outer_ftpc_radius were cut).
57 // QA histograms corrected (0 was supressed).
58 // Code cleanup (several lines of code changed due to *params -> Instance()).
59 // cout -> gMessMgr.
60 //
61 // Revision 1.9 2002/06/04 13:34:57 oldi
62 // Transformation of local FTPC coordinates in global coordinates introduced.
63 // An additional flag keeps track in which coordinate system the point position
64 // is measured.
65 // 'Tracked' flag is set correctly, now.
66 //
67 // Revision 1.8 2002/03/05 16:53:10 jcs
68 // force data type definitions to avoid compiler warnings (this is a correct
69 // but inelegant fix which must be changed)
70 //
71 // Revision 1.7 2002/01/29 11:07:59 oldi
72 // Write() renamed to WriteCluster() resp. WriteTrack() to avoid compiler warnings.
73 // As a result the functions TObject::Write() are available again (directly).
74 //
75 // Revision 1.6 2000/11/10 18:37:46 oldi
76 // New constructor added.
77 // StThreeVector replaced by TVector3 to be able to use ROOT output (e.g. Write()).
78 // Cleanup.
79 //
80 // Revision 1.5 2000/08/01 12:23:15 hummler
81 // add writing to table functionality
82 //
83 // Revision 1.4 2000/07/18 21:22:16 oldi
84 // Changes due to be able to find laser tracks.
85 // Cleanup: - new functions in StFtpcConfMapper, StFtpcTrack, and StFtpcPoint
86 // to bundle often called functions
87 // - short functions inlined
88 // - formulas of StFormulary made static
89 // - avoid streaming of objects of unknown size
90 // (removes the bunch of CINT warnings during compile time)
91 // - two or three minor bugs cured
92 //
93 // Revision 1.3 2000/06/13 14:49:01 oldi
94 // Added SetTrackedFlag(Bool_t tracked) and GetTrackedFlag() to take care of the
95 // bit 5 of mFlags.
96 // Changed SetUsage(Bool_t f) to change the bit 5 of mFlags, too.
97 //
98 // Revision 1.2 2000/06/07 11:37:34 oldi
99 // Cleanup.
100 //
101 // Revision 1.1 2000/05/11 15:14:47 oldi
102 // Changed class names *Hit.* due to already existing class StFtpcHit.cxx in StEvent
103 //
104 
105 //----------Author: Markus D. Oldenburg
106 //----------Last Modified: 19.09.2000
107 //----------Copyright: &copy MDO Production 1999
108 
109 #include "StFtpcPoint.hh"
110 #include "StFtpcHit.h"
111 #include "StFtpcHitCollection.h"
112 #include "StDetectorId.h"
113 #include "StMessMgr.h"
114 
116 // //
117 // StFtpcPoint class - representation of one cluster for the FTPC trackers. //
118 // //
119 // This class contains all data members which are the output of the FTPC //
120 // cluster finder. //
121 // //
123 
124 ClassImp(StFtpcPoint)
125 
126 
128 {
129  // Default constructor.
130  // Sets all pointers to zero.
131 
132  SetStFtpcHit((StFtpcHit*)0);
133 
134  SetHitNumber(-1);
135  SetNextHitNumber(-1);
136  SetTrackNumber(-1);
137 
138  SetPadRow(0);
139  SetSector(0);
140 
141  SetNumberPads(0);
142  SetNumberBins(0);
143 
144  SetMaxADC(0);
145  SetCharge(0);
146 
147  SetPadPos(0);
148  SetTimePos(0);
149  SetPadPosSigma(0);
150  SetTimePosSigma(0);
151 
152  SetX(0);
153  SetY(0);
154  SetZ(0);
155 
156  SetXerr(0);
157  SetYerr(0);
158  SetZerr(0);
159 
160  SetSigmaPhi(0);
161  SetSigmaR(0);
162  SetFlags(0);
163 
164  SetResidualsToZero();
165 
166  SetGlobalCoord(kFALSE);
167  SetUsage(kFALSE);
168 
169  return;
170 }
171 
172 
173 StFtpcPoint::StFtpcPoint(const StFtpcPoint &point)
174 {
175  // Copy constructor for already existing hits.
176 
177  *this = point;
178 
179  SetHitNumber(-1);
180  SetNextHitNumber(-1);
181  SetTrackNumber(-1);
182 
183  SetResidualsToZero();
184 
185  SetGlobalCoord(GetGlobalFlag());
186  SetUsage(kFALSE);
187 
188  return;
189 }
190 
191 
192 StFtpcPoint::StFtpcPoint(Long_t row,
193  Long_t sector,
194  Long_t n_pads,
195  Long_t n_bins,
196  Long_t max_adc,
197  Long_t charge,
198  Float_t padpos,
199  Float_t timepos,
200  Float_t padpossigma,
201  Float_t timepossigma,
202  Double_t x,
203  Double_t y,
204  Double_t z,
205  Double_t x_err,
206  Double_t y_err,
207  Double_t z_err,
208  Double_t s_phi,
209  Double_t s_r,
210  Long_t flags)
211 {
212  // Constructor which fills all values found by the cluster finder directly.
213 
214  SetStFtpcHit((StFtpcHit*)0);
215 
216  SetHitNumber(-1);
217  SetNextHitNumber(-1);
218  SetTrackNumber(-1);
219 
220  SetPadRow(row);
221  SetSector(sector);
222 
223  SetNumberPads(n_pads);
224  SetNumberBins(n_bins);
225 
226  SetMaxADC(max_adc);
227  SetCharge(charge);
228 
229  SetPadPos(padpos);
230  SetTimePos(timepos);
231  SetPadPosSigma(padpossigma);
232  SetTimePosSigma(timepossigma);
233 
234  SetX(x);
235  SetY(y);
236  SetZ(z);
237 
238  SetXerr(x_err);
239  SetYerr(y_err);
240  SetZerr(z_err);
241 
242  SetSigmaPhi(s_phi);
243  SetSigmaR(s_r);
244  SetFlags(flags);
245 
246  SetResidualsToZero();
247 
248  SetGlobalCoord(GetGlobalFlag());
249  SetUsage(kFALSE);
250 
251  return;
252 }
253 
254 
255 StFtpcPoint::StFtpcPoint(Double_t *x, Int_t row)
256 {
257  // Constructor which takes the x, y, and z coodrinate and the pad row.
258 
259  // Hit position is set in local coordinates per default! Change flag (SetGlobalCoord(kTRUE)) if necessary.
260 
261  SetStFtpcHit((StFtpcHit*)0);
262 
263  SetHitNumber(-1);
264  SetNextHitNumber(-1);
265  SetTrackNumber(-1);
266 
267  SetPadRow(row);
268  SetSector(-1);
269 
270  SetNumberPads(-1);
271  SetNumberBins(-1);
272 
273  SetMaxADC(-1);
274  SetCharge(0);
275 
276  SetPadPos(0);
277  SetTimePos(0);
278  SetPadPosSigma(0);
279  SetTimePosSigma(0);
280 
281  SetX(x[0]);
282  SetY(x[1]);
283  SetZ(x[2]);
284 
285  SetXerr(0.);
286  SetYerr(0.);
287  SetZerr(0.);
288 
289  SetSigmaPhi(0.);
290  SetSigmaR(0.);
291  SetFlags(0);
292 
293  SetResidualsToZero();
294 
295  SetGlobalCoord(kFALSE); // Set to local per default.
296  SetUsage(kFALSE);
297 
298  return;
299 }
300 
301 
302 StFtpcPoint::~StFtpcPoint()
303 {
304  // Destructor.
305  // Does nothing except destruct.
306 }
307 
308 
309 void StFtpcPoint::TransformFtpc2Global()
310 {
311  // Coordinate Transformation.
312  // Shift and Rotation of Ftpc coordinates due to the rotation of the TPC with respect to the magnet.
313  // (The FTPC was aligned with respect to the TPC!)
314  // Turns FTPC due to observed shift of reconstructed vertex position in y direction.
315  // Errors are left as they were.
316 
317  if (!IsInGlobalCoord()) {
318 
319  StThreeVectorD org(mCoord.X(), mCoord.Y(), mCoord.Z());
320 
321  // internal FTPC rotation
322  Int_t i = (org.z() < 0) ? 0 : 1; // east or west
323 
324  // first tranformation to new origin (FTPC installation point)
325  org.setY(org.y() - StFtpcTrackingParams::Instance()->InstallationPointY(i));
326  org.setZ(org.z() - StFtpcTrackingParams::Instance()->InstallationPointZ(i));
327 
328  // actual rotation
329  org = StFtpcTrackingParams::Instance()->FtpcRotation(i) * org;
330 
331  // set z-position back to original value
332  org.setY(org.y() + StFtpcTrackingParams::Instance()->InstallationPointY(i));
333  org.setZ(org.z() + StFtpcTrackingParams::Instance()->InstallationPointZ(i));
334 
335  StThreeVectorD transform = StFtpcTrackingParams::Instance()->TpcToGlobalRotation() * org + StFtpcTrackingParams::Instance()->TpcPositionInGlobal();
336 
337  mCoord.SetX(transform.x());
338  mCoord.SetY(transform.y());
339  mCoord.SetZ(transform.z());
340 
341  SetGlobalCoord(kTRUE);
342  }
343 
344  else {
345  // hit is in global coordinates already
346  LOG_WARN << "Hit is in global coordinates already! Not transformed." << endm;
347  }
348 
349  return;
350 }
351 
352 
353 void StFtpcPoint::TransformGlobal2Ftpc()
354 {
355  // Coordinate Transformation.
356  // Shift and Rotation of Ftpc coordinates due to the rotation of the TPC with respect to the magnet.
357  // (The FTPC was aligned with respect to the TPC!)
358  // Turns FTPC due to observed shift of reconstructed vertex position in y direction.
359  // Errors are left as they were.
360 
361  if (IsInGlobalCoord()) {
362 
363  StThreeVectorD org(mCoord.X(), mCoord.Y(), mCoord.Z());
364  StThreeVectorD transform = StFtpcTrackingParams::Instance()->GlobalToTpcRotation() * (org - StFtpcTrackingParams::Instance()->TpcPositionInGlobal());
365 
366  // internal FTPC rotation
367  Int_t i = (transform.z() < 0) ? 0 : 1; // east or west
368 
369  // first tranformation to new origin (FTPC installation point)
370  transform.setY(transform.y() - StFtpcTrackingParams::Instance()->InstallationPointY(i));
371  transform.setZ(transform.z() - StFtpcTrackingParams::Instance()->InstallationPointZ(i));
372 
373  // actual rotation
374  transform = StFtpcTrackingParams::Instance()->FtpcRotationInverse(i) * transform;
375 
376  // set z-position back to original value
377  transform.setY(transform.y() + StFtpcTrackingParams::Instance()->InstallationPointY(i));
378  transform.setZ(transform.z() + StFtpcTrackingParams::Instance()->InstallationPointZ(i));
379 
380  mCoord.SetX(transform.x());
381  mCoord.SetY(transform.y());
382  mCoord.SetZ(transform.z());
383 
384  SetGlobalCoord(kFALSE);
385  }
386 
387  else {
388  // hit is in local (FTPC) coordinates already
389  LOG_WARN << "Hit is in local (FTPC) coordinates already! Not transformed." << endm;
390  }
391 
392  return;
393 }
394 
395 
396 Int_t StFtpcPoint::ToStEvent(StFtpcHitCollection* ftpcHitCollection)
397 {
398  // Writes cluster information into StFtpcHit class inside StEvent.
399 
400  StFtpcHit *point = new StFtpcHit(*this);
401 
402  ftpcHitCollection->addHit(point);
403  SetStFtpcHit(point); // let this StFtpcPoint know its pointer in StEvent
404 
405  return 1;
406 }
407 
408 
409 void StFtpcPoint::SetStFtpcHitCoord()
410 {
411  // Overwrites hit positions with new ones (most likely the rotated ones).
412 
413  StFtpcHit *hit = GetStFtpcHit();
414 
415  if (!hit) {
416  LOG_WARN << "StFtpcPoint: StFtpcHit does not exist! No changes done." << endm;
417  return;
418  }
419 
420  StThreeVectorF hitPos(GetX(), GetY(), GetZ());
421  StThreeVectorF hitErr(GetXerr(), GetYerr(), GetZerr());
422  hit->setPosition(hitPos);
423  hit->setPositionError(hitErr);
424 
425  return;
426 }
427 
428 
429 void StFtpcPoint::SetResidualsToZero()
430 {
431  // Sets all residuals to 0.
432 
433  SetXPrimResidual(0.);
434  SetYPrimResidual(0.);
435  SetRPrimResidual(0.);
436  SetPhiPrimResidual(0.);
437  SetXGlobResidual(0.);
438  SetYGlobResidual(0.);
439  SetRGlobResidual(0.);
440  SetPhiGlobResidual(0.);
441 
442  return;
443 }
444 
445 
446 StFtpcTrack *StFtpcPoint::GetTrack(TObjArray *tracks) const
447 {
448  // Returns the pointer to the track to which this hit belongs.
449 
450  return (StFtpcTrack*)tracks->At(this->GetTrackNumber());
451 }
452 
453 
454 Int_t StFtpcPoint::GetDetectorId() const
455 {
456  // Returns the detector id of this hit.
457 
458  if (mPadRow >= 1 && mPadRow <= 10) return kFtpcWestId;
459  else if (mPadRow >= 11 && mPadRow <= 20) return kFtpcEastId;
460  else {
461  LOG_INFO << "StFtpcPoint.mPadRow = " << mPadRow << " is out of range"<< endm;
462  return -1;
463  }
464 }
465 
466 
467 Long_t StFtpcPoint::GetHardwarePosition() const
468 {
469  // Returns the hardware position of this hit.
470  // hw_position (32 bits)
471  // bits 0-3 det_id
472  // bits 4-8 FTPC pad plane (1-20)
473  // bits 9-11 Sector number within pad-plane (1-6)
474  // bits 12-19 number of pads in cluster (1-160)
475  // bits 20-28 number of consecutive timebins in cluster (1-256)
476  return (mNumberBins<<20)
477  + (mNumberPads<<12)
478  + (mSector<<9)
479  + (mPadRow<<4)
480  + this->GetDetectorId();
481 }
482 
483 
484 void StFtpcPoint::SetTrackedFlag(Bool_t tracked)
485 {
486  // Sets flag, if the cluster was used for tracking.
487  // This has to be done due to consistency with the point bank.
488 
489  Long_t old_flag = GetFlags();
490  SetFlags((old_flag & 0xFFFFFFDF) | ((Long_t)tracked*32));
491 }
492 
493 
494 Bool_t StFtpcPoint::GetTrackedFlag()
495 {
496  // Returns true, if 'tracked flag' is set, otherwise returns false.
497 
498  return (Bool_t)(GetFlags() & (Long_t)32);
499 }
500 
501 
502 void StFtpcPoint::SetGlobalFlag(Bool_t global)
503 {
504  // Sets flag, if the cluster is measured in global coordinates.
505 
506  Long_t old_flag = GetFlags();
507  SetFlags((old_flag & 0xFFFFFFAF) | ((Long_t)global*64));
508 }
509 
510 
511 Bool_t StFtpcPoint::GetGlobalFlag()
512 {
513  // Returns true, if 'global flag' is set, otherwise returns false.
514 
515  return (Bool_t)(GetFlags() & (Long_t)64);
516 }
517 
518 
519 void StFtpcPoint::SetUnusableForTrackingFlag(Bool_t global)
520 {
521  // Sets flag, if the cluster DOES NOT pass all quality criteria to be used for tracking.
522 
523  Long_t old_flag = GetFlags();
524  SetFlags((old_flag & 0xFFFFFFAF) | ((Long_t)global*128));
525 }
526 
527 
528 Bool_t StFtpcPoint::GetUnusableForTrackingFlag()
529 {
530  // Returns true, if 'UnusableForTracking flag' is set, otherwise returns false.
531 
532  return (Bool_t)(GetFlags() & (Long_t)128);
533 }
534 
535 
536 Bool_t StFtpcPoint::IsUsable()
537 {
538  // Returns true, if 'UsableForTracking flag' and 'tracked flag' is set, otherwise returns false.
539 
540  return (Bool_t)((!GetTrackedFlag()) && !(GetUnusableForTrackingFlag()));
541 }
542 
543 
544 Bool_t StFtpcPoint::IsUnusable()
545 {
546  // Returns true, if 'UsableForTracking flag' and 'tracked flag' is set, otherwise returns false.
547 
548  return (Bool_t)(GetTrackedFlag() || GetUnusableForTrackingFlag());
549 }
StMatrixD TpcToGlobalRotation()
transformation due to rotated and displaced TPC