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.3 by peller, Tue Oct 2 13:19:45 2012 UTC vs.
Revision 1.7 by peller, Thu Oct 11 13:40:18 2012 UTC

# Line 6 | Line 6 | from ROOT import TFile, TTree
6   import ROOT
7   from array import array
8   from BetterConfigParser import BetterConfigParser
9 < import sys
9 > import sys,os
10  
11   class HistoMaker:
12      def __init__(self, path, config, region, optionsList,rescale=1,which_weightF='weightF'):
# Line 44 | Line 44 | class HistoMaker:
44          hTreeList=[]
45          groupList=[]
46  
47 +        #get the conversion rate in case of BDT plots
48 +        TrainFlag = eval(self.config.get('Analysis','TrainFlag'))
49 +        if TrainFlag:
50 +            MC_rescale_factor=2.
51 +            print 'I RESCALE BY 2.0'
52 +        else: MC_rescale_factor = 1.
53 +
54 +        BDT_add_cut='EventForTraining == 0'
55 +
56  
57          plot_path = self.config.get('Directories','plotpath')
58 +        addOverFlow=eval(self.config.get('Plot_general','addOverFlow'))
59  
60 +        scratchDir = os.environ["TMPDIR"]
61 +        #scratchDir = '/shome/peller/'
62          # define treeCut
63          if job.type != 'DATA':
64              if type(self.region)==str:
# Line 57 | Line 69 | class HistoMaker:
69                  cutcut=cutcut.replace(self.region[1],self.region[2])
70                  #print cutcut
71              if subsample>-1:
72 <                treeCut='%s & %s & EventForTraining == 0'%(cutcut,job.subcuts[subsample])        
72 >                treeCut='%s & %s'%(cutcut,job.subcuts[subsample])        
73              else:
74 <                treeCut='%s & EventForTraining == 0'%(cutcut)
74 >                treeCut='%s'%(cutcut)
75          elif job.type == 'DATA':
76              cutcut=self.config.get('Cuts',self.region)
77              treeCut='%s'%(cutcut)
78  
79          # get and skim the Trees
80 <        output=TFile.Open(plot_path+'/tmp_plotCache_%s_%s.root'%(self.region,job.identifier),'recreate')
80 >        output=TFile.Open(scratchDir+'/tmp_plotCache_%s_%s.root'%(self.region,job.identifier),'recreate')
81          input = TFile.Open(self.path+'/'+job.getpath(),'read')
82          Tree = input.Get(job.tree)
83          output.cd()
# Line 86 | Line 98 | class HistoMaker:
98              xMin=float(options[4])
99              xMax=float(options[5])
100  
101 +            #options
102 +
103              if job.type != 'DATA':
104                  if CuttedTree.GetEntries():
105 +                    
106 +                    if 'BDT' in treeVar: drawoption = '(%s)*(%s)'%(weightF,BDT_add_cut)
107 +                    else: drawoption = '%s'%(weightF)
108                      output.cd()
109 <                    CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax), weightF, "goff,e")
109 >                    CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax), drawoption, "goff,e")
110                      full=True
111                  else:
112                      full=False
113              elif job.type == 'DATA':
114                  if options[11] == 'blind':
115                      output.cd()
116 <                    CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),treeVar+'<0', "goff,e")
116 >                    if treeVar == 'H.mass':
117 >                        CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),treeVar+'<80. || '+treeVar + '>150.' , "goff,e")
118 >                    else:
119 >                        CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),treeVar+'<0', "goff,e")
120 >
121                  else:
122                      output.cd()
123                      CuttedTree.Draw('%s>>%s(%s,%s,%s)' %(treeVar,name,nBins,xMin,xMax),'1', "goff,e")
# Line 108 | Line 129 | class HistoMaker:
129                  hTree = ROOT.TH1F('%s'%name,'%s'%name,nBins,xMin,xMax)
130                  hTree.Sumw2()
131              if job.type != 'DATA':
132 <                ScaleFactor = self.getScale(job,subsample)
132 >                if 'BDT' in treeVar: ScaleFactor = self.getScale(job,subsample,MC_rescale_factor)
133 >                else: ScaleFactor = self.getScale(job,subsample)
134                  if ScaleFactor != 0:
135                      hTree.Scale(ScaleFactor)
136              #print '\t-->import %s\t Integral: %s'%(job.name,hTree.Integral())
137 +            if addOverFlow:
138 +                uFlow = hTree.GetBinContent(0)+hTree.GetBinContent(1)
139 +                oFlow = hTree.GetBinContent(hTree.GetNbinsX()+1)+hTree.GetBinContent(hTree.GetNbinsX())
140 +                uFlowErr = ROOT.TMath.Sqrt(ROOT.TMath.Power(hTree.GetBinError(0),2)+ROOT.TMath.Power(hTree.GetBinError(1),2))
141 +                oFlowErr = ROOT.TMath.Sqrt(ROOT.TMath.Power(hTree.GetBinError(hTree.GetNbinsX()),2)+ROOT.TMath.Power(hTree.GetBinError(hTree.GetNbinsX()+1),2))
142 +                hTree.SetBinContent(1,uFlow)
143 +                hTree.SetBinContent(hTree.GetNbinsX(),oFlow)
144 +                hTree.SetBinError(1,uFlowErr)
145 +                hTree.SetBinError(hTree.GetNbinsX(),oFlowErr)
146              hTree.SetDirectory(0)
147              input.Close()
148              hTreeList.append(hTree)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines