ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/IsolationTools.cc
Revision: 1.17
Committed: Fri May 13 08:27:16 2011 UTC (13 years, 11 months ago) by ceballos
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_021pre2
Changes since 1.16: +1 -10 lines
Log Message:
fixed in isolation

File Contents

# User Rev Content
1 ceballos 1.17 // $Id: IsolationTools.cc,v 1.16 2011/05/12 16:08:36 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     Double_t IsolationTools::PFMuonIsolation(const Muon *p, const Collection<PFCandidate> *PFCands,
123 ceballos 1.8 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
124 mzanetti 1.15 Double_t extRadius, Double_t intRadius)
125     {
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     // pt cut applied to neutrals
137     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
138    
139     // exclude muon
140     if(pf->TrackerTrk() && p->TrackerTrk() &&
141     pf->TrackerTrk() == p->TrackerTrk()) continue;
142    
143     // ignore the pf candidate if it is too far away in Z
144     Double_t deltaZ = 0.0;
145     if(pf->HasTrk()) {
146     deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
147     }
148     if (deltaZ >= delta_z)
149     continue;
150    
151     // add the pf pt if it is inside the extRadius and outside the intRadius
152     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
153     if ( dr < extRadius && dr >= intRadius ) ptSum += pf->Pt();
154    
155     }
156     return ptSum;
157     }
158    
159     //--------------------------------------------------------------------------------------------------
160     Double_t IsolationTools::PFMuonIsolation(const Muon *p, const Collection<PFCandidate> *PFCands, const Vertex *vertex,
161     const MuonCol *goodMuons, const ElectronCol *goodElectrons,
162     Double_t delta_z, Double_t ptMin, Double_t extRadius,
163     Double_t intRadius, int isoType, Double_t beta)
164 ceballos 1.5 {
165     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
166     //annulus around the particle seed track.
167    
168     Double_t zLepton = 0.0;
169 ceballos 1.8 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
170 ceballos 1.5
171     Double_t ptSum =0.;
172     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
173     const PFCandidate *pf = PFCands->At(i);
174    
175     Bool_t isGoodType = kFALSE;
176     // all particles
177 ceballos 1.6 if (isoType == 0) isGoodType = kTRUE;
178 ceballos 1.5 // charged particles only
179 ceballos 1.6 else if(isoType == 1 && pf->BestTrk()) isGoodType = kTRUE;
180 ceballos 1.5 // charged particles and gammas only
181 ceballos 1.6 else if(isoType == 2 &&
182     (pf->BestTrk() || pf->PFType() == PFCandidate::eGamma)) isGoodType = kTRUE;
183 ceballos 1.8 // all particles, rejecting good leptons
184     else if(isoType == 3) isGoodType = kTRUE;
185 ceballos 1.5
186     if(isGoodType == kFALSE) continue;
187    
188 mzanetti 1.13 // pt cut applied to neutrals
189     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
190 ceballos 1.6
191 ceballos 1.5 if(pf->TrackerTrk() && p->TrackerTrk() &&
192     pf->TrackerTrk() == p->TrackerTrk()) continue;
193    
194     Double_t deltaZ = 0.0;
195     if(pf->BestTrk()) {
196 ceballos 1.8 deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
197 ceballos 1.5 }
198    
199     // ignore the pf candidate if it is too far away in Z
200 ceballos 1.6 if (deltaZ >= delta_z)
201 ceballos 1.5 continue;
202    
203     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
204     // add the pf pt if it is inside the extRadius and outside the intRadius
205     if ( dr < extRadius &&
206     dr >= intRadius ) {
207 ceballos 1.8 Bool_t isLepton = kFALSE;
208     if(goodMuons && isoType == 3){
209     for (UInt_t nl=0; nl<goodMuons->GetEntries();nl++) {
210     const Muon *m = goodMuons->At(nl);
211     if(pf->TrackerTrk() && m->TrackerTrk() &&
212     pf->TrackerTrk() == m->TrackerTrk()) {
213     isLepton = kTRUE;
214     break;
215     }
216     }
217     }
218     if(goodElectrons && isLepton == kFALSE && isoType == 3){
219     for (UInt_t nl=0; nl<goodElectrons->GetEntries();nl++) {
220     const Electron *e = goodElectrons->At(nl);
221     if(pf->TrackerTrk() && e->TrackerTrk() &&
222     pf->TrackerTrk() == e->TrackerTrk()) {
223     isLepton = kTRUE;
224     break;
225     }
226     if(pf->GsfTrk() && e->GsfTrk() &&
227     pf->GsfTrk() == e->GsfTrk()) {
228     isLepton = kTRUE;
229     break;
230     }
231     }
232     }
233     if(isLepton == kFALSE){
234     if(pf->BestTrk()) ptSum += pf->Pt();
235     else ptSum += pf->Pt()*beta;
236     }
237 ceballos 1.5 }
238     }
239     return ptSum;
240     }
241 mzanetti 1.15
242 ceballos 1.5 //--------------------------------------------------------------------------------------------------
243     Double_t IsolationTools::PFElectronIsolation(const Electron *p, const PFCandidateCol *PFCands,
244 ceballos 1.8 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
245 sixie 1.16 Double_t extRadius, Double_t intRadius)
246     {
247    
248     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
249     //annulus around the particle seed track.
250    
251     Double_t zLepton = 0.0;
252     if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
253    
254     Double_t ptSum =0.;
255     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
256     const PFCandidate *pf = PFCands->At(i);
257    
258     // pt cut applied to neutrals
259     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
260    
261     if(pf->TrackerTrk() && p->TrackerTrk() &&
262     pf->TrackerTrk() == p->TrackerTrk()) continue;
263    
264     if(pf->GsfTrk() && p->GsfTrk() &&
265     pf->GsfTrk() == p->GsfTrk()) continue;
266    
267     Double_t deltaZ = 0.0;
268     if(pf->BestTrk()) {
269     deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
270     }
271    
272     // ignore the pf candidate if it is too far away in Z
273     if (deltaZ >= delta_z)
274     continue;
275    
276     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
277     // add the pf pt if it is inside the extRadius and outside the intRadius
278     if ( dr < extRadius &&
279     dr >= intRadius ) {
280    
281     //EtaStrip Veto for Gamma
282     if (pf->PFType() == PFCandidate::eGamma && fabs(p->Eta() - pf->Eta()) < 0.025) continue;
283    
284     //InnerCone (One Tower = dR < 0.07) Veto for non-gamma neutrals
285     if (!pf->HasTrk() && pf->PFType() == PFCandidate::eNeutralHadron
286     && MathUtils::DeltaR(p->Mom(), pf->Mom()) < 0.07 ) continue;
287    
288     ptSum += pf->Pt();
289    
290     }
291     }
292     return ptSum;
293     }
294    
295    
296     //--------------------------------------------------------------------------------------------------
297     Double_t IsolationTools::PFElectronIsolation(const Electron *p, const PFCandidateCol *PFCands,
298     const Vertex *vertex, const MuonCol *goodMuons,
299     const ElectronCol *goodElectrons,
300     Double_t delta_z, Double_t ptMin,
301 ceballos 1.8 Double_t extRadius, Double_t intRadius, int isoType,
302 sixie 1.16 Double_t beta)
303 ceballos 1.5 {
304     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
305     //annulus around the particle seed track.
306    
307     Double_t zLepton = 0.0;
308 ceballos 1.8 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
309 ceballos 1.5
310     Double_t ptSum =0.;
311     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
312     const PFCandidate *pf = PFCands->At(i);
313    
314     Bool_t isGoodType = kFALSE;
315     // all particles
316 ceballos 1.6 if (isoType == 0) isGoodType = kTRUE;
317 ceballos 1.5 // charged particles only
318 ceballos 1.6 else if(isoType == 1 && pf->BestTrk()) isGoodType = kTRUE;
319 ceballos 1.5 // charged particles and gammas only
320 ceballos 1.6 else if(isoType == 2 &&
321     (pf->BestTrk() || pf->PFType() == PFCandidate::eGamma)) isGoodType = kTRUE;
322 ceballos 1.8 // all particles, rejecting good leptons
323     else if(isoType == 3) isGoodType = kTRUE;
324 ceballos 1.5
325     if(isGoodType == kFALSE) continue;
326    
327 sixie 1.14 // pt cut applied to neutrals
328     if(!pf->HasTrk() && pf->Pt() <= ptMin) continue;
329 ceballos 1.6
330 ceballos 1.5 if(pf->TrackerTrk() && p->TrackerTrk() &&
331     pf->TrackerTrk() == p->TrackerTrk()) continue;
332    
333     if(pf->GsfTrk() && p->GsfTrk() &&
334     pf->GsfTrk() == p->GsfTrk()) continue;
335    
336     Double_t deltaZ = 0.0;
337     if(pf->BestTrk()) {
338 ceballos 1.8 deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
339 ceballos 1.5 }
340    
341     // ignore the pf candidate if it is too far away in Z
342 ceballos 1.6 if (deltaZ >= delta_z)
343 ceballos 1.5 continue;
344    
345     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
346     // add the pf pt if it is inside the extRadius and outside the intRadius
347     if ( dr < extRadius &&
348     dr >= intRadius ) {
349 ceballos 1.8 Bool_t isLepton = kFALSE;
350     if(goodMuons && isoType == 3){
351     for (UInt_t nl=0; nl<goodMuons->GetEntries();nl++) {
352     const Muon *m = goodMuons->At(nl);
353     if(pf->TrackerTrk() && m->TrackerTrk() &&
354     pf->TrackerTrk() == m->TrackerTrk()) {
355     isLepton = kTRUE;
356     break;
357     }
358     }
359     }
360     if(goodElectrons && isLepton == kFALSE && isoType == 3){
361     for (UInt_t nl=0; nl<goodElectrons->GetEntries();nl++) {
362     const Electron *e = goodElectrons->At(nl);
363     if(pf->TrackerTrk() && e->TrackerTrk() &&
364     pf->TrackerTrk() == e->TrackerTrk()) {
365     isLepton = kTRUE;
366     break;
367     }
368     if(pf->GsfTrk() && e->GsfTrk() &&
369     pf->GsfTrk() == e->GsfTrk()) {
370     isLepton = kTRUE;
371     break;
372     }
373     }
374     }
375 sixie 1.14
376     if (isLepton == kTRUE) continue;
377    
378     //EtaStrip Veto for Gamma
379     if (pf->PFType() == PFCandidate::eGamma && fabs(p->Eta() - pf->Eta()) < 0.025) continue;
380    
381     //InnerCone (One Tower = dR < 0.07) Veto for non-gamma neutrals
382     if (!pf->HasTrk() && pf->PFType() == PFCandidate::eNeutralHadron
383     && MathUtils::DeltaR(p->Mom(), pf->Mom()) < 0.07 ) continue;
384    
385    
386     if(pf->BestTrk()) ptSum += pf->Pt();
387     else ptSum += pf->Pt()*beta;
388    
389    
390 ceballos 1.5 }
391     }
392     return ptSum;
393     }
394 ceballos 1.7 //--------------------------------------------------------------------------------------------------
395 ceballos 1.8 Double_t IsolationTools::BetaM(const TrackCol *tracks, const Muon *p, const Vertex *vertex,
396 ceballos 1.7 Double_t ptMin, Double_t delta_z, Double_t extRadius,
397     Double_t intRadius){
398    
399 ceballos 1.9 if(!tracks) return 1.0;
400 ceballos 1.7 if(tracks->GetEntries() <= 0) return 1.0;
401    
402     double Pt_jets_X = 0. ;
403     double Pt_jets_Y = 0. ;
404     double Pt_jets_X_tot = 0. ;
405     double Pt_jets_Y_tot = 0. ;
406    
407     for(int i=0;i<int(tracks->GetEntries());i++){
408     const Track *pTrack = tracks->At(i);
409    
410     if(pTrack && p->TrackerTrk() &&
411     pTrack == p->TrackerTrk()) continue;
412    
413     if(pTrack->Pt() <= ptMin) continue;
414    
415     Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
416     if ( dr < extRadius && dr >= intRadius ) {
417     Pt_jets_X_tot += pTrack->Px();
418     Pt_jets_Y_tot += pTrack->Py();
419 ceballos 1.8 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
420 ceballos 1.7 if(pDz < delta_z){
421     Pt_jets_X += pTrack->Px();
422     Pt_jets_Y += pTrack->Py();
423     }
424     }
425     }
426    
427     if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
428     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);
429    
430     return 1.0;
431     }
432    
433     //--------------------------------------------------------------------------------------------------
434 ceballos 1.8 Double_t IsolationTools::BetaE(const TrackCol *tracks, const Electron *p, const Vertex *vertex,
435 ceballos 1.7 Double_t ptMin, Double_t delta_z, Double_t extRadius,
436     Double_t intRadius){
437    
438     if(!tracks) return 1.0;
439     if(tracks->GetEntries() <= 0) return 1.0;
440    
441     double Pt_jets_X = 0. ;
442     double Pt_jets_Y = 0. ;
443     double Pt_jets_X_tot = 0. ;
444     double Pt_jets_Y_tot = 0. ;
445    
446     for(int i=0;i<int(tracks->GetEntries());i++){
447     const Track *pTrack = tracks->At(i);
448    
449     if(pTrack && p->TrackerTrk() &&
450     pTrack == p->TrackerTrk()) continue;
451    
452     if(pTrack && p->GsfTrk() &&
453     pTrack == p->GsfTrk()) continue;
454    
455     if(pTrack->Pt() <= ptMin) continue;
456    
457     Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
458     if ( dr < extRadius && dr >= intRadius ) {
459     Pt_jets_X_tot += pTrack->Px();
460     Pt_jets_Y_tot += pTrack->Py();
461 ceballos 1.8 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
462 ceballos 1.7 if(pDz < delta_z){
463     Pt_jets_X += pTrack->Px();
464     Pt_jets_Y += pTrack->Py();
465     }
466     }
467     }
468    
469     if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
470     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);
471    
472     return 1.0;
473     }
474 fabstoec 1.10
475    
476     // method added by F.Stoeckli: computes the track isolation with NO constrint on the OV-track compatibility
477     Double_t IsolationTools::TrackIsolationNoPV(const mithep::Particle* p, const BaseVertex* bsp,
478     Double_t extRadius,
479     Double_t intRadius,
480     Double_t ptLow,
481     Double_t etaStrip,
482     Double_t maxD0,
483     mithep::TrackQuality::EQuality quality,
484 bendavid 1.11 const mithep::Collection<mithep::Track> *tracks,
485     UInt_t maxNExpectedHitsInner,
486     const mithep::DecayParticleCol *conversions) {
487 fabstoec 1.10
488     // loop over all tracks
489     Double_t tPt = 0.;
490     for(UInt_t i=0; i<tracks->GetEntries(); ++i) {
491     const Track* t = tracks->At(i);
492     if ( t->Pt() < ptLow ) continue;
493     if ( ! t->Quality().Quality(quality) ) continue;
494     // only check for beamspot if available, otherwise ignore cut
495     if ( bsp && fabs(t->D0Corrected( *bsp) ) > maxD0) continue;
496 bendavid 1.11 if (t->NExpectedHitsInner()>maxNExpectedHitsInner) continue;
497     if (conversions && PhotonTools::MatchedConversion(t,conversions,bsp)) continue;
498 fabstoec 1.10 Double_t dR = MathUtils::DeltaR(t->Mom(),p->Mom());
499     Double_t dEta = fabs(t->Eta()-p->Eta());
500     if(dR < extRadius && dR > intRadius && dEta > etaStrip) tPt += t->Pt();
501     }
502     return tPt;
503     }
504