BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
KalmanKinematicFit.cxx
Go to the documentation of this file.
1#include <cmath>
2#include "VertexFit/KalmanKinematicFit.h"
3#include "VertexFit/KinematicConstraints.h"
4#include "VertexFit/HTrackParameter.h"
5#include "TStopwatch.h"
6#include "TGraph2D.h"
7
8const int KalmanKinematicFit::NTRKPAR = 4;
9const int KalmanKinematicFit::Resonance = 1;
10const int KalmanKinematicFit::TotalEnergy = 2;
11const int KalmanKinematicFit::TotalMomentum = 4;
12const int KalmanKinematicFit::Position = 8;
13const int KalmanKinematicFit::ThreeMomentum = 16;
14const int KalmanKinematicFit::FourMomentum = 32;
15const int KalmanKinematicFit::EqualMass = 64;
16//TGraph2D *g = new TGraph2D("/ihepbatch/bes/yanl/6.5.0//TestRelease/TestRelease-00-00-62/run/gamma/new/graph.dat");
17
18KalmanKinematicFit * KalmanKinematicFit::m_pointer = 0;
19
21 if(m_pointer) return m_pointer;
22 m_pointer = new KalmanKinematicFit();
23 return m_pointer;
24}
25
26KalmanKinematicFit::KalmanKinematicFit(){;}
27
29 // if(m_pointer) delete m_pointer;
30 delete m_pointer;
31}
32
33
38 //gamma shape
44 clearone();
45 cleartwo();
46 setBeamPosition(HepPoint3D(0.0,0.0,0.0));
47 setVBeamPosition(HepSymMatrix(3,0));
48 //=============
49 m_kc.clear();
50 m_chisq.clear();
51 m_chi = 9999.;
52 m_niter = 10;
53 m_chicut = 200.;
54 m_chiter = 0.005;
55 m_espread = 0.0;
56 m_collideangle = 11e-3;
57 m_flag = 0;
58 m_dynamicerror = 0;
59 m_nc = 0;
60 m_cpu = HepVector(10, 0);
61 m_virtual_wtrk.clear();
62 m_graph2d = 0;
63 // m_graph2d = TGraph2D("/ihepbatch/bes/yanl/6.5.0//TestRelease/TestRelease-00-00-62/run/gamma/new/graph.dat");
64}
65
66
67//
68// Add Resonance
69//
70
71void KalmanKinematicFit::AddResonance(int number, double mres, int n1) {
72 std::vector<int> tlis = AddList(n1);
73 AddResonance(number, mres, tlis);
74}
75
76void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2) {
77 std::vector<int> tlis = AddList(n1, n2);
78 AddResonance(number, mres, tlis);
79}
80
81void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2, int n3) {
82 std::vector<int> tlis = AddList(n1, n2, n3);
83 AddResonance(number, mres, tlis);
84}
85
86void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2, int n3, int n4) {
87 std::vector<int> tlis = AddList(n1, n2, n3, n4);
88 AddResonance(number, mres, tlis);
89}
90
91void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2, int n3, int n4,
92 int n5) {
93 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5);
94 AddResonance(number, mres, tlis);
95}
96
97void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2, int n3, int n4,
98 int n5, int n6) {
99 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6);
100 AddResonance(number, mres, tlis);
101}
102
103void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2, int n3, int n4,
104 int n5, int n6, int n7) {
105 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7);
106 AddResonance(number, mres, tlis);
107}
108
109void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2, int n3, int n4,
110 int n5, int n6, int n7, int n8) {
111 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8);
112 AddResonance(number, mres, tlis);
113}
114
115void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2, int n3, int n4,
116 int n5, int n6, int n7, int n8, int n9) {
117 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9);
118 AddResonance(number, mres, tlis);
119}
120
121void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2, int n3, int n4,
122 int n5, int n6, int n7, int n8, int n9, int n10) {
123 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10);
124 AddResonance(number, mres, tlis);
125}
126
127
128void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2, int n3, int n4,
129 int n5, int n6, int n7, int n8, int n9,
130 int n10, int n11) {
131 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11);
132 AddResonance(number, mres, tlis);
133}
134
135void KalmanKinematicFit::AddResonance(int number, double mres, int n1, int n2, int n3, int n4,
136 int n5, int n6, int n7, int n8, int n9,
137 int n10, int n11, int n12) {
138 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12);
139 AddResonance(number, mres, tlis);
140}
141
142void KalmanKinematicFit::AddResonance(int number, double mres, std::vector<int> tlis) {
144 HepSymMatrix Vre = HepSymMatrix(1,0);
145 kc.ResonanceConstraints(mres, tlis, Vre);
146 m_kc.push_back(kc);
147 if((unsigned int) number != m_kc.size()-1)
148 std::cout << "wrong kinematic constraints index" << std::endl;
149}
150
151
152//
153// Add TotalMomentum
154//
155
156void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1) {
157 std::vector<int> tlis = AddList(n1);
158 AddTotalMomentum(number, ptot, tlis);
159}
160void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2) {
161 std::vector<int> tlis = AddList(n1, n2);
162 AddTotalMomentum(number, ptot, tlis);
163}
164
165void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2, int n3) {
166 std::vector<int> tlis = AddList(n1, n2, n3);
167 AddTotalMomentum(number, ptot, tlis);
168}
169
170void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2, int n3, int n4) {
171 std::vector<int> tlis = AddList(n1, n2, n3, n4);
172 AddTotalMomentum(number, ptot, tlis);
173}
174
175void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2, int n3, int n4,
176 int n5) {
177 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5);
178 AddTotalMomentum(number, ptot, tlis);
179}
180
181void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2, int n3, int n4,
182 int n5, int n6) {
183 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6);
184 AddTotalMomentum(number, ptot, tlis);
185}
186
187void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2, int n3, int n4,
188 int n5, int n6, int n7) {
189 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7);
190 AddTotalMomentum(number, ptot, tlis);
191}
192
193void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2, int n3, int n4,
194 int n5, int n6, int n7, int n8) {
195 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8);
196 AddTotalMomentum(number, ptot, tlis);
197}
198
199void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2, int n3, int n4,
200 int n5, int n6, int n7, int n8, int n9) {
201 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9);
202 AddTotalMomentum(number, ptot, tlis);
203}
204
205void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2, int n3, int n4,
206 int n5, int n6, int n7, int n8, int n9,
207 int n10) {
208 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10);
209 AddTotalMomentum(number, ptot, tlis);
210}
211
212
213void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2, int n3, int n4,
214 int n5, int n6, int n7, int n8, int n9,
215 int n10, int n11) {
216 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11);
217 AddTotalMomentum(number, ptot, tlis);
218}
219
220void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, int n1, int n2, int n3, int n4,
221 int n5, int n6, int n7, int n8, int n9,
222 int n10, int n11, int n12) {
223 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12);
224 AddTotalMomentum(number, ptot, tlis);
225}
226
227void KalmanKinematicFit::AddTotalMomentum(int number, double ptot, std::vector<int> tlis) {
229 kc.TotalMomentumConstraints(ptot, tlis);
230 m_kc.push_back(kc);
231 if((unsigned int) number != m_kc.size()-1)
232 std::cout << "wrong kinematic constraints index" << std::endl;
233}
234
235//
236// Add TotalEnergy
237//
238
239void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1) {
240 std::vector<int> tlis = AddList(n1);
241 AddTotalEnergy(number, etot, tlis);
242}
243void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2) {
244 std::vector<int> tlis = AddList(n1, n2);
245 AddTotalEnergy(number, etot, tlis);
246}
247
248void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2, int n3) {
249 std::vector<int> tlis = AddList(n1, n2, n3);
250 AddTotalEnergy(number, etot, tlis);
251}
252
253void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2, int n3, int n4) {
254 std::vector<int> tlis = AddList(n1, n2, n3, n4);
255 AddTotalEnergy(number, etot, tlis);
256}
257
258void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2, int n3, int n4,
259 int n5) {
260 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5);
261 AddTotalEnergy(number, etot, tlis);
262}
263
264void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2, int n3, int n4,
265 int n5, int n6) {
266 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6);
267 AddTotalEnergy(number, etot, tlis);
268}
269
270void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2, int n3, int n4,
271 int n5, int n6, int n7) {
272 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7);
273 AddTotalEnergy(number, etot, tlis);
274}
275
276void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2, int n3, int n4,
277 int n5, int n6, int n7, int n8) {
278 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8);
279 AddTotalEnergy(number, etot, tlis);
280}
281
282void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2, int n3, int n4,
283 int n5, int n6, int n7, int n8, int n9) {
284 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9);
285 AddTotalEnergy(number, etot, tlis);
286}
287
288void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2, int n3, int n4,
289 int n5, int n6, int n7, int n8, int n9,
290 int n10) {
291 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10);
292 AddTotalEnergy(number, etot, tlis);
293}
294
295
296void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2, int n3, int n4,
297 int n5, int n6, int n7, int n8, int n9,
298 int n10, int n11) {
299 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11);
300 AddTotalEnergy(number, etot, tlis);
301}
302
303void KalmanKinematicFit::AddTotalEnergy(int number, double etot, int n1, int n2, int n3, int n4,
304 int n5, int n6, int n7, int n8, int n9,
305 int n10, int n11, int n12) {
306 std::vector<int> tlis = AddList(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12);
307 AddTotalEnergy(number, etot, tlis);
308}
309
310void KalmanKinematicFit::AddTotalEnergy(int number, double etot, std::vector<int> tlis) {
313 m_kc.push_back(kc);
314 if((unsigned int) number != m_kc.size()-1)
315 std::cout << "wrong kinematic constraints index" << std::endl;
316}
317//
318// Equal Mass constraints
319//
320
321void KalmanKinematicFit::AddEqualMass(int number, std::vector<int> tlis1, std::vector<int> tlis2) {
323 HepSymMatrix Vne = HepSymMatrix(1,0);
324 kc.EqualMassConstraints(tlis1, tlis2, Vne);
325 m_kc.push_back(kc);
326 if((unsigned int) number != m_kc.size()-1)
327 std::cout << "wrong kinematic constraints index" << std::endl;
328}
329
330//
331// Total 3-momentum constraints
332//
333
334void KalmanKinematicFit::AddThreeMomentum(int number, Hep3Vector p3) {
335 std::vector<int> tlis;
336 tlis.clear();
337 WTrackParameter wtrk;
339
340 for(int i = 0; i < numberWTrack(); i++) {
341 tlis.push_back(i);
342 }
343 kc.ThreeMomentumConstraints(p3, tlis);
344 m_kc.push_back(kc);
345 if((unsigned int) number != m_kc.size()-1)
346 std::cout << "wrong kinematic constraints index" << std::endl;
347}
348
349//
350// Total 4-momentum constraints
351//
352
353void KalmanKinematicFit::AddFourMomentum(int number, HepLorentzVector p4) {
354
355 std::vector<int> tlis;
356 tlis.clear();
358
359 for(int i = 0; i < numberWTrack(); i++) {
360 tlis.push_back(i);
361 }
362
363 HepSymMatrix Vme = HepSymMatrix(4,0);
364 Vme[0][0] = 2*m_espread*m_espread*sin(m_collideangle)*sin(m_collideangle);
365 Vme[0][3] = 2*m_espread*m_espread*sin(m_collideangle);
366 Vme[3][3] = 2*m_espread*m_espread;
367
368 kc.FourMomentumConstraints(p4, tlis, Vme);
369 m_kc.push_back(kc);
370 if((unsigned int) number != m_kc.size()-1)
371 std::cout << "wrong kinematic constraints index" << std::endl;
372}
373
375
376 HepLorentzVector p4(0.0, 0.0, 0.0, etot);
377 std::vector<int> tlis;
378 tlis.clear();
380
381 for(int i = 0; i < numberWTrack(); i++) {
382 tlis.push_back(i);
383 }
384 HepSymMatrix Vme = HepSymMatrix (4,0);
385 Vme[3][3] = 2*m_espread*m_espread;
386 kc.FourMomentumConstraints(p4, tlis, Vme);
387 m_kc.push_back(kc);
388 if((unsigned int) number != m_kc.size()-1)
389 std::cout << "wrong kinematic constraints index" << std::endl;
390}
391
392
393void KalmanKinematicFit::fit() {
394
395
397 int nc = m_nc;
398 int ntrk = numberWTrack();
399
400 TStopwatch timer;
401
402
403
404 timer.Start();
405 //cout<<" =====calculate AC_{0}A^{T}====="<<endl;
406 HepSymMatrix AC(m_nc, 0);
407 AC = m_C0.similarity(m_A);
408 timer.Stop();
409 m_cpu[1] += timer.CpuTime();
410
411 timer.Start();
412 //cout<<" =====calculate W====="<<endl;
413 int ifail;
414 m_W = HepSymMatrix(m_nc, 0);
415 m_W = (m_Vm + m_C0.similarity(m_A)).inverse(ifail);
416 //cout<<" =====calculate D , D^{-1}====="<<endl;
417 int ifailD;
418 m_Dinv = m_D0inv + m_W.similarity(m_B.T());
419 m_D = m_Dinv.inverse(ifailD);
420 timer.Stop();
421 m_cpu[2] += timer.CpuTime();
422
423 timer.Start();
424 //cout<<"===== G equals r ====="<<endl;
425 HepVector G(m_nc, 0);
426 G = m_A * (m_p0 - m_p) + m_B * (m_q0 - m_q)+ m_G;
427 //cout<<"===== calculate KQ, Kp======"<<endl;
428 m_KQ = HepMatrix(numbertwo(), m_nc, 0);
429 m_KQ = m_D * m_BT * m_W;
430
431 m_KP = HepMatrix(numberone(), m_nc, 0);
432 m_KP = m_C0 * m_AT * m_W - m_C0 * m_AT * m_W * m_B * m_KQ;
433 // ===== update track par =====
434 m_p = m_p0 - m_KP * G;
435 m_q = m_q0 - m_KQ * G;
436 timer.Stop();
437 m_cpu[4] += timer.CpuTime();
438
439 timer.Start();
440 //===== caluculate chi2 =====
441 m_chi = (m_W.similarity(G.T()) - m_Dinv.similarity((m_q - m_q0).T()))[0][0];
442 timer.Stop();
443 m_cpu[3] += timer.CpuTime();
444 timer.Start();
445 if(m_dynamicerror ==1)
446 gda();
447
448 timer.Stop();
449 m_cpu[6] += timer.CpuTime();
450
451}
452
453
454
455
456void KalmanKinematicFit::upCovmtx() {
457 HepMatrix E(numberone(), numbertwo(), 0);
458 E = -m_C0 * m_A.T() * m_KQ.T();
459 m_C = m_C0 - m_W.similarity((m_A*m_C0).T()) + m_Dinv.similarity(E);
460}
461
462
463
464
465
466void KalmanKinematicFit::fit(int n) {
467 if(m_chisq.size() == 0) {
468 for(unsigned int i = 0; i < m_kc.size(); i++)
469 m_chisq.push_back(9999.0);
470 }
471
473 int nc = m_nc;
474 int ntrk = numberWTrack();
475
476 //cout<<" =====calculate AC_{0}A^{T}====="<<endl;
477 HepSymMatrix AC(m_nc, 0);
478 AC = m_C0.similarity(m_A);
479
480 //cout<<" =====calculate W====="<<endl;
481 int ifail;
482 m_W = HepSymMatrix(m_nc, 0);
483 m_W = (m_Vm + m_C0.similarity(m_A)).inverse(ifail);
484 //cout<<" =====calculate D , D^{-1}====="<<endl;
485 int ifailD;
486 m_Dinv = m_D0inv + m_W.similarity(m_B.T());
487 m_D = m_Dinv.inverse(ifailD);
488
489 //cout<<"===== G equals r ====="<<endl;
490 HepVector G(m_nc, 0);
491 G = m_A * (m_p0 - m_p) + m_B * (m_q0 - m_q)+ m_G;
492 //cout<<"===== calculate KQ, Kp======"<<endl;
493 m_KQ = HepMatrix(numbertwo(), m_nc, 0);
494 m_KQ = m_D * m_BT * m_W;
495
496 m_KP = HepMatrix(numberone(), m_nc, 0);
497 m_KP = m_C0 * m_AT * m_W - m_C0 * m_AT * m_W * m_B * m_KQ;
498 // ===== update track par =====
499 m_p = m_p0 - m_KP * G;
500 m_q = m_q0 - m_KQ * G;
501
502 //===== caluculate chi2 =====
503 m_chisq[n] = (m_W.similarity(G.T()) - m_Dinv.similarity((m_q - m_q0).T()))[0][0];
504 if(m_dynamicerror ==1)
505 gda();
506}
507
508
509
510
511
512
513
514
516 bool okfit = false;
517 TStopwatch timer;
518 m_nktrk = numberWTrack();
519 m_p0 = HepVector(numberone(), 0);
520 m_p = HepVector(numberone(), 0);
521 m_q0 = HepVector(numbertwo(), 0);
522 m_q = HepVector(numbertwo(), 0);
523 m_C0 = HepSymMatrix(numberone(), 0);
524 m_C = HepSymMatrix(numberone(), 0);
525 m_D0inv = HepSymMatrix(numbertwo(), 0);
526 m_D = HepSymMatrix(numbertwo(), 0);
527
528 HepVector m_p_tmp = HepVector(numberone(), 0);
529 HepVector m_q_tmp = HepVector(numbertwo(), 0);
530 HepMatrix m_A_tmp;
531 HepSymMatrix m_W_tmp;
532 HepMatrix m_KQ_tmp;
533 HepSymMatrix m_Dinv_tmp;
534 for(int i = 0; i < numberWTrack(); i++) {
536 int pa = mappositionA()[i] + 1;
537 int pb = mappositionB()[i] + 1;
538 int ptype = mapkinematic()[i];
539 switch(ptype) {
540 case 0 : {
541 HepVector w1(4, 0);
542 HepSymMatrix Ew1(4, 0);
543 for(int j = 0; j < 3; j++) {
544 w1[j] = wTrackOrigin(i).w()[j];
545 }
546 w1[3] = wTrackOrigin(i).mass();
547
548 for(int m = 0; m < 3; m++) {
549 for(int n = 0; n < 3; n++) {
550 Ew1[m][n] = wTrackOrigin(i).Ew()[m][n];
551 }
552 }
553 setPOrigin(pa, w1);
554 setPInfit(pa, w1);
555 setCOrigin(pa, Ew1);
556 break;
557 }
558 case 1 : {
559 setPOrigin(pa, (wTrackOrigin(i).plmp()).sub(1, 4));
560 setPInfit(pa, (wTrackOrigin(i).plmp()).sub(1, 4));
561 setCOrigin(pa, (wTrackOrigin(i).Vplm()).sub(1, 4));
562 break;
563 }
564 case 2 : {
565 setQOrigin(pb, (wTrackOrigin(i).w()).sub(1, NTRKPAR));
566 setQInfit(pb, (wTrackOrigin(i).w()).sub(1, NTRKPAR));
567 HepSymMatrix Dinv(4,0);
568 setDOriginInv(pb, Dinv);
569 break;
570 }
571 case 3 : {
572 setPOrigin(pa, (wTrackOrigin(i).plmp()).sub(3, 3));
573 setPInfit(pa, (wTrackOrigin(i).plmp()).sub(3, 3));
574 setCOrigin(pa, (wTrackOrigin(i).Vplm()).sub(3, 3));
575 setQOrigin(pb, (wTrackOrigin(i).plmp()).sub(1, 2));
576 setQInfit(pb, (wTrackOrigin(i).plmp()).sub(1, 2));
577 setQOrigin(pb+2, (wTrackOrigin(i).plmp()).sub(4, 4));
578 setQInfit(pb+2, (wTrackOrigin(i).plmp()).sub(4, 4));
579 HepSymMatrix Dinv(3,0);
580 setDOriginInv(pb, Dinv);
581 break;
582 }
583 case 4 : {
584 setPOrigin(pa, (wTrackOrigin(i).plmp()).sub(1, 2));
585 setPInfit(pa, (wTrackOrigin(i).plmp()).sub(1, 2));
586 setCOrigin(pa, (wTrackOrigin(i).Vplm()).sub(1, 2));
587 setQOrigin(pb, (wTrackOrigin(i).plmp()).sub(3, 4));
588 setQInfit(pb, (wTrackOrigin(i).plmp()).sub(3, 4));
589 HepSymMatrix Dinv(2,0);
590 setDOriginInv(pb, Dinv);
591 break;
592 }
593 case 5 : {
594 setPOrigin(pa, (wTrackOrigin(i).plmp()).sub(1, 3));
595 setPInfit(pa, (wTrackOrigin(i).plmp()).sub(1, 3));
596 setCOrigin(pa, (wTrackOrigin(i).Vplm()).sub(1, 3));
597 setQOrigin(pb, (wTrackOrigin(i).plmp()).sub(4, 4));
598 setQInfit(pb, (wTrackOrigin(i).plmp()).sub(4, 4));
599 HepSymMatrix Dinv(1,0);
600 setDOriginInv(pb, Dinv);
601 break;
602 }
603 case 6 : {
604 setPOrigin(pa, (wTrackOrigin(i).w()).sub(5, 7));
605 setPOrigin(pa+3, (wTrackOrigin(i).w()).sub(4, 4));
606 setPInfit(pa, (wTrackOrigin(i).w()).sub(5, 7));
607 setPInfit(pa+3, (wTrackOrigin(i).w()).sub(4, 4));
608 setCOrigin(pa, (wTrackOrigin(i).Ew()).sub(5,7));
609 setCOrigin(pa+3, (wTrackOrigin(i).Ew()).sub(4,4));
610 HepVector beam(3,0);
611 beam[0] = getBeamPosition().x();
612 beam[1] = getBeamPosition().y();
613 beam[2] = getBeamPosition().z();
614 setQOrigin(pb, beam);
615 setQInfit(pb, beam);
616 HepSymMatrix Dinv(3, 0);
617 int ifail;
618 Dinv = getVBeamPosition().inverse(ifail);
619 setDOriginInv(pb, Dinv);
620 break;
621 }
622 case 7 : {
623 HepVector w1(4, 0);
624 HepSymMatrix Ew1(4, 0);
625 for(int j = 0; j < 3; j++) {
626 w1[j] = wTrackOrigin(i).w()[j];
627 }
628 w1[3] = wTrackOrigin(i).mass();
629
630 for(int m = 0; m < 3; m++) {
631 for(int n = 0; n < 3; n++) {
632 Ew1[m][n] = wTrackOrigin(i).Ew()[m][n];
633 }
634 }
635 setPOrigin(pa, w1);
636 setPInfit(pa, w1);
637 setCOrigin(pa, Ew1);
638 break;
639 }
640
641 }
642 }
643
644
645 //
646 // iteration
647 //
648
649 std::vector<double> chisq;
650 chisq.clear();
651 int nc = 0;
652 for(int i = 0; i < m_kc.size(); i++)
653 nc += m_kc[i].nc();
654
655 m_A = HepMatrix(nc, numberone(), 0);
656 m_AT = HepMatrix(numberone(), nc, 0);
657 m_B = HepMatrix(nc, numbertwo(), 0);
658 m_BT = HepMatrix(numbertwo(), nc, 0);
659 m_G = HepVector(nc, 0);
660 m_Vm = HepSymMatrix(nc, 0);
661 int num1 = 0;
662 for(unsigned int i = 0; i < m_kc.size(); i++) {
663 KinematicConstraints kc = m_kc[i];
664 m_Vm.sub(num1+1,kc.Vmeasure());
665 num1 = num1 + kc.nc();
666 }
667
668 double tmp_chisq = 999;
669 bool flag_break = 0;
670 for(int it = 0; it < m_niter; it++) {
671 timer.Start();
672 m_nc = 0;
673 for(unsigned int i = 0; i < m_kc.size(); i++) {
674 KinematicConstraints kc = m_kc[i];
675 updateConstraints(kc);
676 }
677 timer.Stop();
678 m_cpu[0] += timer.CpuTime();
679 fit();
680 //
681 //reset origin parameters for virtual particle
682 //
683 // if(it == 0){
684 // for(int i = 0; i < numberWTrack(); i++) {
685 // // setWTrackInfit(i, wTrackOrigin(i));
686 // int pa = mappositionA()[i] + 1;
687 // int pb = mappositionB()[i] + 1;
688 // int ptype = mapkinematic()[i];
689 // switch(ptype) {
690 // case 3 : {
691 // setPOrigin(pa, m_p.sub(pa, pa));
692 // setPInfit(pa, m_p.sub(pa, pa));
693 // setQOrigin(pb, m_q.sub(pb, pb+2));
694 // setQInfit(pb, m_q.sub(pb, pb+2));
695 // break;
696 // }
697 // case 4 : {
698 // setPOrigin(pa, (wTrackOrigin(i).plmp()).sub(1, 2));
699 // setPInfit(pa, (wTrackOrigin(i).plmp()).sub(1, 2));
700 // setCOrigin(pa, (wTrackOrigin(i).Vplm()).sub(1, 2));
701 // setQOrigin(pb, (wTrackOrigin(i).plmp()).sub(3, 4));
702 // setQInfit(pb, (wTrackOrigin(i).plmp()).sub(3, 4));
703 // HepSymMatrix Dinv(2,0);
704 // setDOriginInv(pb, Dinv);
705 // break;
706 // }
707 // case 5 : {
708 // setPOrigin(pa, (wTrackOrigin(i).plmp()).sub(1, 3));
709 // setPInfit(pa, (wTrackOrigin(i).plmp()).sub(1, 3));
710 // setCOrigin(pa, (wTrackOrigin(i).Vplm()).sub(1, 3));
711 // setQOrigin(pb, (wTrackOrigin(i).plmp()).sub(4, 4));
712 // setQInfit(pb, (wTrackOrigin(i).plmp()).sub(4, 4));
713 // HepSymMatrix Dinv(1,0);
714 // setDOriginInv(pb, Dinv);
715 // break;
716 // }
717 // case 6 : {
718 // setPOrigin(pa, (wTrackOrigin(i).w()).sub(5, 7));
719 // setPOrigin(pa+3, (wTrackOrigin(i).w()).sub(4, 4));
720 // setPInfit(pa, (wTrackOrigin(i).w()).sub(5, 7));
721 // setPInfit(pa+3, (wTrackOrigin(i).w()).sub(4, 4));
722 // setCOrigin(pa, (wTrackOrigin(i).Ew()).sub(5,7));
723 // setCOrigin(pa+3, (wTrackOrigin(i).Ew()).sub(4,4));
724 // HepVector beam(3,0);
725 // beam[0] = getBeamPosition().x();
726 // beam[1] = getBeamPosition().y();
727 // beam[2] = getBeamPosition().z();
728 // setQOrigin(pb, beam);
729 // setQInfit(pb, beam);
730 // HepSymMatrix Dinv(3, 0);
731 // int ifail;
732 // Dinv = getVBeamPosition().inverse(ifail);
733 // setDOriginInv(pb, Dinv);
734 // break;
735 // }
736 //
737 // }
738 // }
739 //
740 // }
741 //
742 //
743 //===================reset over=============================
744 //
745 chisq.push_back(m_chi);
746 if(it > 0) {
747 double delchi = chisq[it]- chisq[it-1];
748 if(fabs(delchi) < m_chiter){
749 flag_break =1;
750 break;
751 }
752 }
753 }
754 if(!flag_break) {
755 return okfit;
756 }
757 if(m_chi > m_chicut) return okfit;
758 timer.Start();
759 timer.Stop();
760 m_cpu[5] += timer.CpuTime();
761 okfit = true;
762 return okfit;
763
764}
765
766
768 bool okfit = false;
769 if(n < 0 || (unsigned int)n >= m_kc.size()) return okfit;
770 m_nktrk = numberWTrack();
771 m_p0 = HepVector(numberone(), 0);
772 m_p = HepVector(numberone(), 0);
773 m_q0 = HepVector(numbertwo(), 0);
774 m_q = HepVector(numbertwo(), 0);
775 m_C0 = HepSymMatrix(numberone(), 0);
776 m_C = HepSymMatrix(numberone(), 0);
777 m_D0inv = HepSymMatrix(numbertwo(), 0);
778 m_D = HepSymMatrix(numbertwo(), 0);
779
780 for(int i = 0; i < numberWTrack(); i++) {
782 int pa = mappositionA()[i] + 1;
783 int pb = mappositionB()[i] + 1;
784 int ptype = mapkinematic()[i];
785 switch(ptype) {
786 case 0 : {
787 HepVector w1(4, 0);
788 HepSymMatrix Ew1(4, 0);
789 for(int j = 0; j < 3; j++) {
790 w1[j] = wTrackOrigin(i).w()[j];
791 }
792 w1[3] = wTrackOrigin(i).mass();
793
794 for(int m = 0; m < 3; m++) {
795 for(int n = 0; n < 3; n++) {
796 Ew1[m][n] = wTrackOrigin(i).Ew()[m][n];
797 }
798 }
799 setPOrigin(pa, w1);
800 setPInfit(pa, w1);
801 setCOrigin(pa, Ew1);
802 break;
803 }
804 case 1 : {
805 setPOrigin(pa, (wTrackOrigin(i).plmp()).sub(1, 4));
806 setPInfit(pa, (wTrackOrigin(i).plmp()).sub(1, 4));
807 setCOrigin(pa, (wTrackOrigin(i).Vplm()).sub(1, 4));
808 break;
809 }
810 case 2 : {
811 setQOrigin(pb, (wTrackOrigin(i).w()).sub(1, NTRKPAR));
812 setQInfit(pb, (wTrackOrigin(i).w()).sub(1, NTRKPAR));
813 HepSymMatrix Dinv(4,0);
814 setDOriginInv(pb, Dinv);
815 break;
816 }
817 case 3 : {
818 setPOrigin(pa, (wTrackOrigin(i).plmp()).sub(3, 3));
819 setPInfit(pa, (wTrackOrigin(i).plmp()).sub(3, 3));
820 setCOrigin(pa, (wTrackOrigin(i).Vplm()).sub(3, 3));
821 setQOrigin(pb, (wTrackOrigin(i).w()).sub(1, 3));
822 setQInfit(pb, (wTrackOrigin(i).w()).sub(1, 3));
823 HepSymMatrix Dinv(3,0);
824 setDOriginInv(pb, Dinv);
825 break;
826 }
827 case 4 : {
828 setPOrigin(pa, (wTrackOrigin(i).plmp()).sub(1, 2));
829 setPInfit(pa, (wTrackOrigin(i).plmp()).sub(1, 2));
830 setCOrigin(pa, (wTrackOrigin(i).Vplm()).sub(1, 2));
831 setQOrigin(pb, (wTrackOrigin(i).plmp()).sub(3, 4));
832 setQInfit(pb, (wTrackOrigin(i).plmp()).sub(3, 4));
833 HepSymMatrix Dinv(2,0);
834 setDOriginInv(pb, Dinv);
835 break;
836 }
837 case 5 : {
838 setPOrigin(pa, (wTrackOrigin(i).plmp()).sub(1, 3));
839 setPInfit(pa, (wTrackOrigin(i).plmp()).sub(1, 3));
840 setCOrigin(pa, (wTrackOrigin(i).Vplm()).sub(1, 3));
841 setQOrigin(pb, (wTrackOrigin(i).plmp()).sub(4, 4));
842 setQInfit(pb, (wTrackOrigin(i).plmp()).sub(4, 4));
843 HepSymMatrix Dinv(1,0);
844 setDOriginInv(pb, Dinv);
845 break;
846 }
847 case 6 : {
848 setPOrigin(pa, (wTrackOrigin(i).w()).sub(5, 7));
849 setPOrigin(pa+3, (wTrackOrigin(i).w()).sub(4, 4));
850 setPInfit(pa, (wTrackOrigin(i).w()).sub(5, 7));
851 setPInfit(pa+3, (wTrackOrigin(i).w()).sub(4, 4));
852 setCOrigin(pa, (wTrackOrigin(i).Ew()).sub(5,7));
853 setCOrigin(pa+3, (wTrackOrigin(i).Ew()).sub(4,4));
854 HepVector beam(3,0);
855 beam[0] = getBeamPosition().x();
856 beam[1] = getBeamPosition().y();
857 beam[2] = getBeamPosition().z();
858 setQOrigin(pb, beam);
859 setQInfit(pb, beam);
860 HepSymMatrix Dinv(3, 0);
861 int ifail;
862 Dinv = getVBeamPosition().inverse(ifail);
863
864 setDOriginInv(pb, Dinv);
865 break;
866 }
867
868 case 7 : {
869 HepVector w1(4, 0);
870 HepSymMatrix Ew1(4, 0);
871 for(int j = 0; j < 3; j++) {
872 w1[j] = wTrackOrigin(i).w()[j];
873 }
874 w1[3] = wTrackOrigin(i).mass();
875
876 for(int m = 0; m < 3; m++) {
877 for(int n = 0; n < 3; n++) {
878 Ew1[m][n] = wTrackOrigin(i).Ew()[m][n];
879 }
880 }
881 setPOrigin(pa, w1);
882 setPInfit(pa, w1);
883 setCOrigin(pa, Ew1);
884 break;
885 }
886 }
887 }
888
889
890
891 //
892 // iteration
893 //
894
895 std::vector<double> chisq;
896 chisq.clear();
897 int nc = 0;
898 // for(int i = 0; i < m_kc.size(); i++)
899 nc += m_kc[n].nc();
900
901 m_A = HepMatrix(nc, numberone(), 0);
902 m_AT = HepMatrix(numberone(), nc, 0);
903 m_B = HepMatrix(nc, numbertwo(), 0);
904 m_BT = HepMatrix(numbertwo(), nc, 0);
905 m_G = HepVector(nc, 0);
906 m_Vm = HepSymMatrix(nc, 0);
907 int num1 = 0;
908 KinematicConstraints kc = m_kc[n];
909 m_Vm.sub(num1+1,kc.Vmeasure());
910 num1 = kc.nc();
911 for(int it = 0; it < m_niter; it++) {
912 m_nc = 0;
913 KinematicConstraints kc = m_kc[n];
914 updateConstraints(kc);
915 fit(n);
916
917 chisq.push_back(m_chisq[n]);
918
919 if(it > 0) {
920
921 double delchi = chisq[it]- chisq[it-1];
922 if(fabs(delchi) < m_chiter)
923 break;
924 }
925 }
926 if(m_chisq[n] >= m_chicut) {
927 return okfit;
928 }
929 //update track parameter and its covariance matrix
930 //upCovmtx();
931
932 okfit = true;
933
934
935 return okfit;
936
937}
938
939
940
941
942
944 upCovmtx();
945 KinematicConstraints kc = m_kc[n];
946 int ntrk = (kc.Ltrk()).size();
947 int charge = 0;
948 HepVector w(7, 0);
949 HepSymMatrix ew1(7, 0);
950 HepSymMatrix ew2(7, 0);
951 HepVector w4(4, 0);
952 HepSymMatrix ew4(4, 0);
953 HepMatrix dwdp(4, 4, 0);
954 dwdp[0][0] = 1;
955 dwdp[1][1] = 1;
956 dwdp[2][2] = 1;
957 dwdp[3][3] = 1;
958 for (int i = 0; i < ntrk; i++) {
959 int itk = (kc.Ltrk())[i];
960 charge += wTrackInfit(itk).charge();
961 w4 = w4 + dwdp * pInfit(itk);
962 // ew = ew + (getCInfit(itk)).similarity(dwdp);
963 }
964 HepMatrix I(4, numberone(), 0);
965 for(int j2=0; j2<ntrk; j2++){
966 I[0][0+j2*4] = 1;
967 I[1][1+j2*4] = 1;
968 I[2][2+j2*4] = 1;
969 I[3][3+j2*4] = 1;
970 }
971 ew4 = m_C.similarity(I);
972 HepMatrix J(7,4,0);
973 double px = w4[0];
974 double py = w4[1];
975 double pz = w4[2];
976 double e = w4[3];
977 double pt = sqrt(px*px + py*py);
978 double p0 = sqrt(px*px + py*py + pz*pz);
979 double m = sqrt(e*e - p0*p0);
980 J[0][0] = -py;
981 J[0][1] = -(pz*px*pt)/(p0*p0);
982 J[0][2] = -m*px/(p0*p0);
983 J[0][3] = e*px/(p0*p0);
984 J[1][0] = px;
985 J[1][1] = -(pz*py*pt)/(p0*p0);
986 J[1][2] = -m*py/(p0*p0);
987 J[1][3] = e*py/(p0*p0);
988 J[2][0] = 0;
989 J[2][1] = pt*pt*pt/(p0*p0);
990 J[2][2] = -m*pz/(p0*p0);
991 J[2][3] = e*pz/(p0*p0);
992 J[3][0] = 0;
993 J[3][1] = 0;
994 J[3][2] = 0;
995 J[3][3] = 1;
996 ew1 = ew4.similarity(J);
997 ew2[0][0] = ew1[0][0];
998 ew2[1][1] = ew1[1][1];
999 ew2[2][2] = ew1[2][2];
1000 ew2[3][3] = ew1[3][3];
1001 w[0] = w4[0];
1002 w[1] = w4[1];
1003 w[2] = w4[2];
1004 w[3] = w4[3];
1005 WTrackParameter vwtrk;
1006 vwtrk.setCharge(charge);
1007 vwtrk.setW(w);
1008 vwtrk.setEw(ew2);
1009 vwtrk.setMass(m);
1010 m_virtual_wtrk.push_back(vwtrk);
1011}
1012
1013
1014
1015void KalmanKinematicFit::gda(){
1016 // TGraph2D *g = new TGraph2D("/ihepbatch/bes/yanl/6.5.0//TestRelease/TestRelease-00-00-62/run/gamma/new/graph.dat");
1017 for(int i = 0; i < numberWTrack(); i++) {
1018 if ((wTrackOrigin(i)).type() == 2 ){
1019 int n ;
1020 for(int j = 0; j < numberGammaShape(); j++) {
1021 if(i==GammaShapeList(j)) n = j;
1022 }
1023 int pa = mappositionA()[i] + 1;
1024 int pb = mappositionB()[i] + 1;
1025 int ptype = mapkinematic()[i];
1026 HepSymMatrix Ew(NTRKPAR, 0);
1027 HepLorentzVector p1 = p4Infit(i);
1028 HepLorentzVector p2 = p4Origin(i);
1029 double eorigin = pOrigin(i)[3];
1030 HepMatrix dwda1(NTRKPAR, 3, 0);
1031 dwda1[0][0] = 1;
1032 dwda1[1][1] = - (p2.e()*p2.e())/(p2.px()*p2.px() + p2.py()*p2.py());
1033 // dwda1[1][1] = - (p1.e()*p1.e())/(p1.px()*p1.px() + p1.py()*p1.py());
1034 dwda1[3][2] = 1;
1035 HepSymMatrix emcmea1(3, 0);
1036 double pk = p1[3];
1037 // double pk = GammaShapeValue(n).peak(p1[3]);
1038 emcmea1[0][0] = GammaShapeValue(n).getdphi() * GammaShapeValue(n).getdphi();
1039 emcmea1[1][1] = GammaShapeValue(n).getdthe() * GammaShapeValue(n).getdthe()*(1/(1 - p2.cosTheta()*p2.cosTheta())) *(1/(1 - p2.cosTheta()*p2.cosTheta()));
1040 // cout<<"delta lambda ="<<emcmea1[1][1]<<endl;
1041 emcmea1[2][2] = GammaShapeValue(n).de(eorigin,pk)*GammaShapeValue(n).de(eorigin,pk);
1042 // double tmp_e22 = m_graph2d->Interpolate(eorigin, pk);
1043 // if(fabs((eorigin/pk)-1)<0.05&&tmp_e22==0)emcmea1[2][2] = 0.025*pk*0.025;
1044 // else emcmea1[2][2] = (tmp_e22*tmp_e22);
1045 // emcmea1[2][2] = m_graph2d->Interpolate(eorigin, pk)*m_graph2d->Interpolate(eorigin, pk);
1046 // emcmea1[2][2] = GammaShapeValue(n).de(eorigin,pk) * GammaShapeValue(n).de(eorigin,pk);
1047 // cout<<"dy_e ="<<GammaShapeValue(n).de(eorigin,pk)<<endl;
1048 // Ew = emcmea1.similarity(dwda1);
1049 Ew[0][0] = emcmea1[0][0];
1050 Ew[1][1] = emcmea1[1][1];
1051 Ew[3][3] = emcmea1[2][2];
1052 // cout<<"Ew ="<<Ew<<endl;
1053 if(ptype==6)
1054 setCOrigin(pa+3, Ew.sub(4,4));
1055 else setCOrigin(pa,Ew);
1056 }
1057 }
1058}
1059
1060
1062 upCovmtx();
1063 int pa = mappositionA()[n] + 1;
1064 int pb = mappositionB()[n] + 1 ;
1065 int ptype = mapkinematic()[n];
1066 switch(ptype) {
1067 case 0 :{
1068 HepVector W(7,0);
1069 HepSymMatrix Ew(7,0);
1070 HepVector W1(7,0);
1071 HepSymMatrix Ew1(7,0);
1073 W = wTrackOrigin(n).w();
1074 Ew = wTrackOrigin(n).Ew();
1075 for(int i=0; i<4; i++) {
1076 W[i] = pInfit(n)[i];
1077 }
1078 for(int j=0; j<4; j++) {
1079 for(int k=0; k<4; k++) {
1080 Ew[j][k] = getCInfit(n)[j][k];
1081 }
1082 }
1083 W1 = W;
1084 double px = p4Infit(n).px();
1085 double py = p4Infit(n).py();
1086 double pz = p4Infit(n).pz();
1087 double m = p4Infit(n).m();
1088 double e = p4Infit(n).e();
1089 HepMatrix J(7, 7, 0);
1090 J[0][0] = 1;
1091 J[1][1] = 1;
1092 J[2][2] = 1;
1093 J[3][0] = px/e;
1094 J[3][1] = py/e;
1095 J[3][2] = pz/e;
1096 J[3][3] = m/e;
1097 J[4][4] = 1;
1098 J[5][5] = 1;
1099 J[6][6] = 1;
1100 Ew1 = Ew.similarity(J);
1101
1102 wtrk.setW(W1);
1103 wtrk.setEw(Ew1);
1104 setWTrackInfit(n, wtrk);
1105
1108 HepVector a0 = horigin.hel();
1109 HepVector a1 = hinfit.hel();
1110 HepSymMatrix v0 = horigin.eHel();
1111 HepSymMatrix v1 = hinfit.eHel();
1112 HepVector pull(9,0);
1113 for (int k=0; k<5; k++) {
1114 pull[k] = (a0[k]-a1[k])/sqrt(abs(v0[k][k]-v1[k][k]));
1115 }
1116 for (int l=5; l<9; l++) {
1117 pull[l] = (wTrackOrigin(n).w()[l-5] - wTrackInfit(n).w()[l-5])/sqrt(abs(wTrackOrigin(n).Ew()[l-5][l-5] - wTrackInfit(n).Ew()[l-5][l-5]));
1118 }
1119 return pull;
1120 break;
1121 }
1122 case 1 : {
1123 HepVector a0(4,0);
1124 HepVector a1(4,0);
1125 a0 = m_p0.sub(pa, pa+3);
1126 a1 = m_p.sub(pa, pa+3);
1127 HepSymMatrix v1 = getCInfit(n);
1128 HepSymMatrix v0 = getCOrigin(n);
1129 HepVector pull(3,0);
1130 for (int k=0; k<2; k++) {
1131 pull[k] = (a0[k]-a1[k])/sqrt(v0[k][k]-v1[k][k]);
1132 }
1133 pull[2] = (a0[3]-a1[3])/sqrt(v0[3][3]-v1[3][3]);
1134 return pull;
1135 break;
1136 }
1137 // case 2 : {
1138 // return pull;
1139 // break;
1140 // }
1141 // case 3 : {
1142 // return pull;
1143 // break;
1144 // }
1145 // case 4 : {
1146 // return pull;
1147 // break;
1148 // }
1149 case 5 : {
1150 HepLorentzVector p0 = p4Origin(n);
1151 HepLorentzVector p1 = p4Infit(n);
1152 HepVector a0(2,0);
1153 HepVector a1(2,0);
1154 a0[0] = p4Origin(n).phi();
1155 a1[0] = p4Infit(n).phi();
1156 a0[1] = p4Origin(n).pz()/p4Origin(n).perp();
1157 a1[1] = p4Infit(n).pz()/p4Infit(n).perp();
1158 HepMatrix Jacobi(2, 4, 0);
1159 Jacobi[0][0] = - p4Infit(n).py()/p4Infit(n).perp2();
1160 Jacobi[0][1] = p4Infit(n).px()/p4Infit(n).perp2();
1161 Jacobi[1][0] = - (p4Infit(n).px()/p4Infit(n).perp()) * (p4Infit(n).pz()/p4Infit(n).perp2());
1162 Jacobi[1][1] = - (p4Infit(n).py()/p4Infit(n).perp()) * (p4Infit(n).pz()/p4Infit(n).perp2());
1163 Jacobi[1][2] = 1/p4Infit(n).perp();
1164 HepSymMatrix v1 = getCInfit(n).similarity(Jacobi);
1165 HepSymMatrix v0 = wTrackOrigin(n).Vplm().sub(1,2);
1166 HepVector pull(2,0);
1167 for (int k=0; k<2; k++) {
1168 pull[k] = (a0[k]-a1[k])/sqrt(v0[k][k]-v1[k][k]);
1169 }
1170 return pull;
1171 break;
1172 }
1173 }
1174}
1175
1176
1177
1178HepVector KalmanKinematicFit::pInfit(int n) const {
1179 int pa = mappositionA()[n] + 1;
1180 int pb = mappositionB()[n] + 1;
1181 int ptype = mapkinematic()[n];
1182 switch(ptype) {
1183 case 0 : {
1184 double mass = m_p.sub(pa+3, pa+3)[0];
1185 HepVector p4(4,0);
1186 p4[0] = m_p.sub(pa,pa)[0];
1187 p4[1] = m_p.sub(pa+1, pa+1)[0];
1188 p4[2] = m_p.sub(pa+2, pa+2)[0];
1189 p4[3] = sqrt(p4[0]*p4[0] + p4[1]*p4[1] + p4[2]*p4[2] + mass * mass);
1190 return p4;
1191 break;
1192 }
1193 case 1 : {
1194 double phi = m_p.sub(pa, pa)[0];
1195 double lambda = m_p.sub(pa+1, pa+1)[0];
1196 double mass = m_p.sub(pa+2, pa+2)[0];
1197 double E = m_p.sub(pa+3, pa+3)[0];
1198 double p0 = sqrt(E*E - mass*mass);
1199 HepVector p4(4,0);
1200 p4[0] = p0*cos(phi)/sqrt(1 + lambda*lambda);
1201 p4[1] = p0*sin(phi)/sqrt(1 + lambda*lambda);
1202 p4[2] = p0*lambda/sqrt(1 + lambda*lambda);
1203 p4[3] = sqrt(p0*p0 + mass*mass);
1204 return p4;
1205 break;
1206 }
1207 case 2 : {
1208 return m_q.sub(pb, pb+3);
1209 break;
1210 }
1211 case 3 : {
1212 double mass = (m_p.sub(pa, pa))[0];
1213 double phi = m_q.sub(pb, pb)[0];
1214 double lambda = m_q.sub(pb+1, pb+1)[0];
1215 double E = m_q.sub(pb+2, pb+2)[0];
1216 double p0 = sqrt(E*E - mass*mass);
1217 HepVector p4(4,0);
1218 p4[0] = p0*cos(phi)/sqrt(1 + lambda*lambda);
1219 p4[1] = p0*sin(phi)/sqrt(1 + lambda*lambda);
1220 p4[2] = p0*lambda/sqrt(1 + lambda*lambda);
1221 p4[3] = sqrt(p0*p0 + mass*mass);
1222 return p4;
1223 break;
1224 }
1225 case 4 : {
1226 double phi = m_p.sub(pa, pa)[0];
1227 double lambda = m_p.sub(pa+1, pa+1)[0];
1228 double mass = m_q.sub(pb, pb)[0];
1229 double E = m_q.sub(pb+1, pb+1)[0];
1230 double p0 = sqrt(E*E - mass*mass);
1231 HepVector p4(4,0);
1232 p4[0] = p0*cos(phi)/sqrt(1 + lambda*lambda);
1233 p4[1] = p0*sin(phi)/sqrt(1 + lambda*lambda);
1234 p4[2] = p0*lambda/sqrt(1 + lambda*lambda);
1235 p4[3] = sqrt(p0*p0 + mass*mass);
1236 return p4;
1237 break;
1238 }
1239 case 5 : {
1240 double phi = m_p.sub(pa, pa)[0];
1241 double lambda = m_p.sub(pa+1, pa+1)[0];
1242 double mass = m_p.sub(pa+2, pa+2)[0];
1243 double p0 = m_q.sub(pb, pb)[0];
1244 HepVector p4(4,0);
1245 p4[0] = p0*cos(phi)/sqrt(1 + lambda*lambda);
1246 p4[1] = p0*sin(phi)/sqrt(1 + lambda*lambda);
1247 p4[2] = p0*lambda/sqrt(1 + lambda*lambda);
1248 p4[3] = sqrt(p0*p0 + mass*mass);
1249 return p4;
1250 break;
1251 }
1252 case 6 : {
1253 double x = m_p.sub(pa, pa)[0] - m_q.sub(pb, pb)[0];
1254 double y = m_p.sub(pa+1, pa+1)[0] - m_q.sub(pb+1, pb+1)[0];
1255 double z = m_p.sub(pa+2, pa+2)[0] - m_q.sub(pb+2, pb+2)[0];
1256 double p0 = m_p.sub(pa+3, pa+3)[0];
1257 double R = sqrt(x*x + y*y + z*z);
1258 HepVector p4(4,0);
1259 p4[0] = p0*x/R;
1260 p4[1] = p0*y/R;
1261 p4[2] = p0*z/R;
1262 p4[3] = p0;
1263 return p4;
1264 break;
1265 }
1266 case 7 : {
1267 double mass = m_p.sub(pa+3, pa+3)[0];
1268 HepVector p4(4,0);
1269 p4[0] = m_p.sub(pa,pa)[0];
1270 p4[1] = m_p.sub(pa+1, pa+1)[0];
1271 p4[2] = m_p.sub(pa+2, pa+2)[0];
1272 p4[3] = sqrt(p4[0]*p4[0] + p4[1]*p4[1] + p4[2]*p4[2] + mass * mass);
1273 return p4;
1274 break;
1275 }
1276 }
1277}
1278
1279
1280HepVector KalmanKinematicFit::pOrigin(int n) const {
1281 int pa = mappositionA()[n] + 1;
1282 int pb = mappositionB()[n] + 1;
1283 int ptype = mapkinematic()[n];
1284 switch(ptype) {
1285 case 0 : {
1286 double mass = m_p0.sub(pa+3, pa+3)[0];
1287 HepVector p4(4,0);
1288 p4[0] = m_p0.sub(pa,pa)[0];
1289 p4[1] = m_p0.sub(pa+1, pa+1)[0];
1290 p4[2] = m_p0.sub(pa+2, pa+2)[0];
1291 p4[3] = sqrt(p4[0]*p4[0] + p4[1]*p4[1] + p4[2]*p4[2] + mass * mass);
1292 return p4;
1293 break;
1294 }
1295 case 1 : {
1296 double phi = m_p0.sub(pa, pa)[0];
1297 double lambda = m_p0.sub(pa+1, pa+1)[0];
1298 double mass = m_p0.sub(pa+2, pa+2)[0];
1299 double E = m_p0.sub(pa+3, pa+3)[0];
1300 double p0 = sqrt(E*E - mass*mass);
1301 HepVector p4(4,0);
1302 p4[0] = p0*cos(phi)/sqrt(1 + lambda*lambda);
1303 p4[1] = p0*sin(phi)/sqrt(1 + lambda*lambda);
1304 p4[2] = p0*lambda/sqrt(1 + lambda*lambda);
1305 p4[3] = sqrt(p0*p0 + mass*mass);
1306 return p4;
1307 break;
1308 }
1309 case 2 : {
1310 return m_q0.sub(pb, pb+3);
1311 break;
1312 }
1313 case 3 : {
1314 double mass = (m_p0.sub(pa, pa))[0];
1315 double phi = m_q0.sub(pb, pb)[0];
1316 double lambda = m_q0.sub(pb+1, pb+1)[0];
1317 double E = m_q0.sub(pb+2, pb+2)[0];
1318 double p0 = sqrt(E*E - mass*mass);
1319 HepVector p4(4,0);
1320 p4[0] = p0*cos(phi)/sqrt(1 + lambda*lambda);
1321 p4[1] = p0*sin(phi)/sqrt(1 + lambda*lambda);
1322 p4[2] = p0*lambda/sqrt(1 + lambda*lambda);
1323 p4[3] = sqrt(p0*p0 + mass*mass);
1324 return p4;
1325 break;
1326 }
1327 case 4 : {
1328 double phi = m_p0.sub(pa, pa)[0];
1329 double lambda = m_p0.sub(pa+1, pa+1)[0];
1330 double mass = m_q0.sub(pb, pb)[0];
1331 double E = m_q0.sub(pb+1, pb+1)[0];
1332 double p0 = sqrt(E*E - mass*mass);
1333 HepVector p4(4,0);
1334 p4[0] = p0*cos(phi)/sqrt(1 + lambda*lambda);
1335 p4[1] = p0*sin(phi)/sqrt(1 + lambda*lambda);
1336 p4[2] = p0*lambda/sqrt(1 + lambda*lambda);
1337 p4[3] = sqrt(p0*p0 + mass*mass);
1338 return p4;
1339 break;
1340 }
1341 case 5 : {
1342 double phi = m_p0.sub(pa, pa)[0];
1343 double lambda = m_p0.sub(pa+1, pa+1)[0];
1344 double mass = m_p0.sub(pa+2, pa+2)[0];
1345 double p0 = m_q0.sub(pb, pb)[0];
1346 HepVector p4(4,0);
1347 p4[0] = p0*cos(phi)/sqrt(1 + lambda*lambda);
1348 p4[1] = p0*sin(phi)/sqrt(1 + lambda*lambda);
1349 p4[2] = p0*lambda/sqrt(1 + lambda*lambda);
1350 p4[3] = sqrt(p0*p0 + mass*mass);
1351 return p4;
1352 break;
1353 }
1354 case 6 : {
1355 double x = m_p0.sub(pa, pa)[0] - m_q0.sub(pb, pb)[0];
1356 double y = m_p0.sub(pa+1, pa+1)[0] - m_q0.sub(pb+1, pb+1)[0];
1357 double z = m_p0.sub(pa+2, pa+2)[0] - m_q0.sub(pb+2, pb+2)[0];
1358 double p0 = m_p0.sub(pa+3, pa+3)[0];
1359 double R = sqrt(x*x + y*y + z*z);
1360 HepVector p4(4,0);
1361 p4[0] = p0*x/R;
1362 p4[1] = p0*y/R;
1363 p4[2] = p0*z/R;
1364 p4[3] = p0;
1365 return p4;
1366 break;
1367 }
1368 case 7 : {
1369 double mass = m_p0.sub(pa+3, pa+3)[0];
1370 HepVector p4(4,0);
1371 p4[0] = m_p0.sub(pa,pa)[0];
1372 p4[1] = m_p0.sub(pa+1, pa+1)[0];
1373 p4[2] = m_p0.sub(pa+2, pa+2)[0];
1374 p4[3] = sqrt(p4[0]*p4[0] + p4[1]*p4[1] + p4[2]*p4[2] + mass * mass);
1375 return p4;
1376 break;
1377 }
1378 }
1379}
1380
1381HepSymMatrix KalmanKinematicFit::getCOrigin(int n) const {
1382 int pa = mappositionA()[n] + 1;
1383 int pb = mappositionB()[n] + 1;
1384 int ptype = mapkinematic()[n];
1385 switch(ptype) {
1386 case 0 : {
1387 return m_C0.sub(pa, pa+NTRKPAR-1);
1388 break;
1389 }
1390 case 1 : {
1391 return m_C0.sub(pa, pa+NTRKPAR-1);
1392 break;
1393 }
1394 case 3 : {
1395 return m_C0.sub(pa, pa);
1396 break;
1397 }
1398 case 4 : {
1399 return m_C0.sub(pa, pa+1);
1400 break;
1401 }
1402 case 5 : {
1403 return m_C0.sub(pa, pa+2);
1404 break;
1405 }
1406 case 7 : {
1407 return m_C0.sub(pa, pa+NTRKPAR-1);
1408 break;
1409 }
1410
1411 }
1412}
1413
1414
1415HepSymMatrix KalmanKinematicFit::getCInfit(int n) const {
1416 int pa = mappositionA()[n] + 1;
1417 int pb = mappositionB()[n] + 1;
1418 int ptype = mapkinematic()[n];
1419 switch(ptype) {
1420 case 0 : {
1421 return m_C.sub(pa, pa+NTRKPAR-1);
1422 break;
1423 }
1424 case 1 : {
1425 return m_C.sub(pa, pa+NTRKPAR-1);
1426 break;
1427 }
1428 case 3 : {
1429 return m_C.sub(pa, pa);
1430 break;
1431 }
1432 case 4 : {
1433 return m_C.sub(pa, pa+1);
1434 break;
1435 }
1436 case 5 : {
1437 return m_C.sub(pa, pa+2);
1438 break;
1439 }
1440 case 7 : {
1441 return m_C.sub(pa, pa+NTRKPAR-1);
1442 break;
1443 }
1444 }
1445}
1446
1447
1448
1449
1450void KalmanKinematicFit::updateConstraints(KinematicConstraints k ) {
1451 KinematicConstraints kc = k;
1452
1453
1454 int type = kc.Type();
1455 switch(type) {
1456 case Resonance: {
1457 //
1458 // E^2 - px^2 - py^2 - pz^2 = mres^2
1459 //
1460 double mres = kc.mres();
1461 HepLorentzVector pmis;
1462 for(unsigned int j = 0; j< (kc.Ltrk()).size(); j++){
1463 int n = (kc.Ltrk())[j];
1464 pmis = pmis + p4Infit(n);
1465 }
1466 for(unsigned int j = 0; j< (kc.Ltrk()).size(); j++){
1467 int n = (kc.Ltrk())[j];
1468 double lambda = p4Infit(n).pz()/p4Infit(n).perp();
1469 double a1 = 1 + lambda*lambda;
1470 int pa = mappositionA()[n] + 1;
1471 int pb = mappositionB()[n] + 1;
1472 int ptype = mapkinematic()[n];
1473 switch(ptype) {
1474 case 0 :{
1475 HepMatrix ta(1, NTRKPAR, 0);
1476 ta[0][0] = -2 * pmis.px() + 2 * pmis.e() * p4Infit(n).px() / p4Infit(n).e();
1477 ta[0][1] = -2 * pmis.py() + 2 * pmis.e() * p4Infit(n).py() / p4Infit(n).e();
1478 ta[0][2] = -2 * pmis.pz() + 2 * pmis.e() * p4Infit(n).pz() / p4Infit(n).e();
1479 ta[0][3] = 2 * pmis.e() * p4Infit(n).m() / p4Infit(n).e();
1480 setA(m_nc,pa,ta);
1481 setAT(pa, m_nc, ta.T());
1482 break;
1483 }
1484 case 1 : {
1485 HepMatrix ta(1, NTRKPAR, 0);
1486 double a1 = lambda * lambda + 1;
1487 ta[0][0] = 2 * pmis.px() * p4Infit(n).py() - 2 * pmis.py() * p4Infit(n).px();
1488 ta[0][1] = 2 * pmis.px() * p4Infit(n).px() * lambda/sqrt(a1) + 2 * pmis.py() * (p4Infit(n)).py() * lambda/sqrt(a1) - 2 * pmis.pz() * (p4Infit(n)).pz() /(sqrt(a1) * lambda);
1489 ta[0][2] = 2 * pmis.px() * (p4Infit(n)).px() * p4Infit(n).m() /((p4Infit(n)).rho() * p4Infit(n).rho()) + 2 * pmis.py() * (p4Infit(n)).py() * p4Infit(n).m()/((p4Infit(n)).rho() * p4Infit(n).rho())+ 2 * pmis.pz() * (p4Infit(n)).pz() * p4Infit(n).m()/((p4Infit(n)).rho() * p4Infit(n).rho());
1490 ta[0][3] = 2 * pmis.e() - 2 * pmis.px() * (p4Infit(n)).px() * p4Infit(n).e() /((p4Infit(n)).rho() * p4Infit(n).rho())- 2 * pmis.py() * (p4Infit(n)).py() * p4Infit(n).e()/((p4Infit(n)).rho() * p4Infit(n).rho())- 2 * pmis.pz() * (p4Infit(n)).pz() * p4Infit(n).e()/((p4Infit(n)).rho() * p4Infit(n).rho());
1491 setA(m_nc,pa,ta);
1492 setAT(pa, m_nc, ta.T());
1493 break;
1494 }
1495 case 2 : {
1496 HepMatrix tb(1, 4, 0);
1497 tb[0][0] = -2 * pmis.px();
1498 tb[0][1] = -2 * pmis.py();
1499 tb[0][2] = -2 * pmis.pz();
1500 tb[0][3] = 2 * pmis.e();
1501 setB(m_nc,pb,tb);
1502 setBT(pb,m_nc,tb.T());
1503 break;
1504 }
1505 case 3 : {
1506 HepMatrix ta(1, 1, 0);
1507 double a1 = lambda * lambda + 1;
1508 ta[0][0] = 2 * pmis.px() * (p4Infit(n)).px() * p4Infit(n).m() /((p4Infit(n)).rho() * p4Infit(n).rho()) + 2 * pmis.py() * (p4Infit(n)).py() * p4Infit(n).m()/((p4Infit(n)).rho() * p4Infit(n).rho())+ 2 * pmis.pz() * (p4Infit(n)).pz() * p4Infit(n).m()/((p4Infit(n)).rho() * p4Infit(n).rho());
1509 setA(m_nc,pa,ta);
1510 setAT(pa, m_nc, ta.T());
1511 HepMatrix tb(1, 3, 0);
1512 tb[0][0] = 2 * pmis.px() * p4Infit(n).py() - 2 * pmis.py() * p4Infit(n).px();
1513 tb[0][1] = 2 * pmis.px() * p4Infit(n).px() * lambda/sqrt(a1) + 2 * pmis.py() * (p4Infit(n)).py() * lambda/sqrt(a1) - 2 * pmis.pz() * (p4Infit(n)).pz() /(sqrt(a1) * lambda);
1514 tb[0][2] = 2 * pmis.e() - 2 * pmis.px() * (p4Infit(n)).px() * p4Infit(n).e() /((p4Infit(n)).rho() * p4Infit(n).rho())- 2 * pmis.py() * (p4Infit(n)).py() * p4Infit(n).e()/((p4Infit(n)).rho() * p4Infit(n).rho())- 2 * pmis.pz() * (p4Infit(n)).pz() * p4Infit(n).e()/((p4Infit(n)).rho() * p4Infit(n).rho());
1515 setB(m_nc,pb,tb);
1516 setBT(pb,m_nc,tb.T());
1517 break;
1518 }
1519 case 4 : {
1520 HepMatrix ta(1, 2, 0);
1521 double a1 = lambda * lambda + 1;
1522 ta[0][0] = 2 * pmis.px() * p4Infit(n).py() - 2 * pmis.py() * p4Infit(n).px();
1523 ta[0][1] = 2 * pmis.px() * p4Infit(n).px() * lambda/sqrt(a1) + 2 * pmis.py() * (p4Infit(n)).py() * lambda/sqrt(a1) - 2 * pmis.pz() * (p4Infit(n)).pz() /(sqrt(a1) * lambda);
1524 setA(m_nc,pa,ta);
1525 setAT(pa, m_nc, ta.T());
1526
1527 HepMatrix tb(1, 2, 0);
1528 tb[0][0] = 2 * pmis.px() * (p4Infit(n)).px() * p4Infit(n).m() /((p4Infit(n)).rho() * p4Infit(n).rho()) + 2 * pmis.py() * (p4Infit(n)).py() * p4Infit(n).m()/((p4Infit(n)).rho() * p4Infit(n).rho())+ 2 * pmis.pz() * (p4Infit(n)).pz() * p4Infit(n).m()/((p4Infit(n)).rho() * p4Infit(n).rho());
1529 tb[0][1] = 2 * pmis.e() - 2 * pmis.px() * (p4Infit(n)).px() * p4Infit(n).e() /((p4Infit(n)).rho() * p4Infit(n).rho())- 2 * pmis.py() * (p4Infit(n)).py() * p4Infit(n).e()/((p4Infit(n)).rho() * p4Infit(n).rho())- 2 * pmis.pz() * (p4Infit(n)).pz() * p4Infit(n).e()/((p4Infit(n)).rho() * p4Infit(n).rho());
1530 setB(m_nc,pb,tb);
1531 setBT(pb, m_nc, tb.T());
1532 break;
1533 }
1534 case 5 : {
1535 HepMatrix ta(1, 3, 0);
1536 ta[0][0] = 2 * pmis.px() * p4Infit(n).py() - 2 * pmis.py() * p4Infit(n).px();
1537 ta[0][1] = 2 * pmis.px() * p4Infit(n).px() * lambda/sqrt(a1)+ 2 * pmis.py() * (p4Infit(n)).py() * lambda/sqrt(a1) - 2 * pmis.pz() * (p4Infit(n)).pz() /(sqrt(a1) * lambda);
1538 ta[0][2] = 2 * pmis.e() * (p4Infit(n)).m()/(p4Infit(n)).e();
1539 setA(m_nc,pa,ta);
1540 setAT(pa, m_nc, ta.T());
1541 HepMatrix tb(1, 1, 0);
1542 tb[0][0] = 2 * pmis.e() * (p4Infit(n)).rho()/(p4Infit(n)).e() - 2 * pmis.px() * (p4Infit(n)).px()/(p4Infit(n)).rho() - 2 * pmis.py() * (p4Infit(n)).py()/(p4Infit(n)).rho() - 2 * pmis.pz() * (p4Infit(n)).pz()/(p4Infit(n)).rho();
1543 setB(m_nc,pb,tb);
1544 setBT(pb, m_nc, tb.T());
1545 break;
1546 }
1547 case 7 :{
1548 HepMatrix ta(1, NTRKPAR, 0);
1549 ta[0][0] = -2 * pmis.px() + 2 * pmis.e() * p4Infit(n).px() / p4Infit(n).e();
1550 ta[0][1] = -2 * pmis.py() + 2 * pmis.e() * p4Infit(n).py() / p4Infit(n).e();
1551 ta[0][2] = -2 * pmis.pz() + 2 * pmis.e() * p4Infit(n).pz() / p4Infit(n).e();
1552 ta[0][3] = 2 * pmis.e() * p4Infit(n).m() / p4Infit(n).e();
1553 setA(m_nc,pa,ta);
1554 setAT(pa, m_nc, ta.T());
1555 break;
1556 }
1557 }
1558 }
1559
1560 HepVector dc(1, 0);
1561 dc[0] = pmis.m2() - mres * mres;
1562 m_G[m_nc] = dc[0];
1563 m_nc+=1;
1564
1565 break;
1566 }
1567 case TotalEnergy: {
1568 //
1569 // E - Etot = 0
1570 //
1571 double etot = kc.etot();
1572 HepLorentzVector pmis;
1573 for(unsigned int j = 0; j < (kc.Ltrk()).size(); j++){
1574 int n = (kc.Ltrk())[j];
1575 pmis = pmis + p4Infit(n);
1576 }
1577
1578 for(unsigned int j = 0; j < (kc.Ltrk()).size(); j++) {
1579 int n = (kc.Ltrk())[j];
1580 int pa = mappositionA()[n] + 1;
1581 int pb = mappositionB()[n] + 1;
1582 int ptype = mapkinematic()[n];
1583 switch(ptype) {
1584 case 0 :{
1585 HepMatrix ta(1, NTRKPAR, 0);
1586 ta[0][0] = p4Infit(n).px()/p4Infit(n).e();
1587 ta[0][1] = p4Infit(n).py()/p4Infit(n).e();
1588 ta[0][2] = p4Infit(n).pz()/p4Infit(n).e();
1589 ta[0][3] = p4Infit(n).m()/p4Infit(n).e();
1590 setA(m_nc,pa,ta);
1591 setAT(pa, m_nc, ta.T());
1592 break;
1593 }
1594 case 1: {
1595 HepMatrix ta(1, NTRKPAR, 0);
1596 ta[0][3] = 1.0;
1597 setA(m_nc,pa,ta);
1598 setAT(pa, m_nc, ta.T());
1599 break;
1600 }
1601 case 2: {
1602 HepMatrix tb(1, 4, 0);
1603 tb[0][3] = 1.0;
1604 setA(m_nc,pb,tb);
1605 setAT(pb, m_nc, tb.T());
1606 break;
1607 }
1608 case 3: {
1609 HepMatrix ta(1, 1, 0);
1610 ta[0][0] = p4Infit(n).m()/p4Infit(n).e();
1611 setA(m_nc,pa,ta);
1612 setAT(pa, m_nc, ta.T());
1613
1614 HepMatrix tb(1, 3, 0);
1615 setB(m_nc,pb,tb);
1616 setBT(pb, m_nc, tb.T());
1617 break;
1618 }
1619 case 4: {
1620 HepMatrix ta(1, 2, 0);
1621 setA(m_nc,pa,ta);
1622 setAT(pa, m_nc, ta.T());
1623
1624 HepMatrix tb(1, 2, 0);
1625 tb[0][0] = 0.0;
1626 tb[0][1] = 1.0;
1627 // tb[0][0] = p4Infit(n).m()/p4Infit(n).e();
1628 // tb[0][1] = p4Infit(n).rho()/p4Infit(n).e();
1629 setB(m_nc,pb,tb);
1630 setBT(pb, m_nc, tb.T());
1631 break;
1632 }
1633 case 5: {
1634 HepMatrix ta(1, 3, 0);
1635 ta[0][2] = p4Infit(n).m()/p4Infit(n).e();
1636 setA(m_nc,pa,ta);
1637 setAT(pa, m_nc, ta.T());
1638
1639 HepMatrix tb(1, 1, 0);
1640 tb[0][0] = p4Infit(n).rho()/p4Infit(n).e();
1641 setB(m_nc,pb,tb);
1642 setBT(pb, m_nc, tb.T());
1643 break;
1644 }
1645 case 7 :{
1646 HepMatrix ta(1, NTRKPAR, 0);
1647 ta[0][0] = p4Infit(n).px()/p4Infit(n).e();
1648 ta[0][1] = p4Infit(n).py()/p4Infit(n).e();
1649 ta[0][2] = p4Infit(n).pz()/p4Infit(n).e();
1650 ta[0][3] = p4Infit(n).m()/p4Infit(n).e();
1651 setA(m_nc,pa,ta);
1652 setAT(pa, m_nc, ta.T());
1653 break;
1654 }
1655 }
1656
1657 }
1658
1659 HepVector dc(1, 0);
1660 dc[0] = pmis.e() - etot;
1661 m_G[m_nc] = dc[0];
1662 m_nc+=1;
1663 break;
1664 }
1665 case TotalMomentum: {
1666 //
1667 // sqrt(px^2+py^2+pz^2) - ptot = 0
1668 //
1669 double ptot = kc.ptot();
1670 HepLorentzVector pmis;
1671 for(unsigned int j = 0; j< (kc.Ltrk()).size(); j++){
1672 int n = (kc.Ltrk())[j];
1673 pmis = pmis + p4Infit(n);
1674 }
1675
1676 for(unsigned int j = 0; j < (kc.Ltrk()).size(); j++) {
1677 int n = (kc.Ltrk())[j];
1678 int pa = mappositionA()[n] + 1;
1679 int pb = mappositionB()[n] + 1;
1680 int ptype = mapkinematic()[n];
1681 double lambda = p4Infit(n).pz()/p4Infit(n).perp();
1682 switch(ptype) {
1683 case 0 : {
1684 HepMatrix ta(1, NTRKPAR, 0);
1685 ta[0][0] = pmis.px()/pmis.rho();
1686 ta[0][1] = pmis.py()/pmis.rho();
1687 ta[0][2] = pmis.pz()/pmis.rho();
1688 setA(m_nc,pa,ta);
1689 setAT(pa, m_nc, ta.T());
1690 break;
1691 }
1692 case 1 : {
1693 HepMatrix ta(1, NTRKPAR, 0);
1694 ta[0][0] = - (pmis.px()/pmis.rho()) * p4Infit(n).py() + (pmis.px()/pmis.rho())*p4Infit(n).px();
1695 ta[0][1] = - (pmis.px()/pmis.rho()) * p4Infit(n).px() * (lambda/(1 + lambda*lambda)) - (pmis.py()/pmis.rho()) * p4Infit(n).py() * (lambda/(1 + lambda*lambda)) + (pmis.pz()/pmis.rho()) * p4Infit(n).pz() * (1/(lambda * (1 + lambda*lambda)));
1696 ta[0][2] = -((pmis.px()/pmis.rho()) * p4Infit(n).m()/(p4Infit(n).rho()*p4Infit(n).rho())) * (p4Infit(n).px() + p4Infit(n).py() +p4Infit(n).pz());
1697 ta[0][3] = ((pmis.px()/pmis.rho()) * p4Infit(n).e()/(p4Infit(n).rho()*p4Infit(n).rho())) * (p4Infit(n).px() + p4Infit(n).py() +
1698 p4Infit(n).pz());
1699
1700 setA(m_nc,pa,ta);
1701 setAT(pa, m_nc, ta.T());
1702 break;
1703 }
1704 case 2 : {
1705 HepMatrix tb(1, 4, 0);
1706 tb[0][0] = pmis.px()/pmis.rho();
1707 tb[0][1] = pmis.py()/pmis.rho();
1708 tb[0][2] = pmis.pz()/pmis.rho();
1709 setB(m_nc,pb,tb);
1710 setBT(pb, m_nc, tb.T());
1711 break;
1712 }
1713 case 3 : {
1714 HepMatrix ta(1, 1, 0);
1715 setA(m_nc,pa,ta);
1716 setAT(pa, m_nc, ta.T());
1717 HepMatrix tb(1, 3, 0);
1718 tb[0][0] = pmis.px()/pmis.rho();
1719 tb[0][1] = pmis.py()/pmis.rho();
1720 tb[0][2] = pmis.pz()/pmis.rho();
1721 setB(m_nc,pb,tb);
1722 setBT(pb, m_nc, tb.T());
1723 break;
1724 }
1725 case 4 : {
1726 HepMatrix ta(1, 2, 0);
1727 ta[0][0] = - (pmis.px()/pmis.rho()) * p4Infit(n).py() + (pmis.px()/pmis.rho())*p4Infit(n).px();
1728 ta[0][1] = - (pmis.px()/pmis.rho()) * p4Infit(n).px() * (lambda/(1 + lambda*lambda)) - (pmis.py()/pmis.rho()) * p4Infit(n).py() * (lambda/(1 + lambda*lambda)) + (pmis.pz()/pmis.rho()) * p4Infit(n).pz() * (1/(lambda * (1 + lambda*lambda)));
1729 setA(m_nc,pa,ta);
1730 setAT(pa, m_nc, ta.T());
1731
1732 HepMatrix tb(1, 2, 0);
1733 tb[0][0] = -((pmis.px()/pmis.rho()) * p4Infit(n).m()/(p4Infit(n).rho()*p4Infit(n).rho())) * (p4Infit(n).px() + p4Infit(n).py() +p4Infit(n).pz());
1734 tb[0][1] = ((pmis.px()/pmis.rho()) * p4Infit(n).e()/(p4Infit(n).rho()*p4Infit(n).rho())) * (p4Infit(n).px() + p4Infit(n).py() +
1735 p4Infit(n).pz());
1736 // tb[0][1] = (pmis.px()/pmis.rho()) * (p4Infit(n).px()/p4Infit(n).rho()) + (pmis.py()/pmis.rho()) * (p4Infit(n).py()/p4Infit(n).rho()) + (pmis.pz()/pmis.rho()) * (p4Infit(n).pz()/p4Infit(n).rho());
1737 setB(m_nc,pb,tb);
1738 setBT(pb, m_nc, tb.T());
1739 break;
1740 }
1741 case 5 : {
1742 HepMatrix ta(1, 3, 0);
1743 ta[0][0] = - (pmis.px()/pmis.rho()) * p4Infit(n).py() + (pmis.px()/pmis.rho())*p4Infit(n).px();
1744 ta[0][1] = - (pmis.px()/pmis.rho()) * p4Infit(n).px() * (lambda/(1 + lambda*lambda)) - (pmis.py()/pmis.rho()) * p4Infit(n).py() * (lambda/(1 + lambda*lambda)) + (pmis.pz()/pmis.rho()) * p4Infit(n).pz() * (1/(lambda * (1 + lambda*lambda)));
1745 setA(m_nc,pa,ta);
1746 setAT(pa, m_nc, ta.T());
1747
1748 HepMatrix tb(1, 1, 0);
1749 tb[0][0] = (pmis.px()/pmis.rho()) * (p4Infit(n).px()/p4Infit(n).rho()) + (pmis.py()/pmis.rho()) * (p4Infit(n).py()/p4Infit(n).rho()) + (pmis.pz()/pmis.rho()) * (p4Infit(n).pz()/p4Infit(n).rho());
1750 setB(m_nc,pb,tb);
1751 setBT(pb, m_nc, tb.T());
1752 break;
1753 }
1754 case 7 : {
1755 HepMatrix ta(1, NTRKPAR, 0);
1756 ta[0][0] = pmis.px()/pmis.rho();
1757 ta[0][1] = pmis.py()/pmis.rho();
1758 ta[0][2] = pmis.pz()/pmis.rho();
1759 setA(m_nc,pa,ta);
1760 setAT(pa, m_nc, ta.T());
1761 break;
1762 }
1763 }
1764 }
1765
1766
1767 HepVector dc(1, 0);
1768 dc[0] = pmis.rho() - ptot;
1769 m_G[m_nc] = dc[0];
1770 m_nc+=1;
1771 break;
1772 }
1773
1774
1775 case ThreeMomentum: {
1776 //
1777 // px - p3x = 0
1778 // py - p3y = 0
1779 // pz - p3z = 0
1780 //
1781 Hep3Vector p3 = kc.p3();
1782 HepLorentzVector pmis;
1783 for(unsigned int j = 0; j< (kc.Ltrk()).size(); j++){
1784 int n = (kc.Ltrk())[j];
1785 pmis = pmis + p4Infit(n);
1786 }
1787 for(unsigned int j = 0; j < (kc.Ltrk()).size(); j++) {
1788 int n = (kc.Ltrk())[j];
1789 int pa = mappositionA()[n] + 1;
1790 int pb = mappositionB()[n] + 1;
1791 int ptype = mapkinematic()[n];
1792 double lambda = p4Infit(n).pz()/p4Infit(n).perp();
1793 switch(ptype) {
1794 case 0 : {
1795 HepMatrix ta(kc.nc(), NTRKPAR, 0);
1796 ta[0][0] = 1.0;
1797 ta[1][1] = 1.0;
1798 ta[2][2] = 1.0;
1799 setA(m_nc, pa, ta);
1800 setAT(pa, m_nc, ta.T());
1801 break;
1802 }
1803 case 1 : {
1804 HepMatrix ta(kc.nc(), NTRKPAR, 0);
1805 ta[0][0] = -p4Infit(n).py();
1806 ta[0][1] = -p4Infit(n).px()*(lambda/sqrt(1 + lambda*lambda));
1807 ta[0][2] = -p4Infit(n).m()*p4Infit(n).px()/(p4Infit(n).rho()*p4Infit(n).rho());
1808 ta[0][3] = p4Infit(n).e()*p4Infit(n).px()/(p4Infit(n).rho()*p4Infit(n).rho());
1809 ta[1][0] = p4Infit(n).px();
1810 ta[1][1] = -p4Infit(n).py()*(lambda/sqrt(1 + lambda*lambda));
1811 ta[1][2] = -p4Infit(n).m()*p4Infit(n).py()/(p4Infit(n).rho()*p4Infit(n).rho());
1812 ta[1][3] = p4Infit(n).e()*p4Infit(n).py()/(p4Infit(n).rho()*p4Infit(n).rho());
1813 ta[2][0] = 0;
1814 ta[2][1] = p4Infit(n).pz()*(1/(lambda * (1 + lambda*lambda)));
1815 ta[2][2] = -p4Infit(n).m()*p4Infit(n).pz()/(p4Infit(n).rho()*p4Infit(n).rho());
1816 ta[2][3] = p4Infit(n).e()*p4Infit(n).pz()/(p4Infit(n).rho()*p4Infit(n).rho());
1817 // ta[0][0] = 1.0;
1818 // ta[1][1] = 1.0;
1819 // ta[2][2] = 1.0;
1820 setA(m_nc, pa, ta);
1821 setAT(pa, m_nc, ta.T());
1822 break;
1823 }
1824 case 2 : {
1825 HepMatrix tb(kc.nc(), 4, 0);
1826 tb[0][0] = 1.0;
1827 tb[1][1] = 1.0;
1828 tb[2][2] = 1.0;
1829 setB(m_nc, pb, tb);
1830 setBT(pb, m_nc, tb.T());
1831 break;
1832 }
1833 case 3 : {
1834 HepMatrix ta(kc.nc(), 1, 0);
1835 setA(m_nc, pa, ta);
1836 setAT(pa, m_nc, ta.T());
1837
1838 HepMatrix tb(kc.nc(), 3, 0);
1839 tb[0][0] = 1.0;
1840 tb[1][1] = 1.0;
1841 tb[2][2] = 1.0;
1842 setB(m_nc, pb, tb);
1843 setBT(pb, m_nc, tb.T());
1844
1845 break;
1846 }
1847 case 4 : {
1848 HepMatrix ta(kc.nc(), 2, 0);
1849 ta[0][0] = -p4Infit(n).py();
1850 ta[0][1] = -p4Infit(n).px()*(lambda/sqrt(1 + lambda*lambda));
1851 ta[1][0] = p4Infit(n).px();
1852 ta[1][1] = -p4Infit(n).py()*(lambda/sqrt(1 + lambda*lambda));
1853 ta[2][0] = 0;
1854 ta[2][1] = p4Infit(n).pz()*(1/(lambda * (1 + lambda*lambda)));
1855 setA(m_nc, pa, ta);
1856 setAT(pa, m_nc, ta.T());
1857
1858 HepMatrix tb(kc.nc(), 2, 0);
1859 tb[0][1] = -p4Infit(n).m()*p4Infit(n).px()/(p4Infit(n).rho()*p4Infit(n).rho());
1860 tb[1][1] = -p4Infit(n).m()*p4Infit(n).py()/(p4Infit(n).rho()*p4Infit(n).rho());
1861 tb[2][1] = -p4Infit(n).m()*p4Infit(n).pz()/(p4Infit(n).rho()*p4Infit(n).rho());
1862 setB(m_nc, pb, tb);
1863 setBT(pb, m_nc, tb.T());
1864 break;
1865 }
1866 case 5 : {
1867 HepMatrix ta(kc.nc(), 3, 0);
1868 ta[0][0] = -p4Infit(n).py();
1869 ta[0][1] = -p4Infit(n).px()*(lambda/sqrt(1 + lambda*lambda));
1870 ta[1][0] = p4Infit(n).px();
1871 ta[1][1] = -p4Infit(n).py()*(lambda/sqrt(1 + lambda*lambda));
1872 ta[2][0] = 0;
1873 ta[2][1] = p4Infit(n).pz()*(1/(lambda * (1 + lambda*lambda)));
1874 setA(m_nc, pa, ta);
1875 setAT(pa, m_nc, ta.T());
1876
1877 HepMatrix tb(kc.nc(), 1, 0);
1878 tb[0][0] = p4Infit(n).px()/p4Infit(n).rho();
1879 tb[1][0] = p4Infit(n).py()/p4Infit(n).rho();
1880 tb[2][0] = p4Infit(n).pz()/p4Infit(n).rho();
1881 setB(m_nc, pb, tb);
1882 setBT(pb, m_nc, tb.T());
1883 break;
1884 }
1885 case 7 : {
1886 HepMatrix ta(kc.nc(), NTRKPAR, 0);
1887 ta[0][0] = 1.0;
1888 ta[1][1] = 1.0;
1889 ta[2][2] = 1.0;
1890 setA(m_nc, pa, ta);
1891 setAT(pa, m_nc, ta.T());
1892 break;
1893 }
1894 }
1895 }
1896 HepVector dc(kc.nc(), 0);
1897 dc[0] = pmis.px() - p3.x();
1898 dc[1] = pmis.py() - p3.y();
1899 dc[2] = pmis.pz() - p3.z();
1900 for(int i = 0; i < kc.nc(); i++) {
1901 m_G[m_nc+i] = dc[i];
1902 }
1903
1904 m_nc += 3;
1905
1906 break;
1907 }
1908 case EqualMass: {
1909 //
1910 // (E_1 ^2 - Px_1 ^2 - Py_1 ^2 - Pz_1 ^2) - (E_2 ^2 - Px_2 ^2 - Py_2 ^2 - Pz_2 ^2) = 0
1911 //
1912
1913 int isiz = (kc.numEqual())[0];
1914 HepLorentzVector pmis1, pmis2;
1915 for(int n = 0; n < isiz; n++) {
1916 int n1 = (kc.Ltrk())[n];
1917 pmis1 = pmis1 + p4Infit(n1);
1918 }
1919
1920 int jsiz = (kc.numEqual())[1];
1921 for(int n = 0; n < jsiz; n++){
1922 int n2 = (kc.Ltrk())[n+isiz];
1923 pmis2 = pmis2 + p4Infit(n2);
1924 }
1925
1926 for(int i = 0; i < isiz; i++) {
1927 int n1 = (kc.Ltrk())[i];
1928 double lambda = p4Infit(n1).pz()/p4Infit(n1).perp();
1929 int pa = mappositionA()[n1] + 1;
1930 int pb = mappositionB()[n1] + 1;
1931 int ptype = mapkinematic()[n1];
1932 switch(ptype) {
1933 case 0: {
1934 HepMatrix ta(1, NTRKPAR, 0);
1935 ta[0][0] = -2 * pmis1.px() + 2 * pmis1.e() * p4Infit(n1).px() / p4Infit(n1).e();
1936 ta[0][1] = -2 * pmis1.py() + 2 * pmis1.e() * p4Infit(n1).py() / p4Infit(n1).e();
1937 ta[0][2] = -2 * pmis1.pz() + 2 * pmis1.e() * p4Infit(n1).pz() / p4Infit(n1).e();
1938 ta[0][3] = 2 * pmis1.e() * p4Infit(n1).m() / p4Infit(n1).e();
1939 setA(m_nc,pa,ta);
1940 setAT(pa, m_nc, ta.T());
1941 break;
1942 }
1943 case 1 : {
1944 HepMatrix ta(1, NTRKPAR, 0);
1945 double a1 = lambda * lambda + 1;
1946 ta[0][0] = 2 * pmis1.px() * p4Infit(n1).py() - 2 * pmis1.py() * p4Infit(n1).px();
1947 ta[0][1] = 2 * pmis1.px() * p4Infit(n1).px() * lambda/sqrt(a1) + 2 * pmis1.py() * (p4Infit(n1)).py() * lambda/sqrt(a1) - 2 * pmis1.pz() * (p4Infit(n1)).pz() /(sqrt(a1) * lambda);
1948 ta[0][2] = 2 * pmis1.px() * (p4Infit(n1)).px() * p4Infit(n1).m() /((p4Infit(n1)).rho() * p4Infit(n1).rho()) + 2 * pmis1.py() * (p4Infit(n1)).py() * p4Infit(n1).m()/((p4Infit(n1)).rho() * p4Infit(n1).rho())+ 2 * pmis1.pz() * (p4Infit(n1)).pz() * p4Infit(n1).m()/((p4Infit(n1)).rho() * p4Infit(n1).rho());
1949 ta[0][3] = 2 * pmis1.e() - 2 * pmis1.px() * (p4Infit(n1)).px() * p4Infit(n1).e() /((p4Infit(n1)).rho() * p4Infit(n1).rho())- 2 * pmis1.py() * (p4Infit(n1)).py() * p4Infit(n1).e()/((p4Infit(n1)).rho() * p4Infit(n1).rho())- 2 * pmis1.pz() * (p4Infit(n1)).pz() * p4Infit(n1).e()/((p4Infit(n1)).rho() * p4Infit(n1).rho());
1950 setA(m_nc,pa,ta);
1951 setAT(pa, m_nc, ta.T());
1952 break;
1953 }
1954 case 2 : {
1955 HepMatrix tb(1, 4, 0);
1956 tb[0][0] = -2 * pmis1.px();
1957 tb[0][1] = -2 * pmis1.py();
1958 tb[0][2] = -2 * pmis1.pz();
1959 tb[0][3] = 2 * pmis1.e();
1960 setB(m_nc,pb,tb);
1961 setBT(pb,m_nc,tb.T());
1962 break;
1963 }
1964 case 3 : {
1965 HepMatrix ta(1, 1, 0);
1966 ta[0][0] = 2 * pmis1.e() * (p4Infit(n1).m()/p4Infit(n1).e());
1967 setA(m_nc,pa,ta);
1968 setAT(pa, m_nc, ta.T());
1969 HepMatrix tb(1, 3, 0);
1970 tb[0][0] = -2 * pmis1.px();
1971 tb[0][1] = -2 * pmis1.py();
1972 tb[0][2] = -2 * pmis1.pz();
1973 setB(m_nc,pb,tb);
1974 setBT(pb,m_nc,tb.T());
1975 break;
1976 }
1977 case 4 : {
1978 HepMatrix ta(1, 2, 0);
1979 double a1 = lambda * lambda + 1;
1980 ta[0][0] = 2 * pmis1.px() * p4Infit(n1).py() - 2 * pmis1.py() * p4Infit(n1).px();
1981 ta[0][1] = 2 * pmis1.px() * p4Infit(n1).px() * lambda/sqrt(a1) + 2 * pmis1.py() * (p4Infit(n1)).py() * lambda/sqrt(a1) - 2 * pmis1.pz() * (p4Infit(n1)).pz() /(sqrt(a1) * lambda);
1982 setA(m_nc,pa,ta);
1983 setAT(pa, m_nc, ta.T());
1984
1985 HepMatrix tb(1, 2, 0);
1986 tb[0][0] = 2 * pmis1.px() * (p4Infit(n1)).px() * p4Infit(n1).m() /((p4Infit(n1)).rho() * p4Infit(n1).rho()) + 2 * pmis1.py() * (p4Infit(n1)).py() * p4Infit(n1).m()/((p4Infit(n1)).rho() * p4Infit(n1).rho())+ 2 * pmis1.pz() * (p4Infit(n1)).pz() * p4Infit(n1).m()/((p4Infit(n1)).rho() * p4Infit(n1).rho());
1987 tb[0][1] = 2 * pmis1.e() - 2 * pmis1.px() * (p4Infit(n1)).px() * p4Infit(n1).e() /((p4Infit(n1)).rho() * p4Infit(n1).rho())- 2 * pmis1.py() * (p4Infit(n1)).py() * p4Infit(n1).e()/((p4Infit(n1)).rho() * p4Infit(n1).rho())- 2 * pmis1.pz() * (p4Infit(n1)).pz() * p4Infit(n1).e()/((p4Infit(n1)).rho() * p4Infit(n1).rho());
1988 setB(m_nc,pb,tb);
1989 setBT(pb, m_nc, tb.T());
1990 break;
1991 }
1992 case 5 : {
1993 HepMatrix ta(1, 3, 0);
1994 double a1 = lambda * lambda + 1;
1995 ta[0][0] = 2 * pmis1.px() * p4Infit(n1).py() - 2 * pmis1.py() * p4Infit(n1).px();
1996 ta[0][1] = 2 * pmis1.px() * p4Infit(n1).px() * lambda/sqrt(a1)+ 2 * pmis1.py() * (p4Infit(n1)).py() * lambda/sqrt(a1) - 2 * pmis1.pz() * (p4Infit(n1)).pz() /(sqrt(a1) * lambda);
1997 ta[0][2] = 2 * pmis1.e() * (p4Infit(n1)).m()/(p4Infit(n1)).e();
1998 setA(m_nc,pa,ta);
1999 setAT(pa, m_nc, ta.T());
2000 HepMatrix tb(1, 1, 0);
2001 tb[0][0] = 2 * pmis1.e() * (p4Infit(n1)).rho()/(p4Infit(n1)).e() - 2 * pmis1.px() * (p4Infit(n1)).px()/(p4Infit(n1)).rho() - 2 * pmis1.py() * (p4Infit(n1)).py()/(p4Infit(n1)).rho() - 2 * pmis1.pz() * (p4Infit(n1)).pz()/(p4Infit(n1)).rho();
2002 setB(m_nc,pb,tb);
2003 setBT(pb, m_nc, tb.T());
2004 break;
2005 }
2006 case 7: {
2007 HepMatrix ta(1, NTRKPAR, 0);
2008 ta[0][0] = -2 * pmis1.px() + 2 * pmis1.e() * p4Infit(n1).px() / p4Infit(n1).e();
2009 ta[0][1] = -2 * pmis1.py() + 2 * pmis1.e() * p4Infit(n1).py() / p4Infit(n1).e();
2010 ta[0][2] = -2 * pmis1.pz() + 2 * pmis1.e() * p4Infit(n1).pz() / p4Infit(n1).e();
2011 ta[0][3] = 2 * pmis1.e() * p4Infit(n1).m() / p4Infit(n1).e();
2012 setA(m_nc,pa,ta);
2013 setAT(pa, m_nc, ta.T());
2014 break;
2015 }
2016 }
2017 }
2018
2019 for(int i = isiz; i < isiz+jsiz; i++) {
2020 int n2 = (kc.Ltrk())[i];
2021 double lambda = p4Infit(n2).pz()/p4Infit(n2).perp();
2022 int pa = mappositionA()[n2] + 1;
2023 int pb = mappositionB()[n2] + 1;
2024 int ptype = mapkinematic()[n2];
2025 switch(ptype) {
2026 case 0 : {
2027 HepMatrix ta(1, NTRKPAR, 0);
2028 ta[0][0] = -2 * pmis2.px() + 2 * pmis2.e() * p4Infit(n2).px() / p4Infit(n2).e();
2029 ta[0][1] = -2 * pmis2.py() + 2 * pmis2.e() * p4Infit(n2).py() / p4Infit(n2).e();
2030 ta[0][2] = -2 * pmis2.pz() + 2 * pmis2.e() * p4Infit(n2).pz() / p4Infit(n2).e();
2031 ta[0][3] = 2 * pmis2.e() * p4Infit(n2).m() / p4Infit(n2).e();
2032 setA(m_nc,pa,-ta);
2033 setAT(pa, m_nc, -ta.T());
2034 break;
2035 }
2036 case 1 : {
2037 HepMatrix ta(1, NTRKPAR, 0);
2038 double a1 = lambda * lambda + 1;
2039 ta[0][0] = 2 * pmis2.px() * p4Infit(n2).py() - 2 * pmis2.py() * p4Infit(n2).px();
2040 ta[0][1] = 2 * pmis2.px() * p4Infit(n2).px() * lambda/sqrt(a1) + 2 * pmis2.py() * (p4Infit(n2)).py() * lambda/sqrt(a1) - 2 * pmis2.pz() * (p4Infit(n2)).pz() /(sqrt(a1) * lambda);
2041 ta[0][2] = 2 * pmis2.px() * (p4Infit(n2)).px() * p4Infit(n2).m() /((p4Infit(n2)).rho() * p4Infit(n2).rho()) + 2 * pmis2.py() * (p4Infit(n2)).py() * p4Infit(n2).m()/((p4Infit(n2)).rho() * p4Infit(n2).rho())+ 2 * pmis2.pz() * (p4Infit(n2)).pz() * p4Infit(n2).m()/((p4Infit(n2)).rho() * p4Infit(n2).rho());
2042 ta[0][3] = 2 * pmis2.e() - 2 * pmis2.px() * (p4Infit(n2)).px() * p4Infit(n2).e() /((p4Infit(n2)).rho() * p4Infit(n2).rho())- 2 * pmis2.py() * (p4Infit(n2)).py() * p4Infit(n2).e()/((p4Infit(n2)).rho() * p4Infit(n2).rho())- 2 * pmis2.pz() * (p4Infit(n2)).pz() * p4Infit(n2).e()/((p4Infit(n2)).rho() * p4Infit(n2).rho());
2043 setA(m_nc,pa,-ta);
2044 setAT(pa, m_nc, -ta.T());
2045 break;
2046 }
2047 case 2 : {
2048 HepMatrix tb(1, 4, 0);
2049 tb[0][0] = -2 * pmis2.px();
2050 tb[0][1] = -2 * pmis2.py();
2051 tb[0][2] = -2 * pmis2.pz();
2052 tb[0][3] = 2 * pmis2.e();
2053 setB(m_nc,pb,-tb);
2054 setBT(pb,m_nc,-tb.T());
2055 break;
2056 }
2057 case 3 : {
2058 HepMatrix ta(1, 1, 0);
2059 ta[0][0] = 2 * pmis2.e() * (p4Infit(n2).m()/p4Infit(n2).e());
2060 setA(m_nc,pa,-ta);
2061 setAT(pa, m_nc, -ta.T());
2062 HepMatrix tb(1, 3, 0);
2063 tb[0][0] = -2 * pmis2.px();
2064 tb[0][1] = -2 * pmis2.py();
2065 tb[0][2] = -2 * pmis2.pz();
2066 setB(m_nc,pb,-tb);
2067 setBT(pb,m_nc,-tb.T());
2068 break;
2069 }
2070 case 4 : {
2071 HepMatrix ta(1, 2, 0);
2072 double a1 = lambda * lambda + 1;
2073 ta[0][0] = 2 * pmis2.px() * p4Infit(n2).py() - 2 * pmis2.py() * p4Infit(n2).px();
2074 ta[0][1] = 2 * pmis2.px() * p4Infit(n2).px() * lambda/sqrt(a1) + 2 * pmis2.py() * (p4Infit(n2)).py() * lambda/sqrt(a1) - 2 * pmis2.pz() * (p4Infit(n2)).pz() /(sqrt(a1) * lambda);
2075 setA(m_nc,pa,-ta);
2076 setAT(pa, m_nc, -ta.T());
2077
2078 HepMatrix tb(1, 2, 0);
2079 tb[0][0] = 2 * pmis2.px() * (p4Infit(n2)).px() * p4Infit(n2).m() /((p4Infit(n2)).rho() * p4Infit(n2).rho()) + 2 * pmis2.py() * (p4Infit(n2)).py() * p4Infit(n2).m()/((p4Infit(n2)).rho() * p4Infit(n2).rho())+ 2 * pmis2.pz() * (p4Infit(n2)).pz() * p4Infit(n2).m()/((p4Infit(n2)).rho() * p4Infit(n2).rho());
2080 tb[0][1] = 2 * pmis2.e() - 2 * pmis2.px() * (p4Infit(n2)).px() * p4Infit(n2).e() /((p4Infit(n2)).rho() * p4Infit(n2).rho())- 2 * pmis2.py() * (p4Infit(n2)).py() * p4Infit(n2).e()/((p4Infit(n2)).rho() * p4Infit(n2).rho())- 2 * pmis2.pz() * (p4Infit(n2)).pz() * p4Infit(n2).e()/((p4Infit(n2)).rho() * p4Infit(n2).rho());
2081 setB(m_nc,pb,-tb);
2082 setBT(pb, m_nc, -tb.T());
2083 break;
2084 }
2085 case 5 : {
2086 HepMatrix ta(1, 3, 0);
2087 double a1 = lambda * lambda + 1;
2088 ta[0][0] = 2 * pmis2.px() * p4Infit(n2).py() - 2 * pmis2.py() * p4Infit(n2).px();
2089 ta[0][1] = 2 * pmis2.px() * p4Infit(n2).px() * lambda/sqrt(a1) + 2 * pmis2.py() * (p4Infit(n2)).py() * lambda/sqrt(a1) - 2 * pmis2.pz() * (p4Infit(n2)).pz() /(sqrt(a1) * lambda);
2090 ta[0][2] = 2 * pmis2.e() * (p4Infit(n2)).m()/(p4Infit(n2)).e();
2091 setA(m_nc,pa,-ta);
2092 setAT(pa, m_nc, -ta.T());
2093 HepMatrix tb(1, 1, 0);
2094 tb[0][0] = 2 * pmis2.e() * (p4Infit(n2)).rho()/(p4Infit(n2)).e() - 2 * pmis2.px() * (p4Infit(n2)).px()/(p4Infit(n2)).rho() - 2 * pmis2.py() * (p4Infit(n2)).py()/(p4Infit(n2)).rho() - 2 * pmis2.pz() * (p4Infit(n2)).pz()/(p4Infit(n2)).rho();
2095 setB(m_nc,pb,-tb);
2096 setBT(pb, m_nc, -tb.T());
2097 break;
2098 }
2099 case 7 : {
2100 HepMatrix ta(1, NTRKPAR, 0);
2101 ta[0][0] = -2 * pmis2.px() + 2 * pmis2.e() * p4Infit(n2).px() / p4Infit(n2).e();
2102 ta[0][1] = -2 * pmis2.py() + 2 * pmis2.e() * p4Infit(n2).py() / p4Infit(n2).e();
2103 ta[0][2] = -2 * pmis2.pz() + 2 * pmis2.e() * p4Infit(n2).pz() / p4Infit(n2).e();
2104 ta[0][3] = 2 * pmis2.e() * p4Infit(n2).m() / p4Infit(n2).e();
2105 setA(m_nc,pa,-ta);
2106 setAT(pa, m_nc, -ta.T());
2107 break;
2108 }
2109 }
2110 }
2111
2112
2113
2114
2115 HepVector dc(1, 0);
2116 dc[0] = pmis1.m2() - pmis2.m2();
2117 m_G[m_nc] = dc[0];
2118
2119 m_nc+=1;
2120
2121 break;
2122 }
2123
2124
2125 case FourMomentum:
2126 default: {
2127 //
2128 // px - p4x = 0
2129 // py - p4y = 0
2130 // pz - p4z = 0
2131 // e - p4e = 0
2132 //
2133 HepLorentzVector p4 = kc.p4();
2134 HepLorentzVector pmis;
2135 for(unsigned int j = 0; j< (kc.Ltrk()).size(); j++){
2136 int n = (kc.Ltrk())[j];
2137 pmis = pmis + p4Infit(n);
2138 }
2139 for(unsigned int j = 0; j < (kc.Ltrk()).size(); j++) {
2140 int n = (kc.Ltrk())[j];
2141 double lambda = p4Infit(n).pz()/p4Infit(n).perp();
2142 int pa = mappositionA()[n] + 1;
2143 int pb = mappositionB()[n] + 1;
2144 int ptype = mapkinematic()[n];
2145 switch(ptype) {
2146 case 0 : {
2147 HepMatrix ta(kc.nc(), NTRKPAR, 0);
2148 ta[0][0] = 1.0;
2149 ta[1][1] = 1.0;
2150 ta[2][2] = 1.0;
2151 ta[3][0] = p4Infit(n).px() / p4Infit(n).e();
2152 ta[3][1] = p4Infit(n).py() / p4Infit(n).e();
2153 ta[3][2] = p4Infit(n).pz() / p4Infit(n).e();
2154 ta[3][3] = p4Infit(n).m() / p4Infit(n).e();
2155 setA(m_nc, pa, ta);
2156 setAT(pa, m_nc, ta.T());
2157 break;
2158 }
2159 case 1 : {
2160 HepMatrix ta(kc.nc(), NTRKPAR, 0);
2161 ta[0][0] = -p4Infit(n).py();
2162 ta[0][1] = -p4Infit(n).px()*(lambda/(1 + lambda*lambda));
2163 ta[0][2] = -p4Infit(n).m()*p4Infit(n).px()/(p4Infit(n).rho()*p4Infit(n).rho());
2164 ta[0][3] = p4Infit(n).e()*p4Infit(n).px()/(p4Infit(n).rho()*p4Infit(n).rho());
2165 ta[1][0] = p4Infit(n).px();
2166 ta[1][1] = -p4Infit(n).py()*(lambda/(1 + lambda*lambda));
2167 ta[1][2] = -p4Infit(n).m()*p4Infit(n).py()/(p4Infit(n).rho()*p4Infit(n).rho());
2168 ta[1][3] = p4Infit(n).e()*p4Infit(n).py()/(p4Infit(n).rho()*p4Infit(n).rho());
2169 ta[2][0] = 0;
2170 ta[2][1] = p4Infit(n).pz()*(1/(lambda * (1 + lambda*lambda)));
2171 ta[2][2] = -p4Infit(n).m()*p4Infit(n).pz()/(p4Infit(n).rho()*p4Infit(n).rho());
2172 ta[2][3] = p4Infit(n).e()*p4Infit(n).pz()/(p4Infit(n).rho()*p4Infit(n).rho());
2173 ta[3][0] = 0;
2174 ta[3][1] = 0;
2175 ta[3][2] = 0;
2176 ta[3][3] = 1.0;
2177 setA(m_nc, pa, ta);
2178 setAT(pa, m_nc, ta.T());
2179 break;
2180 }
2181 case 2 : {
2182 HepMatrix tb(kc.nc(), 4, 0);
2183 tb[0][0] = 1.0;
2184 tb[1][1] = 1.0;
2185 tb[2][2] = 1.0;
2186 tb[3][3] = 1.0;
2187 setB(m_nc, pb, tb);
2188 setBT(pb, m_nc, tb.T());
2189 break;
2190 }
2191 case 3 : {
2192 HepMatrix ta(kc.nc(), 1, 0);
2193 ta[0][0] = -p4Infit(n).m()*p4Infit(n).px()/(p4Infit(n).rho()*p4Infit(n).rho());
2194 ta[1][0] = -p4Infit(n).m()*p4Infit(n).py()/(p4Infit(n).rho()*p4Infit(n).rho());
2195 ta[2][0] = -p4Infit(n).m()*p4Infit(n).pz()/(p4Infit(n).rho()*p4Infit(n).rho());
2196 ta[3][0] = 0;
2197 setA(m_nc, pa, ta);
2198 setAT(pa, m_nc, ta.T());
2199
2200 HepMatrix tb(kc.nc(), 3, 0);
2201 tb[0][0] = -p4Infit(n).py();
2202 tb[0][1] = -p4Infit(n).px()*(lambda/(1 + lambda*lambda));
2203 tb[0][2] = p4Infit(n).e()*p4Infit(n).px()/(p4Infit(n).rho()*p4Infit(n).rho());
2204 tb[1][0] = p4Infit(n).px();
2205 tb[1][1] = -p4Infit(n).py()*(lambda/(1 + lambda*lambda));
2206 tb[1][2] = p4Infit(n).e()*p4Infit(n).py()/(p4Infit(n).rho()*p4Infit(n).rho());
2207 tb[2][0] = 0;
2208 tb[2][1] = p4Infit(n).pz()*(1/(lambda * (1 + lambda*lambda)));
2209 tb[2][2] = p4Infit(n).e()*p4Infit(n).pz()/(p4Infit(n).rho()*p4Infit(n).rho());
2210 tb[3][0] = 0;
2211 tb[3][1] = 0;
2212 tb[3][2] = 1.0;
2213
2214 setB(m_nc, pb, tb);
2215 setBT(pb, m_nc, tb.T());
2216
2217 break;
2218 }
2219 case 4 : {
2220 HepMatrix ta(kc.nc(), 2, 0);
2221 ta[0][0] = -p4Infit(n).py();
2222 ta[0][1] = -p4Infit(n).px()*(lambda/sqrt(1 + lambda*lambda));
2223 ta[1][0] = p4Infit(n).px();
2224 ta[1][1] = -p4Infit(n).py()*(lambda/sqrt(1 + lambda*lambda));
2225 ta[2][0] = 0;
2226 ta[2][1] = p4Infit(n).pz()*(1/(lambda * (1 + lambda*lambda)));
2227
2228 setA(m_nc, pa, ta);
2229 setAT(pa, m_nc, ta.T());
2230
2231 HepMatrix tb(kc.nc(), 2, 0);
2232 // tb[3][0] = p4Infit(n).m()/p4Infit(n).e();
2233 // tb[0][1] = p4Infit(n).px()/p4Infit(n).rho();
2234 // tb[1][1] = p4Infit(n).py()/p4Infit(n).rho();
2235 // tb[2][1] = p4Infit(n).pz()/p4Infit(n).rho();
2236 // tb[3][1] = p4Infit(n).rho()/p4Infit(n).e();
2237 tb[0][0] = -p4Infit(n).m()*p4Infit(n).px()/(p4Infit(n).rho()*p4Infit(n).rho());
2238 tb[1][0] = -p4Infit(n).m()*p4Infit(n).py()/(p4Infit(n).rho()*p4Infit(n).rho());
2239 tb[2][0] = -p4Infit(n).m()*p4Infit(n).pz()/(p4Infit(n).rho()*p4Infit(n).rho());
2240 tb[0][1] = p4Infit(n).e()*p4Infit(n).px()/(p4Infit(n).rho()*p4Infit(n).rho());
2241 tb[1][1] = p4Infit(n).e()*p4Infit(n).py()/(p4Infit(n).rho()*p4Infit(n).rho());
2242 tb[2][1] = p4Infit(n).e()*p4Infit(n).pz()/(p4Infit(n).rho()*p4Infit(n).rho());
2243 tb[3][1] = 1;
2244 setB(m_nc, pb, tb);
2245 setBT(pb, m_nc, tb.T());
2246 break;
2247 }
2248 case 5 : {
2249 HepMatrix ta(kc.nc(), 3, 0);
2250 ta[0][0] = -p4Infit(n).py();
2251 ta[0][1] = -p4Infit(n).px()*(lambda/sqrt(1 + lambda*lambda));
2252 ta[1][0] = p4Infit(n).px();
2253 ta[1][1] = -p4Infit(n).py()*(lambda/sqrt(1 + lambda*lambda));
2254 ta[2][0] = 0;
2255 ta[2][1] = p4Infit(n).pz()*(1/(lambda * (1 + lambda*lambda)));
2256 ta[3][2] = p4Infit(n).m()/p4Infit(n).e();
2257 setA(m_nc, pa, ta);
2258 setAT(pa, m_nc, ta.T());
2259
2260 HepMatrix tb(kc.nc(), 1, 0);
2261 tb[0][0] = p4Infit(n).px()/p4Infit(n).rho();
2262 tb[1][0] = p4Infit(n).py()/p4Infit(n).rho();
2263 tb[2][0] = p4Infit(n).pz()/p4Infit(n).rho();
2264 tb[3][0] = p4Infit(n).rho()/p4Infit(n).e();
2265 setB(m_nc, pb, tb);
2266 setBT(pb, m_nc, tb.T());
2267 break;
2268 }
2269 case 6 : {
2270 double ptrk = m_p.sub(pa+3, pa+3)[0];
2271 double x = m_p.sub(pa, pa)[0] - m_q.sub(pb, pb)[0];
2272 double y = m_p.sub(pa+1, pa+1)[0] - m_q.sub(pb+1, pb+1)[0];
2273 double z = m_p.sub(pa+2, pa+2)[0] - m_q.sub(pb+2, pb+2)[0];
2274 double R = sqrt(x*x + y*y + z*z);
2275 HepMatrix ta(kc.nc(), 4, 0);
2276 ta[0][0] = ptrk*(y*y + z*z)/(R*R*R);
2277 ta[0][1] = -ptrk*x*y/(R*R*R);
2278 ta[0][2] = -ptrk*x*z/(R*R*R);
2279 ta[0][3] = x/R;
2280 ta[1][0] = -ptrk*y*x/(R*R*R);
2281 ta[1][1] = ptrk*(x*x + z*z)/(R*R*R);
2282 ta[1][2] = -ptrk*y*z/(R*R*R);
2283 ta[1][3] = y/R;
2284 ta[2][0] = -ptrk*z*x/(R*R*R);
2285 ta[2][1] = -ptrk*z*y/(R*R*R);
2286 ta[2][2] = ptrk*(x*x + y*y)/(R*R*R);
2287 ta[2][3] = z/R;
2288 ta[3][3] = 1;
2289 setA(m_nc, pa, ta);
2290 setAT(pa, m_nc, ta.T());
2291
2292 HepMatrix tb(kc.nc(), 3, 0);
2293 tb[0][0] = -ptrk*(y*y + z*z)/(R*R*R);
2294 tb[0][1] = ptrk*x*y/(R*R*R);
2295 tb[0][2] = ptrk*x*z/(R*R*R);
2296 tb[1][0] = ptrk*y*x/(R*R*R);
2297 tb[1][1] = -ptrk*(x*x + z*z)/(R*R*R);
2298 tb[1][2] = ptrk*y*z/(R*R*R);
2299 tb[2][0] = ptrk*z*x/(R*R*R);
2300 tb[2][1] = ptrk*z*y/(R*R*R);
2301 tb[2][2] = -ptrk*(x*x + y*y)/(R*R*R);
2302 HepMatrix tbp = m_B.sub(1, 4, 1, 3);
2303 tb = tbp + tb;
2304 setB(m_nc, pb, tb);
2305 setBT(pb, m_nc, tb.T());
2306 break;
2307 }
2308 case 7 : {
2309 HepMatrix ta(kc.nc(), NTRKPAR, 0);
2310 ta[0][0] = 1.0;
2311 ta[1][1] = 1.0;
2312 ta[2][2] = 1.0;
2313 ta[3][0] = p4Infit(n).px() / p4Infit(n).e();
2314 ta[3][1] = p4Infit(n).py() / p4Infit(n).e();
2315 ta[3][2] = p4Infit(n).pz() / p4Infit(n).e();
2316 ta[3][3] = p4Infit(n).m() / p4Infit(n).e();
2317 setA(m_nc, pa, ta);
2318 setAT(pa, m_nc, ta.T());
2319 break;
2320 }
2321 }
2322 }
2323
2324 HepVector dc(kc.nc(), 0);
2325 dc[0] = pmis.px() - p4.px();
2326 dc[1] = pmis.py() - p4.py();
2327 dc[2] = pmis.pz() - p4.pz();
2328 dc[3] = pmis.e() - p4.e();
2329 for(int i = 0; i < kc.nc(); i++) {
2330 m_G[m_nc+i] = dc[i];
2331 }
2332
2333 m_nc += 4;
2334
2335 break;
2336 }
2337 }
2338}
2339
2340
double mass
const Int_t n
Double_t etot
Double_t x[10]
string::const_iterator ptype
Definition: EvtMTree.hh:19
double w
int dc[18]
Definition: EvtPycont.cc:66
HepGeom::Point3D< double > HepPoint3D
Definition: Gam4pikp.cxx:37
double sin(const BesAngle a)
double cos(const BesAngle a)
const DifComplex I
int n2
Definition: SD0Tag.cxx:55
int n1
Definition: SD0Tag.cxx:54
void AddTotalEnergy(int number, double etot, std::vector< int > lis)
void AddFourMomentum(int number, HepLorentzVector p4)
void AddThreeMomentum(int number, Hep3Vector p3)
void BuildVirtualParticle(int number)
HepSymMatrix getCInfit(int i) const
void AddResonance(int number, double mres, std::vector< int > tlis)
void AddTotalMomentum(int number, double ptot, std::vector< int > lis)
HepSymMatrix getCOrigin(int i) const
static KalmanKinematicFit * instance()
void AddEqualMass(int number, std::vector< int > tlis1, std::vector< int > tlis2)
void FourMomentumConstraints(const HepLorentzVector p4, std::vector< int > tlis, HepSymMatrix Vme)
void ResonanceConstraints(const double mres, std::vector< int > tlis, HepSymMatrix Vre)
void ThreeMomentumConstraints(const Hep3Vector p3, std::vector< int > tlis)
void TotalEnergyConstraints(const double etot, std::vector< int > tlis)
void TotalMomentumConstraints(const double ptot, std::vector< int > tlis)
void EqualMassConstraints(std::vector< int > tlis1, std::vector< int > tlis2, HepSymMatrix Vne)
std::vector< int > AddList(int n1)
Definition: TrackPool.cxx:483
std::vector< WTrackParameter > wTrackInfit() const
void setVBeamPosition(const HepSymMatrix VBeamPosition)
std::vector< GammaShape > GammaShapeValue() const
std::vector< WTrackParameter > wTrackOrigin() const
void setBeamPosition(const HepPoint3D BeamPosition)
void setWTrackInfit(const int n, const WTrackParameter wtrk)
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)
Definition: TUtil.h:27