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
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
def setupRanges(self): """ read file with lumi data setup low edges of histograms corresponding to the beginning of lumisections fill array of timing structures (fill, ls, run etc) corresponding to the given bin """ f = TFile(lumiFilePattern.replace('__XXX__', str(self.fill))) tree = f.Get("t") tsPrev = 0 # Data from fill report file fillReport = FillReport(fillReportName) for i in range(0, tree.GetEntries()) : lsDataEntry = LsData() nb = tree.GetEntry(i) if nb < 0: continue #Y range for histograms if tree.lumi > self.yMax: self.yMax = tree.lumi if tree.lumi < self.yMin: self.yMin = tree.lumi #Setting start/end of the fill if tree.tstamp < self.fromto[0]: self.fromto[0] = tree.tstamp if tree.tstamp > self.fromto[1]: self.fromto[1] = tree.tstamp #Low edges for histos (start of the LS) if i > 0: self.lsDuration.insert(i-1, tree.tstamp - tsPrev) # Found negative duration of LS if self.lsDuration[i-1] < 0: continue tsPrev = tree.tstamp self.xx.append(tree.tstamp) fill = int(tree.fill) # fill by-LS data lsDataEntry.fill = fill lsDataEntry.fillStart = fillReport.getFillCreationTime(fill) lsDataEntry.fillStable = fillReport.getFillStableTime(fill) lsDataEntry.fillEnd = fillReport.getFillEndTime(fill) lsDataEntry.durationStable = fillReport.getFillDuration(fill) lsDataEntry.bField = fillReport.getFillField(fill) lsDataEntry.beamEnergy = tree.beamEnergy lsDataEntry.run = tree.run lsDataEntry.lsNo = tree.lsNo lsDataEntry.lsDuration = 0 # will be overwritten later lsDataEntry.tstamp = tree.tstamp lsDataEntry.lumi = tree.lumi # will be scaled on the second pass lsDataEntry.beamStatus = tree.beamStatus lsDataEntry.lumiSource = tree.lumiSource self.lsDataList.append(lsDataEntry) del lsDataEntry del tree del f
def setupRanges(self): """ read file with lumi data setup low edges of histograms corresponding to the beginning of lumisections fill array of timing structures (fill, ls, run etc) corresponding to the given bin """ f = TFile(lumiFilePattern.replace('__XXX__', str(self.fill))) tree = f.Get("t") tsPrev = 0 # Data from fill report file fillReport = FillReport(fillReportName) for i in range(0, tree.GetEntries()): lsDataEntry = LsData() nb = tree.GetEntry(i) if nb < 0: continue #Y range for histograms if tree.lumi > self.yMax: self.yMax = tree.lumi if tree.lumi < self.yMin: self.yMin = tree.lumi #Setting start/end of the fill if tree.tstamp < self.fromto[0]: self.fromto[0] = tree.tstamp if tree.tstamp > self.fromto[1]: self.fromto[1] = tree.tstamp #Low edges for histos (start of the LS) if i > 0: self.lsDuration.insert(i - 1, tree.tstamp - tsPrev) # Found negative duration of LS if self.lsDuration[i - 1] < 0: continue tsPrev = tree.tstamp self.xx.append(tree.tstamp) fill = int(tree.fill) # fill by-LS data lsDataEntry.fill = fill lsDataEntry.fillStart = fillReport.getFillCreationTime(fill) lsDataEntry.fillStable = fillReport.getFillStableTime(fill) lsDataEntry.fillEnd = fillReport.getFillEndTime(fill) lsDataEntry.durationStable = fillReport.getFillDuration(fill) lsDataEntry.bField = fillReport.getFillField(fill) lsDataEntry.beamEnergy = tree.beamEnergy lsDataEntry.run = tree.run lsDataEntry.lsNo = tree.lsNo lsDataEntry.lsDuration = 0 # will be overwritten later lsDataEntry.tstamp = tree.tstamp lsDataEntry.lumi = tree.lumi # will be scaled on the second pass lsDataEntry.beamStatus = tree.beamStatus lsDataEntry.lumiSource = tree.lumiSource self.lsDataList.append(lsDataEntry) del lsDataEntry del tree del f