Skip to content

Commit 96e2593

Browse files
authored
Merge pull request #78 from GuiMacielPereira/add-multivariate-gaussian-fit
Add multivariate gaussian fit
2 parents 86f8e42 + 74095d3 commit 96e2593

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

EVSVesuvio/config/analysis_inputs.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(self, ipFilesPath):
101101
])
102102
constraints = ()
103103

104-
noOfMSIterations = 3 #4
104+
noOfMSIterations = 0 #4
105105
firstSpec = 144 #144
106106
lastSpec = 182 #182
107107

@@ -124,17 +124,24 @@ def __init__(self, ipFilesPath):
124124

125125

126126
class YSpaceFitInitialConditions:
127-
anything = True
127+
showPlots = True
128+
symmetrisationFlag = True
129+
rebinParametersForYSpaceFit = "-25, 0.5, 25" # Needs to be symetric
130+
fitModel = "Gaussian3D" # Options: 'SINGLE_GAUSSIAN', 'GC_C4', 'GC_C6', 'GC_C4_C6', 'DOUBLE_WELL', 'ANSIO_GAUSSIAN', 'Gaussian3D'
131+
runMinos = True
132+
globalFit = True # Performs global fit with Minuit by default
133+
nGlobalFitGroups = 4 # Number or string "ALL"
134+
maskTypeProcedure = "NAN" # Options: 'NCP', 'NAN', None
128135

129136

130137
class UserScriptControls:
131138
runRoutine = True
132139

133140
# Choose main procedure to run
134-
procedure = "BACKWARD" # Options: None, "BACKWARD", "FORWARD", "JOINT"
141+
procedure = "FORWARD" # Options: None, "BACKWARD", "FORWARD", "JOINT"
135142

136143
# Choose on which ws to perform the fit in y space
137-
fitInYSpace = None # Options: None, "BACKWARD", "FORWARD", "JOINT"
144+
fitInYSpace = "FORWARD" # Options: None, "BACKWARD", "FORWARD", "JOINT"
138145

139146

140147
class BootstrapInitialConditions:

EVSVesuvio/vesuvio_analysis/fit_in_yspace.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,31 @@ def model(x, A, sig1, sig2):
617617
defaultPars = {"A":1, "sig1":3, "sig2":5}
618618
sharedPars = ["sig1", "sig2"]
619619

620+
elif modelFlag=="Gaussian3D":
621+
def model(x, A, sig_x, sig_y, sig_z):
622+
623+
y = x[:, np.newaxis, np.newaxis]
624+
n_steps = 50 # Low number of integration steps because otherwise too slow
625+
theta = np.linspace(0, np.pi / 2, n_steps)[np.newaxis, :, np.newaxis]
626+
phi = np.linspace(0, np.pi / 2, n_steps)[np.newaxis, np.newaxis, :]
627+
628+
629+
S2_inv = np.sin(theta)**2 * np.cos(phi)**2 / sig_x**2 \
630+
+ np.sin(theta)**2 * np.sin(phi)**2 / sig_y**2 \
631+
+ np.cos(theta)**2 / sig_z**2
632+
633+
J = np.sin(theta) / S2_inv * np.exp(- y**2 / 2 * S2_inv)
634+
635+
J = np.trapz(J, x=phi, axis=2)[:, :, np.newaxis] # Keep shape
636+
J = np.trapz(J, x=theta, axis=1)
637+
638+
J *= A * 2 / np.pi * 1 / np.sqrt(2 * np.pi) * 1 / (sig_x * sig_y * sig_z) # Normalisation
639+
J = J.squeeze()
640+
return J
641+
642+
defaultPars = {"A": 1, "sig_x": 5, "sig_y": 5, "sig_z": 5}
643+
sharedPars = ["sig_x", "sig_y", "sig_z"]
644+
620645
else:
621646
raise ValueError("Fitting Model not recognized, available options: 'SINGLE_GAUSSIAN', 'GC_C4_C6', 'GC_C4'")
622647

@@ -1018,7 +1043,7 @@ def fitProfileMantidFit(yFitIC, wsYSpaceSym, wsRes):
10181043
*(1.+c6/384*(64*((x-x0)/sqrt(2)/sigma1)^6 - 480*((x-x0)/sqrt(2)/sigma1)^4 + 720*((x-x0)/sqrt(2)/sigma1)^2 - 120)),
10191044
y0=0, A=1,x0=0,sigma1=4.0,c6=0.0,ties=()
10201045
"""
1021-
elif (yFitIC.fitModel=="DOUBLE_WELL") | (yFitIC.fitModel=="ANSIO_GAUSSIAN"):
1046+
elif (yFitIC.fitModel=="DOUBLE_WELL") | (yFitIC.fitModel=="ANSIO_GAUSSIAN") | (yFitIC.fitModel=="Gaussian3D"):
10221047
return
10231048
else:
10241049
raise ValueError("fitmodel not recognized.")

0 commit comments

Comments
 (0)