CMS 3D CMS Logo

MVAConfigBuilder.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 """
4 MVAConfigBuilder.py
5 
6 Author: Evan K. Friis, UC Davis friis@physics.ucdavis.edu
7 
8 Usage: Any objects with file type [name].mvac will be turned into [name].xml with the correct format
9 
10 A configuration script to automate changes in available MVA input variables (for the PhysicsTools/MVAComputer framework)
11 across numerous MVA configurations.
12 
13 This is total kludge and will be deprecated when
14  a. I figure out how you use <xi:include... success full (xml sucks)
15  b. Proposed changes to the MVA objects allow classification steering in a single xml file
16 """
17 
18 import os
19 import glob
20 import string
21 
22 filesToConvert = glob.glob("./*.mvac")
23 
24 RemoveNumEventsSpecifiers = True
25 
26 for aFile in filesToConvert:
27  xmlFileName = string.replace(aFile, "mvac", "xml")
28  if os.path.exists(xmlFileName):
29  os.system("cp %s %s.bak" % (xmlFileName, xmlFileName))
30  os.remove(xmlFileName)
31 
32  print "Building %s..." % xmlFileName
33  os.system("cat Preamble.xml.fragment > %s" % xmlFileName)
34  os.system("cat Inputs.xml.fragment >> %s" % xmlFileName)
35  os.system("cat Helpers.xml.fragment >> %s" % xmlFileName)
36  if RemoveNumEventsSpecifiers:
37  os.system("cat %s | sed 's|NSigTest=[0-9]*|NSigTest=0|' | sed 's|NBkgTest=[0-9]*|NBkgTest=0|' | sed 's|NSigTrain=[0-9]*|NSigTrain=0|' | sed 's|NBkgTrain=[0-9]*|NBkgTrain=0|' >> %s" % (aFile, xmlFileName))
38  else:
39  os.system("cat %s >> %s" % (aFile, xmlFileName))
40  os.system("cat Finale.xml.fragment >> %s" % xmlFileName)
41 
42