def doFitBothF2(inFileName, zeroFileName, sectors, startBin, stopBin, tBins, sectorRangeMap={}, referenceWave=""): f2Mass = ptc.parameter(mF2, "f2Mass") f2Width = ptc.parameter(GF2, "f2Width") f2S = ptc.relativisticBreitWigner([f2Mass, f2Width], mPi, mPi, mPi, 2, 0, False) f2D = ptc.relativisticBreitWigner([f2Mass, f2Width], mPi, mPi, mPi, 2, 2, False) fitF2 = amplitudeAnalysis(inFileName, sectors, { "2-+0+[pi,pi]2++PiS": [f2S], "2-+0+[pi,pi]2++PiD": [f2D] }, startBin, stopBin, tBins, sectorRangeMap=sectorRangeMap, zeroFileName=zeroFileName) fitF2.loadData(referenceWave=referenceWave) fitF2.finishModelSetup() fitF2.fitShapeParameters() fitF2.calculateNonShapeParameters() fitF2.mode = AMPL # fitF2.removeGlobalPhaseFromComa() return fitF2
def doFitBothRho(inFileName, zeroFileName, sectors, startBin, stopBin, tBins, sectorRangeMap={}, referenceWave=""): rhoMass = ptc.parameter(mRho, "rhoMass") rhoWidth = ptc.parameter(Grho, "rhoWidth") rhoP = ptc.relativisticBreitWigner([rhoMass, rhoWidth], mPi, mPi, mPi, 1, 1, False) rhoF = ptc.relativisticBreitWigner([rhoMass, rhoWidth], mPi, mPi, mPi, 1, 3, False) fitRho = amplitudeAnalysis(inFileName, sectors, { "2-+0+[pi,pi]1--PiP": [rhoP], "2-+0+[pi,pi]1--PiF": [rhoF] }, startBin, stopBin, tBins, sectorRangeMap=sectorRangeMap, zeroFileName=zeroFileName) fitRho.loadData(referenceWave=referenceWave) fitRho.finishModelSetup() # for mBin in fitRho.model[0]: # print ">>",mBin.nPar,"<<" # raise Exception fitRho.fitShapeParameters() fitRho.calculateNonShapeParameters() fitRho.mode = AMPL # fitRho.removeGlobalPhaseFromComa() return fitRho
def doFitRhoRadius(inFileName, sectors, startBin, stopBin, tBins, sectorRangeMap = {}, referenceWave = "", writeResultToFile = None, acv = None): rhoMass = ptc.parameter( mRho, "rhoMass" ) rhoWidth = ptc.parameter( Grho, "rhoWidth") rhoRadius = ptc.parameter( Pr0, "rRho" ) pi1radius = ptc.parameter( 100., "rPi1" ) rhoMass.lock = True rhoWidth.lock = True # pi1radius.lock = True rhoRadius.lock = True rho = ptc.relativisticBreitWigner([rhoMass, rhoWidth, pi1radius, rhoRadius], mPi, mPi, mPi, 1, 1, fitPr = True) fitRho = amplitudeAnalysis(inFileName, sectors, {"1-+1+[pi,pi]1--PiP":[rho]}, startBin, stopBin, tBins, sectorRangeMap = sectorRangeMap) fitRho.loadData( loadIntegrals = True, referenceWave = referenceWave) fitRho.finishModelSetup() fitRho.fitShapeParameters() fitRho.calculateNonShapeParameters() fitRho.mode = AMPL # fitRho.removeGlobalPhaseFromComa() if writeResultToFile is not None: with open(writeResultToFile, 'a') as outFile: if len(tBins) > 1: raise ValueError("More than one t' bin not supported") resultString = str(tBins[0]) + " 666. " + str(rhoRadius.value) + "\n" # # # resultString = str(tBins[0])+ " 666. " + str(rhoMass.value) + ' ' + str(rhoMass.error) + ' ' + str(rhoWidth.value) + ' ' + str(rhoWidth.error) + "\n" outFile.write(resultString) return fitRho
def getRhoModel(inFileName, sector, startBin, stopBin, tBins, sectorRangeMap, L, referenceWave="", writeResultToFile=None, loadIntegrals=False): rhoMass = ptc.parameter(mRho - .1, "rhoMass") rhoWidth = ptc.parameter(Grho + .1, "rhoWidth") rho = ptc.relativisticBreitWigner([rhoMass, rhoWidth], mPi, mPi, mPi, 1, L, False) fitRho = amplitudeAnalysis(inFileName, [sector], {sector: [rho]}, startBin, stopBin, tBins, sectorRangeMap=sectorRangeMap) fitRho.loadData(referenceWave=referenceWave, loadIntegrals=loadIntegrals) fitRho.finishModelSetup() fitRho.fitShapeParameters() fitRho.mode = AMPL if writeResultToFile: with open(writeResultToFile, 'a') as outFile: if len(tBins) > 1: raise ValueError("More than one t' bin not supported") resultString = str(tBins[0]) + " 666. " + str( rhoMass.value) + ' ' + str(rhoMass.error) + ' ' + str( rhoWidth.value) + ' ' + str(rhoWidth.error) + "\n" outFile.write(resultString) return fitRho
def doFitF2(inFileName, zeroFileName, sectors, startBin, stopBin, tBins, sectorRangeMap={}, referenceWave="", writeResultToFile=None): f2Mass = ptc.parameter(mF2, "f2Mass") f2Width = ptc.parameter(GF2, "f2Width") f2 = ptc.relativisticBreitWigner([f2Mass, f2Width], mPi, mPi, mPi, 2, 1, False) fitF2 = amplitudeAnalysis(inFileName, sectors, {"2++1+[pi,pi]2++PiP": [f2]}, startBin, stopBin, tBins, sectorRangeMap=sectorRangeMap, zeroFileName=zeroFileName) fitF2.loadData(referenceWave=referenceWave) fitF2.finishModelSetup() fitF2.fitShapeParameters() fitF2.calculateNonShapeParameters() fitF2.mode = AMPL # fitF2.removeGlobalPhaseFromComa() if writeResultToFile: with open(writeResultToFile, 'a') as outFile: if len(tBins) > 1: raise ValueError("More than one t' bin not supported") resultString = str(tBins[0]) + " 666. " + str( f2Mass.value) + ' ' + str(f2Mass.error) + ' ' + str( f2Width.value) + ' ' + str(f2Width.error) + "\n" outFile.write(resultString) return fitF2
def doFitRho(inFileName, sectors, startBin, stopBin, tBins, sectorRangeMap={}, referenceWave=""): rhoMass = ptc.parameter(mRho, "rhoMass") rhoWidth = ptc.parameter(Grho, "rhoWidth") binning = [ 0.278, 0.32, 0.36, 0.4, 0.44, 0.48, 0.52, 0.56, 0.6, 0.64, 0.68, 0.7, 0.72, 0.74, 0.76, 0.78, 0.8, 0.82, 0.84, 0.86, 0.88, 0.9, 0.92, 0.96, 1.0, 1.04, 1.08, 1.12, 1.16, 1.2, 1.24, 1.28, 1.32, 1.36, 1.4, 1.44, 1.48, 1.52, 1.56, 1.6, 1.64, 1.68, 1.72, 1.76, 1.8, 1.84, 1.88, 1.92, 1.96, 2.0, 2.04, 2.08, 2.12, 2.16, 2.2, 2.24, 2.28 ] rho = ptc.relativisticBreitWigner([rhoMass, rhoWidth], mPi, mPi, mPi, 1, 1, False) # rho = ptc.integratedRelativisticBreitWigner([rhoMass,rhoWidth], mPi, mPi, mPi, 1, 1, binning, intensWeight = False, fitPr = False, reweightInverseBW = True) fitRho = amplitudeAnalysis(inFileName, sectors, {"0-+0+[pi,pi]1--PiP": [rho]}, startBin, stopBin, tBins, sectorRangeMap=sectorRangeMap) fitRho.loadData(referenceWave=referenceWave) fitRho.finishModelSetup() fitRho.fitShapeParameters() fitRho.calculateNonShapeParameters() fitRho.mode = AMPL # fitRho.removeGlobalPhaseFromComa() # fitRho.removeZeroModeFromComa() return fitRho
def doFitRho(inFileName, zeroFileName, sectors, startBin, stopBin, tBins, sectorRangeMap={}, referenceWave=""): rhoMass = ptc.parameter(mRho, "rhoMass") rhoWidth = ptc.parameter(Grho, "rhoWidth") rho = ptc.relativisticBreitWigner([rhoMass, rhoWidth], mPi, mPi, mPi, 1, 1, False) fitRho = amplitudeAnalysis(inFileName, sectors, {"2++1+[pi,pi]1--PiD": [rho]}, startBin, stopBin, tBins, sectorRangeMap=sectorRangeMap, zeroFileName=zeroFileName) fitRho.loadData(referenceWave=referenceWave) fitRho.finishModelSetup() fitRho.fitShapeParameters() fitRho.calculateNonShapeParameters() fitRho.mode = AMPL # fitRho.removeGlobalPhaseFromComa() return fitRho
def getF2Model(inFileName, sector, startBin, stopBin, tBins, sectorRangeMap, L, referenceWave="", writeResultToFile=None, loadIntegrals=False): print 'sector', sector, 'has L =', L f2Mass = ptc.parameter(mF2, "f2Mass") f2Width = ptc.parameter(GF2, "f2Width") f2 = ptc.relativisticBreitWigner([f2Mass, f2Width], mPi, mPi, mPi, 2, L, False) fitF2 = amplitudeAnalysis(inFileName, [sector], {sector: [f2]}, startBin, stopBin, tBins, sectorRangeMap=sectorRangeMap) fitF2.loadData(referenceWave=referenceWave, loadIntegrals=loadIntegrals) fitF2.finishModelSetup() fitF2.fitShapeParameters() fitF2.mode = AMPL if writeResultToFile: with open(writeResultToFile, 'a') as outFile: if len(tBins) > 1: raise ValueError("More than one t' bin not supported") resultString = str(tBins[0]) + " 666. " + str( f2Mass.value) + ' ' + str(f2Mass.error) + ' ' + str( f2Width.value) + ' ' + str(f2Width.error) + "\n" outFile.write(resultString) return fitF2
def doFitRho(inFileName, sectors, startBin, stopBin, tBins, sectorRangeMap = {}, referenceWave = "", writeResultToFile = None, acv = None, polDeg = None): rhoMass = ptc.parameter( mRho, "rhoMass" ) rhoWidth = ptc.parameter( Grho , "rhoWidth") rho = ptc.relativisticBreitWigner([rhoMass,rhoWidth], mPi, mPi, mPi, 1, 1, False) model = [rho] if polDeg is not None: params = [] sVal = 1. for i in range(polDeg): params.append(ptc.parameter( sVal, "c"+str(i+1)+"_re" )) sVal = 0. # Make the start value to constant 1 params.append(ptc.parameter( 0., "c"+str(i+1)+"_im" )) polynome = ptc.complexPolynomial(polDeg,params) model.append(polynome) fitRho = amplitudeAnalysis(inFileName, sectors, {"1-+1+[pi,pi]1--PiP":model}, startBin, stopBin, tBins, sectorRangeMap = sectorRangeMap) fitRho.loadData(loadIntegrals = True, referenceWave = referenceWave) fitRho.finishModelSetup() fitRho.fitShapeParameters() fitRho.calculateNonShapeParameters() fitRho.mode = AMPL # fitRho.removeGlobalPhaseFromComa() if writeResultToFile: with open(writeResultToFile, 'a') as outFile: if len(tBins) > 1: raise ValueError("More than one t' bin not supported") resultString = str(tBins[0])+ " 666. " + str(rhoMass.value) + ' ' + str(rhoMass.error) + ' ' + str(rhoWidth.value) + ' ' + str(rhoWidth.error) + "\n" outFile.write(resultString) return fitRho
def doFitRho3(inFileName, zeroFileName, sectors, startBin, stopBin, tBins, sectorRangeMap={}): rho3Mass = ptc.parameter(mRho3, "rho3Mass") rho3Width = ptc.parameter(Grho3, "rho3Width") rho3 = ptc.relativisticBreitWigner([rho3Mass, rho3Width], mPi, mPi, mPi, 3, 0, False) rho3BF = ptc.timesBF(rho3) fitRho = amplitudeAnalysis( inFileName, sectors, {"3++0+[pi,pi]3--PiS": [rho3]}, startBin, stopBin, tBins, sectorRangeMap={"3++0+[pi,pi]3--PiS": (1.4, 2.0)}, zeroFileName=zeroFileName) fitRho.loadData(referenceWave="4-+0+rhoPiF") fitRho.finishModelSetup() fitRho.fitShapeParameters() fitRho.calculateNonShapeParameters() fitRho.mode = AMPL # fitRho.removeGlobalPhaseFromComa() return fitRho
def doFitRho(inFileName, zeroFileName, sectors, startBin, stopBin, tBins, sectorRangeMap={}, referenceWave="", writeResultToFile=None): rhoMass = ptc.parameter(mRho, "rhoMass") rhoWidth = ptc.parameter(Grho, "rhoWidth") rho = ptc.relativisticBreitWigner([rhoMass, rhoWidth], mPi, mPi, mPi, 1, 2, False) fitRho = amplitudeAnalysis(inFileName, sectors, {"3++0+[pi,pi]1--PiD": [rho]}, startBin, stopBin, tBins, sectorRangeMap=sectorRangeMap, zeroFileName=zeroFileName) fitRho.loadData(referenceWave=referenceWave) fitRho.finishModelSetup() fitRho.fitShapeParameters() fitRho.calculateNonShapeParameters() fitRho.mode = AMPL # fitRho.removeGlobalPhaseFromComa() if writeResultToFile: with open(writeResultToFile, 'a') as outFile: if len(tBins) > 1: raise ValueError("More than one t' bin not supported") resultString = str(tBins[0]) + " 666. " + str( rhoMass.value) + ' ' + str(rhoMass.error) + ' ' + str( rhoWidth.value) + ' ' + str(rhoWidth.error) + "\n" outFile.write(resultString) return fitRho
def fitRhoPrime(fitBin, outFileName, inFileName, startBin, stopBin, tBins, pars, zeroModeParameters, plotNameBase = "",referenceWave = ""): global rhoPrimeFit if not rhoPrimeFit: rhoMass = ptc.parameter( pars[0], "rhoMass") rhoWidth = ptc.parameter( pars[1], "rhoWidth") rhoMass.lock = True rhoWidth.lock = True rho = ptc.relativisticBreitWigner([rhoMass,rhoWidth], mPi, mPi, mPi, 1, 0, False) primeMass = ptc.parameter( mRhoPrime, "primeMass" ) primeWidth = ptc.parameter( GrhoPrime, "primeWidth") prime = ptc.relativisticBreitWigner([primeMass,primeWidth], mPi, mPi, mPi, 1, 0, False) rhoPrimeFit = amplitudeAnalysis(inFileName, ["1++0+[pi,pi]1--PiS"], {"1++0+[pi,pi]1--PiS":[rho,prime]}, startBin, stopBin, tBins) rhoPrimeFit.loadData(referenceWave = referenceWave) rhoPrimeFit.finishModelSetup() rhoPrimeFit.fitShapeParameters() rhoPrimeFit.calculateNonShapeParameters() rhoPrimeFit.mode = AMPL binIndex = fitBin+startBin with open(outFileName, 'a') as outFile: outFile.write(str(binIndex)+' '+str(0.52 + 0.04*binIndex)+' ') startValueOffset = 0.01 exceptCount = 0 while True: # try: if True: x,err,c2,ndf = rhoPrimeFit.fitShapeParametersForBinRange([mRhoPrime+startValueOffset,GrhoPrime+startValueOffset], [0],[fitBin], zeroModeParameters = zeroModeParameters) break # except: # print "Fitter exception encountered" # startValueOffset += 0.001 # exceptCount += 1 # if exceptCount > 3: # print "Too many failed attempts in bin "+str(fitBin)+": "+str(exceptCount) # raise Exception # x, err = [0.,0.],[0.,0.] # break outFile.write(str(x[0]) + ' ' + str(err[0]) + ' ' + str(x[1]) + ' ' + str(err[1])) outFile.write(' ' + str(c2/ndf) + '\n') if not plotNameBase == "": rhoPrimeFit.calculateNonShapeParametersForZeroModeParameters(zeroModeParameters) rhoPrimeRV = rhoPrimeFit.produceResultViewer(zeroModeParameters,"1++0+[pi,pi]1--PiS", noRun = True, plotTheory = True) rhoPrimeRV.plotData = True rhoPrimeRV.writeBinToPdf(binIndex, stdCmd = ["", plotNameBase.replace("<mode>","intens"), [], plotNameBase.replace("<mode>","argand"), []])
def doFitRhoPR(inFileName, sectors, startBin, stopBin, tBins, sectorRangeMap = {}, referenceWave = ""): rhoMass = ptc.parameter( mRho, "rhoMass" ) rhoWidth = ptc.parameter( Grho , "rhoWidth") PrA1 = ptc.PRparameter( Pr0, "PrA1" ) PrRho = ptc.PRparameter( Pr0, "PrRho") rho = ptc.relativisticBreitWigner([rhoMass,rhoWidth,PrA1,PrRho], mPi, mPi, mPi, 1, 0, True) fitRho = amplitudeAnalysis(inFileName, sectors, {"1++0+[pi,pi]1--PiS":[rho]}, startBin, stopBin, tBins, sectorRangeMap = sectorRangeMap) fitRho.loadData(referenceWave = referenceWave) fitRho.finishModelSetup() fitRho.fitShapeParameters() fitRho.calculateNonShapeParameters() fitRho.mode = AMPL # fitRho.removeGlobalPhaseFromComa() return fitRho
def doFitRhoPrime(inFileName, sectors, startBin, stopBin, tBins, sectorRangeMap = {},referenceWave = ""): rhoMass = ptc.parameter( mRho, "rhoMass" ) rhoWidth = ptc.parameter( Grho , "rhoWidth") rhoPrimeMass = ptc.parameter( mRhoPrime, "rhoPrimeMass" ) rhoPrimeWidth = ptc.parameter( GrhoPrime, "rhoPrimeWidth") ratio = ptc.parameter( .9 , "reImRatio" ) rho = ptc.relativisticBreitWigner([rhoMass,rhoWidth], mPi, mPi, mPi, 1, 0, False) rhoPrime = ptc.relativisticBreitWignerRatio([rhoPrimeMass,rhoPrimeWidth,ratio], mPi, mPi, mPi, 1, 0, False) fitRho = amplitudeAnalysis(inFileName, sectors, {"1++0+[pi,pi]1--PiS":[rho, rhoPrime]}, startBin, stopBin, tBins, sectorRangeMap = sectorRangeMap) fitRho.loadData(referenceWave = referenceWave) fitRho.finishModelSetup() fitRho.fitShapeParameters() fitRho.calculateNonShapeParameters() fitRho.mode = AMPL # fitRho.removeGlobalPhaseFromComa() return fitRho
def doFit1500(inFileName, sectors, startBin, stopBin, tBins, sectorRangeMap={"0-+0+[pi,pi]0++PiS": (1.15, 1.75)}, referenceWave="", writeResultToFile=None): fixedAMPD_sub = pc.fixedParameterization( "/nfs/freenas/tuph/e18/project/compass/analysis/fkrinner/fkrinner/trunk/massDependentFit/scripts/anything/zeroModes/bwAmplitudes_noBF/amp_0mp0pSigmaPiS" ) const = pc.constant() linea = pc.linear() f0mass = ptc.parameter(m1500, "1500mass") f0width = ptc.parameter(G1500, "1500width") f0_1500 = ptc.relativisticBreitWigner([f0mass, f0width], mPi, mPi, mPi, 0, 0, False) fit1500 = amplitudeAnalysis( inFileName, sectors, {"0-+0+[pi,pi]0++PiS": [f0_1500, fixedAMPD_sub]}, startBin, stopBin, tBins, sectorRangeMap=sectorRangeMap) # fit1500 = amplitudeAnalysis(inFileName, sectors, {"0-+0+[pi,pi]0++PiS":[f0_1500, const, linea]}, startBin, stopBin, tBins, sectorRangeMap = sectorRangeMap) fit1500.loadData(referenceWave=referenceWave) fit1500.finishModelSetup() fit1500.fitShapeParameters() fit1500.calculateNonShapeParameters() fit1500.mode = AMPL # fit1500.removeGlobalPhaseFromComa() if writeResultToFile: with open(writeResultToFile, 'a') as outFile: if len(tBins) > 1: raise ValueError("More than one t' bin not supported") resultString = str(tBins[0]) + " 666. " + str( f0mass.value) + ' ' + str(f0mass.error) + ' ' + str( f0width.value) + ' ' + str(f0width.error) + "\n" outFile.write(resultString) return fit1500
def main(): checkLaTeX() style = modernplotting.mpplot.PlotterStyle() # style.p2dColorMap = 'ocean_r' # style.p2dColorMap = 'YlOrRd' style.p2dColorMap = 'Reds' inFileName = "/nfs/mds/user/fkrinner/extensiveFreedIsobarStudies/results_exotic.root" sectors = ["1-+1+[pi,pi]1--PiP"] tBin = int(sys.argv[1]) if tBin < 0 or tBin > 3: raise ValueError("Invalid t' bin: " + str(tBin)) tBins = [tBin] startBin = 13 stopBin = 50 if len(sys.argv) > 3: startBin = int(sys.argv[2]) stopBin = int(sys.argv[3]) if len(sys.argv) == 4: startBin = int(sys.argv[2]) stopBin = int(sys.argv[3]) acv = 130. # artificial coma value # acv = 1.3e-5 # artificial coma value seedint = randint(0,10000) # startBin = 25 # stopBin = 30 methodBinRanges = { "fitF2" : (22, 50), "fitRhoF" : (22, 50), "fixedShapeF2" : (22, 50)} # methodBinRanges = {} # Override here rhoRange = None for a in sys.argv: if a.startswith("range"): rhoRange = float(a[5:]) sectorRangeMap = {"1++0+[pi,pi]1--PiS":(0.,rhoRange)} sectorRangeMap = {} # sectorRangeMap = {"1-+1+[pi,pi]1--PiP":(0.,1.2)} fixSectorRangeMap = {"1-+1+[pi,pi]1--PiP":(0.,1.12)} allMethods = {} methodStrings = {} shortlabels = { "fixedShapeF0" : r"$\text{fix}_{f_0}^{~}$", "fixedShapeRhoP" : r"$\text{fix}_\rho^{P}$", "fixedShapeRhoF" : r"$\text{fix}_\rho^{F}$", "fixedShapeBothRho" : r"$\text{fix}_\rho^{2}$", "fixedShapeF2" : r"$\text{fix}_{f_2}$", "fixedShapes" : r"$\text{fix}_\text{all}^{~}$", "pipiS" : r"$\phi_{[\pi\pi]_S}^{~}$", "fitRho" : r"$\text{fit}_\rho$", "fitRhoP" : r"$\text{fit}_\rho^{P}$", "fitRhoF" : r"$\text{fit}_\rho^{F}$", "fitBothRho" : r"$\text{fit}_\rho^{2}$", "fitF2" : r"$\text{fit}_{f_2}$", "smooth" : r"smooth"} # # - - - - --- Start here with the model builtind --- - - - - # # rhoRe0 = 0.579053 rhoIm0 = 0.109177 rhoMass = ptc.parameter(mRho, "rho_mass") rhoWidth = ptc.parameter(Grho, "rho_width") rho = ptc.relativisticBreitWigner([rhoMass,rhoWidth], mPi, mPi, mPi, 1, 1, False) poleReal = ptc.parameter(rhoRe0, "rhoRe") poleImag = ptc.parameter(rhoIm0, "rhoIm") nPol = 1 for a in sys.argv: if a.startswith("nPol"): nPol = int(a[4:]) polyDeg_po = 8 for a in sys.argv: if a.startswith("pdpo"): polyDeg_po = int(a[4:]) params = [poleReal,poleImag] for i in range(1, nPol): rePol = ptc.parameter(1.96, "polRe_"+str(i)) imPol = ptc.parameter(0.28, "polIm_"+str(i)) params.append(rePol) params.append(imPol) for d in range(polyDeg_po): params.append(ptc.parameter(2.*random()-1., "c_"+str(d))) Kmatrix = ptc.simpleOneChannelKmatrix(params, nPol, polyDeg_po, 4*mPi**2) useCM = False for a in sys.argv: if a == "CM": useCM = True if a == "rho": useCM = False Kmatrix.use_CM = useCM pPolyDeg3 = 7 pPolyDeg2 = 4 for a in sys.argv: if a.startswith("m3pol"): pPolyDeg3 = int(a[5:]) if a.startswith("m2pol"): pPolyDeg2 = int(a[5:]) params = [] for d in range(pPolyDeg2): for e in range(pPolyDeg3+1): params.append(ptc.parameter(2.*random()-1., "c_"+str(d+1)+"_"+str(e))) pPoly = ptc.twoDimensionalRealPolynomial(pPolyDeg2, pPolyDeg3, params, baseExponent = 2) # baseExponent = 2: polynomial in s func = ptc.multiply([Kmatrix, pPoly]) model = [func] # model = [rho] # # - - - - --- Stop the model building here --- - - - - # # zeroModeParameters = None fixZeroMode = True if fixZeroMode: fixedShapes = doFixedShapes(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave, acv = acv, sectorRangeMap = fixSectorRangeMap) zeroModeParameters = fixedShapes.getZeroModeParametersForMode() # RV = fixedShapes.produceResultViewer(zeroModeParameters,"1-+1+[pi,pi]1--PiP", noRun = True, plotTheory = True) # RV.plotData = True # for b in range(startBin, stopBin): # plotNameBase = "./Kmatrix_plots/1mp1p1mmPiP_<mode>_"+str(b)+"_"+str(tBin)+".pdf" # RV.writeBinToPdf(b, stdCmd = ["", plotNameBase.replace("<mode>","intens"), [], plotNameBase.replace("<mode>","argand"), []]) # return if useCM: ps = "CM" else: ps = "rho" if rhoRange is None: rrs = "" else: rrs = "range"+str(rhoRange)+'_' if nPol == 1: nps = "" else: nps = "nPol"+str(nPol)+"_" resultFile = "./KmatrixResults/1mp_Kmatrix_"+rrs+nps+ps+"_kPol"+str(polyDeg_po-1)+"_pPol"+str(pPolyDeg3)+"-"+str(pPolyDeg2)+"_t"+str(tBin)+"_m"+str(startBin)+'-'+str(stopBin)+'_'+str(seedint)+".dat" fitter = doFunctionFit(inFileName, model, startBin, stopBin, tBins, sectorRangeMap, referenceWave = referenceWave, acv = acv, zeroModeParameters = zeroModeParameters, writeResultToFile = resultFile) rhoFitter = doFunctionFit(inFileName, [rho], startBin, stopBin, tBins, fixSectorRangeMap, referenceWave = referenceWave, acv = acv, zeroModeParameters = zeroModeParameters, writeResultToFile = None) BWfitString = "BW_fit_result: " + str(rhoMass.value) + " " +str(rhoMass.error) + " " + str(rhoWidth.value) + " " + str(rhoWidth.error) # # - - - - --- Start the evaluations here --- - - - - # # nBinsPlot = 1000 def fPlot(v): return v.imag # hist = pyRootPwa.ROOT.TH2D("hhh","hhh", nBinsPlot, -.25, 6.25,nBinsPlot, -1., 1.) # for iX in range(nBinsPlot): # x = hist.GetXaxis().GetBinCenter(iX+1) # for iY in range(nBinsPlot): # y = hist.GetYaxis().GetBinCenter(iY+1) # s = x+1.j*y # val = Kmatrix.complexCall(s) # hist.SetBinContent(iX+1, iY+1,fPlot(val)) # hist.Draw("COLZ") # raw_input("press <enter> to go to the secont sheet") Kmatrix.secondSheet = True # for iX in range(nBinsPlot): # x = hist.GetXaxis().GetBinCenter(iX+1) # for iY in range(nBinsPlot): # y = hist.GetYaxis().GetBinCenter(iY+1) # s = x+1.j*y # val = Kmatrix.complexCall(s) # hist.SetBinContent(iX+1, iY+1, fPlot(val)) # hist.Draw("COLZ") res = scipy.optimize.minimize(Kmatrix.absInverse,[rhoRe0,rhoIm0]) print res.x,"pole position" mfv = res.fun resSting = str(res.fun)+ " function value should be zero" print resSting BWstring = "BW par: "+str(abs(res.x[0])**.5)+" "+str(abs(res.x[1])/abs(res.x[0])**.5)+" (all absolute values)" print BWstring with open(resultFile,'a') as outFile: outFile.write('\n'+BWstring+" "+resSting) print "= = = = = = = = = Starting BW error ersimation = = = = = = = = = " nPoints = 1000 poleMean = res.x poleSamples = [] i = 0 failCount = 0 while i < nPoints: pts = np.random.multivariate_normal(fitter.fitParameters, fitter.MINUITcoma) fitter.MINUIT_function(pts) # Call the function once to set parameters inside # fitter.model[0].setParametersAndErrors(pts, fitter.MINUITerrs) res = scipy.optimize.minimize(Kmatrix.absInverse,poleMean) if abs(res.fun) > 100*mfv: print "No more pole found (mfv = "+str(mfv)+") : fval = "+str(res.fun) failCount += 1 if failCount > nPoints: print "Failed to find poles too often.... abort" return continue # raise ValueError("No more pole found: fval = "+str(res.fun)) poleSamples.append(res.x) i+=1 print i,"Marker to find the PRINT 57473M3N7" meanPole = [0.,0.] for p in poleSamples: meanPole[0] += p[0] meanPole[1] += p[1] meanPole[0] /= len(poleSamples) meanPole[1] /= len(poleSamples) poleComa = [[0.,0.],[0.,0.]] for p in poleSamples: poleComa[0][0] += (p[0]-meanPole[0])**2 poleComa[0][1] += (p[0]-meanPole[0])*(p[1]-meanPole[1]) poleComa[1][0] += (p[1]-meanPole[1])*(p[0]-meanPole[0]) poleComa[1][1] += (p[1]-meanPole[1])**2 poleComa[0][0] /= len(poleSamples)-1 poleComa[0][1] /= len(poleSamples)-1 poleComa[1][0] /= len(poleSamples)-1 poleComa[1][1] /= len(poleSamples)-1 comaString = str(poleComa) print " - - - - - - le compaire pramaitre - - - - - - " print meanPole, poleMean print " - - - - - - le compaire pramaitre - - - - - - " print poleComa print "= = = = = = = = = Finished BW error ersimation = = = = = = = = = " mRhoP = 1.4 GrhoP = .2 res = scipy.optimize.minimize(Kmatrix.absInverse,[mRhoP**2,mRhoP*GrhoP]) print res.x,"pole position" resSting = str(res.fun)+ " function value should be zero" print resSting BWstring = "BW' par: "+str(abs(res.x[0])**.5)+" "+str(abs(res.x[1])/abs(res.x[0])**.5)+" (all absolute values)" print BWstring with open(resultFile,'a') as outFile: outFile.write('\n'+BWstring+" "+resSting+"\ncoma "+comaString) outFile.write('\n'+BWfitString) # # - - - - --- Start the evaluations here --- - - - - # # doPlots = False if doPlots: RV = fitter.produceResultViewer(zeroModeParameters,"1-+1+[pi,pi]1--PiP", noRun = True, plotTheory = True) RV.plotData = True for b in range(startBin, stopBin): plotNameBase = "./Kmatrix_plots/1mp1p1mmPiP_<mode>_"+str(b)+"_"+str(tBin)+".pdf" RV.writeBinToPdf(b, stdCmd = ["", plotNameBase.replace("<mode>","intens"), [], plotNameBase.replace("<mode>","argand"), []]) # raw_input("press <enter> to exit") return ################################################################################# ################################################################################# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # ################################################################################# ################################################################################# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # ################################################################################# ################################################################################# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # ################################################################################# ################################################################################# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # ################################################################################# ################################################################################# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # ################################################################################# ################################################################################# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # ################################################################################# ################################################################################# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # ################################################################################# ################################################################################# ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # ################################################################################# ################################################################################# # The stuff down here does not matter at the moment # polDeg = 2 outFileName = "./pietarinenFits/polyDeg"+str(polDeg)+"_t"+str(tBin)+".txt" piet = doPietarinen(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave, polDeg = polDeg, polDeg3Pi = 2, writeResultToFile = outFileName, sectorRangeMap = sectorRangeMap, acv = acv, zeroModeParameters = zeroModeParameters) if not fixZeroMode: zeroModeParameters = piet.getZeroModeParametersForMode() RV = piet.produceResultViewer(zeroModeParameters,"1-+1+[pi,pi]1--PiP", noRun = True, plotTheory = True) RV.plotData = True for b in range(startBin, stopBin): plotNameBase = "./pietarinenFits/1mp1p1mmPiP_<mode>_"+str(b)+"_"+str(tBin)+".pdf" RV.writeBinToPdf(b, stdCmd = ["", plotNameBase.replace("<mode>","intens"), [], plotNameBase.replace("<mode>","argand"), []]) # doFitRho(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave, writeResultToFile = "rhoMassesAndWidths_1-+1+1--_global.dat", sectorRangeMap = sectorRangeMap, acv = acv, polDeg = polDeg) return print "Starting with fixed shapes" fixedShapes = doFixedShapes(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave, acv = acv, sectorRangeMap = sectorRangeMap) allMethods["fixedShapes"] = fixedShapes print "Finished with fixed shapes" # print "Starting with fitting rho" # fitRho = doFitRho(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave, writeResultToFile = "rhoMassesAndWidths_1-+1+1--_global.dat", sectorRangeMap = sectorRangeMap, acv = acv) # allMethods["fitRho"] = fitRho # print "Finished with fitting rho" # if stopBin - startBin > 1: # print "Starting with smooth" # smooth = doSmooth(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave) # allMethods["smooth"] = smooth # print "Finished with smooth" if "fixedShapeRhoF" in allMethods: allMethods["fixedShapeRhoF"].setZeroModeSignature(fullSig,1) if "fitRhoF" in allMethods: allMethods["fitRhoF"].setZeroModeSignature(fullSig,1) # diffsFull, resolvedWA, nonResolvedWA, comps, resDiffs, nonResDiffs, resolvedDiffsFull,noCorrDiffs = cu.doAllComparisons(allMethods, startBin, methodBinRanges, noBelowZero = True) # print resolvedDiffsFull # from math import isnan # for pair in resolvedDiffsFull: # with modernplotting.toolkit.PdfWriter('./resolvedDiffPlots/1mp_'+pair[0]+"_"+pair[1]+"_"+str(tBin)+".pdf") as pdfOutput: # plot = style.getPlot1D() # line = [0.000000001]*len(resolvedDiffsFull[pair][0]) # line2 = [0.000000001]*len(resolvedDiffsFull[pair][0]) # one = [1.]*len(resolvedDiffsFull[pair][0]) # xAxis = [ .5 + 0.04*(startBin + i) for i in range(len(resolvedDiffsFull[pair][0]))] # for i,v in enumerate(resolvedDiffsFull[pair][0]): # if not isnan(v) and not v <= 0.: # line[i] = v # else: # line[i] = 0.000000001 # # if not pair[1] == "WAres" and not pair[1] == "WAnon": # for i,v in enumerate(resolvedDiffsFull[pair[1],pair[0]][0]): # if not isnan(v) and not v <= 0.: # line2[i] = v # else: # line2[i] = 0.000000001 # # plot.setYlog() # plot.plot(xAxis, line) # plot.plot(xAxis, one) # plot.plot(xAxis, line2) # plot.setYlim(0.00001, 10000) # plot.finishAndSaveAndClose(pdfOutput) # studyList = [] # for m in allMethods: # studyList.append(m) # studyList.sort() style.titleRight = r"$1^{-+}1^+$" style.titleLeft = LaTeX_strings.tBins[tBin] # with modernplotting.toolkit.PdfWriter("compositions_1mp_"+str(tBin)+".pdf") as pdfOutput: # plot = style.getPlot1D() # for m in studyList: # line = [0.]*len(comps[m][0]) # xAxis = [ .5 + 0.04*(startBin + i) for i in range(len(comps[m][0]))] # break # count = 0 # for m in studyList: # newLine = line[:] # for i in range(len(comps[m][0])): # newLine[i] += comps[m][0][i] # plot.axes.fill_between(xAxis, line, newLine, facecolor = modernplotting.colors.makeColorLighter(modernplotting.colors.colorScheme.blue, 0.1*count)) # count += 1 # line = newLine # plot.setYlim(0.,1.) # plot.setXlim(xAxis[0], xAxis[-1]) # plot.finishAndSaveAndClose(pdfOutput) # hist = pyRootPwa.ROOT.TH2D("hist","hist", len(studyList)+2, 0, len(studyList)+2, len(studyList), 0, len(studyList)) # # for i,m in enumerate(studyList): # for j,n in enumerate(studyList): # hist.SetBinContent(i+1, j+1, diffsFull[n,m]) # for i,m in enumerate(studyList): # hist.SetBinContent(len(studyList)+1, i+1, noCorrDiffs[m]) # hist.SetBinContent(len(studyList)+2, i+1, resDiffs[m]) # # axolotl = [] # for i,study in enumerate(studyList): # axolotl.append(shortlabels[study]) # axolotl.append(alphabet[i]) # with modernplotting.toolkit.PdfWriter("studies_1mp_"+str(tBin)+".pdf") as pdfOutput: # plot = style.getPlot2D() # plot.axes.get_xaxis().set_ticks([(i + 0.5) for i in range(len(studyList)+2)]) # plot.axes.get_yaxis().set_ticks([(i + 0.5) for i in range(len(studyList) )]) # studyPlotter.makeValuePlot(plot, hist) # # plot.axes.set_yticklabels(axolotl) # axolotl.append(unCorrected_string) # axolotl.append(weightedAVG_string) # plot.axes.set_xticklabels(axolotl, rotation = 90) # plot.setZlim((0.,1.)) # # plot.finishAndSaveAndClose(pdfOutput) # with open("studies_1mp_"+str(tBin)+".txt",'w') as out: # for axl in axolotl: # out.write(axl + ' ') # out.write("\n") # for i in range(hist.GetNbinsX()): # for j in range(hist.GetNbinsY()): # out.write(str(hist.GetBinContent(i+1, j+1)) + ' ') # out.write('\n') doRhoFits = False writeCpls = False if writeCpls: outFileCpl = open("1mp_rho_cpls_"+str(tBin)+".dat",'w') doActuallyNotFit = True if doRhoFits: with open("rhoMassesAndWidths_exotic_"+str(tBin)+".dat",'w') as out: for i in range(stopBin-startBin): binIndex = i+startBin out.write(str(binIndex)+' '+str(0.52 + 0.04*binIndex)+' ') startValueOffset = 0.00 if doActuallyNotFit: print "The fit has been turned off, due to a workaround... :(" else: exceptCount = 0 try: x,err,c2,ndf = fitRho.fitShapeParametersForBinRange([mRho+startValueOffset,Grho+startValueOffset], [0],[i], zeroModeParameters = resolvedWA) except: print "Fitter exception encountered" startValueOffset += 0.001 exceptCount += 1 if exceptCount > 3: raise Exception("Too many failed attempts: "+str(exceptCount)) out.write(str(x[0]) + ' ' + str(err[0]) + ' ' + str(x[1]) + ' ' + str(err[1])) out.write(' '+str(c2/ndf)+'\n') if writeCpls: fitRho.calculateNonShapeParametersForZeroModeParameters(resolvedWA) cpl, hess = fitRho.getCouplingParameters() hessInv = la.inv(hess[0][i]) if not len(cpl[0][1]) == 2: raise IndexError("Parameter count not 2, change implementation") integral = fitRho.model[0][i].getIntegralForFunction(0, fitRho.model[0][i].funcs[0][0]) outFileCpl.write(str(0.52 + binIndex*.04) + ' ' + str(cpl[0][i][0]**2 + cpl[0][i][0]**2) + ' ' + str(integral) + ' ') outFileCpl.write(str(cpl[0][i][0]) + ' ' + str(cpl[0][i][1]) + ' ') outFileCpl.write(str(hessInv[0][0]/2) + ' ' + str(hessInv[1][1]/2) + ' ' + str(hessInv[0][1]/2)) outFileCpl.write("\n") makeRhoFitPlots = False if makeRhoFitPlots: fitRho.calculateNonShapeParametersForZeroModeParameters(resolvedWA) rhoRV = fitRho.produceResultViewer(resolvedWA,"1-+1+[pi,pi]1--PiP", noRun = True, plotTheory = True) rhoRV.plotData = True plotNameBase = "./rhoFitPlots/1mp1p1mmPiP_<mode>_"+str(binIndex)+"_"+str(tBin)+".pdf" rhoRV.writeBinToPdf(binIndex, stdCmd = ["", plotNameBase.replace("<mode>","intens"), [], plotNameBase.replace("<mode>","argand"), []]) if writeCpls: outFileCpl.close() return ##### Writing starts here # fileNames = {} # fixedShapes.removeZeroModeFromComa() ## binRange = {"1-+1+[pi,pi]1--PiP": (10,22)} # totalHists = fixedShapes.getTotalHists(resolvedWA, binRange = binRange) # with root_open("./totals_1mp_rhoRange.root", "UPDATE") as out: # for t in totalHists: # for m in t: # m.Write() # return # for stu in allMethods: # print "Writing for '" + stu + "'" # for s, sect in enumerate(allMethods[stu].sectors): # if stu == "pipiS": # rv = allMethods[stu].produceResultViewer(allMethods[stu].getZeroModeParametersForMode(),s, plotTheory = True) # rv.run() # rv = allMethods[stu].produceResultViewer(allMethods[stu].getZeroModeParametersForMode(),s, noRun = True) # for bin in range(startBin, stopBin): # fileName = "./collectedMethods/"+stu+"_"+sect+"_1mpData_"+str(bin) # if not (sect,bin) in fileNames: # fileNames[sect,bin] = [] # fileNames[sect,bin].append(fileName) # rv.writeAmplFiles(bin, fileName = fileName) scalle = False if scalle: folder = "./comparisonResultsData_1mp_scale/" else: folder = "./comparisonResultsData_1mp/" fixedShapesFull = doFixedShapes(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave, acv = acv) for s, sect in enumerate(allMethods['fixedShapes'].sectors): # allMethods['fixedShapes'].removeZeroModeFromComa() # allMethods['fixedShapes'].removeGlobalPhaseFromComa() rv = fixedShapesFull.produceResultViewer(allMethods['fixedShapes'].getZeroModeParametersForMode(),s, noRun = True, plotTheory = True) # rv.plotData = False rv.writeBinToPdf(startBin, stdCmd = [ folder + sect + "_data_2D_"+str(tBin)+".pdf", "", [], "", []]) # rv.labelPoints = [0,10,15,20] # rv.makeLegend = True if scalle: rv.scaleTo = "maxCorrData" # rv.yAxisShift = 300. # rv.tStringYpos = 0.8 # rv.topMarginIntens = 1.4 # fakkkk = 1. else: rv.plotData = False # fakkkk = .7 # rv.tStringYpos = 0.865 # rv.topMarginIntens = 1.3 # rv.yAxisShift = 100. # rv.shiftMap = {0:(fakkkk*50.,fakkkk*-280.),10:(fakkkk*-420.,fakkkk*-50.), 15:(fakkkk*-420.,fakkkk*-30.), 20:(fakkkk*-50.,fakkkk*70.)} for b in range(startBin, stopBin): # if not bin == 27: # continue # intensNames = [name+".intens" for name in fileNames[sect,b]] # argandNames = [name+".argand" for name in fileNames[sect,b]] # intensNames = ["/nfs/freenas/tuph/e18/project/compass/analysis/fkrinner/evalDima/dima.intens"] # argandNames = ["/nfs/freenas/tuph/e18/project/compass/analysis/fkrinner/evalDima/dima.argand"] # if not scalle: if True: intensNames = [] argandNames = [] # rv.plotData = True rv.writeBinToPdf(b, stdCmd = ["", folder + sect + "_data_intens_"+str(b)+"_"+str(tBin)+".pdf", intensNames, folder + sect + "_data_argand_"+str(b)+"_"+str(tBin)+".pdf", argandNames]) rv.wiriteReImToPdf(b, folder + sect + "_data_<ri>_"+str(b)+"_"+str(tBin)+".pdf")
def main(): checkLaTeX() style = modernplotting.mpplot.PlotterStyle() # style.p2dColorMap = 'ocean_r' # style.p2dColorMap = 'YlOrRd' style.p2dColorMap = 'Reds' # referenceWave = "" inFileName = fileNameMap["std11"] for a in sys.argv: if a.startswith("mBins"): startBin = int(a.split("-")[1]) stopBin = int(a.split("-")[2]) if a.startswith("tBins"): tMin = int(a.split("-")[1]) tMax = int(a.split("-")[2]) tBins = range(tMin, tMax) nPol = 3 for a in sys.argv: if a.startswith("nPol"): nPol = int(a[4:]) f2Re0 = mF2**2 f2Im0 = mF2 * GF2 mPrime = 1.55 Gprime = .2 mPPrime = 1.91 Gpprime = .3 f2Mass = ptc.parameter(mF2, "f2_mass") f2Width = ptc.parameter(GF2, "f2_width") f2 = ptc.relativisticBreitWigner([f2Mass, f2Width], mPi, mPi, mPi, 2, 0, False) poleReal = ptc.parameter(f2Re0, "f2Re") poleImag = ptc.parameter(f2Im0, "f2Im") pPoleReal = ptc.parameter(mPrime**2, "f2pRe") pPoleImag = ptc.parameter(mPrime * Gprime, "f2pIm") ppPoleReal = ptc.parameter(mPPrime**2, "f2ppRe") ppPoleImag = ptc.parameter(mPPrime * Gpprime, "f2ppIm") # poleRealPrime = ptc.parameter(mPrime**2, "rhoRePrime") # poleImagPrime = ptc.parameter(mPrime*Gprime, "rhoImPrime") polyDeg_po = 3 for a in sys.argv: if a.startswith("pdpo"): polyDeg_po = int(a[4:]) params = [poleReal, poleImag, pPoleReal, pPoleImag, ppPoleReal, ppPoleImag] params = params[:2 * nPol] for d in range(polyDeg_po): params.append(ptc.parameter(2 * random() - 1., "c_" + str(d))) Kmatrix = ptc.simpleOneChannelKmatrix(params, nPol, polyDeg_po, 4 * mPi**2) useCM = False for a in sys.argv: if a == "CM": useCM = True if a == "rho": useCM = False if useCM: psString = "CM" else: psString = "rho" Kmatrix.use_CM = useCM for a in sys.argv: if a.startswith("polyDegP"): polyDegP = int(a[8:]) mMin = .5 + .04 * startBin mMax = .5 + .04 * stopBin smartMode = True tFuncs = [] tpPoly = [] nKpar = len(params) KparValues = [p.value for p in params] funcs = [] for d in range(polyDegP + 1): mnm = ptc.monomial(2 * d) func = ptc.multiply([Kmatrix, mnm]) funcs.append(func) phases = [] for tBin in tBins: tParams = [] for mBin in range(startBin, stopBin): phases.append( ptc.parameter(2 * pi * random(), "phi_t" + str(tBin) + "_m" + str(mBin))) for d in range(polyDegP): tParams.append( ptc.parameter( 2 * random() - 1., "c" + str(d + 1) + "_t" + str(tBin) + "_m" + str(mBin))) nPpar = len(tParams) if not smartMode: params += tParams pPoly = ptc.binnedPolynomial(tParams, mMin=mMin, mMax=mMax, nBins=stopBin - startBin, degree=polyDegP, baseExponent=2, real=True) tpPoly.append(pPoly) func = ptc.multiply([Kmatrix, pPoly]) tFuncs.append(func) bestFitVals = [ 1.591236, 0.234037, 2.419353, 0.005742, 3.702362, 0.000053, -0.189620, 0.207497, -0.058921, 0.517699, 0.166935, 0.181275, 0.959202, 1.528309, 0.501027, -1.146739, -0.535555, 0.417481, -0.419879, 1.561247, 0.120558, 1.059373, 0.393481, -0.283450, -0.182751, -0.667384, 0.619867, 0.343112, 0.069652, 0.677225, -0.116518, -0.485594, 0.693124, 0.270239, 0.139340, -2.694811, -0.062632, 1.570524, -0.493674, -2.409801, 0.394341, 0.421391, -0.524359, 0.112583, 0.285943, -0.166501, -0.408990, -0.010904, 0.088735, 0.117378, 0.166603, -0.949778, 0.500537, -1.352419, -0.639588, -2.139980, -0.146114, 1.877676, 1.025465, -0.120469, 1.197397, 0.792957, -0.507836, 0.354736, -0.571950, -0.439970, 0.635951, 1.119741, 1.078536, -1.707963, -0.894598, -0.379259, -0.256336, 1.811274, 0.460570, -2.370441, -1.519688, -2.596059, -1.472923, 0.329489, 0.963846, -0.174265, 0.497754, 0.523653, -0.082330, -2.288272, 0.238584, 2.432317, -0.219072, -1.818075, 0.101130, -1.315669, -0.095197, 0.185721, -0.468701, 1.150421, -0.706067, 1.336765, 0.114122, -2.514466, -1.292956, 0.909066, -0.136537, 1.579291, 0.917968, 0.519039, 0.560456, -3.141557, -0.919017, 1.034258, 0.651617, 0.414377, -0.954656, 0.432315, -0.250071, -0.306383, -0.916611, 0.241417, 0.196445, -0.594122, -0.610276, -2.115296, -1.232504, 0.210273, -0.539883, 1.134149, 0.582253, -1.330798, -1.189863, 2.000385, -0.286371, 0.997649, -0.268911, -0.358648, 0.209653, 0.307646, 0.294261, 2.350279, -0.342739, 1.010674, -0.547855, -1.715226, 0.599891, 0.567254, -0.731444, 2.852883, -0.398756, 2.450370, 0.296712, 0.499203, 0.284769, -7.040768, -1.148202, -0.982813, 0.349752, -6.325548, -0.494806, 0.183253, 0.745206, 2.547205, 1.571422, 0.713172, -0.253361, 0.610771, 1.308658, 1.501376, 1.023860, 2.184354, 0.927320, 0.677329, 0.589890, 0.139710, 0.550017, -0.702369, -0.847349, -0.729193, 0.541576, -0.508911, 0.495425, 1.287986, -0.364052, -1.338609, 0.281415, 0.168475, 0.184298, -0.904410, 0.193151, -0.773044, 0.324601, 4.473005, 0.046860, -0.359312, 0.368391, -1.623123, 0.531775, 0.384091, 0.988951, -0.779931, 0.030888, -0.139630, -0.264398, -9.821342, -1.601821, -7.745628, -2.010218, -3.540738, -0.067302, 0.153977, -1.635704 ] for p, par in enumerate(params): par.value = bestFitVals[p] if smartMode: params += phases sector = "2-+0+[pi,pi]2++PiS" sectors = [ "2-+0+[pi,pi]0++PiD", "2-+0+[pi,pi]1--PiP", "2-+0+[pi,pi]1--PiF", "2-+0+[pi,pi]2++PiS" ] sectorRangeMap = {} zmPars = [] fitters = [] for t, tBin in enumerate(tBins): if smartMode: ff = funcs else: ff = [tFuncs[t]] fitter = amplitudeAnalysis(inFileName, sectors, {sector: ff}, startBin, stopBin, [tBin], sectorRangeMap=sectorRangeMap) fitter.loadData(loadIntegrals=True, referenceWave=referenceWave) fitter.finishModelSetup() fitter.mode = AMPL fixSectors = [ "2-+0+[pi,pi]1--PiP", "2-+0+[pi,pi]1--PiF", "2-+0+[pi,pi]2++PiS" ] fixRangeMap = { "2-+0+[pi,pi]1--PiP": (0., 1.12), "2-+0+[pi,pi]1--PiF": (0., 1.12), "2-+0+[pi,pi]2++PiS": (0., 1.27) # Use only left side of f_2(1270) } fixedShapes = doFixedShapes(inFileName, fixSectors, startBin, stopBin, [tBin], referenceWave=referenceWave, sectorRangeMap=fixRangeMap) zmPars.append(fixedShapes.getZeroModeParametersForMode()) fitter.setZeroModeParameters(zmPars[-1]) fitter.model.setBinsToEvalueate( [0], range(stopBin - startBin) ) # [0] since it is only one tBin in this fitter (one fitter par t' bin) fitters.append(fitter) c2 = 0. for t in range(len(tBins)): ddd = fitters[t].model.fixedZMPchi2(None) print ddd, "the previous chi2 (this should not give, since it allows phase motion in the p-vector" c2 += ddd print c2 nmBins = stopBin - startBin def evalFunction(params): Kmatrix.setParameters(params[:nKpar]) chi2 = 0. for t in range(len(tBins)): if smartMode: chi2 += fitters[t].model.fixedZMPchi2_realCouplings( None, params[nKpar + t * nmBins:nKpar + (t + 1) * nmBins]) else: chi2 += fitters[t].model.fixedZMPchi2(None) return chi2 print evalFunction([p.value for p in params]), "gives it?" # return argString = ','.join([p.name + '=' + str(p.value) for p in params]) lstString = ','.join([p.name for p in params]) ndf = 0 for fitter in fitters: ndfs = fitter.model.getNDF() for t in ndfs: for m in t: ndf += m[0] - m[1] - m[2] ndf -= len(params) ndf += polyDegP * (stopBin - startBin) * ( tMax - tBin) # the couplings have just a global phase !!! # # # # # # 2mpF2_Kmatrix_nPol3_rho_kPol0_pPol0-3_t3_m49-50_5854.dat for att in range(10): # make 10 attempts at once print "Setting Start Pars for attempt", att + 1 for i in range(len(params)): if i < nKpar: params[i].value = KparValues[i] else: params[i].value = 2 * pi * random() vals = MIGRAD(argString, lstString, evalFunction) chi2 = explicit_MINUIT_function(*vals) seedint = randint(0, 10000) resultFileName = "./globalKmatrixFits/2mpF2_nPol" + str( nPol) + "_" + psString + "_kPol" + str( polyDeg_po - 1) + "_t" + str(tMin) + '-' + str(tMax) + "_m" + str( startBin) + "-" + str(stopBin) + "_polyDegP" + str( polyDegP) + "_" + str(seedint) + ".dat" with open(resultFileName, 'w') as outFile: outFile.write("- - - - parameters - - - -\n") for p in params: outFile.write(str(p) + '\n') outFile.write(" - - - - - fit - - - - -\nchi2/NDF: " + str(chi2) + "/" + str(ndf) + "=" + str(chi2 / ndf) + '\n') outFile.write("ndf corrected!!!") return parameters = [] for f in funcs: for p in f.returnParameters(): parameters.append(p) fitter.initMinuitFunction(parameters) fitter.removeZeroModeFromComa() fitter.removeGlobalPhaseFromComa() if acv is not None: print "adding ACV of", acv fitter.addComaValueForZeroMode(acv) pPoly = ptc.twoDimensionalRealPolynomial( pPolyDeg2, pPolyDeg3, params, baseExponent=2) # baseExponent = 2: polynomial in s func = ptc.multiply([Kmatrix, pPoly]) model = [func] # model = [rho] acv = None # # - - - - --- Stop the model building here --- - - - - # # zeroModeParameters = None fixZeroMode = True # print sectorRangeMap # return if fixZeroMode: fixSectors = [ "2-+0+[pi,pi]1--PiP", "2-+0+[pi,pi]1--PiF", "2-+0+[pi,pi]2++PiS" ] fixRangeMap = { "2-+0+[pi,pi]1--PiP": (0., 1.12), "2-+0+[pi,pi]1--PiF": (0., 1.12), "2-+0+[pi,pi]2++PiS": (0., 1.27) # Use only left side of f_2(1270) } fixedShapes = doFixedShapes(inFileName, fixSectors, startBin, stopBin, tBins, referenceWave=referenceWave, sectorRangeMap=fixRangeMap) zeroModeParameters = fixedShapes.getZeroModeParametersForMode() # RV = fixedShapes.produceResultViewer(zeroModeParameters,"1-+1+[pi,pi]1--PiP", noRun = True, plotTheory = True) # RV.plotData = True # for b in range(startBin, stopBin): # plotNameBase = "./Kmatrix_plots/1mp1p1mmPiP_<mode>_"+str(b)+"_"+str(tBin)+".pdf" # RV.writeBinToPdf(b, stdCmd = ["", plotNameBase.replace("<mode>","intens"), [], plotNameBase.replace("<mode>","argand"), []]) # return if useCM: ps = "CM" else: ps = "rho" if nPol == 1: nps = "" else: nps = "nPol" + str(nPol) + "_" resultFile = "./KmatrixRestrictedZMfixing_allFourSectorsActive/2mpF2_Kmatrix_" + nps + ps + "_kPol" + str( polyDeg_po - 1) + "_pPol" + str(pPolyDeg3) + "-" + str( pPolyDeg2) + "_t" + str(tBin) + "_m" + str(startBin) + '-' + str( stopBin) + '_' + str(seedint) + ".dat" fitter = doFunctionFit(inFileName, model, startBin, stopBin, tBins, sectorRangeMap, referenceWave=referenceWave, acv=acv, zeroModeParameters=zeroModeParameters, writeResultToFile=resultFile, ifn=ifn) # # - - - - --- Start the evaluations here --- - - - - # # nBinsPlot = 1000 def fPlot(v): return v.imag # hist = pyRootPwa.ROOT.TH2D("hhh","hhh", nBinsPlot, -.25, 6.25,nBinsPlot, -1., 1.) # for iX in range(nBinsPlot): # x = hist.GetXaxis().GetBinCenter(iX+1) # for iY in range(nBinsPlot): # y = hist.GetYaxis().GetBinCenter(iY+1) # s = x+1.j*y # val = Kmatrix.complexCall(s) # hist.SetBinContent(iX+1, iY+1,fPlot(val)) # hist.Draw("COLZ") # raw_input("press <enter> to go to the secont sheet") Kmatrix.secondSheet = True # for iX in range(nBinsPlot): # x = hist.GetXaxis().GetBinCenter(iX+1) # for iY in range(nBinsPlot): # y = hist.GetYaxis().GetBinCenter(iY+1) # s = x+1.j*y # val = Kmatrix.complexCall(s) # hist.SetBinContent(iX+1, iY+1, fPlot(val)) # hist.Draw("COLZ") res = scipy.optimize.minimize(Kmatrix.absInverse, [f2Re0, f2Im0]) print res.x, "pole position" mfv = res.fun resSting = str(res.fun) + " function value should be zero" print resSting BWstring = "BW par: " + str(abs(res.x[0])**.5) + " " + str( abs(res.x[1]) / abs(res.x[0])**.5) + " (all absolute values)" print BWstring if ifn is None: print "= = = = = = = = = Starting BW error ersimation = = = = = = = = = " nPoints = 1000 poleMean = res.x poleSamples = [] i = 0 failCount = 0 while i < nPoints: pts = np.random.multivariate_normal(fitter.fitParameters, fitter.MINUITcoma) fitter.MINUIT_function( pts) # Call the function once to set parameters inside # fitter.model[0].setParametersAndErrors(pts, fitter.MINUITerrs) res = scipy.optimize.minimize(Kmatrix.absInverse, poleMean) if abs(res.fun) > 100 * mfv: print "No more pole found (mfv = " + str( mfv) + ") : fval = " + str(res.fun) failCount += 1 if failCount > nPoints: print "Failed to find poles too often.... abort" return continue # raise ValueError("No more pole found: fval = "+str(res.fun)) poleSamples.append(res.x) i += 1 # print i,"Marker to find the PRINT 57473M3N7" meanPole = [0., 0.] for p in poleSamples: meanPole[0] += p[0] meanPole[1] += p[1] meanPole[0] /= len(poleSamples) meanPole[1] /= len(poleSamples) poleComa = [[0., 0.], [0., 0.]] for p in poleSamples: poleComa[0][0] += (p[0] - meanPole[0])**2 poleComa[0][1] += (p[0] - meanPole[0]) * (p[1] - meanPole[1]) poleComa[1][0] += (p[1] - meanPole[1]) * (p[0] - meanPole[0]) poleComa[1][1] += (p[1] - meanPole[1])**2 poleComa[0][0] /= len(poleSamples) - 1 poleComa[0][1] /= len(poleSamples) - 1 poleComa[1][0] /= len(poleSamples) - 1 poleComa[1][1] /= len(poleSamples) - 1 comaString = str(poleComa) print " - - - - - - le compaire pramaitre - - - - - - " print meanPole, poleMean print " - - - - - - le compaire pramaitre - - - - - - " print poleComa print "= = = = = = = = = Finished BW error ersimation = = = = = = = = = " mF2P = 1.9 GF2P = .277 res = scipy.optimize.minimize(Kmatrix.absInverse, [mF2P**2, mF2P * GF2P]) print res.x, "pole position" resSting = str(res.fun) + " function value should be zero" print resSting BWstring = "BW' par: " + str(abs(res.x[0])**.5) + " " + str( abs(res.x[1]) / abs(res.x[0])**.5) + " (all absolute values)" print BWstring with open(resultFile, 'a') as outFile: outFile.write('\n' + BWstring + " " + resSting + "\ncoma " + comaString) # outFile.write('\n'+BWfitString) # # - - - - --- Start the evaluations here --- - - - - # # doPlots = False for a in sys.argv: if a == "plot": doPlots = True if ifn is not None: doPlots = True # Set plots by default, if an inFile is given if doPlots: RV = fitter.produceResultViewer(zeroModeParameters, "2-+0+[pi,pi]2++PiS", noRun=True, plotTheory=True) RV.plotData = True for b in range(startBin, stopBin): plotNameBase = "./Kmatrix_plots/2mp0p2ppPiS_<mode>_" + str( b) + "_" + str(tBin) + "_" + str(seedint) + ".pdf" RV.writeBinToPdf(b, stdCmd=[ "", plotNameBase.replace("<mode>", "intens"), [], plotNameBase.replace("<mode>", "argand"), [] ]) # raw_input("press <enter> to exit") return