Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-04 22:55:07

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     [[clang::suppress]]
0032     std::string CMSSW_BASE(std::getenv("CMSSW_BASE"));
0033     std::string resolution_filename =
0034         CMSSW_BASE + std::string("/src/TopQuarkAnalysis/TopHitFit/data/exampleElectronResolution.txt");
0035     resolution_ = EtaDepResolution(resolution_filename);
0036 
0037   }  // LeptonTranslatorBase<CLHEP::HepLorentzVector>::LeptonTranslatorBase()
0038 
0039   template <>
0040   LeptonTranslatorBase<CLHEP::HepLorentzVector>::LeptonTranslatorBase(const std::string& ifile) {
0041     [[clang::suppress]]
0042     std::string CMSSW_BASE(std::getenv("CMSSW_BASE"));
0043     std::string resolution_filename;
0044 
0045     if (ifile.empty()) {
0046       resolution_filename =
0047           CMSSW_BASE + std::string("/src/TopQuarkAnalysis/TopHitFit/data/exampleElectronResolution.txt");
0048     } else {
0049       resolution_filename = ifile;
0050     }
0051 
0052     resolution_ = EtaDepResolution(resolution_filename);
0053 
0054   }  // LeptonTranslatorBase<CLHEP::HepLorentzVector>::LeptonTranslatorBase(const std::string& ifile)
0055 
0056   template <>
0057   LeptonTranslatorBase<CLHEP::HepLorentzVector>::~LeptonTranslatorBase() {}
0058 
0059   template <>
0060   Lepjets_Event_Lep LeptonTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& lepton,
0061                                                                               int type /* = hitfit::lepton_label */,
0062                                                                               bool useObjEmbRes /* = false */) {
0063     Fourvec p(lepton.px(), lepton.py(), lepton.pz(), lepton.e());
0064 
0065     double lepton_eta(lepton.eta());
0066     Vector_Resolution lepton_resolution = resolution_.GetResolution(lepton_eta);
0067     Lepjets_Event_Lep retlep(p, type, lepton_resolution);
0068     return retlep;
0069 
0070   }  // Lepjets_Event_Lep LeptonTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& lepton)
0071 
0072   template <>
0073   const EtaDepResolution& LeptonTranslatorBase<CLHEP::HepLorentzVector>::resolution() const {
0074     return resolution_;
0075   }
0076 
0077   template <>
0078   bool LeptonTranslatorBase<CLHEP::HepLorentzVector>::CheckEta(const CLHEP::HepLorentzVector& lepton) const {
0079     return resolution_.CheckEta(lepton.eta());
0080   }
0081 
0082   template <>
0083   JetTranslatorBase<CLHEP::HepLorentzVector>::JetTranslatorBase() {
0084     [[clang::suppress]]
0085     std::string CMSSW_BASE(std::getenv("CMSSW_BASE"));
0086     std::string udsc_resolution_filename =
0087         CMSSW_BASE + std::string("/src/TopQuarkAnalysis/TopHitFit/data/exampleJetResolution.txt");
0088     const std::string& b_resolution_filename = udsc_resolution_filename;
0089 
0090     udscResolution_ = EtaDepResolution(udsc_resolution_filename);
0091     bResolution_ = EtaDepResolution(b_resolution_filename);
0092 
0093   }  // JetTranslatorBase<CLHEP::HepLorentzVector>::JetTranslatorBase()
0094 
0095   template <>
0096   JetTranslatorBase<CLHEP::HepLorentzVector>::JetTranslatorBase(const std::string& udscFile, const std::string& bFile) {
0097     [[clang::suppress]]
0098     std::string CMSSW_BASE(std::getenv("CMSSW_BASE"));
0099     std::string udsc_resolution_filename;
0100     std::string b_resolution_filename;
0101 
0102     if (udscFile.empty()) {
0103       udsc_resolution_filename =
0104           CMSSW_BASE + std::string("/src/TopQuarkAnalysis/TopHitFit/data/exampleJetResolution.txt");
0105     } else {
0106       udsc_resolution_filename = udscFile;
0107     }
0108 
0109     if (bFile.empty()) {
0110       b_resolution_filename = CMSSW_BASE + std::string("/src/TopQuarkAnalysis/TopHitFit/data/exampleJetResolution.txt");
0111     } else {
0112       b_resolution_filename = bFile;
0113     }
0114 
0115     udscResolution_ = EtaDepResolution(udsc_resolution_filename);
0116     bResolution_ = EtaDepResolution(b_resolution_filename);
0117 
0118   }  // JetTranslatorBase<CLHEP::HepLorentzVector>::JetTranslatorBase(const std::string& udscFile,const std::string& bFile)
0119 
0120   template <>
0121   JetTranslatorBase<CLHEP::HepLorentzVector>::~JetTranslatorBase() {
0122   }  // JetTranslatorBase<CLHEP::HepLorentzVector>::~JetTranslatorBase()
0123 
0124   template <>
0125   Lepjets_Event_Jet JetTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& jet,
0126                                                                            int type /* = hitfit::unknown_label */,
0127                                                                            bool useObjEmbRes /* = false */) {
0128     Fourvec p(jet.px(), jet.py(), jet.pz(), jet.e());
0129 
0130     double jet_eta = jet.eta();
0131     Vector_Resolution jet_resolution;
0132 
0133     if (type == hitfit::lepb_label || type == hitfit::hadb_label || type == hitfit::higgs_label) {
0134       jet_resolution = bResolution_.GetResolution(jet_eta);
0135     } else {
0136       jet_resolution = udscResolution_.GetResolution(jet_eta);
0137     }
0138 
0139     Lepjets_Event_Jet retjet(p, type, jet_resolution);
0140     return retjet;
0141 
0142   }  // Lepjets_Event_Jet JetTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& j,int type)
0143 
0144   template <>
0145   const EtaDepResolution& JetTranslatorBase<CLHEP::HepLorentzVector>::udscResolution() const {
0146     return udscResolution_;
0147   }
0148 
0149   template <>
0150   const EtaDepResolution& JetTranslatorBase<CLHEP::HepLorentzVector>::bResolution() const {
0151     return bResolution_;
0152   }
0153 
0154   template <>
0155   bool JetTranslatorBase<CLHEP::HepLorentzVector>::CheckEta(const CLHEP::HepLorentzVector& jet) const {
0156     return udscResolution_.CheckEta(jet.eta()) && bResolution_.CheckEta(jet.eta());
0157   }
0158 
0159   template <>
0160   METTranslatorBase<CLHEP::HepLorentzVector>::METTranslatorBase() {
0161     resolution_ = Resolution(std::string("0,0,12"));
0162   }  // METTranslatorBase<CLHEP::HepLorentzVector>::METTranslatorBase()
0163 
0164   template <>
0165   METTranslatorBase<CLHEP::HepLorentzVector>::METTranslatorBase(const std::string& ifile) {
0166     const Defaults_Text defs(ifile);
0167     std::string resolution_string(defs.get_string("met_resolution"));
0168     resolution_ = Resolution(resolution_string);
0169 
0170   }  // METTranslatorBase<CLHEP::HepLorentzVector>::METTranslatorBase(const std::string& ifile)
0171 
0172   template <>
0173   METTranslatorBase<CLHEP::HepLorentzVector>::~METTranslatorBase() {
0174   }  // METTranslatorBase<CLHEP::HepLorentzVector>::~METTranslatorBase()
0175 
0176   template <>
0177   Fourvec METTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& m,
0178                                                                  bool useObjEmbRes /* = false */) {
0179     return Fourvec(m.px(), m.py(), 0.0, m.e());
0180 
0181   }  // Fourvec METTranslatorBase<CLHEP::HepLorentzVector>::operator()(const CLHEP::HepLorentzVector& m)
0182 
0183   template <>
0184   Resolution METTranslatorBase<CLHEP::HepLorentzVector>::KtResolution(const CLHEP::HepLorentzVector& m,
0185                                                                       bool useObjEmbRes /* = false */) const {
0186     return resolution_;
0187   }  // Resolution METTranslatorBase<CLHEP::HepLorentzVector>::KtResolution(const CLHEP::HepLorentzVector& m)
0188 
0189   template <>
0190   Resolution METTranslatorBase<CLHEP::HepLorentzVector>::METResolution(const CLHEP::HepLorentzVector& m,
0191                                                                        bool useObjEmbRes /* = false */) const {
0192     return KtResolution(m, useObjEmbRes);
0193   }  // Resolution METTranslatorBase<CLHEP::HepLorentzVector>::METResolution(const CLHEP::HepLorentzVector& m)
0194 
0195 }  // namespace hitfit