Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:28

0001 
0002 #include "PhysicsTools/Heppy/interface/EGammaMvaEleEstimatorFWLite.h"
0003 #include "EgammaAnalysis/ElectronTools/interface/EGammaMvaEleEstimator.h"
0004 #include "EgammaAnalysis/ElectronTools/interface/EGammaMvaEleEstimatorCSA14.h"
0005 #include "FWCore/ParameterSet/interface/FileInPath.h"
0006 
0007 namespace heppy {
0008 
0009   EGammaMvaEleEstimatorFWLite::EGammaMvaEleEstimatorFWLite() : estimator_(nullptr), estimatorCSA14_(nullptr) {}
0010 
0011   EGammaMvaEleEstimatorFWLite::~EGammaMvaEleEstimatorFWLite() {
0012     delete estimator_;
0013     delete estimatorCSA14_;
0014   }
0015 
0016   void EGammaMvaEleEstimatorFWLite::initialize(std::string methodName,
0017                                                MVAType type,
0018                                                bool useBinnedVersion,
0019                                                std::vector<std::string> weightsfiles) {
0020     delete estimator_;
0021     estimator_ = nullptr;
0022     delete estimatorCSA14_;
0023     estimatorCSA14_ = nullptr;
0024     std::vector<std::string> weightspaths;
0025     weightspaths.reserve(weightsfiles.size());
0026     for (const std::string& s : weightsfiles) {
0027       weightspaths.push_back(edm::FileInPath(s).fullPath());
0028     }
0029     switch (type) {
0030       case EGammaMvaEleEstimatorFWLite::kTrig:
0031         estimator_ = new EGammaMvaEleEstimator();
0032         estimator_->initialize(methodName, EGammaMvaEleEstimator::kTrig, useBinnedVersion, weightspaths);
0033         break;
0034       case EGammaMvaEleEstimatorFWLite::kTrigNoIP:
0035         estimator_ = new EGammaMvaEleEstimator();
0036         estimator_->initialize(methodName, EGammaMvaEleEstimator::kTrigNoIP, useBinnedVersion, weightspaths);
0037         break;
0038       case EGammaMvaEleEstimatorFWLite::kNonTrig:
0039         estimator_ = new EGammaMvaEleEstimator();
0040         estimator_->initialize(methodName, EGammaMvaEleEstimator::kNonTrig, useBinnedVersion, weightspaths);
0041         break;
0042       case EGammaMvaEleEstimatorFWLite::kTrigCSA14:
0043         estimatorCSA14_ = new EGammaMvaEleEstimatorCSA14();
0044         estimatorCSA14_->initialize(methodName, EGammaMvaEleEstimatorCSA14::kTrig, useBinnedVersion, weightspaths);
0045         break;
0046       case EGammaMvaEleEstimatorFWLite::kNonTrigCSA14:
0047         estimatorCSA14_ = new EGammaMvaEleEstimatorCSA14();
0048         estimatorCSA14_->initialize(methodName, EGammaMvaEleEstimatorCSA14::kNonTrig, useBinnedVersion, weightspaths);
0049         break;
0050       case EGammaMvaEleEstimatorFWLite::kNonTrigPhys14:
0051         estimatorCSA14_ = new EGammaMvaEleEstimatorCSA14();
0052         estimatorCSA14_->initialize(
0053             methodName, EGammaMvaEleEstimatorCSA14::kNonTrigPhys14, useBinnedVersion, weightspaths);
0054         break;
0055       default:
0056         return;
0057     }
0058   }
0059 
0060   float EGammaMvaEleEstimatorFWLite::mvaValue(
0061       const pat::Electron& ele, const reco::Vertex& vertex, double rho, bool full5x5, bool printDebug) {
0062     if (estimator_)
0063       return estimator_->mvaValue(ele, vertex, rho, full5x5, printDebug);
0064     else if (estimatorCSA14_)
0065       return estimatorCSA14_->mvaValue(ele, printDebug);
0066     else
0067       throw cms::Exception("LogicError", "You must call unitialize before mvaValue\n");
0068   }
0069 
0070 }  // namespace heppy