Skip to content

Instantly share code, notes, and snippets.

@askielboe
Created August 8, 2010 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save askielboe/514145 to your computer and use it in GitHub Desktop.
Save askielboe/514145 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# Gaudi Libraries
import Gaudi
from Gaudi.Configuration import *
import GaudiPython
# Private functions
from func_general import *
######################## GLOBALS #########################
errorlines = {}
######################## SETTINGS ########################
INTERACTIVE = True
NEV = 1000 # This is overwritten for INTERACTIVE mode.
isMC = False
HltSettings = 'Physics_HighNu_40Vis_15L0_2Hlt1_ExpressHlt2_Jun10'
#HltSettings = 'Physics_MinBiasL0_PassThroughHlt_Jun10'
datacard = "Collision10/recoStrip04/jPsi4Bmm.py"
path = "/afs/cern.ch/user/a/askielbo/datacards/"
TCK = '0x001F'
L0TCK = '0x001F'
######################### MAGIC ##########################
from Configurables import L0Conf, HltConf, CondDB
HltConf().HistogrammingLevel=''
HltConf.Verbose=TRUE
L0Conf().TCK = TCK
HltConf().L0TCK = L0TCK
from Configurables import DaVinci
DaVinci().ReplaceL0BanksWithEmulated=True
from Configurables import HltSelReportsMaker
HltSelReportsMaker().DebugEventPeriod=1
HltSelReportsMaker().MaxCandidatesNonDecision=500
# RELATED TO DATA
if isMC:
DaVinci().Simulation = True
DaVinci().CondDBtag = "sim-20100510-vc-md100" #MC sim04 reco03
DaVinci().DDDBtag = "head-20100407"
if not isMC:
DaVinci().Simulation = False
#CondDB(UseOracle = True) # THIS LINE GIVES AN ERROR..
DaVinci().CondDBtag = "head-20100531" #reco4-strip5!
DaVinci().DDDBtag = "head-20100518"
DaVinci().DataType = "2010"
# RUN THE HLT
DaVinci().Hlt = True
DaVinci().HltThresholdSettings = HltSettings
#DaVinci().EvtMax = NEV
DaVinci().PrintFreq = 100
MessageSvc().Format = "% F%70W%S%7W%R%T %0W%M"
if not INTERACTIVE: DaVinci().HistogramFile = 'trial_tistos.root'
######################## GET DATA ########################
# Datacard
importOptions(path+datacard)
# # MC Jpsi
# EventSelector().Input = [
# "DATAFILE='PFN:/castor/cern.ch/user/a/albrecht/data/Collision10/StrippedJPsi_MC_minBias_mm_tightSelection_from5kLooseJPsi.SeqJpsi.dst' TYP='POOL_ROOTTREE' OPT='READ'"
# ]
#MC min bias
## EventSelector().Input = [
## " DATAFILE='root://castorlhcb.cern.ch//castor/cern.ch/grid/lhcb/MC/2010/DST/00006992/0000/00006992_00000002_1.dst?svcClass=lhcbdata' TYP='POOL_ROOTTREE' OPT='READ'",
## " DATAFILE='root://castorlhcb.cern.ch//castor/cern.ch/grid/lhcb/MC/2010/DST/00006992/0000/00006992_00000003_1.dst?svcClass=lhcbdata' TYP='POOL_ROOTTREE' OPT='READ'"
## ]
#################### CONFIGURE THE TRACKFITTER ###################
# DOESNT WORK THIS WAY. TRYING WITH FILES INSTEAD!
# from Configurables import TrackMasterFitter
# TrackMasterFitter.MaxNumberOutliers = 0
#################### RUNTIME FUNCTIONS ###################
def end():
gaudi.stop()
gaudi.finalize()
gaudi.exit()
#################### INITIALIZE GAUDI ####################
appConf = ApplicationMgr()
appConf.HistogramPersistency = 'ROOT'
appConf.ExtSvc += ['DataOnDemandSvc']
gaudi = GaudiPython.AppMgr(outputlevel=3)
gaudi.initialize()
TES = gaudi.evtsvc()
if INTERACTIVE: NEV=1
#for i in range(NEV):
gaudi.run(NEV)
if not INTERACTIVE: end()
###################### TISTOSTOOL #######################
# get the tool service
tsvc = gaudi.toolsvc()
# used for printout
daughterTool = tsvc.create('ParticleDescendants',interface='IParticleDescendants')
# TisTos tool
tistostool = tsvc.create('TriggerTisTos',interface='ITriggerTisTos')
# tisTosToolL0= tsvc.create('L0TriggerTisTos',interface='ITriggerTisTos')
# reset
tistostool.setOfflineInput()
# tisTosToolL0.setOfflineInput()
################### TISTOS FUNCTIONS ####################
def ttclear():
tistostool.setTriggerInput()
tistostool.setOfflineInput()
def getHlt1Lines(line):
hlt1triggers = tistostool.triggerSelectionNames(line)
dvs( hlt1triggers )
def getHlt1TisTos():
# tistos Hlt1
hlt1g = tistostool.triggerTisTos('Hlt1Global')
print ' Hlt1Global decision=',hlt1g.decision(),' tis=',hlt1g.tis(),' tos=',hlt1g.tos()
hlt1 = tistostool.triggerTisTos('Hlt1.*Decision')
print ' Hlt1 decision=',hlt1.decision(),' tis=',hlt1.tis(),' tos=',hlt1.tos()
print ' Hlt1 TOS triggers'
dvs( tistostool.triggerSelectionNames(tistostool.kTrueRequired,tistostool.kAnything,tistostool.kTrueRequired) )
print ' Hlt1 TIS triggers'
dvs( tistostool.triggerSelectionNames(tistostool.kTrueRequired,tistostool.kTrueRequired,tistostool.kAnything) )
def getTisTos():
#getMuTOSmatch()
gaudi.run(1)
# all saved selections on TES
sids = tistostool.triggerSelectionNames('.*') #Hlt1.*Muon.*
signals = TES['/Event/Sel/Phys/StdLooseMuons/Particles']
#tistostool.setOfflineInput()
tistostool.setOfflineInput(signals[0])
for selname in sids:
if ( selname.find('/Event/MC') == -1 ):
results = tistostool.selectionTisTos(selname)
if results.decision():
# print ' decision=' , results.decision() , ' sel-decision=', 1 if tistostool.hltSelectionObjectSummaries(selname).size() else 0,
print ' TOS=' , results.tos() , ' TIS=' , results.tis(),
print ' #-of-TOS obj ' , tistostool.hltSelectionObjectSummaries(selname,tistostool.kFalseRequired,tistostool.kTrueRequired).size(),
print ' TOB ' , tistostool.hltSelectionObjectSummaries(selname,tistostool.kFalseRequired,tistostool.kFalseRequired).size(),
print ' TIS ' , tistostool.hltSelectionObjectSummaries(selname,tistostool.kTrueRequired,tistostool.kFalseRequired).size(),
print ' #-of-matched TOS tracks ' , tistostool.matchedTOSTracks(selname).size(),
print ' vertices ' , tistostool.matchedTOSVertices(selname).size(),
print ' particles ' , tistostool.matchedTOSParticles(selname).size(),
print ' TES Selection=' , selname
def getTisTosSum(NEV):
noTIS = 0
noTOS = 0
for i in range(NEV):
gaudi.run(1)
sids = tistostool.triggerSelectionNames('.*')
for selname in sids:
#if ( selname.find('/Event/MC') == -1 ):
results = tistostool.triggerTisTos(selname)
if results.decision():
noTOS = noTOS + results.tos()
noTIS = noTIS + results.tis()
print "Number of TOS: ", noTOS
print "Number of TIS: ", noTIS
# /Event/Sel
# /Event/Sel/Phys
# /Event/Sel/Phys/SelJpsi
# /Event/Sel/Phys/SelJpsi/Particles
# /Event/Sel/Phys/SelJpsi/Particle2VertexRelations
# /Event/Sel/Phys/StdLooseJpsi2MuMu
# /Event/Sel/Phys/StdLooseMuons
# /Event/Phys
# /Event/Phys/StdLooseJpsi2MuMu
# /Event/Phys/StdLooseJpsi2MuMu/Particles
# /Event/Phys/StdLooseJpsi2MuMu/Particle2VertexRelations
# /Event/Phys/StdLooseJpsi2MuMu/decayVertices
# /Event/Phys/StdLooseMuons
# /Event/Phys/StdLooseMuons/Particles
# /Event/Phys/StdLooseMuons/Particle2VertexRelations
# /Event/Phys/StdLooseMuons/decayVertices
def getMuTOSmatch():
#gaudi.run(1)
signals = TES['/Event/Sel/Phys/StdLooseMuons/Particles']
#tistostool.setTriggerInput('Hlt1.*')
for signal in signals:
#tistostool.setOfflineInput(particle)
print "no of matchedTOSTracks: ", tistostool.matchedTOSTracks(signal,'Hlt1SingleMuonIPCL0Decision').size()
print "no of matchedTOSParticles: ", tistostool.matchedTOSParticles(signal, 'Hlt1SingleMuonIPCL0Decision').size()
print "tis: ", tistostool.triggerTisTos(signal, 'Hlt1.*').tis()
print "tos: ", tistostool.triggerTisTos(signal, 'Hlt1.*').tos()
def getTOSCandidates():
signals = TES['/Event/Sel/Phys/StdLooseMuons/Particles']
for signal in signals:
tosCandidates = tistostool.hltObjectSummaries(signal,'Hlt1.*Decision',tistostool.kFalseRequired, tistostool.kTrueRequired)
if tosCandidates.size():
for candidate in tosCandidates:
print candidate
print 'This signal was used'
def whichHasTracks(NEV):
d = {}
for i in range(NEV):
getTimeTaken(i,NEV)
if NEV > 1: gaudi.run(1)
lines = tistostool.triggerSelectionNames('.*')
for line in lines:
if getTracks(line).size() > 0: d[line] = 1
linenames = d.keys()
linenames.sort()
print "The following lines had track objects (classID = 10010) in them at some point during ",NEV," iterations:\n"
for name in linenames:
print name
def whichHasChi2(NEV):
d = {}
for i in range(NEV):
getTimeTaken(i,NEV)
if NEV > 1: gaudi.run(1)
lines = tistostool.triggerSelectionNames('.*')
for line in lines:
tracks = getTracks(line)
# if tracks.size() > 0:
for track in tracks:
if track.chi2PerDoF() > 0:
d[line] = 1
linenames = d.keys()
linenames.sort()
print "The following lines had reduced chi2 > 0 at some point during ",NEV," iterations:\n"
for name in linenames:
print name
def whichHasType(ttype,NEV):
d = {}
for i in range(NEV):
getTimeTaken(i,NEV)
if NEV > 1: gaudi.run(1)
lines = tistostool.triggerSelectionNames('.*')
for line in lines:
tracks = getTracks(line)
# if tracks.size() > 0:
for track in tracks:
if (track.type() == ttype):
d[line] = 1
linenames = d.keys()
linenames.sort()
print "The following lines returned a track of type ", ttype, " at some point during ",NEV," iterations:\n"
for name in linenames:
print name
def whichHasTypeChi2(ttype,NEV):
d = {}
for i in range(NEV):
getTimeTaken(i,NEV)
if NEV > 1: gaudi.run(1)
lines = tistostool.triggerSelectionNames('.*')
for line in lines:
tracks = getTracks(line)
# if tracks.size() > 0:
for track in tracks:
if (track.type() == ttype) and (track.chi2PerDoF() > 0):
d[line] = 1
linenames = d.keys()
linenames.sort()
print "The following lines returned a track of type ", ttype, " with chi2 > 0, at some point during ",NEV," iterations:\n"
for name in linenames:
print name
def getObject(line):
summaries = tistostool.hltSelectionObjectSummaries(line)
if summaries.size() > 0:
for summary in summaries:
sumobject = summary.summarizedObject()
print sumobject
else:
print "WARNING: No objects processed by line: ", line
def getnIDsnMeas(NEV,line):
for i in range(NEV):
gaudi.run(1)
getTimeTaken(i,NEV)
tracks = getTracks(line)
for track in tracks:
if track.nLHCbIDs() > track.nMeasurements():
print "OOPS! We have # LHCbID's > # Measurements. Something is not right!"
print "track.lhcbIDs() = ", track.nLHCbIDs()
print "track.nMeasurements() = ", track.nMeasurements()
def getTracks(line):
# Initialize empty tracks vector
tracks = tistostool.matchedTOSTracks('DUMMY')
tracks.clear() # Just to make sure we got an empty vecor
# Get summarized objects for line
summaries = tistostool.hltSelectionObjectSummaries(line)
# Retrieve the real objects
if summaries.size() > 0:
for summary in summaries:
sumobject = summary.summarizedObject() # Get the real object we're interested in
if sumobject.classID() == 10010: # Check if the real object is actually a track
tracks.push_back(sumobject)
#else:
#errorlines[line] = 1
return tracks
def getTrack(line):
for i in range(100):
tracks = getTracks(line)
if tracks.size() > 0:
return tracks[0]
gaudi.run(1)
print "No tracks found within 100 iterations.."
def sumerrMeasure(track):
if track.nMeasurements() > 0:
err = {}
types = ['Unknown',
'VeloR',
'VeloPhi',
'VeloLiteR',
'VeloLitePhi',
'TT',
'IT',
'OT',
'Muon',
'TTLite',
'ITLite',
'VeloPixLite'
]
for t in types:
err[t] = 0.
for lhcbID in track.lhcbIDs():
m = track.measurement(lhcbID)
if m.__nonzero__() == 1:
t = m.type()
err[types[t]] += m.errMeasure()
return err
else:
return 0
# for m in err:
# if err[m] > 0: print repr(m).ljust(15), repr(err[m]).rjust(5)
def sumNodeChi2PerDoF(track):
if track.nMeasurements() > 0:
types = ['Unknown',
'VeloR',
'VeloPhi',
'VeloLiteR',
'VeloLitePhi',
'TT',
'IT',
'OT',
'Muon',
'TTLite',
'ITLite',
'VeloPixLite'
#'ndof'
]
ntypes = [0,0,0,0,0,0,0,0,0,0,0,0]
chi2 = {}
chi2list = []
for t in types:
chi2[t] = 0.
# chi2list contains len(types) elements, which are lists of size 2.
# index 0 will contain the reduced chi2
# index 1 will contain outlier flag
chi2list.append([chi2[t],False])
nodes = track.fitResult().nodes()
# Get DoFs
#chi2['ndof'] = int(track.nMeasurements()) # Removes the 'L'
# chi2['nMeasurements'] = nodes.size()
for node in nodes:
if node.hasMeasurement():
nt = node.measurement().type()
ntypes[nt] += 1 # Count the number of nodes for the given type
chi2[types[nt]] += node.chi2()
#print node.type()
# I FIND NO NODES FLAGGED AS OUTLIERS WITH THE CURRENT TRIGGER SETTINGS
# THEREFORE THE FOLLOWING IS TURNED OFF ATM
#if node.type() == 2:
#chi2list[nt][1] = True # Add a True bool to list if any of the nodes are outliers
# INSTEAD: HERE WE FLAG OUTLIERS IF THEIR CHI2 CONTRIBUTION IS LARGE
if node.chi2() > 3.:
chi2list[nt][1] = True
for i,n in enumerate(ntypes):
if n > 0:
chi2list[i][0] = chi2[types[i]]/n # Calculate reduced chi2
return chi2list
else:
return 0
# for m in chi2:
# if chi2[m] > 0: print repr(m).ljust(15), repr(chi2[m]/chi2['ndof']).rjust(5)
def sumNodeChi2PerDoFPerType(track,nodetype):
if track.nMeasurements() > 0:
# types = ['Unknown',
# 'VeloR',
# 'VeloPhi',
# 'VeloLiteR',
# 'VeloLitePhi',
# 'TT',
# 'IT',
# 'OT',
# 'Muon',
# 'TTLite',
# 'ITLite',
# 'VeloPixLite'
# #'ndof'
# ]
n = 0
chi2 = 0
nodes = track.fitResult().nodes()
for node in nodes:
if node.hasMeasurement() and node.measurement().type() == nodetype:
n += 1 # Count the number of nodes
chi2 += node.chi2()
if n > 0:
chi2 = chi2/n # Calculate reduced chi2
return chi2
else:
return 0
else:
return 0
def sumerrMeasureAll():
i = 0
lines = tistostool.triggerSelectionNames('.*')
for line in lines:
tracks = getTracks(line)
for track in tracks:
print sumerrMeasure(track)
def getNNodeTypes(NEV):
lines = ['Hlt1SingleMuonIPCL0TUFitTrack',
'Hlt1SingleMuonNoIPL0TUFitTrack']
ntype = [0,0,0,0]
for i in range(NEV):
getTimeTaken(i,NEV)
gaudi.run(1)
for line in lines:
tracks = getTracks(line)
for track in tracks:
nodes = track.fitResult().nodes()
for node in nodes:
ntype[node.type()] += 1
for i,n in enumerate(ntype):
print "Type:",i,"Count:",n
###################### HISTOGRAMS #######################
from ROOT import *
def histoChi2():
print "nothing"
def histoFillPt(histo,line):
tracks = getTracks(line)
if tracks.size() > 0:
for track in tracks:
histo.Fill(track.pt())
def histoFillChi2PerDoF(histo,line):
tracks = getTracks(line)
if tracks.size() > 0:
for track in tracks:
chi2PerDoF = track.chi2PerDoF()
if chi2PerDoF > 0:
histo.Fill(chi2PerDoF)
def makeHistos(h,lines):
# Define histograms in a dictionary
# TAKES AS INPUT TYPE: DICTIONARY AND TYPE: LIST
for line in lines:
h[str(line)] = TH1F(line,line,80,0,8000)
return h
def histoWriteMuonIPstamps(NEV):
fname = "histoMuonIPstamps.root"
outfile = TFile(fname, "RECREATE")
# NOTE: The following may be generalized to more groups, by the extended use of dictionaries.
linesSingle = ["Hlt1L0MuonDecision",
"Hlt1AllL0MuPrepTUTConf",
"Hlt1AllL0MuPrepTMVeloT",
"Hlt1MuonPrepTUTConf",
"Hlt1MuonPrepTMVeloT"
]
# linesSingle = ["Hlt1SingleMuonIPCL0Decision",
# "Hlt1MuonPrepTUTConf",
# #"Hlt1MuonPrepTMVeloT",
# "Hlt1SingleMuonIPCL0TUFitTrack"
# ]
linesDiL0Di = ["Hlt1L0DiMuonDecision",
"Hlt1DiMuonPrepTUTConf"
#"Hlt1DiMuonIPCL0DiDecision",
#"Hlt1DiMuonIPCL0DiDecision"
]
linesDi2L0 = ["Hlt1DiMuonIPC2L0Decision",
"Hlt1DiMuonPrepTUTConf"
#"Hlt1DiMuonIPC2L0Decision",
#"Hlt1DiMuonIPC2L0Decision"
]
linesDiSeg = ["Hlt1DiMuonIPCL0SegDecision",
"Hlt1MuonSegPrepTUTConf"
#"",
#""
]
# Define histograms in dictionaries
hSingle = {}
hDiL0Di = {}
hDi2L0 = {}
hDiSeg = {}
makeHistos(hSingle,linesSingle)
makeHistos(hDiL0Di,linesDiL0Di)
makeHistos(hDi2L0,linesDi2L0)
makeHistos(hDiSeg,linesDiSeg)
# vvvvvvvvvvvvvvvvvvvvvvvvvv LOOP: SUM OVER EVENTS vvvvvvvvvvvvvvvvvvvvvvvvvv
for i in range(NEV):
gaudi.run(1)
getTimeTaken(i,NEV)
# Here we get the names of the dictionary entries as histo
for hDict in [hSingle,hDiL0Di,hDi2L0,hDiSeg]:
for line, histo in hDict.iteritems():
histoFillPt(histo,line)
# for histo in hDiL0Di:
# histoFillPt(hDiL0Di[histo],histo)
#
# for histo in hDi2L0:
# histoFillPt(hDi2L0[histo],histo)
#
# for histo in hDiSeg:
# histoFillPt(hDiSeg[histo],histo)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ END LOOP ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# vvvvvvvvvvvvvvvvvvvvvvvvvv CUSTOM HISTOGRAMS vvvvvvvvvvvvvvvvvvvvvvvvvv
# makeHistos(hSingle,['L0vsTConf'])
# hSingle['L0vsTConf'].Divide(hSingle['Hlt1SingleMuonIPCL0Decision'],hSingle['Hlt1MuonPrepTUTConf'])
# makeHistos(hSingle,['sigma_pt'])
# hSingle['sigma_pt'].Add(hSingle['Hlt1MuonPrepTUTConf'],hSingle['Hlt1SingleMuonIPCL0Decision'],1,-1)
# hSingle['sigma_pt'].Divide(hSingle['Hlt1MuonPrepTUTConf'])
# ^^^^^^^^^^^^^^^^^^^^^^^^ END CUSTOM HISTOGRAMS ^^^^^^^^^^^^^^^^^^^^^^^^^^
# vvvvvvvvvvvvvvvvvvvvvvvvvvv GENERATE CANVAS vvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# Calculate number of rows
rows = 0
if len(hSingle) > rows:
rows = len(hSingle)
if len(hDiL0Di) > rows:
rows = len(hDiL0Di)
if len(hDi2L0) > rows:
rows = len(hDi2L0)
if len(hDiSeg) > rows:
rows = len(hDiSeg)
cols = 4
c1 = TCanvas("c1","Name",0,0,300,300)
c1.Divide(cols,rows) # OR THE OTHER WAY AROUND !?
i = 0
for histo in hSingle:
c1.cd(1+i*cols)
hSingle[histo].Draw()
c1.Update()
i = i+1
i = 0
for histo in hDiL0Di:
c1.cd(2+i*cols)
hDiL0Di[histo].Draw()
c1.Update()
i = i+1
i = 0
for histo in hDi2L0:
c1.cd(3+i*cols)
hDi2L0[histo].Draw()
c1.Update()
i = i+1
i = 0
for histo in hDiSeg:
c1.cd(4+i*cols)
hDiSeg[histo].Draw()
c1.Update()
i = i+1
print "\nWARNING: The following lines did, at some point during the ",NEV," iterations, fail to return a Vector object:"
for line in errorlines:
print line
canvasname = "tmp_canvas.ps"
c1.SaveAs(canvasname)
outfile.Write()
outfile.Close()
print "\nSUCCESS: Processed ",NEV," events!"
print "SUCCESS: ROOT histograms written to: ", fname
print "SUCCESS: Canvas written to: ", canvasname
def histoWriteChi2(NEV):
fname = "histoMuonIPChi2.root"
outfile = TFile(fname, "RECREATE")
lines = ['Hlt1SingleMuonIPCL0TUFitTrack',
'Hlt1SingleMuonIPCL0Decision']
histos = []
# Make histograms
for i,line in enumerate(lines):
histos.append(TH1F(line,line,80,0,20))
# Fill histograms
for i in range(NEV):
getTimeTaken(i,NEV)
gaudi.run(1)
for h,histo in enumerate(histos):
histoFillChi2PerDoF(histo,lines[h])
# Write to canvas
c1 = TCanvas("c1","Name",0,0,300,300)
c1.Divide(2,2)
for i,histo in enumerate(histos):
c1.cd(i+1)
histo.Draw()
canvasname = 'histoWriteChi2.ps'
c1.SaveAs(canvasname)
outfile.Write()
outfile.Close()
print "\nSUCCESS: Processed ",NEV," events!"
print "SUCCESS: ROOT histograms written to: ", fname
print "SUCCESS: Canvas written to: ", canvasname
def histoWriteTrackTypes(NEV):
fname = "histoWriteTrackTypes.root"
outfile = TFile(fname, "RECREATE")
# Make histogram
histo = TH1F('histoWriteTrackTypes','histoWriteTrackTypes',11,0,11)
histoFitted = TH1F('histoWriteTrackTypes FITTED','histoWriteTrackTypes FITTED',11,0,11)
histoNon0Chi2 = TH1F('histoWriteTrackTypes chi2 > 0','histoWriteTrackTypes chi2 > 0',11,0,11)
# Fill histograms
for i in range(NEV):
getTimeTaken(i,NEV)
gaudi.run(1)
lines = tistostool.triggerSelectionNames('.*')
for line in lines:
tracks = getTracks(line)
for track in tracks:
ttype = track.type()
histo.Fill(ttype)
if track.fitStatus() == 1:
histoFitted.Fill(ttype)
if track.chi2PerDoF() > 0:
histoNon0Chi2.Fill(ttype)
# Write to canvas
c1 = TCanvas("c1","Name",0,0,300,300)
c1.Divide(2,2)
c1.cd(1)
maximum = histo.GetMaximum()
histo.Draw()
c1.cd(2)
histoFitted.SetMaximum(maximum)
histoFitted.Draw()
c1.cd(3)
histoNon0Chi2.SetMaximum(maximum)
histoNon0Chi2.Draw()
canvasname = 'histoWriteTrackTypes.ps'
c1.SaveAs(canvasname)
outfile.Write()
outfile.Close()
print "\nSUCCESS: Processed ",NEV," events!"
print "SUCCESS: ROOT histograms written to: ", fname
print "SUCCESS: Canvas written to: ", canvasname
def histoWriteMeasErr(NEV):
# Make histogram of the sum of the Track.Measurement.errMeasure()
# for each type of measurement
# for track type: Long
fname = "histoWriteMeasErr.root"
canvasname = 'histoWriteMeasErr.ps'
outfile = TFile(fname, "RECREATE")
types = ['Unknown',
'VeloR',
'VeloPhi',
'VeloLiteR',
'VeloLitePhi',
'TT',
'IT',
'OT',
'Muon',
'TTLite',
'ITLite',
'VeloPixLite'
]
# Define histograms
histos = []
for i,t in enumerate(types):
if t == 'Muon':
histos.append(TH1F(t,t,20,0,40))
else:
histos.append(TH1F(t,t,20,0,1))
# Fill histograms
for i in range(NEV):
getTimeTaken(i,NEV)
gaudi.run(1)
lines = tistostool.triggerSelectionNames('.*')
for line in lines:
tracks = getTracks(line)
for track in tracks:
ttype = track.type()
if ttype == 3: # ie. only do something if this is a long track
errsum = sumerrMeasure(track)
if errsum:
for i,t in enumerate(types):
if errsum[t] > 0:
histos[i].Fill(errsum[t])
if errsum[t] > 1 and t != 'Muon': print "WARNING: ErrorSum Outside range of histogram (= ",errsum[t]," )."
# Write to canvas
c1 = TCanvas("c1","Name",0,0,300,300)
c1.Divide(4,3)
for i,hist in enumerate(histos):
c1.cd(i+1)
hist.Draw()
c1.SaveAs(canvasname)
outfile.Write()
outfile.Close()
print "\nSUCCESS: Processed ",NEV," events!"
print "SUCCESS: ROOT histograms written to: ", fname
print "SUCCESS: Canvas written to: ", canvasname
def histoWriteNodeChi2PerNode(NEV):
fname = "histoWriteNodeChi2PerNode.root"
canvasname = 'histoWriteNodeChi2PerNode.ps'
outfile = TFile(fname, "RECREATE")
nbins = 200
maxchi2 = 20. # Range of histograms!
lines = ['Hlt1SingleMuonIPCL0TUFitTrack']
types = ['Unknown',
'VeloR',
'VeloPhi',
'VeloLiteR',
'VeloLitePhi',
'TT',
'IT',
'OT',
'Muon',
'TTLite',
'ITLite',
'VeloPixLite'
]
# Define histograms
histos = []
histoso = []
histooutrange = []
for i,t in enumerate(types):
histos.append(TH1F(t,t,nbins,0,maxchi2))
histoso.append(TH1F(t+"Outliers",t+"Outliers",nbins,0,maxchi2))
histooutrange.append(TH1F(t+"ORange",t+"ORange",1500,0,1500))
noutrange = 0
# Fill histograms
for i in range(NEV):
getTimeTaken(i,NEV)
gaudi.run(1)
#lines = tistostool.triggerSelectionNames('.*')
for line in lines:
tracks = getTracks('Hlt1SingleMuonIPCL0TUFitTrack')
for track in tracks:
if track.type() == 3: # ie. only do something if this is a long track
nodes = track.fitResult().nodes()
outlier = [0 for i in range(len(types))]
for i,t in enumerate(types):
outlier[i] = False
# FIGURE OUT IF THE TRACK CONTAINS AN OUTLIER NODE
for node in nodes:
if node.hasMeasurement():
nt = node.measurement().type()
#if node.type() == 2: # This never returns 'Outlier, so we don't use this atm'.
if node.chi2() > 3.:
outlier[nt] = True
# FILL HISTOGRAMS ACCORDINGLY
for node in nodes:
if node.hasMeasurement():
nt = node.measurement().type()
if outlier[nt] == True:
histoso[nt].Fill(node.chi2())
elif outlier[nt] == False:
histos[nt].Fill(node.chi2())
# Write to canvas
c1 = TCanvas("c1","Name",0,0,300,300)
c1.Divide(4,3)
n = 1
for hist in histos:
if hist.GetEntries() > 0:
c1.cd(n)
hist.Draw()
n += 1
for hist in histoso:
if hist.GetEntries() > 0:
c1.cd(n)
hist.Draw()
n += 1
c1.SaveAs(canvasname)
outfile.Write()
outfile.Close()
print "\nSUCCESS: Processed ",NEV," events!"
print "Number of node-sets outside range:", noutrange
print "SUCCESS: ROOT histograms written to: ", fname
print "SUCCESS: Canvas written to: ", canvasname
def histoWriteNodeChi2PerType(NEV):
fname = "histoWriteNodeChi2PerType.root"
canvasname = 'histoWriteNodeChi2PerType.ps'
outfile = TFile(fname, "RECREATE")
nbins = 200
maxchi2 = 20. # Range of histograms!
lines = ['Hlt1SingleMuonIPCL0TUFitTrack']
types = ['Unknown',
'VeloR',
'VeloPhi',
'VeloLiteR',
'VeloLitePhi',
'TT',
'IT',
'OT',
'Muon',
'TTLite',
'ITLite',
'VeloPixLite'
]
# Define histograms
histos = []
histoso = []
histooutrange = []
for i,t in enumerate(types):
histos.append(TH1F(t,t,nbins,0,maxchi2))
histoso.append(TH1F(t+"Outliers",t+"Outliers",nbins,0,maxchi2))
histooutrange.append(TH1F(t+"ORange",t+"ORange",1500,0,1500))
noutrange = 0
# Fill histograms
for i in range(NEV):
getTimeTaken(i,NEV)
gaudi.run(1)
#lines = tistostool.triggerSelectionNames('.*')
for line in lines:
tracks = getTracks('Hlt1SingleMuonIPCL0TUFitTrack')
for track in tracks:
if track.type() == 3: # ie. only do something if this is a long track
chi2pd = sumNodeChi2PerDoF(track)
for i,t in enumerate(types):
if chi2pd[i][0] > 0:
if chi2pd[i][1] == True: # WE HAVE AN OUTLIER!
histoso[i].Fill(chi2pd[i][0])
elif chi2pd[i][1] < maxchi2:
histos[i].Fill(chi2pd[i][0])
elif chi2pd[i][0] > maxchi2:
histooutrange[i].Fill(chi2pd[i][0])
#print "WARNING: Chi2 outside range of histogram (",maxchi2,"<",chi2pd[i][0]," ). Type:",t
noutrange += 1
# Write to canvas
c1 = TCanvas("c1","Name",0,0,300,300)
c1.Divide(4,3)
n = 1
for hist in histos:
if hist.GetEntries() > 0:
c1.cd(n)
hist.Draw()
n += 1
for hist in histoso:
if hist.GetEntries() > 0:
c1.cd(n)
hist.Draw()
n += 1
c1.SaveAs(canvasname)
outfile.Write()
outfile.Close()
print "\nSUCCESS: Processed ",NEV," events!"
print "Number of node-sets outside range:", noutrange
print "SUCCESS: ROOT histograms written to: ", fname
print "SUCCESS: Canvas written to: ", canvasname
def histoWriteNodeChi2(NEV):
fname = "histoWriteNodeChi2.root"
canvasname = 'histoWriteNodeChi2.ps'
outfile = TFile(fname, "RECREATE")
nbins = 200
maxchi2 = 20. # Range of histograms!
lines = ['Hlt1SingleMuonIPCL0TUFitTrack']
types = ['Unknown',
'VeloR',
'VeloPhi',
'VeloLiteR',
'VeloLitePhi',
'TT',
'IT',
'OT',
'Muon',
'TTLite',
'ITLite',
'VeloPixLite'
]
# Define histograms
histos = []
histooutrange = []
for i,t in enumerate(types):
histos.append(TH1F(t,t,nbins,0,maxchi2))
histooutrange.append(TH1F(t+"ORange",t+"ORange",int(1500-maxchi2),maxchi2,1500))
noutrange = 0
# Fill histograms
for i in range(NEV):
getTimeTaken(i,NEV)
gaudi.run(1)
#lines = tistostool.triggerSelectionNames('.*')
for line in lines:
tracks = getTracks('Hlt1SingleMuonIPCL0TUFitTrack')
for track in tracks:
if track.type() == 3: # ie. only do something if this is a long track
chi2pd = sumNodeChi2PerDoF(track)
for i,t in enumerate(types):
if chi2pd[i][0] > 0 and chi2pd[i][1] < maxchi2:
histos[i].Fill(chi2pd[i][0])
elif chi2pd[i][0] > 0 and chi2pd[i][1] > maxchi2:
histooutrange[i].Fill(chi2pd[i][0])
#print "WARNING: Chi2 outside range of histogram (",maxchi2,"<",chi2pd[i][0]," ). Type:",t
noutrange += 1
# Write to canvas
c1 = TCanvas("c1","Name",0,0,300,300)
c1.Divide(4,3)
n = 1
for hist in histos:
if hist.GetEntries() > 0:
c1.cd(n)
hist.Draw()
n += 1
c1.SaveAs(canvasname)
outfile.Write()
outfile.Close()
print "\nSUCCESS: Processed ",NEV," events!"
print "Number of node-sets outside range:", noutrange
print "SUCCESS: ROOT histograms written to: ", fname
print "SUCCESS: Canvas written to: ", canvasname
def histoWriteFitCleanedAndMuChi2PerDoF(NEV):
name = 'histoWriteFitMuChi2PerDoF'
fname = name+'.root'
canvasname = name+'.ps'
outfile = TFile(fname, "RECREATE")
nbins = 200
maxchi2 = 20. # Range of histograms!
lines = ['Hlt1SingleMuonIPCL0TUFitTrack']
# Define histograms
histo_chi2perdofmu = TH1F('chi2perdofmu','chi2perdofmu',nbins,0,maxchi2)
histo_chi2perdofclean = TH1F('chi2perdofclean','chi2perdofclean',nbins,0,maxchi2)
# Fill histograms
for i in range(NEV):
getTimeTaken(i,NEV)
gaudi.run(1)
#lines = tistostool.triggerSelectionNames('.*')
for line in lines:
tracks = getTracks('Hlt1SingleMuonIPCL0TUFitTrack')
for track in tracks:
if track.type() == 3: # ie. only do something if this is a long track
if track.nMeasurements() > 0:
nmu = 0.
chi2mu = 0.
nodes = track.fitResult().nodes()
for node in nodes:
if node.hasMeasurement() and node.measurement().type() == 8:
nmu += 1 # Count the number of muon nodes
chi2mu += node.chi2()
if nmu and track.nDoF() > 0:
nclean = track.nDoF() - nmu
chi2clean = track.chi2() - chi2mu
chi2muperdof = chi2mu/nmu
chi2cleanperdof = chi2clean/nclean
histo_chi2perdofmu.Fill(chi2muperdof)
histo_chi2perdofclean.Fill(chi2cleanperdof)
# Write to canvas
c1 = TCanvas("c1","Name",0,0,300,300)
c1.Divide(1,2)
c1.cd(1)
histo_chi2perdofmu.Draw()
c1.cd(2)
histo_chi2perdofclean.Draw()
c1.SaveAs(canvasname)
outfile.Write()
outfile.Close()
print "\nSUCCESS: Processed ",NEV," events!"
print "SUCCESS: ROOT histograms written to: ", fname
print "SUCCESS: Canvas written to: ", canvasname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment