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 
25 public:
27  ~ElectronIdMVAProducer() override;
28 
29 private:
30  bool filter(edm::Event&, const edm::EventSetup&) override;
31 
32  // ----------member data ---------------------------
33  bool verbose_;
39 
40  double _Rho;
42  std::vector<std::string> mvaWeightFiles_;
43  bool Trig_;
44  bool NoIP_;
45 
47 };
48 
49 //
50 // constants, enums and typedefs
51 //
52 
53 //
54 // static data member definitions
55 //
56 
57 //
58 // constructors and destructor
59 //
61  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
62  vertexToken_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
63  electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
64  eventrhoToken_ = consumes<double>(edm::InputTag("kt6PFJets", "rho"));
66  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEBRecHitCollection"));
68  consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("reducedEERecHitCollection"));
69  method_ = iConfig.getParameter<std::string>("method");
70  std::vector<std::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 
77 
79  if (Trig_ && !NoIP_) {
81  }
82 
83  if (Trig_ && NoIP_) {
85  }
86 
87  if (!Trig_) {
89  }
90 
91  bool manualCat_ = true;
92 
93  std::string path_mvaWeightFileEleID;
94  for (unsigned ifile = 0; ifile < fpMvaWeightFiles.size(); ++ifile) {
95  path_mvaWeightFileEleID = edm::FileInPath(fpMvaWeightFiles[ifile].c_str()).fullPath();
96  mvaWeightFiles_.push_back(path_mvaWeightFileEleID);
97  }
98 
99  mvaID_->initialize(method_, type_, manualCat_, mvaWeightFiles_);
100 }
101 
103  // do anything here that needs to be done at desctruction time
104  // (e.g. close files, deallocate resources etc.)
105 }
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called on each new Event ------------
113  std::unique_ptr<edm::ValueMap<float> > out(new edm::ValueMap<float>());
114 
116  iEvent.getByToken(vertexToken_, vertexCollection);
117 
119  const reco::Vertex* pv = &dummy;
120  if (!vertexCollection->empty()) {
121  pv = &*vertexCollection->begin();
122  } else { // create a dummy PV
124  e(0, 0) = 0.0015 * 0.0015;
125  e(1, 1) = 0.0015 * 0.0015;
126  e(2, 2) = 15. * 15.;
127  reco::Vertex::Point p(0, 0, 0);
128  dummy = reco::Vertex(p, e, 0, 0, 0);
129  }
130 
132 
134  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
135  TransientTrackBuilder thebuilder = *(builder.product());
136 
138  iEvent.getByToken(electronToken_, egCollection);
139  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
140 
141  _Rho = 0;
142  edm::Handle<double> rhoPtr;
143  iEvent.getByToken(eventrhoToken_, rhoPtr);
144  _Rho = *rhoPtr;
145 
146  std::vector<float> values;
147  values.reserve(egCollection->size());
148 
149  for (reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end();
150  ++egIter) {
151  double mvaVal = -999999;
152  if (!NoIP_) {
153  mvaVal = mvaID_->mvaValue(*egIter, *pv, thebuilder, lazyTools, verbose_);
154  }
155  if (NoIP_) {
156  mvaVal = mvaID_->mvaValue(*egIter, *pv, _Rho, /*thebuilder,*/ lazyTools, verbose_);
157  }
158 
159  values.push_back(mvaVal);
160  }
161 
163  filler.insert(egCollection, values.begin(), values.end());
164  filler.fill();
165 
166  iEvent.put(std::move(out));
167 
168  return true;
169 }
170 
171 //define this as a plug-in
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< double > eventrhoToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::EDGetTokenT< EcalRecHitCollection > reducedEBRecHitCollectionToken_
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:43
edm::EDGetTokenT< EcalRecHitCollection > reducedEERecHitCollectionToken_
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
bool filter(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
def pv(vc)
Definition: MetAnalyzer.py:7
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Double_t mvaValue(const reco::GsfElectron &ele, const reco::Vertex &vertex, const TransientTrackBuilder &transientTrackBuilder, EcalClusterLazyTools myEcalCluster, bool printDebug=kFALSE)
std::vector< std::string > mvaWeightFiles_
ElectronIdMVAProducer(const edm::ParameterSet &)
T const * product() const
Definition: Handle.h:69
edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_
T get() const
Definition: EventSetup.h:73
std::string fullPath() const
Definition: FileInPath.cc:163
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
EGammaMvaEleEstimator * mvaID_