CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
KalFitTrack.cxx
Go to the documentation of this file.
1
2//#include "TrackUtil/Helix.h"
3#include "KalFitAlg/helix/Helix.h"
4#include "KalFitAlg/KalFitWire.h"
5#include "KalFitAlg/KalFitTrack.h"
6#include "KalFitAlg/KalFitMaterial.h"
7#include "KalFitAlg/KalFitElement.h"
8#include "KalFitAlg/KalFitCylinder.h"
9#include "MdcGeomSvc/MdcGeomSvc.h"
10#include "GaudiKernel/Bootstrap.h"
11#include "CLHEP/Matrix/Vector.h"
12#include "CLHEP/Matrix/Matrix.h"
13#include "CLHEP/Matrix/SymMatrix.h"
14#include "CLHEP/Vector/ThreeVector.h"
15#include "CLHEP/Units/PhysicalConstants.h"
16#include "Math/Point3Dfwd.h"
17#include "Math/Point3D.h"
18#include "Math/Vector3D.h"
19#include "CgemGeomSvc/ICgemGeomSvc.h"
20#include "CgemGeomSvc/CgemGeomSvc.h"
21#include "CgemCalibFunSvc/CgemCalibFunSvc.h"
22
23using namespace ROOT::Math;
24
25using namespace KalmanFit;
26
27using namespace CLHEP;
28
29
30// for debug purpose .
33int KalFitTrack::numf_ = 0;
35double KalFitTrack::Bznom_ = 10;
39// Mdc factors :
42double KalFitTrack::chi2_hitf_ = 1000;
43double KalFitTrack::chi2_hits_ = 1000;
45//double KalFitTrack::chi2_hitf_ = DBL_MAX;
46int KalFitTrack::lead_ = 2;
47int KalFitTrack::back_ = 1;
48// attention resolflag !!!
51// chi2 cut set :
53//int KalFitTrack::LR_ = 0;
54int KalFitTrack::LR_ = 1;
55
56
57double KalFitTrack::dchi2cutf_anal[43] = {0.};
58double KalFitTrack::dchi2cuts_anal[43] = {0.};
59double KalFitTrack::dchi2cutf_calib[43] = {0.};
60double KalFitTrack::dchi2cuts_calib[43] = {0.};
61
62
63///
65
66
67const double KalFitTrack::MASS[NMASS] = { 0.000510999,
68 0.105658,
69 0.139568,
70 0.493677,
71 0.938272 };
72const double
73M_PI2 = 2. * M_PI;
74
75const double
76M_PI4 = 4. * M_PI;
77
78const double
79M_PI8 = 8. * M_PI;
80
81
82
83// constructor
85 const HepVector& a,
86 const HepSymMatrix& Ea,
87 unsigned int m, double chisq, unsigned int nhits)
88: Helix(pivot, a, Ea), type_(0), insist_(0), chiSq_(0),
89 nchits_(0), nster_(0), ncath_(0),
90 ndf_back_(0), chiSq_back_(0), pathip_(0),
91 path_rd_(0), path_ab_(0), tof_(0), dchi2_max_(0), r_max_(0),
92 tof_kaon_(0), tof_proton_(0), pat1_(0), pat2_(0), layer_prec_(0),
93 trasan_id_(0), nhit_r_(0), nhit_z_(0),pathSM_(0),tof2_(0)
94{
95 memset(PathL_, 0, sizeof(PathL_));
96 l_mass_ = m;
97 if (m < NMASS) mass_ = MASS[m];
98 else mass_ = MASS[2];
99 r0_ = fabs(center().perp() - fabs(radius()));
100 //bFieldZ(Bznom_);
101 Bznom_=bFieldZ(); // 2012-09-13 wangll
102 update_last();
103
104 resetLayerUsed();// myLayerUsed
105}
106
107// destructor
109{
110 // delete all objects
111
112}
113
115{
116 pivot_last_ = pivot();
117 a_last_ = a();
118 Ea_last_ = Ea();
119}
120
122{
123 pivot_forMdc_ = pivot();
124 a_forMdc_ = a();
125 Ea_forMdc_ = Ea();
126}
127
129{
130 double m_rad = radius();
131 double l = center().perp();
132
133 double cosPhi = (m_rad * m_rad + l * l - r * r) / (2 * m_rad * l);
134
135 if(cosPhi < -1 || cosPhi > 1) return 0;
136
137 double dPhi = center().phi() - acos(cosPhi) - phi0();
138
139 if(dPhi < -M_PI) dPhi += 2 * M_PI;
140
141 return dPhi;
142}
143
145 double y) const
146{
147 HepPoint3D xc = plane * center();
148 double r = radius();
149 double d = r * r - (y - xc.y()) * (y - xc.y());
150 if(d < 0) return 0;
151
152 double xx = xc.x();
153 if(xx > 0) xx -= sqrt(d);
154 else xx += sqrt(d);
155
156 double l = (plane.inverse() *
157 HepPoint3D(xx, y, 0)).perp();
158
159 return intersect_cylinder(l);
160}
161
163 double x) const
164{
165 HepPoint3D xc = plane * center();
166 double r = radius();
167 double d = r * r - (x - xc.x()) * (x - xc.x());
168 if(d < 0) return 0;
169
170 double yy = xc.y();
171 if(yy > 0) yy -= sqrt(d);
172 else yy += sqrt(d);
173
174 double l = (plane.inverse() *
175 HepPoint3D(x, yy, 0)).perp();
176
177 return intersect_cylinder(l);
178}
179
181{
182 if (tanl() != 0 && radius() != 0)
183 return (pivot().z() + dz() - z) / (radius() * tanl());
184 else return 0;
185}
186
187void KalFitTrack::ms(double path,
188 const KalFitMaterial& material, int index)
189{
190 HepSymMatrix ea = Ea();
191 //cout<<"ms():path "<<path<<endl;
192 //cout<<"ms():ea before: "<<ea<<endl;
193 double k = kappa();
194 double t = tanl();
195 double t2 = t * t;
196 double pt2 = 1 + t2;
197 double k2 = k * k;
198
199 double pmag = 1 / fabs(k) * sqrt(pt2);
200 double dth = material.mcs_angle(mass_, path, pmag);
201 double dth2 = dth * dth;
202 double pt2dth2 = pt2 * dth2;
203
204 ea[1][1] += pt2dth2;
205 ea[2][2] += k2 * t2 * dth2;
206 ea[2][4] += k * t * pt2dth2;
207 ea[4][4] += pt2 * pt2dth2;
208
209 ea[3][3] += dth2 * path * path /3 / (1 + t2);
210 ea[3][4] += dth2 * path/2 * sqrt(1 + t2);
211 ea[3][2] += dth2 * t / sqrt(1 + t2) * k * path/2;
212 ea[0][0] += dth2 * path * path/3;
213 ea[0][1] += dth2 * sqrt(1 + t2) * path/2;
214
215 Ea(ea);
216 //cout<<"ms():ms angle in this: "<<dth<<endl;
217 //cout<<"ms():ea after: "<<Ea()<<endl;
218 if (index < 0) {
219 double x0 = material.X0();
220 if (x0) path_rd_ += path/x0;
221 }
222}
223
224void KalFitTrack::msgasmdc(double path, int index)
225{
226 double k = kappa();
227 double t = tanl();
228 double t2 = t * t;
229 double k2 = k * k;
230
231 double pmag = ( 1 / fabs(k) ) * sqrt(1 + t2);
232 double psq = pmag*pmag;
233 /*
234 double Zprims = 3/2*0.076 + 0.580/9.79*4.99*(4.99+1) +
235 0.041/183.85*74*(74+1) + 0.302/26.98 * 13 * (13+1);
236 double chicc = 0.00039612 * sqrt(Zprims * 0.001168);
237 double dth = 2.557 * chicc * sqrt(path * (mass_*mass_ + psq)) / psq;
238 */
239
240 //std::cout<<" mdcGasRadlen: "<<mdcGasRadlen_<<std::endl;
241 double pathx = path/mdcGasRadlen_;
242 double dth = 0.0136* sqrt(pathx * (mass_*mass_ + psq))/psq
243 *(1 + 0.038 * log(pathx));;
244 HepSymMatrix ea = Ea();
245#ifdef YDEBUG
246 cout<<"msgasmdc():path "<<path<<" pathx "<<pathx<<endl;
247 cout<<"msgasmdc():dth "<<dth<<endl;
248 cout<<"msgasmdc():ea before: "<<ea<<endl;
249#endif
250 double dth2 = dth * dth;
251
252 ea[1][1] += (1 + t2) * dth2;
253 ea[2][2] += k2 * t2 * dth2;
254 ea[2][4] += k * t * (1 + t2) * dth2;
255 ea[4][4] += (1 + t2) * (1 + t2) * dth2;
256
257 // additionnal terms (terms proportional to l and l^2)
258
259 ea[3][3] += dth2 * path * path /3 / (1 + t2);
260 ea[3][4] += dth2 * path/2 * sqrt(1 + t2);
261 ea[3][2] += dth2 * t / sqrt(1 + t2) * k * path/2;
262 ea[0][0] += dth2 * path * path/3;
263 ea[0][1] += dth2 * sqrt(1 + t2) * path/2;
264
265 Ea(ea);
266#ifdef YDEBUG
267 cout<<"msgasmdc():ea after: "<<Ea()<<endl;
268#endif
269 if (index < 0) {
270 pathip_ += path;
271 // RMK : put by hand, take care !!
272 double x0 = mdcGasRadlen_; // for the Mdc gas
273 path_rd_ += path/x0;
274 tof(path);
275#ifdef YDEBUG
276 cout<<"ms...pathip..."<<pathip_<<endl;
277#endif
278 }
279}
280
281void KalFitTrack::eloss(double path,
282 const KalFitMaterial& material, int index)
283{
284#ifdef YDEBUG
285 cout<<"eloss():ea before: "<<Ea()<<endl;
286#endif
287 HepVector v_a = a();
288 double v_a_2_2 = v_a[2] * v_a[2];
289 double v_a_4_2 = v_a[4] * v_a[4];
290 double pmag = 1 / fabs(v_a[2]) * sqrt(1 + v_a_4_2);
291 double psq = pmag * pmag;
292 double E = sqrt(mass_ * mass_ + psq);
293 double dE = material.dE(mass_, path, pmag);
294 //std::cout<<" eloss(): dE: "<<dE<<std::endl;//wangll
295
296 if (index > 0)
297 psq += dE * (dE + 2 * sqrt(mass_ * mass_ + psq));
298 else {
299 double dE_max = E - mass_;
300 if( dE<dE_max ) psq += dE * (dE - 2 * sqrt(mass_ * mass_ + psq));
301 else psq=-1.0;
302 }
303
304 if (tofall_ && index < 0){
305 // Kaon case :
306 if (p_kaon_ > 0){
307 double psq_kaon = p_kaon_ * p_kaon_;
308 double dE_kaon = material.dE(MASS[3], path, p_kaon_);
309 psq_kaon += dE_kaon * (dE_kaon -
310 2 * sqrt(MASS[3] * MASS[3] + psq_kaon));
311 if (psq_kaon < 0) psq_kaon = 0;
312 p_kaon_ = sqrt(psq_kaon);
313 }
314 // Proton case :
315 if (p_proton_ > 0){
316 double psq_proton = p_proton_ * p_proton_;
317 double dE_proton = material.dE(MASS[4], path, p_proton_);
318 psq_proton += dE_proton * (dE_proton -
319 2 * sqrt(MASS[4] * MASS[4] + psq_proton));
320 if (psq_proton < 0) psq_proton = 0;
321 p_proton_ = sqrt(psq_proton);
322 }
323 }
324
325 double dpt;
326 //cout<<"eloss(): psq = "<<psq<<endl;//wangll
327 if(psq < 0) dpt = 9999;
328 else dpt = v_a[2] * pmag / sqrt(psq);
329 //cout<<"eloss():k: "<<v_a[2]<<" k' "<<dpt<<endl;//wangll
330#ifdef YDEBUG
331 cout<<"eloss():k: "<<v_a[2]<<" k' "<<dpt<<endl;
332#endif
333 // attempt to take account of energy loss for error matrix
334
335 HepSymMatrix ea = Ea();
336 double r_E_prim = (E + dE)/E;
337
338 // 1/ Straggling in the energy loss :
339 if (strag_){
340 double del_E(0);
341 if(l_mass_==0) {
342 del_E = dE*factor_strag_;
343 } else {
344 del_E = material.del_E(mass_, path, pmag);
345 }
346
347 ea[2][2] += (v_a[2] * v_a[2]) * E * E * del_E * del_E / (psq*psq);
348 }
349
350 // Effect of the change of curvature (just variables change):
351 double dpt2 = dpt*dpt;
352 double A = dpt*dpt2/(v_a_2_2*v_a[2])*r_E_prim;
353 double B = v_a[4]/(1+v_a_4_2)*
354 dpt*(1-dpt2/v_a_2_2*r_E_prim);
355
356 double ea_2_0 = A*ea[2][0] + B*ea[4][0];
357 double ea_2_1 = A*ea[2][1] + B*ea[4][1];
358 double ea_2_2 = A*A*ea[2][2] + 2*A*B*ea[2][4] + B*B*ea[4][4];
359 double ea_2_3 = A*ea[2][3] + B*ea[4][3];
360 double ea_2_4 = A*ea[2][4] + B*ea[4][4];
361
362 v_a[2] = dpt;
363 a(v_a);
364
365 ea[2][0] = ea_2_0;
366 //std::cout<<"ea[2][0] is "<<ea[2][0]<<" ea(3,1) is "<<ea(3,1)<<std::endl;
367 ea[2][1] = ea_2_1;
368 //std::cout<<"ea[2][2] is "<<ea[2][2]<<" ea(3,3) is "<<ea(3,3)<<std::endl;
369 ea[2][2] = ea_2_2;
370 ea[2][3] = ea_2_3;
371 ea[2][4] = ea_2_4;
372
373 Ea(ea);
374 //cout<<"eloss():dE: "<<dE<<endl;
375 //cout<<"eloss():A: "<<A<<" B: "<<B<<endl;
376 //cout<<"eloss():ea after: "<<Ea()<<endl;
377 r0_ = fabs(center().perp() - fabs(radius()));
378}
379
381{
382 unsigned int nhit = HitsMdc_.size();
383 Helix tracktest = *(Helix*)this;
384 int ind = 0;
385 double* Rad = new double[nhit];
386 double* Ypos = new double[nhit];
387 for( unsigned i=0 ; i < nhit; i++ ){
388
389 HepPoint3D fwd(HitsMdc_[i].wire().fwd());
390 HepPoint3D bck(HitsMdc_[i].wire().bck());
391 Hep3Vector wire = (CLHEP::Hep3Vector)fwd -(CLHEP::Hep3Vector)bck;
392
393 // Modification for stereo wires :
394 Helix work = tracktest;
395 work.ignoreErrorMatrix();
396 work.pivot((fwd + bck) * .5);
397 HepPoint3D x0 = (work.x(0).z() - bck.z())
398 / wire.z() * wire + bck;
399
400 tracktest.pivot(x0);
401 Rad[ind] = tracktest.x(0).perp();
402 Ypos[ind] = x0.y();
403 ind++;
404 //cout<<"Ypos: "<<Ypos[ind-1]<<endl;
405 }
406
407 // Reorder...
408 if (index < 0)
409 for(int j, k = nhit - 1; k >= 0; k = j){
410 j = -1;
411 for(int i = 1; i <= k; i++)
412 if(Rad[i - 1] > Rad[i]){
413 j = i - 1;
414 std::swap(Rad[i], Rad[j]);
415 std::swap(HitsMdc_[i], HitsMdc_[j]);
416 }
417 }
418 if (index > 0)
419 for(int j, k = nhit - 1; k >= 0; k = j){
420 j = -1;
421 for(int i = 1; i <= k; i++)
422 if(Rad[i - 1] < Rad[i]){
423 j = i - 1;
424 std::swap(Rad[i], Rad[j]);
425 std::swap(HitsMdc_[i], HitsMdc_[j]);
426 }
427 }
428 if (index == 0)
429 for(int j, k = nhit - 1; k >= 0; k = j){
430 j = -1;
431 for(int i = 1; i <= k; i++)
432 if(Ypos[i - 1] > Ypos[i]){
433 j = i - 1;
434 std::swap(Ypos[i], Ypos[j]);
435 std::swap(HitsMdc_[i], HitsMdc_[j]);
436 }
437 }
438 delete [] Rad;
439 delete [] Ypos;
440}
441
443 for(int it=0; it<HitsMdc().size()-1; it++){
444 if(HitsMdc_[it].wire().layer().layerId() == HitsMdc_[it+1].wire().layer().layerId())
445 {
446 if((kappa()<0)&&(HitsMdc_[it].wire().localId() > HitsMdc_[it+1].wire().localId())){
447 std::swap(HitsMdc_[it], HitsMdc_[it+1]);
448 }
449 if((kappa()>0)&&(HitsMdc_[it].wire().localId() < HitsMdc_[it+1].wire().localId())){
450 std::swap(HitsMdc_[it], HitsMdc_[it+1]);
451 }
452 }
453 }
454}
455
456
458{
459 unsigned int nhit = HitsMdc_.size();
460 int Num[50] = {0};
461 for( unsigned i=0 ; i < nhit; i++ )
462 Num[HitsMdc_[i].wire().layer().layerId()]++;
463 for( unsigned i=0 ; i < nhit; i++ )
464 if (Num[HitsMdc_[i].wire().layer().layerId()]>2)
465 HitsMdc_[i].chi2(-2);
466}
467
468
469double KalFitTrack::smoother_Mdc(KalFitHitMdc& HitMdc, Hep3Vector& meas, KalFitHelixSeg& seg, double& dchi2, int csmflag)
470{
471 //
472 double lr = HitMdc.LR();
473 // For taking the propagation delay into account :
474 int wire_ID = HitMdc.wire().geoID(); // from 0 to 6796
475 int layerid = HitMdc.wire().layer().layerId();
476 double entrangle = HitMdc.rechitptr()->getEntra();
477 if (wire_ID<0 || wire_ID>6796){ //bes
478 std::cout << "KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
479 return 0;
480 }
481
482 double x[3] ={pivot().x(), pivot().y(), pivot().z()};
483 double pmom[3] ={momentum().x(), momentum().y(), momentum().z()};
484
485 double tofest(0);
486 double dd(0.);
487 double phi = fmod(phi0() + M_PI4, M_PI2);
488 double csf0 = cos(phi);
489 double snf0 = (1. - csf0) * (1. + csf0);
490 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
491 if(phi > M_PI) snf0 = - snf0;
492
493 if (Tof_correc_) {
494 Hep3Vector ip(0, 0, 0);
495 Helix work = *(Helix*)this;
496 work.ignoreErrorMatrix();
497 work.pivot(ip);
498 double phi_ip = work.phi0();
499 if (fabs(phi - phi_ip) > M_PI) {
500 if (phi > phi_ip) phi -= 2 * M_PI;
501 else phi_ip -= 2 * M_PI;
502 }
503 double t = tanl();
504 double l = fabs(radius() * (phi - phi_ip) * sqrt(1 + t * t));
505 double pmag( sqrt( 1.0 + t*t ) / kappa());
506 double mass_over_p( mass_ / pmag );
507 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
508 tofest = l / ( 29.9792458 * beta );
509 if(csmflag==1 && HitMdc.wire().y()>0.) tofest= -1. * tofest;
510 }
511
512 const HepSymMatrix& ea = Ea();
513 const HepVector& v_a = a();
514
515 HepPoint3D pivot_work = pivot();
516
517 double dchi2R(99999999), dchi2L(99999999);
518
519 HepVector v_H(5, 0);
520 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
521 v_H[3] = -meas.z();
522 HepMatrix v_HT = v_H.T();
523
524 double estim = (v_HT * v_a)[0];
525 HepVector ea_v_H = ea * v_H;
526 HepMatrix ea_v_HT = (ea_v_H).T();
527 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
528
529 HepSymMatrix eaNew(5);
530 HepVector aNew(5);
531
532 //double time = HitMdc.tdc();
533 // if (Tof_correc_)
534 // time -= tofest;
535
536 double drifttime = getDriftTime(HitMdc , tofest);
537 //cout<<"drifttime = "<<drifttime<<endl;
538 seg.dt(drifttime);
539 double ddl = getDriftDist(HitMdc, drifttime, 0);
540 double ddr = getDriftDist(HitMdc, drifttime, 1);
541 /*cout<<endl<<" $$$ smoother_Mdc():: "<<endl;//wangll
542 cout<<"pivot = "<<pivot()<<endl;//wangll
543 cout<<"helix = "<<a()<<endl;//wangll
544 cout<<"drifttime = "<<drifttime<<endl;//wangll
545 cout<<"ddl, ddr = "<<ddl<<", "<<ddr<<endl;//wangll
546 */
547 double erddl = getSigma( HitMdc, a()[4], 0, ddl);
548 double erddr = getSigma( HitMdc, a()[4], 1, ddr);
549
550 // double dd = 1.0e-4 * 40.0 * time;
551 double dmeas2[2] = { 0.1*ddl, 0.1*ddr }; //millimeter to centimeter
552 double er_dmeas2[2] = {0. , 0.};
553 if(resolflag_== 1) {
554 er_dmeas2[0] = 0.1*erddl;
555 er_dmeas2[1] = 0.1*erddr;
556 }
557 else if(resolflag_ == 0) {
558 //int layid = HitMdc.wire().layer().layerId();
559 //double sigma = getSigma(layid, dd);
560 //er_dmeas2[0] = er_dmeas2[1] = sigma;
561 }
562
563 // Left hypothesis :
564 if (lr == -1) {
565 double er_dmeasL, dmeasL;
566 if(Tof_correc_) {
567 dmeasL = (-1.0)*dmeas2[0]; // the dmeas&erdmeas calculated by myself
568 er_dmeasL = er_dmeas2[0];
569 } else {
570 dmeasL = (-1.0)*fabs(HitMdc.dist()[0]); // the dmeas&erdmeas calculated by track-finding algorithm
571 er_dmeasL = HitMdc.erdist()[0];
572 }
573
574 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
575 eaNew.assign(ea - ea_v_H * AL * ea_v_HT);
576 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
577 if(0. == RkL) RkL = 1.e-4;
578
579 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
580 aNew = v_a + diffL;
581 double sigL = (dmeasL - (v_HT * aNew)[0]);
582 dchi2L = (sigL*sigL) / (RkL * er_dmeasL*er_dmeasL);
583 } else if (lr == 1) {
584 // Right hypothesis :
585
586 double er_dmeasR, dmeasR;
587 if(Tof_correc_) {
588 dmeasR = dmeas2[1];
589 er_dmeasR = er_dmeas2[1];
590 } else {
591 dmeasR = fabs(HitMdc.dist()[1]);
592 er_dmeasR = HitMdc.erdist()[1];
593 }
594
595
596 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
597 eaNew.assign(ea - ea_v_H * AR * ea_v_HT);
598 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
599 if(0. == RkR) RkR = 1.e-4;
600
601 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
602 aNew = v_a + diffR;
603 double sigR = (dmeasR- (v_HT * aNew)[0]);
604 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
605 }
606
607 // Update Kalman result :
608#ifdef YDEBUG
609 cout<<"in smoother_Mdc: lr= "<<lr<<" a: "<<v_a<<" a_NEW: "<<aNew<<endl;
610#endif
611 double dchi2_loc(0);
612 if ((dchi2R < dchi2cuts_anal[layerid] && lr == 1) ||
613 (dchi2L < dchi2cuts_anal[layerid] && lr == -1)) {
614 ndf_back_++;
615 int chge(1);
616 if ( !( aNew[2] && fabs(aNew[2]-a()[2]) < 1.0 ) ) chge=0;
617 if (lr == 1) {
618 chiSq_back_ += dchi2R;
619 dchi2_loc = dchi2R;
620 dd = 0.1*ddr;
621 } else if (lr == -1) {
622 chiSq_back_ += dchi2L;
623 dchi2_loc = dchi2L;
624 dd = -0.1*ddl;
625 }
626 if (chge){
627 a(aNew);
628 Ea(eaNew);
629 }
630 }
631 dchi2=dchi2_loc;
632
633 seg.doca_include(fabs((v_HT*a())[0]));
634 seg.doca_exclude(fabs(estim));
635 /// move the pivot of the helixseg to IP(0,0,0)
636 Hep3Vector ip(0, 0, 0);
637 KalFitTrack helixNew1(pivot_work, a(), Ea(), 0, 0, 0);
638 helixNew1.pivot(ip);
639 HepVector a_temp1 = helixNew1.a();
640 HepSymMatrix ea_temp1 = helixNew1.Ea();
641 seg.Ea(ea_temp1);
642 seg.a(a_temp1);
643 seg.Ea_include(ea_temp1);
644 seg.a_include(a_temp1);
645
646 KalFitTrack helixNew2(pivot_work, v_a, ea, 0, 0, 0);
647 helixNew2.pivot(ip);
648 HepVector a_temp2 = helixNew2.a();
649 HepSymMatrix ea_temp2 = helixNew2.Ea();
650 seg.Ea_exclude(ea_temp2);
651 seg.a_exclude(a_temp2);
652
653 seg.tof(tofest);
654 seg.dd(dd);
655
656 return chiSq_back_;
657}
658
659// Smoothing procedure in Mdc cosmic align
660// RMK attention for the case chi2R = chi2L during forward filter !
661double KalFitTrack::smoother_Mdc_csmalign(KalFitHelixSeg& seg, Hep3Vector& meas,int& flg, int csmflag )
662{
663
664
665 HepPoint3D ip(0., 0., 0.);
666 // attention! we should not to decide the left&right in the smoother process,
667 // because we choose the left&right of hits from the filter process.
668
669 KalFitHitMdc* HitMdc = seg.HitMdc();
670 double lr = HitMdc->LR();
671
672 // For taking the propagation delay into account :
673 int layerid = (*HitMdc).wire().layer().layerId();
674 int wire_ID = HitMdc->wire().geoID();
675 double entrangle = HitMdc->rechitptr()->getEntra();
676
677 if (wire_ID<0 || wire_ID>6796){ //bes
678 std::cout << "KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
679 return 0;
680 }
681
682 double x[3] ={pivot().x(), pivot().y(), pivot().z()};
683 double pmom[3] ={momentum().x(), momentum().y(), momentum().z()};
684 double dd(0.);
685 double tofest(0);
686 double phi = fmod(phi0() + M_PI4, M_PI2);
687 double csf0 = cos(phi);
688 double snf0 = (1. - csf0) * (1. + csf0);
689 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
690 if(phi > M_PI) snf0 = - snf0;
691
692 if (Tof_correc_) {
693 Hep3Vector ip(0, 0, 0);
694 Helix work = *(Helix*)this;
695 work.ignoreErrorMatrix();
696 work.pivot(ip);
697 double phi_ip = work.phi0();
698 if (fabs(phi - phi_ip) > M_PI) {
699 if (phi > phi_ip) phi -= 2 * M_PI;
700 else phi_ip -= 2 * M_PI;
701 }
702 double t = tanl();
703 double l = fabs(radius() * (phi - phi_ip) * sqrt(1 + t * t));
704 double pmag( sqrt( 1.0 + t*t ) / kappa());
705 double mass_over_p( mass_ / pmag );
706 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
707 tofest = l / ( 29.9792458 * beta );
708 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
709 }
710
711 const HepSymMatrix& ea = Ea();
712 const HepVector& v_a = a();
713
714
715 HepPoint3D pivot_work = pivot();
716
717 /*
718 HepVector a_work = a();
719 HepSymMatrix ea_work = Ea();
720
721 KalFitTrack helix_work(pivot_work, a_work, ea_work, 0, 0, 0);
722 helix_work.pivot(ip);
723
724 HepVector a_temp = helix_work.a();
725 HepSymMatrix ea_temp = helix_work.Ea();
726
727 seg.Ea_pre_bwd(ea_temp);
728 seg.a_pre_bwd(a_temp);
729
730 */
731
732 seg.a_pre_bwd(a());
733 seg.Ea_pre_bwd(Ea());
734
735 double dchi2R(99999999), dchi2L(99999999);
736 HepVector v_H(5, 0);
737 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
738 v_H[3] = -meas.z();
739 HepMatrix v_HT = v_H.T();
740
741 double estim = (v_HT * v_a)[0];
742 HepVector ea_v_H = ea * v_H;
743 HepMatrix ea_v_HT = (ea_v_H).T();
744 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
745 HepSymMatrix eaNew(5);
746 HepVector aNew(5);
747 double time = (*HitMdc).tdc();
748
749 //seg.dt(time);
750 // if (Tof_correc_)
751 // {
752 // time -= tofest;
753 // seg.dt(time);
754 // }
755 // double dd = 1.0e-4 * 40.0 * time;
756 // seg.dd(dd);
757
758 double drifttime = getDriftTime(*HitMdc , tofest);
759 seg.dt(drifttime);
760 double ddl = getDriftDist(*HitMdc, drifttime, 0 );
761 double ddr = getDriftDist(*HitMdc, drifttime, 1 );
762 double erddl = getSigma( *HitMdc, a()[4], 0, ddl);
763 double erddr = getSigma( *HitMdc, a()[4], 1, ddr);
764
765 double dmeas2[2] = { 0.1*ddl, 0.1*ddr }; // millimeter to centimeter
766 double er_dmeas2[2] = {0., 0.};
767 if(resolflag_ == 1) {
768 er_dmeas2[0] = 0.1*erddl;
769 er_dmeas2[1] = 0.1*erddr;
770 }else if(resolflag_ == 0)
771 {
772 }
773
774 // Left hypothesis :
775 if (lr == -1) {
776 double er_dmeasL, dmeasL;
777 if(Tof_correc_) {
778 dmeasL = (-1.0)*dmeas2[0];
779 er_dmeasL = er_dmeas2[0];
780 } else {
781 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
782 er_dmeasL = (*HitMdc).erdist()[0];
783 }
784
785
786 //if(layerid < 4) er_dmeasL*=2.0;
787
788 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
789 eaNew.assign(ea - ea_v_H * AL * ea_v_HT);
790 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
791 if(0. == RkL) RkL = 1.e-4;
792
793 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
794 aNew = v_a + diffL;
795 double sigL = (dmeasL - (v_HT * aNew)[0]);
796 dchi2L = (sigL*sigL) / (RkL * er_dmeasL*er_dmeasL);
797 } else if (lr == 1) {
798 // Right hypothesis :
799
800 double er_dmeasR, dmeasR;
801 if(Tof_correc_) {
802 dmeasR = dmeas2[1];
803 er_dmeasR = er_dmeas2[1];
804 } else {
805 dmeasR = fabs((*HitMdc).dist()[1]);
806 er_dmeasR = (*HitMdc).erdist()[1];
807 }
808
809
810 //if(layerid < 4) er_dmeasR*=2.0;
811
812
813 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
814 eaNew.assign(ea - ea_v_H * AR * ea_v_HT);
815 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
816 if(0. == RkR) RkR = 1.e-4;
817
818 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
819 aNew = v_a + diffR;
820 double sigR = (dmeasR- (v_HT * aNew)[0]);
821 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
822 }
823
824 // Update Kalman result :
825#ifdef YDEBUG
826 cout<<"in smoother_Mdc: lr= "<<lr<<" a: "<<v_a<<" a_NEW: "<<aNew<<endl;
827#endif
828 double dchi2_loc(0);
829 if ((dchi2R < dchi2cuts_calib[layerid] && lr == 1) ||
830 (dchi2L < dchi2cuts_calib[layerid] && lr == -1)) {
831
832 ndf_back_++;
833 flg = 1;
834 int chge(1);
835 if (!(aNew[2] && fabs(aNew[2]-a()[2]) < 1.0)) chge = 0;
836 if (lr == 1) {
837 chiSq_back_ += dchi2R;
838 dchi2_loc = dchi2R;
839 dd = 0.1*ddr;
840 // if(debug_ ==4) std::cout<<"in smoother "<<std::endl;
841
842 } else if (lr == -1) {
843 chiSq_back_ += dchi2L;
844 dchi2_loc = dchi2L;
845 dd = -0.1*ddl;
846
847 }
848 if (chge){
849 a(aNew);
850 Ea(eaNew);
851 }
852
853 seg.a_filt_bwd(aNew);
854 seg.Ea_filt_bwd(eaNew);
855
856 HepVector a_pre_fwd_temp=seg.a_pre_fwd();
857 if( (a_pre_fwd_temp[1]-seg.a_pre_bwd()[1]) > 3. * M_PI /2.) a_pre_fwd_temp[1]-= M_PI2;
858 if( (a_pre_fwd_temp[1]-seg.a_pre_bwd()[1]) < -3. * M_PI /2. ) a_pre_fwd_temp[1]+= M_PI2;
859
860 seg.a_pre_fwd(a_pre_fwd_temp);
861
862 HepVector a_pre_filt_temp=seg.a_filt_fwd();
863 if( (a_pre_filt_temp[1]-seg.a_pre_bwd()[1]) > 3. * M_PI /2. ) a_pre_filt_temp[1] -= M_PI2;
864 if( (a_pre_filt_temp[1]-seg.a_pre_bwd()[1]) < -3. * M_PI /2.) a_pre_filt_temp[1] += M_PI2;
865 seg.a_filt_fwd(a_pre_filt_temp);
866
867 /*
868 KalFitTrack helixNew(pivot_work, aNew, eaNew, 0, 0, 0);
869 helixNew.pivot(ip);
870 a_temp = helixNew.a();
871 ea_temp = helixNew.Ea();
872 seg.Ea_filt_bwd(ea_temp);
873 seg.a_filt_bwd(a_temp);
874 */
875
876 int inv;
877
878 if(debug_ == 4){
879 std::cout<<"seg.Ea_pre_bwd().inverse(inv) ..."<<seg.Ea_pre_bwd().inverse(inv)<<std::endl;
880 std::cout<<"seg.Ea_pre_fwd().inverse(inv) ..."<<seg.Ea_pre_fwd().inverse(inv)<<std::endl;
881 }
882
883 HepSymMatrix Ea_pre_comb = (seg.Ea_pre_bwd().inverse(inv)+seg.Ea_pre_fwd().inverse(inv)).inverse(inv);
884 seg.Ea_exclude(Ea_pre_comb);
885
886
887 if(debug_ == 4) {
888 std::cout<<"Ea_pre_comb_ ... "<<Ea_pre_comb<<std::endl;
889 std::cout<<"seg.a_pre_bwd()..."<<seg.a_pre_bwd()<<std::endl;
890 std::cout<<"seg.a_pre_fwd()..."<<seg.a_pre_fwd()<<std::endl;
891 }
892 HepVector a_pre_comb = Ea_pre_comb*((seg.Ea_pre_bwd().inverse(inv))*seg.a_pre_bwd()+(seg.Ea_pre_fwd().inverse(inv))*seg.a_pre_fwd());
893 seg.a_exclude(a_pre_comb);
894
895 if(debug_ == 4) {
896 std::cout<<"seg.Ea_filt_fwd()..."<<seg.Ea_filt_fwd()<<std::endl;
897 std::cout<<"seg.Ea_filt_fwd().inverse(inv)..."<<seg.Ea_filt_fwd().inverse(inv)<<std::endl;
898 }
899 seg.Ea((seg.Ea_filt_fwd().inverse(inv)+seg.Ea_pre_bwd().inverse(inv)).inverse(inv));
900 seg.Ea_include((seg.Ea_filt_fwd().inverse(inv)+seg.Ea_pre_bwd().inverse(inv)).inverse(inv));
901
902 if(debug_ == 4) {
903 std::cout<<"seg.Ea() is ..."<<seg.Ea()<<std::endl;
904 std::cout<<"seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd() ..."<<seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd()<<std::endl;
905 std::cout<<"seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd() ... "<<seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd()<<std::endl;
906 }
907
908 seg.a(seg.Ea()*(seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd()+seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd()));
909 seg.a_include(seg.Ea()*(seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd()+seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd()));
910
911 if(inv != 0) {
912 //std::cout<<"ERROR OCCUR WHEN INVERSE MATRIX !"<<std::endl;
913 }
914
915 seg.residual_exclude(dd - (v_HT*a_pre_comb)[0]);
916 seg.residual_include(dd - (v_HT*seg.a())[0]);
917 seg.doca_exclude(fabs((v_HT*a_pre_comb)[0]));
918 seg.doca_include(fabs((v_HT*seg.a())[0]));
919
920 if(debug_ == 4){
921 std::cout<<"the dd in smoother_Mdc is "<<dd
922 <<" the (v_HT*a_pre_comb)[0] is "<<(v_HT*a_pre_comb)[0]<<std::endl;
923 }
924
925 //compare the two method to calculate the include doca value :
926 if(debug_ == 4){
927 std::cout<<"method 1 ..."<<sqrt(seg.a()[0]*seg.a()[0]+seg.a()[3]*seg.a()[3])<<std::endl;
928 std::cout<<"method 2 ..."<<fabs((v_HT*seg.a())[0])<<std::endl;
929 }
930
931
932 /// move the pivot of the helixseg to IP(0,0,0)
933 KalFitTrack helixNew1(pivot_work, seg.a(), seg.Ea(), 0, 0, 0);
934 helixNew1.pivot(ip);
935 HepVector a_temp1 = helixNew1.a();
936 HepSymMatrix ea_temp1 = helixNew1.Ea();
937 seg.Ea(ea_temp1);
938 seg.a(a_temp1);
939 seg.Ea_include(ea_temp1);
940 seg.a_include(a_temp1);
941
942 KalFitTrack helixNew2(pivot_work, seg.a_exclude(), seg.Ea_exclude(), 0, 0, 0);
943 helixNew2.pivot(ip);
944 HepVector a_temp2 = helixNew2.a();
945 HepSymMatrix ea_temp2 = helixNew2.Ea();
946 seg.Ea_exclude(ea_temp2);
947 seg.a_exclude(a_temp2);
948
949 seg.tof(tofest);
950 seg.dd(dd);
951
952 }
953 return chiSq_back_;
954}
955
956// Smoothing procedure in Mdc calib
957// RMK attention for the case chi2R = chi2L during forward filter !
958double KalFitTrack::smoother_Mdc(KalFitHelixSeg& seg, Hep3Vector& meas,int& flg, int csmflag )
959{
960
961
962 HepPoint3D ip(0., 0., 0.);
963 // attention! we should not to decide the left&right in the smoother process,
964 // because we choose the left&right of hits from the filter process.
965
966 KalFitHitMdc* HitMdc = seg.HitMdc();
967 double lr = HitMdc->LR();
968
969 // For taking the propagation delay into account :
970 int layerid = (*HitMdc).wire().layer().layerId();
971 int wire_ID = HitMdc->wire().geoID();
972 double entrangle = HitMdc->rechitptr()->getEntra();
973
974 if (wire_ID<0 || wire_ID>6796){ //bes
975 std::cout << "KalFitTrack : wire_ID problem : " << wire_ID << std::endl;
976 return 0;
977 }
978
979 double x[3] ={pivot().x(), pivot().y(), pivot().z()};
980 double pmom[3] ={momentum().x(), momentum().y(), momentum().z()};
981 double dd(0.);
982 double tofest(0);
983 double phi = fmod(phi0() + M_PI4, M_PI2);
984 double csf0 = cos(phi);
985 double snf0 = (1. - csf0) * (1. + csf0);
986 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
987 if(phi > M_PI) snf0 = - snf0;
988
989 if (Tof_correc_) {
990 Hep3Vector ip(0, 0, 0);
991 Helix work = *(Helix*)this;
992 work.ignoreErrorMatrix();
993 work.pivot(ip);
994 double phi_ip = work.phi0();
995 if (fabs(phi - phi_ip) > M_PI) {
996 if (phi > phi_ip) phi -= 2 * M_PI;
997 else phi_ip -= 2 * M_PI;
998 }
999 double t = tanl();
1000 double l = fabs(radius() * (phi - phi_ip) * sqrt(1 + t * t));
1001 double pmag( sqrt( 1.0 + t*t ) / kappa());
1002 double mass_over_p( mass_ / pmag );
1003 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1004 tofest = l / ( 29.9792458 * beta );
1005 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
1006 }
1007
1008 const HepSymMatrix& ea = Ea();
1009 const HepVector& v_a = a();
1010
1011
1012
1013 HepPoint3D pivot_work = pivot();
1014
1015 /*
1016 HepVector a_work = a();
1017 HepSymMatrix ea_work = Ea();
1018
1019 KalFitTrack helix_work(pivot_work, a_work, ea_work, 0, 0, 0);
1020 helix_work.pivot(ip);
1021
1022 HepVector a_temp = helix_work.a();
1023 HepSymMatrix ea_temp = helix_work.Ea();
1024
1025 seg.Ea_pre_bwd(ea_temp);
1026 seg.a_pre_bwd(a_temp);
1027
1028 */
1029
1030 seg.a_pre_bwd(a());
1031 seg.Ea_pre_bwd(Ea());
1032
1033 double dchi2R(99999999), dchi2L(99999999);
1034 HepVector v_H(5, 0);
1035 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
1036 v_H[3] = -meas.z();
1037 HepMatrix v_HT = v_H.T();
1038
1039 double estim = (v_HT * v_a)[0];
1040 HepVector ea_v_H = ea * v_H;
1041 HepMatrix ea_v_HT = (ea_v_H).T();
1042 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
1043 HepSymMatrix eaNew(5);
1044 HepVector aNew(5);
1045 double time = (*HitMdc).tdc();
1046
1047 //seg.dt(time);
1048 // if (Tof_correc_)
1049 // {
1050 // time -= tofest;
1051 // seg.dt(time);
1052 // }
1053 // double dd = 1.0e-4 * 40.0 * time;
1054 // seg.dd(dd);
1055
1056 double drifttime = getDriftTime(*HitMdc , tofest);
1057 seg.dt(drifttime);
1058 double ddl = getDriftDist(*HitMdc, drifttime, 0 );
1059 double ddr = getDriftDist(*HitMdc, drifttime, 1 );
1060 double erddl = getSigma( *HitMdc, a()[4], 0, ddl);
1061 double erddr = getSigma( *HitMdc, a()[4], 1, ddr);
1062
1063 double dmeas2[2] = { 0.1*ddl, 0.1*ddr }; // millimeter to centimeter
1064 double er_dmeas2[2] = {0., 0.};
1065 if(resolflag_ == 1) {
1066 er_dmeas2[0] = 0.1*erddl;
1067 er_dmeas2[1] = 0.1*erddr;
1068 }else if(resolflag_ == 0)
1069 {
1070 }
1071
1072 // Left hypothesis :
1073 if (lr == -1) {
1074 double er_dmeasL, dmeasL;
1075 if(Tof_correc_) {
1076 dmeasL = (-1.0)*dmeas2[0];
1077 er_dmeasL = er_dmeas2[0];
1078 } else {
1079 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
1080 er_dmeasL = (*HitMdc).erdist()[0];
1081 }
1082
1083
1084 //if(layerid < 4) er_dmeasL*=2.0;
1085
1086 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
1087 eaNew.assign(ea - ea_v_H * AL * ea_v_HT);
1088 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
1089 if(0. == RkL) RkL = 1.e-4;
1090
1091 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
1092 aNew = v_a + diffL;
1093 double sigL = (dmeasL - (v_HT * aNew)[0]);
1094 dchi2L = (sigL*sigL) / (RkL * er_dmeasL*er_dmeasL);
1095 } else if (lr == 1) {
1096 // Right hypothesis :
1097
1098 double er_dmeasR, dmeasR;
1099 if(Tof_correc_) {
1100 dmeasR = dmeas2[1];
1101 er_dmeasR = er_dmeas2[1];
1102 } else {
1103 dmeasR = fabs((*HitMdc).dist()[1]);
1104 er_dmeasR = (*HitMdc).erdist()[1];
1105 }
1106
1107
1108 //if(layerid < 4) er_dmeasR*=2.0;
1109
1110
1111 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
1112 eaNew.assign(ea - ea_v_H * AR * ea_v_HT);
1113 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
1114 if(0. == RkR) RkR = 1.e-4;
1115
1116 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
1117 aNew = v_a + diffR;
1118 double sigR = (dmeasR- (v_HT * aNew)[0]);
1119 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
1120 }
1121
1122 // Update Kalman result :
1123#ifdef YDEBUG
1124 cout<<"in smoother_Mdc: lr= "<<lr<<" a: "<<v_a<<" a_NEW: "<<aNew<<endl;
1125#endif
1126 double dchi2_loc(0);
1127 if ((dchi2R < dchi2cuts_calib[layerid] && lr == 1) ||
1128 (dchi2L < dchi2cuts_calib[layerid] && lr == -1)) {
1129
1130 ndf_back_++;
1131 flg = 1;
1132 int chge(1);
1133 if (!(aNew[2] && fabs(aNew[2]-a()[2]) < 1.0)) chge = 0;
1134 if (lr == 1) {
1135 chiSq_back_ += dchi2R;
1136 dchi2_loc = dchi2R;
1137 dd = 0.1*ddr;
1138 // if(debug_ ==4) std::cout<<"in smoother "<<std::endl;
1139
1140 } else if (lr == -1) {
1141 chiSq_back_ += dchi2L;
1142 dchi2_loc = dchi2L;
1143 dd = -0.1*ddl;
1144
1145 }
1146 if (chge){
1147 a(aNew);
1148 Ea(eaNew);
1149 }
1150
1151 seg.a_filt_bwd(aNew);
1152 seg.Ea_filt_bwd(eaNew);
1153
1154 HepVector a_pre_fwd_temp=seg.a_pre_fwd();
1155 if( (a_pre_fwd_temp[1]-seg.a_pre_bwd()[1]) > 3. * M_PI /2.) a_pre_fwd_temp[1]-= M_PI2;
1156 if( (a_pre_fwd_temp[1]-seg.a_pre_bwd()[1]) < -3. * M_PI /2. ) a_pre_fwd_temp[1]+= M_PI2;
1157
1158 seg.a_pre_fwd(a_pre_fwd_temp);
1159
1160 HepVector a_pre_filt_temp=seg.a_filt_fwd();
1161 if( (a_pre_filt_temp[1]-seg.a_pre_bwd()[1]) > 3. * M_PI /2. ) a_pre_filt_temp[1] -= M_PI2;
1162 if( (a_pre_filt_temp[1]-seg.a_pre_bwd()[1]) < -3. * M_PI /2.) a_pre_filt_temp[1] += M_PI2;
1163 seg.a_filt_fwd(a_pre_filt_temp);
1164
1165 /*
1166 KalFitTrack helixNew(pivot_work, aNew, eaNew, 0, 0, 0);
1167 helixNew.pivot(ip);
1168 a_temp = helixNew.a();
1169 ea_temp = helixNew.Ea();
1170 seg.Ea_filt_bwd(ea_temp);
1171 seg.a_filt_bwd(a_temp);
1172 */
1173
1174 int inv;
1175
1176 if(debug_ == 4){
1177 std::cout<<"seg.Ea_pre_bwd().inverse(inv) ..."<<seg.Ea_pre_bwd().inverse(inv)<<std::endl;
1178 std::cout<<"seg.Ea_pre_fwd().inverse(inv) ..."<<seg.Ea_pre_fwd().inverse(inv)<<std::endl;
1179 }
1180
1181 HepSymMatrix Ea_pre_comb = (seg.Ea_pre_bwd().inverse(inv)+seg.Ea_pre_fwd().inverse(inv)).inverse(inv);
1182 seg.Ea_exclude(Ea_pre_comb);
1183
1184
1185 if(debug_ == 4) {
1186 std::cout<<"Ea_pre_comb_ ... "<<Ea_pre_comb<<std::endl;
1187 std::cout<<"seg.a_pre_bwd()..."<<seg.a_pre_bwd()<<std::endl;
1188 std::cout<<"seg.a_pre_fwd()..."<<seg.a_pre_fwd()<<std::endl;
1189 }
1190 HepVector a_pre_comb = Ea_pre_comb*((seg.Ea_pre_bwd().inverse(inv))*seg.a_pre_bwd()+(seg.Ea_pre_fwd().inverse(inv))*seg.a_pre_fwd());
1191 seg.a_exclude(a_pre_comb);
1192
1193
1194 if(debug_ == 4) {
1195 std::cout<<"seg.Ea_filt_fwd()..."<<seg.Ea_filt_fwd()<<std::endl;
1196 std::cout<<"seg.Ea_filt_fwd().inverse(inv)..."<<seg.Ea_filt_fwd().inverse(inv)<<std::endl;
1197 }
1198 seg.Ea((seg.Ea_filt_fwd().inverse(inv)+seg.Ea_pre_bwd().inverse(inv)).inverse(inv));
1199 seg.Ea_include((seg.Ea_filt_fwd().inverse(inv)+seg.Ea_pre_bwd().inverse(inv)).inverse(inv));
1200
1201 if(debug_ == 4) {
1202 std::cout<<"seg.Ea() is ..."<<seg.Ea()<<std::endl;
1203 std::cout<<"seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd() ..."<<seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd()<<std::endl;
1204 std::cout<<"seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd() ... "<<seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd()<<std::endl;
1205 }
1206
1207 seg.a(seg.Ea()*(seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd()+seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd()));
1208 seg.a_include(seg.Ea()*(seg.Ea_filt_fwd().inverse(inv)*seg.a_filt_fwd()+seg.Ea_pre_bwd().inverse(inv)*seg.a_pre_bwd()));
1209
1210 if(inv != 0) {
1211 //std::cout<<"ERROR OCCUR WHEN INVERSE MATRIX !"<<std::endl;
1212 }
1213
1214 seg.residual_exclude(dd - (v_HT*a_pre_comb)[0]);
1215 seg.residual_include(dd - (v_HT*seg.a())[0]);
1216 seg.doca_exclude(fabs((v_HT*a_pre_comb)[0]));
1217 seg.doca_include(fabs((v_HT*seg.a())[0]));
1218
1219 if(debug_ == 4){
1220 std::cout<<"the dd in smoother_Mdc is "<<dd
1221 <<" the (v_HT*a_pre_comb)[0] is "<<(v_HT*a_pre_comb)[0]<<std::endl;
1222 }
1223
1224 //compare the two method to calculate the include doca value :
1225 if(debug_ == 4){
1226 std::cout<<"method 1 ..."<<sqrt(seg.a()[0]*seg.a()[0]+seg.a()[3]*seg.a()[3])<<std::endl;
1227 std::cout<<"method 2 ..."<<fabs((v_HT*seg.a())[0])<<std::endl;
1228 }
1229
1230
1231 /// move the pivot of the helixseg to IP(0,0,0)
1232 KalFitTrack helixNew1(pivot_work, seg.a(), seg.Ea(), 0, 0, 0);
1233 helixNew1.pivot(ip);
1234 HepVector a_temp1 = helixNew1.a();
1235 HepSymMatrix ea_temp1 = helixNew1.Ea();
1236 seg.Ea(ea_temp1);
1237 seg.a(a_temp1);
1238 seg.Ea_include(ea_temp1);
1239 seg.a_include(a_temp1);
1240
1241 KalFitTrack helixNew2(pivot_work, seg.a_exclude(), seg.Ea_exclude(), 0, 0, 0);
1242 helixNew2.pivot(ip);
1243 HepVector a_temp2 = helixNew2.a();
1244 HepSymMatrix ea_temp2 = helixNew2.Ea();
1245 seg.Ea_exclude(ea_temp2);
1246 seg.a_exclude(a_temp2);
1247
1248 seg.tof(tofest);
1249 seg.dd(dd);
1250
1251 }
1252 return chiSq_back_;
1253}
1254
1255
1256
1257
1258
1259double KalFitTrack::filter(double v_m, const HepVector& m_H,
1260 double v_d, double m_V)
1261{
1262 HepMatrix m_HT = m_H.T();
1263 HepPoint3D x0 = x(0);
1264 HepVector v_x(3);
1265 v_x[0] = x0.x();
1266 v_x[1] = x0.y();
1267 v_x[2] = x0.z();
1268 HepMatrix m_X = delXDelA(0);
1269 HepMatrix m_XT = m_X.T();
1270 HepMatrix m_C = m_X * Ea() * m_XT;
1271 //int err;
1272 HepVector m_K = 1 / (m_V + (m_HT * m_C * m_H)[0]) * m_H;
1273 HepVector v_a = a();
1274 HepSymMatrix ea = Ea();
1275 HepMatrix mXTmK = m_XT * m_K;
1276 double v_r = v_m - v_d - (m_HT * v_x)[0];
1277 v_a += ea * mXTmK * v_r;
1278 a(v_a);
1279 ea.assign(ea - ea * mXTmK * m_HT * m_X * ea);
1280 Ea(ea);
1281 // Record last hit included parameters :
1282 update_last();
1283 HepMatrix mCmK = m_C * m_K;
1284 v_x += mCmK * v_r;
1285 m_C -= mCmK * m_HT * m_C;
1286 v_r = v_m - v_d - (m_HT * v_x)[0];
1287 double m_R = m_V - (m_HT * m_C * m_H)[0];
1288 double chiSq = v_r * v_r / m_R;
1289 chiSq_ += chiSq;
1290 return chiSq;
1291}
1292
1293
1294void KalFitTrack::path_add(double path)
1295{
1296 pathip_ += path;
1297 tof(path);
1298}
1299
1300
1301void KalFitTrack::addPathSM(double path){
1302 pathSM_ += path;
1303}
1304
1305
1307 tof2_ += time;
1308}
1309
1310
1311void KalFitTrack::fiTerm(double fi){
1312 fiTerm_ = fi;
1313}
1314
1315
1316void KalFitTrack::tof(double path)
1317{
1318 double light_speed( 29.9792458 ); // light speed in cm/nsec
1319 double t = tanl();
1320 double pmag( sqrt( 1.0 + t*t ) / kappa());
1321 if (pmag !=0) {
1322 double mass_over_p( mass_ / pmag );
1323 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1324 tof_ += path / ( light_speed * beta );
1325 }
1326
1327 if (tofall_) {
1328 if (p_kaon_ > 0){
1329 double massk_over_p( MASS[3] / p_kaon_ );
1330 double beta_kaon( 1.0 / sqrt( 1.0 + massk_over_p * massk_over_p ) );
1331 tof_kaon_ += path / (light_speed * beta_kaon);
1332 }
1333 if (p_proton_ > 0){
1334 double massp_over_p( MASS[4] / p_proton_ );
1335 double beta_proton( 1.0 / sqrt( 1.0 + massp_over_p * massp_over_p ) );
1336 tof_proton_ += path / (light_speed * beta_proton);
1337 }
1338 }
1339}
1340
1341double KalFitTrack::radius_numf(void) const {
1342
1343 double Bz(Bznom_);
1344 //std::cout<<"Bz: "<<Bz<<std::endl;
1345 if (numf_ > 10){
1346 double dr = a()[0];
1347 double phi0 = a()[1];
1348 double dz = a()[3];
1349 double phi = fmod(phi0 + M_PI4, M_PI2);
1350 double csf0 = cos(phi);
1351 double snf0 = (1. - csf0) * (1. + csf0);
1352 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1353 if(phi > M_PI) snf0 = - snf0;
1354 //XYZPoint
1355 HepPoint3D x0((pivot().x() + dr*csf0),
1356 (pivot().y() + dr*snf0),
1357 (pivot().z() + dz));
1358
1359 //XYZVector b;
1360 HepVector3D b;
1361
1362 //std::cout<<"b: "<<b<<std::endl;
1363
1364 MFSvc_->fieldVector(10.*x0, b);
1365
1366 //std::cout<<"b: "<<b<<std::endl;
1367
1368
1369 b = 10000.*b;
1370 Bz = b.z();
1371 }
1372 if (Bz == 0)
1373 Bz = Bznom_;
1374 double ALPHA_loc = 10000./2.99792458/Bz;
1375 return ALPHA_loc / a()[2];
1376}
1377
1378const HepPoint3D &
1380
1381 int nstep(1);
1382 HepPoint3D delta_x((newPivot-pivot()).x()/double(inner_steps_),
1383 (newPivot-pivot()).y()/double(inner_steps_),
1384 (newPivot-pivot()).z()/double(inner_steps_));
1385 int i = 1;
1386
1387 while (i <= inner_steps_) {
1388 HepPoint3D nextPivot(pivot()+delta_x);
1389 double xnp(nextPivot.x()), ynp(nextPivot.y()), znp(nextPivot.z());
1390 HepSymMatrix Ea_now = Ea();
1391 HepPoint3D piv(pivot());
1392 double xp(piv.x()), yp(piv.y()), zp(piv.z());
1393 double dr = a()[0];
1394 double phi0 = a()[1];
1395 double kappa = a()[2];
1396 double dz = a()[3];
1397 double tanl = a()[4];
1398 double m_rad(0);
1399 if (numfcor_ == 1)
1400 m_rad = radius_numf();
1401 else
1402 m_rad = radius();
1403 double rdr = dr + m_rad;
1404 double phi = fmod(phi0 + M_PI4, M_PI2);
1405 double csf0 = cos(phi);
1406 double snf0 = (1. - csf0) * (1. + csf0);
1407 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1408 if(phi > M_PI) snf0 = - snf0;
1409
1410 double xc = xp + rdr * csf0;
1411 double yc = yp + rdr * snf0;
1412 double csf = (xc - xnp) / m_rad;
1413 double snf = (yc - ynp) / m_rad;
1414 double anrm = sqrt(csf * csf + snf * snf);
1415 csf /= anrm;
1416 snf /= anrm;
1417 phi = atan2(snf, csf);
1418 double phid = fmod(phi - phi0 + M_PI8, M_PI2);
1419 if(phid > M_PI) phid = phid - M_PI2;
1420 double drp = (xp + dr * csf0 + m_rad * (csf0 - csf) - xnp)
1421 * csf
1422 + (yp + dr * snf0 + m_rad * (snf0 - snf) - ynp) * snf;
1423 double dzp = zp + dz - m_rad * tanl * phid - znp;
1424
1425 HepVector ap(5);
1426 ap[0] = drp;
1427 ap[1] = fmod(phi + M_PI4, M_PI2);
1428 ap[2] = kappa;
1429 ap[3] = dzp;
1430 ap[4] = tanl;
1431
1432 // Modification due to non uniform magnetic field :
1433 if (numf_ > 10) {
1434
1435 Hep3Vector x1(xp + dr*csf0, yp + dr*snf0, zp + dz);
1436 double csf0p = cos(ap[1]);
1437 double snf0p = (1. - csf0p) * (1. + csf0p);
1438 snf0p = sqrt((snf0p > 0.) ? snf0p : 0.);
1439 if(ap[1] > M_PI) snf0p = - snf0p;
1440
1441 Hep3Vector x2(xnp + drp*csf0p,
1442 ynp + drp*snf0p,
1443 znp + dzp);
1444 Hep3Vector dist((x1 - x2).x()/100.0,
1445 (x1 - x2).y()/100.0,
1446 (x1 - x2).z()/100.0);
1447 HepPoint3D middlebis((x1.x() + x2.x())/2,
1448 (x1.y() + x2.y())/2,
1449 (x1.z() + x2.z())/2);
1450 HepVector3D field;
1451 MFSvc_->fieldVector(10.*middlebis,field);
1452 field = 1000.*field;
1453 Hep3Vector dB(field.x(),
1454 field.y(),
1455 (field.z()-0.1*Bznom_));
1456 if (field.z()) {
1457 double akappa(fabs(kappa));
1458 double sign = kappa/akappa;
1459 HepVector dp(3);
1460 dp = 0.299792458 * sign * dB.cross(dist);
1461 HepVector dhp(3);
1462 dhp[0] = -akappa*(dp[0]*csf0p+dp[1]*snf0p);
1463 dhp[1] = kappa*akappa*(dp[0]*snf0p-dp[1]*csf0p);
1464 dhp[2] = dp[2]*akappa+dhp[1]*tanl/kappa;
1465 if (numfcor_ == 0){
1466 ap[1] += dhp[0];
1467 }
1468 ap[2] += dhp[1];
1469 ap[4] += dhp[2];
1470 }
1471 }
1472 HepMatrix m_del = delApDelA(ap);
1473 Ea_now.assign(m_del * Ea_now * m_del.T());
1474 pivot(nextPivot);
1475 a(ap);
1476 Ea(Ea_now);
1477 i++;
1478 }
1479 return newPivot;
1480}
1481
1482const HepPoint3D &
1483KalFitTrack::pivot_numf(const HepPoint3D & newPivot, double & pathl) {
1484
1485 Helix tracktest = *(Helix*)this;
1486 tracktest.ignoreErrorMatrix();
1487 double tl = a()[4];
1488 double th = 90.0 - 180.0*M_1_PI*atan( tl );
1489 /*
1490 int nstep(1);
1491 if (steplev_ == 1)
1492 nstep = 3;
1493 else if (steplev_ == 2 && (th > 140 || th <45))
1494 if ((pivot()-newPivot).mag()<3.)
1495 nstep = 3;
1496 else
1497 nstep = 6;
1498 */
1499 Hep3Vector delta_x((newPivot-pivot()).x()/double(outer_steps_),
1500 (newPivot-pivot()).y()/double(outer_steps_),
1501 (newPivot-pivot()).z()/double(outer_steps_));
1502 int i = 1;
1503
1504 while (i <= outer_steps_) {
1505 HepPoint3D nextPivot(pivot()+delta_x);
1506 double xnp(nextPivot.x()), ynp(nextPivot.y()), znp(nextPivot.z());
1507
1508 HepSymMatrix Ea_now = Ea();
1509 HepPoint3D piv(pivot());
1510 double xp(piv.x()), yp(piv.y()), zp(piv.z());
1511
1512 double dr = a()[0];
1513 double phi0 = a()[1];
1514 double kappa = a()[2];
1515 double dz = a()[3];
1516 double tanl = a()[4];
1517
1518 double m_rad(0);
1519 m_rad = radius();
1520
1521 double rdr = dr + m_rad;
1522 double phi = fmod(phi0 + M_PI4, M_PI2);
1523 double csf0 = cos(phi);
1524 double snf0 = (1. - csf0) * (1. + csf0);
1525 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1526 if(phi > M_PI) snf0 = - snf0;
1527
1528 double xc = xp + rdr * csf0;
1529 double yc = yp + rdr * snf0;
1530 double csf = (xc - xnp) / m_rad;
1531 double snf = (yc - ynp) / m_rad;
1532 double anrm = sqrt(csf * csf + snf * snf);
1533 csf /= anrm;
1534 snf /= anrm;
1535 phi = atan2(snf, csf);
1536 double phid = fmod(phi - phi0 + M_PI8, M_PI2);
1537 if(phid > M_PI) phid = phid - M_PI2;
1538 double drp = (xp + dr * csf0 + m_rad * (csf0 - csf) - xnp)
1539 * csf
1540 + (yp + dr * snf0 + m_rad * (snf0 - snf) - ynp) * snf;
1541 double dzp = zp + dz - m_rad * tanl * phid - znp;
1542
1543 HepVector ap(5);
1544 ap[0] = drp;
1545 ap[1] = fmod(phi + M_PI4, M_PI2);
1546 ap[2] = kappa;
1547 ap[3] = dzp;
1548 ap[4] = tanl;
1549
1550 //std::cout<<" numf_: "<<numf_<<std::endl;
1551
1552 // Modification due to non uniform magnetic field :
1553 if (numf_ > 10) {
1554
1555 Hep3Vector x1(xp + dr*csf0, yp + dr*snf0, zp + dz);
1556
1557 double csf0p = cos(ap[1]);
1558 double snf0p = (1. - csf0p) * (1. + csf0p);
1559 snf0p = sqrt((snf0p > 0.) ? snf0p : 0.);
1560 if(ap[1] > M_PI) snf0p = - snf0p;
1561
1562 Hep3Vector x2(xnp + drp*csf0p,
1563 ynp + drp*snf0p,
1564 znp + dzp);
1565
1566 Hep3Vector dist((x1 - x2).x()/100.0,
1567 (x1 - x2).y()/100.0,
1568 (x1 - x2).z()/100.0);
1569
1570 HepPoint3D middlebis((x1.x() + x2.x())/2,
1571 (x1.y() + x2.y())/2,
1572 (x1.z() + x2.z())/2);
1573
1574 HepVector3D field;
1575 MFSvc_->fieldVector(10.*middlebis,field);
1576 field = 1000.*field;
1577
1578 //std::cout<<"B field: "<<field<<std::endl;
1579 Hep3Vector dB(field.x(),
1580 field.y(),
1581 (field.z()-0.1*Bznom_));
1582
1583
1584 //std::cout<<" dB: "<<dB<<std::endl;
1585
1586
1587 if (field.z()) {
1588 double akappa(fabs(kappa));
1589 double sign = kappa/akappa;
1590 HepVector dp(3);
1591 dp = 0.299792458 * sign * dB.cross(dist);
1592
1593 //std::cout<<"dp: "<<dp<<std::endl;
1594
1595 HepVector dhp(3);
1596 dhp[0] = -akappa*(dp[0]*csf0p+dp[1]*snf0p);
1597 dhp[1] = kappa*akappa*(dp[0]*snf0p-dp[1]*csf0p);
1598 dhp[2] = dp[2]*akappa+dhp[1]*tanl/kappa;
1599
1600
1601 //std::cout<<"dhp: "<<dhp<<std::endl;
1602
1603
1604 ap[1] += dhp[0];
1605 ap[2] += dhp[1];
1606 ap[4] += dhp[2];
1607 }
1608 }
1609 HepMatrix m_del = delApDelA(ap);
1610 Ea_now.assign(m_del * Ea_now * m_del.T());
1611 pivot(nextPivot);
1612 a(ap);
1613 Ea(Ea_now);
1614 i++;
1615
1616 //std::cout<<" a: "<<a()<<std::endl;
1617 }
1618
1619 // Estimation of the path length :
1620 double tanl_0(tracktest.a()[4]);
1621 double phi0_0(tracktest.a()[1]);
1622 double radius_0(tracktest.radius());
1623 tracktest.pivot(newPivot);
1624
1625 double phi0_1 = tracktest.a()[1];
1626 if (fabs(phi0_1 - phi0_0) > M_PI) {
1627 if (phi0_1 > phi0_0) phi0_1 -= 2 * M_PI;
1628 else phi0_0 -= 2 * M_PI;
1629 }
1630 if(phi0_1 == phi0_0) phi0_1 = phi0_0 + 1.e-10;
1631 pathl = fabs(radius_0 * (phi0_1 - phi0_0)
1632 * sqrt(1 + tanl_0 * tanl_0));
1633 return newPivot;
1634}
1635
1636// function to calculate the path length in the layer
1637/*
1638 double KalFitTrack::PathL(int layer){
1639 HepPoint3D piv(pivot());
1640 double phi0 = a()[1];
1641 double kappa = a()[2];
1642 double tanl = a()[4];
1643
1644#ifdef YDEBUG
1645cout<<"helix "<<a()<<endl;
1646#endif
1647// Choose the local field !!
1648double Bz(Bznom_);
1649if (numf_ > 10){
1650HepVector3D b;
1651MFSvc_->fieldVector(10.*piv, b);
1652b = 10000.*b;
1653Bz=b.z();
1654}
1655double ALPHA_loc = 10000./2.99792458/Bz;
1656int charge = ( kappa >= 0 )? 1 : -1;
1657double rho = ALPHA_loc/kappa;
1658double pt = fabs( 1.0/kappa );
1659double lambda = 180.0*M_1_PI*atan( tanl );
1660double theta = 90.0 - lambda;
1661theta = 2.0*M_PI*theta/360.;
1662double phi = fmod(phi0 + M_PI4, M_PI2);
1663double csf0 = cos(phi);
1664double snf0 = (1. - csf0) * (1. + csf0);
1665snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1666if(phi > M_PI) snf0 = - snf0;
1667
1668double x_c = piv.x() + ( dr() + rho )*csf0;
1669double y_c = piv.y() + ( dr() + rho )*snf0;
1670double z_c = piv.z() + dz();
1671HepPoint3D ccenter(x_c, y_c, 0);
1672double m_c_perp(ccenter.perp());
1673Hep3Vector m_c_unit(((CLHEP::Hep3Vector)ccenter).unit());
1674#ifdef YDEBUG
1675cout<<"rho=..."<<rho<<endl;
1676cout<<"ccenter "<<ccenter<<" m_c_unit "<<m_c_unit<<endl;
1677#endif
1678//phi resion estimation
1679double phi_io[2];
1680HepPoint3D IO = charge*m_c_unit;
1681double dphi0 = fmod( IO.phi()+4*M_PI,2*M_PI ) - phi;
1682if( dphi0 > M_PI ) dphi0 -= 2*M_PI;
1683else if( dphi0 < -M_PI ) dphi0 += 2*M_PI;
1684phi_io[0] = -(1+charge)*M_PI_2 - charge*dphi0;
1685phi_io[1] = phi_io[0]+1.5*M_PI;
1686double phi_in(0); /// for debug
1687
1688double m_crio[2];
1689double m_zb, m_zf;
1690int m_div;
1691
1692// retrieve Mdc geometry information
1693// IMdcGeomSvc* geosvc;
1694StatusCode sc= Gaudi::svcLocator()->service("MdcGeomSvc", geosvc);
1695if(sc==StatusCode::FAILURE) cout << "GeoSvc failing!!!!!!!SC=" << sc << endl;
1696
1697MdcGeomSvc* geomsvc = dynamic_cast<MdcGeomSvc*>(iGeomSvc_);
1698if(!geomsvc){
1699std::cout<<"ERROR OCCUR when dynamic_cast in KalFitTrack.cxx !!"<<std::endl;
1700}
1701double rcsiz1 = geomsvc->Layer(layer)->RCSiz1();
1702double rcsiz2 = geomsvc->Layer(layer)->RCSiz2();
1703double rlay = geomsvc->Layer(layer)->Radius();
1704m_zb = 0.5*(geomsvc->Layer(layer)->Length());
1705m_zf = -0.5*(geomsvc->Layer(layer)->Length());
1706
1707m_crio[0] = rlay - rcsiz1;
1708m_crio[1] = rlay + rcsiz2;
1709//conversion of the units(mm=>cm)
1710m_crio[0] = 0.1*m_crio[0];
1711m_crio[1] = 0.1*m_crio[1];
1712m_zb = 0.1*m_zb;
1713m_zf = 0.1*m_zf;
1714
1715int sign = 1; ///assumed the first half circle
1716int epflag[2];
1717Hep3Vector iocand;
1718Hep3Vector cell_IO[2];
1719double dphi;
1720for( int i = 0; i < 2; i++ ){
1721 double cos_alpha = m_c_perp*m_c_perp + m_crio[i]*m_crio[i] - rho*rho;
1722 cos_alpha = 0.5*cos_alpha/( m_c_perp*m_crio[i] );
1723 double Calpha = acos( cos_alpha );
1724 epflag[i] = 0;
1725 iocand = m_c_unit;
1726 iocand.rotateZ( charge*sign*Calpha );
1727 iocand *= m_crio[i];
1728 double xx = iocand.x() - x_c;
1729 double yy = iocand.y() - y_c;
1730 dphi = atan2(yy, xx) - phi0 - M_PI_2*(1+charge);
1731 dphi = fmod( dphi + 8.0*M_PI, 2*M_PI );
1732
1733 if( dphi < phi_io[0] ){
1734 dphi += 2*M_PI;
1735 }
1736 else if( phi_io[1] < dphi ){
1737 dphi -= 2*M_PI;
1738 }
1739
1740 ///in the Local Helix case, phi must be small
1741
1742 Hep3Vector zvector( 0., 0., z_c-rho*dphi*tanl);
1743
1744 double xcio, ycio, phip;
1745 ///// z region check active volume is between zb+2. and zf-2. [cm]
1746 double delrin = 2.0;
1747 if( m_zf-delrin > zvector.z() ){
1748 phip = z_c - m_zb + delrin;
1749 phip = phip/( rho*tanl );
1750 phip = phip + phi0;
1751 xcio = x_c - rho*cos( phip );
1752 ycio = y_c - rho*sin( phip );
1753 cell_IO[i].setX( xcio );
1754 cell_IO[i].setY( ycio );
1755 cell_IO[i].setZ( m_zb+delrin );
1756 epflag[i] = 1;
1757 }
1758 else if( m_zb+delrin < zvector.z() ){
1759 phip = z_c - m_zf-delrin;
1760 phip = phip/( rho*tanl );
1761 phip = phip + phi0;
1762 xcio = x_c - rho*cos( phip );
1763 ycio = y_c - rho*sin( phip );
1764 cell_IO[i].setX( xcio );
1765 cell_IO[i].setY( ycio );
1766 cell_IO[i].setZ( m_zf-delrin );
1767 epflag[i] = 1;
1768 }
1769 else{
1770 cell_IO[i] = iocand;
1771 cell_IO[i] += zvector;
1772 }
1773 /// for debug
1774 if( i == 0 ) phi_in = dphi;
1775}
1776// path length estimation
1777// phi calculation
1778Hep3Vector cl = cell_IO[1] - cell_IO[0];
1779#ifdef YDEBUG
1780cout<<"cell_IO[0] "<<cell_IO[0]<<" cell_IO[1] "<<cell_IO[1]<<" cl "<<cl<<endl;
1781#endif
1782
1783double ch_theta;
1784double ch_dphi;
1785double ch_ltrk = 0;
1786double ch_ltrk_rp = 0;
1787ch_dphi = cl.perp()*0.5/(ALPHA_loc*pt);
1788ch_dphi = 2.0 * asin( ch_dphi );
1789ch_ltrk_rp = ch_dphi*ALPHA_loc*pt;
1790#ifdef YDEBUG
1791cout<<"ch_dphi "<<ch_dphi<<" ch_ltrk_rp "<<ch_ltrk_rp<<" cl.z "<<cl.z()<<endl;
1792#endif
1793ch_ltrk = sqrt( ch_ltrk_rp*ch_ltrk_rp + cl.z()*cl.z() );
1794ch_theta = cl.theta();
1795
1796if( ch_theta < theta*0.85 || 1.15*theta < ch_theta)
1797 ch_ltrk *= -1; /// miss calculation
1798
1799if( epflag[0] == 1 || epflag [1] == 1 )
1800 ch_ltrk *= -1; /// invalid resion for dE/dx or outside of Mdc
1801
1802 mom_[layer] = momentum( phi_in );
1803 PathL_[layer] = ch_ltrk;
1804#ifdef YDEBUG
1805 cout<<"ch_ltrk "<<ch_ltrk<<endl;
1806#endif
1807 return ch_ltrk;
1808 }
1809*/
1810
1811
1813 int j(0);
1814 if (i < 31){
1815 j = (int) pow(2.,i);
1816 if (!(pat1_ & j))
1817 pat1_ = pat1_ | j;
1818 } else if (i < 50) {
1819 j = (int) pow(2.,(i-31));
1820 if (!(pat2_ & j))
1821 pat2_ = pat2_ | j;
1822 }
1823}
1824
1825int KalFitTrack::nmass(void){ return NMASS;}
1826double KalFitTrack::mass(int i){ return MASS[i];}
1828 mass_=MASS[i];
1829 l_mass_=i;
1830}
1831
1832void KalFitTrack::lead(int i){ lead_ = i;}
1833int KalFitTrack::lead(void){ return lead_;}
1834void KalFitTrack::back(int i){ back_ = i;}
1835int KalFitTrack::back(void){ return back_;}
1838void KalFitTrack::numf(int i){ numf_ = i;}
1839int KalFitTrack::numf(void){ return numf_;}
1840void KalFitTrack::LR(int x){ LR_ = x;}
1841void KalFitTrack::HitsMdc(vector<KalFitHitMdc>& lh){ HitsMdc_ = lh;}
1842void KalFitTrack::appendHitsMdc(KalFitHitMdc h){ HitsMdc_.push_back(h);}
1843
1844/*
1845 This member function is in charge of the forward filter,
1846 for the tof correction of the drift distance in the case of cosmic rays
1847 if way=1, it's a down track means same as track in collision data,
1848 if way=-1, it's a up track !
1849 */
1850
1851double KalFitTrack::update_hits(KalFitHitMdc & HitMdc, int inext, Hep3Vector& meas, int way, double& dchi2out, double& dtrack,double& dtracknew, double& dtdc, int csmflag) {
1852
1853 double lr = HitMdc.LR();
1854 //std::cout<<" in update_hits: lr= " << lr <<std::endl;
1855 // For taking the propagation delay into account :
1856 const KalFitWire& Wire = HitMdc.wire();
1857 int wire_ID = Wire.geoID();
1858 int layerid = HitMdc.wire().layer().layerId();
1859 //std::cout<<" when in layer: "<<layerid<<std::endl;
1860 double entrangle = HitMdc.rechitptr()->getEntra();
1861
1862 if (wire_ID<0 || wire_ID>6796){ //bes
1863 std::cout << " KalFitTrack: wire_ID problem : " << wire_ID
1864 << std::endl;
1865 return 0;
1866 }
1867 int flag_ster = Wire.stereo();
1868 double x[3] ={pivot().x(), pivot().y(), pivot().z()};
1869 double pmom[3] ={momentum().x(), momentum().y(), momentum().z()};
1870 double tofest(0);
1871 double phi = fmod(phi0() + M_PI4, M_PI2);
1872 double csf0 = cos(phi);
1873 double snf0 = (1. - csf0) * (1. + csf0);
1874 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
1875 if(phi > M_PI) snf0 = - snf0;
1876 if (Tof_correc_){
1877 double t = tanl();
1878 double dphi(0);
1879
1880 Helix work = *(Helix*)this;
1881 work.ignoreErrorMatrix();
1882 double phi_ip(0);
1883 Hep3Vector ip(0, 0, 0);
1884 work.pivot(ip);
1885 phi_ip = work.phi0();
1886 if (fabs(phi - phi_ip) > M_PI) {
1887 if (phi > phi_ip) phi -= 2 * M_PI;
1888 else phi_ip -= 2 * M_PI;
1889 }
1890 dphi = phi - phi_ip;
1891 double l = fabs(radius() * dphi * sqrt(1 + t * t));
1892 double pmag( sqrt( 1.0 + t*t ) / kappa());
1893 double mass_over_p( mass_ / pmag );
1894 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
1895 tofest = l / ( 29.9792458 * beta );
1896 if(csmflag==1 && HitMdc.wire().y()>0.) tofest= -1. * tofest;
1897 }
1898
1899 const HepSymMatrix& ea = Ea();
1900 const HepVector& v_a = a();
1901 double dchi2R(99999999), dchi2L(99999999);
1902
1903 HepVector v_H(5, 0);
1904 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
1905 v_H[3] = -meas.z();
1906 HepMatrix v_HT = v_H.T();
1907
1908 double estim = (v_HT * v_a)[0];
1909 dtrack = estim;
1910 // std::cout<<" in update_hits estim is "<<estim<<std::endl;
1911 HepVector ea_v_H = ea * v_H;
1912 HepMatrix ea_v_HT = (ea_v_H).T();
1913 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
1914
1915 HepSymMatrix eaNewL(5), eaNewR(5);
1916 HepVector aNewL(5), aNewR(5);
1917
1918 double drifttime = getDriftTime(HitMdc , tofest);
1919 double ddl = getDriftDist(HitMdc, drifttime, 0 );
1920 double ddr = getDriftDist(HitMdc, drifttime, 1 );
1921 double erddl = getSigma( HitMdc, a()[4], 0, ddl);
1922 double erddr = getSigma( HitMdc, a()[4], 1, ddr);
1923
1924 if(debug_ == 4) {
1925 std::cout<<"drifttime in update_hits() for ananlysis is "<<drifttime<<std::endl;
1926 std::cout<<"ddl in update_hits() for ananlysis is "<<ddl<<std::endl;
1927 std::cout<<"ddr in update_hits() for ananlysis is "<<ddr<<std::endl;
1928 std::cout<<"erddl in update_hits() for ananlysis is "<<erddl<<std::endl;
1929 std::cout<<"erddr in update_hits() for ananlysis is "<<erddr<<std::endl;
1930 }
1931
1932 //the following 3 line : tempory
1933 double dmeas2[2] = { 0.1*ddl, 0.1*ddr }; // millimeter to centimeter
1934 double er_dmeas2[2] = {0.,0.};
1935 if(resolflag_ == 1) {
1936 er_dmeas2[0] = 0.1*erddl;
1937 er_dmeas2[1] = 0.1*erddr;
1938 }
1939 else if(resolflag_ == 0) {
1940 // int layid = HitMdc.wire().layer().layerId();
1941 // double sigma = getSigma(layid, dd);
1942 // er_dmeas2[0] = er_dmeas2[1] = sigma;
1943 }
1944
1945 // Left hypothesis :
1946 if ((LR_==0 && lr != 1.0) ||
1947 (LR_==1 && lr == -1.0)) {
1948 double er_dmeasL, dmeasL;
1949 if(Tof_correc_) {
1950 dmeasL = (-1.0)*fabs(dmeas2[0]);
1951 er_dmeasL = er_dmeas2[0];
1952 } else {
1953 dmeasL = (-1.0)*fabs(HitMdc.dist()[0]);
1954 er_dmeasL = HitMdc.erdist()[0];
1955 }
1956 dtdc = dmeasL;
1957 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
1958 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
1959 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
1960 if(debug_ == 4){
1961 std::cout<<" ea_v_H * AL * ea_v_HT is: "<<ea_v_H * AL * ea_v_HT<<std::endl;
1962 std::cout<<" v_H is: "<<v_H<<" Ea is: "<<ea<<" v_H_T_ea_v_H is: "<<v_H_T_ea_v_H<<std::endl;
1963 std::cout<<" AL is: "<<AL<<" (v_H_T_ea_v_H)[0] * AL is: "<<(v_H_T_ea_v_H)[0]*AL<<std::endl;
1964 }
1965
1966 if(0. == RkL) RkL = 1.e-4;
1967
1968 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
1969 aNewL = v_a + diffL;
1970 double sigL = dmeasL -(v_HT * aNewL)[0];
1971 dtracknew = (v_HT * aNewL)[0];
1972 dchi2L = (sigL * sigL)/(RkL * er_dmeasL*er_dmeasL);
1973
1974 if(debug_ == 4){
1975 std::cout<<" fwd_filter : in left hypothesis dchi2L is "<<dchi2L<<std::endl;
1976 }
1977 }
1978
1979 if ((LR_==0 && lr != -1.0) ||
1980 (LR_==1 && lr == 1.0)) {
1981 double er_dmeasR, dmeasR;
1982 if(Tof_correc_) {
1983 dmeasR = dmeas2[1];
1984 er_dmeasR = er_dmeas2[1];
1985 } else {
1986 dmeasR = fabs(HitMdc.dist()[1]);
1987 er_dmeasR = HitMdc.erdist()[1];
1988 }
1989 dtdc = dmeasR;
1990 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
1991 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
1992 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
1993
1994 if(debug_ == 4){
1995 std::cout<<" ea_v_H * AR * ea_v_HT is: "<<ea_v_H * AR * ea_v_HT<<std::endl;
1996 std::cout<<" v_H is: "<<v_H<<" Ea is: "<<ea<<" v_H_T_ea_v_H is: "<<v_H_T_ea_v_H<<std::endl;
1997 std::cout<<" AR is: "<<AR<<" (v_H_T_ea_v_H)[0] * AR is: "<<(v_H_T_ea_v_H)[0]*AR<<std::endl;
1998 }
1999
2000 if(0. == RkR) RkR = 1.e-4;
2001 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
2002 aNewR = v_a + diffR;
2003 double sigR = dmeasR -(v_HT * aNewR)[0];
2004 dtracknew = (v_HT * aNewR)[0];
2005 dchi2R = (sigR*sigR)/(RkR * er_dmeasR*er_dmeasR);
2006 if(debug_ == 4){
2007 std::cout<<" fwd_filter : in right hypothesis dchi2R is "<<dchi2R<<std::endl;
2008 }
2009 }
2010 // Update Kalman result :
2011 double dchi2_loc(0);
2012 if (fabs(dchi2R-dchi2L)<10. && inext>0) {
2013 KalFitHitMdc & HitMdc_next = HitsMdc_[inext];
2014 Helix H_fromR(pivot(), aNewR, eaNewR);
2015 double chi2_fromR(chi2_next(H_fromR, HitMdc_next, csmflag));
2016 Helix H_fromL(pivot(), aNewL, eaNewL);
2017 double chi2_fromL(chi2_next(H_fromL, HitMdc_next, csmflag));
2018#ifdef YDEBUG
2019 std::cout << " chi2_fromL = " << chi2_fromL
2020 << ", chi2_fromR = " << chi2_fromR << std::endl;
2021#endif
2022 if (fabs(chi2_fromR-chi2_fromL)<10.){
2023 int inext2(-1);
2024 if (inext+1<HitsMdc_.size())
2025 for( int k=inext+1 ; k < HitsMdc_.size(); k++ )
2026 if (!(HitsMdc_[k].chi2()<0)) {
2027 inext2 = k;
2028 break;
2029 }
2030
2031 if (inext2 != -1){
2032 KalFitHitMdc & HitMdc_next2 = HitsMdc_[inext2];
2033 double chi2_fromR2(chi2_next(H_fromR, HitMdc_next2, csmflag));
2034 double chi2_fromL2(chi2_next(H_fromL, HitMdc_next2, csmflag));
2035#ifdef YDEBUG
2036 std::cout << " chi2_fromL2 = " << chi2_fromL2
2037 << ", chi2_fromR2 = " << chi2_fromR2 << std::endl;
2038#endif
2039 if (fabs(dchi2R+chi2_fromR+chi2_fromR2-(dchi2L+chi2_fromL+chi2_fromL2))<2) {
2040 if (chi2_fromR2<chi2_fromL2)
2041 dchi2L = DBL_MAX;
2042 else
2043 dchi2R = DBL_MAX;
2044 }
2045 }
2046 }
2047
2048 if (!(dchi2L == DBL_MAX && dchi2R == DBL_MAX)) {
2049 if (dchi2R+chi2_fromR < dchi2L+chi2_fromL){
2050 dchi2L = DBL_MAX;
2051#ifdef YDEBUG
2052 std::cout << " choose right..." << std::endl;
2053#endif
2054 } else {
2055 dchi2R = DBL_MAX;
2056#ifdef YDEBUG
2057 std::cout << " choose left..." << std::endl;
2058#endif
2059 }
2060 }
2061 }
2062 if ((0 < dchi2R && dchi2R < dchi2cutf_anal[layerid]) ||
2063 (0 < dchi2L && dchi2L < dchi2cutf_anal[layerid])) {
2064
2065 if (((LR_==0 && dchi2R < dchi2L && lr != -1) ||
2066 (LR_==1 && lr == 1)) &&
2067 fabs(aNewR[2]-a()[2]) < 1000. && aNewR[2]) {
2068 if (nchits_ < (unsigned) nmdc_hit2_ || dchi2R < dchi2cutf_anal[layerid]){
2069 nchits_++;
2070 if (flag_ster) nster_++;
2071 useLayer(layerid);// myLayerUsed
2072 Ea(eaNewR);
2073 a(aNewR);
2074 chiSq_ += dchi2R;
2075 dchi2_loc = dchi2R;
2076 if (l_mass_ == lead_){
2077 HitMdc.LR(1);
2078 }
2080 }
2081 } else if (((LR_==0 && dchi2L <= dchi2R && lr != 1) ||
2082 (LR_==1 && lr == -1)) &&
2083 fabs(aNewL[2]-a()[2]) < 1000. && aNewL[2]){
2084 if (nchits_ < (unsigned) nmdc_hit2_ || dchi2L < dchi2cutf_anal[layerid]){
2085 nchits_++;
2086 if (flag_ster) nster_++;
2087 useLayer(layerid);// myLayerUsed
2088 Ea(eaNewL);
2089 a(aNewL);
2090 chiSq_ += dchi2L;
2091 dchi2_loc = dchi2L;
2092 if (l_mass_ == lead_){
2093 HitMdc.LR(-1);
2094 }
2096 }
2097 }
2098 }
2099 //cout<<"__FUNCTION__: layerid = "<<layerid<<endl;
2100 if (dchi2_loc > dchi2_max_) {
2101 dchi2_max_ = dchi2_loc ;
2102 r_max_ = pivot().perp();
2103 }
2104 dchi2out = dchi2_loc;
2105 //if(dchi2out == 0) {
2106 // dchi2out = ( (dchi2L < dchi2R ) ? dchi2L : dchi2R ) ;
2107 // }
2108 return chiSq_;
2109}
2110
2111
2112double KalFitTrack::update_hits_csmalign(KalFitHelixSeg& HelixSeg, int inext, Hep3Vector& meas,int way, double& dchi2out, int csmflag ) {
2113
2114
2115 HepPoint3D ip(0.,0.,0.);
2116
2118 double lr = HitMdc->LR();
2119 int layerid = (*HitMdc).wire().layer().layerId();
2120 // cout<<"layerid: "<<layerid<<endl;
2121 double entrangle = HitMdc->rechitptr()->getEntra();
2122
2123 if(debug_ == 4) {
2124 std::cout<<"in update_hits(kalFitHelixSeg,...) : the layerid ="<<layerid<<std::endl;
2125 std::cout<<" update_hits: lr= " << lr <<std::endl;
2126 }
2127 // For taking the propagation delay into account :
2128 const KalFitWire& Wire = HitMdc->wire();
2129 int wire_ID = Wire.geoID();
2130
2131 if (wire_ID<0 || wire_ID>6796){ //bes
2132 std::cout << " KalFitTrack: wire_ID problem : " << wire_ID
2133 << std::endl;
2134 return 0;
2135 }
2136 int flag_ster = Wire.stereo();
2137 double x[3] ={pivot().x(), pivot().y(), pivot().z()};
2138 double pmom[3] ={momentum().x(), momentum().y(), momentum().z()};
2139 double tofest(0);
2140 double phi = fmod(phi0() + M_PI4, M_PI2);
2141 double csf0 = cos(phi);
2142 double snf0 = (1. - csf0) * (1. + csf0);
2143 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
2144 if(phi > M_PI) snf0 = - snf0;
2145 if (Tof_correc_){
2146 double t = tanl();
2147 double dphi(0);
2148
2149 Helix work = *(Helix*)this;
2150 work.ignoreErrorMatrix();
2151 double phi_ip(0);
2152 Hep3Vector ip(0, 0, 0);
2153 work.pivot(ip);
2154 phi_ip = work.phi0();
2155 if (fabs(phi - phi_ip) > M_PI) {
2156 if (phi > phi_ip) phi -= 2 * M_PI;
2157 else phi_ip -= 2 * M_PI;
2158 }
2159 dphi = phi - phi_ip;
2160
2161 double l = fabs(radius() * dphi * sqrt(1 + t * t));
2162 double pmag( sqrt( 1.0 + t*t ) / kappa());
2163 double mass_over_p( mass_ / pmag );
2164 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2165 tofest = l / ( 29.9792458 * beta );
2166 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
2167 }
2168
2169 const HepSymMatrix& ea = Ea();
2170 HelixSeg.Ea_pre_fwd(ea);
2172
2173
2174 const HepVector& v_a = a();
2175 HelixSeg.a_pre_fwd(v_a);
2176 HelixSeg.a_filt_fwd(v_a);
2177
2178 /*
2179
2180 HepPoint3D pivot_work = pivot();
2181 HepVector a_work = a();
2182 HepSymMatrix ea_work = Ea();
2183 KalFitTrack helix_work(pivot_work, a_work, ea_work, 0, 0, 0);
2184 helix_work.pivot(ip);
2185
2186 HepVector a_temp = helix_work.a();
2187 HepSymMatrix ea_temp = helix_work.Ea();
2188
2189 HelixSeg.Ea_pre_fwd(ea_temp);
2190 HelixSeg.a_pre_fwd(a_temp);
2191
2192 // My God, for the protection purpose
2193 HelixSeg.Ea_filt_fwd(ea_temp);
2194 HelixSeg.a_filt_fwd(a_temp);
2195
2196 */
2197
2198 double dchi2R(99999999), dchi2L(99999999);
2199
2200 HepVector v_H(5, 0);
2201 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2202 v_H[3] = -meas.z();
2203 HepMatrix v_HT = v_H.T();
2204
2205 double estim = (v_HT * v_a)[0];
2206 HepVector ea_v_H = ea * v_H;
2207 HepMatrix ea_v_HT = (ea_v_H).T();
2208 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2209
2210 HepSymMatrix eaNewL(5), eaNewR(5);
2211 HepVector aNewL(5), aNewR(5);
2212#ifdef YDEBUG
2213 cout<<"phi "<<phi<<" snf0 "<<snf0<<" csf0 "<<csf0<<endl
2214 <<" meas: "<<meas <<endl;
2215 cout<<"the related matrix:"<<endl;
2216 cout<<"v_H "<<v_H<<endl;
2217 cout<<"v_a "<<v_a<<endl;
2218 cout<<"ea "<<ea<<endl;
2219 cout<<"v_H_T_ea_v_H "<<v_H_T_ea_v_H<<endl;
2220 cout<<"LR_= "<< LR_ << "lr= " << lr <<endl;
2221#endif
2222
2223 double time = (*HitMdc).tdc();
2224 // if (Tof_correc_)
2225 // time = time - way*tofest;
2226
2227 // double dd = 1.0e-4 * 40.0 * time;
2228 //the following 3 line : tempory
2229
2230 double drifttime = getDriftTime(*HitMdc , tofest);
2231 double ddl = getDriftDist(*HitMdc, drifttime, 0 );
2232 double ddr = getDriftDist(*HitMdc, drifttime, 1 );
2233 double erddl = getSigma( *HitMdc, a()[4], 0, ddl);
2234 double erddr = getSigma( *HitMdc, a()[4], 1, ddr);
2235
2236 if(debug_ == 4){
2237 std::cout<<"the pure drift time is "<<drifttime<<std::endl;
2238 std::cout<<"the drift dist left hypothesis is "<<ddl<<std::endl;
2239 std::cout<<"the drift dist right hypothesis is "<<ddr<<std::endl;
2240 std::cout<<"the error sigma left hypothesis is "<<erddl<<std::endl;
2241 std::cout<<"the error sigma right hypothesis is "<<erddr<<std::endl;
2242 }
2243 double dmeas2[2] = { 0.1*ddl , 0.1*ddr }; //millimeter to centimeter
2244 double er_dmeas2[2] = {0. , 0.} ;
2245
2246 if(resolflag_ == 1) {
2247 er_dmeas2[0] = 0.1*erddl;
2248 er_dmeas2[1] = 0.1*erddr;
2249 }
2250 else if(resolflag_ == 0) {
2251 // int layid = (*HitMdc).wire().layer().layerId();
2252 // double sigma = getSigma(layid, dd);
2253 // er_dmeas2[0] = er_dmeas2[1] = sigma;
2254 }
2255
2256 // Left hypothesis :
2257 if ((LR_==0 && lr != 1.0) ||
2258 (LR_==1 && lr == -1.0)) {
2259
2260 double er_dmeasL, dmeasL;
2261 if(Tof_correc_) {
2262 dmeasL = (-1.0)*fabs(dmeas2[0]);
2263 er_dmeasL = er_dmeas2[0];
2264 } else {
2265 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
2266 er_dmeasL = (*HitMdc).erdist()[0];
2267 }
2268
2269 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
2270 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
2271 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
2272 if(0. == RkL) RkL = 1.e-4;
2273
2274 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
2275
2276 aNewL = v_a + diffL;
2277 double sigL = dmeasL -(v_HT * aNewL)[0];
2278 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
2279 }
2280
2281 if ((LR_==0 && lr != -1.0) ||
2282 (LR_==1 && lr == 1.0)) {
2283
2284 double er_dmeasR, dmeasR;
2285 if(Tof_correc_) {
2286 dmeasR = dmeas2[1];
2287 er_dmeasR = er_dmeas2[1];
2288 } else {
2289 dmeasR = fabs((*HitMdc).dist()[1]);
2290 er_dmeasR = (*HitMdc).erdist()[1];
2291 }
2292
2293 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
2294 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
2295 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
2296 if(0. == RkR) RkR = 1.e-4;
2297
2298 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
2299
2300 aNewR = v_a + diffR;
2301 double sigR = dmeasR -(v_HT * aNewR)[0];
2302 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
2303 }
2304
2305 // Update Kalman result :
2306 double dchi2_loc(0);
2307
2308#ifdef YDEBUG
2309 cout<<" track::update_hits......"<<endl;
2310 std::cout << " dchi2R = " << dchi2R << ", dchi2L = " << dchi2L
2311 << " estimate = "<<estim<< std::endl;
2312 std::cout << " dmeasR = " << dmeas2[1]
2313 << ", dmeasL = " << (-1.0)*fabs(dmeas2[0]) << ", check HitMdc.ddl = "
2314 << (*HitMdc).dist()[0] << std::endl;
2315 std::cout<<"dchi2L : "<<dchi2L<<" ,dchi2R: "<<dchi2R<<std::endl;
2316#endif
2317
2318
2319 if (fabs(dchi2R-dchi2L)<10. && inext>0) {
2320
2321 KalFitHitMdc & HitMdc_next = HitsMdc_[inext];
2322
2323 Helix H_fromR(pivot(), aNewR, eaNewR);
2324 double chi2_fromR(chi2_next(H_fromR, HitMdc_next,csmflag));
2325 //double chi2_fromR(chi2_next(H_fromR, HitMdc_next));
2326
2327 Helix H_fromL(pivot(), aNewL, eaNewL);
2328 double chi2_fromL(chi2_next(H_fromL, HitMdc_next,csmflag));
2329 //double chi2_fromL(chi2_next(H_fromL, HitMdc_next));
2330#ifdef YDEBUG
2331 std::cout << " chi2_fromL = " << chi2_fromL
2332 << ", chi2_fromR = " << chi2_fromR << std::endl;
2333#endif
2334 if (fabs(chi2_fromR-chi2_fromL)<10.){
2335 int inext2(-1);
2336 if (inext+1<HitsMdc_.size())
2337 for( int k=inext+1 ; k < HitsMdc_.size(); k++ )
2338 if (!(HitsMdc_[k].chi2()<0)) {
2339 inext2 = k;
2340 break;
2341 }
2342
2343 if (inext2 != -1){
2344 KalFitHitMdc & HitMdc_next2 = HitsMdc_[inext2];
2345 // double chi2_fromR2(chi2_next(H_fromR, HitMdc_next2));
2346 // double chi2_fromL2(chi2_next(H_fromL, HitMdc_next2));
2347 double chi2_fromR2(chi2_next(H_fromR, HitMdc_next2, csmflag));
2348 double chi2_fromL2(chi2_next(H_fromL, HitMdc_next2, csmflag));
2349#ifdef YDEBUG
2350 std::cout << " chi2_fromL2 = " << chi2_fromL2
2351 << ", chi2_fromR2 = " << chi2_fromR2 << std::endl;
2352#endif
2353 if (fabs(dchi2R+chi2_fromR+chi2_fromR2-(dchi2L+chi2_fromL+chi2_fromL2))<2) {
2354 if (chi2_fromR2<chi2_fromL2)
2355 dchi2L = DBL_MAX;
2356 else
2357 dchi2R = DBL_MAX;
2358 }
2359 }
2360 }
2361
2362 if (!(dchi2L == DBL_MAX && dchi2R == DBL_MAX)) {
2363 if (dchi2R+chi2_fromR < dchi2L+chi2_fromL){
2364 dchi2L = DBL_MAX;
2365#ifdef YDEBUG
2366 std::cout << " choose right..." << std::endl;
2367#endif
2368 } else {
2369 dchi2R = DBL_MAX;
2370#ifdef YDEBUG
2371 std::cout << " choose left..." << std::endl;
2372#endif
2373 }
2374 }
2375 }
2376
2377 if ((0 < dchi2R && dchi2R < dchi2cutf_calib[layerid]) ||
2378 (0 < dchi2L && dchi2L < dchi2cutf_calib[layerid])) {
2379
2380 if (((LR_==0 && dchi2R < dchi2L && lr != -1) ||
2381 (LR_==1 && lr == 1)) &&
2382 fabs(aNewR[2]-a()[2]) < 1000. && aNewR[2]) {
2383 if (nchits_ < (unsigned) nmdc_hit2_ || dchi2R < dchi2cutf_calib[layerid]){
2384 nchits_++;
2385 if (flag_ster) nster_++;
2386 if(layerid>19){
2387 Ea(eaNewR);
2388 HelixSeg.Ea_filt_fwd(eaNewR);
2389 a(aNewR);
2390 HelixSeg.a_filt_fwd(aNewR);
2391 }
2392 /*
2393 Ea(eaNewR);
2394 a(aNewR);
2395
2396 KalFitTrack helixR(pivot_work, aNewR, eaNewR, 0, 0, 0);
2397 helixR.pivot(ip);
2398
2399 a_temp = helixR.a();
2400 ea_temp = helixR.Ea();
2401
2402 HelixSeg.Ea_filt_fwd(ea_temp);
2403 HelixSeg.a_filt_fwd(a_temp);
2404 //HelixSeg.filt_include(1);
2405
2406 */
2407
2408 chiSq_ += dchi2R;
2409 dchi2_loc = dchi2R;
2410 if (l_mass_ == lead_){
2411 (*HitMdc).LR(1);
2412 HelixSeg.LR(1);
2413 }
2414 update_bit((*HitMdc).wire().layer().layerId());
2415 }
2416 } else if (((LR_==0 && dchi2L <= dchi2R && lr != 1) ||
2417 (LR_==1 && lr == -1)) &&
2418 fabs(aNewL[2]-a()[2]) < 1000. && aNewL[2]){
2419 if (nchits_ < (unsigned) nmdc_hit2_ || dchi2L < dchi2cutf_calib[layerid]){
2420 nchits_++;
2421 if (flag_ster) nster_++;
2422 if(layerid>19){
2423 Ea(eaNewL);
2424 HelixSeg.Ea_filt_fwd(eaNewL);
2425 a(aNewL);
2426 HelixSeg.a_filt_fwd(aNewL);
2427 }
2428
2429 /*
2430 Ea(eaNewL);
2431 a(aNewL);
2432
2433 KalFitTrack helixL(pivot_work, aNewL, eaNewL, 0, 0, 0);
2434 helixL.pivot(ip);
2435 a_temp = helixL.a();
2436 ea_temp = helixL.Ea();
2437 HelixSeg.Ea_filt_fwd(ea_temp);
2438 HelixSeg.a_filt_fwd(a_temp);
2439 //HelixSeg.filt_include(1);
2440
2441 */
2442
2443 chiSq_ += dchi2L;
2444 dchi2_loc = dchi2L;
2445 if (l_mass_ == lead_){
2446 (*HitMdc).LR(-1);
2447 HelixSeg.LR(-1);
2448 }
2449 update_bit((*HitMdc).wire().layer().layerId());
2450 }
2451 }
2452 }
2453
2454 if (dchi2_loc > dchi2_max_) {
2455 dchi2_max_ = dchi2_loc ;
2456 r_max_ = pivot().perp();
2457 }
2458 dchi2out = dchi2_loc;
2459 // if(dchi2out == 0) {
2460 // dchi2out = ( (dchi2L < dchi2R ) ? dchi2L : dchi2R ) ;
2461 // }
2462 return chiSq_;
2463}
2464
2465
2466double KalFitTrack::update_hits(KalFitHelixSeg& HelixSeg, int inext, Hep3Vector& meas,int way, double& dchi2out, int csmflag) {
2467
2468
2469 HepPoint3D ip(0.,0.,0.);
2470
2472 double lr = HitMdc->LR();
2473 int layerid = (*HitMdc).wire().layer().layerId();
2474 double entrangle = HitMdc->rechitptr()->getEntra();
2475
2476 if(debug_ == 4) {
2477 std::cout<<"in update_hits(kalFitHelixSeg,...) : the layerid ="<<layerid<<std::endl;
2478 std::cout<<" update_hits: lr= " << lr <<std::endl;
2479 }
2480 // For taking the propagation delay into account :
2481 const KalFitWire& Wire = HitMdc->wire();
2482 int wire_ID = Wire.geoID();
2483
2484 if (wire_ID<0 || wire_ID>6796){ //bes
2485 std::cout << " KalFitTrack: wire_ID problem : " << wire_ID
2486 << std::endl;
2487 return 0;
2488 }
2489 int flag_ster = Wire.stereo();
2490 double x[3] ={pivot().x(), pivot().y(), pivot().z()};
2491 double pmom[3] ={momentum().x(), momentum().y(), momentum().z()};
2492 double tofest(0);
2493 double phi = fmod(phi0() + M_PI4, M_PI2);
2494 double csf0 = cos(phi);
2495 double snf0 = (1. - csf0) * (1. + csf0);
2496 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
2497 if(phi > M_PI) snf0 = - snf0;
2498 if (Tof_correc_){
2499 double t = tanl();
2500 double dphi(0);
2501
2502 Helix work = *(Helix*)this;
2503 work.ignoreErrorMatrix();
2504 double phi_ip(0);
2505 Hep3Vector ip(0, 0, 0);
2506 work.pivot(ip);
2507 phi_ip = work.phi0();
2508 if (fabs(phi - phi_ip) > M_PI) {
2509 if (phi > phi_ip) phi -= 2 * M_PI;
2510 else phi_ip -= 2 * M_PI;
2511 }
2512 dphi = phi - phi_ip;
2513
2514 double l = fabs(radius() * dphi * sqrt(1 + t * t));
2515 double pmag( sqrt( 1.0 + t*t ) / kappa());
2516 double mass_over_p( mass_ / pmag );
2517 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2518 tofest = l / ( 29.9792458 * beta );
2519 if(csmflag==1 && (*HitMdc).wire().y()>0.) tofest= -1. * tofest;
2520 }
2521
2522 const HepSymMatrix& ea = Ea();
2523 HelixSeg.Ea_pre_fwd(ea);
2525
2526
2527 const HepVector& v_a = a();
2528 HelixSeg.a_pre_fwd(v_a);
2529 HelixSeg.a_filt_fwd(v_a);
2530
2531 /*
2532
2533 HepPoint3D pivot_work = pivot();
2534 HepVector a_work = a();
2535 HepSymMatrix ea_work = Ea();
2536 KalFitTrack helix_work(pivot_work, a_work, ea_work, 0, 0, 0);
2537 helix_work.pivot(ip);
2538
2539 HepVector a_temp = helix_work.a();
2540 HepSymMatrix ea_temp = helix_work.Ea();
2541
2542 HelixSeg.Ea_pre_fwd(ea_temp);
2543 HelixSeg.a_pre_fwd(a_temp);
2544
2545 // My God, for the protection purpose
2546 HelixSeg.Ea_filt_fwd(ea_temp);
2547 HelixSeg.a_filt_fwd(a_temp);
2548
2549 */
2550
2551
2552 double dchi2R(99999999), dchi2L(99999999);
2553
2554 HepVector v_H(5, 0);
2555 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2556 v_H[3] = -meas.z();
2557 HepMatrix v_HT = v_H.T();
2558
2559 double estim = (v_HT * v_a)[0];
2560 HepVector ea_v_H = ea * v_H;
2561 HepMatrix ea_v_HT = (ea_v_H).T();
2562 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2563
2564 HepSymMatrix eaNewL(5), eaNewR(5);
2565 HepVector aNewL(5), aNewR(5);
2566#ifdef YDEBUG
2567 cout<<"phi "<<phi<<" snf0 "<<snf0<<" csf0 "<<csf0<<endl
2568 <<" meas: "<<meas <<endl;
2569 cout<<"the related matrix:"<<endl;
2570 cout<<"v_H "<<v_H<<endl;
2571 cout<<"v_a "<<v_a<<endl;
2572 cout<<"ea "<<ea<<endl;
2573 cout<<"v_H_T_ea_v_H "<<v_H_T_ea_v_H<<endl;
2574 cout<<"LR_= "<< LR_ << "lr= " << lr <<endl;
2575#endif
2576
2577 double time = (*HitMdc).tdc();
2578 // if (Tof_correc_)
2579 // time = time - way*tofest;
2580
2581 // double dd = 1.0e-4 * 40.0 * time;
2582 //the following 3 line : tempory
2583
2584 double drifttime = getDriftTime(*HitMdc , tofest);
2585 double ddl = getDriftDist(*HitMdc, drifttime, 0 );
2586 double ddr = getDriftDist(*HitMdc, drifttime, 1 );
2587 double erddl = getSigma( *HitMdc, a()[4], 0, ddl);
2588 double erddr = getSigma( *HitMdc, a()[4], 1, ddr);
2589
2590 if(debug_ == 4){
2591 std::cout<<"the pure drift time is "<<drifttime<<std::endl;
2592 std::cout<<"the drift dist left hypothesis is "<<ddl<<std::endl;
2593 std::cout<<"the drift dist right hypothesis is "<<ddr<<std::endl;
2594 std::cout<<"the error sigma left hypothesis is "<<erddl<<std::endl;
2595 std::cout<<"the error sigma right hypothesis is "<<erddr<<std::endl;
2596 }
2597 double dmeas2[2] = { 0.1*ddl , 0.1*ddr }; //millimeter to centimeter
2598 double er_dmeas2[2] = {0. , 0.} ;
2599
2600 if(resolflag_ == 1) {
2601 er_dmeas2[0] = 0.1*erddl;
2602 er_dmeas2[1] = 0.1*erddr;
2603 }
2604 else if(resolflag_ == 0) {
2605 // int layid = (*HitMdc).wire().layer().layerId();
2606 // double sigma = getSigma(layid, dd);
2607 // er_dmeas2[0] = er_dmeas2[1] = sigma;
2608 }
2609
2610 // Left hypothesis :
2611 if ((LR_==0 && lr != 1.0) ||
2612 (LR_==1 && lr == -1.0)) {
2613
2614 double er_dmeasL, dmeasL;
2615 if(Tof_correc_) {
2616 dmeasL = (-1.0)*fabs(dmeas2[0]);
2617 er_dmeasL = er_dmeas2[0];
2618 } else {
2619 dmeasL = (-1.0)*fabs((*HitMdc).dist()[0]);
2620 er_dmeasL = (*HitMdc).erdist()[0];
2621 }
2622
2623 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
2624 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
2625 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
2626 if(0. == RkL) RkL = 1.e-4;
2627
2628 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
2629
2630 aNewL = v_a + diffL;
2631 double sigL = dmeasL -(v_HT * aNewL)[0];
2632 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
2633 }
2634
2635 if ((LR_==0 && lr != -1.0) ||
2636 (LR_==1 && lr == 1.0)) {
2637
2638 double er_dmeasR, dmeasR;
2639 if(Tof_correc_) {
2640 dmeasR = dmeas2[1];
2641 er_dmeasR = er_dmeas2[1];
2642 } else {
2643 dmeasR = fabs((*HitMdc).dist()[1]);
2644 er_dmeasR = (*HitMdc).erdist()[1];
2645 }
2646
2647 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
2648 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
2649 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
2650 if(0. == RkR) RkR = 1.e-4;
2651
2652 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
2653
2654 aNewR = v_a + diffR;
2655 double sigR = dmeasR -(v_HT * aNewR)[0];
2656 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
2657 }
2658
2659 // Update Kalman result :
2660 double dchi2_loc(0);
2661
2662#ifdef YDEBUG
2663 cout<<" track::update_hits......"<<endl;
2664 std::cout << " dchi2R = " << dchi2R << ", dchi2L = " << dchi2L
2665 << " estimate = "<<estim<< std::endl;
2666 std::cout << " dmeasR = " << dmeas2[1]
2667 << ", dmeasL = " << (-1.0)*fabs(dmeas2[0]) << ", check HitMdc.ddl = "
2668 << (*HitMdc).dist()[0] << std::endl;
2669#endif
2670
2671 if (fabs(dchi2R-dchi2L)<10. && inext>0) {
2672
2673 KalFitHitMdc & HitMdc_next = HitsMdc_[inext];
2674
2675 Helix H_fromR(pivot(), aNewR, eaNewR);
2676 double chi2_fromR(chi2_next(H_fromR, HitMdc_next,csmflag));
2677
2678 Helix H_fromL(pivot(), aNewL, eaNewL);
2679 double chi2_fromL(chi2_next(H_fromL, HitMdc_next,csmflag));
2680#ifdef YDEBUG
2681 std::cout << " chi2_fromL = " << chi2_fromL
2682 << ", chi2_fromR = " << chi2_fromR << std::endl;
2683#endif
2684 if (fabs(chi2_fromR-chi2_fromL)<10.){
2685 int inext2(-1);
2686 if (inext+1<HitsMdc_.size())
2687 for( int k=inext+1 ; k < HitsMdc_.size(); k++ )
2688 if (!(HitsMdc_[k].chi2()<0)) {
2689 inext2 = k;
2690 break;
2691 }
2692
2693 if (inext2 != -1){
2694 KalFitHitMdc & HitMdc_next2 = HitsMdc_[inext2];
2695 double chi2_fromR2(chi2_next(H_fromR, HitMdc_next2, csmflag));
2696 double chi2_fromL2(chi2_next(H_fromL, HitMdc_next2, csmflag));
2697#ifdef YDEBUG
2698 std::cout << " chi2_fromL2 = " << chi2_fromL2
2699 << ", chi2_fromR2 = " << chi2_fromR2 << std::endl;
2700#endif
2701 if (fabs(dchi2R+chi2_fromR+chi2_fromR2-(dchi2L+chi2_fromL+chi2_fromL2))<2) {
2702 if (chi2_fromR2<chi2_fromL2)
2703 dchi2L = DBL_MAX;
2704 else
2705 dchi2R = DBL_MAX;
2706 }
2707 }
2708 }
2709
2710 if (!(dchi2L == DBL_MAX && dchi2R == DBL_MAX)) {
2711 if (dchi2R+chi2_fromR < dchi2L+chi2_fromL){
2712 dchi2L = DBL_MAX;
2713#ifdef YDEBUG
2714 std::cout << " choose right..." << std::endl;
2715#endif
2716 } else {
2717 dchi2R = DBL_MAX;
2718#ifdef YDEBUG
2719 std::cout << " choose left..." << std::endl;
2720#endif
2721 }
2722 }
2723 }
2724
2725 if ((0 < dchi2R && dchi2R < dchi2cutf_calib[layerid]) ||
2726 (0 < dchi2L && dchi2L < dchi2cutf_calib[layerid])) {
2727
2728 if (((LR_==0 && dchi2R < dchi2L && lr != -1) ||
2729 (LR_==1 && lr == 1)) &&
2730 fabs(aNewR[2]-a()[2]) < 1000. && aNewR[2]) {
2731 if (nchits_ < (unsigned) nmdc_hit2_ || dchi2R < dchi2cutf_calib[layerid]){
2732 nchits_++;
2733 if (flag_ster) nster_++;
2734
2735 Ea(eaNewR);
2736 HelixSeg.Ea_filt_fwd(eaNewR);
2737 a(aNewR);
2738 HelixSeg.a_filt_fwd(aNewR);
2739
2740 /*
2741 Ea(eaNewR);
2742 a(aNewR);
2743
2744 KalFitTrack helixR(pivot_work, aNewR, eaNewR, 0, 0, 0);
2745 helixR.pivot(ip);
2746
2747 a_temp = helixR.a();
2748 ea_temp = helixR.Ea();
2749
2750 HelixSeg.Ea_filt_fwd(ea_temp);
2751 HelixSeg.a_filt_fwd(a_temp);
2752 //HelixSeg.filt_include(1);
2753
2754 */
2755
2756 chiSq_ += dchi2R;
2757 dchi2_loc = dchi2R;
2758 if (l_mass_ == lead_){
2759 (*HitMdc).LR(1);
2760 HelixSeg.LR(1);
2761 }
2762 update_bit((*HitMdc).wire().layer().layerId());
2763 }
2764 } else if (((LR_==0 && dchi2L <= dchi2R && lr != 1) ||
2765 (LR_==1 && lr == -1)) &&
2766 fabs(aNewL[2]-a()[2]) < 1000. && aNewL[2]){
2767 if (nchits_ < (unsigned) nmdc_hit2_ || dchi2L < dchi2cutf_calib[layerid]){
2768 nchits_++;
2769 if (flag_ster) nster_++;
2770 Ea(eaNewL);
2771 HelixSeg.Ea_filt_fwd(eaNewL);
2772 a(aNewL);
2773 HelixSeg.a_filt_fwd(aNewL);
2774
2775
2776 /*
2777 Ea(eaNewL);
2778 a(aNewL);
2779
2780 KalFitTrack helixL(pivot_work, aNewL, eaNewL, 0, 0, 0);
2781 helixL.pivot(ip);
2782 a_temp = helixL.a();
2783 ea_temp = helixL.Ea();
2784 HelixSeg.Ea_filt_fwd(ea_temp);
2785 HelixSeg.a_filt_fwd(a_temp);
2786 //HelixSeg.filt_include(1);
2787
2788 */
2789
2790 chiSq_ += dchi2L;
2791 dchi2_loc = dchi2L;
2792 if (l_mass_ == lead_){
2793 (*HitMdc).LR(-1);
2794 HelixSeg.LR(-1);
2795 }
2796 update_bit((*HitMdc).wire().layer().layerId());
2797 }
2798 }
2799 }
2800
2801 if (dchi2_loc > dchi2_max_) {
2802 dchi2_max_ = dchi2_loc ;
2803 r_max_ = pivot().perp();
2804 }
2805 dchi2out = dchi2_loc;
2806 // if(dchi2out == 0) {
2807 // dchi2out = ( (dchi2L < dchi2R ) ? dchi2L : dchi2R ) ;
2808 // }
2809 return chiSq_;
2810}
2811
2812
2813double KalFitTrack::update_hits(RecCgemCluster* Cluster, double recR, int way, int csmflag) //add by Huang Zhen
2814{
2815 //const double a_stero[3] = {(45.94*3.1415926/180),(31.10*3.1415926/180),(32.99*3.1415926/180)};
2816 //const double r_layer[3] = {87.5026,132.7686,175.2686};
2817 //const double x_reso[3]={0.1372,0.1476,0.1412};
2818 //const double v_reso[3]={0.1273,0.1326,0.1378};
2819
2820 // --- measurement
2821 double recZ = Cluster->getRecZ()/10;
2822 double recPhi = Cluster->getrecphi();
2823 while(recPhi > M_PI) recPhi-=2*M_PI;
2824 while(recPhi <-M_PI) recPhi+=2*M_PI;
2825 HepVector v_measu(2,0);
2826 v_measu(1) = recPhi;
2827 v_measu(2) = recZ;
2828
2829 // --- estimation
2830 //double Phi = intersect_cylinder(recR);
2831 HepPoint3D x0kal = x(intersect_cylinder(recR));
2832 pivot_numf(x0kal);
2833 HepVector v_estim(2,0);
2834 v_estim(1) = x0kal.phi();
2835 v_estim(2) = x0kal.z();
2836
2837 const HepSymMatrix& ea = Ea();
2838 HepVector v_a = a();
2839
2840 // --- derivative matrix
2841 double dPhi=intersect_cylinder(recR);
2842 double dr = v_a(1);
2843 double phi0 = v_a(2);
2844 double kappa = v_a(3);
2845 double tanl = v_a(5);
2846 double x0 = x0kal.x();
2847 double y0 = x0kal.y();
2848 double Alpha = alpha();
2849 HepMatrix H(2, 5, 0);
2850 H(1,1) = -y0*cos(phi0)/(y0*y0+x0*x0)+x0*sin(phi0)/(x0*x0+y0*y0);
2851 H(1,2) = -y0/(y0*y0+x0*x0)*((-1)*dr*sin(phi0)+Alpha/kappa*(sin(phi0+dPhi)-sin(phi0)))+x0/(x0*x0+y0*y0)*(dr*cos(phi0)+Alpha/kappa*(cos(phi0)-cos(phi0+dPhi)));
2852 H(1,3) = -y0/(y0*y0+x0*x0)*(-1)*Alpha/(kappa*kappa)*(cos(phi0)-cos(phi0+dPhi))+x0/(x0*x0+y0*y0)*(-1)*Alpha/(kappa*kappa)*(sin(phi0)-sin(phi0+dPhi));
2853 H(2,3) = Alpha/(kappa*kappa)*tanl*dPhi;
2854 H(2,4) = 1.0;
2855 H(2,5) = -1*(Alpha/kappa)*dPhi;
2856
2857 // --- error matrix of Cgem
2858 int layer = Cluster->getlayerid();
2859 ISvcLocator* svcLocator = Gaudi::svcLocator();
2860 ICgemGeomSvc* ISvc;
2861 StatusCode Cgem_sc=svcLocator->service("CgemGeomSvc", ISvc);
2862 CgemGeomSvc* CgemGeomSvc_=dynamic_cast<CgemGeomSvc *>(ISvc);
2863 CgemGeoLayer* CgemLayer = CgemGeomSvc_->getCgemLayer(layer);
2864 double R_x = (CgemLayer->getInnerROfAnodeCu2() + CgemLayer->getOuterROfAnodeCu2())/2;
2865 //R_v = (CgemLayer->getInnerROfAnodeCu1() + CgemLayer->getOuterROfAnodeCu1())/2;
2866 double a_stero = (CgemLayer->getAngleOfStereo())*M_PI/180;
2867
2868 ICgemCalibFunSvc* CgemCalibSvc;
2869 StatusCode sc = svcLocator->service ("CgemCalibFunSvc", CgemCalibSvc);
2870 int iView(0), mode(2);
2871 double Q(100), T(100);
2872 double Phi_momentum = momentum(dPhi).phi();
2873 double Phi_position = x0kal.phi();
2874 double delta_phi=Phi_momentum - Phi_position;
2875 while(delta_phi>M_PI) delta_phi-=CLHEP::twopi;
2876 while(delta_phi<-M_PI) delta_phi+=CLHEP::twopi;
2877 double sigma_X = CgemCalibSvc->getSigma(layer,iView,mode,delta_phi,Q,T);// in mm
2878 double sigma_V = CgemCalibSvc->getSigma(layer,iView,mode,delta_phi,Q,T);// in mm
2879
2880 HepSymMatrix V(2,0);
2881 //V(1,1) = pow(x_reso[layer]/r_layer[layer],2);
2882 //V(2,2) = pow(sqrt(0.01*v_reso[layer]*v_reso[layer]/(sin(a_stero[layer])*sin(a_stero[layer]))+0.01*x_reso[layer]*x_reso[layer]/(tan(a_stero[layer])*tan(a_stero[layer]))),2);
2883 V(1,1) = pow(sigma_X/R_x,2);
2884 V(2,2) = pow(sqrt(0.01*sigma_V*sigma_V/(sin(a_stero)*sin(a_stero))+0.01*sigma_X*sigma_X/(tan(a_stero)*tan(a_stero))),2);
2885 // --- gain matrix
2886 int ierr=-1;
2887 HepMatrix K = ea*H.T()*(V+H*ea*H.T()).inverse(ierr);
2888 if(ierr != 0)cout<<"errer in inverse operation of matrix!"<<endl;
2889
2890 // --- new error matrix
2891 HepSymMatrix EaNew(5,0);
2892 EaNew.assign(ea-K*H*ea);
2893 Ea(EaNew);
2894
2895 // --- diff
2896 HepVector v_diff = v_measu - v_estim;
2897 while(v_diff(1) > M_PI) v_diff(1)-=2*M_PI;
2898 while(v_diff(1) <- M_PI) v_diff(1)+=2*M_PI;
2899
2900 // --- new parameters
2901 //HepVector aNew = v_a + K*v_diff;
2902 a(v_a + K*v_diff);
2903
2904 // --- new v_estim
2905 HepPoint3D x0kal_new = x(intersect_cylinder(recR));
2906 HepVector v_estim_new(2,0);
2907 v_estim_new(1) = x0kal_new.phi();
2908 v_estim_new(2) = x0kal_new.z();
2909
2910 // --- difference between measurement and updated estimation
2911 v_diff = v_measu - v_estim_new;
2912 while(v_diff(1) > M_PI) v_diff(1)-=2*M_PI;
2913 while(v_diff(1) <- M_PI) v_diff(1)+=2*M_PI;
2914
2915 // --- new derivative matrix
2916 //track_new.pivot_numf(x0kal_new,pathl);
2917 //HepVector a_new = track_new.a();
2918 //HepVector Ea_new = track_new.ea();
2919
2920 // --- R matrix and Chisuqre
2921 HepSymMatrix R(2,0);
2922 R.assign(V-H*EaNew*H.T());
2923 HepVector dChi2 = v_diff.T()*R.inverse(ierr)*v_diff;
2924 if(ierr != 0)cout<<"errer in inverse operation of matrix!"<<endl;
2925
2926 // --- update Chisqure of track
2927 if(way>0) chiSq(chiSq()+dChi2(1));
2928 if(way<0) chiSq_back(chiSq_back()+dChi2(1));
2929 return dChi2(1);
2930}
2932
2933 double lr = HitMdc.LR();
2934 const KalFitWire& Wire = HitMdc.wire();
2935 int wire_ID = Wire.geoID();
2936 int layerid = HitMdc.wire().layer().layerId();
2937 double entrangle = HitMdc.rechitptr()->getEntra();
2938
2939 HepPoint3D fwd(Wire.fwd());
2940 HepPoint3D bck(Wire.bck());
2941 Hep3Vector wire = (Hep3Vector)fwd -(Hep3Vector)bck;
2942 Helix work = H;
2943 work.ignoreErrorMatrix();
2944 work.pivot((fwd + bck) * .5);
2945 HepPoint3D x0kal = (work.x(0).z() - bck.z())/ wire.z() * wire + bck;
2946 H.pivot(x0kal);
2947
2948 Hep3Vector meas = H.momentum(0).cross(wire).unit();
2949
2950 if (wire_ID<0 || wire_ID>6796){ //bes
2951 std::cout << "KalFitTrack : wire_ID problem : " << wire_ID
2952 << std::endl;
2953 return DBL_MAX;
2954 }
2955
2956 double x[3] ={pivot().x(), pivot().y(), pivot().z()};
2957 double pmom[3] ={momentum().x(), momentum().y(), momentum().z()};
2958 double tofest(0);
2959 double phi = fmod(phi0() + M_PI4, M_PI2);
2960 double csf0 = cos(phi);
2961 double snf0 = (1. - csf0) * (1. + csf0);
2962 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
2963 if(phi > M_PI) snf0 = - snf0;
2964
2965 if (Tof_correc_) {
2966 Hep3Vector ip(0, 0, 0);
2967 Helix work = *(Helix*)this;
2968 work.ignoreErrorMatrix();
2969 work.pivot(ip);
2970 double phi_ip = work.phi0();
2971 if (fabs(phi - phi_ip) > M_PI) {
2972 if (phi > phi_ip) phi -= 2 * M_PI;
2973 else phi_ip -= 2 * M_PI;
2974 }
2975 double t = tanl();
2976 double l = fabs(radius() * (phi - phi_ip) * sqrt(1 + t * t));
2977 double pmag( sqrt( 1.0 + t*t ) / kappa());
2978 double mass_over_p( mass_ / pmag );
2979 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
2980 tofest = l / ( 29.9792458 * beta );
2981 // if(csmflag==1 && HitMdc.wire().y()>0.) tofest= -1. * tofest;
2982 }
2983
2984 const HepSymMatrix& ea = H.Ea();
2985 const HepVector& v_a = H.a();
2986 double dchi2R(DBL_MAX), dchi2L(DBL_MAX);
2987
2988 HepVector v_H(5, 0);
2989 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
2990 v_H[3] = -meas.z();
2991 HepMatrix v_HT = v_H.T();
2992
2993 double estim = (v_HT * v_a)[0];
2994 HepVector ea_v_H = ea * v_H;
2995 HepMatrix ea_v_HT = (ea_v_H).T();
2996 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
2997
2998 HepSymMatrix eaNewL(5), eaNewR(5);
2999 HepVector aNewL(5), aNewR(5);
3000
3001 //double time = HitMdc.tdc();
3002 //if (Tof_correc_)
3003 // time = time - tofest;
3004 double drifttime = getDriftTime(HitMdc , tofest);
3005 double ddl = getDriftDist(HitMdc, drifttime , 0 );
3006 double ddr = getDriftDist(HitMdc, drifttime , 1 );
3007 double erddl = getSigma( HitMdc, H.a()[4], 0, ddl);
3008 double erddr = getSigma( HitMdc, H.a()[4], 1, ddr);
3009
3010 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
3011 double er_dmeas2[2] = {0. , 0.};
3012 if(resolflag_ == 1) {
3013 er_dmeas2[0] = 0.1*erddl;
3014 er_dmeas2[1] = 0.1*erddr;
3015 }
3016 else if(resolflag_ == 0) {
3017 // int layid = HitMdc.wire().layer().layerId();
3018 // double sigma = getSigma(layid, dd);
3019 // er_dmeas2[0] = er_dmeas2[1] = sigma;
3020 }
3021
3022 if ((LR_==0 && lr != 1.0) ||
3023 (LR_==1 && lr == -1.0)) {
3024
3025 double er_dmeasL, dmeasL;
3026 if(Tof_correc_) {
3027 dmeasL = (-1.0)*fabs(dmeas2[0]);
3028 er_dmeasL = er_dmeas2[0];
3029 } else {
3030 dmeasL = (-1.0)*fabs(HitMdc.dist()[0]);
3031 er_dmeasL = HitMdc.erdist()[0];
3032 }
3033
3034 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
3035 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
3036 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
3037 if(0. == RkL) RkL = 1.e-4;
3038
3039 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
3040 aNewL = v_a + diffL;
3041 double sigL = dmeasL -(v_HT * aNewL)[0];
3042 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
3043 }
3044
3045 if ((LR_==0 && lr != -1.0) ||
3046 (LR_==1 && lr == 1.0)) {
3047
3048 double er_dmeasR, dmeasR;
3049 if(Tof_correc_) {
3050 dmeasR = dmeas2[1];
3051 er_dmeasR = er_dmeas2[1];
3052 } else {
3053 dmeasR = fabs(HitMdc.dist()[1]);
3054 er_dmeasR = HitMdc.erdist()[1];
3055 }
3056
3057 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
3058 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
3059 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
3060 if(0. == RkR) RkR = 1.e-4;
3061
3062 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
3063 aNewR = v_a + diffR;
3064 double sigR = dmeasR -(v_HT * aNewR)[0];
3065 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
3066 }
3067
3068 if (dchi2R < dchi2L){
3069 H.a(aNewR); H.Ea(eaNewR);
3070 } else {
3071 H.a(aNewL); H.Ea(eaNewL);
3072 }
3073 return ((dchi2R < dchi2L) ? dchi2R : dchi2L);
3074}
3075
3076double KalFitTrack::chi2_next(Helix& H, KalFitHitMdc & HitMdc, int csmflag){
3077
3078 double lr = HitMdc.LR();
3079 const KalFitWire& Wire = HitMdc.wire();
3080 int wire_ID = Wire.geoID();
3081 int layerid = HitMdc.wire().layer().layerId();
3082 double entrangle = HitMdc.rechitptr()->getEntra();
3083
3084 HepPoint3D fwd(Wire.fwd());
3085 HepPoint3D bck(Wire.bck());
3086 Hep3Vector wire = (Hep3Vector)fwd -(Hep3Vector)bck;
3087 Helix work = H;
3088 work.ignoreErrorMatrix();
3089 work.pivot((fwd + bck) * .5);
3090 HepPoint3D x0kal = (work.x(0).z() - bck.z())/ wire.z() * wire + bck;
3091 H.pivot(x0kal);
3092
3093 Hep3Vector meas = H.momentum(0).cross(wire).unit();
3094
3095 if (wire_ID<0 || wire_ID>6796){ //bes
3096 std::cout << "KalFitTrack : wire_ID problem : " << wire_ID
3097 << std::endl;
3098 return DBL_MAX;
3099 }
3100
3101 double x[3] ={pivot().x(), pivot().y(), pivot().z()};
3102 double pmom[3] ={momentum().x(), momentum().y(), momentum().z()};
3103 double tofest(0);
3104 double phi = fmod(phi0() + M_PI4, M_PI2);
3105 double csf0 = cos(phi);
3106 double snf0 = (1. - csf0) * (1. + csf0);
3107 snf0 = sqrt((snf0 > 0.) ? snf0 : 0.);
3108 if(phi > M_PI) snf0 = - snf0;
3109
3110 if (Tof_correc_) {
3111 Hep3Vector ip(0, 0, 0);
3112 Helix work = *(Helix*)this;
3113 work.ignoreErrorMatrix();
3114 work.pivot(ip);
3115 double phi_ip = work.phi0();
3116 if (fabs(phi - phi_ip) > M_PI) {
3117 if (phi > phi_ip) phi -= 2 * M_PI;
3118 else phi_ip -= 2 * M_PI;
3119 }
3120 double t = tanl();
3121 double l = fabs(radius() * (phi - phi_ip) * sqrt(1 + t * t));
3122 double pmag( sqrt( 1.0 + t*t ) / kappa());
3123 double mass_over_p( mass_ / pmag );
3124 double beta( 1.0 / sqrt( 1.0 + mass_over_p * mass_over_p ) );
3125 tofest = l / ( 29.9792458 * beta );
3126 if(csmflag==1 && HitMdc.wire().y()>0.) tofest= -1. * tofest;
3127 }
3128
3129 const HepSymMatrix& ea = H.Ea();
3130 const HepVector& v_a = H.a();
3131 double dchi2R(DBL_MAX), dchi2L(DBL_MAX);
3132
3133 HepVector v_H(5, 0);
3134 v_H[0] = -csf0 * meas.x() - snf0 * meas.y();
3135 v_H[3] = -meas.z();
3136 HepMatrix v_HT = v_H.T();
3137
3138 double estim = (v_HT * v_a)[0];
3139 HepVector ea_v_H = ea * v_H;
3140 HepMatrix ea_v_HT = (ea_v_H).T();
3141 HepVector v_H_T_ea_v_H = v_HT * ea_v_H;
3142
3143 HepSymMatrix eaNewL(5), eaNewR(5);
3144 HepVector aNewL(5), aNewR(5);
3145
3146 //double time = HitMdc.tdc();
3147 //if (Tof_correc_)
3148 // time = time - tofest;
3149 double drifttime = getDriftTime(HitMdc , tofest);
3150 double ddl = getDriftDist(HitMdc, drifttime , 0 );
3151 double ddr = getDriftDist(HitMdc, drifttime , 1 );
3152 double erddl = getSigma( HitMdc, H.a()[4], 0, ddl);
3153 double erddr = getSigma( HitMdc, H.a()[4], 1, ddr);
3154
3155 double dmeas2[2] = { 0.1*ddl, 0.1*ddr };
3156 double er_dmeas2[2] = {0. , 0.};
3157 if(resolflag_ == 1) {
3158 er_dmeas2[0] = 0.1*erddl;
3159 er_dmeas2[1] = 0.1*erddr;
3160 }
3161 else if(resolflag_ == 0) {
3162 // int layid = HitMdc.wire().layer().layerId();
3163 // double sigma = getSigma(layid, dd);
3164 // er_dmeas2[0] = er_dmeas2[1] = sigma;
3165 }
3166
3167 if ((LR_==0 && lr != 1.0) ||
3168 (LR_==1 && lr == -1.0)) {
3169
3170 double er_dmeasL, dmeasL;
3171 if(Tof_correc_) {
3172 dmeasL = (-1.0)*fabs(dmeas2[0]);
3173 er_dmeasL = er_dmeas2[0];
3174 } else {
3175 dmeasL = (-1.0)*fabs(HitMdc.dist()[0]);
3176 er_dmeasL = HitMdc.erdist()[0];
3177 }
3178
3179 double AL = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasL*er_dmeasL);
3180 eaNewL.assign(ea - ea_v_H * AL * ea_v_HT);
3181 double RkL = 1 - (v_H_T_ea_v_H)[0] * AL;
3182 if(0. == RkL) RkL = 1.e-4;
3183
3184 HepVector diffL = ea_v_H * AL * (dmeasL - estim);
3185 aNewL = v_a + diffL;
3186 double sigL = dmeasL -(v_HT * aNewL)[0];
3187 dchi2L = (sigL * sigL) / (RkL * er_dmeasL*er_dmeasL);
3188 }
3189
3190 if ((LR_==0 && lr != -1.0) ||
3191 (LR_==1 && lr == 1.0)) {
3192
3193 double er_dmeasR, dmeasR;
3194 if(Tof_correc_) {
3195 dmeasR = dmeas2[1];
3196 er_dmeasR = er_dmeas2[1];
3197 } else {
3198 dmeasR = fabs(HitMdc.dist()[1]);
3199 er_dmeasR = HitMdc.erdist()[1];
3200 }
3201
3202 double AR = 1 / ((v_H_T_ea_v_H)[0] + er_dmeasR*er_dmeasR);
3203 eaNewR.assign(ea - ea_v_H * AR * ea_v_HT);
3204 double RkR = 1 - (v_H_T_ea_v_H)[0] * AR;
3205 if(0. == RkR) RkR = 1.e-4;
3206
3207 HepVector diffR = ea_v_H * AR * (dmeasR - estim);
3208 aNewR = v_a + diffR;
3209 double sigR = dmeasR -(v_HT * aNewR)[0];
3210 dchi2R = (sigR*sigR) / (RkR * er_dmeasR*er_dmeasR);
3211 }
3212
3213 if (dchi2R < dchi2L){
3214 H.a(aNewR); H.Ea(eaNewR);
3215 } else {
3216 H.a(aNewL); H.Ea(eaNewL);
3217 }
3218 return ((dchi2R < dchi2L) ? dchi2R : dchi2L);
3219}
3220
3221
3222double KalFitTrack::getSigma(int layerId, double driftDist ) const {
3223 double sigma1,sigma2,f;
3224 driftDist *= 10;//mm
3225 if(layerId<8){
3226 if(driftDist<0.5){
3227 sigma1=0.112784; sigma2=0.229274; f=0.666;
3228 }else if(driftDist<1.){
3229 sigma1=0.103123; sigma2=0.269797; f=0.934;
3230 }else if(driftDist<1.5){
3231 sigma1=0.08276; sigma2=0.17493; f=0.89;
3232 }else if(driftDist<2.){
3233 sigma1=0.070109; sigma2=0.149859; f=0.89;
3234 }else if(driftDist<2.5){
3235 sigma1=0.064453; sigma2=0.130149; f=0.886;
3236 }else if(driftDist<3.){
3237 sigma1=0.062383; sigma2=0.138806; f=0.942;
3238 }else if(driftDist<3.5){
3239 sigma1=0.061873; sigma2=0.145696; f=0.946;
3240 }else if(driftDist<4.){
3241 sigma1=0.061236; sigma2=0.119584; f=0.891;
3242 }else if(driftDist<4.5){
3243 sigma1=0.066292; sigma2=0.148426; f=0.917;
3244 }else if(driftDist<5.){
3245 sigma1=0.078074; sigma2=0.188148; f=0.911;
3246 }else if(driftDist<5.5){
3247 sigma1=0.088657; sigma2=0.27548; f=0.838;
3248 }else{
3249 sigma1=0.093089; sigma2=0.115556; f=0.367;
3250 }
3251 }else{
3252 if(driftDist<0.5){
3253 sigma1=0.112433; sigma2=0.327548; f=0.645;
3254 }else if(driftDist<1.){
3255 sigma1=0.096703; sigma2=0.305206; f=0.897;
3256 }else if(driftDist<1.5){
3257 sigma1=0.082518; sigma2=0.248913; f= 0.934;
3258 }else if(driftDist<2.){
3259 sigma1=0.072501; sigma2=0.153868; f= 0.899;
3260 }else if(driftDist<2.5){
3261 sigma1= 0.065535; sigma2=0.14246; f=0.914;
3262 }else if(driftDist<3.){
3263 sigma1=0.060497; sigma2=0.126489; f=0.918;
3264 }else if(driftDist<3.5){
3265 sigma1=0.057643; sigma2= 0.112927; f=0.892;
3266 }else if(driftDist<4.){
3267 sigma1=0.055266; sigma2=0.094833; f=0.887;
3268 }else if(driftDist<4.5){
3269 sigma1=0.056263; sigma2=0.124419; f= 0.932;
3270 }else if(driftDist<5.){
3271 sigma1=0.056599; sigma2=0.124248; f=0.923;
3272 }else if(driftDist<5.5){
3273 sigma1= 0.061377; sigma2=0.146147; f=0.964;
3274 }else if(driftDist<6.){
3275 sigma1=0.063978; sigma2=0.150591; f=0.942;
3276 }else if(driftDist<6.5){
3277 sigma1=0.072951; sigma2=0.15685; f=0.913;
3278 }else if(driftDist<7.){
3279 sigma1=0.085438; sigma2=0.255109; f=0.931;
3280 }else if(driftDist<7.5){
3281 sigma1=0.101635; sigma2=0.315529; f=0.878;
3282 }else{
3283 sigma1=0.149529; sigma2=0.374697; f=0.89;
3284 }
3285 }
3286 double sigmax = sqrt(f*sigma1*sigma1+(1 - f)*sigma2*sigma2)*0.1;
3287 return sigmax;//cm
3288}
3289
**********INTEGER nmxhep !maximum number of particles DOUBLE PRECISION vhep INTEGER jdahep COMMON hepevt $ !serial number $ !number of particles $ !status code $ !particle ident KF $ !parent particles $ !childreen particles $ !four momentum
const double a_stero[3]
Double_t x[10]
Double_t time
HepGeom::Point3D< double > HepPoint3D
Definition: Gam4pikp.cxx:37
double tan(const BesAngle a)
double sin(const BesAngle a)
double cos(const BesAngle a)
const double M_PI8
Definition: KalFitTrack.cxx:79
const double M_PI2
Definition: KalFitTrack.cxx:73
const double M_PI4
Definition: KalFitTrack.cxx:76
********INTEGER modcns REAL m_C
Definition: PseuMar.h:13
#define M_PI
Definition: TConstant.h:4
virtual double getSigma(int layer, int xvFlag, int readoutMode, double angle, double Q, double T) const =0
virtual StatusCode fieldVector(const HepGeom::Point3D< double > &xyz, HepGeom::Vector3D< double > &fvec) const =0
const int layerId(void) const
returns layer ID
double del_E(double mass, double path, double p) const
Calculate the straggling of energy loss.
double mcs_angle(double mass, double path, double p) const
Calculate Multiple Scattering angle.
double dE(double mass, double path, double p) const
Calculate energy loss.
Description of a track class (<- Helix.cc)
~KalFitTrack(void)
destructor
double chi2_next(Helix &H, KalFitHitMdc &HitMdc, int csmflag)
static int lead(void)
Magnetic field map.
double getDriftTime(KalFitHitMdc &hitmdc, double toftime) const
static double chi2_hitf_
Cut chi2 for each hit.
KalFitTrack(const HepPoint3D &pivot, const CLHEP::HepVector &a, const CLHEP::HepSymMatrix &Ea, unsigned int m, double chiSq, unsigned int nhits)
constructor
static int nmass(void)
double filter(double v_m, const CLHEP::HepVector &m_H, double v_d, double m_V)
static int back(void)
void update_bit(int i)
void order_wirhit(int index)
static int nmdc_hit2_
Cut chi2 for each hit.
double getSigma(int layerId, double driftDist) const
void addTofSM(double time)
void chgmass(int i)
static double factor_strag_
factor of energy loss straggling for electron
const HepPoint3D & pivot_numf(const HepPoint3D &newPivot)
Sets pivot position in a given mag field.
void ms(double path, const KalFitMaterial &m, int index)
static int Tof_correc_
Flag for TOF correction.
void update_forMdc(void)
double intersect_cylinder(double r) const
Intersection with different geometry.
void fiTerm(double fi)
void number_wirhit(void)
static int numf_
Flag for treatment of non-uniform mag field.
void path_add(double path)
Update the path length estimation.
double update_hits_csmalign(KalFitHelixSeg &HelixSeg, int inext, CLHEP::Hep3Vector &meas, int way, double &dchi2, int csmflag)
static int drifttime_choice_
the drifttime choice
double smoother_Mdc(KalFitHelixSeg &seg, CLHEP::Hep3Vector &meas, int &flg, int csmflag)
Kalman smoother for Mdc.
void msgasmdc(double path, int index)
Calculate multiple scattering angle.
void appendHitsMdc(KalFitHitMdc h)
Functions for Mdc hits list.
void addPathSM(double path)
static int resol(void)
void eloss(double path, const KalFitMaterial &m, int index)
Calculate total energy lost in material.
void update_last(void)
Record the current parameters as ..._last information :
static void LR(int x)
double getDriftDist(KalFitHitMdc &hitmdc, double drifttime, int lr) const
double intersect_yz_plane(const HepTransform3D &plane, double x) const
static int numf(void)
double intersect_zx_plane(const HepTransform3D &plane, double y) const
static int numfcor_
NUMF treatment improved.
void order_hits(void)
double intersect_xy_plane(double z) const
double radius_numf(void) const
Estimation of the radius in a given mag field.
double smoother_Mdc_csmalign(KalFitHelixSeg &seg, CLHEP::Hep3Vector &meas, int &flg, int csmflag)
double update_hits(KalFitHitMdc &HitMdc, int inext, CLHEP::Hep3Vector &meas, int way, double &dchi2, double &dtrack, double &dtracknew, double &dtdc, int csmflag)
Include the Mdc wire hits.
static int LR_
Use L/R decision from MdcRecHit information :
static int strag_
Flag to take account of energy loss straggling :
HepPoint3D fwd(void) const
Geometry :
const KalFitLayer_Mdc & layer(void) const
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
void ignoreErrorMatrix(void)
unsets error matrix. Error calculations will be ignored after this function call until an error matri...
const HepSymMatrix & Ea(void) const
returns error matrix.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
double radius(void) const
returns radious of helix.
double dr(void) const
returns an element of parameters.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
IMPLICIT REAL *A H
Definition: myXsection.h:1
int t()
Definition: t.c:1