ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/IsolationTools.cc
Revision: 1.35
Committed: Tue Oct 23 23:32:59 2012 UTC (12 years, 6 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.34: +2 -1 lines
Log Message:
Add supercluster ref veto for pf gamma isolation

File Contents

# User Rev Content
1 bendavid 1.35 // $Id: IsolationTools.cc,v 1.34 2012/07/12 17:05:49 fabstoec Exp $
2 loizides 1.1
3     #include "MitPhysics/Utils/interface/IsolationTools.h"
4 bendavid 1.11 #include "MitPhysics/Utils/interface/PhotonTools.h"
5 loizides 1.1 #include "MitCommon/MathTools/interface/MathUtils.h"
6    
7 loizides 1.4 ClassImp(mithep::IsolationTools)
8    
9 loizides 1.1 using namespace mithep;
10    
11     //--------------------------------------------------------------------------------------------------
12     Double_t IsolationTools::TrackIsolation(const Track *p, Double_t extRadius, Double_t intRadius,
13     Double_t ptLow, Double_t maxVtxZDist,
14 phedex 1.2 const Collection<Track> *tracks)
15 loizides 1.1 {
16     //Computes the Track Isolation: Summed Transverse Momentum of all tracks inside an
17     //annulus around the electron seed track.
18    
19     Double_t ptSum =0.;
20     for (UInt_t i=0; i<tracks->GetEntries();i++) {
21     Double_t tmpPt = tracks->At(i)->Pt();
22     Double_t deltaZ = fabs(p->Z0() - tracks->At(i)->Z0());
23    
24     //ignore the track if it is below the pt threshold
25     if (tmpPt < ptLow)
26     continue;
27     //ingore the track if it is too far away in Z
28     if (deltaZ > maxVtxZDist)
29     continue;
30    
31 phedex 1.2 Double_t dr = MathUtils::DeltaR(p->Phi(),p->Eta(),tracks->At(i)->Phi(), tracks->At(i)->Eta());
32 loizides 1.1 //add the track pt if it is inside the annulus
33     if ( dr < extRadius &&
34     dr >= intRadius ) {
35     ptSum += tmpPt;
36     }
37     }
38     return ptSum;
39     }
40    
41     //--------------------------------------------------------------------------------------------------
42     Double_t IsolationTools::EcalIsolation(const SuperCluster *sc, Double_t coneSize, Double_t etLow,
43 phedex 1.2 const Collection<BasicCluster> *basicClusters)
44 loizides 1.1 {
45     //Computes the Ecal Isolation: Summed Transverse Energy of all Basic Clusters inside a
46     //cone around the electron, excluding those that are inside the electron super cluster.
47    
48     Double_t ecalIsol=0.;
49     const BasicCluster *basicCluster= 0;
50     for (UInt_t i=0; i<basicClusters->GetEntries();i++) {
51     basicCluster = basicClusters->At(i);
52     Double_t basicClusterEnergy = basicCluster->Energy();
53     Double_t basicClusterEta = basicCluster->Eta();
54     Double_t basicClusterEt = basicClusterEnergy*sin(2*atan(exp(basicClusterEta)));
55    
56 bendavid 1.3 if (basicClusterEt > etLow) {
57 loizides 1.1 bool inSuperCluster = false;
58    
59     // loop over the basic clusters of the supercluster
60     // to make sure that the basic cluster is not inside
61     // the super cluster. We exclude those.
62     for (UInt_t j=0; j<sc->ClusterSize(); j++) {
63     const BasicCluster *tempBasicClusterInSuperCluster = sc->Cluster(j);
64     if (tempBasicClusterInSuperCluster == basicCluster) {
65     inSuperCluster = true;
66     }
67     }
68    
69     if (!inSuperCluster) {
70 phedex 1.2 Double_t dr = MathUtils::DeltaR(sc->Phi(), sc->Eta(),
71     basicCluster->Phi(),basicCluster->Eta());
72 loizides 1.1 if(dr < coneSize) {
73     ecalIsol += basicClusterEt;
74     }
75     }
76     }
77     }
78     return ecalIsol;
79     }
80    
81     //--------------------------------------------------------------------------------------------------
82     Double_t IsolationTools::CaloTowerHadIsolation(const ThreeVector *p, Double_t extRadius,
83     Double_t intRadius, Double_t etLow,
84 phedex 1.2 const Collection<CaloTower> *caloTowers)
85 loizides 1.1 {
86     //Computes the CaloTower Had Et Isolation: Summed Hadronic Transverse Energy of all Calo Towers
87     //inside an annulus around the electron super cluster position.
88    
89     Double_t sumEt = 0;
90     for (UInt_t i=0; i<caloTowers->GetEntries();i++) {
91     Double_t caloTowerEt = caloTowers->At(i)->HadEt();
92     Double_t dr = MathUtils::DeltaR(caloTowers->At(i)->Phi(), caloTowers->At(i)->Eta(),
93     p->Phi(), p->Eta());
94     if (dr < extRadius && dr > intRadius && caloTowerEt > etLow) {
95     sumEt += caloTowerEt;
96     }
97     }
98     return sumEt;
99     }
100    
101     //--------------------------------------------------------------------------------------------------
102     Double_t IsolationTools::CaloTowerEmIsolation(const ThreeVector *p, Double_t extRadius,
103     Double_t intRadius, Double_t etLow,
104 phedex 1.2 const Collection<CaloTower> *caloTowers)
105 loizides 1.1 {
106     //Computes the CaloTower Em Et Isolation: Summed Hadronic Transverse Energy of all Calo Towers
107     //inside an annulus around the electron super cluster position.
108    
109     Double_t sumEt = 0;
110     for (UInt_t i=0; i<caloTowers->GetEntries();i++) {
111     Double_t caloTowerEt = caloTowers->At(i)->EmEt();
112     Double_t dr = MathUtils::DeltaR(caloTowers->At(i)->Phi(), caloTowers->At(i)->Eta(),
113     p->Phi(), p->Eta());
114     if (dr < extRadius && dr > intRadius && caloTowerEt > etLow) {
115     sumEt += caloTowerEt;
116     }
117     }
118     return sumEt;
119     }
120 ceballos 1.5
121     //--------------------------------------------------------------------------------------------------
122 ceballos 1.28 Double_t IsolationTools::PFRadialMuonIsolation(const Muon *p, const PFCandidateCol *PFCands,
123     Double_t ptMin, Double_t extRadius)
124     {
125     //Computes the PF Radial Muon Isolation: Summed Transverse Momentum of all PF candidates inside an
126     //annulus around the particle seed track with a dR weighting
127    
128     double RadialIso = 0;
129     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
130     const PFCandidate *pf = PFCands->At(i);
131    
132     // exclude muon
133     if(pf->TrackerTrk() && p->TrackerTrk() &&
134     pf->TrackerTrk() == p->TrackerTrk()) continue;
135    
136     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
137    
138     // inner cone veto for tracks
139     if (dr < 0.01) continue;
140    
141     // pt cut applied to neutrals
142     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
143    
144     // exclude PFMuons and PFElectrons within the cone
145     if (pf->HasTrk() &&
146     (pf->PFType() == PFCandidate::eElectron ||
147     pf->PFType() == PFCandidate::eMuon)) continue;
148    
149     // add the pf pt if it is inside the extRadius
150     if (dr < extRadius) RadialIso += pf->Pt() * (1.0 - 3.0*dr);
151     }
152     return RadialIso;
153     }
154    
155     //--------------------------------------------------------------------------------------------------
156 ceballos 1.23 Double_t IsolationTools::PFMuonIsolation(const Muon *p, const PFCandidateCol *PFCands,
157 ceballos 1.8 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
158 ceballos 1.21 Double_t extRadius, Double_t intRadiusGamma, Double_t intRadius)
159 mzanetti 1.15 {
160     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
161     //annulus around the particle seed track.
162    
163     Double_t zLepton = 0.0;
164     if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
165    
166     Double_t ptSum =0.;
167     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
168     const PFCandidate *pf = PFCands->At(i);
169    
170     // exclude muon
171     if(pf->TrackerTrk() && p->TrackerTrk() &&
172     pf->TrackerTrk() == p->TrackerTrk()) continue;
173    
174 mzanetti 1.18 Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
175    
176     // pt cut applied to neutrals
177     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
178    
179 mzanetti 1.15 // ignore the pf candidate if it is too far away in Z
180     if(pf->HasTrk()) {
181 sixie 1.24 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
182     if (deltaZ >= delta_z) continue;
183 mzanetti 1.15 }
184 mzanetti 1.18
185     // inner cone veto for gammas
186 ceballos 1.21 if (pf->PFType() == PFCandidate::eGamma && dr < intRadiusGamma) continue;
187 mzanetti 1.18
188 ceballos 1.21 // inner cone veto for tracks
189     if (dr < intRadius) continue;
190    
191 mzanetti 1.18 // add the pf pt if it is inside the extRadius
192 ceballos 1.21 if (dr < extRadius) ptSum += pf->Pt();
193 mzanetti 1.15
194     }
195     return ptSum;
196     }
197    
198     //--------------------------------------------------------------------------------------------------
199 ceballos 1.23 Double_t IsolationTools::PFMuonIsolation(const Muon *p, const PFCandidateCol *PFCands,
200     const MuonCol *goodMuons, const ElectronCol *goodElectrons,
201     const Vertex *vertex, Double_t delta_z, Double_t ptMin,
202     Double_t extRadius, Double_t intRadiusGamma, Double_t intRadius)
203 ceballos 1.5 {
204     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
205     //annulus around the particle seed track.
206    
207     Double_t zLepton = 0.0;
208 ceballos 1.8 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
209 ceballos 1.5
210     Double_t ptSum =0.;
211     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
212     const PFCandidate *pf = PFCands->At(i);
213    
214 ceballos 1.23 // exclude muon
215     if(pf->TrackerTrk() && p->TrackerTrk() &&
216     pf->TrackerTrk() == p->TrackerTrk()) continue;
217 ceballos 1.5
218 ceballos 1.23 Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
219    
220 mzanetti 1.13 // pt cut applied to neutrals
221     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
222 ceballos 1.6
223 ceballos 1.23 // ignore the pf candidate if it is too far away in Z
224     if(pf->HasTrk()) {
225 sixie 1.24 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
226     if (deltaZ >= delta_z) continue;
227 ceballos 1.5 }
228 ceballos 1.23
229 mzanetti 1.18 // inner cone veto for gammas
230 ceballos 1.23 if (pf->PFType() == PFCandidate::eGamma && dr < intRadiusGamma) continue;
231    
232     // inner cone veto for tracks
233     if (dr < intRadius) continue;
234 mzanetti 1.18
235 ceballos 1.5 // add the pf pt if it is inside the extRadius and outside the intRadius
236 mzanetti 1.18 if (dr < extRadius ) {
237 ceballos 1.8 Bool_t isLepton = kFALSE;
238 ceballos 1.23 if(goodMuons){
239 ceballos 1.8 for (UInt_t nl=0; nl<goodMuons->GetEntries();nl++) {
240     const Muon *m = goodMuons->At(nl);
241     if(pf->TrackerTrk() && m->TrackerTrk() &&
242     pf->TrackerTrk() == m->TrackerTrk()) {
243     isLepton = kTRUE;
244     break;
245     }
246     }
247     }
248 ceballos 1.23 if(goodElectrons && isLepton == kFALSE){
249 ceballos 1.8 for (UInt_t nl=0; nl<goodElectrons->GetEntries();nl++) {
250     const Electron *e = goodElectrons->At(nl);
251     if(pf->TrackerTrk() && e->TrackerTrk() &&
252     pf->TrackerTrk() == e->TrackerTrk()) {
253     isLepton = kTRUE;
254     break;
255     }
256     if(pf->GsfTrk() && e->GsfTrk() &&
257     pf->GsfTrk() == e->GsfTrk()) {
258     isLepton = kTRUE;
259     break;
260     }
261     }
262     }
263 ceballos 1.23 if (isLepton == kTRUE) continue;
264     ptSum += pf->Pt();
265     }
266 ceballos 1.5 }
267     return ptSum;
268     }
269 mzanetti 1.15
270 ceballos 1.5 //--------------------------------------------------------------------------------------------------
271     Double_t IsolationTools::PFElectronIsolation(const Electron *p, const PFCandidateCol *PFCands,
272 ceballos 1.8 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
273 sixie 1.26 Double_t extRadius, Double_t intRadius, Int_t PFCandidateType)
274 sixie 1.16 {
275    
276     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
277     //annulus around the particle seed track.
278    
279     Double_t zLepton = 0.0;
280     if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
281    
282     Double_t ptSum =0.;
283     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
284     const PFCandidate *pf = PFCands->At(i);
285    
286 sixie 1.26 //select only specified PFCandidate types
287     if (PFCandidateType >= 0) {
288     if (pf->PFType() != PFCandidateType) continue;
289     }
290    
291 sixie 1.16 // pt cut applied to neutrals
292     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
293    
294     if(pf->TrackerTrk() && p->TrackerTrk() &&
295     pf->TrackerTrk() == p->TrackerTrk()) continue;
296    
297     if(pf->GsfTrk() && p->GsfTrk() &&
298     pf->GsfTrk() == p->GsfTrk()) continue;
299    
300 sixie 1.25 // ignore the pf candidate if it is too far away in Z
301 sixie 1.16 if(pf->BestTrk()) {
302 sixie 1.25 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
303     if (deltaZ >= delta_z) continue;
304 sixie 1.16 }
305    
306    
307     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
308     // add the pf pt if it is inside the extRadius and outside the intRadius
309     if ( dr < extRadius &&
310     dr >= intRadius ) {
311    
312     //EtaStrip Veto for Gamma
313     if (pf->PFType() == PFCandidate::eGamma && fabs(p->Eta() - pf->Eta()) < 0.025) continue;
314    
315     //InnerCone (One Tower = dR < 0.07) Veto for non-gamma neutrals
316     if (!pf->HasTrk() && pf->PFType() == PFCandidate::eNeutralHadron
317     && MathUtils::DeltaR(p->Mom(), pf->Mom()) < 0.07 ) continue;
318    
319     ptSum += pf->Pt();
320    
321     }
322     }
323     return ptSum;
324     }
325    
326    
327     //--------------------------------------------------------------------------------------------------
328     Double_t IsolationTools::PFElectronIsolation(const Electron *p, const PFCandidateCol *PFCands,
329 ceballos 1.23 const MuonCol *goodMuons, const ElectronCol *goodElectrons,
330     const Vertex *vertex, Double_t delta_z, Double_t ptMin,
331 sixie 1.26 Double_t extRadius, Double_t intRadius, Int_t PFCandidateType)
332 ceballos 1.5 {
333 ceballos 1.23
334 ceballos 1.5 //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
335     //annulus around the particle seed track.
336    
337     Double_t zLepton = 0.0;
338 ceballos 1.8 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
339 ceballos 1.5
340     Double_t ptSum =0.;
341     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
342     const PFCandidate *pf = PFCands->At(i);
343    
344 sixie 1.26 //select only specified PFCandidate types
345     if (PFCandidateType >= 0) {
346     if (pf->PFType() != PFCandidateType) continue;
347     }
348    
349 sixie 1.14 // pt cut applied to neutrals
350     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
351 ceballos 1.6
352 ceballos 1.5 if(pf->TrackerTrk() && p->TrackerTrk() &&
353     pf->TrackerTrk() == p->TrackerTrk()) continue;
354    
355     if(pf->GsfTrk() && p->GsfTrk() &&
356     pf->GsfTrk() == p->GsfTrk()) continue;
357    
358 sixie 1.25 // ignore the pf candidate if it is too far away in Z
359 ceballos 1.5 if(pf->BestTrk()) {
360 sixie 1.25 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
361     if (deltaZ >= delta_z) continue;
362 ceballos 1.5 }
363    
364     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
365     // add the pf pt if it is inside the extRadius and outside the intRadius
366     if ( dr < extRadius &&
367     dr >= intRadius ) {
368 ceballos 1.23
369     //EtaStrip Veto for Gamma
370     if (pf->PFType() == PFCandidate::eGamma && fabs(p->Eta() - pf->Eta()) < 0.025) continue;
371    
372     //InnerCone (One Tower = dR < 0.07) Veto for non-gamma neutrals
373     if (!pf->HasTrk() && pf->PFType() == PFCandidate::eNeutralHadron
374     && MathUtils::DeltaR(p->Mom(), pf->Mom()) < 0.07 ) continue;
375    
376 ceballos 1.8 Bool_t isLepton = kFALSE;
377 ceballos 1.23 if(goodMuons){
378 ceballos 1.8 for (UInt_t nl=0; nl<goodMuons->GetEntries();nl++) {
379     const Muon *m = goodMuons->At(nl);
380     if(pf->TrackerTrk() && m->TrackerTrk() &&
381     pf->TrackerTrk() == m->TrackerTrk()) {
382     isLepton = kTRUE;
383     break;
384     }
385     }
386     }
387 ceballos 1.23 if(goodElectrons && isLepton == kFALSE){
388 ceballos 1.8 for (UInt_t nl=0; nl<goodElectrons->GetEntries();nl++) {
389     const Electron *e = goodElectrons->At(nl);
390     if(pf->TrackerTrk() && e->TrackerTrk() &&
391     pf->TrackerTrk() == e->TrackerTrk()) {
392     isLepton = kTRUE;
393     break;
394     }
395     if(pf->GsfTrk() && e->GsfTrk() &&
396     pf->GsfTrk() == e->GsfTrk()) {
397     isLepton = kTRUE;
398     break;
399     }
400     }
401     }
402 sixie 1.14
403     if (isLepton == kTRUE) continue;
404 ceballos 1.23 ptSum += pf->Pt();
405 sixie 1.14
406 ceballos 1.5 }
407     }
408     return ptSum;
409     }
410 ceballos 1.7 //--------------------------------------------------------------------------------------------------
411 ceballos 1.27 Double_t IsolationTools::PFElectronIsolation2012(const Electron *ele, const Vertex *vertex,
412     const PFCandidateCol *PFCands,
413     const PileupEnergyDensityCol *PileupEnergyDensity,
414     ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaTarget,
415     const ElectronCol *goodElectrons,
416 ceballos 1.29 const MuonCol *goodMuons, Double_t dRMax, Bool_t isDebug){
417 ceballos 1.27
418     Double_t tmpChargedIso_DR = 0;
419     Double_t tmpGammaIso_DR = 0;
420     Double_t tmpNeutralHadronIso_DR = 0;
421    
422     for (UInt_t p=0; p<PFCands->GetEntries();p++) {
423     const PFCandidate *pf = PFCands->At(p);
424 ceballos 1.29
425 ceballos 1.27 //exclude the electron itself
426 ceballos 1.29 //if(pf->GsfTrk() && ele->GsfTrk() &&
427     // pf->GsfTrk() == ele->GsfTrk()) continue;
428     //if(pf->TrackerTrk() && ele->TrackerTrk() &&
429     // pf->TrackerTrk() == ele->TrackerTrk()) continue;
430 ceballos 1.27
431     //************************************************************
432     // New Isolation Calculations
433     //************************************************************
434     Double_t dr = MathUtils::DeltaR(ele->Mom(), pf->Mom());
435    
436     if (dr < 1.0) {
437     Bool_t IsLeptonFootprint = kFALSE;
438     //************************************************************
439     // Lepton Footprint Removal
440     //************************************************************
441     for (UInt_t q=0; q < goodElectrons->GetEntries() ; ++q) {
442     //if pf candidate matches an electron passing ID cuts, then veto it
443     if(pf->GsfTrk() && goodElectrons->At(q)->GsfTrk() &&
444     pf->GsfTrk() == goodElectrons->At(q)->GsfTrk()) IsLeptonFootprint = kTRUE;
445     if(pf->TrackerTrk() && goodElectrons->At(q)->TrackerTrk() &&
446     pf->TrackerTrk() == goodElectrons->At(q)->TrackerTrk()) IsLeptonFootprint = kTRUE;
447     //if pf candidate lies in veto regions of electron passing ID cuts, then veto it
448     if(pf->BestTrk() && fabs(goodElectrons->At(q)->SCluster()->Eta()) >= 1.479
449     && MathUtils::DeltaR(goodElectrons->At(q)->Mom(), pf->Mom()) < 0.015) IsLeptonFootprint = kTRUE;
450     if(pf->PFType() == PFCandidate::eGamma && fabs(goodElectrons->At(q)->SCluster()->Eta()) >= 1.479 &&
451     MathUtils::DeltaR(goodElectrons->At(q)->Mom(), pf->Mom()) < 0.08) IsLeptonFootprint = kTRUE;
452     }
453     for (UInt_t q=0; q < goodMuons->GetEntries() ; ++q) {
454     //if pf candidate matches an muon passing ID cuts, then veto it
455     if(pf->TrackerTrk() && goodMuons->At(q)->TrackerTrk() &&
456     pf->TrackerTrk() == goodMuons->At(q)->TrackerTrk()) IsLeptonFootprint = kTRUE;
457     //if pf candidate lies in veto regions of muon passing ID cuts, then veto it
458     if(pf->BestTrk() && MathUtils::DeltaR(goodMuons->At(q)->Mom(), pf->Mom()) < 0.01) IsLeptonFootprint = kTRUE;
459     }
460    
461     if (!IsLeptonFootprint) {
462     Bool_t passVeto = kTRUE;
463     //Charged
464     if(pf->BestTrk()) {
465     // CMS DOESN"T WANT THIS
466     //if (!(fabs(pf->BestTrk()->DzCorrected(*vertex) - ele->BestTrk()->DzCorrected(*vertex)) < 0.2)) passVeto = kFALSE;
467     //************************************************************
468     // Veto any PFmuon, or PFEle
469     if (pf->PFType() == PFCandidate::eElectron || pf->PFType() == PFCandidate::eMuon) passVeto = kFALSE;
470     //************************************************************
471     //************************************************************
472     // Footprint Veto
473     if (fabs(ele->SCluster()->Eta()) >= 1.479 && dr < 0.015) passVeto = kFALSE;
474     //************************************************************
475     if (passVeto) {
476     if (dr < dRMax) tmpChargedIso_DR += pf->Pt();
477 fabstoec 1.34 } //pass veto
478 ceballos 1.27 }
479     //Gamma
480     else if (pf->PFType() == PFCandidate::eGamma) {
481     //************************************************************
482     // Footprint Veto
483     if (fabs(ele->SCluster()->Eta()) >= 1.479) {
484     if (dr < 0.08) passVeto = kFALSE;
485     }
486     //************************************************************
487    
488     if (passVeto) {
489     if (dr < dRMax) tmpGammaIso_DR += pf->Pt();
490     }
491     }
492     //NeutralHadron
493     else {
494     if (dr < dRMax) tmpNeutralHadronIso_DR += pf->Pt();
495     }
496     } //not lepton footprint
497     } //in 1.0 dr cone
498     } //loop over PF candidates
499    
500     Double_t Rho = 0;
501     if (!(TMath::IsNaN(PileupEnergyDensity->At(0)->Rho()) || isinf(PileupEnergyDensity->At(0)->Rho()))) Rho = PileupEnergyDensity->At(0)->Rho();
502    
503     Double_t IsoVar_ChargedIso_DR = tmpChargedIso_DR/ele->Pt();
504     Double_t IsoVar_NeutralIso_DR = tmpGammaIso_DR + tmpNeutralHadronIso_DR;
505 fabstoec 1.34 // Careful here, we have kEleNeutralIso04 only for now ****added kEleGammaIso03 and kEleNeutralHadronIso03 --heng june 16th 2012
506 ceballos 1.27 if(dRMax != 0.4) assert(0);
507 ceballos 1.29 double EA = ElectronTools::ElectronEffectiveArea(ElectronTools::kEleNeutralIso04, ele->SCluster()->Eta(), EffectiveAreaTarget);
508 fabstoec 1.34
509 ceballos 1.29 IsoVar_NeutralIso_DR = TMath::Max((IsoVar_NeutralIso_DR - Rho*EA)/ele->Pt(), 0.0);
510    
511     if(isDebug == kTRUE){
512     printf("Iso(ch, em, nh), EA, RelIso = (%f, %f, %f), %f, %f\n",tmpChargedIso_DR,tmpGammaIso_DR,tmpNeutralHadronIso_DR,
513     EA,IsoVar_ChargedIso_DR + IsoVar_NeutralIso_DR);
514     }
515 ceballos 1.27
516 ceballos 1.29 return (IsoVar_ChargedIso_DR + IsoVar_NeutralIso_DR);
517 ceballos 1.27 }
518 fabstoec 1.34
519     //--------------------------------------------------------------------------------------------------
520    
521     Double_t IsolationTools::PFElectronIsolation2012LepTag(const Electron *ele, const Vertex *vertex,
522     const PFCandidateCol *PFCands,
523     const PileupEnergyDensityCol *PileupEnergyDensity,
524     ElectronTools::EElectronEffectiveAreaTarget EffectiveAreaTarget,
525     const ElectronCol *goodElectrons,
526     const MuonCol *goodMuons, Double_t dRMax, Bool_t isDebug){
527    
528    
529    
530    
531     Double_t tmpChargedIso_DR = 0;
532     Double_t tmpGammaIso_DR = 0;
533     Double_t tmpNeutralHadronIso_DR = 0;
534    
535     for (UInt_t p=0; p<PFCands->GetEntries();p++) {
536     const PFCandidate *pf = PFCands->At(p);
537    
538     //************************************************************
539     // New Isolation Calculations
540     //************************************************************
541     Double_t dr = MathUtils::DeltaR(ele->Mom(), pf->Mom());
542    
543     if (dr < 1.0) {
544     Bool_t IsLeptonFootprint = kFALSE;
545     //************************************************************
546     // Lepton Footprint Removal
547     //************************************************************
548     for (UInt_t q=0; q < goodElectrons->GetEntries() ; ++q) {
549     //if pf candidate matches an electron passing ID cuts, then veto it
550     if(pf->GsfTrk() && goodElectrons->At(q)->GsfTrk() &&
551     pf->GsfTrk() == goodElectrons->At(q)->GsfTrk()) IsLeptonFootprint = kTRUE;
552     if(pf->TrackerTrk() && goodElectrons->At(q)->TrackerTrk() &&
553     pf->TrackerTrk() == goodElectrons->At(q)->TrackerTrk()) IsLeptonFootprint = kTRUE;
554     //if pf candidate lies in veto regions of electron passing ID cuts, then veto it
555     if(pf->BestTrk() && fabs(goodElectrons->At(q)->SCluster()->Eta()) >= 1.479
556     && MathUtils::DeltaR(goodElectrons->At(q)->Mom(), pf->Mom()) < 0.015) IsLeptonFootprint = kTRUE;
557     if(pf->PFType() == PFCandidate::eGamma && fabs(goodElectrons->At(q)->SCluster()->Eta()) >= 1.479 &&
558     MathUtils::DeltaR(goodElectrons->At(q)->Mom(), pf->Mom()) < 0.08) IsLeptonFootprint = kTRUE;
559     }
560     for (UInt_t q=0; q < goodMuons->GetEntries() ; ++q) {
561     //if pf candidate matches an muon passing ID cuts, then veto it
562     if(pf->TrackerTrk() && goodMuons->At(q)->TrackerTrk() &&
563     pf->TrackerTrk() == goodMuons->At(q)->TrackerTrk()) IsLeptonFootprint = kTRUE;
564     //if pf candidate lies in veto regions of muon passing ID cuts, then veto it
565     if(pf->BestTrk() && MathUtils::DeltaR(goodMuons->At(q)->Mom(), pf->Mom()) < 0.01) IsLeptonFootprint = kTRUE;
566     }
567    
568     if (!IsLeptonFootprint) {
569     Bool_t passVeto = kTRUE;
570     //Charged
571     if(pf->BestTrk()) {
572     // CMS DOESN"T WANT THIS
573     //if (!(fabs(pf->BestTrk()->DzCorrected(*vertex) - ele->BestTrk()->DzCorrected(*vertex)) < 0.2)) passVeto = kFALSE;
574     //************************************************************
575     // Veto any PFmuon, or PFEle
576     if (pf->PFType() == PFCandidate::eElectron || pf->PFType() == PFCandidate::eMuon) passVeto = kFALSE;
577     //************************************************************
578     //************************************************************
579     // Footprint Veto
580     if (fabs(ele->SCluster()->Eta()) >= 1.479 && dr < 0.015) passVeto = kFALSE;
581     //************************************************************
582     if (passVeto) {
583     if (dr < dRMax) {
584     printf("PFCand Pt = %f eta= %f phi= %f , dr= %f charge=%f \n",pf->Pt(),pf->Eta(),pf->Phi(),dr, pf->Charge());
585     tmpChargedIso_DR += pf->Pt();
586     } //pass dr
587     } //pass veto
588     }
589     //Gamma
590     else if (pf->PFType() == PFCandidate::eGamma) {
591     //************************************************************
592     // Footprint Veto
593     if (fabs(ele->SCluster()->Eta()) >= 1.479) {
594     if (dr < 0.08) passVeto = kFALSE;
595     }
596     //************************************************************
597    
598     if (passVeto) {
599     if (dr < dRMax) tmpGammaIso_DR += pf->Pt();
600     }
601     }
602     //NeutralHadron
603     else {
604     if (dr < dRMax) tmpNeutralHadronIso_DR += pf->Pt();
605     }
606     } //not lepton footprint
607     } //in 1.0 dr cone
608     } //loop over PF candidates
609    
610     Double_t Rho = 0;
611     if (!(TMath::IsNaN(PileupEnergyDensity->At(0)->Rho()) || isinf(PileupEnergyDensity->At(0)->Rho()))) Rho = PileupEnergyDensity->At(0)->Rho();
612    
613     Double_t IsoVar_ChargedIso_DR = tmpChargedIso_DR/ele->Pt();
614     Double_t IsoVar_NeutralIso_DR = tmpGammaIso_DR + tmpNeutralHadronIso_DR;
615     // Careful here, we have kEleNeutralIso04 only for now ****added kEleGammaIso03 and kEleNeutralHadronIso03 --heng june 16th 2012
616     double EA = ElectronTools::ElectronEffectiveArea(ElectronTools::kEleGammaIso03, ele->SCluster()->Eta(), EffectiveAreaTarget) + ElectronTools::ElectronEffectiveArea(ElectronTools::kEleNeutralHadronIso03, ele->SCluster()->Eta(), EffectiveAreaTarget) ;
617     IsoVar_NeutralIso_DR = TMath::Max((IsoVar_NeutralIso_DR - Rho*EA)/ele->Pt(), 0.0);
618    
619     if(isDebug == kTRUE){
620     printf("Iso(ch, em, nh), EA, RelIso = (%f, %f, %f), %f, %f\n",tmpChargedIso_DR,tmpGammaIso_DR,tmpNeutralHadronIso_DR,
621     EA,IsoVar_ChargedIso_DR + IsoVar_NeutralIso_DR);
622     }
623    
624     return (IsoVar_ChargedIso_DR + IsoVar_NeutralIso_DR);
625     }
626    
627    
628    
629 ceballos 1.27 //--------------------------------------------------------------------------------------------------
630 ceballos 1.8 Double_t IsolationTools::BetaM(const TrackCol *tracks, const Muon *p, const Vertex *vertex,
631 ceballos 1.7 Double_t ptMin, Double_t delta_z, Double_t extRadius,
632     Double_t intRadius){
633    
634 ceballos 1.9 if(!tracks) return 1.0;
635 ceballos 1.7 if(tracks->GetEntries() <= 0) return 1.0;
636    
637     double Pt_jets_X = 0. ;
638     double Pt_jets_Y = 0. ;
639     double Pt_jets_X_tot = 0. ;
640     double Pt_jets_Y_tot = 0. ;
641    
642     for(int i=0;i<int(tracks->GetEntries());i++){
643     const Track *pTrack = tracks->At(i);
644    
645     if(pTrack && p->TrackerTrk() &&
646     pTrack == p->TrackerTrk()) continue;
647    
648     if(pTrack->Pt() <= ptMin) continue;
649    
650     Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
651     if ( dr < extRadius && dr >= intRadius ) {
652     Pt_jets_X_tot += pTrack->Px();
653     Pt_jets_Y_tot += pTrack->Py();
654 ceballos 1.8 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
655 ceballos 1.7 if(pDz < delta_z){
656     Pt_jets_X += pTrack->Px();
657     Pt_jets_Y += pTrack->Py();
658     }
659     }
660     }
661    
662     if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
663     return sqrt(Pt_jets_X*Pt_jets_X + Pt_jets_Y*Pt_jets_Y) / sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot);
664    
665     return 1.0;
666     }
667    
668 fabstoec 1.34
669    
670     //--------------------------------------------------------------------------------------------------
671     Double_t IsolationTools::BetaMwithPUCorrection(const PFCandidateCol *PFNoPileUp, const PFCandidateCol *PFPileUp, const Muon *p, Double_t extRadius){
672    
673     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
674     //annulus around the particle seed track.
675    
676     Double_t ptSumChHadnoPU =0.;
677     Double_t etsumNeuHad =0;
678     Double_t ptsumGamma = 0;
679     Double_t ptsumPU= 0;
680     Double_t ptSum= 0;
681     for (UInt_t i=0; i<PFNoPileUp->GetEntries();i++) {
682     const PFCandidate *pf = PFNoPileUp->At(i);
683     // exclude muon
684     if(pf->TrackerTrk() && p->TrackerTrk() &&
685     pf->TrackerTrk() == p->TrackerTrk()) continue;
686    
687     //exclude PFCands outside of cone 0.4
688     Double_t dr1 = MathUtils::DeltaR(p->Mom(), pf->Mom());
689     if (dr1 > extRadius) continue;
690     if (pf->PFType() == PFCandidate::eHadron) {
691     if (pf->HasTrk()) ptSumChHadnoPU += pf->Pt();
692     else etsumNeuHad += pf->Et();
693     }
694     else if (pf->PFType() == PFCandidate::eGamma) ptsumGamma += pf->Pt();
695     }
696    
697     for (UInt_t i=0; i<PFPileUp->GetEntries();i++) {
698     const PFCandidate *pf = PFPileUp->At(i);
699     // exclude muon
700     if(pf->TrackerTrk() && p->TrackerTrk() &&
701     pf->TrackerTrk() == p->TrackerTrk()) continue;
702     //exclude PFCands outside of cone 0.4
703     Double_t dr2 = MathUtils::DeltaR(p->Mom(), pf->Mom());
704     if (dr2 > extRadius) continue;
705     if (pf->HasTrk()) ptsumPU += pf->Pt();
706     if (pf->PFType() == PFCandidate::eHadron && !pf->HasTrk()) etsumNeuHad += pf->Et();
707     else if (pf->PFType() == PFCandidate::eGamma) ptsumGamma += pf->Pt();
708     }
709    
710     // for (UInt_t i=0; i<PFPUCands->GetEntries(); ++i){
711     // const PFCandidate *pfpu = PFPUCand->At(i);
712     // ptsumPU += pfpu->Pt();
713     // }
714     // printf("ChHad Gamma Neu PU \n");
715     // printf("%f %f %f %f \n",ptSumChHadnoPU,ptsumGamma,etsumNeuHad,ptsumPU);
716     ptSum=ptSumChHadnoPU+ TMath::Max(0.,ptsumGamma+etsumNeuHad - 0.5*ptsumPU);
717     // printf("isolation is %f \n",ptSum);
718    
719     return ptSum;
720     }
721    
722    
723    
724    
725    
726    
727 ceballos 1.7 //--------------------------------------------------------------------------------------------------
728 ceballos 1.8 Double_t IsolationTools::BetaE(const TrackCol *tracks, const Electron *p, const Vertex *vertex,
729 ceballos 1.7 Double_t ptMin, Double_t delta_z, Double_t extRadius,
730     Double_t intRadius){
731    
732     if(!tracks) return 1.0;
733     if(tracks->GetEntries() <= 0) return 1.0;
734    
735     double Pt_jets_X = 0. ;
736     double Pt_jets_Y = 0. ;
737     double Pt_jets_X_tot = 0. ;
738     double Pt_jets_Y_tot = 0. ;
739    
740     for(int i=0;i<int(tracks->GetEntries());i++){
741     const Track *pTrack = tracks->At(i);
742    
743     if(pTrack && p->TrackerTrk() &&
744     pTrack == p->TrackerTrk()) continue;
745    
746     if(pTrack && p->GsfTrk() &&
747     pTrack == p->GsfTrk()) continue;
748    
749     if(pTrack->Pt() <= ptMin) continue;
750    
751     Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
752     if ( dr < extRadius && dr >= intRadius ) {
753     Pt_jets_X_tot += pTrack->Px();
754     Pt_jets_Y_tot += pTrack->Py();
755 ceballos 1.8 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
756 ceballos 1.7 if(pDz < delta_z){
757     Pt_jets_X += pTrack->Px();
758     Pt_jets_Y += pTrack->Py();
759     }
760     }
761     }
762    
763     if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
764     return sqrt(Pt_jets_X*Pt_jets_X + Pt_jets_Y*Pt_jets_Y) / sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot);
765    
766     return 1.0;
767     }
768 fabstoec 1.10
769    
770     // method added by F.Stoeckli: computes the track isolation with NO constrint on the OV-track compatibility
771     Double_t IsolationTools::TrackIsolationNoPV(const mithep::Particle* p, const BaseVertex* bsp,
772     Double_t extRadius,
773     Double_t intRadius,
774     Double_t ptLow,
775     Double_t etaStrip,
776     Double_t maxD0,
777     mithep::TrackQuality::EQuality quality,
778 bendavid 1.11 const mithep::Collection<mithep::Track> *tracks,
779     UInt_t maxNExpectedHitsInner,
780     const mithep::DecayParticleCol *conversions) {
781 fabstoec 1.10
782     // loop over all tracks
783     Double_t tPt = 0.;
784 fabstoec 1.22 //std::cout<<" *** TrackIso:"<<std::endl;
785 fabstoec 1.10 for(UInt_t i=0; i<tracks->GetEntries(); ++i) {
786     const Track* t = tracks->At(i);
787 fabstoec 1.22 if(t->Pt()>1. && false) {
788     std::cout<<" "<<i<<" pt = "<<t->Pt()<<" ("<<ptLow<<")"<<std::endl;
789     std::cout<<" d0 = "<<fabs(t->D0Corrected( *bsp) )<<" ("<<maxD0<<")"<<std::endl;
790     //std::cout<<" conv ? "<<PhotonTools::MatchedConversion(t,conversions,bsp)<<std::endl;
791     std::cout<<" dR = "<<MathUtils::DeltaR(t->Mom(),p->Mom())<<" ("<<extRadius<<","<<intRadius<<")"<<std::endl;
792     std::cout<<" dEta = "<<fabs(t->Eta()-p->Eta())<<" ("<<etaStrip<<")"<<std::endl;
793     }
794 fabstoec 1.10 if ( t->Pt() < ptLow ) continue;
795     if ( ! t->Quality().Quality(quality) ) continue;
796     // only check for beamspot if available, otherwise ignore cut
797     if ( bsp && fabs(t->D0Corrected( *bsp) ) > maxD0) continue;
798 bendavid 1.11 if (t->NExpectedHitsInner()>maxNExpectedHitsInner) continue;
799     if (conversions && PhotonTools::MatchedConversion(t,conversions,bsp)) continue;
800 fabstoec 1.10 Double_t dR = MathUtils::DeltaR(t->Mom(),p->Mom());
801     Double_t dEta = fabs(t->Eta()-p->Eta());
802     if(dR < extRadius && dR > intRadius && dEta > etaStrip) tPt += t->Pt();
803     }
804     return tPt;
805     }
806    
807 fabstoec 1.19
808 fabstoec 1.20 Double_t IsolationTools::CiCTrackIsolation(const mithep::Photon* p,
809 fabstoec 1.19 const BaseVertex* theVtx,
810     Double_t extRadius,
811     Double_t intRadius,
812     Double_t ptLow,
813     Double_t etaStrip,
814     Double_t maxD0,
815     Double_t maxDZ,
816     const mithep::Collection<mithep::Track> *tracks,
817 fabstoec 1.20 unsigned int* worstVtxIndex,
818     const mithep::Collection<mithep::Vertex> *vtxs,
819 fabstoec 1.22 const mithep::Collection<mithep::Electron> *eles,
820     bool print,
821     double* ptmax, double* dRmax) {
822 fabstoec 1.19
823     UInt_t numVtx = 1;
824     const BaseVertex* iVtx = theVtx;
825     if( vtxs ) {
826     numVtx = vtxs->GetEntries();
827     if (numVtx > 0)
828     iVtx = vtxs->At(0);
829     else
830     return 0.;
831     }
832    
833 fabstoec 1.22 // NEW for Electron T&P: need to remove the electron Gsf Track (applied if eles != NULL)
834     const Track* theGsfTrack = NULL;
835     if ( eles ) {
836     // find the electron that matches the Photon SC
837     for(UInt_t j=0; j<eles->GetEntries(); ++j) {
838     if ( eles->At(j)->SCluster() == p->SCluster() ) {
839     if( eles->At(j)->HasTrackerTrk() )
840     theGsfTrack = eles->At(j)->TrackerTrk();
841     break;
842     }
843     }
844     }
845 fabstoec 1.20
846     if(print) {
847     std::cout<<" Testing photon with"<<std::endl;
848     std::cout<<" Et = "<<p->Et()<<std::endl;
849     std::cout<<" Eta = "<<p->Eta()<<std::endl;
850     std::cout<<" Phi = "<<p->Phi()<<std::endl;
851     }
852    
853 fabstoec 1.19 Double_t iIso = 0.;
854     Double_t maxIso = 0.;
855 fabstoec 1.20
856     if(worstVtxIndex)
857     *worstVtxIndex=0;
858 fabstoec 1.19
859 fabstoec 1.22 double t_ptmax = 0.;
860     double t_dRmax = 0.;
861    
862 fabstoec 1.19 for(UInt_t i=0; i<numVtx; ++i) {
863 fabstoec 1.20
864     if(i>0) iVtx = vtxs->At(i);
865    
866    
867     if(print) {
868     std::cout<<" Vertex #"<<i<<std::endl;
869     std::cout<<" with X = "<<iVtx->X()<<std::endl;
870     std::cout<<" with Y = "<<iVtx->Y()<<std::endl;
871     std::cout<<" with Z = "<<iVtx->Z()<<std::endl;
872     }
873    
874 fabstoec 1.22 Photon* phTemp = new Photon(*p);
875    
876     // RESET CALO_POS!
877     phTemp->SetCaloPosXYZ(p->SCluster()->Point().X(),p->SCluster()->Point().Y(),p->SCluster()->Point().Z());
878    
879 fabstoec 1.20 // compute the ph momentum with respect to this Vtx
880 fabstoec 1.22 //FourVectorM phMom = p->MomVtx(iVtx->Position());
881     FourVectorM phMom = phTemp->MomVtx(iVtx->Position());
882    
883     delete phTemp;
884 fabstoec 1.20
885     if(print) {
886     std::cout<<" photon has changed to:"<<std::endl;
887     std::cout<<" Et = "<<phMom.Et()<<std::endl;
888     std::cout<<" eta = "<<phMom.Eta()<<std::endl;
889     std::cout<<" Phi = "<<phMom.Phi()<<std::endl;
890     }
891    
892 fabstoec 1.19 iIso = 0.;
893 fabstoec 1.20 for(UInt_t j=0; j<tracks->GetEntries(); ++j) {
894     const Track* t = tracks->At(j);
895 fabstoec 1.22 if( theGsfTrack && t == theGsfTrack ) continue;
896 fabstoec 1.20
897     //Double_t dR = MathUtils::DeltaR(t->Mom(),p->Mom());
898     //Double_t dEta = TMath::Abs(t->Eta()-p->Eta());
899    
900     Double_t dR = MathUtils::DeltaR(t->Mom(),phMom);
901     Double_t dEta = TMath::Abs(t->Eta()-phMom.Eta());
902    
903 fabstoec 1.22 if(print && t->Pt()>1. && false) {
904 fabstoec 1.20 std::cout<<" passing track #"<<j<<std::endl;
905     std::cout<<" pt = "<<t->Pt()<<std::endl;
906     std::cout<<" eta = "<<t->Eta()<<std::endl;
907     std::cout<<" phi = "<<t->Phi()<<std::endl;
908     std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
909     std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
910     std::cout<<" dR = "<<dR<<std::endl;
911     std::cout<<" dEta = "<<dEta<<std::endl;
912     std::cout<<" vx = "<<t->X0()<<std::endl;
913     std::cout<<" vy = "<<t->Y0()<<std::endl;
914     std::cout<<" vz = "<<t->Z0()<<std::endl;
915     }
916    
917 fabstoec 1.19 if ( t->Pt() < ptLow ) continue;
918     // only check for beamspot if available, otherwise ignore cut
919     if ( fabs(t->D0Corrected( *iVtx )) > maxD0) continue;
920     if ( fabs(t->DzCorrected( *iVtx )) > maxDZ) continue;
921 fabstoec 1.20
922    
923     if(dR < extRadius && dR > intRadius && dEta > etaStrip) {
924     iIso += t->Pt();
925    
926 fabstoec 1.22 if(t->Pt() > t_ptmax) {
927     t_ptmax=t->Pt();
928     t_dRmax=dR;
929     }
930    
931     if(print && t->Pt()>1.) {
932 fabstoec 1.20 std::cout<<" passing track #"<<j<<std::endl;
933     std::cout<<" pt = "<<t->Pt()<<std::endl;
934     std::cout<<" eta = "<<t->Eta()<<std::endl;
935     std::cout<<" phi = "<<t->Phi()<<std::endl;
936     std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
937     std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
938     std::cout<<" dR = "<<dR<<std::endl;
939     std::cout<<" dEta = "<<dEta<<std::endl;
940     std::cout<<" vx = "<<t->X0()<<std::endl;
941     std::cout<<" vy = "<<t->Y0()<<std::endl;
942     std::cout<<" vz = "<<t->Z0()<<std::endl;
943     std::cout<<" new tIso = "<<iIso<<std::endl;
944     }
945     }
946     }
947     if ( iIso > maxIso ) {
948     maxIso = iIso;
949     if(worstVtxIndex)
950     *worstVtxIndex=i;
951 fabstoec 1.19 }
952     }
953 fabstoec 1.20
954 fabstoec 1.22 if(ptmax) (*ptmax)=t_ptmax;
955     if(dRmax) (*dRmax)=t_dRmax;
956    
957 fabstoec 1.20 if(print) {
958     if(worstVtxIndex)
959     std::cout<<" max TrkIso is given by Vtx #"<<*worstVtxIndex<<" with an amount of tIso = "<<maxIso<<std::endl;
960     else
961     std::cout<<" max TrkIso is given by Vtx #0 with an amount of tIso = "<<maxIso<<std::endl;
962     }
963     return maxIso;
964 fabstoec 1.19 }
965 mingyang 1.30
966     //ChargedIso_selvtx_DR0To0p001=IsolationTools::PFChargedIsolation(p, SelVtx, 0.01, 0, 0.0, 0.0, 0.1, 0.2,fPFCands);
967    
968 bendavid 1.31 Double_t IsolationTools::PFChargedIsolation(const mithep::Photon *p,
969     const BaseVertex *theVtx,
970     Double_t extRadius,
971     Double_t intRadius,
972     const PFCandidateCol *PFCands,
973     unsigned int* worstVtxIndex,
974     const mithep::Collection<mithep::Vertex> *vtxs,
975     bool print)
976     {
977 mingyang 1.30
978     UInt_t numVtx = 1;
979    
980     const BaseVertex* iVtx = theVtx;
981    
982     if( vtxs ) {
983     numVtx = vtxs->GetEntries();
984     if (numVtx > 0)
985     iVtx = vtxs->At(0);
986     else
987     return 0.;
988     }
989 bendavid 1.31
990 mingyang 1.30 if(print) {
991     std::cout<<" Testing photon with"<<std::endl;
992     std::cout<<" Et = "<<p->Et()<<std::endl;
993     std::cout<<" Eta = "<<p->Eta()<<std::endl;
994     std::cout<<" Phi = "<<p->Phi()<<std::endl;
995     }
996    
997     Double_t iIso = 0.;
998     Double_t maxIso = 0.;
999    
1000     if(worstVtxIndex)
1001     *worstVtxIndex=0;
1002    
1003     for(UInt_t i=0; i<numVtx; ++i) {
1004    
1005     if(i>0) iVtx = vtxs->At(i);
1006    
1007    
1008     if(print) {
1009     std::cout<<" Vertex #"<<i<<std::endl;
1010     std::cout<<" with X = "<<iVtx->X()<<std::endl;
1011     std::cout<<" with Y = "<<iVtx->Y()<<std::endl;
1012     std::cout<<" with Z = "<<iVtx->Z()<<std::endl;
1013     }
1014 bendavid 1.31
1015     ThreeVector photondir = ThreeVector(p->SCluster()->Point()) - iVtx->Position();
1016    
1017 mingyang 1.30 iIso = 0.;
1018    
1019     for(UInt_t j=0; j<PFCands->GetEntries(); ++j) {
1020     const PFCandidate *pf= PFCands->At(j);
1021 fabstoec 1.33
1022     if( pf->HasTrackerTrk() && pf->PFType()==PFCandidate::eHadron ) {
1023 bendavid 1.31 const Track* t = pf->TrackerTrk();
1024    
1025     Double_t dR = MathUtils::DeltaR(*pf,photondir);
1026     //Double_t dEta = TMath::Abs(pf->Eta()-photondir.Eta());
1027 mingyang 1.30
1028 bendavid 1.31 if (dR<0.02) continue;
1029     if (dR<intRadius) continue;
1030     if (dR>extRadius) continue;
1031    
1032 mingyang 1.30 if(print && pf->Pt()>1. && false) {
1033     std::cout<<" passing track #"<<j<<std::endl;
1034     std::cout<<" pt = "<<pf->Pt()<<std::endl;
1035     std::cout<<" eta = "<<pf->Eta()<<std::endl;
1036     std::cout<<" phi = "<<pf->Phi()<<std::endl;
1037     std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
1038     std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
1039     std::cout<<" dR = "<<dR<<std::endl;
1040 bendavid 1.31 //std::cout<<" dEta = "<<dEta<<std::endl;
1041 mingyang 1.30 std::cout<<" vx = "<<t->X0()<<std::endl;
1042     std::cout<<" vy = "<<t->Y0()<<std::endl;
1043     std::cout<<" vz = "<<t->Z0()<<std::endl;
1044     }
1045    
1046    
1047     // only check for beamspot if available, otherwise ignore cut
1048 bendavid 1.31 if ( fabs(t->D0Corrected( *iVtx )) > 0.1) continue;
1049     if ( fabs(t->DzCorrected( *iVtx )) > 0.2) continue;
1050 mingyang 1.30
1051 bendavid 1.31 iIso += pf->Pt();
1052 mingyang 1.30
1053     }
1054     }
1055    
1056     if ( iIso > maxIso ) {
1057     maxIso = iIso;
1058     if(worstVtxIndex)
1059     *worstVtxIndex=i;
1060     }
1061     }
1062    
1063    
1064     if(print) {
1065     if(worstVtxIndex)
1066     std::cout<<" max TrkIso is given by Vtx #"<<*worstVtxIndex<<" with an amount of tIso = "<<maxIso<<std::endl;
1067     else
1068     std::cout<<" max TrkIso is given by Vtx #0 with an amount of tIso = "<<maxIso<<std::endl;
1069     }
1070     return maxIso;
1071     }
1072    
1073     //
1074     Float_t IsolationTools::PFChargedCount(const mithep::Photon* p,
1075     const BaseVertex* theVtx,
1076     Double_t extRadius,
1077     Double_t intRadius,
1078     Double_t ptLow,
1079     Double_t etaStrip,
1080     Double_t maxD0,
1081     Double_t maxDZ,
1082     const PFCandidateCol *PFCands,
1083     unsigned int* worstVtxIndex,
1084     const mithep::Collection<mithep::Vertex> *vtxs,
1085     const mithep::Collection<mithep::Electron> *eles,
1086     bool print,
1087     double* ptmax,
1088     double* dRmax) {
1089    
1090     UInt_t numVtx = 1;
1091    
1092     const BaseVertex* iVtx = theVtx;
1093    
1094     if( vtxs ) {
1095     numVtx = vtxs->GetEntries();
1096     if (numVtx > 0)
1097     iVtx = vtxs->At(0);
1098     else
1099     return 0.;
1100     }
1101    
1102     // NEW for Electron T&P: need to remove the electron Gsf Track (applied if eles != NULL)
1103     const Track* theGsfTrack = NULL;
1104     if ( eles ) {
1105     // find the electron that matches the Photon SC
1106     for(UInt_t j=0; j<eles->GetEntries(); ++j) {
1107     if ( eles->At(j)->SCluster() == p->SCluster() ) {
1108     if( eles->At(j)->HasTrackerTrk() )
1109     theGsfTrack = eles->At(j)->TrackerTrk();
1110     break;
1111     }
1112     }
1113     }
1114    
1115     if(print) {
1116     std::cout<<" Testing photon with"<<std::endl;
1117     std::cout<<" Et = "<<p->Et()<<std::endl;
1118     std::cout<<" Eta = "<<p->Eta()<<std::endl;
1119     std::cout<<" Phi = "<<p->Phi()<<std::endl;
1120     }
1121    
1122     Double_t iIso = 0.;
1123     Double_t maxIso = 0.;
1124    
1125     Float_t iNumParticles = 0.;
1126     Float_t maxNumParticles = 0.;
1127    
1128     if(worstVtxIndex)
1129     *worstVtxIndex=0;
1130    
1131     double t_ptmax = 0.;
1132     double t_dRmax = 0.;
1133    
1134     for(UInt_t i=0; i<numVtx; ++i) {
1135    
1136     if(i>0) iVtx = vtxs->At(i);
1137    
1138    
1139     if(print) {
1140     std::cout<<" Vertex #"<<i<<std::endl;
1141     std::cout<<" with X = "<<iVtx->X()<<std::endl;
1142     std::cout<<" with Y = "<<iVtx->Y()<<std::endl;
1143     std::cout<<" with Z = "<<iVtx->Z()<<std::endl;
1144     }
1145    
1146     Photon* phTemp = new Photon(*p);
1147    
1148     // RESET CALO_POS! //ming: why?
1149     phTemp->SetCaloPosXYZ(p->SCluster()->Point().X(),p->SCluster()->Point().Y(),p->SCluster()->Point().Z());
1150    
1151     // compute the ph momentum with respect to this Vtx
1152     FourVectorM phMom = phTemp->MomVtx(iVtx->Position());
1153    
1154     delete phTemp;
1155    
1156     if(print) {
1157     std::cout<<" photon has changed to:"<<std::endl;
1158     std::cout<<" Et = "<<phMom.Et()<<std::endl;
1159     std::cout<<" eta = "<<phMom.Eta()<<std::endl;
1160     std::cout<<" Phi = "<<phMom.Phi()<<std::endl;
1161     }
1162    
1163     iIso = 0.;
1164     iNumParticles = 0.;
1165    
1166     for(UInt_t j=0; j<PFCands->GetEntries(); ++j) {
1167     const PFCandidate *pf= PFCands->At(j);
1168     if(pf->HasTrk() && (pf->PFType()==PFCandidate::eHadron || pf->PFType()==PFCandidate::eElectron || pf->PFType()==PFCandidate::eMuon)){
1169     const Track* t = pf->BestTrk();
1170     if(pf->PFType()==PFCandidate::eElectron && pf->HasGsfTrk()){t = pf->GsfTrk();}
1171     if(!(pf->PFType()==PFCandidate::eElectron) && pf->HasTrackerTrk()){t = pf->TrackerTrk();}
1172    
1173     if( theGsfTrack && t == theGsfTrack ) continue;
1174    
1175     Double_t dR = MathUtils::DeltaR(pf->Mom(),phMom);
1176     Double_t dEta = TMath::Abs(pf->Eta()-phMom.Eta());
1177    
1178     if(print && pf->Pt()>1. && false) {
1179     std::cout<<" passing track #"<<j<<std::endl;
1180     std::cout<<" pt = "<<pf->Pt()<<std::endl;
1181     std::cout<<" eta = "<<pf->Eta()<<std::endl;
1182     std::cout<<" phi = "<<pf->Phi()<<std::endl;
1183     std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
1184     std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
1185     std::cout<<" dR = "<<dR<<std::endl;
1186     std::cout<<" dEta = "<<dEta<<std::endl;
1187     std::cout<<" vx = "<<t->X0()<<std::endl;
1188     std::cout<<" vy = "<<t->Y0()<<std::endl;
1189     std::cout<<" vz = "<<t->Z0()<<std::endl;
1190     }
1191    
1192     if ( pf->Pt() < ptLow ) continue;
1193    
1194     // only check for beamspot if available, otherwise ignore cut
1195     if ( fabs(t->D0Corrected( *iVtx )) > maxD0) continue;
1196     if ( fabs(t->DzCorrected( *iVtx )) > maxDZ) continue;
1197    
1198    
1199     if(dR < extRadius && dR > intRadius && dEta > etaStrip) {
1200     iIso += pf->Pt();
1201     iNumParticles += 1;
1202    
1203     if(pf->Pt() > t_ptmax) {
1204     t_ptmax=pf->Pt();
1205     t_dRmax=dR;
1206     }
1207    
1208     if(print && pf->Pt()>1.) {
1209     std::cout<<" passing track #"<<j<<std::endl;
1210     std::cout<<" pt = "<<pf->Pt()<<std::endl;
1211     std::cout<<" eta = "<<pf->Eta()<<std::endl;
1212     std::cout<<" phi = "<<pf->Phi()<<std::endl;
1213     std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
1214     std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
1215     std::cout<<" dR = "<<dR<<std::endl;
1216     std::cout<<" dEta = "<<dEta<<std::endl;
1217     std::cout<<" vx = "<<t->X0()<<std::endl;
1218     std::cout<<" vy = "<<t->Y0()<<std::endl;
1219     std::cout<<" vz = "<<t->Z0()<<std::endl;
1220     std::cout<<" new tIso = "<<iIso<<std::endl;
1221     }
1222     }
1223     }
1224     }
1225    
1226     if ( iIso > maxIso ) {
1227     maxIso = iIso;
1228     maxNumParticles = iNumParticles;
1229    
1230     if(worstVtxIndex)
1231     *worstVtxIndex=i;
1232     }
1233     }
1234    
1235     if(ptmax) (*ptmax)=t_ptmax;
1236     if(dRmax) (*dRmax)=t_dRmax;
1237    
1238     if(print) {
1239     if(worstVtxIndex)
1240     std::cout<<" max TrkIso is given by Vtx #"<<*worstVtxIndex<<" with an amount of tIso = "<<maxIso<<std::endl;
1241     else
1242     std::cout<<" max TrkIso is given by Vtx #0 with an amount of tIso = "<<maxIso<<std::endl;
1243     }
1244     return maxNumParticles;
1245     }
1246 bendavid 1.31
1247     Double_t IsolationTools::PFGammaIsolation(const mithep::Photon *p,
1248     Double_t extRadius,
1249     Double_t intRadius,
1250     const PFCandidateCol *PFCands)
1251     {
1252    
1253     Double_t iso = 0.;
1254    
1255     ThreeVector photondir;
1256 fabstoec 1.33 //Bool_t setdir = kFALSE;
1257 bendavid 1.31
1258     for (UInt_t ipfc = 0; ipfc<PFCands->GetEntries(); ++ipfc) {
1259     const PFCandidate *pfc = PFCands->At(ipfc);
1260     if (pfc->PFType()!=PFCandidate::eGamma) continue;
1261 bendavid 1.32
1262     ThreeVector photondir = ThreeVector(p->SCluster()->Point() - pfc->SourceVertex());
1263 bendavid 1.31
1264     Double_t dR = MathUtils::DeltaR(*pfc,photondir);
1265     Double_t dEta = TMath::Abs(pfc->Eta()-photondir.Eta());
1266    
1267     Bool_t isbarrel = p->SCluster()->AbsEta()<1.5;
1268    
1269     if (isbarrel && dEta<0.015) continue;
1270     if (!isbarrel && dR<0.07) continue;
1271     if (dR<intRadius) continue;
1272     if (dR>extRadius) continue;
1273 bendavid 1.35 if (pfc->HasSCluster() && pfc->SCluster()==p->SCluster()) continue;
1274 bendavid 1.31
1275     iso += pfc->Pt();
1276    
1277     }
1278    
1279     return iso;
1280    
1281    
1282     }
1283    
1284     Double_t IsolationTools::PFNeutralHadronIsolation(const mithep::Photon *p,
1285     Double_t extRadius,
1286     Double_t intRadius,
1287     const PFCandidateCol *PFCands)
1288     {
1289    
1290     Double_t iso = 0.;
1291    
1292     ThreeVector photondir;
1293     Bool_t setdir = kFALSE;
1294    
1295     for (UInt_t ipfc = 0; ipfc<PFCands->GetEntries(); ++ipfc) {
1296     const PFCandidate *pfc = PFCands->At(ipfc);
1297     if (pfc->PFType()!=PFCandidate::eGamma) continue;
1298     if (!setdir) {
1299     photondir = ThreeVector(p->SCluster()->Point() - pfc->SourceVertex());
1300     setdir = kTRUE;
1301     }
1302    
1303     Double_t dR = MathUtils::DeltaR(*pfc,photondir);
1304    
1305     if (dR<intRadius) continue;
1306     if (dR>extRadius) continue;
1307    
1308     iso += pfc->Pt();
1309    
1310     }
1311    
1312     return iso;
1313    
1314    
1315 fabstoec 1.33 }