CMS 3D CMS Logo

ElectronPATIdMVAProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
20 //
21 // class declaration
22 //
23 
25 public:
27  ~ElectronPATIdMVAProducer() override;
28 
29 private:
30  void produce(edm::Event&, const edm::EventSetup&) override;
31 
32  // ----------member data ---------------------------
33  bool verbose_;
35  double _Rho;
38  std::vector<std::string> mvaWeightFiles_;
39 
41 };
42 
43 //
44 // constants, enums and typedefs
45 //
46 
47 //
48 // static data member definitions
49 //
50 
51 //
52 // constructors and destructor
53 //
55  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
56  electronToken_ = consumes<pat::ElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
57  method_ = iConfig.getParameter<std::string>("method");
58  std::vector<std::string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
59  eventrhoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("Rho"));
60 
61  produces<edm::ValueMap<float> >();
62 
64 
66 
68 
69  bool manualCat_ = true;
70 
71  std::string path_mvaWeightFileEleID;
72  for (unsigned ifile = 0; ifile < fpMvaWeightFiles.size(); ++ifile) {
73  path_mvaWeightFileEleID = edm::FileInPath(fpMvaWeightFiles[ifile].c_str()).fullPath();
74  mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
75  }
76 
77  mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);
78 }
79 
81  // do anything here that needs to be done at desctruction time
82  // (e.g. close files, deallocate resources etc.)
83 }
84 
85 //
86 // member functions
87 //
88 
89 // ------------ method called on each new Event ------------
91  std::unique_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>());
92 
94  iEvent.getByToken(electronToken_, egCollection);
95  const pat::ElectronCollection egCandidates = (*egCollection.product());
96 
97  _Rho = 0;
98  edm::Handle<double> rhoPtr;
99  //const edm::InputTag eventrhoToken_("kt6PFJets", "rho");
100  iEvent.getByToken(eventrhoToken_, rhoPtr);
101  _Rho = *rhoPtr;
102 
103  std::vector<float> values;
104  values.reserve(egCollection->size());
105 
106  for (pat::ElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end(); ++egIter) {
107  double mvaVal = -999999;
108 
109  mvaVal = mvaID_->mvaValue(*egIter, _Rho, verbose_);
110 
111  values.push_back(mvaVal);
112  }
113 
115  filler.insert(egCollection, values.begin(), values.end());
116  filler.fill();
117 
118  iEvent.put(std::move(out));
119 }
120 
121 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::string fullPath() const
Definition: FileInPath.cc:161
T const * product() const
Definition: Handle.h:70
Double_t mvaValue(const reco::GsfElectron &ele, const reco::Vertex &vertex, const TransientTrackBuilder &transientTrackBuilder, EcalClusterLazyTools const &myEcalCluster, bool printDebug=kFALSE)
std::vector< std::string > mvaWeightFiles_
ElectronPATIdMVAProducer(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
std::vector< Electron > ElectronCollection
Definition: Electron.h:36
void initialize(std::string methodName, std::string weightsfile, EGammaMvaEleEstimator::MVAType type)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< pat::ElectronCollection > electronToken_
EGammaMvaEleEstimator * mvaID_
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< double > eventrhoToken_
def move(src, dest)
Definition: eostools.py:511