def cv32a(pFile, xTitle, data): lText = '2012' if pFile.count('2011'): lText = '2011' cv = TCanvas('cv', 'cv', 2100, 900) x1, y1, x2, y2 = 0.8, 0.65, 0.9, 0.9 mlegend = TLegend(x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mg = TMultiGraph() xKey, yKey, color, mStyle, lg = 's', 'rho_H2', kCyan - 1, 22, '#rho_{H_{2}}' g0 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g0, lg, "p") mg.Add(g0) xKey, yKey, color, mStyle, lg = 's', 'rho_CH4', kBlue, 23, '#rho_{CH_{4}}' g1 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g1, lg, "p") mg.Add(g1) xKey, yKey, color, mStyle, lg = 's', 'rho_CO', kRed, 20, '#rho_{CO}' g2 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g2, lg, "p") mg.Add(g2) xKey, yKey, color, mStyle, lg = 's', 'rho_CO2', kMagenta, 21, '#rho_{CO_{2}}' g3 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g3, lg, "p") mg.Add(g3) mg.Draw("ap") gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.45, 0.9, lText) mg.SetTitle("pressure profiles") mg.GetXaxis().SetTitle(xTitle) mg.GetYaxis().SetTitle("density #rho [molecules/m^{3}]") mg.GetYaxis().SetRangeUser(1e7, 1e17) mlegend.Draw() # pname = wwwpath # subfolder = 'TCT/HL/relaxedColl/newScatt/' # pname += subfolder + hname + '_' + doZoom + '.png' pname = pFile.split('.csv')[0] + "a_pressure.pdf" print('Saving file as ' + pname) cv.Print(pname)
def cv32a(pFile,xTitle,data): lText = '2012' if pFile.count('2011'): lText = '2011' cv = TCanvas( 'cv', 'cv', 2100, 900) x1, y1, x2, y2 = 0.8, 0.65, 0.9, 0.9 mlegend = TLegend( x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mg = TMultiGraph() xKey, yKey, color, mStyle, lg = 's','rho_H2', kGreen, 22, '#rho_{H_2}' g0 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g0, lg, "p") mg.Add(g0) xKey, yKey, color, mStyle, lg = 's','rho_CH4', kBlue, 23, '#rho_{CH_{4}}' g1 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g1, lg, "p") mg.Add(g1) xKey, yKey, color, mStyle, lg = 's','rho_CO', kRed, 20, '#rho_{CO}' g2 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g2, lg, "p") mg.Add(g2) xKey, yKey, color, mStyle, lg = 's','rho_CO2', kMagenta, 21, '#rho_{CO_2}' g3 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g3, lg, "p") mg.Add(g3) mg.Draw("ap") gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.45, 0.9, lText) mg.SetTitle("pressure profiles") mg.GetXaxis().SetTitle(xTitle) mg.GetYaxis().SetTitle("density #rho [molecules/m^{3}]") mg.GetYaxis().SetRangeUser(1e7,1e17) mlegend.Draw() # pname = wwwpath # subfolder = 'TCT/HL/relaxedColl/newScatt/' # pname += subfolder + hname + '_' + doZoom + '.png' pname = pFile.split('.csv')[0] + "a_pressure.png" print('Saving file as ' + pname ) cv.Print(pname)
def cv09(): print 'run cv09 raw hits plot ' tDict = { # 0=subdir # 1=xnbins # 2=xmin # 3=xmax # 4=ynbins # 5=ymin # 6=ymax # 7=xtitle # 8=ytitle # 9=xInd # 10=yInd 'xy_52_TCTH.4L1.B1': ['TCTH/', 100, -4., 3., 100, -3., 5., 'x [cm]', 'y [cm]', 0, 1], 'yz_52_TCTH.4L1.B1': ['TCTH/', 100, 0., 100., 100, -3., 5., 'z [cm]', 'y [cm]', 2, 1], 'xy_53_TCTVA.4L1.B1': ['TCTV/', 100, -4., 3., 100, -3., 5., 'x [cm]', 'y [cm]', 0, 1], 'yz_53_TCTVA.4L1.B1': ['TCTV/', 100, 0., 100., 100, -3., 5., 'z [cm]', 'y [cm]', 2, 1], 'xy_19_TCTH.4L5.B1': ['TCTH/', 100, -4., 3., 100, -3., 5., 'x [cm]', 'y [cm]', 0, 1], 'yz_19_TCTH.4L5.B1': ['TCTH/', 100, 0., 100., 100, -3., 5., 'z [cm]', 'y [cm]', 2, 1], 'xy_20_TCTVA.4L5.B1': ['TCTV/', 100, -4., 3., 100, -3., 5., 'x [cm]', 'y [cm]', 0, 1], 'yz_20_TCTVA.4L5.B1': ['TCTV/', 100, 0., 100., 100, -3., 5., 'z [cm]', 'y [cm]', 2, 1], #'55_TCTVA.5L1.B1': [], # '57_TCTVA.5L5.B1': [], # '56_TCTH.5L5.B1': [], # '54_TCTH.5L1.B1': [], } for tkey in tDict.keys(): myfile = workpath + 'runs/TCT/rotate/HL/' + tDict[tkey][0] myfile += 'rawhits_influka_units'+ '_' + tkey.lstrip(tkey.split('_')[0] + '_') +'.dat' tct = tkey.split('_')[-1] a,b = 1,1 cv = TCanvas( 'cv' + tkey, 'cv' + tkey, 10, 10, a*800, b*600 ) cv.Divide(a,b) gPad.SetRightMargin(0.13) , gPad.SetLeftMargin(0.08) hname = 'sixtrack_' + tkey xnbins, xmin, xmax = tDict[tkey][1], tDict[tkey][2], tDict[tkey][3] ynbins, ymin, ymax = tDict[tkey][4], tDict[tkey][5], tDict[tkey][6] hist = TH2F(hname, hname, xnbins, xmin, xmax, ynbins, ymin, ymax ) xInd, yInd = tDict[tkey][9], tDict[tkey][10] with open(myfile) as mf: for line in mf: x = float(line.split()[xInd]) y = float(line.split()[yInd]) hist.Fill(x,y) xtitle, ytitle = tDict[tkey][7], tDict[tkey][8] hist.GetYaxis().SetTitleOffset(0.82) hist.GetXaxis().SetTitle(xtitle) hist.GetYaxis().SetTitle(ytitle) hist.Draw('colz') lab = mylabel(60) x1, y1 = 0.6, 0.95 lab.DrawLatex(x1, y1-0.1, tct) pname = wwwpath + 'TCT/HL/' pname += 'HL_' + hname + '.png' print("saving " + pname) cv.Print(pname)
def cv32c(pFile, xTitle, data, doCorr, var): lText = '2012' if pFile.count('2011'): lText = '2011' if not var: a, b = 1, 2 else: a, b, = 1, 1 cv = TCanvas('cv', 'cv', a * 2100, b * 900) cv.Divide(a, b) cv.cd(1) x1, y1, x2, y2 = 0.8, 0.65, 0.9, 0.9 mylegend = TLegend(x1, y1, x2, y2) mylegend.SetFillColor(0) mylegend.SetFillStyle(0) mylegend.SetLineColor(0) mylegend.SetTextSize(0.035) mylegend.SetShadowColor(0) mylegend.SetBorderSize(0) mgr = TMultiGraph() xKey, yKey, color, mStyle, lg = 's', 'avPress', kGreen, 23, 'aver. pressure' g0 = makeGraph(data, xKey, yKey, color, mStyle) mylegend.AddEntry(g0, lg, "p") mgr.Add(g0) if doCorr: xKey, yKey, color, mStyle, lg = 's', 'avPressCorr', kBlue, 24, 'aver. pressure corr.' g1 = makeGraph(data, xKey, yKey, color, mStyle) mylegend.AddEntry(g1, lg, "p") mgr.Add(g1) mgr.Draw("ap") gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.45, 0.9, lText) mgr.SetTitle("pressure profiles") mgr.GetXaxis().SetTitle(xTitle) mgr.GetYaxis().SetTitle("av. pressure") mgr.GetYaxis().SetRangeUser(1e-12, 1e-6) mylegend.Draw() # .................................................................................................... cv.cd(2) x1, y1, x2, y2 = 0.8, 0.65, 0.9, 0.9 mlegend = TLegend(x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mg = TMultiGraph() xKey, yKey, color, mStyle, lg = 's', 'H2Eq', kBlue, 23, 'H_{2} Eq' g2 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g2, lg, "p") mg.Add(g2) if doCorr: xKey, yKey, color, mStyle, lg = 's', 'H2EqCorr', kMagenta, 24, 'H_{2} Eq corr.' g3 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g3, lg, "p") mg.Add(g3) mg.Draw("ap") gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.45, 0.9, lText) mg.SetTitle("pressure profiles") mg.GetXaxis().SetTitle(xTitle) mg.GetYaxis().SetTitle("H_{2} Eq") mg.GetYaxis().SetRangeUser(2e10, 9e17) mlegend.Draw() # pname = wwwpath # subfolder = 'TCT/HL/relaxedColl/newScatt/' # pname += subfolder + hname + '_' + doZoom + '.png' pname = pFile.split('.csv')[0] + "c_pressure.png" print('Saving file as ' + pname) cv.Print(pname)
def cv32bsum(pFile, xTitle, data): # summed N2 equivalents lText = '2012' if pFile.count('2011'): lText = '2011' cv = TCanvas('cv', 'cv', 2100, 900) x1, y1, x2, y2 = 0.74, 0.7, 0.9, 0.9 mlegend = TLegend(x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) hists = [] nbins, xmin, xmax = 300, -270., 270. xKey, yKey, color, mStyle, lg = 's', 'H2_N2Eq', kGreen, 22, 'H_{2} N_{2} Eq' h0 = makeTH1F(data[xKey], data[yKey], yKey, nbins, xmin, xmax, color, mStyle) hsum = h0.Clone('sum') hsum.SetLineColor(kBlack) hsum.SetMarkerColor(kBlack) mlegend.AddEntry(hsum, 'total N_{2} Eq', "l") mlegend.AddEntry(h0, lg, "l") xKey, yKey, color, mStyle, lg = 's', 'CH4_N2Eq', kBlue, 23, 'CH_{4} N_{2} Eq' h1 = makeTH1F(data[xKey], data[yKey], yKey, nbins, xmin, xmax, color, mStyle) mlegend.AddEntry(h1, lg, "l") xKey, yKey, color, mStyle, lg = 's', 'CO_N2Eq', kRed, 20, 'CO N_{2} Eq' h2 = makeTH1F(data[xKey], data[yKey], yKey, nbins, xmin, xmax, color, mStyle) mlegend.AddEntry(h2, lg, "l") xKey, yKey, color, mStyle, lg = 's', 'CO2_N2Eq', kMagenta, 21, 'CO_{2} N_{2} Eq' h3 = makeTH1F(data[xKey], data[yKey], yKey, nbins, xmin, xmax, color, mStyle) mlegend.AddEntry(h3, lg, "l") hsum.Add(h1) hsum.Add(h2) hsum.Add(h3) hsum.Draw("hist") h0.Draw("samehist") h1.Draw("samehist") h2.Draw("samehist") h3.Draw("samehist") gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.48, 0.88, lText) hsum.SetTitle("pressure profiles") hsum.GetXaxis().SetTitle(xTitle) hsum.GetYaxis().SetTitle("N_{2} Eq pressure [bar]") hsum.GetYaxis().SetTitleOffset(0.8) hsum.GetYaxis().SetRangeUser(1e-14, 8e-5) mlegend.Draw() # pname = wwwpath # subfolder = 'TCT/HL/relaxedColl/newScatt/' # pname += subfolder + hname + '_' + doZoom + '.png' pname = pFile.split('.csv')[0] + "bsum_pressure.pdf" pnamelast = pname.split('/')[-1] pname = wwwpath + 'TCT/beamgas/pressure_profiles_2012/' + pnamelast print('Saving file as ' + pname) cv.Print(pname)
def cv32b(pFile, xTitle, data): # single N2 equivalents lText = '2012' if pFile.count('2011'): lText = '2011' cv = TCanvas('cv', 'cv', 2100, 900) x1, y1, x2, y2 = 0.8, 0.65, 0.9, 0.9 mlegend = TLegend(x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mg = TMultiGraph() xKey, yKey, color, mStyle, lg = 's', 'H2_N2Eq', kGreen, 22, 'H_{2} N_{2} Eq' g0 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g0, lg, "p") mg.Add(g0) xKey, yKey, color, mStyle, lg = 's', 'CH4_N2Eq', kBlue, 23, 'CH_{4} N_{2} Eq' g1 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g1, lg, "p") mg.Add(g1) xKey, yKey, color, mStyle, lg = 's', 'CO_N2Eq', kRed, 20, 'CO N_{2} Eq' g2 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g2, lg, "p") mg.Add(g2) xKey, yKey, color, mStyle, lg = 's', 'CO2_N2Eq', kMagenta, 21, 'CO_{2} N_{2} Eq' g3 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g3, lg, "p") mg.Add(g3) mg.Draw("ap") gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.45, 0.9, lText) mg.SetTitle("pressure profiles") mg.GetXaxis().SetTitle(xTitle) mg.GetYaxis().SetTitle("N_{2} Eq") mg.GetYaxis().SetRangeUser(1e-16, 1e-7) mlegend.Draw() # pname = wwwpath # subfolder = 'TCT/HL/relaxedColl/newScatt/' # pname += subfolder + hname + '_' + doZoom + '.png' pname = pFile.split('.csv')[0] + "b_pressure.png" print('Saving file as ' + pname) cv.Print(pname)
def cv11(): rfname = 'results_HL_BH.root' tag = '_BH' norm = 7330000. lText = 'beamhalo' subfolder = 'beamhalo/' XurMin, XurMax = 2e-2,1e4 YurMin, YurMax = 1e-6,9 ytitle = '#frac{dN(counts/TCT hit)}{dlog E}' rfname = 'results_BGac.root' tag = '_BGac' norm = 1. lText = 'BG after cond' subfolder = 'beamgas/' XurMin, XurMax = 2e-2,1e4 YurMin, YurMax = 1e2,9e7 ytitle = '#frac{dN(counts/s)}{dlog E}' rf = TFile.Open('~/Documents/RHUL/work/runs/TCT/HL/' + rfname) # pions char hPins = 'EkinPiPlusRInBP'+tag hMins = 'EkinPiMinusRInBP'+tag hPout = 'EkinPiPlusROutBP'+tag hMout = 'EkinPiMinusROutBP'+tag histPins = rf.Get(hPins) histMins = rf.Get(hMins) histPout = rf.Get(hPout) histMout = rf.Get(hMout) histPionIns = histPins.Clone('cloony'+hPins) histPionIns.Add(histMins) histPionOut = histPout.Clone('cloony'+hPout) histPionOut.Add(histMout) # neutrons histNeutIns = rf.Get('EkinNeutronsRInBP'+tag) histNeutOut = rf.Get('EkinNeutronsROutBP'+tag) # all ins/out histAllIns = rf.Get('EkinAllRInBP'+tag) histAllOut = rf.Get('EkinAllROutBP'+tag) cv = TCanvas( 'cv', 'cv', 1200, 900) x1, y1, x2, y2 = 0.7, 0.65, 0.9, 0.9 mlegend = TLegend( x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) leg= [ ('all, r < r_{bp}', "l"), ('#pi^{#pm}, r < r_{bp}', "l"), ('n, r < r_{bp}', "l"), ('all, r #geq r_{bp}', "l"), ('#pi^{#pm}, r #geq r_{bp}', "l"), ('n, r #geq r_{bp}', "l"), ] gPad.SetLogx(1) gPad.SetLogy(1) gPad.SetGridy(0) hists = [ histAllIns, histPionIns, histNeutIns, histAllOut, histPionOut, histNeutOut, ] hcol = [ kBlack, kCyan, kAzure-3, kRed, kViolet, kOrange, ] for i,hist in enumerate(hists): hist.SetLineColor(hcol[i]) hist.Scale(1./norm) hist.GetXaxis().SetRangeUser(XurMin, XurMax) hist.GetYaxis().SetRangeUser(YurMin, YurMax) hist.GetXaxis().SetTitle('E [GeV]') hist.GetYaxis().SetTitle(ytitle) if not i: hist.Draw('HIST') else: hist.Draw('HISTSAME') mlegend.AddEntry(hist, leg[i][0], "l") mlegend.Draw() lab = mylabel(42) lab.DrawLatex(0.45, 0.85, lText) gPad.RedrawAxis() pname = '/Users/rkwee/Documents/RHUL/work/results/www/TCT/HL/nominalSettings/'+subfolder+'/EkinBp2'+tag+'.pdf' cv.SaveAs(pname)
def cv10(): debug = 1 doWriteRFile = 0 plotLossMaps = 0 doSelectRange= 0 doAvLoss = 1 collsHB1 = [ #hHaloB1 ('hHalo', '_nominal.B1'), ('hHalo', '_sel1.B1'), ('hHalo', '_sel2.B1'), ('hHalo', '_sel3.B1'), ('hHalo', '_sel4.B1'), ('hHalo', '_TCSG.A6L7.B1'), ('hHalo', '_TCSG.B5L7.B1'), ('hHalo', '_TCSG.A5L7.B1'), ('hHalo', '_TCSG.D4L7.B1'), ('hHalo', '_TCSG.B4L7.B1'), ('hHalo', '_TCSG.A4L7.B1'), ('hHalo', '_TCSG.A4R7.B1'), ('hHalo', '_TCSG.B5R7.B1'), ('hHalo', '_TCSG.D5R7.B1'), ('hHalo', '_TCSG.E5R7.B1'), ('hHalo', '_TCSG.6R7.B1'), ] collsVB1 = [ ('vHalo', '_nominal.B1'), ('vHalo', '_sel1.B1'), ('vHalo', '_sel2.B1'), ('vHalo', '_sel3.B1'), ('vHalo', '_sel4.B1'), ('vHalo', '_TCSG.A6L7.B1'), ('vHalo', '_TCSG.B5L7.B1'), ('vHalo', '_TCSG.A5L7.B1'), ('vHalo', '_TCSG.D4L7.B1'), ('vHalo', '_TCSG.B4L7.B1'), ('vHalo', '_TCSG.A4L7.B1'), ('vHalo', '_TCSG.A4R7.B1'), ('vHalo', '_TCSG.B5R7.B1'), ('vHalo', '_TCSG.D5R7.B1'), ('vHalo', '_TCSG.E5R7.B1'), ('vHalo', '_TCSG.6R7.B1'), ] collsHB2 = [ ('hHalo', '_nominal.B2'), ('hHalo', '_sel1.B2'), ('hHalo', '_sel2.B2'), ('hHalo', '_sel3.B2'), ('hHalo', '_sel4.B2'), ('hHalo', '_TCSG.6L7.B2'), ('hHalo', '_TCSG.A4L7.B2'), ('hHalo', '_TCSG.A4R7.B2'), ('hHalo', '_TCSG.A5R7.B2'), ('hHalo', '_TCSG.A6R7.B2'), ('hHalo', '_TCSG.B4R7.B2'), ('hHalo', '_TCSG.B5L7.B2'), ('hHalo', '_TCSG.B5R7.B2'), ('hHalo', '_TCSG.D4R7.B2'), ('hHalo', '_TCSG.D5L7.B2'), ('hHalo', '_TCSG.E5L7.B2'), ] collsVB2 = [ ('vHalo', '_nominal.B2'), ('vHalo', '_sel1.B2'), ('vHalo', '_sel2.B2'), ('vHalo', '_sel3.B2'), ('vHalo', '_sel4.B2'), ] # tcs colls = collsHB1 + collsVB1 # subfolder in wwwpath for result plots subfolder = 'scan/' for haloType,coll in colls: beam = 'b2' beamn = '2' if coll.count('B1'): beam = 'b1' beamn = '1' # my results (tight coll settings) thispath = '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/scan/B'+beamn+'/'+haloType+'/' rfname = thispath + 'scan_lossmaps_'+ haloType+'B'+beamn+coll+'.root' trname = 'normtree' + coll colNumber = 4 f3 = helpers.source_dir + 'HL_TCT_7TeV/' + beam +'/CollPositions.'+beam+'.dat' f3 = helpers.source_dir + 'TCT_4TeV_60cm/'+beam+'/CollPositions.'+beam+'.dat' f3 = helpers.source_dir + 'NewColl7TeVB'+beamn+'/CollPositions.'+beam+'.dat' # use for normalisation the sum of nabs (col 4) f4 = thispath + 'coll_summary' + coll + '.dat' # ------------------------------------------------ if doWriteRFile: print 'Writing ' + '.'* 25 +' ' + rfname # create a root file rf = TFile(rfname, 'recreate') nt = TTree(trname,'norm for each coll') if not os.path.exists(f4): print f4,' does not exist?!' continue t0 = time.time() h_tot_loss, h_cold, h_warm = lossmap.lossmap(beam,thispath,coll, f3) t1 = time.time() print(str(t1-t0)+' for returning lossmap histograms of ' + coll ) if debug: if h_cold.GetEntries() < 1.: print 'Empty histogram! Binary characters in LPI file?' sys.exit() h_tot_loss.Write() h_cold.Write() h_warm.Write() # -- write the for each norm value a branch into ttree t0 = time.time() # setting branch name branchname = coll.replace('.','QQQ') if debug and 0: print globals() # use globals dict to convert strings to variable names globals()[branchname] = array('i',[0]) # create branch nt.Branch(branchname, globals()[branchname], branchname+'/i') # get value maxval = int(addCol(f4, colNumber-1)) # assigning value globals()[branchname][0] = maxval # write to tree nt.Fill() t1 = time.time() nt.Write() rf.Close() # ------------------------------------------------ if plotLossMaps: if not os.path.exists(rfname): print rfname,' does not exist?!' continue print('Plotting lossmaps from ' + '.'*20 + ' '+ rfname) trname = 'normtree' + coll doZooms = [0,1] rel = '' for doZoom in doZooms: rf = TFile.Open(rfname) nt = rf.Get(trname) branchname = coll.replace('.','QQQ') norm = -9999 for entry in nt: norm = getattr(entry,branchname) print 'norm', norm cv = TCanvas( 'cv' + coll + str(doZoom), 'cv' + coll + str(doZoom), 1200, 700) YurMin, YurMax = 3.2e-9, 3. hname = 'coll_loss' +coll if debug: print('Get histograms for coll ' + coll + ', starting with ' + hname) coll_loss = rf.Get(hname) cold_loss = rf.Get('cold_loss' +coll) warm_loss = rf.Get('warm_loss' +coll) coll_loss.SetLineColor(kBlack) warm_loss.SetLineColor(kOrange) cold_loss.SetLineColor(kBlue) coll_loss.SetFillColor(kBlack) warm_loss.SetFillColor(kOrange) cold_loss.SetFillColor(kBlue) coll_loss.Scale(1.0/norm) cold_loss.Scale(1.0/norm) warm_loss.Scale(1.0/norm) if beam.count('1') and not doZoom: x1, y1, x2, y2 = 0.18, 0.78, 0.42, 0.9 else: x1, y1, x2, y2 = 0.68, 0.78, 0.91, 0.9 XurMin, XurMax = 0., length_LHC if doZoom: rel = '_zoom' XurMin, XurMax = 6.3e3, 8.0e3 if beam.count('1') : XurMin, XurMax = 19.7e3, 20.6e3 coll_loss.Draw('hist') cold_loss.Draw('samehist') warm_loss.Draw('samehist') lh = [] # YurMin = 3.2e-9 lhRange = [3e-9+i*1e-9 for i in range(3,7)] lhRange += [i*1.e-8 for i in range(1,11)] lhRange += [i*1.e-7 for i in range(1,11)] lhRange += [i*1.e-6 for i in range(1,11)] lhRange += [i*1.e-5 for i in range(1,11)] lhRange += [i*1.e-4 for i in range(1,11)] lhRange += [i*1.e-3 for i in range(1,11)] lhRange += [i*1.e-2 for i in range(1,11)] lhRange += [i*1.e-1 for i in range(1,11)] lhRange += [i*1. for i in range(1,int(YurMax))] for i in lhRange: lh += [TLine()] lh[-1].SetLineStyle(1) lh[-1].SetLineColor(kGray) lh[-1].DrawLine(XurMin,i,XurMax,i) lv = [] lvRange = [1000*i for i in range(0,int(length_LHC*1e-3))] for s in lvRange: if s > XurMin and s < XurMax: lv += [TLine()] lv[-1].SetLineStyle(1) lv[-1].SetLineColor(kGray) lv[-1].DrawLine(s,YurMin,s,YurMax) coll_loss.Draw('same') cold_loss.Draw('same') warm_loss.Draw('same') coll_loss.GetXaxis().SetRangeUser(XurMin, XurMax) coll_loss.GetYaxis().SetRangeUser(YurMin, YurMax) thelegend = TLegend( x1, y1, x2, y2) thelegend.SetFillColor(0) thelegend.SetLineColor(0) thelegend.SetTextSize(0.035) thelegend.SetShadowColor(10) thelegend.AddEntry(coll_loss,'losses on collimators', 'L') thelegend.AddEntry(cold_loss,'cold losses', 'L') thelegend.AddEntry(warm_loss,'warm losses', 'L') thelegend.Draw() lab = mylabel(60) lab.DrawLatex(x1, y1-0.1, coll.lstrip('_')) lab = mylabel(42) lab.DrawLatex(.5, y1+0.08, haloType) gPad.RedrawAxis() gPad.SetGrid(0,1) gPad.SetLogy(1) pname = wwwpath subfolder = 'scan/' pname += subfolder + hname + '_' + haloType+ rel+'.png' print('Saving file as' + pname ) cv.Print(pname) # ------------------------------------------------ if doSelectRange: rf = TFile.Open(rfname) trname = 'normtree' + coll branchname = coll.replace('.','QQQ') nt = rf.Get(trname) norm = -9999 for entry in nt: norm = getattr(entry,branchname) hist = rf.Get('cold_loss' + coll) hist.Scale(1./norm) cv = TCanvas( 'cv'+coll , 'cv'+coll , 2050, 700) gPad.SetLogy(1) s_startQ8, s_stopQ8 = 6940., 7020. s_startQ10, s_stopQ10 = 7050., 7110. if coll.count('B1'): s_startQ8, s_stopQ8 = 20270., 20340. s_startQ10, s_stopQ10 = 20370., 20435. XurMin, XurMax = s_startQ8, s_stopQ10 hist.GetXaxis().SetRangeUser(XurMin*.995, XurMax*1.005) YurMin, YurMax = 1e-8,5e-6 hist.GetYaxis().SetRangeUser(YurMin, YurMax) hist.GetYaxis().SetTitle('#eta [m^{-1}]') hist.GetYaxis().SetTitle('s [m]') hist.Draw() lv = TLine() lv.SetLineStyle(1) lv.SetLineWidth(2) lv.SetLineColor(kBlue) xval = s_startQ8 lv.DrawLine(xval,YurMin,xval,YurMax) xval = s_stopQ8 lv.DrawLine(xval,YurMin,xval,YurMax) lv.SetLineStyle(1) lv.SetLineWidth(2) lv.SetLineColor(kOrange) xval = s_startQ10 lv.DrawLine(xval,YurMin,xval,YurMax) xval = s_stopQ10 lv.DrawLine(xval,YurMin,xval,YurMax) subfolder = 'scan/benchmarkLosses/' resulthist = 'bm' + coll + '_' + haloType + 'B'+ beamn pname = wwwpath pname += subfolder + resulthist+'.png' print('Saving file as' + pname ) cv.Print(pname) # ------------------------------------------------ if doAvLoss: maxLosses, lossesQ8, lossesQ10 = [],[],[] fraction = 0.1 for haloType,coll in colls: beam = 'b2' beamn = '2' if coll.count('B1'): beam = 'b1' beamn = '1' # my results (tight coll settings) thispath = '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/scan/B'+beamn+'/'+haloType+'/' rfname = thispath + 'scan_lossmaps_'+ haloType+'B'+beamn+coll+'.root' trname = 'normtree' + coll branchname = coll.replace('.','QQQ') print 'Opening.....', rfname rf = TFile.Open(rfname) nt = rf.Get(trname) norm = -9999 for entry in nt: norm = getattr(entry,branchname) print 'norm', norm histname = 'cold_loss' + coll hist = rf.Get(histname) # max loss in cold magnets, get also poisson error maxLoss = hist.GetMaximum() maxLosses += [(fraction*maxLoss/norm,fraction*math.sqrt(maxLoss)/norm)] s_startQ8, s_stopQ8 = 6940., 7020. s_startQ10, s_stopQ10 = 7050., 7110. if coll.count('B1'): s_startQ8, s_stopQ8 = 20270., 20340. s_startQ10, s_stopQ10 = 20370., 20435. bin_startQ8, bin_stopQ8 = hist.FindBin(s_startQ8), hist.FindBin(s_stopQ8) bin_startQ10, bin_stopQ10 = hist.FindBin(s_startQ10), hist.FindBin(s_stopQ10) lQ8, lErrQ8, lQ10, lErrQ10 = 0.,0.,0.,0. for bin in range(bin_startQ8, bin_stopQ8): lQ8 += hist.GetBinContent(bin) for bin in range(bin_startQ10, bin_stopQ10): lQ10 += hist.GetBinContent(bin) nbinsQ8, nbinsQ10 = bin_stopQ8-bin_startQ8, bin_stopQ10-bin_startQ10 vQ8, vQ10 = lQ8/nbinsQ8, lQ10/nbinsQ10 lossesQ8 += [( vQ8/norm,math.sqrt(lQ8)/nbinsQ8/norm )] lossesQ10 += [( vQ10/norm,math.sqrt(lQ10)/nbinsQ10/norm )] hname, nbins, xmin, xmax = 'hmaxLoss', len(colls), 0, len(colls) hist_maxLoss = TH1F(hname, hname, nbins, xmin, xmax) hist_maxLoss.GetYaxis().SetTitle('#eta [m^{-1}]') hist_maxLoss.SetMarkerStyle(20) hist_maxLoss.SetMarkerColor(kBlue) hist_maxLoss.SetLineColor(kBlue) hist_Q8 = hist_maxLoss.Clone('lossesQ8') hist_Q8.SetMarkerStyle(22) hist_Q8.SetMarkerColor(kPink-9) hist_Q8.SetLineColor(kPink-9) hist_Q10 = hist_maxLoss.Clone('lossesQ10') hist_Q10.SetMarkerStyle(23) hist_Q10.SetMarkerColor(kGreen-3) hist_Q10.SetLineColor(kGreen-3) for i in range(len(colls)): hist_maxLoss.SetBinContent(i+1, maxLosses[i][0]) hist_maxLoss.SetBinError(i+1, maxLosses[i][1]) hist_maxLoss.GetXaxis().SetBinLabel(i+1, colls[i][1].lstrip('_')) hist_Q8.SetBinContent(i+1, lossesQ8[i][0]) hist_Q8.SetBinError(i+1, lossesQ8[i][1]) hist_Q10.SetBinContent(i+1,lossesQ10[i][0]) hist_Q10.SetBinError(i+1, lossesQ10[i][1]) cv = TCanvas( 'cv' , 'cv' , 2000, 700) gPad.SetGridx(1) gPad.SetGridy(1) YurMin, YurMax = 6e-7,20e-6 hist_maxLoss.GetYaxis().SetRangeUser(YurMin,YurMax) hist_maxLoss.GetXaxis().SetNdivisions(len(colls)) hist_maxLoss.Draw('pe') hist_Q8.Draw('pesame') hist_Q10.Draw('pesame') if beamn == '1': x1, y1, x2, y2 = 0.75, 0.75, 0.9, 0.9 else: x1, y1, x2, y2 = 0.5, 0.75, 0.7, 0.9 mlegend = TLegend( x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mlegend.AddEntry(hist_maxLoss, '10% of max cold loss', 'lpe') mlegend.AddEntry(hist_Q8, 'loss in Q8', 'lpe') mlegend.AddEntry(hist_Q10, 'loss in Q10', 'lpe') mlegend.Draw() lv = TLine() lv.SetLineStyle(1) lv.SetLineWidth(2) lv.SetLineColor(1) xval = len(collsHB1) lv.DrawLine(xval,YurMin,xval,YurMax) lab = mylabel(42) lab.DrawLatex(.38, y1-0.1, 'hHalo') if beamn == '1': lab.DrawLatex(.69, y1-0.1, 'vHalo') else: lab.DrawLatex(.9, y1-0.1, 'vHalo') resulthist = 'complossesB'+beamn pname = wwwpath pname += subfolder + resulthist+'.png' print('Saving file as' + pname ) cv.Print(pname)
def cv85(): # --------------------------------------------------- rel = 'comppint' # rel = 'compallpress' a, b = 1, 1 cv = TCanvas('cv' + rel, 'cv' + rel, a * 2100, b * 900) cv.Divide(a, b) cv.SetLogy(1) cv.SetGridy(0) x1, y1, x2, y2 = 0.75, 0.6, 0.88, 0.94 mlegend = TLegend(x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mg = TMultiGraph(rel, rel) lm = 'l' grs = [] for i, (pFile, xTitle, lText) in enumerate(pData): print "Getting data from file", pFile print "." * 33 data = {} if pFile.count("LSS1"): data = cv32.getdata14c(pFile) stmp, rho_C, rho_H, rho_O = cv65.getAtomicRho(data) stmp2 = stmp[1:] s_full = stmp2[::-1] moleculeKeys = ['H2_N2Eq', 'CH4_N2Eq', 'CO_N2Eq', 'CO2_N2Eq'] for j in range(1, len(data['H2_N2Eq'])): sumPress = 0. for mk in moleculeKeys: sumPress += float(data[mk][j]) totalPress += [sumPress] else: data = cv79.getdata5c(pFile) totalPress = cv79.getTotalPressure(data) pressCO = data['CO_Eq'] pressCO2 = data['CO2_Eq'] pressCH4 = data['CH4_Eq'] pressH2 = data['H2_Eq'] s_full = data['s'] s_incoming = [] # only one side, chose positive s s_positiveb1, s_positiveb2 = [], [] #print s_full for cs in s_full: s = float(cs) if s < 0.: s_positiveb1 += [-s] else: s_positiveb2 += [s] print "len(s_positiveb1)", len(s_positiveb1) print "len(s_positiveb2)", len(s_positiveb2) if lText.count("B2"): lenposb2 = len(s_positiveb2) press_tot_incomingbeam = totalPress[lenposb2:] pressH2_incoming = pressH2[lenposb2:] pressCO_incoming = pressCO[lenposb2:] pressCH4_incoming = pressCH4[lenposb2:] pressCO2_incoming = pressCO2[lenposb2:] s_incoming = s_positiveb2[:len(s_positiveb2) - 1] else: press_tot_incomingbeam = [ p for p in totalPress[:len(s_positiveb1) + 1] ] pressH2_incoming = pressH2[:len(s_positiveb1) + 1] pressCO_incoming = pressCO[:len(s_positiveb1) + 1] pressCH4_incoming = pressCH4[:len(s_positiveb1) + 1] pressCO2_incoming = pressCO2[:len(s_positiveb1) + 1] s_incoming = s_positiveb1 if pFile.count("LSS"): press_tot_incomingbeam = totalPress[::-1] print s_incoming[:100], press_tot_incomingbeam[:100] xlist, ylist, col, mstyle, lg = s_incoming, press_tot_incomingbeam, cols[ i], 20 + i, lText + 'total' grs += [makeTGraph(xlist, ylist, col, mstyle)] mlegend.AddEntry(grs[-1], lg, lm) mg.Add(grs[-1]) print "plot added" # xlist, ylist, col, mstyle, lg = s_incoming,pressH2_incoming , cols[i]+1, 20,lText + 'H2' # grs += [ makeTGraph(xlist, ylist, col, mstyle)] # mlegend.AddEntry(grs[-1], lg, lm) # mg.Add(grs[-1]) # xlist, ylist, col, mstyle, lg = s_incoming,pressCH4_incoming , cols[i]+2, 20,lText + 'CH4' # grs += [ makeTGraph(xlist, ylist, col, mstyle)] # mlegend.AddEntry(grs[-1], lg, lm) # mg.Add(grs[-1]) # xlist, ylist, col, mstyle, lg = s_incoming,pressCO2_incoming , cols[i]+2, 20,lText + 'CO2' # grs += [ makeTGraph(xlist, ylist, col, mstyle)] # mlegend.AddEntry(grs[-1], lg, lm) # mg.Add(grs[-1]) # xlist, ylist, col, mstyle, lg = s_incoming,pressCO_incoming , cols[i]+2, 20,lText + 'CO' # grs += [ makeTGraph(xlist, ylist, col, mstyle)] # mlegend.AddEntry(grs[-1], lg, lm) # mg.Add(grs[-1]) mg.Draw("al") #mg.SetTitle("pressure profiles") mg.GetXaxis().SetTitle(xTitle) mg.GetYaxis().SetTitle("total interaction probability") #mg.GetYaxis().SetTitle("total pressure [mbar]") mg.GetYaxis().SetRangeUser(5e-18, 4e-10) #mg.GetYaxis().SetRangeUser(5e-15,4e-3) mlegend.Draw() lab = mylabel(42) lab.DrawLatex(0.42, 0.82, 'incoming beams') pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/6500GeV/' pname = rel + ".pdf" print('Saving file as ' + pname) cv.Print(pname)
def cv30(): debug = 1 doWriteRFile = 1 plotLossMaps = 1 doIR1 = 1 # subfolder to which figures are written pname = wwwpath # pname = '' subfolder = 'TCT/HL/nominalColl/2015/lossmaps/' # subfolder = 'TCT/HL/relaxedColl/newScatt/lossmaps/' # subfolder = '/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/' # subfolder = 'TCT/6.5TeV/' # subfolder = 'TCT/4TeV/' colls = [ # ('NewScatt_4TeV_hHaloB1'), # ('NewScatt_4TeV_vHaloB1'), # ('NewScatt_4TeV_hHaloB2'), # ('NewScatt_4TeV_vHaloB2'), # ('6.5TeV_hHaloB1_h5'), # ('6.5TeV_vHaloB1_h5'), # ('6.5TeV_hHaloB2_h5'), # ('6.5TeV_vHaloB2_h5'), # ('H5_HL_TCT5LOUT_relaxColl_hHaloB2_roundthin'), # ('H5_HL_TCT5LOUT_relaxColl_vHaloB2_roundthin'), # ('H5_HL_TCT5IN_relaxColl_hHaloB2_roundthin'), # ('H5_HL_TCT5IN_relaxColl_vHaloB2_roundthin'), # ('H5_HL_TCT5LOUT_relaxColl_hHaloB1_flatthin'), # ('H5_HL_TCT5LOUT_relaxColl_vHaloB1_flatthin'), # ('H5_HL_TCT5LOUT_relaxColl_hHaloB1_roundthin'), # ('H5_HL_TCT5LOUT_relaxColl_vHaloB1_roundthin'), # ('H5_HL_TCT5IN_relaxColl_vHaloB1_roundthin'), # ('H5_HL_TCT5IN_relaxColl_vHaloB1_sroundthin'), # ('H5_HL_TCT5IN_relaxColl_vHaloB1_flatthin'), # ('H5_HL_TCT5IN_relaxColl_vHaloB1_sflatthin'), # ('H5_HL_TCT5IN_relaxColl_hHaloB1_roundthin'), # ('H5_HL_TCT5IN_relaxColl_hHaloB1_sroundthin'), # ('H5_HL_TCT5IN_relaxColl_hHaloB1_flatthin'), # ('H5_HL_TCT5IN_relaxColl_hHaloB1_sflatthin'), # ('H5_HL_nomSett_hHalo_b1'), # ('H5_HL_nomSett_vHalo_b1'), ] for coll in colls: pname = wwwpath # pname = '' if not coll.startswith('_'): tag = coll coll = '_' + coll thiscase = coll beam = 'b2' beamn = '2' beamColor = kRed if coll.count('B1') or coll.count('b1'): beam = 'b1' beamn = '1' beamColor = kBlue # my results thispath = workpath + 'runs/HL_TCT5INOUT_relSett/' + tag + '/' #thispath = projectpath + 'HL1.0/' + tag + '/' cmd = 'pwd' process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) myStdOut = process.stdout.read() #thispath = myStdOut.split()[0] + '/' #thispath += tag +'/' if doIR1: rfname = thispath + 'lossmap' + coll + '_IR1.root' else: rfname = thispath + 'lossmap' + coll + '.root' trname = 'normtree' + coll colNumber = 4 if coll.count("_HL"): f3 = gitpath + 'SixTrackConfig/7TeV/hilumiLHC/TCThaloStudies_relaxedCollSettings/' + beam + '/CollPositions.' + beam + '.dat' elif coll.count("6.5TeV"): f3 = gitpath + 'SixTrackConfig/6.5TeV/MED800/B' + beamn + '/CollPositions.' + beam + '.dat' elif coll.count("4TeV"): f3 = gitpath + 'SixTrackConfig/4TeV/TCThaloStudies/b' + beamn + '/CollPositions.' + beam + '.dat' else: print "No CollPosition file defined. Exitiing.... " sys.exit() # use for normalisation the sum of nabs (col 4) f4 = thispath + 'coll_summary' + coll + '.dat' # ------------------------------------------------ if doWriteRFile: print 'Writing ' + '.' * 25 + ' ' + rfname # create a root file rf = TFile(rfname, 'recreate') nt = TTree(trname, 'norm for each coll') if not os.path.exists(f4): print f4, ' does not exist?!' continue t0 = time.time() if doIR1: shiftVal = 10e3 else: shiftVal = length_LHC h_tot_loss, h_cold, h_warm = lossmap.lossmap( beam, thispath, coll, f3, shiftVal) t1 = time.time() print( str(t1 - t0) + ' for returning lossmap histograms of ' + coll) if debug: if h_tot_loss.GetEntries() < 1.: print 'Empty collimator histogram!' sys.exit() if debug: if h_cold.GetEntries() < 1.: print 'Empty histogram! Binary characters in LPI file?' h_tot_loss.Write() h_cold.Write() h_warm.Write() # -- write the for each norm value a branch into ttree t0 = time.time() # setting branch name branchname = coll.replace('.', 'QQQ') if debug and 0: print globals() # use globals dict to convert strings to variable names globals()[branchname] = array('i', [0]) # create branch nt.Branch(branchname, globals()[branchname], branchname + '/i') # get value maxval = int(addCol(f4, colNumber - 1)) # assigning value globals()[branchname][0] = maxval # write to tree nt.Fill() t1 = time.time() nt.Write() rf.Close() # ------------------------------------------------ if plotLossMaps: if not os.path.exists(rfname): print rfname, ' does not exist?!' continue print('Plotting lossmaps from ' + '.' * 20 + ' ' + rfname) trname = 'normtree' + coll doZooms = ['fullring', 'IR7', 'IR5'] doZooms = ['IR5'] if rfname.count("IR1"): doZooms = ['IR1'] for doZoom in doZooms: rf = TFile.Open(rfname) nt = rf.Get(trname) branchname = coll.replace('.', 'QQQ') norm = -9999 for entry in nt: norm = getattr(entry, branchname) print 'norm', norm cv = TCanvas('cv' + coll + str(doZoom), 'cv' + coll + str(doZoom), 1200, 700) # x1,y1,x2,y2 = 0.2, 0.7,0.5,0.7 # ar2 = TArrow(x1,y1,x2,y2,0.02,"-|>") # ar2.SetLineWidth(2) # ar2.SetLineColor(beamColor) # ar2.SetFillColor(beamColor) # ar2.Draw() # lBeam = mylabel(42) # lBeam.SetTextColor(beamColor) # lBeam.DrawLatex(0.3, 0.7, "B" + beamn) YurMin, YurMax = 3.2e-9, 3. hname = 'coll_loss' + coll if debug: print('Get histograms for coll ' + coll + ', starting with ' + hname) coll_loss = rf.Get(hname) cold_loss = rf.Get('cold_loss' + coll) warm_loss = rf.Get('warm_loss' + coll) coll_loss.SetLineColor(kBlack) warm_loss.SetLineColor(kRed) cold_loss.SetLineColor(kBlue) coll_loss.SetFillColor(kBlack) warm_loss.SetFillColor(kRed) cold_loss.SetFillColor(kBlue) coll_loss.Scale(1.0 / norm) cold_loss.Scale(1.0 / norm) warm_loss.Scale(1.0 / norm) if doZoom == 'IR1': xmin = coll_loss.GetXaxis().GetBinLowEdge(1) xlab = [ str(length_LHC + xmin + i * 10) for i in range(int(-xmin) / 10) ] xlab += [ str(i * 10) for i in range(int(length_LHC + xmin) / 10) ] # for i,xl in enumerate(xlab): coll_loss.GetXaxis().SetBinLabel(i+1, xl) # legend if beam.count('1') and doZoom == 'fullring': x1, y1, x2, y2 = 0.18, 0.78, 0.42, 0.9 elif doZoom == 'IR7': x1, y1, x2, y2 = 0.6, 0.78, 0.91, 0.9 else: x1, y1, x2, y2 = 0.6, 0.78, 0.91, 0.9 # x-axis XurMin, XurMax = 0., length_LHC if beam.count('2'): if doZoom == 'IR5': XurMin, XurMax = 13.e3, 14e3 elif doZoom == 'IR7': XurMin, XurMax = 6.3e3, 8.0e3 elif doZoom == 'IR1': XurMin, XurMax = -2.5e3, 2.0e3 else: if doZoom == 'IR5': XurMin, XurMax = 13.e3, 14e3 elif doZoom == 'IR7': XurMin, XurMax = 19.7e3, 20.6e3 elif doZoom == 'IR1': XurMin, XurMax = -2.5e3, 2.0e3 coll_loss.Draw('hist') warm_loss.Draw('samehist') cold_loss.Draw('samehist') lh = [] # YurMin = 3.2e-9 lhRange = [3e-9 + i * 1e-9 for i in range(3, 7)] lhRange += [i * 1.e-8 for i in range(1, 11)] lhRange += [i * 1.e-7 for i in range(1, 11)] lhRange += [i * 1.e-6 for i in range(1, 11)] lhRange += [i * 1.e-5 for i in range(1, 11)] lhRange += [i * 1.e-4 for i in range(1, 11)] lhRange += [i * 1.e-3 for i in range(1, 11)] lhRange += [i * 1.e-2 for i in range(1, 11)] lhRange += [i * 1.e-1 for i in range(1, 11)] lhRange += [i * 1. for i in range(1, int(YurMax))] for i in lhRange: lh += [TLine()] lh[-1].SetLineStyle(1) lh[-1].SetLineColor(kGray) lh[-1].DrawLine(XurMin, i, XurMax, i) lv = [] lvRange = [1000 * i for i in range(0, int(length_LHC * 1e-3))] for s in lvRange: if s > XurMin and s < XurMax: lv += [TLine()] lv[-1].SetLineStyle(1) lv[-1].SetLineColor(kGray) lv[-1].DrawLine(s, YurMin, s, YurMax) coll_loss.Draw('same') warm_loss.Draw('same') cold_loss.Draw('same') coll_loss.GetXaxis().SetRangeUser(XurMin, XurMax) coll_loss.GetYaxis().SetRangeUser(YurMin, YurMax) thelegend = TLegend(x1, y1, x2, y2) thelegend.SetFillColor(0) thelegend.SetLineColor(0) thelegend.SetTextSize(0.035) thelegend.SetShadowColor(10) thelegend.AddEntry(coll_loss, 'losses on collimators', 'L') thelegend.AddEntry(warm_loss, 'warm losses', 'L') thelegend.AddEntry(cold_loss, 'cold losses', 'L') thelegend.Draw() case = coll.split('_60')[0].replace('_', ' ') case = case.replace("relaxColl", "2#sigma-retract.") case = case.replace("H5", "") lab = mylabel(42) lab.SetTextSize(0.035) lab.DrawLatex(0.28, y2 + 0.055, case) if doZoom == 'fullring' and beam.count('1'): lab = mylabel(42) lab.SetTextColor(kGreen + 1) lab.SetTextSize(0.04) lab.DrawLatex(0.15, 0.62, 'IR1') lab.DrawLatex(0.88, 0.62, 'IR1') lab.DrawLatex(0.23, 0.62, 'IR2') lab.DrawLatex(0.33, 0.62, 'IR3') lab.DrawLatex(0.51, 0.62, 'IR5') lab.DrawLatex(0.61, 0.62, 'IR6') lab.DrawLatex(0.70, 0.92, 'IR7') lab.DrawLatex(0.79, 0.62, 'IR8') elif doZoom == 'fullring' and beam.count('2'): lab = mylabel(42) lab.SetTextColor(kGreen + 1) lab.SetTextSize(0.04) lab.DrawLatex(0.15, 0.6, 'IR1') lab.DrawLatex(0.88, 0.6, 'IR1') lab.DrawLatex(0.23, 0.6, 'IR8') lab.DrawLatex(0.33, 0.92, 'IR7') lab.DrawLatex(0.43, 0.6, 'IR6') lab.DrawLatex(0.52, 0.6, 'IR5') lab.DrawLatex(0.61, 0.6, 'IR4') lab.DrawLatex(0.70, 0.6, 'IR3') lab.DrawLatex(0.79, 0.6, 'IR2') elif doZoom.count("IR"): lab = mylabel(42) lab.SetTextColor(kGreen + 1) lab.SetTextSize(0.04) lab.DrawLatex(0.5, 0.83, doZoom) gPad.RedrawAxis() gPad.SetGrid(0, 1) gPad.SetLogy(1) pname += subfolder + hname + '_' + doZoom + '.pdf' print('Saving file as' + pname) cv.Print(pname)
def cv32c(pFile, xTitle, data, doCorr, var): lText = '2012' if pFile.count('2011'): lText = '2011' if not var: a,b = 1,2 else: a,b, = 1,1 cv = TCanvas( 'cv', 'cv', a*2100, b*900) cv.Divide(a,b) cv.cd(1) x1, y1, x2, y2 = 0.8, 0.65, 0.9, 0.9 mylegend = TLegend( x1, y1, x2, y2) mylegend.SetFillColor(0) mylegend.SetFillStyle(0) mylegend.SetLineColor(0) mylegend.SetTextSize(0.035) mylegend.SetShadowColor(0) mylegend.SetBorderSize(0) mgr = TMultiGraph() xKey, yKey, color, mStyle, lg = 's','avPress', kGreen, 23, 'aver. pressure' g0 = makeGraph(data, xKey, yKey, color, mStyle) mylegend.AddEntry(g0, lg, "p") mgr.Add(g0) if doCorr: xKey, yKey, color, mStyle, lg = 's','avPressCorr', kBlue, 24, 'aver. pressure corr.' g1 = makeGraph(data, xKey, yKey, color, mStyle) mylegend.AddEntry(g1, lg, "p") mgr.Add(g1) mgr.Draw("ap") gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.45, 0.9, lText) mgr.SetTitle("pressure profiles") mgr.GetXaxis().SetTitle(xTitle) mgr.GetYaxis().SetTitle("av. pressure") mgr.GetYaxis().SetRangeUser(1e-12,1e-6) mylegend.Draw() # .................................................................................................... cv.cd(2) x1, y1, x2, y2 = 0.8, 0.65, 0.9, 0.9 mlegend = TLegend( x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mg = TMultiGraph() xKey, yKey, color, mStyle, lg = 's','H2Eq', kBlue, 23, 'H_{2} Eq' g2 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g2, lg, "p") mg.Add(g2) if doCorr: xKey, yKey, color, mStyle, lg = 's','H2EqCorr', kMagenta, 24, 'H_{2} Eq corr.' g3 = makeGraph(data, xKey, yKey, color, mStyle) mlegend.AddEntry(g3, lg, "p") mg.Add(g3) mg.Draw("ap") gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.45, 0.9, lText) mg.SetTitle("pressure profiles") mg.GetXaxis().SetTitle(xTitle) mg.GetYaxis().SetTitle("H_{2} Eq") mg.GetYaxis().SetRangeUser(2e10,9e17) mlegend.Draw() # pname = wwwpath # subfolder = 'TCT/HL/relaxedColl/newScatt/' # pname += subfolder + hname + '_' + doZoom + '.png' pname = pFile.split('.csv')[0] + "c_pressure.png" print('Saving file as ' + pname ) cv.Print(pname)
def cv45(): # current path cpath = workpath + 'runs/checkTrajectory6500GeV/4TeV/' cpath = '/afs/cern.ch/project/lhc_mib/beamgas/6500GeV_beamsize/' cpath = thispath + trakfiles = [ # filen name, Xindex, Yindex, markerstyle, # ['/afs/cern.ch/work/r/rkwee/HL-LHC/runs/checkTrajectory6500GeV/madSY_b2.dat', 0,1, kGreen+1, 21, ], # [cpath + 'ir1b2_exp001_TRAKFILE.luigi', 2,1, kBlue+1, 27, ], # [cpath + 'ir1b2_exp001_TRAKFILE.145', 2,1, kBlue+1, 23, ], # [cpath + 'madSYX_b2_thin.dat', 0,1, kGreen-1, 21, 'madx thin seq'], #plots x:s 2,0, 1,0 plots y:s # [cpath + 'madSYX_b2_thick.dat', 0,1, kBlue-1, 22, 'madx thick seq'], # [cpath + 'ir1_4TeV_settings_from_TWISS_20MeV_b1001_TRAKFILE', 2,1, kRed, 20, 'fluka incoming proton'], # 2,0 plots x:s 1,0 plots y:s] # [cpath + 'ir1_4TeV_settings_from_TWISS_20MeV_b1_MYM001_TRAKFILE', 2,1, kMagenta, 23, 'fluka outgoing aproton'], # 2,0 plots x:s 1,0 plots y:s # [cpath + 'ir1_4TeV_settings_from_TWISS_20MeV_b1001_TRAKFILE', 2,0, kRed, 20, 'fluka incoming proton'], # 2,0 plots x:s 1,0 plots y:s] # [cpath + 'ir1_4TeV_settings_from_TWISS_20MeV_b1_MYM001_TRAKFILE', 2,0, kMagenta, 23, 'fluka outgoing aproton'], # 2,0 plots x:s 1,0 plots y:s # [cpath + 'ir1_4TeV_settings_from_TWISS_20MeV_b1_MYM001_fort.89', 5,4, kBlack, 6, 'test size'], # 0cx 1cy 2cz 3x 4y 5z 6J 7A # [cpath + 'ir1_4TeV_settings_from_TWISS_20MeV_b1_orbitDump001_fort.89', 5,4, kBlack, 6, 'test size'], # 0cx 1cy 2cz 3x 4y 5z 6J 7A # [cpath + 'ir1_4TeV_settings_from_TWISS_20MeV_b1_orbitDump001_fort.89', 5,3, kBlack, 6, 'test size'], # 0cx 1cy 2cz 3x 4y 5z 6J 7A # [cpath + 'BEAMGAS.dat', 2,1, kBlack, 6, 'input final BEAMGAS', '_yBEAMGAS', 'y cm'], # 0x 1y 2z 3u 4v # [cpath + 'BEAMGAS.dat', 2,0, kBlack, 6, 'input final BEAMGAS', '_xBEAMGAS', 'x cm'], # 0x 1y 2z 3u 4v # [cpath + 'startBG.dat', 2,1, kBlack, 6, 'input fluka startBG'], # 0x 1y 2z 3u 4v # [cpath + 'startBG.dat', 2,0, kBlack, 6, 'input fluka startBG'], # 0x 1y 2z 3u 4v # [cpath + 'THISISIT.dat', 5,4, kBlack, 6, 'input THISISIT', '_yTHISISIT', 'y cm'], # 0x 1y 2z 3u 4v # [cpath + 'THISISIT.dat', 2,0, kBlack, 6, 'input THISISIT', '_xTHISISIT', 'x cm'], # 0x 1y 2z 3u 4v # [cpath + 'BGAS10.dat', 2,1, kBlack, 6, 'input final BEAMGAS', '_yBGAS10', 'y cm'], # 0x 1y 2z 3u 4v # [cpath + 'BGAS10.dat', 2,0, kBlack, 6, 'input final BEAMGAS', '_xBGAS10', 'x cm'], # 0x 1y 2z 3u 4v # [cpath + 'BGAS.dat', 2,1, kBlack, 6, 'input final BEAMGAS', '_yBGAS', 'y cm'], # 0x 1y 2z 3u 4v repls #[cpath + 'awked_downselected_fort.89.10.cv53', 2,1, kBlack, 6, 'y-orbit at 6.5 TeV', '_yBGAS', 'y [cm]'], # 0x 1y 2z 3u 4v repls [cpath + 'awked_downselected_fort.89.10.cv53', 2,0, kBlack, 6, 'x-orbit at 6.5 TeV', '_xBGAS', 'x [cm]'], # 0x 1y 2z 3u 4v repls ] energy = "6.5 TeV" rel = '' ytitle = '' XurMin, XurMax = 150.,250. # zoom into badly increased beamsize region XurMin, XurMax = 20,80 #XurMin, XurMax = -1, -1 YurMin, YurMax = -10.5,-9.2 # zoom into badly increased beamsize region YurMin, YurMax = -0.5, 0.5 #YurMin, YurMax = -0.02, 0.7 #YurMin, YurMax = -1,-1 cv = TCanvas( 'cv', 'cv', 1000, 600) x1, y1, x2, y2 = 0.34, 0.65, 0.9, 0.9 mlegend = TLegend( x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mg = TMultiGraph() # marker in legend lm = 'p' gr = [] for fn,Xindex,Yindex,color,mStyle,lg,rel,ytitle in trakfiles: print 'opening', fn [S,Y] = helpers.getListFromColumn([Xindex,Yindex], fn) xList, yList = S,Y xinmeter = [x*0.01 for x in xList] gr += [ makeTGraph(xinmeter, yList, color, mStyle) ] mlegend.AddEntry(gr[-1], lg, lm) mg.Add(gr[-1]) mg.Draw("a"+lm) mg.GetYaxis().SetTitle(ytitle) mg.GetXaxis().SetTitle('s [m]') if XurMin != -1: mg.GetXaxis().SetRangeUser(XurMin,XurMax) rel += 'ZoomX' if YurMin != -1: mg.GetYaxis().SetRangeUser(YurMin,YurMax) rel += 'ZoomY' #mlegend.Draw() lab = mylabel(42) lab.DrawLatex(0.45, 0.955,lg) cpath = '/afs/cern.ch/user/r/rkwee/public/www/HL-LHC/TCT/6.5TeV/beamgas/' pname = cpath + 'inputFluka6500GeV'+rel+'.root' pname = cpath + 'inputFluka6500GeV'+rel+'.pdf' print('Saving file as ' + pname ) cv.Print(pname) pname = cpath + 'inputFluka6500GeV'+rel+'.png' print('Saving file as ' + pname ) cv.Print(pname)
def cv88(): # BH b2 4 TeV bbgFile = thispath + "results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root" hname = "XYNMuons_BH_4TeV_B2_20MeV" lText = '4 TeV Halo B2' lcase = " #mu^{#pm}" # E_{kin} > 10 GeV" yrel = "/TCT hit" # HL B1 TeV original binning is bad bbgFile = thispath + "results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root" # TCT5s in, retracted, use old file as new one doesnt have this kind of info anymore hname = "OrigXZMuon_BH_HL_tct5inrdB1_20MeV" lText = 'HL TCT5s in, rd B1, 2#sigma-retract.' lcase = " #mu^{#pm} E_{kin} > 100 GeV" yrel = "/TCT int." # BH b1 4 TeV bbgFile = thispath + "results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root" hname = "XYNMuons_BH_4TeV_B1_20MeV" lText = '4 TeV Halo B1' lcase = " #mu^{#pm}" # E_{kin} > 10 GeV" yrel = "/TCT hit" # BG 4 TeV bbgFile = thispath + "results_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root" hname = "XYNMuons_BG_4TeV_20MeV_bs" # note the tag is GeV but it is MeV lText = '4 TeV BG with beamsize' lcase = " #mu^{#pm}" # E_{kin} > 10 GeV" yrel = "/BG int." # BH b1 6.5 TeV bbgFile = thispath + "results_ir1_BH_6500GeV_b1_20MeV_nprim4752000_30.root" hname = "XYNMuons_BH_6500GeV_haloB1_20MeV" lText = '6.5 TeV Halo B1' lcase = " #mu^{#pm}" # E_{kin} > 10 GeV" yrel = "/TCT hit" # BG 6.5 TeV bbgFile = thispath + "results_ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root" hname = "XYNMuons_BG_6500GeV_flat_20GeV_bs" # note the tag is GeV but it is MeV lText = '6.5 TeV BG with beamsize' lcase = " #mu^{#pm}" # E_{kin} > 10 GeV" yrel = "/BG int." # HL bbgFile = thispath + "results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5924500_30.root" hname = "XYNMuons_BH_HL_tct5inrdB2_20MeV" lText = "HL TCT5s in, retract. sett., B2" lcase = " #mu^{#pm}" # E_{kin} > 100 GeV" yrel = "/TCT int." bbgFile = thispath + "results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5001000_30.root" hname = "XYNMuons_BH_HL_tct5otrdB2_20MeV" lText = "HL TCT4s only, retract. sett., B2" bbgFile = thispath + "results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5550000_30.root" hname = "XYNMuons_BH_HL_tct5inrdB1_20MeV" lText = "HL TCT5s in, retract. sett., B1" lcase = " #mu^{#pm}" # E_{kin} > 100 GeV" yrel = "/TCT int." xtitle = "x [cm]" ytitle = "y [cm]" # xtitle ="s [cm]" # ytitle ="x [cm]" print "Opening", bbgFile nprim = float(bbgFile.split('nprim')[-1].split('_')[0]) rf = TFile.Open(bbgFile, "READ") rbf = 5 hist = rf.Get(hname) print hist nbinsX = hist.GetXaxis().GetNbins() nbinsY = hist.GetYaxis().GetNbins() print("nbinsX=", nbinsX) print("nbinsY=", nbinsY) print("rebinning histogram in X and Y by factor", rbf) rebinnedX = hist.RebinX(rbf) rebinnedXY = rebinnedX.RebinY(rbf) nbinsX = rebinnedX.GetNbinsX() nbinsY = rebinnedXY.GetNbinsY() for xbin in range(1, nbinsX + 1): xwidth = rebinnedXY.GetXaxis().GetBinWidth(xbin) for ybin in range(1, nbinsY + 1): content = rebinnedXY.GetBinContent(xbin, ybin) ywidth = rebinnedXY.GetYaxis().GetBinWidth(ybin) rebinnedXY.SetBinContent(xbin, ybin, content / xwidth / ywidth) cv = TCanvas("cv", "cv", 1100, 1000) gStyle.SetPalette(1) cv.SetRightMargin(0.2) cv.SetTopMargin(0.12) #cv.SetLeftMargin(-0.1) rebinnedXY.GetXaxis().SetTitle(xtitle) rebinnedXY.GetYaxis().SetTitle(ytitle) rebinnedXY.GetZaxis().SetTitleOffset(1.4) rebinnedXY.GetZaxis().SetTitle("particles/cm^{2}" + yrel) XurMin, XurMax = -1, -1 YurMin, YurMax = -1, -1 #XurMin, XurMax = -15, 15 #YurMin, YurMax = -15, 15 rebinnedXY.Draw("COLZ") if XurMin != -1: pass rebinnedXY.GetXaxis().SetRangeUser(XurMin, XurMax) if YurMin != -1: pass rebinnedXY.GetYaxis().SetRangeUser(YurMin, YurMax) gPad.SetLogz(1) gPad.RedrawAxis() cv.RedrawAxis() lx, ly = 0.5, 0.8 lab = mylabel(62) lab.DrawLatex(lx, ly, lcase) lx, ly = 0.18, 0.9 lab.DrawLatex(lx, ly, lText) pname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/" + hname + ".pdf" cv.SaveAs(pname)
def cv81(): do4TeV = 0 # do6p5 = 1 # if do4TeV: year = "2012" energy = "4 TeV" pressFile = '/afs/cern.ch/work/r/rkwee/HL-LHC/beam-gas-sixtrack/pressure_profiles_2012/LSS1_B1_Fill2736_Final.csv' pressFile = '/Users/rkwee/Documents/RHUL/work/data/4TeV/LSS1_B1_Fill2736_Final.csv' bbgFile = '/afs/cern.ch/project/lhc_mib/valBG4TeV/ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root' bbgFile = thispath + 'ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root' beamintensity = 2e14 tag = '_BG_4TeV_20MeV_bs' bgcl = kPink - 3 subfolder = wwwpath + 'TCT/4TeV/beamgas/fluka/reweighted/' elif do6p5: year = "2015" energy = "6.5 TeV" bbgFile = '/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root' pressFile = "/Users/rkwee/Downloads/Density_Fill4536_2041b_26158.8832-500_B1_withECLOUD.txt" beamintensity = 2.29e14 ## https://acc-stats.web.cern.ch/acc-stats/#lhc/fill-details 4536, ring 1. tag = '_BG_6500GeV_flat_20MeV_bs' #!! MMMeV bgcl = kYellow + 2 subfolder = wwwpath + 'TCT/6.5TeV/beamgas/fluka/reweighted/' else: year = "2011" energy = " 3.5 TeV " pressFile = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/LSS1_B1_fill_2028-sync_rad_and_ecloud.csv" bbgFile = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/beam_gas_3.5TeV_IR1_to_arc_20MeV_100M_nprim7660649_66.root" beamintensity = 1.66e14 tag = "_BG_3p5TeV_20MeV" bgcl = kTeal print "Opening", bbgFile nprim = float(bbgFile.split('nprim')[-1].split('_')[0]) rfile = TFile.Open(bbgFile, "READ") tBBG = rfile.Get("particle") yrel = '' sDict = generate_sDict(tag, nprim, tBBG, yrel) # -- small version of plotSpectra Trev = 1. / 11245 kT = 1.38e-23 * 300 # rootfile with results rfoutname = cv70.resultFileBG(bbgFile, year) print "Opening", "." * 30, rfoutname rf = TFile.Open(rfoutname, "READ") for i, skey in enumerate(sDict.keys()): if skey.count("Sel"): continue elif skey.count("Neg"): continue elif skey.count("Pos"): continue elif skey.count("Z") and not skey.startswith("OrigZ"): continue elif skey.count("Neu_"): continue elif skey.count("Char"): continue elif skey.count("Plus") or skey.count("Minus"): continue elif skey.split(tag)[0].endswith("0") or skey.count("XY"): continue elif skey.count("Pio") or skey.count("Kao"): continue # # FOR DEBUGGING/testing elif not skey.count("EkinMuons"): continue doLeft = 0 if skey.count("Phi"): doLeft = 1 cv = TCanvas(skey + 'cv', skey + 'cv', 1400, 900) # right corner x1, y1, x2, y2 = 0.35, 0.75, 0.9, 0.88 xpos = 0.3 if doLeft: x1, y1, x2, y2 = 0.2, 0.75, 0.5, 0.88 xpos = 0.59 mlegend = TLegend(x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) twoDhname_flat = skey + '_flat' twoDhname_reweighted = skey + '_reweighted' twoDhist_flat = rf.Get(twoDhname_flat) twoDhist_reweighted = rf.Get(twoDhname_reweighted) print twoDhist_flat, skey hist_flat = twoDhist_flat.ProjectionX(skey + "makeit1d_flat") hist_reweighted = twoDhist_reweighted.ProjectionX( skey + "makeit1d_reweighted") nbins = hist_reweighted.GetNbinsX() print hist_flat.GetEntries() hname = skey xtitle = sDict[hname][9] ytitle = sDict[hname][10] ytitle = ytitle.split("/")[0] + '/a.u.' XurMin, XurMax = -1, -1. YurMin, YurMax = -1, -1. doLogx, doLogy = 0, 0 # devide by binwidth if skey.count("Ekin"): hist_flat = doEkin(hist_flat, nbins) hist_reweighted = doEkin(hist_reweighted, nbins) doLogx, doLogy = 1, 1 YurMin, YurMax = 5e2, 8e8 if skey.count("Muons"): YurMin, YurMax = 5e2, 8e6 legendunit = sDict[hname][10] elif skey.count("Phi"): hist_flat = doNormalBinw(hist_flat, nbins) hist_reweighted = doNormalBinw(hist_reweighted, nbins) doLogx, doLogy = 0, 1 legendunit = sDict[hname][10] if skey.count("En") and not skey.count("Mu"): YurMin, YurMax = -1, -1 #3e7,8e9 elif skey.count("Mu") and not skey.count("En"): YurMin, YurMax = 3e4, 5e4 else: YurMin, YurMax = 1e5, 6e8 elif skey.count("Rad"): hist_flat = doRad(hist_flat, nbins) hist_reweighted = doRad(hist_reweighted, nbins) hist_flat = helpers.doRebin(hist_flat, 6) hist_reweighted = helpers.doRebin(hist_reweighted, 6) doLogx, doLogy = 0, 1 legendunit = sDict[hname][10] #XurMin,XurMax = 0, 600. elif skey.count("OrigZ"): rbf = 4 hist_flat = doNormalBinw(hist_flat, nbins) hist_reweighted = doNormalBinw(hist_reweighted, nbins) hist_flat.Rebin(rbf) hist_flat.Scale(1. / rbf) hist_reweighted.Rebin(rbf) hist_reweighted.Scale(1. / rbf) YurMin, YurMax = 1e-1, 6e7 legendunit = "/m" doLogx, doLogy = 0, 1 xtitle = "s [m]" hist_flat.Scale(1e7 / nprim) hist_flat.GetXaxis().SetTitle(xtitle) hist_reweighted.GetXaxis().SetTitle(xtitle) if XurMin != -1: hist_flat.GetXaxis().SetRangeUser(XurMin, XurMax) hist_reweighted.GetXaxis().SetRangeUser(XurMin, XurMax) if YurMin != -1: hist_flat.GetYaxis().SetRangeUser(YurMin, YurMax) hist_reweighted.GetYaxis().SetRangeUser(YurMin, YurMax) lg, lm = "flat [10^{7}" + legendunit + "/BG int.]", 'l' mlegend.AddEntry(hist_flat, lg, lm) # hist_flat.SetLineStyle(2) hist_reweighted.SetLineColor(bgcl) hist_reweighted.SetMarkerColor(bgcl) hist_reweighted.SetMarkerSize(0.2) hist_reweighted.SetMarkerStyle(20) hist_reweighted.GetYaxis().SetTitle(ytitle) hist_reweighted.Draw("hp") hist_flat.Draw("histsame") lg, lm = "reweighted [" + legendunit + "/s]", 'lp' mlegend.AddEntry(hist_reweighted, lg, lm) cv.SetLogx(doLogx) cv.SetLogy(doLogy) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.41, 0.955, energy + ' beam-gas') lab.DrawLatex(xpos, 0.82, sDict[hname][6]) mlegend.Draw() pname = wwwpath + 'TCT/6.5TeV/beamgas/fluka/bs/reweighted/' + skey + '.pdf' pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/6500GeV/reweighted/cv81_' + skey + '.pdf' pname = subfolder + 'cv81_' + skey + '.pdf' if energy.count("4 TeV"): pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/cv81_' + skey + '.pdf' #pname = subfolder + 'cv81_' + skey + '.pdf' elif energy.count("3.5 TeV"): pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/xcheck2011/cv81_' + skey + '.pdf' print('Saving file as ' + pname) cv.Print(pname)
def cv12(): subfolder = 'comp/' hname = 'compMu' # 0.01 5.3e-21 # 0.0125893 5.3e-21 # 0.0125893 5.3e-21 muHalo3p5TeV = '/Users/rkwee/Documents/RHUL/work/runs/TCT/muon_rate_enLog_halo.dat' muBgas3p5TeV = '/Users/rkwee/Documents/RHUL/work/runs/TCT/muon_rate_enLog_localBG.dat' rf = TFile.Open('/Users/rkwee/Documents/RHUL/work/runs/TCT/HL/save/results_comp.root') muHaloHLop = rf.Get('EkinMuBHop') muHaloHLds = rf.Get('EkinMuBHds') muBgasHLst = rf.Get('EkinMuBGst') muBgasHLac = rf.Get('EkinMuBGac') muHaloHLop.SetLineColor(kGreen+2) muHaloHLds.SetLineColor(kPink-9) muBgasHLst.SetLineColor(kBlue-1) muBgasHLac.SetLineColor(kAzure-3) axis, yval = [],[] with open(muHalo3p5TeV) as mf: for i,line in enumerate(mf): # use only every second entry of file if not i%2: axis += [ float(line.split()[0]) ] yval += [ float(line.split()[1]) ] yvalBG = [] with open(muBgas3p5TeV) as mf: for i,line in enumerate(mf): # use only every second entry of file if not i%2: yvalBG += [ float(line.split()[1]) ] axis += [10000.] cv = TCanvas( 'cv', 'cv', 10, 10, 1200, 900 ) gPad.SetLogx(1) # gPad.SetLogy(1) histBH = TH1F(hname, hname, len(axis)-1, array('d', axis) ) histBG = TH1F(hname+'BG', hname+'BG', len(axis)-1, array('d', axis) ) histBG.SetLineColor(kOrange) histBH.SetLineColor(kViolet) for i,y in enumerate(yval): histBH.SetBinContent(i+1,y) for i,y in enumerate(yvalBG): histBG.SetBinContent(i+1,y) histBH.Draw('hist') histBG.Draw('histsame') XurMin, XurMax, YurMin, YurMax = 2e-2,9e3,1e-1,8e9 histBH.GetXaxis().SetRangeUser(XurMin, XurMax) histBH.GetYaxis().SetRangeUser(YurMin, YurMax) xtitle, ytitle = 'E [GeV]', '#frac{dN(counts/s)}{dlog E}' histBH.GetXaxis().SetTitle(xtitle) histBH.GetYaxis().SetTitle(ytitle) muHaloHLop.Draw('histsame') muHaloHLds.Draw('histsame') muBgasHLst.Draw('histsame') muBgasHLac.Draw('histsame') x1, y1, x2, y2 = 0.63,0.7,0.95,0.92 mlegend = TLegend( x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mlegend.AddEntry(muBgasHLst, 'BG start-up', "l") mlegend.AddEntry(muBgasHLac, 'BG after cond.', "l") mlegend.AddEntry(histBG, 'BG at 3.5 TeV', "l") mlegend.AddEntry(muHaloHLds, 'BH 12 min loss', "l") mlegend.AddEntry(muHaloHLop, 'BH 100h loss', "l") mlegend.AddEntry(histBH, 'BH at 3.5 TeV', "l") mlegend.Draw() lab = mylabel(42) lab.DrawLatex(0.45, 0.85, '#mu^{#pm}') gPad.RedrawAxis() pname = '/Users/rkwee/Documents/RHUL/work/results/www/TCT/HL/nominalSettings/'+subfolder+'/EkinMuComp3p5.pdf' #cv.SaveAs(pname) histRatioBG = histBG.Clone('cloon') histRatioBH = histBH.Clone('cloony') # hNumerator.Divide(hNumerator, hDenominator, 1, 1, 'B') histRatioBG.Divide(histRatioBG, muBgasHLac, 1, 1, 'B') XurMin, XurMax, YurMin, YurMax = 2e-2,9e3,0,4 histRatioBG.GetXaxis().SetRangeUser(XurMin, XurMax) histRatioBG.GetYaxis().SetRangeUser(YurMin, YurMax) histRatioBG.Draw('hist') mlabBH = mylabel(42) l = TLine() l.SetLineWidth(1) l.SetLineColor(1) l.DrawLine(XurMin,2.5,XurMax,2.5) l.DrawLine(XurMin,1,XurMax,1) mlabBH.DrawLatex(0.45, 0.85, 'BG 3.5 TeV/BG a.c. HL') pname = '/Users/rkwee/Documents/RHUL/work/results/www/TCT/HL/nominalSettings/'+subfolder+'/compMuBG.pdf' cv.SaveAs(pname) histRatioBH.Divide(histRatioBH, muHaloHLop, 1, 1, 'B') XurMin, XurMax, YurMin, YurMax = 2e-2,9e3,1e-5,1 histRatioBH.GetXaxis().SetRangeUser(XurMin, XurMax) histRatioBH.GetYaxis().SetRangeUser(YurMin, YurMax) histRatioBH.Draw('hist') mlab = mylabel(42) mlab.DrawLatex(0.45, 0.85, 'BH 3.5 TeV/BH #tau_{beam} = 100h') l = TLine() l.SetLineWidth(1) l.SetLineColor(1) l.DrawLine(XurMin,0.1,XurMax,0.1) pname = '/Users/rkwee/Documents/RHUL/work/results/www/TCT/HL/nominalSettings/'+subfolder+'/compMuBH.pdf' cv.SaveAs(pname)
def bmPlot(Q8_losses, Q10_losses, max_cold_losses, hname, QA, QB): nbins = len(Q8_losses) cv = TCanvas('cv' + hname, 'cv' + hname, 2000, 800) cv.SetLeftMargin(0.15) cv.SetRightMargin(0.15) cv.SetTopMargin(0.15) hist1 = TH1F(hname, hname, nbins, 1, nbins + 1) hist1.SetMarkerStyle(22) hist1.SetMarkerColor(kMagenta - 3) hist1.SetLineColor(kMagenta - 3) hist1.GetYaxis().SetTitleOffset(.62) hist1.GetYaxis().SetTitle('Cleaning Inefficiency #eta') hist2 = TH1F(hname + 'd', hname + 'd', nbins, 1, nbins + 1) hist2.SetMarkerStyle(23) hist2.SetMarkerColor(kGreen - 3) hist2.SetLineColor(kGreen - 3) hist3 = TH1F(hname + 'm', hname + 'm', nbins, 1, nbins + 1) hist3.SetMarkerStyle(20) hist3.SetMarkerColor(kAzure - 3) hist3.SetLineColor(kAzure - 3) vals = [] cnt = 0 for tcs, val, err in Q8_losses: cnt += 1 hist1.GetXaxis().SetBinLabel(cnt, tcs) hist1.SetBinContent(cnt, val) hist1.SetBinError(cnt, err) vals += [val] cnt = 0 for tcs, val, err in Q10_losses: cnt += 1 hist2.SetBinContent(cnt, val) hist2.SetBinError(cnt, err) vals += [val] cnt = 0 for val, err in max_cold_losses: cnt += 1 hist3.SetBinContent(cnt, val) hist3.SetBinError(cnt, err) vals += [val] minval = min(vals) maxval = max(vals) hist1.GetYaxis().SetRangeUser(minval * .7, maxval * 1.33) hist1.Draw('P') hist3.Draw('PSAME') hist2.Draw('PSAME') hist1.Draw('PSAME') x1, y1, x2, y2 = 0.16, 0.7, 0.42, 0.82 thelegend = TLegend(x1, y1, x2, y2) thelegend.SetFillColor(0) thelegend.SetLineColor(0) thelegend.SetTextSize(0.035) thelegend.SetShadowColor(10) thelegend.AddEntry(hist1, 'at ' + QA, "PL") thelegend.AddEntry(hist2, 'at ' + QB, "PL") thelegend.AddEntry(hist3, '10% of maximum cold loss', "PL") thelegend.Draw() pname = wwwpath pname += 'scan/' + vhalo + hname + '.png' if vHalo: lab = mylabel(60) lab.DrawLatex(x1 + .3, y1 + 0.18, vhalo.rstrip('/')) print(pname) cv.Print(pname)
def cv24(): debug = 1 doWriteRFile = 1 plotLossMaps = 1 colls = [ #('H5_NewScatt_TCT_4TeV_B1hHalo_testfix'), #('H5_NewScatt_TCT_4TeV_B2hHalo_testfix'), #('NewScatt_TCT_4TeV_B1hHalo'), ('twin_H5_NewScatt_TCT_4TeV_B1hHalo_trajectories'), ('twin_NewScatt_TCT_4TeV_B1hHalo_trajectories'), ] thiscase = 'twin' for coll in colls: if not coll.startswith('_'): tag = coll coll = '_'+coll beam = 'b2' beamn = '2' if coll.count('B1'): beam = 'b1' beamn = '1' # my results thispath = workpath + 'runs/' + tag +'/' #thispath = tag + '/' rfname = thispath + 'lossmap'+ coll +'.root' trname = 'normtree' + coll colNumber = 4 f3 = gitpath + 'SixTrackConfig/4TeV/TCThaloStudies/'+beam+'/CollPositions.'+beam+'.dat' # use for normalisation the sum of nabs (col 4) f4 = thispath + 'coll_summary' + coll + '.dat' # ------------------------------------------------ if doWriteRFile: print 'Writing ' + '.'* 25 +' ' + rfname # create a root file rf = TFile(rfname, 'recreate') nt = TTree(trname,'norm for each coll') if not os.path.exists(f4): print f4,' does not exist?!' continue t0 = time.time() h_tot_loss, h_cold, h_warm = lossmap.lossmap(beam,thispath,coll, f3, length_LHC) t1 = time.time() print(str(t1-t0)+' for returning lossmap histograms of ' + coll ) if debug: if h_cold.GetEntries() < 1.: print 'Empty histogram! Binary characters in LPI file?' sys.exit() h_tot_loss.Write() h_cold.Write() h_warm.Write() # -- write the for each norm value a branch into ttree t0 = time.time() # setting branch name branchname = coll.replace('.','QQQ') if debug and 0: print globals() # use globals dict to convert strings to variable names globals()[branchname] = array('i',[0]) # create branch nt.Branch(branchname, globals()[branchname], branchname+'/i') # get value maxval = int(addCol(f4, colNumber-1)) # assigning value globals()[branchname][0] = maxval # write to tree nt.Fill() t1 = time.time() nt.Write() rf.Close() # ------------------------------------------------ if plotLossMaps: if not os.path.exists(rfname): print rfname,' does not exist?!' continue print('Plotting lossmaps from ' + '.'*20 + ' '+ rfname) trname = 'normtree' + coll doZooms = ['fullring','IR7'] if rfname.count("IR1"): doZooms = ['IR1'] for doZoom in doZooms: rf = TFile.Open(rfname) nt = rf.Get(trname) branchname = coll.replace('.','QQQ') norm = -9999 for entry in nt: norm = getattr(entry,branchname) print 'norm', norm cv = TCanvas( 'cv' + coll + str(doZoom), 'cv' + coll + str(doZoom), 1200, 700) YurMin, YurMax = 3.2e-9, 3. hname = 'coll_loss' +coll if debug: print('Get histograms for coll ' + coll + ', starting with ' + hname) coll_loss = rf.Get(hname) cold_loss = rf.Get('cold_loss' +coll) warm_loss = rf.Get('warm_loss' +coll) coll_loss.SetLineColor(kBlack) warm_loss.SetLineColor(kRed) cold_loss.SetLineColor(kBlue) coll_loss.SetFillColor(kBlack) warm_loss.SetFillColor(kRed) cold_loss.SetFillColor(kBlue) coll_loss.Scale(1.0/norm) cold_loss.Scale(1.0/norm) warm_loss.Scale(1.0/norm) if doZoom == 'IR1': xmin = coll_loss.GetXaxis().GetBinLowEdge(1) xlab = [ str(length_LHC+xmin + i*10) for i in range(int(-xmin)/10) ] xlab += [ str(i*10) for i in range(int(length_LHC+xmin)/10) ] # for i,xl in enumerate(xlab): coll_loss.GetXaxis().SetBinLabel(i+1, xl) # legend if beam.count('1') and doZoom == 'fullring': x1, y1, x2, y2 = 0.18, 0.78, 0.42, 0.9 elif doZoom == 'IR7' : x1, y1, x2, y2 = 0.6, 0.78, 0.91, 0.9 else: x1, y1, x2, y2 = 0.6, 0.78, 0.91, 0.9 # x-axis XurMin, XurMax = 0., length_LHC if beam.count('2'): if doZoom == 'IR5': XurMin, XurMax = 13.e3,14e3 elif doZoom == 'IR7': XurMin, XurMax = 6.3e3, 8.0e3 elif doZoom == 'IR1': XurMin, XurMax = -2.5e3, 2.0e3 else: if doZoom == 'IR5': XurMin, XurMax = 13.e3,14e3 elif doZoom == 'IR7': XurMin, XurMax = 19.7e3, 20.6e3 elif doZoom == 'IR1': XurMin, XurMax = -2.5e3, 2.0e3 coll_loss.Draw('hist') warm_loss.Draw('samehist') cold_loss.Draw('samehist') lh = [] # YurMin = 3.2e-9 lhRange = [3e-9+i*1e-9 for i in range(3,7)] lhRange += [i*1.e-8 for i in range(1,11)] lhRange += [i*1.e-7 for i in range(1,11)] lhRange += [i*1.e-6 for i in range(1,11)] lhRange += [i*1.e-5 for i in range(1,11)] lhRange += [i*1.e-4 for i in range(1,11)] lhRange += [i*1.e-3 for i in range(1,11)] lhRange += [i*1.e-2 for i in range(1,11)] lhRange += [i*1.e-1 for i in range(1,11)] lhRange += [i*1. for i in range(1,int(YurMax))] for i in lhRange: lh += [TLine()] lh[-1].SetLineStyle(1) lh[-1].SetLineColor(kGray) lh[-1].DrawLine(XurMin,i,XurMax,i) lv = [] lvRange = [1000*i for i in range(0,int(length_LHC*1e-3))] for s in lvRange: if s > XurMin and s < XurMax: lv += [TLine()] lv[-1].SetLineStyle(1) lv[-1].SetLineColor(kGray) lv[-1].DrawLine(s,YurMin,s,YurMax) coll_loss.Draw('same') warm_loss.Draw('same') cold_loss.Draw('same') coll_loss.GetXaxis().SetRangeUser(XurMin, XurMax) coll_loss.GetYaxis().SetRangeUser(YurMin, YurMax) thelegend = TLegend( x1, y1, x2, y2) thelegend.SetFillColor(0) thelegend.SetLineColor(0) thelegend.SetTextSize(0.035) thelegend.SetShadowColor(10) thelegend.AddEntry(coll_loss,'losses on collimators', 'L') thelegend.AddEntry(warm_loss,'warm losses', 'L') thelegend.AddEntry(cold_loss,'cold losses', 'L') thelegend.Draw() case = coll.split('_60')[0].replace('_',' ') lab = mylabel(60) lab.SetTextSize(0.035) lab.DrawLatex(0.28, y2+0.055, case) if doZoom == 'fullring' and beam.count('1'): lab = mylabel(42) lab.SetTextColor(kGreen+1) lab.SetTextSize(0.04) lab.DrawLatex(0.15, 0.57, 'IR1') lab.DrawLatex(0.88, 0.57, 'IR1') lab.DrawLatex(0.23, 0.56, 'IR2') lab.DrawLatex(0.33, 0.62, 'IR3') lab.DrawLatex(0.51, 0.50, 'IR5') lab.DrawLatex(0.61, 0.58, 'IR6') lab.DrawLatex(0.70, 0.92, 'IR7') lab.DrawLatex(0.79, 0.62, 'IR8') elif doZoom == 'fullring' and beam.count('2'): lab = mylabel(42) lab.SetTextColor(kGreen+1) lab.SetTextSize(0.04) lab.DrawLatex(0.15, 0.43, 'IR1') lab.DrawLatex(0.88, 0.47, 'IR1') lab.DrawLatex(0.23, 0.30, 'IR8') lab.DrawLatex(0.33, 0.92, 'IR7') lab.DrawLatex(0.43, 0.56, 'IR6') lab.DrawLatex(0.51, 0.48, 'IR5') lab.DrawLatex(0.61, 0.34, 'IR4') lab.DrawLatex(0.70, 0.60, 'IR3') lab.DrawLatex(0.79, 0.30, 'IR2') elif doZoom.count("IR"): lab = mylabel(42) lab.SetTextColor(kGreen+1) lab.SetTextSize(0.04) lab.DrawLatex(0.5, 0.83, doZoom) gPad.RedrawAxis() gPad.SetGrid(0,1) gPad.SetLogy(1) pname = wwwpath subfolder = 'TCT/4TeV/hdf5/'+thiscase+'/' pname += subfolder + hname + '_' + doZoom + '.png' print('Saving file as' + pname ) cv.Print(pname)
def cv03(): debug = 1 doWriteRFile = 0 plotLossMaps = 0 doAvLoss = 1 rfname = "7TeVPostLS1_scan_final_vHalo.root" trname = 'normtree' tA = time.time() if doWriteRFile: print "Writing " + '.' * 25 + ' ' + rfname # create a root file rf = TFile(rfname, 'recreate') nt = TTree(trname, "norm for each tcs") for tcs in TCS: tag = '_' + tcs thispath = '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/' + vhalo + '7TeVPostLS1' + tag + '/' beam = 'b2' if tag.count("B1"): beam = 'b1' t0 = time.time() f4 = thispath + 'FirstImpacts' + tag + '.dat' h_tot_loss, h_cold, h_warm = lossmap.lossmap(beam, thispath, tag) t1 = time.time() print(str(t1 - t0) + " for returning lossmap histograms of " + tcs) h_tot_loss.Write() h_cold.Write() h_warm.Write() # -- write the for each norm value a branch into ttree t0 = time.time() # setting branch name branchname = 'norm' + tag branchname = tcs.replace('.', 'QQQ') if debug: print globals() # use globals dict to convert strings to variable names globals()[branchname] = array('i', [0]) # create branch nt.Branch(branchname, globals()[branchname], branchname + '/i') # get value maxval = int(open(f4).read()) if debug: print "('" + tcs + "', " + str(maxval) + ")," # assigning value globals()[branchname][0] = maxval # write to tree nt.Fill() t1 = time.time() print( str(t1 - t0) + " for checking file_len of " + f4 + " = " + str(maxval)) nt.Write() rf.Close() tB = time.time() print(str(tB - tA) + " for producing " + rfname) # ------------------------------------------------ if plotLossMaps: print("Plotting lossmaps from " + "." * 20 + ' ' + rfname) doZooms = [0, 1] rel = '' for doZoom in doZooms: rf = TFile.Open(rfname) nt = rf.Get(trname) for tcs in TCS: tag = '_' + tcs thispath = '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/vHalo/7TeVPostLS1' + tag + '/' beam = 'b1' branchname = tcs.replace('.', 'QQQ') nt.SetBranchAddress(branchname, globals()[branchname]) nt.GetEntry(0) norm = globals()[branchname][0] if debug: print "('" + tcs + "', " + str(norm) + ")," if tag.count("B1"): beam = 'b1' cv = TCanvas('cv' + tag + str(doZoom), 'cv' + tag + str(doZoom), 1200, 700) YurMin, YurMax = 3.2e-9, 3. hname = 'coll_loss' + tag if debug: print("Get histograms for tcs " + tcs + ", starting with " + hname) coll_loss = rf.Get(hname) cold_loss = rf.Get('cold_loss' + tag) warm_loss = rf.Get('warm_loss' + tag) coll_loss.SetLineColor(kBlack) warm_loss.SetLineColor(kOrange) cold_loss.SetLineColor(kBlue) coll_loss.SetFillColor(kBlack) warm_loss.SetFillColor(kOrange) cold_loss.SetFillColor(kBlue) coll_loss.Scale(1.0 / norm) cold_loss.Scale(1.0 / norm) warm_loss.Scale(1.0 / norm) if beam.count('1') and not doZoom: x1, y1, x2, y2 = 0.18, 0.78, 0.42, 0.9 else: x1, y1, x2, y2 = 0.68, 0.78, 0.91, 0.9 XurMin, XurMax = 0., length_LHC if doZoom and beam.count('1'): XurMin, XurMax = 19.7e3, 20.6e3 rel = tag + '_zoom' if doZoom and beam.count("2"): XurMin, XurMax = 6.4e3, 7.3e3 rel = tag + '_zoom' coll_loss.Draw('hist') cold_loss.Draw('samehist') warm_loss.Draw('samehist') lh = [] # YurMin = 3.2e-9 lhRange = [3e-9 + i * 1e-9 for i in range(3, 7)] lhRange += [i * 1.e-8 for i in range(1, 11)] lhRange += [i * 1.e-7 for i in range(1, 11)] lhRange += [i * 1.e-6 for i in range(1, 11)] lhRange += [i * 1.e-5 for i in range(1, 11)] lhRange += [i * 1.e-4 for i in range(1, 11)] lhRange += [i * 1.e-3 for i in range(1, 11)] lhRange += [i * 1.e-2 for i in range(1, 11)] lhRange += [i * 1.e-1 for i in range(1, 11)] lhRange += [i * 1. for i in range(1, int(YurMax))] for i in lhRange: lh += [TLine()] lh[-1].SetLineStyle(1) lh[-1].SetLineColor(kGray) lh[-1].DrawLine(XurMin, i, XurMax, i) lv = [] lvRange = [1000 * i for i in range(0, int(length_LHC * 1e-3))] for s in lvRange: if s > XurMin and s < XurMax: lv += [TLine()] lv[-1].SetLineStyle(1) lv[-1].SetLineColor(kGray) lv[-1].DrawLine(s, YurMin, s, YurMax) coll_loss.Draw('same') cold_loss.Draw('same') warm_loss.Draw('same') coll_loss.GetXaxis().SetRangeUser(XurMin, XurMax) coll_loss.GetYaxis().SetRangeUser(YurMin, YurMax) thelegend = TLegend(x1, y1, x2, y2) thelegend.SetFillColor(0) thelegend.SetLineColor(0) thelegend.SetTextSize(0.035) thelegend.SetShadowColor(10) thelegend.AddEntry(coll_loss, 'losses on collimators', "L") thelegend.AddEntry(cold_loss, 'cold losses', "L") thelegend.AddEntry(warm_loss, 'warm losses', "L") thelegend.Draw() lab = mylabel(60) lab.DrawLatex(x1, y1 - 0.1, tcs) gPad.RedrawAxis() gPad.SetGrid(0, 1) gPad.SetLogy(1) pname = wwwpath pname += 'scan/' + vhalo + 'losses' + rel + '.png' print('Saving file as' + pname) cv.Print(pname) # ------------------------------------------------ tC = time.time() print(str(tC - tB) + " for plotting lossmaps.") if doAvLoss: print "Calculating losses at Q8 and Q10 for B1 and Q7 and Q9 for B2" print "Opening ", rfname rf = TFile.Open(rfname) nt = rf.Get(trname) max_cold_losses, Q8_losses, Q10_losses = [], [], [] # for better visibility scaleFactor = 10. for tcs in TCS: tag = '_' + tcs cold_loss = rf.Get('cold_loss' + tag) branchname = tag.replace('.', 'QQQ') globals()[branchname] = array('i', [0]) nt.SetBranchAddress(branchname, globals()[branchname]) nt.GetEntry(0) norm = globals()[branchname][0] cold_loss.Scale(1. / norm) print "-" * 20, tcs, "-" * 20 if tag.count("B1"): p1_cold_loss_start, p1_cold_loss_end = 20290., 20340. p2_cold_loss_start, p2_cold_loss_end = 20380., 20430. else: p1_cold_loss_start, p1_cold_loss_end = 6950., 7010. p2_cold_loss_start, p2_cold_loss_end = 7050., 7110. #norm = 1. p1_bin_start = cold_loss.FindBin(p1_cold_loss_start) p1_bin_end = cold_loss.FindBin(p1_cold_loss_end) p1_cold_loss = cold_loss.Integral(p1_bin_start, p1_bin_end) p1_nbins = p1_bin_end - p1_bin_start p2_bin_start = cold_loss.FindBin(p2_cold_loss_start) p2_bin_end = cold_loss.FindBin(p2_cold_loss_end) p2_cold_loss = cold_loss.Integral(p2_bin_start, p2_bin_end) p2_nbins = p2_bin_end - p2_bin_start # statistical uncertainty p1_stat, p2_stat = 0., 0. if debug: print('Q8: averaging from bin ' + str(p1_bin_start) + ' to bin ' + str(p1_bin_end)) Q8_losses += [(tcs, p1_cold_loss / p1_nbins, math.sqrt(p1_cold_loss / norm) / p1_nbins)] Q10_losses += [(tcs, p2_cold_loss / p2_nbins, math.sqrt(p2_cold_loss / norm) / p2_nbins)] max_cold_loss = cold_loss.GetMaximum() / scaleFactor max_cold_losses += [(max_cold_loss, math.sqrt(max_cold_loss / norm))] print "Maximum loss in bin", cold_loss.GetMaximumBin(), \ " from ", cold_loss.GetBinLowEdge(cold_loss.GetMaximumBin()), " to ", cold_loss.GetBinLowEdge(cold_loss.GetMaximumBin() + 1) # plot the benchmark plots bmPlot(Q8_losses, Q10_losses, max_cold_losses, 'complossesErr_' + rfname.split('.')[0], QA, QB)
def cv13(): # ratio BGac to BGst # fNum = workpath + 'results/results_BGst.root' # fDenom = workpath + 'results/results_BGac.root' # subfolder = 'HL/compBG/' # lTextNum = 'BG start-up' # lTextDenom = 'BG after cond.' # tagNum, tagDenom = 'BGst', 'BGac' # sDict = sDict_BH_4TeV fNum = workpath + 'results/results_beam-halo_3.5TeV-R1_D1.root' fDenom = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_b2_nprim7825000_66.root' subfolder = '4TeV/compBH/' lTextNum = 'BH 3.5 TeV ' lTextDenom = 'BH 4 TeV' tagNum, tagDenom = 'BH_3p5TeV', 'BH_4TeV' # tagNum, tagDenom = 'BH_4TeV', 'BH_4TeV' sDict = sDict_BH_3p5TeV # fNum = workpath + 'results/results_BH_3p5TeV.root' # fDenom = workpath + 'results/results_BH.root' # subfolder = 'compBH_HLvs3p5/' # lTextNum = 'BH HL TeV' # lTextDenom = 'BH 3.5 TeV' # tagNum, tagDenom = 'BH_3p5TeV', 'BH' # sDict = sDict_BH_3p5TeV # fNum = workpath + 'results/results_BH_3p5TeV.root' # fDenom = workpath + 'results/results_BH_3p5TeV_v2.root' # subfolder = 'compBH_3p5vs3p5_v2/' # lTextNum = 'BH 3.5 TeV' # lTextDenom = 'BH 3.5 TeV analytic magnf' # tagNum, tagDenom = 'BH_3p5TeV', 'BH_3p5TeV_v2' # sDict = sDict_BH_3p5TeV rfNum = TFile.Open(fNum) rfDenom = TFile.Open(fDenom) print 'opening as numerator', fNum print 'opening as denominator', fDenom msize = 0.05 for skey in sDict.keys(): if skey.count('XY'): continue cv = TCanvas( 'cv'+skey, 'cv'+skey, 10, 10, 80, 80 ) x1, y1, x2, y2 = 0.63,0.7,0.95,0.92 mlegend = TLegend( x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.035) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) p1 = TPad('p1'+skey,'p1'+skey,0.01,0.35,0.99,0.99) if skey.count('Ekin'): p1.SetLogx(1) p1.SetLogy(1) if skey.count('En'): p1.SetLogy(1) p1.Draw() p1.SetBottomMargin(0.00) p2 = TPad('p2'+skey,'p2'+skey,0.01,0.01,0.99,.35) if skey.count('Ekin'): p2.SetLogx(1) p2.Draw() p2.SetTopMargin(0.00) p2.SetBottomMargin(0.25) p1.cd() hnameNum = skey hnameDenom = hnameNum.replace(tagNum, tagDenom) print 'plotting ratio of ', hnameNum, 'and', hnameDenom xtitle, ytitle = sDict[skey][9], sDict[skey][10] histNum = rfNum.Get(hnameNum) histDenom = rfDenom.Get(hnameDenom) if hnameNum.count('Rad'): histNum.Rebin() histDenom.Rebin() histNum.GetXaxis().SetTitle(xtitle) histNum.GetYaxis().SetTitle(ytitle) histNum.SetLineColor(kAzure-2) histDenom.SetLineColor(kOrange-2) histNum.SetMarkerColor(kAzure-2) histDenom.SetMarkerColor(kOrange-2) histNum.SetMarkerStyle(21) histDenom.SetMarkerStyle(20) histDenom.SetMarkerSize(msize) histNum.SetMarkerSize(msize) histNum.Draw('h') histDenom.Draw('hsame') mlegend.AddEntry(histNum, lTextNum, "l") mlegend.AddEntry(histDenom, lTextDenom, "l") mlegend.Draw() lab = mylabel(42) lab.DrawLatex(0.45, 0.85, sDict[skey][6]) hnameRatio = 'ratio'+hnameNum hRatio = histNum.Clone(hnameRatio) hRatio.Divide(histNum, histDenom, 1, 1) hRatio.SetLineColor(kRed) hRatio.SetMarkerColor(kRed) hRatio.SetMarkerStyle(22) hRatio.SetMarkerSize(msize) l = TLine() l.SetLineWidth(1) l.SetLineColor(kSpring) XurMin = hRatio.GetBinLowEdge(1) XurMax = hRatio.GetBinLowEdge( hRatio.GetNbinsX()+1 ) p2.cd() if hnameNum.count('Rad') or hRatio.GetMaximum()>200: hRatio.GetYaxis().SetRangeUser(-2,2) hRatio.GetYaxis().SetTitle('ratio ' + lTextNum + '/' + lTextDenom) hRatio.Draw('pe') l.DrawLine(XurMin,1,XurMax,1) pname = '/Users/rkwee/Documents/RHUL/work/results/www/TCT/'+subfolder+hnameRatio.split('_')[0]+'.pdf' print pname cv.SaveAs(pname)
def cv16(): fNum = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_b2_nprim7825000_66.root' fDenom = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root' subfolder = wwwpath + 'TCT/4TeV/compB2oldB2new/' lTextNum = 'B2 old' lTextDenom = 'B2 new' tagNum, tagDenom = 'BH_4TeV_B2', 'BH_4TeV_B2_20MeV' nColor, dColor = kCyan+1, kTeal fNum = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root' fDenom = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root' subfolder = wwwpath + 'TCT/4TeV/compB1B2/' lTextNum = 'B1' lTextDenom = 'B2' tagNum, tagDenom = 'BH_4TeV_B1', 'BH_4TeV_B2' nColor, dColor = kOrange-3, kPink-7 fDenom = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root' fNum = workpath + 'results/results_beam-halo_3.5TeV-R1_D1_nprim2344800_66.root' subfolder = wwwpath + 'TCT/4TeV/compB2_3p5vs4TeV/' lTextNum = 'B2 3.5 TeV' lTextDenom = 'B2 4 TeV' tagNum, tagDenom = 'BH_3p5TeV', 'BH_4TeV_B2_20MeV' nColor, dColor = kOrange+1, kBlue-3 fNum = workpath + 'runs/FL_TCT5LOUT_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5350000_30.root' fDenom = workpath + 'runs/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root' fDenom = workpath + 'runs/FL_TCT5LOUT_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5350000_30.root' fNum = workpath + 'runs/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root' subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/comp/ratios/normalised/swap/' lTextNum = 'TCT4 only' lTextDenom = 'TCT5 in' lTextDenom = 'TCT4 only' lTextNum = 'TCT5 in' # tagNum, tagDenom = '_BH_HL_tct5otrdB1_20MeV', '_BH_HL_tct5inrdB1_20MeV' normNum, normDenom = normOUT/nprimOUT, normIN/nprimIN tagDenom, tagNum = '_BH_HL_tct5otrdB1_20MeV', '_BH_HL_tct5inrdB1_20MeV' normDenom, normNum = normOUT/nprimOUT, normIN/nprimIN dColor, nColor = kRed-4, kBlue-3 rCol = kPink-7 # need one file to generate sDict bbgFile = fNum print "Opening for sDict generation ...", bbgFile tag = tagNum norm = float(bbgFile.split('nprim')[-1].split('_')[0]) tBBG = TFile.Open(bbgFile).Get(treeName) yrel = '/s' sDict = generate_sDict(tag, norm, tBBG, yrel) if not os.path.exists(subfolder): print 'making dir', subfolder os.mkdir(subfolder) if fNum.count('B1') or fNum.count('b1'): Beam, beam = 'B1', 'b1' elif fNum.count('B2') or fNum.count('b2'): Beam, beam = 'B2','b2' else: Beam, beam = '', '' rfNum = TFile.Open(fNum) rfDenom = TFile.Open(fDenom) print 'opening as numerator', fNum print 'opening as denominator', fDenom print sDict.keys() msize = 0.05 for skey in sDict.keys(): if skey.count('XY'): continue if skey.startswith('Orig'): continue # if not skey.count('EkinNeutro'): continue cv = TCanvas( 'cv'+skey, 'cv'+skey, 100, 120, 600, 600 ) x1, y1, x2, y2 = 0.65,0.75,0.9,0.9 mlegend = TLegend( x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.055) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) p1 = TPad('p1'+skey,'p1'+skey,0.01,0.35,0.99,0.99) ymax = 2. XurMin, XurMax = -1, -1 YurMin, YurMax = -1, -1 dOptNum, dOptDenom = 'h', 'hsame' if skey.count('Ekin'): p1.SetLogx(1) p1.SetLogy(1) ymax = 3. XurMin, XurMax = 0.02, 7.0e3 if skey.count('En') or skey.startswith('Rad'): p1.SetLogy(1) ymax = 3. XurMin, XurMax = 0.0, 600. if skey.count('Zcoor'): p1.SetLogy(1) p1.SetGridx(1) p1.SetGridy(1) p1.Draw() p1.SetBottomMargin(0.00) p2 = TPad('p2'+skey,'p2'+skey,0.01,0.01,0.99,.35) if skey.count('Ekin'): p2.SetLogx(1) p2.Draw() p2.SetTopMargin(0.00) p2.SetBottomMargin(0.25) p1.cd() hnameNum = skey hnameDenom = hnameNum.replace(tagNum, tagDenom) print 'plotting ratio of ', hnameNum, 'and', hnameDenom xtitle, ytitle = sDict[skey][9], sDict[skey][10] histNum = rfNum.Get(hnameNum) histDenom = rfDenom.Get(hnameDenom) integralNum = histNum.Integral() integralDenom = histDenom.Integral() ratioInts = integralNum/integralDenom print "ratio int", ratioInts, ' ', hnameNum if hnameNum.count('Rad'): histNum.Rebin() histDenom.Rebin() # pass histNum.GetXaxis().SetTitle(xtitle) histNum.GetYaxis().SetTitle(ytitle) histDenom.GetXaxis().SetTitle(xtitle) histDenom.GetYaxis().SetTitle(ytitle) histNum.SetLineWidth(3) histNum.SetLineStyle(2) histDenom.SetLineColor(dColor) histNum.SetLineColor(nColor) histDenom.SetLineColor(dColor) histNum.SetMarkerColor(nColor) histDenom.SetMarkerColor(dColor) histNum.SetMarkerStyle(21) histDenom.SetMarkerStyle(20) histDenom.SetMarkerSize(msize) histNum.SetMarkerSize(msize) print normNum, normDenom histNum.Scale(1./normNum) histDenom.Scale(1./normDenom) histNum.GetXaxis().SetLabelSize(0.04) histDenom.GetXaxis().SetLabelSize(0.04) if XurMin != -1: histNum.GetXaxis().SetRangeUser(XurMin,XurMax) if YurMin != -1: histNum.GetXaxis().SetRangeUser(YurMin,YurMax) if dOptNum.count("same"): histDenom.Draw(dOptDenom) histNum.Draw(dOptNum) else: histNum.Draw(dOptNum) histDenom.Draw(dOptDenom) mlegend.AddEntry(histNum, lTextNum, "l") mlegend.AddEntry(histDenom, lTextDenom, "l") mlegend.Draw() lab = mylabel(42) lab.DrawLatex(0.56, 0.955, sDict[skey][6]) lab = mylabel(62) lab.SetTextSize(0.055) lab.DrawLatex(.8,y1-0.07,Beam) hnameRatio = 'ratio'+hnameNum hRatio = histNum.Clone(hnameRatio) hRatio.Divide(histNum, histDenom, 1, 1) hRatio.SetLineStyle(1) hRatio.SetLineWidth(2) hRatio.SetLineColor(rCol) hRatio.SetMarkerColor(rCol) hRatio.SetMarkerStyle(22) hRatio.SetMarkerSize(msize) l = TLine() l.SetLineWidth(1) l.SetLineColor(kGray) #kSpring if XurMin == -1: XurMin = hRatio.GetBinLowEdge(1) XurMax = hRatio.GetBinLowEdge( hRatio.GetNbinsX()+1 ) p2.cd() drawOpt = 'pe' if hnameNum.count('Rad') or hRatio.GetMaximum()>200: # hRatio.GetYaxis().SetRangeUser(0.1,2.6) pass hRatio.GetXaxis().SetLabelSize(0.1) hRatio.GetYaxis().SetLabelSize(0.08) hRatio.GetYaxis().SetTitleOffset(0.6) hRatio.GetYaxis().SetTitleSize(0.08) hRatio.GetXaxis().SetTitleSize(0.08) hRatio.Draw() hRatio.GetYaxis().SetTitle('ratio ' + lTextNum + '/' + lTextDenom + " ") l.DrawLine(XurMin,1,XurMax,1) pname = subfolder+hnameRatio.split('_')[0]+'.pdf' print pname cv.SaveAs(pname)