CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TtFullHadKinFitter.cc
Go to the documentation of this file.
7 
10 
12 
13 static const unsigned int nPartons = 6;
14 
17  : TopKinFitter(),
18  b_(nullptr),
19  bBar_(nullptr),
20  lightQ_(nullptr),
21  lightQBar_(nullptr),
22  lightP_(nullptr),
23  lightPBar_(nullptr),
24  udscResolutions_(nullptr),
25  bResolutions_(nullptr),
26  jetEnergyResolutionScaleFactors_(nullptr),
27  jetEnergyResolutionEtaBinning_(nullptr),
28  jetParam_(kEMom) {
29  setupFitter();
30 }
31 
33 std::vector<TtFullHadKinFitter::Constraint> TtFullHadKinFitter::intToConstraint(
34  const std::vector<unsigned int>& constraints) {
35  std::vector<TtFullHadKinFitter::Constraint> cConstraints;
36  cConstraints.resize(constraints.size());
37  for (unsigned int i = 0; i < constraints.size(); ++i) {
38  cConstraints[i] = (Constraint)constraints[i];
39  }
40  return cConstraints;
41 }
42 
45  int maxNrIter,
46  double maxDeltaS,
47  double maxF,
48  const std::vector<unsigned int>& constraints,
49  double mW,
50  double mTop,
51  const std::vector<edm::ParameterSet>* udscResolutions,
52  const std::vector<edm::ParameterSet>* bResolutions,
53  const std::vector<double>* jetEnergyResolutionScaleFactors,
54  const std::vector<double>* jetEnergyResolutionEtaBinning)
55  : TopKinFitter(maxNrIter, maxDeltaS, maxF, mW, mTop),
56  b_(nullptr),
57  bBar_(nullptr),
58  lightQ_(nullptr),
59  lightQBar_(nullptr),
60  lightP_(nullptr),
61  lightPBar_(nullptr),
62  udscResolutions_(udscResolutions),
63  bResolutions_(bResolutions),
64  jetEnergyResolutionScaleFactors_(jetEnergyResolutionScaleFactors),
65  jetEnergyResolutionEtaBinning_(jetEnergyResolutionEtaBinning),
66  jetParam_((Param)jetParam),
67  constraints_(intToConstraint(constraints)) {
68  setupFitter();
69 }
70 
73  int maxNrIter,
74  double maxDeltaS,
75  double maxF,
76  const std::vector<Constraint>& constraints,
77  double mW,
78  double mTop,
79  const std::vector<edm::ParameterSet>* udscResolutions,
80  const std::vector<edm::ParameterSet>* bResolutions,
81  const std::vector<double>* jetEnergyResolutionScaleFactors,
82  const std::vector<double>* jetEnergyResolutionEtaBinning)
83  : TopKinFitter(maxNrIter, maxDeltaS, maxF, mW, mTop),
84  b_(nullptr),
85  bBar_(nullptr),
86  lightQ_(nullptr),
87  lightQBar_(nullptr),
88  lightP_(nullptr),
89  lightPBar_(nullptr),
90  udscResolutions_(udscResolutions),
91  bResolutions_(bResolutions),
92  jetEnergyResolutionScaleFactors_(jetEnergyResolutionScaleFactors),
93  jetEnergyResolutionEtaBinning_(jetEnergyResolutionEtaBinning),
94  jetParam_(jetParam),
95  constraints_(constraints) {
96  setupFitter();
97 }
98 
101  delete b_;
102  delete bBar_;
103  delete lightQ_;
104  delete lightQBar_;
105  delete lightP_;
106  delete lightPBar_;
107  delete covM_;
108  for (std::map<Constraint, TFitConstraintM*>::iterator it = massConstr_.begin(); it != massConstr_.end(); ++it)
109  delete it->second;
110 }
111 
114  std::stringstream constr;
115  for (unsigned int i = 0; i < constraints_.size(); ++i) {
116  switch (constraints_[i]) {
117  case kWPlusMass:
118  constr << " * W+-mass (" << mW_ << " GeV) \n";
119  break;
120  case kWMinusMass:
121  constr << " * W--mass (" << mW_ << " GeV) \n";
122  break;
123  case kTopMass:
124  constr << " * t-mass (" << mTop_ << " GeV) \n";
125  break;
126  case kTopBarMass:
127  constr << " * tBar-mass (" << mTop_ << " GeV) \n";
128  break;
129  case kEqualTopMasses:
130  constr << " * equal t-masses \n";
131  break;
132  }
133  }
134  edm::LogVerbatim("TtFullHadKinFitter") << "\n"
135  << "+++++++++++ TtFullHadKinFitter Setup ++++++++++++ \n"
136  << " Parametrization: \n"
137  << " * jet : " << param(jetParam_) << "\n"
138  << " Constraints: \n"
139  << constr.str() << " Max(No iterations): " << maxNrIter_ << "\n"
140  << " Max(deltaS) : " << maxDeltaS_ << "\n"
141  << " Max(F) : " << maxF_ << "\n"
142  << "+++++++++++++++++++++++++++++++++++++++++++++++++ \n";
143 }
144 
147  TMatrixD empty3x3(3, 3);
148  TMatrixD empty4x4(4, 4);
149  switch (jetParam_) { // setup jets according to parameterization
150  case kEMom:
151  b_ = new TFitParticleEMomDev("Jet1", "Jet1", nullptr, &empty4x4);
152  bBar_ = new TFitParticleEMomDev("Jet2", "Jet2", nullptr, &empty4x4);
153  lightQ_ = new TFitParticleEMomDev("Jet3", "Jet3", nullptr, &empty4x4);
154  lightQBar_ = new TFitParticleEMomDev("Jet4", "Jet4", nullptr, &empty4x4);
155  lightP_ = new TFitParticleEMomDev("Jet5", "Jet5", nullptr, &empty4x4);
156  lightPBar_ = new TFitParticleEMomDev("Jet6", "Jet6", nullptr, &empty4x4);
157  break;
158  case kEtEtaPhi:
159  b_ = new TFitParticleEtEtaPhi("Jet1", "Jet1", nullptr, &empty3x3);
160  bBar_ = new TFitParticleEtEtaPhi("Jet2", "Jet2", nullptr, &empty3x3);
161  lightQ_ = new TFitParticleEtEtaPhi("Jet3", "Jet3", nullptr, &empty3x3);
162  lightQBar_ = new TFitParticleEtEtaPhi("Jet4", "Jet4", nullptr, &empty3x3);
163  lightP_ = new TFitParticleEtEtaPhi("Jet5", "Jet5", nullptr, &empty3x3);
164  lightPBar_ = new TFitParticleEtEtaPhi("Jet6", "Jet6", nullptr, &empty3x3);
165  break;
166  case kEtThetaPhi:
167  b_ = new TFitParticleEtThetaPhi("Jet1", "Jet1", nullptr, &empty3x3);
168  bBar_ = new TFitParticleEtThetaPhi("Jet2", "Jet2", nullptr, &empty3x3);
169  lightQ_ = new TFitParticleEtThetaPhi("Jet3", "Jet3", nullptr, &empty3x3);
170  lightQBar_ = new TFitParticleEtThetaPhi("Jet4", "Jet4", nullptr, &empty3x3);
171  lightP_ = new TFitParticleEtThetaPhi("Jet5", "Jet5", nullptr, &empty3x3);
172  lightPBar_ = new TFitParticleEtThetaPhi("Jet6", "Jet6", nullptr, &empty3x3);
173  break;
174  }
175 }
176 
179  massConstr_[kWPlusMass] = new TFitConstraintM("WPlusMass", "WPlusMass", nullptr, nullptr, mW_);
180  massConstr_[kWMinusMass] = new TFitConstraintM("WMinusMass", "WMinusMass", nullptr, nullptr, mW_);
181  massConstr_[kTopMass] = new TFitConstraintM("TopMass", "TopMass", nullptr, nullptr, mTop_);
182  massConstr_[kTopBarMass] = new TFitConstraintM("TopBarMass", "TopBarMass", nullptr, nullptr, mTop_);
183  massConstr_[kEqualTopMasses] = new TFitConstraintM("EqualTopMasses", "EqualTopMasses", nullptr, nullptr, 0);
184 
185  massConstr_[kWPlusMass]->addParticles1(lightQ_, lightQBar_);
186  massConstr_[kWMinusMass]->addParticles1(lightP_, lightPBar_);
187  massConstr_[kTopMass]->addParticles1(b_, lightQ_, lightQBar_);
188  massConstr_[kTopBarMass]->addParticles1(bBar_, lightP_, lightPBar_);
189  massConstr_[kEqualTopMasses]->addParticles1(b_, lightQ_, lightQBar_);
191 }
192 
195  printSetup();
196  setupJets();
198 
199  // add measured particles
206 
207  // add constraints
208  for (unsigned int i = 0; i < constraints_.size(); i++) {
210  }
211 
212  // initialize helper class used to bring the resolutions into covariance matrices
213  if (!udscResolutions_->empty() && !bResolutions_->empty())
214  covM_ = new CovarianceMatrix(
216  else
217  covM_ = new CovarianceMatrix();
218 }
219 
221 int TtFullHadKinFitter::fit(const std::vector<pat::Jet>& jets) {
222  if (jets.size() < 6) {
223  throw edm::Exception(edm::errors::Configuration, "Cannot run the TtFullHadKinFitter with less than 6 jets");
224  }
225 
226  // get jets in right order
227  const pat::Jet& b = jets[TtFullHadEvtPartons::B];
228  const pat::Jet& bBar = jets[TtFullHadEvtPartons::BBar];
229  const pat::Jet& lightQ = jets[TtFullHadEvtPartons::LightQ];
230  const pat::Jet& lightQBar = jets[TtFullHadEvtPartons::LightQBar];
231  const pat::Jet& lightP = jets[TtFullHadEvtPartons::LightP];
232  const pat::Jet& lightPBar = jets[TtFullHadEvtPartons::LightPBar];
233 
234  // initialize particles
235  const TLorentzVector p4B(b.px(), b.py(), b.pz(), b.energy());
236  const TLorentzVector p4BBar(bBar.px(), bBar.py(), bBar.pz(), bBar.energy());
237  const TLorentzVector p4LightQ(lightQ.px(), lightQ.py(), lightQ.pz(), lightQ.energy());
238  const TLorentzVector p4LightQBar(lightQBar.px(), lightQBar.py(), lightQBar.pz(), lightQBar.energy());
239  const TLorentzVector p4LightP(lightP.px(), lightP.py(), lightP.pz(), lightP.energy());
240  const TLorentzVector p4LightPBar(lightPBar.px(), lightPBar.py(), lightPBar.pz(), lightPBar.energy());
241 
242  // initialize covariance matrices
243  TMatrixD m1 = covM_->setupMatrix(lightQ, jetParam_);
244  TMatrixD m2 = covM_->setupMatrix(lightQBar, jetParam_);
245  TMatrixD m3 = covM_->setupMatrix(b, jetParam_, "bjets");
246  TMatrixD m4 = covM_->setupMatrix(lightP, jetParam_);
247  TMatrixD m5 = covM_->setupMatrix(lightPBar, jetParam_);
248  TMatrixD m6 = covM_->setupMatrix(bBar, jetParam_, "bjets");
249 
250  // set the kinematics of the objects to be fitted
251  b_->setIni4Vec(&p4B);
252  bBar_->setIni4Vec(&p4BBar);
253  lightQ_->setIni4Vec(&p4LightQ);
254  lightQBar_->setIni4Vec(&p4LightQBar);
255  lightP_->setIni4Vec(&p4LightP);
256  lightPBar_->setIni4Vec(&p4LightPBar);
257 
258  // initialize covariance matrices
259  lightQ_->setCovMatrix(&m1);
260  lightQBar_->setCovMatrix(&m2);
261  b_->setCovMatrix(&m3);
262  lightP_->setCovMatrix(&m4);
263  lightPBar_->setCovMatrix(&m5);
264  bBar_->setCovMatrix(&m6);
265 
266  // perform the fit!
267  fitter_->fit();
268 
269  // add fitted information to the solution
270  if (fitter_->getStatus() == 0) {
271  // read back jet kinematics
273  0,
275  b_->getCurr4Vec()->X(), b_->getCurr4Vec()->Y(), b_->getCurr4Vec()->Z(), b_->getCurr4Vec()->E()),
276  math::XYZPoint()));
279  lightQ_->getCurr4Vec()->Y(),
280  lightQ_->getCurr4Vec()->Z(),
281  lightQ_->getCurr4Vec()->E()),
282  math::XYZPoint()));
285  lightQBar_->getCurr4Vec()->Y(),
286  lightQBar_->getCurr4Vec()->Z(),
287  lightQBar_->getCurr4Vec()->E()),
288  math::XYZPoint()));
289 
291  0,
293  bBar_->getCurr4Vec()->X(), bBar_->getCurr4Vec()->Y(), bBar_->getCurr4Vec()->Z(), bBar_->getCurr4Vec()->E()),
294  math::XYZPoint()));
297  lightP_->getCurr4Vec()->Y(),
298  lightP_->getCurr4Vec()->Z(),
299  lightP_->getCurr4Vec()->E()),
300  math::XYZPoint()));
303  lightPBar_->getCurr4Vec()->Y(),
304  lightPBar_->getCurr4Vec()->Z(),
305  lightPBar_->getCurr4Vec()->E()),
306  math::XYZPoint()));
307  }
308  return fitter_->getStatus();
309 }
310 
313  TtHadEvtSolution fitsol(*asol);
314 
315  std::vector<pat::Jet> jets;
316  jets.resize(6);
317  jets[TtFullHadEvtPartons::LightQ] = fitsol.getCalHadp();
319  jets[TtFullHadEvtPartons::B] = fitsol.getCalHadb();
320  jets[TtFullHadEvtPartons::LightP] = fitsol.getCalHadj();
322  jets[TtFullHadEvtPartons::BBar] = fitsol.getCalHadbbar();
323 
324  fit(jets);
325 
326  // add fitted information to the solution
327  if (fitter_->getStatus() == 0) {
328  // finally fill the fitted particles
329  fitsol.setFitHadb(fittedB_);
330  fitsol.setFitHadp(fittedLightQ_);
332  fitsol.setFitHadk(fittedLightP_);
334  fitsol.setFitHadbbar(fittedBBar_);
335 
336  // store the fit's chi2 probability
337  fitsol.setProbChi2(fitProb());
338  }
339  return fitsol;
340 }
341 
344  : useBTagging_(true),
345  bTags_(2),
346  bTagAlgo_("trackCountingHighPurBJetTags"),
347  minBTagValueBJet_(3.41),
348  maxBTagValueNonBJet_(3.41),
349  udscResolutions_(std::vector<edm::ParameterSet>(0)),
350  bResolutions_(std::vector<edm::ParameterSet>(0)),
351  jetEnergyResolutionScaleFactors_(0),
352  jetEnergyResolutionEtaBinning_(0),
353  jetCorrectionLevel_("L3Absolute"),
354  maxNJets_(-1),
355  maxNComb_(1),
356  maxNrIter_(500),
357  maxDeltaS_(5e-5),
358  maxF_(0.0001),
359  jetParam_(1),
360  mW_(80.4),
361  mTop_(173.),
362  useOnlyMatch_(false),
363  match_(std::vector<int>(0)),
364  invalidMatch_(false) {
365  constraints_.push_back(1);
366  constraints_.push_back(2);
367  constraints_.push_back(5);
368 }
369 
372  unsigned int bTags,
373  std::string bTagAlgo,
374  double minBTagValueBJet,
375  double maxBTagValueNonBJet,
376  const std::vector<edm::ParameterSet>& udscResolutions,
377  const std::vector<edm::ParameterSet>& bResolutions,
378  const std::vector<double>& jetEnergyResolutionScaleFactors,
379  const std::vector<double>& jetEnergyResolutionEtaBinning,
380  std::string jetCorrectionLevel,
381  int maxNJets,
382  int maxNComb,
383  unsigned int maxNrIter,
384  double maxDeltaS,
385  double maxF,
386  unsigned int jetParam,
387  const std::vector<unsigned>& constraints,
388  double mW,
389  double mTop)
390  : useBTagging_(useBTagging),
391  bTags_(bTags),
392  bTagAlgo_(bTagAlgo),
393  minBTagValueBJet_(minBTagValueBJet),
394  maxBTagValueNonBJet_(maxBTagValueNonBJet),
395  udscResolutions_(udscResolutions),
396  bResolutions_(bResolutions),
397  jetEnergyResolutionScaleFactors_(jetEnergyResolutionScaleFactors),
398  jetEnergyResolutionEtaBinning_(jetEnergyResolutionEtaBinning),
399  jetCorrectionLevel_(jetCorrectionLevel),
400  maxNJets_(maxNJets),
401  maxNComb_(maxNComb),
402  maxNrIter_(maxNrIter),
403  maxDeltaS_(maxDeltaS),
404  maxF_(maxF),
405  jetParam_(jetParam),
406  constraints_(constraints),
407  mW_(mW),
408  mTop_(mTop),
409  useOnlyMatch_(false),
410  invalidMatch_(false) {
411  // define kinematic fit interface
413  maxNrIter_,
414  maxDeltaS_,
415  maxF_,
417  mW_,
418  mTop_,
420  &bResolutions_,
423 }
424 
427 
428 bool TtFullHadKinFitter::KinFit::doBTagging(const std::vector<pat::Jet>& jets,
429  const unsigned int& bJetCounter,
430  std::vector<int>& combi) {
431  if (!useBTagging_) {
432  return true;
433  }
434  if (bTags_ == 2 && jets[combi[TtFullHadEvtPartons::B]].bDiscriminator(bTagAlgo_) >= minBTagValueBJet_ &&
435  jets[combi[TtFullHadEvtPartons::BBar]].bDiscriminator(bTagAlgo_) >= minBTagValueBJet_ &&
436  jets[combi[TtFullHadEvtPartons::LightQ]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
437  jets[combi[TtFullHadEvtPartons::LightQBar]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
438  jets[combi[TtFullHadEvtPartons::LightP]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
439  jets[combi[TtFullHadEvtPartons::LightPBar]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_) {
440  return true;
441  } else if (bTags_ == 1) {
442  if (bJetCounter == 1 &&
443  (jets[combi[TtFullHadEvtPartons::B]].bDiscriminator(bTagAlgo_) >= minBTagValueBJet_ ||
444  jets[combi[TtFullHadEvtPartons::BBar]].bDiscriminator(bTagAlgo_) >= minBTagValueBJet_) &&
445  jets[combi[TtFullHadEvtPartons::LightQ]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
446  jets[combi[TtFullHadEvtPartons::LightQBar]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
447  jets[combi[TtFullHadEvtPartons::LightP]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
448  jets[combi[TtFullHadEvtPartons::LightPBar]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_) {
449  return true;
450  } else if (bJetCounter > 1 && jets[combi[TtFullHadEvtPartons::B]].bDiscriminator(bTagAlgo_) >= minBTagValueBJet_ &&
451  jets[combi[TtFullHadEvtPartons::BBar]].bDiscriminator(bTagAlgo_) >= minBTagValueBJet_ &&
452  jets[combi[TtFullHadEvtPartons::LightQ]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
453  jets[combi[TtFullHadEvtPartons::LightQBar]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
454  jets[combi[TtFullHadEvtPartons::LightP]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
455  jets[combi[TtFullHadEvtPartons::LightPBar]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_) {
456  return true;
457  }
458  } else if (bTags_ == 0) {
459  if (bJetCounter == 0) {
460  return true;
461  } else if (bJetCounter == 1 &&
462  (jets[combi[TtFullHadEvtPartons::B]].bDiscriminator(bTagAlgo_) >= minBTagValueBJet_ ||
463  jets[combi[TtFullHadEvtPartons::BBar]].bDiscriminator(bTagAlgo_) >= minBTagValueBJet_) &&
464  jets[combi[TtFullHadEvtPartons::LightQ]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
465  jets[combi[TtFullHadEvtPartons::LightQBar]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
466  jets[combi[TtFullHadEvtPartons::LightP]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
467  jets[combi[TtFullHadEvtPartons::LightPBar]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_) {
468  return true;
469  } else if (bJetCounter > 1 && jets[combi[TtFullHadEvtPartons::B]].bDiscriminator(bTagAlgo_) >= minBTagValueBJet_ &&
470  jets[combi[TtFullHadEvtPartons::BBar]].bDiscriminator(bTagAlgo_) >= minBTagValueBJet_ &&
471  jets[combi[TtFullHadEvtPartons::LightQ]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
472  jets[combi[TtFullHadEvtPartons::LightQBar]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
473  jets[combi[TtFullHadEvtPartons::LightP]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_ &&
474  jets[combi[TtFullHadEvtPartons::LightPBar]].bDiscriminator(bTagAlgo_) < maxBTagValueNonBJet_) {
475  return true;
476  }
477  } else if (bTags_ > 2) {
478  throw cms::Exception("Configuration") << "Wrong number of bTags (" << bTags_ << " bTags not supported)!\n";
479  return true;
480  }
481  return false;
482 }
483 
486  // jetCorrectionLevel was not configured
487  if (jetCorrectionLevel_.empty())
488  throw cms::Exception("Configuration")
489  << "Unconfigured jetCorrectionLevel. Please use an appropriate, non-empty string.\n";
490 
491  // quarkType is unknown
492  if (!(quarkType == "wMix" || quarkType == "uds" || quarkType == "charm" || quarkType == "bottom"))
493  throw cms::Exception("Configuration") << quarkType << " is unknown as a quarkType for the jetCorrectionLevel.\n";
494 
495  float jecFactor = 1.;
496  if (quarkType == "wMix")
497  jecFactor = 0.75 * jet.jecFactor(jetCorrectionLevel_, "uds") + 0.25 * jet.jecFactor(jetCorrectionLevel_, "charm");
498  else
499  jecFactor = jet.jecFactor(jetCorrectionLevel_, quarkType);
500 
501  pat::Jet ret = jet;
502  ret.setP4(ret.p4() * jecFactor);
503  return ret;
504 }
505 
506 std::list<TtFullHadKinFitter::KinFitResult> TtFullHadKinFitter::KinFit::fit(const std::vector<pat::Jet>& jets) {
507  std::list<TtFullHadKinFitter::KinFitResult> fitResults;
508 
515  if (jets.size() < nPartons || invalidMatch_) {
516  // indices referring to the jet combination
517  std::vector<int> invalidCombi;
518  for (unsigned int i = 0; i < nPartons; ++i)
519  invalidCombi.push_back(-1);
520 
522  // status of the fitter
523  result.Status = -1;
524  // chi2
525  result.Chi2 = -1.;
526  // chi2 probability
527  result.Prob = -1.;
528  // the kinFit getters return empty objects here
529  result.B = fitter->fittedB();
530  result.BBar = fitter->fittedBBar();
531  result.LightQ = fitter->fittedLightQ();
532  result.LightQBar = fitter->fittedLightQBar();
533  result.LightP = fitter->fittedLightP();
534  result.LightPBar = fitter->fittedLightPBar();
535  result.JetCombi = invalidCombi;
536  // push back fit result
537  fitResults.push_back(result);
538  return fitResults;
539  }
540 
546  std::vector<int> jetIndices;
547  if (!useOnlyMatch_) {
548  for (unsigned int idx = 0; idx < jets.size(); ++idx) {
549  if (maxNJets_ >= (int)nPartons && maxNJets_ == (int)idx)
550  break;
551  jetIndices.push_back(idx);
552  }
553  }
554 
555  std::vector<int> combi;
556  for (unsigned int idx = 0; idx < nPartons; ++idx) {
557  useOnlyMatch_ ? combi.push_back(match_[idx]) : combi.push_back(idx);
558  }
559 
560  unsigned int bJetCounter = 0;
561  for (std::vector<pat::Jet>::const_iterator jet = jets.begin(); jet < jets.end(); ++jet) {
562  if (jet->bDiscriminator(bTagAlgo_) >= minBTagValueBJet_)
563  ++bJetCounter;
564  }
565 
566  do {
567  for (int cnt = 0; cnt < TMath::Factorial(combi.size()); ++cnt) {
568  // take into account indistinguishability of the two jets from the two W decays,
569  // and the two decay branches, this reduces the combinatorics by a factor of 2*2*2
573  useOnlyMatch_) &&
574  doBTagging(jets, bJetCounter, combi)) {
575  std::vector<pat::Jet> jetCombi;
576  jetCombi.resize(nPartons);
577  jetCombi[TtFullHadEvtPartons::LightQ] = corJet(jets[combi[TtFullHadEvtPartons::LightQ]], "wMix");
578  jetCombi[TtFullHadEvtPartons::LightQBar] = corJet(jets[combi[TtFullHadEvtPartons::LightQBar]], "wMix");
579  jetCombi[TtFullHadEvtPartons::B] = corJet(jets[combi[TtFullHadEvtPartons::B]], "bottom");
580  jetCombi[TtFullHadEvtPartons::BBar] = corJet(jets[combi[TtFullHadEvtPartons::BBar]], "bottom");
581  jetCombi[TtFullHadEvtPartons::LightP] = corJet(jets[combi[TtFullHadEvtPartons::LightP]], "wMix");
582  jetCombi[TtFullHadEvtPartons::LightPBar] = corJet(jets[combi[TtFullHadEvtPartons::LightPBar]], "wMix");
583 
584  // do the kinematic fit
585  int status = fitter->fit(jetCombi);
586 
587  if (status == 0) {
588  // fill struct KinFitResults if converged
590  result.Status = status;
591  result.Chi2 = fitter->fitS();
592  result.Prob = fitter->fitProb();
593  result.B = fitter->fittedB();
594  result.BBar = fitter->fittedBBar();
595  result.LightQ = fitter->fittedLightQ();
596  result.LightQBar = fitter->fittedLightQBar();
597  result.LightP = fitter->fittedLightP();
598  result.LightPBar = fitter->fittedLightPBar();
599  result.JetCombi = combi;
600  // push back fit result
601  fitResults.push_back(result);
602  }
603  }
604  // don't go through combinatorics if useOnlyMatch was chosen
605  if (useOnlyMatch_) {
606  break;
607  }
608  // next permutation
609  std::next_permutation(combi.begin(), combi.end());
610  }
611  // don't go through combinatorics if useOnlyMatch was chosen
612  if (useOnlyMatch_) {
613  break;
614  }
615  } while (stdcomb::next_combination(jetIndices.begin(), jetIndices.end(), combi.begin(), combi.end()));
616 
617  // sort results w.r.t. chi2 values
618  fitResults.sort();
619 
625  if ((unsigned)fitResults.size() < 1) {
626  // in case no fit results were stored in the list (i.e. when all fits were aborted)
627 
629  // status of the fitter
630  result.Status = -1;
631  // chi2
632  result.Chi2 = -1.;
633  // chi2 probability
634  result.Prob = -1.;
635  // the kinFit getters return empty objects here
636  result.B = fitter->fittedB();
637  result.BBar = fitter->fittedBBar();
638  result.LightQ = fitter->fittedLightQ();
639  result.LightQBar = fitter->fittedLightQBar();
640  result.LightP = fitter->fittedLightP();
641  result.LightPBar = fitter->fittedLightPBar();
642  // indices referring to the jet combination
643  std::vector<int> invalidCombi(nPartons, -1);
644  result.JetCombi = invalidCombi;
645  // push back fit result
646  fitResults.push_back(result);
647  }
648  return fitResults;
649 }
650 
653  switch (configParameter) {
655  result = TtFullHadKinFitter::kEMom;
656  break;
659  break;
662  break;
663  default:
664  throw cms::Exception("Configuration")
665  << "Chosen jet parametrization is not supported: " << configParameter << "\n";
666  break;
667  }
668  return result;
669 }
670 
673  switch (configParameter) {
676  break;
679  break;
682  break;
685  break;
688  break;
689  default:
690  throw cms::Exception("Configuration") << "Chosen fit constraint is not supported: " << configParameter << "\n";
691  break;
692  }
693  return result;
694 }
695 
696 std::vector<TtFullHadKinFitter::Constraint> TtFullHadKinFitter::KinFit::constraints(
697  const std::vector<unsigned>& configParameters) {
698  std::vector<TtFullHadKinFitter::Constraint> result;
699  for (unsigned i = 0; i < configParameters.size(); ++i) {
700  result.push_back(constraint(configParameters[i]));
701  }
702  return result;
703 }
TAbsFitParticle * lightQ_
Log< level::Info, true > LogVerbatim
double maxF_
maximal deviation for contstraints
const std::vector< double > * jetEnergyResolutionEtaBinning_
tuple ret
prodAgent to be discontinued
double maxDeltaS_
maximal chi2 equivalent
TtFullHadKinFitter::Param param(unsigned int configParameter)
pat::Jet getCalHadj() const
void setFitHadj(const pat::Particle &aFitHadj)
CovarianceMatrix * covM_
get object resolutions and put them into a matrix
Param
supported parameterizations
Definition: TopKinFitter.h:20
void setupConstraints()
initialize constraints
double pz() const final
z coordinate of momentum vector
TtHadEvtSolution addKinFitInfo(TtHadEvtSolution *asol)
add kin fit information to the old event solution (in for legacy reasons)
TAbsFitParticle * lightP_
Int_t fit()
Definition: TKinFitter.cc:318
TtFullHadKinFitter::Constraint constraint(unsigned int configParameter)
virtual void setIni4Vec(const TLorentzVector *pini)=0
void setFitHadb(const pat::Particle &aFitHadb)
pat::Jet getCalHadq() const
pat::Particle fittedLightPBar_
std::string param(const Param &param) const
convert Param to human readable form
Definition: TopKinFitter.cc:18
pat::Jet getCalHadp() const
list status
Definition: mps_update.py:107
void setFitHadp(const pat::Particle &aFitHadp)
pat::Particle fittedB_
output particles
TMatrixD setupMatrix(const pat::PATObject< T > &object, const TopKinFitter::Param param, const std::string &resolutionProvider="")
return covariance matrix for a PAT object
int fit(const std::vector< pat::Jet > &jets)
kinematic fit interface
void printSetup() const
print fitter setup
TtFullHadKinFitter * fitter
kinematic fit interface
double mW_
W mass value used for constraints.
std::vector< unsigned > constraints_
numbering of different possible kinematic constraints
math::Error< 5 >::type CovarianceMatrix
pat::Particle fittedLightQBar_
const std::vector< double > * jetEnergyResolutionScaleFactors_
scale factors for the jet energy resolution
std::list< TtFullHadKinFitter::KinFitResult > fit(const std::vector< pat::Jet > &jets)
do the fitting and return fit result
int maxNrIter_
maximal allowed number of iterations to be used for the fit
Definition: TopKinFitter.h:49
void setProbChi2(double c)
const LorentzVector & p4() const final
four-momentum Lorentz vector
std::vector< double > jetEnergyResolutionScaleFactors_
scale factors for the jet energy resolution
std::vector< edm::ParameterSet > udscResolutions_
store the resolutions for the jets
double fitProb() const
return fit probability
Definition: TopKinFitter.h:37
tuple m2
Definition: callgraph.py:57
tuple result
Definition: mps_fire.py:311
std::vector< edm::ParameterSet > bResolutions_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
bool doBTagging(const std::vector< pat::Jet > &jets, const unsigned int &bJetCounter, std::vector< int > &combi)
pat::Jet corJet(const pat::Jet &jet, const std::string &quarkType)
helper function to construct the proper corrected jet for its corresponding quarkType ...
std::vector< double > jetEnergyResolutionEtaBinning_
double px() const final
x coordinate of momentum vector
Constraint
supported constraints
unsigned int maxNrIter_
maximal number of iterations to be performed for the fit
std::vector< TtFullHadKinFitter::Constraint > intToConstraint(const std::vector< unsigned int > &constraints)
used to convert vector of int&#39;s to vector of constraints (just used in TtFullHadKinFitter(int, int, double, double, std::vector&lt;unsigned int&gt;))
~TtFullHadKinFitter()
default destructor
const std::vector< edm::ParameterSet > * bResolutions_
void addConstraint(TAbsFitConstraint *constraint)
Definition: TKinFitter.cc:292
vector< PseudoJet > jets
TAbsFitParticle * b_
input particles
pat::Jet getCalHadb() const
Int_t getStatus()
Definition: TKinFitter.h:51
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
pat::Jet getCalHadk() const
double mW_
W mass value used for constraints.
Definition: TopKinFitter.h:55
void addMeasParticle(TAbsFitParticle *particle)
Definition: TKinFitter.cc:194
double py() const final
y coordinate of momentum vector
std::map< Constraint, TFitConstraintM * > massConstr_
supported constraints
std::vector< TtFullHadKinFitter::Constraint > constraints(const std::vector< unsigned int > &configParameters)
pat::Particle fittedLightP_
TAbsFitParticle * lightQBar_
pat::Particle fittedBBar_
double maxDeltaS_
maximal allowed chi2 (not normalized to degrees of freedom)
Definition: TopKinFitter.h:51
double mTop_
top mass value used for constraints
std::vector< Constraint > constraints_
vector of constraints to be used
Param jetParam_
jet parametrization
pat::Particle fittedLightQ_
void setupFitter()
setup fitter
TAbsFitParticle * bBar_
~KinFit()
default destructor
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Analysis-level particle class.
Definition: Particle.h:30
void setFitHadbbar(const pat::Particle &aFitHadbbar)
double b
Definition: hdecay.h:118
const std::vector< edm::ParameterSet > * udscResolutions_
resolutions
Analysis-level calorimeter jet class.
Definition: Jet.h:77
void setFitHadk(const pat::Particle &aFitHadk)
static const unsigned int nPartons
const TLorentzVector * getCurr4Vec()
unsigned int jetParam_
numbering of different possible jet parametrizations
void setFitHadq(const pat::Particle &aFitHadq)
TtFullHadKinFitter()
default constructor
void setupJets()
initialize jet inputs
TKinFitter * fitter_
kinematic fitter
Definition: TopKinFitter.h:47
float jecFactor(const std::string &level, const std::string &flavor="none", const std::string &set="") const
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
Definition: combination.h:19
pat::Jet getCalHadbbar() const
double mTop_
top mass value used for constraints
Definition: TopKinFitter.h:57
void setP4(const LorentzVector &p4) final
set 4-momentum
KinFit()
default constructor
TAbsFitParticle * lightPBar_
double maxF_
maximal allowed distance from constraints
Definition: TopKinFitter.h:53
double energy() const final
energy