StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtSimpleCosmicTrackAlgo.cxx
1 /***************************************************************************
2  *
3  * $Id: StFgtSimpleCosmicTrackAlgo.cxx,v 1.1 2012/01/31 23:25:36 avossen Exp $
4  * Author: C. K. Riley (ckriley@bnl.gov), Oct. 11 2011
5  *
6  ***************************************************************************
7  *
8  * Description: Simple CosmicTrack making algorithm takes 3 points
9  * from all 3 quads in test stand and does a chi^2 fit
10  *
11  ***************************************************************************
12  *
13  * $Log: StFgtSimpleCosmicTrackAlgo.cxx,v $
14  * Revision 1.1 2012/01/31 23:25:36 avossen
15  * moved StFgtCosmicTrackMaker to StFgtPool
16  *
17  * Revision 1.11 2011/11/28 17:03:46 ckriley
18  * minor fix
19  *
20  * Revision 1.10 2011/11/25 20:24:59 ckriley
21  * now will look at all possible point combinations for tracks and pick the best one
22  *
23  * Revision 1.9 2011/11/16 22:15:07 ckriley
24  * now looks at all points on quadrants and gets best track
25  *
26  * Revision 1.8 2011/11/01 18:50:13 sgliske
27  * Updated to correspond with StEvent containers, take 2.
28  *
29  * Revision 1.7 2011/10/28 18:30:09 ckriley
30  * make things up-to-date
31  *
32  * Revision 1.5 2011/10/20 17:13:44 ckriley
33  * major update -> headers, tracks stored in StFgtEvent instead of StFgtDisc, changes to trackmaker and algorithms
34  *
35  *
36  **************************************************************************/
37 
38 #include "StFgtSimpleCosmicTrackAlgo.h"
39 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
40 #include "StRoot/StEvent/StFgtCollection.h"
41 #include "StRoot/StEvent/StFgtPoint.h"
42 
43 
44 StFgtSimpleCosmicTrackAlgo::StFgtSimpleCosmicTrackAlgo():mIsInitialized(0) {
45  //nothing else to do....
46 };
47 
48 // initialize
49 Int_t StFgtSimpleCosmicTrackAlgo::Init() {
50  mIsInitialized=true;
51  return kStOk;
52 };
53 
54 // will loop through all points and assign a track to each, storing the best
55 Int_t StFgtSimpleCosmicTrackAlgo::makeCosmicTracks(StFgtPointCollection& points, StFgtCosmicTrackVec& tracks, Int_t eventCounter) {
56 
57  // calculate track -> get 4 param for best fit line
58  Float_t chi2x=0, chi2y=0, chi2=0, chiMin=99999;
59  Float_t x_0=0, y_0=0, trackX_0=0, trackY_0=0;
60  Float_t a=1, b=1, trackA=1, trackB=1;
61  Float_t dX=0, dY=0, trackdX=0, trackdY=0, hitX=0, hitY=0;
62  Bool_t isTrack=false, isTrueTrack=false;
63  Float_t XoS=0, YoS=0, ZoS=0, OoS=0,
64  XXoS=0, YYoS=0, ZZoS=0, ZXoS=0, ZYoS=0,
65  sigma=0.3*0.3;// +a*a*0.5*0.5;// assuming known Z and XY errors of 3mm
66  Int_t quad0Id, quad1Id, quad2Id;
67  Float_t x0,y0,z0,r0,phi0,x1,y1,z1,r1,phi1,x2,y2,z2,r2,phi2;
68 
69  const StSPtrVecFgtPoint &pointVec = points.getPointVec();
70  StSPtrVecFgtPointConstIterator pointIter0, pointIter1, pointIter2;
71 
72  for( pointIter0 = pointVec.begin(); pointIter0 != pointVec.end(); ++pointIter0 ) {
73  quad0Id = (*pointIter0)->getDisc();
74  r0 = (*pointIter0)->getPositionR();
75  phi0 = (*pointIter0)->getPositionPhi();
76  x0 = r0*cos(phi0+.2618);
77  y0 = r0*sin(phi0+.2618);
78  z0 = 30.48; // 12 inches in cm, top quadrant
79  if( quad0Id==0 ) {
80  for( pointIter1 = pointVec.begin(); pointIter1 != pointVec.end(); ++pointIter1) {
81  quad1Id = (*pointIter1)->getDisc();
82  r1 = (*pointIter1)->getPositionR();
83  phi1 = (*pointIter1)->getPositionPhi();
84  x1 = r1*cos(phi1+.2618);
85  y1 = r1*sin(phi1+.2618);
86  z1 = 15.24; // 6 inches in cm, middle quadrant
87  if( quad1Id==1 ) {
88  for( pointIter2 = pointVec.begin(); pointIter2 != pointVec.end(); ++pointIter2) {
89  quad2Id = (*pointIter2)->getDisc();
90  r2 = (*pointIter2)->getPositionR();
91  phi2 = (*pointIter2)->getPositionPhi();
92  x2 = r2*cos(phi2+.2618);
93  y2 = r2*sin(phi2+.2618);
94  z2 = 0.; // take origin as bottom quadrant
95  if( quad2Id==2 ) {
96  XoS = (x0+x1+x2)/sigma;
97  YoS = (y0+y1+y2)/sigma;
98  ZoS = (z0+z1+z2)/sigma;
99  OoS = 3/sigma;
100  XXoS = (x0*x0+x1*x1+x2*x2)/sigma;
101  YYoS = (y0*y0+y1*y1+y2*y2)/sigma;
102  ZZoS = (z0*z0+z1*z1+z2*z2)/sigma;
103  ZXoS = (x0*z0+x1*z1+x2*z2)/sigma;
104  ZYoS = (y0*z0+y1*z1+y2*z2)/sigma;
105 
106  // do two 2D cases. x = a*z + x_0 and y = b*z + y_0
107  Float_t denominator = ZZoS*OoS-ZoS*ZoS;
108  if(denominator != 0) {
109  a = (ZXoS*OoS-XoS*ZoS)/denominator;
110  x_0 = (ZZoS*XoS-ZXoS*ZoS)/denominator;
111  b = (ZYoS*OoS-YoS*ZoS)/denominator;
112  y_0 = (ZZoS*YoS-ZYoS*ZoS)/denominator;
113  }
114  chi2x = (x0-(a*z0+x_0))*(x0-(a*z0+x_0))/sigma + (x1-(a*z1+x_0))*(x1-(a*z1+x_0))/sigma + (x2-(a*z2+x_0))*(x2-(a*z2+x_0))/sigma;
115  chi2y = (y0-(b*z0+y_0))*(y0-(b*z0+y_0))/sigma + (y1-(b*z1+y_0))*(y1-(b*z1+y_0))/sigma + (y2-(b*z2+y_0))*(y2-(b*z2+y_0))/sigma;
116  // as there is 1 degree of freedom (3datapoints - 2 parameters) this is reduced chi2
117  chi2 = (chi2x+chi2y)/2;
118  if(chi2x<4 && chi2y<4) { // is for 95% track
119  //cout << "\nFound track in event " << eventCounter << "! (chi^2 fit)" << endl;
120  isTrack = true;
121  }
122  // create dX dY distance of actual to expected point on middle disc
123  dX = x1-(a*z1+x_0);
124  dY = y1-(b*z1+y_0);
125 
126  // store track with lowest chi2
127  if(chi2<chiMin) {
128  chiMin=chi2;
129  trackA=a;
130  trackB=b;
131  trackX_0=x_0;
132  trackY_0=y_0;
133  trackdX=dX;
134  trackdY=dY;
135  hitX=x1;
136  hitY=y1;
137  isTrueTrack=isTrack;
138  }
139  }
140  }
141  }
142  }
143  }
144  }
145  // now must store values chi2 and a,b,x_0,y_0 in a container in StFgtEvent
146 
147  tracks.push_back( StFgtCosmicTrack (eventCounter, trackA, trackB, trackX_0, trackY_0, trackdX, trackdY, chiMin, hitX, hitY, isTrueTrack) );
148 
149  return kStOk;
150 };
151 
Definition: Stypes.h:41