CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StKinFitter.cc
Go to the documentation of this file.
1 //
2 //
3 
11 
14 
15 //introduced to repair kinFit w/o resolutions from pat
20 
21 /* other parametrizations and constraints
22 #include "PhysicsTools/KinFitter/interface/TFitParticleESpher.h"
23 #include "PhysicsTools/KinFitter/interface/TFitParticleMCPInvSpher.h"
24 #include "PhysicsTools/KinFitter/interface/TFitConstraintMGaus.h"
25 #include "PhysicsTools/KinFitter/interface/TFitConstraintEp.h"*/
26 
28  TopKinFitter(),
29  jetParam_(kEMom),
30  lepParam_(kEMom),
31  metParam_(kEMom)
32 {
33  setupFitter();
34 }
35 
36 StKinFitter::StKinFitter(int jetParam, int lepParam, int metParam,
37  int maxNrIter, double maxDeltaS, double maxF, const std::vector<int>& constraints) :
38  TopKinFitter(maxNrIter, maxDeltaS, maxF),
39  jetParam_((Param) jetParam),
40  lepParam_((Param) lepParam),
41  metParam_((Param) metParam),
42  constraints_(constraints)
43 {
44  setupFitter();
45 }
46 
47 StKinFitter::StKinFitter(Param jetParam, Param lepParam, Param metParam,
48  int maxNrIter, double maxDeltaS, double maxF, const std::vector<int>& constraints) :
49  TopKinFitter(maxNrIter, maxDeltaS, maxF),
50  jetParam_(jetParam),
51  lepParam_(lepParam),
52  metParam_(metParam),
53  constraints_(constraints)
54 {
55  setupFitter();
56 }
57 
59 {
60  delete cons1_; delete cons2_; delete cons3_;
61  delete fitBottom_; delete fitLight_; delete fitLepton_; delete fitNeutrino_;
62 }
63 
65 {
66  StEvtSolution fitsol(*asol);
67 
68  TMatrixD m1(3,3), m2(3,3);
69  TMatrixD m1b(4,4), m2b(4,4);
70  TMatrixD m3(3,3), m4(3,3);
71  m1.Zero(); m2.Zero();
72  m1b.Zero(); m2b.Zero();
73  m3.Zero(); m4.Zero();
74 
75  TLorentzVector bottomVec(fitsol.getBottom().px(),fitsol.getBottom().py(),
76  fitsol.getBottom().pz(),fitsol.getBottom().energy());
77  TLorentzVector lightVec(fitsol.getLight().px(),fitsol.getLight().py(),
78  fitsol.getLight().pz(),fitsol.getLight().energy());
79  TLorentzVector leplVec;
80  if(fitsol.getDecay()== "electron") leplVec = TLorentzVector(fitsol.getElectron().px(), fitsol.getElectron().py(),
81  fitsol.getElectron().pz(), fitsol.getElectron().energy());
82  if(fitsol.getDecay()== "muon") leplVec = TLorentzVector(fitsol.getMuon().px(), fitsol.getMuon().py(),
83  fitsol.getMuon().pz(), fitsol.getMuon().energy());
84  TLorentzVector lepnVec(fitsol.getNeutrino().px(), fitsol.getNeutrino().py(),
85  0, fitsol.getNeutrino().et());
86 
87  // jet resolutions
88  {
89  //FIXME this dirty hack needs a clean solution soon!
90  double pt = fitsol.getBottom().pt ();
91  double eta = fitsol.getBottom().eta();
92  res::HelperJet jetRes;
93  if (jetParam_ == kEMom) {
94  m1b(0,0) = pow(jetRes.pt (pt, eta, res::HelperJet::kB ), 2);
95  m1b(1,1) = pow(jetRes.pt (pt, eta, res::HelperJet::kB ), 2);
96  m1b(2,2) = pow(jetRes.pt (pt, eta, res::HelperJet::kB ), 2);
97  m1b(3,3) = pow(jetRes.pt (pt, eta, res::HelperJet::kB ), 2);
98  m2b(0,0) = pow(jetRes.pt (pt, eta, res::HelperJet::kUds), 2);
99  m2b(1,1) = pow(jetRes.pt (pt, eta, res::HelperJet::kUds), 2);
100  m2b(2,2) = pow(jetRes.pt (pt, eta, res::HelperJet::kUds), 2);
101  m2b(3,3) = pow(jetRes.pt (pt, eta, res::HelperJet::kUds), 2);
102  } else if (jetParam_ == kEtEtaPhi) {
103  m1 (0,0) = pow(jetRes.pt (pt, eta, res::HelperJet::kB ), 2);
104  m1 (1,1) = pow(jetRes.eta(pt, eta, res::HelperJet::kB ), 2);
105  m1 (2,2) = pow(jetRes.phi(pt, eta, res::HelperJet::kB ), 2);
106  m2 (0,0) = pow(jetRes.pt (pt, eta, res::HelperJet::kUds), 2);
107  m2 (1,1) = pow(jetRes.eta(pt, eta, res::HelperJet::kUds), 2);
108  m2 (2,2) = pow(jetRes.phi(pt, eta, res::HelperJet::kUds), 2);
109  } else if (jetParam_ == kEtThetaPhi) {
110  m1 (0,0) = pow(jetRes.pt (pt, eta, res::HelperJet::kB ), 2);
111  m1 (1,1) = pow(jetRes.eta(pt, eta, res::HelperJet::kB ), 2);
112  m1 (2,2) = pow(jetRes.phi(pt, eta, res::HelperJet::kB ), 2);
113  m2 (0,0) = pow(jetRes.pt (pt, eta, res::HelperJet::kUds), 2);
114  m2 (1,1) = pow(jetRes.eta(pt, eta, res::HelperJet::kUds), 2);
115  m2 (2,2) = pow(jetRes.phi(pt, eta, res::HelperJet::kUds), 2);
116  }
117  }
118  // lepton resolutions
119  {
120  //FIXME this dirty hack needs a clean solution soon!
121  double pt = fitsol.getElectron().pt ();
122  double eta = fitsol.getElectron().eta();
123  res::HelperMuon muonRes;
124  res::HelperElectron elecRes;
125  if (lepParam_ == kEMom) {
126  if(fitsol.getDecay()== "electron"){
127  m3(0,0) = pow(elecRes.pt (pt, eta), 2);
128  m3(1,1) = pow(elecRes.pt (pt, eta), 2);
129  m3(2,2) = pow(elecRes.pt (pt, eta), 2);
130  }
131  if(fitsol.getDecay()== "muon"){
132  m3(0,0) = pow(muonRes.pt (pt, eta), 2);
133  m3(1,1) = pow(muonRes.pt (pt, eta), 2);
134  m3(2,2) = pow(muonRes.pt (pt, eta), 2);
135  }
136  } else if (lepParam_ == kEtEtaPhi) {
137  if(fitsol.getDecay()== "electron"){
138  m3(0,0) = pow(elecRes.pt (pt, eta), 2);
139  m3(1,1) = pow(elecRes.eta(pt, eta), 2);
140  m3(2,2) = pow(elecRes.phi(pt, eta), 2);
141  }
142  if(fitsol.getDecay()== "muon"){
143  m3(0,0) = pow(muonRes.pt (pt, eta), 2);
144  m3(1,1) = pow(muonRes.eta(pt, eta), 2);
145  m3(2,2) = pow(muonRes.phi(pt, eta), 2);
146  }
147  } else if (lepParam_ == kEtThetaPhi) {
148  if(fitsol.getDecay()== "electron"){
149  m3(0,0) = pow(elecRes.pt (pt, eta), 2);
150  m3(1,1) = pow(elecRes.eta(pt, eta), 2);
151  m3(2,2) = pow(elecRes.phi(pt, eta), 2);
152  }
153  if(fitsol.getDecay()== "muon"){
154  m3(0,0) = pow(muonRes.pt (pt, eta), 2);
155  m3(1,1) = pow(muonRes.eta(pt, eta), 2);
156  m3(2,2) = pow(muonRes.phi(pt, eta), 2);
157  }
158  }
159  }
160  // neutrino resolutions
161  {
162  //FIXME this dirty hack needs a clean solution soon!
163  double met = fitsol.getNeutrino().pt();
164  res::HelperMET metRes;
165  if (metParam_ == kEMom) {
166  m4(0,0) = pow(metRes.met(met), 2);
167  m4(1,1) = pow( 9999., 2);
168  m4(2,2) = pow(metRes.met(met), 2);
169  } else if (metParam_ == kEtEtaPhi) {
170  m4(0,0) = pow(metRes.met(met), 2);
171  m4(1,1) = pow( 9999., 2);
172  m4(2,2) = pow(metRes.phi(met), 2);
173  } else if (metParam_ == kEtThetaPhi) {
174  m4(0,0) = pow(metRes.met(met), 2);
175  m4(1,1) = pow( 9999., 2);
176  m4(2,2) = pow(metRes.phi(met), 2);
177  }
178  }
179  // set the kinematics of the objects to be fitted
180  fitBottom_->setIni4Vec(&bottomVec);
181  fitLight_->setIni4Vec(&lightVec);
182  fitLepton_->setIni4Vec(&leplVec);
183  fitNeutrino_->setIni4Vec(&lepnVec);
184  if (jetParam_ == kEMom) {
185  fitBottom_->setCovMatrix(&m1b);
186  fitLight_->setCovMatrix(&m2b);
187  } else {
188  fitBottom_->setCovMatrix(&m1);
189  fitLight_->setCovMatrix(&m2);
190  }
191  fitLepton_->setCovMatrix(&m3);
193 
194  // perform the fit!
195  fitter_->fit();
196 
197  // add fitted information to the solution
198  if (fitter_->getStatus() == 0) {
199  // read back the jet kinematics and resolutions
202 
203  // read back the lepton kinematics and resolutions
205 
206  // read back the MET kinematics and resolutions
208 
209  // finally fill the fitted particles
210  fitsol.setFitBottom(aFitBottom);
211  fitsol.setFitLight(aFitLight);
212  fitsol.setFitLepton(aFitLepton);
213  fitsol.setFitNeutrino(aFitNeutrino);
214 
215  // store the fit's chi2 probability
216  fitsol.setChi2Prob( fitProb() );
217  }
218 
219  return fitsol;
220 
221 }
222 
223 //
224 // Setup the fitter
225 //
227 
228  // FIXME: replace by messagelogger!!!
229 
230  std::cout<<std::endl<<std::endl<<"+++++++++++ KINFIT SETUP ++++++++++++"<<std::endl;
231  std::cout<<" jet parametrisation: " << param(jetParam_) << std::endl;
232  std::cout<<" lepton parametrisation: " << param(lepParam_) << std::endl;
233  std::cout<<" met parametrisation: " << param(metParam_) << std::endl;
234  std::cout<<" constraints: "<<std::endl;
235  for(unsigned int i=0; i<constraints_.size(); i++){
236  if(constraints_[i] == 1) std::cout<<" - hadronic W-mass"<<std::endl;
237  if(constraints_[i] == 2) std::cout<<" - leptonic W-mass"<<std::endl;
238  if(constraints_[i] == 3) std::cout<<" - hadronic top mass"<<std::endl;
239  if(constraints_[i] == 4) std::cout<<" - leptonic top mass"<<std::endl;
240  if(constraints_[i] == 5) std::cout<<" - neutrino mass"<<std::endl;
241  }
242  std::cout<<"Max. number of iterations: "<<maxNrIter_<<std::endl;
243  std::cout<<"Max. deltaS: "<<maxDeltaS_<<std::endl;
244  std::cout<<"Max. F: "<<maxF_<<std::endl;
245  std::cout<<"++++++++++++++++++++++++++++++++++++++++++++"<<std::endl<<std::endl<<std::endl;
246 
247  TMatrixD empty3(3,3); TMatrixD empty4(4,4);
248  if (jetParam_ == kEMom) {
249  fitBottom_ = new TFitParticleEMomDev("Jet1", "Jet1", 0, &empty4);
250  fitLight_ = new TFitParticleEMomDev("Jet2", "Jet2", 0, &empty4);
251  } else if (jetParam_ == kEtEtaPhi) {
252  fitBottom_ = new TFitParticleEtEtaPhi("Jet1", "Jet1", 0, &empty3);
253  fitLight_ = new TFitParticleEtEtaPhi("Jet2", "Jet2", 0, &empty3);
254  } else if (jetParam_ == kEtThetaPhi) {
255  fitBottom_ = new TFitParticleEtThetaPhi("Jet1", "Jet1", 0, &empty3);
256  fitLight_ = new TFitParticleEtThetaPhi("Jet2", "Jet2", 0, &empty3);
257  }
258  if (lepParam_ == kEMom) {
259  fitLepton_ = new TFitParticleEScaledMomDev("Lepton", "Lepton", 0, &empty3);
260  } else if (lepParam_ == kEtEtaPhi) {
261  fitLepton_ = new TFitParticleEtEtaPhi("Lepton", "Lepton", 0, &empty3);
262  } else if (lepParam_ == kEtThetaPhi) {
263  fitLepton_ = new TFitParticleEtThetaPhi("Lepton", "Lepton", 0, &empty3);
264  }
265  if (metParam_ == kEMom) {
266  fitNeutrino_ = new TFitParticleEScaledMomDev("Neutrino", "Neutrino", 0, &empty3);
267  } else if (metParam_ == kEtEtaPhi) {
268  fitNeutrino_ = new TFitParticleEtEtaPhi("Neutrino", "Neutrino", 0, &empty3);
269  } else if (metParam_ == kEtThetaPhi) {
270  fitNeutrino_ = new TFitParticleEtThetaPhi("Neutrino", "Neutrino", 0, &empty3);
271  }
272 
273  cons1_ = new TFitConstraintM("MassConstraint", "Mass-Constraint", 0, 0 , mW_);
275  cons2_ = new TFitConstraintM("MassConstraint", "Mass-Constraint", 0, 0, mTop_);
277  cons3_ = new TFitConstraintM("MassConstraint", "Mass-Constraint", 0, 0, 0.);
279 
280  for (unsigned int i=0; i<constraints_.size(); i++) {
284  }
289 
290 }
virtual double energy() const GCC11_FINAL
energy
double pt(double pt, double eta, Flavor flav)
Definition: Jet.h:25
virtual double et() const GCC11_FINAL
transverse energy
int i
Definition: DBlmapReader.cc:9
TAbsFitParticle * fitLight_
Definition: StKinFitter.h:38
pat::Muon getMuon() const
Definition: StEvtSolution.h:36
tuple met
____________________________________________________________________________||
Definition: CaloMET_cfi.py:4
TFitConstraintM * cons2_
Definition: StKinFitter.h:43
void addParticles1(TAbsFitParticle *p1, TAbsFitParticle *p2=0, TAbsFitParticle *p3=0, TAbsFitParticle *p4=0, TAbsFitParticle *p5=0, TAbsFitParticle *p6=0, TAbsFitParticle *p7=0, TAbsFitParticle *p8=0, TAbsFitParticle *p9=0, TAbsFitParticle *p10=0)
Int_t fit()
Definition: TKinFitter.cc:309
void setupFitter()
Definition: StKinFitter.cc:226
double phi(double pt, double eta, Flavor flav)
Definition: Jet.h:183
virtual void setIni4Vec(const TLorentzVector *pini)=0
double phi(double pt, double eta)
Definition: Electron.h:115
double phi(double pt)
Definition: MET.h:58
std::string param(const Param &param) const
convert Param to human readable form
Definition: TopKinFitter.cc:23
double pt(double pt, double eta)
Definition: Electron.h:23
double eta(double pt, double eta)
Definition: Electron.h:147
T eta() const
int maxNrIter_
maximal allowed number of iterations to be used for the fit
Definition: TopKinFitter.h:48
virtual double pz() const GCC11_FINAL
z coordinate of momentum vector
virtual double py() const GCC11_FINAL
y coordinate of momentum vector
void setFitBottom(const pat::Particle &part)
void setChi2Prob(double prob)
void setFitNeutrino(const pat::Particle &part)
double fitProb() const
return fit probability
Definition: TopKinFitter.h:36
TFitConstraintM * cons3_
Definition: StKinFitter.h:44
TAbsFitParticle * fitBottom_
Definition: StKinFitter.h:37
pat::Jet getBottom() const
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
TAbsFitParticle * fitNeutrino_
Definition: StKinFitter.h:40
Param metParam_
Definition: StKinFitter.h:46
pat::Jet getLight() const
void addConstraint(TAbsFitConstraint *constraint)
Definition: TKinFitter.cc:281
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
Int_t getStatus()
Definition: TKinFitter.h:41
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
std::vector< int > constraints_
Definition: StKinFitter.h:47
void setFitLepton(const pat::Particle &part)
double mW_
W mass value used for constraints.
Definition: TopKinFitter.h:54
void addMeasParticle(TAbsFitParticle *particle)
Definition: TKinFitter.cc:209
double eta(double pt, double eta, Flavor flav)
Definition: Jet.h:241
void setFitLight(const pat::Particle &part)
std::string getDecay() const
Definition: StEvtSolution.h:77
double maxDeltaS_
maximal allowed chi2 (not normalized to degrees of freedom)
Definition: TopKinFitter.h:50
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
pat::MET getNeutrino() const
Definition: StEvtSolution.h:38
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Analysis-level particle class.
Definition: Particle.h:32
Param lepParam_
Definition: StKinFitter.h:46
double eta(double pt, double eta)
Definition: Muon.h:141
TFitConstraintM * cons1_
Definition: StKinFitter.h:42
const TLorentzVector * getCurr4Vec()
void addParticle1(TAbsFitParticle *particle)
double pt(double pt, double eta)
Definition: Muon.h:23
StEvtSolution addKinFitInfo(StEvtSolution *asol)
Definition: StKinFitter.cc:64
tuple cout
Definition: gather_cfg.py:121
TAbsFitParticle * fitLepton_
Definition: StKinFitter.h:39
TKinFitter * fitter_
kinematic fitter
Definition: TopKinFitter.h:46
virtual float pt() const GCC11_FINAL
transverse momentum
Param jetParam_
Definition: StKinFitter.h:46
double phi(double pt, double eta)
Definition: Muon.h:109
double mTop_
top mass value used for constraints
Definition: TopKinFitter.h:56
double met(double met)
Definition: MET.h:23
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
pat::Electron getElectron() const
Definition: StEvtSolution.h:37
double maxF_
maximal allowed distance from constraints
Definition: TopKinFitter.h:52