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

Comparing UserCode/VHbb/python/HistoMaker.py (file contents):
Revision 1.1 by peller, Tue Oct 2 11:23:09 2012 UTC vs.
Revision 1.2 by peller, Tue Oct 2 13:00:32 2012 UTC

# Line 9 | Line 9 | from BetterConfigParser import BetterCon
9   import sys
10  
11   class HistoMaker:
12 <    def __init__(self, path, config, optionsList,rescale=1,which_weightF='weightF'):
12 >    def __init__(self, path, config, region, optionsList,rescale=1,which_weightF='weightF'):
13          self.path = path
14          self.config = config
15          self.optionsList = optionsList
16          self.rescale = rescale
17          self.which_weightF=which_weightF
18 <
19 <
18 >        self.region = region
19  
20      def getScale(self,job,subsample=-1):
21          anaTag=self.config.get('Analysis','tag')
# Line 24 | Line 23 | class HistoMaker:
23          CountWithPU = input.Get("CountWithPU")
24          CountWithPU2011B = input.Get("CountWithPU2011B")
25          #print lumi*xsecs[i]/hist.GetBinContent(1)
27        
26          if subsample>-1:
27              xsec=float(job.xsec[subsample])
28              sf=float(job.sf[subsample])
29          else:
30              xsec=float(job.xsec)
31              sf=float(job.sf)
34        
35        
32          theScale = 1.
33          if anaTag == '7TeV':
34              theScale = float(job.lumi)*xsec*sf/(0.46502*CountWithPU.GetBinContent(1)+0.53498*CountWithPU2011B.GetBinContent(1))*self.rescale/float(job.split)
# Line 46 | Line 42 | class HistoMaker:
42          hTreeList=[]
43          groupList=[]
44  
45 <        output=TFile.Open(self.path+'/tmp_%s.root'%job.name,'recreate')
45 >
46 >        plot_path = self.config.get('Directories','plotpath')
47 >
48 >        # define treeCut
49          if job.type != 'DATA':
50 <        
51 <            if type(self.optionsList[0][7])==str:
52 <                cutcut=self.config.get('Cuts',self.optionsList[0][7])
53 <            elif type(self.optionsList[0][7])==list:
54 <                cutcut=self.config.get('Cuts',self.optionsList[0][7][0])
55 <                cutcut=cutcut.replace(self.optionsList[0][7][1],self.optionsList[0][7][2])
56 <                print cutcut
50 >            if type(self.region)==str:
51 >                cutcut=self.config.get('Cuts',self.region)
52 >            elif type(self.region)==list:
53 >                #replace vars with other vars in the cutstring (used in DC writer)
54 >                cutcut=self.config.get('Cuts',self.region[0])
55 >                cutcut=cutcut.replace(self.region[1],self.region[2])
56 >                #print cutcut
57              if subsample>-1:
58                  treeCut='%s & %s & EventForTraining == 0'%(cutcut,job.subcuts[subsample])        
59              else:
60                  treeCut='%s & EventForTraining == 0'%(cutcut)
62
61          elif job.type == 'DATA':
62 <            cutcut=self.config.get('Cuts',self.optionsList[0][8])
62 >            cutcut=self.config.get('Cuts',self.region)
63              treeCut='%s'%(cutcut)
64 +
65 +        # get and skim the Trees
66 +        output=TFile.Open(plot_path+'/tmp_plotCache_%s_%s.root'%(self.region,job.identifier),'recreate')
67          input = TFile.Open(self.path+'/'+job.getpath(),'read')
68          Tree = input.Get(job.tree)
69 +        output.cd()
70 +        CuttedTree=Tree.CopyTree(treeCut)
71 +    
72 +        # get all Histos at once
73          weightF=self.config.get('Weights',self.which_weightF)
69        if job.type != 'DATA':
70            #if Tree.GetEntries():
71            output.cd()
72            CuttedTree=Tree.CopyTree(treeCut)
73        elif job.type == 'DATA':
74        
75            output.cd()
76            CuttedTree=Tree.CopyTree(treeCut)
77
74          for options in self.optionsList:
79
75              if subsample>-1:
76                  name=job.subnames[subsample]
77                  group=job.group[subsample]
78              else:
79                  name=job.name
80                  group=job.group
86
87
81              treeVar=options[0]
82              name=options[1]
83              nBins=int(options[3])
# Line 99 | Line 92 | class HistoMaker:
92                  else:
93                      full=False
94              elif job.type == 'DATA':
102            
95                  if options[11] == 'blind':
96                      output.cd()
97                      CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),treeVar+'<0', "goff,e")
# Line 113 | Line 105 | class HistoMaker:
105                  output.cd()
106                  hTree = ROOT.TH1F('%s'%name,'%s'%name,nBins,xMin,xMax)
107                  hTree.Sumw2()
116
108              if job.type != 'DATA':
109                  ScaleFactor = self.getScale(job,subsample)
110                  if ScaleFactor != 0:
111                      hTree.Scale(ScaleFactor)
121                    
112              #print '\t-->import %s\t Integral: %s'%(job.name,hTree.Integral())
113              hTree.SetDirectory(0)
114              input.Close()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines