CMS 3D CMS Logo

TtSemiLepKinFitter.cc
Go to the documentation of this file.
8 
11 
13 
16  : TopKinFitter(),
17  hadB_(nullptr),
18  hadP_(nullptr),
19  hadQ_(nullptr),
20  lepB_(nullptr),
21  lepton_(nullptr),
22  neutrino_(nullptr),
23  udscResolutions_(nullptr),
24  bResolutions_(nullptr),
25  lepResolutions_(nullptr),
26  metResolutions_(nullptr),
27  jetEnergyResolutionScaleFactors_(nullptr),
28  jetEnergyResolutionEtaBinning_(nullptr),
29  jetParam_(kEMom),
30  lepParam_(kEMom),
31  metParam_(kEMom) {
32  setupFitter();
33 }
34 
36  Param lepParam,
37  Param metParam,
38  int maxNrIter,
39  double maxDeltaS,
40  double maxF,
41  const std::vector<Constraint>& constraints,
42  double mW,
43  double mTop,
44  const std::vector<edm::ParameterSet>* udscResolutions,
45  const std::vector<edm::ParameterSet>* bResolutions,
46  const std::vector<edm::ParameterSet>* lepResolutions,
47  const std::vector<edm::ParameterSet>* metResolutions,
48  const std::vector<double>* jetEnergyResolutionScaleFactors,
49  const std::vector<double>* jetEnergyResolutionEtaBinning)
50  : TopKinFitter(maxNrIter, maxDeltaS, maxF, mW, mTop),
51  hadB_(nullptr),
52  hadP_(nullptr),
53  hadQ_(nullptr),
54  lepB_(nullptr),
57  udscResolutions_(udscResolutions),
58  bResolutions_(bResolutions),
59  lepResolutions_(lepResolutions),
60  metResolutions_(metResolutions),
61  jetEnergyResolutionScaleFactors_(jetEnergyResolutionScaleFactors),
62  jetEnergyResolutionEtaBinning_(jetEnergyResolutionEtaBinning),
63  jetParam_(jetParam),
64  lepParam_(lepParam),
65  metParam_(metParam),
66  constrList_(constraints) {
67  setupFitter();
68 }
69 
71  delete hadB_;
72  delete hadP_;
73  delete hadQ_;
74  delete lepB_;
75  delete lepton_;
76  delete neutrino_;
77  delete covM_;
78  for (std::map<Constraint, TFitConstraintM*>::iterator it = massConstr_.begin(); it != massConstr_.end(); ++it)
79  delete it->second;
80  delete sumPxConstr_;
81  delete sumPyConstr_;
82 }
83 
85  std::stringstream constr;
86  for (unsigned int i = 0; i < constrList_.size(); ++i) {
87  switch (constrList_[i]) {
88  case kWHadMass:
89  constr << " * hadronic W-mass (" << mW_ << " GeV) \n";
90  break;
91  case kWLepMass:
92  constr << " * leptonic W-mass (" << mW_ << " GeV) \n";
93  break;
94  case kTopHadMass:
95  constr << " * hadronic t-mass (" << mTop_ << " GeV) \n";
96  break;
97  case kTopLepMass:
98  constr << " * leptonic t-mass (" << mTop_ << " GeV) \n";
99  break;
100  case kNeutrinoMass:
101  constr << " * neutrino mass (0 GeV) \n";
102  break;
103  case kEqualTopMasses:
104  constr << " * equal t-masses \n";
105  break;
106  case kSumPt:
107  constr << " * summed transverse momentum \n";
108  break;
109  }
110  }
111  edm::LogVerbatim("TtSemiLepKinFitter") << "\n"
112  << "+++++++++++ TtSemiLepKinFitter Setup ++++++++++++ \n"
113  << " Parametrization: \n"
114  << " * jet : " << param(jetParam_) << "\n"
115  << " * lep : " << param(lepParam_) << "\n"
116  << " * met : " << param(metParam_) << "\n"
117  << " Constraints: \n"
118  << constr.str() << " Max(No iterations): " << maxNrIter_ << "\n"
119  << " Max(deltaS) : " << maxDeltaS_ << "\n"
120  << " Max(F) : " << maxF_ << "\n"
121  << "+++++++++++++++++++++++++++++++++++++++++++++++++ \n";
122 }
123 
125  TMatrixD empty3x3(3, 3);
126  TMatrixD empty4x4(4, 4);
127  switch (jetParam_) { // setup jets according to parameterization
128  case kEMom:
129  hadB_ = new TFitParticleEMomDev("Jet1", "Jet1", nullptr, &empty4x4);
130  hadP_ = new TFitParticleEMomDev("Jet2", "Jet2", nullptr, &empty4x4);
131  hadQ_ = new TFitParticleEMomDev("Jet3", "Jet3", nullptr, &empty4x4);
132  lepB_ = new TFitParticleEMomDev("Jet4", "Jet4", nullptr, &empty4x4);
133  break;
134  case kEtEtaPhi:
135  hadB_ = new TFitParticleEtEtaPhi("Jet1", "Jet1", nullptr, &empty3x3);
136  hadP_ = new TFitParticleEtEtaPhi("Jet2", "Jet2", nullptr, &empty3x3);
137  hadQ_ = new TFitParticleEtEtaPhi("Jet3", "Jet3", nullptr, &empty3x3);
138  lepB_ = new TFitParticleEtEtaPhi("Jet4", "Jet4", nullptr, &empty3x3);
139  break;
140  case kEtThetaPhi:
141  hadB_ = new TFitParticleEtThetaPhi("Jet1", "Jet1", nullptr, &empty3x3);
142  hadP_ = new TFitParticleEtThetaPhi("Jet2", "Jet2", nullptr, &empty3x3);
143  hadQ_ = new TFitParticleEtThetaPhi("Jet3", "Jet3", nullptr, &empty3x3);
144  lepB_ = new TFitParticleEtThetaPhi("Jet4", "Jet4", nullptr, &empty3x3);
145  break;
146  }
147 }
148 
150  TMatrixD empty3x3(3, 3);
151  switch (lepParam_) { // setup lepton according to parameterization
152  case kEMom:
153  lepton_ = new TFitParticleEScaledMomDev("Lepton", "Lepton", nullptr, &empty3x3);
154  break;
155  case kEtEtaPhi:
156  lepton_ = new TFitParticleEtEtaPhi("Lepton", "Lepton", nullptr, &empty3x3);
157  break;
158  case kEtThetaPhi:
159  lepton_ = new TFitParticleEtThetaPhi("Lepton", "Lepton", nullptr, &empty3x3);
160  break;
161  }
162  switch (metParam_) { // setup neutrino according to parameterization
163  case kEMom:
164  neutrino_ = new TFitParticleEScaledMomDev("Neutrino", "Neutrino", nullptr, &empty3x3);
165  break;
166  case kEtEtaPhi:
167  neutrino_ = new TFitParticleEtEtaPhi("Neutrino", "Neutrino", nullptr, &empty3x3);
168  break;
169  case kEtThetaPhi:
170  neutrino_ = new TFitParticleEtThetaPhi("Neutrino", "Neutrino", nullptr, &empty3x3);
171  break;
172  }
173 }
174 
176  massConstr_[kWHadMass] = new TFitConstraintM("WMassHad", "WMassHad", nullptr, nullptr, mW_);
177  massConstr_[kWLepMass] = new TFitConstraintM("WMassLep", "WMassLep", nullptr, nullptr, mW_);
178  massConstr_[kTopHadMass] = new TFitConstraintM("TopMassHad", "TopMassHad", nullptr, nullptr, mTop_);
179  massConstr_[kTopLepMass] = new TFitConstraintM("TopMassLep", "TopMassLep", nullptr, nullptr, mTop_);
180  massConstr_[kNeutrinoMass] = new TFitConstraintM("NeutrinoMass", "NeutrinoMass", nullptr, nullptr, 0.);
181  massConstr_[kEqualTopMasses] = new TFitConstraintM("EqualTopMasses", "EqualTopMasses", nullptr, nullptr, 0.);
182  sumPxConstr_ = new TFitConstraintEp("SumPx", "SumPx", nullptr, TFitConstraintEp::pX, 0.);
183  sumPyConstr_ = new TFitConstraintEp("SumPy", "SumPy", nullptr, TFitConstraintEp::pY, 0.);
184 
185  massConstr_[kWHadMass]->addParticles1(hadP_, hadQ_);
186  massConstr_[kWLepMass]->addParticles1(lepton_, neutrino_);
187  massConstr_[kTopHadMass]->addParticles1(hadP_, hadQ_, hadB_);
188  massConstr_[kTopLepMass]->addParticles1(lepton_, neutrino_, lepB_);
189  massConstr_[kNeutrinoMass]->addParticle1(neutrino_);
190  massConstr_[kEqualTopMasses]->addParticles1(hadP_, hadQ_, hadB_);
194 
195  if (std::find(constrList_.begin(), constrList_.end(), kSumPt) != constrList_.end())
196  constrainSumPt_ = true;
197  constrainSumPt_ = false;
198 }
199 
201  printSetup();
202 
203  setupJets();
204  setupLeptons();
206 
207  // add measured particles
214 
215  // add constraints
216  for (unsigned int i = 0; i < constrList_.size(); i++) {
217  if (constrList_[i] != kSumPt)
219  }
220  if (constrainSumPt_) {
223  }
224 
225  // initialize helper class used to bring the resolutions into covariance matrices
226  if (!udscResolutions_->empty() && !bResolutions_->empty() && !lepResolutions_->empty() && !metResolutions_->empty())
228  *bResolutions_,
233  else
234  covM_ = new CovarianceMatrix();
235 }
236 
237 int TtSemiLepKinFitter::fit(const TLorentzVector& p4HadP,
238  const TLorentzVector& p4HadQ,
239  const TLorentzVector& p4HadB,
240  const TLorentzVector& p4LepB,
241  const TLorentzVector& p4Lepton,
242  const TLorentzVector& p4Neutrino,
243  const int leptonCharge,
245  // initialize covariance matrices
246  TMatrixD covHadP = covM_->setupMatrix(p4HadP, CovarianceMatrix::kUdscJet, jetParam_);
247  TMatrixD covHadQ = covM_->setupMatrix(p4HadQ, CovarianceMatrix::kUdscJet, jetParam_);
248  TMatrixD covHadB = covM_->setupMatrix(p4HadB, CovarianceMatrix::kBJet, jetParam_);
249  TMatrixD covLepB = covM_->setupMatrix(p4LepB, CovarianceMatrix::kBJet, jetParam_);
250  TMatrixD covLepton = covM_->setupMatrix(p4Lepton, leptonType, lepParam_);
251  TMatrixD covNeutrino = covM_->setupMatrix(p4Neutrino, CovarianceMatrix::kMet, metParam_);
252 
253  // now do the part that is fully independent of PAT features
254  return fit(p4HadP,
255  p4HadQ,
256  p4HadB,
257  p4LepB,
258  p4Lepton,
259  p4Neutrino,
260  covHadP,
261  covHadQ,
262  covHadB,
263  covLepB,
264  covLepton,
265  covNeutrino,
266  leptonCharge);
267 }
268 
269 int TtSemiLepKinFitter::fit(const TLorentzVector& p4HadP,
270  const TLorentzVector& p4HadQ,
271  const TLorentzVector& p4HadB,
272  const TLorentzVector& p4LepB,
273  const TLorentzVector& p4Lepton,
274  const TLorentzVector& p4Neutrino,
275  const TMatrixD& covHadP,
276  const TMatrixD& covHadQ,
277  const TMatrixD& covHadB,
278  const TMatrixD& covLepB,
279  const TMatrixD& covLepton,
280  const TMatrixD& covNeutrino,
281  const int leptonCharge) {
282  // set the kinematics of the objects to be fitted
283  hadP_->setIni4Vec(&p4HadP);
284  hadQ_->setIni4Vec(&p4HadQ);
285  hadB_->setIni4Vec(&p4HadB);
286  lepB_->setIni4Vec(&p4LepB);
287  lepton_->setIni4Vec(&p4Lepton);
288  neutrino_->setIni4Vec(&p4Neutrino);
289 
290  hadP_->setCovMatrix(&covHadP);
291  hadQ_->setCovMatrix(&covHadQ);
292  hadB_->setCovMatrix(&covHadB);
293  lepB_->setCovMatrix(&covLepB);
294  lepton_->setCovMatrix(&covLepton);
295  neutrino_->setCovMatrix(&covNeutrino);
296 
297  if (constrainSumPt_) {
298  // setup Px and Py constraint for curent event configuration so that sum Pt will be conserved
299  sumPxConstr_->setConstraint(p4HadP.Px() + p4HadQ.Px() + p4HadB.Px() + p4LepB.Px() + p4Lepton.Px() +
300  p4Neutrino.Px());
301  sumPyConstr_->setConstraint(p4HadP.Py() + p4HadQ.Py() + p4HadB.Py() + p4LepB.Py() + p4Lepton.Py() +
302  p4Neutrino.Py());
303  }
304 
305  // now do the fit
306  fitter_->fit();
307 
308  // read back the resulting particles if the fit converged
309  if (fitter_->getStatus() == 0) {
310  // read back jet kinematics
312  0,
314  hadP_->getCurr4Vec()->X(), hadP_->getCurr4Vec()->Y(), hadP_->getCurr4Vec()->Z(), hadP_->getCurr4Vec()->E()),
315  math::XYZPoint()));
317  0,
319  hadQ_->getCurr4Vec()->X(), hadQ_->getCurr4Vec()->Y(), hadQ_->getCurr4Vec()->Z(), hadQ_->getCurr4Vec()->E()),
320  math::XYZPoint()));
322  0,
324  hadB_->getCurr4Vec()->X(), hadB_->getCurr4Vec()->Y(), hadB_->getCurr4Vec()->Z(), hadB_->getCurr4Vec()->E()),
325  math::XYZPoint()));
327  0,
329  lepB_->getCurr4Vec()->X(), lepB_->getCurr4Vec()->Y(), lepB_->getCurr4Vec()->Z(), lepB_->getCurr4Vec()->E()),
330  math::XYZPoint()));
331 
332  // read back lepton kinematics
335  lepton_->getCurr4Vec()->Y(),
336  lepton_->getCurr4Vec()->Z(),
337  lepton_->getCurr4Vec()->E()),
338  math::XYZPoint()));
339 
340  // read back the MET kinematics
343  neutrino_->getCurr4Vec()->Y(),
344  neutrino_->getCurr4Vec()->Z(),
345  neutrino_->getCurr4Vec()->E()),
346  math::XYZPoint()));
347  }
348  return fitter_->getStatus();
349 }
350 
352  TtSemiEvtSolution fitsol(*asol);
353 
354  std::vector<pat::Jet> jets;
355  jets.resize(4);
356  jets[TtSemiLepEvtPartons::LightQ] = fitsol.getCalHadp();
358  jets[TtSemiLepEvtPartons::HadB] = fitsol.getCalHadb();
359  jets[TtSemiLepEvtPartons::LepB] = fitsol.getCalLepb();
360 
361  // perform the fit, either using the electron or the muon
362  if (fitsol.getDecay() == "electron")
363  fit(jets, fitsol.getCalLepe(), fitsol.getCalLepn());
364  if (fitsol.getDecay() == "muon")
365  fit(jets, fitsol.getCalLepm(), fitsol.getCalLepn());
366 
367  // add fitted information to the solution
368  if (fitter_->getStatus() == 0) {
369  // fill the fitted particles
370  fitsol.setFitHadb(fittedHadB());
371  fitsol.setFitHadp(fittedHadP());
372  fitsol.setFitHadq(fittedHadQ());
373  fitsol.setFitLepb(fittedLepB());
374  fitsol.setFitLepl(fittedLepton());
375  fitsol.setFitLepn(fittedNeutrino());
376  // store the fit's chi2 probability
377  fitsol.setProbChi2(fitProb());
378  }
379  return fitsol;
380 }
void setFitHadq(const pat::Particle &aFitHadq)
const pat::Particle fittedHadP() const
return hadronic light quark candidate
void setFitHadb(const pat::Particle &aFitHadb)
TAbsFitParticle * hadB_
input particles
Param
supported parameterizations
Definition: TopKinFitter.h:20
const std::vector< edm::ParameterSet > * udscResolutions_
resolutions
TAbsFitParticle * neutrino_
Int_t fit()
Definition: TKinFitter.cc:318
const pat::Particle fittedNeutrino() const
return neutrino candidate
const pat::Particle fittedLepB() const
return leptonic b quark candidate
TAbsFitParticle * hadQ_
pat::Jet getCalHadq() const
virtual void setIni4Vec(const TLorentzVector *pini)=0
bool constrainSumPt_
internally use simple boolean for this constraint to reduce the per-event computing time ...
#define nullptr
std::string param(const Param &param) const
convert Param to human readable form
Definition: TopKinFitter.cc:18
pat::MET getCalLepn() const
TMatrixD setupMatrix(const pat::PATObject< T > &object, const TopKinFitter::Param param, const std::string &resolutionProvider="")
return covariance matrix for a PAT object
std::string getDecay() const
TFitConstraintEp * sumPyConstr_
math::Error< 5 >::type CovarianceMatrix
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void addParticles(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)
int maxNrIter_
maximal allowed number of iterations to be used for the fit
Definition: TopKinFitter.h:49
pat::Particle fittedHadP_
double fitProb() const
return fit probability
Definition: TopKinFitter.h:37
pat::Particle fittedLepB_
Param lepParam_
lepton parametrization
pat::Particle fittedHadB_
output particles
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
pat::Electron getCalLepe() const
const std::vector< edm::ParameterSet > * bResolutions_
leptonType
LEPTON
Definition: autophobj.py:48
TAbsFitParticle * lepton_
int fit(const std::vector< pat::Jet > &jets, const pat::Lepton< LeptonType > &leps, const pat::MET &met)
kinematic fit interface for PAT objects
void setupJets()
initialize jet inputs
const std::vector< edm::ParameterSet > * lepResolutions_
void printSetup() const
print fitter setup
void setFitLepb(const pat::Particle &aFitLepb)
pat::Particle fittedLepton_
void addConstraint(TAbsFitConstraint *constraint)
Definition: TKinFitter.cc:292
TAbsFitParticle * hadP_
void setFitHadp(const pat::Particle &aFitHadp)
const std::vector< double > * jetEnergyResolutionScaleFactors_
scale factors for the jet energy resolution
Int_t getStatus()
Definition: TKinFitter.h:51
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
Param jetParam_
jet parametrization
const pat::Particle fittedHadB() const
return hadronic b quark candidate
double mW_
W mass value used for constraints.
Definition: TopKinFitter.h:55
void addMeasParticle(TAbsFitParticle *particle)
Definition: TKinFitter.cc:194
TtSemiLepKinFitter()
default constructor
std::map< Constraint, TFitConstraintM * > massConstr_
supported constraints
Param metParam_
met parametrization
CovarianceMatrix * covM_
object used to construct the covariance matrices for the individual particles
pat::Particle fittedHadQ_
pat::Muon getCalLepm() const
void setConstraint(Double_t constraint)
double maxDeltaS_
maximal allowed chi2 (not normalized to degrees of freedom)
Definition: TopKinFitter.h:51
pat::Jet getCalHadb() const
TtSemiEvtSolution addKinFitInfo(TtSemiEvtSolution *asol)
add kin fit information to the old event solution (in for legacy reasons)
~TtSemiLepKinFitter()
default destructor
void setupConstraints()
initialize constraints
std::vector< Constraint > constrList_
vector of constraints to be used
void setupLeptons()
initialize lepton inputs
TFitConstraintEp * sumPxConstr_
void setFitLepn(const pat::Particle &aFitLepn)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Analysis-level particle class.
Definition: Particle.h:30
const pat::Particle fittedHadQ() const
return hadronic light quark candidate
const TLorentzVector * getCurr4Vec()
const pat::Particle fittedLepton() const
return lepton candidate
void setProbChi2(double c)
pat::Jet getCalLepb() const
void setupFitter()
setup fitter
pat::Particle fittedNeutrino_
const std::vector< double > * jetEnergyResolutionEtaBinning_
TKinFitter * fitter_
kinematic fitter
Definition: TopKinFitter.h:47
void setFitLepl(const pat::Particle &aFitLepl)
double mTop_
top mass value used for constraints
Definition: TopKinFitter.h:57
TAbsFitParticle * lepB_
double maxF_
maximal allowed distance from constraints
Definition: TopKinFitter.h:53
pat::Jet getCalHadp() const
const std::vector< edm::ParameterSet > * metResolutions_