CMS 3D CMS Logo

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)
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)
52  jetParam_(jetParam),
53  lepParam_(lepParam),
54  metParam_(metParam),
55  constraints_(constraints) {
56  setupFitter();
57 }
58 
59 StKinFitter::~StKinFitter() = default;
60 
62  StEvtSolution fitsol(*asol);
63 
64  TMatrixD m1(3, 3), m2(3, 3);
65  TMatrixD m1b(4, 4), m2b(4, 4);
66  TMatrixD m3(3, 3), m4(3, 3);
67  m1.Zero();
68  m2.Zero();
69  m1b.Zero();
70  m2b.Zero();
71  m3.Zero();
72  m4.Zero();
73 
74  TLorentzVector bottomVec(
75  fitsol.getBottom().px(), fitsol.getBottom().py(), fitsol.getBottom().pz(), fitsol.getBottom().energy());
76  TLorentzVector lightVec(
77  fitsol.getLight().px(), fitsol.getLight().py(), fitsol.getLight().pz(), fitsol.getLight().energy());
78  TLorentzVector leplVec;
79  if (fitsol.getDecay() == "electron")
80  leplVec = TLorentzVector(
81  fitsol.getElectron().px(), fitsol.getElectron().py(), fitsol.getElectron().pz(), fitsol.getElectron().energy());
82  if (fitsol.getDecay() == "muon")
83  leplVec =
84  TLorentzVector(fitsol.getMuon().px(), fitsol.getMuon().py(), fitsol.getMuon().pz(), fitsol.getMuon().energy());
85  TLorentzVector lepnVec(fitsol.getNeutrino().px(), fitsol.getNeutrino().py(), 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);
192  fitNeutrino_->setCovMatrix(&m4);
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
200  pat::Particle aFitBottom(reco::LeafCandidate(0,
201  math::XYZTLorentzVector(fitBottom_->getCurr4Vec()->X(),
202  fitBottom_->getCurr4Vec()->Y(),
203  fitBottom_->getCurr4Vec()->Z(),
204  fitBottom_->getCurr4Vec()->E()),
205  math::XYZPoint()));
207  math::XYZTLorentzVector(fitLight_->getCurr4Vec()->X(),
208  fitLight_->getCurr4Vec()->Y(),
209  fitLight_->getCurr4Vec()->Z(),
210  fitLight_->getCurr4Vec()->E()),
211  math::XYZPoint()));
212 
213  // read back the lepton kinematics and resolutions
214  pat::Particle aFitLepton(reco::LeafCandidate(0,
215  math::XYZTLorentzVector(fitLepton_->getCurr4Vec()->X(),
216  fitLepton_->getCurr4Vec()->Y(),
217  fitLepton_->getCurr4Vec()->Z(),
218  fitLepton_->getCurr4Vec()->E()),
219  math::XYZPoint()));
220 
221  // read back the MET kinematics and resolutions
222  pat::Particle aFitNeutrino(reco::LeafCandidate(0,
223  math::XYZTLorentzVector(fitNeutrino_->getCurr4Vec()->X(),
224  fitNeutrino_->getCurr4Vec()->Y(),
225  fitNeutrino_->getCurr4Vec()->Z(),
226  fitNeutrino_->getCurr4Vec()->E()),
227  math::XYZPoint()));
228 
229  // finally fill the fitted particles
230  fitsol.setFitBottom(aFitBottom);
231  fitsol.setFitLight(aFitLight);
232  fitsol.setFitLepton(aFitLepton);
233  fitsol.setFitNeutrino(aFitNeutrino);
234 
235  // store the fit's chi2 probability
236  fitsol.setChi2Prob(fitProb());
237  }
238 
239  return fitsol;
240 }
241 
242 //
243 // Setup the fitter
244 //
246  // FIXME: replace by messagelogger!!!
247 
248  std::cout << std::endl << std::endl << "+++++++++++ KINFIT SETUP ++++++++++++" << std::endl;
249  std::cout << " jet parametrisation: " << param(jetParam_) << std::endl;
250  std::cout << " lepton parametrisation: " << param(lepParam_) << std::endl;
251  std::cout << " met parametrisation: " << param(metParam_) << std::endl;
252  std::cout << " constraints: " << std::endl;
253  for (unsigned int i = 0; i < constraints_.size(); i++) {
254  if (constraints_[i] == 1)
255  std::cout << " - hadronic W-mass" << std::endl;
256  if (constraints_[i] == 2)
257  std::cout << " - leptonic W-mass" << std::endl;
258  if (constraints_[i] == 3)
259  std::cout << " - hadronic top mass" << std::endl;
260  if (constraints_[i] == 4)
261  std::cout << " - leptonic top mass" << std::endl;
262  if (constraints_[i] == 5)
263  std::cout << " - neutrino mass" << std::endl;
264  }
265  std::cout << "Max. number of iterations: " << maxNrIter_ << std::endl;
266  std::cout << "Max. deltaS: " << maxDeltaS_ << std::endl;
267  std::cout << "Max. F: " << maxF_ << std::endl;
268  std::cout << "++++++++++++++++++++++++++++++++++++++++++++" << std::endl << std::endl << std::endl;
269 
270  TMatrixD empty3(3, 3);
271  TMatrixD empty4(4, 4);
272  if (jetParam_ == kEMom) {
273  fitBottom_ = std::make_unique<TFitParticleEMomDev>("Jet1", "Jet1", nullptr, &empty4);
274  fitLight_ = std::make_unique<TFitParticleEMomDev>("Jet2", "Jet2", nullptr, &empty4);
275  } else if (jetParam_ == kEtEtaPhi) {
276  fitBottom_ = std::make_unique<TFitParticleEtEtaPhi>("Jet1", "Jet1", nullptr, &empty3);
277  fitLight_ = std::make_unique<TFitParticleEtEtaPhi>("Jet2", "Jet2", nullptr, &empty3);
278  } else if (jetParam_ == kEtThetaPhi) {
279  fitBottom_ = std::make_unique<TFitParticleEtThetaPhi>("Jet1", "Jet1", nullptr, &empty3);
280  fitLight_ = std::make_unique<TFitParticleEtThetaPhi>("Jet2", "Jet2", nullptr, &empty3);
281  }
282  if (lepParam_ == kEMom) {
283  fitLepton_ = std::make_unique<TFitParticleEScaledMomDev>("Lepton", "Lepton", nullptr, &empty3);
284  } else if (lepParam_ == kEtEtaPhi) {
285  fitLepton_ = std::make_unique<TFitParticleEtEtaPhi>("Lepton", "Lepton", nullptr, &empty3);
286  } else if (lepParam_ == kEtThetaPhi) {
287  fitLepton_ = std::make_unique<TFitParticleEtThetaPhi>("Lepton", "Lepton", nullptr, &empty3);
288  }
289  if (metParam_ == kEMom) {
290  fitNeutrino_ = std::make_unique<TFitParticleEScaledMomDev>("Neutrino", "Neutrino", nullptr, &empty3);
291  } else if (metParam_ == kEtEtaPhi) {
292  fitNeutrino_ = std::make_unique<TFitParticleEtEtaPhi>("Neutrino", "Neutrino", nullptr, &empty3);
293  } else if (metParam_ == kEtThetaPhi) {
294  fitNeutrino_ = std::make_unique<TFitParticleEtThetaPhi>("Neutrino", "Neutrino", nullptr, &empty3);
295  }
296 
297  cons1_ = std::make_unique<TFitConstraintM>("MassConstraint", "Mass-Constraint", nullptr, nullptr, mW_);
298  cons1_->addParticles1(fitLepton_.get(), fitNeutrino_.get());
299  cons2_ = std::make_unique<TFitConstraintM>("MassConstraint", "Mass-Constraint", nullptr, nullptr, mTop_);
300  cons2_->addParticles1(fitLepton_.get(), fitNeutrino_.get(), fitBottom_.get());
301  cons3_ = std::make_unique<TFitConstraintM>("MassConstraint", "Mass-Constraint", nullptr, nullptr, 0.);
302  cons3_->addParticle1(fitNeutrino_.get());
303 
304  for (unsigned int i = 0; i < constraints_.size(); i++) {
305  if (constraints_[i] == 1)
306  fitter_->addConstraint(cons1_.get());
307  if (constraints_[i] == 2)
308  fitter_->addConstraint(cons2_.get());
309  if (constraints_[i] == 3)
310  fitter_->addConstraint(cons3_.get());
311  }
312  fitter_->addMeasParticle(fitBottom_.get());
313  fitter_->addMeasParticle(fitLight_.get());
314  fitter_->addMeasParticle(fitLepton_.get());
315  fitter_->addMeasParticle(fitNeutrino_.get());
316 }
std::string param(const Param &param) const
convert Param to human readable form
Definition: TopKinFitter.cc:18
double pt(double pt, double eta, Flavor flav)
Definition: Jet.h:26
Param
supported parameterizations
Definition: TopKinFitter.h:22
double pz() const final
z coordinate of momentum vector
double pt() const final
transverse momentum
void setupFitter()
Definition: StKinFitter.cc:245
double phi(double pt, double eta, Flavor flav)
Definition: Jet.h:282
double phi(double pt, double eta)
Definition: Electron.h:160
std::unique_ptr< TKinFitter > fitter_
kinematic fitter
Definition: TopKinFitter.h:49
double phi(double pt)
Definition: MET.h:51
double pt(double pt, double eta)
Definition: Electron.h:24
std::string getDecay() const
Definition: StEvtSolution.h:75
double eta(double pt, double eta)
Definition: Electron.h:210
constexpr int pow(int x)
Definition: conifer.h:24
std::unique_ptr< TFitConstraintM > cons1_
Definition: StKinFitter.h:51
pat::Electron getElectron() const
Definition: StEvtSolution.h:35
int maxNrIter_
maximal allowed number of iterations to be used for the fit
Definition: TopKinFitter.h:51
std::unique_ptr< TFitConstraintM > cons3_
Definition: StKinFitter.h:53
void setFitBottom(const pat::Particle &part)
void setChi2Prob(double prob)
void setFitNeutrino(const pat::Particle &part)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
pat::Jet getLight() const
std::unique_ptr< TAbsFitParticle > fitLight_
Definition: StKinFitter.h:47
double px() const final
x coordinate of momentum vector
Param metParam_
Definition: StKinFitter.h:55
double fitProb() const
return fit probability
Definition: TopKinFitter.h:39
pat::Jet getBottom() const
std::unique_ptr< TFitConstraintM > cons2_
Definition: StKinFitter.h:52
std::unique_ptr< TAbsFitParticle > fitNeutrino_
Definition: StKinFitter.h:49
std::vector< int > constraints_
Definition: StKinFitter.h:56
void setFitLepton(const pat::Particle &part)
double mW_
W mass value used for constraints.
Definition: TopKinFitter.h:57
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
pat::MET getNeutrino() const
Definition: StEvtSolution.h:36
double maxDeltaS_
maximal allowed chi2 (not normalized to degrees of freedom)
Definition: TopKinFitter.h:53
std::unique_ptr< TAbsFitParticle > fitLepton_
Definition: StKinFitter.h:48
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:55
double eta(double pt, double eta)
Definition: Muon.h:204
std::unique_ptr< TAbsFitParticle > fitBottom_
Definition: StKinFitter.h:46
double et() const final
transverse energy
double pt(double pt, double eta)
Definition: Muon.h:24
StEvtSolution addKinFitInfo(StEvtSolution *asol)
Definition: StKinFitter.cc:61
Param jetParam_
Definition: StKinFitter.h:55
double phi(double pt, double eta)
Definition: Muon.h:154
double mTop_
top mass value used for constraints
Definition: TopKinFitter.h:59
double met(double met)
Definition: MET.h:24
double maxF_
maximal allowed distance from constraints
Definition: TopKinFitter.h:55
pat::Muon getMuon() const
Definition: StEvtSolution.h:34
double energy() const final
energy
double eta() const final
momentum pseudorapidity