CMS 3D CMS Logo

RunHitFit.h
Go to the documentation of this file.
1 //
2 //
3 
19 #ifndef HITFIT_RUNHITFIT_H
20 #define HITFIT_RUNHITFIT_H
21 
22 #include <algorithm>
23 
31 
32 // Explanation about the MIN/MAX definitions:
33 //
34 // For a given number of jets, there is a corresponding number of
35 // permutations how to assign each jet in the event to the corresponding
36 // parton-level jet.
37 // The number of permutations up to 10 jets are given below for Tt and
38 // TtH events.
39 //
40 // NJet Npermutation (Tt) Npermutation (TtH)
41 // 4 24 --
42 // 5 120 --
43 // 6 360 360
44 // 7 840 2520
45 // 8 1680 10080
46 // 9 3024 30240
47 // 10 5040 75600
48 //
49 // The formulas for the number of permutations for Tt and TtH events
50 // given n jets in the event are
51 //
52 // n!
53 // Tt: -------- ; n >= 4
54 // (n - 4)!
55 //
56 // n!
57 // TtH: ---------- ; n >= 6
58 // (n - 6)!2!
59 //
60 // The current MAX settings are chosen for a maximum number of 8 jets
61 // Increasing this limit should be done with caution, as it will
62 // increase the number of permutations rapidly.
63 //
64 
65 namespace hitfit {
66 
152  template <class AElectron, class AMuon, class AJet, class AMet>
153  class RunHitFit {
154  private:
159 
164 
169 
174 
181 
196  std::vector<AJet> _jets;
197 
208 
213 
217  std::vector<Lepjets_Event> _Unfitted_Events;
218 
222  std::vector<Fit_Result> _Fit_Results;
223 
224  public:
256  const std::string default_file,
257  double lepw_mass,
258  double hadw_mass,
259  double top_mass)
260  : _ElectronTranslator(el),
264  _event(0, 0),
265  _jetObjRes(false),
266  _Top_Fit(Top_Fit_Args(Defaults_Text(default_file)), lepw_mass, hadw_mass, top_mass) {}
267 
272 
276  void clear() {
277  _event = Lepjets_Event(0, 0);
278  _jets.clear();
279  _jetObjRes = false;
280  _Unfitted_Events.clear();
281  _Fit_Results.clear();
282  }
283 
293  void AddLepton(const AElectron& electron, bool useObjRes = false) {
295  return;
296  }
297 
307  void AddLepton(const AMuon& muon, bool useObjRes = false) {
309  return;
310  }
311 
332  void AddJet(const AJet& jet, bool useObjRes = false) {
333  // Only set flag when adding the first jet
334  // the additional jets then WILL be treated in the
335  // same way like the first jet.
336  if (_jets.empty()) {
337  _jetObjRes = useObjRes;
338  }
339 
340  if (_jets.size() < MAX_HITFIT_JET) {
341  _jets.push_back(jet);
342  }
343  return;
344  }
345 
349  void SetMet(const AMet& met, bool useObjRes = false) {
350  _event.met() = _METTranslator(met, useObjRes);
351  _event.kt_res() = _METTranslator.KtResolution(met, useObjRes);
352  return;
353  }
354 
361  _event.kt_res() = res;
362  return;
363  }
364 
373  return;
374  }
375 
379  const Top_Fit& GetTopFit() const { return _Top_Fit; }
380 
386  if (_jets.size() < MIN_HITFIT_JET) {
387  // For ttbar lepton+jets, a minimum of MIN_HITFIT_JETS jets
388  // is required
389  return 0;
390  }
391 
392  if (_jets.size() > MAX_HITFIT_JET) {
393  // Restrict the maximum number of jets in the fit
394  // to prevent loop overflow
395  return 0;
396  }
397 
398  _Unfitted_Events.clear();
399  _Fit_Results.clear();
400 
401  // Prepare the array of jet types for permutation
402  std::vector<int> jet_types(_jets.size(), unknown_label);
403  jet_types[0] = lepb_label;
404  jet_types[1] = hadb_label;
405  jet_types[2] = hadw1_label;
406  jet_types[3] = hadw1_label;
407 
408  if (_Top_Fit.args().do_higgs_flag() && _jets.size() >= MIN_HITFIT_TTH) {
409  jet_types[4] = higgs_label;
410  jet_types[5] = higgs_label;
411  }
412 
413  std::stable_sort(jet_types.begin(), jet_types.end());
414 
415  do {
416  // begin loop over all jet permutation
417  for (int nusol = 0; nusol != 2; nusol++) {
418  // loop over two neutrino solution
419  bool nuz = bool(nusol);
420 
421  // Copy the event
422  Lepjets_Event fev = _event;
423 
424  // Add jets into the event, with the assumed type
425  // in accord with the permutation.
426  // The translator _JetTranslator will correctly
427  // return object of Lepjets_Event_Jet with
428  // jet energy correction applied in accord with
429  // the assumed jet type (b or light).
430  for (size_t j = 0; j != _jets.size(); j++) {
431  fev.add_jet(_JetTranslator(_jets[j], jet_types[j], _jetObjRes));
432  }
433 
434  // Clone fev (intended to be fitted event)
435  // to ufev (intended to be unfitted event)
436  Lepjets_Event ufev = fev;
437 
438  // Set jet types.
439  fev.set_jet_types(jet_types);
440  ufev.set_jet_types(jet_types);
441 
442  // Store the unfitted event
443  _Unfitted_Events.push_back(ufev);
444 
445  // Prepare the placeholder for various kinematic quantities
446  double umwhad;
447  double utmass;
448  double mt;
449  double sigmt;
450  Column_Vector pullx;
451  Column_Vector pully;
452 
453  // Do the fit
454  double chisq = _Top_Fit.fit_one_perm(fev, nuz, umwhad, utmass, mt, sigmt, pullx, pully);
455  // Store output of the fit
456  _Fit_Results.push_back(Fit_Result(chisq, fev, pullx, pully, umwhad, utmass, mt, sigmt));
457 
458  } // end loop over two neutrino solution
459 
460  } while (std::next_permutation(jet_types.begin(), jet_types.end()));
461  // end loop over all jet permutations
462 
463  return _Fit_Results.size();
464  }
465 
469  std::vector<Lepjets_Event> GetUnfittedEvent() { return _Unfitted_Events; }
470 
475  std::vector<Fit_Result> GetFitAllPermutation() { return _Fit_Results; }
476 
480  static const unsigned int MIN_HITFIT_JET = 4;
481 
485  static const unsigned int MIN_HITFIT_TTH = 6;
486 
490  static const unsigned int MAX_HITFIT_JET = 8;
491 
495  static const unsigned int MAX_HITFIT = 1680;
496 
500  static const unsigned int MAX_HITFIT_VAR = 32;
501  };
502 
503 } // namespace hitfit
504 
505 #endif // #ifndef RUNHITFIT_H
std::vector< Lepjets_Event > GetUnfittedEvent()
Return the unfitted events for all permutations.
Definition: RunHitFit.h:469
Hold the result of one kinematic fit.
Definition: Fit_Result.h:50
bool do_higgs_flag() const
Return the do_higgs_flag parameter.
Definition: Top_Fit.cc:90
JetTranslatorBase< AJet > _JetTranslator
Definition: RunHitFit.h:168
std::vector< Fit_Result >::size_type FitAllPermutation()
Fit all permutations of the internal event. Returns the number of permutations.
Definition: RunHitFit.h:385
Template class of function object to translate missing transverse energy physics object to HitFit&#39;s F...
Calculate and represent resolution for a physical quantity.
Definition: Resolution.h:98
Hold on to parameters for the Top_Fit class.
Definition: Top_Fit.h:69
LeptonTranslatorBase< AElectron > _ElectronTranslator
Definition: RunHitFit.h:158
Resolution & kt_res()
Return a reference to the resolution.
Hold the result of one kinematic fit.
RunHitFit(const LeptonTranslatorBase< AElectron > &el, const LeptonTranslatorBase< AMuon > &mu, const JetTranslatorBase< AJet > &jet, const METTranslatorBase< AMet > &met, const std::string default_file, double lepw_mass, double hadw_mass, double top_mass)
Constructor.
Definition: RunHitFit.h:252
bool set_jet_types(const std::vector< int > &)
Set the jet types in the event.
void add_lep(const Lepjets_Event_Lep &lep)
Add a new lepton to the event.
METTranslatorBase< AMet > _METTranslator
Definition: RunHitFit.h:173
void SetKtResolution(const Resolution &res)
Set the resolution of the internal event.
Definition: RunHitFit.h:360
A lightweight implementation of the Defaults interface that uses simple ASCII text files...
CLHEP::HepVector Column_Vector
Definition: matutil.h:63
static const unsigned int MIN_HITFIT_TTH
Definition: RunHitFit.h:485
void SetMet(const AMet &met, bool useObjRes=false)
Set the missing transverse energy of the internal event.
Definition: RunHitFit.h:349
uint16_t size_type
void AddLepton(const AMuon &muon, bool useObjRes=false)
Add one muon into the internal event.
Definition: RunHitFit.h:307
Definition: Electron.h:6
std::vector< Fit_Result > _Fit_Results
Definition: RunHitFit.h:222
double fit_one_perm(Lepjets_Event &ev, bool &nuz, double &umwhad, double &utmass, double &mt, double &sigmt, Column_Vector &pullx, Column_Vector &pully)
Fit for a single jet permutation.
Definition: Top_Fit.cc:355
std::vector< Fit_Result > GetFitAllPermutation()
Return the results of fitting all permutations of the internal event.
Definition: RunHitFit.h:475
static const unsigned int MAX_HITFIT_VAR
Definition: RunHitFit.h:500
std::vector< Lepjets_Event > _Unfitted_Events
Definition: RunHitFit.h:217
Represent a simple event consisting of lepton(s) and jet(s).
static const unsigned int MAX_HITFIT_JET
Definition: RunHitFit.h:490
Lepjets_Event _event
Definition: RunHitFit.h:180
Represent a simple event consisting of lepton(s) and jet(s). An instance of this class holds a list o...
Definition: Lepjets_Event.h:62
Template class of function object to translate missing transverse energy object to HitFit&#39;s Fourvec o...
Handle and fit jet permutations of an event. This is the primary interface between user&#39;s Lepjets_Eve...
LeptonTranslatorBase< AMuon > _MuonTranslator
Definition: RunHitFit.h:163
Template class of experiment-independent interface to HitFit. This class is intended to be used insid...
Definition: RunHitFit.h:153
static const unsigned int MAX_HITFIT
Definition: RunHitFit.h:495
Template class of function object to translate jet physics object to HitFit&#39;s Lepjets_Event_Jet objec...
std::vector< AJet > _jets
Definition: RunHitFit.h:196
Fourvec & met()
Return a reference to the missing transverse energy.
Top_Fit _Top_Fit
Definition: RunHitFit.h:212
Template class of function object to translate lepton physics object to HitFit&#39;s Lepjets_Event_Lep ob...
void SetMETResolution(const Resolution &res)
Set the resolution of the internal event.
Definition: RunHitFit.h:371
Define a concrete interface for getting parameter settings from an ASCII text file.
void add_jet(const Lepjets_Event_Jet &jet)
Add a new jet to the event.
const Top_Fit_Args & args() const
Return a constant reference to the fit arguments.
Definition: Top_Fit.cc:563
Template class of function object to translate jet physics object to HitFit&#39;s Lepjets_Event_Jet objec...
~RunHitFit()
Destructor.
Definition: RunHitFit.h:271
Handle and fit jet permutations of an event. This is the primary interface between user&#39;s Lepjets_Eve...
Definition: Top_Fit.h:232
void AddLepton(const AElectron &electron, bool useObjRes=false)
Add one electron into the internal event.
Definition: RunHitFit.h:293
void clear()
Clear the internal event, fit results, and jets.
Definition: RunHitFit.h:276
static const unsigned int MIN_HITFIT_JET
Definition: RunHitFit.h:480
void AddJet(const AJet &jet, bool useObjRes=false)
Add one jet into the internal event. This function will do nothing if the internal event has already ...
Definition: RunHitFit.h:332
const Top_Fit & GetTopFit() const
Return a constant reference to the underlying Top_Fit object.
Definition: RunHitFit.h:379