def cv66(): # -------------------------------------------------------------------------------- # density profile is given in the following format: # densities per molecule as function of s-coordinate # x,y,z, cx, cy, cz as function of (different s-coordinate) # merge densities with coordinates # note, that the source routine needs fluka units, ie *cm*! # -------------------------------------------------------------------------------- do4TeV = 0 # 1 means 3.5 is off if do4TeV: energy = '4 TeV' bgfile = '/afs/cern.ch/work/r/rkwee/HL-LHC/beam-gas-sixtrack/pressure_profiles_2012/LSS1_B1_Fill2736_Final.csv' bgfile = '/Users/rkwee/Documents/RHUL/work/data/4TeV/LSS1_B1_Fill2736_Final.csv' beamintensity = 2e14 rfoutname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/pressure2012.root" else: energy = " 3.5 TeV " bgfile = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/LSS1_B1_fill_2028-sync_rad_and_ecloud.csv" beamintensity = 1.66e14 rfoutname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/pressure2011.root" print "Using", bgfile debug = 0 data = getdata14c(bgfile) print 'data keys are', data.keys() nb_s = len(data['s']) print 'number of s values', nb_s s, rho_C, rho_H, rho_O = cv65.getAtomicRho(data) # -- # calculate the scaled number # unscaled inf hname, nbins, xmin, xmax = 'muons', 2 * 262, 22.6, 546.6 binw = (xmax - xmin) / nbins hist = TH1F(hname, hname, nbins, xmin, xmax) hist.Sumw2() hist.GetXaxis().SetTitle('s [m]') datafile = '/afs/cern.ch/project/lhc_mib/valBG4TeV/ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67' datafile = '/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67' if not do4TeV: datafile = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/beam_gas_3.5TeV_IR1_to_arc_20MeV_100M_nprim7660649_66" bbgFile = datafile + ".root" print "Using", bbgFile rfile = TFile.Open(bbgFile, "READ") hists = [] cnt = 0 mt = rfile.Get('particle') particleTypes = [10, 11] hname = 'muons_flatpressure' hist_flat = hist.Clone(hname) hist_pint = hist.Clone("pint") hist_pint_re = hist.Clone("pint_re") var = "z_interact*0.01" cuts = "(particle == 10 || particle == 11) && energy_ke > 0.02" print "INFO: applying", cuts, "to", var, "in", hname mt.Project(hname, var, cuts) # divide by binwith for i in range(nbins + 1): cont = hist_flat.GetBinContent(i) hist_flat.SetBinContent(i, cont / binw) err = hist_flat.GetBinError(i) hist_flat.SetBinError(i, err / binw) Trev = 1. / 11245.0 pint_tot = calc_pint_tot(energy, rho_C, rho_H, rho_O) pint_incomingbeam = {} for i, spoS in enumerate(s): spos = float(spoS) if spos < 0.: z = -spos pint_incomingbeam[z] = pint_tot[i] zbin = hist_pint.FindBin(z) hist_pint.SetBinContent(zbin, pint_incomingbeam[z]) # first value is for arc arcvalue = pint_tot[1] startarc = 260. startarcBin = hist_pint.FindBin(startarc) for i in range(startarcBin, nbins - 1): hist_pint.SetBinContent(i, arcvalue) nprim = float(bbgFile.split('nprim')[-1].split('_')[0]) Mk = nprim / nbins # compute normalisation fct for each bin for i in range(1, nbins + 1): m = hist_flat.GetBinContent(i) scale = 1e2 * beamintensity * hist_pint.GetBinContent(i) * binw / Mk hist.SetBinContent(i, scale * m) if i < 10: print "s, m, scale, binw,beamintensity, hist_pint.GetBinContent(i), Mk", hist_pint.GetBinLowEdge( i), m, scale, binw, beamintensity, hist_pint.GetBinContent( i), Mk print "scale * m", hist.GetBinContent(i) cv = TCanvas('cv', 'cv', 1600, 900) cv.SetGridy(0) x1, y1, x2, y2 = 0.5, 0.7, 0.9, 0.88 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) ytitle = "arbitrary units" YurMin, YurMax = 9, 9e6 #hist.GetYaxis().SetRangeUser(YurMin,YurMax) hist.SetMarkerColor(kRed) hist.SetLineColor(kRed) #hist.GetYaxis().SetTitle(ytitle) XurMin, XurMax = 22.6, 540. hist.GetXaxis().SetRangeUser(XurMin, XurMax) hist.GetYaxis().SetRangeUser(YurMin, YurMax) hist.Draw("hist") hist_flat.Scale(1 / nprim) print 'writing ', '.' * 33, rfoutname rfOUTile = TFile.Open(rfoutname, "RECREATE") hist.Write() hist_flat.Write() hist_pint.Write() rfOUTile.Close() hist_flat.Scale(1e7) hist_flat.Draw("histsame") hist_pint.SetLineColor(kGreen - 3) if debug: ztest = 28. print "at ", ztest, ": have pint = ", hist_pint.GetBinContent( hist_pint.FindBin(ztest)), print "at ", ztest, ": have flat = ", hist_flat.GetBinContent( hist_flat.FindBin(ztest)), print "at ", ztest, ": have norm = ", hist.GetBinContent( hist.FindBin(ztest)), hist_pint.Scale(1e16) hist_pint.Draw("histsame") lg, lm = "interaction probability x10^{16} [1/s/m]", 'l' # lg, lm = "interaction probability [1/s/m]", 'l' mlegend.AddEntry(hist_pint, lg, lm) lg, lm = "#mu^{#pm} [1/s/m] ", 'l' mlegend.AddEntry(hist, lg, lm) lg, lm = "#mu^{#pm} 10^{7}/m/BG int. flat pressure", 'l' mlegend.AddEntry(hist_flat, lg, lm) gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.45, 0.9, energy) mlegend.Draw() pname = wwwpath + 'TCT/beamgas/pressure_profiles_2012/flatvsprofile.pdf' pname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/muons2012.pdf" if not do4TeV: pname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/xcheck2011/pint2011.pdf" print('Saving file as ' + pname) cv.Print(pname)
def cv70(): # -------------------------------------------------------------------------------- # density profile is given in the following format: # densities per molecule as function of s-coordinate # x,y,z, cx, cy, cz as function of (different s-coordinate) # merge densities with coordinates # note, that the source routine needs fluka units, ie *cm*! # -------------------------------------------------------------------------------- debug = 0 do4TeV = 1 # do6p5 = 0 # 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' data = getdata14c(pressFile) startarc = 260. 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 data = cv79.getdata5c(pressFile) startarc = 493.6 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" data = getdata14c(pressFile) startarc = 260. print 'data keys are', data.keys() print "Opening", bbgFile nprim = float(bbgFile.split('nprim')[-1].split('_')[0]) rfile = TFile.Open(bbgFile, "READ") tBBG = rfile.Get("particle") yrel = '' print tBBG sDict = generate_sDict(tag, nprim, tBBG, yrel) # -- small version of fillTTree Trev = 1. / 11245 kT = 1.38e-23 * 300 # rootfile with results rfoutname = resultFileBG(bbgFile, year) print 'writing ', '.' * 33, rfoutname rfOUTile = TFile.Open(rfoutname, "RECREATE") rHists, hists_flat, hists_reweighted, cnt = [], [], [], 0 sk = [] for skey in 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 testing #if not skey.startswith("OrigZMuon"): continue sk += [skey] print "histogram ", len(sk) + 1, "." * 33, skey for j, skey in enumerate(sk): print "Now on #", j, ">" * 5, skey cnt += 1 # -- x axis, value particleTypes = sDict[skey][0] hname = skey xnbins = sDict[skey][2] xmin = sDict[skey][3] xmax = sDict[skey][4] mt = tBBG #print xnbins, xmin, xmax, "xnbins, xmin, xmax" var = '' energyweight = '' cf = 0.01 cuts = [' energy_ke > 0.02 '] if skey.startswith("Ekin"): xaxis = getXLogAxis(xnbins, xmin, xmax) var = "energy_ke" elif hname.startswith("Rad"): binwidth = xmax / xnbins xaxis = [i * binwidth for i in range(xnbins + 1)] var = '(TMath::Sqrt(x*x + y*y))' if skey.count("En"): energyweight = "energy_ke * " elif hname.startswith("Phi"): binwidth = (xmax - xmin) / xnbins xaxis = [xmin + i * binwidth for i in range(xnbins + 1)] var = '(TMath::ATan2(y,x))' if skey.count("En"): energyweight = "energy_ke * " elif hname.startswith("OrigZ"): binwidth = cf * (xmax - xmin) / xnbins xaxis = [cf * xmin + i * binwidth for i in range(xnbins + 1)] var = 'z_interact*0.01' xtitle = "s [m]" if not particleTypes[0].count('ll'): pcuts = ['particle ==' + p for p in particleTypes] pcut = '||'.join(pcuts) cuts += ['(' + pcut + ')'] # -- y axis = z-position ynbins, ymin, ymax = 524, 22.6, 546.6 # MUST TAKE FULL RANGE twoDhist = TH2F(skey, skey, xnbins, array('d', xaxis), ynbins, ymin, ymax) binw = (ymax - ymin) / ynbins if debug: print xaxis[:10], xaxis[-5:], len(xaxis), array('d', xaxis)[:10] hname_flat = skey + '_flat' twoDhist_flat = twoDhist.Clone(hname_flat) twoDhist_flat.Sumw2() hname_reweighted = skey + '_reweighted' twoDhist_reweighted = twoDhist.Clone(hname_reweighted) var = '0.01*z_interact:' + var cuts = "weight * " + energyweight + "(" + " && ".join(cuts) + ") " print "INFO: applying", cuts, "to", var, "in", hname_flat mt.Project(hname_flat, var, cuts) print "entries ", twoDhist_flat.GetEntries() hist_flat = twoDhist_flat.ProjectionX("makeit1d_flat" + skey) #hist_flat = twoDhist_flat.Clone("some1dclone") hist_flat.SetLineColor(kTeal - 2) print "hist_flat.GetEntries()", hist_flat.GetEntries() print "twoDhist_flat.GetEntries()", twoDhist_flat.GetEntries() #for i in range(xnbins+1): print "hist_flat.GetBinLowEdge(i)",hist_flat.GetBinLowEdge(i) # -- create pint histogram when at least 1 histogram is formed and do it only once if cnt == 1: hist_pint = twoDhist.ProjectionY("pint") #hist_pint = twoDhist.Clone("pint")## 1d test case if do6p5: data = cv79.getdata5c(pressFile) rho_H2, rho_CH4, rho_CO, rho_CO2 = cv79.getrho( data['H2_Eq']), cv79.getrho(data['CH4_Eq']), cv79.getrho( data['CO_Eq']), cv79.getrho(data['CO2_Eq']) rho_H, rho_C, rho_O = cv79.getAtomicRho( rho_H2, rho_CH4, rho_CO, rho_CO2) s = data['s'] else: s, rho_C, rho_H, rho_O = cv65.getAtomicRho(data) pint_tot = cv66.calc_pint_tot(energy, rho_C, rho_H, rho_O) pint_incomingbeam = {} for i, spoS in enumerate(s): spos = float(spoS) if spos < 0.: z = -spos pint_incomingbeam[z] = pint_tot[i] zbin = hist_pint.FindBin(z) hist_pint.SetBinContent(zbin, pint_incomingbeam[z]) # first value is for arc arcvalue = pint_tot[1] startarcBin = hist_pint.FindBin(startarc) print "setting arc pressure in bin", startarcBin, hist_pint.GetBinLowEdge( startarcBin), hist_pint.GetNbinsX( ) #, hist_pint.GetBinLowEgde(hist_pint.GetNbinsX()+1), for i in range(startarcBin, ynbins + 1): hist_pint.SetBinContent(i, arcvalue) # -- # compute re-weights for each bin Mk = nprim / ynbins # number of primary interactions per zbin on yaxis for j in range(1, ynbins + 1): scale = 1e2 * beamintensity * hist_pint.GetBinContent( j) * binw / Mk for i in range(1, xnbins + 1): m = twoDhist_flat.GetBinContent(i, j) twoDhist_reweighted.SetBinContent(i, j, scale * m) hists_flat += [twoDhist_flat] hists_reweighted += [twoDhist_reweighted] rHists += [skey] print hists_flat[-1].GetNbinsX() hists_flat[-1].Write() hists_reweighted[-1].Write() hist_pint.GetXaxis().SetTitle("s [m]") hist_pint.GetYaxis().SetTitle("interaction probability [1/s/m]") hist_pint.Write() rfOUTile.Close() print 'wrote ', '.' * 20, rfoutname
def cv67(): # -------------------------------------------------------------------------------- # density profile is given in the following format: # densities per molecule as function of s-coordinate # x,y,z, cx, cy, cz as function of (different s-coordinate) # merge densities with coordinates # note, that the source routine needs fluka units, ie *cm*! # -------------------------------------------------------------------------------- energy = "4 TeV" bgfile = '/afs/cern.ch/work/r/rkwee/HL-LHC/beam-gas-sixtrack/pressure_profiles_2012/LSS1_B1_Fill2736_Final.csv' bgfile = "/Users/rkwee/Documents/RHUL/work/data/4TeV/LSS1_B1_Fill2736_Final.csv" beamintensity = 2e14 energy = " 3.5 TeV " bgfile = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/LSS1_B1_fill_2028-sync_rad_and_ecloud.csv" beamintensity = 1.66e14 # https://acc-stats.web.cern.ch/acc-stats/#lhc/fill-details 2028 debug = 0 data = getdata14c(bgfile) print 'data keys are', data.keys() nb_s = len(data['s']) print 'number of s values', nb_s # atomic densities rho_C, rho_H, rho_O = [0 for i in range(nb_s)], [0 for i in range(nb_s) ], [0 for i in range(nb_s)] s = [-9999 for i in range(nb_s)] cf = 1. #for i in [1, 100, 300,500]: for i in range(1, nb_s): # get the data, convert to cm3 try: if debug: print 'i = ', i print "data['rho_H2'][i]", data['rho_H2'][i] print "data['rho_CH4'][i]", data['rho_CH4'][i] print "data['rho_CO'][i]", data['rho_CO'][i] print "data['rho_CO2'][i]", data['rho_CO2'][i] rho_H2 = cf * float(data['rho_H2'][i]) rho_CH4 = cf * float(data['rho_CH4'][i]) rho_CO = cf * float(data['rho_CO'][i]) rho_CO2 = cf * float(data['rho_CO2'][i]) # compute atomic rhos and translate nitrogen equivalent density rho_H[i] = 2.0 * rho_H2 rho_H[i] += 4.0 * rho_CH4 rho_C[i] = 1.0 * rho_CH4 rho_C[i] += 1.0 * rho_CO rho_C[i] += 1.0 * rho_CO2 rho_O[i] = 1.0 * rho_CO rho_O[i] += 2.0 * rho_CO2 s[i] = float(data['s'][i]) except ValueError: continue # -- # calculate the scaled number # unscaled inf hname, nbins, xmin, xmax = 'muons', 523, 22.5, 550 hist = TH1F(hname, hname, nbins, xmin, xmax) hist.Sumw2() hist.GetXaxis().SetTitle('s [m]') datafile = '/afs/cern.ch/project/lhc_mib/valBG4TeV/ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67' datafile = '/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67' datafile = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/beam_gas_3.5TeV_IR1_to_arc_20MeV_100M_nprim7660649_66" bbgFile = datafile + ".root" rfile = TFile.Open(bbgFile, "READ") hists = [] cnt = 0 mt = rfile.Get('particle') particleTypes = [10, 11] hname = 'muons_flatpressure' hist_flat = hist.Clone(hname) hist_pint = hist.Clone("pint") hist_e100 = hist.Clone("e100") hist_e100p = hist.Clone("e100p") cuts = "(particle == 10 || particle == 11) && energy_ke > 100.0" var = 'z_interact * 0.01' print "INFO: applying", cuts, "to", var, "in", "e100" mt.Project("e100", var, cuts) cuts = "(particle == 10 || particle == 11) && energy_ke > 0.02" print "INFO: applying", cuts, "to", var, "in", hname mt.Project(hname, var, cuts) sigma_N = 286.e-31 sigma_N_4TeV = 289.e-31 Trev = 2 * math.pi / 112450 # create histogram with same axis for pint pint_tot_atomic = calc_pint_tot(rho_C, rho_H, rho_O) # N2Eq_tot = [ float(data['CO_N2Eq'][i]) + float(data['CO2_N2Eq'][i]) + float(data['CH4_N2Eq'][i]) + float(data['H2_N2Eq'][i]) for i in range(1,len(data['s'])) ] # pint_tot = [sigma_N*j/Trev for j in range(len(N2Eq_tot))] rho_tot = [ float(data['rho_CO'][i]) + float(data['rho_CO2'][i]) + float(data['rho_CH4'][i]) + float(data['rho_H2'][i]) for i in range(1, len(data['s'])) ] pint_tot = [sigma_N * rho / Trev for rho in rho_tot] pint_incomingbeam = {} for i, sPos in enumerate(s): spos = float(sPos) if spos < 0.: z = -spos pint_incomingbeam[z] = pint_tot[i] zbin = hist_pint.FindBin(z) hist_pint.SetBinContent(zbin, pint_incomingbeam[z]) # first value is for arc arcvalue = pint_tot[1] startarc = 260. startarcBin = hist_pint.FindBin(startarc) for i in range(startarcBin, nbins - 1): hist_pint.SetBinContent(i, arcvalue) nprim = float(bbgFile.split('nprim')[-1].split('_')[0]) Trev = 2 * math.pi / 112450 kT = 1.38e-23 * 300 # compute normalisation fct for each bin for i in range(1, nbins + 1): m = hist_flat.GetBinContent(i) scale = beamintensity * hist_pint.GetBinContent(i) hist.SetBinContent(i, scale * m) hist_e100p.SetBinContent(i, scale * hist_e100.GetBinContent(i)) if i < 11: print "pint in bin", i, "is", hist_pint.GetBinContent(i) print "pint * beamintensity is", scale print "pint * beamintensity * m is", scale * m cv = TCanvas('cv', 'cv', 2100, 900) cv.SetGridy(1) cv.SetGridx(1) x1, y1, x2, y2 = 0.7, 0.65, 0.9, 0.88 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) ytitle = "particles/m/BG int." YurMin, YurMax = 2e2, 9e6 hist.GetYaxis().SetRangeUser(YurMin, YurMax) XurMin, XurMax = 0., 545. hist.GetXaxis().SetRangeUser(XurMin, XurMax) hist_flat.SetLineColor(kRed) hist_flat.GetYaxis().SetTitle(ytitle) hist.GetYaxis().SetTitle(ytitle) hist_e100p.SetFillColor(kRed - 3) hist_e100p.SetLineColor(kRed - 3) # hist_flat.Draw("hist") hist.Draw("hist") hist_e100p.Draw("histsame") #hist_pint.GetXaxis().SetRangeUser(1.e-13,2.5e-11) #hist_pint.Draw("l") lg, lm = "#mu^{#pm}", 'l' mlegend.AddEntry(hist_flat, lg, lm) lg, lm = "#mu^{#pm} E > 100 GeV", 'f' mlegend.AddEntry(hist_e100p, lg, lm) gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) # lab.DrawLatex(0.45, 0.9, energy+'beam-gas' ) lab.DrawLatex(0.4, 0.82, energy) #mlegend.Draw() pname = wwwpath + 'TCT/beamgas/pressure_profiles_2012/muonrates.pdf' pname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/muonrates.pdf" pname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/muonrates2011.pdf" # pname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/pint2011.pdf" 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 cv83(): # --------------------------------------------------- rel = 'compallpint' #rel = 'compallpress' cv = TCanvas('cv' + rel, 'cv' + rel, 1500, 900) cv.SetLogy(1) cv.SetGridy(0) x1, y1, x2, y2 = 0.67, 0.72, 0.88, 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) mg = TMultiGraph(rel, rel) lm = 'l' grs = [] for i, (pFile, xTitle, lText) in enumerate(pData): print "." * 33 print "Getting data from file", pFile data = {} if pFile.count("2736"): data = cv32.getdata14c(pFile) stmp, rho_C, rho_H, rho_O = cv65.getAtomicRho(data) stmp2 = stmp[1:] s_full = stmp2[::-1] pint_C, pint_H, pint_O, pint_tot = cv65.calc_pint_tot( rho_C, rho_H, rho_O) totalPress = [ data['H2_N2Eq'][j] + data['CH4_N2Eq'][j] + data['CO_N2Eq'][j] + data['CO2_N2Eq'][j] for j in range(len(data['H2_N2Eq'])) ] elif pFile.count("Density_Fill4"): data = cv79.getdata5c(pFile) totalPress = cv79.getTotalPressure(data) rho_H2, rho_CH4, rho_CO, rho_CO2 = cv79.getrho( data['H2_Eq']), cv79.getrho(data['CH4_Eq']), cv79.getrho( data['CO_Eq']), cv79.getrho(data['CO2_Eq']) rho_H, rho_C, rho_O = cv79.getAtomicRho(rho_H2, rho_CH4, rho_CO, rho_CO2) pint_H, pint_C, pint_O, pint_tot = cv79.getpint( rho_H, rho_C, rho_O) s_full = data['s'] elif pFile.count("HL_LHC"): # will only work for pint data = cv95.getdata14cHL(pFile) rho_H2 = cv79.getrho(data['H2_N2Eq']) rho_CH4 = cv79.getrho(data['CH4_N2Eq']) rho_CO2 = cv79.getrho(data['CO2_N2Eq']) rho_CO = cv79.getrho(data['CO_N2Eq']) rho_H, rho_C, rho_O = cv79.getAtomicRho(rho_H2, rho_CH4, rho_CO, rho_CO2) pint_H, pint_C, pint_O, pint_tot = cv79.getpint( rho_H, rho_C, rho_O) stmp = data["s"] s_full = list(reversed(list( reversed(stmp)))) # list last element of reversed list first s_incoming = [] pint_incoming, pint_tot_incomingbeam = [], [] # 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"): pint_tot_incomingbeam = pint_tot[len(s_positiveb2):] press_tot_incomingbeam = totalPress[len(s_positiveb2):] s_incoming = s_positiveb2[:len(s_positiveb2) - 1] else: pint_tot_incomingbeam = [ p for p in pint_tot[:len(s_positiveb1) + 1] ] if not pFile.count("HL_LHC"): press_tot_incomingbeam = [ p for p in totalPress[:len(s_positiveb1) + 1] ] s_incoming = s_positiveb1 if pFile.count("2736"): pint_tot_incomingbeam = pint_tot_incomingbeam[::-1] press_tot_incomingbeam = totalPress[::-1] print "len(pint_tot_incomingbeam)", len(pint_tot_incomingbeam) print "len(s_incoming)", len(s_incoming) print i, cols # print s_incoming[:100],press_tot_incomingbeam[:100] xlist, ylist, col, mstyle, lg = s_incoming, pint_tot_incomingbeam, cols[ i], 20 + i, lText #xlist, ylist, col, mstyle, lg = s_incoming,press_tot_incomingbeam , cols[i],20+i, lText grs += [makeTGraph(xlist, ylist, col, mstyle)] mlegend.AddEntry(grs[-1], lg, lm) mg.Add(grs[-1]) mg.Draw("al") Tt = TLatex() Tt = "#splitline{interaction probability density}{[1/proton/m/s]}" #mg.SetTitle("pressure profiles") mg.GetXaxis().SetTitle(xTitle) mg.GetYaxis().SetTitle(Tt) #mg.GetYaxis().SetTitle("total pressure [mbar]") mg.GetYaxis().SetRangeUser(5e-18, 4e-10) #mg.GetYaxis().SetRangeUser(5e-13,4e-6) mg.GetXaxis().SetRangeUser(0, 260) mlegend.Draw() lab = mylabel(42) lab.DrawLatex(0.42, 0.82, 'incoming beams') s = 22.6 lInterface = TLine() lInterface.SetLineStyle(2) lInterface.SetLineColor(kGray + 3) YurMin, YurMax = 5e-18, 4e-10 lInterface.DrawLine(s, YurMin, s, YurMax) pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/6500GeV/reweighted/' pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/HLRunII/' pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLLHCBackgroundPaper/figures/' pname += rel + ".pdf" print('Saving file as ' + pname) cv.Print(pname)
def cv65(): # -------------------------------------------------------------------------------- # density profile is given in the following format: # densities per molecule as function of s-coordinate # x,y,z, cx, cy, cz as function of (different s-coordinate) # merge densities with coordinates # note, that the source routine needs fluka units, ie *cm*! # -------------------------------------------------------------------------------- bgfile = '/afs/cern.ch/work/r/rkwee/HL-LHC/beam-gas-sixtrack/pressure_profiles_2012/LSS1_B1_Fill2736_Final.csv' bgfile = '/Users/rkwee/Documents/RHUL/work/data/4TeV/LSS1_B1_Fill2736_Final.csv' data = getdata14c(bgfile) print 'data keys are', data.keys() # -- s, rho_C, rho_H, rho_O = getAtomicRho(data) # plot atomic densities cv = TCanvas('cv', 'cv', 2100, 900) x1, y1, x2, y2 = 0.8, 0.7, 0.9, 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) mg = TMultiGraph() lm = 'pl' pint_C, pint_H, pint_O, pint_tot = calc_pint_tot(rho_C, rho_H, rho_O) xlist, ylist, col, mstyle, lg = s[1:], pint_tot, kBlack, 28, 'total' g3 = makeTGraph(xlist, ylist, col, mstyle) mlegend.AddEntry(g3, lg, lm) mg.Add(g3) xlist, ylist, col, mstyle, lg = s[1:], pint_O, kGreen, 22, 'O' g0 = makeTGraph(xlist, ylist, col, mstyle) mlegend.AddEntry(g0, lg, lm) mg.Add(g0) xlist, ylist, col, mstyle, lg = s[1:], pint_C, kGreen - 1, 20, 'C' g1 = makeTGraph(xlist, ylist, col, mstyle) mlegend.AddEntry(g1, lg, lm) mg.Add(g1) xlist, ylist, col, mstyle, lg = s[1:], pint_H, kBlue - 2, 23, 'H' g2 = makeTGraph(xlist, ylist, col, mstyle) mlegend.AddEntry(g2, lg, lm) mg.Add(g2) mg.Draw("alp") gPad.SetLogy(1) gPad.RedrawAxis() lab = mylabel(42) lab.DrawLatex(0.45, 0.88, 'interaction probability') mg.SetTitle("pressure profiles") mg.GetXaxis().SetTitle('distance to IP1 [m]') mg.GetYaxis().SetTitle('interaction probability [1/proton/m/s]' ) #"density #rho [atoms/m^{3}]") mg.GetYaxis().SetRangeUser(7e-17, 9e-11) mlegend.Draw() pname = wwwpath + 'TCT/beamgas/pressure_profiles_2012/pint.pdf' pname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/cv65_pint.pdf" pname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/cv65_pint_2011.pdf" print('Saving file as ' + pname) cv.Print(pname)