Example #1
0
def fixCCU(input):

	#input = "/afs/cern.ch/user/p/phansen/public/ecal-timing/dump_EcalTimeCalibConstants_v07_offline__since_00204623_till_4294967295.dat"
	customROOTstyle()

	rawidMap = cal.getRawIDMap()

	print_once = set()
	ccu_adj = {(54, 19): 4.0, (54, 20): 4.0, (48,  1): 2.0, (48,  2): 2.0, (48,  7): 2.0, (48,  5): 2.0, (48,  6): 2.0, (48,  3): 2.0, (48,  8): 2.0, (48,  4): 2.0, (1, 31): 4.0}
	output = input.replace("ecalTiming","ecalTiming-fixCCU-v2")
	with open(input,'r') as f:
		with open(output,'w') as of:
			for line in f:
				if "#" in line: continue
				line = line.split()
				start = line[:3]
				end = line[4:]
				time = float(line[3])
				rawid = int(line[-1])

				key = (rawidMap[rawid].FED, rawidMap[rawid].CCU)
				if key in ccu_adj:
					adj = ccu_adj[key] * 25./24.
					if key not in print_once:
						print_once.add(key)
						print key, line, adj
				else:
					adj = 0
				out = "\t".join(start + ["%.4f" %(time - adj)] + end) + '\n'
				of.write(out)
Example #2
0
def saveEventTimingPlots(eventdir):
    customROOTstyle()
    ROOT.gROOT.SetBatch(True)

    eventName = eventdir.GetName()
    timehist = {
        "EB": eventdir.Get('TimeMapEB'),
        "EEP": eventdir.Get('TimeMapEEP'),
        "EEM": eventdir.Get('TimeMapEEM'),
        "EB_OOT": eventdir.Get('TimeMapEB_OOT'),
        "EEP_OOT": eventdir.Get('TimeMapEEP_OOT'),
        "EEM_OOT": eventdir.Get('TimeMapEEM_OOT'),
        "EB_en": eventdir.Get('EneMapEB'),
        "EEP_en": eventdir.Get('EneMapEEP'),
        "EEM_en": eventdir.Get('EneMapEEM'),
    }

    text = {}

    c = ROOT.TCanvas("c" + eventName, "c" + eventName, 1500, 1100)
    c.Divide(3, 2)
    iPad = 0

    t = ROOT.TText(0, 0, "")
    t.Draw()
    t.SetTextSize(.1)
    for hist_name in ["EEM", "EB", "EEP"]:
        h = timehist[hist_name]
        h_oot = timehist[hist_name + "_OOT"]
        h_en = timehist[hist_name + "_en"]

        iPad += 1
        c.cd(iPad)
        h.Draw("colz")
        t.DrawTextNDC(0, 0, eventName + ' ' + hist_name)

        p = c.cd(iPad + 3)
        p.SetLogz()
        h_en.GetZaxis().SetRangeUser(0, 1000)
        h_en.Draw("colz")

    print eventName, [
        timehist[name].Integral() / timehist[name].GetEntries()
        for name in ["EEM", "EB", "EEP"]
    ]

    c.SaveAs("plots/" + eventName + "_en.pdf")
    c.SaveAs("plots/" + eventName + "_en.png")
Example #3
0
def saveEventTimingPlots(eventdir):
	customROOTstyle()
	ROOT.gROOT.SetBatch(True)

	eventName = eventdir.GetName()
	timehist = {
			"EB":eventdir.Get('TimeMapEB'),
			"EEP": eventdir.Get('TimeMapEEP'),
			"EEM": eventdir.Get('TimeMapEEM'),
			"EB_OOT":eventdir.Get('TimeMapEB_OOT'),
			"EEP_OOT": eventdir.Get('TimeMapEEP_OOT'),
			"EEM_OOT": eventdir.Get('TimeMapEEM_OOT'),
			"EB_en":eventdir.Get('EneMapEB'),
			"EEP_en": eventdir.Get('EneMapEEP'),
			"EEM_en": eventdir.Get('EneMapEEM'),
			}

	text = {}

	c = ROOT.TCanvas("c"+eventName, "c"+eventName, 1500,1100)
	c.Divide(3,2)
	iPad = 0

	
	t = ROOT.TText(0,0,"")
	t.Draw()
	t.SetTextSize(.1)
	for hist_name in ["EEM","EB","EEP"]:
		h = timehist[hist_name]
		h_oot = timehist[hist_name + "_OOT"]
		h_en = timehist[hist_name + "_en"]

		iPad += 1
		c.cd(iPad)
		h.Draw("colz")
		t.DrawTextNDC(0,0,eventName + ' ' + hist_name)

		p = c.cd(iPad+3)
		p.SetLogz()
		h_en.GetZaxis().SetRangeUser(0,1000)
		h_en.Draw("colz")

	print eventName, [timehist[name].Integral()/timehist[name].GetEntries() for name in ["EEM","EB","EEP"]]

	c.SaveAs("plots/" + eventName+"_en.pdf")
	c.SaveAs("plots/" + eventName+"_en.png")
Example #4
0
def shiftCalib(input):

    #input = "/afs/cern.ch/user/p/phansen/public/ecal-timing/dump_EcalTimeCalibConstants_v07_offline__since_00204623_till_4294967295.dat"
    customROOTstyle()

    hists = dict()
    for iz in [0, -1, 1]:
        hists[iz] = ROOT.TH1F("time_{iz}".format(iz=iz), "time", 100, -10, 10)

    with open(input, 'r') as f:
        for line in f:
            line = line.split()
            time = float(line[3])
            iz = int(line[2])
            hists[iz].Fill(time)

    offset = dict()
    for iz in hists:
        offset[iz], __ = addFitToPlot(hists[iz])

    print offset

    #output = os.path.splitext(input)[0] + "-GlobalOffset.txt"
    output = input.replace("ecalTiming", "ecalTimeRelative")
    global_out = input.replace("ecalTiming", "ecalTimeGlobal")
    with open(input, 'r') as f:
        with open(output, 'w') as of:
            for line in f:
                line = line.split()
                start = line[:3]
                end = line[4:]
                time = float(line[3])
                iz = int(line[2])

                out = "\t".join(start + ["%.3f" %
                                         (time - offset[iz])] + end) + '\n'
                of.write(out)
    with open(global_out, 'w') as f:
        for iz in offset:
            f.write("%d\t%.3f\n" % (iz, offset[iz]))
Example #5
0
def shiftCalib(input):

	#input = "/afs/cern.ch/user/p/phansen/public/ecal-timing/dump_EcalTimeCalibConstants_v07_offline__since_00204623_till_4294967295.dat"
	customROOTstyle()

	hists = dict()
	for iz in [0,-1,1]:
		hists[iz] =  ROOT.TH1F("time_{iz}".format(iz=iz),"time",100,-10,10)

	with open(input,'r') as f:
		for line in f:
			line = line.split()
			time = float(line[3])
			iz = int(line[2])
			hists[iz].Fill(time)
	
	offset = dict()
	for iz in hists:
		offset[iz],__ = addFitToPlot(hists[iz])

	print offset

	#output = os.path.splitext(input)[0] + "-GlobalOffset.txt"
	output = input.replace("ecalTiming","ecalTimeRelative")
	global_out = input.replace("ecalTiming","ecalTimeGlobal")
	with open(input,'r') as f:
		with open(output,'w') as of:
			for line in f:
				line = line.split()
				start = line[:3]
				end = line[4:]
				time = float(line[3])
				iz = int(line[2])

				out = "\t".join(start + ["%.3f" %(time - offset[iz])] + end) + '\n'
				of.write(out)
	with open(global_out, 'w') as f:
		for iz in offset:
			f.write("%d\t%.3f\n" % (iz, offset[iz]))
for (x,y,d),(ave,err) in average.iteritems():
	cal.addCrystal(x,y,d,ave,err)

for (x,y,d),(ave,err) in oldcalib.iteritems():
	cal.addCrystal(x,y,d,ave,err)

print len(cal.crystals)
cal.sort()

cal.writeConstant("const.xml")
cal.writeErrors("error.xml")

import ROOT
from EcalTiming.EcalTiming.PlotUtils import drawMultipleGrid,customROOTstyle
customROOTstyle()

def plotCalibration(crystals,histoname):
	EB = ROOT.TProfile2D(histoname + "EB",histoname + " EB",360,1,361,85*2,-84,86) 
	EEP = ROOT.TProfile2D(histoname + "EEP",histoname + " EEP", 100, 1, 101, 100, 1, 101)
	EEM = ROOT.TProfile2D(histoname + "EEM",histoname + " EEM", 100, 1, 101, 100, 1, 101)
	
	EB.SetZTitle("ns")
	EB.SetXTitle("i#phi")
	EB.SetYTitle("i#eta")

	EEP.SetZTitle("ns")
	EEP.SetXTitle("ix")
	EEP.SetYTitle("iy")
	EEM.SetZTitle("ns")
	EEM.SetXTitle("ix")
Example #7
0
import sys, os
import shutil
import errno


def energyDiff(outdir, map1, map2, name1, name2):

    diffMap = cal.addCalib(map1, map2, -1, 1)
    cal.plot1d(diffMap, outdir, "diff" + name2 + "_" + name1, -1, 1)
    cal.plot2d(diffMap, outdir, "diffMap" + name2 + "_" + name1, -1, 1)
    ringdiff = cal.plotiRing(diffMap, outdir, "iRing" + name2 + "_" + name1)
    return ringdiff


if __name__ == "__main__":
    customROOTstyle()
    ROOT.gROOT.SetBatch(True)
    file_pattern = sys.argv[1]
    dirname = sys.argv[2]

    dir, basename = os.path.split(file_pattern)
    dir = dir.split('/')
    print dir[-1:]
    outdir = '/'.join(dir[:-1]) + "/plots/" + dir[-1] + "/" + dirname + "/"
    outdir = os.path.normpath(outdir)

    def mkdir_p(path):
        try:
            os.makedirs(path)
        except OSError as exc:  # Python >2.5
            if exc.errno == errno.EEXIST and os.path.isdir(path):