195 {
196
197
198
199
201 T3DLine&
t = (T3DLine&)tb;
202
203
205
206
207 AList<TMLink> cores =
t.cores();
208 unsigned nCores = cores.length();
210
211
212 bool flag2D = false;
213 if ( ( nStereoCores == 0 ) && ( nCores > 3 ) ) flag2D = true;
214 else if ( ( nStereoCores < 2 ) || ( nCores - nStereoCores < 3 ) )
return TFitErrorFewHits;
215
216
219
220
230 double chi2;
232 double factor = 1.0;
233 int err = 0;
236
237
238 unsigned nTrial = 0;
239 while ( nTrial < 100 )
240 {
241
242
243 chi2 = 0;
244 for ( unsigned j = 0; j < 4; j++ ) dchi2da[j] = 0;
245 d2chi2d2a = zero4;
246
247
248 unsigned i = 0;
249 while ( TMLink* l = cores[i++] )
250 {
251 const TMDCWireHit& h = *l->hit();
252
253
254 t.approach( *l, _sag );
255 const HepPoint3D& onTrack = l->positionOnTrack();
256 const HepPoint3D& onWire = l->positionOnWire();
258 if ( onWire.cross( onTrack ).z() < 0. ) leftRight =
WireHitLeft;
259
260
261 double distance;
262 double eDistance;
263 drift(
t, *l, t0Offset, distance, eDistance );
264 l->drift( distance, 0 );
265 l->drift( distance, 1 );
266 l->dDrift( eDistance, 0 );
267 l->dDrift( eDistance, 1 );
268 double eDistance2 = eDistance * eDistance;
269
270
271
273 double vmag =
v.mag();
274 double dDistance = vmag - distance;
275
277
278 this->dxda( *l,
t, dxda, dyda, dzda, vw );
279
280
281 dDda = ( vmag > 0. ) ? ( (
v.x() * ( 1. - vw.x() * vw.x() ) -
v.y() * vw.x() * vw.y() -
282 v.z() * vw.x() * vw.z() ) *
283 dxda +
284 (
v.y() * ( 1. - vw.y() * vw.y() ) -
v.z() * vw.y() * vw.z() -
285 v.x() * vw.y() * vw.x() ) *
286 dyda +
287 (
v.z() * ( 1. - vw.z() * vw.z() ) -
v.x() * vw.z() * vw.x() -
288 v.y() * vw.z() * vw.y() ) *
289 dzda ) /
290 vmag
292 if ( vmag <= 0.0 )
293 {
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
309 if ( fabs( change ) < 1.0e-5 ) break;
310 if ( change < 0. )
311 {
312 a += factor * da;
313 factor *= 0.1;
314 }
315 else
316 {
317 chi2Old = chi2;
318 if ( flag2D )
319 {
320 f = dchi2da.sub( 1, 2 );
321 e = d2chi2d2a.sub( 1, 2 );
325 da[2] = 0;
326 da[3] = 0;
327 }
328 else
329 {
330
331 da = solve( d2chi2d2a, dchi2da );
332 }
333 }
334 a -= factor * da;
336 ++nTrial;
337 }
338
339
341 unsigned dim;
342 if ( flag2D )
343 {
344 dim = 2;
346 Eb = d2chi2d2a.sub( 1, 3 );
347 Ec = Eb.inverse( err );
348 Ea[0][0] = Ec[0][0];
349 Ea[0][1] = Ec[0][1];
350 Ea[0][2] = Ec[0][2];
351 Ea[1][1] = Ec[1][1];
352 Ea[1][2] = Ec[1][2];
353 Ea[2][2] = Ec[2][2];
354 }
355 else
356 {
357 dim = 4;
358 Ea = d2chi2d2a.inverse( err );
359 }
360
361
362 if ( !err )
363 {
368 }
370
371 t._ndf = nCores - dim;
373
374
375 t.pivot( pivot_bak );
376
377 return err;
378}
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
CLHEP::HepSymMatrix SymMatrix
const HepPoint3D ORIGIN
Constants.
#define TFitAlreadyFitted
unsigned NStereoHits(const AList< TMLink > &links)
returns # of stereo hits.
**********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
HepGeom::Vector3D< double > HepVector3D
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
virtual unsigned objectType(void) const
returns object type.