113 {
114
115#ifdef TRKRECO_DEBUG_DETAIL
116 std::cout << " TCosmicFitter::fit ..." << std::endl;
117#endif
118
120 Gaudi::svcLocator() -> service("MdcCalibFunSvc", l_mdcCalFunSvc);
121
122
124 unsigned nValid = 0;
125 for (
unsigned i = 0; i < b.
links().length(); i++) {
126 unsigned state = b.
links()[i]->hit()->state();
129 }
131
132
133
136
137
138 double _t0_bes = -1.;
140 Gaudi::svcLocator()->service(
"MessageSvc",
msgSvc);
141 MsgStream log(
msgSvc,
"TCosmicFitter");
142
143 IDataProviderSvc* eventSvc = NULL;
144 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
145
146 SmartDataPtr<RecEsTimeCol> aevtimeCol(eventSvc,"/Event/Recon/RecEsTimeCol");
147 if (aevtimeCol) {
148 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
149 _t0_bes = (*iter_evt)->getTest();
150
151 }else{
152 log << MSG::WARNING << "Could not find RecEsTimeCol" << endreq;
153 }
154
155
156
157
166 double chi2;
167
170 bool allAxial = true;
173 int err = 0;
174 double factor = 1.0;
175
177 for (unsigned i = 0; i < 5; i++) maxDouble[i] = (FLT_MAX);
178
179
180 unsigned nTrial = 0;
182
183
184 chi2 = 0.;
185 for (unsigned j = 0; j < 5; j++) dchi2da[j] = 0.;
187
188#if CAL_TOF_HELIX
189
190 const float Rad = 81;
191 float dRho =
t.helix().a()[0];
192 float Lproj = sqrt(Rad*Rad - dRho*dRho);
193 float tlmd =
t.helix().a()[4];
194 float fct = sqrt(1. + tlmd * tlmd);
195#endif
196
197
198 unsigned i = 0;
199 while (
TMLink * l =
t.links()[i++]) {
201
202
205
206
207 if (! nTrial)
209
210
211 int doSagCorrection = 0;
212
213 t.approach(* l, doSagCorrection);
214 double dPhi = l->dPhi();
215 const HepPoint3D & onTrack = l->positionOnTrack();
216 const HepPoint3D & onWire = l->positionOnWire();
217
218#ifdef TRKRECO_DEBUG_DETAIL
219
220
221#endif
222
223
225 if (onWire.cross(onTrack).z() < 0.) leftRight =
WireHitLeft;
226 double distance = h.
drift(leftRight);
227 double eDistance = h.
dDrift(leftRight);
228
229 if(nTrial && !allAxial){
230 int side = leftRight;
231
232 double Tfly = _t0_bes/220.*(110.-onWire.y());
233#if CAL_TOF_HELIX
234 float Rad_wire = sqrt(x[0]*x[0]+x[1]*x[1]);
235 float L_wire = sqrt(Rad_wire*Rad_wire - dRho*dRho);
236 float flyLength = Lproj - L_wire;
237 if (x[1]<0) flyLength = Lproj + L_wire;
238 Tfly = flyLength/29.98*sqrt(1.0+(0.105/0.5)*(0.105/0.5))*fct;
239#endif
240 float time = l->hit()->reccdc()->tdc - Tfly;
241
244 float dist = distance;
245 float edist = eDistance;
246 double T0 = l_mdcCalFunSvc->
getT0(layerId,wire);
247 double rawadc = 0.;
248 rawadc =l->hit()->reccdc()->adc;
249
250 double timeWalk = l_mdcCalFunSvc->
getTimeWalk(layerId, rawadc);
251 double drifttime =
time -T0-timeWalk;
252 dist = l_mdcCalFunSvc->
driftTimeToDist(drifttime,layerId, wire, side, 0.0);
253 edist = l_mdcCalFunSvc->
getSigma(layerId, side, dist, 0.0);
254 dist = dist/10.0;
255 edist = edist/10.0;
256
257
258
259
260 distance = (double) dist;
261 eDistance = (double) edist;
262
263 l->drift(distance,0);
264 l->drift(distance,1);
265 l->dDrift(eDistance,0);
266 l->dDrift(eDistance,1);
267 l->tof(Tfly);
268 }
269 double eDistance2 = eDistance * eDistance;
270
271
273 double vmag =
v.mag();
274 double dDistance = vmag - distance;
275
276
277 this->dxda(*l,
t.helix(), dPhi, dxda, dyda, dzda, doSagCorrection);
278
279
280
282 dDda = (vmag > 0.)
283 ? ((
v.x() * (1. - vw.x() * vw.x()) -
284 v.y() * vw.x() * vw.y() -
v.z() * vw.x() * vw.z())
285 * dxda +
286 (
v.y() * (1. - vw.y() * vw.y()) -
287 v.z() * vw.y() * vw.z() -
v.x() * vw.y() * vw.x())
288 * dyda +
289 (
v.z() * (1. - vw.z() * vw.z()) -
290 v.x() * vw.z() * vw.x() -
v.y() * vw.z() * vw.y())
291 * dzda) / vmag
293 if(vmag<=0.0) {
294 std::cout << " in fit " << onTrack << ", " << onWire;
296 }
297 dchi2da += (dDistance / eDistance2) * dDda;
298 d2chi2d2a += vT_times_v(dDda) / eDistance2;
299 double pChi2 = dDistance * dDistance / eDistance2;
300 chi2 += pChi2;
301
302
303 l->update(onTrack, onWire, leftRight, pChi2);
304 }
305
306
307 double change = chi2Old - chi2;
308 if (fabs(change) < convergence) break;
309
310
311 if (change < 0.){
312#ifdef TRKRECO_DEBUG_DETAIL
313 std::cout << "chi2Old, chi2=" << chi2Old <<" "<< chi2 << std::endl;
314#endif
315
316 a += factor*da;
317
319
320 chi2 = 0.;
321 for (unsigned j = 0; j < 5; j++) dchi2da[j] = 0.;
323
324
325 unsigned i = 0;
326 while (
TMLink * l =
t.links()[i++]) {
328
329
332
333
334 if (! nTrial)
336
337
338 int doSagCorrection = 0;
339
340 t.approach(* l, doSagCorrection);
341 double dPhi = l->dPhi();
342 const HepPoint3D & onTrack = l->positionOnTrack();
343 const HepPoint3D & onWire = l->positionOnWire();
344
345#ifdef TRKRECO_DEBUG_DETAIL
346
347
348#endif
349
350
352 if (onWire.cross(onTrack).z() < 0.) leftRight =
WireHitLeft;
353 double distance = h.
drift(leftRight);
354 double eDistance = h.
dDrift(leftRight);
355 if(nTrial && !allAxial){
356 int side = leftRight;
357
358 double Tfly = _t0_bes/220.*(110.-onWire.y());
359#if CAL_TOF_HELIX
360 float Rad_wire = sqrt(x[0]*x[0]+x[1]*x[1]);
361 float L_wire = sqrt(Rad_wire*Rad_wire - dRho*dRho);
362 float flyLength = Lproj - L_wire;
363 if (x[1]<0) flyLength = Lproj + L_wire;
364 Tfly = flyLength/29.98*sqrt(1.0+(0.105/10)*(0.105/10))*fct;
365#endif
366
367 float time = l->hit()->reccdc()->tdc - Tfly;
368
371 float dist= distance;
372 float edist = eDistance;
373
374
375 double T0 = l_mdcCalFunSvc->
getT0(layerId,wire);
376 double rawadc = 0.;
377 rawadc =l->hit()->reccdc()->adc;
378 double timeWalk = l_mdcCalFunSvc->
getTimeWalk(layerId, rawadc);
379 double drifttime =
time -T0-timeWalk;
380 dist = l_mdcCalFunSvc->
driftTimeToDist(drifttime,layerId, wire, side, 0.0);
381 edist = l_mdcCalFunSvc->
getSigma(layerId, side, dist, 0.0);
382 dist = dist/10.0;
383 edist = edist/10.0;
384
385
386
387
388 distance = (double) dist;
389 eDistance = (double) edist;
390
391 l->drift(distance,0);
392 l->drift(distance,1);
393 l->dDrift(eDistance,0);
394 l->dDrift(eDistance,1);
395 l->tof(Tfly);
396 }
397 double eDistance2 = eDistance * eDistance;
398
399
401 double vmag =
v.mag();
402 double dDistance = vmag - distance;
403
404
405 this->dxda(*l,
t.helix(), dPhi, dxda, dyda, dzda, doSagCorrection);
406
407
408
410 dDda = (vmag > 0.)
411 ? ((
v.x() * (1. - vw.x() * vw.x()) -
412 v.y() * vw.x() * vw.y() -
v.z() * vw.x() * vw.z())
413 * dxda +
414 (
v.y() * (1. - vw.y() * vw.y()) -
415 v.z() * vw.y() * vw.z() -
v.x() * vw.y() * vw.x())
416 * dyda +
417 (
v.z() * (1. - vw.z() * vw.z()) -
418 v.x() * vw.z() * vw.x() -
v.y() * vw.z() * vw.y())
419 * dzda) / vmag
421 if(vmag<=0.0) {
422 std::cout << " in fit " << onTrack << ", " << onWire;
424 }
425 dchi2da += (dDistance / eDistance2) * dDda;
426 d2chi2d2a += vT_times_v(dDda) / eDistance2;
427 double pChi2 = dDistance * dDistance / eDistance2;
428 chi2 += pChi2;
429
430
431 l->update(onTrack, onWire, leftRight, pChi2);
432 }
433
434 factor *= 0.75;
435#ifdef TRKRECO_DEBUG_DETAIL
436 std::cout << "factor = " << factor << std::endl;
437 std::cout << "chi2 = " << chi2 << std::endl;
438#endif
439 if(factor < 0.01)break;
440 }
441
442 chi2Old = chi2;
443
444
445 if (allAxial) {
446 f = dchi2da.sub(1, 3);
447 e = d2chi2d2a.sub(1, 3);
448 f = solve(e, f);
449 da[0] = f[0];
450 da[1] = f[1];
451 da[2] = f[2];
452 da[3] = 0.;
453 da[4] = 0.;
454 }
455 else {
456 da = solve(d2chi2d2a, dchi2da);
457 }
458
459#ifdef TRKRECO_DEBUG_DETAIL
460
461
462
463#endif
464
465 a -= factor*da;
466
468 ++nTrial;
469 }
470
471
473 unsigned dim;
474 if (allAxial) {
475 dim = 3;
477 Eb = d2chi2d2a.sub(1, 3);
478 Ec = Eb.inverse(err);
479 Ea[0][0] = Ec[0][0];
480 Ea[0][1] = Ec[0][1];
481 Ea[0][2] = Ec[0][2];
482 Ea[1][1] = Ec[1][1];
483 Ea[1][2] = Ec[1][2];
484 Ea[2][2] = Ec[2][2];
485 }
486 else {
487 dim = 5;
488 Ea = d2chi2d2a.inverse(err);
489 }
490
491
492 if (! err) {
495 }
496 else {
498 }
499
500 t._ndf = nValid - dim;
502
503
504 return err;
505}
CLHEP::HepSymMatrix SymMatrix
#define WireHitFittingValid
#define WireHitInvalidForFit
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
virtual double driftTimeToDist(double drifttime, int layid, int cellid, int lr, double entrance=0.0) const =0
virtual double getSigma(int layid, int lr, double dist, double entrance=0.0, double tanlam=0.0, double z=0.0, double Q=1000.0) const =0
virtual double getT0(int layid, int cellid) const =0
virtual double getTimeWalk(int layid, double Q) const =0
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
unsigned state(void) const
returns state.
float dDrift(unsigned) const
returns drift distance error.
float drift(unsigned) const
returns drift distance.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
const HepVector3D & direction(void) const
returns direction vector of the wire.
bool stereo(void) const
returns true if this wire is in a stereo layer.
A class to relate TMDCWireHit and TTrack objects.
const AList< TMLink > & links(unsigned mask=0) const
returns a list of masked TMLinks assigned to this track. 'mask' will be applied if mask is not 0.
virtual unsigned objectType(void) const
returns object type.
A class to represent a track in tracking.