How is dipole fitting performed on Brainstorm?


I am a new user on this forum and have been exploring brainstorm tutorials for a while now. I was curious to know how dipole is fitted in Brainstorm. Lets say I have my EEG recording with a certain event of interest ( spike), and that I want to fit a dipole in the brain based on that given spike. How does brainstorm fit dipoles in the source grids? Does it first determine the value of dipole amplitude in nAm or pAm and then proceeds with different orientations to compute the best goodness of fit, or does the process of searching for optimum amplitude and orientation (to explain the given event/spike ) happen at the same time?

My professor wanted me to work on something called Global Optimization where we search for the best fitting source grid location for dipole by varying amplitude and orientation in loops to compute the Goodness of fit for the given dipole. But I wanted to first check if this is the method already employed by Brainstorm or not.

Could anyone from the developer team explain to me in detail how Dipole fitting is performed on Brainstorm, and also if instead of getting just one dipole at location of best goodness of fit,*** is there a way that I can see the maximum values of goodness of fit for dipoles computed at each source grid locations*** ( best goodness of fit value obtained for lets say each of 15000 source grid locations)?

Brainstorm does not include any iterative dipole fitting algorithm. The dipole modeling option is not an iterative method, it is documented here:

For iterative dipole fitting, we rely on FieldTrip's function ft_dipolefitting.m. For understanding what this function does, I recommend you read directly the code of the function:
fieldtrip/ft_dipolefitting.m at master · fieldtrip/fieldtrip · GitHub

Hi @Francois, what does the tutorial mean by already computed dipoles in the discrete grid? Does the source grid has dipole information already decribed for all possible dipole orientations, if not then how is the optimal orientation found by the dipole scanning method?

As the tutorial says " At each point of the grid, three dipoles with orthogonal directions (x,y,z) are considered, just like the unconstrained minimum norm results."
The optimal orientation for the dipoles is estimated from these:

I looked at the Field trip dipole fitting function but couldn’t find the information where the orientation of dipole is changed iteratively to maximize gof. Can someone tell me what line of the code the orientation of the dipole is changed with each iteration? Or is values of all possible orientations a dipole can take already in the Leadfield matrix?

And also what exactly is a lead field matrix? Does it contain the Voltage/ fT signals information picked up by each sensor for all possible orientations of the sources in the source grid or does it contain information for only a unit source at a particularly defined orientation at given location in source?

The position (pos) and orientation (mom) are optimized simultaneously in ft_inverse_dipolefit.m:
fieldtrip/ft_inverse_dipolefit.m at master · fieldtrip/fieldtrip · GitHub

And also what exactly is a lead field matrix?