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

File Contents

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