FairRoot/PandaRoot
RhoFitterBase.cxx
Go to the documentation of this file.
1 // //
3 // RhoFitterBase //
4 // //
5 // Abstract class for composite particle fitting //
6 // //
7 // Author: Marcel Kunze, RUB, Feb. 99 //
8 // Copyright (C) 1999-2001, Ruhr-University Bochum. //
9 // Ralf Kliemt, HIM/GSI Feb.2013 (Cleanup & Restructuring) //
10 // //
12 
13 #include <assert.h>
14 
15 #include "RhoBase/RhoFitterBase.h"
16 #include "RhoBase/RhoFactory.h"
17 
18 
20 
21 TBuffer& operator>> ( TBuffer& buf, RhoFitterBase *&obj )
22 {
23  obj = ( RhoFitterBase* ) buf.ReadObject ( RhoFitterBase::Class() );
24  return buf;
25 }
26 
27 #include <iostream>
28 using namespace std;
29 
30 RhoFitterBase::RhoFitterBase ( RhoCandidate* head ) : fVerbose ( kFALSE ), fChiSquare(-9999), fNDegreesOfFreedom(-9999)
31 {
32  //fHeadOfTree=CopyCand( head );
33  //TODO do we want to copy the trere here and now?
34  fHeadOfTree=CopyTree(head);
35  fChi2Map.clear();
36 }
37 
39 {
40 }
41 
42 RhoFitterBase::RhoFitterBase ( const RhoFitterBase& other ) : TObject(other), fVerbose ( other.fVerbose )
43 {
44  //fHeadOfTree=CopyCand(*other.fHeadOfTree);
45  //TODO do we want to copy the tree here and now?
47 }
48 
49 
52 {
54  newCand->RemoveAssociations();
55  b->SetFit(newCand);//ready to be modified
56  return newCand;
57 }
58 
59 
62 {
63  //std::cout<<"\n\tcopy tree "<<head->Uid()<<" "<<&head<<" "<<head->PdgCode()<<" "<<head->NDaughters()<<"...";
64  RhoCandidate* headcopy=CopyCand(head);
65  RhoCandidate* daucopy=0;
66  RhoCandidate* dau=0;
67  for(Int_t i=0;i<head->NDaughters();i++)
68  {
69  dau=head->Daughter(i);
70  //std::cout<<" daugter "<<dau->Uid()<<" "<<i<<" "<<dau->PdgCode()<<" at "<<dau<<" ";
71  if(dau == head) {
72  std::cout<<endl<<"*** Candidate is its own mother??? *** \n"<<std::endl;
73  std::cout<<" print: "<<*head<<std::endl;;
74  }
75  assert(dau != head);
76  if(dau->IsComposite()) daucopy=CopyTree(dau);
77  else daucopy=CopyCand(dau);
78  //std::cout<<"CopyTree: copied candidate "<<dau->Uid()<<std::endl;
79  daucopy->SetMotherLink(headcopy); //daughter link is set automatically, too
80  }
81  return headcopy;
82 }
83 
84 
85 
87 {
88  if(!b) return -999.;
89  Int_t uid = b->Uid();
90  Double_t chi2=fChi2Map[uid];
91  return chi2 >=0.0 ? chi2 : -1.;
92 }
93 
94 
96 {
97  fChi2Map.clear();
98  return FitNode(fHeadOfTree);
99 }
100 
102 {
103  if(fHeadOfTree->IsLocked())
104  {
105  Warning("RhoFitterBase::FitAll","You tried to fit a locked candidate. Retuning kFALSE now.");
106  return kFALSE;
107  }
108  return IterateAndFit(fHeadOfTree);
109 }
110 
111 
113 {
114  RhoCandidate* dau=0;
115  Bool_t check = kFALSE;
116  for(Int_t i=0;i<b->NDaughters();i++)
117  {
118  dau=b->Daughter(i);
119  if (dau->IsComposite() && !dau->IsLocked())
120  {
121  check = IterateAndFit(dau);
122  if(kFALSE==check) return kFALSE;
123  }
124  }
125  check = FitNode(b);
126  if(kFALSE==check) return kFALSE;
127  return kTRUE;
128 }
129 
131 {
132  Warning("RhoFitterBase::FitNode","Method not implemented in %s",this->GetName());
133  return kFALSE;
134 }
135 
137 {
138  fDaughters.clear();
139  if(cand->IsComposite()){
140  RhoCandidate* tc;
141  for (int k=0;k<cand->NDaughters();k++) {
142  tc=cand->Daughter(k);
143  fDaughters.push_back(tc);
144  }
145  }
146  return;
147 }
148 
150 {
151  RhoCandidate* tc;
152  for (int k=0;k<cand->NDaughters();k++) {
153  tc=cand->Daughter(k);
154  if (!tc->IsComposite() || tc->IsLocked()) { fDaughters.push_back(tc); }
155  else { FindAndAddFinalStateDaughters(tc); }
156  }
157  return;
158 }
159 
161 {
162  RhoCandidate* tc;
163  TLorentzVector tmpLV;
164  TMatrixD tmpCov(7,7);
165  // Sum daughter fourmomenta, dive into nodes if necessary
166  for (int k=0;k<composite->NDaughters();k++) {
167  tc=composite->Daughter(k);
168  if (tc->IsComposite() && !tc->IsLocked()) { SetFourMomentumByDaughters(tc); }
169  tmpLV += tc->P4();
170  tmpCov = tmpCov + tc->Cov7();
171  }
172  composite->SetP4(tmpLV);
173  composite->SetCov7(tmpCov);
174  //std::cout<<" Base fitter cov7 from tc "<<tc->Uid()<<"/"<<tc->Charge()<<"/"<<tc->PdgCode()<<": ";tmpCov.Print();
175  return;
176 }
177 
178 void RhoFitterBase::SetDecayVertex(RhoCandidate* composite, const TVector3& vtx, const TMatrixD& CovVV)
179 {
180  RhoError decaypointcov(CovVV);
181  RhoVector3Err decayvertex(vtx,decaypointcov);
182  composite->SetDecayVtx(decayvertex);
183 }
184 
185 
int fVerbose
Definition: poormantracks.C:24
virtual Bool_t FitNode(RhoCandidate *b)
Int_t i
Definition: run_full.C:25
TTree * b
void FindAndAddFinalStateDaughters(RhoCandidate *cand)
void SetMotherLink(RhoCandidate *m, bool verbose=true)
Bool_t IsComposite() const
RhoCandidate * Daughter(Int_t n)
Int_t Uid() const
Definition: RhoCandidate.h:419
void SetFourMomentumByDaughters(RhoCandidate *composite)
void SetP4(Double_t mass, const TVector3 &p3)
std::map< Int_t, Double_t > fChi2Map
! each particle&#39;s contribution to the chi^2
Definition: RhoFitterBase.h:80
int uid(int lev, int lrun, int lmode)
Definition: autocutx.C:122
Double_t
Bool_t IsLocked()
Definition: RhoCandidate.h:330
void RemoveAssociations()
double Chi2Contribution(const RhoCandidate *)
TLorentzVector P4() const
Definition: RhoCandidate.h:195
static RhoFactory * Instance()
Definition: RhoFactory.cxx:34
std::vector< RhoCandidate * > fDaughters
Definition: RhoFitterBase.h:69
void SetFit(RhoCandidate *b)
Definition: RhoCandidate.h:292
TMatrixD Cov7() const
static RhoCandidate * NewCandidate()
Definition: RhoFactory.cxx:52
RhoCandidate * fHeadOfTree
Definition: RhoFitterBase.h:62
Int_t NDaughters() const
ClassImp(PndAnaContFact)
Bool_t IterateAndFit(RhoCandidate *b)
void SetDecayVtx(RhoVector3Err theVtx)
RhoCandidate * CopyTree(RhoCandidate *)
RhoCandidate * CopyCand(RhoCandidate *)
uppermost particle composite in tree
void SetDaugthersFromComposite(RhoCandidate *cand)
void SetDecayVertex(RhoCandidate *composite, const TVector3 &vtx, const TMatrixD &CovVV)
void SetCov7(const TMatrixD &cov7)
TMatrixT< double > TMatrixD
Definition: PndLmdDim.h:52