Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:16

0001 //
0002 //
0003 
0004 /**
0005     @file CLHEPHitFitTranslator.cc
0006 
0007     @brief Translator for four-vector classes in CLHEP.
0008     Contains specific implementation for the following classes:
0009     - LeptonTranslatorBase<CLHEP::HepLorenzVector>
0010     - JetTranslatorBase<CLHEP::HepLorenzVector>
0011     - METTranslatorBase<CLHEP::HepLorenzVector>
0012 
0013     @author Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
0014 
0015     @date Thu Jul 29 17:54:01 CEST 2010
0016 
0017     @version $Id: CLHEPHitFitTranslator.cc,v 1.4 2010/08/06 22:00:44 haryo Exp $
0018  */
0019 
0020 #include <cstdlib>
0021 #include "CLHEP/Vector/LorentzVector.h"
0022 
0023 #include "TopQuarkAnalysis/TopHitFit/interface/LeptonTranslatorBase.h"
0024 #include "TopQuarkAnalysis/TopHitFit/interface/JetTranslatorBase.h"
0025 #include "TopQuarkAnalysis/TopHitFit/interface/METTranslatorBase.h"
0026 
0027 namespace hitfit {
0028 
0029   template <>
0030   LeptonTranslatorBase<CLHEP::HepLorentzVector>::LeptonTranslatorBase() {
0031     std::string CMSSW_BASE(std::getenv("CMSSW_BASE"));
0032     std::string resolution_filename =
0033         CMSSW_BASE + std::string("/src/TopQuarkAnalysis/TopHitFit/data/exampleElectronResolution.txt");
0034     resolution_ = EtaDepResolution(resolution_filename);
0035 
0036   }  // LeptonTranslatorBase<CLHEP::HepLorentzVector>::LeptonTranslatorBase()
0037 
0038   template <>
0039   LeptonTranslatorBase<CLHEP::HepLorentzVector>::LeptonTranslatorBase(const std::string& ifile) {
0040     std::string CMSSW_BASE(std::getenv("CMSSW_BASE"));
0041     std::string resolution_filename;
0042 
0043     if (ifile.empty()) {
0044       resolution_filename =
0045           CMSSW_BASE + std::string("/src/TopQuarkAnalysis/TopHitFit/data/exampleElectronResolution.txt");
0046     } else {
0047       resolution_filename = ifile;
0048     }
0049 
0050     resolution_ = EtaDepResolution(resolution_filename);
0051 
0052   }  // LeptonTranslatorBase<CLHEP::HepLorentzVector>::LeptonTranslatorBase(const std::string& ifile)
0053 
0054   template <>
0055   LeptonTranslatorBase<CLHEP::HepLorentzVector>::~LeptonTranslatorBase() {}
0056 
0057   template <>
0058   Lepjets_Event_Lep LeptonTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& lepton,
0059                                                                               int type /* = hitfit::lepton_label */,
0060                                                                               bool useObjEmbRes /* = false */) {
0061     Fourvec p(lepton.px(), lepton.py(), lepton.pz(), lepton.e());
0062 
0063     double lepton_eta(lepton.eta());
0064     Vector_Resolution lepton_resolution = resolution_.GetResolution(lepton_eta);
0065     Lepjets_Event_Lep retlep(p, type, lepton_resolution);
0066     return retlep;
0067 
0068   }  // Lepjets_Event_Lep LeptonTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& lepton)
0069 
0070   template <>
0071   const EtaDepResolution& LeptonTranslatorBase<CLHEP::HepLorentzVector>::resolution() const {
0072     return resolution_;
0073   }
0074 
0075   template <>
0076   bool LeptonTranslatorBase<CLHEP::HepLorentzVector>::CheckEta(const CLHEP::HepLorentzVector& lepton) const {
0077     return resolution_.CheckEta(lepton.eta());
0078   }
0079 
0080   template <>
0081   JetTranslatorBase<CLHEP::HepLorentzVector>::JetTranslatorBase() {
0082     std::string CMSSW_BASE(std::getenv("CMSSW_BASE"));
0083     std::string udsc_resolution_filename =
0084         CMSSW_BASE + std::string("/src/TopQuarkAnalysis/TopHitFit/data/exampleJetResolution.txt");
0085     const std::string& b_resolution_filename = udsc_resolution_filename;
0086 
0087     udscResolution_ = EtaDepResolution(udsc_resolution_filename);
0088     bResolution_ = EtaDepResolution(b_resolution_filename);
0089 
0090   }  // JetTranslatorBase<CLHEP::HepLorentzVector>::JetTranslatorBase()
0091 
0092   template <>
0093   JetTranslatorBase<CLHEP::HepLorentzVector>::JetTranslatorBase(const std::string& udscFile, const std::string& bFile) {
0094     std::string CMSSW_BASE(std::getenv("CMSSW_BASE"));
0095     std::string udsc_resolution_filename;
0096     std::string b_resolution_filename;
0097 
0098     if (udscFile.empty()) {
0099       udsc_resolution_filename =
0100           CMSSW_BASE + std::string("/src/TopQuarkAnalysis/TopHitFit/data/exampleJetResolution.txt");
0101     } else {
0102       udsc_resolution_filename = udscFile;
0103     }
0104 
0105     if (bFile.empty()) {
0106       b_resolution_filename = CMSSW_BASE + std::string("/src/TopQuarkAnalysis/TopHitFit/data/exampleJetResolution.txt");
0107     } else {
0108       b_resolution_filename = bFile;
0109     }
0110 
0111     udscResolution_ = EtaDepResolution(udsc_resolution_filename);
0112     bResolution_ = EtaDepResolution(b_resolution_filename);
0113 
0114   }  // JetTranslatorBase<CLHEP::HepLorentzVector>::JetTranslatorBase(const std::string& udscFile,const std::string& bFile)
0115 
0116   template <>
0117   JetTranslatorBase<CLHEP::HepLorentzVector>::~JetTranslatorBase() {
0118   }  // JetTranslatorBase<CLHEP::HepLorentzVector>::~JetTranslatorBase()
0119 
0120   template <>
0121   Lepjets_Event_Jet JetTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& jet,
0122                                                                            int type /* = hitfit::unknown_label */,
0123                                                                            bool useObjEmbRes /* = false */) {
0124     Fourvec p(jet.px(), jet.py(), jet.pz(), jet.e());
0125 
0126     double jet_eta = jet.eta();
0127     Vector_Resolution jet_resolution;
0128 
0129     if (type == hitfit::lepb_label || type == hitfit::hadb_label || type == hitfit::higgs_label) {
0130       jet_resolution = bResolution_.GetResolution(jet_eta);
0131     } else {
0132       jet_resolution = udscResolution_.GetResolution(jet_eta);
0133     }
0134 
0135     Lepjets_Event_Jet retjet(p, type, jet_resolution);
0136     return retjet;
0137 
0138   }  // Lepjets_Event_Jet JetTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& j,int type)
0139 
0140   template <>
0141   const EtaDepResolution& JetTranslatorBase<CLHEP::HepLorentzVector>::udscResolution() const {
0142     return udscResolution_;
0143   }
0144 
0145   template <>
0146   const EtaDepResolution& JetTranslatorBase<CLHEP::HepLorentzVector>::bResolution() const {
0147     return bResolution_;
0148   }
0149 
0150   template <>
0151   bool JetTranslatorBase<CLHEP::HepLorentzVector>::CheckEta(const CLHEP::HepLorentzVector& jet) const {
0152     return udscResolution_.CheckEta(jet.eta()) && bResolution_.CheckEta(jet.eta());
0153   }
0154 
0155   template <>
0156   METTranslatorBase<CLHEP::HepLorentzVector>::METTranslatorBase() {
0157     resolution_ = Resolution(std::string("0,0,12"));
0158   }  // METTranslatorBase<CLHEP::HepLorentzVector>::METTranslatorBase()
0159 
0160   template <>
0161   METTranslatorBase<CLHEP::HepLorentzVector>::METTranslatorBase(const std::string& ifile) {
0162     const Defaults_Text defs(ifile);
0163     std::string resolution_string(defs.get_string("met_resolution"));
0164     resolution_ = Resolution(resolution_string);
0165 
0166   }  // METTranslatorBase<CLHEP::HepLorentzVector>::METTranslatorBase(const std::string& ifile)
0167 
0168   template <>
0169   METTranslatorBase<CLHEP::HepLorentzVector>::~METTranslatorBase() {
0170   }  // METTranslatorBase<CLHEP::HepLorentzVector>::~METTranslatorBase()
0171 
0172   template <>
0173   Fourvec METTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& m,
0174                                                                  bool useObjEmbRes /* = false */) {
0175     return Fourvec(m.px(), m.py(), 0.0, m.e());
0176 
0177   }  // Fourvec METTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& m)
0178 
0179   template <>
0180   Resolution METTranslatorBase<CLHEP::HepLorentzVector>::KtResolution(const CLHEP::HepLorentzVector& m,
0181                                                                       bool useObjEmbRes /* = false */) const {
0182     return resolution_;
0183   }  // Resolution METTranslatorBase<CLHEP::HepLorentzVector>::KtResolution(const CLHEP::HepLorentzVector& m)
0184 
0185   template <>
0186   Resolution METTranslatorBase<CLHEP::HepLorentzVector>::METResolution(const CLHEP::HepLorentzVector& m,
0187                                                                        bool useObjEmbRes /* = false */) const {
0188     return KtResolution(m, useObjEmbRes);
0189   }  // Resolution METTranslatorBase<CLHEP::HepLorentzVector>::METResolution(const CLHEP::HepLorentzVector& m)
0190 
0191 }  // namespace hitfit