ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Betchart/TopRefTuple/interface/Tuple_Electron.h
Revision: 1.1
Committed: Wed Nov 7 21:53:10 2012 UTC (12 years, 6 months ago) by bbetchar
Content type: text/plain
Branch: MAIN
Log Message:
Grab ntuplizing codes from UserCode/SusyCAF

File Contents

# User Rev Content
1 bbetchar 1.1 #ifndef TUPLE_ELECTRON
2     #define TUPLE_ELECTRON
3    
4     #include "FWCore/Framework/interface/EDProducer.h"
5     #include "FWCore/Framework/interface/Frameworkfwd.h"
6     #include "FWCore/Utilities/interface/InputTag.h"
7     #include "FWCore/Framework/interface/Event.h"
8     #include "FWCore/Framework/interface/ESHandle.h"
9     #include "FWCore/ParameterSet/interface/ParameterSet.h"
10    
11     #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
12     #include "DataFormats/PatCandidates/interface/Electron.h"
13     #include "DataFormats/BeamSpot/interface/BeamSpot.h"
14     //#include "SUSYBSMAnalysis/SusyCAF/interface/Tuple_functions.h"
15     #include <string>
16    
17     // Conversion variables
18     #include "RecoEgamma/EgammaTools/interface/ConversionTools.h"
19     #include "RecoEgamma/EgammaTools/interface/ConversionFinder.h"
20     #include "MagneticField/Engine/interface/MagneticField.h"
21     #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
22     #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
23    
24     // ID computation
25     #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
26     #include "EGamma/EGammaAnalysisTools/interface/EGammaCutBasedEleId.h"
27    
28    
29     template< typename T >
30     class Tuple_Electron : public edm::EDProducer {
31     public:
32     explicit Tuple_Electron(const edm::ParameterSet&);
33     private:
34     void initTemplate();
35     void initRECO();
36     void initPAT();
37     std::string underscoreless(std::string);
38     void produce(edm::Event &, const edm::EventSetup & );
39     void produceTemplate(edm::Event &, const edm::EventSetup &, edm::Handle<std::vector<T> > &);
40     void produceRECO(edm::Event &, const edm::EventSetup &, edm::Handle<std::vector<T> > &);
41     void producePAT(edm::Event &, const edm::EventSetup &, edm::Handle<std::vector<T> > &);
42     bool isInCollection(const T&, const std::vector<T>&);
43     void pogIdReco(edm::Event& iEvent, const edm::EventSetup& iSetup, reco::GsfElectronRef ele,
44     bool& veto, bool& loose, bool& medium, bool& tight);
45     void pogIdPat(edm::Event& iEvent, const edm::EventSetup& iSetup, const T& ele,
46     bool& veto, bool& loose, bool& medium, bool& tight);
47    
48     typedef reco::Candidate::LorentzVector LorentzVector;
49    
50     // input tags
51     const edm::InputTag inputTag,selectedTag;
52     const std::string Prefix,Suffix;
53     const bool StoreConversionInfo,IdFromReco;
54     const std::vector<std::string> IdFlagsOldStyle;
55    
56     const edm::InputTag conversionsInputTag_, beamSpotInputTag_, rhoIsoInputTag_, primaryVertexInputTag_;
57     const std::vector<edm::InputTag> isoValInputTags_;
58     };
59    
60     template< typename T >
61     Tuple_Electron<T>::Tuple_Electron(const edm::ParameterSet& iConfig) :
62     inputTag(iConfig.getParameter<edm::InputTag>("InputTag")),
63     selectedTag(iConfig.getParameter<edm::InputTag>("SelectedElectrons")),
64     Prefix(iConfig.getParameter<std::string>("Prefix")),
65     Suffix(iConfig.getParameter<std::string>("Suffix")),
66     StoreConversionInfo(iConfig.getParameter<bool>("StoreConversionInfo")),
67     IdFromReco(iConfig.getParameter<bool>("IdFromReco")),
68     IdFlagsOldStyle(iConfig.getParameter<std::vector< std::string> >("IdFlagsOldStyle")),
69    
70     conversionsInputTag_(iConfig.getParameter<edm::InputTag>("conversionsInputTag")),
71     beamSpotInputTag_(iConfig.getParameter<edm::InputTag>("beamSpotInputTag")),
72     rhoIsoInputTag_(iConfig.getParameter<edm::InputTag>("rhoIsoInputTag")),
73     primaryVertexInputTag_(iConfig.getParameter<edm::InputTag>("primaryVertexInputTag")),
74     isoValInputTags_(iConfig.getParameter<std::vector<edm::InputTag> >("isoValInputTags"))
75     {
76     initTemplate();
77     }
78    
79    
80     template< typename T >
81     void Tuple_Electron<T>::initRECO()
82     {
83     produces <bool> ( Prefix + "HandleValid" + Suffix);
84     produces <std::vector<reco::Candidate::LorentzVector> > ( Prefix + "P4" + Suffix );
85     produces <std::vector<int> > ( Prefix + "Charge" + Suffix);
86     produces <std::vector<double> > ( Prefix + "GsfTracknormalizedChi2" + Suffix);
87     produces <std::vector<unsigned> > ( Prefix + "GsfTracknumberOfValidHits" + Suffix);
88    
89     produces <std::vector<int> > (Prefix + "Selected" + Suffix );
90     produces <std::vector<float> > ( Prefix + "GsfTrackChargeMode" + Suffix);
91     produces <std::vector<float> > ( Prefix + "GsfTrackPtMode" + Suffix);
92     produces <std::vector<float> > ( Prefix + "GsfTrackQoverPErrorMode" + Suffix);
93     produces <std::vector<float> > ( Prefix + "GsfTrackCharge" + Suffix);
94     produces <std::vector<float> > ( Prefix + "GsfTrackPt" + Suffix);
95     produces <std::vector<float> > ( Prefix + "GsfTrackQoverPError" + Suffix);
96     produces <std::vector<float> > ( Prefix + "GsfTrackLostHits" + Suffix);
97     produces <std::vector<int> > ( Prefix + "HasValidHitInFirstPixelBarrel" + Suffix);
98     produces <std::vector<int> > ( Prefix + "GsfTrackTrackerExpectedHitsInner" + Suffix);
99     produces <std::vector<double> > ( Prefix + "GsfTrackDxy" + Suffix);
100     produces <std::vector<double> > ( Prefix + "GsfTrackDz" + Suffix);
101     produces <std::vector<double> > ( Prefix + "GsfTrackDxyBS" + Suffix);
102     produces <std::vector<double> > ( Prefix + "GsfTrackDzBS" + Suffix);
103     produces <std::vector<double> > ( Prefix + "GsfTrackVertexz" + Suffix);
104     produces <std::vector<double> > ( Prefix + "GsfTrackDxyError" + Suffix);
105     produces <std::vector<double> > ( Prefix + "GsfTrackDzError" + Suffix);
106    
107     produces <std::vector<int> > ( Prefix + "IsEB" + Suffix);
108     produces <std::vector<int> > ( Prefix + "IsEE" + Suffix);
109     produces <std::vector<float> > ( Prefix + "E1x5" + Suffix);
110     produces <std::vector<float> > ( Prefix + "E5x5" + Suffix);
111     produces <std::vector<float> > ( Prefix + "E2x5Max" + Suffix);
112     produces <std::vector<float> > ( Prefix + "Fbrem" + Suffix);
113     produces <std::vector<float> > ( Prefix + "HcalOverEcal" + Suffix);
114     produces <std::vector<float> > ( Prefix + "HcalDepth1OverEcal" + Suffix);
115     produces <std::vector<float> > ( Prefix + "HcalDepth2OverEcal" + Suffix);
116     produces <std::vector<float> > ( Prefix + "EEleClusterOverPout" + Suffix);
117     produces <std::vector<float> > ( Prefix + "ESeedClusterOverPout" + Suffix);
118     produces <std::vector<float> > ( Prefix + "ESeedClusterOverP" + Suffix);
119     produces <std::vector<float> > ( Prefix + "ESuperClusterOverP" + Suffix);
120     produces <std::vector<float> > ( Prefix + "ESuperClusterEta" + Suffix);
121     produces <std::vector<float> > ( Prefix + "ESuperClusterPhi" + Suffix);
122     produces <std::vector<float> > ( Prefix + "DeltaPhiSuperClusterTrackAtVtx" + Suffix);
123     produces <std::vector<float> > ( Prefix + "DeltaEtaSuperClusterTrackAtVtx" + Suffix);
124     produces <std::vector<float> > ( Prefix + "DeltaPhiSeedClusterTrackAtCalo" + Suffix);
125     produces <std::vector<float> > ( Prefix + "DeltaEtaSeedClusterTrackAtCalo" + Suffix);
126     produces <std::vector<float> > ( Prefix + "DeltaEtaEleClusterTrackAtCalo" + Suffix);
127     produces <std::vector<float> > ( Prefix + "DeltaPhiEleClusterTrackAtCalo" + Suffix);
128     produces <std::vector<float> > ( Prefix + "SigmaEtaEta" + Suffix);
129     produces <std::vector<float> > ( Prefix + "SigmaIetaIeta" + Suffix);
130     produces <std::vector<float> > ( Prefix + "Classification" + Suffix);
131     produces <std::vector<float> > ( Prefix + "Mva" + Suffix);
132     produces <std::vector<float> > ( Prefix + "Dr03TkSumPt" + Suffix);
133     produces <std::vector<float> > ( Prefix + "Dr03EcalRecHitSumEt" + Suffix);
134     produces <std::vector<float> > ( Prefix + "Dr03HcalTowerSumEt" + Suffix);
135     produces <std::vector<float> > ( Prefix + "Dr03HcalDepth1TowerSumEt" + Suffix);
136     produces <std::vector<float> > ( Prefix + "Dr03HcalDepth2TowerSumEt" + Suffix);
137     produces <std::vector<float> > ( Prefix + "CaloEnergy" + Suffix);
138     produces <std::vector<float> > ( Prefix + "EcalEnergy" + Suffix);
139     produces <std::vector<float> > ( Prefix + "EcalEnergyError" + Suffix);
140     produces <std::vector<float> > ( Prefix + "ElectronMomentumError" + Suffix);
141     produces <std::vector<float> > ( Prefix + "NumberOfTracks" + Suffix);
142     produces <std::vector<int> > ( Prefix + "NumberOfBrems" + Suffix);
143     produces <std::vector<float> > ( Prefix + "ShFracInnerHits" + Suffix);
144     produces <std::vector<math::XYZPoint> > ( Prefix + "Vertex" + Suffix);
145     produces <std::vector<double> > ( Prefix + "VertexChi2" + Suffix);
146     produces <std::vector<double> > ( Prefix + "VertexNdof" + Suffix);
147     produces <bool> ( Prefix + "ConversionInfoStored" + Suffix);
148     if(StoreConversionInfo){
149     produces <std::vector<double> > ( Prefix + "ConversionDCot" + Suffix );
150     produces <std::vector<double> > ( Prefix + "ConversionDist" + Suffix );
151     produces <std::vector<int> > ( Prefix + "ConversionMissingHits" + Suffix );
152     produces <std::vector<int> > ( Prefix + "ConversionPartnerCtfTrackTrackerExpectedHitsInner" + Suffix);
153     produces <std::vector<int> > ( Prefix + "ConversionPartnerGsfTrackTrackerExpectedHitsInner" + Suffix);
154     }
155     produces <std::vector<float> > ( Prefix + "KfTrackCharge" + Suffix );
156     produces <std::vector<int> > ( Prefix + "ScPixCharge" + Suffix );
157     produces <std::vector<int> > ( Prefix + "ClosestCtfTrackCharge" + Suffix );
158    
159     if(IdFromReco){
160     produces <std::vector<int> > (Prefix + "IdVeto" + Suffix);
161     produces <std::vector<int> > (Prefix + "IdLoose" + Suffix);
162     produces <std::vector<int> > (Prefix + "IdMedium" + Suffix);
163     produces <std::vector<int> > (Prefix + "IdTight" + Suffix);
164     }
165     }
166    
167     template< typename T >
168     std::string Tuple_Electron<T>::underscoreless(std::string s) {
169     while(s.find("_")!=std::string::npos) s.replace(s.find("_"), 1, "");
170     return s;
171     }
172    
173     // extra information stored for PAT data
174     template< typename T >
175     void Tuple_Electron<T>::initPAT()
176     {
177     produces <std::vector<float> > (Prefix + "EcalIso" + Suffix);
178     produces <std::vector<float> > (Prefix + "HcalIso" + Suffix);
179     produces <std::vector<float> > (Prefix + "TrackIso" + Suffix);
180     produces <std::vector<float> > (Prefix + "EcalIsoDep" + Suffix);
181     produces <std::vector<float> > (Prefix + "HcalIsoDep" + Suffix);
182     produces <std::vector<int> > (Prefix + "ProducedFromPF" + Suffix);
183     produces <std::vector<float> > (Prefix + "ParticleIso" + Suffix);
184     produces <std::vector<float> > (Prefix + "ChargedHadronIso" + Suffix);
185     produces <std::vector<float> > (Prefix + "NeutralHadronIso" + Suffix);
186     produces <std::vector<float> > (Prefix + "PhotonIso" + Suffix);
187     produces <std::vector<float> > (Prefix + "ChargedHadronIsoRA4" + Suffix);
188     produces <std::vector<float> > (Prefix + "NeutralHadronIsoRA4" + Suffix);
189     produces <std::vector<float> > (Prefix + "PhotonIsoRA4" + Suffix);
190     produces <std::vector<int> > ( Prefix + "ConversionRejection" + Suffix);
191     if(!IdFromReco) {
192     produces <std::vector<int> > (Prefix + "IdVeto" + Suffix);
193     produces <std::vector<int> > (Prefix + "IdLoose" + Suffix);
194     produces <std::vector<int> > (Prefix + "IdMedium" + Suffix);
195     produces <std::vector<int> > (Prefix + "IdTight" + Suffix);
196     }
197    
198     for(std::vector<std::string>::const_iterator name=IdFlagsOldStyle.begin(); name!=IdFlagsOldStyle.end(); ++name) {
199     produces <std::vector<int> > (Prefix + underscoreless(*name) + Suffix);
200     }
201    
202     }
203    
204     template< typename T >
205     void Tuple_Electron<T>::
206     produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
207     edm::Handle<std::vector<T> > collection;
208     iEvent.getByLabel(inputTag,collection);
209    
210     produceTemplate(iEvent, iSetup, collection);
211     }
212    
213     template< typename T >
214     void Tuple_Electron<T>::
215     produceRECO(edm::Event& iEvent, const edm::EventSetup& iSetup, edm::Handle<std::vector<T> >& collection) {
216    
217     std::auto_ptr<bool> isHandleValid ( new bool(collection.isValid()) );
218     std::auto_ptr<std::vector<reco::Candidate::LorentzVector> > p4 ( new std::vector<reco::Candidate::LorentzVector>() );
219     std::auto_ptr<std::vector<int> > charge ( new std::vector<int>() ) ;
220     std::auto_ptr<std::vector<double> > gsfTrack_normalizedChi2 ( new std::vector<double>() ) ;
221     std::auto_ptr<std::vector<unsigned> > gsfTrack_numberOfValidHits ( new std::vector<unsigned>() ) ;
222    
223     std::auto_ptr<std::vector<int> > selected ( new std::vector<int>() ) ;
224    
225     std::auto_ptr<std::vector<double> > gsfTrack_dxy ( new std::vector<double>() ) ;
226     std::auto_ptr<std::vector<double> > gsfTrack_dz ( new std::vector<double>() ) ;
227     std::auto_ptr<std::vector<double> > gsfTrack_dxyBS ( new std::vector<double>() ) ;
228     std::auto_ptr<std::vector<double> > gsfTrack_dzBS ( new std::vector<double>() ) ;
229     std::auto_ptr<std::vector<double> > gsfTrack_vertexz ( new std::vector<double>() ) ;
230     std::auto_ptr<std::vector<double> > gsfTrack_dxyError( new std::vector<double>() ) ;
231     std::auto_ptr<std::vector<double> > gsfTrack_dzError ( new std::vector<double>() ) ;
232    
233     std::auto_ptr<std::vector<int> > isEB (new std::vector<int>() );
234     std::auto_ptr<std::vector<int> > isEE (new std::vector<int>() );
235     std::auto_ptr<std::vector<float> > gsfTrkChargeMode (new std::vector<float>() );
236     std::auto_ptr<std::vector<float> > gsfTrkPtMode (new std::vector<float>() );
237     std::auto_ptr<std::vector<float> > gsfTrkQoverPErrMode (new std::vector<float>() );
238     std::auto_ptr<std::vector<float> > gsfTrkCharge (new std::vector<float>() );
239     std::auto_ptr<std::vector<float> > gsfTrkPt (new std::vector<float>() );
240     std::auto_ptr<std::vector<float> > gsfTrkQoverPErr (new std::vector<float>() );
241     std::auto_ptr<std::vector<float> > gsfTrkLostHits (new std::vector<float>() );
242     std::auto_ptr<std::vector<int> > hasValHitinFirstPixBarrel (new std::vector<int>() );
243     std::auto_ptr<std::vector<int> > gsfTrkTrackerExpectedHitsInner (new std::vector<int>() );
244     std::auto_ptr<std::vector<float> > e1x5 ( new std::vector<float>() ) ;
245     std::auto_ptr<std::vector<float> > e5x5 ( new std::vector<float>() ) ;
246     std::auto_ptr<std::vector<float> > e2x5Max ( new std::vector<float>() ) ;
247     std::auto_ptr<std::vector<float> > fbrem ( new std::vector<float>() ) ;
248     std::auto_ptr<std::vector<float> > hcalOverEcal ( new std::vector<float>() ) ;
249     std::auto_ptr<std::vector<float> > hcalDepth1OverEcal ( new std::vector<float>() ) ;
250     std::auto_ptr<std::vector<float> > hcalDepth2OverEcal ( new std::vector<float>() ) ;
251     std::auto_ptr<std::vector<float> > eEleClusterOverPout ( new std::vector<float>() ) ;
252     std::auto_ptr<std::vector<float> > eSeedClusterOverPout ( new std::vector<float>() ) ;
253     std::auto_ptr<std::vector<float> > eSeedClusterOverP ( new std::vector<float>() ) ;
254     std::auto_ptr<std::vector<float> > eSuperClusterOverP ( new std::vector<float>() ) ;
255     std::auto_ptr<std::vector<float> > eSuperClusterEta ( new std::vector<float>() ) ;
256     std::auto_ptr<std::vector<float> > eSuperClusterPhi ( new std::vector<float>() ) ;
257     std::auto_ptr<std::vector<float> > deltaPhiSuperClusterTrackAtVtx ( new std::vector<float>() ) ;
258     std::auto_ptr<std::vector<float> > deltaEtaSuperClusterTrackAtVtx ( new std::vector<float>() ) ;
259     std::auto_ptr<std::vector<float> > deltaPhiSeedClusterTrackAtCalo ( new std::vector<float>() ) ;
260     std::auto_ptr<std::vector<float> > deltaEtaSeedClusterTrackAtCalo ( new std::vector<float>() ) ;
261     std::auto_ptr<std::vector<float> > deltaEtaEleClusterTrackAtCalo ( new std::vector<float>() ) ;
262     std::auto_ptr<std::vector<float> > deltaPhiEleClusterTrackAtCalo ( new std::vector<float>() ) ;
263     std::auto_ptr<std::vector<float> > sigmaEtaEta ( new std::vector<float>() ) ;
264     std::auto_ptr<std::vector<float> > sigmaIetaIeta ( new std::vector<float>() ) ;
265     std::auto_ptr<std::vector<float> > classification ( new std::vector<float>() ) ;
266     std::auto_ptr<std::vector<float> > mva ( new std::vector<float>() ) ;
267     std::auto_ptr<std::vector<float> > dr03TkSumPt ( new std::vector<float>() ) ;
268     std::auto_ptr<std::vector<float> > dr03EcalRecHitSumEt ( new std::vector<float>() ) ;
269     std::auto_ptr<std::vector<float> > dr03HcalTowerSumEt ( new std::vector<float>() ) ;
270     std::auto_ptr<std::vector<float> > dr03HcalDepth1TowerSumEt ( new std::vector<float>() ) ;
271     std::auto_ptr<std::vector<float> > dr03HcalDepth2TowerSumEt ( new std::vector<float>() ) ;
272     std::auto_ptr<std::vector<float> > caloEnergy ( new std::vector<float>() ) ;
273     std::auto_ptr<std::vector<float> > ecalEnergy ( new std::vector<float>() ) ;
274     std::auto_ptr<std::vector<float> > ecalEnergyError ( new std::vector<float>() ) ;
275     std::auto_ptr<std::vector<float> > electronMomentumError ( new std::vector<float>() ) ;
276     std::auto_ptr<std::vector<float> > numberOfTracks ( new std::vector<float>() ) ;
277     std::auto_ptr<std::vector<int> > numberOfBrems ( new std::vector<int>() ) ;
278     std::auto_ptr<std::vector<float> > shFracInnerHits ( new std::vector<float>() ) ;
279     std::auto_ptr<std::vector<math::XYZPoint> > vertex ( new std::vector<math::XYZPoint>() ) ;
280     std::auto_ptr<std::vector<double> > vertexChi2 ( new std::vector<double>() ) ;
281     std::auto_ptr<std::vector<double> > vertexNdof ( new std::vector<double>() ) ;
282     std::auto_ptr<bool> conversionInfoStored ( new bool() );
283     std::auto_ptr<std::vector<double> > dcot ( new std::vector<double>() ) ;
284     std::auto_ptr<std::vector<double> > dist ( new std::vector<double>() ) ;
285     std::auto_ptr<std::vector<int> > missingHits ( new std::vector<int>() ) ;
286     std::auto_ptr<std::vector<int> > conversionPartnerCtfTrackTrackerExpectedHitsInner ( new std::vector<int>() ) ;
287     std::auto_ptr<std::vector<int> > conversionPartnerGsfTrackTrackerExpectedHitsInner ( new std::vector<int>() ) ;
288     std::auto_ptr<std::vector<float> > kfcharge ( new std::vector<float>() );
289     std::auto_ptr<std::vector<int> > scPixCharge ( new std::vector<int>() );
290     std::auto_ptr<std::vector<int> > closestCtfTrackCharge( new std::vector<int>() );
291    
292     std::auto_ptr<std::vector<int> > idVeto( new std::vector<int>() );
293     std::auto_ptr<std::vector<int> > idLoose( new std::vector<int>() );
294     std::auto_ptr<std::vector<int> > idMedium( new std::vector<int>() );
295     std::auto_ptr<std::vector<int> > idTight( new std::vector<int>() );
296    
297     math::XYZPoint bs = math::XYZPoint(0.,0.,0.);
298     math::XYZPoint vx = math::XYZPoint(0.,0.,0.);
299     edm::Handle<reco::BeamSpot> beamspots; iEvent.getByLabel(beamSpotInputTag_, beamspots);
300     edm::Handle<reco::VertexCollection> vertices; iEvent.getByLabel(primaryVertexInputTag_, vertices);
301    
302     if (beamspots.isValid()) bs = beamspots->position();
303    
304     const MagneticField *mField = 0;
305     edm::Handle<reco::TrackCollection> ctfTracks;
306     edm::Handle<reco::GsfTrackCollection> gsfTracks;
307     ConversionFinder cf;
308     if(StoreConversionInfo){
309     edm::ESHandle<MagneticField> magneticField;
310     iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
311     mField = magneticField.product();
312     iEvent.getByLabel("generalTracks", ctfTracks);
313     iEvent.getByLabel("electronGsfTracks", gsfTracks);
314     }
315    
316     edm::Handle<std::vector<T> > selectedHandle;
317     iEvent.getByLabel(selectedTag,selectedHandle);
318    
319     if (collection.isValid()){
320     for(typename std::vector<T>::const_iterator it = collection->begin(); it!=collection->end(); it++) {
321    
322     p4->push_back(it->p4());
323     charge->push_back(it->charge());
324     gsfTrack_normalizedChi2->push_back(it->gsfTrack()->normalizedChi2());
325     gsfTrack_numberOfValidHits->push_back(it->gsfTrack()->numberOfValidHits());
326    
327     isEB->push_back(it->isEB());
328     isEE->push_back(it->isEE());
329    
330     selected->push_back(selectedHandle.isValid() && isInCollection(*it, *selectedHandle) ) ;
331    
332     //if(vertices.isValid() && vertices->size()) vx = Tuple_functions::closestDzPrimaryVertexPosition(it->gsfTrack().get(),*vertices);
333     gsfTrack_dxy->push_back(it->gsfTrack()->dxy(vx));
334     gsfTrack_dz->push_back(it->gsfTrack()->dz(vx));
335     gsfTrack_dxyBS->push_back(it->gsfTrack()->dxy(bs));
336     gsfTrack_dzBS->push_back(it->gsfTrack()->dz(bs));
337     gsfTrack_vertexz->push_back(it->gsfTrack()->vertex().z());
338     gsfTrack_dxyError->push_back(it->gsfTrack()->dxyError());
339     gsfTrack_dzError->push_back(it->gsfTrack()->dzError());
340    
341     gsfTrkChargeMode->push_back(it->gsfTrack()->chargeMode());
342     gsfTrkPtMode->push_back(it->gsfTrack()->ptMode());
343     gsfTrkQoverPErrMode->push_back(it->gsfTrack()->qoverpModeError());
344     gsfTrkCharge->push_back(it->gsfTrack()->charge());
345     gsfTrkPt->push_back(it->gsfTrack()->pt());
346     gsfTrkQoverPErr->push_back(it->gsfTrack()->qoverpError());
347     gsfTrkLostHits->push_back(it->gsfTrack()->lost());
348     hasValHitinFirstPixBarrel->push_back(it->gsfTrack()->hitPattern().hasValidHitInFirstPixelBarrel());
349     gsfTrkTrackerExpectedHitsInner->push_back(it->gsfTrack()->trackerExpectedHitsInner().numberOfHits());
350     e1x5->push_back(it->e1x5());
351     e5x5->push_back(it->e5x5());
352     e2x5Max->push_back(it->e2x5Max());
353     fbrem->push_back(it->fbrem());
354     hcalOverEcal->push_back(it->hcalOverEcal());
355     hcalDepth1OverEcal->push_back(it->hcalDepth1OverEcal());
356     hcalDepth2OverEcal->push_back(it->hcalDepth2OverEcal());
357     eEleClusterOverPout->push_back(it->eEleClusterOverPout());
358     eSeedClusterOverPout->push_back(it->eSeedClusterOverPout());
359     eSeedClusterOverP->push_back(it->eSeedClusterOverP());
360     eSuperClusterOverP->push_back(it->eSuperClusterOverP());
361     eSuperClusterEta->push_back(it->superClusterPosition().Eta());
362     eSuperClusterPhi->push_back(it->superClusterPosition().Phi());
363     deltaPhiSuperClusterTrackAtVtx->push_back(it->deltaPhiSuperClusterTrackAtVtx());
364     deltaEtaSuperClusterTrackAtVtx->push_back(it->deltaEtaSuperClusterTrackAtVtx());
365     deltaPhiSeedClusterTrackAtCalo->push_back(it->deltaPhiSeedClusterTrackAtCalo());
366     deltaEtaSeedClusterTrackAtCalo->push_back(it->deltaEtaSeedClusterTrackAtCalo());
367     deltaEtaEleClusterTrackAtCalo->push_back(it->deltaEtaEleClusterTrackAtCalo());
368     deltaPhiEleClusterTrackAtCalo->push_back(it->deltaPhiEleClusterTrackAtCalo());
369     sigmaEtaEta->push_back(it->sigmaEtaEta());
370     sigmaIetaIeta->push_back(it->sigmaIetaIeta());
371     classification->push_back(it->classification());
372     mva->push_back(it->mva());
373     dr03TkSumPt->push_back(it->dr03TkSumPt());
374     dr03EcalRecHitSumEt->push_back(it->dr03EcalRecHitSumEt());
375     dr03HcalTowerSumEt->push_back(it->dr03HcalTowerSumEt());
376     dr03HcalDepth1TowerSumEt->push_back(it->dr03HcalDepth1TowerSumEt());
377     dr03HcalDepth2TowerSumEt->push_back(it->dr03HcalDepth2TowerSumEt());
378     caloEnergy->push_back(it->caloEnergy());
379     ecalEnergy->push_back(it->ecalEnergy());
380     ecalEnergyError->push_back(it->ecalEnergyError());
381     electronMomentumError->push_back(it->p4Error(it->candidateP4Kind()));
382     numberOfTracks->push_back(it->numberOfTracks());
383     numberOfBrems->push_back(it->numberOfBrems());
384     shFracInnerHits->push_back(it->shFracInnerHits());
385     vertex->push_back(it->vertex());
386     vertexChi2->push_back(it->vertexChi2());
387     vertexNdof->push_back(it->vertexNdof());
388    
389     if(StoreConversionInfo && ctfTracks.isValid() && gsfTracks.isValid()){
390     *conversionInfoStored = true;
391    
392     const math::XYZPoint tpoint = it->gsfTrack()->referencePoint();
393     const GlobalPoint gp(tpoint.x(), tpoint.y(), tpoint.z());
394     double bfield = mField->inTesla(gp).mag();
395     ConversionInfo info = cf.getConversionInfo(*it, ctfTracks, gsfTracks, bfield);
396     dist->push_back(info.dist());
397     dcot->push_back(info.dcot());
398     missingHits->push_back(it->gsfTrack()->trackerExpectedHitsInner().numberOfHits());
399     conversionPartnerCtfTrackTrackerExpectedHitsInner->push_back(info.conversionPartnerCtfTk().isAvailable() ?
400     info.conversionPartnerCtfTk()->trackerExpectedHitsInner().numberOfHits() : -1);
401     conversionPartnerGsfTrackTrackerExpectedHitsInner->push_back(info.conversionPartnerGsfTk().isAvailable() ?
402     info.conversionPartnerGsfTk()->trackerExpectedHitsInner().numberOfHits() : -1);
403     }
404     kfcharge->push_back(it->track().isAvailable() ? it->track()->charge() : 0);
405     scPixCharge->push_back(it->scPixCharge());
406     closestCtfTrackCharge->push_back(it->closestCtfTrackRef().isAvailable() ? it->closestCtfTrackRef()->charge() : 0) ;
407    
408     //not yet working
409     if(IdFromReco) {
410     //bool veto,loose,medium,tight;
411     //pogIdReco(iEvent, iSetup, reco::GsfElectronRef(*it), veto, loose, medium, tight);
412     //idVeto->push_back(veto);
413     //idLoose->push_back(loose);
414     //idMedium->push_back(medium);
415     //idTight->push_back(tight);
416     }
417     }
418     }
419    
420     iEvent.put( isHandleValid, Prefix + "HandleValid" + Suffix );
421     iEvent.put( p4, Prefix + "P4" + Suffix );
422     iEvent.put( charge, Prefix + "Charge" + Suffix );
423    
424     iEvent.put( selected, Prefix + "Selected" + Suffix );
425     iEvent.put( gsfTrack_normalizedChi2, Prefix + "GsfTracknormalizedChi2" + Suffix );
426     iEvent.put( gsfTrack_numberOfValidHits, Prefix + "GsfTracknumberOfValidHits" + Suffix );
427    
428     iEvent.put( isEB, Prefix + "IsEB" + Suffix );
429     iEvent.put( isEE, Prefix + "IsEE" + Suffix );
430    
431     iEvent.put( gsfTrack_dxy, Prefix + "GsfTrackDxy" + Suffix );
432     iEvent.put( gsfTrack_dz, Prefix + "GsfTrackDz" + Suffix );
433     iEvent.put( gsfTrack_dxyBS, Prefix + "GsfTrackDxyBS" + Suffix );
434     iEvent.put( gsfTrack_dzBS, Prefix + "GsfTrackDzBS" + Suffix );
435     iEvent.put( gsfTrack_vertexz, Prefix + "GsfTrackVertexz" + Suffix );
436     iEvent.put( gsfTrack_dxyError, Prefix + "GsfTrackDxyError" + Suffix );
437     iEvent.put( gsfTrack_dzError, Prefix + "GsfTrackDzError" + Suffix );
438    
439     iEvent.put( gsfTrkChargeMode, Prefix + "GsfTrackChargeMode" + Suffix );
440     iEvent.put( gsfTrkPtMode, Prefix + "GsfTrackPtMode" + Suffix );
441     iEvent.put( gsfTrkQoverPErrMode, Prefix + "GsfTrackQoverPErrorMode" + Suffix );
442     iEvent.put( gsfTrkCharge, Prefix + "GsfTrackCharge" + Suffix );
443     iEvent.put( gsfTrkPt, Prefix+ "GsfTrackPt" + Suffix);
444     iEvent.put( gsfTrkQoverPErr, Prefix + "GsfTrackQoverPError" + Suffix );
445     iEvent.put( gsfTrkLostHits, Prefix + "GsfTrackLostHits" + Suffix );
446     iEvent.put( hasValHitinFirstPixBarrel, Prefix + "HasValidHitInFirstPixelBarrel" + Suffix);
447     iEvent.put( gsfTrkTrackerExpectedHitsInner, Prefix + "GsfTrackTrackerExpectedHitsInner" + Suffix);
448     iEvent.put( e1x5, Prefix + "E1x5" + Suffix );
449     iEvent.put( e5x5, Prefix + "E5x5" + Suffix );
450     iEvent.put( e2x5Max, Prefix + "E2x5Max" + Suffix );
451     iEvent.put( fbrem, Prefix + "Fbrem" + Suffix );
452     iEvent.put( hcalOverEcal, Prefix + "HcalOverEcal" + Suffix );
453     iEvent.put( hcalDepth1OverEcal, Prefix + "HcalDepth1OverEcal" + Suffix );
454     iEvent.put( hcalDepth2OverEcal, Prefix + "HcalDepth2OverEcal" + Suffix );
455     iEvent.put( eEleClusterOverPout, Prefix + "EEleClusterOverPout" + Suffix );
456     iEvent.put( eSeedClusterOverPout, Prefix + "ESeedClusterOverPout" + Suffix );
457     iEvent.put( eSeedClusterOverP, Prefix + "ESeedClusterOverP" + Suffix );
458     iEvent.put (eSuperClusterEta, Prefix + "ESuperClusterEta" + Suffix);
459     iEvent.put (eSuperClusterPhi, Prefix + "ESuperClusterPhi" + Suffix);
460     iEvent.put( eSuperClusterOverP, Prefix + "ESuperClusterOverP" + Suffix );
461     iEvent.put( deltaPhiSuperClusterTrackAtVtx, Prefix + "DeltaPhiSuperClusterTrackAtVtx" + Suffix );
462     iEvent.put( deltaEtaSuperClusterTrackAtVtx, Prefix + "DeltaEtaSuperClusterTrackAtVtx" + Suffix );
463     iEvent.put( deltaPhiSeedClusterTrackAtCalo, Prefix + "DeltaPhiSeedClusterTrackAtCalo" + Suffix );
464     iEvent.put( deltaEtaSeedClusterTrackAtCalo, Prefix + "DeltaEtaSeedClusterTrackAtCalo" + Suffix );
465     iEvent.put( deltaEtaEleClusterTrackAtCalo, Prefix + "DeltaEtaEleClusterTrackAtCalo" + Suffix );
466     iEvent.put( deltaPhiEleClusterTrackAtCalo, Prefix + "DeltaPhiEleClusterTrackAtCalo" + Suffix );
467     iEvent.put( sigmaEtaEta, Prefix + "SigmaEtaEta" + Suffix );
468     iEvent.put( sigmaIetaIeta, Prefix + "SigmaIetaIeta" + Suffix );
469     iEvent.put( classification, Prefix + "Classification" + Suffix );
470     iEvent.put( mva, Prefix + "Mva" + Suffix );
471     iEvent.put( dr03TkSumPt, Prefix + "Dr03TkSumPt" + Suffix );
472     iEvent.put( dr03EcalRecHitSumEt, Prefix + "Dr03EcalRecHitSumEt" + Suffix );
473     iEvent.put( dr03HcalTowerSumEt, Prefix + "Dr03HcalTowerSumEt" + Suffix );
474     iEvent.put( dr03HcalDepth1TowerSumEt, Prefix + "Dr03HcalDepth1TowerSumEt" + Suffix );
475     iEvent.put( dr03HcalDepth2TowerSumEt, Prefix + "Dr03HcalDepth2TowerSumEt" + Suffix );
476     iEvent.put( caloEnergy, Prefix + "CaloEnergy" + Suffix );
477     iEvent.put( ecalEnergy, Prefix + "EcalEnergy" + Suffix );
478     iEvent.put( ecalEnergyError, Prefix + "EcalEnergyError" + Suffix );
479     iEvent.put( electronMomentumError, Prefix + "ElectronMomentumError" + Suffix );
480     iEvent.put( numberOfTracks, Prefix + "NumberOfTracks" + Suffix );
481     iEvent.put( numberOfBrems, Prefix + "NumberOfBrems" + Suffix );
482     iEvent.put( shFracInnerHits, Prefix + "ShFracInnerHits" + Suffix );
483     iEvent.put( vertex, Prefix + "Vertex" + Suffix );
484     iEvent.put( vertexChi2, Prefix + "VertexChi2" + Suffix );
485     iEvent.put( vertexNdof, Prefix + "VertexNdof" + Suffix );
486     if(StoreConversionInfo) {
487     iEvent.put( dist, Prefix + "ConversionDist" + Suffix );
488     iEvent.put( dcot, Prefix + "ConversionDCot" + Suffix );
489     iEvent.put( missingHits, Prefix + "ConversionMissingHits" + Suffix );
490     iEvent.put( conversionPartnerCtfTrackTrackerExpectedHitsInner, Prefix + "ConversionPartnerCtfTrackTrackerExpectedHitsInner" + Suffix );
491     iEvent.put( conversionPartnerGsfTrackTrackerExpectedHitsInner, Prefix + "ConversionPartnerGsfTrackTrackerExpectedHitsInner" + Suffix );
492     }
493     iEvent.put( conversionInfoStored , Prefix + "ConversionInfoStored" + Suffix );
494     iEvent.put(kfcharge, Prefix + "KfTrackCharge" + Suffix);
495     iEvent.put(scPixCharge, Prefix + "ScPixCharge" + Suffix);
496     iEvent.put(closestCtfTrackCharge, Prefix + "ClosestCtfTrackCharge" + Suffix);
497    
498     if(IdFromReco) {
499     iEvent.put(idVeto, Prefix + "IdVeto" + Suffix);
500     iEvent.put(idLoose, Prefix + "IdLoose" + Suffix);
501     iEvent.put(idMedium, Prefix + "IdMedium" + Suffix);
502     iEvent.put(idTight, Prefix + "IdTight" + Suffix);
503     }
504    
505     }
506    
507     // extra information stored for PAT data
508     template< typename T >
509     void Tuple_Electron<T>::
510     producePAT(edm::Event& iEvent, const edm::EventSetup& iSetup, edm::Handle<std::vector<T> >& collection) {
511    
512     std::map< std::string, std::vector<int> > idsOld;
513    
514     for(std::vector<std::string>::const_iterator name=IdFlagsOldStyle.begin(); name!=IdFlagsOldStyle.end(); ++name) {
515     idsOld[*name] = std::vector<int>();
516     }
517    
518     std::auto_ptr<std::vector<int> > idVeto( new std::vector<int>() );
519     std::auto_ptr<std::vector<int> > idLoose( new std::vector<int>() );
520     std::auto_ptr<std::vector<int> > idMedium( new std::vector<int>() );
521     std::auto_ptr<std::vector<int> > idTight( new std::vector<int>() );
522    
523     std::auto_ptr<std::vector<float> > ecalIso ( new std::vector<float>() );
524     std::auto_ptr<std::vector<float> > hcalIso ( new std::vector<float>() );
525     std::auto_ptr<std::vector<float> > trackIso ( new std::vector<float>() );
526     std::auto_ptr<std::vector<float> > ecalIsoDep( new std::vector<float>() );
527     std::auto_ptr<std::vector<float> > hcalIsoDep( new std::vector<float>() );
528    
529     std::auto_ptr<std::vector<int> > ispf (new std::vector<int>() );
530     std::auto_ptr<std::vector<float> > partIso (new std::vector<float>() );
531     std::auto_ptr<std::vector<float> > charHadIso (new std::vector<float>() );
532     std::auto_ptr<std::vector<float> > neutHadIso (new std::vector<float>() );
533     std::auto_ptr<std::vector<float> > photIso (new std::vector<float>() );
534     std::auto_ptr<std::vector<float> > charHadIsoRA4 (new std::vector<float>() );
535     std::auto_ptr<std::vector<float> > neutHadIsoRA4 (new std::vector<float>() );
536     std::auto_ptr<std::vector<float> > photIsoRA4 (new std::vector<float>() );
537     std::auto_ptr<std::vector<int> > conversionRejection ( new std::vector<int>() );
538    
539     if (collection.isValid()){
540     for(std::vector<pat::Electron>::const_iterator it = collection->begin(); it!=collection->end(); it++) {
541    
542    
543     // -- converion rejection store bool
544     // beam spot
545     edm::Handle<reco::BeamSpot> beamspot_h;
546     iEvent.getByLabel(beamSpotInputTag_, beamspot_h);
547     const reco::BeamSpot &beamSpot = *(beamspot_h.product());
548    
549     // conversions
550     edm::Handle<reco::ConversionCollection> conversions_h;
551     iEvent.getByLabel(conversionsInputTag_, conversions_h);
552    
553     // bool tmpConvRej = ConversionTools::hasMatchedConversion((const reco::GsfElectron)*it, conversions_h, beamSpot.position());
554     // conversionRejection->push_back(tmpConvRej);
555     conversionRejection->push_back(ConversionTools::hasMatchedConversion((const reco::GsfElectron)*it, conversions_h, beamSpot.position()));
556    
557     // -- store pfIso values as described below Twiki apply 2012 electron id by hand
558     edm::Ptr< reco::GsfElectron > ele = (edm::Ptr< reco::GsfElectron >) it->originalObjectRef();
559    
560     std::vector< edm::Handle< edm::ValueMap<double> > > isoVals(isoValInputTags_.size());
561     for (size_t j = 0; j < isoValInputTags_.size(); ++j) {
562     iEvent.getByLabel(isoValInputTags_[j], isoVals[j]);
563     }
564    
565     charHadIsoRA4->push_back((*(isoVals)[0])[ele]);
566     photIsoRA4->push_back((*(isoVals)[1])[ele]);
567     neutHadIsoRA4->push_back((*(isoVals)[2])[ele]);
568    
569    
570    
571     //old-style IDs
572     for(std::map< std::string, std::vector<int> >::const_iterator id=idsOld.begin(); id!=idsOld.end(); ++id) {
573     idsOld[id->first].push_back(it->electronID(id->first));
574     }
575    
576     if(!IdFromReco) {
577     bool veto,loose,medium,tight;
578     pogIdPat(iEvent, iSetup, *it, veto, loose, medium, tight);
579    
580     idVeto->push_back(veto);
581     idLoose->push_back(loose);
582     idMedium->push_back(medium);
583     idTight->push_back(tight);
584     }
585    
586     ecalIso ->push_back(it->ecalIso());
587     hcalIso ->push_back(it->hcalIso());
588     trackIso->push_back(it->trackIso());
589     ecalIsoDep->push_back(it->ecalIsoDeposit() ? it->ecalIsoDeposit()->candEnergy() : -999.9);
590     hcalIsoDep->push_back(it->hcalIsoDeposit() ? it->hcalIsoDeposit()->candEnergy() : -999.9);
591    
592     ispf->push_back(it->pfCandidateRef().isAvailable());
593     partIso->push_back(it->particleIso());
594     charHadIso->push_back(it->chargedHadronIso());
595     neutHadIso->push_back(it->neutralHadronIso());
596     photIso->push_back(it->photonIso());
597     }
598     } // end loop over electrons
599    
600     //store old-style IDs
601     for(std::map< std::string, std::vector<int> >::const_iterator id=idsOld.begin(); id!=idsOld.end(); ++id) {
602     std::auto_ptr<std::vector<int> > ptr( new std::vector<int>(id->second) );
603     iEvent.put(ptr, Prefix + underscoreless(id->first) + Suffix);
604     }
605    
606     if(!IdFromReco) {
607     iEvent.put(idVeto, Prefix + "IdVeto" + Suffix);
608     iEvent.put(idLoose, Prefix + "IdLoose" + Suffix);
609     iEvent.put(idMedium, Prefix + "IdMedium" + Suffix);
610     iEvent.put(idTight, Prefix + "IdTight" + Suffix);
611     }
612    
613     iEvent.put(ecalIso, Prefix + "EcalIso" + Suffix);
614     iEvent.put(hcalIso, Prefix + "HcalIso" + Suffix);
615     iEvent.put(trackIso, Prefix + "TrackIso" + Suffix);
616     iEvent.put(ecalIsoDep, Prefix + "EcalIsoDep" + Suffix);
617     iEvent.put(hcalIsoDep, Prefix + "HcalIsoDep" + Suffix);
618    
619     iEvent.put(ispf, Prefix + "ProducedFromPF" + Suffix);
620     iEvent.put(partIso, Prefix + "ParticleIso" + Suffix);
621     iEvent.put(charHadIso, Prefix + "ChargedHadronIso" + Suffix);
622     iEvent.put(neutHadIso, Prefix + "NeutralHadronIso" + Suffix);
623     iEvent.put(photIso, Prefix + "PhotonIso" + Suffix);
624     iEvent.put(charHadIsoRA4, Prefix + "ChargedHadronIsoRA4" + Suffix);
625     iEvent.put(neutHadIsoRA4, Prefix + "NeutralHadronIsoRA4" + Suffix);
626     iEvent.put(photIsoRA4, Prefix + "PhotonIsoRA4" + Suffix);
627     iEvent.put(conversionRejection, Prefix + "ConversionRejection" + Suffix );
628     }
629    
630     //2012 ID helper functions
631     template< typename T >
632     void Tuple_Electron<T>::
633     pogIdReco(edm::Event& iEvent, const edm::EventSetup& iSetup, reco::GsfElectronRef ele,
634     bool& veto, bool& loose, bool& medium, bool& tight)
635     {
636     //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/EGamma/EGammaAnalysisTools/src/EGammaCutBasedEleIdAnalyzer.cc?revision=1.2&view=markup
637    
638     // conversions
639     edm::Handle<reco::ConversionCollection> conversions_h;
640     iEvent.getByLabel(conversionsInputTag_, conversions_h);
641    
642     // iso deposits
643     std::vector< edm::Handle< edm::ValueMap<double> > > isoVals(isoValInputTags_.size());
644     for (size_t j = 0; j < isoValInputTags_.size(); ++j) {
645     iEvent.getByLabel(isoValInputTags_[j], isoVals[j]);
646     }
647    
648     // beam spot
649     edm::Handle<reco::BeamSpot> beamspot_h;
650     iEvent.getByLabel(beamSpotInputTag_, beamspot_h);
651     const reco::BeamSpot &beamSpot = *(beamspot_h.product());
652    
653     // vertices
654     edm::Handle<reco::VertexCollection> vtx_h;
655     iEvent.getByLabel(primaryVertexInputTag_, vtx_h);
656    
657     // rho for isolation
658     edm::Handle<double> rhoIso_h;
659     iEvent.getByLabel(rhoIsoInputTag_, rhoIso_h);
660     double rhoIso = *(rhoIso_h.product());
661    
662    
663     // particle flow isolation
664     double iso_ch = (*(isoVals)[0])[ele];
665     double iso_em = (*(isoVals)[1])[ele];
666     double iso_nh = (*(isoVals)[2])[ele];
667    
668    
669     // working points
670     veto = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::VETO, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
671     loose = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::LOOSE, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
672     medium = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::MEDIUM, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
673     tight = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::TIGHT, ele, conversions_h, beamSpot, vtx_h, iso_ch, iso_em, iso_nh, rhoIso);
674    
675     }
676    
677     template< typename T >
678     void Tuple_Electron<T>::
679     pogIdPat(edm::Event& iEvent, const edm::EventSetup& iSetup, const T& ele,
680     bool& veto, bool& loose, bool& medium, bool& tight)
681     {
682     //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/EGamma/EGammaAnalysisTools/src/EGammaCutBasedEleId.cc?revision=1.7&view=markup
683    
684     // conversions
685     edm::Handle<reco::ConversionCollection> conversions_h;
686     iEvent.getByLabel(conversionsInputTag_, conversions_h);
687    
688     // beam spot
689     edm::Handle<reco::BeamSpot> beamspot_h;
690     iEvent.getByLabel(beamSpotInputTag_, beamspot_h);
691     const reco::BeamSpot &beamSpot = *(beamspot_h.product());
692    
693     // vertices
694     edm::Handle<reco::VertexCollection> vtxs;
695     iEvent.getByLabel(primaryVertexInputTag_, vtxs);
696    
697     // kinematic variables
698     bool isEB = ele.isEB() ? true : false;
699     float pt = ele.pt();
700     float eta = ele.superCluster()->eta();
701    
702     // id variables
703     float dEtaIn = ele.deltaEtaSuperClusterTrackAtVtx();
704     float dPhiIn = ele.deltaPhiSuperClusterTrackAtVtx();
705     float sigmaIEtaIEta = ele.sigmaIetaIeta();
706     float hoe = ele.hadronicOverEm();
707     float ooemoop = (1.0/ele.ecalEnergy() - ele.eSuperClusterOverP()/ele.ecalEnergy());
708    
709     // impact parameter variables
710     float d0vtx = 0.0;
711     float dzvtx = 0.0;
712     if (vtxs->size() > 0) {
713     reco::VertexRef vtx(vtxs, 0);
714     d0vtx = ele.gsfTrack()->dxy(vtx->position());
715     dzvtx = ele.gsfTrack()->dz(vtx->position());
716     } else {
717     d0vtx = ele.gsfTrack()->dxy();
718     dzvtx = ele.gsfTrack()->dz();
719     }
720    
721     double iso_ch = ele.chargedHadronIso();
722     double iso_nh = ele.neutralHadronIso();
723     double iso_em = ele.photonIso();
724    
725     // conversion rejection variables
726     bool vtxFitConversion = ConversionTools::hasMatchedConversion((const reco::GsfElectron)ele, conversions_h, beamSpot.position());
727     float mHits = ele.gsfTrack()->trackerExpectedHitsInner().numberOfHits();
728    
729     // rho for isolation
730     edm::Handle<double> rhoIso_h;
731     iEvent.getByLabel(rhoIsoInputTag_, rhoIso_h);
732     double rho = *(rhoIso_h.product());
733    
734     veto = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::VETO, isEB, pt, eta,
735     dEtaIn, dPhiIn, sigmaIEtaIEta, hoe,
736     ooemoop, d0vtx, dzvtx, iso_ch, iso_em, iso_nh,
737     vtxFitConversion, mHits, rho);
738     loose = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::LOOSE, isEB, pt, eta,
739     dEtaIn, dPhiIn, sigmaIEtaIEta, hoe,
740     ooemoop, d0vtx, dzvtx, iso_ch, iso_em, iso_nh,
741     vtxFitConversion, mHits, rho);
742     medium = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::MEDIUM, isEB, pt, eta,
743     dEtaIn, dPhiIn, sigmaIEtaIEta, hoe,
744     ooemoop, d0vtx, dzvtx, iso_ch, iso_em, iso_nh,
745     vtxFitConversion, mHits, rho);
746     tight = EgammaCutBasedEleId::PassWP(EgammaCutBasedEleId::TIGHT, isEB, pt, eta,
747     dEtaIn, dPhiIn, sigmaIEtaIEta, hoe,
748     ooemoop, d0vtx, dzvtx, iso_ch, iso_em, iso_nh,
749     vtxFitConversion, mHits, rho);
750     }
751    
752     #endif