示例#1
0
    def writeOutput(self):
	
	rootFile = radmonLumiFilePattern.replace('__XXX__', str(self.fill))
	try:
	    fout = TFile(rootFile,'RECREATE')
	except IOError:
	    print "Cannot open file for output", rootFile
	    exit	 

	t = TTree('t', 'Combined Lumi and Radmon data')
	
	fillData = FillData()
	lumiData = LumiData()
	radmonData = RadmonData()
	
	t.Branch('fillBranch', fillData, 'fill/I:fillStart/I:fillStable/I:fillEnd/I:durationStable/I:run/I:lsNo/I:tstamp/I:msecs/I:bunchSpacing/I')
	t.Branch('fillBranchD', AddressOf(fillData, 'bField'), 'bField/D:beamEnergy/D')
	t.Branch('lumiBranch',  lumiData, 'bestLumi/D:bestLumiErr/D:hfLumi/D:hfLumiErr/D:pltLumi/D:pltLumiErr/D:pltZeroLumi/D:pltZeroLumiErr/D:bcmfLumi/D:bcmfLumiErr/D')
    	t.Branch('radmonBranch',  radmonData, 'rates[16]/D:ratesErr[16]/D')
    	
    	href = self.pbest  # Reference histogram
	#self.pbcmf.Draw()
	#raw_input("Press enter to continue")
	
        print "Starting filling tree, file ", radmonLumiFilePattern.replace('__XXX__', str(self.fill))
    	for i in range(len(self.xx) - 1):
            fillData.fill = self.fillDataList[i].fill
            fillData.fillStart =  self.fillDataList[i].fillStart
            fillData.fillStable =  self.fillDataList[i].fillStable
            fillData.fillEnd =  self.fillDataList[i].fillEnd
            fillData.durationStable =  self.fillDataList[i].durationStable
            fillData.run =  self.fillDataList[i].run
            fillData.lsNo =  self.fillDataList[i].lsNo
            fillData.bunchSpacing =  self.fillDataList[i].bunchSpacing
            fillData.bField =  self.fillDataList[i].bField
            fillData.beamEnergy =  self.fillDataList[i].beamEnergy
	    fillData.tstamp = int(href.GetXaxis().GetBinCenter(i))
	    fillData.msecs = int(href.GetXaxis().GetBinCenter(i) - fillData.tstamp)
	    
	    lumiData.bestLumi = self.pbest.GetBinContent(i)
	    lumiData.bestLumiErr = self.pbest.GetBinError(i)
	    lumiData.hfLumi = self.phf.GetBinContent(i)
	    lumiData.hfLumiErr = self.phf.GetBinError(i)
	    lumiData.pltLumi = self.pplt.GetBinContent(i)
	    lumiData.pltLumiErr = self.pplt.GetBinError(i)
	    lumiData.pltZeroLumi = self.ppltZero.GetBinContent(i)
	    lumiData.pltZeroLumiErr = self.ppltZero.GetBinError(i)
	    lumiData.bcmfLumi = self.pbcmf.GetBinContent(i)
	    lumiData.bcmfLumiErr = self.pbcmf.GetBinError(i)
	    
	    for j in range(len(self.pradmon)):
		radmonData.rates[j] = self.pradmon[j].GetBinContent(i)
		radmonData.ratesErr[j] = self.pradmon[j].GetBinError(i)

	    t.Fill()
	print "Writing", rootFile
	fout.Write()
	fout.Close()
	del fout
示例#2
0
    def writeOutput(self):

        rootFile = radmonLumiFilePattern.replace('__XXX__', str(self.fill))
        try:
            fout = TFile(rootFile, 'RECREATE')
        except IOError:
            print "Cannot open file for output", rootFile
            exit

        t = TTree('t', 'Combined Lumi and Radmon data')

        lsData = LsData()
        radmonData = RadmonData()

        t.Branch(
            'IntBranch', lsData,
            'fill/I:fillStart/I:fillStable/I:fillEnd/I:durationStable/I:run/I:lsNo/I:lsDuration/I:tstamp/I'
        )
        t.Branch('DoubleBranch', AddressOf(lsData, 'lumi'),
                 'lumi/D:bField/D:beamEnergy/D')
        t.Branch('BeamStatus', AddressOf(lsData, 'beamStatus'), 'beamStatus/C')
        t.Branch('LumiSource', AddressOf(lsData, 'lumiSource'), 'lumiSource/C')
        t.Branch('RadmonBranch', radmonData, 'rates[16]/D:ratesErr[16]/D')

        href = self.pradmon[0]  # Reference histogram (to get bin center)

        for i in range(len(self.xx) - 1):
            lsData.fill = self.lsDataList[i].fill
            lsData.fillStart = self.lsDataList[i].fillStart
            lsData.fillStable = self.lsDataList[i].fillStable
            lsData.fillEnd = self.lsDataList[i].fillEnd
            lsData.durationStable = self.lsDataList[i].durationStable
            lsData.run = self.lsDataList[i].run
            lsData.lsNo = self.lsDataList[i].lsNo
            lsData.lsDuration = self.lsDataList[i].lsDuration
            #lsData.tstamp = self.lsDataList[i].tstamp
            lsData.lumi = self.lsDataList[i].lumi
            lsData.bField = self.lsDataList[i].bField
            lsData.beamEnergy = self.lsDataList[i].beamEnergy
            lsData.beamStatus = self.lsDataList[i].beamStatus
            lsData.lumiSource = self.lsDataList[i].lumiSource

            # move tstamp to the middle of LS
            lsData.tstamp = int(href.GetXaxis().GetBinCenter(i))
            #lsData.tstamp = self.lsDataList[i].tstamp

            for j in range(len(self.pradmon)):
                radmonData.rates[j] = self.pradmon[j].GetBinContent(i)
                radmonData.ratesErr[j] = self.pradmon[j].GetBinError(i)

            t.Fill()
        print "Writing", rootFile
        fout.Write()
        fout.Close()
        del fout
示例#3
0
    def writeOutput(self):

        rootFile = radmonLumiFilePattern.replace('__XXX__', str(self.fill))
        try:
            fout = TFile(rootFile, 'RECREATE')
        except IOError:
            print "Cannot open file for output", rootFile
            exit

        t = TTree('t', 'Combined Lumi and Radmon data')

        timingData = TimingData()
        lumiData = LumiData()
        radmonData = RadmonData()
        t.Branch('timingBranch', timingData,
                 'fill/D:startFill/D:endFill/D:run/D:lsno/D:tsUtc/D')
        t.Branch(
            'lumiBranch', lumiData,
            'primaryLumi/D:primaryLumiErr/D:hf/D:hfErr/D:plt/D:pltErr/D:pltZero/D:pltZeroErr/D:bcmf/D:bcmfErr/D'
        )
        t.Branch('radmonBranch', radmonData, 'rates[16]/D:ratesErr[16]/D')

        href = self.pprlumi  # Reference histogram
        #self.pbcmf.Draw()
        #raw_input("Press enter to continue")
        for i in range(len(self.xx) - 1):
            timingData.fill = self.td[i].fill
            timingData.startFill = self.td[i].startFill
            timingData.endFill = self.td[i].endFill
            timingData.run = self.td[i].run
            timingData.lsno = self.td[i].lsno
            timingData.tsUtc = href.GetXaxis().GetBinCenter(i)

            lumiData.primaryLumi = self.pprlumi.GetBinContent(i)
            lumiData.primaryLumiErr = self.pprlumi.GetBinError(i)
            lumiData.hf = self.phf.GetBinContent(i)
            lumiData.hfErr = self.phf.GetBinError(i)
            lumiData.plt = self.pplt.GetBinContent(i)
            lumiData.pltErr = self.pplt.GetBinError(i)
            lumiData.pltZero = self.ppltZero.GetBinContent(i)
            lumiData.pltZeroErr = self.ppltZero.GetBinError(i)
            lumiData.bcmf = self.pbcmf.GetBinContent(i)
            lumiData.bcmfErr = self.pbcmf.GetBinError(i)

            for j in range(len(self.pradmon)):
                radmonData.rates[j] = self.pradmon[j].GetBinContent(i)
                radmonData.ratesErr[j] = self.pradmon[j].GetBinError(i)

            t.Fill()
        print "Writing", rootFile
        fout.Write()
        fout.Close()
        del fout
示例#4
0
    def writeOutput(self):
	
	rootFile = radmonLumiFilePattern.replace('__XXX__', str(self.fill))
	try:
	    fout = TFile(rootFile,'RECREATE')
	except IOError:
	    print "Cannot open file for output", rootFile
	    exit	 

	t = TTree('t', 'Combined Lumi and Radmon data')
	
	lsData = LsData()
	radmonData = RadmonData()

	t.Branch('IntBranch',  lsData, 'fill/I:fillStart/I:fillStable/I:fillEnd/I:durationStable/I:run/I:lsNo/I:lsDuration/I:tstamp/I')
	t.Branch('DoubleBranch', AddressOf(lsData, 'lumi'), 'lumi/D:bField/D:beamEnergy/D')
        t.Branch('BeamStatus', AddressOf(lsData, 'beamStatus'), 'beamStatus/C')
        t.Branch('LumiSource', AddressOf(lsData, 'lumiSource'), 'lumiSource/C')        
    	t.Branch('RadmonBranch',  radmonData, 'rates[16]/D:ratesErr[16]/D')
    	
    	href = self.pradmon[0]  # Reference histogram (to get bin center)

    	for i in range(len(self.xx) - 1):
            lsData.fill = self.lsDataList[i].fill
            lsData.fillStart = self.lsDataList[i].fillStart
            lsData.fillStable = self.lsDataList[i].fillStable
            lsData.fillEnd = self.lsDataList[i].fillEnd
            lsData.durationStable = self.lsDataList[i].durationStable
            lsData.run = self.lsDataList[i].run
            lsData.lsNo = self.lsDataList[i].lsNo
            lsData.lsDuration = self.lsDataList[i].lsDuration
            #lsData.tstamp = self.lsDataList[i].tstamp
            lsData.lumi = self.lsDataList[i].lumi
            lsData.bField = self.lsDataList[i].bField
            lsData.beamEnergy = self.lsDataList[i].beamEnergy
            lsData.beamStatus = self.lsDataList[i].beamStatus
            lsData.lumiSource = self.lsDataList[i].lumiSource

            # move tstamp to the middle of LS
            lsData.tstamp = int(href.GetXaxis().GetBinCenter(i))
            #lsData.tstamp = self.lsDataList[i].tstamp

	    for j in range(len(self.pradmon)):
		radmonData.rates[j] = self.pradmon[j].GetBinContent(i)
		radmonData.ratesErr[j] = self.pradmon[j].GetBinError(i)
		
	    t.Fill()
	print "Writing", rootFile
	fout.Write()
	fout.Close()
	del fout
示例#5
0
    def writeOutput(self):
	
	rootFile = radmonLumiFilePattern.replace('__XXX__', str(self.fill))
	try:
	    fout = TFile(rootFile,'RECREATE')
	except IOError:
	    print "Cannot open file for output", rootFile
	    exit	 

	t = TTree('t', 'Combined Lumi and Radmon data')
	
	timingData = TimingData()
	lumiData = LumiData()
	radmonData = RadmonData()
	t.Branch('timingBranch',  timingData, 'fill/D:startFill/D:endFill/D:run/D:lsno/D:tsUtc/D')
	t.Branch('lumiBranch',  lumiData, 'primaryLumi/D:primaryLumiErr/D:hf/D:hfErr/D:plt/D:pltErr/D:pltZero/D:pltZeroErr/D:bcmf/D:bcmfErr/D')
    	t.Branch('radmonBranch',  radmonData, 'rates[16]/D:ratesErr[16]/D')
    	
    	href = self.pprlumi  # Reference histogram
	#self.pbcmf.Draw()
	#raw_input("Press enter to continue")
    	for i in range(len(self.xx) - 1):
	    timingData.fill = self.td[i].fill
	    timingData.startFill = self.td[i].startFill
	    timingData.endFill = self.td[i].endFill
	    timingData.run = self.td[i].run
	    timingData.lsno = self.td[i].lsno
	    timingData.tsUtc = href.GetXaxis().GetBinCenter(i)
	    
	    lumiData.primaryLumi = self.pprlumi.GetBinContent(i)
	    lumiData.primaryLumiErr = self.pprlumi.GetBinError(i)
	    lumiData.hf = self.phf.GetBinContent(i)
	    lumiData.hfErr = self.phf.GetBinError(i)
	    lumiData.plt = self.pplt.GetBinContent(i)
	    lumiData.pltErr = self.pplt.GetBinError(i)
	    lumiData.pltZero = self.ppltZero.GetBinContent(i)
	    lumiData.pltZeroErr = self.ppltZero.GetBinError(i)
	    lumiData.bcmf = self.pbcmf.GetBinContent(i)
	    lumiData.bcmfErr = self.pbcmf.GetBinError(i)
	    
	    for j in range(len(self.pradmon)):
		radmonData.rates[j] = self.pradmon[j].GetBinContent(i)
		radmonData.ratesErr[j] = self.pradmon[j].GetBinError(i)

	    t.Fill()
	print "Writing", rootFile
	fout.Write()
	fout.Close()
	del fout
示例#6
0
def radmon2fill():
    
    #Get fills already processed
    filesDone = glob.glob(radmonFillPattern)
    (toReplace, dummy) = radmonFillPattern.split('.')
    print filesDone
    fillsDone = []
    for file in filesDone:
        name, ext = file.split('.')
        fillsDone.append(int(name.replace(toReplace[0:-1], "")))
    if len(fillsDone) > 0:
        print "Fills already done", fillsDone
    
    fillReport = FillReport(fillReportName)
    #Start/End of each fill in fillReport
    fillStarted = fillReport.getFillCreationTime()
    fillDumped = fillReport.getFillEndTime()
    
    for fill in sorted(fillStarted.keys()):
        
        if int(fill) in fillsDone:
            print "Fill", fill, "is already processed. Skipping..."
            continue
        print "Processing fill", fill, "........."
        
        fillData = FillData()
        radmonData = RadmonData()
        #runningSums = RunningSums()
        
        #rsumsList = []
        for i in range(0, 16):
            #rsumsList.insert(i, [0.]*1800)
            radmonData.rates[i] = 0.
            radmonData.status[i] = 0.

            
        #Output
        rootFile = radmonFillPattern.replace("*", str(fill))
        try:
	    fout = TFile(rootFile,'RECREATE')
	except IOError:
	    print "Cannot open file for output", rootFile
	    exit	 
	t = TTree('t', 'Radmon rates')
	t.Branch('fillBranchI', fillData, 'fill/I:fillStart/I:fillStable/I:fillEnd/I:durationStable/I')
	t.Branch('fillBranchD', AddressOf(fillData, 'bField'), 'bField/D:beamEnergy/D')
	t.Branch('radmonBranchI', radmonData, 'tstamp/I:status[16]/I')
	t.Branch('radmonBranchD', AddressOf(radmonData, 'rates'), 'rates[16]/D')
	#t.Branch('radmonSums', runningSums, 'rsums[28800]/D')
	
        tsStart =  fillStarted[fill]
	tsEnd = fillDumped[fill]
	tsStable = fillReport.getFillStableTime(int(fill))
	duration = fillReport.getFillDuration(int(fill))
	bField = fillReport.getFillField(int(fill))
	beamEnergy = fillReport.getFillBeamEnergy(int(fill))
	
	fromto = [tsStart-hrs*3600, tsEnd+hrs*3600]
        filelist =  get_filelist(RadmonDataDir, radmonFilePattern, fromto)
        
        
        print "Files used:"
	chain = TChain("Rate")
        for file in filelist:
            print file
            chain.Add(file)

        fillData.fillStart = tsStart
        fillData.fillStable = tsStable
        fillData.fillEnd = tsEnd
        fillData.durationStable = duration
        fillData.bField = bField
        fillData.beamEnergy = beamEnergy
        
        for i in range(chain.GetEntries()):
            chain.GetEntry(i)    
        
            #if tsStart - chain.tstamp < 1800:
            if chain.tstamp > tsStart and chain.tstamp < tsEnd:
                radmonData.tstamp = chain.tstamp
                for j in range(0, 16):
                    #rsumsList[j].append(chain.rates[j])
                    #rsumsList[j].pop(0)
                    radmonData.rates[j] = chain.rates[j]
                    radmonData.status[j] = chain.status[j]
                
                #runningSums.rsums = np.asarray(rsumsList).ravel()
                
                #nparray = np.asarray(rsumsList).ravel()
 
                #for j in range(0, 16*1800):
                    #runningSums.rsums[j] = nparray[j]
                
                #nump2d = np.reshape(nump, (-1,1800))  (To get back to 2D)
            
            #if chain.tstamp > tsStable - deltaMinutes*60 and chain.tstamp < tsEnd + deltaMinutes*60:

                t.Fill()

        fout.Write()
        fout.Close()
        
        del chain
        del fillData
        del radmonData
        #del runningSums
        del t
        del fout
示例#7
0
def radmon2fill():

    #Get fills already processed
    filesDone = glob.glob(radmonFillPattern)
    (toReplace, dummy) = radmonFillPattern.split('.')
    print filesDone
    fillsDone = []
    for file in filesDone:
        name, ext = file.split('.')
        fillsDone.append(int(name.replace(toReplace[0:-1], "")))
    if len(fillsDone) > 0:
        print "Fills already done", fillsDone

    fillReport = FillReport(fillReportName)
    #Start/End of each fill in fillReport
    fillStarted = fillReport.getFillCreationTime()
    fillDumped = fillReport.getFillEndTime()

    for fill in sorted(fillStarted.keys()):

        if int(fill) in fillsDone:
            print "Fill", fill, "is already processed. Skipping..."
            continue
        print "Processing fill", fill, "........."

        fillData = FillData()
        radmonData = RadmonData()
        #runningSums = RunningSums()

        #rsumsList = []
        for i in range(0, 16):
            #rsumsList.insert(i, [0.]*1800)
            radmonData.rates[i] = 0.
            radmonData.status[i] = 0.

        #Output
        rootFile = radmonFillPattern.replace("*", str(fill))
        try:
            fout = TFile(rootFile, 'RECREATE')
        except IOError:
            print "Cannot open file for output", rootFile
            exit
        t = TTree('t', 'Radmon rates')
        t.Branch('fillBranchI', fillData,
                 'fill/I:fillStart/I:fillStable/I:fillEnd/I:durationStable/I')
        t.Branch('fillBranchD', AddressOf(fillData, 'bField'),
                 'bField/D:beamEnergy/D')
        t.Branch('radmonBranchI', radmonData, 'tstamp/I:status[16]/I')
        t.Branch('radmonBranchD', AddressOf(radmonData, 'rates'),
                 'rates[16]/D')
        #t.Branch('radmonSums', runningSums, 'rsums[28800]/D')

        tsStart = fillStarted[fill]
        tsEnd = fillDumped[fill]
        tsStable = fillReport.getFillStableTime(int(fill))
        duration = fillReport.getFillDuration(int(fill))
        bField = fillReport.getFillField(int(fill))
        beamEnergy = fillReport.getFillBeamEnergy(int(fill))

        fromto = [tsStart - hrs * 3600, tsEnd + hrs * 3600]
        filelist = get_filelist(RadmonDataDir, radmonFilePattern, fromto)

        print "Files used:"
        chain = TChain("Rate")
        for file in filelist:
            print file
            chain.Add(file)

        fillData.fillStart = tsStart
        fillData.fillStable = tsStable
        fillData.fillEnd = tsEnd
        fillData.durationStable = duration
        fillData.bField = bField
        fillData.beamEnergy = beamEnergy

        for i in range(chain.GetEntries()):
            chain.GetEntry(i)

            #if tsStart - chain.tstamp < 1800:
            if chain.tstamp > tsStart and chain.tstamp < tsEnd:
                radmonData.tstamp = chain.tstamp
                for j in range(0, 16):
                    #rsumsList[j].append(chain.rates[j])
                    #rsumsList[j].pop(0)
                    radmonData.rates[j] = chain.rates[j]
                    radmonData.status[j] = chain.status[j]

                #runningSums.rsums = np.asarray(rsumsList).ravel()

                #nparray = np.asarray(rsumsList).ravel()

                #for j in range(0, 16*1800):
                #runningSums.rsums[j] = nparray[j]

                #nump2d = np.reshape(nump, (-1,1800))  (To get back to 2D)

            #if chain.tstamp > tsStable - deltaMinutes*60 and chain.tstamp < tsEnd + deltaMinutes*60:

                t.Fill()

        fout.Write()
        fout.Close()

        del chain
        del fillData
        del radmonData
        #del runningSums
        del t
        del fout
示例#8
0
def addRunningSum():
    
    for fill in fills:
        
        inputFile = inputPattern.replace('__XXX__', str(fill))
        try:
            fin = ROOT.TFile(inputFile,'READ')
            print "Processing fill", fill
        except IOError:
            print "Cannot open file", inputFile
            continue
        
        inputTree = fin.Get('t')
        
       
        outfile = outputPattern.replace('__XXX__', str(fill))
        try:
	    fout = ROOT.TFile(outfile,'RECREATE')
	except IOError:
	    print "Cannot open file for output", outfile
	    continue       
        
        #Output tree
        fillData = FillData()
        radmonData = RadmonData()
        t = ROOT.TTree('t', "Radmon rates + runnning sums ")
	t.Branch('fillBranchI', fillData, 'fill/I:fillStart/I:fillColl/I:fillStable/I:fillEnd/I:durationStable/I')
	t.Branch('fillBranchD', ROOT.AddressOf(fillData, 'bField'), 'bField/D:beamEnergy/D')
	t.Branch('radmonBranchI', radmonData, 'tstamp/I:status[16]/I')
	t.Branch('radmonRates', ROOT.AddressOf(radmonData, 'rates'), 'rates[16]/D:rsums15[16]/D:rsums30[16]/D:rsums60[16]/D')

        rsums15 = [0.]*16
        rsumsPrev15 = [0.]*16
        rsums30 = [0.]*16
        rsumsPrev30 = [0.]*16
        rsums60 = [0.]*16
        rsumsPrev60 = [0.]*16
        
        # First pass is to find beginning of the collisions
        tsColl = -100000
        
        for i in range(0, inputTree.GetEntries()):
            nb = inputTree.GetEntry(i)
	    if nb < 0:
		continue
            
            if inputTree.rates[refIndx] > rateCut:
                tsColl = inputTree.tstamp
                break
        
        for i in range(0, inputTree.GetEntries()):
            nb = inputTree.GetEntry(i)
	    if nb < 0:
		continue
            
            #Copy data to a new tree
            fillData.fill = inputTree.fill
            fillData.fillStart = inputTree.fillStart
            fillData.fillColl = tsColl
            fillData.fillStable = inputTree.fillStable
            fillData.fillEnd = inputTree.fillEnd
            fillData.durationStable = inputTree.durationStable
            fillData.bField = inputTree.bField
            fillData.beamEnergy = inputTree.beamEnergy
            
            radmonData.tstamp = inputTree.tstamp
            
            for j in range(0, 16):
                radmonData.status[j] = inputTree.status[j]
                radmonData.rates[j] = inputTree.rates[j]
                
                #Running sums (c) AK
                # 15 minutes
                if i+1 < 15*60:
                    rsums15[j] += inputTree.rates[j]
                    radmonData.rsums15[j] = rsums15[j]
                    rsumsPrev15[j] = rsums15[j]
                else:
                    rsums15[j] = ((15*60 - 1)*rsumsPrev15[j] + inputTree.rates[j])/15/60
                    radmonData.rsums15[j] = rsums15[j]
                    rsumsPrev15[j] = rsums15[j]

                 # 30 minutes
                if i+1 < 30*60:
                    rsums30[j] += inputTree.rates[j]
                    radmonData.rsums30[j] = rsums30[j]
                    rsumsPrev30[j] = rsums30[j]
                else:
                    rsums30[j] = ((30*60 - 1)*rsumsPrev30[j] + inputTree.rates[j])/30/60
                    radmonData.rsums30[j] = rsums30[j]
                    rsumsPrev30[j] = rsums30[j]

                 # 60 minutes
                if i+1 < 60*60:
                    rsums60[j] += inputTree.rates[j]
                    radmonData.rsums60[j] = rsums60[j]
                    rsumsPrev60[j] = rsums60[j]
                else:
                    rsums60[j] = ((60*60 - 1)*rsumsPrev60[j] + inputTree.rates[j])/60/60
                    radmonData.rsums60[j] = rsums60[j]
                    rsumsPrev60[j] = rsums60[j]
                        
            
            t.Fill()
            
        fout.Write()
        fout.Close()
        
        del fillData
        del radmonData
        del t
        del fout   
        del inputTree
        del inputFile
示例#9
0
    def writeOutput(self):

        rootFile = radmonLumiFilePattern.replace('__XXX__', str(self.fill))
        try:
            fout = TFile(rootFile, 'RECREATE')
        except IOError:
            print "Cannot open file for output", rootFile
            exit

        t = TTree('t', 'Combined Lumi and Radmon data')

        fillData = FillData()
        lumiData = LumiData()
        radmonData = RadmonData()

        t.Branch(
            'fillBranch', fillData,
            'fill/I:fillStart/I:fillStable/I:fillEnd/I:durationStable/I:run/I:lsNo/I:tstamp/I:msecs/I:bunchSpacing/I'
        )
        t.Branch('fillBranchD', AddressOf(fillData, 'bField'),
                 'bField/D:beamEnergy/D')
        t.Branch(
            'lumiBranch', lumiData,
            'bestLumi/D:bestLumiErr/D:hfLumi/D:hfLumiErr/D:pltLumi/D:pltLumiErr/D:pltZeroLumi/D:pltZeroLumiErr/D:bcmfLumi/D:bcmfLumiErr/D'
        )
        t.Branch('radmonBranch', radmonData, 'rates[16]/D:ratesErr[16]/D')

        href = self.pbest  # Reference histogram
        #self.pbcmf.Draw()
        #raw_input("Press enter to continue")

        print "Starting filling tree, file ", radmonLumiFilePattern.replace(
            '__XXX__', str(self.fill))
        for i in range(len(self.xx) - 1):
            fillData.fill = self.fillDataList[i].fill
            fillData.fillStart = self.fillDataList[i].fillStart
            fillData.fillStable = self.fillDataList[i].fillStable
            fillData.fillEnd = self.fillDataList[i].fillEnd
            fillData.durationStable = self.fillDataList[i].durationStable
            fillData.run = self.fillDataList[i].run
            fillData.lsNo = self.fillDataList[i].lsNo
            fillData.bunchSpacing = self.fillDataList[i].bunchSpacing
            fillData.bField = self.fillDataList[i].bField
            fillData.beamEnergy = self.fillDataList[i].beamEnergy
            fillData.tstamp = int(href.GetXaxis().GetBinCenter(i))
            fillData.msecs = int(href.GetXaxis().GetBinCenter(i) -
                                 fillData.tstamp)

            lumiData.bestLumi = self.pbest.GetBinContent(i)
            lumiData.bestLumiErr = self.pbest.GetBinError(i)
            lumiData.hfLumi = self.phf.GetBinContent(i)
            lumiData.hfLumiErr = self.phf.GetBinError(i)
            lumiData.pltLumi = self.pplt.GetBinContent(i)
            lumiData.pltLumiErr = self.pplt.GetBinError(i)
            lumiData.pltZeroLumi = self.ppltZero.GetBinContent(i)
            lumiData.pltZeroLumiErr = self.ppltZero.GetBinError(i)
            lumiData.bcmfLumi = self.pbcmf.GetBinContent(i)
            lumiData.bcmfLumiErr = self.pbcmf.GetBinError(i)

            for j in range(len(self.pradmon)):
                radmonData.rates[j] = self.pradmon[j].GetBinContent(i)
                radmonData.ratesErr[j] = self.pradmon[j].GetBinError(i)

            t.Fill()
        print "Writing", rootFile
        fout.Write()
        fout.Close()
        del fout