CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/RecoTauTag/TauTagTools/xml/MVAConfigBuilder.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """
00004 MVAConfigBuilder.py
00005 
00006 Author: Evan K. Friis, UC Davis friis@physics.ucdavis.edu
00007 
00008 Usage: Any objects with file type [name].mvac will be turned into [name].xml with the correct format
00009 
00010 A configuration script to automate changes in available MVA input variables (for the PhysicsTools/MVAComputer framework)
00011 across numerous MVA configurations.
00012 
00013 This is total kludge and will be deprecated when 
00014         a. I figure out how you use <xi:include... success full (xml sucks)
00015         b. Proposed changes to the MVA objects allow classification steering in a single xml file
00016 """
00017 
00018 import os
00019 import glob
00020 import string
00021 
00022 filesToConvert = glob.glob("./*.mvac")
00023 
00024 RemoveNumEventsSpecifiers = True
00025 
00026 for aFile in filesToConvert:
00027    xmlFileName = string.replace(aFile, "mvac", "xml")
00028    if os.path.exists(xmlFileName):
00029       os.system("cp %s %s.bak" % (xmlFileName, xmlFileName))
00030       os.remove(xmlFileName)
00031 
00032    print "Building %s..." % xmlFileName
00033    os.system("cat Preamble.xml.fragment >  %s" %         xmlFileName)  
00034    os.system("cat Inputs.xml.fragment   >> %s" %         xmlFileName)  
00035    os.system("cat Helpers.xml.fragment  >> %s" %         xmlFileName)  
00036    if RemoveNumEventsSpecifiers:
00037       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)) 
00038    else:
00039       os.system("cat %s                    >> %s" % (aFile, xmlFileName)) 
00040    os.system("cat Finale.xml.fragment   >> %s" %         xmlFileName)  
00041 
00042