PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/MuonAnalysis/MomentumScaleCalibration/test/PrepareErrors.py

https://github.com/dgonzal/cmssw
Python | 66 lines | 49 code | 6 blank | 11 comment | 10 complexity | 8d82c952b224c8c28d7c688464383d91 MD5 | raw file
Possible License(s): GPL-3.0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Feb 21 12:38:26 2011
  4. @author: -
  5. """
  6. functionNumber = 0
  7. value = []
  8. error = []
  9. inputFile = open("FitParameters.txt",'r')
  10. totalFits = 0
  11. for line in inputFile:
  12. if "Fitting with resolution, scale, bgr function" in line:
  13. totalFits += 1
  14. # print "totalFits = ", totalFits
  15. inputFile = open("FitParameters.txt",'r')
  16. actualFit = 0
  17. for line in inputFile:
  18. if "Fitting with resolution, scale, bgr function" in line and actualFit == totalFits-1:
  19. functionNumber = line.split("# ")[1].split(" ")[0]
  20. # print "functionNumber =", functionNumber
  21. actualFit += 1
  22. elif "Fitting with resolution, scale, bgr function" in line:
  23. actualFit += 1
  24. # print "actualFit = ", actualFit
  25. if "Results of the fit: parameter" in line and actualFit == totalFits:
  26. valueAndError = line.split("value")[1].split(" ")[1].split("+-")
  27. value.append(valueAndError[0])
  28. error.append(valueAndError[1])
  29. # print "value = ", valueAndError
  30. # print valueAndError[0], "+-", valueAndError[1]
  31. if "Scale" in line and actualFit == totalFits:
  32. break
  33. values = ""
  34. errors = ""
  35. errorParameters = ""
  36. prepend = ""
  37. for i in range(len(value)):
  38. values += prepend+str(value[i])
  39. errors += prepend+str(error[i])
  40. errorParameters += prepend+"1"
  41. prepend = ", "
  42. print "values = ", values
  43. print "errors = ", errors
  44. cfgFile = open("ErrorsPropagationAnalyzer_cfg.py", 'r')
  45. outputCfgFile = open("Errors_cfg.py", 'w')
  46. for line in cfgFile:
  47. if "ResolFitType = " in line:
  48. outputCfgFile.write(line.replace("cms.int32(20)","cms.int32("+functionNumber+")"))
  49. elif "Parameters = cms.vdouble()," in line:
  50. outputCfgFile.write(line.replace("Parameters = cms.vdouble(),","Parameters = cms.vdouble("+values+"),"))
  51. elif "Errors = cms.vdouble()," in line:
  52. outputCfgFile.write(line.replace("Errors = cms.vdouble(),","Errors = cms.vdouble("+errors+"),"))
  53. elif "ErrorFactors = cms.vint32()," in line:
  54. outputCfgFile.write(line.replace("ErrorFactors = cms.vint32(),", "ErrorFactors = cms.vint32("+errorParameters+"),"))
  55. else:
  56. outputCfgFile.write( line )
  57. # print line