ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/MuonIDMod.cc
Revision: 1.39
Committed: Wed Feb 23 10:37:12 2011 UTC (14 years, 2 months ago) by ceballos
Content type: text/plain
Branch: MAIN
Changes since 1.38: +10 -10 lines
Log Message:
new ele id

File Contents

# User Rev Content
1 ceballos 1.39 // $Id: MuonIDMod.cc,v 1.38 2011/02/21 13:50:20 ceballos Exp $
2 loizides 1.1
3     #include "MitPhysics/Mods/interface/MuonIDMod.h"
4 loizides 1.6 #include "MitCommon/MathTools/interface/MathUtils.h"
5 ceballos 1.38 #include "MitAna/DataTree/interface/MuonFwd.h"
6     #include "MitAna/DataTree/interface/ElectronFwd.h"
7 loizides 1.23 #include "MitAna/DataTree/interface/VertexCol.h"
8 loizides 1.6 #include "MitPhysics/Init/interface/ModNames.h"
9 loizides 1.1
10     using namespace mithep;
11    
12     ClassImp(mithep::MuonIDMod)
13    
14     //--------------------------------------------------------------------------------------------------
15     MuonIDMod::MuonIDMod(const char *name, const char *title) :
16     BaseMod(name,title),
17 loizides 1.6 fMuonBranchName(Names::gkMuonBrn),
18     fCleanMuonsName(ModNames::gkCleanMuonsName),
19 ceballos 1.39 fNonIsolatedMuonsName("random"),
20     fNonIsolatedElectronsName("random"),
21 ceballos 1.35 fVertexName(ModNames::gkGoodVertexesName),
22 ceballos 1.38 fTrackName(Names::gkTrackBrn),
23     fPFCandidatesName(Names::gkPFCandidatesBrn),
24 ceballos 1.36 fMuonIDType("WWMuId"),
25 ceballos 1.39 fMuonIsoType("TrackCaloSliding"),
26 loizides 1.6 fMuonClassType("Global"),
27 ceballos 1.2 fTrackIsolationCut(3.0),
28     fCaloIsolationCut(3.0),
29 ceballos 1.37 fCombIsolationCut(0.15),
30 ceballos 1.3 fMuonPtMin(10),
31 loizides 1.21 fApplyD0Cut(kTRUE),
32 ceballos 1.30 fD0Cut(0.020),
33     fEtaCut(2.4),
34 loizides 1.20 fReverseIsoCut(kFALSE),
35 ceballos 1.22 fReverseD0Cut(kFALSE),
36 loizides 1.15 fMuIDType(kIdUndef),
37     fMuIsoType(kIsoUndef),
38     fMuClassType(kClassUndef),
39 ceballos 1.14 fMuons(0),
40 loizides 1.15 fVertices(0),
41 ceballos 1.38 fTracks(0),
42     fPFCandidates(0),
43 ceballos 1.39 fNonIsolatedMuons(0),
44     fNonIsolatedElectrons(0)
45 loizides 1.1 {
46     // Constructor.
47     }
48    
49     //--------------------------------------------------------------------------------------------------
50     void MuonIDMod::Process()
51     {
52     // Process entries of the tree.
53    
54 ceballos 1.38 if(fMuIsoType != kPFIsoNoL) {
55     LoadEventObject(fMuonBranchName, fMuons);
56     }
57     else {
58     fMuons = GetObjThisEvt<MuonOArr>(fMuonBranchName);
59     }
60     LoadEventObject(fTrackName, fTracks);
61     LoadEventObject(fPFCandidatesName, fPFCandidates);
62 loizides 1.1
63 loizides 1.7 MuonOArr *CleanMuons = new MuonOArr;
64     CleanMuons->SetName(fCleanMuonsName);
65 loizides 1.1
66 ceballos 1.38 fVertices = GetObjThisEvt<VertexOArr>(fVertexName);
67    
68 loizides 1.1 for (UInt_t i=0; i<fMuons->GetEntries(); ++i) {
69 loizides 1.8 const Muon *mu = fMuons->At(i);
70 loizides 1.6
71     Bool_t pass = kFALSE;
72 ceballos 1.30 Double_t pt = 0; // make sure pt is taken from the correct track!
73     Double_t eta = 0; // make sure eta is taken from the correct track!
74 loizides 1.6 switch (fMuClassType) {
75     case kAll:
76     pass = kTRUE;
77 ceballos 1.30 if (mu->HasTrk()) {
78     pt = mu->Pt();
79     eta = TMath::Abs(mu->Eta());
80     }
81 loizides 1.6 break;
82     case kGlobal:
83 ceballos 1.31 pass = mu->HasGlobalTrk() && mu->IsTrackerMuon();
84 ceballos 1.32 if (pass && mu->TrackerTrk()) {
85 ceballos 1.30 pt = mu->TrackerTrk()->Pt();
86     eta = TMath::Abs(mu->TrackerTrk()->Eta());
87     }
88 ceballos 1.32 else {
89     pt = mu->Pt();
90     eta = TMath::Abs(mu->Eta());
91     }
92 ceballos 1.30 break;
93 loizides 1.6 case kSta:
94 loizides 1.19 pass = mu->HasStandaloneTrk();
95 ceballos 1.30 if (pass) {
96     pt = mu->StandaloneTrk()->Pt();
97     eta = TMath::Abs(mu->StandaloneTrk()->Eta());
98     }
99 loizides 1.6 break;
100 loizides 1.24 case kTrackerMuon:
101 ceballos 1.28 pass = mu->HasTrackerTrk() && mu->IsTrackerMuon() &&
102     mu->Quality().Quality(MuonQuality::TrackerMuonArbitrated);
103 ceballos 1.30 if (pass) {
104     pt = mu->TrackerTrk()->Pt();
105     eta = TMath::Abs(mu->TrackerTrk()->Eta());
106     }
107 loizides 1.24 break;
108     case kCaloMuon:
109     pass = mu->HasTrackerTrk() && mu->IsCaloMuon();
110 ceballos 1.30 if (pass) {
111     pt = mu->TrackerTrk()->Pt();
112     eta = TMath::Abs(mu->TrackerTrk()->Eta());
113     }
114 loizides 1.24 break;
115     case kTrackerBased:
116 loizides 1.19 pass = mu->HasTrackerTrk();
117 ceballos 1.30 if (pass) {
118     pt = mu->TrackerTrk()->Pt();
119     eta = TMath::Abs(mu->TrackerTrk()->Eta());
120     }
121 loizides 1.6 break;
122     default:
123     break;
124 ceballos 1.5 }
125 loizides 1.6
126     if (!pass)
127     continue;
128    
129     if (pt <= fMuonPtMin)
130     continue;
131    
132 ceballos 1.30 if (eta >= fEtaCut)
133     continue;
134    
135 ceballos 1.34 Double_t RChi2 = 0.0;
136     if (mu->HasGlobalTrk()) {
137     RChi2 = mu->GlobalTrk()->Chi2()/mu->GlobalTrk()->Ndof();
138     }
139     else if(mu->BestTrk() != 0){
140     RChi2 = mu->BestTrk()->Chi2()/mu->BestTrk()->Ndof();
141     }
142 loizides 1.6 Bool_t idpass = kFALSE;
143     switch (fMuIDType) {
144 ceballos 1.34 case kWMuId:
145     idpass = mu->BestTrk() != 0 &&
146     mu->BestTrk()->NHits() > 10 &&
147     RChi2 < 10.0 &&
148 ceballos 1.36 (mu->NSegments() > 1 || mu->NMatches() > 1) &&
149 ceballos 1.34 mu->BestTrk()->NPixelHits() > 0 &&
150     mu->Quality().Quality(MuonQuality::GlobalMuonPromptTight);
151     break;
152     case kZMuId:
153     idpass = mu->BestTrk() != 0 &&
154     mu->BestTrk()->NHits() > 10 &&
155 ceballos 1.36 (mu->NSegments() > 1 || mu->NMatches() > 1) &&
156 ceballos 1.34 mu->BestTrk()->NPixelHits() > 0 &&
157     mu->Quality().Quality(MuonQuality::GlobalMuonPromptTight);
158     break;
159 loizides 1.6 case kLoose:
160 ceballos 1.32 idpass = mu->BestTrk() != 0 &&
161     mu->Quality().Quality(MuonQuality::TMOneStationLoose) &&
162 ceballos 1.28 mu->Quality().Quality(MuonQuality::TM2DCompatibilityLoose) &&
163 ceballos 1.29 mu->BestTrk()->NHits() > 10 &&
164 ceballos 1.34 RChi2 < 10.0 &&
165 ceballos 1.30 mu->Quality().Quality(MuonQuality::GlobalMuonPromptTight);
166 loizides 1.6 break;
167     case kTight:
168 ceballos 1.32 idpass = mu->BestTrk() != 0 &&
169     mu->Quality().Quality(MuonQuality::TMOneStationTight) &&
170 ceballos 1.28 mu->Quality().Quality(MuonQuality::TM2DCompatibilityTight) &&
171 ceballos 1.29 mu->BestTrk()->NHits() > 10 &&
172 ceballos 1.34 RChi2 < 10.0 &&
173 ceballos 1.30 mu->Quality().Quality(MuonQuality::GlobalMuonPromptTight);
174 ceballos 1.28 break;
175 ceballos 1.36 case kWWMuId:
176 ceballos 1.32 idpass = mu->BestTrk() != 0 &&
177     mu->BestTrk()->NHits() > 10 &&
178 ceballos 1.34 RChi2 < 10.0 &&
179 ceballos 1.36 (mu->NSegments() > 1 || mu->NMatches() > 1) &&
180     mu->BestTrk()->NPixelHits() > 0 &&
181     mu->Quality().Quality(MuonQuality::GlobalMuonPromptTight) &&
182     mu->BestTrk()->PtErr()/mu->BestTrk()->Pt() < 0.1;
183 loizides 1.6 break;
184 loizides 1.18 case kNoId:
185     idpass = kTRUE;
186     break;
187 loizides 1.6 default:
188     break;
189 ceballos 1.4 }
190 loizides 1.6
191     if (!idpass)
192     continue;
193    
194 ceballos 1.22 Bool_t isocut = kFALSE;
195 loizides 1.6 switch (fMuIsoType) {
196     case kTrackCalo:
197 ceballos 1.22 isocut = (mu->IsoR03SumPt() < fTrackIsolationCut) &&
198 loizides 1.6 (mu->IsoR03EmEt() + mu->IsoR03HadEt() < fCaloIsolationCut);
199     break;
200     case kTrackCaloCombined:
201 ceballos 1.38 isocut = (1.0 * mu->IsoR03SumPt() +
202     1.0 * mu->IsoR03EmEt() +
203     1.0 * mu->IsoR03HadEt() < fCombIsolationCut);
204 loizides 1.6 break;
205     case kTrackCaloSliding:
206     {
207 ceballos 1.38 Double_t beta = IsolationTools::BetaM(fTracks, mu, fVertices->At(0), 0.0, 0.2, 0.3, 0.02);
208     Double_t totalIso = 1.0 * mu->IsoR03SumPt() +
209     (1.0 * mu->IsoR03EmEt() +
210     1.0 * mu->IsoR03HadEt()) * beta;
211 ceballos 1.37 if (totalIso < (mu->Pt()*fCombIsolationCut) )
212 ceballos 1.22 isocut = kTRUE;
213    
214     if (fReverseIsoCut == kTRUE &&
215     isocut == kFALSE && totalIso < 10)
216     isocut = kTRUE;
217     else if(fReverseIsoCut == kTRUE)
218     isocut = kFALSE;
219     }
220 loizides 1.6 break;
221 ceballos 1.38 case kPFIso:
222     {
223     Double_t beta = IsolationTools::BetaM(fTracks, mu, fVertices->At(0), 0.0, 0.2, 0.3, 0.02);
224 ceballos 1.39 Double_t totalIso = IsolationTools::PFMuonIsolation(mu, fPFCandidates, fVertices->At(0), 0.2, 0.5, 0.3, 0.02, 0, beta, fNonIsolatedMuons, fNonIsolatedElectrons);
225 ceballos 1.38 if (totalIso < (mu->Pt()*fCombIsolationCut) )
226     isocut = kTRUE;
227     }
228     break;
229     case kPFIsoNoL:
230     {
231 ceballos 1.39 fNonIsolatedMuons = GetObjThisEvt<MuonCol>(fNonIsolatedMuonsName);
232     fNonIsolatedElectrons = GetObjThisEvt<ElectronCol>(fNonIsolatedElectronsName);
233 ceballos 1.38
234     Double_t beta = IsolationTools::BetaM(fTracks, mu, fVertices->At(0), 0.0, 0.2, 0.3, 0.02);
235 ceballos 1.39 Double_t totalIso = IsolationTools::PFMuonIsolation(mu, fPFCandidates, fVertices->At(0), 0.2, 0.5, 0.3, 0.02, 3, beta, fNonIsolatedMuons, fNonIsolatedElectrons);
236 ceballos 1.38 if (totalIso < (mu->Pt()*fCombIsolationCut) )
237     isocut = kTRUE;
238     }
239     break;
240 loizides 1.13 case kNoIso:
241 ceballos 1.22 isocut = kTRUE;
242 loizides 1.13 break;
243 loizides 1.6 case kCustomIso:
244     default:
245     break;
246 ceballos 1.4 }
247 ceballos 1.3
248 ceballos 1.22 if (isocut == kFALSE)
249 loizides 1.6 continue;
250    
251 loizides 1.21 if (fApplyD0Cut) {
252 ceballos 1.37 Bool_t passD0cut = MuonTools::PassD0Cut(mu, fVertices, fD0Cut);
253 ceballos 1.31 if (!passD0cut)
254 loizides 1.21 continue;
255 ceballos 1.14 }
256    
257 loizides 1.6 // add good muon
258     CleanMuons->Add(mu);
259 loizides 1.1 }
260    
261 loizides 1.10 // sort according to pt
262     CleanMuons->Sort();
263    
264 loizides 1.6 // add objects for other modules to use
265 loizides 1.7 AddObjThisEvt(CleanMuons);
266 loizides 1.1 }
267    
268     //--------------------------------------------------------------------------------------------------
269     void MuonIDMod::SlaveBegin()
270     {
271     // Run startup code on the computer (slave) doing the actual analysis. Here,
272 loizides 1.6 // we just request the muon collection branch.
273    
274 ceballos 1.38 // In this case we cannot have a branch
275     if (fMuonIsoType.CompareTo("PFIsoNoL") != 0) {
276     ReqEventObject(fMuonBranchName, fMuons, kTRUE);
277     }
278     ReqEventObject(fTrackName, fTracks, kTRUE);
279     ReqEventObject(fPFCandidatesName, fPFCandidates, kTRUE);
280 loizides 1.1
281 ceballos 1.34 if (fMuonIDType.CompareTo("WMuId") == 0)
282     fMuIDType = kWMuId;
283     else if (fMuonIDType.CompareTo("ZMuId") == 0)
284     fMuIDType = kZMuId;
285     else if (fMuonIDType.CompareTo("Tight") == 0)
286 loizides 1.6 fMuIDType = kTight;
287     else if (fMuonIDType.CompareTo("Loose") == 0)
288     fMuIDType = kLoose;
289 ceballos 1.36 else if (fMuonIDType.CompareTo("WWMuId") == 0)
290     fMuIDType = kWWMuId;
291 loizides 1.12 else if (fMuonIDType.CompareTo("NoId") == 0)
292     fMuIDType = kNoId;
293 loizides 1.6 else if (fMuonIDType.CompareTo("Custom") == 0) {
294     fMuIDType = kCustomId;
295     SendError(kWarning, "SlaveBegin",
296     "Custom muon identification is not yet implemented.");
297     } else {
298     SendError(kAbortAnalysis, "SlaveBegin",
299     "The specified muon identification %s is not defined.",
300     fMuonIDType.Data());
301     return;
302     }
303 loizides 1.1
304 loizides 1.6 if (fMuonIsoType.CompareTo("TrackCalo") == 0)
305     fMuIsoType = kTrackCalo;
306     else if (fMuonIsoType.CompareTo("TrackCaloCombined") == 0)
307     fMuIsoType = kTrackCaloCombined;
308     else if (fMuonIsoType.CompareTo("TrackCaloSliding") == 0)
309     fMuIsoType = kTrackCaloSliding;
310 ceballos 1.38 else if (fMuonIsoType.CompareTo("PFIso") == 0)
311     fMuIsoType = kPFIso;
312     else if (fMuonIsoType.CompareTo("PFIsoNoL") == 0)
313     fMuIsoType = kPFIsoNoL;
314 loizides 1.6 else if (fMuonIsoType.CompareTo("NoIso") == 0)
315     fMuIsoType = kNoIso;
316     else if (fMuonIsoType.CompareTo("Custom") == 0) {
317     fMuIsoType = kCustomIso;
318     SendError(kWarning, "SlaveBegin",
319     "Custom muon isolation is not yet implemented.");
320     } else {
321     SendError(kAbortAnalysis, "SlaveBegin",
322     "The specified muon isolation %s is not defined.",
323     fMuonIsoType.Data());
324     return;
325     }
326 loizides 1.1
327 loizides 1.6 if (fMuonClassType.CompareTo("All") == 0)
328     fMuClassType = kAll;
329     else if (fMuonClassType.CompareTo("Global") == 0)
330     fMuClassType = kGlobal;
331     else if (fMuonClassType.CompareTo("Standalone") == 0)
332     fMuClassType = kSta;
333 loizides 1.24 else if (fMuonClassType.CompareTo("TrackerMuon") == 0)
334     fMuClassType = kTrackerMuon;
335     else if (fMuonClassType.CompareTo("CaloMuon") == 0)
336     fMuClassType = kCaloMuon;
337     else if (fMuonClassType.CompareTo("TrackerBased") == 0)
338     fMuClassType = kTrackerBased;
339 loizides 1.6 else {
340     SendError(kAbortAnalysis, "SlaveBegin",
341     "The specified muon class %s is not defined.",
342     fMuonClassType.Data());
343     return;
344     }
345 loizides 1.1 }