def cv07(): # used to be doNormR() from flukaText2root: # normlise by loss rate print sometext # lifetime tau_1 = 12*60 # loose beam in 12 minutes tau_2 = 100*60*60 # in 100 h Ntot_H = addCol(csfile_H, 4-1) R1det_H = Ntct_H/Ntot_H * NtotBeam/tau_1 R2det_H = Ntct_H/Ntot_H * NtotBeam/tau_2 print "total #p lost in 200 turns _H", Ntot_H Ntot_V = addCol(csfile_V, 4-1) R1det_V = Ntct_V/Ntot_V * NtotBeam/tau_1 R2det_V = Ntct_V/Ntot_V * NtotBeam/tau_2 print "total #p lost in 200 turns _V", Ntot_V print "fraction #p lost in 200 turns _V", Ntct_V/Ntot_V R1det = int(0.5*( R1det_H + R1det_V )) R2det = int(0.5*( R2det_H + R2det_V )) print "rate at det if beam is lost in 12 min'",R1det, 'Hz' print "rate at det if beam is lost in 100h",R2det, 'Hz'
def cv07(): # used to be doNormR() from flukaText2root: # normlise by loss rate print sometext # lifetime tau_1 = 12 * 60 # loose beam in 12 minutes tau_2 = 100 * 60 * 60 # in 100 h Ntot_H = addCol(csfile_H, 4 - 1) R1det_H = Ntct_H / Ntot_H * NtotBeam / tau_1 R2det_H = Ntct_H / Ntot_H * NtotBeam / tau_2 print "total #p lost in 200 turns _H", Ntot_H Ntot_V = addCol(csfile_V, 4 - 1) R1det_V = Ntct_V / Ntot_V * NtotBeam / tau_1 R2det_V = Ntct_V / Ntot_V * NtotBeam / tau_2 print "total #p lost in 200 turns _V", Ntot_V print "fraction #p lost in 200 turns _V", Ntct_V / Ntot_V R1det = int(0.5 * (R1det_H + R1det_V)) R2det = int(0.5 * (R2det_H + R2det_V)) print "rate at det if beam is lost in 12 min'", R1det, 'Hz' print "rate at det if beam is lost in 100h", R2det, 'Hz'
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 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 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 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 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)