ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/gethistofromtree.py
(Generate patch)

Comparing UserCode/VHbb/python/gethistofromtree.py (file contents):
Revision 1.7 by peller, Thu Aug 2 16:03:52 2012 UTC vs.
Revision 1.16 by peller, Tue Oct 9 21:17:34 2012 UTC

# Line 9 | Line 9 | from BetterConfigParser import BetterCon
9   import sys
10  
11  
12 < #load config
13 < config = BetterConfigParser()
14 < config.read('./config')
15 <
16 < #get locations:
17 < Wdir=config.get('Directories','Wdir')
18 < anaTag=config.get('Analysis','tag')
19 <
20 <
21 <
22 < def getScale(job,rescale,subsample=-1):
23 <    input = TFile.Open(job.getpath())
12 > def getScale(job,path,config,rescale,subsample=-1):
13 >    anaTag=config.get('Analysis','tag')
14 >    input = TFile.Open(path+'/'+job.getpath())
15      CountWithPU = input.Get("CountWithPU")
16      CountWithPU2011B = input.Get("CountWithPU2011B")
17      #print lumi*xsecs[i]/hist.GetBinContent(1)
# Line 40 | Line 31 | def getScale(job,rescale,subsample=-1):
31          theScale = float(job.lumi)*xsec*sf/(CountWithPU.GetBinContent(1))*rescale/float(job.split)
32      return theScale
33  
34 < def getHistoFromTree(job,options,rescale=1,subsample=-1):
34 > def getHistoFromTree(job,path,config,options,rescale=1,subsample=-1,which_weightF='weightF'):
35 >
36 >    #print job.getpath()
37 >    #print options
38      treeVar=options[0]
39      if subsample>-1:
40          name=job.subnames[subsample]
# Line 53 | Line 47 | def getHistoFromTree(job,options,rescale
47      nBins=int(options[3])
48      xMin=float(options[4])
49      xMax=float(options[5])
50 +    #addOverFlow=eval(config.get('Plot_general','addOverFlow'))
51 +    addOverFlow = False
52  
53      if job.type != 'DATA':
54 <        cutcut=config.get('Cuts',options[7])
55 <        if subsample>0:
54 >    
55 >        if type(options[7])==str:
56 >            cutcut=config.get('Cuts',options[7])
57 >        elif type(options[7])==list:
58 >            cutcut=config.get('Cuts',options[7][0])
59 >            cutcut=cutcut.replace(options[7][1],options[7][2])
60 >            #print cutcut
61 >        if subsample>-1:
62              treeCut='%s & %s & EventForTraining == 0'%(cutcut,job.subcuts[subsample])        
63          else:
64              treeCut='%s & EventForTraining == 0'%(cutcut)
65  
66      elif job.type == 'DATA':
67          cutcut=config.get('Cuts',options[8])
68 <        treeCut='%s & EventForTraining == 0'%(cutcut)
68 >        treeCut='%s'%(cutcut)
69  
70  
71 <    input = TFile.Open(job.getpath(),'read')
71 >    input = TFile.Open(path+'/'+job.getpath(),'read')
72  
73      Tree = input.Get(job.tree)
74      #Tree=tmpTree.CloneTree()
75      #Tree.SetDirectory(0)
76      
77      #Tree=tmpTree.Clone()
78 <    weightF=config.get('Weights','weightF')
78 >    weightF=config.get('Weights',which_weightF)
79      #hTree = ROOT.TH1F('%s'%name,'%s'%title,nBins,xMin,xMax)
80      #hTree.SetDirectory(0)
81      #hTree.Sumw2()
# Line 103 | Line 105 | def getHistoFromTree(job,options,rescale
105      #print job.name + ' Sumw2', hTree.GetEntries()
106  
107      if job.type != 'DATA':
108 <        ScaleFactor = getScale(job,rescale,subsample)
108 >        ScaleFactor = getScale(job,path,config,rescale,subsample)
109          if ScaleFactor != 0:
110              hTree.Scale(ScaleFactor)
111 +    
112 +    if addOverFlow:
113 +            print 'Adding overflow'
114 +            uFlow = hTree.GetBinContent(0)+hTree.GetBinContent(1)
115 +            oFlow = hTree.GetBinContent(hTree.GetNbinsX()+1)+hTree.GetBinContent(hTree.GetNbinsX())
116 +            uFlowErr = ROOT.TMath.Sqrt(ROOT.TMath.Power(hTree.GetBinError(0),2)+ROOT.TMath.Power(hTree.GetBinError(1),2))
117 +            oFlowErr = ROOT.TMath.Sqrt(ROOT.TMath.Power(hTree.GetBinError(hTree.GetNbinsX()),2)+ROOT.TMath.Power(hTree.GetBinError(hTree.GetNbinsX()+1),2))
118 +            hTree.SetBinContent(1,uFlow)
119 +            hTree.SetBinContent(hTree.GetNbinsX(),oFlow)
120 +            hTree.SetBinError(1,uFlowErr)
121 +            hTree.SetBinError(hTree.GetNbinsX(),oFlowErr)
122 +              
123              
124      print '\t-->import %s\t Integral: %s'%(job.name,hTree.Integral())
125              
126      hTree.SetDirectory(0)
127      input.Close()  
128      
115              
116    
129      return hTree, group
130      
131  
# Line 140 | Line 152 | def orderandadd(histos,typs,setup):
152      histos=ordnung
153      typs=ordnungtyp
154  
155 +    print typs
156 +
157      for k in range(0,len(num)):
158          for m in range(0,num[k]):
159              if m > 0:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines