def cv44a(): # twiss file #tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/runs/checkTrajectory6500GeV/twiss_b1_80cm_10cm.tfs') #tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/MED800/B1/1cm/MYM_10cm.tfs') #tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/MED800/B2/twiss_lhcb2_med_new_thin_800.tfs') #tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/MED800/B1/twiss_lhcb2_med_new_thin_800_1cm_b2.tfs') #tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/MED800/B1/1cm/twiss_lhcb2_med_new_thin_800_10cm.tfs') tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/background_2015_80cm/twiss_b2_80cm.tfs') #tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/runs/checkTrajectory6500GeV/4TeV/twiss_b2.data.thin') # tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/runs/checkTrajectory6500GeV/4TeV/twiss_b2.data') # -- just dump S and Y row = tf.GetRowDict colS = tf.GetColumn('S') colY = tf.GetColumn('Y') colX = tf.GetColumn('X') fileOutName = '/afs/cern.ch/project/lhc_mib/beamsize/6500GeV_beamsize/checkBeamSize/madx_SYX.dat' print 'writing..', fileOutName mf = open(fileOutName, 'w') for i in range(len(colS)): line = str(colS[i]*100.) + ' ' + str(colY[i]*100) + ' ' +str(colX[i]*100.) + '\n' mf.write(line) mf.close()
def cv47(): # twiss file # tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/runs/checkTrajectory6500GeV/4TeV/compTrajectories/twiss_b2.data') ## erased tf = pymadx.Tfs( "/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/4TeV/beamgas/twiss_4tev_b1.data" ) #tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/background_2015_80cm/twiss_b2_80cm.tfs') # number of randomly produced values per s location N = 1 emittance_norm = 3.5e-6 gamma_rel = 4e3 / 0.938 #gamma_rel = 6.5e3/0.938 emittance_geo = emittance_norm / gamma_rel pointsname = [ 'TCTH.4R1.B2', 'MQXA.1R1', 'MQXA.3R1', 'MCBXV.2R1', 'MQXB.B2R1', ] for name in pointsname: try: row = tf.GetRowDict(name) except KeyError: print "Couldnt find", name continue betx = row['BETX'] xp = row['PX'] bety = row['BETY'] yp = row['PY'] s = row['S'] sigx = math.sqrt(emittance_geo * betx) sigy = math.sqrt(emittance_geo * bety) sigmaxp = math.sqrt(emittance_geo / betx) sigmayp = math.sqrt(emittance_geo / bety) line = 'For ' + name + ' at s = ' +str(s)+ ' m: sigma_x =' + str(sigx*100) + ' cm, sigma_y =' + str(sigy*100) + \ ' cm, xp = '+ str(xp) + ' rad, yp = ' + str(yp) + ' rad' + \ ' sigma_xp = '+ str(sigmaxp) + ' rad, sigma_yp = ' + str(sigmayp) + ' rad' print line
def __init__(self, tfsFile="../madx/ff_twiss", surveyFile=""): self.tfsFile = tfsFile self.tfs = _pymadx.Tfs(tfsFile) self.s = _np.array(self.tfs.ColumnByIndex('S')) self.kw = _np.array(self.tfs.ColumnByIndex('KEYWORD')) self.l = _np.array(self.tfs.ColumnByIndex('L')) self.betx = _np.array(self.tfs.ColumnByIndex('BETX')) self.bety = _np.array(self.tfs.ColumnByIndex('BETY')) # self.alpx = _np.array(self.tfs.ColumnByIndex('ALPX')) # self.alpy = _np.array(self.tfs.ColumnByIndex('ALPX')) # mangets inc multipoles self.k0l = _np.array(self.tfs.ColumnByIndex('K0L')) self.k1l = _np.array(self.tfs.ColumnByIndex('K1L')) self.k2l = _np.array(self.tfs.ColumnByIndex('K2L')) self.k3l = _np.array(self.tfs.ColumnByIndex('K3L')) self.k4l = _np.array(self.tfs.ColumnByIndex('K4L')) self.k5l = _np.array(self.tfs.ColumnByIndex('K5L'))
def cv40(): # twiss file tf = pymadx.Tfs( '/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/MED800/B1/twiss_lhcb1_med_new_thin_800.tfs' ) BETX = tf.GetColumn('BETX') BETY = tf.GetColumn('BETY') ALFX = tf.GetColumn('ALFX') ALFY = tf.GetColumn('ALFY') X = tf.GetColumn('X') Y = tf.GetColumn('Y') PX = tf.GetColumn('PX') PY = tf.GetColumn('PY') S = tf.GetColumn('S') IP5 = tf.GetColumnDict('S')['IP5'] IP8 = tf.GetColumnDict('S')['IP8'] XurMin, XurMax = length_LHC - 300, length_LHC rel = '_IR1Left' XurMin, XurMax = 0, 300 rel = '_IR1Right' XurMin, XurMax = IP5 - 300, IP5 + 300 rel = '_IP5' XurMin, XurMax = IP8 - 300, IP8 + 300 rel = '_IP8' XurMin, XurMax = -1, -1 rel = '_phasespace' cv = TCanvas('cv', 'cv', 900, 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() # marker in legend lm = 'p' xList, yList, color, mStyle, lg = X, PX, kGreen + 1, 21, "x,x'" g1 = makeTGraph(xList, yList, color, mStyle) mlegend.AddEntry(g1, lg, lm) mg.Add(g1) xList, yList, color, mStyle, lg = Y, PY, kBlue + 1, 27, "y,y'" g3 = makeTGraph(xList, yList, color, mStyle) mlegend.AddEntry(g3, lg, lm) mg.Add(g3) mg.Draw("a" + lm) mg.GetXaxis().SetTitle('x,y') if XurMin != -1: mg.GetXaxis().SetRangeUser(XurMin, XurMax) mlegend.Draw() pname = wwwpath subfolder = 'TCT/6.5TeV/beamgas/' pname += subfolder + 'twiss_b1' + rel + '.png' print('Saving file as ' + pname) cv.Print(pname)
def cv41(): # twiss file #tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/MED800/B1/twiss_lhcb1_med_new_thin_800.tfs') #tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/runs/checkTrajectory6500GeV/4TeV/twiss_b2_mym.data') # erased # tf = pymadx.Tfs("/afs/cern.ch/user/r/rbruce/public/for_regina/MADX_4TeV/twiss_b1.data.thin") # alfa missing # tf = pymadx.Tfs("/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/4TeV/beamgas/twiss_b4.data.thin") tf = pymadx.Tfs("/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/4TeV/beamgas/twiss_4tev_b1.data") # locations of sampling the beam-size # - passen nicht mehr auf tfs #pointsName = ['TCTH.4L1.B1', 'TCTVA.4L1.B1', 'MBRC.4L1.B1','MQXA.1L1..2', 'MQXB.B2L1..16', 'BPTX.5L1.B1', "MB.A8L1.B1..2", "MCD.9L1.B1", "MCBCH.10L1.B1", "MB.C13L1.B1..2"] #pointsName = ["MYM.S"] #pointsName = ['TCTH.4L1.B1'] pointsName = ["IP1"] energy = "6.5TeV" gamma_rel = 6.5e3/0.938 betaStar = 0.8 energy = "4TeV" gamma_rel = 4e3/0.938 betaStar = 0.6 # number of randomly produced values per s location N = 1000 doWrite = 0 # canvas a,b = 2,len(pointsName) cv = TCanvas( 'cv', 'cv', a*600, b*600) cv.Divide(a,b) cv.SetRightMargin(0.3) cv.SetLeftMargin(0.2) cv.SetTopMargin(0.1) emittance_norm = 3.5e-6 emittance_geo = emittance_norm/gamma_rel gauss1 = TF1('gauss1', 'exp(-0.5*(x**2))', -5.,5.) gauss2 = TF1('gauss2', 'exp(-0.5*(x**2))', -5.,5.) gauss3 = TF1('gauss3', 'exp(-0.5*(x**2))', -5.,5.) gauss4 = TF1('gauss4', 'exp(-0.5*(x**2))', -5.,5.) gauss5 = TF1('gauss5', 'exp(-0.5*(x**2))', -5.,5.) gauss6 = TF1('gauss6', 'exp(-0.5*(x**2))', -5.,5.) j = 1 hx, c_x1, c_x2, c_x3, hy, c_y1, c_y2, c_y3 = [],[],[],[], [],[],[],[] for name in pointsName: print '-'*55, name hx += [ TH2F("f1" + name,"f1" + name,200,-0.004,0.004,200,-0.1e-4,0.1e-4) ] hy += [ TH2F("f2" + name,"f2" + name,200,-0.2e-2,0.2e-2,200,-3.e-5,3.e-5) ] c_x1 += [ TGraph() ] c_x1[-1].Set(N) c_x2 += [ TGraph() ] c_x2[-1].Set(N) c_x3 += [ TGraph() ] c_x3[-1].Set(N) c_y1 += [ TGraph() ] c_y1[-1].Set(N) c_y2 += [ TGraph() ] c_y2[-1].Set(N) c_y3 += [ TGraph() ] c_y3[-1].Set(N) row = tf.GetRowDict(name) betx = row['BETX'] alfx = row['ALFX'] bety = row['BETY'] alfy = row['ALFY'] s = str(row['S']) sigx = math.sqrt(emittance_geo * betx) sigy = math.sqrt(emittance_geo * bety) print sigy, sigx, "sigy, sigx" foutname = name + '_N' + str(N) + '.txt' if doWrite: fot = open(foutname, 'w') for i in range(N): # histogram big_x = gauss1.GetRandom() big_xp = gauss2.GetRandom() small_xp = math.sqrt(emittance_geo/betx) * big_xp - alfx*big_x/math.sqrt(betx * emittance_geo) small_x = big_x*sigx hx[-1].Fill(small_x,small_xp) line = str(i) + ' ' + str(small_x) + ' ' + str(small_xp) + ' ' # 3 contour lines phi = 2*random.random()*math.pi big_x = math.cos(phi) big_xp = math.sin(phi) small_xp = math.sqrt(emittance_geo/betx) * big_xp - alfx*big_x/math.sqrt(betx * emittance_geo) small_x = big_x*sigx c_x1[-1].SetPoint(i+1,small_x,small_xp) big_x = 2*math.cos(phi) big_xp = 2*math.sin(phi) small_xp = math.sqrt(emittance_geo/betx) * big_xp - alfx*big_x/math.sqrt(betx * emittance_geo) small_x = big_x*sigx c_x2[-1].SetPoint(i+1,small_x,small_xp) big_x = 3*math.cos(phi) big_xp = 3*math.sin(phi) small_xp = math.sqrt(emittance_geo/betx) * big_xp - alfx*big_x/math.sqrt(betx * emittance_geo) small_x = big_x*sigx c_x3[-1].SetPoint(i+1,small_x,small_xp) big_y = gauss3.GetRandom() big_yp = gauss4.GetRandom() small_yp = math.sqrt(emittance_geo/bety) * big_yp - alfy*big_y/math.sqrt(emittance_geo*bety) small_y = math.sqrt(bety*emittance_geo) * big_y hy[-1].Fill(small_y,small_yp) line += str(small_y) + ' ' + str(small_yp) + ' \n' if doWrite: fot.write(line) phi = 2*random.random()*math.pi big_y = math.cos(phi) big_yp = math.sin(phi) small_yp = math.sqrt(emittance_geo/bety) * big_yp - alfy*big_y/math.sqrt(emittance_geo*bety) small_y = big_y*sigy c_y1[-1].SetPoint(i+1,small_y,small_yp) big_y = 2*math.cos(phi) big_yp = 2*math.sin(phi) small_yp = math.sqrt(emittance_geo/bety) * big_yp - alfy*big_y/math.sqrt(emittance_geo*bety) small_y = big_y*sigy c_y2[-1].SetPoint(i+1,small_y,small_yp) big_y = 3*math.cos(phi) big_yp = 3*math.sin(phi) small_yp = math.sqrt(emittance_geo/bety) * big_yp - alfy*big_y/math.sqrt(emittance_geo*bety) small_y = big_y*sigy c_y3[-1].SetPoint(i+1,small_y,small_yp) if doWrite:print 'wrote', foutname cStyle = 6 ms = 0.01 xtitle, ytitle = 'x [m]', "x' [rad]" hx[-1].GetXaxis().SetLabelSize(0.03) hx[-1].GetYaxis().SetLabelSize(0.03) hx[-1].GetZaxis().SetLabelSize(0.03) hx[-1].GetXaxis().SetTitle(xtitle) hx[-1].GetYaxis().SetTitle(ytitle) c_x1[-1].SetMarkerSize(ms) c_x1[-1].SetMarkerColor(kRed+2) c_x2[-1].SetMarkerSize(ms) c_x2[-1].SetMarkerColor(kRed) c_x3[-1].SetMarkerSize(ms) c_x3[-1].SetMarkerColor(kRed-7) c_x1[-1].SetMarkerStyle(cStyle) c_x2[-1].SetMarkerStyle(cStyle) c_x3[-1].SetMarkerStyle(cStyle) xtitle, ytitle = 'y [m]', "y' [rad]" hy[-1].GetXaxis().SetLabelSize(0.03) hy[-1].GetYaxis().SetLabelSize(0.03) hy[-1].GetZaxis().SetLabelSize(0.03) hy[-1].GetXaxis().SetTitle(xtitle) hy[-1].GetYaxis().SetTitle(ytitle) c_y1[-1].SetMarkerSize(ms) c_y1[-1].SetMarkerColor(kGreen+2) c_y1[-1].SetMarkerStyle(cStyle) c_y2[-1].SetMarkerSize(ms) c_y2[-1].SetMarkerStyle(cStyle) c_y2[-1].SetMarkerColor(kGreen+1) c_y3[-1].SetMarkerSize(ms) c_y3[-1].SetMarkerStyle(cStyle) c_y3[-1].SetMarkerColor(kGreen-10) xtitle, ytitle = '#sigma_{x}', "#sigma_{y}" m,n = j*2-1,j*2 print m,n lab = mylabel(42) cv.cd(m) hx[-1].Draw('colz') c_x1[-1].Draw("SAMEP") c_x2[-1].Draw("SAMEP") c_x3[-1].Draw("SAMEP") lab.DrawLatex(0.3, 0.85, name + ' ('+s+')') cv.cd(n) hy[-1].Draw('colz') c_y1[-1].Draw("SAMEP") c_y2[-1].Draw("SAMEP") c_y3[-1].Draw("SAMEP") #lab.DrawLatex(0.26, 0.87, name + ' (' + row["KEYWORD"] + ')') j+=1 rel = '_gauss' pname = wwwpath subfolder = "TCT/"+energy+"/beamgas/" pname += subfolder + 'twiss'+rel+'_'+energy+'.png' print('Saving file as ' + pname ) cv.SaveAs(pname)
def cv61(): showInfo = 1 # for each set serveral plots sets = [ # # 4 TeV # [ workpath + 'runs/4TeV_Halo/coll_summary_TCT_4TeV_B2hHalo.dat',\ # workpath + 'runs/4TeV_Halo/HALO4TeVB2.dat.root',\ # gitpath + 'SixTrackConfig/4TeV/TCThaloStudies/b2/collgaps.dat',\ # 'TCT/4TeV/B2/', '4 TeV B2', 1., \ # 100,0., 10., # ], # [ workpath + 'runs/4TeV_Halo/coll_summary_TCT_4TeV_B1hHalo.dat',\ # workpath + 'runs/sourcedirs/TCT_4TeV_60cm/fluka/impacts_real_HALO.dat.root',\ # gitpath + 'SixTrackConfig/4TeV/TCThaloStudies/b1/collgaps.dat',\ # 'TCT/4TeV/B1/', '4 TeV B1', 1., \ # 100,0., 10., # ], # [ workpath + 'runs/4TeV_Halo/coll_summary_NewScatt_TCT_4TeV_B2hHalo.dat',\ # workpath + 'runs/4TeV_Halo/impacts_real_NewScatt_TCT_4TeV_B2.txt.root',\ # gitpath + 'SixTrackConfig/4TeV/TCThaloStudies/b2/collgaps.dat',\ # 'TCT/4TeV/', '4 TeV B2', 1., \ # 100,0., 10., # ], # [ projectpath + 'bgChecks2/NewScatt_4TeV_hHaloB1/coll_summary_NewScatt_4TeV_hHaloB1.dat',\ # projectpath + 'bgChecks2/impacts_real_NewScatt_4TeV_haloB1.txt.root',\ # projectpath + 'bgChecks2/NewScatt_4TeV_hHaloB1/run_test/collgaps.dat',\ # 'TCT/4TeV/', '4 TeV B1', 1., \ # 100,0., 10., # ], [ projectpath + 'bgChecks2/NewScatt_4TeV_hHaloB2/coll_summary_NewScatt_4TeV_hHaloB2.dat',\ projectpath + 'bgChecks2/impacts_real_NewScatt_4TeV_haloB2.txt.root',\ projectpath + 'bgChecks2/NewScatt_4TeV_hHaloB2/run_test/collgaps.dat',\ 'TCT/4TeV/', '4 TeV B2', 1., \ '/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/4TeV/TCThaloStudies/b2/twiss_b4.data.thin' ], ] # activate only last entry # sets = [sets[-1]] # collimators colls = [ # 'TCTH.5L1.B1', # 'TCTVA.5L1.B1', # 'TCTH.4L1.B1', # 'TCTVA.4L1.B1', # 'TCTH.4L5.B1', # 'TCTVA.4L5.B1', # 'TCTH.5R1.B2', # 'TCTVA.5R1.B2', # 'TCTH.4R1.B2', 'TCTVA.4R1.B2', # 'TCTH.4R5.B2', # 'TCTVA.4R5.B2', ] # for each collimator fix a color bCol = [ kBlue, kCyan, kCyan-2, kOrange-6, kRed-5, kMagenta+1, kMagenta+2, kViolet, kGreen+2, kOrange-2, kRed+2, kGreen-2, kMagenta-2, ] hDict = { ## x,y in [m] #0 var #1 xnbins, xmin, xmax, ynbins, ymin, ymax, #2 xtitle, #3 ytitle , #4 doNormalise # 'xxpHist':['xp:x', [300,-20.,20., 300,-0.3,0.3],'x', 'x\'[mrad]',0,], #'yypHist':['yp:y', [300,-20.,20., 300,-0.3,0.3],'y', 'y\'[mrad]', 1,], # 'xsHist' :['x:s', [300,0,1, 300,-15.,15.],'s[m]', 'x[m]',0,], # 'ysHist' :['y:s', [300,0,1,300,-15.,15.],'s[m]', 'y[m]',0,], # 'xyHist':['y:x', [300,-15.,15., 300,-15.,15.],'x [mm]', 'y [mm]',0,], #'ypHist':['yp', [300,-0.3,0.3], 'y\'[mrad]', 'entries',0,], 'yHist':['y', [3000,-15.,15], 'y [mrad]', 'entries',0,], } # ----------------------------------------------------------------------------------- emittance_norm = 3.5e-6 gamma_rel = 4e3/0.938 emittance_geo = emittance_norm/gamma_rel # ----------------------------------------------------------------------------------- def doDraw(hist,rel): # canvas a,b = 1,1 cv = TCanvas( 'cv', 'cv', a*900, b*700) cv.Divide(a,b) cv.SetTopMargin(0.18) cv.SetRightMargin(0.18) cv.SetGridx(1) cv.SetGridy(1) # name+mean #gStyle.SetOptStat(101) gStyle.SetOptStat(111) gStyle.SetPalette(1) x1, y1, x2, y2 = 0.2, 0.98, 0.84, 0.9 lab = mylabel(42) lText = '' if type(hist) == TH1F: maxbin = hist.GetMaximumBin() maxval = hist.GetXaxis().GetBinLowEdge(maxbin) binwid = hist.GetXaxis().GetBinLowEdge(maxbin+1) delta = binwid - maxval lText = 'maximum at ' + str(maxval) + ' + ' + str(delta) hist.Draw("HIST") elif type(hist) == TH2F: hist.Draw("COLZ") entries = hist.GetEntries() meanval = hist.GetMean() collName = hist.GetName().split(filename + '_')[-1].replace('_', '.') hname = hist.GetName() if showInfo: print 'INFO: Plotting', hname #lab.DrawLatex(x1+0.45, y1-0.1, "entries " + str(int(entries))) lab.DrawLatex(0.2, 0.85, lText) lab.DrawLatex(0.2, 0.9, energy) lab.DrawLatex(0.4, 0.9, collName) pname = wwwpath subfolder = 'TCT/4TeV/haloShower/cv61/' pname += subfolder + hname + rel + '.png' print('Saving file as ' + pname) cv.SaveAs(pname) # ----------------------------------------------------------------------------------- # get the histograms for myset in sets: cfile = myset[0] if cfile.count("collgap"): cDict = collDict(cfile) elif cfile.count("summary"): cDict = collgapsDict(cfile) else: print "Cannot get the name identifier from", cfile sys.exit() rfname = myset[1] print "Opening","."*33, rfname rf = TFile.Open(rfname) mt = rf.Get('particle') filename = rfname.split('/')[-1].split('.')[0] collgaps = myset[2] cgDict = collgapsDict(collgaps) print "and using","."*33, collgaps subfolder, energy, ymax = myset[3], myset[4], myset[5] TwissFile = pymadx.Tfs(myset[6]) betaXDict = TwissFile.GetColumnDict('BETX') betaYDict = TwissFile.GetColumnDict('BETY') for collName in colls: betx = betaXDict[collName] bety = betaYDict[collName] sigmax = math.sqrt(emittance_geo * betx) sigmay = math.sqrt(emittance_geo * bety) sigmaxp = math.sqrt(emittance_geo/betx) sigmayp = math.sqrt(emittance_geo/bety) print "sigmax ", sigmax, "m" print "sigmay ", sigmay, "m" try: collid = cDict[collName][0] except KeyError: print(collName, 'key not found') continue for hkey in hDict.keys(): # define histograms hname = hkey + '_' + filename + '_' + collName.replace('.', '_') var = hDict[hkey][0] if var.count(":"): xnbins, xmin, xmax = hDict[hkey][1][0],hDict[hkey][1][1],hDict[hkey][1][2] ynbins, ymin, ymax = hDict[hkey][1][3],hDict[hkey][1][4],hDict[hkey][1][5] hist = TH2F(hname, hname, xnbins, xmin, xmax, ynbins, ymin, ymax) else: xnbins, xmin, xmax = hDict[hkey][1][0],hDict[hkey][1][1],hDict[hkey][1][2] hist = TH1F(hname, hname, xnbins, xmin, xmax) maxval = hist.GetMaximum() xtitle, ytitle = hDict[hkey][2],hDict[hkey][3] hist.GetXaxis().SetTitle(xtitle) hist.GetYaxis().SetTitle(ytitle) cut = 'icoll == ' + collid cut += ' && y < 0.' rel = '_negY' # store sum of squares of weights hist.Sumw2() if showInfo: print 'INFO: will fill these variables ', var, 'into', hname if showInfo: print 'INFO: will apply a cut of ', cut, 'to', hname mt.Project(hname, var, cut) entries = hist.GetEntries() if showInfo: print 'INFO: Have ',entries, ' entries in', hname, ' for ', collName if entries: doDraw(hist, rel)
def cv42(): # twiss file tf = pymadx.Tfs( '/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/MED800/B1/1cm/MYM.tfs' ) # use all locations for sampling the beam-size # number of randomly produced values per s location N = 1 # out file name as input for fluka foutname = 'bgpos.dat' fout = open(foutname, 'w') emittance_norm = 3.5e-6 gamma_rel = 6.5e3 / 0.938 emittance_geo = emittance_norm / gamma_rel gauss1 = TF1('gauss1', 'exp(-0.5*(x**2))', -5., 5.) gauss2 = TF1('gauss2', 'exp(-0.5*(x**2))', -5., 5.) gauss3 = TF1('gauss3', 'exp(-0.5*(x**2))', -5., 5.) gauss4 = TF1('gauss4', 'exp(-0.5*(x**2))', -5., 5.) gauss5 = TF1('gauss5', 'exp(-0.5*(x**2))', -5., 5.) gauss6 = TF1('gauss6', 'exp(-0.5*(x**2))', -5., 5.) nsteps = 545850 for i in range(nsteps): name = 'MYM.' + str(i + 1) row = tf.GetRowDict(name) betx = row['BETX'] alfx = row['ALFX'] bety = row['BETY'] alfy = row['ALFY'] s = row['S'] * 100 sigx = math.sqrt(emittance_geo * betx) sigy = math.sqrt(emittance_geo * bety) ts = str(0.0) for i in range(N): # convert x and y from m to cm big_x = gauss1.GetRandom() big_xp = gauss2.GetRandom() small_xp = math.sqrt( emittance_geo / betx) * big_xp - alfx * big_x / math.sqrt( betx * emittance_geo) small_x = big_x * sigx * 100 big_y = gauss3.GetRandom() big_yp = gauss4.GetRandom() small_yp = math.sqrt( emittance_geo / bety) * big_yp - alfy * big_y / math.sqrt( emittance_geo * bety) small_y = math.sqrt(bety * emittance_geo) * big_y * 100 line = '{0:15} {1:15} {2:10} {3:15} {4:15} {5:5}'.format( small_x, small_y, s, small_xp, small_yp, ts) fout.write(line + '\n') fout.close()
def cv75(): # twiss file do4TeV = 0 if do4TeV: tf = pymadx.Tfs( "/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/4TeV/beamgas/twiss_b4.data.thin" ) energy = "4TeV" gamma_rel = 4e3 / 0.938 betaStar = 0.6 else: tf = pymadx.Tfs( '/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/MED800/B1/twiss_lhcb1_med_new_thin_800.tfs' ) gamma_rel = 6.5e3 / 0.938 energy = '6.5TeV' betaStar = 0.8 print energy, "." * 45 BETX = tf.GetColumn('BETX') BETY = tf.GetColumn('BETY') S = tf.GetColumn('S') # print "first elements of twiss betax", BETX[100:200] # print "first elements of twiss betay", BETY[100:200] # no shift if val is length shiftVal = length_LHC #-500 cnt = 0 S_shifted, X_shifted = [], [] for s in S: s_shifted = s + shiftVal #print "s_shifted", s_shifted if s_shifted >= length_LHC: cnt += 1 s_shifted -= length_LHC #print "s_shifted after subtraction", s_shifted S_shifted += [s_shifted] #print "using", s_shifted S_shifted.sort() XurMin, XurMax = 0, 548. #XurMin, XurMax = 0,5. rel = '_compsigma_IR1Right_' + energy lShift = 0.0 # ----------------------------------------------- # fluka part from cv74 # full sample at 4 TeV #filename = projectpath + 'HaloRun2/valBG4TeV2/oneFileAllTraj.dat.89.root' filename = projectpath + 'HaloRun2/valBG4TeV2/traj_fort.89.10.root' # as used in fluka simulations filename = projectpath + '4TeVBGnoBS/createTrajectories6p5_checkfix/runs_fix/ir1_6500GeV_b1_20MeV_orbitDumpINICON_89.root' # fixed version of inicons filename = projectpath + '4TeVBGnoBS/createTrajectories6p5_checkrepfix/run_repfix/ir1_6500GeV_b1_20MeV_orbitDumpINICON_89.root' # fixed version of inicons # sufficient trajectories at 6.5 TeV #if not do4TeV: filename = '/afs/cern.ch/project/lhc_mib/HaloRun2/valBG4TeV2/400Traj.fort.89.root' print "Opening", filename rf = TFile.Open(filename) mt = rf.Get("particle") SIGXflu = [] # getStatErrFromTProf(mt, "XTRACK",-1000.,1) # SIGYflu1 = getStatErrFromTProf(mt, "YTRACK",0.,2) # to cut off outlier use only up to s=1000cm # SIGYflu2 = getStatErrFromTProf(mt, "YTRACK",-1.,2)# then use this when outlier is gone # SIGYflu = [ SIGYflu1[i] for i in range(1001)] # SIGYflu += [ SIGYflu2[i] for i in range(1001,54694)] SIGYflu = [] # getStatErrFromTProf(mt, "YTRACK",-1.,2) srange_meter = [0.01 * s for s in range(54694)] a, b = 1, 1 cv = TCanvas('cv', 'cv', a * 2100, b * 900) cv.Divide(a, b) cv.cd(1) x1, y1, x2, y2 = 0.5 - lShift, 0.65, 0.9 - lShift, 0.9 mlegend = TLegend(x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.05) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mg = TMultiGraph() # marker in legend lm = 'lp' emittance_norm = 3.5e-6 emittance_geo = emittance_norm / gamma_rel SIGX = [math.sqrt(betax * emittance_geo) for betax in BETX] SIGY = [math.sqrt(betay * emittance_geo) for betay in BETY] for S in SIGY: if S in SIGX: print "?>>> S in both??", S SIGMAX = [s * 1000. for s in SIGX] xList, yList, color, mStyle, lg = S_shifted, SIGMAX, kGreen - 1, 22, '#sigma_{x} from Twiss' g0 = makeTGraph(xList, yList, color, mStyle) mlegend.AddEntry(g0, lg, lm) mg.Add(g0) print '-' * 11, lg SIGMAY = [s * 1000 for s in SIGY] xList, yList, color, mStyle, lg = S_shifted, SIGMAY, kGreen - 2, 20, '#sigma_{y} from Twiss' g1 = makeTGraph(xList, yList, color, mStyle) # mlegend.AddEntry(g1, lg, lm) # mg.Add(g1) ytitle = 'beam size [mm]' print '-' * 11, lg print S_shifted[:10], srange_meter[:10] SIGYfluka = [s * 10 for s in SIGYflu] xList, yList, color, mStyle, lg = srange_meter, SIGYfluka, kGreen + 1, 21, '#sigma_{y} from fluka' g2 = makeTGraph(xList, yList, color, mStyle) # mlegend.AddEntry(g2, lg, lm) #mg.Add(g2) print '-' * 11, lg SIGXfluka = [s * 10. for s in SIGXflu] xList, yList, color, mStyle, lg = srange_meter, SIGXfluka, kBlue + 1, 27, "#sigma_{x} from fluka" g3 = makeTGraph(xList, yList, color, mStyle) mlegend.AddEntry(g3, lg, lm) mg.Add(g3) print '-' * 11, lg sigxflu_x, sigxtwi_x, sigxflu_y, sigxtwi_y = ROOT.Double(), ROOT.Double( ), ROOT.Double(), ROOT.Double() collectNp = [] for i in range(20, len(SIGYflu)): g3.GetPoint(i, sigxflu_x, sigxflu_y) g1.GetPoint(i, sigxtwi_x, sigxtwi_y) ratiosigx = 0. if sigxtwi_y: ratiosigx = sigxflu_y**2 / sigxtwi_y**2 newEmittance = emittance_norm * ratiosigx collectNp += [ratiosigx] print "New emittance", newEmittance, " dev:", collectNp[ -1], "at ", srange_meter[ i], "sigxflu", sigxflu_y, "sigxtwi", sigxtwi_y print "max deviation", max(collectNp), "at ", collectNp.index( max(collectNp)), mg.Draw("a" + lm) l = TLine() l.SetLineStyle(1) YurMin, YurMax = 0, 0.0019 l.SetLineColor(kRed) s = 22.6 l.DrawLine(s, YurMin, s, YurMax) s = 59. l.DrawLine(s, YurMin, s, YurMax) s = 153. l.DrawLine(s, YurMin, s, YurMax) s = 269. l.DrawLine(s, YurMin, s, YurMax) mg.GetYaxis().SetTitle(ytitle) mg.GetXaxis().SetTitle('s [m]') if XurMin != -1: mg.GetXaxis().SetRangeUser(XurMin, XurMax) mlegend.Draw() pname = wwwpath subfolder = 'TCT/' + energy + '/beamgas/' pname += subfolder + 'from_twiss_b1' + rel + '.png' print('Saving file as ' + pname) cv.Print(pname)
def compare(): # twiss file v10tf = pymadx.Tfs( '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/sourcedirs/HL_TCT_7TeV/twiss.hllhcv1.b1.tfs' ) v11tf = pymadx.Tfs( '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/sourcedirs/HL_TCT_7TeV/twiss.hllhcv1.1-b1.tfs' ) v10BetX = v10tf.GetColumnDict('BETX') v10BetY = v10tf.GetColumnDict('BETY') v10AlfX = v10tf.GetColumnDict('ALFX') v10AlfY = v10tf.GetColumnDict('ALFY') v10X = v10tf.GetColumnDict('X') v10Y = v10tf.GetColumnDict('Y') v10S = v10tf.GetColumnDict('S') v10PX = v10tf.GetColumnDict('PX') v10PY = v10tf.GetColumnDict('PY') v10colls = [ 'TCTH.4L1.B1', 'TCTVA.4L1.B1', 'TCTH.5L1.B1', 'TCTVA.5L1.B1', 'TCTH.4L5.B1', 'TCTVA.4L5.B1', 'TCTH.5L5.B1', 'TCTVA.5L5.B1', ] print "NAME S BETX BETY SIGX SIGY in v1.0" for coll in v10colls: betX = v10BetX[coll] betY = v10BetY[coll] alfX = v10AlfX[coll] alfY = v10AlfY[coll] x, y, s = v10X[coll], v10Y[coll], v10S[coll] pX, pY = v10PX[coll], v10PY[coll] #print "alfX, x, pX, y, pY", alfX, x, pX, y, pY # values gamX = 1. / betX * (1. + alfX**2) gamY = 1. / betY * (1. + alfY**2) emiX = gamX * x**2 + 2. * alfX * x * pX + betX * pX**2 emiY = gamY * y**2 + 2. * alfY * y * pY + betY * pY**2 sigX = betX * emiX sigY = betY * emiY print coll, ' ', s, betX, betY, sigX, sigY print '-' * 30 v11BetX = v11tf.GetColumnDict('BETX') v11BetY = v11tf.GetColumnDict('BETY') v11AlfX = v11tf.GetColumnDict('ALFX') v11AlfY = v11tf.GetColumnDict('ALFY') v11X = v11tf.GetColumnDict('X') v11Y = v11tf.GetColumnDict('Y') v11PX = v11tf.GetColumnDict('PX') v11PY = v11tf.GetColumnDict('PY') v11S = v11tf.GetColumnDict('S') v11colls = [ 'TCTH.4L1.B1', 'TCTV.4L1.B1', 'TCTH.5L1.B1', 'TCTV.5L1.B1', 'TCTH.4L5.B1', 'TCTV.4L5.B1', 'TCTH.5L5.B1', 'TCTV.5L5.B1', ] print "NAME S BETX BETY SIGX SIGY in v1.1" for coll in v11colls: betX = v11BetX[coll] betY = v11BetY[coll] alfX = v11AlfX[coll] alfY = v11AlfY[coll] x, y, s = v11X[coll], v11Y[coll], v11S[coll] pX, pY = v11PX[coll], v11PY[coll] # values gamX = 1. / betX * (1. + alfX**2) gamY = 1. / betY * (1. + alfY**2) emiX = gamX * x**2 + 2. * alfX * x * pX + betX * pX**2 emiY = gamY * y**2 + 2. * alfY * y * pY + betY * pY**2 sigX = betX * emiX sigY = betY * emiY print coll, ' ', s, betX, betY, sigX, sigY
def cv39(): gamma_rel = 4.e3 / 0.938 energy = '4TeV' # twiss file # tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/MED800/B1/twiss_lhcb1_med_new_thin_800.tfs') # tf = pymadx.Tfs('/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/MED800/B1/1cm/twiss_lhcb1_med_new_thin_800_1cm.tfs') # tf = pymadx.Tfs("/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/4TeV/beamgas/twiss_4tev_b1.data") tf = pymadx.Tfs( "/afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/SixTrackConfig/6.5TeV/background_2015_80cm/MADX_2015/twiss_b2.tfs" ) gamma_rel = 6.5e3 / 0.938 energy = "6.5TeV" BETX = tf.GetColumn('BETX') BETY = tf.GetColumn('BETY') ALFX = tf.GetColumn('ALFX') ALFY = tf.GetColumn('ALFY') X = tf.GetColumn('X') Y = tf.GetColumn('Y') PX = tf.GetColumn('PX') PY = tf.GetColumn('PY') S = tf.GetColumn('S') IP5 = tf.GetColumnDict('S')['IP5'] IP8 = tf.GetColumnDict('S')['IP8'] # no shift if val is length shiftVal = length_LHC #-500 cnt = 0 S_shifted, X_shifted = [], [] for s in S: s_shifted = s + shiftVal #print "s_shifted", s_shifted if s_shifted >= length_LHC: cnt += 1 s_shifted -= length_LHC #print "s_shifted after subtraction", s_shifted S_shifted += [s_shifted] #print "using", s_shifted S_shifted.sort() lShift = 0.5 XurMin, XurMax = 0, 548. XurMin, XurMax = -1, -1 XurMin, XurMax = length_LHC - 500, length_LHC # rel = '_sigma_IR1Right_1cm' # rel = '_sigma_IR1Left_'+energy rel = 'from_twiss_orbit_IR1' # lShift = 0.0 # XurMin, XurMax = IP5-300, IP5+300 # rel = '_IP5' # XurMin, XurMax = IP8-300, IP8+300 # rel = '_IP8' cv = TCanvas('cv', 'cv', 2100, 900) x1, y1, x2, y2 = 0.8 - lShift, 0.65, 0.9 - lShift, 0.9 mlegend = TLegend(x1, y1, x2, y2) mlegend.SetFillColor(0) mlegend.SetFillStyle(0) mlegend.SetLineColor(0) mlegend.SetTextSize(0.05) mlegend.SetShadowColor(0) mlegend.SetBorderSize(0) mg = TMultiGraph() # marker in legend lm = 'l' emittance_norm = 3.5e-6 emittance_geo = emittance_norm / gamma_rel SIGX = [math.sqrt(betax * emittance_geo) for betax in BETX] SIGY = [math.sqrt(betay * emittance_geo) for betay in BETY] # xList, yList, color, mStyle, lg = S_shifted, SIGX, kGreen-1, 22, '#sigma_{x}' # g0 = makeTGraph(xList, yList, color, mStyle) # mlegend.AddEntry(g0, lg, lm) # mg.Add(g0) # xList, yList, color, mStyle, lg = S_shifted, SIGY, kGreen-2, 20, '#sigma_{y}' # g1 = makeTGraph(xList, yList, color, mStyle) # mlegend.AddEntry(g1, lg, lm) # mg.Add(g1) ytitle = 'beam size [m]' xList, yList, color, mStyle, lg = S_shifted, X, kGreen + 1, 21, "x [m]" g1 = makeTGraph(xList, yList, color, mStyle) mlegend.AddEntry(g1, lg, lm) mg.Add(g1) xList, yList, color, mStyle, lg = S_shifted, Y, kBlue - 1, 20, "y [m]" g2 = makeTGraph(xList, yList, color, mStyle) mlegend.AddEntry(g2, lg, lm) mg.Add(g2) ytitle = 'orbit' # xList, yList, color, mStyle, lg = S_shifted, PY, kBlue+1, 27, "y'" # g3 = makeTGraph(xList, yList, color, mStyle) # mlegend.AddEntry(g3, lg, lm) # mg.Add(g3) mg.Draw("a" + lm) l = TLine() l.SetLineStyle(1) YurMin, YurMax = 0, 0.0019 l.SetLineColor(kRed) # s = 22.6 # l.DrawLine(s,YurMin,s,YurMax) # s = 59. # l.DrawLine(s,YurMin,s,YurMax) # s = 153. # l.DrawLine(s,YurMin,s,YurMax) # s = 269. # l.DrawLine(s,YurMin,s,YurMax) mg.GetYaxis().SetTitle(ytitle) mg.GetXaxis().SetTitle('s [m]') if XurMin != -1: mg.GetXaxis().SetRangeUser(XurMin, XurMax) mlegend.Draw() pname = wwwpath subfolder = 'TCT/' + energy + '/beamgas/' pname += subfolder + ytitle + '_' + rel.replace(".", "p") + '.pdf' print('Saving file as ' + pname) cv.Print(pname) pname = wwwpath subfolder = 'TCT/' + energy + '/beamgas/' pname += subfolder + 'from_twiss_' + rel.replace(".", "p") + '.png' print('Saving file as ' + pname) cv.Print(pname)