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 // 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  vertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
65  electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
66  eventrhoToken_ = consumes<double>(edm::InputTag("kt6PFJets", "rho"));
67  reducedEBRecHitCollectionToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEBRecHitCollection"));
68  reducedEERecHitCollectionToken_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEERecHitCollection"));
69  method_ = iConfig.getParameter<string>("method");
70  std::vector<string> fpMvaWeightFiles = iConfig.getParameter<std::vector<std::string> >("mvaWeightFile");
71  Trig_ = iConfig.getParameter<bool>("Trig");
72  NoIP_ = iConfig.getParameter<bool>("NoIP");
73 
74  produces<edm::ValueMap<float> >("");
75 
76  mvaID_ = new EGammaMvaEleEstimator();
77 
79  if(Trig_ && !NoIP_){type_ = EGammaMvaEleEstimator::kTrig;}
80 
81  if(Trig_ && NoIP_){type_ = EGammaMvaEleEstimator::kTrigNoIP;}
82 
83  if(!Trig_){type_ = EGammaMvaEleEstimator::kNonTrig;}
84 
85  bool manualCat_ = true;
86 
87  string path_mvaWeightFileEleID;
88  for(unsigned ifile=0 ; ifile < fpMvaWeightFiles.size() ; ++ifile) {
89  path_mvaWeightFileEleID = edm::FileInPath ( fpMvaWeightFiles[ifile].c_str() ).fullPath();
90  mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
91  }
92 
93  mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);
94 
95 }
96 
97 
99 {
100 
101  // do anything here that needs to be done at desctruction time
102  // (e.g. close files, deallocate resources etc.)
103 
104 }
105 
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called on each new Event ------------
113  using namespace edm;
114 
115  std::auto_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>() );
116 
118  iEvent.getByToken(vertexToken_, vertexCollection);
119 
120  Vertex dummy;
121  const Vertex *pv = &dummy;
122  if ( vertexCollection->size() != 0) {
123  pv = &*vertexCollection->begin();
124  } else { // create a dummy PV
126  e(0, 0) = 0.0015 * 0.0015;
127  e(1, 1) = 0.0015 * 0.0015;
128  e(2, 2) = 15. * 15.;
129  Vertex::Point p(0, 0, 0);
130  dummy = Vertex(p, e, 0, 0, 0);
131  }
132 
133  EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollectionToken_, reducedEERecHitCollectionToken_);
134 
136  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
137  TransientTrackBuilder thebuilder = *(builder.product());
138 
140  iEvent.getByToken(electronToken_,egCollection);
141  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
142 
143  _Rho=0;
144  edm::Handle<double> rhoPtr;
145  iEvent.getByToken(eventrhoToken_,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_
edm::EDGetTokenT< double > eventrhoToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< EcalRecHitCollection > reducedEBRecHitCollectionToken_
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
edm::EDGetTokenT< EcalRecHitCollection > reducedEERecHitCollectionToken_
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
tuple vertexCollection
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
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
std::string fullPath() const
Definition: FileInPath.cc:165
EGammaMvaEleEstimator * mvaID_