import ROOT,glob,math,sys,subprocess,copy,os,commands sys.path.append('$PANDAPATH/macro/tpc/FOPI/mberger') pandapath=os.environ.get('PANDAPATH') sys.path.append(pandapath+'/macro/tpc/FOPI/python/argparse-1.2.1') import argparse from anaFile import anaFile from functions import * parser=argparse.ArgumentParser(description='compare clerr graph files') parser.add_argument('files',help='the graph files (run_clrr.py output)',type=str,nargs='+') parser.add_argument('--list',help='the input file is a list',action='store_true') parser.add_argument('--titles',help='the titles to use for the files',type=str,nargs='+',default=['None']) parser.add_argument('--entries',help='the entries to use',type=str,nargs=2) parser.add_argument('--hlp',help='print help',action='store_true') args=parser.parse_args() ROOT.gROOT.ProcessLine(".x rootlogon.C") ROOT.gROOT.ProcessLine('gROOT->SetStyle("Plain")') set_palette() colors=getColors() if args.hlp: parser.print_help() exit(0) if args.list: listfile=open(args.files[0],'r') files=[] titles=[] fcol=[] entries=[] fcolcounter=-1 for line in listfile: fcolcounter+=1 if line[0]=='#' or line[0]=='\n': continue words=line.split(';') files.append(str(words[0])) titles.append(str(words[1]).replace('\n','')) fcol.append(fcolcounter) entries.append(words[2].replace('\n','')) listfile.close() else: files=args.files entries=args.entries if args.titles[0]=='None' and not args.list: titles=range(len(files)) for i in range(len(titles)): titles[i]=str(titles[i]) gsigfA=[] gsigfA_diff=[] gsigfA_mdiff=[] gsigA=[] gsigA_diff=[] gsigA_mdiff=[] for i in range(3): gsigfA_mdiff.append(ROOT.TH1D("hsigfA_meandiff"+str(i),'Mean Diff Sig fA',len(files),0,len(files))) gsigA_mdiff.append(ROOT.TH1D("hsigA_meandiff"+str(i),'Mean Diff Sig A',len(files),0,len(files))) counter=-1 for f in files: print f counter+=1 rfile=ROOT.TFile(f,'read') phies=entries[counter].split(':') gsigfA.append([]) gsigA.append([]) for phi in phies: gsigfA[counter].append([]) gsigA[counter].append([]) for i in range(3): gsigfA[counter][-1].append(rfile.Get('hErrA'+str(i+1)+'rAmpVsZ_Sigma_'+phi)) gsigA[counter][-1].append(rfile.Get('RMS hErrA'+str(i+1)+'rAmpVsZ'+phi)) gsigfA_diff.append([]) gsigA_diff.append([]) for i in range(3): meandiff=0 diff_counter=-1 gsigfA_diff[counter].append(ROOT.TGraph()) for j in range(gsigfA[counter][0][i].GetNbinsX()): diff_counter+=1 gsigfA_diff[counter][i].SetPoint(diff_counter,diff_counter, abs(gsigfA[counter][0][i].GetBinContent(j+1)- gsigfA[counter][1][i].GetBinContent(j+1))) if j<5 and gsigfA[counter][1][i].GetBinContent(j+1) >0 : meandiff+=abs(gsigfA[counter][0][i].GetBinContent(j+1)-gsigfA[counter][1][i].GetBinContent(j+1))/gsigfA[counter][0][i].GetBinContent(j+1) meandiff/=5. gsigfA_mdiff[i].Fill(counter,meandiff) diff_counter=-1 meandiff=0 gsigA_diff[counter].append(ROOT.TGraph()) for j in range(gsigA[counter][0][i].GetN()): diff_counter+=1 x1, y1 = ROOT.Double(0), ROOT.Double(0) x2, y2 = ROOT.Double(0), ROOT.Double(0) gsigA[counter][0][i].GetPoint(j,x1,y1) gsigA[counter][1][i].GetPoint(j,x2,y2) gsigA_diff[counter][i].SetPoint(diff_counter,diff_counter,abs(y1-y2)) if j <2 and y1>0: meandiff+=abs(y1-y2)/y1 meandiff/=2 gsigA_mdiff[i].Fill(counter,meandiff) csigf_diff=ROOT.TCanvas('csigf_diff','sigf_diff',700,1000) csigf_diff.Divide(1,3) csig_diff=ROOT.TCanvas('csig_diff','sig_diff',700,1000) csig_diff.Divide(1,3) opt='AP' colors=getColors() fcounter=-1 leg=ROOT.TLegend(0,0,1,1) leg.SetFillColor(0) leg.SetTextSize(0.05) legp=[] cleg=ROOT.TCanvas('cleg','Diff Leg',600,1000) for files_g in gsigfA_diff: fcounter+=1 gcounter=-1 for graph in files_g: gcounter+=1 csigf_diff.cd(gcounter+1) graph.SetMarkerStyle(20) graph.SetMarkerSize(0.6) graph.SetMarkerColor(colors[fcounter]) graph.Draw(opt) legp.append(ROOT.TPolyMarker()) legp[-1].SetMarkerStyle(graph.GetMarkerStyle()) legp[-1].SetMarkerSize(2.5) legp[-1].SetMarkerColor(graph.GetMarkerColor()) leg.AddEntry(legp[-1],titles[fcounter],'p') opt='P' opt='AP' fcounter=-1 for files_g in gsigA_diff: fcounter+=1 gcounter=-1 for graph in files_g: gcounter+=1 csig_diff.cd(gcounter+1) graph.SetMarkerStyle(20) graph.SetMarkerSize(0.6) graph.SetMarkerColor(colors[fcounter]) graph.Draw(opt) opt='P' cleg.cd() leg.Draw() cleg.Update() csigf_diff.Update() csig_diff.Update() csigf_mdiff=ROOT.TCanvas('csigf_mdiff','sigf mdiff',700,1000) csigf_mdiff.Divide(1,3) csig_mdiff=ROOT.TCanvas('csig_mdiff','sig mdiff',700,1000) csig_mdiff.Divide(1,3) for i in range(3): for j in range(gsigfA_mdiff[i].GetNbinsX()): label=titles[j].split('_') label=label[0][7:len(label[0])]+':'+label[1][4:len(label[1])]+":"+label[2][3:len(label[2])] gsigfA_mdiff[i].GetXaxis().SetBinLabel(j+1,label) gsigA_mdiff[i].GetXaxis().SetBinLabel(j+1,label) # gsigfA_mdiff[i].SetFillColor(ROOT.kViolet+4) csigf_mdiff.cd(i+1) gsigfA_mdiff[i].SetStats(0) gsigfA_mdiff[i].GetXaxis().SetLabelSize(0.09) gsigfA_mdiff[i].GetYaxis().SetLabelSize(0.09) gsigfA_mdiff[i].Draw() gsigfA_mdiff[i].Draw("same text45") csig_mdiff.cd(i+1) gsigA_mdiff[i].SetStats(0) gsigA_mdiff[i].GetXaxis().SetLabelSize(0.09) gsigA_mdiff[i].GetYaxis().SetLabelSize(0.09) gsigA_mdiff[i].Draw() gsigA_mdiff[i].Draw("same text45") csigf_mdiff.Update() csig_mdiff.Update() u=raw_input('done?')