Exemplo n.º 1
0
	def plot(self) :
		rd42Style()
		if self.histo_type == 'PulseHeight' :
			ROOT.gStyle.SetOptStat('m')
		if self.histo_type == 'Noise' :
			ROOT.gStyle.SetOptFit(01111)
#		ROOT.gStyle.SetDrawOption('colz')
#		ROOT.gStyle.SetCanvasDefW(1200)
		canvas = ROOT.TCanvas('%s_%s' % (self.histo_name, self.rand.Integer(10000)), 'canvas')
		histo = self.get_histo()
		canvas.cd()
		histo.Draw(self.draw_opt)
		histo.GetXaxis().SetTitle(self.xTitle)
		histo.GetYaxis().SetTitle(self.yTitle)
		self.draw_rd42Line()
		canvas.UseCurrentStyle()
		if histo.GetListOfFunctions().FindObject('palette') == None :
			histo.SetMaximum(1.4 * histo.GetMaximum())
		else :
#			canvas.SetWindowSize(1200, 600)
			canvas.SetRightMargin(canvas.GetRightMargin() + 0.08)
			pal = histo.GetListOfFunctions().FindObject('palette')
			pal_offset = 0.012
			pal.SetX1NDC(1. - canvas.GetRightMargin() + pal_offset)
			pal.SetX2NDC(1. - canvas.GetRightMargin() + pal_offset + 0.82*histo.GetZaxis().GetTickLength())
			pal.SetY1NDC(canvas.GetBottomMargin())
			pal.SetY2NDC(1. - canvas.GetTopMargin())
		if self.histo_type == 'FidCut' :
			fid_cut = self.get_fidCut()
			fid_cut.SetLineColor(ROOT.kRed)
#			fid_cut.Dump()
			canvas.cd()
			fid_cut.Draw('same')
		canvas.Update()
#		ROOT.gPad.Update()
#		canvas.Dump()
#		raw_input('ok?')
		canvas.Print('%s%s.pdf' % (self.output_path, self.histo_name))
		canvas.Print('%s%s.tex' % (self.output_path, self.histo_name))
		if self.return_value == 'mean' :
			mean = histo.GetMean()
			print 'Mean: %f' % mean
			return mean
		elif self.return_value == 'sigma' :
			fit = histo.GetListOfFunctions().FindObject('histofitx')
			sigma = fit.GetParameter(2)
			print 'Sigma: %f' % sigma
			return sigma
		else :
			return -1.
	def __init__(self, config_file, path, output_path, run_no, position, histo_type, run_config_file = '', event_number = 0) :
		self.config_file = config_file
		self.config = ConfigParser.ConfigParser()
		self.config.optionxform = str # case sensitive options
		self.config.read(config_file)
		self.run_no = int(run_no)
		self.position = position
		self.histo_type = histo_type
		if not path.endswith('/') : path += '/'
		self.path = '%s%s' % (path, self.run_no)
		if self.position != '' :
			self.path += '/%s/' % self.position
		else : self.path += '/'
		if not output_path.endswith('/') : output_path += '/'
		self.output_path = '%s%s/' % (output_path, self.run_no)
		self.event_number = event_number
		rd42Style()

		for key, value in self.config.items(histo_type) :
			value = value.replace('EVENTNUMBER', '%d' % self.event_number)
			setattr(self, key, value)
		if not hasattr(self, 'name') :
			self.name = self.histo_name
		if not hasattr(self, 'variable') :
			self.variable = histo_type
		if not hasattr(self, 'nstrips') :
			self.nstrips = 0
		else :
			self.nstrips = int(self.nstrips)
		if hasattr(self, 'output_dir') :
			self.output_path += self.output_dir
			if not self.output_path.endswith('/') : self.output_path += '/'
		helper.mkdir(self.output_path)
		if hasattr(self, 'rebin') :
			self.rebin = int(self.rebin)
		self.root_file = self.root_file.replace('RUNNUMBER', '.%d' % self.run_no)
		self.file_path = self.path + self.root_file
		self.rand = ROOT.TRandom3(0)

		self.run_config_file = run_config_file
		if self.run_config_file != '' :
			self.run_config = ConfigParser.ConfigParser()
			self.run_config.optionxform = str # case sensitive options
			self.run_config.read(run_config_file)
Exemplo n.º 3
0
	def __init__(self, config_file, path, output_path, run_no, position, histo_type) :
		self.config = ConfigParser.ConfigParser()
		self.config.optionxform = str # case sensitive options
		self.config.read(config_file)
		self.run_no = run_no
		self.position = position
		self.histo_type = histo_type
		if not path.endswith('/') : path += '/'
		self.path = '%s%s' % (path, self.run_no)
		if self.position != '' :
			self.path += '/%s/' % self.position
		else : self.path += '/'
		if not output_path.endswith('/') : output_path += '/'
		self.output_path = '%s%s/' % (output_path, self.run_no)
		helper.mkdir(self.output_path)
		rd42Style()

		for key, value in self.config.items(histo_type) :
			setattr(self, key, value)
		self.file_path = self.path + self.root_file
		self.rand = ROOT.TRandom3(0)
	def plot(self) :
		print '[status] plotting %s..' % self.name
		rd42Style()
		if self.histo_type == 'PulseHeight' :
			ROOT.gStyle.SetOptStat('m')
		if self.histo_type == 'Noise' :
			ROOT.gStyle.SetOptFit(01111)
#		ROOT.gStyle.SetDrawOption('colz')
#		ROOT.gStyle.SetCanvasDefW(1200)
		canvas = ROOT.TCanvas('%s_%s' % (self.name, self.rand.Integer(10000)), 'canvas')
		histo = self.get_histo()
		if 'PulseHeight_Cluster1-' in self.histo_type :
			for i in range(1, self.nstrips) :
				if self.position != '' :
					path_tmp = self.path.rstrip('%d/%s/' % (self.run_no, self.position))
				else :
					path_tmp = self.path.rstrip('%d/' % self.run_no)
				pl = plotter(self.config_file, path_tmp, self.output_path.rstrip('%d' % self.run_no), self.run_no, self.position, 'PulseHeight_Cluster%d_%s' % (i, self.histo_type.split('_')[-1]), self.run_config_file)
				histo_tmp = pl.get_histo()
				histo.Add(histo_tmp)
		canvas.cd()
		histo.Draw(self.draw_opt)
		histo.GetXaxis().SetTitle(self.xTitle)
		histo.GetYaxis().SetTitle(self.yTitle)
		self.draw_rd42Line()
		canvas.UseCurrentStyle()
		if histo.GetListOfFunctions().FindObject('palette') == None :
			histo.SetMaximum(1.4 * histo.GetMaximum())
		else :
#			canvas.SetWindowSize(1200, 600)
			canvas.SetRightMargin(canvas.GetRightMargin() + 0.08)
			pal = histo.GetListOfFunctions().FindObject('palette')
			pal_offset = 0.012
			pal.SetX1NDC(1. - canvas.GetRightMargin() + pal_offset)
			pal.SetX2NDC(1. - canvas.GetRightMargin() + pal_offset + 0.82*histo.GetZaxis().GetTickLength())
			pal.SetY1NDC(canvas.GetBottomMargin())
			pal.SetY2NDC(1. - canvas.GetTopMargin())
		if self.histo_type == 'FidCut' or self.histo_type == 'TrackPos' :
			self.save_TH2histo2table(histo, path = '%s%s.dat' % (self.output_path, self.name), rebinx = 4, rebiny = 4, xmin = 48., ymin = 48., sfx = 0.05, sfy = 0.05)
			fid_cut = self.get_fidCut()
			fid_cut.SetLineColor(ROOT.kRed)
#			fid_cut.Dump()
			canvas.cd()
			fid_cut.Draw('same')
		if 'Alignment_Plane2_YPred_DeltaX' in self.histo_type :
			if 'Post' in self.histo_type :
				self.save_TH2histo2table(histo, path = '%s%s.dat' % (self.output_path, self.name), rebinx = 3, rebiny = 5, xmin = 3000., ymin = -15., nxbins = 30, nybins = 96, sfx = 0.001, sfy = 1.)
			else :
				self.save_TH2histo2table(histo, path = '%s%s.dat' % (self.output_path, self.name), rebinx = 4, rebiny = 2, xmin = 3000., ymin = -260., nxbins = 32, nybins = 146, sfx = 0.001, sfy = 1.)
			return
		if 'Alignment_Plane2_XPred_DeltaY' in self.histo_type :
			if 'Post' in self.histo_type :
				self.save_TH2histo2table(histo, path = '%s%s.dat' % (self.output_path, self.name), rebinx = 4, rebiny = 13, xmin = 3000., ymin = -6.2, nxbins = 30, nybins = 37, sfx = 0.001, sfy = 1.)
			else :
				self.save_TH2histo2table(histo, path = '%s%s.dat' % (self.output_path, self.name), rebinx = 4, rebiny = 2, xmin = 3000., ymin = -540., nxbins = 32, nybins = 148, sfx = 0.001, sfy = 1.)
			return
		if self.histo_type == 'StripMeanPedestal_Dia' :
			profile = histo.ProfileX('profile', 1, -1, 'os')
			nbins = profile.GetNbinsX()
			sigma_histo = ROOT.TH1F('ped_sigma', 'ped_sigma', nbins, profile.GetBinLowEdge(1), profile.GetXaxis().GetBinUpEdge(nbins))
			for ibin in range(1, nbins+1) :
				projection = histo.ProjectionY('tmp%d' % ibin, ibin, ibin, 'o')
				sigma_histo.SetBinContent(ibin, projection.GetRMS())
				sigma_histo.SetBinError  (ibin, projection.GetRMSError())
			print profile.GetEntries()
			print profile.GetBinLowEdge(1)
			print profile.GetBinContent(1)
			print profile.GetBinError(1)
			histos = self.add_statistics(profile)
			print histos['data'].GetEntries()
			print histos['data'].GetBinLowEdge(1)
			print histos['data'].GetBinContent(1)
			print histos['data'].GetBinError(1)
			histos['sigma'] = sigma_histo
			processes = ['data', 'sigma', 'stat']
			print profile
			self.save_histo2table(histos = histos, processes = processes, path = '%s%s.dat' % (self.output_path, self.name), var = self.variable, bin_width = False)
			# sigma spectra
			histos = self.add_statistics(sigma_histo)
			processes = ['data', 'stat']
			self.save_histo2table(histos = histos, processes = processes, path = '%s%s.dat' % (self.output_path, 'StripPedestalSigma_Dia'), var = 'StripPedestalSigma', bin_width = False)
			return
		if self.histo_type == 'PulseHeight_ClusterSize' or self.histo_type == 'Eta_Dia_Area' :
			processes = ['data', 'stat']
			slice_name = self.histo_type
			if self.histo_type == 'Eta_Dia_Area' :
				slice_name = 'Eta_Area'
			slices = self.get_histoSlices(histo, path = self.output_path, slice_name = slice_name)
			for projection in slices :
				if '-' in projection :
					self.nstrips = int(projection.lstrip('1-'))
				else :
					self.nstrips = int(projection)
				print self.nstrips
				histos = self.add_statistics(slices[projection], slices[projection].GetName())
				self.save_histo2table(histos = histos, processes = processes, path = '%s%s.dat' % (self.output_path, slices[projection].GetName()), var = self.variable, bin_width = False)
			return
		canvas.Update()
#		ROOT.gPad.Update()
#		canvas.Dump()
#		raw_input('ok?')
		processes = ['data',]
		if self.return_value == 'mean' :
			histos = self.add_statistics(histo)
			processes.append('stat')
		elif self.return_value == 'sigma' :
			fit = histo.GetListOfFunctions().FindObject('histofitx')
			histos = self.add_statistics(histo, fit = fit)
			processes.append('stat')
			mean  = (fit.GetParameter(1), fit.GetParError(1))
			sigma = (fit.GetParameter(2), fit.GetParError(2))
			print 'Mean : %s +- %s' % rn.get_roundedNumber(*mean )
			print 'Sigma: %s +- %s' % rn.get_roundedNumber(*sigma)
			entries = []
			entries.append(('$\\chi^2 / \\ndof$', '{%.0f / %d}' % (fit.GetChisquare(), fit.GetNDF())))
			entries.append(('Mean' , '%s +- %s' % rn.get_roundedNumber(fit.GetParameter(1), fit.GetParError(1))))
			entries.append(('Sigma', '%s +- %s' % rn.get_roundedNumber(fit.GetParameter(2), fit.GetParError(2))))
			print entries
#			ROOT.gStyle.SetOptFit(0)
#			self.draw_statbox(entries)
		if self.histo_type != 'FidCut' and self.histo_type != 'TrackPos' :
			self.save_histo2table(histos = histos, processes = processes, path = '%s%s.dat' % (self.output_path, self.name), var = self.variable, bin_width = False)
		canvas.Print('%s%s.pdf' % (self.output_path, self.name))
		canvas.Print('%s%s.tex' % (self.output_path, self.name))
		return -1.
	def plot(self) :
		rd42Style()
		if self.histo_type == 'PulseHeight' :
			ROOT.gStyle.SetOptStat('m')
		if self.histo_type == 'Noise' :
			ROOT.gStyle.SetOptFit(01111)
#		ROOT.gStyle.SetDrawOption('colz')
#		ROOT.gStyle.SetCanvasDefW(1200)
		canvas = ROOT.TCanvas('%s_%s' % (self.histo_name, self.rand.Integer(10000)), 'canvas')
		histo = self.get_histo()
		histos = {}
		histos['data'] = histo
		canvas.cd()
		histo.Draw(self.draw_opt)
		histo.GetXaxis().SetTitle(self.xTitle)
		histo.GetYaxis().SetTitle(self.yTitle)
		self.draw_rd42Line()
		canvas.UseCurrentStyle()
		if histo.GetListOfFunctions().FindObject('palette') == None :
			histo.SetMaximum(1.4 * histo.GetMaximum())
		else :
#			canvas.SetWindowSize(1200, 600)
			canvas.SetRightMargin(canvas.GetRightMargin() + 0.08)
			pal = histo.GetListOfFunctions().FindObject('palette')
			pal_offset = 0.012
			pal.SetX1NDC(1. - canvas.GetRightMargin() + pal_offset)
			pal.SetX2NDC(1. - canvas.GetRightMargin() + pal_offset + 0.82*histo.GetZaxis().GetTickLength())
			pal.SetY1NDC(canvas.GetBottomMargin())
			pal.SetY2NDC(1. - canvas.GetTopMargin())
		if self.histo_type == 'FidCut' :
			self.save_TH2histo2table(histo, path = '%s%s.dat' % (self.output_path, self.histo_name))
			fid_cut = self.get_fidCut()
			fid_cut.SetLineColor(ROOT.kRed)
#			fid_cut.Dump()
			canvas.cd()
			fid_cut.Draw('same')
		canvas.Update()
#		ROOT.gPad.Update()
#		canvas.Dump()
#		raw_input('ok?')
		processes = ['data',]
		if self.return_value == 'mean' :
			mean = histo.GetMean()
			print 'Mean: %f' % mean
		elif self.return_value == 'sigma' :
			fit = histo.GetListOfFunctions().FindObject('histofitx')
			histos['fit'] = ROOT.TH1F('%s_fit' % self.histo_type, 'fit', histo.GetNbinsX(), 0., 1.)
			for i in [0, 1, 2] :
				histos['fit'].SetBinContent(i+1, fit.GetParameter(i))
				histos['fit'].SetBinError  (i+1  , fit.GetParError(i))
			processes.append('fit')
			mean  = (fit.GetParameter(1), fit.GetParError(1))
			sigma = (fit.GetParameter(2), fit.GetParError(2))
			print 'Mean : %s +- %s' % rn.get_roundedNumber(*mean )
			print 'Sigma: %s +- %s' % rn.get_roundedNumber(*sigma)
			entries = []
			entries.append(('$\\chi^2 / \\ndof$', '{%.0f / %d}' % (fit.GetChisquare(), fit.GetNDF())))
			entries.append(('Mean' , '%s +- %s' % rn.get_roundedNumber(fit.GetParameter(1), fit.GetParError(1))))
			entries.append(('Sigma', '%s +- %s' % rn.get_roundedNumber(fit.GetParameter(2), fit.GetParError(2))))
			print entries
#			ROOT.gStyle.SetOptFit(0)
#			self.draw_statbox(entries)
		if self.histo_type != 'FidCut' :
			self.save_histo2table(histos = histos, processes = processes, path = '%s%s.dat' % (self.output_path, self.histo_name), var = self.histo_type, bin_width = False)
		canvas.Print('%s%s.pdf' % (self.output_path, self.histo_name))
		canvas.Print('%s%s.tex' % (self.output_path, self.histo_name))
		return -1.