CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronIdMVAProducer.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:
30 
31  private:
32  virtual bool filter(edm::Event&, const edm::EventSetup&);
33 
34  // ----------member data ---------------------------
35  bool verbose_;
40 
41  double _Rho;
42  string method_;
43  vector<string> mvaWeightFiles_;
44  bool Trig_;
45  bool NoIP_;
46 
48 
49 };
50 
51 //
52 // constants, enums and typedefs
53 //
54 
55 //
56 // static data member definitions
57 //
58 
59 //
60 // constructors and destructor
61 //
63  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
64  vertexTag_ = iConfig.getParameter<edm::InputTag>("vertexTag");
65  electronTag_ = iConfig.getParameter<edm::InputTag>("electronTag");
66  reducedEBRecHitCollection_ = iConfig.getParameter<edm::InputTag>("reducedEBRecHitCollection");
67  reducedEERecHitCollection_ = iConfig.getParameter<edm::InputTag>("reducedEERecHitCollection");
68  method_ = iConfig.getParameter<string>("method");
69  std::vector<string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
70  Trig_ = iConfig.getParameter<bool>("Trig");
71  NoIP_ = iConfig.getParameter<bool>("NoIP");
72 
73  produces<edm::ValueMap<float> >("");
74 
75  mvaID_ = new EGammaMvaEleEstimator();
76 
78  if(Trig_ && !NoIP_){type_ = EGammaMvaEleEstimator::kTrig;}
79 
80  if(Trig_ && NoIP_){type_ = EGammaMvaEleEstimator::kTrigNoIP;}
81 
82  if(!Trig_){type_ = EGammaMvaEleEstimator::kNonTrig;}
83 
84  bool manualCat_ = true;
85 
86  string path_mvaWeightFileEleID;
87  for(unsigned ifile=0 ; ifile < fpMvaWeightFiles.size() ; ++ifile) {
88  path_mvaWeightFileEleID = edm::FileInPath ( fpMvaWeightFiles[ifile].c_str() ).fullPath();
89  mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
90  }
91 
92  mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);
93 
94 }
95 
96 
98 {
99 
100  // do anything here that needs to be done at desctruction time
101  // (e.g. close files, deallocate resources etc.)
102 
103 }
104 
105 
106 //
107 // member functions
108 //
109 
110 // ------------ method called on each new Event ------------
112  using namespace edm;
113 
114  std::auto_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>() );
115 
117  iEvent.getByLabel(vertexTag_, vertexCollection);
118 
119  Vertex dummy;
120  const Vertex *pv = &dummy;
121  if ( vertexCollection->size() != 0) {
122  pv = &*vertexCollection->begin();
123  } else { // create a dummy PV
125  e(0, 0) = 0.0015 * 0.0015;
126  e(1, 1) = 0.0015 * 0.0015;
127  e(2, 2) = 15. * 15.;
128  Vertex::Point p(0, 0, 0);
129  dummy = Vertex(p, e, 0, 0, 0);
130  }
131 
132  EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollection_, reducedEERecHitCollection_);
133 
135  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
136  TransientTrackBuilder thebuilder = *(builder.product());
137 
139  iEvent.getByLabel(electronTag_,egCollection);
140  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
141 
142  _Rho=0;
143  edm::Handle<double> rhoPtr;
144  const edm::InputTag eventrho("kt6PFJets", "rho");
145  iEvent.getByLabel(eventrho,rhoPtr);
146  _Rho=*rhoPtr;
147 
148  std::vector<float> values;
149  values.reserve(egCollection->size());
150 
151  for ( reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end(); ++egIter) {
152 
153  double mvaVal = -999999;
154  if(!NoIP_){
155  mvaVal = mvaID_->mvaValue( *egIter, *pv,thebuilder,lazyTools, verbose_);
156  }
157  if(NoIP_){
158  mvaVal = mvaID_->mvaValue( *egIter, *pv, _Rho,/*thebuilder,*/lazyTools, verbose_);
159  }
160 
161  values.push_back( mvaVal );
162  }
163 
164  edm::ValueMap<float>::Filler filler(*out);
165  filler.insert(egCollection, values.begin(), values.end() );
166  filler.fill();
167 
168  iEvent.put(out);
169 
170  return true;
171 }
172 
173 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
vector< string > mvaWeightFiles_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
tuple vertexCollection
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
edm::InputTag reducedEBRecHitCollection_
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
virtual bool filter(edm::Event &, const edm::EventSetup &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
ElectronIdMVAProducer(const edm::ParameterSet &)
tuple out
Definition: dbtoconf.py:99
const T & get() const
Definition: EventSetup.h:55
edm::InputTag reducedEERecHitCollection_
std::string fullPath() const
Definition: FileInPath.cc:171
EGammaMvaEleEstimator * mvaID_