-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTrackletConstructor.cxx
279 lines (213 loc) · 7.22 KB
/
TrackletConstructor.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
TNtuple *nt = (TNtuple*) gDirectory->FindObjectAny("mcTracklets");
"part:nhits:pt:p:w:nl:fitpt:layer:x:y:z:r:phi:ephiL:ezL:ephi:ez:dv:dz:dupl");
*/
#include "TrackletConstructor.h"
#include "Tracker.h"
#include "util.h"
#include "TString.h"
#include "TFile.h"
#include "TH1.h"
#include "TNtuple.h"
#include <iostream>
#include "TrackModelPhysical.h"
#include "FitLayer.h"
#include "TStopwatch.h"
using namespace std;
void TrackletConstructor::Reconstruct( const CreationCuts &crCuts, const ProlongationCuts &prCuts )
{
//cout<<"----------------- tracklet constructor .."<<endl;
mCreationCuts = crCuts;
mProlongationCuts = prCuts;
int statFitErrors=0;
int *mcParticlesNRec3=nullptr;
if( mTracker->mcFlag ){
mcParticlesNRec3 = new int[mTracker->mParticles.size()];
for( int i=0; i<mTracker->mParticles.size(); i++ ){
mcParticlesNRec3[i] = 0;
}
}
TStopwatch timer;
FitLayer layers[3];
for( int i=0; i<3; i++ ){
FitLayer &layer = layers[i];
layer.mTracker = mTracker;
}
LayerCreationCuts cuts1 = mCreationCuts.layerCuts[0];
LayerCreationCuts cuts2 = mCreationCuts.layerCuts[1];
LayerCreationCuts cuts3 = mCreationCuts.layerCuts[2];
int iLayer1 = cuts1.iLayer;
int iLayer2 = cuts2.iLayer;
int iLayer3 = cuts3.iLayer;
layers[0].Create( iLayer1, 0, 2*cuts2.cutPhiL, 2*cuts2.cutTL ); // make same bins as in layer2
layers[1].Create( iLayer2, 0, 2*cuts2.cutPhiL, 2*cuts2.cutTL );
layers[2].Create( iLayer3, 0, 2*cuts3.cutPhiL, 2*cuts3.cutTL );
FitLayer &layer1 = layers[0];
FitLayer &layer2 = layers[1];
FitLayer &layer3 = layers[2];
int nTracklets2 = 0;
int nTracklets2Good = 0;
int nTracklets3 = 0;
int nTracklets3Good = 0;
long int statN1=0;
long int statN2=0;
long int statN3=0;
// create layers for fit
{
for( int vol=0; vol<Geo::NVolumes; vol++){
const LayerProlongationCuts &cuts = mProlongationCuts.volumeCuts[vol];
Volume &v = Geo::volumes[vol];
for( int ilayer=0; ilayer<v.nLayers; ilayer++ ){
int id = Geo::getLayerID(vol,ilayer) ;
FitLayer &layer = mTracker->mFitLayers[ id ];
layer.Create( id, 0, 2*cuts.cutPhi, 2*cuts.cutT );
}
}
}
for( int ih1=0; ih1<layer1.mFitHits.size(); ih1++ ){
statN1++;
FitLayerHit h1 = layer1.mFitHits[ih1];
int mcID1 = -1;
// skip cloned hits in first and last phi search bins
if( h1.isClone ) continue;
if( mTracker->mcFlag ) mcID1 = mTracker->mHitsMC[h1.id].partID;
double extr2T;
double extr2Phi = h1.phi;
if( crCuts.useVertex ){
if( layer2.mType==0 ){
extr2T = layer2.mR * h1.z/h1.r;
} else {
extr2T = layer2.mZ * h1.r/h1.z;
}
} else {
extr2T = h1.t;
}
// cut on the layer size in Z/R
if( extr2T < layer2.mTmin - cuts2.cutTL || extr2T > layer2.mTmax + cuts2.cutTL ) continue;
// look for the second hit
int iBin2Phi = layer2.getBinPhi( extr2Phi );
int iBin2T = layer2.getBinT( extr2T );
if( iBin2Phi<0 || iBin2T<0 ) continue;
for( int it2=0; it2<2; it2++, iBin2T++ ){
int iBin2 = iBin2T*layer2.mNbinsPhi + iBin2Phi;
int ih2 = layer2.mBins[iBin2].firstHit;
int ih2end = layer2.mBins[iBin2+1].firstHit+layer2.mBins[iBin2+1].nHits;
for( ; ih2<ih2end; ih2++){
statN2++;
FitLayerHit &h2 = layer2.mFitHits[ih2];
// accurate cut on z and phi
if( fabs( extr2T - h2.t ) > cuts2.cutTL ) continue;
if( fabs( extr2Phi - h2.searchPhi ) > cuts2.cutPhiL ) continue;
nTracklets2++;
// check mc info
int mcID2=-1;
if( mTracker->mcFlag ) {
HitMC &mc2 = mTracker->mHitsMC[h2.id];
mcID2 = mc2.partID;
if( mcID1 >=0 && mc2.partID != mcID1 ){
mcID2 = -1;
}
if( mcID2>=0 ) nTracklets2Good++;
}
// look for the third hit
double extr3T = 0;
double extr3Phi = 0;
// make straight helix to use existing helix utility for layer crossing (TODO: use simple math )
TrackModelPhysical t2Line;
{
int err = t2Line.createXYLast( h1.x, h1.y, h1.z,
(h1.x+h2.x)/2, (h1.y+h2.y)/2,(h1.z+h2.z)/2,
h2.x, h2.y, h2.z, (h1.BzFwd+h2.BzBck)/2 );
if( layer3.mType == 0 ){ // radial layer
err = t2Line.getPhiZatR( layer3.mR, extr3Phi, extr3T, h2.BzFwd );
} else {
err = t2Line.getPhiRatZ( layer3.mZ, extr3Phi, extr3T, h2.BzFwd );
}
if( err!=0 ){
cout<<"Error by tracklet line extrapolation to layer "<<iLayer3<<" r: "<<layer3.mR<<" z "<<layer3.mZ<<" !!!: err= "<<err<<endl;
layer3.Print();
statFitErrors++;
continue;
}
}
// cut on z
if( extr3T < layer3.mTmin - cuts3.cutTL || extr3T > layer3.mTmax + cuts3.cutTL ) continue;
int iBin3Phi = layer3.getBinPhi( extr3Phi );
int iBin3T = layer3.getBinT( extr3T );
if( iBin3Phi<0 || iBin3T<0 ) continue;
for( int it3=0; it3<2; it3++, iBin3T++ ){
int iBin3 = iBin3T*layer3.mNbinsPhi + iBin3Phi;
int ih3 = layer3.mBins[iBin3].firstHit;
int ih3end = layer3.mBins[iBin3+1].firstHit+layer3.mBins[iBin3+1].nHits;
for( ; ih3<ih3end; ih3++){
statN3++;
FitLayerHit &h3 = layer3.mFitHits[ih3];
// accurate cut on z and phi
if( fabs( h3.t - extr3T ) > cuts3.cutTL ) continue;
if( fabs( h3.searchPhi - extr3Phi ) > cuts3.cutPhiL ) continue;
// all cuts passed, try to create a helix
double Bz = h2.BzMid;
TrackModelPhysical t;
int err = t.createXYLast( h1.x, h1.y, h1.z,
h2.x, h2.y, h2.z,
h3.x, h3.y, h3.z, Bz);
if( err!=0 ){
// cout<<"Error by tracklet creation "<<" err= "<<err<<endl;
statFitErrors++;
continue;
}
// get Z deviation for the first hit
double dv=0, duz=0;
if( layer1.mType==0 ){
err = t.getDistanceAtXY( h1.x, h1.y, h1.z, duz, dv, Bz);
} else {
err = t.getDistanceAtZ( h1.x, h1.y, h1.z, duz, dv, Bz);
}
if( err!=0 ){
cout<<"Error by track chi2 calculation!!!: err= "<<err<<endl;
statFitErrors++;
continue;
}
// cut on dz at layer 2
if( fabs(duz) > cuts3.cutDuz ) continue;
if( t.getPtkG() < mCreationCuts.ptCut ) continue;
nTracklets3++;
int mcID3=-1;
if( mTracker->mcFlag ) {
HitMC &mc3 = mTracker->mHitsMC[h3.id];
if( mcID2 >=0 && mc3.partID==mcID2 ){
mcID3 = mcID2;
nTracklets3Good++;
mcParticlesNRec3[mcID3]++;
}
}
//if( mcID3<0 ) continue;//SG!!!
//t.Print();
ProlongateTracklet( iLayer1, h1,
iLayer2, h2,
iLayer3, h3,
t, vTracklets );
} // ih3
} // iz3
} // ih2
} // iz2
} // ih1
timer.Stop();
int nParticlesRec3=0;
if( mTracker->mcFlag ){
for( int i=0; i<mTracker->mParticles.size(); i++ ){
Particle &p = mTracker->mParticles[i];
if( p.w>0 && mcParticlesNRec3[i]>0 ) nParticlesRec3++;
}
}
delete[] mcParticlesNRec3;
cout<<"Created "<<nTracklets3<<" triplets ("<< nTracklets3Good <<" good )"<<endl;
cout<<"Reconstructed "<<nParticlesRec3<<" particles at layer 3"<<endl;
/*
cout<<"\nfit errors: "<<statFitErrors<<endl;
cout<<"\ntime "<<timer.CpuTime()*1000<<" ms\n"<<endl;
cout<<"entries in 1 loop: "<<statN1<<endl;
cout<<"entries in 2 loop: "<<statN2<<endl;
cout<<"entries in 3 loop: "<<statN3<<endl;
*/
}