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

Comparing UserCode/VHbb/python/myutils/HistoMaker.py (file contents):
Revision 1.10 by peller, Tue Feb 19 17:22:31 2013 UTC vs.
Revision 1.19 by peller, Mon Apr 8 09:40:27 2013 UTC

# Line 18 | Line 18 | class HistoMaker:
18          self.cuts = []
19          for options in optionsList:
20              self.cuts.append(options['cut'])
21 <        print self.cuts
21 >        #print self.cuts
22          #self.tc = TreeCache(self.cuts,samples,path)
23          self.tc = TreeCache(self.cuts,samples,path,config)
24          self._rebin = False
25          self.mybinning = None
26          self.GroupDict=GroupDict
27          self.calc_rebin_flag = False
28 +        VHbbNameSpace=config.get('VHbbNameSpace','library')
29 +        ROOT.gSystem.Load(VHbbNameSpace)
30  
31 <    def get_histos_from_tree(self,job):
31 >    def get_histos_from_tree(self,job,cutOverWrite=None):
32          if self.lumi == 0:
33              raise Exception("You're trying to plot with no lumi")
34          
# Line 41 | Line 43 | class HistoMaker:
43          addOverFlow=eval(self.config.get('Plot_general','addOverFlow'))
44  
45          # get all Histos at once
46 +        CuttedTree = self.tc.get_tree(job,'1')
47          for options in self.optionsList:
48              name=job.name
49              if self.GroupDict is None:
# Line 56 | Line 59 | class HistoMaker:
59              xMin=float(options['xMin'])
60              xMax=float(options['xMax'])
61              weightF=options['weight']
62 <            treeCut='%s'%(options['cut'])
63 <            CuttedTree = self.tc.get_tree(job,treeCut)
62 >            if cutOverWrite:
63 >                treeCut=cutOverWrite
64 >            else:
65 >                treeCut='%s'%(options['cut'])
66  
67              #options
68  
69              if job.type != 'DATA':
70                  if CuttedTree.GetEntries():
71                      if 'RTight' in treeVar or 'RMed' in treeVar:
72 <                        drawoption = '(%s)*(%s)'%(weightF,BDT_add_cut)
72 >                        drawoption = '(%s)*(%s & %s)'%(weightF,treeCut,BDT_add_cut)
73 >                        #print drawoption
74                      else:
75 <                        drawoption = '%s'%(weightF)
75 >                        drawoption = '(%s)*(%s)'%(weightF,treeCut)
76                      CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax), drawoption, "goff,e")
77                      full=True
78                  else:
79                      full=False
80              elif job.type == 'DATA':
81 <                if eval(options['blind']):
81 >                if options['blind']:
82                      if treeVar == 'H.mass':
83 <                        CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),treeVar+'<90. || '+treeVar + '>150.' , "goff,e")
83 >                        CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),' (%(var)s <90. || %(var)s > 150.) & %(cut)s' %options, "goff,e")
84                      else:
85 <                        CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),treeVar+'<0', "goff,e")
85 >                        CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),'%(var)s < 0. & %(cut)s'%options, "goff,e")
86  
87                  else:
88 <                    CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),'1', "goff,e")
88 >                    CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),'%s' %treeCut, "goff,e")
89                  full = True
90              if full:
91                  hTree = ROOT.gDirectory.Get(name)
# Line 114 | Line 120 | class HistoMaker:
120                  gDict[group] = self.mybinning.rebin(hTree)
121                  del hTree
122              else:
123 <                print 'not rebinning %s'%job.name
123 >                #print 'not rebinning %s'%job.name
124                  gDict[group] = hTree
125              hTreeList.append(gDict)
126 <            CuttedTree.IsA().Destructor(CuttedTree)
127 <            del CuttedTree
126 >        CuttedTree.IsA().Destructor(CuttedTree)
127 >        del CuttedTree
128          return hTreeList
129        
130      @property
# Line 142 | Line 148 | class HistoMaker:
148          elif not self._rebin and not self.value:
149              return False
150  
151 <    def calc_rebin(self, bg_list, nBins_start=1000, tolerance=0.35):
151 >    def calc_rebin(self, bg_list, nBins_start=1000, tolerance=0.25):
152          self.calc_rebin_flag = True
153          self.norebin_nBins = copy(self.nBins)
154          self.rebin_nBins = nBins_start
# Line 173 | Line 179 | class HistoMaker:
179              if not TotR == 0 and not ErrorR == 0:
180                  rel=ErrorR/TotR
181                  #print rel
182 <        print 'upper bin is %s'%binR
182 >        #print 'upper bin is %s'%binR
183  
184          #---- from left
185          rel=1.0
# Line 186 | Line 192 | class HistoMaker:
192                  #print rel
193          #it's the lower edge
194          binL+=1
195 <        print 'lower bin is %s'%binL
195 >        #print 'lower bin is %s'%binL
196  
197          inbetween=binR-binL
198          stepsize=int(inbetween)/(int(self.norebin_nBins)-2)
199          modulo = int(inbetween)%(int(self.norebin_nBins)-2)
200  
201 <        print 'stepsize %s'% stepsize
201 >        #print 'stepsize %s'% stepsize
202          #print 'modulo %s'%modulo
203          binlist=[binL]
204          for i in range(0,int(self.norebin_nBins)-3):
# Line 200 | Line 206 | class HistoMaker:
206          binlist[-1]+=modulo
207          binlist.append(binR)
208          binlist.append(self.rebin_nBins+1)
209 <        print 'binning set to %s'%binlist
209 >        #print 'binning set to %s'%binlist
210          self.mybinning = Rebinner(int(self.norebin_nBins),array('d',[-1.0]+[totalBG.GetBinLowEdge(i) for i in binlist]),True)
211          self._rebin = True
212          print '\t > rebinning is set <\n'

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines