示例#1
0
def plotSpectra(bbgFile, tag, doComp):

    print "Using ...", bbgFile
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    tBBG = TFile.Open(bbgFile).Get(treeName)
    yrel = '/TCT hit'
 
    if doComp:
        # for comparisons plots, also edit rel
        sDict = sDict_HL_hybridComp
        rel = 'hybridComp_'
    else:
        sDict = generate_sDict(tag, norm, tBBG, yrel)
        rel = ''

    rfname = fillTTree.resultFile(bbgFile,rel)
    print "Want to open ", rfname

    if rfname.count('B1') or rfname.count('b1'): Beam, beam = 'B1', 'b1'
    elif rfname.count('B2') or rfname.count('b2'): Beam, beam = 'B2','b2'
    else: Beam, beam = '', ''

    if rfname.count('20MeV'): EnCutOff = '20MeV'
    elif rfname.count('20GeV'): EnCutOff = '20GeV'
    else: print 'no energycutoff?!'

    debug = 1

    if rfname.count("BH") and not rfname.count('4TeV') and not rfname.count('3p5TeV'): 
        hDict = hDict_HL_BH
        subfolder= 'TCT/HL/nominalSettings/beamhalo/'

        if debug: print "Using HL BG format", '.'*10

    elif rfname.count("BGac"): 
        hDict = hDict_HL_BGac
        subfolder= 'TCT/HL/nominalSettings/beamgas/'
        if debug: print "Using HL BH format", '.'*10

    elif rfname.count("comp"): 
        hDict = hDict_HL_comp
        subfolder= 'TCT/HL/nominalSettings/comp/'
        if debug: print "Using HL comp format", '.'*10

    elif rfname.count('4TeV'): 
        hDict = hDict_BH_4TeV
        subfolder= 'TCT/4TeV/'+Beam+'/' + EnCutOff + '/'
        if debug: print "Using 4 TeV format", '.'*10

    elif rfname.count('BG_4TeV'): 
        hDict = hDict_BG_4TeV
        subfolder= 'TCT/4TeV/'
        if debug: print "Using 4 TeV format", '.'*10

    elif rfname.count('BG_3p5TeV'): 
        hDict = hDict_BG_3p5TeV
        subfolder= 'TCT/3p5TeV/'
        if debug: print "Using 4 TeV format", '.'*10

    elif rfname.count('beam-halo_3.5TeV-R1_D1'): 
        hDict = hDict_BH_3p5TeV
        subfolder= 'TCT/3p5TeV/'
        if debug: print "Using 4 TeV format", '.'*10

    elif rfname.count('beam-halo_3.5TeV-R1_D1'): 
        hDict = hDict_BH_3p5TeV
        subfolder= 'TCT/3p5TeV/'
        if debug: print "Using 4 TeV format", '.'*10

    elif rfname.count('hybrid') and not rfname.count('Comp'): 
        hDict = hDict_BH_HL_hybrid
        if tag.count('tct5ot'): subfolder = 'TCT/HL/relaxedColl/newScatt/fluka/tct5otrd/'
        elif tag.count('tct5in'): subfolder= 'TCT/HL/relaxedColl/newScatt/fluka/tct5inrd/'
        else: print "define where to put the plots?"

    elif rfname.count('hybrid') and rfname.count('Comp'): 
        hDict = hDict_HLhybrid_comp
        subfolder = 'TCT/HL/relaxedColl/newScatt/fluka/comp/'

    else:
        print "no dictionary defined"
        sys.exit()

    if not os.path.exists(wwwpath + subfolder):
        print 'making dir', wwwpath + subfolder
        os.mkdir(wwwpath + subfolder)
    else: "Writing plot to ", wwwpath + subfolder

    # ---------------------------------------------------------------------------------
    print 'Opening ','.'*20, rfname
    rfile = TFile.Open(rfname)
    if rfname.count('comp') or rfname.count('Comp'):
        tag = ''

    for hkey in hDict.keys():
      
      print "Plotting ...", hkey
      hists = []
      cv = TCanvas( 'cv'+hkey, 'cv'+hkey, 1200, 900)

      gStyle.SetPalette(1)
      cv.SetRightMargin(0.15)
      #cv.SetLeftMargin(-0.1)

      hList = hDict[hkey][0] 
      x1, y1, x2, y2 = hDict[hkey][1],hDict[hkey][2],hDict[hkey][3],hDict[hkey][4]
      doLogx, doLogy = hDict[hkey][5], hDict[hkey][6]
      pname = wwwpath + subfolder + hkey 
      XurMin, XurMax = hDict[hkey][7],hDict[hkey][8]
      YurMin, YurMax = hDict[hkey][9],hDict[hkey][10]
      ZurMin, ZurMax = hDict[hkey][15],hDict[hkey][16]
      doFill = hDict[hkey][11]
      lText  = hDict[hkey][12] 
      lx, ly = hDict[hkey][13],hDict[hkey][14]

      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)
      
      for i,hname in enumerate(hList):
           hname += tag
           hists += [rfile.Get(hname)]

           if not hists[-1]:
               print "WARNING: histogram", hname," not found","!"*10
               continue

           print "INFO: ", hists[-1].GetName(), ' has ', hists[-1].GetEntries(), ' entries.'
           
           hcolor = sDict[hname][7]
           hists[-1].SetLineColor(hcolor)
           hists[-1].SetLineWidth(2)
           # if doFill:  hists[-1].SetFillColor(hcolor)
           
           norm   = sDict[hname][1]
           if norm != 1.: print 'normalising by ', norm
           #hists[-1].Scale(1./norm)
           leg = "l"
           if not i: 
               if   type(hists[-1]) == TH1F: hists[-1].Draw("HIST")
               elif type(hists[-1]) == TH2F: hists[-1].Draw("COLZ")
               elif type(hists[-1]) == TProfile: 
                   hists[-1].SetMarkerColor(hcolor)
                   hists[-1].Draw("P")
                   leg = "lp"
           else:
               if   type(hists[-1]) == TH1F: hists[-1].Draw("HISTSAME")

           prettyName = sDict[hname][6]
           mlegend.AddEntry(hists[-1],prettyName, leg)
           
           xtitle = sDict[hname][9]
           ytitle = sDict[hname][10]
        
      # ....................................
      if not hists[-1] or not hists[0]:
          continue

      if XurMin != -1:
          hists[0].GetXaxis().SetRangeUser(XurMin, XurMax)

      if YurMin != -1:
          hists[0].GetYaxis().SetRangeUser(YurMin, YurMax)

      if ZurMin != -1 and type(hists[0]) == TH2F: 
          hists[0].GetZaxis().SetRangeUser(ZurMin, ZurMax)
        
      hists[0].GetYaxis().SetTitleSize(0.04)
      hists[0].GetYaxis().SetLabelSize(0.035)
      hists[0].GetXaxis().SetTitleSize(0.04)
      hists[0].GetXaxis().SetLabelSize(0.035)
      if type(hists[0]) == TH2F: 
          hists[0].GetZaxis().SetLabelSize(0.035)

      hists[0].GetXaxis().SetTitle(xtitle)
      hists[0].GetYaxis().SetTitle(ytitle)

      mlegend.Draw()
      lab = mylabel(62)
      lab.DrawLatex(lx,ly,lText)
      #lab.DrawLatex(0.74,ly,Beam)

      gPad.RedrawAxis()
      if type(hists[0]) == TH2F: 
          gPad.SetLogz(doLogx)
      else:
          cv.SetGridx(0)
          cv.SetGridy(0)
          cv.SetLogx(doLogx)
          cv.SetLogy(doLogy)
      
      print('Saving file as' + pname ) 
      cv.Print(pname + '.pdf')
示例#2
0
def cv71():

    energy = "4 TeV"
    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'
    tag = '_BG_4TeV_20MeV_bs'
    beamintensity = 2e14
    bgcl = kAzure - 3
    bgcl = kPink - 3

    energy = "6.5 TeV"
    datafile = '/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67'
    tag = '_BG_6500GeV_flat_20MeV_bs'  #!! MMMeV NOT GeV
    bgcl = kYellow - 2
    beamintensity = 2.29e14  ## https://acc-stats.web.cern.ch/acc-stats/#lhc/fill-details 4536, ring 1.

    bbgFile = datafile + ".root"
    print "Opening", bbgFile
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    rfile = TFile.Open(bbgFile, "READ")
    tBBG = rfile.Get("particle")
    yrel = ''
    sDict = generate_sDict(tag, norm, tBBG, yrel)

    # -- small version of plotSpectra
    Trev = 2 * math.pi / 112450
    kT = 1.38e-23 * 300

    # rootfile with results
    rfoutname = resultFileBG(bbgFile, '')
    print "Opening", "." * 30, bbgFile
    rf = TFile.Open(rfoutname, "READ")

    for i, skey in enumerate(sDict.keys()):

        if skey.count("Sel"): continue
        elif skey.count("Neg"): continue
        elif skey.count("Pos"): continue
        elif skey.count("Z"): continue
        elif skey.count("Neu_"): continue
        elif skey.count("Char"): continue
        elif skey.count("Plus") or skey.count("Minus"): continue
        elif skey.split(tag)[0].endswith("0") or skey.count("XY"): continue
        elif skey.count("Pio") or skey.count("Kao"):
            continue

            # # FOR DEBUGGING
        elif not skey.count("N"):
            continue

        doLeft = 0
        if skey.count("Phi"): doLeft = 1
        cv = TCanvas(skey + 'cv', skey + 'cv', 1400, 900)
        # right corner
        x1, y1, x2, y2 = 0.7, 0.75, 0.9, 0.88
        if doLeft:
            x1, y1, x2, y2 = 0.2, 0.75, 0.5, 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)

        twoDhname_flat = skey + '_flat'
        twoDhname_reweighted = skey + '_reweighted'
        twoDhist_flat = rf.Get(twoDhname_flat)
        twoDhist_reweighted = rf.Get(twoDhname_reweighted)

        print twoDhist_flat, skey
        hist_flat = twoDhist_flat.ProjectionY(skey + "makeit1d_flat")
        hist_reweighted = twoDhist_reweighted.ProjectionY(
            skey + "makeit1d_reweighted")
        nbins = hist_reweighted.GetNbinsX()

        XurMin, XurMax = -1, -1.
        YurMin, YurMax = -1, -1.
        doLogx, doLogy = 0, 0
        if skey.count("Ekin"):
            hist_flat = doEkin(hist_flat, nbins)
            hist_reweighted = doEkin(hist_reweighted, nbins)
            doLogx, doLogy = 1, 1
            YurMin, YurMax = 1e-5, 8e-1
        elif skey.count("Phi"):
            hist_flat = doPhi(hist_flat, nbins)
            hist_reweighted = doPhi(hist_reweighted, nbins)
            doLogx, doLogy = 0, 1
            YurMin, YurMax = 1e-3, 2e-1
        elif skey.count("Rad"):
            hist_flat = doRad(hist_flat, nbins)
            hist_reweighted = doRad(hist_reweighted, nbins)
            hist_flat = helpers.doRebin(hist_flat, 3)
            hist_reweighted = helpers.doRebin(hist_reweighted, 3)
            doLogx, doLogy = 0, 1
            YurMin, YurMax = 1e-12, 1.2
            #XurMin,XurMax = 0, 600.

        hname = skey
        xtitle = sDict[hname][9]
        ytitle = sDict[hname][10] + ' a.u.'

        #hist_flat.Scale(1./hist_flat.Integral())
        #hist_reweighted.Scale(1./hist_reweighted.Integral())
        xtitle = 'z [m]'
        hist_flat.GetXaxis().SetTitle(xtitle)
        hist_reweighted.GetXaxis().SetTitle(xtitle)

        hist_flat.GetYaxis().SetRangeUser(YurMin, YurMax)
        hist_reweighted.GetYaxis().SetRangeUser(YurMin, YurMax)

        if XurMin != -1:
            hist_flat.GetXaxis().SetRangeUser(XurMin, XurMax)

        lg, lm = "flat", 'l'
        mlegend.AddEntry(hist_flat, lg, lm)
        #        hist_flat.SetLineStyle(2)

        hist_reweighted.SetLineColor(bgcl)
        hist_reweighted.SetMarkerColor(bgcl)
        hist_reweighted.SetMarkerStyle(20)

        hist_reweighted.GetYaxis().SetTitle(ytitle)
        hist_reweighted.Draw("hp")
        hist_flat.Draw("histsame")
        lg, lm = "reweighted", 'lp'
        mlegend.AddEntry(hist_reweighted, lg, lm)

        cv.SetLogx(0)
        cv.SetLogy(doLogy)
        gPad.RedrawAxis()

        lab = mylabel(42)
        lab.DrawLatex(0.41, 0.955, energy + ' beam-gas')
        lab.DrawLatex(0.5, 0.82, sDict[hname][6])

        mlegend.Draw()

        pname = wwwpath + 'TCT/6.5TeV/beamgas/fluka/bs/reweighted/' + skey + '.pdf'
        pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/6500GeV/reweighted/cv71_' + skey + '.pdf'
        if energy.count("4 TeV"):
            pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/cv71_' + skey + '.pdf'
        print('Saving file as ' + pname)
        cv.Print(pname)
示例#3
0
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
示例#4
0
def fillHistos(bbgFile, tag, doComp):

    # bbgFile is the rootfile with the TTree, use this to fill histograms
    # write out a rootfile with histograms

    print "Opening...", bbgFile
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])

    rf = TFile.Open(bbgFile)
    tBBG = rf.Get(treeName)

    yrel = '/TCT hit'

    if doComp:
        # for comparisons plots, also edit rel
        sDict = sDict_HL_hybridComp
        rel = 'hybridComp_'
    else:
        sDict = generate_sDict(tag, norm, tBBG, yrel)
        rel = ''

    # histograms which should be written one to rootfile
    rHists = []

    # rootfile with results
    rfoutname = resultFile(bbgFile, rel)

    print 'writing ', '.' * 20, rfoutname
    rfile = TFile.Open(rfoutname, "RECREATE")

    hists = []
    cnt = 0
    for i, skey in enumerate(sDict.keys()):

        if skey in rHists:
            continue

        cnt += 1

        # shorten for testing, useful for large size files and new functionality!!
        # if skey.count('RadNMuons_'): pass
        # elif skey.count('RadNNeutrons_'): pass
        # else: continue
        print "Getting ...", skey, '... #', cnt

        mt = sDict[skey][5]
        hists += [getHistogram(sDict, skey, mt)]
        rHists += [skey]

        norm = sDict[skey][1]
        if norm != 1.: print 'scaling by ', 1. / norm
        hists[-1].Scale(1. / norm)

        hcolor = sDict[skey][7]
        hists[-1].SetLineColor(hcolor)
        hists[-1].SetLineWidth(3)

        if not i:
            if type(hists[-1]) == TH1F: hists[-1].Draw("HIST")
            elif type(hists[-1]) == TH2F: hists[-1].Draw("COLZ")
            elif type(hists[-1]) == TProfile:
                hists[-1].SetMarkerColor(hcolor)
                hists[-1].Draw("P")
        else:
            if type(hists[-1]) == TH1F: hists[-1].Draw("HISTSAME")

        hists[-1].Write()

    rfile.Close()
    print 'wrote ', '.' * 20, rfoutname
示例#5
0
def cv78():
    # new halo (new scatt)
    norm4TeVB1newHalo = 1380 * 1.4e11 / 360000 * 0.5 * (622.0 / 50807535 +
                                                        930.0 / 53036514)
    # IR5: (866+92 + 170.0+456 )/(60948098 + 64935501) = 1.26e-5,>>> (866+92)/60948098 + (170.0+456)/64935501 = 9.64e-06
    # norm4TeVB2Offmom = 1380*1.4e11/360000 * ()
    norm4TeVB2newHalo = 1380 * 1.4e11 / 360000 * (1179.0 / 49207325 +
                                                  967 / 46222723.) / 2.
    # IR5: (1893.0 + 135)/(59198135 +56887051) = 1.75e-5, >>> 1893.0/59198135 +135/56887051. = 3.435e-05

    norm4TeVoffmomPLUS500 = 1380 * 1.4e11 / 360000 * 0.5 * (11919. / 995698)
    norm4TeVoffmomMINUS500 = 1380 * 1.4e11 / 360000 * 0.5 * (22278. / 3501844)
    norm6500GeVB1OLD = 2748 * 1.2e11 / 360000 * 0.5 * (
        739. / 53731448 + (312 + 273.) / 52806720)  # 2.1e-5
    norm6500GeVB2OLD = 2748 * 1.2e11 / 360000 * 0.5 * (
        779. / 43692659 + 773. / 52962459.
    )  # 2.76e-5 take the average of H an V runs!

    norm6500GeVB1 = 2041 * 1.12e11 / 360000 * 0.5 * (739. / 53731448 +
                                                     (312 + 273.) / 52806720)
    norm6500GeVB2 = 2041 * 1.12e11 / 360000 * 0.5 * (779. / 43692659 +
                                                     773. / 52962459.)
    # ---- HL -
    HLinitialFlux = 2736 * 2.2e11 / 360000  # 1.7e9

    # retracted settings
    normTCT5LOUTb1 = HLinitialFlux * 0.5 * (
        9024.0 / 54609869.0 + 3071.0 / 52175081.0
    )  # 0.00011205218641475149 #12091./(63828643+61405975) # 9.7e-5
    normTCT5LOUTb2 = HLinitialFlux * 0.5 * (
        9936.0 / 40392116.0 + 11898.0 / 53157089.0
    )  # 0.0002349078766943835 ### 21822/(47196776+63051589) # 2e-4
    normTCT5INb1 = HLinitialFlux * 0.5 * (
        9712.0 / 54532193.0 + 3366.0 / 52154816.0)  # 0.00012131762826402283
    normTCT5INb2 = HLinitialFlux * 0.5 * (
        9948.0 / 40401333.0 + 12028.0 / 53199970.0
    )  # 0.0002361599262 # 11172./(47203328+63096910) # 1e-4 sum of all tcts over protons lost on primary for h and v separately

    # python /afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/AnalysisScripts/py/collsummary.py -f 6.5TeV_vHaloB2_h5/coll_summary_6.5TeV_vHaloB2_h5.dat -c TCT*R5
    # IR5 B1: h:( 53754939.0 protons on IR7 primaries, 346.0 protons on TCT*L5.B1), v(52838656.0 on primaries IR7,  408.0 protons on TCTL5)
    # .5*( 346.0/53754939.0 + 408.0/52838656.0 ) = 7.0791187088930279e-06
    # IR5 B2: h:( 43718962.0 IR7,  302.0 protons ), v(53000835.0, 106.0 protons. )
    # 0.5 * (302.0/43718962.0 + 106.0/53000835.0) = 4.4538612500709768e-06

    # steer
    do4TeV, do6500GeV = 1, 0
    doHLcomp = 0
    doNumbers = 0
    # ------------------------------------------------------------------------
    if do4TeV:

        energy = "4 TeV"
        # all at 4 TeV
        f1 = '/afs/cern.ch/project/lhc_mib/valBG4TeV/results_pressure2012_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
        f2 = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
        f3 = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
        # f4 = '/afs/cern.ch/project/lhc_mib/offmom/FL_4TeVplusB2/results_ir1_offplus500Hz_4TeV_settings_from_TWISS_20MeV_b2_nprim3980000_30.root'
        #f5 = '/afs/cern.ch/project/lhc_mib/offmom/FL_4TeVminusB2/results_ir1_offmin500Hz4TeV_settings_from_TWISS_20MeV_b2_nprim3987000_30.root'

        # local
        f1 = thispath + 'results_pressure2012_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
        f2 = thispath + 'results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
        f3 = thispath + 'results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
        #f4 = thispath + 'results_ir1_offplus500Hz_4TeV_settings_from_TWISS_20MeV_b2_nprim3980000_30.root'
        #f5 = thispath + 'results_ir1_offmin500Hz4TeV_settings_from_TWISS_20MeV_b2_nprim3987000_30.root'

        filenames = [f1, f2, f3]

        subfolder = wwwpath + 'TCT/4TeV/compAllBKG/'

        lTexts = [
            'beam-gas', 'halo B1', 'halo B2', 'dp/p<0 (+500 Hz)',
            'dp/p>0 (-500 Hz)'
        ]
        tags = [
            '_BG_4TeV_20MeV_bs_reweighted', '_BH_4TeV_B1_20MeV',
            '_BH_4TeV_B2_20MeV', '_offplus500Hz_4TeV_B2_20MeV',
            '_offmin500Hz_4TeV_B2_20MeV'
        ]
        cols = [kOrange - 3, kBlue, kRed, kMagenta + 4, kTeal + 4]
        mars = [33, 20, 24, 22, 23]
        dOpt = ['hp', 'hsame', 'hsame', 'hsame', 'hsame']
        scalf = [
            1., norm4TeVB1newHalo, norm4TeVB2newHalo, norm4TeVoffmomPLUS500,
            norm4TeVoffmomMINUS500
        ]
        roundingDigit = 3
    elif do6500GeV:

        energy = "6.5 TeV"
        # all at 6.5 TeV # from cv69
        f1 = thispath + 'results_ir1_BH_6500GeV_b1_20MeV_nprim4752000_30.root'
        f2 = thispath + 'results_ir1_BH_6500GeV_b2_20MeV_nprim3646000_30.root'
        f3 = thispath + 'results_pressure2015_ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root'
        filenames = [f3, f1, f2]

        lTexts = ['beam-gas', 'Halo B1', 'Halo B2']
        tags = [
            '_BG_6500GeV_flat_20MeV_bs_reweighted', '_BH_6500GeV_haloB1_20MeV',
            '_BH_6500GeV_haloB2_20MeV'
        ]
        cols = [kYellow - 2, kAzure + 9, kPink - 8]
        mars = [33, 20, 24]
        dOpt = ['hist', 'histsame', 'histsame']
        scalf = [1., norm6500GeVB1, norm6500GeVB2]
        roundingDigit = 2

    elif doHLcomp:
        roundingDigit = 2
        energy = ""
        f1 = thispath + 'results_pressure2015_ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root'
        f2 = thispath + "results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5550000_30.root"
        f2 = thispath + "results_ir1_BH_6500GeV_b2_20MeV_nprim3646000_30.root"
        f3 = thispath + "results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5924500_30.root"
        f4 = thispath + "results_hilumi_ir1_fort_scaled_afterconditioning_max_nprim1_30.root"

        filenames = [f4, f3, f1, f2]
        tags = [
            "_BG_HL_ac_20MeV",
            "_BH_HL_tct5inrdB2_20MeV",
            "_BG_6500GeV_flat_20MeV_bs_reweighted",
            "_BH_6500GeV_haloB2_20MeV",
        ]

        lTexts = [
            'HL BG a.c.',
            'HL Halo B2',
            'Run II BG',
            'Run II Halo B2',
        ]
        cols = [kAzure + 2, kGreen - 3, kYellow - 2, kRed - 4]
        mars = [23, 20, 22, 24]
        dOpt = ['hp', 'hpsame', 'hpsame', 'hpsame']
        scalf = [1., normTCT5INb2, 1., norm6500GeVB2]

    # ------------------------------------------------------------------------
    debug = 1
    # need one file to generate sDict
    bbgFile = f1
    print "Opening for sDict generation ...", bbgFile
    tag = tags[0]
    yrel = '/s'
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    tBBG = TFile.Open(bbgFile).Get(treeName)
    sDict = generate_sDict(tag, norm, tBBG, yrel)
    try:
        if not os.path.exists(subfolder):
            print 'making dir', subfolder
            os.mkdir(subfolder)
    except:
        pass

    rfs = [TFile.Open(f_i) for f_i in filenames]

    msize = 0.05
    for skey in sDict.keys():

        if skey.count("Sel"): continue
        elif skey.count("Neg"): continue
        elif skey.count("Pos"): continue
        elif skey.count("Z"): 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.count('Muons'): continue

        cv = TCanvas('cv' + skey, 'cv' + skey, 10, 10, 1200, 900)
        xpos = 0.65
        if doNumbers: xpos = 0.5
        x1, y1, x2, y2 = xpos, 0.73, 0.95, 0.93  # right corner

        if 0:  # skey.count("PhiEnAll") or skey.count("PhiEnPhot") or skey.count("PhiNAllE") or skey.count("PhiNP") or skey.count("EnPro"):
            x1, y1, x2, y2 = 0.2, 0.75, 0.44, 0.93  # left corner

        mlegend = TLegend(x1, y1, x2, y2)
        mlegend.SetFillColor(0)
        mlegend.SetFillStyle(0)
        mlegend.SetLineColor(0)
        mlegend.SetTextSize(0.04)
        mlegend.SetShadowColor(0)
        mlegend.SetBorderSize(0)

        XurMin, XurMax = -1, -1
        YurMin, YurMax = -1, -1

        hname = skey  # contains tag
        hnames = [hname.replace(tag, tg) for tg in tags]
        if debug: print 'plotting ', hnames

        xtitle, ytitle = sDict[skey][9], sDict[skey][10]

        # per rf file 1 histogram
        hists = []
        Ymax, Ymin = [], []
        for i, rf in enumerate(rfs):

            if debug: print "trying to get", hnames[i], "from ", rf
            hists += [rf.Get(hnames[i])]

            if not hists[-1]:
                print "WARNING : Didn't find ", hnames[i]
                continue

        if debug: print "Have in hists", hists

        intvals, ratios = [], []
        for i in range(len(hists)):

            isLogx, isLogy = 0, 0

            try:
                hname = hnames[i]

                if hname.count('Ekin') or hname.count(
                        "En") or hname.startswith("Rad") or hname.startswith(
                            "Phi"):
                    isLogy = 1
                    if hname.count("Ekin"):
                        isLogx = 1
                        #XurMin,XurMax = 0.02,8e3

                hists[i].SetLineWidth(2)
                hists[i].SetLineStyle(1)
                hists[i].SetLineColor(cols[i])
                hists[i].SetMarkerStyle(mars[i])
                hists[i].SetMarkerSize(1.03)
                hists[i].SetMarkerColor(cols[i])
                #hists[i].GetXaxis().SetLabelSize(0.2))
                # To scale get min max value from all histograms first before drawing
                print ".." * 22, hists[i].GetEntries(
                ), "." * 22, hists[i].GetName()
                if isLogy:
                    Ymax += [hists[i].GetMaximum()]
                    Ymin += [hists[i].GetBinContent(10)]
                # if debug: print Ymin, " for", hname

            except AttributeError:
                print "WARNING : histogram", hnames[
                    i], "doesn't exist in", filenames[i]
                break

        # skip all histograms when one is missing
        if not hists[0]: continue

        hists[0].GetXaxis().SetTitle(xtitle)

        cv.cd()
        if isLogx: cv.SetLogx()
        if isLogy: cv.SetLogy()

        if debug: print len(hists), hists
        for i in range(len(hists)):
            hists[i].Scale(scalf[i])

            if debug: print "Setting y axes", YurMin, YurMax, dOpt[i]

            if hnames[i].count("Phi"):
                XurMin, XurMax = -3.14, 3.01
                YurMin, YurMax = 1e-1 * max(Ymax), max(Ymax) * 1e4
                if hnames[i].count("En"):
                    YurMin, YurMax = 1e2, 2e11

                    #if not hnames[i].count("All") and not hnames[i].count("Prot"):
                    #    YurMin, YurMax = 1e2,9e8

            elif hnames[i].count("Ekin"):
                YurMin, YurMax = 1e-3, 2e8

            elif hnames[i].count("Rad"):
                XurMin, XurMax = 0., 600.
                YurMin, YurMax = 1e-3, 1e10
                if hnames[i].count("All"):
                    YurMin, YurMax = 1e-4, 1e12

            if hists[i].GetName().endswith("reweighted"):
                hists[i].ProjectionX().GetYaxis().SetRangeUser(YurMin, YurMax)
                hists[i].ProjectionX().GetYaxis().SetTitle(ytitle)
                intvals += [hists[i].ProjectionX().Integral()]
                hists[i].ProjectionX().Draw(dOpt[i])
                if XurMin != -1:
                    hists[i].ProjectionX().GetXaxis().SetRangeUser(
                        XurMin, XurMax)
            else:
                intvals += [hists[i].Integral()]
                hists[i].GetXaxis().SetTitle(xtitle)
                hists[i].GetYaxis().SetTitle(ytitle)
                if XurMin != -1:
                    hists[i].GetXaxis().SetRangeUser(XurMin, XurMax)

                if YurMin != -1:
                    hists[i].GetYaxis().SetRangeUser(YurMin, YurMax)

                hists[i].Draw(dOpt[i])

            ratios += [round(intvals[-1] / intvals[0], roundingDigit)]
            print " intergral of ", hists[i].GetName(
            ), "=", intvals[-1], ratios[-1]
            numbers = ""
            if doNumbers: numbers = " (" + str(ratios[i]) + ")"
            mlegend.AddEntry(hists[i], lTexts[i] + numbers, "lp")

        mlegend.Draw()

        print "  ", hname, "=", intvals[-1]
        lab = mylabel(42)
        lab.SetTextSize(0.06)
        lab.DrawLatex(0.35, 0.855, sDict[skey][6])
        nlab = mylabel(42)
        nlab.DrawLatex(0.45, 0.955, energy)

        lab = mylabel(42)
        lab.SetTextSize(0.1)
        #        lab.SetTextColor(col)

        # add new folder to separate from main note
        pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/6500GeV/reweighted/app/cv78_' + hnames[
            i].split('_')[0] + '.pdf'
        if do4TeV:
            pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/app/cv78_' + hnames[
                i].split('_')[0] + '.pdf'
        elif doHLcomp:

            pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/HLRunII/cv78_' + hnames[
                i].split('_')[0] + '.pdf'
            #subfolder = wwwpath + "TCT/HL/compHLRun2/"
            #pname = subfolder + "cv78_" + hnames[i].split("_")[0]+".pdf"
            print pname
        cv.SaveAs(pname)
示例#6
0
def cv84():

    datafile = '/afs/cern.ch/project/lhc_mib/valBG4TeV/ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67'
    tag = '_BG_4TeV_20MeV_bs'
    beamintensity = 2e14

    energy = "6.5 TeV"
    datafile = '/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67'
    tag = '_BG_6500GeV_flat_20MeV_bs'  #!! MMMeV NOT GeV
    beamintensity = 2.29e14  ## https://acc-stats.web.cern.ch/acc-stats/#lhc/fill-details 4536, ring 1.

    bbgFile = datafile + ".root"
    print "Opening", bbgFile
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    rfile = TFile.Open(bbgFile, "READ")
    tBBG = rfile.Get("particle")
    yrel = ''
    sDict = generate_sDict(tag, norm, tBBG, yrel)

    # -- small version of plotSpectra
    Trev = 2 * math.pi / 112450
    kT = 1.38e-23 * 300

    # rootfile with results
    rfoutname = resultFileBG(bbgFile, '')
    print "Opening", "." * 30, bbgFile
    rf = TFile.Open(rfoutname, "READ")

    for i, skey in enumerate(sDict.keys()):

        if skey.count("Sel"): continue
        elif skey.count("Neg"): continue
        elif skey.count("Pos"): continue
        elif skey.count("Z"): 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
        elif not skey.count("Ekin"):
            continue
        a, b = 1, 2
        cv = TCanvas(skey + 'cv', skey + 'cv', a * 1400, b * 900)
        cv.Divide(a, b)

        x1, y1, x2, y2 = 0.7, 0.75, 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)
        xtitle = sDict[skey][9]

        twoDhname_flat = skey + '_flat'
        twoDhname_reweighted = skey + '_reweighted'
        twoDhist_flat = rf.Get(twoDhname_flat)
        twoDhist_reweighted = rf.Get(twoDhname_reweighted)
        twoDhist_reweighted.GetXaxis().SetTitle(xtitle)
        lg, lm = "reweighted", 'l'
        #        mlegend.AddEntry(hist_reweighted, lg, lm)

        doLogx, doLogy = 0, 0
        if skey.count("Ekin"):
            doLogx, doLogy = 1, 1
        elif skey.count("Phi"):
            doLogx, doLogy = 0, 1
        elif skey.count("Rad"):
            doLogx, doLogy = 0, 1

        cv.cd(2)
        twoDhist_reweighted.Draw("colz")
        cv.SetLogx(doLogx)
        cv.SetLogy(doLogy)
        gPad.RedrawAxis()
        cv.cd(1)
        twoDhist_flat.Draw("colz")

        cv.SetLogx(doLogx)
        cv.SetLogy(doLogy)
        gPad.RedrawAxis()

        lab = mylabel(42)
        lab.DrawLatex(0.2, 0.9, 'flat (1)')
        lab.DrawLatex(0.5, 0.82, 'reweighted (2)')

        #   mlegend.Draw()

        pname = wwwpath + 'TCT/6.5TeV/beamgas/fluka/bs/reweighted/' + skey + '.pdf'
        pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/6500GeV/reweighted/2d_' + skey + '.pdf'
        print('Saving file as ' + pname)
        cv.Print(pname)
示例#7
0
def cv16():
    thispath = '/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/'

    # DONT USE
    # --- norm4TeVB1  = 1380 *1.4e11/360000 * (265+95.)/(61832091+12732234) # 98 TCTH 65 TCTV, 6.37e6 6.1e6 primaries
    # --- norm4TeVB2 = 1380 * 1.4e11/360000 * (521.0+454.0)/(69021155+63014399)
    #norm4TeVB1 = 1380 *1.4e11/360000 * (65+98.)/(6.1e6+6.37e6) # 98 TCTH 65 TCTV, 6.37e6 6.1e6 primaries
    #norm4TeVB2 = 1380 * 1.4e11/360000 * (124.0+115)/(6.4e6+6.3e6)

    # old scatt
    norm4TeVB1oldHalo = 1380 * 1.4e11 / 360000 * (265 + 95.) / (
        61832091 + 12732234)  # 98 TCTH 65 TCTV, 6.37e6 6.1e6 primaries
    norm4TeVB2oldHalo = 1380 * 1.4e11 / 360000 * (521.0 + 454.0) / (69021155 +
                                                                    63014399)

    # new halo (new scatt)
    norm4TeVB1newHalo = 1380 * 1.4e11 / 360000 * 0.5 * (
        622.0 / 60948098 + 930.0 / 64935501
    )  # = 1.2263654213882985e-05 with factor 0.5
    norm4TeVB1newHalo50h = 1380 * 1.4e11 / 180000 * 0.5 * (
        622.0 / 60948098 + 930.0 / 64935501
    )  # = 1.2263654213882985e-05 with factor 0.5
    # IR5: (866+92 + 170.0+456 )/(60948098 + 64935501) = 1.26e-5,>>> (866+92)/60948098 + (170.0+456)/64935501 = 9.64e-06

    norm4TeVB2newHalo = 1380 * 1.4e11 / 360000 * (1179.0 / 59198135 +
                                                  967 / 56887051.) / 2.
    # IR5: (1893.0 + 135)/(59198135 +56887051) = 1.75e-5, >>> 1893.0/59198135 +135/56887051. = 3.435e-05

    norm6500GeVB1Old = 2748 * 1.2e11 / 360000 * 0.5 * (
        739. / 53731448 + (312 + 273.) / 52806720)  # 1.24e-5
    norm6500GeVB2Old = 2748 * 1.2e11 / 360000 * 0.5 * (
        779. / 43692659 + 773. / 52962459.)  # new 1.62e-5

    norm6500GeVB1 = 2041 * 1.12e11 / 360000 * 0.5 * (
        739. / 53731448 + (312 + 273.) / 52806720)  # 1.24e-5
    norm6500GeVB2 = 2041 * 1.12e11 / 360000 * 0.5 * (
        779. / 43692659 + 773. / 52962459.)  # new 1.62e-5

    # python /afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/AnalysisScripts/py/collsummary.py -f 6.5TeV_vHaloB2_h5/coll_summary_6.5TeV_vHaloB2_h5.dat -c TCT*R5
    # IR5 B1: h:( 53754939.0 protons on IR7 primaries, 346.0 protons on TCT*L5.B1), v(52838656.0 on primaries IR7,  408.0 protons on TCTL5)
    # .5*( 346.0/53754939.0 + 408.0/52838656.0 ) = 7.0791187088930279e-06
    # IR5 B2: h:( 43718962.0 IR7,  302.0 protons ), v(53000835.0, 106.0 protons. )
    # 0.5 * (302.0/43718962.0 + 106.0/53000835.0) = 4.4538612500709768e-06

    run1iniFlux = 1380 * 1.5e11 / 180000.  # from Roderiks NIM paper: 2010: 368 up to 2011 1380, lifetime only 50h!
    norm3500GeVB1 = 1.02813e-5 * run1iniFlux  # from http://bbgen.web.cern.ch/bbgen/bruce/fluka_beam-halo_3.5TeV/flukaIR15.html
    norm3500GeVB2 = 2.25625e-5 * run1iniFlux  # from http://bbgen.web.cern.ch/bbgen/bruce/fluka_beam-halo_3.5TeV/flukaIR15.html

    # fNum   = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_b2_nprim7825000_66.root'
    # fDenom = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/compB2oldB2new/'
    # lTextNum = 'B2 old'
    # lTextDenom = 'B2 new'
    # tagNum, tagDenom = 'BH_4TeV_B2', 'BH_4TeV_B2_20MeV'
    # nColor, dColor = kCyan+1, kTeal

    # fNum = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim7945000_66.root'
    # #fDenom   = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/compNewScattB1/'
    # fDenom = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
    # #fNum   = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # normDenom, normNum = 1., 1.
    # lTextNum = 'B2 old'
    # lTextDenom = 'B2 new'
    # tagDenom, tagNum = '_BH_4TeV_B2_20MeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink-6
    # yrel = '/TCT hit'
    # # yrel = '/s'

    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
    # fDenom   = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim7945000_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/compOldNewScattB2/perTCThit/'
    # lTextNum = 'new'
    # lTextDenom = 'old'
    # normDenom, normNum = 1./norm4TeVB2oldHalo, 1./norm4TeVB2newHalo
    # normDenom, normNum = 1., 1.
    # tagDenom, tagNum = '_BH_4TeV_B2_20MeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink+8
    # yrel = '/s'
    # yrel = '/TCT hit'

    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_4TeV_settings_from_TWISS_20GeV_b2_nprim6914000_30.root'
    # fDenom = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2_20GeV/results_ir1_4TeV_settings_from_TWISS_20GeV_b2_nprim90520000_30.root'
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/newScatt/compB2tail/'
    # lTextNum = 'all energies'
    # lTextDenom = '20 GeV tail'
    # normDenom, normNum = 1., 1.
    # tagDenom, tagNum = '_BH_4TeV_B2_20GeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink+2
    # yrel = '/TCT hit'

    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # fDenom = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1_20GeV/results_ir1_4TeV_settings_from_TWISS_20GeV_b1_nprim125170000_30.root'
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/newScatt/compB1tail/'
    # lTextNum = 'all energies'
    # lTextDenom = '20 GeV tail'
    # normDenom, normNum = 1., 1.
    # tagDenom, tagNum = '_BH_4TeV_B1_20GeV', '_BH_4TeV_B1_20MeV'
    # nColor, dColor = kOrange-3, kPink-2
    # yrel = '/TCT hit'

    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # fDenom   = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/compOldNewScattB1/perTCThit/'
    # lTextNum = 'new'
    # lTextDenom = 'old'
    # normDenom, normNum = 1./norm4TeVB1oldHalo, 1./norm4TeVB1newHalo
    # normDenom, normNum = 1., 1.
    # tagDenom, tagNum = '_BH_4TeV_B1_20MeV', '_BH_4TeV_B1_20MeV'
    # nColor, dColor = kOrange-3, kPink-2
    # yrel = '/s'
    # yrel = '/TCT hit'

    # fDenom = workpath + 'runs/3.5TeV/results_beam-halo_3.5TeV-R1_D1_20MeV_b2_nprim2344800_66.root'
    # fDenom="/Users/rkwee/Documents/RHUL/work/data/3p5TeV/results_beam-halo_3.5TeV-R1_D1_20MeV_b2_nprim2344800_66.root"
    # fNum=thispath+"results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root"
    # subfolder = wwwpath + 'TCT/4TeV/compB2_3p5vs4TeV/perTCThit/'
    # lTextNum, lTextDenom = '4 TeV w/ x-ing', '3.5 TeV w/o x-ing'
    # # #normNum, normDenom = 1./norm4TeVB2, 1./(norm3500GeVB2)
    # normNum, normDenom = 1., 1.
    # tagDenom, tagNum = '_BH_3p5TeV_B2_20MeV', '_BH_4TeV_B2_20MeV'
    # subfolder = wwwpath + 'TCT/4TeV/compB2_3p5vs4TeV/'
    # nColor, dColor = kOrange+1, kBlue-3
    # yrel = '/TCT hit'

    # subfolder = wwwpath + 'TCT/4TeV/compB2_3p5vs4TeV/'
    # normDenom, normNum = 1.,1.
    # yrel = '/TCT hit'

    # # - comparison BH 3.5 vs 4 TeV
    # # #-- OLD SIM    # fNum = workpath + 'data/4TeV/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # fDenom =  projectpath + 'bbgen/3.5TeV/results_beam-halo_3.5TeV-L1_20MeV_b1_nprim1731200_66.root'

    # fNum = thispath + 'results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # fDenom =  "/Users/rkwee/Documents/RHUL/work/data/3p5TeV/results_beam-halo_3.5TeV-L1_20MeV_b1_nprim1731200_66.root"
    # lTextNum, lTextDenom = '4 TeV', '3.5 TeV'
    # # normNum, normDenom, yrel = 1./norm4TeVB1newHalo50h, 1./norm3500GeVB1, '/s'
    # normNum, normDenom, yrel = 1.,1., '/TCT hit'
    # tagDenom, tagNum = '_BH_3p5TeV_B1_20MeV', '_BH_4TeV_B1_20MeV'
    # nColor, dColor = kOrange+3, kMagenta-3
    # subfolder = wwwpath + 'TCT/compBHB1_3p5vs4TeV/perTCThit/'

    # # # comparison BG 3.5 vs 4 TeV
    # # fNum = projectpath + '4TeVBGnoBS/results_beam-gas_4TeV-IR1_to_arc_20MeV_cutoff_100M_nprim7283044_66.root' # erased, produce new....
    # # fDenom = projectpath + '4TeVBGnoBS/results_beam_gas_3.5TeV_IR1_to_arc_20MeV_100M_nprim7660649_66.root'
    # fNum = thispath + 'results_beam-gas_4TeV-IR1_to_arc_20MeV_cutoff_100M_nprim7283044_66.root' # erased, produce new....
    # fDenom = thispath + 'results_beam_gas_3.5TeV_IR1_to_arc_20MeV_100M_nprim7660649_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/compBG_3p5_vs_4TeV/'
    # subfolder =  '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/compBG_3p5_vs_4TeV/perBGint/'
    # lTextDenom, lTextNum = '3.5 TeV w/o x-ing', '4 TeV w/ x-ing'
    # normDenom, normNum = 1.,1.
    # tagDenom, tagNum = '_BG_3p5TeV_20MeV', '_BG_4TeV_20MeV'
    # nColor, dColor = kOrange-1, kRed-2
    # yrel = '/inel.BG int.'

    # # # comparison BG 3.5 vs 4 TeV with beamsize
    # fNum = thispath + 'results_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
    # fDenom = thispath + 'results_beam_gas_3.5TeV_IR1_to_arc_20MeV_100M_nprim7660649_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/compBG_3p5_vs_4TeV/'
    # subfolder =  '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/compBG_3p5_vs_4TeV/perBGint_bs/'
    # lTextDenom, lTextNum = '3.5 TeV w/o x-ing', '4 TeV w/x-ing + bs'
    # normDenom, normNum = 1.,1.
    # tagDenom, tagNum = '_BG_3p5TeV_20MeV', '_BG_4TeV_20MeV_bs'
    # nColor, dColor = kOrange-2, kRed+1
    # yrel = '/inel.BG int.'

    # ------------------------------------------------------------------------
    # # beamgas 4 TeV
    # fNum = projectpath + '4TeVBGnoBS/results_beam-gas_4TeV-IR1_to_arc_20MeV_cutoff_100M_nprim7283044_66.root'
    # fDenom = '/afs/cern.ch/project/lhc_mib/valBG4TeV/results_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
    # subfolder = wwwpath + 'TCT/4TeV/beamgas/beamsizeRatio/'
    # fNum = thispath + "results_beam-gas_4TeV-IR1_to_arc_20MeV_cutoff_100M_nprim7283044_66.root"
    # fDenom = thispath + "results_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root"
    # subfolder =  '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/beamsizeRatio/'
    # lTextNum, lTextDenom = 'pointlike', 'w/ beamsize'
    # normDenom, normNum = 1.,1.
    # tagDenom, tagNum = '_BG_4TeV_20MeV_bs', '_BG_4TeV_20MeV'
    # nColor, dColor = kOrange-1, kRed-3
    # yrel = '/inel.BG int.'

    # # beamgas 4 TeV vs 6.5 TeV
    # fNum = projectpath + 'beamgas/6500GeV_beamsize/runs400/results_ir1_BG_bs_6500GeV_b1_20MeV_nprim2716000_67.root'
    # fDenom = projectpath + 'bbgen/4TeV/beamgas/withBeamSize/results_ir1_BG_4TeV_settings_from_TWISS_20MeV_b1_nprim5925000_67.root'
    # subfolder = wwwpath + 'TCT/compBG_4TeV_vs_6.5TeV/'
    # lTextNum, lTextDenom = '6.5 TeV bs', '4 TeV bs'
    # normDenom, normNum = 1.,1.
    # tagDenom, tagNum = '_BG_4TeV_20MeV_bs', '_BG_6500GeV_flat_20MeV_bs'
    # nColor, dColor = kOrange-1, kMagenta-3
    # yrel = '/inel.BG int.'

    # # # # beamgas 4 TeV vs 6.5 TeV reweighted
    # fNum = thispath + 'results_pressure2012_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
    # fDenom = thispath + 'results_pressure2015_ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root'
    # subfolder = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/compBGreweighted/'
    # lTextNum, lTextDenom = '4 TeV', '6.5 TeV'
    # normDenom, normNum = 1.,1. # IS ALREADY Normalised
    # tagNum, tagDenom = '_BG_4TeV_20MeV_bs_reweighted', '_BG_6500GeV_flat_20MeV_bs_reweighted'
    # nColor, dColor = kGray+2, kBlue+4
    # labelText = ''
    # yrel = '/s'

    # # # # beamgas 4 TeV vs 4 TeV reweighted vs flat
    # fDenom = thispath + 'results_pressure2012_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root' the flat hists are not normalised, except for binning
    # fNum = thispath + 'results_pressure2012_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root' the flat hists are not normalised, except for binning
    # subfolder = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/compBGflat/'
    # lTextDenom, lTextNum = 'reweighted [1/s]', 'flat x10^{7}'
    # normNum, normDenom = 5925000./1e7,1.
    # tagDenom, tagNum = '_BG_4TeV_20MeV_bs_reweighted', '_BG_4TeV_20MeV_bs_flat'
    # nColor, dColor = kPink-3, kBlack
    # yrel = '/a.u.'

    # fDenom = thispath + 'results_pressure2015_ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root'
    # fNum = thispath + 'results_pressure2015_ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root'
    # subfolder = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/6500GeV/compBGflat/'
    # lTextDenom, lTextNum = 'reweighted [1/s]', 'flat x10^{7}'
    # normNum, normDenom = 3198000./1e7,1.
    # tagDenom, tagNum = '_BG_6500GeV_flat_20MeV_bs_reweighted', '_BG_6500GeV_flat_20MeV_bs_flat'
    # dColor, nColor = kYellow-3, kBlack
    # yrel = '/a.u.'

    #    # # beamgas 6.5 TeV, 20 MeV vs 6.5 TeV, 20 GeV
    # fNum = projectpath + 'bbgen/6.5TeV/runs400_20MeV/results_ir1_BG_bs_6500GeV_b1_20MeV_nprim2716000_67.root'
    #    fDenom = projectpath + 'beamgas/6500GeV_beamsize/runs10k_20GeV/results_ir1_BG_bs_6500GeV_b1_20GeV_nprim181730000_67.root'
    #    subfolder = wwwpath + 'TCT/compBG_6.5TeV/'
    #    lTextNum, lTextDenom = '20 MeV', '20 GeV'
    #    normDenom, normNum = 1.,1.
    #    tagDenom, tagNum = '_BG_6500GeV_flat_20GeV_bs', '_BG_6500GeV_flat_20MeV_bs'
    #    nColor, dColor = kBlue-1, kMagenta-3
    #    yrel = '/inel.BG int.'

    # # # beamgas 4 TeV 20 MeV vs 20 GeV
    # fNum = projectpath + 'bbgen/4TeV/beamgas/withBeamSize/results_ir1_BG_4TeV_settings_from_TWISS_20MeV_b1_nprim5925000_67.root'
    # fDenom = projectpath + 'BG/FL_4TeV_BG_20GeV_10k/results_ir1_BG_bs_4TeV_settings_from_TWISS_20GeV_b1_nprim89940000_67.root'
    # subfolder = wwwpath + 'TCT/4TeV/beamgas/fluka/bs/compBGtail/'
    # lTextNum, lTextDenom = '20 MeV', '20 GeV'
    # normDenom, normNum = 1.,1.
    # tagDenom, tagNum = '_BG_4TeV_20GeV_bs', '_BG_4TeV_20MeV_bs'
    # nColor, dColor = kOrange-1, kMagenta-3
    # yrel = '/inel.BG int.'

    # ------------------------------------------------------------------------
    # ---- HL -
    # awk '{ sum += $4; } END { print sum; }' H5_HL_TCT5LOUT_relaxColl_hHaloB1_roundthin/coll_summary_H5_HL_TCT5LOUT_relaxColl_hHaloB1_roundthin.dat
    # awk '{ sum += $4; } END { print sum; }' H5_HL_TCT5LOUT_relaxColl_vHaloB1_roundthin/coll_summary_H5_HL_TCT5LOUT_relaxColl_vHaloB1_roundthin.dat
    # awk '{ sum += $4; } END { print sum; }' H5_HL_TCT5LOUT_relaxColl_hHaloB2_roundthin/coll_summary_H5_HL_TCT5LOUT_relaxColl_hHaloB2_roundthin.dat
    # awk '{ sum += $4; } END { print sum; }' H5_HL_TCT5LOUT_relaxColl_vHaloB2_roundthin/coll_summary_H5_HL_TCT5LOUT_relaxColl_vHaloB2_roundthin.dat
    HLinitialFlux = 2736 * 2.2e11 / 360000  # 1.7e9

    # retracted settings
    normTCT5LOUTb1 = HLinitialFlux * 0.5 * (
        9024.0 / 54609869.0 + 3071.0 / 52175081.0
    )  # 0.00011205218641475149 #12091./(63828643+61405975) # 9.7e-5
    normTCT5LOUTb2 = HLinitialFlux * 0.5 * (
        9936.0 / 40392116.0 + 11898.0 / 53157089.0
    )  # 0.0002349078766943835 ### 21822/(47196776+63051589) # 2e-4
    normTCT5INb1 = HLinitialFlux * 0.5 * (
        9712.0 / 54532193.0 + 3366.0 / 52154816.0)  # 0.00012131762826402283
    normTCT5INb2 = HLinitialFlux * 0.5 * (
        9948.0 / 40401333.0 + 12028.0 / 53199970.0
    )  # 0.0002361599262 # 11172./(47203328+63096910) # 1e-4 sum of all tcts over protons lost on primary for h and v separately

    # nominal cases
    normTCT5INb1nom = HLinitialFlux * 0.5 * (
        32557.0 / 52836357.0 + 15813.0 / 50278617.0
    )  #(15813.0/61193703 + 32557.0/63640747) # 7.7e-4

    # fDenom = thispath + 'results_ir1_BH_6500GeV_b1_20MeV_nprim4752000_30.root'     # 6.5TeV Halo B1
    # fNum = thispath + 'results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root' # HL retracted Halo B1 round
    # subfolder = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/HL/compB1HaloRetrRun2/normalised/'
    # lTextNum, lTextDenom = 'HL', '6.5 TeV'
    # tagNum, tagDenom = '_BH_HL_tct5inrdB1_20MeV', '_BH_6500GeV_haloB1_20MeV'
    # normNum, normDenom, yrel = 1., 1.,'/TCT hit'
    # normNum, normDenom, yrel = 1./normTCT5INb1, 1./norm6500GeVB1, "/s"
    # dColor, nColor = kYellow+1, kBlue+2

    # fNum = thispath + "FL_TCT5In_retracted_rdB2_fixgaps/results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim3425000_30.root"
    # fDenom = thispath + 'results_ir1_BH_6500GeV_b2_20MeV_nprim3646000_30.root'     # 6.5TeV Halo B2
    # subfolder = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/HL/compB2HaloRetrRun2/normalised/'
    # lTextNum, lTextDenom = 'HL', '6.5 TeV'
    # tagNum, tagDenom = '_BH_HL_tct5inrdB2_20MeV', '_BH_6500GeV_haloB2_20MeV'
    # normNum, normDenom, yrel = 1./normTCT5INb2, 1./norm6500GeVB2, '/s'
    # #normNum, normDenom, yrel = 1., 1.,'/TCT hit'
    # dColor, nColor = kYellow+2, kBlue+3

    # fDenom = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_30.root'
    # fNum = projectpath + 'HL1.0/FL_HL_TCT5IN_nomCollSett_haloB1/results_hilumi_BH_ir1b1_exp_20MeV_nominalCollSett_nprim3320000_30.root'
    # subfolder = wwwpath + 'TCT/HL/compHLnomRun2B1/'
    # lTextNum, lTextDenom = 'HL nominal', '6.5 TeV'
    # tagNum, tagDenom = '_BH_HL_tct5inrdB1_nomCollSett_20MeV', '_BH_6500GeV_haloB1_20MeV'
    # normNum, normDenom = 1./normTCT5INb1, 1./norm6500GeVB1
    # dColor, nColor = kPink-1, kBlue-4
    # yrel = '/s'

    # # fNum = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5LOUT_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5350000_30.root'
    # # fDenom = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # # subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/compINOUTB1/'
    # fNum = thispath + "results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5350000_30.root"
    # fDenom = thispath + "results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5550000_30.root"
    # subfolder = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/HL/compINOUTB1_retracted/normalised/"
    # lTextNum = 'TCT4 only'
    # lTextDenom = 'TCT5 in'
    # tagDenom, tagNum =  '_BH_HL_tct5inrdB1_20MeV', '_BH_HL_tct5otrdB1_20MeV'
    #yrel,normDenom, normNum = '/s',1./normTCT5INb1, 1./normTCT5LOUTb1
    # yrel,normDenom, normNum = '/TCT hit',1., 1.
    # dColor, nColor = kPink-1, kBlue-1

    # # fNum = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # # fDenom = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5IN_roundthin_B2/results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim6466000_30.root'
    # # subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/compINB1B2/perTCThit/'
    # subfolder = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/HL/compINB1B2_retracted/perTCThit/"
    # fDenom = thispath + "results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5550000_30.root"
    # fNum = thispath + "results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5924500_30.root"
    # lTextDenom = 'TCT5 in, B1'
    # lTextNum = 'TCT5 in, B2'
    # tagNum, tagDenom = '_BH_HL_tct5inrdB2_20MeV', '_BH_HL_tct5inrdB1_20MeV'
    # normNum, normDenom,yrel =  1./normTCT5INb2, 1./normTCT5INb1, "/s"
    # normDenom, normNum,yrel =  1., 1., "/TCT hit"
    # nColor, dColor = kPink, kBlue+2

    # fNum = thispath + "results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5001000_30.root"
    # fDenom = thispath + "results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5924500_30.root"
    # subfolder = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/HL/compINOUTB2_retracted/normalised/"
    # # # fNum = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5LOUT_roundthin_B2/results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5001000_30.root'
    # # subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/compINOUTB2/perTCThit/'
    # lTextNum = 'TCT4 only'
    # lTextDenom = 'TCT5 in'
    # normDenom, normNum, yrel = 1./normTCT5INb2, 1./normTCT5LOUTb2, '/s'
    # # normDenom, normNum, yrel = 1., 1., '/TCT hit'
    # tagNum, tagDenom = '_BH_HL_tct5otrdB2_20MeV', '_BH_HL_tct5inrdB2_20MeV'
    # dColor, nColor = kGreen-2, kMagenta+1

    # fDenom = workpath + 'runs/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # fNum = workpath + 'runs/FL_TCT5IN_roundthin_B2/results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5315000_30.root'
    # subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/compINB1B2/'
    # lTextDenom = 'TCT5 in B1'
    # lTextNum = 'TCT5 in B2'
    # normDenom, normNum = 1./normTCT5INb1, 1./normTCT5INb2
    # tagDenom, tagNum = '_BH_HL_tct5inrdB1_20MeV', '_BH_HL_tct5inrdB2_20MeV'
    # dColor, nColor = kRed-3, kCyan-3

    # fDenom = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5LOUT_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5350000_30.root'
    # fNum = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5LOUT_roundthin_B2/results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5001000_30.root'
    # subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/compOUTB1B2/stableOpRate/'
    # lTextNum = 'TCT5 out B2'
    # lTextDenom = 'TCT5 out B1'
    # normNum, normDenom = 1./normTCT5LOUTb2, 1./normTCT5LOUTb1
    # #    normDenom, normNum = 1.,1.
    # tagNum, tagDenom = '_BH_HL_tct5otrdB2_20MeV', '_BH_HL_tct5otrdB1_20MeV'
    # dColor, nColor = kRed-4, kBlue-3

    # # ------------------------------------------------------------------------
    # 6.5 TeV

    # fNum = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_ntct1324_30.root'
    # fDenom = projectpath + 'valBG4TeV/results_beam_halo_6.5TeV_80cm_IR1B1_20MeV_nprim4702400_66.root'
    # # # old scattering routine
    # # fDenom = workpath + 'runs/4TeV_Halo/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # lTextNum = 'old format'
    # lTextDenom = 'new format'
    # normDenom, normNum, yrel, addon = 1., 1., '/TCT hit', ''
    # tagNum, tagDenom = '_BH_6500GeV_haloB1_20MeV', '_BH_6500GeV_haloB1_20MeV'
    # nColor, dColor = kOrange-3, kPink-5
    # subfolder = wwwpath + 'TCT/6.5TeV/tctimpacts/validationBH/'
    # fNum = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_ntct1324_30.root'
    # fDenom = 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # subfolder = wwwpath + 'TCT/compBHB1_4TeV_vs_6.5TeVB1/'

    # ### ----- 4 TeV vs 6.5 TeV B1
    # subfolder = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/compBHB1_4TeV_vs_6p5TeV/normalised/"
    # fNum = thispath + 'results_ir1_BH_6500GeV_b1_20MeV_nprim4752000_30.root'
    # fDenom = thispath + 'results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # lTextNum = '6.5 TeV'
    # lTextDenom = '4 TeV'
    # normDenom, normNum, yrel = 1./norm4TeVB1newHalo, 1./norm6500GeVB1, '/s'
    # #    normDenom, normNum, yrel = 1., 1., '/TCT hit'
    # tagNum, tagDenom = '_BH_6500GeV_haloB1_20MeV', '_BH_4TeV_B1_20MeV'
    # nColor, dColor = kOrange-3, kPink-5

    # # ### ----- 4 TeV vs 6.5 TeV B2
    # # # fNum = workpath + 'runs/FL_6500GeV_HaloB2_20MeV/results_BH_ir1_6500GeV_b2_20MeV_nprim3646000_30.root'
    # # # fDenom = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
    # # # subfolder = wwwpath + 'TCT/compBHB2_4TeV_vs_6.5TeV/'
    # # # # ## -- fDenom = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'     # -- 4TeV are old fluka sim -- newer exist!
    fDenom = thispath + "results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root"
    fNum = thispath + "results_ir1_BH_6500GeV_b2_20MeV_nprim3646000_30.root"
    subfolder = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/compBHB2_4TeV_vs_6p5TeV/normalised/"
    lTextNum = '6.5 TeV'
    lTextDenom = '4 TeV'
    #    normNum, normDenom, yrel = 1., 1., "/TCT hit"
    normNum, normDenom, yrel = 1. / norm6500GeVB2, 1. / norm4TeVB2newHalo, "/s"
    tagDenom, tagNum = '_BH_4TeV_B2_20MeV', '_BH_6500GeV_haloB2_20MeV'
    nColor, dColor = kOrange - 3, kPink - 4

    # fNum = workpath + 'runs/4TeV_Halo/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # fDenom = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/comp4TeVB1B2/'
    # lTextNum = 'B1'
    # lTextDenom = 'B2'
    # normNum, normDenom = 1./norm4TeVB1, 1./norm4TeVB2
    # tagNum, tagDenom = '_BH_4TeV_B1_20MeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink-3

    #     fDenom = workpath + 'runs/FL_6500GeV_HaloB2_20MeV/results_ir1_6500GeV_b2_20MeV_nprim3646000_30.root'
    #     fNum = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_30.root'
    #     # fDenom = workpath + 'data/6p5TeV/results_ir1_BH_6500GeV_b2_20MeV_nprim3646000_30.root'
    #     # fNum = workpath + 'data/6p5TeV/results_ir1_BH_6500GeV_b1_20MeV_nprim4752000_30.root'
    #     subfolder = wwwpath + 'TCT/6.5TeV/tctimpacts/compB1B2/perTCThit/'
    #     lTextNum = 'B1'
    #     lTextDenom = 'B2'
    # #    normDenom, normNum = 1./norm6500GeVB2, 1./norm6500GeVB1
    #     normDenom, normNum = 1.,1.
    #     tagNum, tagDenom = '_BH_6500GeV_haloB1_20MeV', '_BH_6500GeV_haloB2_20MeV'
    #     nColor, dColor = kOrange+5, kGreen+2
    #     yrel = "/TCT hit"

    # fNum =  '/afs/cern.ch/project/lhc_mib/tct_simulations/FlukaRuns/runs_usrbin/results_hilumi_ir1b1_exp_20MeV_nominalCollSett_nprim4269100_30.root'
    # fDenom = '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/FL_TCT5IN_roundthin/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # subfolder = wwwpath + 'TCT/HL/compB1CrabCFHalo/'
    # lTextNum = 'crabcf'
    # lTextDenom = 'halo'
    # normNum, normDenom, yrel = 1., 1., '/TCT hit'
    # tagDenom, tagNum =  '_BH_HL_tct5inrdB1_20MeV', '_crabcfb1'
    # dColor, nColor = kMagenta-2, kBlue-1

    # # fNum = projectpath + 'HL1.0/FL_HL_TCT5IN_nomCollSett_haloB1/results_hilumi_BH_ir1b1_exp_20MeV_nominalCollSett_nprim3320000_30.root'
    # # fDenom = '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/HL_TCT5INOUT_relSett/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # # subfolder = wwwpath + 'TCT/HL/compNomRetrCollSett/perTCThit/'
    # subfolder = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/HL/compNomRetrCollSett/normalised/"
    # fNum = thispath + "results_hilumi_BH_ir1b1_exp_20MeV_nominalCollSett_nprim3320000_30.root"
    # fDenom = thispath + "results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root"
    # lTextNum = 'nominal'
    # lTextDenom = 'retracted'
    # normDenom, normNum, yrel = 1./normTCT5INb1, 1./normTCT5INb1nom, '/s'
    # #normDenom, normNum, yrel = 1., 1., '/TCT hit'
    # tagDenom,tagNum =  '_BH_HL_tct5inrdB1_20MeV','_BH_HL_tct5inrdB1_nomCollSett_20MeV'
    # dColor, nColor = kMagenta-2, kBlue-2

    # fNum =  '/afs/cern.ch/project/lhc_mib/crabcfb1/runs_usrbin/results_hilumi_ir1b1_exp_20MeV_nominalCollSett_nprim4269100_30.root'
    # fDenom = '/afs/cern.ch/project/lhc_mib/tct_simulations/FlukaRuns/runs_modTAN/results_hilumi_ir1b1_exp_20MeV_nominalCollSett_modTAN_nprim1390500_30.root'
    # subfolder = wwwpath + 'TCT/HL/compCrabsTAN/'
    # lTextNum = 'nom TAXN'
    # lTextDenom = 'mod TAXN'
    # normNum, normDenom, yrel = 1., 1., '/TCT hit'
    # tagDenom, tagNum =  '_crabcfb1_modTAN', '_crabcfb1'
    # dColor, nColor = kMagenta+4, kBlue+3

    # # BG ac and BG Run II reweighted

    # fDenom = thispath + 'results_hilumi_ir1_fort_scaled_afterconditioning_max_nprim1_30.root'
    # fNum = thispath + 'results_pressure2015_ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root'
    # subfolder = wwwpath + 'TCT/HL/compBGRun2HL/'
    # lTextDenom, lTextNum = 'HL BG a.c.', 'Run II BG'
    # normDenom, normNum = 1.,1.
    # tagDenom, tagNum = '_BG_HL_ac_20MeV','_BG_6500GeV_flat_20MeV_bs_reweighted'
    # nColor, dColor = kOrange-1, kMagenta-3
    # yrel = '/s'

    # ------------------------------------------------------------------------

    # # # offmomentum
    # fNum =  '/afs/cern.ch/project/lhc_mib/offmom/FL_4TeVminusB2/results_ir1_offmin500Hz4TeV_settings_from_TWISS_20MeV_b2_nprim3987000_30.root'
    # fDenom = '/afs/cern.ch/project/lhc_mib/offmom/FL_4TeVplusB2/results_ir1_offplus500Hz_4TeV_settings_from_TWISS_20MeV_b2_nprim3980000_30.root'
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/newScatt/comppm500Hz/'
    # lTextNum = '-500 Hz'
    # lTextDenom = '+500 Hz'
    # normNum, normDenom, yrel = 1., 1., '/TCT hit'
    # tagNum, tagDenom =  '_offmin500Hz_4TeV_B2_20MeV', '_offplus500Hz_4TeV_B2_20MeV'
    # dColor, nColor = kMagenta+4, kBlue+3
    # ------------------------------------------------------------------------

    rCol = kPink - 7
    # need one file to generate sDict
    bbgFile = fNum
    print "Opening for sDict generation ...", bbgFile
    tag = tagNum
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    tBBG = TFile.Open(bbgFile).Get(treeName)
    sDict = generate_sDict(tag, norm, tBBG, yrel)

    nprimN = norm
    nprimD = float(fDenom.split('nprim')[-1].split('_')[0])

    print nprimN, nprimD, "nprimN, nprimD", ".."
    if not os.path.exists(subfolder):
        print 'making dir', subfolder
        os.mkdir(subfolder)

    # only for label
    Beam, beam = '', ''
    if fNum.count('B1') or fNum.count('b1'): Beam, beam = 'B1', 'b1'
    elif fNum.count('B2') or fNum.count('b2'): Beam, beam = 'B2', 'b2'
    if fNum.count("BG"): Beam, beam = '', ''
    if not fDenom.count(beam): Beam, beam = '', ''

    rfNum = TFile.Open(fNum)
    rfDenom = TFile.Open(fDenom)
    print 'opening as numerator', fNum
    print 'opening as denominator', fDenom

    msize = 0.05
    for skey in sDict.keys():

        if skey.count('XY'): continue
        if skey.count('Orig'): continue
        if skey.startswith('Prof'): continue
        if skey.count('Sel'): continue

        # testing
        # if not skey.count('EkinMuon') : continue

        goLeft = 0
        if skey.count("Phi"): goLeft = 1

        cv = TCanvas('cv' + skey, 'cv' + skey, 100, 120, 600, 600)
        x1, y1, x2, y2 = 0.65, 0.75, 0.9, 0.9  # right corner
        if goLeft: x1, y1, x2, y2 = 0.2, 0.75, 0.4, 0.9  # left corner
        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)

        p1 = TPad('p1' + skey, 'p1' + skey, 0.01, 0.35, 0.99, 0.99)

        XurMin, XurMax = -1, -1
        YurMin, YurMax = -1, -1

        if subfolder.count("normalised"):
            scalefactorNorm = 1e3
        else:
            scalefactorNorm = 1.

        if subfolder.count('_4TeV_vs_6p5TeV'):
            if skey.count("Phi"):
                YurMin, YurMax = 1.e-2 * scalefactorNorm, scalefactorNorm * 1.e2
                if skey.count("EnMu"):
                    YurMin, YurMax = 1.e-1 * scalefactorNorm, scalefactorNorm * 1.e2
                if skey.count("NMu"):
                    YurMin, YurMax = 1.e-6 * scalefactorNorm, scalefactorNorm

        if subfolder.count(
                'HaloRetrRun2') and not subfolder.count("perTCThit"):
            if skey.count("EkinA"):
                YurMin, YurMax = 1.1, 5e5
            elif skey.count("PhiEnAl"):
                YurMin, YurMax = 1.e4, 5e6

        dOptNum, dOptDenom = 'h', 'hsame'
        isLogy = 0
        if skey.count('Ekin'):
            p1.SetLogx(1)
            p1.SetLogy(1)
            XurMin, XurMax = 0.02, 8e3
            isLogy = 1

        if skey.count('En'):
            p1.SetLogy(1)
            isLogy = 1

        rbf = 8
        if skey.startswith('Rad'):
            p1.SetLogy(1)
            isLogy = 1
            XurMin, XurMax = 0.0, 1190.
            #YurMin, YurMax = scalefactorNorm*2e-12,scalefactorNorm*9e-2
            if skey.count("reweighted"):
                YurMin, YurMax = 2, 1e9
                if skey.count("Mu"):
                    YurMin, YurMax = 2e-2, 8e5
                    rbf = 10

        if skey.count('Phi'):
            XurMin, XurMax = -3.14, 3.01
            if skey.endswith("reweighted"):
                YurMin, YurMax = 5e6, 9e8
                if skey.count("EnMu"):
                    YurMin, YurMax = 2e3, 9e6

            if skey.count('PhiN'):
                if not subfolder.count("beamsizeRatio"):
                    p1.SetLogy(1)
                if skey.endswith("reweighted"):
                    YurMin, YurMax = 1e5, 9e9
                    YurMin, YurMax = -1, -1
        if skey.count('Zcoor'):
            p1.SetLogy(1)
            p1.SetGridx(1)
            p1.SetGridy(1)

        p1.Draw()
        p1.SetBottomMargin(0.00)

        p2 = TPad('p2' + skey, 'p2' + skey, 0.01, 0.01, 0.99, .35)
        if skey.count('Ekin'):
            p2.SetLogx(1)

        p2.Draw()
        p2.SetTopMargin(0.00)
        p2.SetBottomMargin(0.29)

        p1.cd()
        hnameNum = skey
        hnameDenom = hnameNum.replace(tagNum, tagDenom)
        print 'plotting ratio of num', hnameNum, 'and denom', hnameDenom

        xtitle, ytitle = sDict[skey][9], sDict[skey][10]
        if ytitle.count('/s') and not yrel.count('/s'):
            ytitle.replace('/s', yrel)

        histNum = rfNum.Get(hnameNum)
        histDenom = rfDenom.Get(hnameDenom)

        if not histNum:
            print "WARNING : Didn't find ", hnameNum
            continue

        if not histDenom:
            print "WARNING : Didn't find ", hnameDenom
            continue

        if histNum.GetName().endswith(
                "reweighted") or histNum.GetName().endswith("_flat"):
            histNum = histNum.ProjectionX()

        if histDenom.GetName().endswith(
                "reweighted") or histDenom.GetName().endswith("_flat"):
            histDenom = histDenom.ProjectionX()

        print "histNum.GetNbinsX(), histDenom.GetNbinsX()", histNum.GetNbinsX(
        ), histDenom.GetNbinsX()

        if hnameNum.count('Rad'):
            #pass
            histNum = doRebin(histNum, rbf)
            histDenom = doRebin(histDenom, rbf)

        print "histNum.GetNbinsX(), histDenom.GetNbinsX()", histNum.GetNbinsX(
        ), histDenom.GetNbinsX()

        histNum.GetXaxis().SetTitle(xtitle)
        histNum.GetYaxis().SetTitle(ytitle)
        histDenom.GetXaxis().SetTitle(xtitle)
        histDenom.GetYaxis().SetTitle(ytitle)

        histNum.SetLineWidth(3)
        histNum.SetLineStyle(2)
        histDenom.SetLineColor(dColor)
        histNum.SetLineColor(nColor)
        histDenom.SetLineColor(dColor)
        histNum.SetMarkerColor(nColor)
        histDenom.SetMarkerColor(dColor)
        histNum.SetMarkerStyle(21)
        histDenom.SetMarkerStyle(20)
        histDenom.SetMarkerSize(msize)
        histNum.SetMarkerSize(msize)
        print 'normalised factors', normNum, normDenom
        histNum.Scale(1. / normNum)
        histDenom.Scale(1. / normDenom)
        integralNum = histNum.Integral()  #0
        integralDenom = histDenom.Integral()  #0
        # for b in range(histNum.GetNbinsX()):
        #     integralNum+=histNum.GetBinContent(b+1)*histNum.GetBinWidth(b+1)
        #     integralDenom+=histDenom.GetBinContent(b+1)*histDenom.GetBinWidth(b+1)
        ratioIntegrals = 0.
        if integralDenom:
            ratioIntegrals = integralNum / integralDenom
            print "here: integralNum, integralDenom", integralNum, integralDenom, integralNum / integralDenom

        ls = 0.4
        histNum.GetXaxis().SetLabelSize(ls)
        histDenom.GetXaxis().SetLabelSize(ls)

        scaleYAxis = 1.3
        if isLogy:
            ymax = histNum.GetMaximum()
            ymin = histDenom.GetMinimum()

            # print "-"*59, 'ymin', ymin
            # if not ymin: ymin = 1.e-2
            # histNum.GetYaxis().SetRangeUser(ymin/20.,ymax*scaleYAxis)

            if skey.count('Ekin'):
                histNum.SetMaximum(5 * ymax)

        if XurMin != -1:
            histNum.GetXaxis().SetRangeUser(XurMin, XurMax)

        if YurMin != -1:
            histNum.GetYaxis().SetRangeUser(YurMin, YurMax)

        print "XurMin,XurMax", XurMin, XurMax
        print "YurMin,YurMax", YurMin, YurMax
        # if skey.count('PhiEnMuPlus'):
        #     histNum.GetYaxis().SetRangeUser(20,2e4)
        if dOptNum.count("same"):
            histDenom.Draw(dOptDenom)
            histNum.Draw(dOptNum)
        else:
            histNum.Draw(dOptNum)
            histDenom.Draw(dOptDenom)

        mlegend.AddEntry(histNum, lTextNum, "l")
        mlegend.AddEntry(histDenom, lTextDenom, "l")
        mlegend.Draw()
        doBig = 0
        if subfolder.count("beamsizeRatio") and skey.count(
                "Z") and not skey.startswith("Orig"):
            doBig = 1
        lab = mylabel(42)

        xpos, ypos = 0.356, 0.955
        if doBig:
            fontsize = 0.09
            xpos, ypos = 0.18, 0.01955
            lab.SetTextSize(fontsize)

        lab.DrawLatex(xpos, ypos, sDict[skey][6].replace("z", "s"))
        lab = mylabel(62)
        lab.SetTextSize(0.055)
        lab.DrawLatex(x1 + 0.02, y1 - 0.07, Beam)

        hnameRatio = 'ratio' + hnameNum
        hRatio = histNum.Clone(hnameRatio)

        hRatio.Divide(histNum, histDenom, 1, 1)
        hRatio.SetLineStyle(1)
        hRatio.SetLineWidth(2)
        hRatio.SetLineColor(rCol)
        hRatio.SetMarkerColor(rCol)
        hRatio.SetMarkerStyle(22)
        hRatio.SetMarkerSize(msize)
        hRatioInt = 0
        hWidth = 0
        # for b in range(histNum.GetNbinsX()):
        #     hRatioInt+=hRatio.GetBinContent(b+1)*hRatio.GetBinWidth(b+1)
        #     hWidth+=hRatio.GetBinWidth(b+1)
        # print "hRatioInt/hWidth",hRatioInt/hWidth

        l = TLine()
        l.SetLineWidth(1)
        l.SetLineColor(kGray)  #kSpring
        if XurMin == -1:
            XurMin = hRatio.GetBinLowEdge(1)
            XurMax = hRatio.GetBinLowEdge(hRatio.GetNbinsX() + 1)

        p2.cd()

        drawOpt = 'pe'
        if hnameNum.count('Rad') or hRatio.GetMaximum() > 200:
            # hRatio.GetYaxis().SetRangeUser(0.1,2.6)
            pass

        hRatio.GetXaxis().SetLabelSize(0.105)
        hRatio.GetYaxis().SetLabelSize(0.08)
        hRatio.GetYaxis().SetTitleOffset(0.8)
        hRatio.GetYaxis().SetTitleSize(0.08)
        hRatio.GetXaxis().SetTitleSize(0.1)
        hRatio.Draw()

        ratiorounded = str(round(ratioIntegrals, 2))
        print ' ratio of integrals', ratiorounded
        hRatio.GetYaxis().SetTitle('ratio ' + lTextNum + '/' + lTextDenom +
                                   " ")

        if hRatio.GetMinimum() < 1.:
            l.DrawLine(XurMin, 1, XurMax, 1)

        lab = mylabel(42)
        lab.SetTextSize(0.1)
        lab.SetTextColor(rCol)
        if not subfolder.count("beamsizeRatio") and not subfolder.count(
                "compBGflat"):
            lab.DrawLatex(0.195, 0.88, ratiorounded)

        pname = subfolder + hnameRatio.split('_')[0] + '.pdf'

        print pname
        cv.SaveAs(pname)
示例#8
0
def cv87():

    f1 = thispath + 'results_pressure2011_beam_gas_3.5TeV_IR1_to_arc_20MeV_100M_nprim7660649_66.root'
    f2 = thispath + 'results_pressure2012_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
    f3 = thispath + 'results_pressure2015_ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root'

    filenames = [f1, f2, f3]

    lTexts = ['3.5 TeV', '4 TeV', '6.5 TeV']
    tags = [
        '_BG_3p5TeV_20MeV_reweighted', '_BG_4TeV_20MeV_bs_reweighted',
        '_BG_6500GeV_flat_20MeV_bs_reweighted'
    ]
    cols = [kAzure + 3, kPink - 3, kYellow - 2]
    mars = [33, 20, 22]
    dOpt = ['h', 'hsame', 'hsame']

    # ------------------------------------------------------------------------
    debug = 0
    # need one file to generate sDict
    bbgFile = f1
    print "Opening for sDict generation ...", bbgFile
    tag = tags[0]
    yrel = '/s'
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    tBBG = TFile.Open(bbgFile).Get(treeName)
    sDict = generate_sDict(tag, norm, tBBG, yrel)
    try:
        if not os.path.exists(subfolder):
            print 'making dir', subfolder
            os.mkdir(subfolder)
    except:
        pass

    rfs = [TFile.Open(f_i) for f_i in filenames]

    msize = 0.05
    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
        elif not skey.count('OrigZM'):
            continue

        cv = TCanvas('cv' + skey, 'cv' + skey, 10, 10, 1200, 900)

        x1, y1, x2, y2 = 0.65, 0.73, 0.95, 0.93  # right corner

        if 0:  # skey.count("PhiEnAll") or skey.count("PhiEnPhot") or skey.count("PhiNAllE") or skey.count("PhiNP") or skey.count("EnPro"):
            x1, y1, x2, y2 = 0.2, 0.75, 0.44, 0.93  # left corner

        mlegend = TLegend(x1, y1, x2, y2)
        mlegend.SetFillColor(0)
        mlegend.SetFillStyle(0)
        mlegend.SetLineColor(0)
        mlegend.SetTextSize(0.04)
        mlegend.SetShadowColor(0)
        mlegend.SetBorderSize(0)

        XurMin, XurMax = -1, -1
        YurMin, YurMax = -1, -1

        hname = skey  # contains tag
        hnames = [hname.replace(tag, tg) for tg in tags]
        if debug: print 'plotting ', hnames

        xtitle, ytitle = sDict[skey][9], sDict[skey][10]

        # per rf file 1 histogram
        hists = []
        Ymax, Ymin = [], []
        for i, rf in enumerate(rfs):

            if debug: print "trying to get", hnames[i], "from ", rf
            hists += [rf.Get(hnames[i])]

            if not hists[-1]:
                print "WARNING : Didn't find ", hnames[i]
                continue

            print "Have in hists", hists
        for i in range(len(hists)):

            isLogx, isLogy = 0, 0

            try:
                hname = hnames[i]

                if hname.count('Ekin') or hname.count(
                        "En") or hname.startswith("Rad") or hname.startswith(
                            "Phi"):
                    isLogy = 1
                    if hname.count("Ekin"):
                        isLogx = 1

                hists[i].SetLineWidth(2)
                hists[i].SetLineStyle(1)
                hists[i].SetLineColor(cols[i])
                hists[i].SetMarkerStyle(mars[i])
                hists[i].SetMarkerSize(1.03)
                hists[i].SetMarkerColor(cols[i])
                #hists[i].GetXaxis().SetLabelSize(0.2))
                # To scale get min max value from all histograms first before drawing

            except AttributeError:
                print "WARNING : histogram", hnames[
                    i], "doesn't exist in", filenames[i]
                break

        # skip all histograms when one is missing
        if not hists[0]: continue

        print len(hists), hists
        for i in range(len(hists)):

            hist_reweighted = hists[i].ProjectionX()

            #     XurMin, XurMax = -3.14, 3.01
            #     YurMin, YurMax = 1e-1*max(Ymax), max(Ymax)*1e4
            #     if hnames[i].count("En"):
            #         YurMin, YurMax = 1e-5*max(Ymax), max(Ymax)*5e4

            # elif hnames[i].count("Ekin"):
            #     YurMin, YurMax = 1e-2,8e10

            # elif hnames[i].count("Rad"):
            #     XurMin, XurMax = 0.,600.
            #     YurMin, YurMax = 1e-3,1e10
            #     if  hnames[i].count("All"):
            #         YurMin, YurMax = 1e-4,1e12

            legendunit = "/m"

            nbins = hist_reweighted.GetNbinsX()
            hist_reweighted.GetYaxis().SetRangeUser(YurMin, YurMax)
            rbf = 4
            hist_reweighted = cv81.doNormalBinw(hist_reweighted, nbins)
            hist_reweighted.Rebin(rbf)
            hist_reweighted.Scale(1. / rbf)
            hist_reweighted.GetYaxis().SetTitle(ytitle.replace("cm", "m"))
            hist_reweighted.Draw(dOpt[i])
            doLogx, doLogy = 0, 1
            xtitle = "s [m]"
            hist_reweighted.GetXaxis().SetTitle(xtitle)
            cv.SetLogy(doLogy)
            mlegend.AddEntry(hists[i], lTexts[i], "lp")

            YurMin, YurMax = 1e-2, 1e7
            if XurMin != -1:
                hist_reweighted.GetXaxis().SetRangeUser(XurMin, XurMax)

            if YurMin != -1:
                hist_reweighted.GetYaxis().SetRangeUser(YurMin, YurMax)
            print "Setting y axes", YurMin, YurMax, dOpt[i]

        mlegend.Draw()

        lab = mylabel(42)
        lab.SetTextSize(0.06)
        lab.DrawLatex(0.39, 0.855, sDict[skey][6])
        nlab = mylabel(42)
        nlab.DrawLatex(0.45, 0.955, "")

        lab = mylabel(42)
        lab.SetTextSize(0.1)
        #        lab.SetTextColor(col)

        #

        pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/cv87_allenergies_' + hnames[
            i].split('_')[0] + '.pdf'
        pname = hnames[i].split('_')[0] + '.pdf'
        print pname
        cv.SaveAs(pname)
示例#9
0
def fillHistos(bbgFile, tag, doComp):
    
    # bbgFile is the rootfile with the TTree, use this to fill histograms
    # write out a rootfile with histograms

    print "Opening...", bbgFile
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])

    rf = TFile.Open(bbgFile)
    tBBG = rf.Get(treeName)

    yrel = '/primary'

    if doComp:
        # for comparisons plots, also edit rel
        sDict = sDict_HL_hybridComp
        rel = 'hybridComp_'
    else:
        sDict = generate_sDict(tag, norm, tBBG, yrel)
        rel = ''

    # histograms which should be written one to rootfile
    rHists = []

    # rootfile with results
    rfoutname = resultFile(bbgFile,rel)

    print 'writing ','.'*20, rfoutname
    rfile = TFile.Open(rfoutname, "RECREATE")

    hists = []
    cnt = 0
    for i,skey in enumerate(sDict.keys()):

       if skey in rHists:
          continue

       cnt += 1
       print "Getting ...", skey, '... #', cnt

       mt     = sDict[skey][5]
       hists += [getHistogram(sDict, skey, mt)]          
       rHists += [skey]

       norm   = sDict[skey][1]
       if norm != 1.: print 'scaling by ', 1./norm
       hists[-1].Scale(1./norm)

       hcolor = sDict[skey][7]
       hists[-1].SetLineColor(hcolor)
       hists[-1].SetLineWidth(3)

       if not i: 
           if   type(hists[-1]) == TH1F: hists[-1].Draw("HIST")
           elif type(hists[-1]) == TH2F: hists[-1].Draw("COLZ")
           elif type(hists[-1]) == TProfile: 
               hists[-1].SetMarkerColor(hcolor)
               hists[-1].Draw("P")
       else:
           if   type(hists[-1]) == TH1F: hists[-1].Draw("HISTSAME")

       hists[-1].Write()

    rfile.Close()
    print 'wrote ','.'*20, rfoutname
示例#10
0
def cv80():
    print pData
    pFile, xtitle,lText = pData[0]
    datafile = '/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67'
    bbgFile = datafile + ".root"
    print "Opening", bbgFile
    tag = '_BG_6500GeV_flat_20MeV_bs' #!! MMMeV
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    rfile = TFile.Open(bbgFile, "READ")
    tBBG = rfile.Get("particle")
    yrel = ''
    print tBBG
    sDict = generate_sDict(tag, norm, tBBG, yrel)

    # -- small version of fillTTree
    beamintensity = 2.29e14 ## https://acc-stats.web.cern.ch/acc-stats/#lhc/fill-details 4536, ring 1.
    Trev  = 1./11245
    kT = 1.38e-23*300

    # rootfile with results
    rfoutname = resultFileBG(bbgFile,'')
    
    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("Rad"): 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

        var = ''
        energyweight = ''
        cuts = [' energy_ke > 0.02 ']
        cf = 0.01
        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)]
            var = '(TMath::Sqrt(x*x + y*y))'
            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)]
            var = 'z_interact*0.01'
            xtitle = "s [m]"

        elif hname.startswith("Phi"):
            binwidth = (xmax-xmin)/xnbins
            xaxis = [xmin+i*binwidth for i in range(xnbins)]
            var = '(TMath::ATan2(y,x))'
            if skey.count("En"): energyweight = "energy_ke * "

        if not particleTypes[0].count('ll'):
            pcuts = [ 'particle ==' + p for p in particleTypes  ]
            pcut  = '||'.join(pcuts)
            cuts += ['('+ pcut + ')']

        # -- y axis, weigths
        ynbins, ymin, ymax = 2*262, 22.6, 546.6 # MUST TAKE FULL RANGE
        twoDhist = TH2F(skey, skey, xnbins-1, array('d', xaxis), ynbins, ymin, ymax)

        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.SetLineColor(kTeal-2)

        # -- create histogram with same axis for pint 
        if cnt == 1:
            hist_pint = twoDhist.ProjectionY("pint")
            data = cv79.getdata5c(pFile)
            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)
            pint_incomingbeam = {}

            # incoming beam is left side of B1
            for i,spos in enumerate(data['s']):
                if float(spos)<0:
                    z = -float(spos)
                    pint_incomingbeam[z] = pint_tot[i]
                    zbin = hist_pint.FindBin(z)
                    hist_pint.SetBinContent(zbin, pint_incomingbeam[z])
                    #print z, zbin, pint_incomingbeam[z]

        # --
        # compute re-weights for each bin
        for w in range(1,ynbins+1):
            scale = beamintensity * hist_pint.GetBinContent(w)
            for v in range(1,xnbins+1):
                m = twoDhist_flat.GetBinContent(v,w)  
                #print "Weight", scale * m, "m", m, "scale",scale, "x,y", v,w
                twoDhist_reweighted.SetBinContent(v,w,scale * m)

        hists_flat += [twoDhist_flat]          
        hists_reweighted += [twoDhist_reweighted]
        rHists += [skey]
        
        # writing two d hists
        hists_flat[-1].Write()
        hists_reweighted[-1].Write()

    # for debugging
    hist_pint.Write()
        
    rfOUTile.Close()
    print 'wrote ','.'*20, rfoutname
示例#11
0
def cv86():

    bbgFile = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/hilumi_ir1_hybrid_b1_exp_20MeV_nprim4050000_30.root"
    tag = '_BH_HL_tct5inrdB1_20MeV'
    cname = "checkB1tct5in"

    # bbgFile = '/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/hilumi_ir1_hybrid_b2_exp_20MeV_nprim5924500_30.root'
    # #bbgFile = '/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/hilumi_ir1_hybrid_b2_exp_20MeV_nprim3425000_30.root'
    # #bbgFile = projectpath + 'HL1.0/FL_TCT5In_retracted_rdB2_fixgaps/hilumi_ir1_hybrid_b2_exp_20MeV_nprim3425000_30.root'
    # tag  = '_BH_HL_tct5inrdB2_20MeV'
    # cname = "checkB2tct5in"

    doTCT4only = 0
    if doTCT4only:

        cname = "checkB1tct4only"
        bbgFile = thispath + 'hilumi_ir1_hybrid_b1_exp_20MeV_nprim5350000_30.root'
        tag = '_BH_HL_tct5otrdB1_20MeV'

        # cname = "checkB2tct4only"
        # bbgFile = thispath + 'hilumi_ir1_hybrid_b2_exp_20MeV_nprim5001000_30.root'
        # tag =  '_BH_HL_tct5otrdB2_20MeV'

    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
    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"): 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("PhiNAll_"): continue
        if not skey.startswith("EkinAll_"): continue
        doEkinHist = 1
        sk += [skey]

        print "histogram ", len(sk) + 1, "." * 33, skey

    for j, skey in enumerate(sk):
        print "Now on #", j, ">" * 5, skey

        # -- 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 = ''
        enCut = ' 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 * "

        if not particleTypes[0].count('ll'):
            pcuts = ['particle ==' + p for p in particleTypes]
            pcut = '||'.join(pcuts)
            cuts += ['(' + pcut + ')']

        # -- y axis, weigths
        nbins, xmin, xmax = 250, 0., 250e2
        #hist = TH1F(skey, skey, nbins, xmin, xmax)
        hname4 = skey + "tct4"
        hist4 = TH1F(hname4, hname4, xnbins, array('d', xaxis))
        hname5 = skey + "tct5"
        hist5 = TH1F(hname5, hname5, xnbins, array('d', xaxis))

        hnameControl = "histControl"
        histControl = hist5.Clone(hnameControl)
        tct5Cut = "(z_interact > 211.79e2 && z_interact <= 212.79e2) ||  (z_interact <= 214.79e2 && z_interact > 213.79e2)"
        tct4Cut = "(z_interact > 132.6e2 && z_interact <= 133.6e2) ||  (z_interact > 130.97e2 && z_interact <= 131.97e2)"
        tct4a = 130.97e2
        tct4b = tct4a + 1e2
        tct4c = 132.6e2
        tct4d = tct4c + 1e2
        tct5a = 211.79e2
        tct5b = tct5a + 1e2
        tct5c = 213.79e2
        tct5d = tct5c + 1e2

        tct4Cut = "((z_interact > " + str(tct4a) + " && z_interact <= " + str(
            tct4b) + " ) || (z_interact > " + str(
                tct4c) + " && z_interact <= " + str(tct4d) + "))"
        tct5Cut = "((z_interact > " + str(tct5a) + " && z_interact <= " + str(
            tct5b) + " ) || (z_interact > " + str(
                tct5c) + " && z_interact <= " + str(tct5d) + "))"

        # B2
        if cname.count("B2"):
            n4 = (6678 + 83.)
            n5 = (14914 + 304.)
        else:

            # B1
            n4, n5 = 2460., 10600.

        sumn4n5 = n4 + n5

        nprim4 = n4 / sumn4n5 * nprim
        nprim5 = n5 / sumn4n5 * nprim
        if doTCT4only: nprim5 = nprim
        print "nprim4", nprim4
        print "nprim5", nprim5

        cuts = [enCut, tct4Cut]
        cuts = "weight * " + energyweight + "(" + " && ".join(cuts) + ") "
        print "INFO: applying", cuts, "to", var, "in", hname4
        mt.Project(hname4, var, cuts)
        if doEkinHist: hist4 = cv84.doEkin(hist4, hist4.GetNbinsX())
        else: hist4 = cv84.doPhi(hist4, hist4.GetNbinsX())
        entries4 = hist4.Integral()  #/nprim4

        print "entries 4 ", hist4.Integral(), nprim4
        cuts = [enCut, tct5Cut]
        cuts = "weight * " + energyweight + "(" + " && ".join(cuts) + ") "
        print "INFO: applying", cuts, "to", var, "in", hname5
        mt.Project(hname5, var, cuts)
        if doEkinHist: hist5 = cv84.doEkin(hist5, hist5.GetNbinsX())
        else: hist5 = cv84.doPhi(hist5, hist5.GetNbinsX())
        entries5 = hist5.Integral() / nprim5

        if doTCT4only:
            print "INFO: applying", encut, "to", var, "in", hname5
            print "overwriting previous histogram!!!!!"
            mt.Project(hname5, var, encut)
            if doEkinHist: hist5 = cv84.doEkin(hist5, hist5.GetNbinsX())
            else: hist5 = cv84.doPhi(hist5, hist5.GetNbinsX())
            entries5 = hist5.Integral()  #/nprim5

        else:
            print "summe", n4 * entries4 + n5 * entries5
            print "summe", sumn4n5
            print "ratio", (n4 * entries4 + n5 * entries5) / sumn4n5

        print "GetEntries 4 ", hist4.GetEntries()
        print "GetEntries 5 ", hist5.GetEntries()

        #hist4.Scale(1./nprim)
        #hist5.Scale(1./nprim)
        print "integral 4 ", hist4.Integral()
        print "integral 5 ", hist5.Integral()

        inth4, inth5 = 0, 0
        for i in range(1, hist4.GetNbinsX() + 1):
            inth4 += hist4.GetBinContent(i)
            inth5 += hist5.GetBinContent(i)
        print "inth4", inth4
        print "inth5", inth5
        print "inth4+5", inth4 + inth5

        print "INFO: applying", cuts, "to", var, "in", hnameControl
        mt.Project(hnameControl, var, encut)
        if doEkinHist:
            histControl = cv84.doEkin(histControl, histControl.GetNbinsX())
        else:
            histControl = cv84.doPhi(histControl, histControl.GetNbinsX())
        entriesCont = histControl.Integral()

        print "entries controlhist ", histControl.Integral()
        print "Is the sum of tct4 and 5 the same as in control hist? If tct4only case this number doesnt make sense.", \
            hist4.Integral(),hist5.Integral(), hist4.Integral()+hist5.Integral()

        cv = TCanvas(skey + 'cv', skey + 'cv', 1400, 900)
        cv.SetLogx(0)
        cv.SetLogy(0)
        # right corner
        x1, y1, x2, y2 = 0.6, 0.75, 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)
        #XurMin, XurMax = 120.e2, 218e2
        #xtitle,ytitle = "z [cm]", "entries"
        xtitle, ytitle = "E [GeV]", "dN/dlogE/TCT hit"
        xtitle, ytitle = "#phi [rad]", "#phi/rad//TCT hit"
        hist4.GetXaxis().SetTitle(xtitle)
        hist4.GetYaxis().SetTitle(ytitle)
        #hist5.GetXaxis().SetRangeUser(XurMin, XurMax)

        hist4.SetLineColor(kTeal + 3)
        hist5.SetLineColor(kRed + 3)
        hist4.GetYaxis().SetTitle("entries")
        hist4.Draw("hist")
        hist5.Draw("histsame")

        mlegend.AddEntry(hist4,
                         "origin in TCT4, entries4:" + str(round(entries4, 4)),
                         "l")
        mlegend.AddEntry(hist5,
                         "origin in TCT5, entries5:" + str(round(entries5, 4)),
                         "l")
        mlegend.Draw()

        lab = mylabel(42)
        #lab.DrawLatex(0.2, 0.9, cuts)
        #lab.DrawLatex(0.2, 0.8, var)

        YurMin, YurMax = 0., 12000
        l = TLine()
        l.SetLineStyle(1)
        l.SetLineColor(kRed)
        if 0:
            s = tct4a
            l.DrawLine(s, YurMin, s, YurMax)
            s = tct4b
            l.DrawLine(s, YurMin, s, YurMax)
            s = tct4c
            l.DrawLine(s, YurMin, s, YurMax)
            s = tct4d
            l.DrawLine(s, YurMin, s, YurMax)

            s = tct5a
            l.DrawLine(s, YurMin, s, YurMax)
            s = tct5b
            l.DrawLine(s, YurMin, s, YurMax)
            s = tct5c
            l.DrawLine(s, YurMin, s, YurMax)
            s = tct5d
            l.DrawLine(s, YurMin, s, YurMax)

        pname = projectpath + "HL1.0/checkB2.png"
        pname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/HL/" + cname + ".png"
        pname = "/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/HL/" + cname + ".png"
        cv.SaveAs(pname)
示例#12
0
def cv68():
    # new halo (new scatt)
    norm4TeVB1newHalo = 1380 *1.4e11/360000 * 0.5*(622.0/60948098 + 930.0/64935501) 
    # IR5: (866+92 + 170.0+456 )/(60948098 + 64935501) = 1.26e-5,>>> (866+92)/60948098 + (170.0+456)/64935501 = 9.64e-06

    norm4TeVB2newHalo = 1380 * 1.4e11/360000 * (1179.0/59198135 +967/56887051.)/2.  
    # IR5: (1893.0 + 135)/(59198135 +56887051) = 1.75e-5, >>> 1893.0/59198135 +135/56887051. = 3.435e-05

    norm6500GeVB1 = 2748 * 1.2e11/360000 *0.5*(739./62515929 +(312+273.)/62692523) # 2.1e-5
    norm6500GeVB2 = 2748 * 1.2e11/360000 *0.5*(779./50890652+773./63119778.) # 2.76e-5 take the average of H an V runs!

    # python /afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/AnalysisScripts/py/collsummary.py -f 6.5TeV_vHaloB2_h5/coll_summary_6.5TeV_vHaloB2_h5.dat -c TCT*R5
    # IR5 B1: h:( 53754939.0 protons on IR7 primaries, 346.0 protons on TCT*L5.B1), v(52838656.0 on primaries IR7,  408.0 protons on TCTL5)
    # .5*( 346.0/53754939.0 + 408.0/52838656.0 ) = 7.0791187088930279e-06
    # IR5 B2: h:( 43718962.0 IR7,  302.0 protons ), v(53000835.0, 106.0 protons. )
    # 0.5 * (302.0/43718962.0 + 106.0/53000835.0) = 4.4538612500709768e-06

    run1iniFlux = 368 * 1.2e11/360000. # from Roderiks NIM paper: 2010: 368 up to 2011 1380
    norm3500GeVB1 = 1.02813e-5 # from http://bbgen.web.cern.ch/bbgen/bruce/fluka_beam-halo_3.5TeV/flukaIR15.html
    norm3500GeVB2 = 2.25625e-5 # from http://bbgen.web.cern.ch/bbgen/bruce/fluka_beam-halo_3.5TeV/flukaIR15.html

    # fNum   = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_b2_nprim7825000_66.root'
    # fDenom = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/compB2oldB2new/'
    # lTextNum = 'B2 old'
    # lTextDenom = 'B2 new'
    # tagNum, tagDenom = 'BH_4TeV_B2', 'BH_4TeV_B2_20MeV'
    # nColor, dColor = kCyan+1, kTeal

    # #fNum   = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # #fDenom = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'
    # fNum = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim7945000_66.root'
    # fDenom   = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # normDenom, normNum = 1./norm4TeVB1oldHalo, 1./norm4TeVB2oldHalo
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/oldScatt/compB1B2oldScatt/'
    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
    # fDenom = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # #    normDenom, normNum = 1./norm4TeVB1newHalo, 1./norm4TeVB2newHalo
    # normDenom, normNum = 1., 1.
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/newScatt/compB1B2/perTCThit/'
    # lTextNum = 'B2'
    # lTextDenom = 'B1'
    # tagDenom, tagNum = '_BH_4TeV_B1_20MeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink-6
    # yrel = '/TCT hit'
    # # yrel = '/s'

    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
    # fDenom   = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim7945000_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/compOldNewScattB2/perTCThit/'
    # lTextNum = 'new'
    # lTextDenom = 'old'
    # normDenom, normNum = 1./norm4TeVB2oldHalo, 1./norm4TeVB2newHalo
    # normDenom, normNum = 1., 1.
    # tagDenom, tagNum = '_BH_4TeV_B2_20MeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink+8
    # yrel = '/s'
    # yrel = '/TCT hit'

    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_4TeV_settings_from_TWISS_20GeV_b2_nprim6914000_30.root'
    # fDenom = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2_20GeV/results_ir1_4TeV_settings_from_TWISS_20GeV_b2_nprim90520000_30.root'
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/newScatt/compB2tail/'
    # lTextNum = 'all energies'
    # lTextDenom = '20 GeV tail'
    # normDenom, normNum = 1., 1.
    # tagDenom, tagNum = '_BH_4TeV_B2_20GeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink+2
    # yrel = '/TCT hit'

    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # fDenom = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1_20GeV/results_ir1_4TeV_settings_from_TWISS_20GeV_b1_nprim125170000_30.root'
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/newScatt/compB1tail/'
    # lTextNum = 'all energies'
    # lTextDenom = '20 GeV tail'
    # normDenom, normNum = 1., 1.
    # tagDenom, tagNum = '_BH_4TeV_B1_20GeV', '_BH_4TeV_B1_20MeV'
    # nColor, dColor = kOrange-3, kPink-2
    # yrel = '/TCT hit'

    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # fDenom   = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/tctimpacts/compOldNewScattB1/perTCThit/'
    # lTextNum = 'new'
    # lTextDenom = 'old'
    # normDenom, normNum = 1./norm4TeVB1oldHalo, 1./norm4TeVB1newHalo
    # normDenom, normNum = 1., 1.
    # tagDenom, tagNum = '_BH_4TeV_B1_20MeV', '_BH_4TeV_B1_20MeV'
    # nColor, dColor = kOrange-3, kPink-2
    # yrel = '/s'
    # yrel = '/TCT hit'

    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
    # fDenom = workpath + 'runs/3.5TeV/results_beam-halo_3.5TeV-R1_D1_20MeV_b2_nprim2344800_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/compB2_3p5vs4TeV/'
    # lTextNum, lTextDenom = '4 TeV w/ x-ing', '3.5 TeV w/o x-ing'
    # #normNum, normDenom = 1./norm4TeVB2, 1./(run1iniFlux * norm3500GeVB2)
    # normNum, normDenom = 1., 1.
    # tagDenom, tagNum = '_BH_3p5TeV_B2_20MeV', '_BH_4TeV_B2_20MeV'
    # subfolder = wwwpath + 'TCT/4TeV/compB2_3p5vs4TeV/' 
    # nColor, dColor = kOrange+1, kBlue-3
    # yrel = '/TCT hit'

    # subfolder = wwwpath + 'TCT/4TeV/compB2_3p5vs4TeV/'
    # normDenom, normNum = 1.,1.     
    # yrel = '/TCT hit'

    # # - comparison BH 3.5 vs 4 TeV
    # # #-- OLD SIM    # fNum = workpath + 'data/4TeV/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # fNum = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # fDenom =  projectpath + 'bbgen/3.5TeV/results_beam-halo_3.5TeV-L1_20MeV_b1_nprim1731200_66.root'
    # lTextNum, lTextDenom = '4 TeV', '3.5 TeV'
    # #normNum, normDenom, yrel, addon = 1./norm4TeVB1, 1./(run1iniFlux * norm3500GeVB1), '/s', 'normalised/'
    # normNum, normDenom, yrel, addon = 1.,1., '/TCT hit', ''
    # tagDenom, tagNum = '_BH_3p5TeV_B1_20MeV', '_BH_4TeV_B1_20MeV'
    # nColor, dColor = kOrange+3, kMagenta-3
    # subfolder = wwwpath + 'TCT/4TeV/compBHB1_3p5vs4TeV/' + addon 
    

    # # comparison BG 3.5 vs 4 TeV 
    # fNum = projectpath + '4TeVBGnoBS/results_beam-gas_4TeV-IR1_to_arc_20MeV_cutoff_100M_nprim7283044_66.root'
    # fDenom = projectpath + '4TeVBGnoBS/results_beam_gas_3.5TeV_IR1_to_arc_20MeV_100M_nprim7660649_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/compBG_3p5_vs_4TeV/'
    # lTextDenom, lTextNum = '3.5 TeV w/o x-ing', '4 TeV w/ x-ing'
    # normDenom, normNum = 1.,1.
    # tagDenom, tagNum = '_BG_3p5TeV_20MeV', '_BG_4TeV_20MeV'
    # nColor, dColor = kOrange-1, kRed-2
    # yrel = '/inel.BG int.'

    # ------------------------------------------------------------------------
    # # beamgas 4 TeV
    # fNum = projectpath + '4TeVBGnoBS/results_beam-gas_4TeV-IR1_to_arc_20MeV_cutoff_100M_nprim7283044_66.root'
    # #fNum = projectpath + 'bbgen/4TeV/beamgas/results_ir1_BG_bs_4TeV_settings_from_TWISS_20MeV_b1_nprim5925000_67.root'
    # #fNum = projectpath + 'beamisze/4TeV_beamsize/runBG_UVcorr/results_ir1_BG_4TeV_settings_from_TWISS_20MeV_b1_nprim4414500_67.root'
    # fDenom = '/afs/cern.ch/project/lhc_mib/valBG4TeV/results_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
    # subfolder = wwwpath + 'TCT/4TeV/beamgas/beamsizeRatio/'
    # lTextNum, lTextDenom = 'pointlike', 'w/ beamsize'
    # normDenom, normNum = 1.,1.
    # tagDenom, tagNum = '_BG_4TeV_20MeV_bs', '_BG_4TeV_20MeV'
    # nColor, dColor = kOrange-1, kRed-3
    # yrel = '/inel.BG int.'

    # # beamgas 4 TeV vs 6.5 TeV
    # fNum = projectpath + 'beamgas/6500GeV_beamsize/runs400/results_ir1_BG_bs_6500GeV_b1_20MeV_nprim2716000_67.root'
    # fDenom = projectpath + 'bbgen/4TeV/beamgas/withBeamSize/results_ir1_BG_4TeV_settings_from_TWISS_20MeV_b1_nprim5925000_67.root'
    # subfolder = wwwpath + 'TCT/compBG_4TeV_vs_6.5TeV/'
    # lTextNum, lTextDenom = '6.5 TeV bs', '4 TeV bs'
    # normDenom, normNum = 1.,1.
    # tagDenom, tagNum = '_BG_4TeV_20MeV_bs', '_BG_6500GeV_flat_20MeV_bs'
    # nColor, dColor = kOrange-1, kMagenta-3
    # yrel = '/inel.BG int.'

 #    # # beamgas 6.5 TeV, 20 MeV vs 6.5 TeV, 20 GeV
 # fNum = projectpath + 'bbgen/6.5TeV/runs400_20MeV/results_ir1_BG_bs_6500GeV_b1_20MeV_nprim2716000_67.root'
 #    fDenom = projectpath + 'beamgas/6500GeV_beamsize/runs10k_20GeV/results_ir1_BG_bs_6500GeV_b1_20GeV_nprim181730000_67.root'
 #    subfolder = wwwpath + 'TCT/compBG_6.5TeV/'
 #    lTextNum, lTextDenom = '20 MeV', '20 GeV'
 #    normDenom, normNum = 1.,1.
 #    tagDenom, tagNum = '_BG_6500GeV_flat_20GeV_bs', '_BG_6500GeV_flat_20MeV_bs'
 #    nColor, dColor = kBlue-1, kMagenta-3
 #    yrel = '/inel.BG int.'

    # # # beamgas 4 TeV 20 MeV vs 20 GeV
    # fNum = projectpath + 'bbgen/4TeV/beamgas/withBeamSize/results_ir1_BG_4TeV_settings_from_TWISS_20MeV_b1_nprim5925000_67.root'
    # fDenom = projectpath + 'BG/FL_4TeV_BG_20GeV_10k/results_ir1_BG_bs_4TeV_settings_from_TWISS_20GeV_b1_nprim89940000_67.root'
    # subfolder = wwwpath + 'TCT/4TeV/beamgas/fluka/bs/compBGtail/'
    # lTextNum, lTextDenom = '20 MeV', '20 GeV'
    # normDenom, normNum = 1.,1.
    # tagDenom, tagNum = '_BG_4TeV_20GeV_bs', '_BG_4TeV_20MeV_bs'
    # nColor, dColor = kOrange-1, kMagenta-3
    # yrel = '/inel.BG int.'

    # ------------------------------------------------------------------------
    # ---- HL -
    # awk '{ sum += $4; } END { print sum; }' H5_HL_TCT5LOUT_relaxColl_hHaloB1_roundthin/coll_summary_H5_HL_TCT5LOUT_relaxColl_hHaloB1_roundthin.dat
    # awk '{ sum += $4; } END { print sum; }' H5_HL_TCT5LOUT_relaxColl_vHaloB1_roundthin/coll_summary_H5_HL_TCT5LOUT_relaxColl_vHaloB1_roundthin.dat
    # awk '{ sum += $4; } END { print sum; }' H5_HL_TCT5LOUT_relaxColl_hHaloB2_roundthin/coll_summary_H5_HL_TCT5LOUT_relaxColl_hHaloB2_roundthin.dat 
    # awk '{ sum += $4; } END { print sum; }' H5_HL_TCT5LOUT_relaxColl_vHaloB2_roundthin/coll_summary_H5_HL_TCT5LOUT_relaxColl_vHaloB2_roundthin.dat 
    HLinitialFlux = 2736*2.2e11/360000 # 1.7e9

    # retracted settings
    normTCT5LOUTb1 = HLinitialFlux * 0.5*(9024.0/54609869.0 + 3071.0/52175081.0)##12091./(63828643+61405975) # 9.7e-5
    normTCT5LOUTb2 = HLinitialFlux * 0.5*(9936.0/40392116.0 + 11898.0/53157089.0)#21822/(47196776+63051589) # 2e-4
    normTCT5INb1 = HLinitialFlux * 0.5*(9712.0/54532193.0 + 3366.0/52154816.0)
    normTCT5INb2 = HLinitialFlux * 0.5 * (9948.0/40401333.0 + 6064.0/26614313.0)## 11172./(47203328+63096910) # 1e-4 sum of all tcts over protons lost on primary for h and v separately

    # nominal cases
    normTCT5INb1nom = HLinitialFlux * 0.5*(32557.0/52836357.0 + 15813.0/50278617.0)#(15813.0/61193703 + 32557.0/63640747) # 7.7e-4

    # fDenom = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_30.root'
    # fNum = projectpath + 'HL1.0/FL_HL_TCT5IN_nomCollSett_haloB1/results_hilumi_BH_ir1b1_exp_20MeV_nominalCollSett_nprim3320000_30.root'
    # subfolder = wwwpath + 'TCT/HL/compHLnomRun2B1/'
    # lTextNum, lTextDenom = 'HL nominal', '6.5 TeV'
    # tagNum, tagDenom = '_BH_HL_tct5inrdB1_nomCollSett_20MeV', '_BH_6500GeV_haloB1_20MeV'
    # normNum, normDenom = 1./normTCT5INb1, 1./norm6500GeVB1
    # dColor, nColor = kPink-1, kBlue-4
    # yrel = '/s'
 
    # fNum = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5LOUT_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5350000_30.root'
    # fDenom = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/compINOUTB1/perTCThit/'
    # lTextNum = 'TCT4 only'
    # lTextDenom = 'TCT5 in'
    # tagDenom, tagNum =  '_BH_HL_tct5inrdB1_20MeV', '_BH_HL_tct5otrdB1_20MeV'
    # yrel,normDenom, normNum = '/s',1./normTCT5INb1, 1./normTCT5LOUTb1
    # yrel,normDenom, normNum = '/TCT hit',1., 1.
    # dColor, nColor = kPink-1, kBlue-1
    

    # fNum = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # fDenom = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5IN_roundthin_B2/results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5315000_30.root'
    # subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/compINB1B2/perTCThit/'
    # lTextNum = 'TCT5 in, B1'
    # lTextDenom = 'TCT5 in, B2'
    # tagDenom, tagNum = '_BH_HL_tct5inrdB2_20MeV', '_BH_HL_tct5inrdB1_20MeV'
    # #normDenom, normNum,yrel =  1./normTCT5INb2, 1./normTCT5INb1, "/s"
    # normDenom, normNum,yrel =  1., 1., "/TCT hit"
    # dColor, nColor = kPink, kBlue+2


    # fNum = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5LOUT_roundthin_B2/results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5001000_30.root'
    # fDenom = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5IN_roundthin_B2/results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5315000_30.root'
    # subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/compINOUTB2/perTCThit/'
    # lTextNum = 'TCT4 only'
    # lTextDenom = 'TCT5 in'
    # normDenom, normNum, yrel = 1./normTCT5INb2, 1./normTCT5LOUTb2, '/s'
    # normDenom, normNum, yrel = 1., 1., '/TCT hit'
    # tagNum, tagDenom = '_BH_HL_tct5otrdB2_20MeV', '_BH_HL_tct5inrdB2_20MeV'
    # dColor, nColor = kGreen-2, kMagenta+1


    # fDenom = workpath + 'runs/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # fNum = workpath + 'runs/FL_TCT5IN_roundthin_B2/results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5315000_30.root'
    # subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/compINB1B2/'
    # lTextDenom = 'TCT5 in B1'
    # lTextNum = 'TCT5 in B2'
    # normDenom, normNum = 1./normTCT5INb1, 1./normTCT5INb2
    # tagDenom, tagNum = '_BH_HL_tct5inrdB1_20MeV', '_BH_HL_tct5inrdB2_20MeV'
    # dColor, nColor = kRed-3, kCyan-3

    # fDenom = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5LOUT_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5350000_30.root'
    # fNum = workpath + 'runs/HL_TCT5INOUT_relSett/FL_TCT5LOUT_roundthin_B2/results_hilumi_ir1_hybrid_b2_exp_20MeV_nprim5001000_30.root'
    # subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/compOUTB1B2/stableOpRate/'
    # lTextNum = 'TCT5 out B2'
    # lTextDenom = 'TCT5 out B1'
    # normNum, normDenom = 1./normTCT5LOUTb2, 1./normTCT5LOUTb1
    # #    normDenom, normNum = 1.,1.
    # tagNum, tagDenom = '_BH_HL_tct5otrdB2_20MeV', '_BH_HL_tct5otrdB1_20MeV'
    # dColor, nColor = kRed-4, kBlue-3

    # # ------------------------------------------------------------------------
    # 6.5 TeV

    # fNum = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_ntct1324_30.root'
    # fDenom = projectpath + 'valBG4TeV/results_beam_halo_6.5TeV_80cm_IR1B1_20MeV_nprim4702400_66.root'
    # # # old scattering routine
    # # fDenom = workpath + 'runs/4TeV_Halo/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # lTextNum = 'old format'
    # lTextDenom = 'new format'
    # normDenom, normNum, yrel, addon = 1., 1., '/TCT hit', ''
    # tagNum, tagDenom = '_BH_6500GeV_haloB1_20MeV', '_BH_6500GeV_haloB1_20MeV'
    # nColor, dColor = kOrange-3, kPink-5
    # subfolder = wwwpath + 'TCT/6.5TeV/tctimpacts/validationBH/' 

    # fNum = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_ntct1324_30.root'
    # fDenom = 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # # # old scattering routine
    # # fDenom = workpath + 'runs/4TeV_Halo/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # lTextNum = '6.5 TeV'
    # lTextDenom = '4 TeV'
    # #    normDenom, normNum, yrel, addon = 1./norm4TeVB1, 1./norm6500GeVB1, '/s', ''
    # normDenom, normNum, yrel, addon = 1., 1., '/TCT hit', 'perTCThit/'
    # tagNum, tagDenom = '_BH_6500GeV_haloB1_20MeV', '_BH_4TeV_B1_20MeV'
    # nColor, dColor = kOrange-3, kPink-5
    # subfolder = wwwpath + 'TCT/compBHB1_4TeV_vs_6.5TeVB1/' 


    # fNum = workpath + 'runs/FL_6500GeV_HaloB2_20MeV/results_ir1_6500GeV_b2_20MeV_nprim3646000_30.root'
    # fDenom = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
    # # ## -- fDenom = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'     # -- 4TeV are old fluka sim -- newer exist!
    # subfolder = wwwpath + 'TCT/compBHB2_4TeV_vs_6.5TeV/'
    # lTextNum = '6.5 TeV'
    # lTextDenom = '4 TeV'
    # normNum, normDenom = 1., 1.
    # tagNum, tagDenom = '_BH_6500GeV_haloB2_20MeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink-4
    # yrel = '/TCT hit'

    # fNum = workpath + 'runs/4TeV_Halo/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # fDenom = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/comp4TeVB1B2/'
    # lTextNum = 'B1'
    # lTextDenom = 'B2'
    # normNum, normDenom = 1./norm4TeVB1, 1./norm4TeVB2
    # tagNum, tagDenom = '_BH_4TeV_B1_20MeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink-3

#     fDenom = workpath + 'runs/FL_6500GeV_HaloB2_20MeV/results_ir1_6500GeV_b2_20MeV_nprim3646000_30.root'
#     fNum = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_30.root'
#     # fDenom = workpath + 'data/6p5TeV/results_ir1_BH_6500GeV_b2_20MeV_nprim3646000_30.root'
#     # fNum = workpath + 'data/6p5TeV/results_ir1_BH_6500GeV_b1_20MeV_nprim4752000_30.root'
#     subfolder = wwwpath + 'TCT/6.5TeV/tctimpacts/compB1B2/perTCThit/'
#     lTextNum = 'B1'
#     lTextDenom = 'B2'
# #    normDenom, normNum = 1./norm6500GeVB2, 1./norm6500GeVB1
#     normDenom, normNum = 1.,1.
#     tagNum, tagDenom = '_BH_6500GeV_haloB1_20MeV', '_BH_6500GeV_haloB2_20MeV'
#     nColor, dColor = kOrange+5, kGreen+2
#     yrel = "/TCT hit"

    # fNum =  '/afs/cern.ch/project/lhc_mib/tct_simulations/FlukaRuns/runs_usrbin/results_hilumi_ir1b1_exp_20MeV_nominalCollSett_nprim4269100_30.root'
    # fDenom = '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/FL_TCT5IN_roundthin/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # subfolder = wwwpath + 'TCT/HL/compB1CrabCFHalo/'
    # lTextNum = 'crabcf'
    # lTextDenom = 'halo'
    # normNum, normDenom, yrel = 1., 1., '/TCT hit'
    # tagDenom, tagNum =  '_BH_HL_tct5inrdB1_20MeV', '_crabcfb1'
    # dColor, nColor = kMagenta-2, kBlue-1

    # fNum = projectpath + 'HL1.0/FL_HL_TCT5IN_nomCollSett_haloB1/results_hilumi_BH_ir1b1_exp_20MeV_nominalCollSett_nprim3320000_30.root'
    # fDenom = '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/HL_TCT5INOUT_relSett/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # subfolder = wwwpath + 'TCT/HL/compNomRetrCollSett/perTCThit/'
    # lTextNum = 'nominal'
    # lTextDenom = 'retracted'
    # normDenom, normNum, yrel = 1./normTCT5INb1, 1./normTCT5INb1nom, '/s'
    # normDenom, normNum, yrel = 1., 1., '/TCT hit'
    # tagDenom,tagNum =  '_BH_HL_tct5inrdB1_20MeV','_BH_HL_tct5inrdB1_nomCollSett_20MeV'
    # dColor, nColor = kMagenta-2, kBlue-2

    # fNum =  '/afs/cern.ch/project/lhc_mib/crabcfb1/runs_usrbin/results_hilumi_ir1b1_exp_20MeV_nominalCollSett_nprim4269100_30.root'
    # fDenom = '/afs/cern.ch/project/lhc_mib/tct_simulations/FlukaRuns/runs_modTAN/results_hilumi_ir1b1_exp_20MeV_nominalCollSett_modTAN_nprim1390500_30.root'
    # subfolder = wwwpath + 'TCT/HL/compCrabsTAN/'
    # lTextNum = 'nom TAXN'
    # lTextDenom = 'mod TAXN'
    # normNum, normDenom, yrel = 1., 1., '/TCT hit'
    # tagDenom, tagNum =  '_crabcfb1_modTAN', '_crabcfb1'
    # dColor, nColor = kMagenta+4, kBlue+3

    # ------------------------------------------------------------------------

    # all at 4 TeV
    f1 = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    f2 = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
    f3 = '/afs/cern.ch/project/lhc_mib/valBG4TeV/results_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
    f3 = projectpath + 'bbgen/4TeV/beamgas/results_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
    f4 = '/afs/cern.ch/project/lhc_mib/offmom/FL_4TeVplusB2/results_ir1_offplus500Hz_4TeV_settings_from_TWISS_20MeV_b2_nprim3980000_30.root'
    f5 = '/afs/cern.ch/project/lhc_mib/offmom/FL_4TeVminusB2/results_ir1_offmin500Hz4TeV_settings_from_TWISS_20MeV_b2_nprim3987000_30.root'

    # local
    f1 = thispath + 'results_pressure2012_ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
    f2 = thispath + 'results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    f3 = thispath + 'results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
    f4 = thispath + 'results_ir1_offplus500Hz_4TeV_settings_from_TWISS_20MeV_b2_nprim3980000_30.root'
    f5 = thispath + 'results_ir1_offmin500Hz4TeV_settings_from_TWISS_20MeV_b2_nprim3987000_30.root'

    filenames = [f2,f3,f1,f4,f5]

    subfolder = wwwpath + 'TCT/4TeV/compAllBKG/'
    lTexts = [ 'betatron halo B1', 'betatron halo B2','beam-gas','dp/p<0 (+500 Hz)', 'dp/p>0 (-500 Hz)']
    tags   = ['_BH_4TeV_B1_20MeV', '_BH_4TeV_B2_20MeV', '_BG_4TeV_20MeV_bs' , '_offplus500Hz_4TeV_B2_20MeV', '_offmin500Hz_4TeV_B2_20MeV']
    cols   = [kBlue, kRed, kOrange-3,kMagenta+4, kTeal+4]
    mars   = [ 20, 24, 33, 22, 23 ]
    dOpt   = [ 'h', 'hsame', 'hsame', 'hsame', 'hsame']
    # ------------------------------------------------------------------------

    # need one file to generate sDict
    bbgFile = f1
    print "Opening for sDict generation ...", bbgFile
    tag = tags[0]
    yrel = '/interaction' 
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    tBBG = TFile.Open(bbgFile).Get(treeName)
    sDict = generate_sDict(tag, norm, tBBG, yrel)

    if not os.path.exists(subfolder):
        print 'making dir',  subfolder
        os.mkdir(subfolder)

    rfs = [  TFile.Open(f_i) for f_i in filenames ]

    msize = 0.05
    for skey in sDict.keys():

        if skey.count('XY'): continue
        if skey.count('Orig'): continue
        if skey.startswith('Prof'): continue
        if skey.count('Sel'): continue
        if skey.count('Z'): continue

        cv = TCanvas( 'cv'+skey, 'cv'+skey,  10, 10, 1200, 900 )     

        x1, y1, x2, y2 = 0.65,0.73,0.95,0.93 # right corner        

        if skey.count("PhiEnAll") or skey.count("PhiEnPhot") or skey.count("PhiNAllE") or skey.count("PhiNP") or skey.count("EnPro"):
            x1, y1, x2, y2 = 0.2,0.75,0.44,0.93 # left corner

        mlegend = TLegend( x1, y1, x2, y2)
        mlegend.SetFillColor(0)
        mlegend.SetFillStyle(0)
        mlegend.SetLineColor(0)
        mlegend.SetTextSize(0.04)
        mlegend.SetShadowColor(0)
        mlegend.SetBorderSize(0)

        XurMin, XurMax = -1, -1
        YurMin, YurMax = -1, -1

        hname = skey # contains tag
        hnames = [ hname.replace(tag, tg) for tg in tags ] 
        print 'plotting ', hnames

        xtitle, ytitle = sDict[skey][9], sDict[skey][10]

        # per rf file 1 histogram

        hists = []
        Ymax, Ymin = [], []
        for i,rf  in enumerate(rfs):
            print "trying to get", hnames[i], "from ", rf
            hists += [ rf.Get(hnames[i]) ]

            if not hists[-1]:
                print "WARNING : Didn't find ", hnames[i]
                continue
        

        print "Have in hists", hists
        for i in range(len(hists)):

            isLogx, isLogy = 0, 0

            try:
                hname  =  hnames[i]

                if hname.count('Ekin') or hname.count("En") or hname.startswith("Rad") or hname.startswith("Phi"):
                    isLogy = 1
                    if hname.count("Ekin"): 
                        isLogx = 1

                hists[i].GetXaxis().SetTitle(xtitle)
                hists[i].GetYaxis().SetTitle(ytitle)

                hists[i].SetLineWidth(2)
                hists[i].SetLineStyle(1)
                hists[i].SetLineColor(cols[i])
                hists[i].SetMarkerStyle(mars[i])
                hists[i].SetMarkerSize(1.03)
                hists[i].SetMarkerColor(cols[i])
                #hists[i].GetXaxis().SetLabelSize(0.2))
                # To scale get min max value from all histograms first before drawing

                if isLogy:
                    Ymax += [ hists[i].GetMaximum() ]
                    Ymin += [ hists[i].GetBinContent(10) ]
                print Ymin, " for", hname

            except AttributeError:
                print "WARNING : histogram", hnames[i], "doesn't exist in", filenames[i]
                break

        # skip all histograms when one is missing        
        if not hists[0]: continue
       
        cv.cd()
        if isLogx:  cv.SetLogx()
        if isLogy:  cv.SetLogy()

        for i in range(len(hists)):
            hists[i].Draw(dOpt[i])
            mlegend.AddEntry(hists[i], lTexts[i], "lp")

        mlegend.Draw()

        lab = mylabel(42)
        lab.DrawLatex(0.356, 0.955, sDict[skey][6])
        lab = mylabel(62)
        lab.SetTextSize(0.055)
        lab.DrawLatex(.8,y1-0.07,'')

        lab = mylabel(42)
        lab.SetTextSize(0.1)
#        lab.SetTextColor(col)


        if hnames[i].count('Ekin'):
            YurMin, YurMax = 0.0001, 5*max(Ymax)
            if hnames[i].count('EkinProt'):
                YurMin, YurMax = 1e-6, 30*max(Ymax)
        if hnames[i].count("Rad"):
            XurMin, XurMax = 0.00001, 600.
            YurMin, YurMax = 1e-9, 10*max(Ymax)

        if hnames[i].count("Phi"):
            XurMin, XurMax = -3.14, 3.01
            YurMin, YurMax = 0.5*min(Ymin), 4*max(Ymax)
            if hnames[i].count("All"):
                YurMin, YurMax = 0.1*min(Ymin), 10*max(Ymax)
            elif hnames[i].count("EnPro"):
                YurMin, YurMax = 0.1, 10*max(Ymax)
            elif hnames[i].count("EnMuE"):
                YurMin, YurMax = 1e-3, 10*max(Ymax)


        print "Setting y axes", YurMin, YurMax
        # set the axes
        if XurMin != -1:
            hists[0].GetXaxis().SetRangeUser(XurMin,XurMax)

        if YurMin != -1:
            hists[0].GetYaxis().SetRangeUser(YurMin,YurMax)



        gPad.RedrawAxis()

        pname = subfolder+hnames[i].split('_')[0]+'.pdf'

        print pname
        cv.SaveAs(pname)
示例#13
0
def plotSpectra(bbgFile, tag, doComp):


    print "Using ...", bbgFile
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    tBBG = TFile.Open(bbgFile).Get(treeName)
    yrel = '/TCT hit'
    rel  = ''
    if doComp: rel = 'hybridComp_'

    rfname = fillTTree.resultFile(bbgFile,rel)
    print "Want to open ", rfname

    if rfname.count('B1') or rfname.count('b1'): Beam, beam = 'B1', 'b1'
    elif rfname.count('B2') or rfname.count('b2'): Beam, beam = 'B2','b2'
    else: Beam, beam = '', ''

    if rfname.count('20MeV'): EnCutOff = '20MeV'
    elif rfname.count('20GeV'): EnCutOff = '20GeV'
    else: print 'no energycutoff?!'

    debug = 1

    if rfname.count("BH") and not rfname.count('4TeV') and not rfname.count('3p5TeV') and not rfname.count('6500GeV'): 
        hDict = hDict_HL_BH
        subfolder= 'TCT/HL/nominalSettings/2015/beamhalo/'

        if debug: print "Using HL BH format", '.'*10

    elif rfname.count("BGac"): 
        hDict = hDict_HL_BGac
        subfolder= 'TCT/HL/nominalSettings/beamgas/'
        if debug: print "Using HL BH format", '.'*10
        yrel = '/inel. BG int.'

    elif rfname.count("comp"): 
        hDict = hDict_HL_comp
        subfolder= 'TCT/HL/nominalSettings/comp/'
        if debug: print "Using HL comp format", '.'*10

    elif rfname.count('BH_4TeV_settings_from_TWISS') or rfname.count("500Hz") or rfname.count("beam-halo_3.5TeV"): 
        hDict = hDict_BH_4TeV
        subfolder= 'TCT/4TeV/ttimpacts/oldScatt/'+Beam+'/' + EnCutOff + '/'
        subfolder= 'TCT/4TeV/tctimpacts/newScatt/'+Beam+'/' + EnCutOff + '/'
        #subfolder= 'TCT/4TeV/tctimpacts/newScatt/offmin500Hz/'+Beam+'/' + EnCutOff + '/'
        #subfolder= 'TCT/3p5TeV/' + beam + '/'
        if debug: print "Using 4 TeV BH format", '.'*10


    elif rfname.count('off') and rfname.count('6500'):
        hDict = hDict_BH_4TeV
        subfolder= 'TCT/6.5TeV/tctimpacts/offplus500Hz/'+ Beam + '/'+EnCutOff + '/'
        if debug: print "Using 4 TeV BH dict", '.'*10

    elif rfname.count('BG_bs_4TeV') or rfname.count('beam-gas_4TeV') or rfname.count('beam_gas_3.5TeV_IR1_to_arc_20MeV'): 
        hDict = hDict_BG_4TeV
        if rfname.count('beam_gas_3.5TeV_IR1_to_arc_20MeV'):
            subfolder= 'TCT/3p5TeV/beamgas/'
        elif rfname.count('beam-gas_4TeV'): 
            subfolder= 'TCT/4TeV/beamgas/fluka/RoderiksBG4TeV/'
        elif rfname.count('BG_bs_4TeV'):
            subfolder= 'TCT/4TeV/beamgas/fluka/bs/'+ EnCutOff + '/'
        yrel = '/inel.BG int.'
    
        if debug: print "Using 4 TeV BG dict", '.'*10

    elif rfname.count('BG_bs_6500GeV'):
        hDict = hDict_BG_4TeV
        subfolder= 'TCT/6.5TeV/beamgas/fluka/bs/' + EnCutOff + '/'
        if debug: print "Using 6.5 TeV BG format", '.'*10
        yrel = '/inel.BG int.'

        if debug: print "Using 4 TeV format", '.'*10

    elif rfname.count('hilumi') and not rfname.count('Comp') and not rfname.count('crab'):# and not rfname.count('HL-LHC'):
        hDict = hDict_HL_BH_hybrid
        if tag.count('nom'): 
            subfolder= 'TCT/HL/nominalColl/2015/halo/'
        else:
            if tag.count('tct5ot'): subfolder = 'TCT/HL/relaxedColl/newScatt/fluka/'+beam+'/tct5otrd/'
            elif tag.count('tct5in'): subfolder= 'TCT/HL/relaxedColl/newScatt/fluka/'+beam+'/tct5inrd/repeat/'
            else: 
                print "define where to put the plots?"
                sys.exit()

    elif rfname.count('hybrid') and rfname.count('Comp'): 
        hDict = hDict_HLhybrid_comp
        subfolder = 'TCT/HL/relaxedColl/newScatt/fluka/comp/'

    elif rfname.count('BH_6500GeV'): 
        hDict = hDict_BH_6p5TeV
        subfolder = 'TCT/6.5TeV/tctimpacts/'+beam+'/'

    elif rfname.count('80cm'): 
        hDict = hDict_BH_6p5TeV
        subfolder = 'TCT/6.5TeV/tctimpacts/'+beam+'/oldFormat/'

    elif rfname.count('crab'): 
        subfolder= 'TCT/HL/nominalColl/2015/crabcf/v3/tct5inrd/nomTAN/'
        if rfname.count('modTAN'): 
            subfolder= 'TCT/HL/nominalColl/2015/crabcf/v3/tct5inrd/modTAN/'
        hDict = hDict_HL_crabs_hybrid
        if debug: print "Using  format", '.'*10

    else:
        print "no dictionary defined"
        sys.exit()

    print "-"*11,"using subfolder", subfolder

    if not os.path.exists(wwwpath + subfolder):
        print 'making dir', wwwpath + subfolder
        os.mkdir(wwwpath + subfolder)
    else: "Writing plot to ", wwwpath + subfolder

   # ---------------------------------------------------------------------------------
    if doComp:
        # for comparisons plots, also edit rel
        sDict = sDict_HL_hybridComp
    else:
        sDict = generate_sDict(tag, norm, tBBG, yrel)
        print "using standard dictionary"

   # ---------------------------------------------------------------------------------
    print 'Opening ','.'*20, rfname
    rfile = TFile.Open(rfname)

    if rfname.count('comp') or rfname.count('Comp'):
        tag = ''
    for hkey in hDict.keys():
      
        try:
            pname = wwwpath + subfolder + hkey

            #testing
            if not hkey.count("XYNM"): continue


            print "Plotting ...", hkey
            
            hists = []
            cv = TCanvas( 'cv'+hkey, 'cv'+hkey, 1200, 900)

            gStyle.SetPalette(1)
            cv.SetRightMargin(0.15)
            #cv.SetLeftMargin(-0.1)

            hList = hDict[hkey][0] 
            x1, y1, x2, y2 = hDict[hkey][1],hDict[hkey][2],hDict[hkey][3],hDict[hkey][4]
            doLogx, doLogy = hDict[hkey][5], hDict[hkey][6]
            XurMin, XurMax = hDict[hkey][7],hDict[hkey][8]
            YurMin, YurMax = hDict[hkey][9],hDict[hkey][10]
            ZurMin, ZurMax = hDict[hkey][15],hDict[hkey][16]
            doFill = hDict[hkey][11]
            lText  = hDict[hkey][12] 
            lx, ly = hDict[hkey][13],hDict[hkey][14]

            mlegend = TLegend(x1-0.07, y1, x2, y2)
            mlegend.SetFillColor(0)
            mlegend.SetFillStyle(0)
            mlegend.SetLineColor(0)
            mlegend.SetTextSize(0.035)
            mlegend.SetShadowColor(0)
            mlegend.SetBorderSize(0)

            for i,hname in enumerate(hList):
                 hname += tag
                 hists += [rfile.Get(hname)]

                 if not hists[-1]:
                     print "WARNING: histogram", hname," not found","!"*10
                     continue

                 print "INFO: ", hists[-1].GetName(), ' has ', hists[-1].GetEntries(), ' entries.'

                 hcolor = sDict[hname][7]
                 hists[-1].SetLineColor(hcolor)
                 hists[-1].SetLineWidth(2)
                 # if doFill:  hists[-1].SetFillColor(hcolor)

                 norm   = sDict[hname][1]
                 if norm != 1.: print 'had been normalised by ', norm
                 #hists[-1].Scale(1./norm)
                 leg = "l"

                 xtitle = sDict[hname][9].replace("z", "s")
                 ytitle = sDict[hname][10]
                 ztitle = ''
                 if hkey.count("XYN"): ztitle = "particles/cm^{2}" + yrel
                 
                 if not i: 
                     if   type(hists[-1]) == TH1F: hists[-1].Draw("HIST")
                     elif type(hists[-1]) == TH2F: hists[-1].Draw("COLZ")
                     elif type(hists[-1]) == TProfile: 
                         hists[-1].SetMarkerColor(hcolor)
                         hists[-1].Draw("P")
                         leg = "lp"
                 else:
                     if   type(hists[-1]) == TH1F: hists[-1].Draw("HISTSAME")

                 prettyName = sDict[hname][6]
                 mlegend.AddEntry(hists[-1],prettyName, leg)

            # ....................................
            if not hists[-1] or not hists[0]:
                continue

            if XurMin != -1:
                hists[0].GetXaxis().SetRangeUser(XurMin, XurMax)

            if YurMin != -1:
                hists[0].GetYaxis().SetRangeUser(YurMin, YurMax)

            if ZurMin != -1 and type(hists[0]) == TH2F: 
                hists[0].GetZaxis().SetRangeUser(ZurMin, ZurMax)
                hists[0].GetZaxis().SetTitleOffset(0.05)
                hists[0].GetZaxis().SetTitle(ztitle)

            hists[0].GetYaxis().SetTitleSize(0.04)
            hists[0].GetYaxis().SetLabelSize(0.035)
            hists[0].GetXaxis().SetTitleSize(0.04)
            hists[0].GetXaxis().SetLabelSize(0.035)
            if type(hists[0]) == TH2F: 
                hists[0].GetZaxis().SetLabelSize(0.035)
                hists[0].GetZaxis().SetTitle(ztitle)

            hists[0].GetXaxis().SetTitle(xtitle)
            hists[0].GetYaxis().SetTitle(ytitle)
        
            mlegend.Draw()
            lab = mylabel(62)
            lab.DrawLatex(lx,ly,lText)
            #lab.DrawLatex(0.74,ly,Beam)

            gPad.RedrawAxis()
            if type(hists[0]) == TH2F: 
                gPad.SetLogz(doLogx)
            else:
                cv.SetGridx(0)
                cv.SetGridy(0)
                cv.SetLogx(doLogx)
                cv.SetLogy(doLogy)

            print('Saving file as' + pname ) 
            cv.Print(pname + '.pdf')
            #cv.Print(pname + '.png')
        except KeyError:
            continue
示例#14
0
def cv81():

    do4TeV = 0  #
    do6p5 = 1  #

    if do4TeV:
        year = "2012"
        energy = "4 TeV"
        pressFile = '/afs/cern.ch/work/r/rkwee/HL-LHC/beam-gas-sixtrack/pressure_profiles_2012/LSS1_B1_Fill2736_Final.csv'
        pressFile = '/Users/rkwee/Documents/RHUL/work/data/4TeV/LSS1_B1_Fill2736_Final.csv'

        bbgFile = '/afs/cern.ch/project/lhc_mib/valBG4TeV/ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
        bbgFile = thispath + 'ir1_BG_bs_4TeV_20MeV_b1_nprim5925000_67.root'
        beamintensity = 2e14
        tag = '_BG_4TeV_20MeV_bs'
        bgcl = kPink - 3
        subfolder = wwwpath + 'TCT/4TeV/beamgas/fluka/reweighted/'
    elif do6p5:
        year = "2015"
        energy = "6.5 TeV"
        bbgFile = '/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root'
        pressFile = "/Users/rkwee/Downloads/Density_Fill4536_2041b_26158.8832-500_B1_withECLOUD.txt"
        beamintensity = 2.29e14  ## https://acc-stats.web.cern.ch/acc-stats/#lhc/fill-details 4536, ring 1.
        tag = '_BG_6500GeV_flat_20MeV_bs'  #!! MMMeV
        bgcl = kYellow + 2
        subfolder = wwwpath + 'TCT/6.5TeV/beamgas/fluka/reweighted/'
    else:
        year = "2011"
        energy = " 3.5 TeV "
        pressFile = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/LSS1_B1_fill_2028-sync_rad_and_ecloud.csv"
        bbgFile = "/Users/rkwee/Documents/RHUL/work/HL-LHC/runs/TCT/beam_gas_3.5TeV_IR1_to_arc_20MeV_100M_nprim7660649_66.root"
        beamintensity = 1.66e14
        tag = "_BG_3p5TeV_20MeV"
        bgcl = kTeal

    print "Opening", bbgFile
    nprim = float(bbgFile.split('nprim')[-1].split('_')[0])
    rfile = TFile.Open(bbgFile, "READ")
    tBBG = rfile.Get("particle")
    yrel = ''
    sDict = generate_sDict(tag, nprim, tBBG, yrel)

    # -- small version of plotSpectra
    Trev = 1. / 11245
    kT = 1.38e-23 * 300

    # rootfile with results
    rfoutname = cv70.resultFileBG(bbgFile, year)
    print "Opening", "." * 30, rfoutname
    rf = TFile.Open(rfoutname, "READ")

    for i, skey in enumerate(sDict.keys()):

        if skey.count("Sel"): continue
        elif skey.count("Neg"): continue
        elif skey.count("Pos"): continue
        elif skey.count("Z") and not skey.startswith("OrigZ"): continue
        elif skey.count("Neu_"): continue
        elif skey.count("Char"): continue
        elif skey.count("Plus") or skey.count("Minus"): continue
        elif skey.split(tag)[0].endswith("0") or skey.count("XY"): continue
        elif skey.count("Pio") or skey.count("Kao"):
            continue

            # # FOR DEBUGGING/testing
        elif not skey.count("EkinMuons"):
            continue

        doLeft = 0
        if skey.count("Phi"): doLeft = 1
        cv = TCanvas(skey + 'cv', skey + 'cv', 1400, 900)
        # right corner
        x1, y1, x2, y2 = 0.35, 0.75, 0.9, 0.88
        xpos = 0.3
        if doLeft:
            x1, y1, x2, y2 = 0.2, 0.75, 0.5, 0.88
            xpos = 0.59
        mlegend = TLegend(x1, y1, x2, y2)
        mlegend.SetFillColor(0)
        mlegend.SetFillStyle(0)
        mlegend.SetLineColor(0)
        mlegend.SetTextSize(0.035)
        mlegend.SetShadowColor(0)
        mlegend.SetBorderSize(0)

        twoDhname_flat = skey + '_flat'
        twoDhname_reweighted = skey + '_reweighted'
        twoDhist_flat = rf.Get(twoDhname_flat)
        twoDhist_reweighted = rf.Get(twoDhname_reweighted)

        print twoDhist_flat, skey
        hist_flat = twoDhist_flat.ProjectionX(skey + "makeit1d_flat")
        hist_reweighted = twoDhist_reweighted.ProjectionX(
            skey + "makeit1d_reweighted")
        nbins = hist_reweighted.GetNbinsX()
        print hist_flat.GetEntries()

        hname = skey
        xtitle = sDict[hname][9]
        ytitle = sDict[hname][10]
        ytitle = ytitle.split("/")[0] + '/a.u.'

        XurMin, XurMax = -1, -1.
        YurMin, YurMax = -1, -1.
        doLogx, doLogy = 0, 0

        # devide by binwidth
        if skey.count("Ekin"):
            hist_flat = doEkin(hist_flat, nbins)
            hist_reweighted = doEkin(hist_reweighted, nbins)
            doLogx, doLogy = 1, 1
            YurMin, YurMax = 5e2, 8e8
            if skey.count("Muons"):
                YurMin, YurMax = 5e2, 8e6
            legendunit = sDict[hname][10]
        elif skey.count("Phi"):
            hist_flat = doNormalBinw(hist_flat, nbins)
            hist_reweighted = doNormalBinw(hist_reweighted, nbins)
            doLogx, doLogy = 0, 1
            legendunit = sDict[hname][10]
            if skey.count("En") and not skey.count("Mu"):
                YurMin, YurMax = -1, -1  #3e7,8e9
            elif skey.count("Mu") and not skey.count("En"):
                YurMin, YurMax = 3e4, 5e4
            else:
                YurMin, YurMax = 1e5, 6e8
        elif skey.count("Rad"):
            hist_flat = doRad(hist_flat, nbins)
            hist_reweighted = doRad(hist_reweighted, nbins)
            hist_flat = helpers.doRebin(hist_flat, 6)
            hist_reweighted = helpers.doRebin(hist_reweighted, 6)
            doLogx, doLogy = 0, 1
            legendunit = sDict[hname][10]
            #XurMin,XurMax = 0, 600.
        elif skey.count("OrigZ"):
            rbf = 4
            hist_flat = doNormalBinw(hist_flat, nbins)
            hist_reweighted = doNormalBinw(hist_reweighted, nbins)
            hist_flat.Rebin(rbf)
            hist_flat.Scale(1. / rbf)
            hist_reweighted.Rebin(rbf)
            hist_reweighted.Scale(1. / rbf)
            YurMin, YurMax = 1e-1, 6e7
            legendunit = "/m"
            doLogx, doLogy = 0, 1
            xtitle = "s [m]"

        hist_flat.Scale(1e7 / nprim)
        hist_flat.GetXaxis().SetTitle(xtitle)
        hist_reweighted.GetXaxis().SetTitle(xtitle)

        if XurMin != -1:
            hist_flat.GetXaxis().SetRangeUser(XurMin, XurMax)
            hist_reweighted.GetXaxis().SetRangeUser(XurMin, XurMax)

        if YurMin != -1:
            hist_flat.GetYaxis().SetRangeUser(YurMin, YurMax)
            hist_reweighted.GetYaxis().SetRangeUser(YurMin, YurMax)

        lg, lm = "flat [10^{7}" + legendunit + "/BG int.]", 'l'
        mlegend.AddEntry(hist_flat, lg, lm)
        #        hist_flat.SetLineStyle(2)

        hist_reweighted.SetLineColor(bgcl)
        hist_reweighted.SetMarkerColor(bgcl)
        hist_reweighted.SetMarkerSize(0.2)
        hist_reweighted.SetMarkerStyle(20)

        hist_reweighted.GetYaxis().SetTitle(ytitle)
        hist_reweighted.Draw("hp")
        hist_flat.Draw("histsame")
        lg, lm = "reweighted [" + legendunit + "/s]", 'lp'
        mlegend.AddEntry(hist_reweighted, lg, lm)

        cv.SetLogx(doLogx)
        cv.SetLogy(doLogy)
        gPad.RedrawAxis()

        lab = mylabel(42)
        lab.DrawLatex(0.41, 0.955, energy + ' beam-gas')
        lab.DrawLatex(xpos, 0.82, sDict[hname][6])

        mlegend.Draw()

        pname = wwwpath + 'TCT/6.5TeV/beamgas/fluka/bs/reweighted/' + skey + '.pdf'
        pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/6500GeV/reweighted/cv81_' + skey + '.pdf'
        pname = subfolder + 'cv81_' + skey + '.pdf'
        if energy.count("4 TeV"):
            pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/cv81_' + skey + '.pdf'
            #pname = subfolder + 'cv81_' + skey + '.pdf'
        elif energy.count("3.5 TeV"):
            pname = '/Users/rkwee/Documents/RHUL/work/HL-LHC/LHC-Collimation/Documentation/ATS/HLHaloBackgroundNote/figures/4TeV/reweighted/xcheck2011/cv81_' + skey + '.pdf'
        print('Saving file as ' + pname)
        cv.Print(pname)
示例#15
0
def cv69():

    norm6500GeVB1 = 2748 * 1.2e11 / 360000 * 0.5 * (
        739. / 62515929 + (312 + 273.) / 62692523)  # 2.1e-5
    norm6500GeVB2 = 2748 * 1.2e11 / 360000 * 0.5 * (
        779. / 50890652 + 773. / 63119778.
    )  # 2.76e-5 take the average of H an V runs!

    # python /afs/cern.ch/work/r/rkwee/HL-LHC/LHC-Collimation/AnalysisScripts/py/collsummary.py -f 6.5TeV_vHaloB2_h5/coll_summary_6.5TeV_vHaloB2_h5.dat -c TCT*R5
    # IR5 B1: h:( 53754939.0 protons on IR7 primaries, 346.0 protons on TCT*L5.B1), v(52838656.0 on primaries IR7,  408.0 protons on TCTL5)
    # .5*( 346.0/53754939.0 + 408.0/52838656.0 ) = 7.0791187088930279e-06
    # IR5 B2: h:( 43718962.0 IR7,  302.0 protons ), v(53000835.0, 106.0 protons. )
    # 0.5 * (302.0/43718962.0 + 106.0/53000835.0) = 4.4538612500709768e-06

    run1iniFlux = 368 * 1.2e11 / 360000.  # from Roderiks NIM paper: 2010: 368 up to 2011 1380
    norm3500GeVB1 = 1.02813e-5  # from http://bbgen.web.cern.ch/bbgen/bruce/fluka_beam-halo_3.5TeV/flukaIR15.html
    norm3500GeVB2 = 2.25625e-5  # from http://bbgen.web.cern.ch/bbgen/bruce/fluka_beam-halo_3.5TeV/flukaIR15.html

    # # ------------------------------------------------------------------------
    # 6.5 TeV

    # fNum = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_ntct1324_30.root'
    # fDenom = projectpath + 'valBG4TeV/results_beam_halo_6.5TeV_80cm_IR1B1_20MeV_nprim4702400_66.root'
    # # # old scattering routine
    # # fDenom = workpath + 'runs/4TeV_Halo/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # lTextNum = 'old format'
    # lTextDenom = 'new format'
    # normDenom, normNum, yrel, addon = 1., 1., '/TCT hit', ''
    # tagNum, tagDenom = '_BH_6500GeV_haloB1_20MeV', '_BH_6500GeV_haloB1_20MeV'
    # nColor, dColor = kOrange-3, kPink-5
    # subfolder = wwwpath + 'TCT/6.5TeV/tctimpacts/validationBH/'

    # fNum = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_ntct1324_30.root'
    # fDenom = 'bgChecks2/FL_NewHalo_4TeV_B1/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim6904000_30.root'
    # # # old scattering routine
    # # fDenom = workpath + 'runs/4TeV_Halo/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # lTextNum = '6.5 TeV'
    # lTextDenom = '4 TeV'
    # #    normDenom, normNum, yrel, addon = 1./norm4TeVB1, 1./norm6500GeVB1, '/s', ''
    # normDenom, normNum, yrel, addon = 1., 1., '/TCT hit', 'perTCThit/'
    # tagNum, tagDenom = '_BH_6500GeV_haloB1_20MeV', '_BH_4TeV_B1_20MeV'
    # nColor, dColor = kOrange-3, kPink-5
    # subfolder = wwwpath + 'TCT/compBHB1_4TeV_vs_6.5TeVB1/'

    # fNum = workpath + 'runs/FL_6500GeV_HaloB2_20MeV/results_ir1_6500GeV_b2_20MeV_nprim3646000_30.root'
    # fDenom = projectpath + 'bgChecks2/FL_NewHalo_4TeV_B2/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b2_nprim6914000_30.root'
    # # ## -- fDenom = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'     # -- 4TeV are old fluka sim -- newer exist!
    # subfolder = wwwpath + 'TCT/compBHB2_4TeV_vs_6.5TeV/'
    # lTextNum = '6.5 TeV'
    # lTextDenom = '4 TeV'
    # normNum, normDenom = 1., 1.
    # tagNum, tagDenom = '_BH_6500GeV_haloB2_20MeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink-4
    # yrel = '/TCT hit'

    # fNum = workpath + 'runs/4TeV_Halo/results_ir1_BH_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    # fDenom = workpath + 'runs/4TeV_Halo/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'
    # subfolder = wwwpath + 'TCT/4TeV/comp4TeVB1B2/'
    # lTextNum = 'B1'
    # lTextDenom = 'B2'
    # normNum, normDenom = 1./norm4TeVB1, 1./norm4TeVB2
    # tagNum, tagDenom = '_BH_4TeV_B1_20MeV', '_BH_4TeV_B2_20MeV'
    # nColor, dColor = kOrange-3, kPink-3

    #     fDenom = workpath + 'runs/FL_6500GeV_HaloB2_20MeV/results_ir1_6500GeV_b2_20MeV_nprim3646000_30.root'
    #     fNum = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_6500GeV_b1_20MeV_nprim4752000_30.root'
    #     # fDenom = workpath + 'data/6p5TeV/results_ir1_BH_6500GeV_b2_20MeV_nprim3646000_30.root'
    #     # fNum = workpath + 'data/6p5TeV/results_ir1_BH_6500GeV_b1_20MeV_nprim4752000_30.root'
    #     subfolder = wwwpath + 'TCT/6.5TeV/tctimpacts/compB1B2/perTCThit/'
    #     lTextNum = 'B1'
    #     lTextDenom = 'B2'
    # #    normDenom, normNum = 1./norm6500GeVB2, 1./norm6500GeVB1
    #     normDenom, normNum = 1.,1.
    #     tagNum, tagDenom = '_BH_6500GeV_haloB1_20MeV', '_BH_6500GeV_haloB2_20MeV'
    #     nColor, dColor = kOrange+5, kGreen+2
    #     yrel = "/TCT hit"

    # fNum =  '/afs/cern.ch/project/lhc_mib/tct_simulations/FlukaRuns/runs_usrbin/results_hilumi_ir1b1_exp_20MeV_nominalCollSett_nprim4269100_30.root'
    # fDenom = '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/FL_TCT5IN_roundthin/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # subfolder = wwwpath + 'TCT/HL/compB1CrabCFHalo/'
    # lTextNum = 'crabcf'
    # lTextDenom = 'halo'
    # normNum, normDenom, yrel = 1., 1., '/TCT hit'
    # tagDenom, tagNum =  '_BH_HL_tct5inrdB1_20MeV', '_crabcfb1'
    # dColor, nColor = kMagenta-2, kBlue-1

    # fNum = projectpath + 'HL1.0/FL_HL_TCT5IN_nomCollSett_haloB1/results_hilumi_BH_ir1b1_exp_20MeV_nominalCollSett_nprim3320000_30.root'
    # fDenom = '/afs/cern.ch/work/r/rkwee/HL-LHC/runs/HL_TCT5INOUT_relSett/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    # subfolder = wwwpath + 'TCT/HL/compNomRetrCollSett/perTCThit/'
    # lTextNum = 'nominal'
    # lTextDenom = 'retracted'
    # normDenom, normNum, yrel = 1./normTCT5INb1, 1./normTCT5INb1nom, '/s'
    # normDenom, normNum, yrel = 1., 1., '/TCT hit'
    # tagDenom,tagNum =  '_BH_HL_tct5inrdB1_20MeV','_BH_HL_tct5inrdB1_nomCollSett_20MeV'
    # dColor, nColor = kMagenta-2, kBlue-2

    # fNum =  '/afs/cern.ch/project/lhc_mib/crabcfb1/runs_usrbin/results_hilumi_ir1b1_exp_20MeV_nominalCollSett_nprim4269100_30.root'
    # fDenom = '/afs/cern.ch/project/lhc_mib/tct_simulations/FlukaRuns/runs_modTAN/results_hilumi_ir1b1_exp_20MeV_nominalCollSett_modTAN_nprim1390500_30.root'
    # subfolder = wwwpath + 'TCT/HL/compCrabsTAN/'
    # lTextNum = 'nom TAXN'
    # lTextDenom = 'mod TAXN'
    # normNum, normDenom, yrel = 1., 1., '/TCT hit'
    # tagDenom, tagNum =  '_crabcfb1_modTAN', '_crabcfb1'
    # dColor, nColor = kMagenta+4, kBlue+3

    # ------------------------------------------------------------------------

    # all at 6.5 TeV
    f1 = workpath + 'runs/FL_6500GeV_HaloB1_20MeV/results_ir1_BH_6500GeV_b1_20MeV_nprim4752000_30.root'
    f2 = workpath + 'runs/FL_6500GeV_HaloB2_20MeV/results_ir1_6500GeV_b2_20MeV_nprim3646000_30.root'
    f3 = projectpath + 'bbgen/6.5TeV/results_ir1_BG_bs_6500GeV_b1_20MeV_nprim3198000_67.root'  # hat falschen tag!
    filenames = [f1, f2, f3]

    subfolder = wwwpath + 'TCT/6.5TeV/compAllBKG/'

    lTexts = ['Halo B1', 'Halo B2', 'beam-gas']
    tags = [
        '_BH_6500GeV_haloB1_20MeV', '_BH_6500GeV_haloB2_20MeV',
        '_BG_6500GeV_flat_20GeV_bs'
    ]
    cols = [kAzure + 9, kPink - 8, kYellow - 2]
    mars = [20, 24, 33]
    dOpt = ['h', 'hsame', 'hsame']
    # ------------------------------------------------------------------------

    # need one file to generate sDict
    bbgFile = f1
    print "Opening for sDict generation ...", bbgFile
    tag = tags[0]
    yrel = '/interaction'
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    tBBG = TFile.Open(bbgFile).Get(treeName)
    sDict = generate_sDict(tag, norm, tBBG, yrel)

    if not os.path.exists(subfolder):
        print 'making dir', subfolder
        os.mkdir(subfolder)

    rfs = [TFile.Open(f_i) for f_i in filenames]

    msize = 0.05
    for skey in sDict.keys():

        if skey.count('XY'): continue
        if skey.count('Orig'): continue
        if skey.startswith('Prof'): continue
        if skey.count('Sel'): continue
        if skey.count('Z'): continue

        cv = TCanvas('cv' + skey, 'cv' + skey, 10, 10, 1200, 900)

        x1, y1, x2, y2 = 0.65, 0.78, 0.9, 0.9  # right corner

        if skey.count("PhiEnAll") or skey.count("PhiEnPhot") or skey.count(
                "PhiNAllE") or skey.count("PhiNP") or skey.count("EnPro"):
            x1, y1, x2, y2 = 0.2, 0.78, 0.45, 0.9  # left corner

        mlegend = TLegend(x1, y1, x2, y2)
        mlegend.SetFillColor(0)
        mlegend.SetFillStyle(0)
        mlegend.SetLineColor(0)
        mlegend.SetTextSize(0.04)
        mlegend.SetShadowColor(0)
        mlegend.SetBorderSize(0)

        XurMin, XurMax = -1, -1
        YurMin, YurMax = -1, -1

        hname = skey  # contains tag
        hnames = [hname.replace(tag, tg) for tg in tags]
        print 'plotting ', hnames

        xtitle, ytitle = sDict[skey][9], sDict[skey][10]

        # per rf file 1 histogram

        hists = []
        Ymax, Ymin = [], []
        for i, rf in enumerate(rfs):
            print "trying to get", hnames[i], "from ", rf
            hists += [rf.Get(hnames[i])]

            if not hists[-1]:
                print "WARNING : Didn't find ", hnames[i]
                continue

        print "Have in hists", hists
        for i in range(len(hists)):

            isLogx, isLogy = 0, 0

            try:
                hname = hnames[i]

                if hname.count('Ekin') or hname.count(
                        "En") or hname.startswith("Rad") or hname.startswith(
                            "Phi"):
                    isLogy = 1
                    if hname.count("Ekin"):
                        isLogx = 1

                hists[i].GetXaxis().SetTitle(xtitle)
                hists[i].GetYaxis().SetTitle(ytitle)

                hists[i].SetLineWidth(2)
                hists[i].SetLineStyle(1)
                hists[i].SetLineColor(cols[i])
                hists[i].SetMarkerStyle(mars[i])
                hists[i].SetMarkerSize(1.03)
                hists[i].SetMarkerColor(cols[i])
                #hists[i].GetXaxis().SetLabelSize(0.2))
                # To scale get min max value from all histograms first before drawing

                if isLogy:
                    Ymax += [hists[i].GetMaximum()]
                    Ymin += [hists[i].GetBinContent(10)]
                print Ymin, " for", hname

            except AttributeError:
                print "WARNING : histogram", hnames[
                    i], "doesn't exist in", filenames[i]
                break

        # skip all histograms when one is missing

        cv.cd()
        if isLogx: cv.SetLogx()
        if isLogy: cv.SetLogy()

        for i in range(len(hists)):
            if hists[i]:
                hists[i].Draw(dOpt[i])
                mlegend.AddEntry(hists[i], lTexts[i], "lp")
            else:
                break

        mlegend.Draw()

        lab = mylabel(42)
        lab.DrawLatex(0.356, 0.955, sDict[skey][6])
        lab = mylabel(62)
        lab.SetTextSize(0.055)
        lab.DrawLatex(x1 + 0.06, y1 - 0.06, '6.5 TeV')

        lab = mylabel(42)
        lab.SetTextSize(0.1)
        #        lab.SetTextColor(col)

        if hnames[i].count('Ekin'):
            YurMin, YurMax = 0.0001, 5 * max(Ymax)
            if hnames[i].count('EkinProt'):
                YurMin, YurMax = 0.000001, 30 * max(Ymax)
        if hnames[i].count("Rad"):
            XurMin, XurMax = 0.00001, 600.
            YurMin, YurMax = 1e-9, 10 * max(Ymax)

        if hnames[i].count("Phi"):
            XurMin, XurMax = -3.14, 3.01
            YurMin, YurMax = 0.5 * min(Ymin), 4 * max(Ymax)
            if hnames[i].count("All"):
                YurMin, YurMax = 0.1 * min(Ymin), 10 * max(Ymax)
            elif hnames[i].count("EnPro"):
                YurMin, YurMax = 0.1, 10 * max(Ymax)
            elif hnames[i].count("EnMuE"):
                YurMin, YurMax = 1e-3, 10 * max(Ymax)

        print "Setting y axes", YurMin, YurMax
        # set the axes
        if XurMin != -1:
            hists[0].GetXaxis().SetRangeUser(XurMin, XurMax)

        if YurMin != -1:
            hists[0].GetYaxis().SetRangeUser(YurMin, YurMax)

        gPad.RedrawAxis()

        pname = subfolder + hnames[i].split('_')[0] + '.pdf'

        print pname
        cv.SaveAs(pname)
示例#16
0
def cv16():

    fNum   = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_b2_nprim7825000_66.root'
    fDenom = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'
    subfolder = wwwpath + 'TCT/4TeV/compB2oldB2new/'
    lTextNum = 'B2 old'
    lTextDenom = 'B2 new'
    tagNum, tagDenom = 'BH_4TeV_B2', 'BH_4TeV_B2_20MeV'
    nColor, dColor = kCyan+1, kTeal

    fNum   = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b1_nprim7964000_66.root'
    fDenom = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'
    subfolder = wwwpath + 'TCT/4TeV/compB1B2/'
    lTextNum = 'B1'
    lTextDenom = 'B2'
    tagNum, tagDenom = 'BH_4TeV_B1', 'BH_4TeV_B2'
    nColor, dColor = kOrange-3, kPink-7

    fDenom = workpath + 'results/results_ir1_4TeV_settings_from_TWISS_20MeV_b2_nprim5356000_66.root'
    fNum = workpath + 'results/results_beam-halo_3.5TeV-R1_D1_nprim2344800_66.root'
    subfolder = wwwpath + 'TCT/4TeV/compB2_3p5vs4TeV/'
    lTextNum = 'B2 3.5 TeV'
    lTextDenom = 'B2 4 TeV'
    tagNum, tagDenom = 'BH_3p5TeV', 'BH_4TeV_B2_20MeV'
    nColor, dColor = kOrange+1, kBlue-3

    fNum = workpath + 'runs/FL_TCT5LOUT_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5350000_30.root'
    fDenom = workpath + 'runs/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    fDenom = workpath + 'runs/FL_TCT5LOUT_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5350000_30.root'
    fNum = workpath + 'runs/FL_TCT5IN_roundthinB1_2nd/results_hilumi_ir1_hybrid_b1_exp_20MeV_nprim5319000_30.root'
    subfolder = wwwpath + 'TCT/HL/relaxedColl/newScatt/fluka/comp/ratios/normalised/swap/'
    lTextNum = 'TCT4 only'
    lTextDenom = 'TCT5 in'
    lTextDenom = 'TCT4 only'
    lTextNum = 'TCT5 in'
    # tagNum, tagDenom = '_BH_HL_tct5otrdB1_20MeV', '_BH_HL_tct5inrdB1_20MeV'
    normNum, normDenom = normOUT/nprimOUT, normIN/nprimIN
    tagDenom, tagNum = '_BH_HL_tct5otrdB1_20MeV', '_BH_HL_tct5inrdB1_20MeV'
    normDenom, normNum = normOUT/nprimOUT, normIN/nprimIN
    dColor, nColor = kRed-4, kBlue-3

    rCol = kPink-7
    # need one file to generate sDict
    bbgFile = fNum
    print "Opening for sDict generation ...", bbgFile
    tag = tagNum
    norm = float(bbgFile.split('nprim')[-1].split('_')[0])
    tBBG = TFile.Open(bbgFile).Get(treeName)
    yrel = '/s'
    sDict = generate_sDict(tag, norm, tBBG, yrel)

    if not os.path.exists(subfolder):
        print 'making dir',  subfolder
        os.mkdir(subfolder)

    if fNum.count('B1') or fNum.count('b1'): Beam, beam = 'B1', 'b1'
    elif fNum.count('B2') or fNum.count('b2'): Beam, beam = 'B2','b2'
    else: Beam, beam = '', ''

    rfNum = TFile.Open(fNum)
    rfDenom = TFile.Open(fDenom)
    print 'opening as numerator', fNum
    print 'opening as denominator', fDenom

    print sDict.keys()

    msize = 0.05
    for skey in sDict.keys():

        if skey.count('XY'): continue
        if skey.startswith('Orig'): continue
        # if not skey.count('EkinNeutro'): continue

        cv = TCanvas( 'cv'+skey, 'cv'+skey, 100, 120, 600, 600 )

        x1, y1, x2, y2 = 0.65,0.75,0.9,0.9
        mlegend = TLegend( x1, y1, x2, y2)
        mlegend.SetFillColor(0)
        mlegend.SetFillStyle(0)
        mlegend.SetLineColor(0)
        mlegend.SetTextSize(0.055)
        mlegend.SetShadowColor(0)
        mlegend.SetBorderSize(0)

        p1 = TPad('p1'+skey,'p1'+skey,0.01,0.35,0.99,0.99)

        ymax = 2.
        XurMin, XurMax = -1, -1
        YurMin, YurMax = -1, -1
        dOptNum, dOptDenom = 'h', 'hsame'
        if skey.count('Ekin'): 
            p1.SetLogx(1)
            p1.SetLogy(1)
            ymax = 3.
            XurMin, XurMax = 0.02, 7.0e3

        if skey.count('En') or skey.startswith('Rad'): 
            p1.SetLogy(1)
            ymax = 3.
            XurMin, XurMax = 0.0, 600.

        if skey.count('Zcoor'):
            p1.SetLogy(1)
            p1.SetGridx(1)
            p1.SetGridy(1)

        p1.Draw()
        p1.SetBottomMargin(0.00)

        p2 = TPad('p2'+skey,'p2'+skey,0.01,0.01,0.99,.35)
        if skey.count('Ekin'):
            p2.SetLogx(1)

        p2.Draw()
        p2.SetTopMargin(0.00)
        p2.SetBottomMargin(0.25)

        p1.cd()
        hnameNum = skey
        hnameDenom = hnameNum.replace(tagNum, tagDenom)
        print 'plotting ratio of ', hnameNum, 'and', hnameDenom

        xtitle, ytitle = sDict[skey][9], sDict[skey][10]
        histNum  = rfNum.Get(hnameNum)
        histDenom  = rfDenom.Get(hnameDenom)

        integralNum = histNum.Integral()
        integralDenom = histDenom.Integral()

        ratioInts = integralNum/integralDenom
        print "ratio int", ratioInts, ' ', hnameNum

        if hnameNum.count('Rad'):
            histNum.Rebin()
            histDenom.Rebin()
            # pass

        histNum.GetXaxis().SetTitle(xtitle)
        histNum.GetYaxis().SetTitle(ytitle)
        histDenom.GetXaxis().SetTitle(xtitle)
        histDenom.GetYaxis().SetTitle(ytitle)

        histNum.SetLineWidth(3)
        histNum.SetLineStyle(2)
        histDenom.SetLineColor(dColor)
        histNum.SetLineColor(nColor)
        histDenom.SetLineColor(dColor)
        histNum.SetMarkerColor(nColor)
        histDenom.SetMarkerColor(dColor)
        histNum.SetMarkerStyle(21)
        histDenom.SetMarkerStyle(20)
        histDenom.SetMarkerSize(msize)
        histNum.SetMarkerSize(msize)
        print normNum, normDenom
        histNum.Scale(1./normNum)
        histDenom.Scale(1./normDenom)

        histNum.GetXaxis().SetLabelSize(0.04)
        histDenom.GetXaxis().SetLabelSize(0.04)

        if XurMin != -1:
            histNum.GetXaxis().SetRangeUser(XurMin,XurMax)

        if YurMin != -1:
            histNum.GetXaxis().SetRangeUser(YurMin,YurMax)

        if dOptNum.count("same"):
            histDenom.Draw(dOptDenom)
            histNum.Draw(dOptNum)
        else:
            histNum.Draw(dOptNum)
            histDenom.Draw(dOptDenom)


        mlegend.AddEntry(histNum, lTextNum, "l")
        mlegend.AddEntry(histDenom, lTextDenom, "l")
        mlegend.Draw()

        lab = mylabel(42)
        lab.DrawLatex(0.56, 0.955, sDict[skey][6])
        lab = mylabel(62)
        lab.SetTextSize(0.055)
        lab.DrawLatex(.8,y1-0.07,Beam)

        hnameRatio = 'ratio'+hnameNum
        hRatio = histNum.Clone(hnameRatio)

        hRatio.Divide(histNum, histDenom, 1, 1)
        hRatio.SetLineStyle(1)
        hRatio.SetLineWidth(2)
        hRatio.SetLineColor(rCol)
        hRatio.SetMarkerColor(rCol)
        hRatio.SetMarkerStyle(22)
        hRatio.SetMarkerSize(msize)

        l = TLine()
        l.SetLineWidth(1)
        l.SetLineColor(kGray) #kSpring
        if XurMin == -1:
            XurMin = hRatio.GetBinLowEdge(1)
            XurMax = hRatio.GetBinLowEdge( hRatio.GetNbinsX()+1 )

        p2.cd()

        drawOpt = 'pe'
        if hnameNum.count('Rad') or hRatio.GetMaximum()>200:
           # hRatio.GetYaxis().SetRangeUser(0.1,2.6)
            pass

        hRatio.GetXaxis().SetLabelSize(0.1)
        hRatio.GetYaxis().SetLabelSize(0.08)
        hRatio.GetYaxis().SetTitleOffset(0.6)
        hRatio.GetYaxis().SetTitleSize(0.08)
        hRatio.GetXaxis().SetTitleSize(0.08)
        hRatio.Draw()
        hRatio.GetYaxis().SetTitle('ratio ' + lTextNum + '/' + lTextDenom + " ")
        l.DrawLine(XurMin,1,XurMax,1)
        pname = subfolder+hnameRatio.split('_')[0]+'.pdf'

        print pname
        cv.SaveAs(pname)