def NormalizeYAxis(h2,axis_N="Y"): h2_new = h2.Clone() h2_new.SetDirectory(0) TH2.AddDirectory(0) if axis_N == "Y": for ibx in range(1, h2.GetNbinsX()+1): verticalsum = 0.0 for iby in range(1, h2.GetNbinsY()+1): verticalsum = verticalsum + h2.GetBinContent(ibx, iby) #print 'old bin content = ',ibx, iby, h2.GetBinContent(ibx, iby) # once the sum is calculated this has to be used to scaling each bin content in the X bin i.e. # divide each bin content by verticalsum # following is outside the for loop of iby, create another loop for the Y axis. for iby_ in range (1, h2.GetNbinsY()+1): new_content = 0.0 old_content = h2.GetBinContent(ibx, iby_) # safety check to avoid divide by zero. if verticalsum != 0: new_content = old_content / verticalsum h2_new.SetBinContent(ibx, iby_, new_content) ## error calculation error_ = 0.0 if verticalsum !=0: delta_a = math.sqrt(verticalsum) / verticalsum delta_b = 0.0 if old_content > 0.0: delta_b = math.sqrt(old_content) / old_content error_ = new_content * (delta_a + delta_b) h2_new.SetBinError(ibx,iby_, error_) h2_new.SetDirectory(0) TH2.AddDirectory(0) if axis_N == "X": for iby in range(1, h2.GetNbinsY()+1): verticalsum = 0.0 for ibx in range(1, h2.GetNbinsX()+1): verticalsum = verticalsum + h2.GetBinContent(ibx, iby) #print 'old bin content = ',ibx, iby, h2.GetBinContent(ibx, iby) ## same as above but now normalised over X for ibx_ in range (1, h2.GetNbinsX()+1): new_content = 0.0 old_content = h2.GetBinContent(ibx_, iby) # safety check to avoid divide by zero. if verticalsum != 0: new_content = old_content / verticalsum h2_new.SetBinContent(ibx_, iby, new_content) return h2_new
def NormalizedPrefiringProbability(h2,axis_N="Y"): h2_new = h2.Clone() h2_new.SetDirectory(0) TH2.AddDirectory(0) Vsum_=[] if axis_N == "Y": for ibx in range(1, h2.GetNbinsX()+1): verticalsum = 0.0 for iby in range(1, h2.GetNbinsY()+1): verticalsum = verticalsum + h2.GetBinContent(ibx, iby) #print 'old bin content = ',ibx, iby, h2.GetBinContent(ibx, iby) Vsum_.append(verticalsum) if axis_N == "X": for iby in range(1, h2.GetNbinsY()+1): verticalsum = 0.0 for ibx in range(1, h2.GetNbinsX()+1): verticalsum = verticalsum + h2.GetBinContent(ibx, iby) #print 'old bin content = ',ibx, iby, h2.GetBinContent(ibx, iby) Vsum_.append(verticalsum) prob_ = Vsum_[1]/(Vsum_[1]+Vsum_[2]) delta_a = 0.0 if Vsum_[1]>0.0: delta_a = math.sqrt(Vsum_[1])/Vsum_[1] delta_b = 0.0 if (Vsum_[1]+Vsum_[2])>0: delta_b = math.sqrt(Vsum_[1]+Vsum_[2]) / (Vsum_[1]+Vsum_[2]) prob_e_ = prob_ * (delta_a + delta_b) return [prob_,prob_e_]
def normilize_xaxis(input_h: ROOT.TH2) -> ROOT.TH2: normilized_h = input_h.Clone() projection = hist.ProjectionY() print("projection:", projection.GetXaxis().GetNbins()) for y_bin in range(input_h.GetYaxis().GetNbins() + 2): norm = projection.GetBinContent(y_bin) print("norm: ", norm) for x_bin in range(input_h.GetXaxis().GetNbins() + 2): if norm == 0: normilized_h.SetBinContent(x_bin, y_bin, 0) else: normilized_h.SetBinContent( x_bin, y_bin, round( normilized_h.GetBinContent(x_bin, y_bin) / norm, 2)) return normilized_h
def fixZScale(self, canvas): ''' Temperature plot scales may run off the right side of the canvas. Fix that if applicable ''' for obj in canvas.GetListOfPrimitives(): if obj.InheritsFrom(TH2.Class()): scale = obj.GetListOfFunctions().FindObject("palette") if scale: if canvas.GetRightMargin() < 0.075: canvas.SetRightMargin(0.075) scale.SetX1(1.005) scale.SetX2(1.035) canvas.Update()
def generalEMCOptions(subsystem, hist, processingOptions): # Set options for when not debugging if processingParameters["debug"] == False: # Disable hist stats hist.hist.SetStats(False) # Disable the title gStyle.SetOptTitle(0) # Allows curotmization of draw options for 2D hists if hist.hist.InheritsFrom(TH2.Class()): hist.canvas.SetLogz() # Updates the canvas, as Update() does not seem to work # See: https://root.cern.ch/root/roottalk/roottalk02/3965.html hist.canvas.Modified()
def NormalizedPrefiringProbability(h2,axis_N="Y"): h2_new = h2.Clone() h2_new.SetDirectory(0) TH2.AddDirectory(0) Vsum_=[] if axis_N == "Y": for ibx in range(1, h2.GetNbinsX()+1): verticalsum = 0.0 for iby in range(1, h2.GetNbinsY()+1): verticalsum = verticalsum + h2.GetBinContent(ibx, iby) #print 'old bin content = ',ibx, iby, h2.GetBinContent(ibx, iby) Vsum_.append(verticalsum) print "Vsum =", Vsum_ prob_ = Vsum_[1]/(Vsum_[1]+Vsum_[2]) print "prob = ", prob_ return prob_
def setEMCHistogramOptions(subsystem): """ Set general hist object options. Canvas and additional options must be set later.""" # Set the histogram pretty names # We can remove the first 12 characters for hist in subsystem.histsAvailable.values(): # Truncate the prefix off EMC hists, but also protect against truncating non-EMC hists if "EMC" in hist.histName: hist.prettyName = hist.histName[12:] # Set colz for any TH2 hists if hist.histType.InheritsFrom(TH2.Class()): hist.drawOptions += " colz" # Set general processing options # Sets the histograms to scale if they are setup to scale by nEvents subsystem.processingOptions["scaleHists"] = True # Sets the hot channel threshold. 0 uses the default in the defined function subsystem.processingOptions["hotChannelThreshold"] = 0
def invert_col(pad, fgcol=rt.kOrange - 3, bgcol=rt.kBlack): #set foreground and background color #fgcol = rt.kAzure #fgcol = rt.kGreen #fgcol = rt.kOrange-3 pad.SetFillColor(bgcol) pad.SetFrameLineColor(fgcol) next = TIter(pad.GetListOfPrimitives()) obj = next() while obj != None: #H1 if obj.InheritsFrom(TH1.Class()) == True: if obj.GetLineColor() == rt.kBlack: obj.SetLineColor(fgcol) obj.SetFillColor(bgcol) if obj.GetMarkerColor() == rt.kBlack: obj.SetMarkerColor(fgcol) obj.SetAxisColor(fgcol, "X") obj.SetAxisColor(fgcol, "Y") obj.SetLabelColor(fgcol, "X") obj.SetLabelColor(fgcol, "Y") obj.GetXaxis().SetTitleColor(fgcol) obj.GetYaxis().SetTitleColor(fgcol) #Legend if obj.InheritsFrom(TLegend.Class()) == True: obj.SetTextColor(fgcol) #obj.SetFillStyle(1000) #obj.SetFillColor(fgcol) #obj.SetTextColor(bgcol) #ln = TIter(obj.GetListOfPrimitives()) #lo = ln.Next() #while lo != None: #if lo.GetObject() == None: #lo = ln.Next() #continue #if lo.GetObject().InheritsFrom(TH1.Class()) == True: #hx = lo.GetObject() #hx.SetFillColor(bgcol) #if hx.GetMarkerColor() == rt.kBlack: #hx.SetMarkerColor(fgcol) #hx.SetLineColor(fgcol) #pass #lo = ln.Next() #RooHist if obj.InheritsFrom(RooHist.Class()) == True: if obj.GetMarkerColor() == rt.kBlack: obj.SetLineColor(fgcol) obj.SetMarkerColor(fgcol) #H2 if obj.InheritsFrom(TH2.Class()) == True: obj.SetAxisColor(fgcol, "Z") obj.SetLabelColor(fgcol, "Z") obj.GetZaxis().SetTitleColor(fgcol) #obj.SetLineColor(fgcol) #obj.SetMarkerColor(fgcol) #TLatex if obj.InheritsFrom(TLatex.Class()) == True: if obj.GetTextColor() == rt.kBlack: obj.SetTextColor(fgcol) #F2 if obj.InheritsFrom(TF2.Class()) == True: axes = [obj.GetXaxis(), obj.GetYaxis(), obj.GetZaxis()] for i in range(len(axes)): axes[i].SetAxisColor(fgcol) axes[i].SetLabelColor(fgcol) axes[i].SetTitleColor(fgcol) #F1 if obj.InheritsFrom(TF1.Class()) == True: axes = [obj.GetXaxis(), obj.GetYaxis()] for i in range(len(axes)): axes[i].SetAxisColor(fgcol) axes[i].SetLabelColor(fgcol) axes[i].SetTitleColor(fgcol) #TGraph if obj.InheritsFrom(TGraph.Class()) == True: obj.SetFillColor(bgcol) ax = obj.GetXaxis() ay = obj.GetYaxis() ax.SetAxisColor(fgcol) ay.SetAxisColor(fgcol) ax.SetLabelColor(fgcol) ay.SetLabelColor(fgcol) ax.SetTitleColor(fgcol) ay.SetTitleColor(fgcol) if obj.GetLineColor() == rt.kBlack: obj.SetLineColor(fgcol) obj.SetMarkerColor(fgcol) #TGaxis if obj.InheritsFrom(TGaxis.Class()) == True: obj.SetLineColor(fgcol) obj.SetLabelColor(fgcol) obj.SetTitleColor(fgcol) #TFrame if obj.InheritsFrom(TFrame.Class()) == True: if obj.GetLineColor() == rt.kBlack: obj.SetLineColor(fgcol) obj.SetFillColor(bgcol) #move to next item obj = next()
#THIS SCRIPT IS MADE TO COMPARE THE NJET DISTRIBUTIONS FROM MC12 TTW EVENTS AND FROM MC14 NJET EVENTS. IT ALSO CALCULATE THE REAL AND THE FAKE RATES IN TTBAR EVENTS. IT USES THE NOMINAL TTBARMC SELECTED REQUIRING TRUTH MATCHING FOR REAL RATES (OS REGION) AND THE FAKE EVENTS (AT LEAST ONE NON-PROMPT LEPTON) FOR FAKE RATES IN THE SS REGION from math import sqrt, pow from ROOT import TCanvas, TFile, TGraph, TGraphErrors, TColor, TAttFill, TStyle, TLegend, TH1, TH2, TH1D, gROOT, TF1, TTree, TH1I, gDirectory, TChain, TH2D import array import copy import csv gROOT.SetBatch(True) TH1.SetDefaultSumw2() TH2.SetDefaultSumw2() #path_data12 = '/mel_data/ttH/NewReprocessed_Melb13_ttH_v1.1_noBjetcut/ttW/' #path_dc14 = '/mel_data/ttH/NewReprocessed_Melb13_ttH_Run2Test18_DxAOD_nobjetcut/ttW/' path_data12 = '/mel_data/ttH/NewReprocessed_Melb13_ttH_v1.1/ttW/' path_dc14 = '/mel_data/ttH/NewReprocessed_Melb13_ttH_Run2Test22_DxAOD/ttW/' import os dists = ['evtsel_jets_num', 'Jet0Pt'] channels = ['ee', 'em', 'mm'] #this selection has no bjet requirements selection = { 'ee': 'evtsel_is_sltmatch && evtsel_dilep_type && evtsel_tau_num==0 && (isSS01==1 && Lep0Pt>20 && Lep1Pt>20) && isTT01==1 && evtsel_is_diel && ((fabs(Lep0PDG)!=11 || fabs(Lep0Eta)<1.5) && (fabs(Lep1PDG)!=11 || fabs(Lep1Eta)<1.5))', 'em': 'evtsel_is_sltmatch && evtsel_dilep_type && evtsel_tau_num==0 && (isSS01==1 && Lep0Pt>20 && Lep1Pt>20) && isTT01==1 && evtsel_is_muel && ((fabs(Lep0PDG)!=11 || fabs(Lep0Eta)<1.5) && (fabs(Lep1PDG)!=11 || fabs(Lep1Eta)<1.5))', 'mm': 'evtsel_is_sltmatch && evtsel_dilep_type && evtsel_tau_num==0 && (isSS01==1 && Lep0Pt>20 && Lep1Pt>20) && isTT01==1 && evtsel_is_dimu' } #selection={'ee':'evtsel_is_sltmatch && evtsel_bjets_num>=1 && evtsel_dilep_type && evtsel_jets_num>=1 && evtsel_tau_num==0 && (isSS01==1 && Lep0Pt>20 && Lep1Pt>20) && isTT01==1 && evtsel_is_diel && ((fabs(Lep0PDG)!=11 || fabs(Lep0Eta)<1.5) && (fabs(Lep1PDG)!=11 || fabs(Lep1Eta)<1.5))', 'em':'evtsel_is_sltmatch && evtsel_bjets_num>=1 && evtsel_dilep_type && evtsel_jets_num>=1 && evtsel_tau_num==0 && (isSS01==1 && Lep0Pt>20 && Lep1Pt>20) && isTT01==1 && evtsel_is_muel && ((fabs(Lep0PDG)!=11 || fabs(Lep0Eta)<1.5) && (fabs(Lep1PDG)!=11 || fabs(Lep1Eta)<1.5))', 'mm':'evtsel_is_sltmatch && evtsel_bjets_num>=1 && evtsel_dilep_type && evtsel_jets_num>=1 && evtsel_tau_num==0 && (isSS01==1 && Lep0Pt>20 && Lep1Pt>20) && isTT01==1 && evtsel_is_dimu'}