ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerElectrons.cc
Revision: 1.14
Committed: Sat Sep 6 18:11:35 2008 UTC (16 years, 8 months ago) by sixie
Content type: text/plain
Branch: MAIN
Changes since 1.13: +14 -2 lines
Log Message:
Add CMSSW CaloTower Isolation calculation to electrons

File Contents

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