ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/IsolationTools.cc
Revision: 1.23
Committed: Wed Nov 2 20:12:03 2011 UTC (13 years, 6 months ago) by ceballos
Content type: text/plain
Branch: MAIN
Changes since 1.22: +39 -69 lines
Log Message:
updating isolation for non-iso leptons

File Contents

# User Rev Content
1 ceballos 1.23 // $Id: IsolationTools.cc,v 1.22 2011/10/18 11:27:19 fabstoec Exp $
2 loizides 1.1
3     #include "MitPhysics/Utils/interface/IsolationTools.h"
4 bendavid 1.11 #include "MitPhysics/Utils/interface/PhotonTools.h"
5 loizides 1.1 #include "MitCommon/MathTools/interface/MathUtils.h"
6    
7 loizides 1.4 ClassImp(mithep::IsolationTools)
8    
9 loizides 1.1 using namespace mithep;
10    
11     //--------------------------------------------------------------------------------------------------
12     Double_t IsolationTools::TrackIsolation(const Track *p, Double_t extRadius, Double_t intRadius,
13     Double_t ptLow, Double_t maxVtxZDist,
14 phedex 1.2 const Collection<Track> *tracks)
15 loizides 1.1 {
16     //Computes the Track Isolation: Summed Transverse Momentum of all tracks inside an
17     //annulus around the electron seed track.
18    
19     Double_t ptSum =0.;
20     for (UInt_t i=0; i<tracks->GetEntries();i++) {
21     Double_t tmpPt = tracks->At(i)->Pt();
22     Double_t deltaZ = fabs(p->Z0() - tracks->At(i)->Z0());
23    
24     //ignore the track if it is below the pt threshold
25     if (tmpPt < ptLow)
26     continue;
27     //ingore the track if it is too far away in Z
28     if (deltaZ > maxVtxZDist)
29     continue;
30    
31 phedex 1.2 Double_t dr = MathUtils::DeltaR(p->Phi(),p->Eta(),tracks->At(i)->Phi(), tracks->At(i)->Eta());
32 loizides 1.1 //add the track pt if it is inside the annulus
33     if ( dr < extRadius &&
34     dr >= intRadius ) {
35     ptSum += tmpPt;
36     }
37     }
38     return ptSum;
39     }
40    
41     //--------------------------------------------------------------------------------------------------
42     Double_t IsolationTools::EcalIsolation(const SuperCluster *sc, Double_t coneSize, Double_t etLow,
43 phedex 1.2 const Collection<BasicCluster> *basicClusters)
44 loizides 1.1 {
45     //Computes the Ecal Isolation: Summed Transverse Energy of all Basic Clusters inside a
46     //cone around the electron, excluding those that are inside the electron super cluster.
47    
48     Double_t ecalIsol=0.;
49     const BasicCluster *basicCluster= 0;
50     for (UInt_t i=0; i<basicClusters->GetEntries();i++) {
51     basicCluster = basicClusters->At(i);
52     Double_t basicClusterEnergy = basicCluster->Energy();
53     Double_t basicClusterEta = basicCluster->Eta();
54     Double_t basicClusterEt = basicClusterEnergy*sin(2*atan(exp(basicClusterEta)));
55    
56 bendavid 1.3 if (basicClusterEt > etLow) {
57 loizides 1.1 bool inSuperCluster = false;
58    
59     // loop over the basic clusters of the supercluster
60     // to make sure that the basic cluster is not inside
61     // the super cluster. We exclude those.
62     for (UInt_t j=0; j<sc->ClusterSize(); j++) {
63     const BasicCluster *tempBasicClusterInSuperCluster = sc->Cluster(j);
64     if (tempBasicClusterInSuperCluster == basicCluster) {
65     inSuperCluster = true;
66     }
67     }
68    
69     if (!inSuperCluster) {
70 phedex 1.2 Double_t dr = MathUtils::DeltaR(sc->Phi(), sc->Eta(),
71     basicCluster->Phi(),basicCluster->Eta());
72 loizides 1.1 if(dr < coneSize) {
73     ecalIsol += basicClusterEt;
74     }
75     }
76     }
77     }
78     return ecalIsol;
79     }
80    
81     //--------------------------------------------------------------------------------------------------
82     Double_t IsolationTools::CaloTowerHadIsolation(const ThreeVector *p, Double_t extRadius,
83     Double_t intRadius, Double_t etLow,
84 phedex 1.2 const Collection<CaloTower> *caloTowers)
85 loizides 1.1 {
86     //Computes the CaloTower Had Et Isolation: Summed Hadronic Transverse Energy of all Calo Towers
87     //inside an annulus around the electron super cluster position.
88    
89     Double_t sumEt = 0;
90     for (UInt_t i=0; i<caloTowers->GetEntries();i++) {
91     Double_t caloTowerEt = caloTowers->At(i)->HadEt();
92     Double_t dr = MathUtils::DeltaR(caloTowers->At(i)->Phi(), caloTowers->At(i)->Eta(),
93     p->Phi(), p->Eta());
94     if (dr < extRadius && dr > intRadius && caloTowerEt > etLow) {
95     sumEt += caloTowerEt;
96     }
97     }
98     return sumEt;
99     }
100    
101     //--------------------------------------------------------------------------------------------------
102     Double_t IsolationTools::CaloTowerEmIsolation(const ThreeVector *p, Double_t extRadius,
103     Double_t intRadius, Double_t etLow,
104 phedex 1.2 const Collection<CaloTower> *caloTowers)
105 loizides 1.1 {
106     //Computes the CaloTower Em Et Isolation: Summed Hadronic Transverse Energy of all Calo Towers
107     //inside an annulus around the electron super cluster position.
108    
109     Double_t sumEt = 0;
110     for (UInt_t i=0; i<caloTowers->GetEntries();i++) {
111     Double_t caloTowerEt = caloTowers->At(i)->EmEt();
112     Double_t dr = MathUtils::DeltaR(caloTowers->At(i)->Phi(), caloTowers->At(i)->Eta(),
113     p->Phi(), p->Eta());
114     if (dr < extRadius && dr > intRadius && caloTowerEt > etLow) {
115     sumEt += caloTowerEt;
116     }
117     }
118     return sumEt;
119     }
120 ceballos 1.5
121     //--------------------------------------------------------------------------------------------------
122 ceballos 1.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     Double_t deltaZ = 0.0;
147     if(pf->HasTrk()) {
148     deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
149     }
150 mzanetti 1.18 if (deltaZ >= delta_z) continue;
151    
152     // inner cone veto for gammas
153 ceballos 1.21 if (pf->PFType() == PFCandidate::eGamma && dr < intRadiusGamma) continue;
154 mzanetti 1.18
155 ceballos 1.21 // inner cone veto for tracks
156     if (dr < intRadius) continue;
157    
158 mzanetti 1.18 // add the pf pt if it is inside the extRadius
159 ceballos 1.21 if (dr < extRadius) ptSum += pf->Pt();
160 mzanetti 1.15
161     }
162     return ptSum;
163     }
164    
165     //--------------------------------------------------------------------------------------------------
166 ceballos 1.23 Double_t IsolationTools::PFMuonIsolation(const Muon *p, const PFCandidateCol *PFCands,
167     const MuonCol *goodMuons, const ElectronCol *goodElectrons,
168     const Vertex *vertex, Double_t delta_z, Double_t ptMin,
169     Double_t extRadius, Double_t intRadiusGamma, Double_t intRadius)
170 ceballos 1.5 {
171     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
172     //annulus around the particle seed track.
173    
174     Double_t zLepton = 0.0;
175 ceballos 1.8 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
176 ceballos 1.5
177     Double_t ptSum =0.;
178     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
179     const PFCandidate *pf = PFCands->At(i);
180    
181 ceballos 1.23 // exclude muon
182     if(pf->TrackerTrk() && p->TrackerTrk() &&
183     pf->TrackerTrk() == p->TrackerTrk()) continue;
184 ceballos 1.5
185 ceballos 1.23 Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
186    
187 mzanetti 1.13 // pt cut applied to neutrals
188     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
189 ceballos 1.6
190 ceballos 1.23 // ignore the pf candidate if it is too far away in Z
191 ceballos 1.5 Double_t deltaZ = 0.0;
192 ceballos 1.23 if(pf->HasTrk()) {
193 ceballos 1.8 deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
194 ceballos 1.5 }
195 ceballos 1.23 if (deltaZ >= delta_z) continue;
196    
197 mzanetti 1.18 // inner cone veto for gammas
198 ceballos 1.23 if (pf->PFType() == PFCandidate::eGamma && dr < intRadiusGamma) continue;
199    
200     // inner cone veto for tracks
201     if (dr < intRadius) continue;
202 mzanetti 1.18
203 ceballos 1.5 // add the pf pt if it is inside the extRadius and outside the intRadius
204 mzanetti 1.18 if (dr < extRadius ) {
205 ceballos 1.8 Bool_t isLepton = kFALSE;
206 ceballos 1.23 if(goodMuons){
207 ceballos 1.8 for (UInt_t nl=0; nl<goodMuons->GetEntries();nl++) {
208     const Muon *m = goodMuons->At(nl);
209     if(pf->TrackerTrk() && m->TrackerTrk() &&
210     pf->TrackerTrk() == m->TrackerTrk()) {
211     isLepton = kTRUE;
212     break;
213     }
214     }
215     }
216 ceballos 1.23 if(goodElectrons && isLepton == kFALSE){
217 ceballos 1.8 for (UInt_t nl=0; nl<goodElectrons->GetEntries();nl++) {
218     const Electron *e = goodElectrons->At(nl);
219     if(pf->TrackerTrk() && e->TrackerTrk() &&
220     pf->TrackerTrk() == e->TrackerTrk()) {
221     isLepton = kTRUE;
222     break;
223     }
224     if(pf->GsfTrk() && e->GsfTrk() &&
225     pf->GsfTrk() == e->GsfTrk()) {
226     isLepton = kTRUE;
227     break;
228     }
229     }
230     }
231 ceballos 1.23 if (isLepton == kTRUE) continue;
232     ptSum += pf->Pt();
233     }
234 ceballos 1.5 }
235     return ptSum;
236     }
237 mzanetti 1.15
238 ceballos 1.5 //--------------------------------------------------------------------------------------------------
239     Double_t IsolationTools::PFElectronIsolation(const Electron *p, const PFCandidateCol *PFCands,
240 ceballos 1.8 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
241 sixie 1.16 Double_t extRadius, Double_t intRadius)
242     {
243    
244     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
245     //annulus around the particle seed track.
246    
247     Double_t zLepton = 0.0;
248     if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
249    
250     Double_t ptSum =0.;
251     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
252     const PFCandidate *pf = PFCands->At(i);
253    
254     // pt cut applied to neutrals
255     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
256    
257     if(pf->TrackerTrk() && p->TrackerTrk() &&
258     pf->TrackerTrk() == p->TrackerTrk()) continue;
259    
260     if(pf->GsfTrk() && p->GsfTrk() &&
261     pf->GsfTrk() == p->GsfTrk()) continue;
262    
263     Double_t deltaZ = 0.0;
264     if(pf->BestTrk()) {
265     deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
266     }
267    
268     // ignore the pf candidate if it is too far away in Z
269     if (deltaZ >= delta_z)
270     continue;
271    
272     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
273     // add the pf pt if it is inside the extRadius and outside the intRadius
274     if ( dr < extRadius &&
275     dr >= intRadius ) {
276    
277     //EtaStrip Veto for Gamma
278     if (pf->PFType() == PFCandidate::eGamma && fabs(p->Eta() - pf->Eta()) < 0.025) continue;
279    
280     //InnerCone (One Tower = dR < 0.07) Veto for non-gamma neutrals
281     if (!pf->HasTrk() && pf->PFType() == PFCandidate::eNeutralHadron
282     && MathUtils::DeltaR(p->Mom(), pf->Mom()) < 0.07 ) continue;
283    
284     ptSum += pf->Pt();
285    
286     }
287     }
288     return ptSum;
289     }
290    
291    
292     //--------------------------------------------------------------------------------------------------
293     Double_t IsolationTools::PFElectronIsolation(const Electron *p, const PFCandidateCol *PFCands,
294 ceballos 1.23 const MuonCol *goodMuons, const ElectronCol *goodElectrons,
295     const Vertex *vertex, Double_t delta_z, Double_t ptMin,
296     Double_t extRadius, Double_t intRadius)
297 ceballos 1.5 {
298 ceballos 1.23
299 ceballos 1.5 //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
300     //annulus around the particle seed track.
301    
302     Double_t zLepton = 0.0;
303 ceballos 1.8 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
304 ceballos 1.5
305     Double_t ptSum =0.;
306     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
307     const PFCandidate *pf = PFCands->At(i);
308    
309 sixie 1.14 // pt cut applied to neutrals
310     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
311 ceballos 1.6
312 ceballos 1.5 if(pf->TrackerTrk() && p->TrackerTrk() &&
313     pf->TrackerTrk() == p->TrackerTrk()) continue;
314    
315     if(pf->GsfTrk() && p->GsfTrk() &&
316     pf->GsfTrk() == p->GsfTrk()) continue;
317    
318     Double_t deltaZ = 0.0;
319     if(pf->BestTrk()) {
320 ceballos 1.8 deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
321 ceballos 1.5 }
322    
323     // ignore the pf candidate if it is too far away in Z
324 ceballos 1.6 if (deltaZ >= delta_z)
325 ceballos 1.5 continue;
326    
327     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
328     // add the pf pt if it is inside the extRadius and outside the intRadius
329     if ( dr < extRadius &&
330     dr >= intRadius ) {
331 ceballos 1.23
332     //EtaStrip Veto for Gamma
333     if (pf->PFType() == PFCandidate::eGamma && fabs(p->Eta() - pf->Eta()) < 0.025) continue;
334    
335     //InnerCone (One Tower = dR < 0.07) Veto for non-gamma neutrals
336     if (!pf->HasTrk() && pf->PFType() == PFCandidate::eNeutralHadron
337     && MathUtils::DeltaR(p->Mom(), pf->Mom()) < 0.07 ) continue;
338    
339 ceballos 1.8 Bool_t isLepton = kFALSE;
340 ceballos 1.23 if(goodMuons){
341 ceballos 1.8 for (UInt_t nl=0; nl<goodMuons->GetEntries();nl++) {
342     const Muon *m = goodMuons->At(nl);
343     if(pf->TrackerTrk() && m->TrackerTrk() &&
344     pf->TrackerTrk() == m->TrackerTrk()) {
345     isLepton = kTRUE;
346     break;
347     }
348     }
349     }
350 ceballos 1.23 if(goodElectrons && isLepton == kFALSE){
351 ceballos 1.8 for (UInt_t nl=0; nl<goodElectrons->GetEntries();nl++) {
352     const Electron *e = goodElectrons->At(nl);
353     if(pf->TrackerTrk() && e->TrackerTrk() &&
354     pf->TrackerTrk() == e->TrackerTrk()) {
355     isLepton = kTRUE;
356     break;
357     }
358     if(pf->GsfTrk() && e->GsfTrk() &&
359     pf->GsfTrk() == e->GsfTrk()) {
360     isLepton = kTRUE;
361     break;
362     }
363     }
364     }
365 sixie 1.14
366     if (isLepton == kTRUE) continue;
367 ceballos 1.23 ptSum += pf->Pt();
368 sixie 1.14
369 ceballos 1.5 }
370     }
371     return ptSum;
372     }
373 ceballos 1.7 //--------------------------------------------------------------------------------------------------
374 ceballos 1.8 Double_t IsolationTools::BetaM(const TrackCol *tracks, const Muon *p, const Vertex *vertex,
375 ceballos 1.7 Double_t ptMin, Double_t delta_z, Double_t extRadius,
376     Double_t intRadius){
377    
378 ceballos 1.9 if(!tracks) return 1.0;
379 ceballos 1.7 if(tracks->GetEntries() <= 0) return 1.0;
380    
381     double Pt_jets_X = 0. ;
382     double Pt_jets_Y = 0. ;
383     double Pt_jets_X_tot = 0. ;
384     double Pt_jets_Y_tot = 0. ;
385    
386     for(int i=0;i<int(tracks->GetEntries());i++){
387     const Track *pTrack = tracks->At(i);
388    
389     if(pTrack && p->TrackerTrk() &&
390     pTrack == p->TrackerTrk()) continue;
391    
392     if(pTrack->Pt() <= ptMin) continue;
393    
394     Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
395     if ( dr < extRadius && dr >= intRadius ) {
396     Pt_jets_X_tot += pTrack->Px();
397     Pt_jets_Y_tot += pTrack->Py();
398 ceballos 1.8 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
399 ceballos 1.7 if(pDz < delta_z){
400     Pt_jets_X += pTrack->Px();
401     Pt_jets_Y += pTrack->Py();
402     }
403     }
404     }
405    
406     if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
407     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);
408    
409     return 1.0;
410     }
411    
412     //--------------------------------------------------------------------------------------------------
413 ceballos 1.8 Double_t IsolationTools::BetaE(const TrackCol *tracks, const Electron *p, const Vertex *vertex,
414 ceballos 1.7 Double_t ptMin, Double_t delta_z, Double_t extRadius,
415     Double_t intRadius){
416    
417     if(!tracks) return 1.0;
418     if(tracks->GetEntries() <= 0) return 1.0;
419    
420     double Pt_jets_X = 0. ;
421     double Pt_jets_Y = 0. ;
422     double Pt_jets_X_tot = 0. ;
423     double Pt_jets_Y_tot = 0. ;
424    
425     for(int i=0;i<int(tracks->GetEntries());i++){
426     const Track *pTrack = tracks->At(i);
427    
428     if(pTrack && p->TrackerTrk() &&
429     pTrack == p->TrackerTrk()) continue;
430    
431     if(pTrack && p->GsfTrk() &&
432     pTrack == p->GsfTrk()) continue;
433    
434     if(pTrack->Pt() <= ptMin) continue;
435    
436     Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
437     if ( dr < extRadius && dr >= intRadius ) {
438     Pt_jets_X_tot += pTrack->Px();
439     Pt_jets_Y_tot += pTrack->Py();
440 ceballos 1.8 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
441 ceballos 1.7 if(pDz < delta_z){
442     Pt_jets_X += pTrack->Px();
443     Pt_jets_Y += pTrack->Py();
444     }
445     }
446     }
447    
448     if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
449     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);
450    
451     return 1.0;
452     }
453 fabstoec 1.10
454    
455     // method added by F.Stoeckli: computes the track isolation with NO constrint on the OV-track compatibility
456     Double_t IsolationTools::TrackIsolationNoPV(const mithep::Particle* p, const BaseVertex* bsp,
457     Double_t extRadius,
458     Double_t intRadius,
459     Double_t ptLow,
460     Double_t etaStrip,
461     Double_t maxD0,
462     mithep::TrackQuality::EQuality quality,
463 bendavid 1.11 const mithep::Collection<mithep::Track> *tracks,
464     UInt_t maxNExpectedHitsInner,
465     const mithep::DecayParticleCol *conversions) {
466 fabstoec 1.10
467     // loop over all tracks
468     Double_t tPt = 0.;
469 fabstoec 1.22 //std::cout<<" *** TrackIso:"<<std::endl;
470 fabstoec 1.10 for(UInt_t i=0; i<tracks->GetEntries(); ++i) {
471     const Track* t = tracks->At(i);
472 fabstoec 1.22 if(t->Pt()>1. && false) {
473     std::cout<<" "<<i<<" pt = "<<t->Pt()<<" ("<<ptLow<<")"<<std::endl;
474     std::cout<<" d0 = "<<fabs(t->D0Corrected( *bsp) )<<" ("<<maxD0<<")"<<std::endl;
475     //std::cout<<" conv ? "<<PhotonTools::MatchedConversion(t,conversions,bsp)<<std::endl;
476     std::cout<<" dR = "<<MathUtils::DeltaR(t->Mom(),p->Mom())<<" ("<<extRadius<<","<<intRadius<<")"<<std::endl;
477     std::cout<<" dEta = "<<fabs(t->Eta()-p->Eta())<<" ("<<etaStrip<<")"<<std::endl;
478     }
479 fabstoec 1.10 if ( t->Pt() < ptLow ) continue;
480     if ( ! t->Quality().Quality(quality) ) continue;
481     // only check for beamspot if available, otherwise ignore cut
482     if ( bsp && fabs(t->D0Corrected( *bsp) ) > maxD0) continue;
483 bendavid 1.11 if (t->NExpectedHitsInner()>maxNExpectedHitsInner) continue;
484     if (conversions && PhotonTools::MatchedConversion(t,conversions,bsp)) continue;
485 fabstoec 1.10 Double_t dR = MathUtils::DeltaR(t->Mom(),p->Mom());
486     Double_t dEta = fabs(t->Eta()-p->Eta());
487     if(dR < extRadius && dR > intRadius && dEta > etaStrip) tPt += t->Pt();
488     }
489     return tPt;
490     }
491    
492 fabstoec 1.19
493 fabstoec 1.20 Double_t IsolationTools::CiCTrackIsolation(const mithep::Photon* p,
494 fabstoec 1.19 const BaseVertex* theVtx,
495     Double_t extRadius,
496     Double_t intRadius,
497     Double_t ptLow,
498     Double_t etaStrip,
499     Double_t maxD0,
500     Double_t maxDZ,
501     const mithep::Collection<mithep::Track> *tracks,
502 fabstoec 1.20 unsigned int* worstVtxIndex,
503     const mithep::Collection<mithep::Vertex> *vtxs,
504 fabstoec 1.22 const mithep::Collection<mithep::Electron> *eles,
505     bool print,
506     double* ptmax, double* dRmax) {
507 fabstoec 1.19
508     UInt_t numVtx = 1;
509     const BaseVertex* iVtx = theVtx;
510     if( vtxs ) {
511     numVtx = vtxs->GetEntries();
512     if (numVtx > 0)
513     iVtx = vtxs->At(0);
514     else
515     return 0.;
516     }
517    
518 fabstoec 1.22 // NEW for Electron T&P: need to remove the electron Gsf Track (applied if eles != NULL)
519     const Track* theGsfTrack = NULL;
520     if ( eles ) {
521     // find the electron that matches the Photon SC
522     for(UInt_t j=0; j<eles->GetEntries(); ++j) {
523     if ( eles->At(j)->SCluster() == p->SCluster() ) {
524     if( eles->At(j)->HasTrackerTrk() )
525     theGsfTrack = eles->At(j)->TrackerTrk();
526     break;
527     }
528     }
529     }
530 fabstoec 1.20
531     if(print) {
532     std::cout<<" Testing photon with"<<std::endl;
533     std::cout<<" Et = "<<p->Et()<<std::endl;
534     std::cout<<" Eta = "<<p->Eta()<<std::endl;
535     std::cout<<" Phi = "<<p->Phi()<<std::endl;
536     }
537    
538 fabstoec 1.19 Double_t iIso = 0.;
539     Double_t maxIso = 0.;
540 fabstoec 1.20
541     if(worstVtxIndex)
542     *worstVtxIndex=0;
543 fabstoec 1.19
544 fabstoec 1.22 double t_ptmax = 0.;
545     double t_dRmax = 0.;
546    
547 fabstoec 1.19 for(UInt_t i=0; i<numVtx; ++i) {
548 fabstoec 1.20
549     if(i>0) iVtx = vtxs->At(i);
550    
551    
552     if(print) {
553     std::cout<<" Vertex #"<<i<<std::endl;
554     std::cout<<" with X = "<<iVtx->X()<<std::endl;
555     std::cout<<" with Y = "<<iVtx->Y()<<std::endl;
556     std::cout<<" with Z = "<<iVtx->Z()<<std::endl;
557     }
558    
559 fabstoec 1.22 Photon* phTemp = new Photon(*p);
560    
561     // RESET CALO_POS!
562     phTemp->SetCaloPosXYZ(p->SCluster()->Point().X(),p->SCluster()->Point().Y(),p->SCluster()->Point().Z());
563    
564 fabstoec 1.20 // compute the ph momentum with respect to this Vtx
565 fabstoec 1.22 //FourVectorM phMom = p->MomVtx(iVtx->Position());
566     FourVectorM phMom = phTemp->MomVtx(iVtx->Position());
567    
568     delete phTemp;
569 fabstoec 1.20
570     if(print) {
571     std::cout<<" photon has changed to:"<<std::endl;
572     std::cout<<" Et = "<<phMom.Et()<<std::endl;
573     std::cout<<" eta = "<<phMom.Eta()<<std::endl;
574     std::cout<<" Phi = "<<phMom.Phi()<<std::endl;
575     }
576    
577 fabstoec 1.19 iIso = 0.;
578 fabstoec 1.20 for(UInt_t j=0; j<tracks->GetEntries(); ++j) {
579     const Track* t = tracks->At(j);
580 fabstoec 1.22 if( theGsfTrack && t == theGsfTrack ) continue;
581 fabstoec 1.20
582     //Double_t dR = MathUtils::DeltaR(t->Mom(),p->Mom());
583     //Double_t dEta = TMath::Abs(t->Eta()-p->Eta());
584    
585     Double_t dR = MathUtils::DeltaR(t->Mom(),phMom);
586     Double_t dEta = TMath::Abs(t->Eta()-phMom.Eta());
587    
588 fabstoec 1.22 if(print && t->Pt()>1. && false) {
589 fabstoec 1.20 std::cout<<" passing track #"<<j<<std::endl;
590     std::cout<<" pt = "<<t->Pt()<<std::endl;
591     std::cout<<" eta = "<<t->Eta()<<std::endl;
592     std::cout<<" phi = "<<t->Phi()<<std::endl;
593     std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
594     std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
595     std::cout<<" dR = "<<dR<<std::endl;
596     std::cout<<" dEta = "<<dEta<<std::endl;
597     std::cout<<" vx = "<<t->X0()<<std::endl;
598     std::cout<<" vy = "<<t->Y0()<<std::endl;
599     std::cout<<" vz = "<<t->Z0()<<std::endl;
600     }
601    
602 fabstoec 1.19 if ( t->Pt() < ptLow ) continue;
603     // only check for beamspot if available, otherwise ignore cut
604     if ( fabs(t->D0Corrected( *iVtx )) > maxD0) continue;
605     if ( fabs(t->DzCorrected( *iVtx )) > maxDZ) continue;
606 fabstoec 1.20
607    
608     if(dR < extRadius && dR > intRadius && dEta > etaStrip) {
609     iIso += t->Pt();
610    
611 fabstoec 1.22 if(t->Pt() > t_ptmax) {
612     t_ptmax=t->Pt();
613     t_dRmax=dR;
614     }
615    
616     if(print && t->Pt()>1.) {
617 fabstoec 1.20 std::cout<<" passing track #"<<j<<std::endl;
618     std::cout<<" pt = "<<t->Pt()<<std::endl;
619     std::cout<<" eta = "<<t->Eta()<<std::endl;
620     std::cout<<" phi = "<<t->Phi()<<std::endl;
621     std::cout<<" d0 = "<<fabs(t->D0Corrected( *iVtx ))<<std::endl;
622     std::cout<<" dZ = "<<fabs(t->DzCorrected( *iVtx ))<<std::endl;
623     std::cout<<" dR = "<<dR<<std::endl;
624     std::cout<<" dEta = "<<dEta<<std::endl;
625     std::cout<<" vx = "<<t->X0()<<std::endl;
626     std::cout<<" vy = "<<t->Y0()<<std::endl;
627     std::cout<<" vz = "<<t->Z0()<<std::endl;
628     std::cout<<" new tIso = "<<iIso<<std::endl;
629     }
630     }
631     }
632     if ( iIso > maxIso ) {
633     maxIso = iIso;
634     if(worstVtxIndex)
635     *worstVtxIndex=i;
636 fabstoec 1.19 }
637     }
638 fabstoec 1.20
639 fabstoec 1.22 if(ptmax) (*ptmax)=t_ptmax;
640     if(dRmax) (*dRmax)=t_dRmax;
641    
642 fabstoec 1.20 if(print) {
643     if(worstVtxIndex)
644     std::cout<<" max TrkIso is given by Vtx #"<<*worstVtxIndex<<" with an amount of tIso = "<<maxIso<<std::endl;
645     else
646     std::cout<<" max TrkIso is given by Vtx #0 with an amount of tIso = "<<maxIso<<std::endl;
647     }
648     return maxIso;
649 fabstoec 1.19 }