hdus = ntc.getNTupleNames ( full_path ) print "Names of the Header/Data Units are..." print hdus events = ntc.createNTuple ( full_path, hdus[1] ) print "Names of the columns" labels = events.getLabels() print labels from hippo import Display # # Create a 1D histogram # hist = Display ( "Histogram", events, ('GLON', ) ) canvas.addDisplay ( hist ) # # Create a cut and set its range # from hippo import Cut cut1 = Cut ( events, ( 'zenith_angle', ) ) canvas.addDisplay ( cut1 ) cut1.setCutRange ( 80., 100., 'x' ) # # Create a another cut and set its range # cut2 = Cut ( events, ( 'energy', ) ) canvas.addDisplay ( cut2 )
hdu_names = fc.getNTupleNames(fullname) print "Names of the HDUs are ", hdu_names darray = fc.createDataArray(fullname, hdu_names[1]) # pass the empty image print "Number of columns = ", darray.columns print "Column labels are ..." print darray.getLabels() print "Number of rows = ", darray.rows import hippo app = hippo.HDApp() canvas = app.canvas() plot = Display("Color Plot", darray, ('GLON', 'GLAT', 'nil', 'nil')) canvas.addDisplay(plot) # # Calculate Log(energy) and add it as new column # import numarray darray['LogE'] = numarray.log(darray['energy']) lplot = Display('Histogram', darray, ('LogE', )) lplot.setLog('y', True) canvas.addDisplay(lplot) # # Compare it with logrithmic binning #
from hippo import DataArray da = DataArray ( 'NTuple' ) # use NTuple to store data da.register ( 'randomized line' ) # name the data source # Fill the contents by adding named columns in the order expected by # the fitter (more later) da['x'] = x da['y'] = y da['xerr'] = xerr da['yerr'] = yerr # Create an XY plot, ignoring xerr, and add it to the canvas. from hippo import Display disp = Display ('XY Plot', da, ('x', 'y', 'nil', 'yerr' ) ) canvas.addDisplay ( disp ) # Get the name of the available fitters from the factory from hippo import FitterFactory factory = FitterFactory.instance() fitters = factory.names() print fitters # Create a fitter, in this case Minuit Migrad algorithm with Chi Sq migrad = factory.create ( fitters[1] ) print migrad.name() # create a function f = Linear ()
da = DataArray('NTuple') # use NTuple to store data da.register('randomized line') # name the data source # Fill the contents by adding named columns in the order expected by # the fitter (more later) da['x'] = x da['y'] = y da['xerr'] = xerr da['yerr'] = yerr # Create an XY plot, ignoring xerr, and add it to the canvas. from hippo import Display disp = Display('XY Plot', da, ('x', 'y', 'nil', 'yerr')) canvas.addDisplay(disp) # Get the name of the available fitters from the factory from hippo import FitterFactory factory = FitterFactory.instance() fitters = factory.names() print fitters # Create a fitter, in this case Minuit Migrad algorithm with Chi Sq migrad = factory.create(fitters[1]) print migrad.name() # create a function f = Linear()
""" Demonstrates making simple XY plot. author Paul F. Kunz <*****@*****.**> """ # # load the HippoDraw module # from load_hippo import app, canvas from hippo import Display # Create list of data energy = [90.74, 91.06, 91.43, 91.50, 92.16, 92.22, 92.96, 89.24, 89.98, 90.35] sigma = [29.0, 30.0, 28.40, 28.80, 21.95, 22.90, 13.50, 4.50, 10.80, 24.20] errors = [5.9, 3.15, 3.0, 5.8, 7.9, 3.1, 4.6, 3.5, 4.6, 3.6] # make a plot to test it. xy = Display("XY Plot", [energy, sigma, errors], ['Energy', 'Sigma', 'nil', 'error']) canvas.addDisplay(xy) xy.setTitle('Mark II Z0 scan') print "An XY plot is now displayed. You can use the Inspector dialog" print "to modify the appearance or fit a function to it."
# Get the top level tree names from the file ntuple_names = rc.getNTupleNames ( filename ) print "In this file, tree names are ", ntuple_names # Create a data array from the first tree ntuple = rc.createDataArray ( filename, 'MeritTuple' ) # Pprint some information about this tree print "Number of columns = ", ntuple.columns labels = ntuple.getLabels() print "First ten column labels are ... ", labels[:10] print "Number of rows = ", ntuple.rows # Create a histogram for one of the columns and add it to the canvas hist = Display ( "Histogram", ntuple, ('TkrEnergy', ) ) # Up to now, we didn't need the HippoDraw application running. # Now we do in order to view the data. app = HDApp() canvas = app.canvas() canvas.addDisplay ( hist ) # Set the Y axis on log scale of better viewing hist.setLog ( 'y', True ) # Add a cut from data in another column from hippo import Cut hits_cut = Cut ( ntuple, ('TkrTotalHits',) ) canvas.addDisplay ( hits_cut ) hits_cut.setLog ( 'y', True )
nt = NTuple () nt.setLabels ( [ 'x' ] ) xmin = 1. xmax = 100. gamma = 2.1 xpmax = math.pow ( xmax, 1. - gamma ) xpmin = math.pow ( xmin, 1. - gamma ) nsamp = 10000 for i in range(nsamp): x = shoot(0, 1) xx = math.pow ( x*( xpmax - xpmin ) + xpmin, 1./ (1. - gamma) ) nt.addRow ( (xx, ) ) from hippo import Display hist = Display ( 'Histogram', nt, ( 'x', ) ) canvas.addDisplay ( hist ) # Set the x and y axis on log scale hist.setLog ( 'x', True ) hist.setLog ( 'y', True ) # fit to power law function from hippo import Function datarep = hist.getDataRep () powerlaw = Function ( "PowerLaw", datarep ) powerlaw.addTo( hist ) powerlaw.fit()
hdus = ntc.getNTupleNames ( full_path ) print "Names of the Header/Data Units are..." print hdus events = ntc.createDataArray ( full_path, hdus[1] ) # Set matrix of ploats canvas.setPlotMatrix ( 3, 3 ) from hippo import Display, Cut # # Create a 1D histogram # hist = Display ( "Histogram", events, ('GLON', ) ) canvas.addDisplay ( hist ) # # First create cuts individually # from hippo import Cut cut1 = Cut ( events, ( 'zenith_angle', ) ) canvas.addDisplay ( cut1 ) cut1.setCutRange ( 80., 100., 'x' ) # # Create a another cut and set its range # cut2 = Cut ( events, ( 'energy', ) ) canvas.addDisplay ( cut2 )
# # If GemConditionsWord == 7., then fill element with `nbrTkrTriggered', # otherwise with -1 # daSvac [ label_TowerTkrTrigGemCond ] = \ numarray.choose ( t, ( nbrTkrTriggered, -1 ) ) daSvac [ label_TowerCalLeTrigGemCond ] = \ numarray.choose ( t, ( nbrCalLeTriggered, -1 ) ) tend = time.time() print "Took %f seconds create the 4 new columns with 500,000 rows each" % \ (tend -tstart) # # The rest is standard procedure # tkrtrighist = Display ("Histogram", daSvac, (label_TkrTriggered,) ) canvas.addDisplay ( tkrtrighist ) tkrtrighist.setLog ( 'y', True) calletrighist = Display ("Histogram", daSvac, (label_CalLeTriggered, ) ) canvas.addDisplay ( calletrighist ) calletrighist.setLog ( 'y', True) tkrtrighist_gemcond = Display ( "Histogram", daSvac, (label_TowerTkrTrigGemCond, ) ) canvas.addDisplay ( tkrtrighist_gemcond ) tkrtrighist_gemcond.setRange ( 'x', 0, 16) tkrtrighist_gemcond.setLog ( 'y', True) print tkrtrighist_gemcond.numberOfEntries()
# Create NTuple with its controller so Inspector can see it. # from hippo import NTupleController ntc = NTupleController.instance() # # Create full path to example file in case this script is not run from # this directory. # full_path = sys.path[0] + '/' + 'aptuple.tnt' nt1 = ntc.createNTuple ( full_path ) canvas.setPlotMatrix ( 2, 3 ) from hippo import Display hist = Display ( "Histogram", nt1, ("Cost", ) ) canvas.addDisplay( hist ) # Get the data representation so we can add function to it. datarep1 = hist.getDataRep() from hippo import Function gauss = Function ( "Gaussian", datarep1 ) gauss.addTo ( hist ) # Get the function parameters and display them. print "Before fitting" parmnames = gauss.parmNames ( ) print parmnames parms = gauss.parameters ( ) print parms
hdus = ntc.getNTupleNames ( full_path ) print "Names of the Header/Data Units are..." print hdus events = ntc.createNTuple ( full_path, hdus[1] ) print "Names of the columns" labels = events.getLabels() print labels from hippo import Display # # Create a 1D histograms # hist1 = Display ( "Histogram", events, ('GLON', ) ) canvas.addDisplay ( hist1 ) hist2 = Display ( "Histogram", events, ('GLAT', ) ) canvas.addDisplay ( hist2 ) # # Create a cut # cut = hippo.Cut ( events, ( 'zenith_angle', ) ) canvas.addDisplay ( cut ) cut.setCutRange ( 80., 90., 'x' ) # # Add this cut to multiple displays ( a Python tuple of displays ). # cut.addTargets ( ( hist1, hist2 ) )
print "Names of the Header/Data Units are..." print hdus events = ntc.createNTuple(full_path, hdus[1]) print "Names of the columns" labels = events.getLabels() print labels from hippo import Display # # Create the displays. # hist = Display("Histogram", events, ('energy', )) hist.setLog('x', True) hist.setLog('y', True) canvas.addDisplay(hist) color = Display("Color Plot", events, ('GLON', 'GLAT')) color.setRange('z', 0.5, 150.) color.setLog('z', True) canvas.addDisplay(color) contour = Display("Contour Plot", events, ('time', 'GLON')) canvas.addDisplay(contour) profile = Display("Profile", events, ('time', 'energy')) canvas.addDisplay(profile)
app = hippo.HDApp() canvas = app.canvas() plot = Display("Color Plot", darray, ("GLON", "GLAT", "nil", "nil")) canvas.addDisplay(plot) # # Calculate Log(energy) and add it as new column # import numarray darray["LogE"] = numarray.log(darray["energy"]) lplot = Display("Histogram", darray, ("LogE",)) lplot.setLog("y", True) canvas.addDisplay(lplot) # # Compare it with logrithmic binning # clplot = Display("Histogram", darray, ("energy",)) canvas.addDisplay(clplot) clplot.setLog("x", True) clplot.setLog("y", True) # # Apply a cut to the displays # cut = hippo.Cut(darray, ("time",))
print "Names of the Header/Data Units are..." print hdus events = ntc.createNTuple(full_path, hdus[1]) print "Names of the columns" labels = events.getLabels() print labels from hippo import Display # # Create the displays. # hist = Display("Histogram", events, ("energy",)) hist.setLog("x", True) hist.setLog("y", True) canvas.addDisplay(hist) color = Display("Color Plot", events, ("GLON", "GLAT")) color.setRange("z", 0.5, 150.0) color.setLog("z", True) canvas.addDisplay(color) contour = Display("Contour Plot", events, ("time", "GLON")) canvas.addDisplay(contour) profile = Display("Profile", events, ("time", "energy")) canvas.addDisplay(profile)
Demonstraton of static versus dynamic histograms. Also demonstrates taking difference between two histograms and plotting it. @author Paul F. Kunz <*****@*****.**> """ import random from time import sleep from load_hippo import app, canvas from hippo import Display, NTuple, NTupleController # Create static histogram and add it to canvas. sthist = Display ( "Static Histogram" ) sthist.setTitle ( "Gaussian Distribution (static hist)" ) sthist.setLabel ( 'x', 'X' ) sthist.setRange ( 'x', 0, 100) sthist.setBinWidth ( 'x', 1. ) canvas.addDisplay ( sthist ) # Create second static histogram and add it to canvas sthists = Display ( "Static Histogram" ) sthists.setTitle ( "Gaussian Distribution (low statistics)" ) sthists.setLabel ( 'x', 'X' ) sthists.setRange ( 'x', 0, 100) sthists.setBinWidth ( 'x', 1. ) canvas.addDisplay ( sthists ) # Create empty NTuple and set the column label.
nt = NTuple() nt.setLabels(['x']) xmin = 1. xmax = 100. gamma = 2.1 xpmax = math.pow(xmax, 1. - gamma) xpmin = math.pow(xmin, 1. - gamma) nsamp = 10000 for i in range(nsamp): x = shoot(0, 1) xx = math.pow(x * (xpmax - xpmin) + xpmin, 1. / (1. - gamma)) nt.addRow((xx, )) from hippo import Display hist = Display('Histogram', nt, ('x', )) canvas.addDisplay(hist) # Set the x and y axis on log scale hist.setLog('x', True) hist.setLog('y', True) # fit to power law function from hippo import Function datarep = hist.getDataRep() powerlaw = Function("PowerLaw", datarep) powerlaw.addTo(hist) powerlaw.fit()
nt1 = ntc.createNTuple ( full_path ) from hippo import Display # Change the matrix from the default canvas.setPlotMatrix ( 3, 4 ) # Create the displays. hist = Display ("Histogram", nt1, ('Cost', ) ) canvas.addDisplay( hist ) profile = Display ( "Profile", nt1, ('Age', 'Cost' )) canvas.addDisplay ( profile ) color = Display ( "Color Plot", nt1, ('Age', 'Cost' )) color.setBinWidth ( 'x', 1.0 ) canvas.addDisplay ( color ) contour = Display ( "Contour Plot", nt1, ('Age', 'Cost' )) contour.setBinWidth ( 'x', 1.0 ) canvas.addDisplay ( contour ) profile2D = Display ( "Profile 2D", nt1, ('Age', 'Cost', 'Service' )) canvas.addDisplay ( profile2D ) profileC = Display ( "Profile Contour", nt1, ('Age', 'Cost', 'Service' )) canvas.addDisplay ( profileC ) scatter = Display ( "Scatter Plot", nt1, ('Age', 'Cost' )) canvas.addDisplay ( scatter )
hdus = ntc.getNTupleNames(full_path) print "Names of the Header/Data Units are..." print hdus events = ntc.createNTuple(full_path, hdus[1]) print "Names of the columns" labels = events.getLabels() print labels from hippo import Display # # Create a 1D histogram # hist = Display("Histogram", events, ('GLON', )) canvas.addDisplay(hist) # # Create a cut and set its range # from hippo import Cut cut1 = Cut(events, ('zenith_angle', )) canvas.addDisplay(cut1) cut1.setCutRange(80., 100., 'x') # # Create a another cut and set its range # cut2 = Cut(events, ('energy', )) canvas.addDisplay(cut2)
from hippo import NTupleController # Create NTuple with its's controller. ntc = NTupleController.instance() # # create full path to the file in case this script is not run from this # directory # import sys full_path = sys.path[0] + '/' + 'aptuple.tnt' nt = ntc.createNTuple ( full_path ) from hippo import Display # Create a histogram hist = Display ("Histogram", nt, ('Age', ) ) canvas.addDisplay( hist ) # Overlay another histogram. hist.addDataRep ( 'Histogram', nt, ['Service'] ) # # Set the line style and color # reps = hist.getDataReps () from hippo import Line print "The available line styles are ..." print Line.values print "" try : reps[1].set ( Line.dash )
from hippo import NTupleController # Create NTuple with its's controller. ntc = NTupleController.instance() # # create full path to the file in case this script is not run from this # directory # import sys full_path = sys.path[0] + '/' + 'aptuple.tnt' nt = ntc.createNTuple(full_path) from hippo import Display # Create a histogram hist = Display("Histogram", nt, ('Age', )) canvas.addDisplay(hist) # Overlay another histogram. hist.addDataRep('Histogram', nt, ['Service']) # # Set the line style and color # reps = hist.getDataReps() from hippo import Line print "The available line styles are ..." print Line.values print "" try: reps[1].set(Line.dash)
""" Demonstrates making simple XY plot. author Paul F. Kunz <*****@*****.**> """ # # load the HippoDraw module # from load_hippo import app, canvas from hippo import Display # Create list of data energy = [90.74, 91.06, 91.43, 91.50, 92.16, 92.22, 92.96, 89.24, 89.98, 90.35] sigma = [ 29.0, 30.0, 28.40, 28.80, 21.95, 22.90, 13.50, 4.50, 10.80, 24.20] errors = [ 5.9, 3.15, 3.0, 5.8, 7.9, 3.1, 4.6, 3.5, 4.6, 3.6] # make a plot to test it. xy = Display ( "XY Plot", [ energy, sigma, errors ], ['Energy', 'Sigma', 'nil', 'error' ] ) canvas.addDisplay ( xy ) xy.setTitle ( 'Mark II Z0 scan' ) print "An XY plot is now displayed. You can use the Inspector dialog" print "to modify the appearance or fit a function to it."