Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-21 23:59:02

0001 #!/bin/env python
0002 #
0003 # PyROOT study of standard selector performance using sim-hit matching 
0004 # to identify fake and signal muons
0005 #
0006 import os, re, ROOT, sys, pickle, time
0007 from pprint import pprint
0008 from math import *
0009 from array import array
0010 from DataFormats.FWLite import Events, Handle
0011 import numpy as np
0012 
0013 
0014 ##
0015 ## User Input
0016 ##
0017 def getPFNs(lfns):
0018     files = []
0019     for file in lfns:
0020         fullpath = "/eos/cms/" + file
0021         if os.path.exists(fullpath):
0022             files.append(fullpath)
0023         else:
0024             raise Exception("File not found: %s" % fullpath)
0025     return files
0026 
0027 
0028 def IsMatched(muon1,muon2,sharedFrac=0.5):
0029     # first check if muon share Wh/Se/St 
0030     if (muon1.whNum()!=muon2.whNum()): return False 
0031     if (muon1.scNum()!=muon2.scNum()): return False 
0032     if (muon1.stNum()!=muon2.stNum()): return False     
0033     
0034     # now count the number of shared hits: 
0035     numShared=0.
0036     totMuon1=0.
0037     for ly in range(0,7):
0038         if (muon1.pathWireId(ly)>=0): 
0039             totMuon1=totMuon1+1. 
0040         else:                         
0041             continue
0042 
0043         if (muon1.pathWireId(ly)!=muon2.pathWireId(ly)): continue
0044         if (muon1.pathTDC(ly)!=muon2.pathTDC(ly)): continue
0045         
0046         numShared = numShared+1.
0047 
0048     if (numShared/totMuon1 >= sharedFrac): return True
0049 
0050     return False
0051 
0052 muoBayesHandle, muoBayesLabel = Handle("L1Phase2MuDTExtPhContainer"), ("dtTriggerPhase2BayesPrimitiveDigis","","L1DTTrigPhase2Prod")
0053 muoStdHandle, muoStdLabel = Handle("L1Phase2MuDTExtPhContainer"), ("dtTriggerPhase2StdPrimitiveDigis","","L1DTTrigPhase2Prod")
0054 genHandle, genLabel = Handle("vector<reco::GenParticle>"), "genParticles"
0055 
0056 
0057 ROOT.gROOT.SetBatch(True)
0058 
0059 ##
0060 ## Main part
0061 ##
0062 files = ['../../../../DTTriggerPhase2Primitives.root']
0063 
0064 print "Number of files: %d" % len(files)
0065 
0066 events = Events(files)
0067 
0068 ## load some histograms (and efficiencies): 
0069 outputDict = {} 
0070 dumpToFile = True
0071 
0072 for frac in [0.25,0.5,0.75,1.00]:
0073     
0074     it = 0
0075 
0076     fracname="shared%i" %(frac*100)
0077     
0078     # Inclusive in MB
0079     hPhiRes_q1  = []
0080     hPhiRes_q3  = []
0081     hPhiRes_q5  = []
0082     hPhiRes_q8  = []
0083     
0084     hPhiBRes_q1 = []
0085     hPhiBRes_q3 = []
0086     hPhiBRes_q5 = []
0087     hPhiBRes_q8 = []
0088     
0089     hChi2Res_q1 = []
0090     hChi2Res_q3 = []
0091     hChi2Res_q5 = []
0092     hChi2Res_q8 = []
0093     
0094     hBxRes_q1 = []
0095     hBxRes_q3 = []
0096     hBxRes_q5 = []
0097     hBxRes_q8 = []
0098     
0099     hTimeRes_q1 = []
0100     hTimeRes_q3 = []
0101     hTimeRes_q5 = []
0102     hTimeRes_q8 = []
0103 
0104     hMatchingEff = []
0105 
0106 
0107     # Exclusive in MB
0108     hPhiRes_MB_q1  = []
0109     hPhiRes_MB_q3  = []
0110     hPhiRes_MB_q5  = []
0111     hPhiRes_MB_q8  = []
0112     
0113     hPhiBRes_MB_q1 = []
0114     hPhiBRes_MB_q3 = []
0115     hPhiBRes_MB_q5 = []
0116     hPhiBRes_MB_q8 = []
0117     
0118     hChi2Res_MB_q1 = []
0119     hChi2Res_MB_q3 = []
0120     hChi2Res_MB_q5 = []
0121     hChi2Res_MB_q8 = []
0122     
0123     hBxRes_MB_q1 = []
0124     hBxRes_MB_q3 = []
0125     hBxRes_MB_q5 = []
0126     hBxRes_MB_q8 = []
0127     
0128     hTimeRes_MB_q1 = []
0129     hTimeRes_MB_q3 = []
0130     hTimeRes_MB_q5 = []
0131     hTimeRes_MB_q8 = []
0132 
0133     hMatchingEff_MB = []
0134 
0135     # Split into 4 MB (1, 2, 3, 4)
0136     for st in range(1,5):    
0137         hMatchingEff.append(ROOT.TEfficiency("hMatchingEff_MB%i_%s" %(st,fracname), "",9,0.5,9.5))
0138 
0139         hPhiRes_q1.append(ROOT.TH1F("hPhiRes_MB%i_q1_%s" %(st,fracname),"",20,-5000,5000.))
0140         hPhiRes_q3.append(ROOT.TH1F("hPhiRes_MB%i_q3_%s" %(st,fracname),"",20,-5000,5000.))
0141         hPhiRes_q5.append(ROOT.TH1F("hPhiRes_MB%i_q5_%s" %(st,fracname),"",20,-5000,5000.))
0142         hPhiRes_q8.append(ROOT.TH1F("hPhiRes_MB%i_q8_%s" %(st,fracname),"",20,-5000,5000.))
0143         
0144         hPhiBRes_q1.append(ROOT.TH1F("hPhiBRes_MB%i_q1_%s" %(st,fracname),"",20,-100,100.))
0145         hPhiBRes_q3.append(ROOT.TH1F("hPhiBRes_MB%i_q3_%s" %(st,fracname),"",20,-100,100.))
0146         hPhiBRes_q5.append(ROOT.TH1F("hPhiBRes_MB%i_q5_%s" %(st,fracname),"",20,-100,100.))
0147         hPhiBRes_q8.append(ROOT.TH1F("hPhiBRes_MB%i_q8_%s" %(st,fracname),"",20,-100,100.))
0148         
0149         hChi2Res_q1.append(ROOT.TH1F("hChi2Res_MB%i_q1_%s" %(st,fracname),"",20,-5000,5000.))
0150         hChi2Res_q3.append(ROOT.TH1F("hChi2Res_MB%i_q3_%s" %(st,fracname),"",20,-5000,5000.))
0151         hChi2Res_q5.append(ROOT.TH1F("hChi2Res_MB%i_q5_%s" %(st,fracname),"",20,-5000,5000.))
0152         hChi2Res_q8.append(ROOT.TH1F("hChi2Res_MB%i_q8_%s" %(st,fracname),"",20,-5000,5000.))
0153             
0154         hBxRes_q1.append(ROOT.TH1F("hBxRes_MB%i_q1_%s" %(st,fracname),"",20,-10,10.))
0155         hBxRes_q3.append(ROOT.TH1F("hBxRes_MB%i_q3_%s" %(st,fracname),"",20,-10,10.))
0156         hBxRes_q5.append(ROOT.TH1F("hBxRes_MB%i_q5_%s" %(st,fracname),"",20,-10,10.))
0157         hBxRes_q8.append(ROOT.TH1F("hBxRes_MB%i_q8_%s" %(st,fracname),"",20,-10,10.))
0158         
0159         hTimeRes_q1.append(ROOT.TH1F("hTimeRes_MB%i_q1_%s" %(st,fracname),"",20,-100,100.))
0160         hTimeRes_q3.append(ROOT.TH1F("hTimeRes_MB%i_q3_%s" %(st,fracname),"",20,-100,100.))
0161         hTimeRes_q5.append(ROOT.TH1F("hTimeRes_MB%i_q5_%s" %(st,fracname),"",20,-100,100.))
0162         hTimeRes_q8.append(ROOT.TH1F("hTimeRes_MB%i_q8_%s" %(st,fracname),"",20,-100,100.))
0163     
0164         # Split into 5 wheels (-2, -1, 0, 1, 2)
0165         for wh in range(-2,3):
0166             hMatchingEff_MB.append(ROOT.TEfficiency("hMatchingEff_MB%i_Wh%i_%s" %(st, wh, fracname), "", 9, 0.5, 9.5))
0167 
0168             hPhiRes_MB_q1.append(ROOT.TH1F("hPhiRes_MB_MB%i_MB_Wh%i_MB_q1_MB_%s"   %(st, wh, fracname), "", 20, -5000, 5000.))
0169             hPhiRes_MB_q3.append(ROOT.TH1F("hPhiRes_MB_MB%i_MB_Wh%i_MB_q3_MB_%s"   %(st, wh, fracname), "", 20, -5000, 5000.))
0170             hPhiRes_MB_q5.append(ROOT.TH1F("hPhiRes_MB_MB%i_MB_Wh%i_MB_q5_MB_%s"   %(st, wh, fracname), "", 20, -5000, 5000.))
0171             hPhiRes_MB_q8.append(ROOT.TH1F("hPhiRes_MB_MB%i_MB_Wh%i_MB_q8_MB_%s"   %(st, wh, fracname), "", 20, -5000, 5000.))
0172         
0173             hPhiBRes_MB_q1.append(ROOT.TH1F("hPhiBRes_MB_MB%i_MB_Wh%i_MB_q1_MB_%s" %(st, wh, fracname), "", 20, -100, 100.))
0174             hPhiBRes_MB_q3.append(ROOT.TH1F("hPhiBRes_MB_MB%i_MB_Wh%i_MB_q3_MB_%s" %(st, wh, fracname), "", 20, -100, 100.))
0175             hPhiBRes_MB_q5.append(ROOT.TH1F("hPhiBRes_MB_MB%i_MB_Wh%i_MB_q5_MB_%s" %(st, wh, fracname), "", 20, -100, 100.))
0176             hPhiBRes_MB_q8.append(ROOT.TH1F("hPhiBRes_MB_MB%i_MB_Wh%i_MB_q8_MB_%s" %(st, wh, fracname), "", 20, -100, 100.))
0177         
0178             hChi2Res_MB_q1.append(ROOT.TH1F("hChi2Res_MB_MB%i_MB_Wh%i_MB_q1_MB_%s" %(st, wh, fracname), "", 20, -5000, 5000.))
0179             hChi2Res_MB_q3.append(ROOT.TH1F("hChi2Res_MB_MB%i_MB_Wh%i_MB_q3_MB_%s" %(st, wh, fracname), "", 20, -5000, 5000.))
0180             hChi2Res_MB_q5.append(ROOT.TH1F("hChi2Res_MB_MB%i_MB_Wh%i_MB_q5_MB_%s" %(st, wh, fracname), "", 20, -5000, 5000.))
0181             hChi2Res_MB_q8.append(ROOT.TH1F("hChi2Res_MB_MB%i_MB_Wh%i_MB_q8_MB_%s" %(st, wh, fracname), "", 20, -5000, 5000.))
0182             
0183             hBxRes_MB_q1.append(ROOT.TH1F("hBxRes_MB_MB%i_MB_Wh%i_MB_q1_MB_%s"     %(st, wh, fracname), "", 20, -10, 10.))
0184             hBxRes_MB_q3.append(ROOT.TH1F("hBxRes_MB_MB%i_MB_Wh%i_MB_q3_MB_%s"     %(st, wh, fracname), "", 20, -10, 10.))
0185             hBxRes_MB_q5.append(ROOT.TH1F("hBxRes_MB_MB%i_MB_Wh%i_MB_q5_MB_%s"     %(st, wh, fracname), "", 20, -10, 10.))
0186             hBxRes_MB_q8.append(ROOT.TH1F("hBxRes_MB_MB%i_MB_Wh%i_MB_q8_MB_%s"     %(st, wh, fracname), "", 20, -10, 10.))
0187         
0188             hTimeRes_MB_q1.append(ROOT.TH1F("hTimeRes_MB_MB%i_MB_Wh%i_MB_q1_MB_%s" %(st, wh, fracname), "", 20, -100, 100.))
0189             hTimeRes_MB_q3.append(ROOT.TH1F("hTimeRes_MB_MB%i_MB_Wh%i_MB_q3_MB_%s" %(st, wh, fracname), "", 20, -100, 100.))
0190             hTimeRes_MB_q5.append(ROOT.TH1F("hTimeRes_MB_MB%i_MB_Wh%i_MB_q5_MB_%s" %(st, wh, fracname), "", 20, -100, 100.))
0191             hTimeRes_MB_q8.append(ROOT.TH1F("hTimeRes_MB_MB%i_MB_Wh%i_MB_q8_MB_%s" %(st, wh, fracname), "", 20, -100, 100.))
0192 
0193 
0194     print "now save into dictionary"
0195     outputDict[fracname] = {}
0196     for st in range(1,5):
0197         outputDict[fracname]['hMatchingEff_MB%i'%st] = hMatchingEff[st-1]
0198 
0199         outputDict[fracname]['hPhiRes_MB%i_q1'%st] = hPhiRes_q1[st-1]
0200         outputDict[fracname]['hPhiRes_MB%i_q3'%st] = hPhiRes_q3[st-1]
0201         outputDict[fracname]['hPhiRes_MB%i_q5'%st] = hPhiRes_q5[st-1]
0202         outputDict[fracname]['hPhiRes_MB%i_q8'%st] = hPhiRes_q8[st-1]       
0203 
0204         outputDict[fracname]['hPhiBRes_MB%i_q1'%st] = hPhiBRes_q1[st-1]
0205         outputDict[fracname]['hPhiBRes_MB%i_q3'%st] = hPhiBRes_q3[st-1]
0206         outputDict[fracname]['hPhiBRes_MB%i_q5'%st] = hPhiBRes_q5[st-1]
0207         outputDict[fracname]['hPhiBRes_MB%i_q8'%st] = hPhiBRes_q8[st-1]
0208     
0209         outputDict[fracname]['hChi2Res_MB%i_q1'%st] = hChi2Res_q1[st-1]
0210         outputDict[fracname]['hChi2Res_MB%i_q3'%st] = hChi2Res_q3[st-1]
0211         outputDict[fracname]['hChi2Res_MB%i_q5'%st] = hChi2Res_q5[st-1]
0212         outputDict[fracname]['hChi2Res_MB%i_q8'%st] = hChi2Res_q8[st-1]       
0213 
0214         outputDict[fracname]['hBxRes_MB%i_q1'%st] = hBxRes_q1[st-1]
0215         outputDict[fracname]['hBxRes_MB%i_q3'%st] = hBxRes_q3[st-1]
0216         outputDict[fracname]['hBxRes_MB%i_q5'%st] = hBxRes_q5[st-1]
0217         outputDict[fracname]['hBxRes_MB%i_q8'%st] = hBxRes_q8[st-1]       
0218 
0219         outputDict[fracname]['hTimeRes_MB%i_q1'%st] = hTimeRes_q1[st-1]
0220         outputDict[fracname]['hTimeRes_MB%i_q3'%st] = hTimeRes_q3[st-1]
0221         outputDict[fracname]['hTimeRes_MB%i_q5'%st] = hTimeRes_q5[st-1]
0222         outputDict[fracname]['hTimeRes_MB%i_q8'%st] = hTimeRes_q8[st-1]       
0223 
0224         for wh in range(-2,3):
0225 
0226             it = it + 1
0227             print("MB = {}, Wheel = {}, iteration = {}".format(st, wh, it))
0228 
0229             outputDict[fracname]['hMatchingEff_MB%i_Wh%i'%(st, wh)] = hMatchingEff_MB[wh+2 + 5*(st-1)]
0230 
0231             outputDict[fracname]['hPhiRes_MB%i_Wh%i_q1'%(st, wh)]  = hPhiRes_MB_q1[wh+2 + 5*(st-1)]
0232             outputDict[fracname]['hPhiRes_MB%i_Wh%i_q3'%(st, wh)]  = hPhiRes_MB_q3[wh+2 + 5*(st-1)]
0233             outputDict[fracname]['hPhiRes_MB%i_Wh%i_q5'%(st, wh)]  = hPhiRes_MB_q5[wh+2 + 5*(st-1)]
0234             outputDict[fracname]['hPhiRes_MB%i_Wh%i_q8'%(st, wh)]  = hPhiRes_MB_q8[wh+2 + 5*(st-1)]       
0235 
0236             outputDict[fracname]['hPhiBRes_MB%i_Wh%i_q1'%(st, wh)] = hPhiBRes_MB_q1[wh+2 + 5*(st-1)]
0237             outputDict[fracname]['hPhiBRes_MB%i_Wh%i_q3'%(st, wh)] = hPhiBRes_MB_q3[wh+2 + 5*(st-1)]
0238             outputDict[fracname]['hPhiBRes_MB%i_Wh%i_q5'%(st, wh)] = hPhiBRes_MB_q5[wh+2 + 5*(st-1)]
0239             outputDict[fracname]['hPhiBRes_MB%i_Wh%i_q8'%(st, wh)] = hPhiBRes_MB_q8[wh+2 + 5*(st-1)]
0240     
0241             outputDict[fracname]['hChi2Res_MB%i_Wh%i_q1'%(st, wh)] = hChi2Res_MB_q1[wh+2 + 5*(st-1)]
0242             outputDict[fracname]['hChi2Res_MB%i_Wh%i_q3'%(st, wh)] = hChi2Res_MB_q3[wh+2 + 5*(st-1)]
0243             outputDict[fracname]['hChi2Res_MB%i_Wh%i_q5'%(st, wh)] = hChi2Res_MB_q5[wh+2 + 5*(st-1)]
0244             outputDict[fracname]['hChi2Res_MB%i_Wh%i_q8'%(st, wh)] = hChi2Res_MB_q8[wh+2 + 5*(st-1)]       
0245 
0246             outputDict[fracname]['hBxRes_MB%i_Wh%i_q1'%(st, wh)]   = hBxRes_MB_q1[wh+2 + 5*(st-1)]
0247             outputDict[fracname]['hBxRes_MB%i_Wh%i_q3'%(st, wh)]   = hBxRes_MB_q3[wh+2 + 5*(st-1)]
0248             outputDict[fracname]['hBxRes_MB%i_Wh%i_q5'%(st, wh)]   = hBxRes_MB_q5[wh+2 + 5*(st-1)]
0249             outputDict[fracname]['hBxRes_MB%i_Wh%i_q8'%(st, wh)]   = hBxRes_MB_q8[wh+2 + 5*(st-1)]       
0250 
0251             outputDict[fracname]['hTimeRes_MB%i_Wh%i_q1'%(st, wh)] = hTimeRes_MB_q1[wh+2 + 5*(st-1)]
0252             outputDict[fracname]['hTimeRes_MB%i_Wh%i_q3'%(st, wh)] = hTimeRes_MB_q3[wh+2 + 5*(st-1)]
0253             outputDict[fracname]['hTimeRes_MB%i_Wh%i_q5'%(st, wh)] = hTimeRes_MB_q5[wh+2 + 5*(st-1)]
0254             outputDict[fracname]['hTimeRes_MB%i_Wh%i_q8'%(st, wh)] = hTimeRes_MB_q8[wh+2 + 5*(st-1)]       
0255 
0256     # loop over events
0257     count = 0
0258 
0259     if (dumpToFile): 
0260         f= open("EventDumpList_StdToBayes.log","w+")
0261 
0262     for ev in events:
0263         if not count%1000:  print count, events.size()
0264         count = count+1
0265         
0266         ev.getByLabel(muoBayesLabel, muoBayesHandle)
0267         ev.getByLabel(muoStdLabel, muoStdHandle)
0268         ev.getByLabel(genLabel, genHandle)
0269 
0270         muon_bayes = muoBayesHandle.product().getContainer()
0271         muon_std = muoStdHandle.product().getContainer()
0272     
0273         if (dumpToFile):
0274             f.write( "\nInspecting Event Number %i \n" %(ev.eventAuxiliary().id().event())  )
0275             f.write( "        Wh   Se   St  | w1 w2 w3 w4 w5 w6 w7 w8 |  tdc1  tdc2  tdc3  tdc4  tdc5  tdc6  tdc7  tdc8 | lat1 lat2 lat3 lat4 lat5 lat6 lat7 lat8 | Q     phi  phib  phi_cmssw  phib_cmssw  bX      Chi2         x tanPsi     t0 \n" )
0276             f.write( "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \n" )
0277             for muon in muon_bayes:
0278                 f.write( "[Bayes]: Wh%2d Se%2d St%1d | %2d %2d %2d %2d %2d %2d %2d %2d | %5d %5d %5d %5d %5d %5d %5d %5d |  %2d   %2d   %2d   %2d   %2d   %2d   %2d   %2d | Q%1d %6d %5d     %6d       %5d %3d %9d %9d %6d %6d\n" %(muon.whNum(),muon.scNum(),muon.stNum(),muon.pathWireId(0),muon.pathWireId(1),muon.pathWireId(2),muon.pathWireId(3),muon.pathWireId(4),muon.pathWireId(5),muon.pathWireId(6),muon.pathWireId(7),muon.pathTDC(0),muon.pathTDC(1),muon.pathTDC(2),muon.pathTDC(3),muon.pathTDC(4),muon.pathTDC(5),muon.pathTDC(6),muon.pathTDC(7),muon.pathLat(0),muon.pathLat(1),muon.pathLat(2),muon.pathLat(3),muon.pathLat(4),muon.pathLat(5),muon.pathLat(6),muon.pathLat(7),muon.quality(),muon.phi(),muon.phiBend(),muon.phiCMSSW(),muon.phiBendCMSSW(),muon.bxNum()-20,muon.chi2(), muon.xLocal(), muon.tanPsi(), muon.t0() ) )
0279         
0280 
0281         for muon in muon_std:
0282             if (dumpToFile): 
0283                 f.write( "[Std  ]: Wh%2d Se%2d St%1d | %2d %2d %2d %2d %2d %2d %2d %2d | %5d %5d %5d %5d %5d %5d %5d %5d |  %2d   %2d   %2d   %2d   %2d   %2d   %2d   %2d | Q%1d %6d %5d     %6d       %5d %3d %9d %9d %6d %6d\n" %(muon.whNum(),muon.scNum(),muon.stNum(),muon.pathWireId(0),muon.pathWireId(1),muon.pathWireId(2),muon.pathWireId(3),muon.pathWireId(4),muon.pathWireId(5),muon.pathWireId(6),muon.pathWireId(7),muon.pathTDC(0),muon.pathTDC(1),muon.pathTDC(2),muon.pathTDC(3),muon.pathTDC(4),muon.pathTDC(5),muon.pathTDC(6),muon.pathTDC(7),muon.pathLat(0),muon.pathLat(1),muon.pathLat(2),muon.pathLat(3),muon.pathLat(4),muon.pathLat(5),muon.pathLat(6),muon.pathLat(7),muon.quality(),muon.phi(),muon.phiBend(),muon.phiCMSSW(),muon.phiBendCMSSW(),muon.bxNum()-20,muon.chi2(), muon.xLocal(), muon.tanPsi(), muon.t0() ) )
0284             ## now match with the previous 
0285             st = muon.stNum()-1
0286             wh = muon.whNum()+2
0287             matched = False
0288             for muon2 in muon_bayes: 
0289                 matched = matched or IsMatched(muon,muon2,frac)
0290                 if not IsMatched(muon,muon2,frac): continue
0291 
0292                 if (muon.quality()>=1) :  
0293                     # Inclusive in MB
0294                     hPhiRes_q1[st]  .Fill( (muon.phi()-muon2.phi()) )
0295                     hPhiBRes_q1[st] .Fill( (muon.phiBend()-muon2.phiBend()) )
0296                     hChi2Res_q1[st] .Fill( (muon.chi2()-muon2.chi2()) )
0297                     hBxRes_q1[st]   .Fill( (muon.bxNum()-muon2.bxNum()) )
0298                     hTimeRes_q1[st] .Fill( (muon.t0()-muon2.t0()) )
0299 
0300                     # Exclusive in MB
0301                     hPhiRes_MB_q1[5*st + wh]  .Fill( (muon.phi()-muon2.phi()) )
0302                     hPhiBRes_MB_q1[5*st + wh] .Fill( (muon.phiBend()-muon2.phiBend()) )
0303                     hChi2Res_MB_q1[5*st + wh] .Fill( (muon.chi2()-muon2.chi2()) )
0304                     hBxRes_MB_q1[5*st + wh]   .Fill( (muon.bxNum()-muon2.bxNum()) )
0305                     hTimeRes_MB_q1[5*st + wh] .Fill( (muon.t0()-muon2.t0()) )
0306                     
0307                 if (muon.quality()>=3) :
0308                     # Inclusive in MB
0309                     hPhiRes_q3[st]  .Fill( (muon.phi()-muon2.phi()) )
0310                     hPhiBRes_q3[st] .Fill( (muon.phiBend()-muon2.phiBend()) )
0311                     hChi2Res_q3[st] .Fill( (muon.chi2()-muon2.chi2()) )
0312                     hBxRes_q3[st]   .Fill( (muon.bxNum()-muon2.bxNum()) )
0313                     hTimeRes_q3[st] .Fill( (muon.t0()-muon2.t0()) )
0314 
0315                     # Exclusive in MB
0316                     hPhiRes_MB_q3[5*st + wh]  .Fill( (muon.phi()-muon2.phi()) )
0317                     hPhiBRes_MB_q3[5*st + wh] .Fill( (muon.phiBend()-muon2.phiBend()) )
0318                     hChi2Res_MB_q3[5*st + wh] .Fill( (muon.chi2()-muon2.chi2()) )
0319                     hBxRes_MB_q3[5*st + wh]   .Fill( (muon.bxNum()-muon2.bxNum()) )
0320                     hTimeRes_MB_q3[5*st + wh] .Fill( (muon.t0()-muon2.t0()) )
0321 
0322                 if (muon.quality()>=5) :
0323                     # Inclusive in MB
0324                     hPhiRes_q5[st]  .Fill( (muon.phi()-muon2.phi()) )
0325                     hPhiBRes_q5[st] .Fill( (muon.phiBend()-muon2.phiBend()) )
0326                     hChi2Res_q5[st] .Fill( (muon.chi2()-muon2.chi2()) )
0327                     hBxRes_q5[st]   .Fill( (muon.bxNum()-muon2.bxNum()) )
0328                     hTimeRes_q5[st] .Fill( (muon.t0()-muon2.t0()) )
0329 
0330                     # Exclusive in MB
0331                     hPhiRes_MB_q5[5*st + wh]  .Fill( (muon.phi()-muon2.phi()) )
0332                     hPhiBRes_MB_q5[5*st + wh] .Fill( (muon.phiBend()-muon2.phiBend()) )
0333                     hChi2Res_MB_q5[5*st + wh] .Fill( (muon.chi2()-muon2.chi2()) )
0334                     hBxRes_MB_q5[5*st + wh]   .Fill( (muon.bxNum()-muon2.bxNum()) )
0335                     hTimeRes_MB_q5[5*st + wh] .Fill( (muon.t0()-muon2.t0()) )
0336                
0337                 if (muon.quality()>=8) :
0338                     # Inclusive in MB
0339                     hPhiRes_q8[st]  .Fill( (muon.phi()-muon2.phi()) )
0340                     hPhiBRes_q8[st] .Fill( (muon.phiBend()-muon2.phiBend()) )
0341                     hChi2Res_q8[st] .Fill( (muon.chi2()-muon2.chi2()) )
0342                     hBxRes_q8[st]   .Fill( (muon.bxNum()-muon2.bxNum()) )
0343                     hTimeRes_q8[st] .Fill( (muon.t0()-muon2.t0()) )
0344 
0345                     # Exclusive in MB
0346                     hPhiRes_MB_q8[5*st + wh]  .Fill( (muon.phi()-muon2.phi()) )
0347                     hPhiBRes_MB_q8[5*st + wh] .Fill( (muon.phiBend()-muon2.phiBend()) )
0348                     hChi2Res_MB_q8[5*st + wh] .Fill( (muon.chi2()-muon2.chi2()) )
0349                     hBxRes_MB_q8[5*st + wh]   .Fill( (muon.bxNum()-muon2.bxNum()) )
0350                     hTimeRes_MB_q8[5*st + wh] .Fill( (muon.t0()-muon2.t0()) )
0351                 
0352             hMatchingEff[st].Fill(matched, muon.quality())
0353             hMatchingEff_MB[5*st + wh].Fill(matched, muon.quality())
0354 
0355     if (dumpToFile): f.close()
0356     ev.toBegin()
0357     dumpToFile=False
0358 
0359         
0360 
0361 import pickle 
0362 with open('GroupingComparison_StdToBayes.pickle', 'wb') as handle:
0363     pickle.dump(outputDict,   handle, protocol=pickle.HIGHEST_PROTOCOL)