for opt, arg in options: if opt=='-e': ebeam=float(arg) if opt=='-h': print_usage() sys.exit(0) if len(remainder)<3: print_usage() sys.exit(0) gROOT.SetBatch(True) c = TCanvas("c","c",1200,900); gStyle.SetOptFit(1) gStyle.SetStatW(0.2) gStyle.SetStatH(0.1) outfile = TFile(remainder[0]+".root","RECREATE") c.Print(remainder[0]+".pdf[") #masses = [0.020, 0.030, 0.040, 0.050, 0.060, 0.070, 0.080, 0.090] #masses = [0.020, 0.022, 0.024, 0.026, 0.028, 0.030, 0.035, 0.040, 0.050, 0.060, 0.070, 0.080, 0.090] masses = [0.022, 0.024, 0.026, 0.028, 0.030, 0.035, 0.040, 0.050, 0.060, 0.070, 0.080, 0.090] massArr=array.array('d') zeroArr=array.array('d') gammaArr=array.array('d') mresL1p0Arr=array.array('d') mresL1p1Arr=array.array('d') mresL1p0Err=array.array('d') mresL1p1Err=array.array('d') effTargetArr=array.array('d') effL1p0Arr=array.array('d')
def setTDRStyle(force): gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetCanvasDefH(600) gStyle.SetCanvasDefW(600) gStyle.SetCanvasDefX(0) gStyle.SetCanvasDefY(0) gStyle.SetPadBorderMode(0) gStyle.SetPadColor(kWhite) gStyle.SetPadGridX(False) gStyle.SetPadGridY(False) gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillColor(0) gStyle.SetFrameFillStyle(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) if force: gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(1) gStyle.SetEndErrorSize(2) gStyle.SetErrorX(0.) gStyle.SetMarkerStyle(20) gStyle.SetOptFit(1) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) gStyle.SetOptDate(0) gStyle.SetOptFile(0) gStyle.SetOptStat(0) gStyle.SetStatColor(kWhite) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.04) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.2) gStyle.SetPadTopMargin(0.05) gStyle.SetPadBottomMargin(0.13) gStyle.SetPadLeftMargin(0.16) gStyle.SetPadRightMargin(0.04) gStyle.SetOptTitle(0) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1) gStyle.SetTitleTextColor(1) gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.05) gStyle.SetTitleColor(1, "XYZ") gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.06, "XYZ") gStyle.SetTitleXOffset(0.9) gStyle.SetTitleYOffset(1.25) gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelOffset(0.007, "XYZ") gStyle.SetLabelSize(0.05, "XYZ") gStyle.SetAxisColor(1, "XYZ") gStyle.SetStripDecimals(True) gStyle.SetTickLength(0.03, "XYZ") gStyle.SetNdivisions(510, "XYZ") gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetOptLogx(0) gStyle.SetOptLogy(0) gStyle.SetOptLogz(0) gStyle.SetPaperSize(20., 20.) gROOT.ForceStyle()
hp1.Fill((p1Fit - p1End) / p1FitError) p0Fit = fitresult.Parameter(0) # - dsMeanVal.getValV(); p0FitError = fitresult.ParError(0) print 'P0FIT = ', p0Fit, '\nDSMEANVAL = ', etaAvg.getValV( ), '\nP0END = ', p0End, '\n' hp0.Fill((p0Fit - p0End) / p0FitError) #break; from ROOT import gStyle, TStyle gStyle.SetOptFit(111) gStyle.SetOptStat(11) gStyle.SetStatW(gStyle.GetStatW() / 1.1) gStyle.SetStatH(gStyle.GetStatH() / 1.1) gStyle.SetStatX(gStyle.GetStatX()) gStyle.SetStatY(gStyle.GetStatY() - 0.05) currentTime = time.time() theHistCanvas = TCanvas() theHistCanvas.SetBottomMargin(0.2) theHistCanvas.SetRightMargin(0.05) hp1.Fit("gaus", "ILL") hp1.Draw() hp1.GetYaxis().SetTitleSize(0.05) hp1.GetXaxis().SetTitleSize(0.05) hp1.GetXaxis().SetTitleOffset(1.5)
def analyzeMeshes(self, dictOfMeshes, doCull=False, cullCut=0.90): """ analyzeMeshes takes a dictionary with meshes as input, and fits it to the references output dictionary includes a deepcopy of the input meshes note: this fits to zDiff = dictOfMeshes - interpolation of self.meshDict ie. the sign is defined as (other guy) - (me) """ # deepcopy the meshes! no longer adjusts in place dictOfMeshesCopy = {} for key in list(dictOfMeshes.keys()): theMesh = copy.deepcopy(dictOfMeshes[key]) dictOfMeshesCopy[key] = theMesh # then we analyze the Zernike polynomials by comparing them to stored references # analyzeDonuts returns a dictionary containing deltas and rotation angles for focus, astigmatism and coma # as well as the hexapod adjustments # it also makes a Canvas of plots for study dictOfResults = {} # loop over keys, fitting References for key in list(dictOfMeshesCopy.keys()): # some special cases resultsKeyName = "%sResultDict" % (key.replace("Mesh", "")) meshName = key if key == "z4Mesh": print("Python 3 debugging: %r" % self.meshDict) dictOfResults[resultsKeyName] = self.fitToRefMesh( self.meshDict[meshName], dictOfMeshesCopy[meshName], self.zangleconv) elif key == "rzeroMesh": dictOfResults[resultsKeyName] = self.analyzeRzero( dictOfMeshesCopy["rzeroMesh"], dictOfMeshesCopy["chi2Mesh"], dictOfMeshesCopy["neleMesh"]) elif key == "chi2Mesh": continue elif key == "neleMesh": continue else: # check that meshDict has the appropriate mesh if meshName in self.meshDict: dictOfResults[resultsKeyName] = self.fitToRefMesh( self.meshDict[meshName], dictOfMeshesCopy[meshName]) # if we want to cull, cull and refit! # use the fitted weight to cull - culltype="fit" if doCull: # this will take the wgt's from the fit and take their product # for each point, and cull at a product of cullCut self.cullAllMeshes(dictOfMeshesCopy, cullCut=cullCut) for key in list(dictOfMeshesCopy.keys()): # some special cases resultsKeyName = "%sResultDict" % (key.replace("Mesh", "")) meshName = key if key == "z4Mesh": dictOfResults[resultsKeyName] = self.fitToRefMesh( self.meshDict[meshName], dictOfMeshesCopy[meshName], self.zangleconv) elif key == "rzeroMesh": dictOfResults[resultsKeyName] = self.analyzeRzero( dictOfMeshesCopy["rzeroMesh"], dictOfMeshesCopy["chi2Mesh"], dictOfMeshesCopy["neleMesh"]) elif key == "chi2Mesh": continue elif key == "neleMesh": continue else: # check that meshDict has the appropriate mesh if meshName in self.meshDict: dictOfResults[resultsKeyName] = self.fitToRefMesh( self.meshDict[meshName], dictOfMeshesCopy[meshName]) # analyze this data and extract the hexapod coefficients donutDict = self.calcHexapod(dictOfResults) if len(donutDict) == 0: goodCalc = False else: goodCalc = True # add the individual fit results here too for key in list(dictOfResults.keys()): donutDict[key] = dictOfResults[key] # and add the meshes too for key in list(dictOfMeshesCopy.keys()): donutDict[key] = dictOfMeshesCopy[key] # make a Canvas of plots for this image # plot Histogram of Difference before fit, after fit, and after fit vs. X,Y position if self.paramDict["histFlag"] and "deltaArrayBefore" in dictOfResults[ "z4ResultDict"] and goodCalc: # setup plots gStyle.SetStatH(0.32) gStyle.SetStatW(0.4) gStyle.SetOptStat(1111111) gStyle.SetMarkerStyle(20) gStyle.SetMarkerSize(0.5) gStyle.SetPalette(1) gROOT.ForceStyle() # loop over results, making plots for each nplots = 0 plotDict = {} for key in list(dictOfResults.keys()): theResultDict = dictOfResults[key] keyId = key.replace("ResultDict", "") # special cases if keyId == "z4": nWavesBefore = 200.0 nWavesAfter = 200.0 else: nWavesBefore = 1.0 nWavesAfter = 0.2 if keyId != "rzero": nplots = nplots + 1 hBefore = hfillhist(key + "Before", "Delta " + key + ", Before Fit", theResultDict["deltaArrayBefore"], 200, -nWavesBefore, nWavesBefore) hAfter = hfillhist(key + "zAfter", "Delta " + key + ", After Fit", theResultDict["deltaArrayAfter"], 200, -nWavesAfter, nWavesAfter) hBefore2D = TGraph2D( key + "Before2D", "Delta " + key + ", Before Fit, vs. Position;X[mm];Y[mm]", theResultDict["deltaArrayBefore"].shape[0], theResultDict["deltaArrayX"], theResultDict["deltaArrayY"], theResultDict["deltaArrayBefore"]) hAfter2D = TGraph2D( key + "After2D", "Delta " + key + ", After Fit, vs. Position;X[mm];Y[mm]", theResultDict["deltaArrayAfter"].shape[0], theResultDict["deltaArrayX"], theResultDict["deltaArrayY"], theResultDict["deltaArrayAfter"]) plotList = [hBefore, hAfter, hBefore2D, hAfter2D] plotDict[keyId] = plotList # the Canvas # unique name for our canvas # might be that # gROOT.SetBatch(kTRUE) # will prevent the Canvas from appearing, but will still get made in output pickle tstr = "canvas" + str(time.time()) canvas = TCanvas(tstr, tstr, 300 * nplots, 1000) canvas.Divide(nplots, 4) # plot em jZ = 0 for iZ in range(4, 15 + 1): key = "z%d" % (iZ) if key in plotDict: jZ = jZ + 1 plotList = plotDict[key] icanvas = jZ + 0 * nplots canvas.cd(icanvas) plotList[0].Draw() icanvas = jZ + 1 * nplots canvas.cd(icanvas) plotList[1].Draw() icanvas = jZ + 2 * nplots canvas.cd(icanvas) plotList[2].Draw("zcolpcol") icanvas = jZ + 3 * nplots canvas.cd(icanvas) plotList[3].Draw("zcolpcol") # set it so that python doesn't own these ROOT object for key in list(plotDict.keys()): for plot in plotDict[key]: SetOwnership(plot, False) # save canvas in the output Dictionary donutDict["canvas"] = canvas # all done return donutDict
def initialization(batch=True, font=default_font): '''-- ROOT initialization --''' print "Initializing ROOT ..." # general gROOT.Reset() gROOT.SetBatch(batch) gROOT.SetStyle("Plain") # gStyle gStyle.SetFillColor(0) gStyle.SetCanvasColor(10) gStyle.SetLineWidth(1) gStyle.SetPalette(8) gStyle.SetTextFont(font) #gStyle.SetTextSize(30) # Frame gStyle.SetFrameBorderMode(0) gStyle.SetFrameFillColor(0) # Pad gStyle.SetPadBorderMode(0) gStyle.SetPadColor(0) gStyle.SetPadBottomMargin(0.1) gStyle.SetPadTopMargin(0.01) gStyle.SetPadLeftMargin(0.1) gStyle.SetPadRightMargin(0.01) gStyle.SetPadTickX(1) # make ticks be on all 4 sides. gStyle.SetPadTickY(1) gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) # histogram gStyle.SetHistFillStyle(0) gStyle.SetOptTitle(0) gStyle.SetTitleSize(0.22) gStyle.SetTitleFontSize(10) gStyle.SetTitleFont(font) gStyle.SetTitleFont(font, "xyz") gStyle.SetTitleYOffset(1.0) gStyle.SetTitleXOffset(1.0) gStyle.SetTitleXSize(0.04) gStyle.SetTitleYSize(0.04) gStyle.SetTitleX(.15) gStyle.SetTitleY(.98) gStyle.SetTitleW(.70) gStyle.SetTitleH(.05) # statistics box gStyle.SetOptStat(0) gStyle.SetStatFont(font) gStyle.SetStatFontSize(10) gStyle.SetStatX(.91) gStyle.SetStatY(.90) gStyle.SetStatW(.15) gStyle.SetStatH(.15) # axis labels gStyle.SetLabelFont(font) gStyle.SetLabelFont(font, "xyz") gStyle.SetLabelSize(10, "xyz") # gStyle.SetGridColor(1) gStyle.SetLegendBorderSize(1)
def initStyle(): gROOT.SetStyle("Plain") gStyle.SetOptFit() gStyle.SetOptStat(0) # For the canvas: gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetCanvasDefH(700) #Height of canvas gStyle.SetCanvasDefW(700) #Width of canvas gStyle.SetCanvasDefX(0) #POsition on screen gStyle.SetCanvasDefY(0) # For the Pad: gStyle.SetPadBorderMode(0) # gStyle.SetPadBorderSize(Width_t size = 1) gStyle.SetPadColor(kWhite) gStyle.SetPadGridX(True) gStyle.SetPadGridY(True) gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) # For the frame: gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillColor(0) gStyle.SetFrameFillStyle(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) # For the histo: # gStyle.SetHistFillColor(1) # gStyle.SetHistFillStyle(0) gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(1) # gStyle.SetLegoInnerR(Float_t rad = 0.5) # gStyle.SetNumberContours(Int_t number = 20) #gStyle.SetEndErrorSize(2) #gStyle.SetErrorMarker(20) #gStyle.SetErrorX(0.) #gStyle.SetMarkerStyle(20) #For the fit/function: gStyle.SetOptFit(1) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(2) #For the date: gStyle.SetOptDate(0) # gStyle.SetDateX(Float_t x = 0.01) # gStyle.SetDateY(Float_t y = 0.01) # For the statistics box: gStyle.SetOptFile(0) gStyle.SetOptStat(0) # To display the mean and RMS: SetOptStat("mr") gStyle.SetStatColor(kWhite) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.025) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.15) # gStyle.SetStatStyle(Style_t style = 1001) # gStyle.SetStatX(Float_t x = 0) # gStyle.SetStatY(Float_t y = 0) # Margins: #gStyle.SetPadTopMargin(0.15) gStyle.SetPadTopMargin(0.05) #gStyle.SetPadBottomMargin(0.13) gStyle.SetPadLeftMargin(0.16) gStyle.SetPadRightMargin(0.04) # top group adaption, original is 0.02 gStyle.SetPadBottomMargin(0.13) # For the Global title: gStyle.SetOptTitle(0) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1) gStyle.SetTitleTextColor(1) gStyle.SetTitleFillColor(10) # gStyle.SetTitleFontSize(0.05) # gStyle.SetTitleH(0) # Set the height of the title box # gStyle.SetTitleW(0) # Set the width of the title box # gStyle.SetTitleX(0.35) # Set the position of the title box # gStyle.SetTitleY(0.986) # Set the position of the title box # gStyle.SetTitleStyle(Style_t style = 1001) #gStyle.SetTitleBorderSize(0) # For the axis titles: gStyle.SetTitleColor(1, "XYZ") gStyle.SetTitleFont(42, "XYZ") #gStyle.SetTitleSize(0.06, "XYZ") #gStyle.SetTitleSize(0.06, "XYZ") # gStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size? # gStyle.SetTitleYSize(Float_t size = 0.02) gStyle.SetTitleXOffset(0.9) gStyle.SetTitleYOffset(1.25) #gStyle.SetTitleOffset(1.1, "Y") # Another way to set the Offset # For the axis labels: gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelOffset(0.007, "XYZ") #gStyle.SetLabelSize(0.05, "XYZ") #gStyle.SetLabelSize(0.04, "XYZ") # For the axis: gStyle.SetAxisColor(1, "XYZ") gStyle.SetStripDecimals(True) gStyle.SetTickLength(0.03, "XYZ") gStyle.SetNdivisions(510, "XYZ") gStyle.SetPadTickX( 1) # To get tick marks on the opposite side of the frame gStyle.SetPadTickY(1) # Change for log plots: gStyle.SetOptLogx(0) gStyle.SetOptLogy(0) gStyle.SetOptLogz(0) gStyle.SetPalette(1) #(1,0) # another top group addition gStyle.SetHatchesSpacing(1.0) # Postscript options: gStyle.SetPaperSize(20., 20.) #gStyle.SetPaperSize(TStyle.kA4) #gStyle.SetPaperSize(27., 29.7) #TGaxis.SetMaxDigits(3) # gStyle.SetLineScalePS(Float_t scale = 3) # gStyle.SetLineStyleString(Int_t i, const char* text) # gStyle.SetHeaderPS(const char* header) # gStyle.SetTitlePS(const char* pstitle) #gStyle.SetColorModelPS(1) # gStyle.SetBarOffset(Float_t baroff = 0.5) # gStyle.SetBarWidth(Float_t barwidth = 0.5) # gStyle.SetPaintTextFormat(const char* format = "g") # gStyle.SetPalette(Int_t ncolors = 0, Int_t* colors = 0) # gStyle.SetTimeOffset(Double_t toffset) # gStyle.SetHistMinimumZero(kTRUE) #gStyle.cd() print "TDR Style initialized"
def initialize(fitresults=True, grid=False): gROOT.SetStyle("Plain") gStyle.SetOptFit() gStyle.SetOptStat(0) # For the canvas: gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasColor(kWhite) gStyle.SetCanvasDefH(600) #Height of canvas gStyle.SetCanvasDefW(600) #Width of canvas gStyle.SetCanvasDefX(0) #POsition on screen gStyle.SetCanvasDefY(0) # For the Pad: gStyle.SetPadBorderMode(0) gStyle.SetPadColor(kWhite) gStyle.SetPadGridX(False) gStyle.SetPadGridY(False) gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) # For the frame: gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillColor(kWhite) gStyle.SetFrameFillStyle(1000) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) gStyle.SetFrameLineWidth(1) # For the histo: gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(2) gStyle.SetEndErrorSize(2) gStyle.SetErrorX(0.) gStyle.SetMarkerStyle(20) #For the fit/function: gStyle.SetOptFit(1) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) #For the date: gStyle.SetOptDate(0) # For the statistics box: gStyle.SetOptFile(0) gStyle.SetOptStat(0) # To display the mean and RMS: SetOptStat("mr") gStyle.SetStatColor(kWhite) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.025) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.15) # Margins: gStyle.SetPadTopMargin(0.05) gStyle.SetPadLeftMargin(0.16) gStyle.SetPadRightMargin(0.04) # top group adaption, original is 0.02 gStyle.SetPadBottomMargin(0.13) # For the Global title: gStyle.SetOptTitle(0) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1) gStyle.SetTitleTextColor(1) gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.05) # For the axis titles: gStyle.SetTitleColor(1, "XYZ") gStyle.SetTitleFont(42, "XYZ") gStyle.SetTitleSize(0.06, "XYZ") gStyle.SetTitleXOffset(0.9) gStyle.SetTitleYOffset(1.25) # For the axis labels: gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42, "XYZ") gStyle.SetLabelOffset(0.007, "XYZ") gStyle.SetLabelSize(0.05, "XYZ") #gStyle.SetLabelSize(0.04, "XYZ") # For the axis: gStyle.SetAxisColor(1, "XYZ") gStyle.SetStripDecimals(True) gStyle.SetTickLength(0.03, "XYZ") gStyle.SetNdivisions(510, "XYZ") gStyle.SetPadTickX(1) # To get tick marks on the opposite side of the frame gStyle.SetPadTickY(1) # Change for log plots: gStyle.SetOptLogx(0) gStyle.SetOptLogy(0) gStyle.SetOptLogz(0) gStyle.SetPalette(1) #(1,0) # another top group addition gStyle.SetHatchesSpacing(1.0) # Postscript options: gStyle.SetPaperSize(20., 20.) # For graphs gStyle.SetErrorX(0) # suppress error along x if grid: gStyle.SetPadGridX(gridOn) gStyle.SetPadGridY(gridOn) gStyle.SetGridColor(kGray)
def tdrstyle(): gROOT.SetStyle("Plain") gStyle.SetAxisColor(1, "XYZ") gStyle.SetCanvasColor(0) #gStyle.SetCanvasBorderSize(10) gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasDefH(700) gStyle.SetCanvasDefW(700) gStyle.SetCanvasDefX(0) gStyle.SetCanvasDefY(0) gStyle.SetFitFormat("5.4g") gStyle.SetFuncColor(2) gStyle.SetFuncStyle(1) gStyle.SetFuncWidth(1) gStyle.SetFrameBorderMode(0) gStyle.SetFrameBorderSize(1) gStyle.SetFrameFillStyle(0) gStyle.SetFrameFillColor(0) gStyle.SetFrameLineColor(1) gStyle.SetFrameLineStyle(1) # 0? gStyle.SetFrameLineWidth(1) # 1? gStyle.SetGridColor(0) gStyle.SetGridStyle(3) gStyle.SetGridWidth(1) #gStyle.SetHistFillColor(1) #gStyle.SetHistFillStyle(0) gStyle.SetHistLineColor(1) gStyle.SetHistLineStyle(0) gStyle.SetHistLineWidth(1) gStyle.SetLabelColor(1, "XYZ") gStyle.SetLabelFont(42,"XYZ") gStyle.SetLabelOffset(0.007,"XYZ") # 0.010? gStyle.SetLabelSize(0.05,"XYZ") # 0.04? gStyle.SetLegendBorderSize(0) gStyle.SetLegendFillColor(0) gStyle.SetLegendFont(42) gStyle.SetMarkerSize(1.0) gStyle.SetMarkerStyle(20) gStyle.SetLineColor(1) gStyle.SetLineWidth(2) #gStyle.SetLineScalePS(2) gStyle.SetOptDate(0) gStyle.SetOptFile(0) gStyle.SetOptFit(1) gStyle.SetOptStat(0) gStyle.SetOptTitle(0) #gStyle.SetOptLogx(0) #gStyle.SetOptLogy(0) #gStyle.SetOptLogz(0) gStyle.SetPadColor(0) gStyle.SetPadBorderMode(0) gStyle.SetPadBorderSize(10) gStyle.SetPadTopMargin(0.05) # 0.08? gStyle.SetPadBottomMargin(0.13) gStyle.SetPadLeftMargin(0.16) gStyle.SetPadRightMargin(0.03) # 0.05? gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) gStyle.SetStatColor(0) gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.025) gStyle.SetStatTextColor(1) gStyle.SetStatFormat("6.4g") gStyle.SetStatBorderSize(1) gStyle.SetStatH(0.1) gStyle.SetStatW(0.15) #gStyle.SetStatX(0) #gStyle.SetStatY(0) #gStyle.SetTextSize(0.055) gStyle.SetTextFont(42) gStyle.SetTitleBorderSize(0) gStyle.SetTitleColor(1) gStyle.SetTitleFont(42) gStyle.SetTitleColor(1,"XYZ") gStyle.SetTitleFont(42,"XYZ") gStyle.SetTitleSize(0.06,"XYZ") # 0.05? #gStyle.SetTitleOffset(1.4,"XYZ") gStyle.SetTitleOffset(0.9,"X") gStyle.SetTitleOffset(1.20,"Y") gStyle.SetTitleFillColor(10) gStyle.SetTitleFontSize(0.05) gStyle.SetTitleTextColor(1) #gStyle.SetTitleH(0) #gStyle.SetTitleW(0) #gStyle.SetTitleX(0) #gStyle.SetTitleY(0.985) #gStyle.SetTitleStyle(1001) gStyle.SetPalette(1) #gStyle.SetNdivisions(510, "XYZ") # 505? gStyle.SetNdivisions(505, "XYZ") gStyle.SetEndErrorSize(2) # 2? #gStyle.SetErrorMarker(20) #gStyle.SetErrorX(0.) #gStyle.SetPaperSize(20.,20.) gStyle.SetStripDecimals(1) gStyle.SetTickLength(0.03, "XYZ") return 1
def plotAndFit(self): # Plot self.setstyle() # Get D0 histogram out of file 'loadFile' h1 = self.loadFile.Get('hist') h1.UseCurrentStyle() # Plot D0 mass distribution before fit c1 = TCanvas('c1', 'Canvas1', 0, 0, 700, 500) c1.Clear() h1.Draw() c1.Update() c1.SaveAs('D0.pdf') # Fit h1 with Breit-Wigner distribution breitW = TF1('breitW', BreitWig, 1.7, 2.0, 5) breitW.SetNpx(1000) fkt = TF1("fkt", "gaus", 1.8, 1.95) # The value given in breitW.SetParameter(1, 1.8648) is the # PDG value of the D0 mass breitW.SetParameter(0, 0.05) # Width breitW.SetParameter(1, 1.8648) # Mean Value breitW.SetParameter(2, 0.1) # Norm breitW.SetParameter(3, 1.75) # Bkg parameter 1 breitW.SetParameter(4, 0.0) # Bkg parameter 2 gStyle.SetStatH(0.4) # Choose fit options: Print fit probability, # chisquare/number of degress of freedom, # errors, name/value of parameters gStyle.SetOptFit(1111) h1.UseCurrentStyle() # Start fit with breitW h1.Fit("breitW") self.breitWFit = breitW.Clone() #h1.Fit("fkt") #mean = fkt.GetParameter(1) #error = fkt.GetParError(1) #fkt.SetLineColor(3) #fkt.Draw("SAME") breitW.Draw("same") c1.Update() c1.SaveAs("Fit_gaus.pdf") print "width=", breitW.GetParameter(0), " mean=", breitW.GetParameter( 1) #print "sigma=",fkt.GetParameter(2)," gauss_mean=",mean x_min = 1.8 x_max = 1.95 # def sigToBkgRatio(self, x_min, x_max): ges = self.breitWFit.Integral(x_min, x_max) bkg_fkt_1 = TF1("bkg_fkt_1", bkg1, 1.7, 2.0, 5) bkg_fkt_2 = TF1("bkg_fkt_2", bkg2, 1.7, 2.0, 5) bkg_fkt_3 = TF1("bkg_fkt_3", bkg3, 1.7, 2.0, 5) print par bkg_1 = bkg_fkt_1.Integral(x_min, x_max) print bkg_1 bkg_2 = bkg_fkt_2.Integral(x_min, x_max) print bkg_2 bkg_3 = bkg_fkt_3.Integral(x_min, x_max) print bkg_3 sbr1 = (ges - bkg_1) / bkg_1 sbr2 = (ges - bkg_2) / bkg_2 sbr3 = (ges - bkg_3) / bkg_3 print "signal-to-background ratio between ", x_min, " and ", x_max, " for linear background:\n (S/B)_lin= ", sbr1, "\n\n\n" print "signal-to-background ratio between ", x_min, " and ", x_max, " for exponential background:\n (S/B)_exp= ", sbr2, "\n\n\n" print "signal-to-background ratio between ", x_min, " and ", x_max, " for quadratic background:\n (S/B)_quad= ", sbr2, "\n\n\n"