ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/IsolationTools.cc
Revision: 1.37
Committed: Sat Feb 23 14:53:07 2013 UTC (12 years, 2 months ago) by mingyang
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029c, Mit_029b, Mit_029a
Changes since 1.36: +24 -12 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 // $Id: IsolationTools.cc,v 1.36 2012/10/26 19:23:04 fabstoec Exp $
2
3 #include "MitPhysics/Utils/interface/IsolationTools.h"
4 #include "MitPhysics/Utils/interface/PhotonTools.h"
5 #include "MitCommon/MathTools/interface/MathUtils.h"
6
7 ClassImp(mithep::IsolationTools)
8
9 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 const Collection<Track> *tracks)
15 {
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 Double_t dr = MathUtils::DeltaR(p->Phi(),p->Eta(),tracks->At(i)->Phi(), tracks->At(i)->Eta());
32 //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 const Collection<BasicCluster> *basicClusters)
44 {
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 if (basicClusterEt > etLow) {
57 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 Double_t dr = MathUtils::DeltaR(sc->Phi(), sc->Eta(),
71 basicCluster->Phi(),basicCluster->Eta());
72 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 const Collection<CaloTower> *caloTowers)
85 {
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 const Collection<CaloTower> *caloTowers)
105 {
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
121 //--------------------------------------------------------------------------------------------------
122 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 Double_t IsolationTools::PFMuonIsolation(const Muon *p, const PFCandidateCol *PFCands,
157 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
158 Double_t extRadius, Double_t intRadiusGamma, Double_t intRadius)
159 {
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 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 // ignore the pf candidate if it is too far away in Z
180 if(pf->HasTrk()) {
181 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
182 if (deltaZ >= delta_z) continue;
183 }
184
185 // inner cone veto for gammas
186 if (pf->PFType() == PFCandidate::eGamma && dr < intRadiusGamma) continue;
187
188 // inner cone veto for tracks
189 if (dr < intRadius) continue;
190
191 // add the pf pt if it is inside the extRadius
192 if (dr < extRadius) ptSum += pf->Pt();
193
194 }
195 return ptSum;
196 }
197
198 //--------------------------------------------------------------------------------------------------
199 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 {
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 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
209
210 Double_t ptSum =0.;
211 for (UInt_t i=0; i<PFCands->GetEntries();i++) {
212 const PFCandidate *pf = PFCands->At(i);
213
214 // exclude muon
215 if(pf->TrackerTrk() && p->TrackerTrk() &&
216 pf->TrackerTrk() == p->TrackerTrk()) continue;
217
218 Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
219
220 // pt cut applied to neutrals
221 if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
222
223 // ignore the pf candidate if it is too far away in Z
224 if(pf->HasTrk()) {
225 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
226 if (deltaZ >= delta_z) continue;
227 }
228
229 // inner cone veto for gammas
230 if (pf->PFType() == PFCandidate::eGamma && dr < intRadiusGamma) continue;
231
232 // inner cone veto for tracks
233 if (dr < intRadius) continue;
234
235 // add the pf pt if it is inside the extRadius and outside the intRadius
236 if (dr < extRadius ) {
237 Bool_t isLepton = kFALSE;
238 if(goodMuons){
239 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 if(goodElectrons && isLepton == kFALSE){
249 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 if (isLepton == kTRUE) continue;
264 ptSum += pf->Pt();
265 }
266 }
267 return ptSum;
268 }
269
270 //--------------------------------------------------------------------------------------------------
271 Double_t IsolationTools::PFElectronIsolation(const Electron *p, const PFCandidateCol *PFCands,
272 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
273 Double_t extRadius, Double_t intRadius, Int_t PFCandidateType)
274 {
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 //select only specified PFCandidate types
287 if (PFCandidateType >= 0) {
288 if (pf->PFType() != PFCandidateType) continue;
289 }
290
291 // 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 // ignore the pf candidate if it is too far away in Z
301 if(pf->BestTrk()) {
302 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
303 if (deltaZ >= delta_z) continue;
304 }
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 const MuonCol *goodMuons, const ElectronCol *goodElectrons,
330 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
331 Double_t extRadius, Double_t intRadius, Int_t PFCandidateType)
332 {
333
334 //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 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
339
340 Double_t ptSum =0.;
341 for (UInt_t i=0; i<PFCands->GetEntries();i++) {
342 const PFCandidate *pf = PFCands->At(i);
343
344 //select only specified PFCandidate types
345 if (PFCandidateType >= 0) {
346 if (pf->PFType() != PFCandidateType) continue;
347 }
348
349 // pt cut applied to neutrals
350 if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
351
352 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 // ignore the pf candidate if it is too far away in Z
359 if(pf->BestTrk()) {
360 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
361 if (deltaZ >= delta_z) continue;
362 }
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
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 Bool_t isLepton = kFALSE;
377 if(goodMuons){
378 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 if(goodElectrons && isLepton == kFALSE){
388 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
403 if (isLepton == kTRUE) continue;
404 ptSum += pf->Pt();
405
406 }
407 }
408 return ptSum;
409 }
410 //--------------------------------------------------------------------------------------------------
411 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 const MuonCol *goodMuons, Double_t dRMax, Bool_t isDebug){
417
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
425 //exclude the electron itself
426 //if(pf->GsfTrk() && ele->GsfTrk() &&
427 // pf->GsfTrk() == ele->GsfTrk()) continue;
428 //if(pf->TrackerTrk() && ele->TrackerTrk() &&
429 // pf->TrackerTrk() == ele->TrackerTrk()) continue;
430
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 } //pass veto
478 }
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 // Careful here, we have kEleNeutralIso04 only for now ****added kEleGammaIso03 and kEleNeutralHadronIso03 --heng june 16th 2012
506 if(dRMax != 0.4) assert(0);
507 double EA = ElectronTools::ElectronEffectiveArea(ElectronTools::kEleNeutralIso04, ele->SCluster()->Eta(), EffectiveAreaTarget);
508
509 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
516 return (IsoVar_ChargedIso_DR + IsoVar_NeutralIso_DR);
517 }
518
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 if (dr < 1.0) {
543 Bool_t IsLeptonFootprint = kFALSE;
544 //************************************************************
545 // Lepton Footprint Removal
546 //************************************************************
547 if(pf->PFType() == PFCandidate::eGamma){
548 for (UInt_t i=0; i<PFCands->GetEntries();i++) {
549 const PFCandidate *pf2 = PFCands->At(i);
550 if(pf2->PFType()==PFCandidate::eElectron && pf->SCluster() == pf2->SCluster())IsLeptonFootprint = kTRUE;
551 }
552 }
553
554 for (UInt_t q=0; q < goodElectrons->GetEntries() ; ++q) {
555 //if pf candidate matches an electron passing ID cuts, then veto it
556 if(pf->GsfTrk() && goodElectrons->At(q)->GsfTrk() &&
557 pf->GsfTrk() == goodElectrons->At(q)->GsfTrk()) IsLeptonFootprint = kTRUE;
558 if(pf->TrackerTrk() && goodElectrons->At(q)->TrackerTrk() &&
559 pf->TrackerTrk() == goodElectrons->At(q)->TrackerTrk()) IsLeptonFootprint = kTRUE;
560 //if pf candidate lies in veto regions of electron passing ID cuts, then veto it
561 if(pf->BestTrk() && fabs(goodElectrons->At(q)->SCluster()->Eta()) >= 1.479
562 && MathUtils::DeltaR(goodElectrons->At(q)->Mom(), pf->Mom()) < 0.015) IsLeptonFootprint = kTRUE;
563 if(pf->PFType() == PFCandidate::eGamma && fabs(goodElectrons->At(q)->SCluster()->Eta()) >= 1.479 &&
564 MathUtils::DeltaR(goodElectrons->At(q)->Mom(), pf->Mom()) < 0.08) IsLeptonFootprint = kTRUE;
565 }
566 for (UInt_t q=0; q < goodMuons->GetEntries() ; ++q) {
567 //if pf candidate matches an muon passing ID cuts, then veto it
568 if(pf->TrackerTrk() && goodMuons->At(q)->TrackerTrk() &&
569 pf->TrackerTrk() == goodMuons->At(q)->TrackerTrk()) IsLeptonFootprint = kTRUE;
570 //if pf candidate lies in veto regions of muon passing ID cuts, then veto it
571 if(pf->BestTrk() && MathUtils::DeltaR(goodMuons->At(q)->Mom(), pf->Mom()) < 0.01) IsLeptonFootprint = kTRUE;
572 }
573
574 if (!IsLeptonFootprint) {
575 Bool_t passVeto = kTRUE;
576 //Charged
577 if(pf->BestTrk()) {
578 // CMS DOESN"T WANT THIS
579 //if (!(fabs(pf->BestTrk()->DzCorrected(*vertex) - ele->BestTrk()->DzCorrected(*vertex)) < 0.2)) passVeto = kFALSE;
580 //************************************************************
581 // Veto any PFmuon, or PFEle
582 if (pf->PFType() == PFCandidate::eElectron || pf->PFType() == PFCandidate::eMuon) passVeto = kFALSE;
583 //************************************************************
584 //************************************************************
585 // Footprint Veto
586 if (fabs(ele->SCluster()->Eta()) >= 1.479 && dr < 0.015) passVeto = kFALSE;
587 //************************************************************
588 if (passVeto) {
589 if (dr < dRMax) {
590 if ( false ) printf("Charged PFCand Pt = %f eta= %f phi= %f , dr= %f charge=%f \n",pf->Pt(),pf->Eta(),pf->Phi(),dr, pf->Charge());
591 tmpChargedIso_DR += pf->Pt();
592 } //pass dr
593 } //pass veto
594 }
595 //Gamma
596 else if (pf->PFType() == PFCandidate::eGamma) {
597 //************************************************************
598 // Footprint Veto
599 if (fabs(ele->SCluster()->Eta()) >= 1.479) {
600 if (dr < 0.08) passVeto = kFALSE;
601 }
602 //************************************************************
603
604 if (passVeto) {
605 if(pf->HasSCluster()){
606 if ( false ) printf("Gamma PFCand Pt = %f eta= %f phi= %f , dr= %f \n",pf->Pt(),pf->SCluster()->Eta(),pf->Phi(),dr);//ming
607 }
608 //if (dr < dRMax ) tmpGammaIso_DR += pf->Pt();
609 //if (dr < dRMax && ((pf->HasSCluster() && pf->SCluster()!=ele->SCluster()) || !pf->HasSCluster())) tmpGammaIso_DR += pf->Pt();//ming
610 if(dr < dRMax && !(ele->GsfTrk()->NExpectedHitsInner()>0 && pf->MvaGamma() > 0.99 && pf->HasSCluster() && ele->SCluster() == pf->SCluster())) tmpGammaIso_DR += pf->Pt();//ming:HZZ
611 }
612 }
613 //NeutralHadron
614 else {
615 if ( false ) printf("NeutralHadron PFCand Pt = %f eta= %f phi= %f , dr= %f \n",pf->Pt(),pf->Eta(),pf->Phi(),dr);
616 if (dr < dRMax) tmpNeutralHadronIso_DR += pf->Pt();
617 }
618 } //not lepton footprint
619 } //in 1.0 dr cone
620 } //loop over PF candidates
621
622 Double_t Rho = 0;
623 assert(PileupEnergyDensity);
624 //if (!(TMath::IsNaN(PileupEnergyDensity->At(0)->Rho()) || isinf(PileupEnergyDensity->At(0)->Rho()))) Rho = PileupEnergyDensity->At(0)->Rho();//ming
625 Rho = PileupEnergyDensity->At(0)->RhoKt6PFJets();//ming
626
627 Double_t IsoVar_ChargedIso_DR = tmpChargedIso_DR/ele->Pt();
628 Double_t IsoVar_NeutralIso_DR = tmpGammaIso_DR + tmpNeutralHadronIso_DR;
629 // Careful here, we have kEleNeutralIso04 only for now ****added kEleGammaIso03 and kEleNeutralHadronIso03 --heng june 16th 2012
630 double EA = ElectronTools::ElectronEffectiveArea(ElectronTools::kEleGammaIso03, ele->SCluster()->Eta(), EffectiveAreaTarget) + ElectronTools::ElectronEffectiveArea(ElectronTools::kEleNeutralHadronIso03, ele->SCluster()->Eta(), EffectiveAreaTarget) ;
631 IsoVar_NeutralIso_DR = TMath::Max((IsoVar_NeutralIso_DR - Rho*EA)/ele->Pt(), 0.0);
632
633 if(isDebug == kTRUE){
634 printf("Iso(ch, em, nh), EA, RelIso = (%f, %f, %f), %f, %f\n",tmpChargedIso_DR,tmpGammaIso_DR,tmpNeutralHadronIso_DR,
635 EA,IsoVar_ChargedIso_DR + IsoVar_NeutralIso_DR);
636 }
637
638 return (IsoVar_ChargedIso_DR + IsoVar_NeutralIso_DR);
639 }
640
641 //--------------------------------------------------------------------------------------------------
642 Double_t IsolationTools::BetaM(const TrackCol *tracks, const Muon *p, const Vertex *vertex,
643 Double_t ptMin, Double_t delta_z, Double_t extRadius,
644 Double_t intRadius){
645
646 if(!tracks) return 1.0;
647 if(tracks->GetEntries() <= 0) return 1.0;
648
649 double Pt_jets_X = 0. ;
650 double Pt_jets_Y = 0. ;
651 double Pt_jets_X_tot = 0. ;
652 double Pt_jets_Y_tot = 0. ;
653
654 for(int i=0;i<int(tracks->GetEntries());i++){
655 const Track *pTrack = tracks->At(i);
656
657 if(pTrack && p->TrackerTrk() &&
658 pTrack == p->TrackerTrk()) continue;
659
660 if(pTrack->Pt() <= ptMin) continue;
661
662 Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
663 if ( dr < extRadius && dr >= intRadius ) {
664 Pt_jets_X_tot += pTrack->Px();
665 Pt_jets_Y_tot += pTrack->Py();
666 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
667 if(pDz < delta_z){
668 Pt_jets_X += pTrack->Px();
669 Pt_jets_Y += pTrack->Py();
670 }
671 }
672 }
673
674 if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
675 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);
676
677 return 1.0;
678 }
679
680
681
682 //--------------------------------------------------------------------------------------------------
683 Double_t IsolationTools::BetaMwithPUCorrection(const PFCandidateCol *PFNoPileUp, const PFCandidateCol *PFPileUp, const Muon *p, Double_t extRadius){
684
685 //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
686 //annulus around the particle seed track.
687
688 Double_t ptSumChHadnoPU =0.;
689 Double_t etsumNeuHad =0;
690 Double_t ptsumGamma = 0;
691 Double_t ptsumPU= 0;
692 Double_t ptSum= 0;
693 for (UInt_t i=0; i<PFNoPileUp->GetEntries();i++) {
694 const PFCandidate *pf = PFNoPileUp->At(i);
695 // exclude muon
696 if(pf->TrackerTrk() && p->TrackerTrk() &&
697 pf->TrackerTrk() == p->TrackerTrk()) continue;
698
699 //exclude PFCands outside of cone 0.4
700 Double_t dr1 = MathUtils::DeltaR(p->Mom(), pf->Mom());
701 if (dr1 > extRadius) continue;
702 if (pf->PFType() == PFCandidate::eHadron) {
703 if (pf->HasTrk()) ptSumChHadnoPU += pf->Pt();
704 else etsumNeuHad += pf->Et();
705 }
706 else if (pf->PFType() == PFCandidate::eGamma) ptsumGamma += pf->Pt();
707 }
708
709 for (UInt_t i=0; i<PFPileUp->GetEntries();i++) {
710 const PFCandidate *pf = PFPileUp->At(i);
711 // exclude muon
712 if(pf->TrackerTrk() && p->TrackerTrk() &&
713 pf->TrackerTrk() == p->TrackerTrk()) continue;
714 //exclude PFCands outside of cone 0.4
715 Double_t dr2 = MathUtils::DeltaR(p->Mom(), pf->Mom());
716 if (dr2 > extRadius) continue;
717 if (pf->HasTrk()) ptsumPU += pf->Pt();
718 if (pf->PFType() == PFCandidate::eHadron && !pf->HasTrk()) etsumNeuHad += pf->Et();
719 else if (pf->PFType() == PFCandidate::eGamma) ptsumGamma += pf->Pt();
720 }
721
722 // for (UInt_t i=0; i<PFPUCands->GetEntries(); ++i){
723 // const PFCandidate *pfpu = PFPUCand->At(i);
724 // ptsumPU += pfpu->Pt();
725 // }
726 //printf("ChHad Gamma Neu PU \n");
727 // printf("%f %f %f %f \n",ptSumChHadnoPU,ptsumGamma,etsumNeuHad,ptsumPU);
728 ptSum=ptSumChHadnoPU+ TMath::Max(0.,ptsumGamma+etsumNeuHad - 0.5*ptsumPU);
729 //printf("ming muon check isolation is %f \n",ptSum);
730
731 return ptSum;
732 }
733
734
735
736
737
738
739 //--------------------------------------------------------------------------------------------------
740 Double_t IsolationTools::BetaE(const TrackCol *tracks, const Electron *p, const Vertex *vertex,
741 Double_t ptMin, Double_t delta_z, Double_t extRadius,
742 Double_t intRadius){
743
744 if(!tracks) return 1.0;
745 if(tracks->GetEntries() <= 0) return 1.0;
746
747 double Pt_jets_X = 0. ;
748 double Pt_jets_Y = 0. ;
749 double Pt_jets_X_tot = 0. ;
750 double Pt_jets_Y_tot = 0. ;
751
752 for(int i=0;i<int(tracks->GetEntries());i++){
753 const Track *pTrack = tracks->At(i);
754
755 if(pTrack && p->TrackerTrk() &&
756 pTrack == p->TrackerTrk()) continue;
757
758 if(pTrack && p->GsfTrk() &&
759 pTrack == p->GsfTrk()) continue;
760
761 if(pTrack->Pt() <= ptMin) continue;
762
763 Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
764 if ( dr < extRadius && dr >= intRadius ) {
765 Pt_jets_X_tot += pTrack->Px();
766 Pt_jets_Y_tot += pTrack->Py();
767 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
768 if(pDz < delta_z){
769 Pt_jets_X += pTrack->Px();
770 Pt_jets_Y += pTrack->Py();
771 }
772 }
773 }
774
775 if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
776 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);
777
778 return 1.0;
779 }
780
781
782 // method added by F.Stoeckli: computes the track isolation with NO constrint on the OV-track compatibility
783 Double_t IsolationTools::TrackIsolationNoPV(const mithep::Particle* p, const BaseVertex* bsp,
784 Double_t extRadius,
785 Double_t intRadius,
786 Double_t ptLow,
787 Double_t etaStrip,
788 Double_t maxD0,
789 mithep::TrackQuality::EQuality quality,
790 const mithep::Collection<mithep::Track> *tracks,
791 UInt_t maxNExpectedHitsInner,
792 const mithep::DecayParticleCol *conversions) {
793
794 // loop over all tracks
795 Double_t tPt = 0.;
796 //std::cout<<" *** TrackIso:"<<std::endl;
797 for(UInt_t i=0; i<tracks->GetEntries(); ++i) {
798 const Track* t = tracks->At(i);
799 if(t->Pt()>1. && false) {
800 std::cout<<" "<<i<<" pt = "<<t->Pt()<<" ("<<ptLow<<")"<<std::endl;
801 std::cout<<" d0 = "<<fabs(t->D0Corrected( *bsp) )<<" ("<<maxD0<<")"<<std::endl;
802 //std::cout<<" conv ? "<<PhotonTools::MatchedConversion(t,conversions,bsp)<<std::endl;
803 std::cout<<" dR = "<<MathUtils::DeltaR(t->Mom(),p->Mom())<<" ("<<extRadius<<","<<intRadius<<")"<<std::endl;
804 std::cout<<" dEta = "<<fabs(t->Eta()-p->Eta())<<" ("<<etaStrip<<")"<<std::endl;
805 }
806 if ( t->Pt() < ptLow ) continue;
807 if ( ! t->Quality().Quality(quality) ) continue;
808 // only check for beamspot if available, otherwise ignore cut
809 if ( bsp && fabs(t->D0Corrected( *bsp) ) > maxD0) continue;
810 if (t->NExpectedHitsInner()>maxNExpectedHitsInner) continue;
811 if (conversions && PhotonTools::MatchedConversion(t,conversions,bsp)) continue;
812 Double_t dR = MathUtils::DeltaR(t->Mom(),p->Mom());
813 Double_t dEta = fabs(t->Eta()-p->Eta());
814 if(dR < extRadius && dR > intRadius && dEta > etaStrip) tPt += t->Pt();
815 }
816 return tPt;
817 }
818
819
820 Double_t IsolationTools::CiCTrackIsolation(const mithep::Photon* p,
821 const BaseVertex* theVtx,
822 Double_t extRadius,
823 Double_t intRadius,
824 Double_t ptLow,
825 Double_t etaStrip,
826 Double_t maxD0,
827 Double_t maxDZ,
828 const mithep::Collection<mithep::Track> *tracks,
829 unsigned int* worstVtxIndex,
830 const mithep::Collection<mithep::Vertex> *vtxs,
831 const mithep::Collection<mithep::Electron> *eles,
832 bool print,
833 double* ptmax, double* dRmax) {
834
835 UInt_t numVtx = 1;
836 const BaseVertex* iVtx = theVtx;
837 if( vtxs ) {
838 numVtx = vtxs->GetEntries();
839 if (numVtx > 0)
840 iVtx = vtxs->At(0);
841 else
842 return 0.;
843 }
844
845 // NEW for Electron T&P: need to remove the electron Gsf Track (applied if eles != NULL)
846 const Track* theGsfTrack = NULL;
847 if ( eles ) {
848 // find the electron that matches the Photon SC
849 for(UInt_t j=0; j<eles->GetEntries(); ++j) {
850 if ( eles->At(j)->SCluster() == p->SCluster() ) {
851 if( eles->At(j)->HasTrackerTrk() )
852 theGsfTrack = eles->At(j)->TrackerTrk();
853 break;
854 }
855 }
856 }
857
858 if(print) {
859 std::cout<<" Testing photon with"<<std::endl;
860 std::cout<<" Et = "<<p->Et()<<std::endl;
861 std::cout<<" Eta = "<<p->Eta()<<std::endl;
862 std::cout<<" Phi = "<<p->Phi()<<std::endl;
863 }
864
865 Double_t iIso = 0.;
866 Double_t maxIso = 0.;
867
868 if(worstVtxIndex)
869 *worstVtxIndex=0;
870
871 double t_ptmax = 0.;
872 double t_dRmax = 0.;
873
874 for(UInt_t i=0; i<numVtx; ++i) {
875
876 if(i>0) iVtx = vtxs->At(i);
877
878
879 if(print) {
880 std::cout<<" Vertex #"<<i<<std::endl;
881 std::cout<<" with X = "<<iVtx->X()<<std::endl;
882 std::cout<<" with Y = "<<iVtx->Y()<<std::endl;
883 std::cout<<" with Z = "<<iVtx->Z()<<std::endl;
884 }
885
886 Photon* phTemp = new Photon(*p);
887
888 // RESET CALO_POS!
889 phTemp->SetCaloPosXYZ(p->SCluster()->Point().X(),p->SCluster()->Point().Y(),p->SCluster()->Point().Z());
890
891 // compute the ph momentum with respect to this Vtx
892 //FourVectorM phMom = p->MomVtx(iVtx->Position());
893 FourVectorM phMom = phTemp->MomVtx(iVtx->Position());
894
895 delete phTemp;
896
897 if(print) {
898 std::cout<<" photon has changed to:"<<std::endl;
899 std::cout<<" Et = "<<phMom.Et()<<std::endl;
900 std::cout<<" eta = "<<phMom.Eta()<<std::endl;
901 std::cout<<" Phi = "<<phMom.Phi()<<std::endl;
902 }
903
904 iIso = 0.;
905 for(UInt_t j=0; j<tracks->GetEntries(); ++j) {
906 const Track* t = tracks->At(j);
907 if( theGsfTrack && t == theGsfTrack ) continue;
908
909 //Double_t dR = MathUtils::DeltaR(t->Mom(),p->Mom());
910 //Double_t dEta = TMath::Abs(t->Eta()-p->Eta());
911
912 Double_t dR = MathUtils::DeltaR(t->Mom(),phMom);
913 Double_t dEta = TMath::Abs(t->Eta()-phMom.Eta());
914
915 if(print && t->Pt()>1. && false) {
916 std::cout<<" passing track #"<<j<<std::endl;
917 std::cout<<" pt = "<<t->Pt()<<std::endl;
918 std::cout<<" eta = "<<t->Eta()<<std::endl;
919 std::cout<<" phi = "<<t->Phi()<<std::endl;
920 std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
921 std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
922 std::cout<<" dR = "<<dR<<std::endl;
923 std::cout<<" dEta = "<<dEta<<std::endl;
924 std::cout<<" vx = "<<t->X0()<<std::endl;
925 std::cout<<" vy = "<<t->Y0()<<std::endl;
926 std::cout<<" vz = "<<t->Z0()<<std::endl;
927 }
928
929 if ( t->Pt() < ptLow ) continue;
930 // only check for beamspot if available, otherwise ignore cut
931 if ( fabs(t->D0Corrected( *iVtx )) > maxD0) continue;
932 if ( fabs(t->DzCorrected( *iVtx )) > maxDZ) continue;
933
934
935 if(dR < extRadius && dR > intRadius && dEta > etaStrip) {
936 iIso += t->Pt();
937
938 if(t->Pt() > t_ptmax) {
939 t_ptmax=t->Pt();
940 t_dRmax=dR;
941 }
942
943 if(print && t->Pt()>1.) {
944 std::cout<<" passing track #"<<j<<std::endl;
945 std::cout<<" pt = "<<t->Pt()<<std::endl;
946 std::cout<<" eta = "<<t->Eta()<<std::endl;
947 std::cout<<" phi = "<<t->Phi()<<std::endl;
948 std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
949 std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
950 std::cout<<" dR = "<<dR<<std::endl;
951 std::cout<<" dEta = "<<dEta<<std::endl;
952 std::cout<<" vx = "<<t->X0()<<std::endl;
953 std::cout<<" vy = "<<t->Y0()<<std::endl;
954 std::cout<<" vz = "<<t->Z0()<<std::endl;
955 std::cout<<" new tIso = "<<iIso<<std::endl;
956 }
957 }
958 }
959 if ( iIso > maxIso ) {
960 maxIso = iIso;
961 if(worstVtxIndex)
962 *worstVtxIndex=i;
963 }
964 }
965
966 if(ptmax) (*ptmax)=t_ptmax;
967 if(dRmax) (*dRmax)=t_dRmax;
968
969 if(print) {
970 if(worstVtxIndex)
971 std::cout<<" max TrkIso is given by Vtx #"<<*worstVtxIndex<<" with an amount of tIso = "<<maxIso<<std::endl;
972 else
973 std::cout<<" max TrkIso is given by Vtx #0 with an amount of tIso = "<<maxIso<<std::endl;
974 }
975 return maxIso;
976 }
977
978 //ChargedIso_selvtx_DR0To0p001=IsolationTools::PFChargedIsolation(p, SelVtx, 0.01, 0, 0.0, 0.0, 0.1, 0.2,fPFCands);
979
980 Double_t IsolationTools::PFChargedIsolation(const mithep::Photon *p,
981 const BaseVertex *theVtx,
982 Double_t extRadius,
983 Double_t intRadius,
984 const PFCandidateCol *PFCands,
985 unsigned int* worstVtxIndex,
986 const mithep::Collection<mithep::Vertex> *vtxs,
987 bool print)
988 {
989
990 UInt_t numVtx = 1;
991
992 const BaseVertex* iVtx = theVtx;
993
994 if( vtxs ) {
995 numVtx = vtxs->GetEntries();
996 if (numVtx > 0)
997 iVtx = vtxs->At(0);
998 else
999 return 0.;
1000 }
1001
1002 if(print) {
1003 std::cout<<" Testing photon with"<<std::endl;
1004 std::cout<<" Et = "<<p->Et()<<std::endl;
1005 std::cout<<" Eta = "<<p->Eta()<<std::endl;
1006 std::cout<<" Phi = "<<p->Phi()<<std::endl;
1007 }
1008
1009 Double_t iIso = 0.;
1010 Double_t maxIso = 0.;
1011
1012 if(worstVtxIndex)
1013 *worstVtxIndex=0;
1014
1015 for(UInt_t i=0; i<numVtx; ++i) {
1016
1017 if(i>0) iVtx = vtxs->At(i);
1018
1019
1020 if(print) {
1021 std::cout<<" Vertex #"<<i<<std::endl;
1022 std::cout<<" with X = "<<iVtx->X()<<std::endl;
1023 std::cout<<" with Y = "<<iVtx->Y()<<std::endl;
1024 std::cout<<" with Z = "<<iVtx->Z()<<std::endl;
1025 }
1026
1027 ThreeVector photondir = ThreeVector(p->SCluster()->Point()) - iVtx->Position();
1028
1029 iIso = 0.;
1030
1031 for(UInt_t j=0; j<PFCands->GetEntries(); ++j) {
1032 const PFCandidate *pf= PFCands->At(j);
1033
1034 if( pf->HasTrackerTrk() && pf->PFType()==PFCandidate::eHadron ) {
1035 const Track* t = pf->TrackerTrk();
1036
1037 Double_t dR = MathUtils::DeltaR(*pf,photondir);
1038 //Double_t dEta = TMath::Abs(pf->Eta()-photondir.Eta());
1039
1040 if (dR<0.02) continue;
1041 if (dR<intRadius) continue;
1042 if (dR>extRadius) continue;
1043
1044 if(print && pf->Pt()>1. && false) {
1045 std::cout<<" passing track #"<<j<<std::endl;
1046 std::cout<<" pt = "<<pf->Pt()<<std::endl;
1047 std::cout<<" eta = "<<pf->Eta()<<std::endl;
1048 std::cout<<" phi = "<<pf->Phi()<<std::endl;
1049 std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
1050 std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
1051 std::cout<<" dR = "<<dR<<std::endl;
1052 //std::cout<<" dEta = "<<dEta<<std::endl;
1053 std::cout<<" vx = "<<t->X0()<<std::endl;
1054 std::cout<<" vy = "<<t->Y0()<<std::endl;
1055 std::cout<<" vz = "<<t->Z0()<<std::endl;
1056 }
1057
1058
1059 // only check for beamspot if available, otherwise ignore cut
1060 if ( fabs(t->D0Corrected( *iVtx )) > 0.1) continue;
1061 if ( fabs(t->DzCorrected( *iVtx )) > 0.2) continue;
1062
1063 iIso += pf->Pt();
1064
1065 }
1066 }
1067
1068 if ( iIso > maxIso ) {
1069 maxIso = iIso;
1070 if(worstVtxIndex)
1071 *worstVtxIndex=i;
1072 }
1073 }
1074
1075
1076 if(print) {
1077 if(worstVtxIndex)
1078 std::cout<<" max TrkIso is given by Vtx #"<<*worstVtxIndex<<" with an amount of tIso = "<<maxIso<<std::endl;
1079 else
1080 std::cout<<" max TrkIso is given by Vtx #0 with an amount of tIso = "<<maxIso<<std::endl;
1081 }
1082 return maxIso;
1083 }
1084
1085 //
1086 Float_t IsolationTools::PFChargedCount(const mithep::Photon* p,
1087 const BaseVertex* theVtx,
1088 Double_t extRadius,
1089 Double_t intRadius,
1090 Double_t ptLow,
1091 Double_t etaStrip,
1092 Double_t maxD0,
1093 Double_t maxDZ,
1094 const PFCandidateCol *PFCands,
1095 unsigned int* worstVtxIndex,
1096 const mithep::Collection<mithep::Vertex> *vtxs,
1097 const mithep::Collection<mithep::Electron> *eles,
1098 bool print,
1099 double* ptmax,
1100 double* dRmax) {
1101
1102 UInt_t numVtx = 1;
1103
1104 const BaseVertex* iVtx = theVtx;
1105
1106 if( vtxs ) {
1107 numVtx = vtxs->GetEntries();
1108 if (numVtx > 0)
1109 iVtx = vtxs->At(0);
1110 else
1111 return 0.;
1112 }
1113
1114 // NEW for Electron T&P: need to remove the electron Gsf Track (applied if eles != NULL)
1115 const Track* theGsfTrack = NULL;
1116 if ( eles ) {
1117 // find the electron that matches the Photon SC
1118 for(UInt_t j=0; j<eles->GetEntries(); ++j) {
1119 if ( eles->At(j)->SCluster() == p->SCluster() ) {
1120 if( eles->At(j)->HasTrackerTrk() )
1121 theGsfTrack = eles->At(j)->TrackerTrk();
1122 break;
1123 }
1124 }
1125 }
1126
1127 if(print) {
1128 std::cout<<" Testing photon with"<<std::endl;
1129 std::cout<<" Et = "<<p->Et()<<std::endl;
1130 std::cout<<" Eta = "<<p->Eta()<<std::endl;
1131 std::cout<<" Phi = "<<p->Phi()<<std::endl;
1132 }
1133
1134 Double_t iIso = 0.;
1135 Double_t maxIso = 0.;
1136
1137 Float_t iNumParticles = 0.;
1138 Float_t maxNumParticles = 0.;
1139
1140 if(worstVtxIndex)
1141 *worstVtxIndex=0;
1142
1143 double t_ptmax = 0.;
1144 double t_dRmax = 0.;
1145
1146 for(UInt_t i=0; i<numVtx; ++i) {
1147
1148 if(i>0) iVtx = vtxs->At(i);
1149
1150
1151 if(print) {
1152 std::cout<<" Vertex #"<<i<<std::endl;
1153 std::cout<<" with X = "<<iVtx->X()<<std::endl;
1154 std::cout<<" with Y = "<<iVtx->Y()<<std::endl;
1155 std::cout<<" with Z = "<<iVtx->Z()<<std::endl;
1156 }
1157
1158 Photon* phTemp = new Photon(*p);
1159
1160 // RESET CALO_POS! //ming: why?
1161 phTemp->SetCaloPosXYZ(p->SCluster()->Point().X(),p->SCluster()->Point().Y(),p->SCluster()->Point().Z());
1162
1163 // compute the ph momentum with respect to this Vtx
1164 FourVectorM phMom = phTemp->MomVtx(iVtx->Position());
1165
1166 delete phTemp;
1167
1168 if(print) {
1169 std::cout<<" photon has changed to:"<<std::endl;
1170 std::cout<<" Et = "<<phMom.Et()<<std::endl;
1171 std::cout<<" eta = "<<phMom.Eta()<<std::endl;
1172 std::cout<<" Phi = "<<phMom.Phi()<<std::endl;
1173 }
1174
1175 iIso = 0.;
1176 iNumParticles = 0.;
1177
1178 for(UInt_t j=0; j<PFCands->GetEntries(); ++j) {
1179 const PFCandidate *pf= PFCands->At(j);
1180 if(pf->HasTrk() && (pf->PFType()==PFCandidate::eHadron || pf->PFType()==PFCandidate::eElectron || pf->PFType()==PFCandidate::eMuon)){
1181 const Track* t = pf->BestTrk();
1182 if(pf->PFType()==PFCandidate::eElectron && pf->HasGsfTrk()){t = pf->GsfTrk();}
1183 if(!(pf->PFType()==PFCandidate::eElectron) && pf->HasTrackerTrk()){t = pf->TrackerTrk();}
1184
1185 if( theGsfTrack && t == theGsfTrack ) continue;
1186
1187 Double_t dR = MathUtils::DeltaR(pf->Mom(),phMom);
1188 Double_t dEta = TMath::Abs(pf->Eta()-phMom.Eta());
1189
1190 if(print && pf->Pt()>1. && false) {
1191 std::cout<<" passing track #"<<j<<std::endl;
1192 std::cout<<" pt = "<<pf->Pt()<<std::endl;
1193 std::cout<<" eta = "<<pf->Eta()<<std::endl;
1194 std::cout<<" phi = "<<pf->Phi()<<std::endl;
1195 std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
1196 std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
1197 std::cout<<" dR = "<<dR<<std::endl;
1198 std::cout<<" dEta = "<<dEta<<std::endl;
1199 std::cout<<" vx = "<<t->X0()<<std::endl;
1200 std::cout<<" vy = "<<t->Y0()<<std::endl;
1201 std::cout<<" vz = "<<t->Z0()<<std::endl;
1202 }
1203
1204 if ( pf->Pt() < ptLow ) continue;
1205
1206 // only check for beamspot if available, otherwise ignore cut
1207 if ( fabs(t->D0Corrected( *iVtx )) > maxD0) continue;
1208 if ( fabs(t->DzCorrected( *iVtx )) > maxDZ) continue;
1209
1210
1211 if(dR < extRadius && dR > intRadius && dEta > etaStrip) {
1212 iIso += pf->Pt();
1213 iNumParticles += 1;
1214
1215 if(pf->Pt() > t_ptmax) {
1216 t_ptmax=pf->Pt();
1217 t_dRmax=dR;
1218 }
1219
1220 if(print && pf->Pt()>1.) {
1221 std::cout<<" passing track #"<<j<<std::endl;
1222 std::cout<<" pt = "<<pf->Pt()<<std::endl;
1223 std::cout<<" eta = "<<pf->Eta()<<std::endl;
1224 std::cout<<" phi = "<<pf->Phi()<<std::endl;
1225 std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
1226 std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
1227 std::cout<<" dR = "<<dR<<std::endl;
1228 std::cout<<" dEta = "<<dEta<<std::endl;
1229 std::cout<<" vx = "<<t->X0()<<std::endl;
1230 std::cout<<" vy = "<<t->Y0()<<std::endl;
1231 std::cout<<" vz = "<<t->Z0()<<std::endl;
1232 std::cout<<" new tIso = "<<iIso<<std::endl;
1233 }
1234 }
1235 }
1236 }
1237
1238 if ( iIso > maxIso ) {
1239 maxIso = iIso;
1240 maxNumParticles = iNumParticles;
1241
1242 if(worstVtxIndex)
1243 *worstVtxIndex=i;
1244 }
1245 }
1246
1247 if(ptmax) (*ptmax)=t_ptmax;
1248 if(dRmax) (*dRmax)=t_dRmax;
1249
1250 if(print) {
1251 if(worstVtxIndex)
1252 std::cout<<" max TrkIso is given by Vtx #"<<*worstVtxIndex<<" with an amount of tIso = "<<maxIso<<std::endl;
1253 else
1254 std::cout<<" max TrkIso is given by Vtx #0 with an amount of tIso = "<<maxIso<<std::endl;
1255 }
1256 return maxNumParticles;
1257 }
1258
1259 Double_t IsolationTools::PFGammaIsolation(const mithep::Photon *p,
1260 Double_t extRadius,
1261 Double_t intRadius,
1262 const PFCandidateCol *PFCands)
1263 {
1264
1265 Double_t iso = 0.;
1266
1267 ThreeVector photondir;
1268 //Bool_t setdir = kFALSE;
1269
1270 for (UInt_t ipfc = 0; ipfc<PFCands->GetEntries(); ++ipfc) {
1271 const PFCandidate *pfc = PFCands->At(ipfc);
1272 if (pfc->PFType()!=PFCandidate::eGamma) continue;
1273
1274 ThreeVector photondir = ThreeVector(p->SCluster()->Point() - pfc->SourceVertex());
1275
1276 Double_t dR = MathUtils::DeltaR(*pfc,photondir);
1277 Double_t dEta = TMath::Abs(pfc->Eta()-photondir.Eta());
1278
1279 Bool_t isbarrel = p->SCluster()->AbsEta()<1.5;
1280
1281 if (isbarrel && dEta<0.015) continue;
1282 if (!isbarrel && dR<0.07) continue;
1283 if (dR<intRadius) continue;
1284 if (dR>extRadius) continue;
1285 if (pfc->HasSCluster() && pfc->SCluster()==p->SCluster()) continue;
1286
1287 iso += pfc->Pt();
1288
1289 }
1290
1291 return iso;
1292
1293
1294 }
1295
1296 Double_t IsolationTools::PFNeutralHadronIsolation(const mithep::Photon *p,
1297 Double_t extRadius,
1298 Double_t intRadius,
1299 const PFCandidateCol *PFCands)
1300 {
1301
1302 Double_t iso = 0.;
1303
1304 ThreeVector photondir;
1305 Bool_t setdir = kFALSE;
1306
1307 for (UInt_t ipfc = 0; ipfc<PFCands->GetEntries(); ++ipfc) {
1308 const PFCandidate *pfc = PFCands->At(ipfc);
1309 if (pfc->PFType()!=PFCandidate::eGamma) continue;
1310 if (!setdir) {
1311 photondir = ThreeVector(p->SCluster()->Point() - pfc->SourceVertex());
1312 setdir = kTRUE;
1313 }
1314
1315 Double_t dR = MathUtils::DeltaR(*pfc,photondir);
1316
1317 if (dR<intRadius) continue;
1318 if (dR>extRadius) continue;
1319
1320 iso += pfc->Pt();
1321
1322 }
1323
1324 return iso;
1325
1326
1327 }