Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ReconstructTracks.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ReconstructTracks.C
1 #include "ReconstructTracks.h"
2 #include "groot.h"
3 #include "ABlob.h"
4 #include "ABlob.h"
5 
6 #include "ATrack.h"
7 
8 #include "TH2D.h"
9 #include "TMath.h"
10 
11 #include <iostream>
12 #include <cmath>
13 
14 using namespace std;
15 
16 
17 static TH2D *trkDeltaOri; // accumalation of uncorrected data per run
18 static TH2D *trkDeltaRes; // accumalation of corrected and normalized data per run
19 
21 {
22  groot* Tree = groot::instance();
23  Tree->theTracks.clear();
24 
25  //
26  // OK Track Fans. Now that we have some studies
27  // done of the beam at FNAL, we find that the
28  // TRUE beam is pretty well columnated. For this reason,
29  // we can a priori reject blob combinations that
30  // do not follow the standard pointing.
31  //
32  // We shall apply hard-coded fits to the rough
33  // correlation between the track directions and
34  // thereby be able to make cuts that will result in
35  // only pretty good tracks.
36  //
37  // Wish us luck!
38  //
39  // TKH 10-12-2013
40  //
41  //
42 
43  static bool trkCreateOutput = true;
44  double xmu, ymu, xsg, ysg, xysg;
45 
46  if(trkCreateOutput) { // create new containers. Once per running program
47  trkDeltaOri = new TH2D("trkDeltaOri","trkDeltaOri;dX (cm);dY (cm)",768,-10,+10,768,-10,+10);
48  trkDeltaRes = new TH2D("trkDeltaRes","trkDeltaRes;Normalized dX; Normalized dY",120,-6,+6,120,-6,+6);
49  trkCreateOutput = false;
50  }
51 
52  // gathering blob info
53  const int mxcl1 = 40;
54  const int mxcl2 = 90; //mxcl2>mxcl1!
55  int cl1[mxcl1], cl2[mxcl2];
56  int ncl1=0, ncl2=0;
57  for( int i=0; i< Tree->theBlob.size(); i++)
58  {
59  if ( Tree->theBlob.at( i )->ID() == 0 )
60  cl1[ncl1++] = i;
61  if ( Tree->theBlob.at( i )->ID() == 1 )
62  cl2[ncl2++] = i;
63  if((ncl1+1)>mxcl1)
64  {
65  printf("We found more than %d blobs!!\n",mxcl1);
66  break;
67  }
68  if((ncl2+1)>mxcl2)
69  {
70  printf("We found more than %d blobs!!\n",mxcl2);
71  break;
72  }
73  }
74  // making all combinations
75  xysg = ReconstructTracks_Ref(xmu,xsg,ymu,ysg);
76  double var[mxcl1][mxcl2];
77  double vc3[mxcl1][mxcl2];
78  for(int i=0; i!=ncl1; ++i)
79  for(int j=0; j<ncl2; j++) {
80  double x1 = Tree->theBlob[cl1[i]]->BestX();
81  double y1 = Tree->theBlob[cl1[i]]->BestY();
82  double x2 = Tree->theBlob[cl2[j]]->BestX();
83  double y2 = Tree->theBlob[cl2[j]]->BestY();
84  double c1 = Tree->theBlob[cl1[i]]->GetNSigma();
85  double c2 = Tree->theBlob[cl2[j]]->GetNSigma();
86  double dx = x2-x1;
87  double dy = y2-y1;
88  trkDeltaOri->Fill(dx/10000,dy/10000); //in cm
89  double nSigmaX = (dx-xmu)/xsg;
90  double nSigmaY = (dy-ymu)/ysg;
91  trkDeltaRes->Fill(nSigmaX,nSigmaY);
92  double c3 = nSigmaX*nSigmaX + nSigmaY*nSigmaY;
93  var[i][j] = c1*c1+c2*c2+c3;
94  vc3[i][j] = TMath::Sqrt(c3);
95  }
96  // sorting
97  int nMAXtrk=TMath::Min(ncl1,ncl2);
98  int trk[mxcl1][2];
99  int ntrk=0;
100  for(;ntrk!=nMAXtrk;++ntrk) {
101  double min = 1e12; // to save time and hopping no nsigma is bigger than this =)
102  int pi, pj;
103  double c3;
104  for(int i=0; i!=ncl1; ++i) {
105  bool skip = false;
106  for(int n=0; n!=ntrk; ++n) if(trk[n][0]==cl1[i]) skip=true; // skipping combinations with used blobs from TR1
107  if(skip) continue;
108  //cout << "loop " << cl1[i] << endl;
109  for(int j=0; j!=ncl2; ++j) {
110  skip=false;
111  for(int n=0; n!=ntrk; ++n) if(trk[n][1]==cl2[j]) skip=true; // skipping combinations with used blobs from TR2
112  if(skip) continue;
113  //cout << " loop " << cl2[j] << " quality^2 " << var[i][j] << endl;
114  if(var[i][j]<min) {
115  min = var[i][j];
116  c3 = vc3[i][j];
117  pi = cl1[i];
118  pj = cl2[j];
119  }
120  }
121  }
122  trk[ntrk][0] = pi;
123  trk[ntrk][1] = pj;
124  vector<ABlob*> tempvec;
125  tempvec.push_back( Tree->theBlob.at( pi ) ); //tr1
126  tempvec.push_back( Tree->theBlob.at( pj ) ); //tr2
127  Tree->theTracks.push_back ( new ATrack( tempvec,
128  Tree->theBlob.at(pi)->GetNSigma(),
129  Tree->theBlob.at(pj)->GetNSigma(),
130  c3) );
131  //cout << "Found track " << ntrk << " made out of blobs " << pi << " and " << pj << " with quality " << Tree->theTracks.at(ntrk)->GetOverallQuality() << endl;
132  }
133 
134 }