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.12 by peller, Thu Sep 20 13:10:53 2012 UTC vs.
Revision 1.22 by peller, Wed Jan 16 16:22:46 2013 UTC

# Line 1 | Line 1
1 from samplesclass import sample
2 from printcolor import printc
1   import pickle
2   import ROOT
3   from ROOT import TFile, TTree
4   import ROOT
5   from array import array
8 from BetterConfigParser import BetterConfigParser
6   import sys
7 <
7 > from myutils import sample, printc
8  
9   def getScale(job,path,config,rescale,subsample=-1):
10      anaTag=config.get('Analysis','tag')
11 <    input = TFile.Open(path+'/'+job.getpath())
12 <    CountWithPU = input.Get("CountWithPU")
13 <    CountWithPU2011B = input.Get("CountWithPU2011B")
11 >    inputfile = TFile.Open(path+'/'+job.getpath())
12 >    CountWithPU = inputfile.Get("CountWithPU")
13 >    CountWithPU2011B = inputfile.Get("CountWithPU2011B")
14      #print lumi*xsecs[i]/hist.GetBinContent(1)
15      
16      if subsample>-1:
17 <        xsec=float(job.xsec[subsample])
17 >        if type(job.xsec[subsample]) == str: xsec=float(eval(job.xsec[subsample]))
18 >        else: xsec=float(job.xsec[subsample])
19          sf=float(job.sf[subsample])
20      else:
21 <        xsec=float(job.xsec)
21 >        if type(job.xsec) == str: xsec=float(eval(job.xsec))
22 >        else: xsec=float(job.xsec)
23          sf=float(job.sf)
24      
25      
# Line 29 | Line 28 | def getScale(job,path,config,rescale,sub
28          theScale = float(job.lumi)*xsec*sf/(0.46502*CountWithPU.GetBinContent(1)+0.53498*CountWithPU2011B.GetBinContent(1))*rescale/float(job.split)
29      elif anaTag == '8TeV':
30          theScale = float(job.lumi)*xsec*sf/(CountWithPU.GetBinContent(1))*rescale/float(job.split)
31 +    inputfile.Close()
32      return theScale
33  
34   def getHistoFromTree(job,path,config,options,rescale=1,subsample=-1,which_weightF='weightF'):
# Line 47 | Line 47 | def getHistoFromTree(job,path,config,opt
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 +    TrainFlag = eval(config.get('Analysis','TrainFlag'))
54 +    if TrainFlag: traincut = " & EventForTraining == 0"
55 +    if not TrainFlag: traincut=""
56  
57      if job.type != 'DATA':
58      
# Line 55 | Line 61 | def getHistoFromTree(job,path,config,opt
61          elif type(options[7])==list:
62              cutcut=config.get('Cuts',options[7][0])
63              cutcut=cutcut.replace(options[7][1],options[7][2])
64 <            print cutcut
64 >            #print cutcut
65          if subsample>-1:
66 <            treeCut='%s & %s & EventForTraining == 0'%(cutcut,job.subcuts[subsample])        
66 >            treeCut='%s & %s%s'%(cutcut,job.subcuts[subsample],traincut)        
67          else:
68 <            treeCut='%s & EventForTraining == 0'%(cutcut)
68 >            treeCut='%s%s'%(cutcut,traincut)
69  
70      elif job.type == 'DATA':
71          cutcut=config.get('Cuts',options[8])
# Line 106 | Line 112 | def getHistoFromTree(job,path,config,opt
112          ScaleFactor = getScale(job,path,config,rescale,subsample)
113          if ScaleFactor != 0:
114              hTree.Scale(ScaleFactor)
115 +    
116 +    if addOverFlow:
117 +            print 'Adding overflow'
118 +            uFlow = hTree.GetBinContent(0)+hTree.GetBinContent(1)
119 +            oFlow = hTree.GetBinContent(hTree.GetNbinsX()+1)+hTree.GetBinContent(hTree.GetNbinsX())
120 +            uFlowErr = ROOT.TMath.Sqrt(ROOT.TMath.Power(hTree.GetBinError(0),2)+ROOT.TMath.Power(hTree.GetBinError(1),2))
121 +            oFlowErr = ROOT.TMath.Sqrt(ROOT.TMath.Power(hTree.GetBinError(hTree.GetNbinsX()),2)+ROOT.TMath.Power(hTree.GetBinError(hTree.GetNbinsX()+1),2))
122 +            hTree.SetBinContent(1,uFlow)
123 +            hTree.SetBinContent(hTree.GetNbinsX(),oFlow)
124 +            hTree.SetBinError(1,uFlowErr)
125 +            hTree.SetBinError(hTree.GetNbinsX(),oFlowErr)
126 +              
127              
128      print '\t-->import %s\t Integral: %s'%(job.name,hTree.Integral())
129              
130      hTree.SetDirectory(0)
131      input.Close()  
132      
115              
116    
133      return hTree, group
134      
135  
# Line 129 | Line 145 | def orderandadd(histos,typs,setup):
145      num=[0]*len(setup)
146      for i in range(0,len(setup)):
147          for j in range(0,len(histos)):
148 <            if typs[j] in setup[i]:
148 >            if typs[j] == setup[i]:
149                  num[i]+=1
150                  ordnung.append(histos[j])
151                  ordnungtyp.append(typs[j])
# Line 140 | Line 156 | def orderandadd(histos,typs,setup):
156      histos=ordnung
157      typs=ordnungtyp
158  
159 +    print typs
160 +
161      for k in range(0,len(num)):
162          for m in range(0,num[k]):
163              if m > 0:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines