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
EGammaMvaEleEstimator
Definition: EGammaMvaEleEstimator.h:38
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EDProducer.h
pat::ElectronCollection
std::vector< Electron > ElectronCollection
Definition: Electron.h:36
ElectronPATIdMVAProducer::mvaID_
EGammaMvaEleEstimator * mvaID_
Definition: ElectronPATIdMVAProducer.cc:40
edm::EDGetTokenT< pat::ElectronCollection >
ElectronPATIdMVAProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ElectronPATIdMVAProducer.cc:90
EGammaMvaEleEstimator::kTrigNoIP
Definition: EGammaMvaEleEstimator.h:45
EGammaMvaEleEstimator::initialize
void initialize(std::string methodName, std::string weightsfile, EGammaMvaEleEstimator::MVAType type)
Definition: EGammaMvaEleEstimator.cc:42
ElectronPATIdMVAProducer::method_
std::string method_
Definition: ElectronPATIdMVAProducer.cc:37
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Handle
Definition: AssociativeIterator.h:50
EGammaMvaEleEstimator::MVAType
MVAType
Definition: EGammaMvaEleEstimator.h:43
ElectronPATIdMVAProducer::ElectronPATIdMVAProducer
ElectronPATIdMVAProducer(const edm::ParameterSet &)
Definition: ElectronPATIdMVAProducer.cc:54
ElectronPATIdMVAProducer::verbose_
bool verbose_
Definition: ElectronPATIdMVAProducer.cc:33
edm::FileInPath
Definition: FileInPath.h:64
ElectronPATIdMVAProducer::eventrhoToken_
edm::EDGetTokenT< double > eventrhoToken_
Definition: ElectronPATIdMVAProducer.cc:36
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
compare_using_db.ifile
ifile
Definition: compare_using_db.py:251
GsfElectron.h
EGammaMvaEleEstimator.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
GsfElectronFwd.h
edm::ParameterSet
Definition: ParameterSet.h:47
ElectronPATIdMVAProducer
Definition: ElectronPATIdMVAProducer.cc:24
Event.h
ElectronPATIdMVAProducer::_Rho
double _Rho
Definition: ElectronPATIdMVAProducer.cc:35
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
TransientTrackRecord.h
VertexFwd.h
EGammaMvaEleEstimator::mvaValue
Double_t mvaValue(const reco::GsfElectron &ele, const reco::Vertex &vertex, const TransientTrackBuilder &transientTrackBuilder, EcalClusterLazyTools const &myEcalCluster, bool printDebug=kFALSE)
Definition: EGammaMvaEleEstimator.cc:954
eostools.move
def move(src, dest)
Definition: eostools.py:511
IPTools.h
Frameworkfwd.h
ElectronPATIdMVAProducer::electronToken_
edm::EDGetTokenT< pat::ElectronCollection > electronToken_
Definition: ElectronPATIdMVAProducer.cc:34
edm::ValueMap< float >
edm::EDProducer
Definition: EDProducer.h:35
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Electron.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
edm::helper::Filler
Definition: ValueMap.h:22
ElectronPATIdMVAProducer::~ElectronPATIdMVAProducer
~ElectronPATIdMVAProducer() override
Definition: ElectronPATIdMVAProducer.cc:80
ParameterSet.h
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161
ElectronPATIdMVAProducer::mvaWeightFiles_
std::vector< std::string > mvaWeightFiles_
Definition: ElectronPATIdMVAProducer.cc:38