#!/usr/bin/env python """ Rescale all the histograms contained in a DetResponseFile options: -f : DRF/ingredients ROOT file default=$AADIR/data/aanet_detresponse.cut2.v1.0.0.root -o : path for the output default=$AADIR/data/ -N : number of lines default=115 -h : help message and exit default=False -i : Python interative mode (prompt when done) default=False """ import aa, ROOT, sys, itertools from ROOT import TH1,TH2,TH3 options = aa.Options( __doc__.split("options:")[1], sys.argv[1:] ) def combine_detresp(detres1,detres2,deters_out): f1=ROOT.TFile(detres1,"READ") f2=ROOT.TFile(detres2,"READ") outfile= ROOT.TFile(deters_out,"RECREATE") counter=0 for obj in f1.GetListOfKeys(): # loop on all the objects in TFile if "TH" in obj.GetClassName(): # only histos h1=obj.ReadObj() h2=f2.Get(h1.GetName()) h3=h1 h3.Add(h2) h3.Write() counter=counter+1 print(counter) f1.Close() f2.Close() outfile.Close() def rescale_detresp(): f=ROOT.TFile(options.f,"READ") resc=options.N/float(115) print(resc) filename=options.o+"aanet_detresponse.cut2.v1.0.0."+str(options.N)+".root" print(filename) outfile= ROOT.TFile(filename,"RECREATE") counter=0 for obj in f.GetListOfKeys(): # loop on all the objects in TFile if "TH" in obj.GetClassName(): # only histos h=obj.ReadObj() # DEBUG #if "EFFNUCL" in obj.GetName() and "nueCC" in obj.GetName() :print (obj.GetName(),h.GetName()) h.Scale(resc) h.Write() counter=counter+1 print(counter) f.Close() outfile.Close() def compare_detresp(detres1,detres2): f1=ROOT.TFile(detres1,"READ") f2=ROOT.TFile(detres2,"READ") counter=0 ratio_prev=0 for obj in f1.GetListOfKeys(): # loop on all the objects in TFile if "TH" in obj.GetClassName(): # only histos h1=obj.ReadObj() h2=f2.Get(h1.GetName()) if counter >0: ratio_prev=ratio if(h1.Integral()!=0 and h2.Integral()!=0): ratio=(h1.Integral()/h2.Integral()) if(counter>0 and round(ratio_prev,6) != round(ratio,6)): print("DetectorResponse ", detres1," and ",detres2," are different (not only rescaled)") return -999 counter=counter+1 f1.Close() f2.Close() return round(ratio,6) #MAIN rescale_detresp() #detres1="$AADIR/data/aanet_detresponse.cut2.v1.0.0.root" #detres2="$AADIR/data/aanet_detresponse.cut2.v1.0.0.115.root" #detres3="$AADIR/data/aanet_detresponse.cut2.v1.0.0.75.root" #detres4="$AADIR/data/aanet_detresponse.cut2.v1.0.0.25.root" #detres5="$AADIR/data/aanet_detresponse.cut2.v1.0.0.140.root" #detres6="$AADIR/data/aanet_detresponse.cut2.v1.0.0.115+25.root" #ratio=compare_detresp(detres5,detres6) #print(ratio) #deters_out="$AADIR/data/aanet_detresponse.cut2.v1.0.0.25+115.root" #combine_detresp(detres2,detres4,deters_out)