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;
43  public:
44  explicit ElectronIdMVABased(const edm::ParameterSet&);
46 
47  private:
48  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
49 
50 
51  // ----------member data ---------------------------
60 
62 };
63 
64 //
65 // constants, enums and typedefs
66 //
67 
68 //
69 // static data member definitions
70 //
71 
72 //
73 // constructors and destructor
74 //
76  vertexToken = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTag"));
77  electronToken = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronTag"));
78  mvaWeightFileEleID = iConfig.getParameter<string>("HZZmvaWeightFile");
79  thresholdBarrel = iConfig.getParameter<double>("thresholdBarrel");
80  thresholdEndcap = iConfig.getParameter<double>("thresholdEndcap");
81  thresholdIsoBarrel = iConfig.getParameter<double>("thresholdIsoDR03Barrel");
82  thresholdIsoEndcap = iConfig.getParameter<double>("thresholdIsoDR03Endcap");
83 
84  produces<reco::GsfElectronCollection>();
85  path_mvaWeightFileEleID = edm::FileInPath ( mvaWeightFileEleID.c_str() ).fullPath();
86  FILE * fileEleID = fopen(path_mvaWeightFileEleID.c_str(), "r");
87  if (fileEleID) {
88  fclose(fileEleID);
89  }
90  else {
91  string err = "ElectronIdMVABased: cannot open weight file '";
92  err += path_mvaWeightFileEleID;
93  err += "'";
94  throw invalid_argument( err );
95  }
96 
97  mvaID_ = new ElectronMVAEstimator(path_mvaWeightFileEleID);
98 }
99 
100 
102 {
103 
104  delete mvaID_;
105  // do anything here that needs to be done at desctruction time
106  // (e.g. close files, deallocate resources etc.)
107 
108 }
109 
110 
111 //
112 // member functions
113 //
114 
115 // ------------ method called on each new Event ------------
117  using namespace edm;
118 
119  std::auto_ptr<reco::GsfElectronCollection> mvaElectrons(new reco::GsfElectronCollection);
120 
122  iEvent.getByToken(vertexToken, vertexCollection);
123  int nVtx = vertexCollection->size();
124 
126  iEvent.getByToken(electronToken,egCollection);
127  const reco::GsfElectronCollection egCandidates = (*egCollection.product());
128  for ( reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); egIter != egCandidates.end(); ++egIter) {
129  double mvaVal = mvaID_->mva( *egIter, nVtx );
130  double isoDr03 = egIter->dr03TkSumPt() + egIter->dr03EcalRecHitSumEt() + egIter->dr03HcalTowerSumEt();
131  double eleEta = fabs(egIter->eta());
132  if (eleEta <= 1.485 && mvaVal > thresholdBarrel && isoDr03 < thresholdIsoBarrel) {
133  mvaElectrons->push_back( *egIter );
134  reco::GsfElectron::MvaOutput myMvaOutput;
135  myMvaOutput.mva = mvaVal;
136  mvaElectrons->back().setMvaOutput(myMvaOutput);
137  }
138  else if (eleEta > 1.485 && mvaVal > thresholdEndcap && isoDr03 < thresholdIsoEndcap) {
139  mvaElectrons->push_back( *egIter );
140  reco::GsfElectron::MvaOutput myMvaOutput;
141  myMvaOutput.mva = mvaVal;
142  mvaElectrons->back().setMvaOutput(myMvaOutput);
143  }
144 
145 
146  }
147 
148 
149  iEvent.put(mvaElectrons);
150 
151  return true;
152 }
153 
154 //define this as a plug-in
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
ElectronMVAEstimator * mvaID_
tuple vertexCollection
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual bool filter(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::VertexCollection > vertexToken
edm::EDGetTokenT< reco::GsfElectronCollection > electronToken
ElectronIdMVABased(const edm::ParameterSet &)