CMS 3D CMS Logo

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