16 using namespace FitNewton;
17 using namespace Eigen;
19 int main(
int argc,
char** argv)
21 bool print_truth =
false;
22 bool print_reco =
false;
24 TFile infile(argv[1]);
27 infile.GetObject(
"events", etree);
28 etree->SetBranchAddress(
"tracklist", &ttree);
45 radii.assign(nlayers,0.);
50 vector<float> smear_xy_layer;smear_xy_layer.assign(nlayers,0);
51 vector<float> smear_z_layer;smear_z_layer.assign(nlayers,0);
52 float sqrt_12 = sqrt(12.);
53 smear_xy_layer[0] = (50.0e-4/sqrt_12);
54 smear_z_layer[0] = (425.0e-4/sqrt_12);
55 smear_xy_layer[1] = (50.0e-4/sqrt_12);
56 smear_z_layer[1] = (425.0e-4/sqrt_12);
57 smear_xy_layer[2] = (80.0e-4/sqrt_12);
58 smear_z_layer[2] = (1000.0e-4/sqrt_12);
59 smear_xy_layer[3] = (80.0e-4/sqrt_12);
60 smear_z_layer[3] = (1000.0e-4/sqrt_12);
65 HelixRange top_range(0., 1.*
M_PI, -0.0025, 0.0025, 0., 0.03, -0.9, 0.9, -0.005, 0.005);
72 unsigned int max_hits = 5;
78 for(
unsigned int ev=0;ev<etree->GetEntries();ev++)
81 ttree->SetBranchAddress(
"track", &track);
82 ttree->SetBranchAddress(
"nhits", &nhits);
83 ttree->SetBranchAddress(
"x_hits", &x_hits);
84 ttree->SetBranchAddress(
"y_hits", &y_hits);
85 ttree->SetBranchAddress(
"z_hits", &z_hits);
86 ttree->SetBranchAddress(
"layer", &layer);
87 ttree->SetBranchAddress(
"trk_kappa", &trk_kappa);
88 ttree->SetBranchAddress(
"trk_d", &trk_d);
89 ttree->SetBranchAddress(
"trk_phi", &trk_phi);
90 ttree->SetBranchAddress(
"trk_dzdl", &trk_dzdl);
91 ttree->SetBranchAddress(
"trk_z0", &trk_z0);
92 ttree->SetBranchAddress(
"charge", &charge);
94 cout<<
"event "<<ev<<
":"<<endl<<endl;
96 vector<SimpleHit3D> hits;
97 vector<SimpleTrack3D> tracks;
99 cout<<
"total MC tracks = "<<ttree->GetEntries()<<endl;
102 for(
unsigned int trk=0;trk<ttree->GetEntries();trk++)
104 ttree->GetEntry(trk);
105 if(print_truth==
true)
107 cout<<
"truth track : "<<endl;
108 cout<<
"phi = "<<trk_phi<<endl;
109 cout<<
"d = "<<trk_d<<endl;
110 cout<<
"kappa = "<<trk_kappa<<endl;
111 cout<<
"dzdl = "<<trk_dzdl<<endl;
112 cout<<
"z0 = "<<trk_z0<<endl;
115 for(
unsigned int hit=0;hit<nhits;hit++)
117 float phi = atan2(y_hits[hit], x_hits[hit]);
118 float xy_error = smear_xy_layer[layer[hit]]*sqrt_12*0.5;
119 float x_error = fabs(xy_error*sin(phi));
120 float y_error = fabs(xy_error*
cos(phi));
121 float z_error = smear_z_layer[layer[hit]]*sqrt_12*0.5;
123 hits.push_back(
SimpleHit3D(x_hits[hit],x_error, y_hits[hit],y_error, z_hits[hit],z_error, index, layer[hit]));
129 double z_weight = 0.;
130 for(
unsigned int ht=0;ht<hits.size();++ht)
132 double temp = 1./(hits[ht].dz);
133 z_avg += (hits[ht].z)*temp;
137 cout<<
"z average = "<<z_avg<<endl;
141 HelixRange top_range_init(0., 1.*
M_PI, -0.1, 0.1, 0., 0.005, -0.9, 0.9, -0.1 + z_avg, 0.1 + z_avg);
142 FourHitSeedFinder tracker_init(radii, 2, 1, 2, 4, 2, min_res_init, max_res_init, top_range_init);
148 unsigned int max_hits_init = 8;
149 unsigned int maxtracks = 160;
152 maxtracks = 15*(hits.size())/1000;
153 if(maxtracks < 40){maxtracks=40;}
158 gettimeofday(&t1, NULL);
159 tracker_init.
findHelices(hits, 4, max_hits_init, tracks, maxtracks);
160 gettimeofday(&t2, NULL);
161 time1 = ((double)(t1.tv_sec) + (double)(t1.tv_usec)/1000000.);
162 time2 = ((double)(t2.tv_sec) + (double)(t2.tv_usec)/1000000.);
163 cout<<
"initial tracking time = "<<(time2 - time1)<<endl;
165 unsigned int ngood = 0;
166 unsigned int n_trk = tracks.size();
167 for(
unsigned int trk=0;trk<n_trk;++trk)
169 unsigned int high = 0;
170 unsigned int low = (1<<31);
171 unsigned int n_hit = tracks[trk].hits.size();
172 for(
unsigned int ht=0;ht<n_hit;++ht)
174 tracks[trk].hits[ht].index > high ? high = tracks[trk].hits[ht].index : high = high;
175 tracks[trk].hits[ht].index < low ? low = tracks[trk].hits[ht].index : low = low;
177 if( (high - low) <= 3 ){ngood++;}
180 cout<<
"tracks found before vertex finding = "<<tracks.size()<<endl;
181 cout<<
"good tracks found before vertex finding = "<<ngood<<endl;
190 VectorXd start_point = VectorXd::Zero(3);
191 VectorXd min_point = VectorXd::Zero(3);
201 minimizer.
minimize(start_point, min_point, 1.0
e-9, 16, 1.0
e-15);
204 start_point = min_point;
205 minimizer.
minimize(start_point, min_point, 1.0
e-9, 16, 1.0
e-15);
207 start_point = min_point;
208 minimizer.
minimize(start_point, min_point, 1.0
e-9, 16, 1.0
e-15);
212 vector<double> vertex;
214 vertex[0] = min_point(0);
215 vertex[1] = min_point(1);
216 vertex[2] = min_point(2);
222 cout <<
"Found Event vertex = " << vertex[0] <<
" " << vertex[1] <<
" " << vertex[2] << endl << endl;
227 for(
unsigned int ht=0;ht<hits.size();++ht)
229 hits[ht].x -= vertex[0];
230 hits[ht].y -= vertex[1];
231 hits[ht].z -= vertex[2];
234 gettimeofday(&t1, NULL);
237 gettimeofday(&t2, NULL);
238 time1 = ((double)(t1.tv_sec) + (double)(t1.tv_usec)/1000000.);
239 time2 = ((double)(t2.tv_sec) + (double)(t2.tv_usec)/1000000.);
240 cout<<
"primary tracking time = "<<(time2 - time1)<<endl;
242 for(
unsigned int trk=0;trk<tracks.size();++trk)
244 for(
unsigned int ht=0;ht<tracks[trk].hits.size();++ht)
246 tracks[trk].hits[ht].x += vertex[0];
247 tracks[trk].hits[ht].y += vertex[1];
248 tracks[trk].hits[ht].z += vertex[2];
255 n_trk = tracks.size();
256 for(
unsigned int trk=0;trk<n_trk;++trk)
258 unsigned int high = 0;
259 unsigned int low = (1<<31);
260 unsigned int n_hit = tracks[trk].hits.size();
261 for(
unsigned int ht=0;ht<n_hit;++ht)
263 tracks[trk].hits[ht].index > high ? high = tracks[trk].hits[ht].index : high = high;
264 tracks[trk].hits[ht].index < low ? low = tracks[trk].hits[ht].index : low = low;
266 if( (high - low) <= 3 ){ngood++;}
271 for(
unsigned int trk=0;trk<n_trk;++trk)
273 cout<<
"track "<<trk<<
" : "<<endl;
274 unsigned int n_hit = tracks[trk].hits.size();
275 for(
unsigned int ht=0;ht<n_hit;++ht)
277 cout<<
"hit "<<ht<<
" : ";
278 cout<<tracks[trk].hits[ht].x<<
" ";
279 cout<<tracks[trk].hits[ht].y<<
" ";
280 cout<<tracks[trk].hits[ht].z<<
" ";
281 cout<<tracks[trk].hits[ht].index<<endl;
283 cout<<
"phi = "<<tracks[trk].phi<<endl;
284 cout<<
"d = "<<tracks[trk].d<<endl;
285 cout<<
"kappa = "<<tracks[trk].kappa<<endl;
286 cout<<
"dzdl = "<<tracks[trk].dzdl<<endl;
287 cout<<
"z0 = "<<tracks[trk].z0<<endl;
293 cout<<n_trk<<
" tracks found"<<endl;
294 cout<<ngood<<
" good tracks found"<<endl;