ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerElectrons.cc
Revision: 1.13
Committed: Fri Aug 22 09:57:35 2008 UTC (16 years, 8 months ago) by sixie
Content type: text/plain
Branch: MAIN
Changes since 1.12: +27 -18 lines
Log Message:
add pin and pout. add electron ID information.

File Contents

# User Rev Content
1 sixie 1.13 // $Id: FillerElectrons.cc,v 1.12 2008/08/18 11:34:02 sixie Exp $
2 loizides 1.1
3     #include "MitProd/TreeFiller/interface/FillerElectrons.h"
4     #include "FWCore/MessageLogger/interface/MessageLogger.h"
5     #include "DataFormats/Common/interface/Handle.h"
6     #include "DataFormats/TrackReco/interface/Track.h"
7     #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
8     #include "DataFormats/TrackReco/interface/TrackFwd.h"
9 sixie 1.11 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
10     #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
11     #include "DataFormats/EgammaReco/interface/ClusterShape.h"
12     #include "DataFormats/EgammaReco/interface/BasicClusterShapeAssociation.h"
13     #include "RecoEgamma/EgammaIsolationAlgos/interface/ElectronTkIsolation.h"
14     #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaEcalIsolation.h"
15 loizides 1.1 #include "MitAna/DataTree/interface/Track.h"
16     #include "MitAna/DataTree/interface/Names.h"
17 sixie 1.12 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
18     #include "AnalysisDataFormats/Egamma/interface/ElectronID.h"
19     #include "AnalysisDataFormats/Egamma/interface/ElectronIDAssociation.h"
20 loizides 1.1
21 sixie 1.13 #include "DataFormats/Common/interface/ValueMap.h"
22    
23 loizides 1.1 using namespace std;
24     using namespace edm;
25     using namespace mithep;
26    
27 loizides 1.5 //--------------------------------------------------------------------------------------------------
28 loizides 1.10 FillerElectrons::FillerElectrons(const edm::ParameterSet &cfg, bool active) :
29 loizides 1.8 BaseFiller(cfg,"Electrons",active),
30 loizides 1.1 edmName_(Conf().getUntrackedParameter<string>("edmName","pixelMatchGsfElectrons")),
31     mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkElectronBrn)),
32 loizides 1.10 gsfTrackMapName_(Conf().getUntrackedParameter<string>("gsfTrackMapName","")),
33     trackerTrackMapName_(Conf().getUntrackedParameter<string>("trackerTrackMapName","")),
34 sixie 1.12 barrelEcalRecHitName_(Conf().getUntrackedParameter<string>("barrelEcalRecHitName","")),
35     endcapEcalRecHitName_(Conf().getUntrackedParameter<string>("endcapEcalRecHitName","")),
36     barrelSuperClusterName_(Conf().getUntrackedParameter<string>("barrelSuperClusterName", "")),
37     endcapSuperClusterName_(Conf().getUntrackedParameter<string>("endcapSuperClusterName", "")),
38     barrelBasicClusterName_(Conf().getUntrackedParameter<string>("barrelBasicClusterName", "")),
39     endcapBasicClusterName_(Conf().getUntrackedParameter<string>("endcapBasicClusterName", "")),
40     barrelSuperClusterMapName_(Conf().getUntrackedParameter<string>("barrelSuperClusterMapName","")),
41     endcapSuperClusterMapName_(Conf().getUntrackedParameter<string>("endcapSuperClusterMapName","")),
42 sixie 1.13 eIDCutBasedTightName_(Conf().getUntrackedParameter<string>("eIDCutBasedTightName","eidTight'")),
43     eIDCutBasedLooseName_(Conf().getUntrackedParameter<string>("eIDCutBasedLooseName","eidLoose")),
44 sixie 1.12 eIDLikelihoodName_(Conf().getUntrackedParameter<string>("eIDLikelihood","eidLikelihood")),
45     eIDNeuralNetName_(Conf().getUntrackedParameter<string>("eIDNeuralNet","eidNeuralNet")),
46    
47 loizides 1.8 electrons_(new mithep::ElectronArr(16)),
48 loizides 1.10 gsfTrackMap_(0),
49 sixie 1.11 trackerTrackMap_(0),
50 sixie 1.12 barrelSuperClusterMap_(0),
51     endcapSuperClusterMap_(0)
52 loizides 1.1 {
53     // Constructor.
54     }
55    
56 loizides 1.5 //--------------------------------------------------------------------------------------------------
57 loizides 1.1 FillerElectrons::~FillerElectrons()
58     {
59     // Destructor.
60 loizides 1.6
61     delete electrons_;
62 loizides 1.1 }
63    
64 loizides 1.5 //--------------------------------------------------------------------------------------------------
65 loizides 1.1 void FillerElectrons::BookDataBlock(TreeWriter &tws)
66     {
67 loizides 1.10 // Add electron branch to our tree and get our maps.
68 loizides 1.1
69     tws.AddBranch(mitName_.c_str(),&electrons_);
70 loizides 1.10
71     if (!gsfTrackMapName_.empty())
72     gsfTrackMap_ = OS()->get<GsfTrackMap>(gsfTrackMapName_.c_str());
73     if (!trackerTrackMapName_.empty())
74 sixie 1.11 trackerTrackMap_ = OS()->get<TrackMap>(trackerTrackMapName_.c_str());
75 sixie 1.12 if (!barrelSuperClusterMapName_.empty())
76     barrelSuperClusterMap_ = OS()->get<SuperClusterMap>(barrelSuperClusterMapName_.c_str());
77     if (!endcapSuperClusterMapName_.empty())
78     endcapSuperClusterMap_ = OS()->get<SuperClusterMap>(endcapSuperClusterMapName_.c_str());
79 loizides 1.1 }
80    
81 loizides 1.5 //--------------------------------------------------------------------------------------------------
82 sixie 1.11 void FillerElectrons::FillDataBlock(const edm::Event &event, const edm::EventSetup &setup)
83 loizides 1.1 {
84     // Fill electrons from edm collection into our collection.
85    
86     electrons_->Reset();
87    
88 sixie 1.11 Handle<reco::GsfElectronCollection> hElectronProduct;
89 loizides 1.7 GetProduct(edmName_, hElectronProduct, event);
90 loizides 1.1
91 sixie 1.13 //Handles to get the electron ID information
92     Handle<edm::ValueMap<float> > eidLooseMap;
93     GetProduct(eIDCutBasedLooseName_, eidLooseMap, event);
94     Handle<edm::ValueMap<float> > eidTightMap;
95     GetProduct(eIDCutBasedTightName_, eidTightMap, event);
96     Handle<edm::ValueMap<float> > eidLikelihoodMap;
97     GetProduct(eIDLikelihoodName_, eidLikelihoodMap, event);
98    
99 sixie 1.11 const reco::GsfElectronCollection inElectrons = *(hElectronProduct.product());
100     //loop over electrons
101 sixie 1.13
102 sixie 1.11 for (reco::GsfElectronCollection::const_iterator iM = inElectrons.begin();
103 loizides 1.1 iM != inElectrons.end(); ++iM) {
104 sixie 1.13
105     //the index and Ref are needed for the eID association Map
106     unsigned int iElectron = iM - inElectrons.begin();
107     reco::GsfElectronRef eRef(hElectronProduct, iElectron);
108    
109 loizides 1.8 mithep::Electron *outElectron = electrons_->AddNew();
110 sixie 1.12
111 sixie 1.11 outElectron->SetESuperClusterOverP( iM->eSuperClusterOverP() ) ;
112     outElectron->SetESeedClusterOverPout( iM->eSeedClusterOverPout() ) ;
113 sixie 1.13 outElectron->SetPIn( iM->trackMomentumAtVtx().R() ) ;
114     outElectron->SetPOut( iM->trackMomentumOut().R() );
115 sixie 1.11 outElectron->SetDeltaEtaSuperClusterTrackAtVtx( iM->deltaEtaSuperClusterTrackAtVtx() ) ;
116     outElectron->SetDeltaEtaSeedClusterTrackAtCalo( iM->deltaEtaSeedClusterTrackAtCalo() ) ;
117     outElectron->SetDeltaPhiSuperClusterTrackAtVtx( iM->deltaPhiSuperClusterTrackAtVtx() ) ;
118     outElectron->SetDeltaPhiSeedClusterTrackAtCalo( iM->deltaPhiSeedClusterTrackAtCalo() ) ;
119     outElectron->SetHadronicOverEm( iM->hadronicOverEm() ) ;
120     outElectron->SetIsEnergyScaleCorrected( iM->isEnergyScaleCorrected() ) ;
121     outElectron->SetIsMomentumCorrected( iM->isMomentumCorrected() ) ;
122     outElectron->SetNumberOfClusters( iM->numberOfClusters() ) ;
123     outElectron->SetClassification( iM->classification() ) ;
124    
125     //initialize
126     outElectron->SetE33( -999.0 ) ;
127     outElectron->SetE55( -999.0 ) ;
128     outElectron->SetCovEtaEta( -999.0 ) ;
129     outElectron->SetCovEtaPhi( -999.0 ) ;
130 sixie 1.12 outElectron->SetCovPhiPhi( -999.0 ) ;
131    
132     EcalClusterLazyTools lazyTools( event, setup, edm::InputTag(barrelEcalRecHitName_),
133     edm::InputTag(endcapEcalRecHitName_) );
134    
135     //Shower shape variables
136     outElectron->SetE33 (lazyTools.e3x3( *(iM->superCluster()->seed()) ));
137     outElectron->SetE55 (lazyTools.e5x5( *(iM->superCluster()->seed()) ));
138     std::vector<float> vCov = lazyTools.covariances( *(iM->superCluster()->seed()) );
139     outElectron->SetCovEtaEta(vCov[0]);
140     outElectron->SetCovEtaPhi(vCov[1]);
141     outElectron->SetCovPhiPhi(vCov[2]);
142    
143 sixie 1.11 //Compute Isolations
144     //Get the barrel basicClusters
145 sixie 1.12 edm::Handle<reco::BasicClusterCollection> barrelBasicClusterHandle;
146     GetProduct(barrelBasicClusterName_, barrelBasicClusterHandle, event);
147 sixie 1.11 const reco::BasicClusterCollection* barrelBasicClusters = barrelBasicClusterHandle.product();
148    
149     //Get the endcap basicClusters
150     edm::Handle<reco::BasicClusterCollection> endcapBasicClusterHandle;
151 sixie 1.12 GetProduct(endcapBasicClusterName_, endcapBasicClusterHandle, event);
152 sixie 1.11 const reco::BasicClusterCollection* endcapBasicClusters = endcapBasicClusterHandle.product();
153    
154 sixie 1.12 //Get the barrel superClusters
155     edm::Handle<reco::SuperClusterCollection> barrelSuperClusterHandle;
156     GetProduct(barrelSuperClusterName_, barrelSuperClusterHandle, event);
157     const reco::SuperClusterCollection* barrelSuperClusters = barrelSuperClusterHandle.product();
158    
159     //Get the endcap superClusters
160     edm::Handle<reco::SuperClusterCollection> endcapSuperClusterHandle;
161     GetProduct(endcapSuperClusterName_, endcapSuperClusterHandle, event);
162     const reco::SuperClusterCollection* endcapSuperClusters = endcapSuperClusterHandle.product();
163    
164     //find out whether this electron super cluster is in the barrel or endcap
165     bool isBarrel=false ;
166     if(barrelSuperClusterMap_->HasMit(iM->superCluster()))
167     isBarrel = true;
168    
169 sixie 1.11 //compute ECAL isolation
170     double extRadius = 0.3;
171     double etLow = 0.0;
172 sixie 1.12 EgammaEcalIsolation *myEcalIsolation =
173     new EgammaEcalIsolation(extRadius,etLow,barrelBasicClusters,barrelSuperClusters);
174 sixie 1.11
175 sixie 1.12 if (!isBarrel) {
176     delete myEcalIsolation;
177     myEcalIsolation =
178     new EgammaEcalIsolation(extRadius,etLow,endcapBasicClusters,endcapSuperClusters);
179     }
180     double ecalIsoValue = myEcalIsolation->getEcalEtSum(&(*iM));
181    
182 sixie 1.11 //Compute Track Isolation
183     edm::Handle<reco::TrackCollection> tracks;
184     event.getByLabel("generalTracks",tracks);
185     const reco::TrackCollection* trackCollection = tracks.product();
186     extRadius = 0.2;
187     double intRadius = 0.02;
188     double maxVtxDist = 0.1;
189     double ptMin = 1.5;
190     ElectronTkIsolation myTkIsolation (extRadius,intRadius,ptMin,maxVtxDist,trackCollection) ;
191     double trackIsoValue = myTkIsolation.getPtTracks(&(*iM));
192    
193     //Fill the isolation values
194     outElectron->SetCaloIsolation( ecalIsoValue ) ;
195     outElectron->SetTrackIsolation( trackIsoValue ) ;
196    
197     //Make proper links to Tracks and Super Clusters
198 loizides 1.1 if (gsfTrackMap_ && iM->gsfTrack().isNonnull())
199 loizides 1.9 outElectron->SetGsfTrk(gsfTrackMap_->GetMit(iM->gsfTrack()));
200 loizides 1.1 if (trackerTrackMap_ && iM->track().isNonnull())
201 loizides 1.9 outElectron->SetTrackerTrk(trackerTrackMap_->GetMit(iM->track()));
202 sixie 1.12 if (barrelSuperClusterMap_ && endcapSuperClusterMap_ && iM->superCluster().isNonnull())
203     if(isBarrel) {
204     outElectron->SetSuperCluster(barrelSuperClusterMap_->GetMit(iM->superCluster()));
205     } else {
206     outElectron->SetSuperCluster(endcapSuperClusterMap_->GetMit(iM->superCluster()));
207     }
208 sixie 1.13
209     //Fill Electron ID information
210     outElectron->SetPassLooseID((*eidLooseMap)[eRef]);
211     outElectron->SetPassTightID((*eidTightMap)[eRef]);
212     outElectron->SetIDLikelihood((*eidLikelihoodMap)[eRef]);
213    
214 sixie 1.12 }
215 loizides 1.1 electrons_->Trim();
216     }