import ROOT,glob,math,argparse,sys, os import numpy as np from anaFile import anaFile from functions import * parser=argparse.ArgumentParser(description="plot the McResX vs z graph") parser.add_argument('path',help='path to the hisos',type=str) parser.add_argument('ra',help='force variation',type=int) parser.add_argument('--hlp',help='print help',action='store_true') parser.add_argument('--dLs',help='only dLs',action='store_true') parser.add_argument('--Bend',help='only Bending',action='store_true') parser.add_argument('--shortcuts',help='only ShortCuts',action='store_true') parser.add_argument('--rot',help='only Bending',action='store_true') parser.add_argument('--pdir',help='the picture print directory',type=str,default="not") parser.add_argument('--titles',help='the titles to plot in legend and canvas for the files', type=str,nargs='+',default=None) args=parser.parse_args() ROOT.gROOT.ProcessLine(".x rootlogon.C") ROOT.gROOT.ProcessLine('gStyle->SetPalette(1)') ROOT.gROOT.ProcessLine('gROOT->SetStyle("Plain")') if args.hlp: parser.print_help() exit(0) c1 = ROOT.TCanvas("c1", "reldiff3d", 700,500) c2 = ROOT.TCanvas("c2", "reldiff3d", 700,500) graphsX=[] graphsXRMS=[] for grX in range(args.ra): graphX=ROOT.TGraph() graphX.SetMarkerColor(grX+9) graphX.SetMarkerSize(2) graphX.SetMarkerStyle(23) graphsX.append(graphX) for grXRMS in range(args.ra): graphXRMS=ROOT.TGraph() graphXRMS.SetMarkerColor(grXRMS+9) graphXRMS.SetMarkerSize(2) graphXRMS.SetMarkerStyle(23) graphsXRMS.append(graphXRMS) HistList = os.listdir(args.path) HistList.sort() for H in HistList: print H parameter=[] scho=0 cou=0 for his in range(len(HistList)): if HistList[cou]==".svn": continue parameter.append([]) name=HistList[cou] print name if args.dLs: if args.shortcuts: dLs=scho else: dLs=float(name[31:34]) force=float(0) elif args.Bend: dLs=float(4.7) force=float(name[51:56]) elif args.rot: dLs=float(4.7) print name[58:61] force=float(name[58:63]) else: dLs=float(name[31:34]) force=float(name[51:56]) parameter[cou].append(dLs) parameter[cou].append(force) hfile=args.path + HistList[his] histo=open(hfile, "r") histo=np.genfromtxt(hfile) print histo me = float(histo[0]) rms= float((histo[1])) print me, rms parameter[cou].append(me) parameter[cou].append(rms) cou+=1 scho+=1 count = -1 bins=0 bini=10 for xr in range(len(parameter)): count+=1 if args.Bend or args.rot: graphsX[count].SetPoint(bins, parameter[xr][1], parameter[xr][2]) graphsXRMS[count].SetPoint(bins, parameter[xr][1], parameter[xr][3]) else: graphsX[count].SetPoint(bins, parameter[xr][0], parameter[xr][2]) graphsXRMS[count].SetPoint(bins, parameter[xr][0], parameter[xr][3]) if count+1 == args.ra: count=-1 bins+=1 legX = ROOT.TLegend(0.6,0.7,0.90,0.9) legXRMS = ROOT.TLegend(0.6,0.7,0.90,0.9) GraphX=ROOT.TMultiGraph() GraphXRMS=ROOT.TMultiGraph() for a in parameter: print a for gr in range(len(graphsX)): if args.Bend or args.rot: name="dLs"+str(parameter[gr][0])+" N" else: name="Force"+str(parameter[gr][1])+" N" legX.AddEntry(graphsX[gr],name,"PE") GraphX.Add(graphsX[gr]) legXRMS.AddEntry(graphsXRMS[gr],name,"PE") GraphXRMS.Add(graphsXRMS[gr]) if args.Bend: GraphX.SetTitle("Relative Difference 3D: X Residuals - Mean; Force [N]; mean"); GraphXRMS.SetTitle("Relative Difference 3D: X Residuals - sigma; Force [N]; sigma"); elif args.rot: GraphX.SetTitle("Relative Difference 3D: X Residuals - Mean; Theta [Degree]; mean"); GraphXRMS.SetTitle("Relative Difference 3D: X Residuals - sigma; Theta [Degree]; sigma"); else: if args.shortcuts: GraphX.SetTitle("Relative Difference 3D: X Residuals - Mean; ; mean"); GraphXRMS.SetTitle("Relative Difference 3D: X Residuals - sigma; ; sigma"); else: GraphX.SetTitle("Relative Difference 3D: X Residuals - Mean; dLs [cm]; mean"); GraphXRMS.SetTitle("Relative Difference 3D: X Residuals - sigma; dLs [cm]; sigma"); c1.SetGrid(1,1) c1.cd() GraphX.Draw("AP") #legX.Draw("SAME") c1.Update() c2.SetGrid(1,1) c2.cd() GraphXRMS.Draw("AP") #legX.Draw("SAME") c2.Update() x = raw_input()