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 // $Id: RunHitFit.h,v 1.1 2011/05/26 09:46:53 mseidel Exp $
3 //
4 
20 #ifndef HITFIT_RUNHITFIT_H
21 #define HITFIT_RUNHITFIT_H
22 
23 #include <algorithm>
24 
32 
33 // Explanation about the MIN/MAX definitions:
34 //
35 // For a given number of jets, there is a corresponding number of
36 // permutations how to assign each jet in the event to the corresponding
37 // parton-level jet.
38 // The number of permutations up to 10 jets are given below for Tt and
39 // TtH events.
40 //
41 // NJet Npermutation (Tt) Npermutation (TtH)
42 // 4 24 --
43 // 5 120 --
44 // 6 360 360
45 // 7 840 2520
46 // 8 1680 10080
47 // 9 3024 30240
48 // 10 5040 75600
49 //
50 // The formulas for the number of permutations for Tt and TtH events
51 // given n jets in the event are
52 //
53 // n!
54 // Tt: -------- ; n >= 4
55 // (n - 4)!
56 //
57 // n!
58 // TtH: ---------- ; n >= 6
59 // (n - 6)!2!
60 //
61 // The current MAX settings are chosen for a maximum number of 8 jets
62 // Increasing this limit should be done with caution, as it will
63 // increase the number of permutations rapidly.
64 //
65 
66 namespace hitfit{
67 
153 template <class AElectron,
154  class AMuon,
155  class AJet,
156  class AMet>
157 class RunHitFit {
158 
159 private:
160 
165 
170 
175 
180 
187 
202  std::vector<AJet> _jets;
203 
214 
219 
223  std::vector<Lepjets_Event> _Unfitted_Events;
224 
228  std::vector<Fit_Result> _Fit_Results;
229 
230 public:
231 
263  const std::string default_file,
264  double lepw_mass,
265  double hadw_mass,
266  double top_mass):
268  _MuonTranslator(mu),
269  _JetTranslator(jet),
270  _METTranslator(met),
271  _event(0,0),
272  _jetObjRes(false),
273  _Top_Fit(Top_Fit_Args(Defaults_Text(default_file)),lepw_mass,hadw_mass,top_mass)
274  {
275  }
276 
281  {
282  }
283 
287  void
289  {
290  _event = Lepjets_Event(0,0);
291  _jets.clear();
292  _jetObjRes = false;
293  _Unfitted_Events.clear();
294  _Fit_Results.clear();
295  }
296 
306  void
307  AddLepton(const AElectron& electron,
308  bool useObjRes = false)
309  {
310  _event.add_lep(_ElectronTranslator(electron,electron_label,useObjRes));
311  return;
312  }
313 
323  void
324  AddLepton(const AMuon& muon,
325  bool useObjRes = false)
326  {
327  _event.add_lep(_MuonTranslator(muon,muon_label,useObjRes));
328  return;
329  }
330 
351  void
352  AddJet(const AJet& jet,
353  bool useObjRes = false)
354  {
355  // Only set flag when adding the first jet
356  // the additional jets then WILL be treated in the
357  // same way like the first jet.
358  if (_jets.empty()) {
359  _jetObjRes = useObjRes;
360  }
361 
362  if (_jets.size() < MAX_HITFIT_JET) {
363  _jets.push_back(jet);
364  }
365  return;
366  }
367 
371  void
372  SetMet(const AMet& met,
373  bool useObjRes = false)
374  {
375  _event.met() = _METTranslator(met,useObjRes);
376  _event.kt_res() = _METTranslator.KtResolution(met,useObjRes);
377  return;
378  }
379 
385  void
387  {
388  _event.kt_res() = res;
389  return;
390  }
391 
398  void
400  {
401  SetKtResolution(res);
402  return;
403  }
404 
408  const Top_Fit&
409  GetTopFit() const
410  {
411  return _Top_Fit;
412  }
413 
420  {
421 
422  if (_jets.size() < MIN_HITFIT_JET) {
423  // For ttbar lepton+jets, a minimum of MIN_HITFIT_JETS jets
424  // is required
425  return 0;
426  }
427 
428  if (_jets.size() > MAX_HITFIT_JET) {
429  // Restrict the maximum number of jets in the fit
430  // to prevent loop overflow
431  return 0;
432  }
433 
434  _Unfitted_Events.clear();
435  _Fit_Results.clear();
436 
437  // Prepare the array of jet types for permutation
438  std::vector<int> jet_types (_jets.size(), unknown_label);
439  jet_types[0] = lepb_label;
440  jet_types[1] = hadb_label;
441  jet_types[2] = hadw1_label;
442  jet_types[3] = hadw1_label;
443 
444  if (_Top_Fit.args().do_higgs_flag() && _jets.size() >= MIN_HITFIT_TTH) {
445  jet_types[4] = higgs_label;
446  jet_types[5] = higgs_label;
447  }
448 
449  std::stable_sort(jet_types.begin(),jet_types.end());
450 
451  do {
452 
453  // begin loop over all jet permutation
454  for (int nusol = 0 ; nusol != 2 ; nusol++) {
455  // loop over two neutrino solution
456  bool nuz = bool(nusol);
457 
458  // Copy the event
459  Lepjets_Event fev = _event;
460 
461  // Add jets into the event, with the assumed type
462  // in accord with the permutation.
463  // The translator _JetTranslator will correctly
464  // return object of Lepjets_Event_Jet with
465  // jet energy correction applied in accord with
466  // the assumed jet type (b or light).
467  for (size_t j = 0 ; j != _jets.size(); j++) {
468  fev.add_jet(_JetTranslator(_jets[j],jet_types[j],_jetObjRes));
469  }
470 
471  // Clone fev (intended to be fitted event)
472  // to ufev (intended to be unfitted event)
473  Lepjets_Event ufev = fev;
474 
475  // Set jet types.
476  fev.set_jet_types(jet_types);
477  ufev.set_jet_types(jet_types);
478 
479  // Store the unfitted event
480  _Unfitted_Events.push_back(ufev);
481 
482  // Prepare the placeholder for various kinematic quantities
483  double umwhad;
484  double utmass;
485  double mt;
486  double sigmt;
487  Column_Vector pullx;
488  Column_Vector pully;
489 
490  // Do the fit
491  double chisq= _Top_Fit.fit_one_perm(fev,
492  nuz,
493  umwhad,
494  utmass,
495  mt,
496  sigmt,
497  pullx,
498  pully);
499  // Store output of the fit
500  _Fit_Results.push_back(Fit_Result(chisq,
501  fev,
502  pullx,
503  pully,
504  umwhad,
505  utmass,
506  mt,
507  sigmt));
508 
509  } // end loop over two neutrino solution
510 
511  } while (std::next_permutation (jet_types.begin(), jet_types.end()));
512  // end loop over all jet permutations
513 
514  return _Fit_Results.size();
515 
516  }
517 
521  std::vector<Lepjets_Event>
523  {
524  return _Unfitted_Events;
525  }
526 
531  std::vector<Fit_Result>
533  {
534  return _Fit_Results;
535  }
536 
540  static const unsigned int MIN_HITFIT_JET = 4 ;
541 
545  static const unsigned int MIN_HITFIT_TTH = 6 ;
546 
550  static const unsigned int MAX_HITFIT_JET = 8 ;
551 
555  static const unsigned int MAX_HITFIT = 1680;
556 
560  static const unsigned int MAX_HITFIT_VAR = 32 ;
561 
562 
563 };
564 
565 } // namespace hitfit
566 
567 #endif // #ifndef RUNHITFIT_H
std::vector< Lepjets_Event > GetUnfittedEvent()
Return the unfitted events for all permutations.
Definition: RunHitFit.h:522
Hold the result of one kinematic fit.
Definition: Fit_Result.h:54
JetTranslatorBase< AJet > _JetTranslator
Definition: RunHitFit.h:174
std::vector< Fit_Result >::size_type FitAllPermutation()
Fit all permutations of the internal event. Returns the number of permutations.
Definition: RunHitFit.h:419
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:103
Hold on to parameters for the Top_Fit class.
Definition: Top_Fit.h:78
LeptonTranslatorBase< AElectron > _ElectronTranslator
Definition: RunHitFit.h:164
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:259
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:179
void SetKtResolution(const Resolution &res)
Set the resolution of the internal event.
Definition: RunHitFit.h:386
A lightweight implementation of the Defaults interface that uses simple ASCII text files...
CLHEP::HepVector Column_Vector
Definition: matutil.h:67
static const unsigned int MIN_HITFIT_TTH
Definition: RunHitFit.h:545
void SetMet(const AMet &met, bool useObjRes=false)
Set the missing transverse energy of the internal event.
Definition: RunHitFit.h:372
uint16_t size_type
void AddLepton(const AMuon &muon, bool useObjRes=false)
Add one muon into the internal event.
Definition: RunHitFit.h:324
std::vector< Fit_Result > _Fit_Results
Definition: RunHitFit.h:228
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:393
std::vector< Fit_Result > GetFitAllPermutation()
Return the results of fitting all permutations of the internal event.
Definition: RunHitFit.h:532
static const unsigned int MAX_HITFIT_VAR
Definition: RunHitFit.h:560
std::vector< Lepjets_Event > _Unfitted_Events
Definition: RunHitFit.h:223
Represent a simple event consisting of lepton(s) and jet(s).
static const unsigned int MAX_HITFIT_JET
Definition: RunHitFit.h:550
Lepjets_Event _event
Definition: RunHitFit.h:186
Represent a simple event consisting of lepton(s) and jet(s). An instance of this class holds a list o...
Definition: Lepjets_Event.h:67
const Top_Fit & GetTopFit() const
Return a constant reference to the underlying Top_Fit object.
Definition: RunHitFit.h:409
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:23
LeptonTranslatorBase< AMuon > _MuonTranslator
Definition: RunHitFit.h:169
Template class of experiment-independent interface to HitFit. This class is intended to be used insid...
Definition: RunHitFit.h:157
static const unsigned int MAX_HITFIT
Definition: RunHitFit.h:555
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:202
Fourvec & met()
Return a reference to the missing transverse energy.
Top_Fit _Top_Fit
Definition: RunHitFit.h:218
const Top_Fit_Args & args() const
Return a constant reference to the fit arguments.
Definition: Top_Fit.cc:609
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:399
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:99
Template class of function object to translate jet physics object to HitFit&#39;s Lepjets_Event_Jet objec...
~RunHitFit()
Destructor.
Definition: RunHitFit.h:280
Handle and fit jet permutations of an event. This is the primary interface between user&#39;s Lepjets_Eve...
Definition: Top_Fit.h:244
void AddLepton(const AElectron &electron, bool useObjRes=false)
Add one electron into the internal event.
Definition: RunHitFit.h:307
void clear()
Clear the internal event, fit results, and jets.
Definition: RunHitFit.h:288
static const unsigned int MIN_HITFIT_JET
Definition: RunHitFit.h:540
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:352