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.1 by peller, Fri May 25 13:07:06 2012 UTC vs.
Revision 1.8 by peller, Fri Aug 10 09:36:16 2012 UTC

# Line 5 | Line 5 | import ROOT
5   from ROOT import TFile, TTree
6   import ROOT
7   from array import array
8 < from ConfigParser import SafeConfigParser
8 > from BetterConfigParser import BetterConfigParser
9   import sys
10  
11  
12   #load config
13 < config = SafeConfigParser()
14 < config.read('./config')
13 > config = BetterConfigParser()
14 > config.read('./config7TeV_ZZ')
15  
16   #get locations:
17   Wdir=config.get('Directories','Wdir')
18 + anaTag=config.get('Analysis','tag')
19  
20  
21  
22 <
22 < def getScale(job,rescale):
22 > def getScale(job,rescale,subsample=-1):
23      input = TFile.Open(job.getpath())
24      CountWithPU = input.Get("CountWithPU")
25      CountWithPU2011B = input.Get("CountWithPU2011B")
26      #print lumi*xsecs[i]/hist.GetBinContent(1)
27 <    return float(job.lumi)*float(job.xsec)*float(job.sf)/(0.46502*CountWithPU.GetBinContent(1)+0.53498*CountWithPU2011B.GetBinContent(1))*rescale/float(job.split)
27 >    
28 >    if subsample>-1:
29 >        xsec=float(job.xsec[subsample])
30 >        sf=float(job.sf[subsample])
31 >    else:
32 >        xsec=float(job.xsec)
33 >        sf=float(job.sf)
34 >    
35 >    
36 >    theScale = 1.
37 >    if anaTag == '7TeV':
38 >        theScale = float(job.lumi)*xsec*sf/(0.46502*CountWithPU.GetBinContent(1)+0.53498*CountWithPU2011B.GetBinContent(1))*rescale/float(job.split)
39 >    elif anaTag == '8TeV':
40 >        theScale = float(job.lumi)*xsec*sf/(CountWithPU.GetBinContent(1))*rescale/float(job.split)
41 >    return theScale
42  
43 + def getHistoFromTree(job,options,rescale=1,subsample=-1):
44  
45 < def getHistoFromTree(job,options,rescale=1):
45 >    #print job.getpath()
46 >    #print options
47      treeVar=options[0]
48 <    name=job.name
48 >    if subsample>-1:
49 >        name=job.subnames[subsample]
50 >        group=job.group[subsample]
51 >    else:
52 >        name=job.name
53 >        group=job.group
54 >
55      #title=job.plotname()
56      nBins=int(options[3])
57      xMin=float(options[4])
# Line 37 | Line 59 | def getHistoFromTree(job,options,rescale
59  
60      if job.type != 'DATA':
61          cutcut=config.get('Cuts',options[7])
62 <        treeCut='%s & EventForTraining == 0'%cutcut
62 >        if subsample>-1:
63 >            treeCut='%s & %s & EventForTraining == 0'%(cutcut,job.subcuts[subsample])        
64 >        else:
65 >            treeCut='%s & EventForTraining == 0'%(cutcut)
66  
67      elif job.type == 'DATA':
68 <        treeCut=config.get('Cuts',options[8])
68 >        cutcut=config.get('Cuts',options[8])
69 >        treeCut='%s'%(cutcut)
70 >
71  
72      input = TFile.Open(job.getpath(),'read')
73  
# Line 79 | Line 106 | def getHistoFromTree(job,options,rescale
106      #print job.name + ' Sumw2', hTree.GetEntries()
107  
108      if job.type != 'DATA':
109 <        ScaleFactor = getScale(job,rescale)
109 >        ScaleFactor = getScale(job,rescale,subsample)
110          if ScaleFactor != 0:
111              hTree.Scale(ScaleFactor)
112              
113      print '\t-->import %s\t Integral: %s'%(job.name,hTree.Integral())
114              
115      hTree.SetDirectory(0)
116 <    input.Close()            
117 <    return hTree, job.group
116 >    input.Close()  
117 >    
118 >              
119 >    
120 >    return hTree, group
121      
122  
123   ######################
# Line 102 | Line 132 | def orderandadd(histos,typs,setup):
132      num=[0]*len(setup)
133      for i in range(0,len(setup)):
134          for j in range(0,len(histos)):
135 <            if typs[j] == setup[i]:
135 >            if typs[j] in setup[i]:
136                  num[i]+=1
137                  ordnung.append(histos[j])
138                  ordnungtyp.append(typs[j])
# Line 119 | Line 149 | def orderandadd(histos,typs,setup):
149              
150                  #add
151                  histos[k].Add(histos[k+1],1)
152 <                #printc('red','','\t--> added %s to %s'%(typs[k],typs[k+1]))
152 >                printc('magenta','','\t--> added %s to %s'%(typs[k],typs[k+1]))
153                  del histos[k+1]
154                  del typs[k+1]
155  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines