Example #1
0
def test_ROOT():

    a = ROOT.TH1F("a", "a", 10, 0, 1)
    assert_true(isinstance(a, _Hist))

    b = ROOT.Hist(10, 0, 1, type='F')
    assert_equal(a.TYPE, b.TYPE)
Example #2
0
	outputFile = root_open("W-mass.root","recreate")

# Create chain of root trees
chain = ROOT.TChain("Delphes")
chain.Add(inputFile)

# Create object of class ExRootTreeReader
treeReader = ROOT.ExRootTreeReader(chain)
numberOfEntries = treeReader.GetEntries()

# Get pointers to branches used in this analysis
branchMET = treeReader.UseBranch("MissingET")
branchElectron = treeReader.UseBranch("Electron")

# Define histograms
histMass = ROOT.TH1F("mass", "W^{+} Transverse Mass",100, 0, 300.0)



# --EventLoop start
for entry in range(0, numberOfEntries):
	# Load selected branches with data from specified event
	treeReader.ReadEntry(entry)

	# If event contains at least 1 electrons
	if branchElectron.GetEntries() == 0:
		continue
	
	# Take e, ve
	elec = branchElectron.At(0)
	metc = branchMET.At(0)
Example #3
0
                    print("Temporary filename: {}".format(filename))
                    f.seek(0, os.SEEK_END)
                    print("f length with localfile: {}".format(f.tell()))
                    f.write("Appended information in temp file.\n")
                    f.seek(0)
                    print("f.read(): {}".format(f.read()))
        except ErrorInGettingFile as e:
            print(e)

    if rootFile:
        try:
            with FileWithLocalFilename(
                    filename="246980/EMC/EMChists.2015_12_13_5_7_22.root",
                    writeFile=writeFile) as filename:
                print("Temporary filename: {}".format(filename))
                testHist = ROOT.TH1F("testHist", "testHist", 10, 0, 10)
                testHist.Fill(3)
                # Stricktly speaking, this only works on unix! But this should be fine for our purposes,
                # as Overwatch is not designed to work on Windows anyway.
                # "RECREATE" will not work, as the file is being recreated in a way that isn't
                # compatiable with the temp file!
                with rootpy.io.root_open(filename, "UPDATE") as f:
                    print("f.ls()  pre write:")
                    # Needs to be in a separate line. Otherwise, it will print before saying "pre/post write"
                    f.ls()

                    # Write hist
                    testHist.Write()

                    # Needs to be in a separate line. Otherwise, it will print before saying "pre/post write"
                    print("f.ls() post write:")
Example #4
0
                             "recreate")  ### <- Set Your output file name

# Create chain of root trees
chain = ROOT.TChain("LHEF")
chain.Add(inputFile)

# Create object of class ExRootTreeReader
treeReader = ROOT.ExRootTreeReader(chain)
numberOfEntries = treeReader.GetEntries()

# Get pointers to branches used in this analysis
branchParticle = treeReader.UseBranch("Particle")
# branchElectron = treeReader.UseBranch("Electron")

# Define histograms
histPT = ROOT.TH1F("pt", "p_{T} distribution", 80, 0, 400.0)
histEta = ROOT.TH1F("eta", "eta distribution", 100, -10, 10)
histPhi = ROOT.TH1F("phi", "phi distribution", 100, -10, 10)

# --EventLoop start
for entry in range(0, numberOfEntries):
    # Load selected branches with data from specified event
    treeReader.ReadEntry(entry)

    # If event contains at least 1 electrons
    if branchParticle.GetEntries() == 0:
        continue

    for i in range(0, branchParticle.GetEntries()):

        a = branchParticle.At(i)
Example #5
0
    outputFile = root_open("powheg_muon.root", "recreate")

# Create chain of root trees
chain = ROOT.TChain("LHEF")
chain.Add(inputFile)

# Create object of class ExRootTreeReader
treeReader = ROOT.ExRootTreeReader(chain)
numberOfEntries = treeReader.GetEntries()

# Get pointers to branches used in this analysis
branchParticle = treeReader.UseBranch("Particle")
# branchElectron = treeReader.UseBranch("Electron")

# Define histograms
histPT = ROOT.TH1F("pt", "P_{T} distribution", 100, 0, 400.0)

# --EventLoop start
for entry in range(0, numberOfEntries):
    # Load selected branches with data from specified event
    treeReader.ReadEntry(entry)

    # If event contains at least 1 electrons
    if branchParticle.GetEntries() == 0:
        continue

    for i in range(0, branchParticle.GetEntries()):

        a = branchParticle.At(i)
        if abs(a.PID) in [11, 12, 13, 14]:
            histPT.Fill(a.PT)
Example #6
0
chain.Add(inputFile)

# Create object of class ExRootTreeReader
treeReader = ROOT.ExRootTreeReader(chain)
numberOfEntries = treeReader.GetEntries()

# Get pointers to branches used in this analysis
# branchElec = treeReader.UseBranch("Electron")
# branchMuon = treeReader.UseBranch("Muon")
branchMET = treeReader.UseBranch("MissingET")


# Define histograms
# histElecPT = ROOT.TH1F("ept", "P_{T} distribution",100, 0, 400.0)
# histMuonPT = ROOT.TH1F("mpt", "P_{T} distribution",100, 0, 400.0)
histMET = ROOT.TH1F("met", "MET distribution",100, 0, 400.0)

# --EventLoop start
for entry in range(0, numberOfEntries):
	# Load selected branches with data from specified event
	treeReader.ReadEntry(entry)

	# If event contains at least 1 electrons
	if branchMET.GetEntries() == 0:
		continue
	
	# Take
	# Elec = branchElec.At(0)
	Metc = branchMET.At(0)