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

Comparing UserCode/VHbb/python/evaluateMVA.py (file contents):
Revision 1.26 by bortigno, Tue Feb 19 21:22:05 2013 UTC vs.
Revision 1.29 by nmohr, Thu Apr 4 09:01:30 2013 UTC

# Line 1 | Line 1
1   #!/usr/bin/env python
2   from __future__ import print_function
3   import sys
4 < import os
4 > import os,subprocess
5   import ROOT
6   from array import array
7   from math import sqrt
# Line 89 | Line 89 | for mva in MVAinfos:
89  
90   samples = info.get_samples(namelist)
91   print(samples)
92 + tmpDir = os.environ["TMPDIR"]
93   for job in samples:
94      #get trees:
95      print(INpath+'/'+job.prefix+job.identifier+'.root')
96      input = ROOT.TFile.Open(INpath+'/'+job.prefix+job.identifier+'.root','read')
97      print(OUTpath+'/'+job.prefix+job.identifier+'.root')
98 <    outfile = ROOT.TFile.Open(OUTpath+'/'+job.prefix+job.identifier+'.root','recreate')
98 >    outfile = ROOT.TFile.Open(tmpDir+'/'+job.prefix+job.identifier+'.root','recreate')
99      input.cd()
100      obj = ROOT.TObject
101      for key in ROOT.gDirectory.GetListOfKeys():
# Line 109 | Line 110 | for job in samples:
110      tree = input.Get(job.tree)
111      nEntries = tree.GetEntries()
112      outfile.cd()
113 <    newtree = tree.CopyTree('') #hard skim to get faster
113 <    input.Close()
113 >    newtree = tree.CloneTree(0)
114              
115      #Set branch adress for all vars
116      for i in range(0,len(theMVAs)):
117 <        theMVAs[i].setVariables(newtree,job)
117 >        theMVAs[i].setVariables(tree,job)
118      outfile.cd()
119      #Setup Branches
120      mvaVals=[]
# Line 129 | Line 129 | for job in samples:
129          print('\n--> ' + job.name +':')
130      #Fill event by event:
131      for entry in range(0,nEntries):
132 <        newtree.GetEntry(entry)
132 >        tree.GetEntry(entry)
133                              
134          for i in range(0,len(theMVAs)):
135              theMVAs[i].evaluate(mvaVals[i],job)
# Line 137 | Line 137 | for job in samples:
137          newtree.Fill()
138      newtree.AutoSave()
139      outfile.Close()
140 +    targetStorage = OUTpath.replace('gsidcap://t3se01.psi.ch:22128/','srm://t3se01.psi.ch:8443/srm/managerv2?SFN=')+'/'+job.prefix+job.identifier+'.root'
141 +    command = 'lcg-del -b -D srmv2 -l %s' %(targetStorage)
142 +    print(command)
143 +    subprocess.call([command], shell=True)
144 +    command = 'lcg-cp -b -D srmv2 file:///%s %s' %(tmpDir+'/'+job.prefix+job.identifier+'.root',targetStorage)
145 +    print(command)
146 +    subprocess.call([command], shell=True)
147                  
148   print('\n')

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines