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