ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/IsolationTools.cc
Revision: 1.12
Committed: Sat May 7 06:05:38 2011 UTC (14 years ago) by ceballos
Content type: text/plain
Branch: MAIN
Changes since 1.11: +7 -3 lines
Log Message:
fixed in isolation

File Contents

# User Rev Content
1 ceballos 1.12 // $Id: IsolationTools.cc,v 1.11 2011/04/14 22:05:42 bendavid 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     Double_t extRadius, Double_t intRadius, int isoType,
125     Double_t beta, const MuonCol *goodMuons,
126     const ElectronCol *goodElectrons)
127 ceballos 1.5 {
128     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
129     //annulus around the particle seed track.
130    
131     Double_t zLepton = 0.0;
132 ceballos 1.8 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
133 ceballos 1.5
134     Double_t ptSum =0.;
135     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
136     const PFCandidate *pf = PFCands->At(i);
137    
138     Bool_t isGoodType = kFALSE;
139     // all particles
140 ceballos 1.6 if (isoType == 0) isGoodType = kTRUE;
141 ceballos 1.5 // charged particles only
142 ceballos 1.6 else if(isoType == 1 && pf->BestTrk()) isGoodType = kTRUE;
143 ceballos 1.5 // charged particles and gammas only
144 ceballos 1.6 else if(isoType == 2 &&
145     (pf->BestTrk() || pf->PFType() == PFCandidate::eGamma)) isGoodType = kTRUE;
146 ceballos 1.8 // all particles, rejecting good leptons
147     else if(isoType == 3) isGoodType = kTRUE;
148 ceballos 1.5
149     if(isGoodType == kFALSE) continue;
150    
151 ceballos 1.12 if( pf->BestTrk() && pf->Pt() <= 0.1) continue;
152    
153     if(!pf->BestTrk() && pf->Pt() <= ptMin) continue;
154 ceballos 1.6
155 ceballos 1.5 if(pf->TrackerTrk() && p->TrackerTrk() &&
156     pf->TrackerTrk() == p->TrackerTrk()) continue;
157    
158     Double_t deltaZ = 0.0;
159     if(pf->BestTrk()) {
160 ceballos 1.8 deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
161 ceballos 1.5 }
162    
163     // ignore the pf candidate if it is too far away in Z
164 ceballos 1.6 if (deltaZ >= delta_z)
165 ceballos 1.5 continue;
166    
167     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
168     // add the pf pt if it is inside the extRadius and outside the intRadius
169     if ( dr < extRadius &&
170     dr >= intRadius ) {
171 ceballos 1.8 Bool_t isLepton = kFALSE;
172     if(goodMuons && isoType == 3){
173     for (UInt_t nl=0; nl<goodMuons->GetEntries();nl++) {
174     const Muon *m = goodMuons->At(nl);
175     if(pf->TrackerTrk() && m->TrackerTrk() &&
176     pf->TrackerTrk() == m->TrackerTrk()) {
177     isLepton = kTRUE;
178     break;
179     }
180     }
181     }
182     if(goodElectrons && isLepton == kFALSE && isoType == 3){
183     for (UInt_t nl=0; nl<goodElectrons->GetEntries();nl++) {
184     const Electron *e = goodElectrons->At(nl);
185     if(pf->TrackerTrk() && e->TrackerTrk() &&
186     pf->TrackerTrk() == e->TrackerTrk()) {
187     isLepton = kTRUE;
188     break;
189     }
190     if(pf->GsfTrk() && e->GsfTrk() &&
191     pf->GsfTrk() == e->GsfTrk()) {
192     isLepton = kTRUE;
193     break;
194     }
195     }
196     }
197     if(isLepton == kFALSE){
198     if(pf->BestTrk()) ptSum += pf->Pt();
199     else ptSum += pf->Pt()*beta;
200     }
201 ceballos 1.5 }
202     }
203     return ptSum;
204     }
205     //--------------------------------------------------------------------------------------------------
206     Double_t IsolationTools::PFElectronIsolation(const Electron *p, const PFCandidateCol *PFCands,
207 ceballos 1.8 const Vertex *vertex, Double_t delta_z, Double_t ptMin,
208     Double_t extRadius, Double_t intRadius, int isoType,
209     Double_t beta, const MuonCol *goodMuons,
210     const ElectronCol *goodElectrons)
211 ceballos 1.5 {
212     //Computes the PF Isolation: Summed Transverse Momentum of all PF candidates inside an
213     //annulus around the particle seed track.
214    
215     Double_t zLepton = 0.0;
216 ceballos 1.8 if(p->BestTrk()) zLepton = p->BestTrk()->DzCorrected(*vertex);
217 ceballos 1.5
218     Double_t ptSum =0.;
219     for (UInt_t i=0; i<PFCands->GetEntries();i++) {
220     const PFCandidate *pf = PFCands->At(i);
221    
222     Bool_t isGoodType = kFALSE;
223     // all particles
224 ceballos 1.6 if (isoType == 0) isGoodType = kTRUE;
225 ceballos 1.5 // charged particles only
226 ceballos 1.6 else if(isoType == 1 && pf->BestTrk()) isGoodType = kTRUE;
227 ceballos 1.5 // charged particles and gammas only
228 ceballos 1.6 else if(isoType == 2 &&
229     (pf->BestTrk() || pf->PFType() == PFCandidate::eGamma)) isGoodType = kTRUE;
230 ceballos 1.8 // all particles, rejecting good leptons
231     else if(isoType == 3) isGoodType = kTRUE;
232 ceballos 1.5
233     if(isGoodType == kFALSE) continue;
234    
235 ceballos 1.12 if( pf->BestTrk() && pf->Pt() <= 0.1) continue;
236    
237     if(!pf->BestTrk() && pf->Pt() <= ptMin) continue;
238 ceballos 1.6
239 ceballos 1.5 if(pf->TrackerTrk() && p->TrackerTrk() &&
240     pf->TrackerTrk() == p->TrackerTrk()) continue;
241    
242     if(pf->GsfTrk() && p->GsfTrk() &&
243     pf->GsfTrk() == p->GsfTrk()) continue;
244    
245     Double_t deltaZ = 0.0;
246     if(pf->BestTrk()) {
247 ceballos 1.8 deltaZ = TMath::Abs(pf->BestTrk()->DzCorrected(*vertex) - zLepton);
248 ceballos 1.5 }
249    
250     // ignore the pf candidate if it is too far away in Z
251 ceballos 1.6 if (deltaZ >= delta_z)
252 ceballos 1.5 continue;
253    
254     Double_t dr = MathUtils::DeltaR(p->Mom(), pf->Mom());
255     // add the pf pt if it is inside the extRadius and outside the intRadius
256     if ( dr < extRadius &&
257     dr >= intRadius ) {
258 ceballos 1.8 Bool_t isLepton = kFALSE;
259     if(goodMuons && isoType == 3){
260     for (UInt_t nl=0; nl<goodMuons->GetEntries();nl++) {
261     const Muon *m = goodMuons->At(nl);
262     if(pf->TrackerTrk() && m->TrackerTrk() &&
263     pf->TrackerTrk() == m->TrackerTrk()) {
264     isLepton = kTRUE;
265     break;
266     }
267     }
268     }
269     if(goodElectrons && isLepton == kFALSE && isoType == 3){
270     for (UInt_t nl=0; nl<goodElectrons->GetEntries();nl++) {
271     const Electron *e = goodElectrons->At(nl);
272     if(pf->TrackerTrk() && e->TrackerTrk() &&
273     pf->TrackerTrk() == e->TrackerTrk()) {
274     isLepton = kTRUE;
275     break;
276     }
277     if(pf->GsfTrk() && e->GsfTrk() &&
278     pf->GsfTrk() == e->GsfTrk()) {
279     isLepton = kTRUE;
280     break;
281     }
282     }
283     }
284     if(isLepton == kFALSE){
285     if(pf->BestTrk()) ptSum += pf->Pt();
286     else ptSum += pf->Pt()*beta;
287     }
288 ceballos 1.5 }
289     }
290     return ptSum;
291     }
292 ceballos 1.7 //--------------------------------------------------------------------------------------------------
293 ceballos 1.8 Double_t IsolationTools::BetaM(const TrackCol *tracks, const Muon *p, const Vertex *vertex,
294 ceballos 1.7 Double_t ptMin, Double_t delta_z, Double_t extRadius,
295     Double_t intRadius){
296    
297 ceballos 1.9 if(!tracks) return 1.0;
298 ceballos 1.7 if(tracks->GetEntries() <= 0) return 1.0;
299    
300     double Pt_jets_X = 0. ;
301     double Pt_jets_Y = 0. ;
302     double Pt_jets_X_tot = 0. ;
303     double Pt_jets_Y_tot = 0. ;
304    
305     for(int i=0;i<int(tracks->GetEntries());i++){
306     const Track *pTrack = tracks->At(i);
307    
308     if(pTrack && p->TrackerTrk() &&
309     pTrack == p->TrackerTrk()) continue;
310    
311     if(pTrack->Pt() <= ptMin) continue;
312    
313     Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
314     if ( dr < extRadius && dr >= intRadius ) {
315     Pt_jets_X_tot += pTrack->Px();
316     Pt_jets_Y_tot += pTrack->Py();
317 ceballos 1.8 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
318 ceballos 1.7 if(pDz < delta_z){
319     Pt_jets_X += pTrack->Px();
320     Pt_jets_Y += pTrack->Py();
321     }
322     }
323     }
324    
325     if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
326     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);
327    
328     return 1.0;
329     }
330    
331     //--------------------------------------------------------------------------------------------------
332 ceballos 1.8 Double_t IsolationTools::BetaE(const TrackCol *tracks, const Electron *p, const Vertex *vertex,
333 ceballos 1.7 Double_t ptMin, Double_t delta_z, Double_t extRadius,
334     Double_t intRadius){
335    
336     if(!tracks) return 1.0;
337     if(tracks->GetEntries() <= 0) return 1.0;
338    
339     double Pt_jets_X = 0. ;
340     double Pt_jets_Y = 0. ;
341     double Pt_jets_X_tot = 0. ;
342     double Pt_jets_Y_tot = 0. ;
343    
344     for(int i=0;i<int(tracks->GetEntries());i++){
345     const Track *pTrack = tracks->At(i);
346    
347     if(pTrack && p->TrackerTrk() &&
348     pTrack == p->TrackerTrk()) continue;
349    
350     if(pTrack && p->GsfTrk() &&
351     pTrack == p->GsfTrk()) continue;
352    
353     if(pTrack->Pt() <= ptMin) continue;
354    
355     Double_t dr = MathUtils::DeltaR(pTrack->Mom(),p->Mom());
356     if ( dr < extRadius && dr >= intRadius ) {
357     Pt_jets_X_tot += pTrack->Px();
358     Pt_jets_Y_tot += pTrack->Py();
359 ceballos 1.8 double pDz = TMath::Abs(pTrack->DzCorrected(*vertex));
360 ceballos 1.7 if(pDz < delta_z){
361     Pt_jets_X += pTrack->Px();
362     Pt_jets_Y += pTrack->Py();
363     }
364     }
365     }
366    
367     if(sqrt(Pt_jets_X_tot*Pt_jets_X_tot + Pt_jets_Y_tot*Pt_jets_Y_tot) > 0)
368     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);
369    
370     return 1.0;
371     }
372 fabstoec 1.10
373    
374     // method added by F.Stoeckli: computes the track isolation with NO constrint on the OV-track compatibility
375     Double_t IsolationTools::TrackIsolationNoPV(const mithep::Particle* p, const BaseVertex* bsp,
376     Double_t extRadius,
377     Double_t intRadius,
378     Double_t ptLow,
379     Double_t etaStrip,
380     Double_t maxD0,
381     mithep::TrackQuality::EQuality quality,
382 bendavid 1.11 const mithep::Collection<mithep::Track> *tracks,
383     UInt_t maxNExpectedHitsInner,
384     const mithep::DecayParticleCol *conversions) {
385 fabstoec 1.10
386     // loop over all tracks
387     Double_t tPt = 0.;
388     for(UInt_t i=0; i<tracks->GetEntries(); ++i) {
389     const Track* t = tracks->At(i);
390     if ( t->Pt() < ptLow ) continue;
391     if ( ! t->Quality().Quality(quality) ) continue;
392     // only check for beamspot if available, otherwise ignore cut
393     if ( bsp && fabs(t->D0Corrected( *bsp) ) > maxD0) continue;
394 bendavid 1.11 if (t->NExpectedHitsInner()>maxNExpectedHitsInner) continue;
395     if (conversions && PhotonTools::MatchedConversion(t,conversions,bsp)) continue;
396 fabstoec 1.10 Double_t dR = MathUtils::DeltaR(t->Mom(),p->Mom());
397     Double_t dEta = fabs(t->Eta()-p->Eta());
398     if(dR < extRadius && dR > intRadius && dEta > etaStrip) tPt += t->Pt();
399     }
400     return tPt;
401     }
402