Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:47

0001 #ifndef RecoMET_METPUSubtraction_PFMETAlgorithmMVA_h
0002 #define RecoMET_METPUSubtraction_PFMETAlgorithmMVA_h
0003 
0004 /** \class PFMETAlgorithmMVA
0005  *
0006  * MVA based algorithm for computing the particle-flow missing Et
0007  *
0008  * \authors Phil Harris, CERN
0009  *          Christian Veelken, LLR
0010  *
0011  */
0012 
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/Framework/interface/ConsumesCollector.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 
0017 #include "CondFormats/GBRForest/interface/GBRForest.h"
0018 #include "CondFormats/DataRecord/interface/GBRWrapperRcd.h"
0019 
0020 #include "DataFormats/Candidate/interface/Candidate.h"
0021 #include "DataFormats/METReco/interface/MET.h"
0022 #include "DataFormats/VertexReco/interface/Vertex.h"
0023 
0024 #include "RecoMET/METPUSubtraction/interface/MvaMEtUtilities.h"
0025 
0026 #include <Math/SMatrix.h>
0027 
0028 #include <string>
0029 #include <vector>
0030 #include <ostream>
0031 
0032 class PFMETAlgorithmMVA {
0033 public:
0034   PFMETAlgorithmMVA(const edm::ParameterSet& cfg, edm::ConsumesCollector iC);
0035   ~PFMETAlgorithmMVA();
0036 
0037   void initialize(const edm::EventSetup&);
0038 
0039   void setHasPhotons(bool hasPhotons) { hasPhotons_ = hasPhotons; }
0040 
0041   void setInput(const std::vector<reco::PUSubMETCandInfo>&,
0042                 const std::vector<reco::PUSubMETCandInfo>&,
0043                 const std::vector<reco::PUSubMETCandInfo>&,
0044                 const std::vector<reco::Vertex::Point>&);
0045 
0046   void evaluateMVA();
0047 
0048   reco::Candidate::LorentzVector getMEt() const { return mvaMEt_; }
0049   const reco::METCovMatrix& getMEtCov() const { return mvaMEtCov_; }
0050 
0051   double getU() const { return mvaOutputU_; }
0052   double getDPhi() const { return mvaOutputDPhi_; }
0053   double getCovU1() const { return mvaOutputCovU1_; }
0054   double getCovU2() const { return mvaOutputCovU2_; }
0055 
0056   void print(std::ostream&) const;
0057 
0058 private:
0059   const std::string updateVariableNames(std::string input);
0060   const GBRForest* loadMVAfromFile(const edm::FileInPath& inputFileName, const std::string& mvaName);
0061 
0062   const float evaluateU();
0063   const float evaluateDPhi();
0064   const float evaluateCovU1();
0065   const float evaluateCovU2();
0066 
0067   MvaMEtUtilities utils_;
0068 
0069   std::string mvaNameU_;
0070   std::string mvaNameDPhi_;
0071   std::string mvaNameCovU1_;
0072   std::string mvaNameCovU2_;
0073 
0074   edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaTokenU_;
0075   edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaTokenDPhi_;
0076   edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaTokenCovU1_;
0077   edm::ESGetToken<GBRForest, GBRWrapperRcd> mvaTokenCovU2_;
0078 
0079   int mvaType_;
0080   bool hasPhotons_;
0081 
0082   double dZcut_;
0083   std::unique_ptr<float[]> createFloatVector(std::vector<std::string> variableNames);
0084   const float GetResponse(const GBRForest* Reader, std::vector<std::string>& variableNames);
0085   void computeMET();
0086   std::map<std::string, float> var_;
0087 
0088   float* mvaInputU_;
0089   float* mvaInputDPhi_;
0090   float* mvaInputCovU1_;
0091   float* mvaInputCovU2_;
0092 
0093   float mvaOutputU_;
0094   float mvaOutputDPhi_;
0095   float mvaOutputCovU1_;
0096   float mvaOutputCovU2_;
0097 
0098   std::vector<std::string> varForU_;
0099   std::vector<std::string> varForDPhi_;
0100   std::vector<std::string> varForCovU1_;
0101   std::vector<std::string> varForCovU2_;
0102 
0103   double sumLeptonPx_;
0104   double sumLeptonPy_;
0105   double chargedSumLeptonPx_;
0106   double chargedSumLeptonPy_;
0107 
0108   reco::Candidate::LorentzVector mvaMEt_;
0109   //TMatrixD mvaMEtCov_;
0110   reco::METCovMatrix mvaMEtCov_;
0111 
0112   const GBRForest* mvaReaderU_;
0113   const GBRForest* mvaReaderDPhi_;
0114   const GBRForest* mvaReaderCovU1_;
0115   const GBRForest* mvaReaderCovU2_;
0116 
0117   bool loadMVAfromDB_;
0118 
0119   edm::ParameterSet cfg_;
0120 };
0121 #endif