ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerElectrons.cc
Revision: 1.38
Committed: Mon Jul 20 03:19:24 2009 UTC (15 years, 9 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_011, Mit_010a, Mit_010
Changes since 1.37: +7 -6 lines
Log Message:
Cleanup

File Contents

# User Rev Content
1 loizides 1.38 // $Id: FillerElectrons.cc,v 1.37 2009/07/07 08:32:26 bendavid Exp $
2 loizides 1.1
3     #include "MitProd/TreeFiller/interface/FillerElectrons.h"
4     #include "DataFormats/TrackReco/interface/Track.h"
5     #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
6     #include "DataFormats/TrackReco/interface/TrackFwd.h"
7 sixie 1.11 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
8     #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
9     #include "DataFormats/EgammaReco/interface/ClusterShape.h"
10     #include "DataFormats/EgammaReco/interface/BasicClusterShapeAssociation.h"
11 bendavid 1.18 #include "DataFormats/Common/interface/RefToPtr.h"
12 loizides 1.35 #include "DataFormats/Common/interface/ValueMap.h"
13     #include "AnalysisDataFormats/Egamma/interface/ElectronID.h"
14     #include "AnalysisDataFormats/Egamma/interface/ElectronIDAssociation.h"
15 sixie 1.11 #include "RecoEgamma/EgammaIsolationAlgos/interface/ElectronTkIsolation.h"
16     #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaEcalIsolation.h"
17 sixie 1.14 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
18 loizides 1.35 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
19     #include "MitAna/DataTree/interface/ElectronCol.h"
20     #include "MitAna/DataTree/interface/Names.h"
21     #include "MitAna/DataTree/interface/Track.h"
22 loizides 1.33 #include "MitEdm/DataFormats/interface/RefToBaseToPtr.h"
23 loizides 1.35 #include "MitProd/ObjectService/interface/ObjectService.h"
24 sixie 1.13
25 loizides 1.1 using namespace std;
26     using namespace edm;
27     using namespace mithep;
28    
29 loizides 1.5 //--------------------------------------------------------------------------------------------------
30 loizides 1.28 FillerElectrons::FillerElectrons(const edm::ParameterSet &cfg, const char *name, bool active) :
31     BaseFiller(cfg,name,active),
32 loizides 1.1 edmName_(Conf().getUntrackedParameter<string>("edmName","pixelMatchGsfElectrons")),
33     mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkElectronBrn)),
34 loizides 1.10 gsfTrackMapName_(Conf().getUntrackedParameter<string>("gsfTrackMapName","")),
35     trackerTrackMapName_(Conf().getUntrackedParameter<string>("trackerTrackMapName","")),
36 sixie 1.12 barrelSuperClusterMapName_(Conf().getUntrackedParameter<string>("barrelSuperClusterMapName","")),
37     endcapSuperClusterMapName_(Conf().getUntrackedParameter<string>("endcapSuperClusterMapName","")),
38 bendavid 1.36 pfSuperClusterMapName_(Conf().getUntrackedParameter<string>("pfSuperClusterMapName","")),
39 loizides 1.16 eIDCutBasedTightName_(Conf().getUntrackedParameter<string>("eIDCutBasedTightName","eidTight")),
40 sixie 1.13 eIDCutBasedLooseName_(Conf().getUntrackedParameter<string>("eIDCutBasedLooseName","eidLoose")),
41 loizides 1.8 electrons_(new mithep::ElectronArr(16)),
42 loizides 1.10 gsfTrackMap_(0),
43 sixie 1.11 trackerTrackMap_(0),
44 sixie 1.12 barrelSuperClusterMap_(0),
45     endcapSuperClusterMap_(0)
46 loizides 1.1 {
47     // Constructor.
48     }
49    
50 loizides 1.5 //--------------------------------------------------------------------------------------------------
51 loizides 1.1 FillerElectrons::~FillerElectrons()
52     {
53     // Destructor.
54 loizides 1.6
55     delete electrons_;
56 loizides 1.1 }
57    
58 loizides 1.5 //--------------------------------------------------------------------------------------------------
59 loizides 1.1 void FillerElectrons::BookDataBlock(TreeWriter &tws)
60     {
61 loizides 1.10 // Add electron branch to our tree and get our maps.
62 loizides 1.1
63 loizides 1.29 tws.AddBranch(mitName_,&electrons_);
64     OS()->add<mithep::ElectronArr>(electrons_,mitName_);
65 loizides 1.10
66 loizides 1.29 if (!gsfTrackMapName_.empty()) {
67     gsfTrackMap_ = OS()->get<TrackMap>(gsfTrackMapName_);
68     if (gsfTrackMap_)
69     AddBranchDep(mitName_,gsfTrackMap_->GetBrName());
70     }
71     if (!trackerTrackMapName_.empty()) {
72     trackerTrackMap_ = OS()->get<TrackMap>(trackerTrackMapName_);
73     if (trackerTrackMap_)
74     AddBranchDep(mitName_,trackerTrackMap_->GetBrName());
75     }
76     if (!barrelSuperClusterMapName_.empty()) {
77     barrelSuperClusterMap_ = OS()->get<SuperClusterMap>(barrelSuperClusterMapName_);
78     if (barrelSuperClusterMap_)
79     AddBranchDep(mitName_,barrelSuperClusterMap_->GetBrName());
80     }
81     if (!endcapSuperClusterMapName_.empty()) {
82     endcapSuperClusterMap_ = OS()->get<SuperClusterMap>(endcapSuperClusterMapName_);
83     if (endcapSuperClusterMap_)
84     AddBranchDep(mitName_,endcapSuperClusterMap_->GetBrName());
85     }
86 bendavid 1.36 if (!pfSuperClusterMapName_.empty()) {
87     pfSuperClusterMap_ = OS()->get<SuperClusterMap>(pfSuperClusterMapName_);
88     if (pfSuperClusterMap_)
89     AddBranchDep(mitName_,pfSuperClusterMap_->GetBrName());
90     }
91 loizides 1.1 }
92    
93 loizides 1.5 //--------------------------------------------------------------------------------------------------
94 loizides 1.29 void FillerElectrons::FillDataBlock(const edm::Event &event, const edm::EventSetup &setup)
95 loizides 1.1 {
96     // Fill electrons from edm collection into our collection.
97    
98 bendavid 1.26 electrons_->Delete();
99 loizides 1.1
100 sixie 1.11 Handle<reco::GsfElectronCollection> hElectronProduct;
101 loizides 1.7 GetProduct(edmName_, hElectronProduct, event);
102 loizides 1.1
103 loizides 1.29 // handles to get the electron ID information
104 sixie 1.13 Handle<edm::ValueMap<float> > eidLooseMap;
105     GetProduct(eIDCutBasedLooseName_, eidLooseMap, event);
106     Handle<edm::ValueMap<float> > eidTightMap;
107     GetProduct(eIDCutBasedTightName_, eidTightMap, event);
108 bendavid 1.19
109 sixie 1.11 const reco::GsfElectronCollection inElectrons = *(hElectronProduct.product());
110 loizides 1.29 // loop over electrons
111 sixie 1.11 for (reco::GsfElectronCollection::const_iterator iM = inElectrons.begin();
112 loizides 1.1 iM != inElectrons.end(); ++iM) {
113 sixie 1.13
114 loizides 1.29 // the index and Ref are needed for the eID association Map
115 sixie 1.13 unsigned int iElectron = iM - inElectrons.begin();
116     reco::GsfElectronRef eRef(hElectronProduct, iElectron);
117    
118 loizides 1.8 mithep::Electron *outElectron = electrons_->AddNew();
119 bendavid 1.31
120     outElectron->SetPtEtaPhi(iM->pt(),iM->eta(),iM->phi());
121 sixie 1.12
122 loizides 1.30 outElectron->SetESuperClusterOverP(iM->eSuperClusterOverP());
123     outElectron->SetESeedClusterOverPout(iM->eSeedClusterOverPout());
124     outElectron->SetPIn(iM->trackMomentumAtVtx().R());
125 loizides 1.29 outElectron->SetPOut(iM->trackMomentumOut().R());
126 loizides 1.30 outElectron->SetDeltaEtaSuperClusterTrackAtVtx(iM->deltaEtaSuperClusterTrackAtVtx());
127     outElectron->SetDeltaEtaSeedClusterTrackAtCalo(iM->deltaEtaSeedClusterTrackAtCalo());
128     outElectron->SetDeltaPhiSuperClusterTrackAtVtx(iM->deltaPhiSuperClusterTrackAtVtx());
129     outElectron->SetDeltaPhiSeedClusterTrackAtCalo(iM->deltaPhiSeedClusterTrackAtCalo());
130     outElectron->SetIsEnergyScaleCorrected(iM->isEnergyScaleCorrected());
131     outElectron->SetIsMomentumCorrected(iM->isMomentumCorrected());
132 bendavid 1.36 outElectron->SetNumberOfClusters(iM->basicClustersSize());
133 loizides 1.30 outElectron->SetClassification(iM->classification());
134 bendavid 1.37 outElectron->SetFBrem(iM->fbrem());
135    
136 loizides 1.38 // pflow electron stuff
137 bendavid 1.37 outElectron->SetIsEcalDriven(iM->isEcalDriven());
138     outElectron->SetIsTrackerDriven(iM->isTrackerDriven());
139     outElectron->SetMva(iM->mva());
140    
141 loizides 1.29 // shower shape variables
142 bendavid 1.37 outElectron->SetE15(iM->e1x5());
143     outElectron->SetE25Max(iM->e2x5Max());
144     outElectron->SetE55(iM->e5x5());
145     outElectron->SetCovEtaEta(iM->sigmaEtaEta());
146     outElectron->SetCoviEtaiEta(iM->sigmaIetaIeta());
147     outElectron->SetHadronicOverEm(iM->hcalOverEcal());
148     outElectron->SetHcalDepth1OverEcal(iM->hcalDepth1OverEcal());
149     outElectron->SetHcalDepth2OverEcal(iM->hcalDepth2OverEcal());
150 sixie 1.12
151 loizides 1.38 // fill isolation variables for both cone sizes
152 bendavid 1.37 outElectron->SetEcalRecHitIsoDr04(iM->dr04EcalRecHitSumEt());
153     outElectron->SetHcalDepth1TowerSumEtDr04(iM->dr04HcalDepth1TowerSumEt());
154     outElectron->SetHcalDepth2TowerSumEtDr04(iM->dr04HcalDepth2TowerSumEt());
155     outElectron->SetTrackIsolationDr04(iM->dr04TkSumPt());
156     outElectron->SetEcalRecHitIsoDr03(iM->dr03EcalRecHitSumEt());
157     outElectron->SetHcalTowerSumEtDr03(iM->dr03HcalTowerSumEt());
158     outElectron->SetHcalDepth1TowerSumEtDr03(iM->dr03HcalDepth1TowerSumEt());
159     outElectron->SetHcalDepth2TowerSumEtDr03(iM->dr03HcalDepth2TowerSumEt());
160     outElectron->SetTrackIsolationDr03(iM->dr03TkSumPt());
161    
162 loizides 1.38 // fiducial flags
163 bendavid 1.37 outElectron->SetIsEB(iM->isEB());
164     outElectron->SetIsEE(iM->isEE());
165     outElectron->SetIsEBEEGap(iM->isEBEEGap());
166     outElectron->SetIsEBEtaGap(iM->isEBEtaGap());
167     outElectron->SetIsEBPhiGap(iM->isEBPhiGap());
168     outElectron->SetIsEEDeeGap(iM->isEEDeeGap());
169     outElectron->SetIsEERingGap(iM->isEERingGap());
170 sixie 1.12
171 loizides 1.38 // gsf-tracker match quality
172 bendavid 1.37 outElectron->SetFracSharedHits(iM->shFracInnerHits());
173 sixie 1.15
174 loizides 1.29 // make proper links to Tracks and Super Clusters
175 loizides 1.1 if (gsfTrackMap_ && iM->gsfTrack().isNonnull())
176 bendavid 1.18 outElectron->SetGsfTrk(gsfTrackMap_->GetMit(refToPtr(iM->gsfTrack())));
177 loizides 1.29 // make tracker track links, relinking from gsf track associations if configured and
178     // link is otherwise absent
179 bendavid 1.37 if (trackerTrackMap_ && iM->closestCtfTrackRef().isNonnull()) {
180 bendavid 1.36 outElectron->SetTrackerTrk(trackerTrackMap_->GetMit(refToPtr(iM->closestCtfTrackRef())));
181 bendavid 1.19 }
182 loizides 1.38 if (barrelSuperClusterMap_ && endcapSuperClusterMap_ &&
183     pfSuperClusterMap_ && iM->superCluster().isNonnull()) {
184 bendavid 1.37 if(barrelSuperClusterMap_->HasMit(iM->superCluster())) {
185 sixie 1.12 outElectron->SetSuperCluster(barrelSuperClusterMap_->GetMit(iM->superCluster()));
186 bendavid 1.36 }
187     else if (endcapSuperClusterMap_->HasMit(iM->superCluster())) {
188 sixie 1.12 outElectron->SetSuperCluster(endcapSuperClusterMap_->GetMit(iM->superCluster()));
189     }
190 bendavid 1.36 else if (pfSuperClusterMap_->HasMit(iM->superCluster())) {
191     outElectron->SetSuperCluster(pfSuperClusterMap_->GetMit(iM->superCluster()));
192     }
193     else throw edm::Exception(edm::errors::Configuration, "FillerElectrons:FillDataBlock()\n")
194     << "Error! SuperCluster reference in unmapped collection " << edmName_ << endl;
195     }
196 sixie 1.13
197 loizides 1.29 // fill Electron ID information
198 sixie 1.13 outElectron->SetPassLooseID((*eidLooseMap)[eRef]);
199     outElectron->SetPassTightID((*eidTightMap)[eRef]);
200 bendavid 1.31
201     if (verbose_>1) {
202     double recomass = sqrt(iM->energy()*iM->energy() - iM->p()*iM->p());
203 loizides 1.32 printf(" mithep::Electron, pt=%5f, eta=%5f, phi=%5f, energy=%5f, p=%5f, mass=%5f\n",
204     outElectron->Pt(), outElectron->Eta(), outElectron->Phi(),
205     outElectron->E(), outElectron->P(), outElectron->Mass());
206     printf("reco::GsfElectron , pt=%5f, eta=%5f, phi=%5f, energy=%5f, p=%5f, mass=%5f\n",
207     iM->pt(), iM->eta(), iM->phi(), iM->energy(), iM->p(), recomass);
208 bendavid 1.31 }
209 sixie 1.12 }
210 loizides 1.1 electrons_->Trim();
211     }