ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/MuonIDMod.cc
(Generate patch)

Comparing UserCode/MitPhysics/Mods/src/MuonIDMod.cc (file contents):
Revision 1.3 by ceballos, Wed Nov 5 14:06:09 2008 UTC vs.
Revision 1.20 by loizides, Mon May 11 08:02:43 2009 UTC

# Line 1 | Line 1
1   // $Id$
2  
3   #include "MitPhysics/Mods/interface/MuonIDMod.h"
4 #include "MitAna/DataTree/interface/Names.h"
5 #include "MitAna/DataCont/interface/ObjArray.h"
6 #include "MitPhysics/Utils/interface/IsolationTools.h"
4   #include "MitCommon/MathTools/interface/MathUtils.h"
5 + #include "MitPhysics/Init/interface/ModNames.h"
6  
7   using namespace mithep;
8  
# Line 13 | Line 11 | ClassImp(mithep::MuonIDMod)
11   //--------------------------------------------------------------------------------------------------
12    MuonIDMod::MuonIDMod(const char *name, const char *title) :
13    BaseMod(name,title),
14 <  fPrintDebug(false),
15 <  fMuonName(Names::gkMuonBrn),
16 <  fCleanMuonsName(Names::gkCleanMuonsName),  
17 <  fMuonIDType("Tight"),
18 <  fMuonIsoType("TrackCalo"),  
19 <  fMuons(0),
14 >  fMuonBranchName(Names::gkMuonBrn),
15 >  fCleanMuonsName(ModNames::gkCleanMuonsName),  
16 >  fVertexName("PrimaryVertexesBeamSpot"),
17 >  fMuonIDType("Loose"),
18 >  fMuonIsoType("TrackCaloSliding"),  
19 >  fMuonClassType("Global"),  
20    fTrackIsolationCut(3.0),
21    fCaloIsolationCut(3.0),
22 +  fCombIsolationCut(5.0),
23    fMuonPtMin(10),
24 <  fNEventsProcessed(0)
24 >  fD0Cut(0.025),
25 >  fReverseIsoCut(kFALSE),
26 >  fMuIDType(kIdUndef),
27 >  fMuIsoType(kIsoUndef),
28 >  fMuClassType(kClassUndef),
29 >  fMuons(0),
30 >  fVertices(0),
31 >  fMuonTools(0)
32   {
33    // Constructor.
34   }
35  
36   //--------------------------------------------------------------------------------------------------
31 void MuonIDMod::Begin()
32 {
33  // Run startup code on the client machine. For this module, we dont do
34  // anything here.
35 }
36
37 //--------------------------------------------------------------------------------------------------
37   void MuonIDMod::Process()
38   {
39    // Process entries of the tree.
40  
41 <  fNEventsProcessed++;
42 <
43 <  if (fNEventsProcessed % 1000 == 0 || fPrintDebug) {
44 <    time_t systime;
45 <    systime = time(NULL);
46 <
48 <    cerr << endl << "MuonIDMod : Process Event " << fNEventsProcessed << "  Time: " << ctime(&systime) << endl;  
49 <  }  
50 <
51 <  //Get Muons
52 <  LoadBranch(fMuonName);
53 <  ObjArray<Muon> *CleanMuons = new ObjArray<Muon>;
41 >  LoadBranch(fMuonBranchName);
42 >  LoadBranch(fVertexName);
43 >
44 >  MuonOArr *CleanMuons = new MuonOArr;
45 >  CleanMuons->SetName(fCleanMuonsName);
46 >
47    for (UInt_t i=0; i<fMuons->GetEntries(); ++i) {
48 <    Muon *mu = fMuons->At(i);
49 <  
50 <    Double_t MuonClass = -1;    
51 <    if (mu->GlobalTrk())      
52 <      MuonClass = 0;
53 <    else if (mu->StandaloneTrk())      
54 <      MuonClass = 1;
55 <    else if (mu->TrackerTrk())
56 <      MuonClass = 2;
57 <
58 <    bool allCuts = false;
59 <
60 <    if(MuonClass == 0) allCuts = true;
61 <
62 <    if(mu->IsoR03SumPt() >= fTrackIsolationCut) allCuts = false;
63 <
64 <    if(mu->IsoR03EmEt() +
65 <       mu->IsoR03HadEt() >= fCaloIsolationCut) allCuts = false;
66 <
67 <    if(mu->Pt() <= fMuonPtMin) allCuts = false;
68 <        
69 <    if(allCuts) {    
70 <      CleanMuons->Add(mu);
48 >    const Muon *mu = fMuons->At(i);
49 >
50 >    Bool_t pass = kFALSE;
51 >    Double_t pt = 0; // make sure pt is taken from the correct track!
52 >    switch (fMuClassType) {
53 >      case kAll:
54 >        pass = kTRUE;
55 >        if (mu->HasTrk())
56 >          pt = mu->Pt();
57 >        break;
58 >      case kGlobal:
59 >        pass = mu->HasGlobalTrk();
60 >        if (pass)
61 >          pt = mu->GlobalTrk()->Pt();
62 >        break;
63 >      case kSta:
64 >        pass = mu->HasStandaloneTrk();
65 >        if (pass)
66 >          pt = mu->StandaloneTrk()->Pt();
67 >        break;
68 >      case kTrackerOnly:
69 >        pass = mu->HasTrackerTrk();
70 >        if (pass)
71 >          pt = mu->TrackerTrk()->Pt();
72 >        break;
73 >      default:
74 >        break;
75 >    }
76 >
77 >    if (!pass)
78 >      continue;
79 >
80 >    if (pt <= fMuonPtMin)
81 >      continue;
82 >
83 >    Bool_t idpass = kFALSE;
84 >    switch (fMuIDType) {
85 >      case kLoose:
86 >        idpass = fMuonTools->IsGood(mu, MuonTools::kTMOneStationLoose) &&
87 >                 fMuonTools->IsGood(mu, MuonTools::kTM2DCompatibilityLoose);
88 >        break;
89 >      case kTight:
90 >        idpass = fMuonTools->IsGood(mu, MuonTools::kTMOneStationTight) &&
91 >                 fMuonTools->IsGood(mu, MuonTools::kTM2DCompatibilityTight);
92 >        break;
93 >      case kNoId:
94 >        idpass = kTRUE;
95 >        break;
96 >      default:
97 >        break;
98 >    }
99 >
100 >    if (!idpass)
101 >      continue;
102 >
103 >    Bool_t isopass = kFALSE;
104 >    switch (fMuIsoType) {
105 >      case kTrackCalo:
106 >        isopass = (mu->IsoR03SumPt() < fTrackIsolationCut) &&
107 >          (mu->IsoR03EmEt() + mu->IsoR03HadEt() < fCaloIsolationCut);
108 >        break;
109 >      case kTrackCaloCombined:
110 >        isopass = (1.0 * mu->IsoR03SumPt() + 1.0 * mu->IsoR03EmEt() +
111 >                   1.0 * mu->IsoR03HadEt() < fCombIsolationCut);
112 >        break;
113 >      case kTrackCaloSliding:
114 >        {
115 >          Double_t totalIso = 1.0 * mu->IsoR03SumPt() +
116 >                              1.0 * mu->IsoR03EmEt() +
117 >                              1.0 * mu->IsoR03HadEt();
118 >          if ((totalIso < (pt-10.0)*5.0/15.0 && pt <= 25) ||
119 >              (totalIso < 5.0 && mu->Pt() > 25) ||
120 >               totalIso <= 0)
121 >            isopass = kTRUE;
122 >        }
123 >        break;
124 >      case kNoIso:
125 >        isopass = kTRUE;
126 >        break;
127 >      case kCustomIso:
128 >      default:
129 >        break;
130      }
131 +
132 +    if ((isopass == kFALSE && fReverseIsoCut == kFALSE) ||
133 +        (isopass == kTRUE  && fReverseIsoCut == kTRUE))
134 +      continue;
135 +
136 +    // d0 cut only for muons that have a track
137 +    const Track *mt = mu->BestTrk();
138 +    if (!mt)
139 +      continue;
140 +    Double_t d0_real = 1e30;
141 +    for(UInt_t i0 = 0; i0 < fVertices->GetEntries(); i0++) {
142 +      Double_t pD0 = mt->D0Corrected(*fVertices->At(i0));
143 +      if(TMath::Abs(pD0) < TMath::Abs(d0_real))
144 +        d0_real = TMath::Abs(pD0);
145 +    }
146 +    if(d0_real >= fD0Cut)
147 +      continue;
148 +
149 +    // add good muon
150 +    CleanMuons->Add(mu);
151    }
152  
153 <  //Final Summary Debug Output  
154 <  if ( fPrintDebug ) {
83 <    cerr << "Event Dump: " << fNEventsProcessed << endl;  
84 <    cerr << "Muons" << endl;
85 <    for (UInt_t i = 0; i < CleanMuons->GetEntries(); i++) {
86 <      cerr << i << " " << CleanMuons->At(i)->Pt() << " " << CleanMuons->At(i)->Eta()
87 <           << " " << CleanMuons->At(i)->Phi() << endl;    
88 <    }  
89 <  }  
90 <  
91 <  //Save Objects for Other Modules to use
92 <  AddObjThisEvt(CleanMuons, fCleanMuonsName.Data());  
93 < }
153 >  // sort according to pt
154 >  CleanMuons->Sort();
155  
156 +  // add objects for other modules to use
157 +  AddObjThisEvt(CleanMuons);  
158 + }
159  
160   //--------------------------------------------------------------------------------------------------
161   void MuonIDMod::SlaveBegin()
162   {
163    // Run startup code on the computer (slave) doing the actual analysis. Here,
164 <  // we typically initialize histograms and other analysis objects and request
101 <  // branches. For this module, we request a branch of the MitTree.
164 >  // we just request the muon collection branch.
165  
166 <  ReqBranch(fMuonName,              fMuons);
167 < }
166 >  ReqBranch(fMuonBranchName, fMuons);
167 >  ReqBranch(fVertexName, fVertices);
168  
169 < //--------------------------------------------------------------------------------------------------
107 < void MuonIDMod::SlaveTerminate()
108 < {
109 <  // Run finishing code on the computer (slave) that did the analysis. For this
110 <  // module, we dont do anything here.
169 >  fMuonTools = new MuonTools;
170  
171 < }
171 >  if (fMuonIDType.CompareTo("Tight") == 0)
172 >    fMuIDType = kTight;
173 >  else if (fMuonIDType.CompareTo("Loose") == 0)
174 >    fMuIDType = kLoose;
175 >  else if (fMuonIDType.CompareTo("NoId") == 0)
176 >    fMuIDType = kNoId;
177 >  else if (fMuonIDType.CompareTo("Custom") == 0) {
178 >    fMuIDType = kCustomId;
179 >    SendError(kWarning, "SlaveBegin",
180 >              "Custom muon identification is not yet implemented.");
181 >  } else {
182 >    SendError(kAbortAnalysis, "SlaveBegin",
183 >              "The specified muon identification %s is not defined.",
184 >              fMuonIDType.Data());
185 >    return;
186 >  }
187  
188 < //--------------------------------------------------------------------------------------------------
189 < void MuonIDMod::Terminate()
190 < {
191 <  // Run finishing code on the client computer. For this module, we dont do
192 <  // anything here.
188 >  if (fMuonIsoType.CompareTo("TrackCalo") == 0)
189 >    fMuIsoType = kTrackCalo;
190 >  else if (fMuonIsoType.CompareTo("TrackCaloCombined") == 0)
191 >    fMuIsoType = kTrackCaloCombined;
192 >  else if (fMuonIsoType.CompareTo("TrackCaloSliding") == 0)
193 >    fMuIsoType = kTrackCaloSliding;
194 >  else if (fMuonIsoType.CompareTo("NoIso") == 0)
195 >    fMuIsoType = kNoIso;
196 >  else if (fMuonIsoType.CompareTo("Custom") == 0) {
197 >    fMuIsoType = kCustomIso;
198 >    SendError(kWarning, "SlaveBegin",
199 >              "Custom muon isolation is not yet implemented.");
200 >  } else {
201 >    SendError(kAbortAnalysis, "SlaveBegin",
202 >              "The specified muon isolation %s is not defined.",
203 >              fMuonIsoType.Data());
204 >    return;
205 >  }
206 >
207 >  if (fMuonClassType.CompareTo("All") == 0)
208 >    fMuClassType = kAll;
209 >  else if (fMuonClassType.CompareTo("Global") == 0)
210 >    fMuClassType = kGlobal;
211 >  else if (fMuonClassType.CompareTo("Standalone") == 0)
212 >    fMuClassType = kSta;
213 >  else if (fMuonClassType.CompareTo("TrackerOnly") == 0)
214 >    fMuClassType = kTrackerOnly;
215 >  else {
216 >    SendError(kAbortAnalysis, "SlaveBegin",
217 >              "The specified muon class %s is not defined.",
218 >              fMuonClassType.Data());
219 >    return;
220 >  }
221   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines