def plotHitTruthPositions(topPlotPath,topPlotTitle,bottomPlotPath,bottomPlotTitle) :

  #Create a fresh canvas
  c = TCanvas("c","",1200,800)
  c.Divide(1,2)

  #First hit plot
  h_primaryPositronHits = rh.getFromFile(rootFile,topPlotPath)
  c.cd(1)
  h_primaryPositronHits.SetTitle(topPlotTitle)
  #h_primaryPositronHits.GetYaxis().SetTitleOffset(1.5)
  h_primaryPositronHits.SetStats(False)
  h_primaryPositronHits.GetYaxis().SetRangeUser(-200.,400.)
  h_primaryPositronHits.Draw("COLZ")

  #Second hit plot
  h_secondaryHits = rh.getFromFile(rootFile,bottomPlotPath)
  c.cd(2)
  h_secondaryHits.SetTitle(bottomPlotTitle)
  #h_secondaryHits.GetYaxis().SetTitleOffset(1.5)
  h_secondaryHits.SetStats(False)
  h_secondaryHits.GetYaxis().SetRangeUser(-200.,400.)
  h_secondaryHits.Draw("COLZ")

  raw_input("Press Enter to continue...")
def plotHitTrajectories(particle,station) :

  gr = rh.getFromFile(rootFile,'straw_calo_truth/%s/station_%i/g_hitPosTop' % (particle,station) )

  gr.Draw("AP")
  gr.GetYaxis().SetTitleOffset(1.5)
  raw_input("Press Enter to continue...")
Example #3
0
def makePlots(inputFiles,message) :

  #Open all files (keep them in dict so have them in memory simultaneously)
  rootFiles = OrderedDict()
  for key, rootFileName in inputFiles.iteritems() :
    print key,':',rootFileName
    rootFiles[key] = rh.openFile(rootFileName)

  mg_numDigits = TMultiGraph()

  #Loop over files to get each graph to add to mutligraph
  counter = 0
  for key, rootFile in rootFiles.items() :

    counter += 1

    #Get graph
    g_numDigits = rh.getFromFile(rootFile,"straw_unpackers_summary/g_numDigits")

    #Set colors
    g_numDigits.SetMarkerColor(counter)
    g_numDigits.SetLineColor(counter)

    #Add to multigraph to canvas
    mg_numDigits.Add(g_numDigits)


  #
  # Draw the final multigraph
  #

  mg_numDigits.Draw("APL") #Draw once to populate axes
  mg_numDigits.GetXaxis().SetTitle( "Event number" )
  mg_numDigits.GetYaxis().SetTitle( "Num hits" )
  mg_numDigits.GetYaxis().SetTitleOffset(1.2)
  #mg_numDigits.GetXaxis().SetRangeUser(700.,900.)
  mg_numDigits.SetTitle(message)
  mg_numDigits.Draw("APL")
  raw_input("Press Enter to continue...")
Example #4
0
def plotBirthAndHitPositionsFromChosenVolume(particle,station,volume,xRange,yRange) :

  mg = TMultiGraph()

  #Get birth points and add to multi-graph
  g_birthPos = rh.getFromFile(rootFile,'straw_calo_truth/%s/tracker/station_%i/g_birthPosTop_%s' % (particle,station,volume) )
  g_birthPos.SetMarkerColor(kGreen)
  mg.Add(g_birthPos)

  #Get hit points and add to multi-graph
  g_hitPos = rh.getFromFile(rootFile,'straw_calo_truth/%s/tracker/station_%i/g_hitPosTop_%s' % (particle,station,volume) )
  g_hitPos.SetMarkerColor(kRed)
  mg.Add(g_hitPos)

  #Draw multi-graph
  mg.Draw("AP")
  mg.SetTitle( g_birthPos.GetTitle() )
  mg.GetXaxis().SetTitle("Downstream pos (calo at left) [mm]")
  mg.GetYaxis().SetTitle("Radially inwards pos (ring towards bottom) [mm]")
  mg.GetXaxis().SetRangeUser(xRange[0],xRange[1])
  mg.GetYaxis().SetRangeUser(yRange[0],yRange[1])
  mg.GetYaxis().SetTitleOffset(1.5)

  raw_input("Press Enter to continue...")
Example #5
0
def combineAndPlotTrajectories(xaxis,yaxis) :

  mg = TMultiGraph()

  numTrajsPlotted = 0

  for i_event in range(0,args.numEventsTotal) :

    #Add trajectory plot to multi graph
    axesLabel = xaxis.capitalize() + yaxis.capitalize() #e.g. "x" and "y" -> "XY"
    gr = rh.getFromFile(rootFile,'trajectories/primary_e+/trajectories/g_traj%s_evt%05i' % (axesLabel,i_event+1), False )
    if not gr : continue #Skip if this event didn't return a trajectory (e.g. due to filters)
    gr.SetMarkerStyle(7)
    mg.Add(gr)

    #Plot birth point
    birthPoint = TGraph(1)
    x = Double(0)
    y = Double(0)
    gr.GetPoint(0,x,y)
    birthPoint.SetPoint(0,x,y)
    birthPoint.SetMarkerStyle(4)
    birthPoint.SetMarkerColor(kGreen)
    mg.Add(birthPoint)
  
    #Plot death point
    birthPoint = TGraph(1)
    x = Double(0)
    y = Double(0)
    gr.GetPoint(gr.GetN()-1,x,y)
    birthPoint.SetPoint(0,x,y)
    birthPoint.SetMarkerStyle(4)
    birthPoint.SetMarkerColor(kRed)
    mg.Add(birthPoint)

    #Break loop if have plotted enough
    numTrajsPlotted += 1
    if numTrajsPlotted >= args.numEventsToPlot: break
  
  print "Number of events plotted = %i" % (numTrajsPlotted)

  #Draw multi graph
  mg.Draw("APL")
  mg.SetTitle( "Decay positron trajectories;%s global [mm];%s global [mm]" % (xaxis,yaxis) )
  mg.GetXaxis().SetRangeUser(-1.5e4,1.5e4)
  mg.GetYaxis().SetRangeUser(-1.5e4,1.5e4)
  mg.GetYaxis().SetTitleOffset(1.5)
  raw_input("Press Enter to continue...")
Example #6
0
#Compare mean cluster E across multiple runs

from ROOT import TFile, gROOT, TCanvas, gStyle, TGraph, TMultiGraph, Double, kRed, kGreen, kBlue
import os, argparse, math, sys
import RootHelper as rh

#Get args
parser = argparse.ArgumentParser(description='')
parser.add_argument('-i','--input-file', type=str, required=False, default="./meanEnergyPlots.root", help='Input ROOT file containing plots from MeanElectronE module', dest='inputFile')
args = parser.parse_args()

#Open input file
rootFile = rh.openFile(args.inputFile)
if not rootFile : sys.exit(-1)

clusterRootDirName = "mean_electron_energy/cluster"

gStyle.SetOptStat(0)

mg = TMultiGraph()


#
# Get electron and laser E sum graphs
#

mg = TMultiGraph()

g_electronMeanE = rh.getFromFile(rootFile,clusterRootDirName+'/g_electronMeanE')
g_electronMeanE.SetMarkerStyle(8)
g_electronMeanE.SetMarkerSize(1)
Example #7
0
import argparse
import RootHelper as rh
from collections import OrderedDict

#Define files to read
inputRootDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_merge/data/'
inputFileName = 'mtestDigitsAnalysis_strawTriggerDigitPlots.root'
inputFiles = OrderedDict()
inputFiles['Ar-CO2 : Run 316'] = inputRootDir + 'run00316/deadTime150ns/' + inputFileName
inputFiles['Ar-Ethane : Run 405'] = inputRootDir + 'run00405/deadTime150ns/' + inputFileName

#Open all files (keep them in dict so have them in memory simultaneously)
rootFiles = OrderedDict()
for key, rootFileName in inputFiles.items() :
  print key,':',rootFileName
  rootFiles[key] = rh.openFile(rootFileName)


#
# Drift time diff histo
#

#Create a fresh canvas
canvas = TCanvas()
canvas.Divide(2)
#gStyle.SetOptStat(False)

#Loop over files
counter = 0
for key, rootFile in rootFiles.items() :
Example #8
0
import argparse
import RootHelper as rh
from collections import OrderedDict

#Define files to read
inputRootDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_merge/data/'
inputFileName = 'mtestRecoAnalysis_eventSelectionPlots.root'
inputFiles = OrderedDict()
inputFiles['Ar-CO2 : Run 316'] = inputRootDir + 'run00316/deadTime150ns/' + inputFileName
inputFiles['Ar-Ethane : Run 405'] = inputRootDir + 'run00405/deadTime150ns/' + inputFileName

#Open all files (keep them in dict so have them in memory simultaneously)
rootFiles = OrderedDict()
for key, rootFileName in inputFiles.items() :
  print key,':',rootFileName
  rootFiles[key] = rh.openFile(rootFileName)


#
# Cross-talk in same layer
#


lbDir = 'EventSelection/Islands/LB0/'
asdq = 'TDC2ASDQ0'

#Create a fresh canvas
canvas = TCanvas()
canvas.Divide(2)
#gStyle.SetOptStat(False)
#rootFileDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Res_140um/'
#rootFileDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Res_200um/'
#rootFileDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Eff_80-Res_200um/'
#rootFileDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/run00316/'
rootFileDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/run00402/'
#rootFileDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/run00404/'

#Plots
#rootFileName = 'mtestRecoAnalysis_compareSiliconTrackToStraws.root'  #If using silicon for t0
rootFileName = 'mtestDriftTimesFromOtherView.root'  #If using one straw view to trigger the other
rootFilePath = rootFileDir + "/" + rootFileName
#graphName = 'CompareTrackToStraws/StrawDoublets/g_doubletDriftTimes'   #If using silicon for t0
graphName = 'UTriggersV/g_doubletDriftTimes'   #If using one straw view to trigger the other

#Open input file
rootFile = rh.openFile(rootFilePath)


'''
#
# Doublet drift time pairs profile
#

#Get drift time pair graph
profile = rh.getFromFile(rootFile,rootDirName+"p_doubletDriftTimesCut")

#Fit it
profileFit = TF1("profileFit", "[0] + [1]*x", 15., 35.)
profileFit.SetParameters(50., -1)
profileFit.FixParameter(1,profileFit.GetParameter(1)) #Fix gradient
profile.Fit("profileFit","R") #R enforces range of TF1 for fit
#Define files to read
inputRootDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_merge/data/'
inputFileName = 'mtestDigitsAnalysis_strawTriggerDigitPlots.root'
efficiencyScanFiles = OrderedDict()
inputFiles = OrderedDict()
inputFiles['Ar-CO2 : Run 314'] = inputRootDir + 'run00316/deadTime150ns/' + inputFileName
inputFiles['Ar-Ethane : Run 404'] = inputRootDir + 'run00404/deadTime150ns/' + inputFileName
#inputFiles['Ar-Ethane : Run 405'] = inputRootDir + 'run00405/deadTime150ns/' + inputFileName


#Open all files (keep them in dict so have them in memory simultaneously)
rootFiles = OrderedDict()
for key, rootFileName in inputFiles.iteritems() :
  print key,':',rootFileName
  rootFiles[key] = rh.openFile(rootFileName)


#
# Global layer number for hit histo
#

#Create a fresh canvas
canvas = TCanvas()
canvas.Divide(2)

#Loop over files
counter = 0
for key, rootFile in rootFiles.items() :

  #Get histogram
Example #11
0
import os
#import argparse
import RootHelper as rh

#Define files to read
inputRootDir = '/home/tstuttard/physics/g-2/software/offline/gm2Dev_v6_01_00_testbeam/data/simplestCase_testSiStrawT0/'
recoHitsFileName = mtestRecoAnalysis_strawRecoPlots.root
goodRecoHitsFileName = mtestRecoAnalysis_strawGoodRecoPlots.root
inputFileNames = dict() #TODO Ordered
inputFileNames['Reco hits'] = inputRootDir + recoHitsFileName
inputFileNames['Good reco hits'] = inputRootDir + goodRecoHitsFileName

#Open all files (keep them in dict so have them in memory simultaneously)
rootFiles = dict() #TODO Ordered
for key, rootFileName in inputFileNames.iteritems() :
  rootFiles[key] = rh.openFile(rootFileName)


#
# Track time difference between doublets
#

#Create a fresh canvas
canvas = TCanvas()
canvas.Divide(2)

#Loop over files
counter = 0
for key, rootFile in rootFiles.iteritems() :

  #Get histogram
def combineAndPlotTrajectories(station,perspective,yMin,yMax) :

  mg = TMultiGraph()

  numTrajsPlotted = 0

  #Add "trackable" to path if arg set
  rootDirName = "straw_calo_truth/primary_e+/station_%i" % (station)
  if args.trackable : rootDirName += "/trackable"
  rootDirName += "/trajectories"

  for i_event in range(0,args.numEventsTotal) :

    if args.chosenEvent > 0 :
      if i_event != args.chosenEvent : continue

    #Add trajectory plot to multi graph
    name = rootDirName + "/g_trajInStation%s_evt%05i" % (perspective,i_event+1)
    gr = rh.getFromFile(rootFile,name,False)
    if not gr : continue #Skip if this event didn't return a trajectory (e.g. due to filters)
    gr.SetMarkerStyle(8)
    gr.SetMarkerSize(1)
    mg.Add(gr)

    print "Using event %i" % (i_event)

    #Plot birth point
    birthPoint = TGraph(1)
    x = Double(0)
    y = Double(0)
    gr.GetPoint(0,x,y)
    birthPoint.SetPoint(0,x,y)
    birthPoint.SetMarkerStyle(4)
    birthPoint.SetMarkerColor(kGreen)
    mg.Add(birthPoint)
  
    #Plot death point
    birthPoint = TGraph(1)
    x = Double(0)
    y = Double(0)
    gr.GetPoint(gr.GetN()-1,x,y)
    birthPoint.SetPoint(0,x,y)
    birthPoint.SetMarkerStyle(4)
    birthPoint.SetMarkerColor(kRed)
    mg.Add(birthPoint)

    #Store first graph so can copy titles etc later
    if numTrajsPlotted == 0 :
      storedGraph = gr

    #Break loop if have plotted enough
    numTrajsPlotted += 1
    if numTrajsPlotted >= args.numEventsToPlot: break

  if numTrajsPlotted == 0 : 
    print "No trajectories plotted for \"%s\" perspective in station %i" % (perspective,station)
    return

  print "Number of events plotted = %i" % (numTrajsPlotted)

  #Draw multi graph
  mg.Draw("APL")
  #mg.GetXaxis().SetRangeUser(xMin,xMax) #TODO Can't make larger that range in point x values, FIXME Can this be forced before filling?
  mg.GetYaxis().SetRangeUser(yMin,yMax)
  mg.GetXaxis().SetTitle( storedGraph.GetXaxis().GetTitle() ) #Get axis titles from one of the individual graphs
  mg.GetYaxis().SetTitle( storedGraph.GetYaxis().GetTitle() )
  mg.GetYaxis().SetTitleOffset(1.2)
  mg.GetYaxis().SetTitleOffset(1.5)
  mg.SetTitle( "Decay positron trajectories in station %i (using straw hit positions) : %s" % (station,perspective) )
  mg.Draw("APL")
  raw_input("Press Enter to continue...")
import argparse
import RootHelper as rh
from collections import OrderedDict

#Define files to read
inputRootDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/'
inputFileName = 'mtestDigitsAnalysis_strawTriggerDigitPlots.root'
inputFiles = OrderedDict()
inputFiles['Ar-CO2 : Run 316'] = inputRootDir + 'run00316/' + inputFileName
inputFiles['Ar-Ethane : Run 402'] = inputRootDir + 'run00402/' + inputFileName

#Open all files (keep them in dict so have them in memory simultaneously)
rootFiles = OrderedDict()
for key, rootFileName in inputFiles.items() :
  print key,':',rootFileName
  rootFiles[key] = rh.openFile(rootFileName)


#
# Drift time diff histo
#

#Create a fresh canvas
canvas = TCanvas()
canvas.Divide(2)
#gStyle.SetOptStat(False)

#Loop over files
counter = 0
for key, rootFile in rootFiles.items() :
Example #14
0
#Uses the output ROOT file from TrajectorySanityPlots module

from ROOT import TFile, gROOT, TCanvas, gStyle, TGraph, TMultiGraph, Double, kRed, kGreen, kBlue
import os, argparse, math, sys
import RootHelper as rh

#Get args
parser = argparse.ArgumentParser(description='')
parser.add_argument('-i','--input-file', type=str, required=False, default="./trajectoryPlots.root", help='Input ROOT file containing plots from TrajectorySanityPlots module', dest='inputFile')
parser.add_argument('-nt','--num-events-total', type=int, required=True, dest='numEventsTotal', help='Num events')
parser.add_argument('-np','--num-events-to-plot', type=int, required=True, dest='numEventsToPlot', help='Num events with trajectories plotted' )
args = parser.parse_args()


#Open input file
rootFile = rh.openFile(args.inputFile)



#
# Functions for overlayign trajectories onto single plot
#

def combineAndPlotTrajectories(xaxis,yaxis) :

  mg = TMultiGraph()

  numTrajsPlotted = 0

  for i_event in range(0,args.numEventsTotal) :
Example #15
0
import RootHelper as rh

#Get args
parser = argparse.ArgumentParser(description='')
parser.add_argument('-i','--input-file', type=str, required=False, default="./truthPlots.root", help='Input ROOT file containing plots from DetectorAcceptancePlots module', dest='inputFile')
parser.add_argument('-p','--pause-for-plots', action='store_true', help='Pause to allow user to look at each plot', dest='pauseForPlots')
parser.add_argument('-o','--output-dir', type=str, required=False, default="./", help='Output directory for images', dest='outputDir')
args = parser.parse_args()

#Check output directory exists
if not os.path.isdir(args.outputDir) :
  print "ERROR: Output directory does not exist : [%s]" % (args.outputDir)
  sys.exit(-1)

#Open input file
rootFile = rh.openFile(args.inputFile)


#
# Function for plotting ratio of two histograms
#

def plotRatioOfTwoHistos(numeratorHist,denominatorHist,imgName,title,xtitle,smallestHistScaleFactor=1.) :

  # Get the two histograms
  hn = numeratorHist
  hd = denominatorHist

  # Find which has the largest value
  numeratorHistoHasLargestValue = True if hn.GetMaximum() > hd.GetMaximum() else False
from collections import OrderedDict

# Define files to read
inputRootDir = "/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_merge/data/sim/"
inputFileName = "mtestRecoAnalysis_strawEfficiencyPlots.root"
efficiencyScanFiles = OrderedDict()
efficiencyScanFiles[0.25] = inputRootDir + "strawEff25/" + inputFileName
efficiencyScanFiles[0.5] = inputRootDir + "strawEff50/" + inputFileName
efficiencyScanFiles[0.75] = inputRootDir + "strawEff75/" + inputFileName
efficiencyScanFiles[1.0] = inputRootDir + "strawEff100/" + inputFileName

# Open all files (keep them in dict so have them in memory simultaneously)
rootFiles = OrderedDict()
for efficiency, rootFileName in efficiencyScanFiles.iteritems():
    print efficiency, ":", rootFileName
    rootFiles[efficiency] = rh.openFile(rootFileName)


#
# Num digits in island histo
#

# Create a fresh canvas
canvas = TCanvas()
canvas.Divide(2, 2)
# gStyle.SetOptStat(False)

# Loop over files
counter = 0
for efficiency, rootFile in rootFiles.iteritems():
import math

#Inputs
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/singleOcc/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/singleOcc-Res_140um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/singleOcc-Res_200um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Eff_80/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Res_140um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Res_200um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Eff_80-Res_200um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/run00402/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/run00404/mtestRecoAnalysis_compareSiliconTrackToStraws.root'

#Open input file
rootFile = rh.openFile(rootFileName)



#
# Look at uncertainty in detector offsets
#

gStyle.SetOptStat(0)

glibClockPeriodNs = 25.

#Loop over straw views
views = ["U","V"]
for view in views :
import math

#Inputs
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/singleOcc/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/singleOcc-Res_140um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/singleOcc-Res_200um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Eff_80/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Res_140um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Res_200um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Eff_80-Res_200um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/run00402/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/run00404/mtestRecoAnalysis_compareSiliconTrackToStraws.root'

#Open input file
rootFile = rh.openFile(rootFileName)



#Function to get residuals
def residual(m,c,x,y) :

  #Convert from y=mx+c to more general ax+by+c=0 => a=m,b=-1
  a = m
  b = -1

  #Calculate DCA residual (e.g. perpendicular to line)
  dca = abs( a*x + b*y + c ) / math.sqrt( math.pow(a,2) + math.pow(b,2) )
  sign = 1. if y > m*x+c else -1. #Get sign (+ve means above fit line)
  perpRes = sign * dca
Example #19
0
    # Get args
    parser = argparse.ArgumentParser(description="")
    parser.add_argument("-i", "--input-file", type=str, required=True, help="Input ROOT file", dest="inputFile")
    parser.add_argument(
        "-o", "--output-dir", type=str, required=False, default="./", help="Output directory", dest="outputDir"
    )
    args = parser.parse_args()

    # Check output directory exists
    if not os.path.isdir(args.outputDir):
        print "ERROR: Output directory does not exist : [%s]" % (args.outputDir)
        sys.exit(-1)

    # Open input file
    rootFile = rh.openFile(args.inputFile)
    if not rootFile:
        sys.exit(-1)

    numClosestClustersUsed = 3

    #
    # Drift times
    #

    gStyle.SetOptStat(111111)

    canvas = TCanvas("canvas", "", 800, 600)
    h_firstCrossingTime = rh.getFromFile(rootFile, "h_firstCrossingTime")
    h_firstCrossingTime.SetTitle(";Drift time [ns]")
    h_firstCrossingTime.Draw()
Example #20
0
def plotRatioOfTwoHistos(numeratorHistoName,denominatorHistoName,title,xtitle,addScaledPlot) :

  # Get the two histograms
  hn = rh.getFromFile(rootFile,numeratorHistoName)
  hd = rh.getFromFile(rootFile,denominatorHistoName)

  # Find which has the largest value
  numeratorHistoHasLargestValue = True if hn.GetMaximum() > hd.GetMaximum() else False

  # Normalise
  #hn.Scale( 1. / hn.Integral() )
  #hd.Scale( 1. / hd.Integral() )

  # Define the Canvas
  c = TCanvas("c", "canvas", 800, 800)

  # Upper plot will be in topPad
  topPad = TPad("topPad", "topPad", 0, 0.3, 1, 1.0)
  topPad.SetBottomMargin(0.04) # Upper and lower plot are joined
  topPad.SetGridx()         # Vertical grid
  topPad.Draw()             # Draw the upper pad: topPad
  topPad.cd()               # topPad becomes the current pad
  hn.SetStats(0)          # No statistics on upper plot

  # Draw histo with largest value first (to get correct y axis range), then overlay other
  if numeratorHistoHasLargestValue : 
    hn.SetTitle(title)
    hn.Draw()               # Draw hn
    hd.Draw("same")         # Draw hd on top of hn
  else :
    hd.SetTitle(title)
    hd.Draw()               # Draw hd
    hn.Draw("same")         # Draw hn on top of hd

  # Draw a scaled version of the smaller histo for ease of viewer
  if addScaledPlot :
    hs = hd.Clone("hs") if numeratorHistoHasLargestValue else hn.Clone("hs")
    maxBin = hd.GetMaximumBin() if numeratorHistoHasLargestValue else hn.GetMaximumBin()
    scaleFactor = hn.GetBinContent(maxBin)/hd.GetBinContent(maxBin) if numeratorHistoHasLargestValue else hd.GetBinContent(maxBin)/hn.GetBinContent(maxBin)
    hs.Scale(scaleFactor)
    hs.SetStats(0)
    hs.Draw("same")

  # Do not draw the Y axis label on the upper plot and redraw a small
  # axis instead, in order to avoid the first label (0) to be clipped.

  # lower plot will be in pad
  c.cd()          # Go back to the main canvas before defining bottomPad
  bottomPad = TPad("bottomPad", "bottomPad", 0, 0.05, 1, 0.3)
  bottomPad.SetBottomMargin(0.25)
  bottomPad.SetGridx() # vertical grid
  bottomPad.Draw()
  bottomPad.cd()       # bottomPad becomes the current pad

  # Define the ratio plot
  hr = hn.Clone("hr")
  hr.SetLineColor(kBlack)
  #hr.SetMinimum(0.8)  # Define Y ..
  #hr.SetMaximum(1.35) # .. range
  hr.Sumw2()
  hr.SetStats(0)      # No statistics on lower plot
  hr.Divide(hd)
  hr.Scale(100.)      # Ratio -> percentage
  hr.SetMarkerStyle(21)
  hr.Draw("ep")       # Draw the ratio plot

  # hn settings
  hn.SetLineColor(kBlue+1)
  hn.SetLineWidth(2)

  # X axis hn plot settings
  hn.GetXaxis().SetTitleSize(0)
  hn.GetXaxis().SetLabelSize(0)

  # Y axis hn plot settings
  hn.GetYaxis().SetTitleSize(20)
  hn.GetYaxis().SetTitleFont(43)
  hn.GetYaxis().SetTitleOffset(1.55)

  # hd settings
  hd.SetLineColor(kRed)
  hd.SetLineWidth(2)

  # hs settings
  if addScaledPlot :
    if numeratorHistoHasLargestValue : hs.SetLineColor(kRed)
    else : hs.SetLineColor(kBlue+1)
    hs.SetLineWidth(2)
    hs.SetLineStyle(7)

  # Ratio plot (hr) settings
  hr.SetTitle("") # Remove the ratio title
  hr.GetXaxis().SetTitle(xtitle)

  # Y axis ratio plot settings
  hr.GetYaxis().SetTitle("ratio (%)")
  hr.GetYaxis().SetNdivisions(505)
  hr.GetYaxis().SetTitleSize(20)
  hr.GetYaxis().SetTitleFont(43)
  hr.GetYaxis().SetTitleOffset(1.55)
  hr.GetYaxis().SetLabelFont(43) # Absolute font size in pixel (precision 3)
  hr.GetYaxis().SetLabelSize(15)

  # X axis ratio plot settings
  hr.GetXaxis().SetTitleSize(20)
  hr.GetXaxis().SetTitleFont(43)
  hr.GetXaxis().SetTitleOffset(4.)
  hr.GetXaxis().SetLabelFont(43) # Absolute font size in pixel (precision 3)
  hr.GetXaxis().SetLabelSize(15)

  # Set ratio plot x axis range
  minNonZeroBinContent = 1.e99
  for i_bin in range(1,hr.GetXaxis().GetNbins()+1) :
    binContent = hr.GetBinContent(i_bin)
    if binContent > 0. :
      minNonZeroBinContent = min(binContent,minNonZeroBinContent) 
  hr.GetYaxis().SetRangeUser(minNonZeroBinContent*0.6,hr.GetMaximum()*1.4)

  # wait so user can see the plot
  raw_input("Press Enter to continue...")
Example #21
0
#Define files to read
inputRootDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_merge/data/'
inputFileName = 'mtestRecoAnalysis_strawEfficiencyPlots.root'
efficiencyScanFiles = OrderedDict()
inputFiles = OrderedDict()
inputFiles[1500.] = inputRootDir + 'run00359/deadTime150ns/' + inputFileName
inputFiles[1600.] = inputRootDir + 'run00372/deadTime150ns/' + inputFileName
inputFiles[1700.] = inputRootDir + 'run00390/deadTime150ns/' + inputFileName
inputFiles[1800.] = inputRootDir + 'run00405/deadTime150ns/' + inputFileName

#Open all files (keep them in dict so have them in memory simultaneously)
rootFiles = OrderedDict()
for hv, rootFileName in inputFiles.iteritems() :
  print str(hv)+'V',':',rootFileName
  rootFiles[hv] = rh.openFile(rootFileName)


#
# Num digits in island histo
#

#Create a fresh canvas
canvas = TCanvas()
canvas.Divide(2,2)
#gStyle.SetOptStat(False)

#Loop over files
counter = 0
for hv, rootFile in rootFiles.items() :
inputFiles['Ar-Ethane : Run 404'] = inputRootDir + '/run00404/deadTime150ns/' + inputFileName
#inputFiles['Ar-Ethane : Run 405'] = inputRootDir + '/run00405/deadTime150ns/' + inputFileName

#Also define normalisations (expected # protons per MTest spill after considering DAQ active time)
numProtonsExpected = OrderedDict()
#numProtonsExpected['Sim : 100% efficiency : 0% MO'] = 5000.
#numProtonsExpected['Sim : 40% efficiency : 35% MO'] = 5000.
numProtonsExpected['Sim : 50% efficiency : 35% MO'] = 5000.
numProtonsExpected['Ar-Ethane : Run 404'] = 50000.
#numProtonsExpected['Ar-Ethane : Run 405'] = 50000.

#Open all files (keep them in dict so have them in memory simultaneously)
rootFiles = OrderedDict()
for key, rootFileName in inputFiles.iteritems() :
  print key,':',rootFileName
  rootFiles[key] = rh.openFile(rootFileName)


#
# Num digits in island histo
#

#Create a fresh canvas
canvas = TCanvas()
canvas.Divide(2)
#gStyle.SetOptStat(False)

#Loop over files
counter = 0
for key, rootFile in rootFiles.items() :
Example #23
0
#Compare calibration scan results in different fibers

from ROOT import TFile, gROOT, TCanvas, gStyle, TGraph, TMultiGraph, Double, kRed, kGreen, kBlue, TLegend
import os, argparse, math, sys
import RootHelper as rh

#Get args
parser = argparse.ArgumentParser(description='')
parser.add_argument('-i','--input-file', type=str, required=False, default="./fiberHarpCalibrationPlots.root", \
                    help='Input ROOT file containing plots from FiberHarpCalibrationScan module', dest='inputFile')
args = parser.parse_args()

#Open input file
rootFile = rh.openFile(args.inputFile)
if not rootFile : sys.exit(-1)

gStyle.SetOptStat(0)

#Prepare multi-graphs
mg_x_amplitude = TMultiGraph()
leg_x_amplitude = TLegend(0.4,0.6,0.7,0.8)

mg_x_area = TMultiGraph()
leg_x_area = TLegend(0.4,0.6,0.7,0.8)

#
# Loop over fibers
#

for i_fiber in range(0,7) :
Example #24
0
  #Init plotting
  gStyle.SetOptStat(111111)


  #
  # Loop over input files
  #

  i_file = 0 

  for inputFile in inputFiles :

    #Open input file
    print "\n+++ Opening %s\n" % (inputFile)
    rootFile = rh.openFile(inputFile)
    if not rootFile : sys.exit(-1)

    #Get run info tree
    t_runInfo = rh.getFromFile(rootFile,"Garfield/RunInfo")
    t_runInfo.GetEntry(0) #Only one entry

    #
    # Event loop
    #

    #Get event tree
    t_event = rh.getFromFile(rootFile,"Garfield/Events")

    #Get mean gain for this run
    tmpHistName = "h_tmp_%i" % (i_file)
#Compare gain correction for each crystal

from ROOT import TFile, gROOT, TCanvas, gStyle, TGraph, TMultiGraph, Double, kRed, kGreen, kBlue
import os, argparse, math, sys
import RootHelper as rh

#Get args
parser = argparse.ArgumentParser(description='')
parser.add_argument('-i','--input-file', type=str, required=False, default="./validateGainCorrection.root", help='Input ROOT file containing plots from ValidateGainCorrection module', dest='inputFile')
args = parser.parse_args()

#Open input file
rootFile = rh.openFile(args.inputFile)
if not rootFile : sys.exit(-1)

gStyle.SetOptStat(0)



#
# Compare laser cluster E
#

clusterRootDirName = "gain_correction/clusters"

mg_laserClusters = TMultiGraph()

g_meanLaserEnergy = rh.getFromFile(rootFile,clusterRootDirName+'/g_meanLaserEnergy')
g_meanLaserEnergy.SetMarkerStyle(1)
g_meanLaserEnergy.SetMarkerSize(1)
g_meanLaserEnergy.SetMarkerColor(kRed)
Example #26
0
import RootHelper as rh
from collections import OrderedDict

#Define files to read
inputRootDir = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/'
inputFileName = 'mtestRecoAnalysis_strawRecoPlots.root'
efficiencyScanFiles = OrderedDict()
inputFiles = OrderedDict()
inputFiles['Ar-CO2 : Run 316'] = inputRootDir + '/run00316/' + inputFileName
inputFiles['Ar-Ethane : Run 402'] = inputRootDir + '/run00402/' + inputFileName

#Open all files (keep them in dict so have them in memory simultaneously)
rootFiles = OrderedDict()
for key, rootFileName in inputFiles.iteritems() :
  print key,':',rootFileName
  rootFiles[key] = rh.openFile(rootFileName)


#
# Num digits in island histo
#

#Create a fresh canvas
canvas = TCanvas()
canvas.Divide(2)
#gStyle.SetOptStat(False)

#Loop over files
counter = 0
for key, rootFile in rootFiles.items() :
from ROOT import TFile, TTree, gROOT, TH1F, TCanvas, gStyle, TF1, TProfile, TH2F, TGraph, TF1, Double, TCut
from sys import exit
import os
import argparse
import RootHelper as rh
import math

# Inputs
rootFileName = "/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/run00344/mtestRecoAnalysis_reconstructedSiTrackPlots.root"

# Open input file
rootFile = rh.openFile(rootFileName)


#
# Compare first and last stations
#

# Get drift time pair graph
gr = rh.getFromFile(rootFile, "Station_0/g_YvsY_Station_3")

# Fit it
fit = TF1("fit", "[0] + [1]*x", -10.0e3, 10.0e3)
fit.SetParameters(0.0, 1.0)
# fit.FixParameter(1,fit.GetParameter(1)) #Fix gradient
gr.Fit("fit", "R")  # R enforces range of TF1 for fit
fitIntercept = fit.GetParameter(0)
fitSlope = fit.GetParameter(1)

# Draw it
# gr.GetXaxis().SetRangeUser(-10.,60.)
import argparse
import RootHelper as rh
import math

#Inputs
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/singleOcc/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/singleOcc-Res_140um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/singleOcc-Res_200um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Eff_80/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/sim/MO_80_15_5-Res_140um/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/run00402/mtestRecoAnalysis_compareSiliconTrackToStraws.root'
#rootFileName = '/unix/muons/g-2/scratch/tom/sim/gm2Dev_v6_01_00_testbeam_coordSystems/data/testbeam/run00404/mtestRecoAnalysis_compareSiliconTrackToStraws.root'

#Open input file
rootFile = rh.openFile(rootFileName)

gStyle.SetOptStat(0)


#
# Fit y residuals
#

#Get histo
h_yResiduals = rh.getFromFile(rootFile,'CompareTrackToStraws/StrawRecoHits/h_recoHitToTrackYResidual')

#Fit core
f_yResiduals = TF1("f_yResiduals", "gaus", -500., 500.);
h_yResiduals.Fit("f_yResiduals","R")
inputFileName = "mtestRecoAnalysis_eventSelectionPlots.root"
efficiencyScanFiles = OrderedDict()
inputFiles = OrderedDict()
inputFiles["Sim : 0% cross-talk"] = inputRootDir + "/sim/strawEff40/MO-60-30-8-2/deadTime150ns/" + inputFileName
inputFiles["Sim : 1% cross-talk"] = (
    inputRootDir + "/sim/strawEff40/MO-60-30-8-2/deadTime150ns_crossTalk1/" + inputFileName
)
inputFiles["Sim : 5% cross-talk"] = (
    inputRootDir + "/sim/strawEff40/MO-60-30-8-2/deadTime150ns_crossTalk5/" + inputFileName
)

# Open all files (keep them in dict so have them in memory simultaneously)
rootFiles = OrderedDict()
for key, rootFileName in inputFiles.iteritems():
    print key, ":", rootFileName
    rootFiles[key] = rh.openFile(rootFileName)


#
# Cross-talk in same layer
#

strawDir = "EventSelection/Islands/Station_0/"

# Create a fresh canvas
canvas = TCanvas()
canvas.Divide(3)

# Loop over files
counter = 0
for key, rootFile in rootFiles.items():