CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/TopQuarkAnalysis/TopHitFit/interface/RunHitFit.h

Go to the documentation of this file.
00001 //
00002 //     $Id: RunHitFit.h,v 1.1 2011/05/26 09:46:53 mseidel Exp $
00003 //
00004 
00020 #ifndef HITFIT_RUNHITFIT_H
00021 #define HITFIT_RUNHITFIT_H
00022 
00023 #include <algorithm>
00024 
00025 #include "TopQuarkAnalysis/TopHitFit/interface/Defaults_Text.h"
00026 #include "TopQuarkAnalysis/TopHitFit/interface/LeptonTranslatorBase.h"
00027 #include "TopQuarkAnalysis/TopHitFit/interface/JetTranslatorBase.h"
00028 #include "TopQuarkAnalysis/TopHitFit/interface/METTranslatorBase.h"
00029 #include "TopQuarkAnalysis/TopHitFit/interface/Fit_Result.h"
00030 #include "TopQuarkAnalysis/TopHitFit/interface/Lepjets_Event.h"
00031 #include "TopQuarkAnalysis/TopHitFit/interface/Top_Fit.h"
00032 
00033 // Explanation about the MIN/MAX definitions:
00034 //
00035 // For a given number of jets, there is a corresponding number of
00036 // permutations how to assign each jet in the event to the corresponding
00037 // parton-level jet.
00038 // The number of permutations up to 10 jets are given below for Tt and
00039 // TtH events.
00040 //
00041 // NJet         Npermutation (Tt)       Npermutation (TtH)
00042 // 4            24                      --
00043 // 5            120                     --
00044 // 6            360                     360
00045 // 7            840                     2520
00046 // 8            1680                    10080
00047 // 9            3024                    30240
00048 // 10           5040                    75600
00049 //
00050 // The formulas for the number of permutations for Tt and TtH events
00051 // given n jets in the event are
00052 //
00053 //         n!
00054 // Tt:  -------- ; n >= 4
00055 //      (n - 4)!
00056 //
00057 //          n!
00058 // TtH: ---------- ; n >= 6
00059 //      (n - 6)!2!
00060 //
00061 // The current MAX settings are chosen for a maximum number of 8 jets
00062 // Increasing this limit should be done with caution, as it will
00063 // increase the number of permutations rapidly.
00064 //
00065 
00066 namespace hitfit{
00067 
00153 template <class AElectron,
00154           class AMuon,
00155           class AJet,
00156           class AMet>
00157 class RunHitFit {
00158 
00159 private:
00160 
00164     LeptonTranslatorBase<AElectron>     _ElectronTranslator;
00165 
00169     LeptonTranslatorBase<AMuon>         _MuonTranslator;
00170 
00174     JetTranslatorBase<AJet>             _JetTranslator;
00175 
00179     METTranslatorBase<AMet>             _METTranslator;
00180 
00186     Lepjets_Event                       _event;
00187 
00202     std::vector<AJet>                   _jets;
00203 
00213     bool                                _jetObjRes;
00214 
00218     Top_Fit                             _Top_Fit;
00219 
00223     std::vector<Lepjets_Event>          _Unfitted_Events;
00224 
00228     std::vector<Fit_Result>             _Fit_Results;
00229 
00230 public:
00231 
00259     RunHitFit(const LeptonTranslatorBase<AElectron>& el,
00260               const LeptonTranslatorBase<AMuon>&     mu,
00261               const JetTranslatorBase<AJet>&         jet,
00262               const METTranslatorBase<AMet>&         met,
00263               const std::string                      default_file,
00264               double                                 lepw_mass,
00265               double                                 hadw_mass,
00266               double                                 top_mass):
00267         _ElectronTranslator(el),
00268         _MuonTranslator(mu),
00269         _JetTranslator(jet),
00270         _METTranslator(met),
00271         _event(0,0),
00272         _jetObjRes(false),
00273         _Top_Fit(Top_Fit_Args(Defaults_Text(default_file)),lepw_mass,hadw_mass,top_mass)
00274     {
00275     }
00276 
00280     ~RunHitFit()
00281     {
00282     }
00283 
00287     void
00288     clear()
00289     {
00290         _event = Lepjets_Event(0,0);
00291         _jets.clear();
00292         _jetObjRes = false;
00293         _Unfitted_Events.clear();
00294         _Fit_Results.clear();
00295     }
00296 
00306     void
00307     AddLepton(const AElectron& electron,
00308               bool useObjRes = false)
00309     {
00310         _event.add_lep(_ElectronTranslator(electron,electron_label,useObjRes));
00311         return;
00312     }
00313 
00323     void
00324     AddLepton(const AMuon& muon,
00325               bool useObjRes = false)
00326     {
00327         _event.add_lep(_MuonTranslator(muon,muon_label,useObjRes));
00328         return;
00329     }
00330 
00351     void
00352     AddJet(const AJet& jet,
00353            bool useObjRes = false)
00354     {
00355         // Only set flag when adding the first jet
00356         // the additional jets then WILL be treated in the
00357         // same way like the first jet.
00358         if (_jets.empty()) {
00359             _jetObjRes = useObjRes;
00360         }
00361 
00362         if (_jets.size() < MAX_HITFIT_JET) {
00363             _jets.push_back(jet);
00364         }
00365         return;
00366     }
00367 
00371     void
00372     SetMet(const AMet& met,
00373            bool useObjRes = false)
00374     {
00375         _event.met()    = _METTranslator(met,useObjRes);
00376         _event.kt_res() = _METTranslator.KtResolution(met,useObjRes);
00377         return;
00378     }
00379 
00385     void
00386     SetKtResolution(const Resolution& res)
00387     {
00388         _event.kt_res() = res;
00389         return;
00390     }
00391 
00398     void
00399     SetMETResolution(const Resolution& res)
00400     {
00401         SetKtResolution(res);
00402         return;
00403     }
00404 
00408     const Top_Fit&
00409     GetTopFit() const
00410     {
00411         return _Top_Fit;
00412     }
00413 
00418     std::vector<Fit_Result>::size_type
00419     FitAllPermutation()
00420     {
00421 
00422         if (_jets.size() < MIN_HITFIT_JET) {
00423             // For ttbar lepton+jets, a minimum of MIN_HITFIT_JETS jets
00424             // is required
00425             return 0;
00426         }
00427 
00428         if (_jets.size() > MAX_HITFIT_JET) {
00429             // Restrict the maximum number of jets in the fit
00430             // to prevent loop overflow
00431             return 0;
00432         }
00433 
00434         _Unfitted_Events.clear();
00435         _Fit_Results.clear();
00436 
00437         // Prepare the array of jet types for permutation
00438         std::vector<int> jet_types (_jets.size(), unknown_label);
00439         jet_types[0] = lepb_label;
00440         jet_types[1] = hadb_label;
00441         jet_types[2] = hadw1_label;
00442         jet_types[3] = hadw1_label;
00443 
00444         if (_Top_Fit.args().do_higgs_flag() && _jets.size() >= MIN_HITFIT_TTH) {
00445             jet_types[4] = higgs_label;
00446             jet_types[5] = higgs_label;
00447         }
00448 
00449         std::stable_sort(jet_types.begin(),jet_types.end());
00450 
00451         do {
00452 
00453             // begin loop over all jet permutation
00454             for (int nusol = 0 ; nusol != 2 ; nusol++) {
00455                 // loop over two neutrino solution
00456                 bool nuz = bool(nusol);
00457 
00458                 // Copy the event
00459                 Lepjets_Event fev = _event;
00460 
00461                 // Add jets into the event, with the assumed type
00462                 // in accord with the permutation.
00463                 // The translator _JetTranslator will correctly
00464                 // return object of Lepjets_Event_Jet with
00465                 // jet energy correction applied in accord with
00466                 // the assumed jet type (b or light).
00467                 for (size_t j = 0 ; j != _jets.size(); j++) {
00468                     fev.add_jet(_JetTranslator(_jets[j],jet_types[j],_jetObjRes));
00469                 }
00470 
00471                 // Clone fev (intended to be fitted event)
00472                 // to ufev (intended to be unfitted event)
00473                 Lepjets_Event ufev = fev;
00474 
00475                 // Set jet types.
00476                 fev.set_jet_types(jet_types);
00477                 ufev.set_jet_types(jet_types);
00478 
00479                 // Store the unfitted event
00480                 _Unfitted_Events.push_back(ufev);
00481 
00482                 // Prepare the placeholder for various kinematic quantities
00483                 double umwhad;
00484                 double utmass;
00485                 double mt;
00486                 double sigmt;
00487                 Column_Vector pullx;
00488                 Column_Vector pully;
00489 
00490                 // Do the fit
00491                 double chisq= _Top_Fit.fit_one_perm(fev,
00492                                                     nuz,
00493                                                     umwhad,
00494                                                     utmass,
00495                                                     mt,
00496                                                     sigmt,
00497                                                     pullx,
00498                                                     pully);
00499                 // Store output of the fit
00500                 _Fit_Results.push_back(Fit_Result(chisq,
00501                                                   fev,
00502                                                   pullx,
00503                                                   pully,
00504                                                   umwhad,
00505                                                   utmass,
00506                                                   mt,
00507                                                   sigmt));
00508 
00509             } // end loop over two neutrino solution
00510 
00511         } while (std::next_permutation (jet_types.begin(), jet_types.end()));
00512         // end loop over all jet permutations
00513 
00514         return _Fit_Results.size();
00515 
00516     }
00517 
00521     std::vector<Lepjets_Event>
00522     GetUnfittedEvent()
00523     {
00524         return _Unfitted_Events;
00525     }
00526 
00531     std::vector<Fit_Result>
00532     GetFitAllPermutation()
00533     {
00534         return _Fit_Results;
00535     }
00536 
00540     static const unsigned int MIN_HITFIT_JET =   4 ;
00541 
00545     static const unsigned int MIN_HITFIT_TTH =   6 ;
00546 
00550     static const unsigned int MAX_HITFIT_JET =   8 ;
00551 
00555     static const unsigned int MAX_HITFIT     = 1680;
00556 
00560     static const unsigned int MAX_HITFIT_VAR =  32 ;
00561 
00562 
00563 };
00564 
00565 } // namespace hitfit
00566 
00567 #endif // #ifndef RUNHITFIT_H