FairRoot/PandaRoot
Rho4CFitter.cxx
Go to the documentation of this file.
1 // //
3 // Rho4CFitter //
4 // //
5 // Author: K. Goetzen, GSI, 2008 //
6 // //
8 
9 #include <iostream>
10 #include "Rho4CFitter.h"
12 
13 #include "RhoBase/RhoFactory.h"
14 
15 using namespace std;
16 
18 
19 TBuffer& operator>>(TBuffer& buf, Rho4CFitter *&obj)
20 {
21  obj = (Rho4CFitter*) buf.ReadObject(Rho4CFitter::Class());
22  return buf;
23 }
24 
25 Rho4CFitter::Rho4CFitter( RhoCandidate* b , TLorentzVector lv) :
26  RhoFitterBase( b ),
27  fLv4C(lv),
28  fNDau(0),
29  fConserveDaughterMasses(false)
30 {
31  fChiSquare=0.;
32 }
33 
34 
36 {
37 }
38 
40 {
41  for (int i=0; i<l; i++) { std::cout <<" "; }
42  if (c) {
43  printf("[%d, %1.5f]",c->Uid(),c->M());
44  if (c->NDaughters()>0) {
45  cout<<" ->"<<endl;
46  for (int j=0; j<c->NDaughters(); j++) {
47  PrintTree(c->Daughter(j),l+1);
48  }
49  } else { cout<<endl; }
50  }
51 }
52 
54 {
55  fDaughters.clear();
56  FindAndAddFinalStateDaughters(fHeadOfTree); //add all leaves as deep as they are unlocked in fit status!
57  fNDau=fDaughters.size();
58  Bool_t check = Do4CFit();
60  return check;
61 }
62 
63 
65 {
66  fDaughters.clear();
68  fNDau=fDaughters.size();
71  return check;
72 }
73 
74 
75 
76 
78 {
79  int nd=fNDau;
80 
81  TMatrixD al(4*nd,1);
82  TMatrixD V_al0(4*nd,4*nd);
83  TMatrixD V_D(4,4);
84  TMatrixD d(4,1);
85  TMatrixD D(4,4*nd);
86 
87  int k,i,j;
88 
89  for (k=0; k<nd; k++) {
90  TLorentzVector p1=fDaughters[k]->P4();
91  al[k*4+0][0]=p1.X();
92  al[k*4+1][0]=p1.Y();
93  al[k*4+2][0]=p1.Z();
94  al[k*4+3][0]=p1.T();
95 
96  TMatrixD p1Cov=fDaughters[k]->Cov7();
97  for(i=0; i<4; i++) {
98  for (j=0; j<4; j++) {
99  V_al0[k*4+i][k*4+j] = p1Cov[i+3][j+3];
100  V_D[i][j] += p1Cov[i+3][j+3];
101  }
102  }
103 
104  for (i=0; i<4; i++) {
105  D[i][i+k*4] = 1;
106  d[i][0] += al[k*4+i][0];
107  }
108  }
109 
110  TMatrixD D_t(4*nd,4);
111  D_t=D_t.Transpose(D);
112 
113  //cout <<"D_t:"<<endl;
114  //D_t.Print();
115 
116  d[0][0] -= fLv4C.X();
117  d[1][0] -= fLv4C.Y();
118  d[2][0] -= fLv4C.Z();
119  d[3][0] -= fLv4C.T();
120 
121  //cout <<"d:"<<endl;
122  //d.Print();
123 
124 
125  //TMatrixD V_D = D*V_al0*D_t;
126  //cout <<"V_D:"<<endl;
127  //V_D.Print();
128 
129  V_D=V_D.Invert(0);
130 
131  //cout <<"V_D inv:"<<endl;
132  //V_D.Print();
133 
134 
135  TMatrixD lam(4,1);
136 
137  lam=V_D*d;
138  /*
139  for (i=0;i<4;i++)
140  {
141  lam2[i][0]=0;
142  double sum=0;
143  for (j=0;j<4;j++){
144 
145  // cout <<"v:"<<V_D[j][i]<<" d:"<<d[i][0]<<endl;
146  sum+=V_D[i][j]*d[j][0];
147  }
148  lam2[i][0]=sum;
149  }
150  */
151  TMatrixD alnew=al-V_al0*D_t*lam;
152 
153  // Writing results to final state
154 
155  for (k=0; k<nd; k++) {
156  TLorentzVector p1;//=fDaughters[k]->P4();
157  p1.SetX(alnew[k*4+0][0]);
158  p1.SetY(alnew[k*4+1][0]);
159  p1.SetZ(alnew[k*4+2][0]);
160  p1.SetT(alnew[k*4+3][0]);
161  fDaughters[k]->SetP4(p1);
162  }
163  //TMatrixD chi2(1,1);
164 
165  double chi2=0;//lam2[0][0]*d[0][0]+lam2[1][0]*d[1][0]+lam2[2][0]*d[2][0]+lam2[3][0]*d[3][0];
166 
167  for (i=0; i<4; i++) { chi2+=lam[i][0]*d[i][0]; }
168 
169  fChiSquare=chi2;
170  //fNDegreesOfFreedom=4*nd+4-4*nd; //(measurement+constraints-adjusted)
172  return kTRUE;
173 }
174 
175 
176 
177 //Fit conserves the daughter masses (only 3 params per track...)
178 
180 {
181  int nd=fDaughters.size();
182 
183  TMatrixD al(3*nd,1);
184  TMatrixD V_al0(3*nd,3*nd);
185  TMatrixD V_D(4,4);
186  TMatrixD d(4,1);
187  TMatrixD D(4,3*nd);
188 
189  TMatrixD m(nd,1);
190 
191 
192  int k,i,j;
193 
194  for (k=0; k<nd; k++) {
195  TLorentzVector p1=fDaughters[k]->P4();
196  al[k*3+0][0]=p1.X();
197  al[k*3+1][0]=p1.Y();
198  al[k*3+2][0]=p1.Z();
199  //al[k*4+3][0]=p1.T();
200  m[k][0]=p1.M();
201 
202  TMatrixD p1Cov=fDaughters[k]->Cov7();
203  for(i=0; i<3; i++) {
204  for (j=0; j<3; j++) {
205  V_al0[k*3+i][k*3+j] = p1Cov[i+3][j+3];
206  //V_D[i][j] += p1Cov[i+3][j+3];
207  }
208  }
209 
210  for (i=0; i<3; i++) {
211  D[i][k*3+i] = 1;
212  D[3][k*3+i] = al[k*3+i][0]/p1.T();
213  d[i][0] += al[k*3+i][0];
214  }
215  d[3][0] += p1.T();
216  }
217 
218  TMatrixD D_t(3*nd,4);
219  D_t=D_t.Transpose(D);
220 
221  //cout <<"D_t:"<<endl;
222  //D_t.Print();
223 
224  d[0][0] -= fLv4C.X();
225  d[1][0] -= fLv4C.Y();
226  d[2][0] -= fLv4C.Z();
227  d[3][0] -= fLv4C.T();
228 
229  //cout <<"d:"<<endl;
230  //d.Print();
231 
232 
233  V_D = D*V_al0*D_t;
234  //cout <<"V_D:"<<endl;
235  //V_D.Print();
236 
237  V_D=V_D.Invert(0);
238 
239  //cout <<"V_D inv:"<<endl;
240  //V_D.Print();
241 
242 
243  TMatrixD lam(4,1);
244 
245  lam=V_D*d;
246  /*
247  for (i=0;i<4;i++)
248  {
249  lam2[i][0]=0;
250  double sum=0;
251  for (j=0;j<4;j++){
252 
253  // cout <<"v:"<<V_D[j][i]<<" d:"<<d[i][0]<<endl;
254  sum+=V_D[i][j]*d[j][0];
255  }
256  lam2[i][0]=sum;
257  }
258  */
259  TMatrixD alnew=al-V_al0*D_t*lam;
260 
261  // Write to final state/daughters
262  for (k=0; k<nd; k++) {
263  TLorentzVector p1;//=fDaughters[k]->P4();
264  p1.SetXYZM(alnew[k*3+0][0],alnew[k*3+1][0],alnew[k*3+2][0],m[k][0]);
265  fDaughters[k]->SetP4(p1);
266  }
267  //TMatrixD chi2(1,1);
268 
269  double chi2=0;//lam2[0][0]*d[0][0]+lam2[1][0]*d[1][0]+lam2[2][0]*d[2][0]+lam2[3][0]*d[3][0];
270 
271  for (i=0; i<4; i++) { chi2+=lam[i][0]*d[i][0]; }
272 
273  fChiSquare=chi2;
274  //fNDegreesOfFreedom=nd+4;
276  return kTRUE;
277 }
278 
279 
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
virtual ~Rho4CFitter()
Definition: Rho4CFitter.cxx:35
TObjArray * d
Int_t i
Definition: run_full.C:25
__m128 m
Definition: P4_F32vec4.h:28
TTree * b
void FindAndAddFinalStateDaughters(RhoCandidate *cand)
Bool_t FitConserveMasses()
Definition: Rho4CFitter.cxx:64
RhoCandidate * Daughter(Int_t n)
Int_t Uid() const
Definition: RhoCandidate.h:419
TLorentzVector fLv4C
Definition: Rho4CFitter.h:36
void SetFourMomentumByDaughters(RhoCandidate *composite)
Rho4CFitter(RhoCandidate *b, TLorentzVector lv)
Definition: Rho4CFitter.cxx:25
void PrintTree(RhoCandidate *c, int l=0)
Definition: Rho4CFitter.cxx:39
Bool_t Fit()
Definition: Rho4CFitter.cxx:53
std::vector< RhoCandidate * > fDaughters
Definition: RhoFitterBase.h:69
Double_t M() const
Bool_t Do4CFitWithMassConservation()
RhoCandidate * fHeadOfTree
Definition: RhoFitterBase.h:62
Int_t NDaughters() const
double fChiSquare
Definition: RhoFitterBase.h:74
ClassImp(PndAnaContFact)
TPad * p1
Definition: hist-t7.C:116
Bool_t Do4CFit()
Definition: Rho4CFitter.cxx:77
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:52
int fNDegreesOfFreedom
Definition: RhoFitterBase.h:75