ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/interface/MuonTools.h
(Generate patch)

Comparing UserCode/MitPhysics/Utils/interface/MuonTools.h (file contents):
Revision 1.1 by pharris, Mon Nov 3 16:43:51 2008 UTC vs.
Revision 1.18 by ceballos, Sun Oct 2 10:03:21 2011 UTC

# Line 1 | Line 1
1 < #ifndef MITPHYSICS_UTIL_MUONTOOLS_H
2 < #define MITPHYSICS_UTIL_MUONTOOLS_H
3 < #include <vector>
4 < #include <iostream>
1 > //--------------------------------------------------------------------------------------------------
2 > // $Id$
3 > //
4 > // MuonTools
5 > //
6 > // This class allows you to classify a given muon according to defined criteria. For this purpose
7 > // is loads histograms from two ROOT files, specified in the constructor. The main function then
8 > // is "IsGood(*muon, selection)" which returns true if the given muon fulfills the selection
9 > // criteria.
10 > //
11 > // Logically, the code has been put together by Phil who took most of the ideas from
12 > //  http://cmslxr.fnal.gov/lxr/source/RecoMuon/MuonIdentification/
13 > //  http://cmslxr.fnal.gov/lxr/source/DataFormats/MuonReco/
14 > //
15 > // Authors: P.Harris, C.Loizides
16 > //--------------------------------------------------------------------------------------------------
17  
18 < #include "TH2D.h"
19 < #include "TFile.h"
20 < #include "MitAna/DataTree/interface/Collections.h"
18 > #ifndef MITPHYSICS_UTILS_MUONTOOLS_H
19 > #define MITPHYSICS_UTILS_MUONTOOLS_H
20 >
21 > #include "MitAna/DataTree/interface/Muon.h"
22 > #include "MitAna/DataTree/interface/VertexCol.h"
23 > #include "MitAna/DataTree/interface/BeamSpotCol.h"
24   #include "MitCommon/MathTools/interface/MathUtils.h"
25 + #include "TH2D.h"
26  
27   namespace mithep {
28    class MuonTools {
29 <  public:
30 <    MuonTools();
31 <    ~MuonTools();
32 <    double getCaloCompatability(mithep::Muon* iMuon,bool iEMSpecial, bool iCorrectedHCAL);
33 <    enum selection {
34 <      AllArbitrated,
35 <      PromptTight,
36 <      TMLastStationLoose,
37 <      TMLastStationTight,
38 <      TMOneStationLoose,
39 <      TMOneStationTight,
40 <      TM2DCompatibilityLoose,
41 <      TM2DCompatibilityTight
42 <    };
43 <    static inline double sigWeight(double iVal0,double iVal1) {
44 <      if(iVal1 < 1.) return 1;
45 <      if(iVal0 < 3. && iVal1 > 3.) {
46 <        double lVal = TMath::Max(iVal0,1.);
47 <        return 1/TMath::Power(lVal,0.25);
48 <      }
49 <      double lVal = TMath::Max(iVal1,1.);
50 <      return 1/TMath::Power(lVal,0.25);
51 <    }
52 <    static inline int lastHit(mithep::Muon *iMuon) {
53 <      int lId = -1;
54 <      for(int i0 = 0; i0 < 8; i0++) {
55 <        if(iMuon->GetDX(i0) < 99999 || iMuon->GetDY(i0) < 99999) lId = i0;
56 <      }
57 <      return lId;
58 <    }
59 <    static inline int maxChamberId(mithep::Muon* iMuon,double iMaxD,double iMaxP) {
60 <      int lId = -1;
61 <      for(int i0 = 0; i0 < 8; i0++) {
62 <        if(iMuon->GetTrackDist(i0)                            < iMaxD &&
63 <           iMuon->GetTrackDist(i0)/iMuon->GetTrackDistErr(i0) < iMaxP) {
64 <          if(iMuon->GetDX(i0) >= 999999) {lId = i0;} else {lId = -1;}
65 <        }
66 <      }
67 <      return lId;
68 <    }
69 <    static inline int lastStation(mithep::Muon* iMuon,double iMaxD,double iMaxP) {
70 <      int lId = -1;
71 <      for(int i0 = 0; i0 < 8; i0++) {
72 <        if((lId % 4) > (i0 % 4)) continue;
73 <        if(iMuon->GetTrackDist(i0)                            < iMaxD &&
74 <           iMuon->GetTrackDist(i0)/iMuon->GetTrackDistErr(i0) < iMaxP) lId = i0;
75 <      }
76 <      return lId;
77 <    }
78 <    static inline int lastStation(mithep::Muon* iMuon,int iMax=8) {
79 <      int lId = -1; if(iMax > 8) iMax = 8;
80 <      for(int i0 = 0; i0 < iMax; i0++) {if(iMuon->StationBit(i0) && ((lId % 4) < (i0 % 4)))lId = i0;}
81 <      return lId;
82 <    }
83 <    static inline bool overflow(TH2D *iHist,double lVal0,double lVal1) {
84 <      if(iHist == 0) return true;
85 <      if(iHist ->GetXaxis()->FindBin(lVal0) == 0               ||
86 <         iHist ->GetXaxis()->FindBin(lVal0) >  iHist->GetNbinsX() ||
71 <         iHist ->GetYaxis()->FindBin(lVal0) == 0               ||
72 <         iHist ->GetYaxis()->FindBin(lVal0) >  iHist->GetNbinsY()) return true;
73 <      return false;
74 <    }
75 <    static inline MCParticle* etaPhiMatch(MCParticleCol* iMCParts,Muon *iMuon) {
76 <      mithep::MCParticle *lMC = 0; double lDR = 1.; double lPt = -1.;
77 <      for(unsigned int i0 = 0; i0 < iMCParts->GetEntries(); i0++) {
78 <        mithep::MCParticle* pMC = iMCParts->At(i0);
79 <        if(pMC->Status() != 1) continue;
80 <        double pDR = mithep::MathUtils::DeltaR(pMC->Mom(),iMuon->Mom());
81 <        if(pDR > lDR && pDR > 0.01) continue;
82 <        if(fabs(pMC->Pt()) < lPt)   continue;
83 <        lDR = pDR;
84 <        lMC = pMC;
85 <        lPt = pMC->Pt();
86 <      }
87 <      return lMC;
88 <    }
89 <    static inline Muon* match(MuonCol* iMuons,Track *iTrack) {
90 <      mithep::Muon *lMuon = 0; double lDR = 1.; double lPt = -1.;
91 <      for(unsigned int i0 = 0; i0 < iMuons->GetEntries(); i0++) {
92 <        mithep::Muon* pMuon = iMuons->At(i0);
93 <        double pDR = mithep::MathUtils::DeltaR(pMuon->Mom(),iTrack->Mom4(0.109));
94 <        if(pDR > lDR && pDR > 0.01) continue;
95 <        if(fabs(pMuon->Pt()) < lPt)   continue;
96 <        lDR   = pDR;
97 <        lMuon = pMuon;
98 <        lPt   = pMuon->Pt();
99 <      }
100 <      return lMuon;
101 <    }
102 <    static inline int NSegments(mithep::Muon *iMuon) {
103 <      int lNSegs = 0;
104 <      for(int i0 = 0; i0 < 8; i0++) {
105 <        if(iMuon->StationBit(i0)) lNSegs++;
106 <      }
107 <      return lNSegs;
108 <    }
109 <    static inline bool promptTight(int iId,Muon *iMuon) {
110 <      const mithep::Track *lTrack = 0;
111 <      if(iId == 0                              ) lTrack = iMuon->GlobalTrk();
112 <      if(iId == 1 || (iId == -1 && lTrack == 0)) lTrack = iMuon->TrackerTrk();
113 <      if(iId == 2 || (iId == -1 && lTrack == 0)) lTrack = iMuon->StandaloneTrk();
114 <      if(lTrack == 0) return 0;
115 <      if(lTrack->NHits() < 11)                                        return false;
116 <      if(lTrack->Chi2()/lTrack->Ndof() > 10.)                         return false;
117 <      if(lTrack->D0() > 0.2)                                          return false;
118 <      if((lastHit(iMuon)% 4) == 0)                                    return false;
119 <      return true;
120 <    }
121 <    static inline bool TMLastStation(Muon *iMuon,double iDYMin = 3., double iPYMin = 3.,double iDXMin = 3., double iPXMin = 3.,int iN = 2) {
122 <      if(iMuon->NSegments()       < iN)               return false; //2Last 1One
123 <      int lLast = lastStation(iMuon,-3.,-3.);                       //Last Required Station
124 <      if(lLast < 0)                                   return false;
125 <      if(iMuon->GetDX(lLast)  > 9999.)                return false;
126 <      lLast = lastStation(iMuon);                                   //No Requirements Imply StationMask (Segment and Track Arbitrated)
127 <      if(lLast < 0)                                   return false;
128 <      if(!(fabs(iMuon->GetDX(lLast))      < iDXMin  ||
129 <           fabs(iMuon->GetPullX(lLast))   < iPXMin))  return false;
130 <      if(lLast == 3) lLast = lastStation(iMuon,3);
131 <      if(lLast < 0)                                   return false;
132 <      if(!(fabs(iMuon->GetDY(lLast))      < iDYMin ||               //Old Code it was 9999
133 <           fabs(iMuon->GetPullY(lLast))   < iPYMin))  return false;
134 <      return true;
135 <    }
136 <    static inline bool TMOneStation(Muon *iMuon,double iDYMin = 3., double iPYMin = 3.,double iDXMin = 3., double iPXMin = 3.,int iN = 1) {
137 <      if(iMuon->NSegments()       < iN)               return false; //2Last 1One
138 <      bool pGoodX  = false; bool pBadY = false;
139 <      for(int i0 = 0; i0 < 8; i0++) {
140 <        if((fabs(iMuon->GetDX(i0))      < iDXMin  ||
141 <            fabs(iMuon->GetPullX(i0))   < iPXMin)) pGoodX = true;
142 <        if(pGoodX                                 &&
143 <           (fabs(iMuon->GetDY(i0))      < iDYMin  ||
144 <            fabs(iMuon->GetPullY(i0))   < iPYMin))  return true;
145 <        if(fabs(iMuon->GetDY(i0)) < 999999) pBadY = true;
146 <        if(i0 == 3 && pGoodX && !pBadY)             return true;
147 <      }
148 <      return false;
149 <    }
150 <    static inline double getCaloCompatabilitySlowly(mithep::Muon* iMuon,bool iEMSpecial, bool iCorrectedHCAL) {
151 <      //if(fpion_em_etaEmi == 0) {
152 <      std::cout << "Warning Loading Compatability Slowly" << std::endl;
153 <        TFile* lPion_templates = new TFile("MitCommon/MuonTools/data/PionCaloTemplate.root","READ");
154 <        TFile* lMuon_templates = new TFile("MitCommon/MuonTools/data/MuonCaloTemplate.root","READ");
155 <        TH2D* lpion_em_etaEmi  = (TH2D*) lPion_templates->Get("em_etaEmi");
156 <        TH2D* lpion_had_etaEmi = (TH2D*) lPion_templates->Get("had_etaEmi");
157 <        TH2D* lpion_had_etaTmi = (TH2D*) lPion_templates->Get("had_etaTmi");
158 <        TH2D* lpion_em_etaB    = (TH2D*) lPion_templates->Get("em_etaB")   ;
159 <        TH2D* lpion_had_etaB   = (TH2D*) lPion_templates->Get("had_etaB")  ;
160 <        TH2D* lpion_ho_etaB    = (TH2D*) lPion_templates->Get("ho_etaB")   ;
161 <        TH2D* lpion_had_etaTpl = (TH2D*) lPion_templates->Get("had_etaTpl");
162 <        TH2D* lpion_em_etaEpl  = (TH2D*) lPion_templates->Get("em_etaEpl") ;
163 <        TH2D* lpion_had_etaEpl = (TH2D*) lPion_templates->Get("had_etaEpl");
164 <        TH2D* lmuon_em_etaEmi  = (TH2D*) lMuon_templates->Get("em_etaEmi") ;
165 <        TH2D* lmuon_had_etaEmi = (TH2D*) lMuon_templates->Get("had_etaEmi");
166 <        TH2D* lmuon_had_etaTmi = (TH2D*) lMuon_templates->Get("had_etaTmi");
167 <        TH2D* lmuon_em_etaB    = (TH2D*) lMuon_templates->Get("em_etaB")   ;
168 <        TH2D* lmuon_had_etaB   = (TH2D*) lMuon_templates->Get("had_etaB")  ;
169 <        TH2D* lmuon_ho_etaB    = (TH2D*) lMuon_templates->Get("ho_etaB")   ;
170 <        TH2D* lmuon_had_etaTpl = (TH2D*) lMuon_templates->Get("had_etaTpl");
171 <        TH2D* lmuon_em_etaEpl  = (TH2D*) lMuon_templates->Get("em_etaEpl");
172 <        TH2D* lmuon_had_etaEpl = (TH2D*) lMuon_templates->Get("had_etaEpl");
173 <        //}
174 <        double lEta = -1.; double lP = -1;
175 <        double lEM  = -5.;      double lHad = 0;      double lHO = 0;
176 <        lEta = iMuon->Eta();
177 <        lP   = iMuon->P();
178 <        if(lP >= 2000.) lP = 1999.9;
179 <        if(!iEMSpecial || iMuon->EmEnergy() != 0.) lEM  = iMuon->EmEnergy();
180 <        lHad = iMuon->HadEnergy();
181 <        lHO  = iMuon->HoEnergy();
182 <        if(lP < 0. )           return 0.5;
183 <        if(fabs(lEta) >  2.5 ) return 0.5;
184 <        TH2D* lTMuonHad = NULL;
185 <        TH2D* lTPionHad = NULL;
186 <        TH2D* lTMuonHo  = NULL;
187 <        TH2D* lTPionHo  = NULL;
188 <        TH2D* lTMuonEm  = NULL;
189 <        TH2D* lTPionEm  = NULL;
190 <        
191 <        if(fabs(lEta) >=  1.27) {
192 <          if(iCorrectedHCAL) lHad *= 1.8/2.2;
193 <          if(lEta > 0) {
194 <            lTPionHad = lpion_had_etaEpl;
195 <            lTMuonHad = lmuon_had_etaEpl;
196 <          } else {
197 <            lTPionHad = lpion_had_etaEmi;
198 <            lTMuonHad = lmuon_had_etaEmi;
199 <          }
200 <        }
201 <        if(fabs(lEta) <  1.27  && fabs(lEta) >=  1.1 ) {
202 <          if(iCorrectedHCAL)    lHad *= (1.8/(-2.2*fabs(lEta)+5.5));
203 <          if(lEta > 0) {
204 <            lTPionHad  = lpion_had_etaTpl;
205 <            lTMuonHad  = lmuon_had_etaTpl;
206 <          } else {
207 <            lTPionHad  = lpion_had_etaTmi;
208 <            lTMuonHad  = lmuon_had_etaTmi;
209 <          }
210 <        }
211 <        if(fabs(lEta) <  1.1) {
212 <          if(iCorrectedHCAL)    lHad *= sin(2*atan(exp(iMuon->Eta())));
213 <          lTPionHad  = lpion_had_etaB;
214 <          lTMuonHad  = lmuon_had_etaB;
215 <        }
216 <        if(lEta >  1.479  ) {
217 <          lTPionEm  = lpion_em_etaEpl;
218 <          lTMuonEm  = lmuon_em_etaEpl;
219 <        }
220 <        if(fabs(lEta) <=  1.479) {
221 <          lTPionEm  = lpion_em_etaB;
222 <          lTMuonEm  = lmuon_em_etaB;
223 <        }
224 <        if(lEta < -1.479 ) {
225 <          lTPionEm  = lpion_em_etaEmi;
226 <          lTMuonEm  = lmuon_em_etaEmi;
227 <        }
228 <        if(fabs(lEta) < 1.28) {
229 <          lTPionHo  = lpion_ho_etaB;
230 <          lTMuonHo  = lmuon_ho_etaB;
231 <        }
232 <        
233 <        double lPBX = 1.;     double lPSX = 1.;
234 <        double lPBY = 1.;     double lPSY = 1.;
235 <        double lPBZ = 1.;     double lPSZ = 1.;
236 <        if(!overflow(lTPionEm, lP,lEM))  lPBX =  lTPionEm ->GetBinContent(lTPionEm ->GetXaxis()->FindBin(lP),lTPionEm ->GetYaxis()->FindBin(lEM) );
237 <        if(!overflow(lTPionHad,lP,lHad)) lPBY =  lTPionHad->GetBinContent(lTPionHad->GetXaxis()->FindBin(lP),lTPionHad->GetYaxis()->FindBin(lHad));
238 <        if(!overflow(lTPionHo, lP,lHO))  lPBZ =  lTPionHo ->GetBinContent(lTPionHo ->GetXaxis()->FindBin(lP),lTPionHo ->GetYaxis()->FindBin(lHO) );
239 <        if(!overflow(lTMuonEm, lP,lEM )) lPSX =  lTMuonEm ->GetBinContent(lTMuonEm ->GetXaxis()->FindBin(lP),lTMuonEm ->GetYaxis()->FindBin(lEM) );
240 <        if(!overflow(lTMuonHad,lP,lHad)) lPSY =  lTMuonHad->GetBinContent(lTMuonHad->GetXaxis()->FindBin(lP),lTMuonHad->GetYaxis()->FindBin(lHad));
241 <        if(!overflow(lTMuonHo ,lP,lHO))  lPSZ =  lTMuonHo ->GetBinContent(lTMuonHo ->GetXaxis()->FindBin(lP),lTMuonHo ->GetYaxis()->FindBin(lHO) );
242 <        
243 <        if(lPSX == 0. || lPBX == 0. || (lEM <= 0. && !iEMSpecial)) {lPSX = 1.; lPBX = 1.;}
244 <        if(lPSY == 0. || lPBY == 0. || lHad == 0.) {lPSY = 1.; lPBY = 1.;}
245 <        if(lPSZ == 0. || lPBZ == 0. || lHO  == 0.) {lPSZ = 1.; lPBZ = 1.;}
246 <        lPion_templates->Close();
247 <        lMuon_templates->Close();
248 <        if((lPSX*lPSY*lPSZ+lPBX*lPBY*lPBZ) > 0.) return lPSX*lPSY*lPSZ/(lPSX*lPSY*lPSZ+lPBX*lPBY*lPBZ);
249 <        return 0.5;
250 <    }
251 <    static inline float getSegmentCompatability(const mithep::Muon* iMuon) {
252 <      int lNStationsCrossed = 0;
253 <      int lNStationsSegment = 0;
254 <      
255 <      std::vector<int>   lStTrack(8);
256 <      std::vector<int>   lStSegmentmatch(8);
257 <      std::vector<int>   lStCrossed(8);
258 <      std::vector<float> lStBoundary(8);
259 <      std::vector<float> lStWeight(8);
260 <      float lWeight    = 0.;
261 <      bool  lAdjust    = true;
262 <      for(int i0 = 0; i0 < 8; i0++) {
263 <        if(iMuon->GetTrackDist(i0) < 999999. ) {
264 <          lNStationsCrossed++;
265 <          lStCrossed[i0]  = 1;
266 <          lStBoundary[i0] = 0.;
267 <          if(iMuon->GetTrackDist(i0) > -10. ) lStBoundary[i0] = iMuon->GetTrackDist(i0);
268 <        }
269 <        if(iMuon->GetDX(i0) < 999999.) { //Use iMuon->GetSegmentX--> CHECK
270 <          lNStationsSegment++;
271 <          lStSegmentmatch[i0] = 1;
272 <        }
273 <        if(iMuon->GetDY(i0) < 999999.) lAdjust = false;
274 <      }
275 <      int lPCross = -1;
276 <      const float lAtWeight = 0.5;
277 <      for(int i0 = 0; i0< 8; i0++)     {
278 <        lStWeight[i0] = 0;
279 <        if(lStCrossed[i0] > 0 )        { lPCross++;
280 <        switch ( lNStationsCrossed ) {
281 <        case 1 :
282 <          lStWeight[i0] =  1.;
283 <          break;
284 <        case 2 :
285 <          if     ( lPCross  == 0 ) lStWeight[i0] =  0.33;
286 <          else   lStWeight[i0] =  0.67;
287 <          break;
288 <        case 3 :
289 <          if     ( lPCross == 0 ) lStWeight[i0] =  0.23;
290 <          else if( lPCross == 1 ) lStWeight[i0] =  0.33;
291 <          else                    lStWeight[i0] =  0.44;
292 <          break;
293 <        case 4 :
294 <          if     ( lPCross == 0 ) lStWeight[i0] =  0.10;
295 <          else if( lPCross == 1 ) lStWeight[i0] =  0.20;
296 <          else if( lPCross == 2 ) lStWeight[i0] =  0.30;
297 <          else                    lStWeight[i0] =  0.40;
298 <          break;
299 <          
300 <        default :
301 <          lStWeight[i0] = 1./lNStationsCrossed;
302 <        }
303 <        
304 <        if(lStSegmentmatch[i0] <= 0 && lStBoundary[i0] != 0. ) {
305 <          lStWeight[i0] *= lAtWeight*0.5*(TMath::Erf(lStBoundary[i0]/6.)+1.);
306 <        } else if(lStSegmentmatch[i0] <= 0 && lStBoundary[i0] == 0) {lStWeight[i0] = 0.;}
307 <        
308 <        if( lStSegmentmatch[i0] > 0) {
309 <          double lP2X = TMath::Power(iMuon->GetPullX(i0),2.);
310 <          double lP2Y = TMath::Power(iMuon->GetPullY(i0),2.);
311 <          double lD2X = TMath::Power(iMuon->GetDX(i0),2.);
312 <          double lD2Y = TMath::Power(iMuon->GetDY(i0),2.);
313 <          if( iMuon->GetDY(i0) < 999999 && iMuon->GetDX(i0) < 999999) {
314 <            lStWeight[i0] *= sigWeight(sqrt(lD2X+lD2Y),sqrt(lP2X+lP2Y));
315 <          } else if (iMuon->GetDY(i0) >= 999999 && i0 < 4) {
316 <            lStWeight[i0] *= sigWeight(iMuon->GetDX(i0),iMuon->GetPullX(i0));
317 <          } else if(i0 < 4) {
318 <            lStWeight[i0] *= sigWeight(iMuon->GetDY(i0),iMuon->GetPullY(i0));
319 <          }
320 <        }
321 <        }
322 <        lWeight += lStWeight[i0];
323 <      }
324 <      if(lNStationsCrossed == 0) lWeight = 0.5;
325 <      return lWeight;
326 <    }
327 <    static inline bool isGoodMuon(mithep::Muon *iMuon,selection iSelection) {
328 <      double lVal = 0;
329 <      switch(iSelection) {
330 <      case AllArbitrated:
331 <        if(iMuon->StandaloneTrk() != 0 || iMuon->GlobalTrk()!= 0)  return true;
332 <        if(iMuon->NSegments() > 0) return true;
333 <        return false;
334 <        break;
335 <      case PromptTight:
336 <        return promptTight(-1,iMuon);
337 <        break;
338 <      case TMOneStationLoose:
339 <        return TMOneStation(iMuon,99999,999999);
340 <      case TMOneStationTight:
341 <        return TMOneStation(iMuon);
342 <      case TMLastStationLoose:
343 <        return TMLastStation(iMuon,999999,999999);
344 <        break;
345 <      case TMLastStationTight:
346 <        return TMLastStation(iMuon);
347 <        break;
348 <      case TM2DCompatibilityLoose:
349 <        lVal             = 1.2*getSegmentCompatability(iMuon);
350 <        if(lVal/1.2 == 0.5) return false;
351 <        //if(fClass ) lVal += 0.8*getCaloCompatability(iMuon,true,true);
352 <        lVal += 0.8*getCaloCompatabilitySlowly(iMuon,true,true);
353 <        if(lVal > 0.7) return true;
354 <        return false;
355 <        break;
356 <      case TM2DCompatibilityTight:
357 <        lVal             = 1.2*getSegmentCompatability(iMuon);
358 <        if(lVal/1.2 == 0.5) return false;
359 <        //if(fClass ) lVal += 0.8*getCaloCompatability(iMuon,true,true);
360 <        lVal += 0.8*getCaloCompatabilitySlowly(iMuon,true,true);
361 <        if(lVal > 1.0) return true;
362 <        return false;
363 <        break;
364 <      default:
365 <        return false;
366 <      }
367 <      return false;
368 <    }
369 <    bool isGood(mithep::Muon *iMuon,selection iSelection);
370 <  private:
371 <    TFile *fMuon_templates;
372 <    TFile *fPion_templates;
373 <    TH2D* fpion_em_etaEmi;
374 <    TH2D* fpion_had_etaEmi;
375 <    TH2D* fpion_had_etaTmi;
376 <    TH2D* fpion_em_etaB;
377 <    TH2D* fpion_had_etaB;
378 <    TH2D* fpion_ho_etaB;
379 <    TH2D* fpion_had_etaTpl;
380 <    TH2D* fpion_em_etaEpl;
381 <    TH2D* fpion_had_etaEpl;
382 <    TH2D* fmuon_em_etaEmi;
383 <    TH2D* fmuon_had_etaEmi;
384 <    TH2D* fmuon_had_etaTmi;
385 <    TH2D* fmuon_em_etaB;
386 <    TH2D* fmuon_had_etaB;
387 <    TH2D* fmuon_ho_etaB;
388 <    TH2D* fmuon_had_etaTpl;
389 <    TH2D* fmuon_em_etaEpl;
390 <    TH2D* fmuon_had_etaEpl;
29 >    public:
30 >      MuonTools(const char *mutemp="$CMSSW_BASE/src/MitPhysics/data/MuonCaloTemplate.root",
31 >                const char *pitemp="$CMSSW_BASE/src/MitPhysics/data/PionCaloTemplate.root");
32 >      virtual ~MuonTools();
33 >
34 >      enum ESelType {
35 >        kAllArbitrated,          //All arbitration (DT/CSC/RPC Hits) put on at least one
36 >                                 //  segments given a global Muon
37 >        kPromptTight,            //Standard global muon identification
38 >        kTMLastStationLoose,     //Loose matching requirements on lastmost muon station of reco
39 >        kTMLastStationTight,     //Tight matching requirements on lastmost muon station of reco
40 >        kTMOneStationLoose,      //Loose matching requirements on at least one muon station of reco
41 >        kTMOneStationTight,      //Tight matching requirements on at least one muon station of reco
42 >        kTM2DCompatibilityLoose, //Loose requirement on sum of compatabiliity variables
43 >                                 //  ===> 1.2 Segment compatability + 0.8 calo compatability > 0.8
44 >        kTM2DCompatibilityTight  //Tight requirement on sum of compatabiliity variables
45 >                                 //  ===> 1.2 Segment compatability + 0.8 calo compatability > 1.2
46 >      };
47 >
48 >      Bool_t        Init(const char *mutemp, const char *pitemp);
49 >      Bool_t        IsGood(const mithep::Muon *iMuon, ESelType iSel) const;
50 >      Double_t      GetCaloCompatability(const mithep::Muon *iMuon,
51 >                                         Bool_t iEMSpecial, Bool_t iCorrectedHCAL) const;
52 >      Double_t      GetSegmentCompatability(const mithep::Muon *iMuon)             const;
53 >      static Bool_t PassD0Cut(const Muon *mu, const VertexCol *vertices, Double_t fD0Cut, Int_t nVertex = 0);
54 >      static Bool_t PassD0Cut(const Muon *mu, const BeamSpotCol *beamspots, Double_t fD0Cut);
55 >      static Bool_t PassDZCut(const Muon *mu, const VertexCol *vertices, Double_t fDZCut, Int_t nVertex = 0);
56 >      static Bool_t PassSoftMuonCut(const Muon *mu, const VertexCol *vertices, const Double_t fDZCut = 0.2);
57 >
58 >    protected:
59 >      void        DeleteHistos();
60 >      Bool_t      Overflow(const TH2D *iHist, Double_t lVal0, Double_t lVal1)    const;
61 >      Double_t    SigWeight(Double_t iVal0, Double_t iVal1)                      const;
62 >  
63 >    private:
64 >      Bool_t      fIsInit;              //!=true if histograms are loaded
65 >      TH2D       *fmuon_em_etaEmi;      //!Neg Endcap EM       Calo Deposit Template for Muons
66 >      TH2D       *fmuon_had_etaEmi;     //!Neg Endcap Hadronic Calo Deposit Template for Muons
67 >      TH2D       *fmuon_had_etaTmi;     //!Neg Transition Hadronic Calo Deposit Template for Muons
68 >      TH2D       *fmuon_em_etaB;        //!Barrel EM       Calo Deposit Template for Muons
69 >      TH2D       *fmuon_had_etaB;       //!Barrel Hadronic Calo Deposit Template for Muons
70 >      TH2D       *fmuon_ho_etaB;        //!Barrel HO       Calo Deposit Template for Muons
71 >      TH2D       *fmuon_had_etaTpl;     //!Plus Transition Hadronic Calo Deposit Template for Muons
72 >      TH2D       *fmuon_em_etaEpl;      //!Plus Endcap EM       Calo Deposit Template for Muons
73 >      TH2D       *fmuon_had_etaEpl;     //!Plus Endcap Hadronic Calo Deposit Template for Muons
74 >      TH2D       *fpion_em_etaEmi;      //!Neg  Endcap EM       Calo Deposit Template for Pions
75 >      TH2D       *fpion_had_etaEmi;     //!Neg  Endcap Hadronic Calo Deposit Template for Pions
76 >      TH2D       *fpion_had_etaTmi;     //!Neg Transition Hadronic Calo Deposit Template for Pions
77 >      TH2D       *fpion_em_etaB;        //!Barrel EM       Calo Deposit Template for Pions
78 >      TH2D       *fpion_had_etaB;       //!Barrel Hadronic Calo Deposit Template for Pions
79 >      TH2D       *fpion_ho_etaB;        //!Barrel HO       Calo Deposit Template for Pions
80 >      TH2D       *fpion_had_etaTpl;     //!Plus Transition Hadronic Calo Deposit Template for Pions
81 >      TH2D       *fpion_em_etaEpl;      //!Plus Endcap EM       Calo Deposit Template for Pions
82 >      TH2D       *fpion_had_etaEpl;     //!Plus Endcap Hadronic Calo Deposit Template for Pions
83 >
84 >      TH2D       *LoadHisto(const char *fname, TFile *file)                      const;
85 >
86 >    ClassDef(MuonTools, 0) // Muon tools
87    };
88   }
89  
90 + //--------------------------------------------------------------------------------------------------
91 + inline Double_t mithep::MuonTools::SigWeight(Double_t iVal0, Double_t iVal1) const
92 + {
93 +  // Returns weighted uncertainty given segment matching uncertainty (iVal0) and
94 +  // segment matching pull (iVal1).
95 +
96 +  if (iVal1 < 1.)  //if pull defined and within range
97 +    return 1.;
98 +  if (iVal0 < 3. && iVal1 > 3.) {       //if pull not well defined and uncertainty defined
99 +    Double_t lVal = TMath::Max(iVal0,1.);
100 +    return 1./TMath::Power(lVal,0.25);
101 +  }
102 +
103 +  Double_t lVal = TMath::Max(iVal1,1.); //if pull > 1 and pull < 3 return 1/pull^4
104 +  return 1./TMath::Power(lVal,0.25);
105 + }
106 + //--------------------------------------------------------------------------------------------------
107 + inline Bool_t mithep::MuonTools::Overflow(const TH2D *iHist, Double_t lVal0, Double_t lVal1) const
108 + {
109 +  // Check if values are in overflow bins of given histogram.
110 +
111 +  if(iHist == 0)
112 +    return kTRUE;
113 +
114 +  if (iHist ->GetXaxis()->FindBin(lVal0) == 0                  ||
115 +      iHist ->GetXaxis()->FindBin(lVal0) >  iHist->GetNbinsX() ||
116 +      iHist ->GetYaxis()->FindBin(lVal1) == 0                  ||
117 +      iHist ->GetYaxis()->FindBin(lVal1) >  iHist->GetNbinsY()) {
118 +    return kTRUE;
119 +  }
120 +  return kFALSE;
121 + }
122   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines