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