print "Mean hit energy: ", ma.h_hitEnergy.GetMean()
print "1/SF calculated: ", energy/(ma.h_hitEnergy.GetMean())

  #Longo-Sestili formula
  #http://arxiv.org/pdf/hep-ex/0001020.pdf
fit = TF1("fit","[0]*(pow([2]*x,[1]-1)*[2]*exp(-[2]*(x))/TMath::Gamma([1]))")
fit.SetParName(0,"A") #normalization factor
fit.SetParName(1,"#alpha")
fit.SetParName(2,"#beta")

gStyle.SetOptStat("emr");

c1 = TCanvas("c1","c1",1000,1000)
c1.Divide(3,2)
c1.cd(1)
draw_1histogram(ma.h_ptGen, "p_{T}^{gen} [GeV]","")
c1.cd(2)
draw_1histogram(ma.h_pdgGen, "PDG code","")
c1.cd(4)
ma.h_cellEnergy.Rebin(2)
draw_1histogram(ma.h_cellEnergy, "Total cell energy [GeV]","")
if (ma.h_cellEnergy.GetEntries()>50):
    ma.h_cellEnergy.Fit("gaus")
c1.cd(5)
draw_2histograms(ma.h_longProfile_particle, ma.h_longProfile, "Longitudinal distance/X0", "Energy [GeV]", "Particle dir.", "Hits in 1st layer")
fit.SetParameters(100, 8.15/1.15,1.0/1.15);
ma.h_longProfile.Fit("fit")
gPad.SetLogy(1)
c1.cd(6)
draw_2histograms(ma.h_radialProfile_particle, ma.h_radialProfile, "Radial distance/X0", "Energy [GeV]", "Particle dir.", "Hits in 1st layer")
Esempio n. 2
0
            fitProfile = TF1("fitProfile", "pol1", 0, energy)
        result = hUpstremCellProfile.Fit(fitProfile, "SNR")

        # fill energy-dependent graphs
        param0.SetPoint(ifile, energyGraph, result.Get().Parameter(0))
        param0.SetPointError(ifile, energyErrorGraph, result.Get().Error(0))
        param1.SetPoint(ifile, energyGraph, result.Get().Parameter(1))
        param1.SetPointError(ifile, energyErrorGraph, result.Get().Error(1))

        if calo_init.args.preview:
            canvProfile = prepare_single_canvas(
                'upstreamEnergy_e' + str(energy) + 'GeV_eta' + str(eta),
                'Upstream energy vs energy in first layer for #eta = ' +
                str(eta))
            draw_1histogram(hUpstremCellProfile,
                            'E_{firstLayer} ' + energyUnit,
                            'upstream energy ' + energyUnit)
            hUpstremCellProfile.Fit(fitProfile, "SR")
            for ibin in reversed(
                    range(0,
                          hUpstremCellProfile.GetXaxis().GetNbins())):
                if hUpstremCellProfile.GetBinContent(ibin) > 0:
                    lastNonEmpty = ibin
                    break
            hUpstremCellProfile.GetXaxis().SetRange(0, lastNonEmpty + 3)
            legendProfile = draw_text([str(energy) + ' GeV e^{-}, B = 4T'],
                                      [0.67, 0.18, 0.85, 0.28], 9, 0)
            legendProfile.SetTextSize(0.05)
            legendProfile.SetTextFont(42)
            canvProfile.Update()
            # save canvases filled for each energy and eta
 else:
     fitoptions = "SQRN"
 for islice, h in enumerate(hmerged):
     fitPre = TF1("fitPre","gaus", h.GetMean() - 1. * h.GetRMS(), h.GetMean() + 1. * h.GetRMS())
     h.Rebin(1)
     resultPre = h.Fit(fitPre, fitoptions)
     fit = TF1("fit","gaus",resultPre.Get().Parameter(1) - 2. * resultPre.Get().Parameter(2), resultPre.Get().Parameter(1) + 2. * resultPre.Get().Parameter(2) )
     result = h.Fit(fit, fitoptions)
     if result and result.Ndf() > 0:
         # if it fits terribly, try to fit in narrower range
         if result.Chi2() / result.Ndf() > 10:
             refit = TF1("refit","gaus",resultPre.Get().Parameter(1) - resultPre.Get().Parameter(2), resultPre.Get().Parameter(1) + resultPre.Get().Parameter(2) )
             result = h.Fit(refit, fitoptions)
     if calo_init.args.preview:
         cPreview.cd(islice + 1)
         draw_1histogram(h,"","")
     # make graph
     if result:
         gSF.SetPoint(islice, sliceSum[islice]-sliceWidth[islice]*0.5, result.Get().Parameter(1))
         gSF.SetPointError(islice, sliceWidth[islice]*0.5 , result.Get().Parameter(2))
 prepare_graph(gSF, 'sf_'+str(len(merge))+'layers', ';radial depth [cm];sampling fraction', ifile+9)
 all_graphs.append(gSF)
 graphTitles.append('#color['+str(colour[ifile])+']{'+str(energy)+' GeV e^{-}}')
 print("samplFractMap ["+str(energy)+"]= ", end='')
 for islice in range(0, Nslicesmerged):
     if islice == 0:
         print("{ ", end='')
     if islice > 0:
         print(", ", end='')
     print(str(gSF.GetY()[islice]), end='')
 print("};")
gSystem.Load("libCaloAnalysis")
from ROOT import SimpleAnalysis, TCanvas, TFile, TF1, gPad
from draw_functions import draw_1histogram, draw_2histograms

# use this script for multiple files

for ifile, filename in enumerate(calo_init.filenamesIn):
    energy = calo_init.energy(ifile)
    analysis = SimpleAnalysis(energy, SF)
    analysis.loop(filename, calo_init.verbose)
    print "Energy of the initial particle: ", energy
    print "Mean hit energy: ", analysis.hHitEnergy.GetMean()
    print "1/SF calculated: ", energy / (analysis.hHitEnergy.GetMean())

    c1 = TCanvas("c1" + str(energy), "c1_" + str(energy) + "_GeV", 1000, 1000)
    c1.Divide(2, 2)
    c1.cd(1)
    draw_1histogram(analysis.hHitEnergy, "hit level energy [GeV]", "")
    c1.cd(2)
    draw_1histogram(analysis.hCellEnergy, "cell level energy [GeV]", "")
    analysis.hCellEnergy.Rebin(2)
    analysis.hCellEnergy.Fit("gaus")
    c1.cd(3)
    draw_1histogram(analysis.hGenPt, "Generated pt [GeV]", "")
    if calo_init.output(ifile):
        c1.SaveAs(calo_init.output(ifile) + ".png")
    else:
        c1.SaveAs("plots_electron_" + str(energy) + "GeV.png")

raw_input("Press ENTER to exit")
    else:
        fitoptions = "SQRN"
    for islice, h in enumerate(hmerged):
        fitPre = TF1("fitPre","gaus", h.GetMean() - 1. * h.GetRMS(), h.GetMean() + 1. * h.GetRMS())
        h.Rebin(10)
        resultPre = h.Fit(fitPre, fitoptions)
        fit = TF1("fit","gaus",resultPre.Get().Parameter(1) - 2. * resultPre.Get().Parameter(2), resultPre.Get().Parameter(1) + 2. * resultPre.Get().Parameter(2) )
        result = h.Fit(fit, fitoptions)
        if result and result.Ndf() > 0:
            # if it fits terribly, try to fit in narrower range
            if result.Chi2() / result.Ndf() > 10:
                refit = TF1("refit","gaus",resultPre.Get().Parameter(1) - resultPre.Get().Parameter(2), resultPre.Get().Parameter(1) + resultPre.Get().Parameter(2) )
                result = h.Fit(refit, fitoptions)
        if calo_init.args.preview:
            cPreview.cd(islice + 1)
            draw_1histogram(h,"","")
        # make graph
        if result:
            if islice < len(merge) - 1:
                gSF.SetPoint(islice, (merge[islice] + 0.5 * (merge[islice + 1] - merge[islice])) * sliceWidth, result.Get().Parameter(1))
                gSF.SetPointError(islice, 0.5 * (merge[islice + 1] - merge[islice]) * sliceWidth , result.Get().Parameter(2))
            else:
                gSF.SetPoint(islice, (merge[islice] + 0.5 * (merge[islice] - merge[islice - 1])) * sliceWidth, result.Get().Parameter(1))
                gSF.SetPointError(islice, 0.5 * (merge[islice] - merge[islice - 1]) * sliceWidth , result.Get().Parameter(2))
    all_graphs.append(gSF)

canv = prepare_single_canvas('sf_e'+str(energy)+'GeV', 'Sampling fraction for '+str(energy)+'GeV')

# Draw graph and all labels
prepare_graph(gSF, 'sf_'+str(len(merge))+'layers', ';radial depth;sampling fraction', ifile+9)
all_graphs[0].Draw("ape")
Esempio n. 6
0
from ROOT import gSystem
gSystem.Load("libcaloanalysis-myanalysis")
from ROOT import CaloAnalysis_simple, TCanvas, TFile, TF1, gPad
from draw_functions import draw_1histogram, draw_2histograms

ENERGY = 50
SF = 5.4
filename = "../../FCCSW/output_ecalSim_e50GeV_eta0_10events.root"

print "Processing file ", filename
ma = CaloAnalysis_simple(SF, ENERGY)
ma.loop(filename)
print "Mean hit energy: ", ma.histClass.h_hitEnergy.GetMean()
print "1/SF calculated: ", ENERGY / (ma.histClass.h_hitEnergy.GetMean())

c1 = TCanvas("c1", "c1", 1000, 1000)
c1.Divide(2, 2)
c1.cd(1)
draw_1histogram(ma.histClass.h_hitEnergy, "hit level energy [GeV]", "")
c1.cd(2)
draw_1histogram(ma.histClass.h_cellEnergy, "cell level energy [GeV]", "")
ma.histClass.h_cellEnergy.Rebin(2)
ma.histClass.h_cellEnergy.Fit("gaus")
c1.cd(3)
draw_1histogram(ma.histClass.h_ptGen, "Generated pt [GeV]", "")

closeInput = raw_input("Press ENTER to exit")
#c1.SaveAs("plots_"+PARTICLE+str(ENERGY)+".gif")
print( "Mean hit energy: ", ma.h_hitEnergy.GetMean())
print( "1/SF calculated: ", energy/(ma.h_hitEnergy.GetMean()))

  #Longo-Sestili formula
  #http://arxiv.org/pdf/hep-ex/0001020.pdf
fit = TF1("fit","[0]*(pow([2]*x,[1]-1)*[2]*exp(-[2]*(x))/TMath::Gamma([1]))")
fit.SetParName(0,"A") #normalization factor
fit.SetParName(1,"#alpha")
fit.SetParName(2,"#beta")

gStyle.SetOptStat("emr");

c1 = TCanvas("c1","c1",1000,1000)
c1.Divide(3,2)
c1.cd(1)
draw_1histogram(ma.h_ptGen, "p_{T}^{gen} [GeV]","")
c1.cd(2)
draw_1histogram(ma.h_pdgGen, "PDG code","")
c1.cd(4)
ma.h_cellEnergy.Rebin(2)
draw_1histogram(ma.h_cellEnergy, "Total cell energy [GeV]","")
if (ma.h_cellEnergy.GetEntries()>50):
    ma.h_cellEnergy.Fit("gaus")
c1.cd(5)
draw_2histograms(ma.h_longProfile_particle, ma.h_longProfile, "Longitudinal distance/X0", "Energy [GeV]", "Particle dir.", "Hits in 1st layer")
fit.SetParameters(100, 8.15/1.15,1.0/1.15);
ma.h_longProfile.Fit("fit")
gPad.SetLogy(1)
c1.cd(6)
draw_2histograms(ma.h_radialProfile_particle, ma.h_radialProfile, "Radial distance/X0", "Energy [GeV]", "Particle dir.", "Hits in 1st layer")
            else:
                fitProfile = TF1("fitProfile","pol1", 0, calo_init.args.fitRangeUp[ifile])
                print("fitting in range: ", 0, calo_init.args.fitRangeUp[ifile])
        else:
            fitProfile = TF1("fitProfile","pol1", 0, energy)
        result = hUpstremCellProfile.Fit(fitProfile, "SNR")

        # fill energy-dependent graphs
        param0.SetPoint(ifile,energyGraph,result.Get().Parameter(0))
        param0.SetPointError(ifile,energyErrorGraph,result.Get().Error(0))
        param1.SetPoint(ifile,energyGraph,result.Get().Parameter(1))
        param1.SetPointError(ifile,energyErrorGraph,result.Get().Error(1))

        if calo_init.args.preview:
            canvProfile = prepare_single_canvas( 'upstreamEnergy_e'+str(energy)+'GeV_eta'+str(eta), 'Upstream energy vs energy in first layer for #eta = '+str(eta))
            draw_1histogram(hUpstremCellProfile, 'E_{firstLayer} '+energyUnit,'upstream energy '+energyUnit)
            hUpstremCellProfile.Fit(fitProfile, "SR")
            for ibin in reversed(range(0,hUpstremCellProfile.GetXaxis().GetNbins())):
                if hUpstremCellProfile.GetBinContent(ibin) > 0:
                    lastNonEmpty = ibin
                    break
            hUpstremCellProfile.GetXaxis().SetRange(0, lastNonEmpty + 3)
            legendProfile = draw_text([str(energy)+' GeV e^{-}, B = 4T'], [0.67,0.18, 0.85,0.28], 9, 0)
            legendProfile.SetTextSize(0.05)
            legendProfile.SetTextFont(42)
            canvProfile.Update()
            # save canvases filled for each energy and eta
            if calo_init.output(ifile):
                canvProfile.SaveAs(calo_init.output(ifile) + "_previewProfile_eta" + str(eta) + "_e"+str(energy)+"GeV.png")
            else:
                canvProfile.SaveAs("upstremCorrection_previewProfile_eta"+str(eta)+"_"+str(layer*width)+"cm.png")
gSystem.Load("libCaloAnalysis")
from ROOT import SimpleAnalysis, TCanvas, TFile, TF1, gPad
from draw_functions import draw_1histogram, draw_2histograms

# use this script for multiple files

for ifile, filename in enumerate(calo_init.filenamesIn):
    energy = calo_init.energy(ifile)
    analysis = SimpleAnalysis(energy, SF)
    analysis.loop(filename, calo_init.verbose)
    print "Energy of the initial particle: ", energy
    print "Mean hit energy: ", analysis.hHitEnergy.GetMean()
    print "1/SF calculated: ", energy/(analysis.hHitEnergy.GetMean())

    c1 = TCanvas("c1"+str(energy),"c1_"+str(energy)+"_GeV",1000,1000)
    c1.Divide(2,2)
    c1.cd(1)
    draw_1histogram(analysis.hHitEnergy,"hit level energy [GeV]","")
    c1.cd(2)
    draw_1histogram(analysis.hCellEnergy,"cell level energy [GeV]","")
    analysis.hCellEnergy.Rebin(2)
    analysis.hCellEnergy.Fit("gaus")
    c1.cd(3)
    draw_1histogram(analysis.hGenPt,"Generated pt [GeV]","")
    if calo_init.output(ifile):
        c1.SaveAs(calo_init.output(ifile)+".png")
    else:
        c1.SaveAs("plots_electron_"+str(energy)+"GeV.png")

raw_input("Press ENTER to exit")