Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:41

0001 # -*- coding: utf-8 -*-
0002 """
0003 Created on Mon Feb 21 12:38:26 2011
0004 
0005 @author: Marco De Mattia, marco.de.mattia@cern.ch
0006 
0007 This script goes with the template_MuScleFit_cfg.py. It reads the scale
0008 parameters from the FitParameters.txt file (the first set it finds) and
0009 it creates a MuScleFit_cfg.py from the template with them.
0010 It does not replace the parFix and parOrder.
0011 """
0012 
0013 functionNumber = 0
0014 value = []
0015 error = []
0016 
0017 inputFile = open("FitParameters.txt",'r')
0018 
0019 for line in inputFile:
0020     if "Fitting with resolution, scale, bgr function" in line:
0021         functionNumber = line.split("# ")[1].split(" ")[0]
0022     if "Results of the fit: parameter" in line:
0023         valueAndError = line.split("value")[1].split(" ")[1].split("+-")
0024         value.append(valueAndError[0])
0025         error.append(valueAndError[1])
0026         # print valueAndError[0], "+-", valueAndError[1]
0027         
0028     if "Scale" in line:
0029         break
0030 
0031 values = ""
0032 errors = ""
0033 errorParameters = ""
0034 prepend = ""
0035 for i in range(len(value)):
0036     values += prepend+str(value[i])
0037     errors += prepend+str(error[i])
0038     errorParameters += prepend+"1"
0039     prepend = ", "
0040 
0041 print values
0042     
0043 cfgFile = open("template_MuScleFit_cfg.py", 'r')
0044 outputCfgFile = open("MuScleFit_cfg.py", 'w')
0045 for line in cfgFile:
0046     if "ResolFitType = " in line:
0047         outputCfgFile.write(line.replace("cms.int32(20)","cms.int32("+functionNumber+")"))
0048     elif "parResol = cms.vdouble()," in line:
0049         outputCfgFile.write(line.replace("parResol = cms.vdouble(),","parResol = cms.vdouble("+values+"),"))
0050     else:
0051         outputCfgFile.write( line )
0052     # print line