コード例 #1
0
def makeHistos(hfile, dir = ""):
	
	#first setup stats box
	gStyle.SetOptStat(args.statistics)
	
	
	for key in hfile.GetKeys(dir):
		active_dir = histodir + dir
		ensure_dir(active_dir)
		tclass = gROOT.GetClass(key.GetClassName())
		
		if tclass.InheritsFrom("TDirectory"):
			if args.recursion:
				makeHistos(hfile, key.ReadObj().GetPath()[len(args.path + ":/"):] + "/") #call the function with the sub directory
		if not tclass.InheritsFrom("TH1"):
			continue
			
		if tclass.InheritsFrom("TH1") and args.logarithm:
			c1.SetLogy(1)
			
			if tclass.InheritsFrom("TH2"): #if it is 2d we want to disable logy and enable logz
				c1.SetLogy(0)
				c1.SetLogz(1)
		
			
			
		histo = key.ReadObj()
		
		if tclass.InheritsFrom("TH2"):
			histo.Draw("colz" + args.draw2D)
		else:
			histo.Draw("colz" + args.draw1D)
		
		c1.Update()
		c1.Print(active_dir + key.GetName() + ".png")
コード例 #2
0
def copy_directory(newdir, olddir, condition=None):
    """Reads all objects from olddir and writes them to newdir.

    newdir, olddir: Directories (inheriting from TDirectory).
    condition: Function that takes key name and returns whether the file should
        be kept or not (optional).
    """
    for key in olddir.GetListOfKeys():
        if condition is not None and (not condition(key) or
                                      key.GetName().startswith('ProcessID')):
            continue
        cl = gROOT.GetClass(key.GetClassName())
        if not cl:
            continue
        if cl.InheritsFrom(TDirectory.Class()):
            newsub = newdir.mkdir(key.GetName())
            oldsub = olddir.GetDirectory(key.GetName())
            copy_directory(newsub, oldsub)
        elif cl.InheritsFrom(TTree.Class()):
            oldtree = olddir.Get(key.GetName())
            newdir.cd()
            newtree = oldtree.CloneTree(-1, 'fast')
            newtree.Write()
        else:
            olddir.cd()
            obj = key.ReadObj()
            newdir.cd()
            obj.Write(key.GetName())
            del obj
コード例 #3
0
def getObjects(dir, type='TH1'):
    objs = []
    for key in dir.GetListOfKeys():
        if gROOT.GetClass(key.GetClassName()).InheritsFrom(type):
            objname = key.GetName()
            obj = dir.Get(objname)
            obj.SetName(objname)  # if key name != obj name
            objs.append(obj)
    return objs
コード例 #4
0
ファイル: plot_hex.py プロジェクト: b-fontana/HGCal
def keyTitleMap(keylist):
    """
    Creates a map linking histogram titles to keys.
    Arguments:
    -> keylist: The list of keys from which the map is created
    Returns:
    -> a map
    """
    m = {}
    for k in keylist:
        if not gROOT.GetClass(k.GetClassName()).InheritsFrom('TH1'):
            continue
        m.update({k.ReadObj().GetTitle(): k})
    return m
コード例 #5
0
ファイル: printHistoFile.py プロジェクト: atpathak/ATLAS
def printDirectory(directory, prefix, args):
    for key in directory.GetListOfKeys():
        classname = key.GetClassName()
        cl = gROOT.GetClass(classname)
        if (not cl):
            continue
        if (cl.InheritsFrom(TDirectory.Class())):
            print prefix, key.GetName()
            printDirectory(key.ReadObj(), prefix + "   ", args)
        elif (cl.InheritsFrom(TH1.Class())):
            hist = key.ReadObj()
            if args.systematics or hist.GetName(
            ) == "nominal" or hist.GetTitle() == "nominal":
                if args.full:
                    print prefix, hist.GetName(), hist.GetSumOfWeights()
                    for i in range(0, hist.GetNbinsX() + 2):
                        print prefix, "   ", hist.GetBinContent(
                            i), " +/- ", hist.GetBinError(i)
                else:
                    print prefix, key.GetName(), hist.GetSumOfWeights()
        else:
            print "Unknown", key.GetName()
コード例 #6
0
    if len(sys.argv) < 4:
        print 'Too few arguments:', sys.argv
        exit(-1)

    fplots = TFile(sys.argv[1])  # Plots file
    fbinning = TFile(sys.argv[2])  # Binning file
    fout = TFile(sys.argv[3], 'recreate')  # Output file

    for key in fplots.GetListOfKeys():

        name = key.GetName()

        # Pick only the category name
        name = 'bins_' + name[name.find('hh'):]

        if not gROOT.GetClass(key.GetClassName()).InheritsFrom("TH1"):
            print 'Skipping', key.GetClassName(), ':', name
            continue

        print 'Processing', name

        # Get hist from plots file
        hplot = key.ReadObj()

        # Get hist from binning file
        hbinning = fbinning.Get('binning/%s' % name)
        nbins = hbinning.GetNbinsX()

        # Adjust bins
        bins = [0] * (nbins + 1)
        bins = array('d', bins)
コード例 #7
0
    def test3ObjectCallHeuristics(self):
        """Test memory mgmt heuristics for object calls"""

        MemTester = ROOT.MemTester
        kMemoryStrict = ROOT.kMemoryStrict
        kMemoryHeuristics = ROOT.kMemoryHeuristics

        # reference calls should not give up ownership
        a = MemTester()
        self.assertEqual(MemTester.counter, 1)
        MemTester.CallRef(a)
        self.assertEqual(MemTester.counter, 1)

        self.set_mem_policy(MemTester.CallRef, kMemoryStrict)
        MemTester.CallRef(a)
        self.assertEqual(MemTester.counter, 1)

        self.set_mem_policy(MemTester.CallRef, kMemoryHeuristics)
        MemTester.CallRef(a)
        self.assertEqual(MemTester.counter, 1)

        del a
        self.assertEqual(MemTester.counter, 0)

        MemTester.CallConstRef(MemTester())
        self.assertEqual(MemTester.counter, 0)

        # give up ownership in case of non-const pointer call only, unless overridden
        MemTester.CallConstPtr(MemTester())
        self.assertEqual(MemTester.counter, 0)

        self.set_mem_policy(MemTester.CallConstPtr, kMemoryStrict)
        MemTester.CallConstPtr(MemTester())
        self.assertEqual(MemTester.counter, 0)

        self.set_mem_policy(MemTester.CallConstPtr, kMemoryHeuristics)
        MemTester.CallConstPtr(MemTester())
        self.assertEqual(MemTester.counter, 0)

        b1 = MemTester()
        self.assertEqual(MemTester.counter, 1)
        MemTester.CallPtr(b1)
        self.assertEqual(MemTester.counter, 1)
        del b1
        counter = 1
        self.assertEqual(MemTester.counter, counter)

        b2 = MemTester()
        counter += 1
        self.assertEqual(MemTester.counter, counter)
        SetMemoryPolicy(kMemoryStrict)
        MemTester.CallPtr(b2)
        self.assertEqual(MemTester.counter, counter)
        del b2
        counter -= 1
        self.assertEqual(MemTester.counter, counter)

        b3 = MemTester()
        counter += 1
        self.assertEqual(MemTester.counter, counter)
        SetMemoryPolicy(kMemoryHeuristics)
        MemTester.CallPtr(b3)
        self.assertEqual(MemTester.counter, counter)
        del b3
        self.assertEqual(MemTester.counter, counter)

        b4 = MemTester()
        counter += 1
        self.assertEqual(MemTester.counter, counter)
        self.set_mem_policy(MemTester.CallPtr, kMemoryStrict)
        MemTester.CallPtr(b4)
        self.assertEqual(MemTester.counter, counter)
        del b4
        counter -= 1
        self.assertEqual(MemTester.counter, counter)

        b5 = MemTester()
        counter += 1
        self.assertEqual(MemTester.counter, counter)
        SetMemoryPolicy(kMemoryStrict)
        self.set_mem_policy(MemTester.CallPtr, kMemoryHeuristics)
        MemTester.CallPtr(b5)
        self.assertEqual(MemTester.counter, counter)
        del b5
        self.assertEqual(MemTester.counter, counter)

        # test explicit destruction
        SetMemoryPolicy(kMemoryHeuristics)
        MemTester().counter = 1  # silly way of setting it to 0
        self.set_mem_policy(MemTester.CallPtr, kMemoryHeuristics)
        self.assertEqual(MemTester.counter, 0)
        c = MemTester()
        self.assertEqual(MemTester.counter, 1)
        MemTester.CallPtr(c)
        self.assertEqual(MemTester.counter, 1)
        klass = gROOT.GetClass('MemTester')
        klass.Destructor(c)
        self.assertEqual(MemTester.counter, 0)
        del c  # c not derived from TObject, no notification
        self.assertEqual(MemTester.counter, 0)
コード例 #8
0
print "Time now: ", now, "s. Last modification of reference file: ", mtimeref, "s. Diff = ", now - mtimeref, "s. Age of reference file in weeks: ", weekold
if weekold == 2:
    "Warning! Could be older than this.."
release_current = "rel_" + str(day)
release_previous = "rel_" + str(dayref)
print "Current release: ", release_current, " Reference release: ", release_previous

# get trigger counts histograms from input .root file
directory = inputfile.GetDirectory(basePathExpert)
next = ROOT.TIter(directory.GetListOfKeys())
key = 1
triggerhistos_inputfile = []
while (key != 0):
    key = next()
    if key == None: break
    cl = gROOT.GetClass(key.GetClassName())
    if (cl.InheritsFrom("TH1") == False): continue
    h = key.ReadObj()
    if "trigger_counts" in h.GetName():
        triggerhistos_inputfile.append(h.GetName())

print "Trigger count histograms in current file: ", triggerhistos_inputfile

if doReference == True:  # read reference file
    inputfile_reference = TFile(referencefile)
    if inputfile_reference.IsZombie():
        doReference = False
        print "Error: no reference found"

if doReference == True:  # get trigger counts histograms from reference .root file
    #inputfile_reference.cd(basePathExpert)