def create_fourthroothistograms(traditionalcherreconstructedenergy, machinelearningcherreconstructedenergy): """Function to perform ROOT histograms""" #Set ROOT histograms TH1TraditionalCherEnergy = TH1F("Cher Energy","",100,0.0, np.mean(traditionalcherreconstructedenergy)*2) TH1MLCherEnergy = TH1F("ML Cher Energy","",100,0.0, np.mean(machinelearningcherreconstructedenergy)*2) #Fill histograms in for loop for Event in range(len(traditionalcherreconstructedenergy)): TH1TraditionalCherEnergy.Fill(traditionalcherreconstructedenergy[Event]) TH1MLCherEnergy.Fill(machinelearningcherreconstructedenergy[Event]) #Draw + DrawOptions histograms Style = gStyle Style.SetLineWidth(1) #TH1TraditionalCherEnergy Style.SetOptStat(1) #Show statistics XAxis = TH1TraditionalCherEnergy.GetXaxis() XAxis.SetTitle("Energy (MeV)") YAxis = TH1TraditionalCherEnergy.GetYaxis() YAxis.SetTitle("# events") TH1TraditionalCherEnergy.Draw() gPad.SaveAs("TraditionalCherEnergy.pdf") gPad.Close() XAxis = TH1MLCherEnergy.GetXaxis() #TH1SignalsCher XAxis.SetTitle("Energy (MeV)") YAxis = TH1MLCherEnergy.GetYaxis() YAxis.SetTitle("# events") Style.SetOptFit() TH1MLCherEnergy.Fit("gaus") TH1MLCherEnergy.Draw() gPad.SaveAs("MLCherEnergy.pdf") gPad.Close()
def create_secondroothistograms(traditionalreconstructedenergy, machinelearningreconstructedenergy): """Function to perform ROOT histograms""" #Set ROOT histograms TH1TraditionalEnergy = TH1F("DR Energy","",100,0.0, np.mean(traditionalreconstructedenergy)*2) TH1MLEnergy = TH1F("ML Energy","",100,0.0, np.mean(machinelearningreconstructedenergy)*2) #Set ROOT 2D histogram TH2FScatter = TH2F("", "", 100, 0.0, np.mean(traditionalreconstructedenergy)*2, 100, 0.0, np.mean(machinelearningreconstructedenergy)*2) #Fill histograms in for loop for Event in range(len(traditionalreconstructedenergy)): TH1TraditionalEnergy.Fill(traditionalreconstructedenergy[Event]) TH1MLEnergy.Fill(machinelearningreconstructedenergy[Event]) TH2FScatter.Fill(traditionalreconstructedenergy[Event], machinelearningreconstructedenergy[Event]) #Draw + DrawOptions histograms Style = gStyle Style.SetLineWidth(1) #TH1TraditionalEnergy Style.SetOptStat(1) #Show statistics XAxis = TH1TraditionalEnergy.GetXaxis() XAxis.SetTitle("Energy (MeV)") YAxis = TH1TraditionalEnergy.GetYaxis() YAxis.SetTitle("# events") TH1TraditionalEnergy.Fit("gaus") myfit = TH1TraditionalEnergy.GetFunction("gaus") drmean = myfit.GetParameter(1) drmeanerror = myfit.GetParError(1) drsigma = myfit.GetParameter(2) drsigmaerror = myfit.GetParError(2) Style.SetOptFit() TH1TraditionalEnergy.Draw() gPad.SaveAs("DREnergy.pdf") gPad.Close() XAxis = TH1MLEnergy.GetXaxis() #TH1SignalsCher XAxis.SetTitle("Energy (MeV)") YAxis = TH1MLEnergy.GetYaxis() YAxis.SetTitle("# events") TH1MLEnergy.Fit("gaus") mymlfit = TH1MLEnergy.GetFunction("gaus") mlmean = mymlfit.GetParameter(1) mlmeanerror = mymlfit.GetParError(1) mlsigma = mymlfit.GetParameter(2) mlsigmaerror = mymlfit.GetParError(2) Style.SetOptFit() TH1MLEnergy.Draw() gPad.SaveAs("MLEnergy.pdf") gPad.Close() Style.SetOptStat(0) #Dont shown statistics XAxis = TH2FScatter.GetXaxis() #TH2FScatter XAxis.SetTitle("DR Energy (MeV)") YAxis = TH2FScatter.GetYaxis() YAxis.SetTitle("ML Energy (MeV)") TH2FScatter.Draw("COLZ") gPad.SaveAs("ScatterEnergies.pdf") gPad.Close() return drmean, drmeanerror, drsigma, drsigmaerror, mlmean, mlmeanerror, mlsigma, mlsigmaerror
def outputCanvas(self, name, options="width=45%"): "Saves the current Canvas to pdf and png files, and includes them in report" if not self._enabled: return # Saves the files gPad.SaveAs(self._path + '/' + self._figureFileName(name, "pdf")) gPad.SaveAs(self._path + '/' + self._figureFileName(name, "png")) #logs the output in report self << "<A border=0 href=\"" + self._figureFileName(name, "pdf") + "\">" \ << "<IMG src=\"" + self._figureFileName(name, 'png') + "\""+options\ << "/></A>\n" self._figIndex += 1
def create_minenergyroothistograms(vector, histogramtitle, xtitle, ytitle, histogramname): """Function to perform ROOT histograms""" rms = 0 #Set ROOT histograms TH1Hist = TH1F(histogramtitle,"",100,0.0, np.mean(vector)*2) #Fill histograms in for loop for entry in range(len(vector)): TH1Hist.Fill(vector[entry]) #Draw + DrawOptions histograms Style = gStyle Style.SetLineWidth(1) #TH1Hist Style.SetOptStat(1) #Show statistics XAxis = TH1Hist.GetXaxis() XAxis.SetTitle(xtitle) YAxis = TH1Hist.GetYaxis() YAxis.SetTitle(ytitle) TH1Hist.Fit("gaus") myminfit = TH1Hist.GetFunction("gaus") minmean = myminfit.GetParameter(1) minmeanerror = myminfit.GetParError(1) minsigma = myminfit.GetParameter(2) minsigmaerror = myminfit.GetParError(2) Style.SetOptFit() TH1Hist.Draw() mean = TH1Hist.GetMean() rms = TH1Hist.GetRMS() Entries = TH1Hist.GetEntries() gPad.SaveAs(histogramname) gPad.Close() return minmean, minmeanerror, minsigma, minsigmaerror
def write_imposedattenuationgraphs(ordered_graphslinearity): if len(ordered_graphslinearity) == 40: sectors = [1, 2, 3, 4, 5] else: sectors = [6, 7, 8] colors = [1, 2, 3, 4, 5, 6, 7, 8, 9] for c, s in enumerate(sectors): plots = [x for x in ordered_graphslinearity if str(s) in x.filename[8]] mgraph = TMultiGraph() for counter, p in enumerate(plots): x = array('d', p.setattenvalues) y = array('d', p.normalizedsetmeancurrents) n = len(x) graph = TGraph(n, x, y) graph.SetMarkerColor(colors[counter]) graph.SetLineColor(colors[counter]) graph.SetMarkerStyle(20) graph.SetMarkerSize(1) mgraph.Add(graph) mgraph.SetTitle("PCBs type " + str(s)) mgraph.GetXaxis().SetRangeUser(0.0, 1.2) mgraph.GetXaxis().SetTitle("1/attenuation") mgraph.GetYaxis().SetTitle("i/area (uA/cm^{2})") mgraph.GetYaxis().SetTitleOffset(1.2) mgraph.Draw("APL") gPad.SaveAs("Overimposed_" + str(s) + ".pdf") gPad.Close()
def savePlot(name): if gPad is None: print 'no active canvas' return fileName = '%s/%s' % (anaDir, name) print 'pad', gPad.GetName(), 'saved to', fileName gPad.SaveAs( fileName )
def lumiReport(cuts=None, hist=None, opt=''): if hist == None: events.Draw('lumi:run', '', opt) else: events.Draw('lumi:run>>' + hist.GetName(), '', opt) gPad.SaveAs('lumiReport.png')
def create_fastroothistograms(vector, histogramtitle, xtitle, ytitle, histogramname): """Function to perform ROOT histograms""" rms = 0 #Set ROOT histograms TH1Hist = TH1F(histogramtitle,"",100,0.0, np.mean(vector)*2) #Fill histograms in for loop for entry in range(len(vector)): TH1Hist.Fill(vector[entry]) #Draw + DrawOptions histograms Style = gStyle Style.SetLineWidth(1) #TH1Hist Style.SetOptStat(1) #Show statistics XAxis = TH1Hist.GetXaxis() XAxis.SetTitle(xtitle) YAxis = TH1Hist.GetYaxis() YAxis.SetTitle(ytitle) TH1Hist.Draw() mean = TH1Hist.GetMean() rms = TH1Hist.GetRMS() Entries = TH1Hist.GetEntries() gPad.SaveAs(histogramname) gPad.Close() return mean, rms, Entries
def create_resolutiongraph(n, energies, sigmasmeans, energieserrors, sigmasmeanserrors, graphname): """Function to perform ROOT graphs of resolutions""" #How many points n = int(n) TGraphresolution = TGraphErrors(n, energies, sigmasmeans, energieserrors, sigmasmeanserrors) #Draw + DrawOptions, Fit + parameter estimation Style = gStyle Style.SetOptFit() XAxis = TGraphresolution.GetXaxis() #TGraphresolution TGraphresolution.SetMarkerColor(4) TGraphresolution.SetMarkerStyle(20) TGraphresolution.SetMarkerSize(2) XAxis.SetTitle("Energy (GeV)") YAxis = TGraphresolution.GetYaxis() YAxis.SetTitle("Sigma/Mean") resolutionfit = TF1("resolutionfit", '([0]/((x)**0.5))+[1]', 0, max(energies)) #somma non quadratura TGraphresolution.Fit("resolutionfit") a = resolutionfit.GetParameter(0) b = resolutionfit.GetParameter(1) TGraphresolution.Draw("AP") gPad.SaveAs(graphname) gPad.Close() return a, b
def write_attenuationrootgraph(vectorx, vectory, graphtitle, xtitle, ytitle, rootdirectory): """Function to perform ROOT graph""" arrayx = array('d') arrayy = array('d') for x in vectorx: arrayx.append(x) for y in vectory: arrayy.append(y) if ytitle == "i": ytitle = ytitle + "/area (uA/cm^{2})" color = 2 offset = 1.5 if ytitle == "v": ytitle = ytitle + " (V)" color = 4 offset = 0.9 #How many graph points n = len(vectorx) MyTGraph = TGraph(n, arrayx, arrayy) MyTGraph.SetName(graphtitle) #Draw + DrawOptions Style = gStyle Style.SetPadLeftMargin(2.0) XAxis = MyTGraph.GetXaxis() #TGraphfasthescin #XAxis.SetTitleOffset(offset) XAxis.SetTitle(xtitle) MyTGraph.SetMarkerColor(4) MyTGraph.SetMarkerStyle(20) MyTGraph.SetMarkerSize(3) MyTGraph.SetTitle(graphtitle + " V") XAxis.SetTitle(xtitle) YAxis = MyTGraph.GetYaxis() YAxis.SetTitleOffset(offset) YAxis.SetTitle(ytitle) MyTGraph.Fit("pol1") intercept = MyTGraph.GetFunction("pol1").GetParameter(0) slope = MyTGraph.GetFunction("pol1").GetParameter(1) intercpetandslope = [intercept, slope] rootdirectory.WriteTObject(MyTGraph) c = TCanvas() #c.SetLogx() c.SetName(graphtitle + "_canvas") MyTGraph.Draw("APL") rootdirectory.WriteTObject(c) #MyTGraph.Write(graphname) #MyTGraph.Draw("AP") gPad.SaveAs(graphtitle[0:9] + ".pdf") gPad.Close() return intercpetandslope
def create_seventhroothistograms(secondmlreconstructedenergy, secondmlscinreconstructedenergy, secondmlcherreconstructedenergy): """Function to perform ROOT histograms""" #Set ROOT histograms TH1SMLEnergy = TH1F("Sec ML Energy","",100,0.0, np.mean(secondmlreconstructedenergy)*2) TH1SMLScinEnergy = TH1F("Sec ML Scin Energy","",100,0.0, np.mean(secondmlscinreconstructedenergy)*2) TH1SMLCherEnergy = TH1F("Sec ML Cher Energy","",100,0.0, np.mean(secondmlcherreconstructedenergy)*2) #Fill histograms in for loop for Event in range(len(secondmlreconstructedenergy)): TH1SMLEnergy.Fill(secondmlreconstructedenergy[Event]) TH1SMLScinEnergy.Fill(secondmlscinreconstructedenergy[Event]) TH1SMLCherEnergy.Fill(secondmlcherreconstructedenergy[Event]) #Draw + DrawOptions histograms Style = gStyle Style.SetLineWidth(1) #TH1SMLEnergy Style.SetOptStat(1) #Show statistics XAxis = TH1SMLEnergy.GetXaxis() XAxis.SetTitle("Energy (MeV)") YAxis = TH1SMLEnergy.GetYaxis() YAxis.SetTitle("# events") TH1SMLEnergy.Fit("gaus") Style.SetOptFit() TH1SMLEnergy.Draw() gPad.SaveAs("SecondMLEnergy.pdf") gPad.Close() XAxis = TH1SMLScinEnergy.GetXaxis() #TH1SMLScinEnergy XAxis.SetTitle("Energy (MeV)") YAxis = TH1SMLScinEnergy.GetYaxis() YAxis.SetTitle("# events") TH1SMLScinEnergy.Fit("gaus") Style.SetOptFit() TH1SMLScinEnergy.Draw() gPad.SaveAs("SecondMLScinEnergy.pdf") gPad.Close() XAxis = TH1SMLCherEnergy.GetXaxis() #TH1SMLCherEnergy XAxis.SetTitle("Energy (MeV)") YAxis = TH1SMLCherEnergy.GetYaxis() YAxis.SetTitle("# events") TH1SMLCherEnergy.Fit("gaus") Style.SetOptFit() TH1SMLCherEnergy.Draw() gPad.SaveAs("SecondMLCherEnergy.pdf") gPad.Close()
def draw(self): self.canvas = TCanvas('can' + self.name, self.name, 1000, 800) if self.histo == None: self.bookCorrelationHisto() self.histo.Draw('boxtext') gPad.SetBottomMargin(0.3) gPad.SetLeftMargin(0.3) gPad.SetRightMargin(0.2) gPad.SaveAs('cutCorr_' + self.name + '_' + varStringToFileName(self.addtlCut) + '.png')
def plot(fname, nbins=50, xmin=10, xmax=200): root_file = TFile(fname) tree = root_file.Get('events') canvas = TCanvas("canvas", "canvas", 600, 600) hist = TH1F("hist", ";mass of all particles (GeV)", nbins, 0, 200) tree.Draw('sum_all_m>>hist', '', '') hist.Fit("gaus", "LM", "", xmin, xmax) gPad.Update() gPad.SaveAs('sum_all_m.png') time.sleep(1) func = hist.GetFunction("gaus") holder.extend([root_file, tree, canvas, hist, func]) return func.GetParameter(1), func.GetParameter(2)
def create_fastgraph(Fastscinenergy, Fastcherenergy, fem, PrimaryParticleEnergy): """Function to perform ROOT graphs and compute he values""" #How many graph points n = len(Fastscinenergy) TGraphfasthescin = TGraph(n, fem, Fastscinenergy) TGraphfasthecher = TGraph(n, fem, Fastcherenergy) #Draw + DrawOptions, Fit + parameter estimation Style = gStyle XAxis = TGraphfasthescin.GetXaxis() #TGraphfasthescin TGraphfasthescin.SetMarkerColor(4) TGraphfasthescin.SetMarkerStyle(1) TGraphfasthescin.SetMarkerSize(1) XAxis.SetTitle("fem") YAxis = TGraphfasthescin.GetYaxis() YAxis.SetTitle("Energy scin (MeV)") TGraphfasthescin.Fit("pol1") myfit = TGraphfasthescin.GetFunction("pol1") Fasthescin = myfit.GetParameter(0)/PrimaryParticleEnergy TGraphfasthescin.Draw("AP") gPad.SaveAs("Fasthescin.pdf") gPad.Close() XAxis = TGraphfasthecher.GetXaxis() #TGraphfasthecher TGraphfasthecher.SetMarkerColor(4) TGraphfasthecher.SetMarkerStyle(1) TGraphfasthecher.SetMarkerSize(1) XAxis.SetTitle("fem") YAxis = TGraphfasthecher.GetYaxis() YAxis.SetTitle("Energy Cher (MeV)") TGraphfasthecher.Fit("pol1") myfit = TGraphfasthecher.GetFunction("pol1") Fasthecher = myfit.GetParameter(0)/PrimaryParticleEnergy TGraphfasthecher.Draw("AP") gPad.SaveAs("Fasthecher.pdf") gPad.Close() return Fasthescin, Fasthecher
def plot(fname): root_file = TFile(fname) tree = root_file.Get('events') canvas = TCanvas("canvas", "canvas", 600,600) hist = TH1F("h", "higgs di-jet mass;m_{jj} (GeV)", 50, 0, 200) tree.Draw('higgs_m>>h', 'zed_m>50') # h.GetYaxis().SetRangeUser(0, 120) hist.Fit("gaus") gPad.Update() gPad.SaveAs('ee_ZH_mjj.png') time.sleep(1) func = hist.GetFunction("gaus") holder.extend([root_file, tree, canvas, hist, func]) return func.GetParameter(1), func.GetParameter(2)
def drawNext(allData, b, r): """This function creates a new TH1F and fills it with the data corresponding to the next buffer/read combination and returns it.""" constraints = "BufferSize== %i && ConcurrentReads== %i " % (b, r) BG = TCanvas("c1", "Read Velocity on Local Disk for root Files", 1920, 1080) hist = TH1F("hist", "", 40, 0, 200) numPoints = allData.Draw("VelocityMBps>>hist", constraints, "goff") hist.SetTitle("%s Concurrent Reads with %s Byte Buffer" % (r, b)) hist.SetXTitle("Read Velocity (MB/s)") hist.Draw() gPad.SaveAs("b%sr%s.png" % (b, r))
def create_ninethroothistogram(traditionalscinreconstructedenergy, traditionalcherreconstructedenergy): """Function to perform ROOT histograms""" #Set ROOT 2D histogram TH2FScinCherEnergy = TH2F("", "", 100, 0.0, np.mean(traditionalscinreconstructedenergy)*2, 100, 0.0, np.mean(traditionalcherreconstructedenergy)*2) #Fill histogram in for loop for event in range(len(traditionalscinreconstructedenergy)): TH2FScinCherEnergy.Fill(traditionalscinreconstructedenergy[event], traditionalcherreconstructedenergy[event]) #Draw + Draw Options XAxis = TH2FScinCherEnergy.GetXaxis() #TH2FScinCherEnergy XAxis.SetTitle("Scin Energy (MeV)") YAxis = TH2FScinCherEnergy.GetYaxis() YAxis.SetTitle("Cher Energy (MeV)") TH2FScinCherEnergy.Draw("COLZ") gPad.SaveAs("ScatterScinCherEnergies.pdf") gPad.Close()
def create_mlemscatterplot(trueem, differencemlem): """Function to perform ROOT histograms""" #Set ROOT 2D histogram TH2FScatter = TH2F("", "Fem", 100, 0.0, np.mean(trueem)*2, 100, 0.0, np.mean(differencemlem)*2) #Fill histograms in for loop for Event in range(len(trueem)): TH2FScatter.Fill(trueem[Event], differencemlem[Event]) #Draw + DrawOptions histograms Style = gStyle Style.SetOptStat(0) XAxis = TH2FScatter.GetXaxis() #TH2FScatter XAxis.SetTitle("True fem") YAxis = TH2FScatter.GetYaxis() YAxis.SetTitle("Difference em (ML)") TH2FScatter.Draw("COLZ") gPad.SaveAs("ScatterfemML.pdf") gPad.Close()
def create_linearitygraph(n, energies, energieserrors, means, sigmameans, graphname): """Function to perform ROOT graphs of resolutions""" #How many points n = int(n) TGraphlinearity = TGraphErrors(n, energies, means, energieserrors, sigmameans) #Draw + DrawOptions, Fit + parameter estimation Style = gStyle Style.SetOptFit() XAxis = TGraphlinearity.GetXaxis() #TGraphresolution TGraphlinearity.SetMarkerColor(4) TGraphlinearity.SetMarkerStyle(20) TGraphlinearity.SetMarkerSize(2) XAxis.SetTitle("Energy (GeV)") YAxis = TGraphlinearity.GetYaxis() YAxis.SetTitle("Mean/TrueEnergy") TGraphlinearity.Draw("AP") gPad.SaveAs(graphname) gPad.Close()
def create_sixthroothistograms(SecondCombinedEnergy): """Function to perform ROOT histograms""" #Set ROOT histograms TH1SecondCombinedEnergy = TH1F("Second Comb Energy","",100,0.0, np.mean(SecondCombinedEnergy)*2) #Fill histograms in for loop for Event in range(len(SecondCombinedEnergy)): TH1SecondCombinedEnergy.Fill(SecondCombinedEnergy[Event]) #Draw + DrawOptions histograms Style = gStyle Style.SetLineWidth(1) #TH1TraditionalCherEnergy Style.SetOptStat(1) #Show statistics XAxis = TH1SecondCombinedEnergy.GetXaxis() XAxis.SetTitle("Energy (MeV)") YAxis = TH1SecondCombinedEnergy.GetYaxis() YAxis.SetTitle("# events") TH1SecondCombinedEnergy.Draw() gPad.SaveAs("SecondCombinedEnergy.pdf") gPad.Close()
def create_fastgraph2(xs, ys): """Function to perform ROOT graph""" #How many graph points n = len(xs) TGraph2 = TGraph(n, xs, ys) #Draw + DrawOptions, Fit + parameter estimation Style = gStyle XAxis = TGraph2.GetXaxis() #TGraphfasthescin TGraph2.SetMarkerColor(4) TGraph2.SetMarkerStyle(20) TGraph2.SetMarkerSize(1) XAxis.SetLimits(0.,0.6) XAxis.SetTitle("") YAxis = TGraph2.GetYaxis() YAxis.SetTitle("") TGraph2.Draw("ACP") gPad.SaveAs("Fastgraph.pdf") gPad.Close()
def drawEnergyDist(hist, legT, leg, minX, maxX): histClone = hist.Clone() legD = r.TLegend(0.25, 0.55, 0.7, 0.85, legT) legD.SetTextFont(132) legD.SetTextSize(0.05) legD.SetFillColor(0) legD.SetFillStyle(0) legD.AddEntry(hist, leg, "lp") r.gROOT.SetBatch(True) canD = TCanvas("canD", "", 600, 500) canD.cd() histClone.Draw("histe") histClone.GetXaxis().SetTitle("E_{pred}/E_{true}") histClone.GetYaxis().SetTitle("norm") histClone.GetXaxis().SetRangeUser(minX, maxX) histClone.Draw("func same") legD.Draw() gPad.Update() gPad.SaveAs("plots/" + str(legT).replace(" ", "_") + "_energyDists_" + str(leg) + ".pdf")
plotter = Plotter( [h_data_WJ_plot, h_DY_WJ_plot, h_WJ_plot, h_TT_WJ_plot, h_QCD_WJ_plot], lumi_in_barn) #plotter = Plotter([h_data, h_Ztt, h_Zll, h_WJ, h_TT, h_Jtf], lumi_in_barn) plotter.draw('M_{T}^{#mu} (GeV)', 'Events') cmsPrel(lumi, energy=13., simOnly=False, onLeft=True, sp=0, textScale=1., xoffset=0.) #plotter.print_info('Channel #mu#tau_{h}',xmin=.175, ymin=.8) gPad.Update() gPad.SaveAs("plot_WJ_SF.png") h_data.stack = False plotter = Plotter([h_data, h_DY, h_WJ, h_TT, h_QCD], lumi_in_barn) #plotter = Plotter([h_data, h_Ztt, h_Zll, h_WJ, h_TT, h_Jtf], lumi_in_barn) plotter.draw('M_{T}^{total} (GeV)', 'Events') cmsPrel(lumi, energy=13., simOnly=False, onLeft=True, sp=0, textScale=1., xoffset=0.) #plotter.print_info('Channel #mu#tau_{h}',xmin=.175, ymin=.8) gPad.Update()
def write_rootdategraph_fromgif(vectorx, vectory, graphtitle, xtitle, ytitle, rootdirectory): """Function to perform ROOT graph""" arrayx = array('d') arrayy = array('d') for x in vectorx: arrayx.append(x.Convert()) for y in vectory: arrayy.append(y) if ytitle == "i": ytitle = ytitle + " (uA)" color = 2 offset = 1. minimum = -1 maximum = int(np.max(vectory) + 1.5) if maximum > 10: maximum = int(maximum) if ytitle == "v": ytitle = ytitle + " (V)" color = 4 offset = 0.9 minimum = 400 maximum = 600 #How many graph points n = len(vectorx) MyTGraph = TGraph(n, arrayx, arrayy) MyTGraph.SetName(graphtitle) #Draw + DrawOptions c = TCanvas() Style = gStyle Style.SetPadLeftMargin(2.0) XAxis = MyTGraph.GetXaxis() #TGraphfasthescin XAxis.SetTimeDisplay(1) XAxis.SetTimeFormat("#splitline{%d/%m}{%H:%M:%S}") XAxis.SetLabelOffset(0.025) MyTGraph.SetMarkerColor(color) MyTGraph.SetMarkerStyle(1) MyTGraph.SetMarkerSize(1) MyTGraph.SetLineColor(color) MyTGraph.SetTitle(graphtitle) #XAxis.SetTitle(xtitle) YAxis = MyTGraph.GetYaxis() YAxis.SetTitleOffset(offset) YAxis.SetTitleOffset(offset) YAxis.SetTitle(ytitle) MyTGraph.GetHistogram().SetMinimum(minimum) MyTGraph.GetHistogram().SetMaximum(maximum) MyTGraph.Draw("APL") rootdirectory.WriteTObject(MyTGraph) #MyTGraph.Write(graphtitle) MyTGraph.Draw("APL") if "D" not in graphtitle: gPad.SaveAs("GIF-" + graphtitle + ".pdf") gPad.Close()
setTDRStyle() if __name__ == "__main__": from ROOT import gStyle, TH1F, gPad, TLegend, TF1, TCanvas c1 = TCanvas("c1", "c1") h = TH1F("h", "; p_{T}^{Bar} (TeV); Events / 2 TeV (10^{3})", 50, -50, 50) gaus1 = TF1('gaus1', 'gaus') gaus1.SetParameters(1, 0, 5) h.FillRandom("gaus1", 50000) h.Scale(0.001) # h.GetXaxis().SetNdivisions(5) # h.GetXaxis().SetRangeUser(-70,70) h.Draw() legend_args = (0.645, 0.79, 0.985, 0.91, '', 'NDC') legend = TLegend(*legend_args) legend.SetFillStyle(0) legend.AddEntry(h, "h1", "l") legend.AddEntry(h, "h1 again", "l") legend.Draw() cmsPrel(25000., 8., True) gPad.Update() gPad.SaveAs('tdrstyle.png')
# draws the jet photon and neutral hadron fractions # just copy paste the lines below to your python prompt from ROOT import gDirectory, TLegend, gPad, TCanvas nEvents = 999999999999 jets = 'jets' addCut = '' gCan = TCanvas() events.Draw(jets + '.obj.component(4).fraction()', '1' + addCut, '', nEvents) h1 = events.GetHistogram() h1.SetLineWidth(2) h1.SetTitle(';f_{#gamma}') gPad.SaveAs('fgamma.png') nhCan = TCanvas() events.Draw(jets + '.obj.component(5).fraction()', '1' + addCut, '', nEvents) h2 = events.GetHistogram() h2.SetLineWidth(2) h2.SetTitle(';f_{nh}') gPad.SaveAs('fnh.png')
def create_firstroothistograms(PrimaryParticleName, VectorSignals, VectorSignalsCher, GroupedVectorSignals, GroupedVectorSignalsCher, ScinTreshold, CherTreshold, ScinMaxFiber, CherMaxFiber, NumFibers, NumModules): """Function to perform ROOT histograms""" #Set ROOT histograms TH2Signals = TH2F("ScatterplotSignals",PrimaryParticleName,111*8,1.2*0,1.2*111,111*8,1.2*0,1.2*111) TH2SignalsGrouped = TH2F("ScatterplotSignalsGrouped",PrimaryParticleName,111,1.2*0,1.2*111,111,1.2*0,1.2*111) TH2SignalsCher = TH2F("ScatterplotSignalsCher",PrimaryParticleName,111*8,0.0*111,1.2*111,111*8,0.0*111,1.2*111) TH2SignalsCherGrouped = TH2F("ScatterplotSignalsCherGrouped",PrimaryParticleName,111,1.2*0,1.2*111,111,1.2*0,1.2*111) TH1Signals = TH1F("Scintillation",PrimaryParticleName,100,0.0,ScinMaxFiber+200.0) TH1SignalsCher = TH1F("Cherenkov",PrimaryParticleName,100,0.0,CherMaxFiber+5) #Fill histograms in for loop for fiberindex in range(NumFibers): X,Y = map.mapXY(fiberindex) if VectorSignals[fiberindex] > ScinTreshold: TH2Signals.Fill(X,Y,VectorSignals[fiberindex]) TH1Signals.Fill(VectorSignals[fiberindex]) if VectorSignalsCher[fiberindex] > CherTreshold: TH2SignalsCher.Fill(X,Y,VectorSignalsCher[fiberindex]) TH1SignalsCher.Fill(VectorSignalsCher[fiberindex]) for moduleindex in range(NumModules): X,Y = mapgroup.mapgroupedXY(moduleindex) TH2SignalsGrouped.Fill(X,Y,GroupedVectorSignals[moduleindex]) TH2SignalsCherGrouped.Fill(X,Y,GroupedVectorSignalsCher[moduleindex]) #Draw + DrawOptions histograms Style = gStyle Style.SetPalette(1) #Root palette style Style.SetOptStat(0) #Do not show statistics TH2Signals.SetLineWidth(0) #TH2Signals #No line width TH2Signals.SetLineColor(2) #TH2Signals.SetFillColorAlpha(2, 0.) XAxis = TH2Signals.GetXaxis() XAxis.SetTitle("x (cm)") XAxis.CenterTitle() XAxis.SetTitleOffset(1.8) YAxis = TH2Signals.GetYaxis() YAxis.SetTitle("y (cm)") YAxis.CenterTitle() YAxis.SetTitleOffset(1.8) ZAxis = TH2Signals.GetZaxis() ZAxis.SetTitle("Energy (MeV)") ZAxis.SetTitleOffset(1.4) TH2Signals.Draw("LEGO2Z 0 FB") gPad.SaveAs("ImageScintillation.pdf") TH2SignalsGrouped.SetLineWidth(0) #TH2GroupedSignals #No line width TH2SignalsGrouped.SetLineColor(2) #TH2Signals.SetFillColorAlpha(2, 0.) XAxis = TH2SignalsGrouped.GetXaxis() XAxis.SetTitle("x (cm)") XAxis.CenterTitle() XAxis.SetTitleOffset(1.8) YAxis = TH2SignalsGrouped.GetYaxis() YAxis.SetTitle("y (cm)") YAxis.CenterTitle() YAxis.SetTitleOffset(1.8) ZAxis = TH2SignalsGrouped.GetZaxis() ZAxis.SetTitle("Energy (MeV)") ZAxis.SetTitleOffset(1.4) TH2SignalsGrouped.Draw("LEGO2Z 0 FB") gPad.SaveAs("ImageScintillationGrouped.pdf") TH2SignalsCherGrouped.SetLineWidth(0) #TH2GroupedCherSignals #No line width TH2SignalsCherGrouped.SetLineColor(4) #TH2Signals.SetFillColorAlpha(2, 0.) XAxis = TH2SignalsCherGrouped.GetXaxis() XAxis.SetTitle("x (cm)") XAxis.CenterTitle() XAxis.SetTitleOffset(1.8) YAxis = TH2SignalsCherGrouped.GetYaxis() YAxis.SetTitle("y (cm)") YAxis.CenterTitle() YAxis.SetTitleOffset(1.8) ZAxis = TH2SignalsCherGrouped.GetZaxis() ZAxis.SetTitle("Energy (MeV)") ZAxis.SetTitleOffset(1.4) TH2SignalsCherGrouped.Draw("LEGO2Z 0 FB") gPad.SaveAs("ImageCherenkovGrouped.pdf") TH2SignalsCher.SetLineWidth(0) #TH2SignalsCher #No line width TH2SignalsCher.SetLineColor(4) XAxis = TH2SignalsCher.GetXaxis() XAxis.SetTitle("x (cm)") XAxis.CenterTitle() XAxis.SetTitleOffset(1.8) YAxis = TH2SignalsCher.GetYaxis() YAxis.SetTitle("y (cm)") YAxis.CenterTitle() YAxis.SetTitleOffset(1.8) ZAxis = TH2SignalsCher.GetZaxis() ZAxis.SetTitle("Energy (MeV)") ZAxis.SetTitleOffset(1.4) TH2SignalsCher.Draw("LEGO2Z FB 0") gPad.SaveAs("ImageCherenkov.pdf") Style.SetLineWidth(1) #TH1Signals Style.SetOptStat(1) #Show statistics gPad.SetLogy() gPad.SetLogx() XAxis = TH1Signals.GetXaxis() XAxis.SetTitle("Energy (MeV)") XAxis.SetTitleOffset(1.2) YAxis = TH1Signals.GetYaxis() YAxis.SetTitle("# fibers") TH1Signals.Draw() gPad.SaveAs("EnergyFibers.pdf") XAxis = TH1SignalsCher.GetXaxis() #TH1SignalsCher XAxis.SetTitle("# Cher p.e.") XAxis.SetTitleOffset(1.2) YAxis = TH1SignalsCher.GetYaxis() YAxis.SetTitle("# fibers") TH1SignalsCher.Draw() gPad.SaveAs("CherpeFibers.pdf") gPad.Close()
h_data.stack = False plotter = Plotter([h_data_TT_plot, h_DY_TT_plot, h_TT_plot], lumi_in_barn) #plotter = Plotter([h_data, h_Ztt, h_Zll, h_WJ, h_TT, h_Jtf], lumi_in_barn) plotter.draw('M_{T}^{total} (GeV)', 'Events') cmsPrel(lumi, energy=13., simOnly=False, onLeft=True, sp=0, textScale=1., xoffset=0.) #plotter.print_info('Channel #mu#tau_{h}',xmin=.175, ymin=.8) gPad.Update() gPad.SaveAs("plot_TT_SF.png") plotter.plot.DrawDataOverMCMinus1() cmsPrel(lumi, energy=13., simOnly=False, onLeft=True, sp=0, textScale=1., xoffset=0.) gPad.Update() gPad.SaveAs("plot_TT_SF_ratio.png") h_data.stack = False plotter = Plotter(
def create_fastgrapherror(Fastscinenergy, Fastcherenergy, rmsScin, rmsCher, fem, rmsfem, PrimaryParticleEnergy): """Function to perform ROOT graphs and compute he values""" #How many graph points n = len(Fastscinenergy) TGraphfasthescin = TGraphErrors(n, fem, Fastscinenergy, rmsfem, rmsScin) TGraphfasthecher = TGraphErrors(n, fem, Fastcherenergy, rmsfem, rmsCher) #Draw + DrawOptions, Fit + parameter estimation Style = gStyle Style.SetOptFit(1) Style.SetOptStat(0) #Do not show statistics XAxis = TGraphfasthescin.GetXaxis() #TGraphfasthescin TGraphfasthescin.SetMarkerColor(4) TGraphfasthescin.SetMarkerStyle(1) TGraphfasthescin.SetMarkerSize(1) XAxis.SetTitle("fem") XAxis.SetLimits(0.0,1.0) YAxis = TGraphfasthescin.GetYaxis() YAxis.SetTitle("Energy scin (MeV)") YAxis.SetRange(int(0.0),int(float(PrimaryParticleEnergy)+10000.0)) TGraphfasthescin.Fit("pol1") myfit = TGraphfasthescin.GetFunction("pol1") Fasthescin = myfit.GetParameter(0)/PrimaryParticleEnergy Fasthescinerror = myfit.GetParError(0)/PrimaryParticleEnergy Fasthescin2 = (PrimaryParticleEnergy - myfit.GetParameter(1))/PrimaryParticleEnergy TGraphfasthescin.SetTitle("") TGraphfasthescin.Draw("AP") gPad.SaveAs("Fasthescin-pol1fit.pdf") gPad.Close() combinedfit = TF1("combinedfit", '(x)*([1]-[0]*[1])+[0]*[1]', 0, max(fem)) combinedfit.FixParameter(1, PrimaryParticleEnergy) TGraphfasthescin.Fit("combinedfit") hes = combinedfit.GetParameter(0) heserror = combinedfit.GetParError(0) TGraphfasthescin.Draw("AP") gPad.SaveAs("Fasthescin.pdf") gPad.Close() XAxis = TGraphfasthecher.GetXaxis() #TGraphfasthecher TGraphfasthecher.SetMarkerColor(4) TGraphfasthecher.SetMarkerStyle(1) TGraphfasthecher.SetMarkerSize(1) XAxis.SetTitle("fem") XAxis.SetLimits(0.0,1.0) YAxis = TGraphfasthecher.GetYaxis() YAxis.SetTitle("Energy Cher (MeV)") YAxis.SetRange(int(0.0),int(float(PrimaryParticleEnergy)+10000.0)) TGraphfasthecher.Fit("pol1") myfit = TGraphfasthecher.GetFunction("pol1") Fasthecher = myfit.GetParameter(0)/PrimaryParticleEnergy Fasthechererror = myfit.GetParError(0)/PrimaryParticleEnergy Fasthecher2 = (PrimaryParticleEnergy - myfit.GetParameter(1))/PrimaryParticleEnergy TGraphfasthecher.SetTitle("") TGraphfasthecher.Draw("AP") gPad.SaveAs("Fasthecher-pol1fit.pdf") gPad.Close() TGraphfasthecher.Fit("combinedfit") hec = combinedfit.GetParameter(0) hecerror = combinedfit.GetParError(0) TGraphfasthecher.Draw("AP") gPad.SaveAs("Fasthecher.pdf") gPad.Close() return Fasthescin, Fasthecher, Fasthescinerror, Fasthechererror, Fasthescin2, Fasthecher2, hes, hec, heserror, hecerror