CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
24 using namespace std;
25 using namespace reco;
27  public:
29  virtual ~ElectronPATIdMVAProducer();
30 
31  private:
32  virtual void produce(edm::Event&, const edm::EventSetup&);
33 
34  // ----------member data ---------------------------
35  bool verbose_;
37  double _Rho;
39  string method_;
40  vector<string> mvaWeightFiles_;
41 
42 
44 
45 };
46 
47 //
48 // constants, enums and typedefs
49 //
50 
51 //
52 // static data member definitions
53 //
54 
55 //
56 // constructors and destructor
57 //
59  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
60  electronToken_ = consumes<pat::ElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
61  method_ = iConfig.getParameter<string>("method");
62  std::vector<string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
63  eventrhoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("Rho"));
64 
65  produces<edm::ValueMap<float> >();
66 
67  mvaID_ = new EGammaMvaEleEstimator();
68 
70 
71 
73 
74 
75 
76  bool manualCat_ = true;
77 
78  string path_mvaWeightFileEleID;
79  for(unsigned ifile=0 ; ifile < fpMvaWeightFiles.size() ; ++ifile) {
80  path_mvaWeightFileEleID = edm::FileInPath ( fpMvaWeightFiles[ifile].c_str() ).fullPath();
81  mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
82  }
83 
84  mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);
85 
86 }
87 
88 
90 {
91 
92  // do anything here that needs to be done at desctruction time
93  // (e.g. close files, deallocate resources etc.)
94 
95 }
96 
97 
98 //
99 // member functions
100 //
101 
102 // ------------ method called on each new Event ------------
104  using namespace edm;
105 
106  std::auto_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>() );
107 
108 
109 
110 
111 
112 
113 
114  Handle<pat::ElectronCollection> egCollection;
115  iEvent.getByToken(electronToken_,egCollection);
116  const pat::ElectronCollection egCandidates = (*egCollection.product());
117 
118  _Rho=0;
119  edm::Handle<double> rhoPtr;
120  //const edm::InputTag eventrhoToken_("kt6PFJets", "rho");
121  iEvent.getByToken(eventrhoToken_,rhoPtr);
122  _Rho=*rhoPtr;
123 
124  std::vector<float> values;
125  values.reserve(egCollection->size());
126 
127  for ( pat::ElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end(); ++egIter) {
128 
129  double mvaVal = -999999;
130 
131 
132 
133 
134  mvaVal = mvaID_->mvaValue( *egIter, _Rho, verbose_);
135 
136 
137  values.push_back( mvaVal );
138  }
139 
140  edm::ValueMap<float>::Filler filler(*out);
141  filler.insert(egCollection, values.begin(), values.end() );
142  filler.fill();
143 
144  iEvent.put(out);
145 
146 
147 }
148 
149 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
ElectronPATIdMVAProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:243
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< Electron > ElectronCollection
Definition: Electron.h:37
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
edm::EDGetTokenT< pat::ElectronCollection > electronToken_
tuple out
Definition: dbtoconf.py:99
EGammaMvaEleEstimator * mvaID_
edm::EDGetTokenT< double > eventrhoToken_
std::string fullPath() const
Definition: FileInPath.cc:171