CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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,
153  class AMuon,
154  class AJet,
155  class AMet>
156 class RunHitFit {
157 
158 private:
159 
164 
169 
174 
179 
186 
201  std::vector<AJet> _jets;
202 
213 
218 
222  std::vector<Lepjets_Event> _Unfitted_Events;
223 
227  std::vector<Fit_Result> _Fit_Results;
228 
229 public:
230 
262  const std::string default_file,
263  double lepw_mass,
264  double hadw_mass,
265  double top_mass):
267  _MuonTranslator(mu),
268  _JetTranslator(jet),
269  _METTranslator(met),
270  _event(0,0),
271  _jetObjRes(false),
272  _Top_Fit(Top_Fit_Args(Defaults_Text(default_file)),lepw_mass,hadw_mass,top_mass)
273  {
274  }
275 
280  {
281  }
282 
286  void
288  {
289  _event = Lepjets_Event(0,0);
290  _jets.clear();
291  _jetObjRes = false;
292  _Unfitted_Events.clear();
293  _Fit_Results.clear();
294  }
295 
305  void
306  AddLepton(const AElectron& electron,
307  bool useObjRes = false)
308  {
309  _event.add_lep(_ElectronTranslator(electron,electron_label,useObjRes));
310  return;
311  }
312 
322  void
323  AddLepton(const AMuon& muon,
324  bool useObjRes = false)
325  {
326  _event.add_lep(_MuonTranslator(muon,muon_label,useObjRes));
327  return;
328  }
329 
350  void
351  AddJet(const AJet& jet,
352  bool useObjRes = false)
353  {
354  // Only set flag when adding the first jet
355  // the additional jets then WILL be treated in the
356  // same way like the first jet.
357  if (_jets.empty()) {
358  _jetObjRes = useObjRes;
359  }
360 
361  if (_jets.size() < MAX_HITFIT_JET) {
362  _jets.push_back(jet);
363  }
364  return;
365  }
366 
370  void
371  SetMet(const AMet& met,
372  bool useObjRes = false)
373  {
374  _event.met() = _METTranslator(met,useObjRes);
375  _event.kt_res() = _METTranslator.KtResolution(met,useObjRes);
376  return;
377  }
378 
384  void
386  {
387  _event.kt_res() = res;
388  return;
389  }
390 
397  void
399  {
400  SetKtResolution(res);
401  return;
402  }
403 
407  const Top_Fit&
408  GetTopFit() const
409  {
410  return _Top_Fit;
411  }
412 
419  {
420 
421  if (_jets.size() < MIN_HITFIT_JET) {
422  // For ttbar lepton+jets, a minimum of MIN_HITFIT_JETS jets
423  // is required
424  return 0;
425  }
426 
427  if (_jets.size() > MAX_HITFIT_JET) {
428  // Restrict the maximum number of jets in the fit
429  // to prevent loop overflow
430  return 0;
431  }
432 
433  _Unfitted_Events.clear();
434  _Fit_Results.clear();
435 
436  // Prepare the array of jet types for permutation
437  std::vector<int> jet_types (_jets.size(), unknown_label);
438  jet_types[0] = lepb_label;
439  jet_types[1] = hadb_label;
440  jet_types[2] = hadw1_label;
441  jet_types[3] = hadw1_label;
442 
443  if (_Top_Fit.args().do_higgs_flag() && _jets.size() >= MIN_HITFIT_TTH) {
444  jet_types[4] = higgs_label;
445  jet_types[5] = higgs_label;
446  }
447 
448  std::stable_sort(jet_types.begin(),jet_types.end());
449 
450  do {
451 
452  // begin loop over all jet permutation
453  for (int nusol = 0 ; nusol != 2 ; nusol++) {
454  // loop over two neutrino solution
455  bool nuz = bool(nusol);
456 
457  // Copy the event
458  Lepjets_Event fev = _event;
459 
460  // Add jets into the event, with the assumed type
461  // in accord with the permutation.
462  // The translator _JetTranslator will correctly
463  // return object of Lepjets_Event_Jet with
464  // jet energy correction applied in accord with
465  // the assumed jet type (b or light).
466  for (size_t j = 0 ; j != _jets.size(); j++) {
467  fev.add_jet(_JetTranslator(_jets[j],jet_types[j],_jetObjRes));
468  }
469 
470  // Clone fev (intended to be fitted event)
471  // to ufev (intended to be unfitted event)
472  Lepjets_Event ufev = fev;
473 
474  // Set jet types.
475  fev.set_jet_types(jet_types);
476  ufev.set_jet_types(jet_types);
477 
478  // Store the unfitted event
479  _Unfitted_Events.push_back(ufev);
480 
481  // Prepare the placeholder for various kinematic quantities
482  double umwhad;
483  double utmass;
484  double mt;
485  double sigmt;
486  Column_Vector pullx;
487  Column_Vector pully;
488 
489  // Do the fit
490  double chisq= _Top_Fit.fit_one_perm(fev,
491  nuz,
492  umwhad,
493  utmass,
494  mt,
495  sigmt,
496  pullx,
497  pully);
498  // Store output of the fit
499  _Fit_Results.push_back(Fit_Result(chisq,
500  fev,
501  pullx,
502  pully,
503  umwhad,
504  utmass,
505  mt,
506  sigmt));
507 
508  } // end loop over two neutrino solution
509 
510  } while (std::next_permutation (jet_types.begin(), jet_types.end()));
511  // end loop over all jet permutations
512 
513  return _Fit_Results.size();
514 
515  }
516 
520  std::vector<Lepjets_Event>
522  {
523  return _Unfitted_Events;
524  }
525 
530  std::vector<Fit_Result>
532  {
533  return _Fit_Results;
534  }
535 
539  static const unsigned int MIN_HITFIT_JET = 4 ;
540 
544  static const unsigned int MIN_HITFIT_TTH = 6 ;
545 
549  static const unsigned int MAX_HITFIT_JET = 8 ;
550 
554  static const unsigned int MAX_HITFIT = 1680;
555 
559  static const unsigned int MAX_HITFIT_VAR = 32 ;
560 
561 
562 };
563 
564 } // namespace hitfit
565 
566 #endif // #ifndef RUNHITFIT_H
std::vector< Lepjets_Event > GetUnfittedEvent()
Return the unfitted events for all permutations.
Definition: RunHitFit.h:521
Hold the result of one kinematic fit.
Definition: Fit_Result.h:53
JetTranslatorBase< AJet > _JetTranslator
Definition: RunHitFit.h:173
tuple met
____________________________________________________________________________||
Definition: CaloMET_cfi.py:7
std::vector< Fit_Result >::size_type FitAllPermutation()
Fit all permutations of the internal event. Returns the number of permutations.
Definition: RunHitFit.h:418
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:102
Hold on to parameters for the Top_Fit class.
Definition: Top_Fit.h:77
LeptonTranslatorBase< AElectron > _ElectronTranslator
Definition: RunHitFit.h:163
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:258
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:178
void SetKtResolution(const Resolution &res)
Set the resolution of the internal event.
Definition: RunHitFit.h:385
A lightweight implementation of the Defaults interface that uses simple ASCII text files...
CLHEP::HepVector Column_Vector
Definition: matutil.h:66
static const unsigned int MIN_HITFIT_TTH
Definition: RunHitFit.h:544
void SetMet(const AMet &met, bool useObjRes=false)
Set the missing transverse energy of the internal event.
Definition: RunHitFit.h:371
uint16_t size_type
void AddLepton(const AMuon &muon, bool useObjRes=false)
Add one muon into the internal event.
Definition: RunHitFit.h:323
std::vector< Fit_Result > _Fit_Results
Definition: RunHitFit.h:227
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:392
std::vector< Fit_Result > GetFitAllPermutation()
Return the results of fitting all permutations of the internal event.
Definition: RunHitFit.h:531
static const unsigned int MAX_HITFIT_VAR
Definition: RunHitFit.h:559
std::vector< Lepjets_Event > _Unfitted_Events
Definition: RunHitFit.h:222
Represent a simple event consisting of lepton(s) and jet(s).
static const unsigned int MAX_HITFIT_JET
Definition: RunHitFit.h:549
Lepjets_Event _event
Definition: RunHitFit.h:185
Represent a simple event consisting of lepton(s) and jet(s). An instance of this class holds a list o...
Definition: Lepjets_Event.h:66
const Top_Fit & GetTopFit() const
Return a constant reference to the underlying Top_Fit object.
Definition: RunHitFit.h:408
int j
Definition: DBlmapReader.cc:9
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...
const int mu
Definition: Constants.h:22
LeptonTranslatorBase< AMuon > _MuonTranslator
Definition: RunHitFit.h:168
Template class of experiment-independent interface to HitFit. This class is intended to be used insid...
Definition: RunHitFit.h:156
static const unsigned int MAX_HITFIT
Definition: RunHitFit.h:554
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:201
Fourvec & met()
Return a reference to the missing transverse energy.
Top_Fit _Top_Fit
Definition: RunHitFit.h:217
const Top_Fit_Args & args() const
Return a constant reference to the fit arguments.
Definition: Top_Fit.cc:608
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:398
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.
bool do_higgs_flag() const
Return the do_higgs_flag parameter.
Definition: Top_Fit.cc:98
Template class of function object to translate jet physics object to HitFit&#39;s Lepjets_Event_Jet objec...
~RunHitFit()
Destructor.
Definition: RunHitFit.h:279
Handle and fit jet permutations of an event. This is the primary interface between user&#39;s Lepjets_Eve...
Definition: Top_Fit.h:243
volatile std::atomic< bool > shutdown_flag false
void AddLepton(const AElectron &electron, bool useObjRes=false)
Add one electron into the internal event.
Definition: RunHitFit.h:306
void clear()
Clear the internal event, fit results, and jets.
Definition: RunHitFit.h:287
static const unsigned int MIN_HITFIT_JET
Definition: RunHitFit.h:539
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:351