File indexing completed on 2025-08-05 08:15:11
0001 #include "ReconstructTracks.h"
0002 #include "groot.h"
0003 #include "ABlob.h"
0004 #include "ABlob.h"
0005
0006 #include "ATrack.h"
0007
0008 #include "TH2D.h"
0009 #include "TMath.h"
0010
0011 #include <iostream>
0012 #include <cmath>
0013
0014 using namespace std;
0015
0016
0017 static TH2D *trkDeltaOri;
0018 static TH2D *trkDeltaRes;
0019
0020 void ReconstructTracks()
0021 {
0022 groot* Tree = groot::instance();
0023 Tree->theTracks.clear();
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 static bool trkCreateOutput = true;
0044 double xmu, ymu, xsg, ysg, xysg;
0045
0046 if(trkCreateOutput) {
0047 trkDeltaOri = new TH2D("trkDeltaOri","trkDeltaOri;dX (cm);dY (cm)",768,-10,+10,768,-10,+10);
0048 trkDeltaRes = new TH2D("trkDeltaRes","trkDeltaRes;Normalized dX; Normalized dY",120,-6,+6,120,-6,+6);
0049 trkCreateOutput = false;
0050 }
0051
0052
0053 const int mxcl1 = 40;
0054 const int mxcl2 = 90;
0055 int cl1[mxcl1], cl2[mxcl2];
0056 int ncl1=0, ncl2=0;
0057 for( int i=0; i< Tree->theBlob.size(); i++)
0058 {
0059 if ( Tree->theBlob.at( i )->ID() == 0 )
0060 cl1[ncl1++] = i;
0061 if ( Tree->theBlob.at( i )->ID() == 1 )
0062 cl2[ncl2++] = i;
0063 if((ncl1+1)>mxcl1)
0064 {
0065 printf("We found more than %d blobs!!\n",mxcl1);
0066 break;
0067 }
0068 if((ncl2+1)>mxcl2)
0069 {
0070 printf("We found more than %d blobs!!\n",mxcl2);
0071 break;
0072 }
0073 }
0074
0075 xysg = ReconstructTracks_Ref(xmu,xsg,ymu,ysg);
0076 double var[mxcl1][mxcl2];
0077 double vc3[mxcl1][mxcl2];
0078 for(int i=0; i!=ncl1; ++i)
0079 for(int j=0; j<ncl2; j++) {
0080 double x1 = Tree->theBlob[cl1[i]]->BestX();
0081 double y1 = Tree->theBlob[cl1[i]]->BestY();
0082 double x2 = Tree->theBlob[cl2[j]]->BestX();
0083 double y2 = Tree->theBlob[cl2[j]]->BestY();
0084 double c1 = Tree->theBlob[cl1[i]]->GetNSigma();
0085 double c2 = Tree->theBlob[cl2[j]]->GetNSigma();
0086 double dx = x2-x1;
0087 double dy = y2-y1;
0088 trkDeltaOri->Fill(dx/10000,dy/10000);
0089 double nSigmaX = (dx-xmu)/xsg;
0090 double nSigmaY = (dy-ymu)/ysg;
0091 trkDeltaRes->Fill(nSigmaX,nSigmaY);
0092 double c3 = nSigmaX*nSigmaX + nSigmaY*nSigmaY;
0093 var[i][j] = c1*c1+c2*c2+c3;
0094 vc3[i][j] = TMath::Sqrt(c3);
0095 }
0096
0097 int nMAXtrk=TMath::Min(ncl1,ncl2);
0098 int trk[mxcl1][2];
0099 int ntrk=0;
0100 for(;ntrk!=nMAXtrk;++ntrk) {
0101 double min = 1e12;
0102 int pi, pj;
0103 double c3;
0104 for(int i=0; i!=ncl1; ++i) {
0105 bool skip = false;
0106 for(int n=0; n!=ntrk; ++n) if(trk[n][0]==cl1[i]) skip=true;
0107 if(skip) continue;
0108
0109 for(int j=0; j!=ncl2; ++j) {
0110 skip=false;
0111 for(int n=0; n!=ntrk; ++n) if(trk[n][1]==cl2[j]) skip=true;
0112 if(skip) continue;
0113
0114 if(var[i][j]<min) {
0115 min = var[i][j];
0116 c3 = vc3[i][j];
0117 pi = cl1[i];
0118 pj = cl2[j];
0119 }
0120 }
0121 }
0122 trk[ntrk][0] = pi;
0123 trk[ntrk][1] = pj;
0124 vector<ABlob*> tempvec;
0125 tempvec.push_back( Tree->theBlob.at( pi ) );
0126 tempvec.push_back( Tree->theBlob.at( pj ) );
0127 Tree->theTracks.push_back ( new ATrack( tempvec,
0128 Tree->theBlob.at(pi)->GetNSigma(),
0129 Tree->theBlob.at(pj)->GetNSigma(),
0130 c3) );
0131
0132 }
0133
0134 }