test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronIdMVABased.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ElectronIdMVABased
4 // Class: ElectronIdMVABased
5 //
13 //
14 // Original Author: Zablocki Jakub
15 // Created: Thu Feb 9 10:47:50 CST 2012
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
36 //
37 // class declaration
38 //
39 
40 using namespace std;
41 using namespace reco;
42 
43 namespace gsfidhelper {
45  public:
47  std::vector<std::string> mvaWeightFileEleID =
48  config.getParameter<std::vector<std::string> >("HZZmvaWeightFile");
50  cfg.vweightsfiles = mvaWeightFileEleID;
51  mvaID_.reset( new ElectronMVAEstimator(cfg) );
52  }
53  std::unique_ptr<const ElectronMVAEstimator> mvaID_;
54  };
55 }
56 
57 class ElectronIdMVABased : public edm::stream::EDFilter< edm::GlobalCache<gsfidhelper::HeavyObjectCache> > {
58 public:
61 
62 
63  static std::unique_ptr<gsfidhelper::HeavyObjectCache>
65  return std::unique_ptr<gsfidhelper::HeavyObjectCache>(new gsfidhelper::HeavyObjectCache(conf));
66  }
67 
69  }
70 
71 private:
72  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
73 
74 
75  // ----------member data ---------------------------
78  std::vector<string> mvaWeightFileEleID;
84 };
85 
86 //
87 // constants, enums and typedefs
88 //
89 
90 //
91 // static data member definitions
92 //
93 
94 //
95 // constructors and destructor
96 //
98  vertexToken = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
99  electronToken = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
100  thresholdBarrel = iConfig.getParameter<double>("thresholdBarrel");
101  thresholdEndcap = iConfig.getParameter<double>("thresholdEndcap");
102  thresholdIsoBarrel = iConfig.getParameter<double>("thresholdIsoDR03Barrel");
103  thresholdIsoEndcap = iConfig.getParameter<double>("thresholdIsoDR03Endcap");
104 
105  produces<reco::GsfElectronCollection>();
106 }
107 
108 
110 {
111  // do anything here that needs to be done at desctruction time
112  // (e.g. close files, deallocate resources etc.)
113 
114 }
115 
116 
117 //
118 // member functions
119 //
120 
121 // ------------ method called on each new Event ------------
123  using namespace edm;
124 
125  constexpr double etaEBEE = 1.485;
126 
127  std::auto_ptr<reco::GsfElectronCollection> mvaElectrons(new reco::GsfElectronCollection);
128 
130  iEvent.getByToken(vertexToken, vertexCollection);
131  int nVtx = vertexCollection->size();
132 
134  iEvent.getByToken(electronToken,egCollection);
135  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
136  for ( reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end(); ++egIter) {
137  double mvaVal = globalCache()->mvaID_->mva( *egIter, nVtx );
138  double isoDr03 = egIter->dr03TkSumPt() + egIter->dr03EcalRecHitSumEt() + egIter->dr03HcalTowerSumEt();
139  double eleEta = fabs(egIter->eta());
140  if (eleEta <= etaEBEE && mvaVal > thresholdBarrel && isoDr03 < thresholdIsoBarrel) {
141  mvaElectrons->push_back( *egIter );
142  reco::GsfElectron::MvaOutput myMvaOutput;
143  myMvaOutput.mva_Isolated = mvaVal;
144  mvaElectrons->back().setMvaOutput(myMvaOutput);
145  }
146  else if (eleEta > etaEBEE && mvaVal > thresholdEndcap && isoDr03 < thresholdIsoEndcap) {
147  mvaElectrons->push_back( *egIter );
148  reco::GsfElectron::MvaOutput myMvaOutput;
149  myMvaOutput.mva_Isolated = mvaVal;
150  mvaElectrons->back().setMvaOutput(myMvaOutput);
151  }
152  }
153 
154  iEvent.put(mvaElectrons);
155 
156  return true;
157 }
158 
159 //define this as a plug-in
T getParameter(std::string const &) const
tuple cfg
Definition: looper.py:293
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
static std::unique_ptr< gsfidhelper::HeavyObjectCache > initializeGlobalCache(const edm::ParameterSet &conf)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< string > mvaWeightFileEleID
tuple vertexCollection
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
#define constexpr
static void globalEndJob(gsfidhelper::HeavyObjectCache const *)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
std::unique_ptr< const ElectronMVAEstimator > mvaID_
virtual bool filter(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::VertexCollection > vertexToken
ElectronIdMVABased(const edm::ParameterSet &, const gsfidhelper::HeavyObjectCache *)
tuple conf
Definition: dbtoconf.py:185
edm::EDGetTokenT< reco::GsfElectronCollection > electronToken
HeavyObjectCache(const edm::ParameterSet &config)