ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/IsolationTools.cc
Revision: 1.25
Committed: Wed Dec 21 13:05:47 2011 UTC (13 years, 4 months ago) by sixie
Content type: text/plain
Branch: MAIN
Changes since 1.24: +7 -12 lines
Log Message:
small modification: apply dZ cut only on charged pf candidates

File Contents

# User Rev Content
1 sixie 1.25 // $Id: IsolationTools.cc,v 1.24 2011/12/21 13:03:23 sixie 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.23 Double_t IsolationTools::PFMuonIsolation(const Muon *p, const PFCandidateCol *PFCands,
123 ceballos 1.8 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
124 ceballos 1.21 Double_t extRadius, Double_t intRadiusGamma, Double_t intRadius)
125 mzanetti 1.15 {
126     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
127     //annulus around the particle seed track.
128    
129     Double_t zLepton = 0.0;
130     if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
131    
132     Double_t ptSum =0.;
133     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
134     const PFCandidate *pf = PFCands->At(i);
135    
136     // exclude muon
137     if(pf->TrackerTrk() && p->TrackerTrk() &&
138     pf->TrackerTrk() == p->TrackerTrk()) continue;
139    
140 mzanetti 1.18 Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
141    
142     // pt cut applied to neutrals
143     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
144    
145 mzanetti 1.15 // ignore the pf candidate if it is too far away in Z
146     if(pf->HasTrk()) {
147 sixie 1.24 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
148     if (deltaZ >= delta_z) continue;
149 mzanetti 1.15 }
150 mzanetti 1.18
151     // inner cone veto for gammas
152 ceballos 1.21 if (pf->PFType() == PFCandidate::eGamma && dr < intRadiusGamma) continue;
153 mzanetti 1.18
154 ceballos 1.21 // inner cone veto for tracks
155     if (dr < intRadius) continue;
156    
157 mzanetti 1.18 // add the pf pt if it is inside the extRadius
158 ceballos 1.21 if (dr < extRadius) ptSum += pf->Pt();
159 mzanetti 1.15
160     }
161     return ptSum;
162     }
163    
164     //--------------------------------------------------------------------------------------------------
165 ceballos 1.23 Double_t IsolationTools::PFMuonIsolation(const Muon *p, const PFCandidateCol *PFCands,
166     const MuonCol *goodMuons, const ElectronCol *goodElectrons,
167     const Vertex *vertex, Double_t delta_z, Double_t ptMin,
168     Double_t extRadius, Double_t intRadiusGamma, Double_t intRadius)
169 ceballos 1.5 {
170     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
171     //annulus around the particle seed track.
172    
173     Double_t zLepton = 0.0;
174 ceballos 1.8 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
175 ceballos 1.5
176     Double_t ptSum =0.;
177     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
178     const PFCandidate *pf = PFCands->At(i);
179    
180 ceballos 1.23 // exclude muon
181     if(pf->TrackerTrk() && p->TrackerTrk() &&
182     pf->TrackerTrk() == p->TrackerTrk()) continue;
183 ceballos 1.5
184 ceballos 1.23 Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
185    
186 mzanetti 1.13 // pt cut applied to neutrals
187     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
188 ceballos 1.6
189 ceballos 1.23 // ignore the pf candidate if it is too far away in Z
190     if(pf->HasTrk()) {
191 sixie 1.24 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
192     if (deltaZ >= delta_z) continue;
193 ceballos 1.5 }
194 ceballos 1.23
195 mzanetti 1.18 // inner cone veto for gammas
196 ceballos 1.23 if (pf->PFType() == PFCandidate::eGamma && dr < intRadiusGamma) continue;
197    
198     // inner cone veto for tracks
199     if (dr < intRadius) continue;
200 mzanetti 1.18
201 ceballos 1.5 // add the pf pt if it is inside the extRadius and outside the intRadius
202 mzanetti 1.18 if (dr < extRadius ) {
203 ceballos 1.8 Bool_t isLepton = kFALSE;
204 ceballos 1.23 if(goodMuons){
205 ceballos 1.8 for (UInt_t nl=0; nl<goodMuons->GetEntries();nl++) {
206     const Muon *m = goodMuons->At(nl);
207     if(pf->TrackerTrk() && m->TrackerTrk() &&
208     pf->TrackerTrk() == m->TrackerTrk()) {
209     isLepton = kTRUE;
210     break;
211     }
212     }
213     }
214 ceballos 1.23 if(goodElectrons && isLepton == kFALSE){
215 ceballos 1.8 for (UInt_t nl=0; nl<goodElectrons->GetEntries();nl++) {
216     const Electron *e = goodElectrons->At(nl);
217     if(pf->TrackerTrk() && e->TrackerTrk() &&
218     pf->TrackerTrk() == e->TrackerTrk()) {
219     isLepton = kTRUE;
220     break;
221     }
222     if(pf->GsfTrk() && e->GsfTrk() &&
223     pf->GsfTrk() == e->GsfTrk()) {
224     isLepton = kTRUE;
225     break;
226     }
227     }
228     }
229 ceballos 1.23 if (isLepton == kTRUE) continue;
230     ptSum += pf->Pt();
231     }
232 ceballos 1.5 }
233     return ptSum;
234     }
235 mzanetti 1.15
236 ceballos 1.5 //--------------------------------------------------------------------------------------------------
237     Double_t IsolationTools::PFElectronIsolation(const Electron *p, const PFCandidateCol *PFCands,
238 ceballos 1.8 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
239 sixie 1.16 Double_t extRadius, Double_t intRadius)
240     {
241    
242     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
243     //annulus around the particle seed track.
244    
245     Double_t zLepton = 0.0;
246     if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
247    
248     Double_t ptSum =0.;
249     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
250     const PFCandidate *pf = PFCands->At(i);
251    
252     // pt cut applied to neutrals
253     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
254    
255     if(pf->TrackerTrk() && p->TrackerTrk() &&
256     pf->TrackerTrk() == p->TrackerTrk()) continue;
257    
258     if(pf->GsfTrk() && p->GsfTrk() &&
259     pf->GsfTrk() == p->GsfTrk()) continue;
260    
261 sixie 1.25 // ignore the pf candidate if it is too far away in Z
262 sixie 1.16 if(pf->BestTrk()) {
263 sixie 1.25 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
264     if (deltaZ >= delta_z) continue;
265 sixie 1.16 }
266    
267    
268     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
269     // add the pf pt if it is inside the extRadius and outside the intRadius
270     if ( dr < extRadius &&
271     dr >= intRadius ) {
272    
273     //EtaStrip Veto for Gamma
274     if (pf->PFType() == PFCandidate::eGamma && fabs(p->Eta() - pf->Eta()) < 0.025) continue;
275    
276     //InnerCone (One Tower = dR < 0.07) Veto for non-gamma neutrals
277     if (!pf->HasTrk() && pf->PFType() == PFCandidate::eNeutralHadron
278     && MathUtils::DeltaR(p->Mom(), pf->Mom()) < 0.07 ) continue;
279    
280     ptSum += pf->Pt();
281    
282     }
283     }
284     return ptSum;
285     }
286    
287    
288     //--------------------------------------------------------------------------------------------------
289     Double_t IsolationTools::PFElectronIsolation(const Electron *p, const PFCandidateCol *PFCands,
290 ceballos 1.23 const MuonCol *goodMuons, const ElectronCol *goodElectrons,
291     const Vertex *vertex, Double_t delta_z, Double_t ptMin,
292     Double_t extRadius, Double_t intRadius)
293 ceballos 1.5 {
294 ceballos 1.23
295 ceballos 1.5 //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
296     //annulus around the particle seed track.
297    
298     Double_t zLepton = 0.0;
299 ceballos 1.8 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
300 ceballos 1.5
301     Double_t ptSum =0.;
302     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
303     const PFCandidate *pf = PFCands->At(i);
304    
305 sixie 1.14 // pt cut applied to neutrals
306     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
307 ceballos 1.6
308 ceballos 1.5 if(pf->TrackerTrk() && p->TrackerTrk() &&
309     pf->TrackerTrk() == p->TrackerTrk()) continue;
310    
311     if(pf->GsfTrk() && p->GsfTrk() &&
312     pf->GsfTrk() == p->GsfTrk()) continue;
313    
314 sixie 1.25 // ignore the pf candidate if it is too far away in Z
315 ceballos 1.5 if(pf->BestTrk()) {
316 sixie 1.25 Double_t deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
317     if (deltaZ >= delta_z) continue;
318 ceballos 1.5 }
319    
320     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
321     // add the pf pt if it is inside the extRadius and outside the intRadius
322     if ( dr < extRadius &&
323     dr >= intRadius ) {
324 ceballos 1.23
325     //EtaStrip Veto for Gamma
326     if (pf->PFType() == PFCandidate::eGamma && fabs(p->Eta() - pf->Eta()) < 0.025) continue;
327    
328     //InnerCone (One Tower = dR < 0.07) Veto for non-gamma neutrals
329     if (!pf->HasTrk() && pf->PFType() == PFCandidate::eNeutralHadron
330     && MathUtils::DeltaR(p->Mom(), pf->Mom()) < 0.07 ) continue;
331    
332 ceballos 1.8 Bool_t isLepton = kFALSE;
333 ceballos 1.23 if(goodMuons){
334 ceballos 1.8 for (UInt_t nl=0; nl<goodMuons->GetEntries();nl++) {
335     const Muon *m = goodMuons->At(nl);
336     if(pf->TrackerTrk() && m->TrackerTrk() &&
337     pf->TrackerTrk() == m->TrackerTrk()) {
338     isLepton = kTRUE;
339     break;
340     }
341     }
342     }
343 ceballos 1.23 if(goodElectrons && isLepton == kFALSE){
344 ceballos 1.8 for (UInt_t nl=0; nl<goodElectrons->GetEntries();nl++) {
345     const Electron *e = goodElectrons->At(nl);
346     if(pf->TrackerTrk() && e->TrackerTrk() &&
347     pf->TrackerTrk() == e->TrackerTrk()) {
348     isLepton = kTRUE;
349     break;
350     }
351     if(pf->GsfTrk() && e->GsfTrk() &&
352     pf->GsfTrk() == e->GsfTrk()) {
353     isLepton = kTRUE;
354     break;
355     }
356     }
357     }
358 sixie 1.14
359     if (isLepton == kTRUE) continue;
360 ceballos 1.23 ptSum += pf->Pt();
361 sixie 1.14
362 ceballos 1.5 }
363     }
364     return ptSum;
365     }
366 ceballos 1.7 //--------------------------------------------------------------------------------------------------
367 ceballos 1.8 Double_t IsolationTools::BetaM(const TrackCol *tracks, const Muon *p, const Vertex *vertex,
368 ceballos 1.7 Double_t ptMin, Double_t delta_z, Double_t extRadius,
369     Double_t intRadius){
370    
371 ceballos 1.9 if(!tracks) return 1.0;
372 ceballos 1.7 if(tracks->GetEntries() <= 0) return 1.0;
373    
374     double Pt_jets_X = 0. ;
375     double Pt_jets_Y = 0. ;
376     double Pt_jets_X_tot = 0. ;
377     double Pt_jets_Y_tot = 0. ;
378    
379     for(int i=0;i<int(tracks->GetEntries());i++){
380     const Track *pTrack = tracks->At(i);
381    
382     if(pTrack && p->TrackerTrk() &&
383     pTrack == p->TrackerTrk()) continue;
384    
385     if(pTrack->Pt() <= ptMin) continue;
386    
387     Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
388     if ( dr < extRadius && dr >= intRadius ) {
389     Pt_jets_X_tot += pTrack->Px();
390     Pt_jets_Y_tot += pTrack->Py();
391 ceballos 1.8 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
392 ceballos 1.7 if(pDz < delta_z){
393     Pt_jets_X += pTrack->Px();
394     Pt_jets_Y += pTrack->Py();
395     }
396     }
397     }
398    
399     if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
400     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);
401    
402     return 1.0;
403     }
404    
405     //--------------------------------------------------------------------------------------------------
406 ceballos 1.8 Double_t IsolationTools::BetaE(const TrackCol *tracks, const Electron *p, const Vertex *vertex,
407 ceballos 1.7 Double_t ptMin, Double_t delta_z, Double_t extRadius,
408     Double_t intRadius){
409    
410     if(!tracks) return 1.0;
411     if(tracks->GetEntries() <= 0) return 1.0;
412    
413     double Pt_jets_X = 0. ;
414     double Pt_jets_Y = 0. ;
415     double Pt_jets_X_tot = 0. ;
416     double Pt_jets_Y_tot = 0. ;
417    
418     for(int i=0;i<int(tracks->GetEntries());i++){
419     const Track *pTrack = tracks->At(i);
420    
421     if(pTrack && p->TrackerTrk() &&
422     pTrack == p->TrackerTrk()) continue;
423    
424     if(pTrack && p->GsfTrk() &&
425     pTrack == p->GsfTrk()) continue;
426    
427     if(pTrack->Pt() <= ptMin) continue;
428    
429     Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
430     if ( dr < extRadius && dr >= intRadius ) {
431     Pt_jets_X_tot += pTrack->Px();
432     Pt_jets_Y_tot += pTrack->Py();
433 ceballos 1.8 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
434 ceballos 1.7 if(pDz < delta_z){
435     Pt_jets_X += pTrack->Px();
436     Pt_jets_Y += pTrack->Py();
437     }
438     }
439     }
440    
441     if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
442     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);
443    
444     return 1.0;
445     }
446 fabstoec 1.10
447    
448     // method added by F.Stoeckli: computes the track isolation with NO constrint on the OV-track compatibility
449     Double_t IsolationTools::TrackIsolationNoPV(const mithep::Particle* p, const BaseVertex* bsp,
450     Double_t extRadius,
451     Double_t intRadius,
452     Double_t ptLow,
453     Double_t etaStrip,
454     Double_t maxD0,
455     mithep::TrackQuality::EQuality quality,
456 bendavid 1.11 const mithep::Collection<mithep::Track> *tracks,
457     UInt_t maxNExpectedHitsInner,
458     const mithep::DecayParticleCol *conversions) {
459 fabstoec 1.10
460     // loop over all tracks
461     Double_t tPt = 0.;
462 fabstoec 1.22 //std::cout<<" *** TrackIso:"<<std::endl;
463 fabstoec 1.10 for(UInt_t i=0; i<tracks->GetEntries(); ++i) {
464     const Track* t = tracks->At(i);
465 fabstoec 1.22 if(t->Pt()>1. && false) {
466     std::cout<<" "<<i<<" pt = "<<t->Pt()<<" ("<<ptLow<<")"<<std::endl;
467     std::cout<<" d0 = "<<fabs(t->D0Corrected( *bsp) )<<" ("<<maxD0<<")"<<std::endl;
468     //std::cout<<" conv ? "<<PhotonTools::MatchedConversion(t,conversions,bsp)<<std::endl;
469     std::cout<<" dR = "<<MathUtils::DeltaR(t->Mom(),p->Mom())<<" ("<<extRadius<<","<<intRadius<<")"<<std::endl;
470     std::cout<<" dEta = "<<fabs(t->Eta()-p->Eta())<<" ("<<etaStrip<<")"<<std::endl;
471     }
472 fabstoec 1.10 if ( t->Pt() < ptLow ) continue;
473     if ( ! t->Quality().Quality(quality) ) continue;
474     // only check for beamspot if available, otherwise ignore cut
475     if ( bsp && fabs(t->D0Corrected( *bsp) ) > maxD0) continue;
476 bendavid 1.11 if (t->NExpectedHitsInner()>maxNExpectedHitsInner) continue;
477     if (conversions && PhotonTools::MatchedConversion(t,conversions,bsp)) continue;
478 fabstoec 1.10 Double_t dR = MathUtils::DeltaR(t->Mom(),p->Mom());
479     Double_t dEta = fabs(t->Eta()-p->Eta());
480     if(dR < extRadius && dR > intRadius && dEta > etaStrip) tPt += t->Pt();
481     }
482     return tPt;
483     }
484    
485 fabstoec 1.19
486 fabstoec 1.20 Double_t IsolationTools::CiCTrackIsolation(const mithep::Photon* p,
487 fabstoec 1.19 const BaseVertex* theVtx,
488     Double_t extRadius,
489     Double_t intRadius,
490     Double_t ptLow,
491     Double_t etaStrip,
492     Double_t maxD0,
493     Double_t maxDZ,
494     const mithep::Collection<mithep::Track> *tracks,
495 fabstoec 1.20 unsigned int* worstVtxIndex,
496     const mithep::Collection<mithep::Vertex> *vtxs,
497 fabstoec 1.22 const mithep::Collection<mithep::Electron> *eles,
498     bool print,
499     double* ptmax, double* dRmax) {
500 fabstoec 1.19
501     UInt_t numVtx = 1;
502     const BaseVertex* iVtx = theVtx;
503     if( vtxs ) {
504     numVtx = vtxs->GetEntries();
505     if (numVtx > 0)
506     iVtx = vtxs->At(0);
507     else
508     return 0.;
509     }
510    
511 fabstoec 1.22 // NEW for Electron T&P: need to remove the electron Gsf Track (applied if eles != NULL)
512     const Track* theGsfTrack = NULL;
513     if ( eles ) {
514     // find the electron that matches the Photon SC
515     for(UInt_t j=0; j<eles->GetEntries(); ++j) {
516     if ( eles->At(j)->SCluster() == p->SCluster() ) {
517     if( eles->At(j)->HasTrackerTrk() )
518     theGsfTrack = eles->At(j)->TrackerTrk();
519     break;
520     }
521     }
522     }
523 fabstoec 1.20
524     if(print) {
525     std::cout<<" Testing photon with"<<std::endl;
526     std::cout<<" Et = "<<p->Et()<<std::endl;
527     std::cout<<" Eta = "<<p->Eta()<<std::endl;
528     std::cout<<" Phi = "<<p->Phi()<<std::endl;
529     }
530    
531 fabstoec 1.19 Double_t iIso = 0.;
532     Double_t maxIso = 0.;
533 fabstoec 1.20
534     if(worstVtxIndex)
535     *worstVtxIndex=0;
536 fabstoec 1.19
537 fabstoec 1.22 double t_ptmax = 0.;
538     double t_dRmax = 0.;
539    
540 fabstoec 1.19 for(UInt_t i=0; i<numVtx; ++i) {
541 fabstoec 1.20
542     if(i>0) iVtx = vtxs->At(i);
543    
544    
545     if(print) {
546     std::cout<<" Vertex #"<<i<<std::endl;
547     std::cout<<" with X = "<<iVtx->X()<<std::endl;
548     std::cout<<" with Y = "<<iVtx->Y()<<std::endl;
549     std::cout<<" with Z = "<<iVtx->Z()<<std::endl;
550     }
551    
552 fabstoec 1.22 Photon* phTemp = new Photon(*p);
553    
554     // RESET CALO_POS!
555     phTemp->SetCaloPosXYZ(p->SCluster()->Point().X(),p->SCluster()->Point().Y(),p->SCluster()->Point().Z());
556    
557 fabstoec 1.20 // compute the ph momentum with respect to this Vtx
558 fabstoec 1.22 //FourVectorM phMom = p->MomVtx(iVtx->Position());
559     FourVectorM phMom = phTemp->MomVtx(iVtx->Position());
560    
561     delete phTemp;
562 fabstoec 1.20
563     if(print) {
564     std::cout<<" photon has changed to:"<<std::endl;
565     std::cout<<" Et = "<<phMom.Et()<<std::endl;
566     std::cout<<" eta = "<<phMom.Eta()<<std::endl;
567     std::cout<<" Phi = "<<phMom.Phi()<<std::endl;
568     }
569    
570 fabstoec 1.19 iIso = 0.;
571 fabstoec 1.20 for(UInt_t j=0; j<tracks->GetEntries(); ++j) {
572     const Track* t = tracks->At(j);
573 fabstoec 1.22 if( theGsfTrack && t == theGsfTrack ) continue;
574 fabstoec 1.20
575     //Double_t dR = MathUtils::DeltaR(t->Mom(),p->Mom());
576     //Double_t dEta = TMath::Abs(t->Eta()-p->Eta());
577    
578     Double_t dR = MathUtils::DeltaR(t->Mom(),phMom);
579     Double_t dEta = TMath::Abs(t->Eta()-phMom.Eta());
580    
581 fabstoec 1.22 if(print && t->Pt()>1. && false) {
582 fabstoec 1.20 std::cout<<" passing track #"<<j<<std::endl;
583     std::cout<<" pt = "<<t->Pt()<<std::endl;
584     std::cout<<" eta = "<<t->Eta()<<std::endl;
585     std::cout<<" phi = "<<t->Phi()<<std::endl;
586     std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
587     std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
588     std::cout<<" dR = "<<dR<<std::endl;
589     std::cout<<" dEta = "<<dEta<<std::endl;
590     std::cout<<" vx = "<<t->X0()<<std::endl;
591     std::cout<<" vy = "<<t->Y0()<<std::endl;
592     std::cout<<" vz = "<<t->Z0()<<std::endl;
593     }
594    
595 fabstoec 1.19 if ( t->Pt() < ptLow ) continue;
596     // only check for beamspot if available, otherwise ignore cut
597     if ( fabs(t->D0Corrected( *iVtx )) > maxD0) continue;
598     if ( fabs(t->DzCorrected( *iVtx )) > maxDZ) continue;
599 fabstoec 1.20
600    
601     if(dR < extRadius && dR > intRadius && dEta > etaStrip) {
602     iIso += t->Pt();
603    
604 fabstoec 1.22 if(t->Pt() > t_ptmax) {
605     t_ptmax=t->Pt();
606     t_dRmax=dR;
607     }
608    
609     if(print && t->Pt()>1.) {
610 fabstoec 1.20 std::cout<<" passing track #"<<j<<std::endl;
611     std::cout<<" pt = "<<t->Pt()<<std::endl;
612     std::cout<<" eta = "<<t->Eta()<<std::endl;
613     std::cout<<" phi = "<<t->Phi()<<std::endl;
614     std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
615     std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
616     std::cout<<" dR = "<<dR<<std::endl;
617     std::cout<<" dEta = "<<dEta<<std::endl;
618     std::cout<<" vx = "<<t->X0()<<std::endl;
619     std::cout<<" vy = "<<t->Y0()<<std::endl;
620     std::cout<<" vz = "<<t->Z0()<<std::endl;
621     std::cout<<" new tIso = "<<iIso<<std::endl;
622     }
623     }
624     }
625     if ( iIso > maxIso ) {
626     maxIso = iIso;
627     if(worstVtxIndex)
628     *worstVtxIndex=i;
629 fabstoec 1.19 }
630     }
631 fabstoec 1.20
632 fabstoec 1.22 if(ptmax) (*ptmax)=t_ptmax;
633     if(dRmax) (*dRmax)=t_dRmax;
634    
635 fabstoec 1.20 if(print) {
636     if(worstVtxIndex)
637     std::cout<<" max TrkIso is given by Vtx #"<<*worstVtxIndex<<" with an amount of tIso = "<<maxIso<<std::endl;
638     else
639     std::cout<<" max TrkIso is given by Vtx #0 with an amount of tIso = "<<maxIso<<std::endl;
640     }
641     return maxIso;
642 fabstoec 1.19 }