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

Comparing UserCode/VHbb/python/write_systematics.py (file contents):
Revision 1.1 by peller, Tue May 8 10:37:17 2012 UTC vs.
Revision 1.4 by peller, Sat May 12 06:50:49 2012 UTC

# Line 9 | Line 9 | import shutil
9   from ROOT import TFile
10   import ROOT
11   from array import array
12 + import warnings
13 + warnings.filterwarnings( action='ignore', category=RuntimeWarning, message='creating converter.*' )
14  
15  
16   #usage: ./write_systematic.py path
17  
16
18   path=sys.argv[1]
19  
20   #load info
21   infofile = open(path+'/samples.info','r')
22   info = pickle.load(infofile)
23   infofile.close()
24 < os.mkdir(path+'/sys')
24 > #os.mkdir(path+'/sys')
25  
26   for job in info:
27      if job.type != 'DATA':
28          print '\t - %s' %(job.name)
28
29          input = TFile.Open(job.getpath(),'read')
30          output = TFile.Open(job.path+'/sys/'+job.prefix+job.identifier+'.root','recreate')
31  
# Line 34 | Line 34 | for job in info:
34          for key in ROOT.gDirectory.GetListOfKeys():
35              input.cd()
36              obj = key.ReadObj()
37 <            print obj.GetName()
37 >            #print obj.GetName()
38              if obj.GetName() == job.tree:
39                  continue
40              output.cd()
41 <            print key.GetName()
41 >            #print key.GetName()
42              obj.Write(key.GetName())
43  
44          tree = input.Get(job.tree)
45          nEntries = tree.GetEntries()
46        job.addpath('/sys')
47        output.cd()
48        newtree = tree.CloneTree(0)
49
50
51        '''
52        input = TFile.Open(job.getpath(),'read')
53        Count = input.Get("Count")
54        CountWithPU = input.Get("CountWithPU")
55        CountWithPU2011B = input.Get("CountWithPU2011B")
56        tree = input.Get(job.tree)
57        nEntries = tree.GetEntries()
46          
47          job.addpath('/sys')
60        output = ROOT.TFile(job.getpath(), 'RECREATE')
61        newtree = tree.CloneTree(0)
62        '''
48          job.SYS = ['Nominal','JER_up','JER_down','JES_up','JES_down','beff_up','beff_down','bmis_up','bmis_down']
49 +
50 +        output.cd()
51 +        newtree = tree.CloneTree(0)
52          
53          hJ0 = ROOT.TLorentzVector()
54          hJ1 = ROOT.TLorentzVector()
# Line 93 | Line 81 | for job in info:
81          EventForTraining = array('f',[0])
82          newtree.Branch('EventForTraining',EventForTraining,'EventForTraining/F')
83          
84 <        iter=0
84 >        #iter=0
85 >        
86 >        TFlag=ROOT.TTreeFormula("EventForTraining","EVENT.event%2",tree)
87          
88          for entry in range(0,nEntries):
89              tree.GetEntry(entry)
90  
91              #fill training flag
92 <            iter+=1
93 <            if (iter%2==0):
94 <                EventForTraining[0]=1
95 <            else:
96 <                EventForTraining[0]=0
92 >            #iter+=1
93 >            #if (iter%2==0):
94 >            #    EventForTraining[0]=1
95 >            #else:
96 >            #    EventForTraining[0]=0
97 >            #iter+=1
98 >            
99 >            EventForTraining[0]=int(not TFlag.EvalInstance())
100  
101              #get
102              hJet_pt0 = tree.hJet_pt[0]
# Line 186 | Line 179 | for job in info:
179              newtree.Fill()
180                    
181          newtree.AutoSave()
189        #newtree.Write()            
190        #Count.Write()
191        #CountWithPU.Write()
192        #CountWithPU2011B.Write()
182          output.Close()
183 <
183 >        
184      else: #(is data)
185      
186 <        shutil.copy(job.getpath(),path+'/sys')
186 >        print '\t - %s' %(job.name)
187 >        input = TFile.Open(job.getpath(),'read')
188 >        output = TFile.Open(job.path+'/sys/'+job.prefix+job.identifier+'.root','recreate')
189 >        #input.cd()
190 >        obj = ROOT.TObject
191 >        for key in ROOT.gDirectory.GetListOfKeys():
192 >            input.cd()
193 >            obj = key.ReadObj()
194 >            if obj.GetName() == job.tree:
195 >                continue
196 >            output.cd()
197 >            obj.Write(key.GetName())
198 >        #output.cd()
199 >        tree = input.Get(job.tree)
200 >        nEntries = tree.GetEntries()
201          job.addpath('/sys')
202 +        output.cd()
203 +        newtree = tree.CloneTree(0)
204 +        #Add training Flag
205 +        EventForTraining = array('f',[0])
206 +        newtree.Branch('EventForTraining',EventForTraining,'EventForTraining/F')
207 +        for entry in range(0,nEntries):
208 +            tree.GetEntry(entry)
209 +            EventForTraining[0]=0
210 +            newtree.Fill()
211 +        newtree.AutoSave()
212 +        output.Close()
213 +
214  
215   #dump info
216   infofile = open(path+'/sys'+'/samples.info','w')

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines