Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-15 04:15:14

0001 #include <iostream>
0002 
0003 #include "FWCore/Framework/interface/stream/EDAnalyzer.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 
0009 #include "PhysicsTools/MVAComputer/interface/MVAComputerCache.h"
0010 #include "PhysicsTools/MVAComputer/interface/HelperMacros.h"
0011 
0012 #include "PhysicsTools/MVAComputer/test/testMVAComputerEvaluate.h"
0013 
0014 // take the event setup record for "MVADemoRcd" from the header above
0015 // definition shared with PhysicsTools/MVATrainer/test/testMVATrainerLooper
0016 // (the "Rcd" is implicitly appended by the macro)
0017 //
0018 // MVA_COMPUTER_CONTAINER_DEFINE(MVADemo);
0019 
0020 using namespace PhysicsTools;
0021 
0022 class testMVAComputerEvaluate : public edm::stream::EDAnalyzer<> {
0023 public:
0024   explicit testMVAComputerEvaluate(const edm::ParameterSet& params);
0025 
0026   virtual void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup);
0027 
0028 private:
0029   edm::ESGetToken<PhysicsTools::Calibration::MVAComputerContainer, MVADemoRcd> mvaToken_;
0030   MVAComputerCache mvaComputer;
0031 };
0032 
0033 testMVAComputerEvaluate::testMVAComputerEvaluate(const edm::ParameterSet& params) {}
0034 
0035 void testMVAComputerEvaluate::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0036   // update the cached MVAComputer from calibrations
0037   // passed via EventSetup.
0038   // you can use a MVAComputerContainer to pass around
0039   // multiple different MVA's in one event setup record
0040   // identify the right one by a definable name string
0041   mvaComputer.update(&iSetup.getData(mvaToken_), "testMVA");
0042 
0043   Variable::Value values[] = {Variable::Value("x", 1.0), Variable::Value("y", 1.5)};
0044 
0045   double result = mvaComputer->eval(values, values + 2);
0046   // arguments are begin() and end() (for plain C++ arrays done this way)
0047   // std::vector also works, but plain array has better performance
0048   // for fixed-size arrays (no internal malloc/free)
0049 
0050   edm::LogPrint("testMVAComputerEvaluate") << "mva.eval(x = 1.0, y = 1.5) = " << result;
0051 }
0052 
0053 // define this as a plug-in
0054 DEFINE_FWK_MODULE(testMVAComputerEvaluate);
0055 
0056 // define the plugins for the record
0057 MVA_COMPUTER_CONTAINER_IMPLEMENT(MVADemo);
0058 // this will implictly define an EDM es_source named "MVADemoFileSource"
0059 // which will allow to read the calibration from file into the EventSetup
0060 // note that for CondDB the PoolDBESSource can be used instead