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.16 by ceballos, Thu Apr 30 06:34:09 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 >  fMuIDType(kIdUndef),
26 >  fMuIsoType(kIsoUndef),
27 >  fMuClassType(kClassUndef),
28 >  fMuons(0),
29 >  fVertices(0),
30 >  fMuonTools(0),
31 >  fReverseIsoCut(kTRUE)
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 = -1; // make sure pt is taken from the correct track!
52 >    switch (fMuClassType) {
53 >      case kAll:
54 >        pass = kTRUE;
55 >        pt = mu->Pt();
56 >        break;
57 >      case kGlobal:
58 >        pass = (mu->GlobalTrk() != 0);
59 >        if (pass)
60 >          pt = mu->GlobalTrk()->Pt();
61 >        break;
62 >      case kSta:
63 >        pass = (mu->StandaloneTrk() != 0);
64 >        if (pass)
65 >          pt = mu->StandaloneTrk()->Pt();
66 >        break;
67 >      case kTrackerOnly:
68 >        pass = (mu->TrackerTrk() != 0);
69 >        if (pass)
70 >          pt = mu->TrackerTrk()->Pt();
71 >        break;
72 >      default:
73 >        break;
74 >    }
75 >
76 >    if (!pass)
77 >      continue;
78 >
79 >    if (pt <= fMuonPtMin)
80 >      continue;
81 >
82 >    Bool_t idpass = kFALSE;
83 >    switch (fMuIDType) {
84 >      case kLoose:
85 >        idpass = fMuonTools->IsGood(mu, MuonTools::kTMOneStationLoose) &&
86 >                 fMuonTools->IsGood(mu, MuonTools::kTM2DCompatibilityLoose);
87 >        break;
88 >      case kTight:
89 >        idpass = fMuonTools->IsGood(mu, MuonTools::kTMOneStationTight) &&
90 >                 fMuonTools->IsGood(mu, MuonTools::kTM2DCompatibilityTight);
91 >        break;
92 >      default:
93 >        break;
94 >    }
95 >
96 >    if (!idpass)
97 >      continue;
98 >
99 >    Bool_t isopass = kFALSE;
100 >    switch (fMuIsoType) {
101 >      case kTrackCalo:
102 >        isopass = (mu->IsoR03SumPt() < fTrackIsolationCut) &&
103 >          (mu->IsoR03EmEt() + mu->IsoR03HadEt() < fCaloIsolationCut);
104 >        break;
105 >      case kTrackCaloCombined:
106 >        isopass = (1.0 * mu->IsoR03SumPt() + 1.0 * mu->IsoR03EmEt() +
107 >                   1.0 * mu->IsoR03HadEt() < fCombIsolationCut);
108 >        break;
109 >      case kTrackCaloSliding:
110 >        {
111 >          Double_t totalIso = 1.0 * mu->IsoR03SumPt() +
112 >                              1.0 * mu->IsoR03EmEt() +
113 >                              1.0 * mu->IsoR03HadEt();
114 >          if ((totalIso < (mu->Pt()-10.0)*5.0/15.0 && mu->Pt() <= 25) ||
115 >              (totalIso < 5.0 && mu->Pt() > 25) ||
116 >               totalIso <= 0)
117 >            isopass = kTRUE;
118 >        }
119 >        break;
120 >      case kNoIso:
121 >        isopass = kTRUE;
122 >        break;
123 >      case kCustomIso:
124 >      default:
125 >        break;
126      }
127 +
128 +    if ((isopass == kFALSE && fReverseIsoCut == kFALSE) ||
129 +        (isopass == kTRUE  && fReverseIsoCut == kTRUE))
130 +      continue;
131 +
132 +    // d0 cut
133 +    double d0_real = 99999;
134 +    for(uint i0 = 0; i0 < fVertices->GetEntries(); i0++) {
135 +      double pD0 = mu->GlobalTrk()->D0Corrected(*fVertices->At(i0));
136 +      if(TMath::Abs(pD0) < TMath::Abs(d0_real)) d0_real = TMath::Abs(pD0);
137 +    }
138 +    if(d0_real >= fD0Cut) continue;
139 +
140 +    // add good muon
141 +    CleanMuons->Add(mu);
142    }
143  
144 <  //Final Summary Debug Output  
145 <  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 < }
144 >  // sort according to pt
145 >  CleanMuons->Sort();
146  
147 +  // add objects for other modules to use
148 +  AddObjThisEvt(CleanMuons);  
149 + }
150  
151   //--------------------------------------------------------------------------------------------------
152   void MuonIDMod::SlaveBegin()
153   {
154    // Run startup code on the computer (slave) doing the actual analysis. Here,
155 <  // we typically initialize histograms and other analysis objects and request
101 <  // branches. For this module, we request a branch of the MitTree.
155 >  // we just request the muon collection branch.
156  
157 <  ReqBranch(fMuonName,              fMuons);
158 < }
157 >  ReqBranch(fMuonBranchName, fMuons);
158 >  ReqBranch(fVertexName, fVertices);
159  
160 < //--------------------------------------------------------------------------------------------------
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.
160 >  fMuonTools = new MuonTools;
161  
162 < }
162 >  if (fMuonIDType.CompareTo("Tight") == 0)
163 >    fMuIDType = kTight;
164 >  else if (fMuonIDType.CompareTo("Loose") == 0)
165 >    fMuIDType = kLoose;
166 >  else if (fMuonIDType.CompareTo("NoId") == 0)
167 >    fMuIDType = kNoId;
168 >  else if (fMuonIDType.CompareTo("Custom") == 0) {
169 >    fMuIDType = kCustomId;
170 >    SendError(kWarning, "SlaveBegin",
171 >              "Custom muon identification is not yet implemented.");
172 >  } else {
173 >    SendError(kAbortAnalysis, "SlaveBegin",
174 >              "The specified muon identification %s is not defined.",
175 >              fMuonIDType.Data());
176 >    return;
177 >  }
178  
179 < //--------------------------------------------------------------------------------------------------
180 < void MuonIDMod::Terminate()
181 < {
182 <  // Run finishing code on the client computer. For this module, we dont do
183 <  // anything here.
179 >  if (fMuonIsoType.CompareTo("TrackCalo") == 0)
180 >    fMuIsoType = kTrackCalo;
181 >  else if (fMuonIsoType.CompareTo("TrackCaloCombined") == 0)
182 >    fMuIsoType = kTrackCaloCombined;
183 >  else if (fMuonIsoType.CompareTo("TrackCaloSliding") == 0)
184 >    fMuIsoType = kTrackCaloSliding;
185 >  else if (fMuonIsoType.CompareTo("NoIso") == 0)
186 >    fMuIsoType = kNoIso;
187 >  else if (fMuonIsoType.CompareTo("Custom") == 0) {
188 >    fMuIsoType = kCustomIso;
189 >    SendError(kWarning, "SlaveBegin",
190 >              "Custom muon isolation is not yet implemented.");
191 >  } else {
192 >    SendError(kAbortAnalysis, "SlaveBegin",
193 >              "The specified muon isolation %s is not defined.",
194 >              fMuonIsoType.Data());
195 >    return;
196 >  }
197 >
198 >  if (fMuonClassType.CompareTo("All") == 0)
199 >    fMuClassType = kAll;
200 >  else if (fMuonClassType.CompareTo("Global") == 0)
201 >    fMuClassType = kGlobal;
202 >  else if (fMuonClassType.CompareTo("Standalone") == 0)
203 >    fMuClassType = kSta;
204 >  else if (fMuonClassType.CompareTo("TrackerOnly") == 0)
205 >    fMuClassType = kTrackerOnly;
206 >  else {
207 >    SendError(kAbortAnalysis, "SlaveBegin",
208 >              "The specified muon class %s is not defined.",
209 >              fMuonClassType.Data());
210 >    return;
211 >  }
212   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines