ROOT  6.06/08
Reference Guide
TSpectrum2Fit.cxx
Go to the documentation of this file.
1 // @(#)root/spectrum:$Id$
2 // Author: Miroslav Morhac 25/09/2006
3 
4 /////////////////////////////////////////////////////////////////////////////
5 // THIS CLASS CONTAINS ADVANCED TWO-DIMENSIONAL SPECTRA //
6 // FITTING FUNCTIONS //
7 // //
8 // These functions were written by: //
9 // Miroslav Morhac //
10 // Institute of Physics //
11 // Slovak Academy of Sciences //
12 // Dubravska cesta 9, 842 28 BRATISLAVA //
13 // SLOVAKIA //
14 // //
15 // email:fyzimiro@savba.sk, fax:+421 7 54772479 //
16 // //
17 // The original code in C has been repackaged as a C++ class by R.Brun //
18 // //
19 // The algorithms in this class have been published in the following //
20 // references: //
21 // [1] M. Morhac et al.: Efficient fitting algorithms applied to //
22 // analysis of coincidence gamma-ray spectra. Computer Physics //
23 // Communications, Vol 172/1 (2005) pp. 19-41. //
24 // //
25 // [2] M. Morhac et al.: Study of fitting algorithms applied to //
26 // simultaneous analysis of large number of peaks in gamma-ray spectra. //
27 // Applied Spectroscopy, Vol. 57, No. 7, pp. 753-760, 2003. //
28 // //
29 // //
30 //____________________________________________________________________________
31 
32 /** \class TSpectrum2Fit
33  \ingroup Hist
34  \brief Advanced 2-dimentional spectra fitting functions
35  \author Miroslav Morhac
36 
37  The original code in C has been repackaged as a C++ class by R.Brun
38 
39  The algorithms in this class have been published in the following
40  references:
41  1. M. Morhac et al.: Efficient fitting algorithms applied to
42  analysis of coincidence gamma-ray spectra. Computer Physics
43  Communications, Vol 172/1 (2005) pp. 19-41.
44 
45  2. M. Morhac et al.: Study of fitting algorithms applied to
46  simultaneous analysis of large number of peaks in gamma-ray spectra.
47  Applied Spectroscopy, Vol. 57, No. 7, pp. 753-760, 2003.
48 
49 */
50 
51 #include "TSpectrum2Fit.h"
52 #include "TMath.h"
53 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 ///default constructor
58 
59 TSpectrum2Fit::TSpectrum2Fit() :TNamed("Spectrum2Fit", "Miroslav Morhac peak fitter")
60 {
61  fNPeaks = 0;
62  fNumberIterations = 1;
63  fXmin = 0;
64  fXmax = 100;
65  fYmin = 0;
66  fYmax = 100;
67  fStatisticType = kFitOptimChiCounts;
68  fAlphaOptim = kFitAlphaHalving;
69  fPower = kFitPower2;
70  fFitTaylor = kFitTaylorOrderFirst;
71  fAlpha = 1;
72  fChi = 0;
73  fPositionInitX = 0;
74  fPositionCalcX = 0;
75  fPositionErrX = 0;
76  fPositionInitY = 0;
77  fPositionCalcY = 0;
78  fPositionErrY = 0;
79  fPositionInitX1 = 0;
80  fPositionCalcX1 = 0;
81  fPositionErrX1 = 0;
82  fPositionInitY1 = 0;
83  fPositionCalcY1 = 0;
84  fPositionErrY1 = 0;
85  fAmpInit = 0;
86  fAmpCalc = 0;
87  fAmpErr = 0;
88  fAmpInitX1 = 0;
89  fAmpCalcX1 = 0;
90  fAmpErrX1 = 0;
91  fAmpInitY1 = 0;
92  fAmpCalcY1 = 0;
93  fAmpErrY1 = 0;
94  fVolume = 0;
95  fVolumeErr = 0;
96  fSigmaInitX = 2;
97  fSigmaCalcX = 0;
98  fSigmaErrX = 0;
99  fSigmaInitY = 2;
100  fSigmaCalcY = 0;
101  fSigmaErrY = 0;
102  fRoInit = 0;
103  fRoCalc = 0;
104  fRoErr = 0;
105  fTxyInit = 0;
106  fTxyCalc = 0;
107  fTxyErr = 0;
108  fTxInit = 0;
109  fTxCalc = 0;
110  fTxErr = 0;
111  fTyInit = 0;
112  fTyCalc = 0;
113  fTyErr = 0;
114  fBxInit = 1;
115  fBxCalc = 0;
116  fBxErr = 0;
117  fByInit = 1;
118  fByCalc = 0;
119  fByErr = 0;
120  fSxyInit = 0;
121  fSxyCalc = 0;
122  fSxyErr = 0;
123  fSxInit = 0;
124  fSxCalc = 0;
125  fSxErr = 0;
126  fSyInit = 0;
127  fSyCalc = 0;
128  fSyErr = 0;
129  fA0Init = 0;
130  fA0Calc = 0;
131  fA0Err = 0;
132  fAxInit = 0;
133  fAxCalc = 0;
134  fAxErr = 0;
135  fAyInit = 0;
136  fAyCalc = 0;
137  fAyErr = 0;
138  fFixPositionX = 0;
139  fFixPositionY = 0;
140  fFixPositionX1 = 0;
141  fFixPositionY1 = 0;
142  fFixAmp = 0;
143  fFixAmpX1 = 0;
144  fFixAmpY1 = 0;
145  fFixSigmaX = false;
146  fFixSigmaY = false;
147  fFixRo = true;
148  fFixTxy = true;
149  fFixTx = true;
150  fFixTy = true;
151  fFixBx = true;
152  fFixBy = true;
153  fFixSxy = true;
154  fFixSx = true;
155  fFixSy = true;
156  fFixA0 = true;
157  fFixAx = true;
158  fFixAy = true;
159 
160 }
161 ////////////////////////////////////////////////////////////////////////////////
162 ///numberPeaks: number of fitted peaks (must be greater than zero)
163 ///the constructor allocates arrays for all fitted parameters (peak positions, amplitudes etc) and sets the member
164 ///variables to their default values. One can change these variables by member functions (setters) of TSpectrumFit class.
165 
166 TSpectrum2Fit::TSpectrum2Fit(Int_t numberPeaks) :TNamed("Spectrum2Fit", "Miroslav Morhac peak fitter")
167 {
168 /*
169 <div class=Section1>
170 
171 <p class=MsoNormal style='text-align:justify'>Shape function of the fitted
172 peaks contains the two-dimensional symmetrical Gaussian two one-dimensional
173 symmetrical Gaussian ridges as well as nonsymmetrical terms and background.</p>
174 
175 <p class=MsoNormal style='text-align:justify'><sub><span style='font-size:10.0pt'><img
176 width=600 height=401 src="gif/spectrum2fit_constructor_image001.gif"></span></sub></p>
177 
178 </div>
179 
180  */
181  if (numberPeaks <= 0){
182  Error ("TSpectrum2Fit","Invalid number of peaks, must be > than 0");
183  return;
184  }
185  fNPeaks = numberPeaks;
186  fNumberIterations = 1;
187  fXmin = 0;
188  fXmax = 100;
189  fYmin = 0;
190  fYmax = 100;
193  fPower = kFitPower2;
195  fAlpha = 1;
196  fChi = 0;
197  fPositionInitX = new Double_t[numberPeaks];
198  fPositionCalcX = new Double_t[numberPeaks];
199  fPositionErrX = new Double_t[numberPeaks];
200  fPositionInitY = new Double_t[numberPeaks];
201  fPositionCalcY = new Double_t[numberPeaks];
202  fPositionErrY = new Double_t[numberPeaks];
203  fPositionInitX1 = new Double_t[numberPeaks];
204  fPositionCalcX1 = new Double_t[numberPeaks];
205  fPositionErrX1 = new Double_t[numberPeaks];
206  fPositionInitY1 = new Double_t[numberPeaks];
207  fPositionCalcY1 = new Double_t[numberPeaks];
208  fPositionErrY1 = new Double_t[numberPeaks];
209  fAmpInit = new Double_t[numberPeaks];
210  fAmpCalc = new Double_t[numberPeaks];
211  fAmpErr = new Double_t[numberPeaks];
212  fAmpInitX1 = new Double_t[numberPeaks];
213  fAmpCalcX1 = new Double_t[numberPeaks];
214  fAmpErrX1 = new Double_t[numberPeaks];
215  fAmpInitY1 = new Double_t[numberPeaks];
216  fAmpCalcY1 = new Double_t[numberPeaks];
217  fAmpErrY1 = new Double_t[numberPeaks];
218  fVolume = new Double_t[numberPeaks];
219  fVolumeErr = new Double_t[numberPeaks];
220  fSigmaInitX = 2;
221  fSigmaCalcX = 0;
222  fSigmaErrX = 0;
223  fSigmaInitY = 2;
224  fSigmaCalcY = 0;
225  fSigmaErrY = 0;
226  fRoInit = 0;
227  fRoCalc = 0;
228  fRoErr = 0;
229  fTxyInit = 0;
230  fTxyCalc = 0;
231  fTxyErr = 0;
232  fTxInit = 0;
233  fTxCalc = 0;
234  fTxErr = 0;
235  fTyInit = 0;
236  fTyCalc = 0;
237  fTyErr = 0;
238  fBxInit = 1;
239  fBxCalc = 0;
240  fBxErr = 0;
241  fByInit = 1;
242  fByCalc = 0;
243  fByErr = 0;
244  fSxyInit = 0;
245  fSxyCalc = 0;
246  fSxyErr = 0;
247  fSxInit = 0;
248  fSxCalc = 0;
249  fSxErr = 0;
250  fSyInit = 0;
251  fSyCalc = 0;
252  fSyErr = 0;
253  fA0Init = 0;
254  fA0Calc = 0;
255  fA0Err = 0;
256  fAxInit = 0;
257  fAxCalc = 0;
258  fAxErr = 0;
259  fAyInit = 0;
260  fAyCalc = 0;
261  fAyErr = 0;
262  fFixPositionX = new Bool_t[numberPeaks];
263  fFixPositionY = new Bool_t[numberPeaks];
264  fFixPositionX1 = new Bool_t[numberPeaks];
265  fFixPositionY1 = new Bool_t[numberPeaks];
266  fFixAmp = new Bool_t[numberPeaks];
267  fFixAmpX1 = new Bool_t[numberPeaks];
268  fFixAmpY1 = new Bool_t[numberPeaks];
269  fFixSigmaX = false;
270  fFixSigmaY = false;
271  fFixRo = true;
272  fFixTxy = true;
273  fFixTx = true;
274  fFixTy = true;
275  fFixBx = true;
276  fFixBy = true;
277  fFixSxy = true;
278  fFixSx = true;
279  fFixSy = true;
280  fFixA0 = true;
281  fFixAx = true;
282  fFixAy = true;
283 }
284 
285 ////////////////////////////////////////////////////////////////////////////////
286 /// destructor
287 
289 {
290  delete [] fPositionInitX;
291  delete [] fPositionCalcX;
292  delete [] fPositionErrX;
293  delete [] fFixPositionX;
294  delete [] fPositionInitY;
295  delete [] fPositionCalcY;
296  delete [] fPositionErrY;
297  delete [] fFixPositionY;
298  delete [] fPositionInitX1;
299  delete [] fPositionCalcX1;
300  delete [] fPositionErrX1;
301  delete [] fFixPositionX1;
302  delete [] fPositionInitY1;
303  delete [] fPositionCalcY1;
304  delete [] fPositionErrY1;
305  delete [] fFixPositionY1;
306  delete [] fAmpInit;
307  delete [] fAmpCalc;
308  delete [] fAmpErr;
309  delete [] fFixAmp;
310  delete [] fAmpInitX1;
311  delete [] fAmpCalcX1;
312  delete [] fAmpErrX1;
313  delete [] fFixAmpX1;
314  delete [] fAmpInitY1;
315  delete [] fAmpCalcY1;
316  delete [] fAmpErrY1;
317  delete [] fFixAmpY1;
318  delete [] fVolume;
319  delete [] fVolumeErr;
320 }
321 
322 
323 /////////////////BEGINNING OF AUXILIARY FUNCTIONS USED BY FITTING FUNCTIONS//////////////////////////
324 ////////////////////////////////////////////////////////////////////////////////
325 ///////////////////////////////////////////////////////////////////////////////
326 /// AUXILIARY FUNCTION //
327 /// //
328 /// This function calculates error function of x. //
329 /// //
330 ///////////////////////////////////////////////////////////////////////////////
331 
333 {
334  Double_t da1 = 0.1740121, da2 = -0.0479399, da3 = 0.3739278, dap =
335  0.47047;
336  Double_t a, t, c, w;
337  a = TMath::Abs(x);
338  w = 1. + dap * a;
339  t = 1. / w;
340  w = a * a;
341  if (w < 700)
342  c = exp(-w);
343 
344  else {
345  c = 0;
346  }
347  c = c * t * (da1 + t * (da2 + t * da3));
348  if (x < 0)
349  c = 1. - c;
350  return (c);
351 }
352 
353 ////////////////////////////////////////////////////////////////////////////////
354 ///////////////////////////////////////////////////////////////////////////////
355 /// AUXILIARY FUNCTION //
356 /// //
357 /// This function calculates derivative of error function of x. //
358 /// //
359 ///////////////////////////////////////////////////////////////////////////////
360 
362 {
363  Double_t a, t, c, w;
364  Double_t da1 = 0.1740121, da2 = -0.0479399, da3 = 0.3739278, dap =
365  0.47047;
366  a = TMath::Abs(x);
367  w = 1. + dap * a;
368  t = 1. / w;
369  w = a * a;
370  if (w < 700)
371  c = exp(-w);
372 
373  else {
374  c = 0;
375  }
376  c = (-1.) * dap * c * t * t * (da1 + t * (2. * da2 + t * 3. * da3)) -
377  2. * a * Erfc(a);
378  return (c);
379 }
380 
381 ////////////////////////////////////////////////////////////////////////////////
382 ///power function
383 
385 {
386  Double_t c;
387  Double_t a2 = a*a;
388  c = 1;
389  if (pw > 0) c *= a2;
390  if (pw > 2) c *= a2;
391  if (pw > 4) c *= a2;
392  if (pw > 6) c *= a2;
393  if (pw > 8) c *= a2;
394  if (pw > 10) c *= a2;
395  if (pw > 12) c *= a2;
396  return (c);
397 }
399 {
400 //////////////////////////////////////////////////////////////////////////////////
401 // AUXILIARY FUNCTION //
402 // //
403 // This function calculates solution of the system of linear equations. //
404 // The matrix a should have a dimension size*(size+4) //
405 // The calling function should fill in the matrix, the column size should //
406 // contain vector y (right side of the system of equations). The result is //
407 // placed into size+1 column of the matrix. //
408 // according to sigma of peaks. //
409 // Function parameters: //
410 // -a-matrix with dimension size*(size+4) // //
411 // -size-number of rows of the matrix //
412 // //
413 //////////////////////////////////////////////////////////////////////////////////
414  Int_t i, j, k = 0;
415  Double_t sk = 0, b, lambdak, normk, normk_old = 0;
416 
417  do {
418  normk = 0;
419 
420  //calculation of rk and norm
421  for (i = 0; i < size; i++) {
422  a[i][size + 2] = -a[i][size]; //rk=-C
423  for (j = 0; j < size; j++) {
424  a[i][size + 2] += a[i][j] * a[j][size + 1]; //A*xk-C
425  }
426  normk += a[i][size + 2] * a[i][size + 2]; //calculation normk
427  }
428 
429  //calculation of sk
430  if (k != 0) {
431  sk = normk / normk_old;
432  }
433 
434  //calculation of uk
435  for (i = 0; i < size; i++) {
436  a[i][size + 3] = -a[i][size + 2] + sk * a[i][size + 3]; //uk=-rk+sk*uk-1
437  }
438 
439  //calculation of lambdak
440  lambdak = 0;
441  for (i = 0; i < size; i++) {
442  for (j = 0, b = 0; j < size; j++) {
443  b += a[i][j] * a[j][size + 3]; //A*uk
444  }
445  lambdak += b * a[i][size + 3];
446  }
447  if (TMath::Abs(lambdak) > 1e-50) //computer zero
448  lambdak = normk / lambdak;
449 
450  else
451  lambdak = 0;
452  for (i = 0; i < size; i++)
453  a[i][size + 1] += lambdak * a[i][size + 3]; //xk+1=xk+lambdak*uk
454  normk_old = normk;
455  k += 1;
456  } while (k < size && TMath::Abs(normk) > 1e-50); //computer zero
457  return;
458 }
459 
460 ////////////////////////////////////////////////////////////////////////////////
461 ///////////////////////////////////////////////////////////////////////////////////
462 /// AUXILIARY FUNCTION //
463 /// //
464 /// This function calculates 2D peaks shape function (see manual) //
465 /// Function parameters: //
466 /// -numOfFittedPeaks-number of fitted peaks //
467 /// -x-channel in x-dimension //
468 /// -y-channel in y-dimension //
469 /// -parameter-array of peaks parameters (amplitudes and positions) //
470 /// -sigmax-sigmax of peaks //
471 /// -sigmay-sigmay of peaks //
472 /// -ro-correlation coefficient //
473 /// -a0,ax,ay-bac kground coefficients //
474 /// -txy,tx,ty, sxy,sy,sx-relative amplitudes //
475 /// -bx, by-slopes //
476 /// //
477 ///////////////////////////////////////////////////////////////////////////////////
478 
480  const Double_t *parameter, Double_t sigmax,
481  Double_t sigmay, Double_t ro, Double_t a0, Double_t ax,
482  Double_t ay, Double_t txy, Double_t sxy, Double_t tx,
483  Double_t ty, Double_t sx, Double_t sy, Double_t bx,
484  Double_t by)
485 {
486  Int_t j;
487  Double_t r, p, r1, e, ex, ey, vx, s2, px, py, rx, ry, erx, ery;
488  vx = 0;
489  s2 = TMath::Sqrt(2.0);
490  for (j = 0; j < numOfFittedPeaks; j++) {
491  p = (x - parameter[7 * j + 1]) / sigmax;
492  r = (y - parameter[7 * j + 2]) / sigmay;
493  if (TMath::Abs(p) < 3 && TMath::Abs(r) < 3) {
494  e = (p * p - 2 * ro * p * r + r * r) / (2 * (1 - ro * ro));
495  if (e < 700)
496  r1 = exp(-e);
497 
498  else {
499  r1 = 0;
500  }
501  if (txy != 0) {
502  px = 0, py = 0;
503  erx = Erfc(p / s2 + 1 / (2 * bx)), ery =
504  Erfc(r / s2 + 1 / (2 * by));
505  ex = p / (s2 * bx), ey = r / (s2 * by);
506  if (TMath::Abs(ex) < 9 && TMath::Abs(ey) < 9) {
507  px = exp(ex) * erx, py = exp(ey) * ery;
508  }
509  r1 += 0.5 * txy * px * py;
510  }
511  if (sxy != 0) {
512  rx = Erfc(p / s2), ry = Erfc(r / s2);
513  r1 += 0.5 * sxy * rx * ry;
514  }
515  vx = vx + parameter[7 * j] * r1;
516  }
517  p = (x - parameter[7 * j + 5]) / sigmax;
518  if (TMath::Abs(p) < 3) {
519  e = p * p / 2;
520  if (e < 700)
521  r1 = exp(-e);
522 
523  else {
524  r1 = 0;
525  }
526  if (tx != 0) {
527  px = 0;
528  erx = Erfc(p / s2 + 1 / (2 * bx));
529  ex = p / (s2 * bx);
530  if (TMath::Abs(ex) < 9) {
531  px = exp(ex) * erx;
532  }
533  r1 += 0.5 * tx * px;
534  }
535  if (sx != 0) {
536  rx = Erfc(p / s2);
537  r1 += 0.5 * sx * rx;
538  }
539  vx = vx + parameter[7 * j + 3] * r1;
540  }
541  r = (y - parameter[7 * j + 6]) / sigmay;
542  if (TMath::Abs(r) < 3) {
543  e = r * r / 2;
544  if (e < 700)
545  r1 = exp(-e);
546 
547  else {
548  r1 = 0;
549  }
550  if (ty != 0) {
551  py = 0;
552  ery = Erfc(r / s2 + 1 / (2 * by));
553  ey = r / (s2 * by);
554  if (TMath::Abs(ey) < 9) {
555  py = exp(ey) * ery;
556  }
557  r1 += 0.5 * ty * py;
558  }
559  if (sy != 0) {
560  ry = Erfc(r / s2);
561  r1 += 0.5 * sy * ry;
562  }
563  vx = vx + parameter[7 * j + 4] * r1;
564  }
565  }
566  vx = vx + a0 + ax * x + ay * y;
567  return (vx);
568 }
569 
570 ////////////////////////////////////////////////////////////////////////////////
571 ///////////////////////////////////////////////////////////////////////////////////
572 /// AUXILIARY FUNCTION //
573 /// //
574 /// This function calculates derivative of 2D peaks shape function (see manual) //
575 /// according to amplitude of 2D peak //
576 /// Function parameters: //
577 /// -x-channel in x-dimension //
578 /// -y-channel in y-dimension //
579 /// -x0-position of peak in x-dimension //
580 /// -y0-position of peak in y-dimension //
581 /// -sigmax-sigmax of peaks //
582 /// -sigmay-sigmay of peaks //
583 /// -ro-correlation coefficient //
584 /// -txy, sxy-relative amplitudes //
585 /// -bx, by-slopes //
586 /// //
587 ///////////////////////////////////////////////////////////////////////////////////
588 
590  Double_t sigmax, Double_t sigmay, Double_t ro,
591  Double_t txy, Double_t sxy, Double_t bx, Double_t by)
592 {
593  Double_t p, r, r1 = 0, e, ex, ey, px, py, rx, ry, erx, ery, s2;
594  p = (x - x0) / sigmax;
595  r = (y - y0) / sigmay;
596  if (TMath::Abs(p) < 3 && TMath::Abs(r) < 3) {
597  s2 = TMath::Sqrt(2.0);
598  e = (p * p - 2 * ro * p * r + r * r) / (2 * (1 - ro * ro));
599  if (e < 700)
600  r1 = exp(-e);
601 
602  else {
603  r1 = 0;
604  }
605  if (txy != 0) {
606  px = 0, py = 0;
607  erx = Erfc(p / s2 + 1 / (2 * bx)), ery =
608  Erfc(r / s2 + 1 / (2 * by));
609  ex = p / (s2 * bx), ey = r / (s2 * by);
610  if (TMath::Abs(ex) < 9 && TMath::Abs(ey) < 9) {
611  px = exp(ex) * erx, py = exp(ey) * ery;
612  }
613  r1 += 0.5 * txy * px * py;
614  }
615  if (sxy != 0) {
616  rx = Erfc(p / s2), ry = Erfc(r / s2);
617  r1 += 0.5 * sxy * rx * ry;
618  }
619  }
620  return (r1);
621 }
622 
623 ////////////////////////////////////////////////////////////////////////////////
624 ///////////////////////////////////////////////////////////////////////////////////
625 /// AUXILIARY FUNCTION //
626 /// //
627 /// This function calculates derivative of 2D peaks shape function (see manual) //
628 /// according to amplitude of the ridge //
629 /// Function parameters: //
630 /// -x-channel in x-dimension //
631 /// -x0-position of peak in x-dimension //
632 /// -y0-position of peak in y-dimension //
633 /// -sigmax-sigmax of peaks //
634 /// -ro-correlation coefficient //
635 /// -tx, sx-relative amplitudes //
636 /// -bx-slope //
637 /// //
638 ///////////////////////////////////////////////////////////////////////////////////
639 
641  Double_t sx, Double_t bx)
642 {
643  Double_t p, r1 = 0, px, erx, rx, ex, s2;
644  p = (x - x0) / sigmax;
645  if (TMath::Abs(p) < 3) {
646  s2 = TMath::Sqrt(2.0);
647  p = p * p / 2;
648  if (p < 700)
649  r1 = exp(-p);
650 
651  else {
652  r1 = 0;
653  }
654  if (tx != 0) {
655  px = 0;
656  erx = Erfc(p / s2 + 1 / (2 * bx));
657  ex = p / (s2 * bx);
658  if (TMath::Abs(ex) < 9) {
659  px = exp(ex) * erx;
660  }
661  r1 += 0.5 * tx * px;
662  }
663  if (sx != 0) {
664  rx = Erfc(p / s2);
665  r1 += 0.5 * sx * rx;
666  }
667  }
668  return (r1);
669 }
670 
671 ////////////////////////////////////////////////////////////////////////////////
672 ///////////////////////////////////////////////////////////////////////////////////
673 /// AUXILIARY FUNCTION //
674 /// //
675 /// This function calculates derivative of 2D peaks shape function (see manual) //
676 /// according to x position of 2D peak //
677 /// Function parameters: //
678 /// -x-channel in x-dimension //
679 /// -y-channel in y-dimension //
680 /// -a-amplitude //
681 /// -x0-position of peak in x-dimension //
682 /// -y0-position of peak in y-dimension //
683 /// -sigmax-sigmax of peaks //
684 /// -sigmay-sigmay of peaks //
685 /// -ro-correlation coefficient //
686 /// -txy, sxy-relative amplitudes //
687 /// -bx, by-slopes //
688 /// //
689 ///////////////////////////////////////////////////////////////////////////////////
690 
692  Double_t y0, Double_t sigmax, Double_t sigmay,
693  Double_t ro, Double_t txy, Double_t sxy, Double_t bx,
694  Double_t by)
695 {
696  Double_t p, r, r1 = 0, e, ex, ey, px, py, rx, ry, erx, ery, s2;
697  p = (x - x0) / sigmax;
698  r = (y - y0) / sigmay;
699  if (TMath::Abs(p) < 3 && TMath::Abs(r) < 3) {
700  s2 = TMath::Sqrt(2.0);
701  e = (p * p - 2 * ro * p * r + r * r) / (2 * (1 - ro * ro));
702  if (e < 700)
703  r1 = exp(-e);
704 
705  else {
706  r1 = 0;
707  }
708  e = -(ro * r - p) / sigmax;
709  e = e / (1 - ro * ro);
710  r1 = r1 * e;
711  if (txy != 0) {
712  px = 0, py = 0;
713  erx =
714  (-Erfc(p / s2 + 1 / (2 * bx)) / (s2 * bx * sigmax) -
715  Derfc(p / s2 + 1 / (2 * bx)) / (s2 * sigmax)), ery =
716  Erfc(r / s2 + 1 / (2 * by));
717  ex = p / (s2 * bx), ey = r / (s2 * by);
718  if (TMath::Abs(ex) < 9 && TMath::Abs(ey) < 9) {
719  px = exp(ex) * erx, py = exp(ey) * ery;
720  }
721  r1 += 0.5 * txy * px * py;
722  }
723  if (sxy != 0) {
724  rx = -Derfc(p / s2) / (s2 * sigmax), ry = Erfc(r / s2);
725  r1 += 0.5 * sxy * rx * ry;
726  }
727  r1 = a * r1;
728  }
729  return (r1);
730 }
731 
732 ////////////////////////////////////////////////////////////////////////////////
733 ///////////////////////////////////////////////////////////////////////////////////
734 /// AUXILIARY FUNCTION //
735 /// //
736 /// This function calculates second derivative of 2D peaks shape function //
737 /// (see manual) according to x position of 2D peak //
738 /// Function parameters: //
739 /// -x-channel in x-dimension //
740 /// -y-channel in y-dimension //
741 /// -a-amplitude //
742 /// -x0-position of peak in x-dimension //
743 /// -y0-position of peak in y-dimension //
744 /// -sigmax-sigmax of peaks //
745 /// -sigmay-sigmay of peaks //
746 /// -ro-correlation coefficient //
747 /// //
748 ///////////////////////////////////////////////////////////////////////////////////
749 
751  Double_t y0, Double_t sigmax, Double_t sigmay,
752  Double_t ro)
753 {
754  Double_t p, r, r1 = 0, e;
755  p = (x - x0) / sigmax;
756  r = (y - y0) / sigmay;
757  if (TMath::Abs(p) < 3 && TMath::Abs(r) < 3) {
758  e = (p * p - 2 * ro * p * r + r * r) / (2 * (1 - ro * ro));
759  if (e < 700)
760  r1 = exp(-e);
761 
762  else {
763  r1 = 0;
764  }
765  e = -(ro * r - p) / sigmax;
766  e = e / (1 - ro * ro);
767  r1 = r1 * (e * e - 1 / ((1 - ro * ro) * sigmax * sigmax));
768  r1 = a * r1;
769  }
770  return (r1);
771 }
773  Double_t y0, Double_t sigmax, Double_t sigmay,
774  Double_t ro, Double_t txy, Double_t sxy, Double_t bx,
775  Double_t by)
776 {
777 //////////////////////////////////////////////////////////////////////////////////
778 // AUXILIARY FUNCTION //
779 // //
780 // This function calculates derivative of 2D peaks shape function (see manual) //
781 // according to y position of 2D peak //
782 // Function parameters: //
783 // -x-channel in x-dimension //
784 // -y-channel in y-dimension //
785 // -a-amplitude //
786 // -x0-position of peak in x-dimension //
787 // -y0-position of peak in y-dimension //
788 // -sigmax-sigmax of peaks //
789 // -sigmay-sigmay of peaks //
790 // -ro-correlation coefficient //
791 // -txy, sxy-relative amplitudes //
792 // -bx, by-slopes //
793 // //
794 //////////////////////////////////////////////////////////////////////////////////
795  Double_t p, r, r1 = 0, e, ex, ey, px, py, rx, ry, erx, ery, s2;
796  p = (x - x0) / sigmax;
797  r = (y - y0) / sigmay;
798  if (TMath::Abs(p) < 3 && TMath::Abs(r) < 3) {
799  s2 = TMath::Sqrt(2.0);
800  e = (p * p - 2 * ro * p * r + r * r) / (2 * (1 - ro * ro));
801  if (e < 700)
802  r1 = exp(-e);
803 
804  else {
805  r1 = 0;
806  }
807  e = -(ro * p - r) / sigmay;
808  e = e / (1 - ro * ro);
809  r1 = r1 * e;
810  if (txy != 0) {
811  px = 0, py = 0;
812  ery =
813  (-Erfc(r / s2 + 1 / (2 * by)) / (s2 * by * sigmay) -
814  Derfc(r / s2 + 1 / (2 * by)) / (s2 * sigmay)), erx =
815  Erfc(p / s2 + 1 / (2 * bx));
816  ex = p / (s2 * bx), ey = r / (s2 * by);
817  if (TMath::Abs(ex) < 9 && TMath::Abs(ey) < 9) {
818  px = exp(ex) * erx, py = exp(ey) * ery;
819  }
820  r1 += 0.5 * txy * px * py;
821  }
822  if (sxy != 0) {
823  ry = -Derfc(r / s2) / (s2 * sigmay), rx = Erfc(p / s2);
824  r1 += 0.5 * sxy * rx * ry;
825  }
826  r1 = a * r1;
827  }
828  return (r1);
829 }
830 
831 ////////////////////////////////////////////////////////////////////////////////
832 ///////////////////////////////////////////////////////////////////////////////////
833 /// AUXILIARY FUNCTION //
834 /// //
835 /// This function calculates second derivative of 2D peaks shape function //
836 /// (see manual) according to y position of 2D peak //
837 /// Function parameters: //
838 /// -x-channel in x-dimension //
839 /// -y-channel in y-dimension //
840 /// -a-amplitude //
841 /// -x0-position of peak in x-dimension //
842 /// -y0-position of peak in y-dimension //
843 /// -sigmax-sigmax of peaks //
844 /// -sigmay-sigmay of peaks //
845 /// -ro-correlation coefficient //
846 /// //
847 ///////////////////////////////////////////////////////////////////////////////////
848 
850  Double_t y0, Double_t sigmax, Double_t sigmay,
851  Double_t ro)
852 {
853  Double_t p, r, r1 = 0, e;
854  p = (x - x0) / sigmax;
855  r = (y - y0) / sigmay;
856  if (TMath::Abs(p) < 3 && TMath::Abs(r) < 3) {
857  e = (p * p - 2 * ro * p * r + r * r) / (2 * (1 - ro * ro));
858  if (e < 700)
859  r1 = exp(-e);
860 
861  else {
862  r1 = 0;
863  }
864  e = -(ro * p - r) / sigmay;
865  e = e / (1 - ro * ro);
866  r1 = r1 * (e * e - 1 / ((1 - ro * ro) * sigmay * sigmay));
867  r1 = a * r1;
868  }
869  return (r1);
870 }
871 
872 ////////////////////////////////////////////////////////////////////////////////
873 ///////////////////////////////////////////////////////////////////////////////////
874 /// AUXILIARY FUNCTION //
875 /// //
876 /// This function calculates derivative of 2D peaks shape function (see manual) //
877 /// according to x position of 1D ridge //
878 /// Function parameters: //
879 /// -x-channel in x-dimension //
880 /// -ax-amplitude of ridge //
881 /// -x0-position of peak in x-dimension //
882 /// -sigmax-sigmax of peaks //
883 /// -ro-correlation coefficient //
884 /// -tx, sx-relative amplitudes //
885 /// -bx-slope //
886 /// //
887 ///////////////////////////////////////////////////////////////////////////////////
888 
890  Double_t tx, Double_t sx, Double_t bx)
891 {
892  Double_t p, e, r1 = 0, px, rx, erx, ex, s2;
893  p = (x - x0) / sigmax;
894  if (TMath::Abs(p) < 3) {
895  s2 = TMath::Sqrt(2.0);
896  e = p * p / 2;
897  if (e < 700)
898  r1 = exp(-e);
899 
900  else {
901  r1 = 0;
902  }
903  r1 = r1 * p / sigmax;
904  if (tx != 0) {
905  px = 0;
906  erx =
907  (-Erfc(p / s2 + 1 / (2 * bx)) / (s2 * bx * sigmax) -
908  Derfc(p / s2 + 1 / (2 * bx)) / (s2 * sigmax));
909  ex = p / (s2 * bx);
910  if (TMath::Abs(ex) < 9)
911  px = exp(ex) * erx;
912  r1 += 0.5 * tx * px;
913  }
914  if (sx != 0) {
915  rx = -Derfc(p / s2) / (s2 * sigmax);
916  r1 += 0.5 * sx * rx;
917  }
918  r1 = ax * r1;
919  }
920  return (r1);
921 }
922 
923 ////////////////////////////////////////////////////////////////////////////////
924 ///////////////////////////////////////////////////////////////////////////////////
925 /// AUXILIARY FUNCTION //
926 /// //
927 /// This function calculates second derivative of 2D peaks shape function //
928 /// (see manual) according to x position of 1D ridge //
929 /// Function parameters: //
930 /// -x-channel in x-dimension //
931 /// -ax-amplitude of ridge //
932 /// -x0-position of peak in x-dimension //
933 /// -sigmax-sigmax of peaks //
934 /// //
935 ///////////////////////////////////////////////////////////////////////////////////
936 
938  Double_t sigmax)
939 {
940  Double_t p, e, r1 = 0;
941  p = (x - x0) / sigmax;
942  if (TMath::Abs(p) < 3) {
943  e = p * p / 2;
944  if (e < 700)
945  r1 = exp(-e);
946 
947  else {
948  r1 = 0;
949  }
950  r1 = r1 * (p * p / (sigmax * sigmax) - 1 / (sigmax * sigmax));
951  r1 = ax * r1;
952  }
953  return (r1);
954 }
955 
956 ////////////////////////////////////////////////////////////////////////////////
957 ///////////////////////////////////////////////////////////////////////////////////
958 /// AUXILIARY FUNCTION //
959 /// //
960 /// This function calculates derivative of peaks shape function (see manual) //
961 /// according to sigmax of peaks. //
962 /// Function parameters: //
963 /// -numOfFittedPeaks-number of fitted peaks //
964 /// -x,y-position of channel //
965 /// -parameter-array of peaks parameters (amplitudes and positions) //
966 /// -sigmax-sigmax of peaks //
967 /// -sigmay-sigmay of peaks //
968 /// -ro-correlation coefficient //
969 /// -txy, sxy, tx, sx-relative amplitudes //
970 /// -bx, by-slopes //
971 /// //
972 ///////////////////////////////////////////////////////////////////////////////////
973 
975  const Double_t *parameter, Double_t sigmax,
976  Double_t sigmay, Double_t ro, Double_t txy,
977  Double_t sxy, Double_t tx, Double_t sx, Double_t bx,
978  Double_t by)
979 {
980  Double_t p, r, r1 =
981  0, e, a, b, x0, y0, s2, px, py, rx, ry, erx, ery, ex, ey;
982  Int_t j;
983  s2 = TMath::Sqrt(2.0);
984  for (j = 0; j < numOfFittedPeaks; j++) {
985  a = parameter[7 * j];
986  x0 = parameter[7 * j + 1];
987  y0 = parameter[7 * j + 2];
988  p = (x - x0) / sigmax;
989  r = (y - y0) / sigmay;
990  if (TMath::Abs(p) < 3 && TMath::Abs(r) < 3) {
991  e = (p * p - 2 * ro * p * r + r * r) / (2 * (1 - ro * ro));
992  if (e < 700)
993  e = exp(-e);
994 
995  else {
996  e = 0;
997  }
998  b = -(ro * p * r - p * p) / sigmax;
999  e = e * b / (1 - ro * ro);
1000  if (txy != 0) {
1001  px = 0, py = 0;
1002  erx =
1003  -Erfc(p / s2 + 1 / (2 * bx)) * p / (s2 * bx * sigmax) -
1004  Derfc(p / s2 + 1 / (2 * bx)) * p / (s2 * sigmax), ery =
1005  Erfc(r / s2 + 1 / (2 * by));
1006  ex = p / (s2 * bx), ey = r / (s2 * by);
1007  if (TMath::Abs(ex) < 9 && TMath::Abs(ey) < 9) {
1008  px = exp(ex) * erx, py = exp(ey) * ery;
1009  }
1010  e += 0.5 * txy * px * py;
1011  }
1012  if (sxy != 0) {
1013  rx = -Derfc(p / s2) * p / (s2 * sigmax), ry = Erfc(r / s2);
1014  e += 0.5 * sxy * rx * ry;
1015  }
1016  r1 = r1 + a * e;
1017  }
1018  if (TMath::Abs(p) < 3) {
1019  x0 = parameter[7 * j + 5];
1020  p = (x - x0) / sigmax;
1021  b = p * p / 2;
1022  if (b < 700)
1023  e = exp(-b);
1024 
1025  else {
1026  e = 0;
1027  }
1028  e = 2 * b * e / sigmax;
1029  if (tx != 0) {
1030  px = 0;
1031  erx =
1032  (-Erfc(p / s2 + 1 / (2 * bx)) * p / (s2 * bx * sigmax) -
1033  Derfc(p / s2 + 1 / (2 * bx)) * p / (s2 * sigmax));
1034  ex = p / (s2 * bx);
1035  if (TMath::Abs(ex) < 9)
1036  px = exp(ex) * erx;
1037  e += 0.5 * tx * px;
1038  }
1039  if (sx != 0) {
1040  rx = -Derfc(p / s2) * p / (s2 * sigmax);
1041  e += 0.5 * sx * rx;
1042  }
1043  r1 += parameter[7 * j + 3] * e;
1044  }
1045  }
1046  return (r1);
1047 }
1048 
1049 ////////////////////////////////////////////////////////////////////////////////
1050 ///////////////////////////////////////////////////////////////////////////////////
1051 /// AUXILIARY FUNCTION //
1052 /// //
1053 /// This function calculates second derivative of peaks shape function //
1054 /// (see manual) according to sigmax of peaks. //
1055 /// Function parameters: //
1056 /// -numOfFittedPeaks-number of fitted peaks //
1057 /// -x,y-position of channel //
1058 /// -parameter-array of peaks parameters (amplitudes and positions) //
1059 /// -sigmax-sigmax of peaks //
1060 /// -sigmay-sigmay of peaks //
1061 /// -ro-correlation coefficient //
1062 /// //
1063 ///////////////////////////////////////////////////////////////////////////////////
1064 
1066  Double_t y, const Double_t *parameter,
1067  Double_t sigmax, Double_t sigmay,
1068  Double_t ro)
1069 {
1070  Double_t p, r, r1 = 0, e, a, b, x0, y0;
1071  Int_t j;
1072  for (j = 0; j < numOfFittedPeaks; j++) {
1073  a = parameter[7 * j];
1074  x0 = parameter[7 * j + 1];
1075  y0 = parameter[7 * j + 2];
1076  p = (x - x0) / sigmax;
1077  r = (y - y0) / sigmay;
1078  if (TMath::Abs(p) < 3 && TMath::Abs(r) < 3) {
1079  e = (p * p - 2 * ro * p * r + r * r) / (2 * (1 - ro * ro));
1080  if (e < 700)
1081  e = exp(-e);
1082 
1083  else {
1084  e = 0;
1085  }
1086  b = -(ro * p * r - p * p) / sigmax;
1087  e = e * (b * b / (1 - ro * ro) -
1088  (3 * p * p - 2 * ro * p * r) / (sigmax * sigmax)) / (1 -
1089  ro
1090  *
1091  ro);
1092  r1 = r1 + a * e;
1093  }
1094  if (TMath::Abs(p) < 3) {
1095  x0 = parameter[7 * j + 5];
1096  p = (x - x0) / sigmax;
1097  b = p * p / 2;
1098  if (b < 700)
1099  e = exp(-b);
1100 
1101  else {
1102  e = 0;
1103  }
1104  e = e * (4 * b * b - 6 * b) / (sigmax * sigmax);
1105  r1 += parameter[7 * j + 3] * e;
1106  }
1107  }
1108  return (r1);
1109 }
1110 
1111 ////////////////////////////////////////////////////////////////////////////////
1112 ///////////////////////////////////////////////////////////////////////////////////
1113 /// AUXILIARY FUNCTION //
1114 /// //
1115 /// This function calculates derivative of peaks shape function (see manual) //
1116 /// according to sigmax of peaks. //
1117 /// Function parameters: //
1118 /// -numOfFittedPeaks-number of fitted peaks //
1119 /// -x,y-position of channel //
1120 /// -parameter-array of peaks parameters (amplitudes and positions) //
1121 /// -sigmax-sigmax of peaks //
1122 /// -sigmay-sigmay of peaks //
1123 /// -ro-correlation coefficient //
1124 /// -txy, sxy, ty, sy-relative amplitudes //
1125 /// -bx, by-slopes //
1126 /// //
1127 ///////////////////////////////////////////////////////////////////////////////////
1128 
1130  const Double_t *parameter, Double_t sigmax,
1131  Double_t sigmay, Double_t ro, Double_t txy,
1132  Double_t sxy, Double_t ty, Double_t sy, Double_t bx,
1133  Double_t by)
1134 {
1135  Double_t p, r, r1 =
1136  0, e, a, b, x0, y0, s2, px, py, rx, ry, erx, ery, ex, ey;
1137  Int_t j;
1138  s2 = TMath::Sqrt(2.0);
1139  for (j = 0; j < numOfFittedPeaks; j++) {
1140  a = parameter[7 * j];
1141  x0 = parameter[7 * j + 1];
1142  y0 = parameter[7 * j + 2];
1143  p = (x - x0) / sigmax;
1144  r = (y - y0) / sigmay;
1145  if (TMath::Abs(p) < 3 && TMath::Abs(r) < 3) {
1146  e = (p * p - 2 * ro * p * r + r * r) / (2 * (1 - ro * ro));
1147  if (e < 700)
1148  e = exp(-e);
1149 
1150  else {
1151  e = 0;
1152  }
1153  b = -(ro * p * r - r * r) / sigmay;
1154  e = e * b / (1 - ro * ro);
1155  if (txy != 0) {
1156  px = 0, py = 0;
1157  ery =
1158  -Erfc(r / s2 + 1 / (2 * by)) * r / (s2 * by * sigmay) -
1159  Derfc(r / s2 + 1 / (2 * by)) * r / (s2 * sigmay), erx =
1160  Erfc(p / s2 + 1 / (2 * bx));
1161  ex = p / (s2 * bx), ey = r / (s2 * by);
1162  if (TMath::Abs(ex) < 9 && TMath::Abs(ey) < 9) {
1163  px = exp(ex) * erx, py = exp(ey) * ery;
1164  }
1165  e += 0.5 * txy * px * py;
1166  }
1167  if (sxy != 0) {
1168  ry = -Derfc(r / s2) * r / (s2 * sigmay), rx = Erfc(p / s2);
1169  e += 0.5 * sxy * rx * ry;
1170  }
1171  r1 = r1 + a * e;
1172  }
1173  if (TMath::Abs(r) < 3) {
1174  y0 = parameter[7 * j + 6];
1175  r = (y - y0) / sigmay;
1176  b = r * r / 2;
1177  if (b < 700)
1178  e = exp(-b);
1179 
1180  else {
1181  e = 0;
1182  }
1183  e = 2 * b * e / sigmay;
1184  if (ty != 0) {
1185  py = 0;
1186  ery =
1187  (-Erfc(r / s2 + 1 / (2 * by)) * r / (s2 * by * sigmay) -
1188  Derfc(r / s2 + 1 / (2 * by)) * r / (s2 * sigmay));
1189  ey = r / (s2 * by);
1190  if (TMath::Abs(ey) < 9)
1191  py = exp(ey) * ery;
1192  e += 0.5 * ty * py;
1193  }
1194  if (sy != 0) {
1195  ry = -Derfc(r / s2) * r / (s2 * sigmay);
1196  e += 0.5 * sy * ry;
1197  }
1198  r1 += parameter[7 * j + 4] * e;
1199  }
1200  }
1201  return (r1);
1202 }
1203 
1204 ////////////////////////////////////////////////////////////////////////////////
1205 ///////////////////////////////////////////////////////////////////////////////////
1206 /// AUXILIARY FUNCTION //
1207 /// //
1208 /// This function calculates second derivative of peaks shape function //
1209 /// (see manual) according to sigmay of peaks. //
1210 /// Function parameters: //
1211 /// -numOfFittedPeaks-number of fitted peaks //
1212 /// -x,y-position of channel //
1213 /// -parameter-array of peaks parameters (amplitudes and positions) //
1214 /// -sigmax-sigmax of peaks //
1215 /// -sigmay-sigmay of peaks //
1216 /// -ro-correlation coefficient //
1217 /// //
1218 ///////////////////////////////////////////////////////////////////////////////////
1219 
1221  Double_t y, const Double_t *parameter,
1222  Double_t sigmax, Double_t sigmay,
1223  Double_t ro)
1224 {
1225  Double_t p, r, r1 = 0, e, a, b, x0, y0;
1226  Int_t j;
1227  for (j = 0; j < numOfFittedPeaks; j++) {
1228  a = parameter[7 * j];
1229  x0 = parameter[7 * j + 1];
1230  y0 = parameter[7 * j + 2];
1231  p = (x - x0) / sigmax;
1232  r = (y - y0) / sigmay;
1233  if (TMath::Abs(p) < 3 && TMath::Abs(r) < 3) {
1234  e = (p * p - 2 * ro * p * r + r * r) / (2 * (1 - ro * ro));
1235  if (e < 700)
1236  e = exp(-e);
1237 
1238  else {
1239  e = 0;
1240  }
1241  b = -(ro * p * r - r * r) / sigmay;
1242  e = e * (b * b / (1 - ro * ro) -
1243  (3 * r * r - 2 * ro * r * p) / (sigmay * sigmay)) / (1 -
1244  ro
1245  *
1246  ro);
1247  r1 = r1 + a * e;
1248  }
1249  if (TMath::Abs(r) < 3) {
1250  y0 = parameter[7 * j + 6];
1251  r = (y - y0) / sigmay;
1252  b = r * r / 2;
1253  if (b < 700)
1254  e = exp(-b);
1255 
1256  else {
1257  e = 0;
1258  }
1259  e = e * (4 * b * b - 6 * b) / (sigmay * sigmay);
1260  r1 += parameter[7 * j + 4] * e;
1261  }
1262  }
1263  return (r1);
1264 }
1265 
1266 ////////////////////////////////////////////////////////////////////////////////
1267 ///////////////////////////////////////////////////////////////////////////////////
1268 /// AUXILIARY FUNCTION //
1269 /// //
1270 /// This function calculates derivative of peaks shape function (see manual) //
1271 /// according to correlation coefficient ro. //
1272 /// Function parameters: //
1273 /// -numOfFittedPeaks-number of fitted peaks //
1274 /// -x,y-position of channel //
1275 /// -parameter-array of peaks parameters (amplitudes and positions) //
1276 /// -sx-sigmax of peaks //
1277 /// -sy-sigmay of peaks //
1278 /// -r-correlation coefficient ro //
1279 /// //
1280 ///////////////////////////////////////////////////////////////////////////////////
1281 
1283  const Double_t *parameter, Double_t sx, Double_t sy,
1284  Double_t r)
1285 {
1286  Double_t px, qx, rx, vx, x0, y0, a, ex, tx;
1287  Int_t j;
1288  vx = 0;
1289  for (j = 0; j < numOfFittedPeaks; j++) {
1290  a = parameter[7 * j];
1291  x0 = parameter[7 * j + 1];
1292  y0 = parameter[7 * j + 2];
1293  px = (x - x0) / sx;
1294  qx = (y - y0) / sy;
1295  if (TMath::Abs(px) < 3 && TMath::Abs(qx) < 3) {
1296  rx = (px * px - 2 * r * px * qx + qx * qx);
1297  ex = rx / (2 * (1 - r * r));
1298  if ((ex) < 700)
1299  ex = exp(-ex);
1300 
1301  else {
1302  ex = 0;
1303  }
1304  tx = px * qx / (1 - r * r);
1305  tx = tx - r * rx / ((1 - r * r) * (1 - r * r));
1306  vx = vx + a * ex * tx;
1307  }
1308  }
1309  return (vx);
1310 }
1311 
1312 ////////////////////////////////////////////////////////////////////////////////
1313 ///////////////////////////////////////////////////////////////////////////////////
1314 /// AUXILIARY FUNCTION //
1315 /// //
1316 /// This function calculates derivative of peaks shape function (see manual) //
1317 /// according to relative amplitude txy. //
1318 /// Function parameters: //
1319 /// -numOfFittedPeaks-number of fitted peaks //
1320 /// -x,y-position of channel //
1321 /// -parameter-array of peaks parameters (amplitudes and positions) //
1322 /// -sigmax-sigmax of peaks //
1323 /// -sigmay-sigmay of peaks //
1324 /// -bx, by-slopes //
1325 /// //
1326 ///////////////////////////////////////////////////////////////////////////////////
1327 
1329  const Double_t *parameter, Double_t sigmax,
1330  Double_t sigmay, Double_t bx, Double_t by)
1331 {
1332  Double_t p, r, r1 = 0, ex, ey, px, py, erx, ery, s2, x0, y0, a;
1333  Int_t j;
1334  s2 = TMath::Sqrt(2.0);
1335  for (j = 0; j < numOfFittedPeaks; j++) {
1336  a = parameter[7 * j];
1337  x0 = parameter[7 * j + 1];
1338  y0 = parameter[7 * j + 2];
1339  p = (x - x0) / sigmax;
1340  r = (y - y0) / sigmay;
1341  px = 0, py = 0;
1342  erx = Erfc(p / s2 + 1 / (2 * bx)), ery =
1343  Erfc(r / s2 + 1 / (2 * by));
1344  ex = p / (s2 * bx), ey = r / (s2 * by);
1345  if (TMath::Abs(ex) < 9 && TMath::Abs(ey) < 9) {
1346  px = exp(ex) * erx, py = exp(ey) * ery;
1347  }
1348  r1 += 0.5 * a * px * py;
1349  }
1350  return (r1);
1351 }
1352 
1353 ////////////////////////////////////////////////////////////////////////////////
1354 ///////////////////////////////////////////////////////////////////////////////////
1355 /// AUXILIARY FUNCTION //
1356 /// //
1357 /// This function calculates derivative of peaks shape function (see manual) //
1358 /// according to relative amplitude sxy. //
1359 /// Function parameters: //
1360 /// -numOfFittedPeaks-number of fitted peaks //
1361 /// -x,y-position of channel //
1362 /// -parameter-array of peaks parameters (amplitudes and positions) //
1363 /// -sigmax-sigmax of peaks //
1364 /// -sigmay-sigmay of peaks //
1365 /// //
1366 ///////////////////////////////////////////////////////////////////////////////////
1367 
1369  const Double_t *parameter, Double_t sigmax,
1370  Double_t sigmay)
1371 {
1372  Double_t p, r, r1 = 0, rx, ry, x0, y0, a, s2;
1373  Int_t j;
1374  s2 = TMath::Sqrt(2.0);
1375  for (j = 0; j < numOfFittedPeaks; j++) {
1376  a = parameter[7 * j];
1377  x0 = parameter[7 * j + 1];
1378  y0 = parameter[7 * j + 2];
1379  p = (x - x0) / sigmax;
1380  r = (y - y0) / sigmay;
1381  rx = Erfc(p / s2), ry = Erfc(r / s2);
1382  r1 += 0.5 * a * rx * ry;
1383  }
1384  return (r1);
1385 }
1386 
1387 ////////////////////////////////////////////////////////////////////////////////
1388 ///////////////////////////////////////////////////////////////////////////////////
1389 /// AUXILIARY FUNCTION //
1390 /// //
1391 /// This function calculates derivative of peaks shape function (see manual) //
1392 /// according to relative amplitude tx. //
1393 /// Function parameters: //
1394 /// -numOfFittedPeaks-number of fitted peaks //
1395 /// -x-position of channel //
1396 /// -parameter-array of peaks parameters (amplitudes and positions) //
1397 /// -sigmax-sigma of 1D ridge //
1398 /// -bx-slope //
1399 /// //
1400 ///////////////////////////////////////////////////////////////////////////////////
1401 
1403  const Double_t *parameter, Double_t sigmax,
1404  Double_t bx)
1405 {
1406  Double_t p, r1 = 0, ex, px, erx, s2, ax, x0;
1407  Int_t j;
1408  s2 = TMath::Sqrt(2.0);
1409  for (j = 0; j < numOfFittedPeaks; j++) {
1410  ax = parameter[7 * j + 3];
1411  x0 = parameter[7 * j + 5];
1412  p = (x - x0) / sigmax;
1413  px = 0;
1414  erx = Erfc(p / s2 + 1 / (2 * bx));
1415  ex = p / (s2 * bx);
1416  if (TMath::Abs(ex) < 9) {
1417  px = exp(ex) * erx;
1418  }
1419  r1 += 0.5 * ax * px;
1420  }
1421  return (r1);
1422 }
1423 
1424 ////////////////////////////////////////////////////////////////////////////////
1425 ///////////////////////////////////////////////////////////////////////////////////
1426 /// AUXILIARY FUNCTION //
1427 /// //
1428 /// This function calculates derivative of peaks shape function (see manual) //
1429 /// according to relative amplitude ty. //
1430 /// Function parameters: //
1431 /// -numOfFittedPeaks-number of fitted peaks //
1432 /// -x-position of channel //
1433 /// -parameter-array of peaks parameters (amplitudes and positions) //
1434 /// -sigmax-sigma of 1D ridge //
1435 /// -bx-slope //
1436 /// //
1437 ///////////////////////////////////////////////////////////////////////////////////
1438 
1440  const Double_t *parameter, Double_t sigmax,
1441  Double_t bx)
1442 {
1443  Double_t p, r1 = 0, ex, px, erx, s2, ax, x0;
1444  Int_t j;
1445  s2 = TMath::Sqrt(2.0);
1446  for (j = 0; j < numOfFittedPeaks; j++) {
1447  ax = parameter[7 * j + 4];
1448  x0 = parameter[7 * j + 6];
1449  p = (x - x0) / sigmax;
1450  px = 0;
1451  erx = Erfc(p / s2 + 1 / (2 * bx));
1452  ex = p / (s2 * bx);
1453  if (TMath::Abs(ex) < 9) {
1454  px = exp(ex) * erx;
1455  }
1456  r1 += 0.5 * ax * px;
1457  }
1458  return (r1);
1459 }
1460 
1461 ////////////////////////////////////////////////////////////////////////////////
1462 ///////////////////////////////////////////////////////////////////////////////////
1463 /// AUXILIARY FUNCTION //
1464 /// //
1465 /// This function calculates derivative of peaks shape function (see manual) //
1466 /// according to relative amplitude sx. //
1467 /// Function parameters: //
1468 /// -numOfFittedPeaks-number of fitted peaks //
1469 /// -x-position of channel //
1470 /// -parameter-array of peaks parameters (amplitudes and positions) //
1471 /// -sigmax-sigma of 1D ridge //
1472 /// //
1473 ///////////////////////////////////////////////////////////////////////////////////
1474 
1476  const Double_t *parameter, Double_t sigmax)
1477 {
1478  Double_t p, r1 = 0, rx, ax, x0, s2;
1479  Int_t j;
1480  s2 = TMath::Sqrt(2.0);
1481  for (j = 0; j < numOfFittedPeaks; j++) {
1482  ax = parameter[7 * j + 3];
1483  x0 = parameter[7 * j + 5];
1484  p = (x - x0) / sigmax;
1485  s2 = TMath::Sqrt(2.0);
1486  rx = Erfc(p / s2);
1487  r1 += 0.5 * ax * rx;
1488  }
1489  return (r1);
1490 }
1491 
1492 ////////////////////////////////////////////////////////////////////////////////
1493 ///////////////////////////////////////////////////////////////////////////////////
1494 /// AUXILIARY FUNCTION //
1495 /// //
1496 /// This function calculates derivative of peaks shape function (see manual) //
1497 /// according to relative amplitude sy. //
1498 /// Function parameters: //
1499 /// -numOfFittedPeaks-number of fitted peaks //
1500 /// -x-position of channel //
1501 /// -parameter-array of peaks parameters (amplitudes and positions) //
1502 /// -sigmax-sigma of 1D ridge //
1503 /// //
1504 ///////////////////////////////////////////////////////////////////////////////////
1505 
1507  const Double_t *parameter, Double_t sigmax)
1508 {
1509  Double_t p, r1 = 0, rx, ax, x0, s2;
1510  Int_t j;
1511  s2 = TMath::Sqrt(2.0);
1512  for (j = 0; j < numOfFittedPeaks; j++) {
1513  ax = parameter[7 * j + 4];
1514  x0 = parameter[7 * j + 6];
1515  p = (x - x0) / sigmax;
1516  s2 = TMath::Sqrt(2.0);
1517  rx = Erfc(p / s2);
1518  r1 += 0.5 * ax * rx;
1519  }
1520  return (r1);
1521 }
1522 
1523 ////////////////////////////////////////////////////////////////////////////////
1524 ///////////////////////////////////////////////////////////////////////////////////
1525 /// AUXILIARY FUNCTION //
1526 /// //
1527 /// This function calculates derivative of peaks shape function (see manual) //
1528 /// according to slope bx. //
1529 /// Function parameters: //
1530 /// -numOfFittedPeaks-number of fitted peaks //
1531 /// -x,y-position of channel //
1532 /// -parameter-array of peaks parameters (amplitudes and positions) //
1533 /// -sigmax-sigmax of peaks //
1534 /// -sigmay-sigmay of peaks //
1535 /// -txy, tx-relative amplitudes //
1536 /// -bx, by-slopes //
1537 /// //
1538 ///////////////////////////////////////////////////////////////////////////////////
1539 
1541  const Double_t *parameter, Double_t sigmax,
1542  Double_t sigmay, Double_t txy, Double_t tx, Double_t bx,
1543  Double_t by)
1544 {
1545  Double_t p, r, r1 = 0, a, x0, y0, s2, px, py, erx, ery, ex, ey;
1546  Int_t j;
1547  s2 = TMath::Sqrt(2.0);
1548  for (j = 0; j < numOfFittedPeaks; j++) {
1549  a = parameter[7 * j];
1550  x0 = parameter[7 * j + 1];
1551  y0 = parameter[7 * j + 2];
1552  p = (x - x0) / sigmax;
1553  r = (y - y0) / sigmay;
1554  if (txy != 0) {
1555  px = 0, py = 0;
1556  erx =
1557  -Erfc(p / s2 + 1 / (2 * bx)) * p / (s2 * bx * bx) -
1558  Derfc(p / s2 + 1 / (2 * bx)) / (s2 * bx * bx), ery =
1559  Erfc(r / s2 + 1 / (2 * by));
1560  ex = p / (s2 * bx), ey = r / (s2 * by);
1561  if (TMath::Abs(ex) < 9 && TMath::Abs(ey) < 9) {
1562  px = exp(ex) * erx, py = exp(ey) * ery;
1563  }
1564  r1 += 0.5 * a * txy * px * py;
1565  }
1566  a = parameter[7 * j + 3];
1567  x0 = parameter[7 * j + 5];
1568  p = (x - x0) / sigmax;
1569  if (tx != 0) {
1570  px = 0;
1571  erx =
1572  (-Erfc(p / s2 + 1 / (2 * bx)) * p / (s2 * bx * bx) -
1573  Derfc(p / s2 + 1 / (2 * bx)) / (s2 * bx * bx));
1574  ex = p / (s2 * bx);
1575  if (TMath::Abs(ex) < 9)
1576  px = exp(ex) * erx;
1577  r1 += 0.5 * a * tx * px;
1578  }
1579  }
1580  return (r1);
1581 }
1582 
1583 ////////////////////////////////////////////////////////////////////////////////
1584 ///////////////////////////////////////////////////////////////////////////////////
1585 /// AUXILIARY FUNCTION //
1586 /// //
1587 /// This function calculates derivative of peaks shape function (see manual) //
1588 /// according to slope by. //
1589 /// Function parameters: //
1590 /// -numOfFittedPeaks-number of fitted peaks //
1591 /// -x,y-position of channel //
1592 /// -parameter-array of peaks parameters (amplitudes and positions) //
1593 /// -sigmax-sigmax of peaks //
1594 /// -sigmay-sigmay of peaks //
1595 /// -txy, ty-relative amplitudes //
1596 /// -bx, by-slopes //
1597 /// //
1598 ///////////////////////////////////////////////////////////////////////////////////
1599 
1601  const Double_t *parameter, Double_t sigmax,
1602  Double_t sigmay, Double_t txy, Double_t ty, Double_t bx,
1603  Double_t by)
1604 {
1605  Double_t p, r, r1 = 0, a, x0, y0, s2, px, py, erx, ery, ex, ey;
1606  Int_t j;
1607  s2 = TMath::Sqrt(2.0);
1608  for (j = 0; j < numOfFittedPeaks; j++) {
1609  a = parameter[7 * j];
1610  x0 = parameter[7 * j + 1];
1611  y0 = parameter[7 * j + 2];
1612  p = (x - x0) / sigmax;
1613  r = (y - y0) / sigmay;
1614  if (txy != 0) {
1615  px = 0, py = 0;
1616  ery =
1617  -Erfc(r / s2 + 1 / (2 * by)) * r / (s2 * by * by) -
1618  Derfc(r / s2 + 1 / (2 * by)) / (s2 * by * by), erx =
1619  Erfc(p / s2 + 1 / (2 * bx));
1620  ex = p / (s2 * bx), ey = r / (s2 * by);
1621  if (TMath::Abs(ex) < 9 && TMath::Abs(ey) < 9) {
1622  px = exp(ex) * erx, py = exp(ey) * ery;
1623  }
1624  r1 += 0.5 * a * txy * px * py;
1625  }
1626  a = parameter[7 * j + 4];
1627  y0 = parameter[7 * j + 6];
1628  r = (y - y0) / sigmay;
1629  if (ty != 0) {
1630  py = 0;
1631  ery =
1632  (-Erfc(r / s2 + 1 / (2 * by)) * r / (s2 * by * by) -
1633  Derfc(r / s2 + 1 / (2 * by)) / (s2 * by * by));
1634  ey = r / (s2 * by);
1635  if (TMath::Abs(ey) < 9)
1636  py = exp(ey) * ery;
1637  r1 += 0.5 * a * ty * py;
1638  }
1639  }
1640  return (r1);
1641 }
1642 
1643 ////////////////////////////////////////////////////////////////////////////////
1644 ///////////////////////////////////////////////////////////////////////////////////
1645 /// AUXILIARY FUNCTION //
1646 /// //
1647 /// This function calculates volume of a peak //
1648 /// Function parameters: //
1649 /// -a-amplitude of the peak //
1650 /// -sx,sy-sigmas of peak //
1651 /// -ro-correlation coefficient //
1652 /// //
1653 ///////////////////////////////////////////////////////////////////////////////////
1654 
1656 {
1657  Double_t pi = 3.1415926535, r;
1658  r = 1 - ro * ro;
1659  if (r > 0)
1660  r = TMath::Sqrt(r);
1661 
1662  else {
1663  return (0);
1664  }
1665  r = 2 * a * pi * sx * sy * r;
1666  return (r);
1667 }
1668 
1669 ////////////////////////////////////////////////////////////////////////////////
1670 ///////////////////////////////////////////////////////////////////////////////////
1671 /// AUXILIARY FUNCTION //
1672 /// //
1673 /// This function calculates derivative of the volume of a peak //
1674 /// according to amplitute //
1675 /// Function parameters: //
1676 /// -sx,sy-sigmas of peak //
1677 /// -ro-correlation coefficient //
1678 /// //
1679 ///////////////////////////////////////////////////////////////////////////////////
1680 
1682 {
1683  Double_t pi = 3.1415926535, r;
1684  r = 1 - ro * ro;
1685  if (r > 0)
1686  r = TMath::Sqrt(r);
1687 
1688  else {
1689  return (0);
1690  }
1691  r = 2 * pi * sx * sy * r;
1692  return (r);
1693 }
1694 
1695 ////////////////////////////////////////////////////////////////////////////////
1696 ///////////////////////////////////////////////////////////////////////////////////
1697 /// AUXILIARY FUNCTION //
1698 /// //
1699 /// This function calculates derivative of the volume of a peak //
1700 /// according to sigmax //
1701 /// Function parameters: //
1702 /// -a-amplitude of peak //
1703 /// -sy-sigma of peak //
1704 /// -ro-correlation coefficient //
1705 /// //
1706 ///////////////////////////////////////////////////////////////////////////////////
1707 
1709 {
1710  Double_t pi = 3.1415926535, r;
1711  r = 1 - ro * ro;
1712  if (r > 0)
1713  r = TMath::Sqrt(r);
1714 
1715  else {
1716  return (0);
1717  }
1718  r = a * 2 * pi * sy * r;
1719  return (r);
1720 }
1721 
1722 ////////////////////////////////////////////////////////////////////////////////
1723 ///////////////////////////////////////////////////////////////////////////////////
1724 /// AUXILIARY FUNCTION //
1725 /// //
1726 /// This function calculates derivative of the volume of a peak //
1727 /// according to sigmay //
1728 /// Function parameters: //
1729 /// -a-amplitude of peak //
1730 /// -sx-sigma of peak //
1731 /// -ro-correlation coefficient //
1732 /// //
1733 ///////////////////////////////////////////////////////////////////////////////////
1734 
1736 {
1737  Double_t pi = 3.1415926535, r;
1738  r = 1 - ro * ro;
1739  if (r > 0)
1740  r = TMath::Sqrt(r);
1741 
1742  else {
1743  return (0);
1744  }
1745  r = a * 2 * pi * sx * r;
1746  return (r);
1747 }
1748 
1749 ////////////////////////////////////////////////////////////////////////////////
1750 ///////////////////////////////////////////////////////////////////////////////////
1751 /// AUXILIARY FUNCTION //
1752 /// //
1753 /// This function calculates derivative of the volume of a peak //
1754 /// according to ro //
1755 /// Function parameters: //
1756 /// -a-amplitude of peak //
1757 /// -sx,sy-sigmas of peak //
1758 /// -ro-correlation coefficient //
1759 /// //
1760 ///////////////////////////////////////////////////////////////////////////////////
1761 
1763 {
1764  Double_t pi = 3.1415926535, r;
1765  r = 1 - ro * ro;
1766  if (r > 0)
1767  r = TMath::Sqrt(r);
1768 
1769  else {
1770  return (0);
1771  }
1772  r = -a * 2 * pi * sx * sy * ro / r;
1773  return (r);
1774 }
1775 
1776 
1777 /////////////////END OF AUXILIARY FUNCTIONS USED BY FITTING FUNCTION fit2//////////////////////////
1778 /////////////////FITTING FUNCTION WITHOUT MATRIX INVERSION///////////////////////////////////////
1779 ////////////////////////////////////////////////////////////////////////////////
1780 //////////////////////////////////////////////////////////////////////////////
1781 /// TWO-DIMENSIONAL FIT FUNCTION
1782 /// ALGORITHM WITHOUT MATRIX INVERSION
1783 /// This function fits the source spectrum. The calling program should
1784 /// fill in input parameters of the TSpectrum2Fit class.
1785 /// The fitted parameters are written into
1786 /// TSpectrum2Fit class output parameters and fitted data are written into
1787 /// source spectrum.
1788 ///
1789 /// Function parameters:
1790 /// source-pointer to the matrix of source spectrum
1791 ///
1792 //////////////////////////////////////////////////////////////////////////////
1793 ///
1794 
1796 {
1797 /*
1798 <div class=Section2>
1799 
1800 <p class=MsoNormal><b><span style='font-size:14.0pt'>Fitting</span></b></p>
1801 
1802 <p class=MsoNormal style='text-align:justify'><i>&nbsp;</i></p>
1803 
1804 <p class=MsoNormal style='text-align:justify'><i>Goal: to estimate
1805 simultaneously peak shape parameters in spectra with large number of peaks</i></p>
1806 
1807 <p class=MsoNormal>&nbsp;</p>
1808 
1809 <p class=MsoNormal style='margin-left:36.0pt;text-align:justify;text-indent:
1810 -18.0pt'>•<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1811 </span>peaks can be fitted separately, each peak (or multiplets) in a region or
1812 together all peaks in a spectrum. To fit separately each peak one needs to
1813 determine the fitted region. However it can happen that the regions of
1814 neighboring peaks are overlapping. Then the results of fitting are very poor.
1815 On the other hand, when fitting together all peaks found in a  spectrum, one
1816 needs to have a method that is  stable (converges) and fast enough to carry out
1817 fitting in reasonable time </p>
1818 
1819 <p class=MsoNormal style='margin-left:36.0pt;text-align:justify;text-indent:
1820 -18.0pt'>•<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1821 </span>we have implemented the nonsymmetrical semiempirical peak shape function</p>
1822 
1823 <p class=MsoNormal style='margin-left:36.0pt;text-align:justify;text-indent:
1824 -18.0pt'>•<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1825 </span>it contains the two-dimensional symmetrical Gaussian two one-dimensional
1826 symmetrical Gaussian ridges as well as nonsymmetrical terms and background.</p>
1827 
1828 <p class=MsoNormal style='text-align:justify'><sub><img width=600 height=315
1829 src="gif/spectrum2fit_awmi_image001.gif"></sub></p>
1830 
1831 <p class=MsoNormal style='margin-left:37.05pt'>where Txy, Tx, Ty, Sxy, Sx, Sy
1832 are relative amplitudes and Bx, By are slopes.</p>
1833 
1834 <p class=MsoNormal>&nbsp;</p>
1835 
1836 <p class=MsoNormal style='margin-left:36.0pt;text-indent:-18.0pt'>•<span
1837 style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1838 </span>algorithm without matrix inversion (AWMI) allows fitting tens, hundreds
1839 of peaks simultaneously that represent sometimes thousands of parameters [2],
1840 [5]. </p>
1841 
1842 <p class=MsoNormal>&nbsp;</p>
1843 
1844 <p class=MsoNormal>&nbsp;</p>
1845 
1846 <p class=MsoNormal><i>Function:</i></p>
1847 
1848 <p class=MsoNormal style='text-align:justify'>void <a
1849 href="http://root.cern.ch/root/html/TSpectrum.html#TSpectrum:Fit1Awmi"><b>TSpectrumFit2::FitAwmi</b></a>(<a
1850 href="http://root.cern.ch/root/html/ListOfTypes.html#float"><b>float</b></a> **fSource)</p>
1851 
1852 <p class=MsoNormal style='text-align:justify'> </p>
1853 
1854 <p class=MsoNormal style='text-align:justify'>This function fits the source
1855 spectrum using AWMI algorithm. The calling program should fill in input
1856 parameters of the TSpectrumFit2 class using a set of TSpectrumFit2 setters. The
1857 fitted parameters are written into the class and fitted data are written into
1858 source spectrum. </p>
1859 
1860 <p class=MsoNormal>&nbsp;</p>
1861 
1862 <p class=MsoNormal>&nbsp;</p>
1863 
1864 <p class=MsoNormal><i><span style='color:red'>Parameter:</span></i></p>
1865 
1866 <p class=MsoNormal style='text-align:justify'>        <b>fSource</b>-pointer to
1867 the matrix of source spectrum                  </p>
1868 
1869 <p class=MsoNormal>&nbsp;</p>
1870 
1871 <p class=MsoNormal>&nbsp;</p>
1872 
1873 <p class=MsoNormal><i><span style='font-size:10.0pt;color:red'>Member variables
1874 of  TSpectrumFit2 class:</span></i></p>
1875 
1876 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t    
1877 fNPeaks;                        //number of peaks present in fit, input
1878 parameter, it should be &gt; 0</span></p>
1879 
1880 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t    
1881 fNumberIterations;              //number of iterations in fitting procedure,
1882 input parameter, it should be &gt; 0</span></p>
1883 
1884 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t    
1885 fXmin;                          //first fitted channel in x direction</span></p>
1886 
1887 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t    
1888 fXmax;                          //last fitted channel in x direction</span></p>
1889 
1890 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t    
1891 fYmin;                          //first fitted channel in y direction</span></p>
1892 
1893 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t    
1894 fYmax;                          //last fitted channel in y direction</span></p>
1895 
1896 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t    
1897 fStatisticType;                 //type of statistics, possible values
1898 kFitOptimChiCounts (chi square statistics with counts as weighting
1899 coefficients), kFitOptimChiFuncValues (chi square statistics with function
1900 values as weighting coefficients),kFitOptimMaxLikelihood</span></p>
1901 
1902 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t     fAlphaOptim;                   
1903 //optimization of convergence algorithm, possible values kFitAlphaHalving,
1904 kFitAlphaOptimal</span></p>
1905 
1906 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t    
1907 fPower;                         //possible values kFitPower2,4,6,8,10,12, for
1908 details see references. It applies only for Awmi fitting function.</span></p>
1909 
1910 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t    
1911 fFitTaylor;                     //order of Taylor expansion, possible values
1912 kFitTaylorOrderFirst, kFitTaylorOrderSecond. It applies only for Awmi fitting
1913 function.</span></p>
1914 
1915 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
1916 fAlpha;                         //convergence coefficient, input parameter, it
1917 should be positive number and &lt;=1, for details see references</span></p>
1918 
1919 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
1920 fChi;                           //here the fitting functions return resulting
1921 chi square   </span></p>
1922 
1923 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1924 *fPositionInitX;                 //[fNPeaks] array of initial values of x
1925 positions of 2D peaks, input parameters</span></p>
1926 
1927 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1928 *fPositionCalcX;                 //[fNPeaks] array of calculated values of x
1929 positions of 2D peaks, output parameters</span></p>
1930 
1931 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1932 *fPositionErrX;                  //[fNPeaks] array of error values of x
1933 positions of 2D peaks, output parameters</span></p>
1934 
1935 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1936 *fPositionInitY;                 //[fNPeaks] array of initial values of y
1937 positions of 2D peaks, input parameters</span></p>
1938 
1939 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1940 *fPositionCalcY;                 //[fNPeaks] array of calculated values of y
1941 positions of 2D peaks, output parameters</span></p>
1942 
1943 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1944 *fPositionErrY;                  //[fNPeaks] array of error values of y
1945 positions of 2D peaks, output parameters</span></p>
1946 
1947 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1948 *fPositionInitX1;                //[fNPeaks] array of initial x positions of 1D
1949 ridges, input parameters</span></p>
1950 
1951 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1952 *fPositionCalcX1;                //[fNPeaks] array of calculated x positions of
1953 1D ridges, output parameters</span></p>
1954 
1955 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1956 *fPositionErrX1;                 //[fNPeaks] array of x positions errors of 1D
1957 ridges, output parameters</span></p>
1958 
1959 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1960 *fPositionInitY1;                //[fNPeaks] array of initial y positions of 1D
1961 ridges, input parameters</span></p>
1962 
1963 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1964 *fPositionCalcY1;                //[fNPeaks] array of calculated y positions of
1965 1D ridges, output parameters</span></p>
1966 
1967 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1968 *fPositionErrY1;                 //[fNPeaks] array of y positions errors of 1D
1969 ridges, output parameters</span></p>
1970 
1971 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1972 *fAmpInit;                       //[fNPeaks] array of initial values of
1973 amplitudes of 2D peaks, input parameters</span></p>
1974 
1975 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1976 *fAmpCalc;                       //[fNPeaks] array of calculated values of
1977 amplitudes of 2D peaks, output parameters</span></p>
1978 
1979 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1980 *fAmpErr;                        //[fNPeaks] array of amplitudes errors of 2D
1981 peaks, output parameters</span></p>
1982 
1983 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1984 *fAmpInitX1;                     //[fNPeaks] array of initial values of
1985 amplitudes of 1D ridges in x direction, input parameters</span></p>
1986 
1987 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1988 *fAmpCalcX1;                     //[fNPeaks] array of calculated values of
1989 amplitudes of 1D ridges in x direction, output parameters</span></p>
1990 
1991 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1992 *fAmpErrX1;                      //[fNPeaks] array of amplitudes errors of 1D
1993 ridges in x direction, output parameters</span></p>
1994 
1995 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
1996 *fAmpInitY1;                     //[fNPeaks] array of initial values of
1997 amplitudes of 1D ridges in y direction, input parameters</span></p>
1998 
1999 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
2000 *fAmpCalcY1;                     //[fNPeaks] array of calculated values of
2001 amplitudes of 1D ridges in y direction, output parameters</span></p>
2002 
2003 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
2004 *fAmpErrY1;                      //[fNPeaks] array of amplitudes errors of 1D
2005 ridges in y direction, output parameters</span></p>
2006 
2007 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
2008 *fVolume;                        //[fNPeaks] array of calculated volumes of 2D
2009 peaks, output parameters</span></p>
2010 
2011 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t
2012 *fVolumeErr;                     //[fNPeaks] array of volumes errors of 2D
2013 peaks, output parameters</span></p>
2014 
2015 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2016 fSigmaInitX;                    //initial value of sigma x parameter</span></p>
2017 
2018 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2019 fSigmaCalcX;                    //calculated value of sigma x parameter</span></p>
2020 
2021 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2022 fSigmaErrX;                     //error value of sigma x parameter</span></p>
2023 
2024 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2025 fSigmaInitY;                    //initial value of sigma y parameter</span></p>
2026 
2027 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2028 fSigmaCalcY;                    //calculated value of sigma y parameter</span></p>
2029 
2030 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2031 fSigmaErrY;                     //error value of sigma y parameter</span></p>
2032 
2033 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2034 fRoInit;                        //initial value of correlation coefficient</span></p>
2035 
2036 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2037 fRoCalc;                        //calculated value of correlation coefficient</span></p>
2038 
2039 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2040 fRoErr;                         //error value of correlation coefficient</span></p>
2041 
2042 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2043 fTxyInit;                       //initial value of t parameter for 2D peaks
2044 (relative amplitude of tail), for details see html manual and references</span></p>
2045 
2046 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2047 fTxyCalc;                       //calculated value of t parameter for 2D peaks</span></p>
2048 
2049 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2050 fTxyErr;                        //error value of t parameter for 2D peaks</span></p>
2051 
2052 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2053 fSxyInit;                       //initial value of s parameter for 2D peaks
2054 (relative amplitude of step), for details see html manual and references</span></p>
2055 
2056 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2057 fSxyCalc;                       //calculated value of s parameter for 2D peaks</span></p>
2058 
2059 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2060 fSxyErr;                        //error value of s parameter for 2D peaks</span></p>
2061 
2062 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2063 fTxInit;                        //initial value of t parameter for 1D ridges in
2064 x direction (relative amplitude of tail), for details see html manual and
2065 references</span></p>
2066 
2067 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2068 fTxCalc;                        //calculated value of t parameter for 1D ridges
2069 in x direction</span></p>
2070 
2071 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2072 fTxErr;                         //error value of t parameter for 1D ridges in x
2073 direction</span></p>
2074 
2075 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2076 fTyInit;                        //initial value of t parameter for 1D ridges in
2077 y direction (relative amplitude of tail), for details see html manual and
2078 references</span></p>
2079 
2080 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t  fTyCalc;                       
2081 //calculated value of t parameter for 1D ridges in y direction</span></p>
2082 
2083 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2084 fTyErr;                         //error value of t parameter for 1D ridges in y
2085 direction</span></p>
2086 
2087 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2088 fSxInit;                        //initial value of s parameter for 1D ridges in
2089 x direction (relative amplitude of step), for details see html manual and
2090 references</span></p>
2091 
2092 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2093 fSxCalc;                        //calculated value of s parameter for 1D ridges
2094 in x direction</span></p>
2095 
2096 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t  fSxErr;                         //error
2097 value of s parameter for 1D ridges in x direction</span></p>
2098 
2099 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2100 fSyInit;                        //initial value of s parameter for 1D ridges in
2101 y direction (relative amplitude of step), for details see html manual and
2102 references</span></p>
2103 
2104 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2105 fSyCalc;                        //calculated value of s parameter for 1D ridges
2106 in y direction</span></p>
2107 
2108 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2109 fSyErr;                         //error value of s parameter for 1D ridges in y
2110 direction</span></p>
2111 
2112 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2113 fBxInit;                        //initial value of b parameter for 1D ridges in
2114 x direction (slope), for details see html manual and references</span></p>
2115 
2116 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2117 fBxCalc;                        //calculated value of b parameter for 1D ridges
2118 in x direction</span></p>
2119 
2120 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2121 fBxErr;                         //error value of b parameter for 1D ridges in x
2122 direction</span></p>
2123 
2124 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2125 fByInit;                        //initial value of b parameter for 1D ridges in
2126 y direction (slope), for details see html manual and references</span></p>
2127 
2128 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2129 fByCalc;                        //calculated value of b parameter for 1D ridges
2130 in y direction</span></p>
2131 
2132 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2133 fByErr;                         //error value of b parameter for 1D ridges in y
2134 direction</span></p>
2135 
2136 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2137 fA0Init;                        //initial value of background a0 parameter(backgroud
2138 is estimated as a0+ax*x+ay*y)</span></p>
2139 
2140 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2141 fA0Calc;                        //calculated value of background a0 parameter</span></p>
2142 
2143 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2144 fA0Err;                         //error value of background a0 parameter</span></p>
2145 
2146 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t  fAxInit;        
2147                //initial value of background ax parameter(backgroud is
2148 estimated as a0+ax*x+ay*y)</span></p>
2149 
2150 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2151 fAxCalc;                        //calculated value of background ax parameter</span></p>
2152 
2153 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2154 fAxErr;                         //error value of background ax parameter</span></p>
2155 
2156 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2157 fAyInit;                        //initial value of background ay
2158 parameter(backgroud is estimated as a0+ax*x+ay*y)</span></p>
2159 
2160 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t 
2161 fAyCalc;                        //calculated value of background ay parameter</span></p>
2162 
2163 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t  fAyErr;                        
2164 //error value of background ay parameter   </span></p>
2165 
2166 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t  
2167 *fFixPositionX;                  //[fNPeaks] array of logical values which
2168 allow to fix appropriate x positions of 2D peaks (not fit). However they are
2169 present in the estimated functional</span></p>
2170 
2171 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t  
2172 *fFixPositionY;                  //[fNPeaks] array of logical values which
2173 allow to fix appropriate y positions of 2D peaks (not fit). However they are
2174 present in the estimated functional</span></p>
2175 
2176 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t  
2177 *fFixPositionX1;                 //[fNPeaks] array of logical values which
2178 allow to fix appropriate x positions of 1D ridges (not fit). However they are
2179 present in the estimated functional</span></p>
2180 
2181 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t  
2182 *fFixPositionY1;                 //[fNPeaks] array of logical values which
2183 allow to fix appropriate y positions of 1D ridges (not fit). However they are
2184 present in the estimated functional</span></p>
2185 
2186 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t  
2187 *fFixAmp;                        //[fNPeaks] array of logical values which
2188 allow to fix appropriate amplitudes of 2D peaks (not fit). However they are
2189 present in the estimated functional</span></p>
2190 
2191 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t  
2192 *fFixAmpX1;                      //[fNPeaks] array of logical values which
2193 allow to fix appropriate amplitudes of 1D ridges in x direction (not fit).
2194 However they are present in the estimated functional</span></p>
2195 
2196 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t  
2197 *fFixAmpY1;                      //[fNPeaks] array of logical values which
2198 allow to fix appropriate amplitudes of 1D ridges in y direction (not fit).
2199 However they are present in the estimated functional</span></p>
2200 
2201 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2202 fFixSigmaX;                     //logical value of sigma x parameter, which
2203 allows to fix the parameter (not to fit).</span></p>
2204 
2205 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2206 fFixSigmaY;                     //logical value of sigma y parameter, which
2207 allows to fix the parameter (not to fit).</span></p>
2208 
2209 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t    fFixRo;                         //logical
2210 value of correlation coefficient, which allows to fix the parameter (not to
2211 fit).</span></p>
2212 
2213 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2214 fFixTxy;                        //logical value of t parameter for 2D peaks,
2215 which allows to fix the parameter (not to fit).</span></p>
2216 
2217 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2218 fFixSxy;                        //logical value of s parameter for 2D peaks,
2219 which allows to fix the parameter (not to fit).</span></p>
2220 
2221 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2222 fFixTx;                         //logical value of t parameter for 1D ridges in
2223 x direction, which allows to fix the parameter (not to fit).</span></p>
2224 
2225 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2226 fFixTy;                         //logical value of t parameter for 1D ridges in
2227 y direction, which allows to fix the parameter (not to fit).</span></p>
2228 
2229 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2230 fFixSx;                         //logical value of s parameter for 1D ridges in
2231 x direction, which allows to fix the parameter (not to fit).</span></p>
2232 
2233 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2234 fFixSy;                         //logical value of s parameter for 1D ridges in
2235 y direction, which allows to fix the parameter (not to fit).</span></p>
2236 
2237 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t    fFixBx;                         //logical
2238 value of b parameter for 1D ridges in x direction, which allows to fix the
2239 parameter (not to fit).</span></p>
2240 
2241 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2242 fFixBy;                         //logical value of b parameter for 1D ridges in
2243 y direction, which allows to fix the parameter (not to fit).</span></p>
2244 
2245 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2246 fFixA0;                         //logical value of a0 parameter, which allows
2247 to fix the parameter (not to fit).</span></p>
2248 
2249 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2250 fFixAx;                         //logical value of ax parameter, which allows
2251 to fix the parameter (not to fit).</span></p>
2252 
2253 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t   
2254 fFixAy;                         //logical value of ay parameter, which allows
2255 to fix the parameter (not to fit).</span></p>
2256 
2257 <p class=MsoNormal> </p>
2258 
2259 <p class=MsoNormal style='text-align:justify'><b><i>References:</i></b></p>
2260 
2261 <p class=MsoNormal style='text-align:justify'>[1] Phillps G.W., Marlow K.W.,
2262 NIM 137 (1976) 525.</p>
2263 
2264 <p class=MsoNormal style='text-align:justify'>[2] I. A. Slavic: Nonlinear
2265 least-squares fitting without matrix inversion applied to complex Gaussian
2266 spectra analysis. NIM 134 (1976) 285-289.</p>
2267 
2268 <p class=MsoNormal style='text-align:justify'>[3] T. Awaya: A new method for
2269 curve fitting to the data with low statistics not using chi-square method. NIM
2270 165 (1979) 317-323.</p>
2271 
2272 <p class=MsoNormal style='text-align:justify'>[4] T. Hauschild, M. Jentschel:
2273 Comparison of maximum likelihood estimation and chi-square statistics applied
2274 to counting experiments. NIM A 457 (2001) 384-401.</p>
2275 
2276 <p class=MsoNormal style='text-align:justify'> [5]  M. Morhá&#269;,  J.
2277 Kliman,  M. Jandel,  &#317;. Krupa, V. Matoušek: Study of fitting algorithms
2278 applied to simultaneous analysis of large number of peaks in -ray spectra. <span
2279 lang=EN-GB>Applied Spectroscopy, Vol. 57, No. 7, pp. 753-760, 2003</span></p>
2280 
2281 <p class=MsoNormal style='text-align:justify'> </p>
2282 
2283 <p class=MsoNormal style='text-align:justify'><i>Example  – script FitAwmi2.c:</i></p>
2284 
2285 <p class=MsoNormal style='text-align:justify'><span style='font-size:18.0pt'><img
2286 border=0 width=602 height=455 src="gif/spectrum2fit_awmi_image002.jpg"></span></p>
2287 
2288 <p class=MsoNormal style='text-align:justify'><b>Fig. 1 Original two-dimensional
2289 spectrum with found peaks (using TSpectrum2 peak searching function). The
2290 positions of peaks were used as initial estimates in fitting procedure.</b></p>
2291 
2292 <p class=MsoNormal style='text-align:justify'><b><span style='font-size:16.0pt'><img
2293 border=0 width=602 height=455 src="gif/spectrum2fit_awmi_image003.jpg"></span></b></p>
2294 
2295 <p class=MsoBodyText2 style='text-align:justify'>Fig. 2 Fitted (generated from
2296 fitted parameters) spectrum of the data from Fig. 1 using Algorithm Without
2297 Matrix Inversion. Each peak was represented by 7 parameters, which together
2298 with Sigmax, Sigmay and a0 resulted in 38 fitted parameters. The chi-square
2299 after 1000 iterations was 0.642342.</p>
2300 
2301 <p class=MsoNormal><b><span style='color:#339966'>&nbsp;</span></b></p>
2302 
2303 <p class=MsoNormal><b><span style='color:#339966'>Script:</span></b></p>
2304 
2305 <p class=MsoNormal>&nbsp;</p>
2306 
2307 <p class=MsoNormal><span style='font-size:10.0pt'>// Example to illustrate fitting
2308 function, algorithm without matrix inversion (AWMI) (class TSpectrumFit2).</span></p>
2309 
2310 <p class=MsoNormal><span style='font-size:10.0pt'>// To execute this example,
2311 do</span></p>
2312 
2313 <p class=MsoNormal><span style='font-size:10.0pt'>// root &gt; .x FitAwmi2.C</span></p>
2314 
2315 <p class=MsoNormal><span style='font-size:10.0pt'>&nbsp;</span></p>
2316 
2317 <p class=MsoNormal><span style='font-size:10.0pt'>void FitAwmi2() {</span></p>
2318 
2319 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t i, j, nfound;</span></p>
2320 
2321 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t nbinsx = 64;</span></p>
2322 
2323 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t nbinsy = 64;   </span></p>
2324 
2325 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t xmin  = 0;</span></p>
2326 
2327 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t xmax  = nbinsx;</span></p>
2328 
2329 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t ymin  = 0;</span></p>
2330 
2331 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t ymax  = nbinsy;</span></p>
2332 
2333 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t ** source = new
2334 float *[nbinsx];   </span></p>
2335 
2336 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t ** dest = new
2337 float *[nbinsx];      </span></p>
2338 
2339 <p class=MsoNormal><span style='font-size:10.0pt'>   for (i=0;i&lt;nbinsx;i++)</span></p>
2340 
2341 <p class=MsoNormal><span style='font-size:10.0pt'>                                                source[i]=new
2342 float[nbinsy];</span></p>
2343 
2344 <p class=MsoNormal><span style='font-size:10.0pt'>   for (i=0;i&lt;nbinsx;i++)</span></p>
2345 
2346 <p class=MsoNormal><span style='font-size:10.0pt'>                                                dest[i]=new
2347 float[nbinsy];</span></p>
2348 
2349 <p class=MsoNormal><span style='font-size:10.0pt'>   TH2F *search = new
2350 TH2F(&quot;search&quot;,&quot;High resolution peak
2351 searching&quot;,nbinsx,xmin,xmax,nbinsy,ymin,ymax);</span></p>
2352 
2353 <p class=MsoNormal><span style='font-size:10.0pt'>   TFile *f = new
2354 TFile(&quot;TSpectrum2.root&quot;);</span></p>
2355 
2356 <p class=MsoNormal><span style='font-size:10.0pt'>   search=(TH2F*)
2357 f-&gt;Get(&quot;search4;1&quot;);</span></p>
2358 
2359 <p class=MsoNormal><span style='font-size:10.0pt'>   TCanvas *Searching = new
2360 TCanvas(&quot;Searching&quot;,&quot;Two-dimensional fitting using Algorithm
2361 Without Matrix Inversion&quot;,10,10,1000,700);</span></p>
2362 
2363 <p class=MsoNormal><span style='font-size:10.0pt'>   TSpectrum2 *s = new
2364 TSpectrum2();</span></p>
2365 
2366 <p class=MsoNormal><span style='font-size:10.0pt'>   for (i = 0; i &lt; nbinsx;
2367 i++){</span></p>
2368 
2369 <p class=MsoNormal><span style='font-size:10.0pt'>     for (j = 0; j &lt;
2370 nbinsy; j++){</span></p>
2371 
2372 <p class=MsoNormal><span style='font-size:10.0pt'>                    source[i][j]
2373 = search-&gt;GetBinContent(i + 1,j + 1); </span></p>
2374 
2375 <p class=MsoNormal><span style='font-size:10.0pt'>                 }</span></p>
2376 
2377 <p class=MsoNormal><span style='font-size:10.0pt'>   } </span></p>
2378 
2379 <p class=MsoNormal><span style='font-size:10.0pt'>   //searching for candidate
2380 peaks positions     </span></p>
2381 
2382 <p class=MsoNormal><span style='font-size:10.0pt'>   nfound =
2383 s-&gt;SearchHighRes(source, dest, nbinsx, nbinsy, 2, 5, kTRUE, 3, kFALSE, 3);  
2384 </span></p>
2385 
2386 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t *FixPosX = new
2387 Bool_t[nfound];</span></p>
2388 
2389 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t *FixPosY = new
2390 Bool_t[nfound];   </span></p>
2391 
2392 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t *FixAmp = new
2393 Bool_t[nfound];      </span></p>
2394 
2395 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t *PosX = new
2396 Double_t[nfound];         </span></p>
2397 
2398 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t *PosY = new
2399 Double_t[nfound];</span></p>
2400 
2401 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t *Amp = new
2402 Double_t[nfound];      </span></p>
2403 
2404 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t *AmpXY = new
2405 Double_t[nfound];         </span></p>
2406 
2407 <p class=MsoNormal><span style='font-size:10.0pt'>   PosX =
2408 s-&gt;GetPositionX();</span></p>
2409 
2410 <p class=MsoNormal><span style='font-size:10.0pt'>   PosY =
2411 s-&gt;GetPositionY();      </span></p>
2412 
2413 <p class=MsoNormal><span style='font-size:10.0pt'>   printf(&quot;Found %d
2414 candidate peaks\n&quot;,nfound);   </span></p>
2415 
2416 <p class=MsoNormal><span style='font-size:10.0pt'>   for(i = 0; i&lt; nfound ;
2417 i++){</span></p>
2418 
2419 <p class=MsoNormal><span style='font-size:10.0pt'>      FixPosX[i] = kFALSE;</span></p>
2420 
2421 <p class=MsoNormal><span style='font-size:10.0pt'>      FixPosY[i] =
2422 kFALSE;      </span></p>
2423 
2424 <p class=MsoNormal><span style='font-size:10.0pt'>      FixAmp[i] = kFALSE;    </span></p>
2425 
2426 <p class=MsoNormal><span style='font-size:10.0pt'>      Amp[i] =
2427 source[(Int_t)(PosX[i]+0.5)][(Int_t)(PosY[i]+0.5)];      //initial values of peaks
2428 amplitudes, input parameters          </span></p>
2429 
2430 <p class=MsoNormal><span style='font-size:10.0pt'>      AmpXY[i] = 0;</span></p>
2431 
2432 <p class=MsoNormal><span style='font-size:10.0pt'>   }</span></p>
2433 
2434 <p class=MsoNormal><span style='font-size:10.0pt'>   //filling in the initial
2435 estimates of the input parameters</span></p>
2436 
2437 <p class=MsoNormal><span style='font-size:10.0pt'>   TSpectrumFit2 *pfit=new
2438 TSpectrumFit2(nfound);</span></p>
2439 
2440 <p class=MsoNormal><span style='font-size:10.0pt'>  
2441 pfit-&gt;SetFitParameters(xmin, xmax-1, ymin, ymax-1, 1000, 0.1, pfit-&gt;kFitOptimChiCounts,
2442 pfit-&gt;kFitAlphaHalving, pfit-&gt;kFitPower2,
2443 pfit-&gt;kFitTaylorOrderFirst);   </span></p>
2444 
2445 <p class=MsoNormal><span style='font-size:10.0pt'>  
2446 pfit-&gt;SetPeakParameters(2, kFALSE, 2, kFALSE, 0, kTRUE, PosX, (Bool_t *)
2447 FixPosX, PosY, (Bool_t *) FixPosY, PosX, (Bool_t *) FixPosX, PosY, (Bool_t *)
2448 FixPosY, Amp, (Bool_t *) FixAmp, AmpXY, (Bool_t *) FixAmp, AmpXY, (Bool_t *)
2449 FixAmp);      </span></p>
2450 
2451 <p class=MsoNormal><span style='font-size:10.0pt'>  
2452 pfit-&gt;SetBackgroundParameters(0, kFALSE, 0, kTRUE, 0, kTRUE);   </span></p>
2453 
2454 <p class=MsoNormal><span style='font-size:10.0pt'>   pfit-&gt;FitAwmi(source);</span></p>
2455 
2456 <p class=MsoNormal><span style='font-size:10.0pt'>    for (i = 0; i &lt;
2457 nbinsx; i++){</span></p>
2458 
2459 <p class=MsoNormal><span style='font-size:10.0pt'>     for (j = 0; j &lt;
2460 nbinsy; j++){</span></p>
2461 
2462 <p class=MsoNormal><span style='font-size:10.0pt'>                  search-&gt;SetBinContent(i
2463 + 1, j + 1,source[i][j]);</span></p>
2464 
2465 <p class=MsoNormal><span style='font-size:10.0pt'>                 }</span></p>
2466 
2467 <p class=MsoNormal><span style='font-size:10.0pt'>   }   </span></p>
2468 
2469 <p class=MsoNormal><span style='font-size:10.0pt'>  
2470 search-&gt;Draw(&quot;SURF&quot;);</span></p>
2471 
2472 <p class=MsoNormal><span style='font-size:10.0pt'>}</span></p>
2473 
2474 <p class=MsoNormal style='text-align:justify'><i><span style='font-size:16.0pt'>&nbsp;</span></i></p>
2475 
2476 <p class=MsoNormal style='text-align:justify'><i>Example 2 – script FitA2.c:</i></p>
2477 
2478 <p class=MsoNormal><img border=0 width=602 height=455
2479 src="gif/spectrum2fit_awmi_image004.jpg"></p>
2480 
2481 <p class=MsoNormal style='text-align:justify'><b>Fig. 3 Original
2482 two-dimensional gamma-gamma-ray spectrum with found peaks (using TSpectrum2
2483 peak searching function). </b></p>
2484 
2485 <p class=MsoNormal style='text-align:justify'><img border=0 width=602
2486 height=455 src="gif/spectrum2fit_awmi_image005.jpg"></p>
2487 
2488 <p class=MsoNormal style='text-align:justify'><b>Fig. 4 Fitted (generated from
2489 fitted parameters) spectrum of the data from Fig. 3 using Algorithm Without
2490 Matrix Inversion. 152 peaks were identified. </b><b>Each peak was represented
2491 by 7 parameters, which together with Sigmax, Sigmay and a0 resulted in 1067
2492 fitted parameters. The chi-square after 1000 iterations was 0.728675. One can
2493 observe good correspondence with the original data.</b></p>
2494 
2495 <p class=MsoNormal style='text-align:justify'><b><span style='font-size:16.0pt'>&nbsp;</span></b></p>
2496 
2497 <p class=MsoNormal><b><span style='color:#339966'>Script:</span></b></p>
2498 
2499 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>//
2500 Example to illustrate fitting function, algorithm without matrix inversion
2501 (AWMI) (class TSpectrumFit2).</span></p>
2502 
2503 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>//
2504 To execute this example, do</span></p>
2505 
2506 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>//
2507 root &gt; .x FitA2.C</span></p>
2508 
2509 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>void
2510 FitA2() {</span></p>
2511 
2512 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2513 Int_t i, j, nfound;</span></p>
2514 
2515 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2516 Int_t nbinsx = 256;</span></p>
2517 
2518 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2519 Int_t nbinsy = 256;   </span></p>
2520 
2521 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2522 Int_t xmin  = 0;</span></p>
2523 
2524 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2525 Int_t xmax  = nbinsx;</span></p>
2526 
2527 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2528 Int_t ymin  = 0;</span></p>
2529 
2530 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2531 Int_t ymax  = nbinsy;</span></p>
2532 
2533 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2534 Double_t ** source = new float *[nbinsx];   </span></p>
2535 
2536 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2537 Double_t ** dest = new float *[nbinsx];      </span></p>
2538 
2539 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2540 for (i=0;i&lt;nbinsx;i++)</span></p>
2541 
2542 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>                                                source[i]=new
2543 float[nbinsy];</span></p>
2544 
2545 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2546 for (i=0;i&lt;nbinsx;i++)</span></p>
2547 
2548 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>                                                dest[i]=new
2549 float[nbinsy];   </span></p>
2550 
2551 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2552 TH2F *search = new TH2F(&quot;search&quot;,&quot;High resolution peak
2553 searching&quot;,nbinsx,xmin,xmax,nbinsy,ymin,ymax);</span></p>
2554 
2555 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2556 TFile *f = new TFile(&quot;TSpectrum2.root&quot;);</span></p>
2557 
2558 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2559 search=(TH2F*) f-&gt;Get(&quot;fit1;1&quot;);</span></p>
2560 
2561 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2562 TCanvas *Searching = new TCanvas(&quot;Searching&quot;,&quot;Two-dimensional
2563 fitting using Algorithm Without Matrix Inversion&quot;,10,10,1000,700);</span></p>
2564 
2565 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2566 TSpectrum2 *s = new TSpectrum2(1000,1);</span></p>
2567 
2568 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2569 for (i = 0; i &lt; nbinsx; i++){</span></p>
2570 
2571 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>    
2572 for (j = 0; j &lt; nbinsy; j++){</span></p>
2573 
2574 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2575                  source[i][j] = search-&gt;GetBinContent(i + 1,j + 1); </span></p>
2576 
2577 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2578               }</span></p>
2579 
2580 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2581 }   </span></p>
2582 
2583 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2584 nfound = s-&gt;SearchHighRes(source, dest, nbinsx, nbinsy, 2, 2, kTRUE, 100,
2585 kFALSE, 3);   </span></p>
2586 
2587 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2588 printf(&quot;Found %d candidate peaks\n&quot;,nfound);</span></p>
2589 
2590 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2591 Bool_t *FixPosX = new Bool_t[nfound];</span></p>
2592 
2593 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2594 Bool_t *FixPosY = new Bool_t[nfound];   </span></p>
2595 
2596 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2597 Bool_t *FixAmp = new Bool_t[nfound];      </span></p>
2598 
2599 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2600 Double_t *PosX = new Double_t[nfound];         </span></p>
2601 
2602 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2603 Double_t *PosY = new Double_t[nfound];</span></p>
2604 
2605 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2606 Double_t *Amp = new Double_t[nfound];      </span></p>
2607 
2608 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2609 Double_t *AmpXY = new Double_t[nfound];         </span></p>
2610 
2611 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2612 PosX = s-&gt;GetPositionX();</span></p>
2613 
2614 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2615 PosY = s-&gt;GetPositionY();      </span></p>
2616 
2617 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2618 for(i = 0; i&lt; nfound ; i++){</span></p>
2619 
2620 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>     
2621 FixPosX[i] = kFALSE;</span></p>
2622 
2623 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>     
2624 FixPosY[i] = kFALSE;      </span></p>
2625 
2626 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>     
2627 FixAmp[i] = kFALSE;    </span></p>
2628 
2629 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>     
2630 Amp[i] = source[(Int_t)(PosX[i]+0.5)][(Int_t)(PosY[i]+0.5)];      //initial values
2631 of peaks amplitudes, input parameters          </span></p>
2632 
2633 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>     
2634 AmpXY[i] = 0;</span></p>
2635 
2636 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2637 }</span></p>
2638 
2639 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2640 //filling in the initial estimates of the input parameters</span></p>
2641 
2642 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2643 TSpectrumFit2 *pfit=new TSpectrumFit2(nfound);</span></p>
2644 
2645 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2646 pfit-&gt;SetFitParameters(xmin, xmax-1, ymin, ymax-1, 1000, 0.1,
2647 pfit-&gt;kFitOptimChiCounts, pfit-&gt;kFitAlphaHalving, pfit-&gt;kFitPower2,
2648 pfit-&gt;kFitTaylorOrderFirst);   </span></p>
2649 
2650 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2651 pfit-&gt;SetPeakParameters(2, kFALSE, 2, kFALSE, 0, kTRUE, PosX, (Bool_t *)
2652 FixPosX, PosY, (Bool_t *) FixPosY, PosX, (Bool_t *) FixPosX, PosY, (Bool_t *)
2653 FixPosY, Amp, (Bool_t *) FixAmp, AmpXY, (Bool_t *) FixAmp, AmpXY, (Bool_t *)
2654 FixAmp);      </span></p>
2655 
2656 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2657 pfit-&gt;SetBackgroundParameters(0, kFALSE, 0, kTRUE, 0, kTRUE);   </span></p>
2658 
2659 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2660 pfit-&gt;FitAwmi(source);</span></p>
2661 
2662 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2663 for (i = 0; i &lt; nbinsx; i++){</span></p>
2664 
2665 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>    
2666 for (j = 0; j &lt; nbinsy; j++){</span></p>
2667 
2668 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>    
2669              search-&gt;SetBinContent(i + 1, j + 1,source[i][j]);</span></p>
2670 
2671 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2672               }</span></p>
2673 
2674 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2675 }   </span></p>
2676 
2677 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>  
2678 search-&gt;Draw(&quot;SURF&quot;);   </span></p>
2679 
2680 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>}</span></p>
2681 
2682 <p class=MsoNormal style='text-align:justify'><span style='font-size:10.0pt'>&nbsp;</span></p>
2683 
2684 </div>
2685 
2686  */
2687 
2688  Int_t i, i1, i2, j, k, shift =
2689  7 * fNPeaks + 14, peak_vel, size, iter, pw,
2690  regul_cycle, flag;
2691  Double_t a, b, c, d = 0, alpha, chi_opt, yw, ywm, f, chi2, chi_min, chi =
2692  0, pi, pmin = 0, chi_cel = 0, chi_er;
2693  Double_t *working_space = new Double_t[5 * (7 * fNPeaks + 14)];
2694  for (i = 0, j = 0; i < fNPeaks; i++) {
2695  working_space[7 * i] = fAmpInit[i]; //vector parameter
2696  if (fFixAmp[i] == false) {
2697  working_space[shift + j] = fAmpInit[i]; //vector xk
2698  j += 1;
2699  }
2700  working_space[7 * i + 1] = fPositionInitX[i]; //vector parameter
2701  if (fFixPositionX[i] == false) {
2702  working_space[shift + j] = fPositionInitX[i]; //vector xk
2703  j += 1;
2704  }
2705  working_space[7 * i + 2] = fPositionInitY[i]; //vector parameter
2706  if (fFixPositionY[i] == false) {
2707  working_space[shift + j] = fPositionInitY[i]; //vector xk
2708  j += 1;
2709  }
2710  working_space[7 * i + 3] = fAmpInitX1[i]; //vector parameter
2711  if (fFixAmpX1[i] == false) {
2712  working_space[shift + j] = fAmpInitX1[i]; //vector xk
2713  j += 1;
2714  }
2715  working_space[7 * i + 4] = fAmpInitY1[i]; //vector parameter
2716  if (fFixAmpY1[i] == false) {
2717  working_space[shift + j] = fAmpInitY1[i]; //vector xk
2718  j += 1;
2719  }
2720  working_space[7 * i + 5] = fPositionInitX1[i]; //vector parameter
2721  if (fFixPositionX1[i] == false) {
2722  working_space[shift + j] = fPositionInitX1[i]; //vector xk
2723  j += 1;
2724  }
2725  working_space[7 * i + 6] = fPositionInitY1[i]; //vector parameter
2726  if (fFixPositionY1[i] == false) {
2727  working_space[shift + j] = fPositionInitY1[i]; //vector xk
2728  j += 1;
2729  }
2730  }
2731  peak_vel = 7 * i;
2732  working_space[7 * i] = fSigmaInitX; //vector parameter
2733  if (fFixSigmaX == false) {
2734  working_space[shift + j] = fSigmaInitX; //vector xk
2735  j += 1;
2736  }
2737  working_space[7 * i + 1] = fSigmaInitY; //vector parameter
2738  if (fFixSigmaY == false) {
2739  working_space[shift + j] = fSigmaInitY; //vector xk
2740  j += 1;
2741  }
2742  working_space[7 * i + 2] = fRoInit; //vector parameter
2743  if (fFixRo == false) {
2744  working_space[shift + j] = fRoInit; //vector xk
2745  j += 1;
2746  }
2747  working_space[7 * i + 3] = fA0Init; //vector parameter
2748  if (fFixA0 == false) {
2749  working_space[shift + j] = fA0Init; //vector xk
2750  j += 1;
2751  }
2752  working_space[7 * i + 4] = fAxInit; //vector parameter
2753  if (fFixAx == false) {
2754  working_space[shift + j] = fAxInit; //vector xk
2755  j += 1;
2756  }
2757  working_space[7 * i + 5] = fAyInit; //vector parameter
2758  if (fFixAy == false) {
2759  working_space[shift + j] = fAyInit; //vector xk
2760  j += 1;
2761  }
2762  working_space[7 * i + 6] = fTxyInit; //vector parameter
2763  if (fFixTxy == false) {
2764  working_space[shift + j] = fTxyInit; //vector xk
2765  j += 1;
2766  }
2767  working_space[7 * i + 7] = fSxyInit; //vector parameter
2768  if (fFixSxy == false) {
2769  working_space[shift + j] = fSxyInit; //vector xk
2770  j += 1;
2771  }
2772  working_space[7 * i + 8] = fTxInit; //vector parameter
2773  if (fFixTx == false) {
2774  working_space[shift + j] = fTxInit; //vector xk
2775  j += 1;
2776  }
2777  working_space[7 * i + 9] = fTyInit; //vector parameter
2778  if (fFixTy == false) {
2779  working_space[shift + j] = fTyInit; //vector xk
2780  j += 1;
2781  }
2782  working_space[7 * i + 10] = fSxyInit; //vector parameter
2783  if (fFixSx == false) {
2784  working_space[shift + j] = fSxInit; //vector xk
2785  j += 1;
2786  }
2787  working_space[7 * i + 11] = fSyInit; //vector parameter
2788  if (fFixSy == false) {
2789  working_space[shift + j] = fSyInit; //vector xk
2790  j += 1;
2791  }
2792  working_space[7 * i + 12] = fBxInit; //vector parameter
2793  if (fFixBx == false) {
2794  working_space[shift + j] = fBxInit; //vector xk
2795  j += 1;
2796  }
2797  working_space[7 * i + 13] = fByInit; //vector parameter
2798  if (fFixBy == false) {
2799  working_space[shift + j] = fByInit; //vector xk
2800  j += 1;
2801  }
2802  size = j;
2803  for (iter = 0; iter < fNumberIterations; iter++) {
2804  for (j = 0; j < size; j++) {
2805  working_space[2 * shift + j] = 0, working_space[3 * shift + j] = 0; //der,temp
2806  }
2807 
2808  //filling vectors
2809  alpha = fAlpha;
2810  chi_opt = 0, pw = fPower - 2;
2811  for (i1 = fXmin; i1 <= fXmax; i1++) {
2812  for (i2 = fYmin; i2 <= fYmax; i2++) {
2813  yw = source[i1][i2];
2814  ywm = yw;
2815  f = Shape2(fNPeaks, i1, i2,
2816  working_space, working_space[peak_vel],
2817  working_space[peak_vel + 1],
2818  working_space[peak_vel + 2],
2819  working_space[peak_vel + 3],
2820  working_space[peak_vel + 4],
2821  working_space[peak_vel + 5],
2822  working_space[peak_vel + 6],
2823  working_space[peak_vel + 7],
2824  working_space[peak_vel + 8],
2825  working_space[peak_vel + 9],
2826  working_space[peak_vel + 10],
2827  working_space[peak_vel + 11],
2828  working_space[peak_vel + 12],
2829  working_space[peak_vel + 13]);
2831  if (f > 0.00001)
2832  chi_opt += yw * TMath::Log(f) - f;
2833  }
2834 
2835  else {
2836  if (ywm != 0)
2837  chi_opt += (yw - f) * (yw - f) / ywm;
2838  }
2840  ywm = f;
2841  if (f < 0.00001)
2842  ywm = 0.00001;
2843  }
2844 
2845  else if (fStatisticType == kFitOptimMaxLikelihood) {
2846  ywm = f;
2847  if (f < 0.00001)
2848  ywm = 0.00001;
2849  }
2850 
2851  else {
2852  if (ywm == 0)
2853  ywm = 1;
2854  }
2855 
2856  //calculation of gradient vector
2857  for (j = 0, k = 0; j < fNPeaks; j++) {
2858  if (fFixAmp[j] == false) {
2859  a = Deramp2(i1, i2,
2860  working_space[7 * j + 1],
2861  working_space[7 * j + 2],
2862  working_space[peak_vel],
2863  working_space[peak_vel + 1],
2864  working_space[peak_vel + 2],
2865  working_space[peak_vel + 6],
2866  working_space[peak_vel + 7],
2867  working_space[peak_vel + 12],
2868  working_space[peak_vel + 13]);
2869  if (ywm != 0) {
2870  c = Ourpowl(a, pw);
2872  b = a * (yw * yw - f * f) / (ywm * ywm);
2873  working_space[2 * shift + k] += b * c; //der
2874  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
2875  working_space[3 * shift + k] += b * c; //temp
2876  }
2877 
2878  else {
2879  b = a * (yw - f) / ywm;
2880  working_space[2 * shift + k] += b * c; //der
2881  b = a * a / ywm;
2882  working_space[3 * shift + k] += b * c; //temp
2883  }
2884  }
2885  k += 1;
2886  }
2887  if (fFixPositionX[j] == false) {
2888  a = Deri02(i1, i2,
2889  working_space[7 * j],
2890  working_space[7 * j + 1],
2891  working_space[7 * j + 2],
2892  working_space[peak_vel],
2893  working_space[peak_vel + 1],
2894  working_space[peak_vel + 2],
2895  working_space[peak_vel + 6],
2896  working_space[peak_vel + 7],
2897  working_space[peak_vel + 12],
2898  working_space[peak_vel + 13]);
2900  d = Derderi02(i1, i2,
2901  working_space[7 * j],
2902  working_space[7 * j + 1],
2903  working_space[7 * j + 2],
2904  working_space[peak_vel],
2905  working_space[peak_vel + 1],
2906  working_space[peak_vel + 2]);
2907  if (ywm != 0) {
2908  c = Ourpowl(a, pw);
2909  if (TMath::Abs(a) > 0.00000001
2911  d = d * TMath::Abs(yw - f) / (2 * a * ywm);
2912  if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0
2913  && a <= 0))
2914  d = 0;
2915  }
2916 
2917  else
2918  d = 0;
2919  a = a + d;
2921  b = a * (yw * yw - f * f) / (ywm * ywm);
2922  working_space[2 * shift + k] += b * c; //der
2923  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
2924  working_space[3 * shift + k] += b * c; //temp
2925  }
2926 
2927  else {
2928  b = a * (yw - f) / ywm;
2929  working_space[2 * shift + k] += b * c; //der
2930  b = a * a / ywm;
2931  working_space[3 * shift + k] += b * c; //temp
2932  }
2933  }
2934  k += 1;
2935  }
2936  if (fFixPositionY[j] == false) {
2937  a = Derj02(i1, i2,
2938  working_space[7 * j],
2939  working_space[7 * j + 1],
2940  working_space[7 * j + 2],
2941  working_space[peak_vel],
2942  working_space[peak_vel + 1],
2943  working_space[peak_vel + 2],
2944  working_space[peak_vel + 6],
2945  working_space[peak_vel + 7],
2946  working_space[peak_vel + 12],
2947  working_space[peak_vel + 13]);
2949  d = Derderj02(i1, i2,
2950  working_space[7 * j],
2951  working_space[7 * j + 1],
2952  working_space[7 * j + 2],
2953  working_space[peak_vel],
2954  working_space[peak_vel + 1],
2955  working_space[peak_vel + 2]);
2956  if (ywm != 0) {
2957  c = Ourpowl(a, pw);
2958  if (TMath::Abs(a) > 0.00000001
2960  d = d * TMath::Abs(yw - f) / (2 * a * ywm);
2961  if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0
2962  && a <= 0))
2963  d = 0;
2964  }
2965 
2966  else
2967  d = 0;
2968  a = a + d;
2970  b = a * (yw * yw - f * f) / (ywm * ywm);
2971  working_space[2 * shift + k] += b * c; //der
2972  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
2973  working_space[3 * shift + k] += b * c; //temp
2974  }
2975 
2976  else {
2977  b = a * (yw - f) / ywm;
2978  working_space[2 * shift + k] += b * c; //der
2979  b = a * a / ywm;
2980  working_space[3 * shift + k] += b * c; //temp
2981  }
2982  }
2983  k += 1;
2984  }
2985  if (fFixAmpX1[j] == false) {
2986  a = Derampx(i1, working_space[7 * j + 5],
2987  working_space[peak_vel],
2988  working_space[peak_vel + 8],
2989  working_space[peak_vel + 10],
2990  working_space[peak_vel + 12]);
2991  if (ywm != 0) {
2992  c = Ourpowl(a, pw);
2994  b = a * (yw * yw - f * f) / (ywm * ywm);
2995  working_space[2 * shift + k] += b * c; //der
2996  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
2997  working_space[3 * shift + k] += b * c; //temp
2998  }
2999 
3000  else {
3001  b = a * (yw - f) / ywm;
3002  working_space[2 * shift + k] += b * c; //der
3003  b = a * a / ywm;
3004  working_space[3 * shift + k] += b * c; //temp
3005  }
3006  }
3007  k += 1;
3008  }
3009  if (fFixAmpY1[j] == false) {
3010  a = Derampx(i2, working_space[7 * j + 6],
3011  working_space[peak_vel + 1],
3012  working_space[peak_vel + 9],
3013  working_space[peak_vel + 11],
3014  working_space[peak_vel + 13]);
3015  if (ywm != 0) {
3016  c = Ourpowl(a, pw);
3018  b = a * (yw * yw - f * f) / (ywm * ywm);
3019  working_space[2 * shift + k] += b * c; //der
3020  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3021  working_space[3 * shift + k] += b * c; //temp
3022  }
3023 
3024  else {
3025  b = a * (yw - f) / ywm;
3026  working_space[2 * shift + k] += b * c; //der
3027  b = a * a / ywm;
3028  working_space[3 * shift + k] += b * c; //temp
3029  }
3030  }
3031  k += 1;
3032  }
3033  if (fFixPositionX1[j] == false) {
3034  a = Deri01(i1, working_space[7 * j + 3],
3035  working_space[7 * j + 5],
3036  working_space[peak_vel],
3037  working_space[peak_vel + 8],
3038  working_space[peak_vel + 10],
3039  working_space[peak_vel + 12]);
3041  d = Derderi01(i1, working_space[7 * j + 3],
3042  working_space[7 * j + 5],
3043  working_space[peak_vel]);
3044  if (ywm != 0) {
3045  c = Ourpowl(a, pw);
3046  if (TMath::Abs(a) > 0.00000001
3048  d = d * TMath::Abs(yw - f) / (2 * a * ywm);
3049  if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0
3050  && a <= 0))
3051  d = 0;
3052  }
3053 
3054  else
3055  d = 0;
3056  a = a + d;
3058  b = a * (yw * yw - f * f) / (ywm * ywm);
3059  working_space[2 * shift + k] += b * c; //Der
3060  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3061  working_space[3 * shift + k] += b * c; //temp
3062  }
3063 
3064  else {
3065  b = a * (yw - f) / ywm;
3066  working_space[2 * shift + k] += b * c; //Der
3067  b = a * a / ywm;
3068  working_space[3 * shift + k] += b * c; //temp
3069  }
3070  }
3071  k += 1;
3072  }
3073  if (fFixPositionY1[j] == false) {
3074  a = Deri01(i2, working_space[7 * j + 4],
3075  working_space[7 * j + 6],
3076  working_space[peak_vel + 1],
3077  working_space[peak_vel + 9],
3078  working_space[peak_vel + 11],
3079  working_space[peak_vel + 13]);
3081  d = Derderi01(i2, working_space[7 * j + 4],
3082  working_space[7 * j + 6],
3083  working_space[peak_vel + 1]);
3084  if (ywm != 0) {
3085  c = Ourpowl(a, pw);
3086  if (TMath::Abs(a) > 0.00000001
3088  d = d * TMath::Abs(yw - f) / (2 * a * ywm);
3089  if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0
3090  && a <= 0))
3091  d = 0;
3092  }
3093 
3094  else
3095  d = 0;
3096  a = a + d;
3098  b = a * (yw * yw - f * f) / (ywm * ywm);
3099  working_space[2 * shift + k] += b * c; //der
3100  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3101  working_space[3 * shift + k] += b * c; //temp
3102  }
3103 
3104  else {
3105  b = a * (yw - f) / ywm;
3106  working_space[2 * shift + k] += b * c; //der
3107  b = a * a / ywm;
3108  working_space[3 * shift + k] += b * c; //temp
3109  }
3110  }
3111  k += 1;
3112  }
3113  }
3114  if (fFixSigmaX == false) {
3115  a = Dersigmax(fNPeaks, i1, i2,
3116  working_space, working_space[peak_vel],
3117  working_space[peak_vel + 1],
3118  working_space[peak_vel + 2],
3119  working_space[peak_vel + 6],
3120  working_space[peak_vel + 7],
3121  working_space[peak_vel + 8],
3122  working_space[peak_vel + 10],
3123  working_space[peak_vel + 12],
3124  working_space[peak_vel + 13]);
3126  d = Derdersigmax(fNPeaks, i1,
3127  i2, working_space,
3128  working_space[peak_vel],
3129  working_space[peak_vel + 1],
3130  working_space[peak_vel + 2]);
3131  if (ywm != 0) {
3132  c = Ourpowl(a, pw);
3133  if (TMath::Abs(a) > 0.00000001
3135  d = d * TMath::Abs(yw - f) / (2 * a * ywm);
3136  if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0 && a <= 0))
3137  d = 0;
3138  }
3139 
3140  else
3141  d = 0;
3142  a = a + d;
3144  b = a * (yw * yw - f * f) / (ywm * ywm);
3145  working_space[2 * shift + k] += b * c; //der
3146  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3147  working_space[3 * shift + k] += b * c; //temp
3148  }
3149 
3150  else {
3151  b = a * (yw - f) / ywm;
3152  working_space[2 * shift + k] += b * c; //der
3153  b = a * a / ywm;
3154  working_space[3 * shift + k] += b * c; //temp
3155  }
3156  }
3157  k += 1;
3158  }
3159  if (fFixSigmaY == false) {
3160  a = Dersigmay(fNPeaks, i1, i2,
3161  working_space, working_space[peak_vel],
3162  working_space[peak_vel + 1],
3163  working_space[peak_vel + 2],
3164  working_space[peak_vel + 6],
3165  working_space[peak_vel + 7],
3166  working_space[peak_vel + 9],
3167  working_space[peak_vel + 11],
3168  working_space[peak_vel + 12],
3169  working_space[peak_vel + 13]);
3171  d = Derdersigmay(fNPeaks, i1,
3172  i2, working_space,
3173  working_space[peak_vel],
3174  working_space[peak_vel + 1],
3175  working_space[peak_vel + 2]);
3176  if (ywm != 0) {
3177  c = Ourpowl(a, pw);
3178  if (TMath::Abs(a) > 0.00000001
3180  d = d * TMath::Abs(yw - f) / (2 * a * ywm);
3181  if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0 && a <= 0))
3182  d = 0;
3183  }
3184 
3185  else
3186  d = 0;
3187  a = a + d;
3189  b = a * (yw * yw - f * f) / (ywm * ywm);
3190  working_space[2 * shift + k] += b * c; //der
3191  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3192  working_space[3 * shift + k] += b * c; //temp
3193  }
3194 
3195  else {
3196  b = a * (yw - f) / ywm;
3197  working_space[2 * shift + k] += b * c; //der
3198  b = a * a / ywm;
3199  working_space[3 * shift + k] += b * c; //temp
3200  }
3201  }
3202  k += 1;
3203  }
3204  if (fFixRo == false) {
3205  a = Derro(fNPeaks, i1, i2,
3206  working_space, working_space[peak_vel],
3207  working_space[peak_vel + 1],
3208  working_space[peak_vel + 2]);
3209  if (ywm != 0) {
3210  c = Ourpowl(a, pw);
3211  if (TMath::Abs(a) > 0.00000001
3213  d = d * TMath::Abs(yw - f) / (2 * a * ywm);
3214  if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0 && a <= 0))
3215  d = 0;
3216  }
3217 
3218  else
3219  d = 0;
3220  a = a + d;
3222  b = a * (yw * yw - f * f) / (ywm * ywm);
3223  working_space[2 * shift + k] += b * c; //der
3224  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3225  working_space[3 * shift + k] += b * c; //temp
3226  }
3227 
3228  else {
3229  b = a * (yw - f) / ywm;
3230  working_space[2 * shift + k] += b * c; //der
3231  b = a * a / ywm;
3232  working_space[3 * shift + k] += b * c; //temp
3233  }
3234  }
3235  k += 1;
3236  }
3237  if (fFixA0 == false) {
3238  a = 1.;
3239  if (ywm != 0) {
3240  c = Ourpowl(a, pw);
3242  b = a * (yw * yw - f * f) / (ywm * ywm);
3243  working_space[2 * shift + k] += b * c; //der
3244  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3245  working_space[3 * shift + k] += b * c; //temp
3246  }
3247 
3248  else {
3249  b = a * (yw - f) / ywm;
3250  working_space[2 * shift + k] += b * c; //der
3251  b = a * a / ywm;
3252  working_space[3 * shift + k] += b * c; //temp
3253  }
3254  }
3255  k += 1;
3256  }
3257  if (fFixAx == false) {
3258  a = i1;
3259  if (ywm != 0) {
3260  c = Ourpowl(a, pw);
3262  b = a * (yw * yw - f * f) / (ywm * ywm);
3263  working_space[2 * shift + k] += b * c; //der
3264  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3265  working_space[3 * shift + k] += b * c; //temp
3266  }
3267 
3268  else {
3269  b = a * (yw - f) / ywm;
3270  working_space[2 * shift + k] += b * c; //der
3271  b = a * a / ywm;
3272  working_space[3 * shift + k] += b * c; //temp
3273  }
3274  }
3275  k += 1;
3276  }
3277  if (fFixAy == false) {
3278  a = i2;
3279  if (ywm != 0) {
3280  c = Ourpowl(a, pw);
3282  b = a * (yw * yw - f * f) / (ywm * ywm);
3283  working_space[2 * shift + k] += b * c; //der
3284  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3285  working_space[3 * shift + k] += b * c; //temp
3286  }
3287 
3288  else {
3289  b = a * (yw - f) / ywm;
3290  working_space[2 * shift + k] += b * c; //der
3291  b = a * a / ywm;
3292  working_space[3 * shift + k] += b * c; //temp
3293  }
3294  }
3295  k += 1;
3296  }
3297  if (fFixTxy == false) {
3298  a = Dertxy(fNPeaks, i1, i2,
3299  working_space, working_space[peak_vel],
3300  working_space[peak_vel + 1],
3301  working_space[peak_vel + 12],
3302  working_space[peak_vel + 13]);
3303  if (ywm != 0) {
3304  c = Ourpowl(a, pw);
3306  b = a * (yw * yw - f * f) / (ywm * ywm);
3307  working_space[2 * shift + k] += b * c; //der
3308  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3309  working_space[3 * shift + k] += b * c; //temp
3310  }
3311 
3312  else {
3313  b = a * (yw - f) / ywm;
3314  working_space[2 * shift + k] += b * c; //der
3315  b = a * a / ywm;
3316  working_space[3 * shift + k] += b * c; //temp
3317  }
3318  }
3319  k += 1;
3320  }
3321  if (fFixSxy == false) {
3322  a = Dersxy(fNPeaks, i1, i2,
3323  working_space, working_space[peak_vel],
3324  working_space[peak_vel + 1]);
3325  if (ywm != 0) {
3326  c = Ourpowl(a, pw);
3328  b = a * (yw * yw - f * f) / (ywm * ywm);
3329  working_space[2 * shift + k] += b * c; //der
3330  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3331  working_space[3 * shift + k] += b * c; //temp
3332  }
3333 
3334  else {
3335  b = a * (yw - f) / ywm;
3336  working_space[2 * shift + k] += b * c; //der
3337  b = a * a / ywm;
3338  working_space[3 * shift + k] += b * c; //temp
3339  }
3340  }
3341  k += 1;
3342  }
3343  if (fFixTx == false) {
3344  a = Dertx(fNPeaks, i1, working_space,
3345  working_space[peak_vel],
3346  working_space[peak_vel + 12]);
3347  if (ywm != 0) {
3348  c = Ourpowl(a, pw);
3350  b = a * (yw * yw - f * f) / (ywm * ywm);
3351  working_space[2 * shift + k] += b * c; //der
3352  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3353  working_space[3 * shift + k] += b * c; //temp
3354  }
3355 
3356  else {
3357  b = a * (yw - f) / ywm;
3358  working_space[2 * shift + k] += b * c; //der
3359  b = a * a / ywm;
3360  working_space[3 * shift + k] += b * c; //temp
3361  }
3362  }
3363  k += 1;
3364  }
3365  if (fFixTy == false) {
3366  a = Derty(fNPeaks, i2, working_space,
3367  working_space[peak_vel + 1],
3368  working_space[peak_vel + 13]);
3369  if (ywm != 0) {
3370  c = Ourpowl(a, pw);
3372  b = a * (yw * yw - f * f) / (ywm * ywm);
3373  working_space[2 * shift + k] += b * c; //der
3374  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3375  working_space[3 * shift + k] += b * c; //temp
3376  }
3377 
3378  else {
3379  b = a * (yw - f) / ywm;
3380  working_space[2 * shift + k] += b * c; //der
3381  b = a * a / ywm;
3382  working_space[3 * shift + k] += b * c; //temp
3383  }
3384  }
3385  k += 1;
3386  }
3387  if (fFixSx == false) {
3388  a = Dersx(fNPeaks, i1, working_space,
3389  working_space[peak_vel]);
3390  if (ywm != 0) {
3391  c = Ourpowl(a, pw);
3393  b = a * (yw * yw - f * f) / (ywm * ywm);
3394  working_space[2 * shift + k] += b * c; //der
3395  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3396  working_space[3 * shift + k] += b * c; //temp
3397  }
3398 
3399  else {
3400  b = a * (yw - f) / ywm;
3401  working_space[2 * shift + k] += b * c; //der
3402  b = a * a / ywm;
3403  working_space[3 * shift + k] += b * c; //temp
3404  }
3405  }
3406  k += 1;
3407  }
3408  if (fFixSy == false) {
3409  a = Dersy(fNPeaks, i2, working_space,
3410  working_space[peak_vel + 1]);
3411  if (ywm != 0) {
3412  c = Ourpowl(a, pw);
3414  b = a * (yw * yw - f * f) / (ywm * ywm);
3415  working_space[2 * shift + k] += b * c; //der
3416  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3417  working_space[3 * shift + k] += b * c; //temp
3418  }
3419 
3420  else {
3421  b = a * (yw - f) / ywm;
3422  working_space[2 * shift + k] += b * c; //der
3423  b = a * a / ywm;
3424  working_space[3 * shift + k] += b * c; //temp
3425  }
3426  }
3427  k += 1;
3428  }
3429  if (fFixBx == false) {
3430  a = Derbx(fNPeaks, i1, i2,
3431  working_space, working_space[peak_vel],
3432  working_space[peak_vel + 1],
3433  working_space[peak_vel + 6],
3434  working_space[peak_vel + 8],
3435  working_space[peak_vel + 12],
3436  working_space[peak_vel + 13]);
3437  if (ywm != 0) {
3438  c = Ourpowl(a, pw);
3440  b = a * (yw * yw - f * f) / (ywm * ywm);
3441  working_space[2 * shift + k] += b * c; //der
3442  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3443  working_space[3 * shift + k] += b * c; //temp
3444  }
3445 
3446  else {
3447  b = a * (yw - f) / ywm;
3448  working_space[2 * shift + k] += b * c; //der
3449  b = a * a / ywm;
3450  working_space[3 * shift + k] += b * c; //temp
3451  }
3452  }
3453  k += 1;
3454  }
3455  if (fFixBy == false) {
3456  a = Derby(fNPeaks, i1, i2,
3457  working_space, working_space[peak_vel],
3458  working_space[peak_vel + 1],
3459  working_space[peak_vel + 6],
3460  working_space[peak_vel + 8],
3461  working_space[peak_vel + 12],
3462  working_space[peak_vel + 13]);
3463  if (ywm != 0) {
3464  c = Ourpowl(a, pw);
3466  b = a * (yw * yw - f * f) / (ywm * ywm);
3467  working_space[2 * shift + k] += b * c; //der
3468  b = a * a * (4 * yw - 2 * f) / (ywm * ywm);
3469  working_space[3 * shift + k] += b * c; //temp
3470  }
3471 
3472  else {
3473  b = a * (yw - f) / ywm;
3474  working_space[2 * shift + k] += b * c; //der
3475  b = a * a / ywm;
3476  working_space[3 * shift + k] += b * c; //temp
3477  }
3478  }
3479  k += 1;
3480  }
3481  }
3482  }
3483  for (j = 0; j < size; j++) {
3484  if (TMath::Abs(working_space[3 * shift + j]) > 0.000001)
3485  working_space[2 * shift + j] = working_space[2 * shift + j] / TMath::Abs(working_space[3 * shift + j]); //der[j]=der[j]/temp[j]
3486  else
3487  working_space[2 * shift + j] = 0; //der[j]
3488  }
3489 
3490  //calculate chi_opt
3491  chi2 = chi_opt;
3492  chi_opt = TMath::Sqrt(TMath::Abs(chi_opt));
3493 
3494  //calculate new parameters
3495  regul_cycle = 0;
3496  for (j = 0; j < size; j++) {
3497  working_space[4 * shift + j] = working_space[shift + j]; //temp_xk[j]=xk[j]
3498  }
3499 
3500  do {
3501  if (fAlphaOptim == kFitAlphaOptimal) {
3503  chi_min = 10000 * chi2;
3504 
3505  else
3506  chi_min = 0.1 * chi2;
3507  flag = 0;
3508  for (pi = 0.1; flag == 0 && pi <= 100; pi += 0.1) {
3509  for (j = 0; j < size; j++) {
3510  working_space[shift + j] = working_space[4 * shift + j] + pi * alpha * working_space[2 * shift + j]; //xk[j]=temp_xk[j]+pi*alpha*der[j]
3511  }
3512  for (i = 0, j = 0; i < fNPeaks; i++) {
3513  if (fFixAmp[i] == false) {
3514  if (working_space[shift + j] < 0) //xk[j]
3515  working_space[shift + j] = 0; //xk[j]
3516  working_space[7 * i] = working_space[shift + j]; //parameter[7*i]=xk[j]
3517  j += 1;
3518  }
3519  if (fFixPositionX[i] == false) {
3520  if (working_space[shift + j] < fXmin) //xk[j]
3521  working_space[shift + j] = fXmin; //xk[j]
3522  if (working_space[shift + j] > fXmax) //xk[j]
3523  working_space[shift + j] = fXmax; //xk[j]
3524  working_space[7 * i + 1] = working_space[shift + j]; //parameter[7*i+1]=xk[j]
3525  j += 1;
3526  }
3527  if (fFixPositionY[i] == false) {
3528  if (working_space[shift + j] < fYmin) //xk[j]
3529  working_space[shift + j] = fYmin; //xk[j]
3530  if (working_space[shift + j] > fYmax) //xk[j]
3531  working_space[shift + j] = fYmax; //xk[j]
3532  working_space[7 * i + 2] = working_space[shift + j]; //parameter[7*i+2]=xk[j]
3533  j += 1;
3534  }
3535  if (fFixAmpX1[i] == false) {
3536  if (working_space[shift + j] < 0) //xk[j]
3537  working_space[shift + j] = 0; //xk[j]
3538  working_space[7 * i + 3] = working_space[shift + j]; //parameter[7*i+3]=xk[j]
3539  j += 1;
3540  }
3541  if (fFixAmpY1[i] == false) {
3542  if (working_space[shift + j] < 0) //xk[j]
3543  working_space[shift + j] = 0; //xk[j]
3544  working_space[7 * i + 4] = working_space[shift + j]; //parameter[7*i+4]=xk[j]
3545  j += 1;
3546  }
3547  if (fFixPositionX1[i] == false) {
3548  if (working_space[shift + j] < fXmin) //xk[j]
3549  working_space[shift + j] = fXmin; //xk[j]
3550  if (working_space[shift + j] > fXmax) //xk[j]
3551  working_space[shift + j] = fXmax; //xk[j]
3552  working_space[7 * i + 5] = working_space[shift + j]; //parameter[7*i+5]=xk[j]
3553  j += 1;
3554  }
3555  if (fFixPositionY1[i] == false) {
3556  if (working_space[shift + j] < fYmin) //xk[j]
3557  working_space[shift + j] = fYmin; //xk[j]
3558  if (working_space[shift + j] > fYmax) //xk[j]
3559  working_space[shift + j] = fYmax; //xk[j]
3560  working_space[7 * i + 6] = working_space[shift + j]; //parameter[7*i+6]=xk[j]
3561  j += 1;
3562  }
3563  }
3564  if (fFixSigmaX == false) {
3565  if (working_space[shift + j] < 0.001) { //xk[j]
3566  working_space[shift + j] = 0.001; //xk[j]
3567  }
3568  working_space[peak_vel] = working_space[shift + j]; //parameter[peak_vel]=xk[j]
3569  j += 1;
3570  }
3571  if (fFixSigmaY == false) {
3572  if (working_space[shift + j] < 0.001) { //xk[j]
3573  working_space[shift + j] = 0.001; //xk[j]
3574  }
3575  working_space[peak_vel + 1] = working_space[shift + j]; //parameter[peak_vel+1]=xk[j]
3576  j += 1;
3577  }
3578  if (fFixRo == false) {
3579  if (working_space[shift + j] < -1) { //xk[j]
3580  working_space[shift + j] = -1; //xk[j]
3581  }
3582  if (working_space[shift + j] > 1) { //xk[j]
3583  working_space[shift + j] = 1; //xk[j]
3584  }
3585  working_space[peak_vel + 2] = working_space[shift + j]; //parameter[peak_vel+2]=xk[j]
3586  j += 1;
3587  }
3588  if (fFixA0 == false) {
3589  working_space[peak_vel + 3] = working_space[shift + j]; //parameter[peak_vel+3]=xk[j]
3590  j += 1;
3591  }
3592  if (fFixAx == false) {
3593  working_space[peak_vel + 4] = working_space[shift + j]; //parameter[peak_vel+4]=xk[j]
3594  j += 1;
3595  }
3596  if (fFixAy == false) {
3597  working_space[peak_vel + 5] = working_space[shift + j]; //parameter[peak_vel+5]=xk[j]
3598  j += 1;
3599  }
3600  if (fFixTxy == false) {
3601  working_space[peak_vel + 6] = working_space[shift + j]; //parameter[peak_vel+6]=xk[j]
3602  j += 1;
3603  }
3604  if (fFixSxy == false) {
3605  working_space[peak_vel + 7] = working_space[shift + j]; //parameter[peak_vel+7]=xk[j]
3606  j += 1;
3607  }
3608  if (fFixTx == false) {
3609  working_space[peak_vel + 8] = working_space[shift + j]; //parameter[peak_vel+8]=xk[j]
3610  j += 1;
3611  }
3612  if (fFixTy == false) {
3613  working_space[peak_vel + 9] = working_space[shift + j]; //parameter[peak_vel+9]=xk[j]
3614  j += 1;
3615  }
3616  if (fFixSx == false) {
3617  working_space[peak_vel + 10] = working_space[shift + j]; //parameter[peak_vel+10]=xk[j]
3618  j += 1;
3619  }
3620  if (fFixSy == false) {
3621  working_space[peak_vel + 11] = working_space[shift + j]; //parameter[peak_vel+11]=xk[j]
3622  j += 1;
3623  }
3624  if (fFixBx == false) {
3625  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
3626  if (working_space[shift + j] < 0) //xk[j]
3627  working_space[shift + j] = -0.001; //xk[j]
3628  else
3629  working_space[shift + j] = 0.001; //xk[j]
3630  }
3631  working_space[peak_vel + 12] = working_space[shift + j]; //parameter[peak_vel+12]=xk[j]
3632  j += 1;
3633  }
3634  if (fFixBy == false) {
3635  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
3636  if (working_space[shift + j] < 0) //xk[j]
3637  working_space[shift + j] = -0.001; //xk[j]
3638  else
3639  working_space[shift + j] = 0.001; //xk[j]
3640  }
3641  working_space[peak_vel + 13] = working_space[shift + j]; //parameter[peak_vel+13]=xk[j]
3642  j += 1;
3643  }
3644  chi2 = 0;
3645  for (i1 = fXmin; i1 <= fXmax; i1++) {
3646  for (i2 = fYmin; i2 <= fYmax; i2++) {
3647  yw = source[i1][i2];
3648  ywm = yw;
3649  f = Shape2(fNPeaks, i1,
3650  i2, working_space,
3651  working_space[peak_vel],
3652  working_space[peak_vel + 1],
3653  working_space[peak_vel + 2],
3654  working_space[peak_vel + 3],
3655  working_space[peak_vel + 4],
3656  working_space[peak_vel + 5],
3657  working_space[peak_vel + 6],
3658  working_space[peak_vel + 7],
3659  working_space[peak_vel + 8],
3660  working_space[peak_vel + 9],
3661  working_space[peak_vel + 10],
3662  working_space[peak_vel + 11],
3663  working_space[peak_vel + 12],
3664  working_space[peak_vel + 13]);
3666  ywm = f;
3667  if (f < 0.00001)
3668  ywm = 0.00001;
3669  }
3671  if (f > 0.00001)
3672  chi2 += yw * TMath::Log(f) - f;
3673  }
3674 
3675  else {
3676  if (ywm != 0)
3677  chi2 += (yw - f) * (yw - f) / ywm;
3678  }
3679  }
3680  }
3681  if ((chi2 < chi_min
3683  || (chi2 > chi_min
3685  pmin = pi, chi_min = chi2;
3686  }
3687 
3688  else
3689  flag = 1;
3690  if (pi == 0.1)
3691  chi_min = chi2;
3692  chi = chi_min;
3693  }
3694  if (pmin != 0.1) {
3695  for (j = 0; j < size; j++) {
3696  working_space[shift + j] = working_space[4 * shift + j] + pmin * alpha * working_space[2 * shift + j]; //xk[j]=temp_xk[j]+pmin*alpha*der[j]
3697  }
3698  for (i = 0, j = 0; i < fNPeaks; i++) {
3699  if (fFixAmp[i] == false) {
3700  if (working_space[shift + j] < 0) //xk[j]
3701  working_space[shift + j] = 0; //xk[j]
3702  working_space[7 * i] = working_space[shift + j]; //parameter[7*i]=xk[j]
3703  j += 1;
3704  }
3705  if (fFixPositionX[i] == false) {
3706  if (working_space[shift + j] < fXmin) //xk[j]
3707  working_space[shift + j] = fXmin; //xk[j]
3708  if (working_space[shift + j] > fXmax) //xk[j]
3709  working_space[shift + j] = fXmax; //xk[j]
3710  working_space[7 * i + 1] = working_space[shift + j]; //parameter[7*i+1]=xk[j]
3711  j += 1;
3712  }
3713  if (fFixPositionY[i] == false) {
3714  if (working_space[shift + j] < fYmin) //xk[j]
3715  working_space[shift + j] = fYmin; //xk[j]
3716  if (working_space[shift + j] > fYmax) //xk[j]
3717  working_space[shift + j] = fYmax; //xk[j]
3718  working_space[7 * i + 2] = working_space[shift + j]; //parameter[7*i+2]=xk[j]
3719  j += 1;
3720  }
3721  if (fFixAmpX1[i] == false) {
3722  if (working_space[shift + j] < 0) //xk[j]
3723  working_space[shift + j] = 0; //xk[j]
3724  working_space[7 * i + 3] = working_space[shift + j]; //parameter[7*i+3]=xk[j]
3725  j += 1;
3726  }
3727  if (fFixAmpY1[i] == false) {
3728  if (working_space[shift + j] < 0) //xk[j]
3729  working_space[shift + j] = 0; //xk[j]
3730  working_space[7 * i + 4] = working_space[shift + j]; //parameter[7*i+4]=xk[j]
3731  j += 1;
3732  }
3733  if (fFixPositionX1[i] == false) {
3734  if (working_space[shift + j] < fXmin) //xk[j]
3735  working_space[shift + j] = fXmin; //xk[j]
3736  if (working_space[shift + j] > fXmax) //xk[j]
3737  working_space[shift + j] = fXmax; //xk[j]
3738  working_space[7 * i + 5] = working_space[shift + j]; //parameter[7*i+5]=xk[j]
3739  j += 1;
3740  }
3741  if (fFixPositionY1[i] == false) {
3742  if (working_space[shift + j] < fYmin) //xk[j]
3743  working_space[shift + j] = fYmin; //xk[j]
3744  if (working_space[shift + j] > fYmax) //xk[j]
3745  working_space[shift + j] = fYmax; //xk[j]
3746  working_space[7 * i + 6] = working_space[shift + j]; //parameter[7*i+6]=xk[j]
3747  j += 1;
3748  }
3749  }
3750  if (fFixSigmaX == false) {
3751  if (working_space[shift + j] < 0.001) { //xk[j]
3752  working_space[shift + j] = 0.001; //xk[j]
3753  }
3754  working_space[peak_vel] = working_space[shift + j]; //parameter[peak_vel]=xk[j]
3755  j += 1;
3756  }
3757  if (fFixSigmaY == false) {
3758  if (working_space[shift + j] < 0.001) { //xk[j]
3759  working_space[shift + j] = 0.001; //xk[j]
3760  }
3761  working_space[peak_vel + 1] = working_space[shift + j]; //parameter[peak_vel+1]=xk[j]
3762  j += 1;
3763  }
3764  if (fFixRo == false) {
3765  if (working_space[shift + j] < -1) { //xk[j]
3766  working_space[shift + j] = -1; //xk[j]
3767  }
3768  if (working_space[shift + j] > 1) { //xk[j]
3769  working_space[shift + j] = 1; //xk[j]
3770  }
3771  working_space[peak_vel + 2] = working_space[shift + j]; //parameter[peak_vel+2]=xk[j]
3772  j += 1;
3773  }
3774  if (fFixA0 == false) {
3775  working_space[peak_vel + 3] = working_space[shift + j]; //parameter[peak_vel+3]=xk[j]
3776  j += 1;
3777  }
3778  if (fFixAx == false) {
3779  working_space[peak_vel + 4] = working_space[shift + j]; //parameter[peak_vel+4]=xk[j]
3780  j += 1;
3781  }
3782  if (fFixAy == false) {
3783  working_space[peak_vel + 5] = working_space[shift + j]; //parameter[peak_vel+5]=xk[j]
3784  j += 1;
3785  }
3786  if (fFixTxy == false) {
3787  working_space[peak_vel + 6] = working_space[shift + j]; //parameter[peak_vel+6]=xk[j]
3788  j += 1;
3789  }
3790  if (fFixSxy == false) {
3791  working_space[peak_vel + 7] = working_space[shift + j]; //parameter[peak_vel+7]=xk[j]
3792  j += 1;
3793  }
3794  if (fFixTx == false) {
3795  working_space[peak_vel + 8] = working_space[shift + j]; //parameter[peak_vel+8]=xk[j]
3796  j += 1;
3797  }
3798  if (fFixTy == false) {
3799  working_space[peak_vel + 9] = working_space[shift + j]; //parameter[peak_vel+9]=xk[j]
3800  j += 1;
3801  }
3802  if (fFixSx == false) {
3803  working_space[peak_vel + 10] = working_space[shift + j]; //parameter[peak_vel+10]=xk[j]
3804  j += 1;
3805  }
3806  if (fFixSy == false) {
3807  working_space[peak_vel + 11] = working_space[shift + j]; //parameter[peak_vel+11]=xk[j]
3808  j += 1;
3809  }
3810  if (fFixBx == false) {
3811  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
3812  if (working_space[shift + j] < 0) //xk[j]
3813  working_space[shift + j] = -0.001; //xk[j]
3814  else
3815  working_space[shift + j] = 0.001; //xk[j]
3816  }
3817  working_space[peak_vel + 12] = working_space[shift + j]; //parameter[peak_vel+12]=xk[j]
3818  j += 1;
3819  }
3820  if (fFixBy == false) {
3821  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
3822  if (working_space[shift + j] < 0) //xk[j]
3823  working_space[shift + j] = -0.001; //xk[j]
3824  else
3825  working_space[shift + j] = 0.001; //xk[j]
3826  }
3827  working_space[peak_vel + 13] = working_space[shift + j]; //parameter[peak_vel+13]=xk[j]
3828  j += 1;
3829  }
3830  chi = chi_min;
3831  }
3832  }
3833 
3834  else {
3835  for (j = 0; j < size; j++) {
3836  working_space[shift + j] = working_space[4 * shift + j] + alpha * working_space[2 * shift + j]; //xk[j]=temp_xk[j]+pi*alpha*der[j]
3837  }
3838  for (i = 0, j = 0; i < fNPeaks; i++) {
3839  if (fFixAmp[i] == false) {
3840  if (working_space[shift + j] < 0) //xk[j]
3841  working_space[shift + j] = 0; //xk[j]
3842  working_space[7 * i] = working_space[shift + j]; //parameter[7*i]=xk[j]
3843  j += 1;
3844  }
3845  if (fFixPositionX[i] == false) {
3846  if (working_space[shift + j] < fXmin) //xk[j]
3847  working_space[shift + j] = fXmin; //xk[j]
3848  if (working_space[shift + j] > fXmax) //xk[j]
3849  working_space[shift + j] = fXmax; //xk[j]
3850  working_space[7 * i + 1] = working_space[shift + j]; //parameter[7*i+1]=xk[j]
3851  j += 1;
3852  }
3853  if (fFixPositionY[i] == false) {
3854  if (working_space[shift + j] < fYmin) //xk[j]
3855  working_space[shift + j] = fYmin; //xk[j]
3856  if (working_space[shift + j] > fYmax) //xk[j]
3857  working_space[shift + j] = fYmax; //xk[j]
3858  working_space[7 * i + 2] = working_space[shift + j]; //parameter[7*i+2]=xk[j]
3859  j += 1;
3860  }
3861  if (fFixAmpX1[i] == false) {
3862  if (working_space[shift + j] < 0) //xk[j]
3863  working_space[shift + j] = 0; //xk[j]
3864  working_space[7 * i + 3] = working_space[shift + j]; //parameter[7*i+3]=xk[j]
3865  j += 1;
3866  }
3867  if (fFixAmpY1[i] == false) {
3868  if (working_space[shift + j] < 0) //xk[j]
3869  working_space[shift + j] = 0; //xk[j]
3870  working_space[7 * i + 4] = working_space[shift + j]; //parameter[7*i+4]=xk[j]
3871  j += 1;
3872  }
3873  if (fFixPositionX1[i] == false) {
3874  if (working_space[shift + j] < fXmin) //xk[j]
3875  working_space[shift + j] = fXmin; //xk[j]
3876  if (working_space[shift + j] > fXmax) //xk[j]
3877  working_space[shift + j] = fXmax; //xk[j]
3878  working_space[7 * i + 5] = working_space[shift + j]; //parameter[7*i+5]=xk[j]
3879  j += 1;
3880  }
3881  if (fFixPositionY1[i] == false) {
3882  if (working_space[shift + j] < fYmin) //xk[j]
3883  working_space[shift + j] = fYmin; //xk[j]
3884  if (working_space[shift + j] > fYmax) //xk[j]
3885  working_space[shift + j] = fYmax; //xk[j]
3886  working_space[7 * i + 6] = working_space[shift + j]; //parameter[7*i+6]=xk[j]
3887  j += 1;
3888  }
3889  }
3890  if (fFixSigmaX == false) {
3891  if (working_space[shift + j] < 0.001) { //xk[j]
3892  working_space[shift + j] = 0.001; //xk[j]
3893  }
3894  working_space[peak_vel] = working_space[shift + j]; //parameter[peak_vel]=xk[j]
3895  j += 1;
3896  }
3897  if (fFixSigmaY == false) {
3898  if (working_space[shift + j] < 0.001) { //xk[j]
3899  working_space[shift + j] = 0.001; //xk[j]
3900  }
3901  working_space[peak_vel + 1] = working_space[shift + j]; //parameter[peak_vel+1]=xk[j]
3902  j += 1;
3903  }
3904  if (fFixRo == false) {
3905  if (working_space[shift + j] < -1) { //xk[j]
3906  working_space[shift + j] = -1; //xk[j]
3907  }
3908  if (working_space[shift + j] > 1) { //xk[j]
3909  working_space[shift + j] = 1; //xk[j]
3910  }
3911  working_space[peak_vel + 2] = working_space[shift + j]; //parameter[peak_vel+2]=xk[j]
3912  j += 1;
3913  }
3914  if (fFixA0 == false) {
3915  working_space[peak_vel + 3] = working_space[shift + j]; //parameter[peak_vel+3]=xk[j]
3916  j += 1;
3917  }
3918  if (fFixAx == false) {
3919  working_space[peak_vel + 4] = working_space[shift + j]; //parameter[peak_vel+4]=xk[j]
3920  j += 1;
3921  }
3922  if (fFixAy == false) {
3923  working_space[peak_vel + 5] = working_space[shift + j]; //parameter[peak_vel+5]=xk[j]
3924  j += 1;
3925  }
3926  if (fFixTxy == false) {
3927  working_space[peak_vel + 6] = working_space[shift + j]; //parameter[peak_vel+6]=xk[j]
3928  j += 1;
3929  }
3930  if (fFixSxy == false) {
3931  working_space[peak_vel + 7] = working_space[shift + j]; //parameter[peak_vel+7]=xk[j]
3932  j += 1;
3933  }
3934  if (fFixTx == false) {
3935  working_space[peak_vel + 8] = working_space[shift + j]; //parameter[peak_vel+8]=xk[j]
3936  j += 1;
3937  }
3938  if (fFixTy == false) {
3939  working_space[peak_vel + 9] = working_space[shift + j]; //parameter[peak_vel+9]=xk[j]
3940  j += 1;
3941  }
3942  if (fFixSx == false) {
3943  working_space[peak_vel + 10] = working_space[shift + j]; //parameter[peak_vel+10]=xk[j]
3944  j += 1;
3945  }
3946  if (fFixSy == false) {
3947  working_space[peak_vel + 11] = working_space[shift + j]; //parameter[peak_vel+11]=xk[j]
3948  j += 1;
3949  }
3950  if (fFixBx == false) {
3951  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
3952  if (working_space[shift + j] < 0) //xk[j]
3953  working_space[shift + j] = -0.001; //xk[j]
3954  else
3955  working_space[shift + j] = 0.001; //xk[j]
3956  }
3957  working_space[peak_vel + 12] = working_space[shift + j]; //parameter[peak_vel+12]=xk[j]
3958  j += 1;
3959  }
3960  if (fFixBy == false) {
3961  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
3962  if (working_space[shift + j] < 0) //xk[j]
3963  working_space[shift + j] = -0.001; //xk[j]
3964  else
3965  working_space[shift + j] = 0.001; //xk[j]
3966  }
3967  working_space[peak_vel + 13] = working_space[shift + j]; //parameter[peak_vel+13]=xk[j]
3968  j += 1;
3969  }
3970  chi = 0;
3971  for (i1 = fXmin; i1 <= fXmax; i1++) {
3972  for (i2 = fYmin; i2 <= fYmax; i2++) {
3973  yw = source[i1][i2];
3974  ywm = yw;
3975  f = Shape2(fNPeaks, i1, i2,
3976  working_space, working_space[peak_vel],
3977  working_space[peak_vel + 1],
3978  working_space[peak_vel + 2],
3979  working_space[peak_vel + 3],
3980  working_space[peak_vel + 4],
3981  working_space[peak_vel + 5],
3982  working_space[peak_vel + 6],
3983  working_space[peak_vel + 7],
3984  working_space[peak_vel + 8],
3985  working_space[peak_vel + 9],
3986  working_space[peak_vel + 10],
3987  working_space[peak_vel + 11],
3988  working_space[peak_vel + 12],
3989  working_space[peak_vel + 13]);
3991  ywm = f;
3992  if (f < 0.00001)
3993  ywm = 0.00001;
3994  }
3996  if (f > 0.00001)
3997  chi += yw * TMath::Log(f) - f;
3998  }
3999 
4000  else {
4001  if (ywm != 0)
4002  chi += (yw - f) * (yw - f) / ywm;
4003  }
4004  }
4005  }
4006  }
4007  chi2 = chi;
4008  chi = TMath::Sqrt(TMath::Abs(chi));
4009  if (fAlphaOptim == kFitAlphaHalving && chi > 1E-6)
4010  alpha = alpha * chi_opt / (2 * chi);
4011 
4012  else if (fAlphaOptim == kFitAlphaOptimal)
4013  alpha = alpha / 10.0;
4014  iter += 1;
4015  regul_cycle += 1;
4016  } while (((chi > chi_opt
4018  || (chi < chi_opt
4020  && regul_cycle < kFitNumRegulCycles);
4021  for (j = 0; j < size; j++) {
4022  working_space[4 * shift + j] = 0; //temp_xk[j]
4023  working_space[2 * shift + j] = 0; //der[j]
4024  }
4025  for (i1 = fXmin, chi_cel = 0; i1 <= fXmax; i1++) {
4026  for (i2 = fYmin; i2 <= fYmax; i2++) {
4027  yw = source[i1][i2];
4028  if (yw == 0)
4029  yw = 1;
4030  f = Shape2(fNPeaks, i1, i2,
4031  working_space, working_space[peak_vel],
4032  working_space[peak_vel + 1],
4033  working_space[peak_vel + 2],
4034  working_space[peak_vel + 3],
4035  working_space[peak_vel + 4],
4036  working_space[peak_vel + 5],
4037  working_space[peak_vel + 6],
4038  working_space[peak_vel + 7],
4039  working_space[peak_vel + 8],
4040  working_space[peak_vel + 9],
4041  working_space[peak_vel + 10],
4042  working_space[peak_vel + 11],
4043  working_space[peak_vel + 12],
4044  working_space[peak_vel + 13]);
4045  chi_opt = (yw - f) * (yw - f) / yw;
4046  chi_cel += (yw - f) * (yw - f) / yw;
4047 
4048  //calculate gradient vector
4049  for (j = 0, k = 0; j < fNPeaks; j++) {
4050  if (fFixAmp[j] == false) {
4051  a = Deramp2(i1, i2,
4052  working_space[7 * j + 1],
4053  working_space[7 * j + 2],
4054  working_space[peak_vel],
4055  working_space[peak_vel + 1],
4056  working_space[peak_vel + 2],
4057  working_space[peak_vel + 6],
4058  working_space[peak_vel + 7],
4059  working_space[peak_vel + 12],
4060  working_space[peak_vel + 13]);
4061  if (yw != 0) {
4062  c = Ourpowl(a, pw);
4063  working_space[2 * shift + k] += chi_opt * c; //der[k]
4064  b = a * a / yw;
4065  working_space[4 * shift + k] += b * c; //temp_xk[k]
4066  }
4067  k += 1;
4068  }
4069  if (fFixPositionX[j] == false) {
4070  a = Deri02(i1, i2,
4071  working_space[7 * j],
4072  working_space[7 * j + 1],
4073  working_space[7 * j + 2],
4074  working_space[peak_vel],
4075  working_space[peak_vel + 1],
4076  working_space[peak_vel + 2],
4077  working_space[peak_vel + 6],
4078  working_space[peak_vel + 7],
4079  working_space[peak_vel + 12],
4080  working_space[peak_vel + 13]);
4081  if (yw != 0) {
4082  c = Ourpowl(a, pw);
4083  working_space[2 * shift + k] += chi_opt * c; //der[k]
4084  b = a * a / yw;
4085  working_space[4 * shift + k] += b * c; //temp_xk[k]
4086  }
4087  k += 1;
4088  }
4089  if (fFixPositionY[j] == false) {
4090  a = Derj02(i1, i2,
4091  working_space[7 * j],
4092  working_space[7 * j + 1],
4093  working_space[7 * j + 2],
4094  working_space[peak_vel],
4095  working_space[peak_vel + 1],
4096  working_space[peak_vel + 2],
4097  working_space[peak_vel + 6],
4098  working_space[peak_vel + 7],
4099  working_space[peak_vel + 12],
4100  working_space[peak_vel + 13]);
4101  if (yw != 0) {
4102  c = Ourpowl(a, pw);
4103  working_space[2 * shift + k] += chi_opt * c; //der[k]
4104  b = a * a / yw;
4105  working_space[4 * shift + k] += b * c; //temp_xk[k]
4106  }
4107  k += 1;
4108  }
4109  if (fFixAmpX1[j] == false) {
4110  a = Derampx(i1, working_space[7 * j + 5],
4111  working_space[peak_vel],
4112  working_space[peak_vel + 8],
4113  working_space[peak_vel + 10],
4114  working_space[peak_vel + 12]);
4115  if (yw != 0) {
4116  c = Ourpowl(a, pw);
4117  working_space[2 * shift + k] += chi_opt * c; //der[k]
4118  b = a * a / yw;
4119  working_space[4 * shift + k] += b * c; //temp_xk[k]
4120  }
4121  k += 1;
4122  }
4123  if (fFixAmpY1[j] == false) {
4124  a = Derampx(i2, working_space[7 * j + 6],
4125  working_space[peak_vel + 1],
4126  working_space[peak_vel + 9],
4127  working_space[peak_vel + 11],
4128  working_space[peak_vel + 13]);
4129  if (yw != 0) {
4130  c = Ourpowl(a, pw);
4131  working_space[2 * shift + k] += chi_opt * c; //der[k]
4132  b = a * a / yw;
4133  working_space[4 * shift + k] += b * c; //temp_xk[k]
4134  }
4135  k += 1;
4136  }
4137  if (fFixPositionX1[j] == false) {
4138  a = Deri01(i1, working_space[7 * j + 3],
4139  working_space[7 * j + 5],
4140  working_space[peak_vel],
4141  working_space[peak_vel + 8],
4142  working_space[peak_vel + 10],
4143  working_space[peak_vel + 12]);
4144  if (yw != 0) {
4145  c = Ourpowl(a, pw);
4146  working_space[2 * shift + k] += chi_opt * c; //der[k]
4147  b = a * a / yw;
4148  working_space[4 * shift + k] += b * c; //temp_xk[k]
4149  }
4150  k += 1;
4151  }
4152  if (fFixPositionY1[j] == false) {
4153  a = Deri01(i2, working_space[7 * j + 4],
4154  working_space[7 * j + 6],
4155  working_space[peak_vel + 1],
4156  working_space[peak_vel + 9],
4157  working_space[peak_vel + 11],
4158  working_space[peak_vel + 13]);
4159  if (yw != 0) {
4160  c = Ourpowl(a, pw);
4161  working_space[2 * shift + k] += chi_opt * c; //der[k]
4162  b = a * a / yw;
4163  working_space[4 * shift + k] += b * c; //temp_xk[k]
4164  }
4165  k += 1;
4166  }
4167  }
4168  if (fFixSigmaX == false) {
4169  a = Dersigmax(fNPeaks, i1, i2,
4170  working_space, working_space[peak_vel],
4171  working_space[peak_vel + 1],
4172  working_space[peak_vel + 2],
4173  working_space[peak_vel + 6],
4174  working_space[peak_vel + 7],
4175  working_space[peak_vel + 8],
4176  working_space[peak_vel + 10],
4177  working_space[peak_vel + 12],
4178  working_space[peak_vel + 13]);
4179  if (yw != 0) {
4180  c = Ourpowl(a, pw);
4181  working_space[2 * shift + k] += chi_opt * c; //der[k]
4182  b = a * a / yw;
4183  working_space[4 * shift + k] += b * c; //temp_xk[k]
4184  }
4185  k += 1;
4186  }
4187  if (fFixSigmaY == false) {
4188  a = Dersigmay(fNPeaks, i1, i2,
4189  working_space, working_space[peak_vel],
4190  working_space[peak_vel + 1],
4191  working_space[peak_vel + 2],
4192  working_space[peak_vel + 6],
4193  working_space[peak_vel + 7],
4194  working_space[peak_vel + 9],
4195  working_space[peak_vel + 11],
4196  working_space[peak_vel + 12],
4197  working_space[peak_vel + 13]);
4198  if (yw != 0) {
4199  c = Ourpowl(a, pw);
4200  working_space[2 * shift + k] += chi_opt * c; //der[k]
4201  b = a * a / yw;
4202  working_space[4 * shift + k] += b * c; //temp_xk[k]
4203  }
4204  k += 1;
4205  }
4206  if (fFixRo == false) {
4207  a = Derro(fNPeaks, i1, i2,
4208  working_space, working_space[peak_vel],
4209  working_space[peak_vel + 1],
4210  working_space[peak_vel + 2]);
4211  if (yw != 0) {
4212  c = Ourpowl(a, pw);
4213  working_space[2 * shift + k] += chi_opt * c; //der[k]
4214  b = a * a / yw;
4215  working_space[4 * shift + k] += b * c; //temp_xk[k]
4216  }
4217  k += 1;
4218  }
4219  if (fFixA0 == false) {
4220  a = 1.;
4221  if (yw != 0) {
4222  c = Ourpowl(a, pw);
4223  working_space[2 * shift + k] += chi_opt * c; //der[k]
4224  b = a * a / yw;
4225  working_space[4 * shift + k] += b * c; //temp_xk[k]
4226  }
4227  k += 1;
4228  }
4229  if (fFixAx == false) {
4230  a = i1;
4231  if (yw != 0) {
4232  c = Ourpowl(a, pw);
4233  working_space[2 * shift + k] += chi_opt * c; //der[k]
4234  b = a * a / yw;
4235  working_space[4 * shift + k] += b * c; //temp_xk[k]
4236  }
4237  k += 1;
4238  }
4239  if (fFixAy == false) {
4240  a = i2;
4241  if (yw != 0) {
4242  c = Ourpowl(a, pw);
4243  working_space[2 * shift + k] += chi_opt * c; //der[k]
4244  b = a * a / yw;
4245  working_space[4 * shift + k] += b * c; //temp_xk[k]
4246  }
4247  k += 1;
4248  }
4249  if (fFixTxy == false) {
4250  a = Dertxy(fNPeaks, i1, i2,
4251  working_space, working_space[peak_vel],
4252  working_space[peak_vel + 1],
4253  working_space[peak_vel + 12],
4254  working_space[peak_vel + 13]);
4255  if (yw != 0) {
4256  c = Ourpowl(a, pw);
4257  working_space[2 * shift + k] += chi_opt * c; //der[k]
4258  b = a * a / yw;
4259  working_space[4 * shift + k] += b * c; //temp_xk[k]
4260  }
4261  k += 1;
4262  }
4263  if (fFixSxy == false) {
4264  a = Dersxy(fNPeaks, i1, i2,
4265  working_space, working_space[peak_vel],
4266  working_space[peak_vel + 1]);
4267  if (yw != 0) {
4268  c = Ourpowl(a, pw);
4269  working_space[2 * shift + k] += chi_opt * c; //der[k]
4270  b = a * a / yw;
4271  working_space[4 * shift + k] += b * c; //temp_xk[k]
4272  }
4273  k += 1;
4274  }
4275  if (fFixTx == false) {
4276  a = Dertx(fNPeaks, i1, working_space,
4277  working_space[peak_vel],
4278  working_space[peak_vel + 12]);
4279  if (yw != 0) {
4280  c = Ourpowl(a, pw);
4281  working_space[2 * shift + k] += chi_opt * c; //der[k]
4282  b = a * a / yw;
4283  working_space[4 * shift + k] += b * c; //temp_xk[k]
4284  }
4285  k += 1;
4286  }
4287  if (fFixTy == false) {
4288  a = Derty(fNPeaks, i2, working_space,
4289  working_space[peak_vel + 1],
4290  working_space[peak_vel + 13]);
4291  if (yw != 0) {
4292  c = Ourpowl(a, pw);
4293  working_space[2 * shift + k] += chi_opt * c; //der[k]
4294  b = a * a / yw;
4295  working_space[4 * shift + k] += b * c; //temp_xk[k]
4296  }
4297  k += 1;
4298  }
4299  if (fFixSx == false) {
4300  a = Dersx(fNPeaks, i1, working_space,
4301  working_space[peak_vel]);
4302  if (yw != 0) {
4303  c = Ourpowl(a, pw);
4304  working_space[2 * shift + k] += chi_opt * c; //der[k]
4305  b = a * a / yw;
4306  working_space[4 * shift + k] += b * c; //temp_xk[k]
4307  }
4308  k += 1;
4309  }
4310  if (fFixSy == false) {
4311  a = Dersy(fNPeaks, i2, working_space,
4312  working_space[peak_vel + 1]);
4313  if (yw != 0) {
4314  c = Ourpowl(a, pw);
4315  working_space[2 * shift + k] += chi_opt * c; //der[k]
4316  b = a * a / yw;
4317  working_space[4 * shift + k] += b * c; //temp_xk[k]
4318  }
4319  k += 1;
4320  }
4321  if (fFixBx == false) {
4322  a = Derbx(fNPeaks, i1, i2,
4323  working_space, working_space[peak_vel],
4324  working_space[peak_vel + 1],
4325  working_space[peak_vel + 6],
4326  working_space[peak_vel + 8],
4327  working_space[peak_vel + 12],
4328  working_space[peak_vel + 13]);
4329  if (yw != 0) {
4330  c = Ourpowl(a, pw);
4331  working_space[2 * shift + k] += chi_opt * c; //der[k]
4332  b = a * a / yw;
4333  working_space[4 * shift + k] += b * c; //temp_xk[k]
4334  }
4335  k += 1;
4336  }
4337  if (fFixBy == false) {
4338  a = Derby(fNPeaks, i1, i2,
4339  working_space, working_space[peak_vel],
4340  working_space[peak_vel + 1],
4341  working_space[peak_vel + 6],
4342  working_space[peak_vel + 8],
4343  working_space[peak_vel + 12],
4344  working_space[peak_vel + 13]);
4345  if (yw != 0) {
4346  c = Ourpowl(a, pw);
4347  working_space[2 * shift + k] += chi_opt * c; //der[k]
4348  b = a * a / yw;
4349  working_space[4 * shift + k] += b * c; //temp_xk[k]
4350  }
4351  k += 1;
4352  }
4353  }
4354  }
4355  }
4356  b = (fXmax - fXmin + 1) * (fYmax - fYmin + 1) - size;
4357  chi_er = chi_cel / b;
4358  for (i = 0, j = 0; i < fNPeaks; i++) {
4359  fVolume[i] =
4360  Volume(working_space[7 * i], working_space[peak_vel],
4361  working_space[peak_vel + 1], working_space[peak_vel + 2]);
4362  if (fVolume[i] > 0) {
4363  c = 0;
4364  if (fFixAmp[i] == false) {
4365  a = Derpa2(working_space[peak_vel],
4366  working_space[peak_vel + 1],
4367  working_space[peak_vel + 2]);
4368  b = working_space[4 * shift + j]; //temp_xk[j]
4369  if (b == 0)
4370  b = 1;
4371 
4372  else
4373  b = 1 / b;
4374  c = c + a * a * b;
4375  }
4376  if (fFixSigmaX == false) {
4377  a = Derpsigmax(working_space[shift + j],
4378  working_space[peak_vel + 1],
4379  working_space[peak_vel + 2]);
4380  b = working_space[4 * shift + peak_vel]; //temp_xk[j]
4381  if (b == 0)
4382  b = 1;
4383 
4384  else
4385  b = 1 / b;
4386  c = c + a * a * b;
4387  }
4388  if (fFixSigmaY == false) {
4389  a = Derpsigmay(working_space[shift + j],
4390  working_space[peak_vel],
4391  working_space[peak_vel + 2]);
4392  b = working_space[4 * shift + peak_vel + 1]; //temp_xk[j]
4393  if (b == 0)
4394  b = 1;
4395 
4396  else
4397  b = 1 / b;
4398  c = c + a * a * b;
4399  }
4400  if (fFixRo == false) {
4401  a = Derpro(working_space[shift + j], working_space[peak_vel],
4402  working_space[peak_vel + 1],
4403  working_space[peak_vel + 2]);
4404  b = working_space[4 * shift + peak_vel + 2]; //temp_xk[j]
4405  if (b == 0)
4406  b = 1;
4407 
4408  else
4409  b = 1 / b;
4410  c = c + a * a * b;
4411  }
4412  fVolumeErr[i] = TMath::Sqrt(TMath::Abs(chi_er * c));
4413  }
4414 
4415  else {
4416  fVolumeErr[i] = 0;
4417  }
4418  if (fFixAmp[i] == false) {
4419  fAmpCalc[i] = working_space[shift + j]; //xk[j]
4420  if (working_space[3 * shift + j] != 0)
4421  fAmpErr[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4422  j += 1;
4423  }
4424 
4425  else {
4426  fAmpCalc[i] = fAmpInit[i];
4427  fAmpErr[i] = 0;
4428  }
4429  if (fFixPositionX[i] == false) {
4430  fPositionCalcX[i] = working_space[shift + j]; //xk[j]
4431  if (working_space[3 * shift + j] != 0)
4432  fPositionErrX[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4433  j += 1;
4434  }
4435 
4436  else {
4438  fPositionErrX[i] = 0;
4439  }
4440  if (fFixPositionY[i] == false) {
4441  fPositionCalcY[i] = working_space[shift + j]; //xk[j]
4442  if (working_space[3 * shift + j] != 0)
4443  fPositionErrY[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4444  j += 1;
4445  }
4446 
4447  else {
4449  fPositionErrY[i] = 0;
4450  }
4451  if (fFixAmpX1[i] == false) {
4452  fAmpCalcX1[i] = working_space[shift + j]; //xk[j]
4453  if (working_space[3 * shift + j] != 0)
4454  fAmpErrX1[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4455  j += 1;
4456  }
4457 
4458  else {
4459  fAmpCalcX1[i] = fAmpInitX1[i];
4460  fAmpErrX1[i] = 0;
4461  }
4462  if (fFixAmpY1[i] == false) {
4463  fAmpCalcY1[i] = working_space[shift + j]; //xk[j]
4464  if (working_space[3 * shift + j] != 0)
4465  fAmpErrY1[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4466  j += 1;
4467  }
4468 
4469  else {
4470  fAmpCalcY1[i] = fAmpInitY1[i];
4471  fAmpErrY1[i] = 0;
4472  }
4473  if (fFixPositionX1[i] == false) {
4474  fPositionCalcX1[i] = working_space[shift + j]; //xk[j]
4475  if (working_space[3 * shift + j] != 0)
4476  fPositionErrX1[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4477  j += 1;
4478  }
4479 
4480  else {
4482  fPositionErrX1[i] = 0;
4483  }
4484  if (fFixPositionY1[i] == false) {
4485  fPositionCalcY1[i] = working_space[shift + j]; //xk[j]
4486  if (working_space[3 * shift + j] != 0)
4487  fPositionErrY1[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4488  j += 1;
4489  }
4490 
4491  else {
4493  fPositionErrY1[i] = 0;
4494  }
4495  }
4496  if (fFixSigmaX == false) {
4497  fSigmaCalcX = working_space[shift + j]; //xk[j]
4498  if (working_space[3 * shift + j] != 0) //temp[j]
4499  fSigmaErrX = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4500  j += 1;
4501  }
4502 
4503  else {
4505  fSigmaErrX = 0;
4506  }
4507  if (fFixSigmaY == false) {
4508  fSigmaCalcY = working_space[shift + j]; //xk[j]
4509  if (working_space[3 * shift + j] != 0) //temp[j]
4510  fSigmaErrY = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4511  j += 1;
4512  }
4513 
4514  else {
4516  fSigmaErrY = 0;
4517  }
4518  if (fFixRo == false) {
4519  fRoCalc = working_space[shift + j]; //xk[j]
4520  if (working_space[3 * shift + j] != 0) //temp[j]
4521  fRoErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4522  j += 1;
4523  }
4524 
4525  else {
4526  fRoCalc = fRoInit;
4527  fRoErr = 0;
4528  }
4529  if (fFixA0 == false) {
4530  fA0Calc = working_space[shift + j]; //xk[j]
4531  if (working_space[3 * shift + j] != 0) //temp[j]
4532  fA0Err = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4533  j += 1;
4534  }
4535 
4536  else {
4537  fA0Calc = fA0Init;
4538  fA0Err = 0;
4539  }
4540  if (fFixAx == false) {
4541  fAxCalc = working_space[shift + j]; //xk[j]
4542  if (working_space[3 * shift + j] != 0) //temp[j]
4543  fAxErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4544  j += 1;
4545  }
4546 
4547  else {
4548  fAxCalc = fAxInit;
4549  fAxErr = 0;
4550  }
4551  if (fFixAy == false) {
4552  fAyCalc = working_space[shift + j]; //xk[j]
4553  if (working_space[3 * shift + j] != 0) //temp[j]
4554  fAyErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4555  j += 1;
4556  }
4557 
4558  else {
4559  fAyCalc = fAyInit;
4560  fAyErr = 0;
4561  }
4562  if (fFixTxy == false) {
4563  fTxyCalc = working_space[shift + j]; //xk[j]
4564  if (working_space[3 * shift + j] != 0) //temp[j]
4565  fTxyErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4566  j += 1;
4567  }
4568 
4569  else {
4570  fTxyCalc = fTxyInit;
4571  fTxyErr = 0;
4572  }
4573  if (fFixSxy == false) {
4574  fSxyCalc = working_space[shift + j]; //xk[j]
4575  if (working_space[3 * shift + j] != 0) //temp[j]
4576  fSxyErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4577  j += 1;
4578  }
4579 
4580  else {
4581  fSxyCalc = fSxyInit;
4582  fSxyErr = 0;
4583  }
4584  if (fFixTx == false) {
4585  fTxCalc = working_space[shift + j]; //xk[j]
4586  if (working_space[3 * shift + j] != 0) //temp[j]
4587  fTxErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4588  j += 1;
4589  }
4590 
4591  else {
4592  fTxCalc = fTxInit;
4593  fTxErr = 0;
4594  }
4595  if (fFixTy == false) {
4596  fTyCalc = working_space[shift + j]; //xk[j]
4597  if (working_space[3 * shift + j] != 0) //temp[j]
4598  fTyErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4599  j += 1;
4600  }
4601 
4602  else {
4603  fTyCalc = fTyInit;
4604  fTyErr = 0;
4605  }
4606  if (fFixSx == false) {
4607  fSxCalc = working_space[shift + j]; //xk[j]
4608  if (working_space[3 * shift + j] != 0) //temp[j]
4609  fSxErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4610  j += 1;
4611  }
4612 
4613  else {
4614  fSxCalc = fSxInit;
4615  fSxErr = 0;
4616  }
4617  if (fFixSy == false) {
4618  fSyCalc = working_space[shift + j]; //xk[j]
4619  if (working_space[3 * shift + j] != 0) //temp[j]
4620  fSyErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4621  j += 1;
4622  }
4623 
4624  else {
4625  fSyCalc = fSyInit;
4626  fSyErr = 0;
4627  }
4628  if (fFixBx == false) {
4629  fBxCalc = working_space[shift + j]; //xk[j]
4630  if (working_space[3 * shift + j] != 0) //temp[j]
4631  fBxErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4632  j += 1;
4633  }
4634 
4635  else {
4636  fBxCalc = fBxInit;
4637  fBxErr = 0;
4638  }
4639  if (fFixBy == false) {
4640  fByCalc = working_space[shift + j]; //xk[j]
4641  if (working_space[3 * shift + j] != 0) //temp[j]
4642  fByErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
4643  j += 1;
4644  }
4645 
4646  else {
4647  fByCalc = fByInit;
4648  fByErr = 0;
4649  }
4650  b = (fXmax - fXmin + 1) * (fYmax - fYmin + 1) - size;
4651  fChi = chi_cel / b;
4652  for (i1 = fXmin; i1 <= fXmax; i1++) {
4653  for (i2 = fYmin; i2 <= fYmax; i2++) {
4654  f = Shape2(fNPeaks, i1, i2,
4655  working_space, working_space[peak_vel],
4656  working_space[peak_vel + 1],
4657  working_space[peak_vel + 2],
4658  working_space[peak_vel + 3],
4659  working_space[peak_vel + 4],
4660  working_space[peak_vel + 5],
4661  working_space[peak_vel + 6],
4662  working_space[peak_vel + 7],
4663  working_space[peak_vel + 8],
4664  working_space[peak_vel + 9],
4665  working_space[peak_vel + 10],
4666  working_space[peak_vel + 11],
4667  working_space[peak_vel + 12],
4668  working_space[peak_vel + 13]);
4669  source[i1][i2] = f;
4670  }
4671  }
4672  delete [] working_space;
4673  return;
4674 }
4675 
4676 
4677 
4678 
4679 // ____________________________________________________________________________________________________________________________
4681 {
4682 /////////////////////////////////////////////////////////////////////////////
4683 // TWO-DIMENSIONAL FIT FUNCTION USING STIEFEL-HESTENS
4684 // ALGORITHM.
4685 // This function fits the source spectrum. The calling program should
4686 // fill in input parameters of the TSpectrum2Fit class.
4687 // The fitted parameters are written into
4688 // TSpectrum2Fit class output parameters and fitted data are written into
4689 // source spectrum.
4690 //
4691 // Function parameters:
4692 // source-pointer to the matrix of source spectrum
4693 //
4694 /////////////////////////////////////////////////////////////////////////////
4695 //
4696 /*
4697 <div class=Section1>
4698 
4699 <p class=MsoNormal><b><span style='font-size:14.0pt'>Stiefel fitting algorithm</span></b></p>
4700 
4701 <p class=MsoNormal style='text-align:justify'><i><span style='font-size:18.0pt'>&nbsp;</span></i></p>
4702 
4703 <p class=MsoNormal><i>Function:</i></p>
4704 
4705 <p class=MsoNormal style='text-align:justify'>void <a
4706 href="http://root.cern.ch/root/html/TSpectrum.html#TSpectrum:Fit1Awmi"><b>TSpectrumFit2::FitStiefel</b></a>(<a
4707 href="http://root.cern.ch/root/html/ListOfTypes.html#float"><b>float</b></a>
4708 **fSource) </p>
4709 
4710 <p class=MsoNormal style='text-align:justify'>This function fits the source
4711 spectrum using Stiefel-Hestens method [1].  The calling program should fill in
4712 input fitting parameters of the TSpectrumFit2 class using a set of
4713 TSpectrumFit2 setters. The fitted parameters are written into the class and the
4714 fitted data are written into source spectrum. It converges faster than Awmi
4715 method.</p>
4716 
4717 <p class=MsoNormal><i><span style='color:red'>&nbsp;</span></i></p>
4718 
4719 <p class=MsoNormal><i><span style='color:red'>Parameter:</span></i></p>
4720 
4721 <p class=MsoNormal style='text-align:justify'>        <b>fSource</b>-pointer to
4722 the matrix of source spectrum                  </p>
4723 
4724 <p class=MsoNormal style='text-align:justify'>        </p>
4725 
4726 <p class=MsoNormal style='text-align:justify'><b><i>Reference:</i></b></p>
4727 
4728 <p class=MsoNormal style='text-align:justify'>[1] B. Mihaila: Analysis of
4729 complex gamma spectra, Rom. Jorn. Phys., Vol. 39, No. 2, (1994), 139-148.</p>
4730 
4731 <p class=MsoNormal style='text-align:justify'>&nbsp;</p>
4732 
4733 <p class=MsoNormal style='text-align:justify'><i>Example 1 – script FitS.c:</i></p>
4734 
4735 <p class=MsoNormal style='text-align:justify'><span style='font-size:18.0pt'><img
4736 border=0 width=602 height=455 src="gif/spectrum2fit_stiefel_image001.jpg"></span></p>
4737 
4738 <p class=MsoNormal style='text-align:justify'><b>Fig. 1 Original
4739 two-dimensional spectrum with found peaks (using TSpectrum2 peak searching
4740 function). The positions of peaks were used as initial estimates in fitting
4741 procedure.</b></p>
4742 
4743 <p class=MsoNormal style='text-align:justify'><b><span style='font-size:16.0pt'><img
4744 border=0 width=602 height=455 src="gif/spectrum2fit_stiefel_image002.jpg"></span></b></p>
4745 
4746 <p class=MsoBodyText2 style='text-align:justify'>Fig. 2 Fitted (generated from
4747 fitted parameters) spectrum of the data from Fig. 1 using Stiefel-Hestens
4748 method. Each peak was represented by 7 parameters, which together with Sigmax,
4749 Sigmay and a0 resulted in 38 fitted parameters. The chi-square after 1000
4750 iterations was 0.642157.</p>
4751 
4752 <p class=MsoNormal style='text-align:justify'><span style='font-size:18.0pt'>&nbsp;</span></p>
4753 
4754 <p class=MsoNormal><b><span style='color:#339966'>Script:</span></b></p>
4755 
4756 <p class=MsoNormal><span style='font-size:10.0pt'>// Example to illustrate
4757 fitting function, algorithm without matrix inversion (AWMI) (class
4758 TSpectrumFit2).</span></p>
4759 
4760 <p class=MsoNormal><span style='font-size:10.0pt'>// To execute this example,
4761 do</span></p>
4762 
4763 <p class=MsoNormal><span style='font-size:10.0pt'>// root &gt; .x FitStiefel2.C</span></p>
4764 
4765 <p class=MsoNormal><span style='font-size:10.0pt'>&nbsp;</span></p>
4766 
4767 <p class=MsoNormal><span style='font-size:10.0pt'>void FitStiefel2() {</span></p>
4768 
4769 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t i, j, nfound;</span></p>
4770 
4771 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t nbinsx = 64;</span></p>
4772 
4773 <p class=MsoNormal><span style='font-size:10.0pt'>   Int_t nbinsy = 64;   </span></p>
4774 
4775 <p class=MsoNormal><span style='font-size:10.0pt'>   </span><span lang=FR
4776 style='font-size:10.0pt'>Int_t xmin  = 0;</span></p>
4777 
4778 <p class=MsoNormal><span lang=FR style='font-size:10.0pt'>   Int_t xmax  =
4779 nbinsx;</span></p>
4780 
4781 <p class=MsoNormal><span lang=FR style='font-size:10.0pt'>   Int_t ymin  = 0;</span></p>
4782 
4783 <p class=MsoNormal><span lang=FR style='font-size:10.0pt'>   Int_t ymax  =
4784 nbinsy;</span></p>
4785 
4786 <p class=MsoNormal><span lang=FR style='font-size:10.0pt'>   </span><span
4787 style='font-size:10.0pt'>Double_t ** source = new float *[nbinsx];   </span></p>
4788 
4789 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t ** dest = new
4790 float *[nbinsx];      </span></p>
4791 
4792 <p class=MsoNormal><span style='font-size:10.0pt'>   for (i=0;i&lt;nbinsx;i++)</span></p>
4793 
4794 <p class=MsoNormal><span style='font-size:10.0pt'>                                                source[i]=new
4795 float[nbinsy];</span></p>
4796 
4797 <p class=MsoNormal><span style='font-size:10.0pt'>   for (i=0;i&lt;nbinsx;i++)</span></p>
4798 
4799 <p class=MsoNormal><span style='font-size:10.0pt'>                                                dest[i]=new
4800 float[nbinsy];</span></p>
4801 
4802 <p class=MsoNormal><span style='font-size:10.0pt'>   TH2F *search = new
4803 TH2F(&quot;search&quot;,&quot;High resolution peak
4804 searching&quot;,nbinsx,xmin,xmax,nbinsy,ymin,ymax);</span></p>
4805 
4806 <p class=MsoNormal><span style='font-size:10.0pt'>   TFile *f = new
4807 TFile(&quot;TSpectrum2.root&quot;);</span></p>
4808 
4809 <p class=MsoNormal><span style='font-size:10.0pt'>   search=(TH2F*)
4810 f-&gt;Get(&quot;search4;1&quot;);</span></p>
4811 
4812 <p class=MsoNormal><span style='font-size:10.0pt'>   TCanvas *Searching = new
4813 TCanvas(&quot;Searching&quot;,&quot;Two-dimensional fitting using
4814 Stiefel-Hestens method&quot;,10,10,1000,700);</span></p>
4815 
4816 <p class=MsoNormal><span style='font-size:10.0pt'>   TSpectrum2 *s = new
4817 TSpectrum2();</span></p>
4818 
4819 <p class=MsoNormal><span style='font-size:10.0pt'>   for (i = 0; i &lt; nbinsx;
4820 i++){</span></p>
4821 
4822 <p class=MsoNormal><span style='font-size:10.0pt'>     for (j = 0; j &lt;
4823 nbinsy; j++){</span></p>
4824 
4825 <p class=MsoNormal><span style='font-size:10.0pt'>                    source[i][j]
4826 = search-&gt;GetBinContent(i + 1,j + 1); </span></p>
4827 
4828 <p class=MsoNormal><span style='font-size:10.0pt'>                 }</span></p>
4829 
4830 <p class=MsoNormal><span style='font-size:10.0pt'>   }   </span></p>
4831 
4832 <p class=MsoNormal><span style='font-size:10.0pt'>   nfound =
4833 s-&gt;SearchHighRes(source, dest, nbinsx, nbinsy, 2, 5, kTRUE, 3, kFALSE, 3);  
4834 </span></p>
4835 
4836 <p class=MsoNormal><span style='font-size:10.0pt'>   printf(&quot;Found %d
4837 candidate peaks\n&quot;,nfound);</span></p>
4838 
4839 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t *FixPosX = new
4840 Bool_t[nfound];</span></p>
4841 
4842 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t *FixPosY = new
4843 Bool_t[nfound];   </span></p>
4844 
4845 <p class=MsoNormal><span style='font-size:10.0pt'>   Bool_t *FixAmp = new
4846 Bool_t[nfound];      </span></p>
4847 
4848 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t *PosX = new
4849 Double_t[nfound];         </span></p>
4850 
4851 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t *PosY = new
4852 Double_t[nfound];</span></p>
4853 
4854 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t *Amp = new
4855 Double_t[nfound];      </span></p>
4856 
4857 <p class=MsoNormal><span style='font-size:10.0pt'>   Double_t *AmpXY = new
4858 Double_t[nfound];         </span></p>
4859 
4860 <p class=MsoNormal><span style='font-size:10.0pt'>   PosX = s-&gt;GetPositionX();</span></p>
4861 
4862 <p class=MsoNormal><span style='font-size:10.0pt'>   PosY =
4863 s-&gt;GetPositionY();      </span></p>
4864 
4865 <p class=MsoNormal><span style='font-size:10.0pt'>   for(i = 0; i&lt; nfound ;
4866 i++){</span></p>
4867 
4868 <p class=MsoNormal><span style='font-size:10.0pt'>      FixPosX[i] = kFALSE;</span></p>
4869 
4870 <p class=MsoNormal><span style='font-size:10.0pt'>      FixPosY[i] =
4871 kFALSE;      </span></p>
4872 
4873 <p class=MsoNormal><span style='font-size:10.0pt'>      FixAmp[i] = kFALSE;    </span></p>
4874 
4875 <p class=MsoNormal><span style='font-size:10.0pt'>      Amp[i] =
4876 source[(Int_t)(PosX[i]+0.5)][(Int_t)(PosY[i]+0.5)];      //initial values of peaks
4877 amplitudes, input parameters          </span></p>
4878 
4879 <p class=MsoNormal><span style='font-size:10.0pt'>      AmpXY[i] = 0;</span></p>
4880 
4881 <p class=MsoNormal><span style='font-size:10.0pt'>   }</span></p>
4882 
4883 <p class=MsoNormal><span style='font-size:10.0pt'>   //filling in the initial
4884 estimates of the input parameters</span></p>
4885 
4886 <p class=MsoNormal><span style='font-size:10.0pt'>   TSpectrumFit2 *pfit=new
4887 TSpectrumFit2(nfound);</span></p>
4888 
4889 <p class=MsoNormal><span style='font-size:10.0pt'>  
4890 pfit-&gt;SetFitParameters(xmin, xmax-1, ymin, ymax-1, 1000, 0.1,
4891 pfit-&gt;kFitOptimChiCounts, pfit-&gt;kFitAlphaHalving, pfit-&gt;kFitPower2,
4892 pfit-&gt;kFitTaylorOrderFirst);   </span></p>
4893 
4894 <p class=MsoNormal><span style='font-size:10.0pt'>  
4895 pfit-&gt;SetPeakParameters(2, kFALSE, 2, kFALSE, 0, kTRUE, PosX, (Bool_t *)
4896 FixPosX, PosY, (Bool_t *) FixPosY, PosX, (Bool_t *) FixPosX, PosY, (Bool_t *)
4897 FixPosY, Amp, (Bool_t *) FixAmp, AmpXY, (Bool_t *) FixAmp, AmpXY, (Bool_t *)
4898 FixAmp);      </span></p>
4899 
4900 <p class=MsoNormal><span style='font-size:10.0pt'>  
4901 pfit-&gt;SetBackgroundParameters(0, kFALSE, 0, kTRUE, 0, kTRUE);   </span></p>
4902 
4903 <p class=MsoNormal><span style='font-size:10.0pt'>  
4904 pfit-&gt;FitStiefel(source);</span></p>
4905 
4906 <p class=MsoNormal><span style='font-size:10.0pt'>    for (i = 0; i &lt;
4907 nbinsx; i++){</span></p>
4908 
4909 <p class=MsoNormal><span style='font-size:10.0pt'>     for (j = 0; j &lt;
4910 nbinsy; j++){</span></p>
4911 
4912 <p class=MsoNormal><span style='font-size:10.0pt'>                  search-&gt;SetBinContent(i
4913 + 1, j + 1,source[i][j]);</span></p>
4914 
4915 <p class=MsoNormal><span style='font-size:10.0pt'>                 }</span></p>
4916 
4917 <p class=MsoNormal><span style='font-size:10.0pt'>   }   </span></p>
4918 
4919 <p class=MsoNormal><span style='font-size:10.0pt'>  
4920 search-&gt;Draw(&quot;SURF&quot;);</span></p>
4921 
4922 <p class=MsoNormal><span style='font-size:10.0pt'>}</span></p>
4923 
4924 </div>
4925 
4926  */
4927 
4928  Int_t i, i1, i2, j, k, shift =
4929  7 * fNPeaks + 14, peak_vel, size, iter, regul_cycle,
4930  flag;
4931  Double_t a, b, c, alpha, chi_opt, yw, ywm, f, chi2, chi_min, chi = 0
4932  , pi, pmin = 0, chi_cel = 0, chi_er;
4933  Double_t *working_space = new Double_t[5 * (7 * fNPeaks + 14)];
4934  for (i = 0, j = 0; i < fNPeaks; i++) {
4935  working_space[7 * i] = fAmpInit[i]; //vector parameter
4936  if (fFixAmp[i] == false) {
4937  working_space[shift + j] = fAmpInit[i]; //vector xk
4938  j += 1;
4939  }
4940  working_space[7 * i + 1] = fPositionInitX[i]; //vector parameter
4941  if (fFixPositionX[i] == false) {
4942  working_space[shift + j] = fPositionInitX[i]; //vector xk
4943  j += 1;
4944  }
4945  working_space[7 * i + 2] = fPositionInitY[i]; //vector parameter
4946  if (fFixPositionY[i] == false) {
4947  working_space[shift + j] = fPositionInitY[i]; //vector xk
4948  j += 1;
4949  }
4950  working_space[7 * i + 3] = fAmpInitX1[i]; //vector parameter
4951  if (fFixAmpX1[i] == false) {
4952  working_space[shift + j] = fAmpInitX1[i]; //vector xk
4953  j += 1;
4954  }
4955  working_space[7 * i + 4] = fAmpInitY1[i]; //vector parameter
4956  if (fFixAmpY1[i] == false) {
4957  working_space[shift + j] = fAmpInitY1[i]; //vector xk
4958  j += 1;
4959  }
4960  working_space[7 * i + 5] = fPositionInitX1[i]; //vector parameter
4961  if (fFixPositionX1[i] == false) {
4962  working_space[shift + j] = fPositionInitX1[i]; //vector xk
4963  j += 1;
4964  }
4965  working_space[7 * i + 6] = fPositionInitY1[i]; //vector parameter
4966  if (fFixPositionY1[i] == false) {
4967  working_space[shift + j] = fPositionInitY1[i]; //vector xk
4968  j += 1;
4969  }
4970  }
4971  peak_vel = 7 * i;
4972  working_space[7 * i] = fSigmaInitX; //vector parameter
4973  if (fFixSigmaX == false) {
4974  working_space[shift + j] = fSigmaInitX; //vector xk
4975  j += 1;
4976  }
4977  working_space[7 * i + 1] = fSigmaInitY; //vector parameter
4978  if (fFixSigmaY == false) {
4979  working_space[shift + j] = fSigmaInitY; //vector xk
4980  j += 1;
4981  }
4982  working_space[7 * i + 2] = fRoInit; //vector parameter
4983  if (fFixRo == false) {
4984  working_space[shift + j] = fRoInit; //vector xk
4985  j += 1;
4986  }
4987  working_space[7 * i + 3] = fA0Init; //vector parameter
4988  if (fFixA0 == false) {
4989  working_space[shift + j] = fA0Init; //vector xk
4990  j += 1;
4991  }
4992  working_space[7 * i + 4] = fAxInit; //vector parameter
4993  if (fFixAx == false) {
4994  working_space[shift + j] = fAxInit; //vector xk
4995  j += 1;
4996  }
4997  working_space[7 * i + 5] = fAyInit; //vector parameter
4998  if (fFixAy == false) {
4999  working_space[shift + j] = fAyInit; //vector xk
5000  j += 1;
5001  }
5002  working_space[7 * i + 6] = fTxyInit; //vector parameter
5003  if (fFixTxy == false) {
5004  working_space[shift + j] = fTxyInit; //vector xk
5005  j += 1;
5006  }
5007  working_space[7 * i + 7] = fSxyInit; //vector parameter
5008  if (fFixSxy == false) {
5009  working_space[shift + j] = fSxyInit; //vector xk
5010  j += 1;
5011  }
5012  working_space[7 * i + 8] = fTxInit; //vector parameter
5013  if (fFixTx == false) {
5014  working_space[shift + j] = fTxInit; //vector xk
5015  j += 1;
5016  }
5017  working_space[7 * i + 9] = fTyInit; //vector parameter
5018  if (fFixTy == false) {
5019  working_space[shift + j] = fTyInit; //vector xk
5020  j += 1;
5021  }
5022  working_space[7 * i + 10] = fSxyInit; //vector parameter
5023  if (fFixSx == false) {
5024  working_space[shift + j] = fSxInit; //vector xk
5025  j += 1;
5026  }
5027  working_space[7 * i + 11] = fSyInit; //vector parameter
5028  if (fFixSy == false) {
5029  working_space[shift + j] = fSyInit; //vector xk
5030  j += 1;
5031  }
5032  working_space[7 * i + 12] = fBxInit; //vector parameter
5033  if (fFixBx == false) {
5034  working_space[shift + j] = fBxInit; //vector xk
5035  j += 1;
5036  }
5037  working_space[7 * i + 13] = fByInit; //vector parameter
5038  if (fFixBy == false) {
5039  working_space[shift + j] = fByInit; //vector xk
5040  j += 1;
5041  }
5042  size = j;
5043  Double_t **working_matrix = new Double_t *[size];
5044  for (i = 0; i < size; i++)
5045  working_matrix[i] = new Double_t[size + 4];
5046  for (iter = 0; iter < fNumberIterations; iter++) {
5047  for (j = 0; j < size; j++) {
5048  working_space[3 * shift + j] = 0; //temp
5049  for (k = 0; k <= size; k++) {
5050  working_matrix[j][k] = 0;
5051  }
5052  }
5053 
5054  //filling working matrix
5055  alpha = fAlpha;
5056  chi_opt = 0;
5057  for (i1 = fXmin; i1 <= fXmax; i1++) {
5058  for (i2 = fYmin; i2 <= fYmax; i2++) {
5059  //calculation of gradient vector
5060  for (j = 0, k = 0; j < fNPeaks; j++) {
5061  if (fFixAmp[j] == false) {
5062  working_space[2 * shift + k] =
5063  Deramp2(i1, i2,
5064  working_space[7 * j + 1],
5065  working_space[7 * j + 2],
5066  working_space[peak_vel],
5067  working_space[peak_vel + 1],
5068  working_space[peak_vel + 2],
5069  working_space[peak_vel + 6],
5070  working_space[peak_vel + 7],
5071  working_space[peak_vel + 12],
5072  working_space[peak_vel + 13]);
5073  k += 1;
5074  }
5075  if (fFixPositionX[j] == false) {
5076  working_space[2 * shift + k] =
5077  Deri02(i1, i2,
5078  working_space[7 * j],
5079  working_space[7 * j + 1],
5080  working_space[7 * j + 2],
5081  working_space[peak_vel],
5082  working_space[peak_vel + 1],
5083  working_space[peak_vel + 2],
5084  working_space[peak_vel + 6],
5085  working_space[peak_vel + 7],
5086  working_space[peak_vel + 12],
5087  working_space[peak_vel + 13]);
5088  k += 1;
5089  }
5090  if (fFixPositionY[j] == false) {
5091  working_space[2 * shift + k] =
5092  Derj02(i1, i2,
5093  working_space[7 * j],
5094  working_space[7 * j + 1],
5095  working_space[7 * j + 2],
5096  working_space[peak_vel],
5097  working_space[peak_vel + 1],
5098  working_space[peak_vel + 2],
5099  working_space[peak_vel + 6],
5100  working_space[peak_vel + 7],
5101  working_space[peak_vel + 12],
5102  working_space[peak_vel + 13]);
5103  k += 1;
5104  }
5105  if (fFixAmpX1[j] == false) {
5106  working_space[2 * shift + k] =
5107  Derampx(i1, working_space[7 * j + 5],
5108  working_space[peak_vel],
5109  working_space[peak_vel + 8],
5110  working_space[peak_vel + 10],
5111  working_space[peak_vel + 12]);
5112  k += 1;
5113  }
5114  if (fFixAmpY1[j] == false) {
5115  working_space[2 * shift + k] =
5116  Derampx(i2, working_space[7 * j + 6],
5117  working_space[peak_vel + 1],
5118  working_space[peak_vel + 9],
5119  working_space[peak_vel + 11],
5120  working_space[peak_vel + 13]);
5121  k += 1;
5122  }
5123  if (fFixPositionX1[j] == false) {
5124  working_space[2 * shift + k] =
5125  Deri01(i1, working_space[7 * j + 3],
5126  working_space[7 * j + 5],
5127  working_space[peak_vel],
5128  working_space[peak_vel + 8],
5129  working_space[peak_vel + 10],
5130  working_space[peak_vel + 12]);
5131  k += 1;
5132  }
5133  if (fFixPositionY1[j] == false) {
5134  working_space[2 * shift + k] =
5135  Deri01(i2, working_space[7 * j + 4],
5136  working_space[7 * j + 6],
5137  working_space[peak_vel + 1],
5138  working_space[peak_vel + 9],
5139  working_space[peak_vel + 11],
5140  working_space[peak_vel + 13]);
5141  k += 1;
5142  }
5143  } if (fFixSigmaX == false) {
5144  working_space[2 * shift + k] =
5145  Dersigmax(fNPeaks, i1, i2,
5146  working_space, working_space[peak_vel],
5147  working_space[peak_vel + 1],
5148  working_space[peak_vel + 2],
5149  working_space[peak_vel + 6],
5150  working_space[peak_vel + 7],
5151  working_space[peak_vel + 8],
5152  working_space[peak_vel + 10],
5153  working_space[peak_vel + 12],
5154  working_space[peak_vel + 13]);
5155  k += 1;
5156  }
5157  if (fFixSigmaY == false) {
5158  working_space[2 * shift + k] =
5159  Dersigmay(fNPeaks, i1, i2,
5160  working_space, working_space[peak_vel],
5161  working_space[peak_vel + 1],
5162  working_space[peak_vel + 2],
5163  working_space[peak_vel + 6],
5164  working_space[peak_vel + 7],
5165  working_space[peak_vel + 9],
5166  working_space[peak_vel + 11],
5167  working_space[peak_vel + 12],
5168  working_space[peak_vel + 13]);
5169  k += 1;
5170  }
5171  if (fFixRo == false) {
5172  working_space[2 * shift + k] =
5173  Derro(fNPeaks, i1, i2,
5174  working_space, working_space[peak_vel],
5175  working_space[peak_vel + 1],
5176  working_space[peak_vel + 2]);
5177  k += 1;
5178  }
5179  if (fFixA0 == false) {
5180  working_space[2 * shift + k] = 1.;
5181  k += 1;
5182  }
5183  if (fFixAx == false) {
5184  working_space[2 * shift + k] = i1;
5185  k += 1;
5186  }
5187  if (fFixAy == false) {
5188  working_space[2 * shift + k] = i2;
5189  k += 1;
5190  }
5191  if (fFixTxy == false) {
5192  working_space[2 * shift + k] =
5193  Dertxy(fNPeaks, i1, i2,
5194  working_space, working_space[peak_vel],
5195  working_space[peak_vel + 1],
5196  working_space[peak_vel + 12],
5197  working_space[peak_vel + 13]);
5198  k += 1;
5199  }
5200  if (fFixSxy == false) {
5201  working_space[2 * shift + k] =
5202  Dersxy(fNPeaks, i1, i2,
5203  working_space, working_space[peak_vel],
5204  working_space[peak_vel + 1]);
5205  k += 1;
5206  }
5207  if (fFixTx == false) {
5208  working_space[2 * shift + k] =
5209  Dertx(fNPeaks, i1, working_space,
5210  working_space[peak_vel],
5211  working_space[peak_vel + 12]);
5212  k += 1;
5213  }
5214  if (fFixTy == false) {
5215  working_space[2 * shift + k] =
5216  Derty(fNPeaks, i2, working_space,
5217  working_space[peak_vel + 1],
5218  working_space[peak_vel + 13]);
5219  k += 1;
5220  }
5221  if (fFixSx == false) {
5222  working_space[2 * shift + k] =
5223  Dersx(fNPeaks, i1, working_space,
5224  working_space[peak_vel]);
5225  k += 1;
5226  }
5227  if (fFixSy == false) {
5228  working_space[2 * shift + k] =
5229  Dersy(fNPeaks, i2, working_space,
5230  working_space[peak_vel + 1]);
5231  k += 1;
5232  }
5233  if (fFixBx == false) {
5234  working_space[2 * shift + k] =
5235  Derbx(fNPeaks, i1, i2,
5236  working_space, working_space[peak_vel],
5237  working_space[peak_vel + 1],
5238  working_space[peak_vel + 6],
5239  working_space[peak_vel + 8],
5240  working_space[peak_vel + 12],
5241  working_space[peak_vel + 13]);
5242  k += 1;
5243  }
5244  if (fFixBy == false) {
5245  working_space[2 * shift + k] =
5246  Derby(fNPeaks, i1, i2,
5247  working_space, working_space[peak_vel],
5248  working_space[peak_vel + 1],
5249  working_space[peak_vel + 6],
5250  working_space[peak_vel + 8],
5251  working_space[peak_vel + 12],
5252  working_space[peak_vel + 13]);
5253  k += 1;
5254  }
5255  yw = source[i1][i2];
5256  ywm = yw;
5257  f = Shape2(fNPeaks, i1, i2,
5258  working_space, working_space[peak_vel],
5259  working_space[peak_vel + 1],
5260  working_space[peak_vel + 2],
5261  working_space[peak_vel + 3],
5262  working_space[peak_vel + 4],
5263  working_space[peak_vel + 5],
5264  working_space[peak_vel + 6],
5265  working_space[peak_vel + 7],
5266  working_space[peak_vel + 8],
5267  working_space[peak_vel + 9],
5268  working_space[peak_vel + 10],
5269  working_space[peak_vel + 11],
5270  working_space[peak_vel + 12],
5271  working_space[peak_vel + 13]);
5273  if (f > 0.00001)
5274  chi_opt += yw * TMath::Log(f) - f;
5275  }
5276 
5277  else {
5278  if (ywm != 0)
5279  chi_opt += (yw - f) * (yw - f) / ywm;
5280  }
5282  ywm = f;
5283  if (f < 0.00001)
5284  ywm = 0.00001;
5285  }
5286 
5287  else if (fStatisticType == kFitOptimMaxLikelihood) {
5288  ywm = f;
5289  if (f < 0.00001)
5290  ywm = 0.00001;
5291  }
5292 
5293  else {
5294  if (ywm == 0)
5295  ywm = 1;
5296  }
5297  for (j = 0; j < size; j++) {
5298  for (k = 0; k < size; k++) {
5299  b = working_space[2 * shift +
5300  j] * working_space[2 * shift +
5301  k] / ywm;
5303  b = b * (4 * yw - 2 * f) / ywm;
5304  working_matrix[j][k] += b;
5305  if (j == k)
5306  working_space[3 * shift + j] += b;
5307  }
5308  }
5310  b = (f * f - yw * yw) / (ywm * ywm);
5311 
5312  else
5313  b = (f - yw) / ywm;
5314  for (j = 0; j < size; j++) {
5315  working_matrix[j][size] -=
5316  b * working_space[2 * shift + j];
5317  }
5318  }
5319  }
5320  for (i = 0; i < size; i++) {
5321  working_matrix[i][size + 1] = 0; //xk
5322  }
5323  StiefelInversion(working_matrix, size);
5324  for (i = 0; i < size; i++) {
5325  working_space[2 * shift + i] = working_matrix[i][size + 1]; //der
5326  }
5327 
5328  //calculate chi_opt
5329  chi2 = chi_opt;
5330  chi_opt = TMath::Sqrt(TMath::Abs(chi_opt));
5331 
5332  //calculate new parameters
5333  regul_cycle = 0;
5334  for (j = 0; j < size; j++) {
5335  working_space[4 * shift + j] = working_space[shift + j]; //temp_xk[j]=xk[j]
5336  }
5337 
5338  do {
5339  if (fAlphaOptim == kFitAlphaOptimal) {
5341  chi_min = 10000 * chi2;
5342 
5343  else
5344  chi_min = 0.1 * chi2;
5345  flag = 0;
5346  for (pi = 0.1; flag == 0 && pi <= 100; pi += 0.1) {
5347  for (j = 0; j < size; j++) {
5348  working_space[shift + j] = working_space[4 * shift + j] + pi * alpha * working_space[2 * shift + j]; //xk[j]=temp_xk[j]+pi*alpha*der[j]
5349  }
5350  for (i = 0, j = 0; i < fNPeaks; i++) {
5351  if (fFixAmp[i] == false) {
5352  if (working_space[shift + j] < 0) //xk[j]
5353  working_space[shift + j] = 0; //xk[j]
5354  working_space[7 * i] = working_space[shift + j]; //parameter[7*i]=xk[j]
5355  j += 1;
5356  }
5357  if (fFixPositionX[i] == false) {
5358  if (working_space[shift + j] < fXmin) //xk[j]
5359  working_space[shift + j] = fXmin; //xk[j]
5360  if (working_space[shift + j] > fXmax) //xk[j]
5361  working_space[shift + j] = fXmax; //xk[j]
5362  working_space[7 * i + 1] = working_space[shift + j]; //parameter[7*i+1]=xk[j]
5363  j += 1;
5364  }
5365  if (fFixPositionY[i] == false) {
5366  if (working_space[shift + j] < fYmin) //xk[j]
5367  working_space[shift + j] = fYmin; //xk[j]
5368  if (working_space[shift + j] > fYmax) //xk[j]
5369  working_space[shift + j] = fYmax; //xk[j]
5370  working_space[7 * i + 2] = working_space[shift + j]; //parameter[7*i+2]=xk[j]
5371  j += 1;
5372  }
5373  if (fFixAmpX1[i] == false) {
5374  if (working_space[shift + j] < 0) //xk[j]
5375  working_space[shift + j] = 0; //xk[j]
5376  working_space[7 * i + 3] = working_space[shift + j]; //parameter[7*i+3]=xk[j]
5377  j += 1;
5378  }
5379  if (fFixAmpY1[i] == false) {
5380  if (working_space[shift + j] < 0) //xk[j]
5381  working_space[shift + j] = 0; //xk[j]
5382  working_space[7 * i + 4] = working_space[shift + j]; //parameter[7*i+4]=xk[j]
5383  j += 1;
5384  }
5385  if (fFixPositionX1[i] == false) {
5386  if (working_space[shift + j] < fXmin) //xk[j]
5387  working_space[shift + j] = fXmin; //xk[j]
5388  if (working_space[shift + j] > fXmax) //xk[j]
5389  working_space[shift + j] = fXmax; //xk[j]
5390  working_space[7 * i + 5] = working_space[shift + j]; //parameter[7*i+5]=xk[j]
5391  j += 1;
5392  }
5393  if (fFixPositionY1[i] == false) {
5394  if (working_space[shift + j] < fYmin) //xk[j]
5395  working_space[shift + j] = fYmin; //xk[j]
5396  if (working_space[shift + j] > fYmax) //xk[j]
5397  working_space[shift + j] = fYmax; //xk[j]
5398  working_space[7 * i + 6] = working_space[shift + j]; //parameter[7*i+6]=xk[j]
5399  j += 1;
5400  }
5401  }
5402  if (fFixSigmaX == false) {
5403  if (working_space[shift + j] < 0.001) { //xk[j]
5404  working_space[shift + j] = 0.001; //xk[j]
5405  }
5406  working_space[peak_vel] = working_space[shift + j]; //parameter[peak_vel]=xk[j]
5407  j += 1;
5408  }
5409  if (fFixSigmaY == false) {
5410  if (working_space[shift + j] < 0.001) { //xk[j]
5411  working_space[shift + j] = 0.001; //xk[j]
5412  }
5413  working_space[peak_vel + 1] = working_space[shift + j]; //parameter[peak_vel+1]=xk[j]
5414  j += 1;
5415  }
5416  if (fFixRo == false) {
5417  if (working_space[shift + j] < -1) { //xk[j]
5418  working_space[shift + j] = -1; //xk[j]
5419  }
5420  if (working_space[shift + j] > 1) { //xk[j]
5421  working_space[shift + j] = 1; //xk[j]
5422  }
5423  working_space[peak_vel + 2] = working_space[shift + j]; //parameter[peak_vel+2]=xk[j]
5424  j += 1;
5425  }
5426  if (fFixA0 == false) {
5427  working_space[peak_vel + 3] = working_space[shift + j]; //parameter[peak_vel+3]=xk[j]
5428  j += 1;
5429  }
5430  if (fFixAx == false) {
5431  working_space[peak_vel + 4] = working_space[shift + j]; //parameter[peak_vel+4]=xk[j]
5432  j += 1;
5433  }
5434  if (fFixAy == false) {
5435  working_space[peak_vel + 5] = working_space[shift + j]; //parameter[peak_vel+5]=xk[j]
5436  j += 1;
5437  }
5438  if (fFixTxy == false) {
5439  working_space[peak_vel + 6] = working_space[shift + j]; //parameter[peak_vel+6]=xk[j]
5440  j += 1;
5441  }
5442  if (fFixSxy == false) {
5443  working_space[peak_vel + 7] = working_space[shift + j]; //parameter[peak_vel+7]=xk[j]
5444  j += 1;
5445  }
5446  if (fFixTx == false) {
5447  working_space[peak_vel + 8] = working_space[shift + j]; //parameter[peak_vel+8]=xk[j]
5448  j += 1;
5449  }
5450  if (fFixTy == false) {
5451  working_space[peak_vel + 9] = working_space[shift + j]; //parameter[peak_vel+9]=xk[j]
5452  j += 1;
5453  }
5454  if (fFixSx == false) {
5455  working_space[peak_vel + 10] = working_space[shift + j]; //parameter[peak_vel+10]=xk[j]
5456  j += 1;
5457  }
5458  if (fFixSy == false) {
5459  working_space[peak_vel + 11] = working_space[shift + j]; //parameter[peak_vel+11]=xk[j]
5460  j += 1;
5461  }
5462  if (fFixBx == false) {
5463  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
5464  if (working_space[shift + j] < 0) //xk[j]
5465  working_space[shift + j] = -0.001; //xk[j]
5466  else
5467  working_space[shift + j] = 0.001; //xk[j]
5468  }
5469  working_space[peak_vel + 12] = working_space[shift + j]; //parameter[peak_vel+12]=xk[j]
5470  j += 1;
5471  }
5472  if (fFixBy == false) {
5473  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
5474  if (working_space[shift + j] < 0) //xk[j]
5475  working_space[shift + j] = -0.001; //xk[j]
5476  else
5477  working_space[shift + j] = 0.001; //xk[j]
5478  }
5479  working_space[peak_vel + 13] = working_space[shift + j]; //parameter[peak_vel+13]=xk[j]
5480  j += 1;
5481  }
5482  chi2 = 0;
5483  for (i1 = fXmin; i1 <= fXmax; i1++) {
5484  for (i2 = fYmin; i2 <= fYmax; i2++) {
5485  yw = source[i1][i2];
5486  ywm = yw;
5487  f = Shape2(fNPeaks, i1,
5488  i2, working_space,
5489  working_space[peak_vel],
5490  working_space[peak_vel + 1],
5491  working_space[peak_vel + 2],
5492  working_space[peak_vel + 3],
5493  working_space[peak_vel + 4],
5494  working_space[peak_vel + 5],
5495  working_space[peak_vel + 6],
5496  working_space[peak_vel + 7],
5497  working_space[peak_vel + 8],
5498  working_space[peak_vel + 9],
5499  working_space[peak_vel + 10],
5500  working_space[peak_vel + 11],
5501  working_space[peak_vel + 12],
5502  working_space[peak_vel + 13]);
5504  ywm = f;
5505  if (f < 0.00001)
5506  ywm = 0.00001;
5507  }
5509  if (f > 0.00001)
5510  chi2 += yw * TMath::Log(f) - f;
5511  }
5512 
5513  else {
5514  if (ywm != 0)
5515  chi2 += (yw - f) * (yw - f) / ywm;
5516  }
5517  }
5518  }
5519  if ((chi2 < chi_min
5521  || (chi2 > chi_min
5523  pmin = pi, chi_min = chi2;
5524  }
5525 
5526  else
5527  flag = 1;
5528  if (pi == 0.1)
5529  chi_min = chi2;
5530  chi = chi_min;
5531  }
5532  if (pmin != 0.1) {
5533  for (j = 0; j < size; j++) {
5534  working_space[shift + j] = working_space[4 * shift + j] + pmin * alpha * working_space[2 * shift + j]; //xk[j]=temp_xk[j]+pmin*alpha*der[j]
5535  }
5536  for (i = 0, j = 0; i < fNPeaks; i++) {
5537  if (fFixAmp[i] == false) {
5538  if (working_space[shift + j] < 0) //xk[j]
5539  working_space[shift + j] = 0; //xk[j]
5540  working_space[7 * i] = working_space[shift + j]; //parameter[7*i]=xk[j]
5541  j += 1;
5542  }
5543  if (fFixPositionX[i] == false) {
5544  if (working_space[shift + j] < fXmin) //xk[j]
5545  working_space[shift + j] = fXmin; //xk[j]
5546  if (working_space[shift + j] > fXmax) //xk[j]
5547  working_space[shift + j] = fXmax; //xk[j]
5548  working_space[7 * i + 1] = working_space[shift + j]; //parameter[7*i+1]=xk[j]
5549  j += 1;
5550  }
5551  if (fFixPositionY[i] == false) {
5552  if (working_space[shift + j] < fYmin) //xk[j]
5553  working_space[shift + j] = fYmin; //xk[j]
5554  if (working_space[shift + j] > fYmax) //xk[j]
5555  working_space[shift + j] = fYmax; //xk[j]
5556  working_space[7 * i + 2] = working_space[shift + j]; //parameter[7*i+2]=xk[j]
5557  j += 1;
5558  }
5559  if (fFixAmpX1[i] == false) {
5560  if (working_space[shift + j] < 0) //xk[j]
5561  working_space[shift + j] = 0; //xk[j]
5562  working_space[7 * i + 3] = working_space[shift + j]; //parameter[7*i+3]=xk[j]
5563  j += 1;
5564  }
5565  if (fFixAmpY1[i] == false) {
5566  if (working_space[shift + j] < 0) //xk[j]
5567  working_space[shift + j] = 0; //xk[j]
5568  working_space[7 * i + 4] = working_space[shift + j]; //parameter[7*i+4]=xk[j]
5569  j += 1;
5570  }
5571  if (fFixPositionX1[i] == false) {
5572  if (working_space[shift + j] < fXmin) //xk[j]
5573  working_space[shift + j] = fXmin; //xk[j]
5574  if (working_space[shift + j] > fXmax) //xk[j]
5575  working_space[shift + j] = fXmax; //xk[j]
5576  working_space[7 * i + 5] = working_space[shift + j]; //parameter[7*i+5]=xk[j]
5577  j += 1;
5578  }
5579  if (fFixPositionY1[i] == false) {
5580  if (working_space[shift + j] < fYmin) //xk[j]
5581  working_space[shift + j] = fYmin; //xk[j]
5582  if (working_space[shift + j] > fYmax) //xk[j]
5583  working_space[shift + j] = fYmax; //xk[j]
5584  working_space[7 * i + 6] = working_space[shift + j]; //parameter[7*i+6]=xk[j]
5585  j += 1;
5586  }
5587  }
5588  if (fFixSigmaX == false) {
5589  if (working_space[shift + j] < 0.001) { //xk[j]
5590  working_space[shift + j] = 0.001; //xk[j]
5591  }
5592  working_space[peak_vel] = working_space[shift + j]; //parameter[peak_vel]=xk[j]
5593  j += 1;
5594  }
5595  if (fFixSigmaY == false) {
5596  if (working_space[shift + j] < 0.001) { //xk[j]
5597  working_space[shift + j] = 0.001; //xk[j]
5598  }
5599  working_space[peak_vel + 1] = working_space[shift + j]; //parameter[peak_vel+1]=xk[j]
5600  j += 1;
5601  }
5602  if (fFixRo == false) {
5603  if (working_space[shift + j] < -1) { //xk[j]
5604  working_space[shift + j] = -1; //xk[j]
5605  }
5606  if (working_space[shift + j] > 1) { //xk[j]
5607  working_space[shift + j] = 1; //xk[j]
5608  }
5609  working_space[peak_vel + 2] = working_space[shift + j]; //parameter[peak_vel+2]=xk[j]
5610  j += 1;
5611  }
5612  if (fFixA0 == false) {
5613  working_space[peak_vel + 3] = working_space[shift + j]; //parameter[peak_vel+3]=xk[j]
5614  j += 1;
5615  }
5616  if (fFixAx == false) {
5617  working_space[peak_vel + 4] = working_space[shift + j]; //parameter[peak_vel+4]=xk[j]
5618  j += 1;
5619  }
5620  if (fFixAy == false) {
5621  working_space[peak_vel + 5] = working_space[shift + j]; //parameter[peak_vel+5]=xk[j]
5622  j += 1;
5623  }
5624  if (fFixTxy == false) {
5625  working_space[peak_vel + 6] = working_space[shift + j]; //parameter[peak_vel+6]=xk[j]
5626  j += 1;
5627  }
5628  if (fFixSxy == false) {
5629  working_space[peak_vel + 7] = working_space[shift + j]; //parameter[peak_vel+7]=xk[j]
5630  j += 1;
5631  }
5632  if (fFixTx == false) {
5633  working_space[peak_vel + 8] = working_space[shift + j]; //parameter[peak_vel+8]=xk[j]
5634  j += 1;
5635  }
5636  if (fFixTy == false) {
5637  working_space[peak_vel + 9] = working_space[shift + j]; //parameter[peak_vel+9]=xk[j]
5638  j += 1;
5639  }
5640  if (fFixSx == false) {
5641  working_space[peak_vel + 10] = working_space[shift + j]; //parameter[peak_vel+10]=xk[j]
5642  j += 1;
5643  }
5644  if (fFixSy == false) {
5645  working_space[peak_vel + 11] = working_space[shift + j]; //parameter[peak_vel+11]=xk[j]
5646  j += 1;
5647  }
5648  if (fFixBx == false) {
5649  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
5650  if (working_space[shift + j] < 0) //xk[j]
5651  working_space[shift + j] = -0.001; //xk[j]
5652  else
5653  working_space[shift + j] = 0.001; //xk[j]
5654  }
5655  working_space[peak_vel + 12] = working_space[shift + j]; //parameter[peak_vel+12]=xk[j]
5656  j += 1;
5657  }
5658  if (fFixBy == false) {
5659  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
5660  if (working_space[shift + j] < 0) //xk[j]
5661  working_space[shift + j] = -0.001; //xk[j]
5662  else
5663  working_space[shift + j] = 0.001; //xk[j]
5664  }
5665  working_space[peak_vel + 13] = working_space[shift + j]; //parameter[peak_vel+13]=xk[j]
5666  j += 1;
5667  }
5668  chi = chi_min;
5669  }
5670  }
5671 
5672  else {
5673  for (j = 0; j < size; j++) {
5674  working_space[shift + j] = working_space[4 * shift + j] + alpha * working_space[2 * shift + j]; //xk[j]=temp_xk[j]+pi*alpha*der[j]
5675  }
5676  for (i = 0, j = 0; i < fNPeaks; i++) {
5677  if (fFixAmp[i] == false) {
5678  if (working_space[shift + j] < 0) //xk[j]
5679  working_space[shift + j] = 0; //xk[j]
5680  working_space[7 * i] = working_space[shift + j]; //parameter[7*i]=xk[j]
5681  j += 1;
5682  }
5683  if (fFixPositionX[i] == false) {
5684  if (working_space[shift + j] < fXmin) //xk[j]
5685  working_space[shift + j] = fXmin; //xk[j]
5686  if (working_space[shift + j] > fXmax) //xk[j]
5687  working_space[shift + j] = fXmax; //xk[j]
5688  working_space[7 * i + 1] = working_space[shift + j]; //parameter[7*i+1]=xk[j]
5689  j += 1;
5690  }
5691  if (fFixPositionY[i] == false) {
5692  if (working_space[shift + j] < fYmin) //xk[j]
5693  working_space[shift + j] = fYmin; //xk[j]
5694  if (working_space[shift + j] > fYmax) //xk[j]
5695  working_space[shift + j] = fYmax; //xk[j]
5696  working_space[7 * i + 2] = working_space[shift + j]; //parameter[7*i+2]=xk[j]
5697  j += 1;
5698  }
5699  if (fFixAmpX1[i] == false) {
5700  if (working_space[shift + j] < 0) //xk[j]
5701  working_space[shift + j] = 0; //xk[j]
5702  working_space[7 * i + 3] = working_space[shift + j]; //parameter[7*i+3]=xk[j]
5703  j += 1;
5704  }
5705  if (fFixAmpY1[i] == false) {
5706  if (working_space[shift + j] < 0) //xk[j]
5707  working_space[shift + j] = 0; //xk[j]
5708  working_space[7 * i + 4] = working_space[shift + j]; //parameter[7*i+4]=xk[j]
5709  j += 1;
5710  }
5711  if (fFixPositionX1[i] == false) {
5712  if (working_space[shift + j] < fXmin) //xk[j]
5713  working_space[shift + j] = fXmin; //xk[j]
5714  if (working_space[shift + j] > fXmax) //xk[j]
5715  working_space[shift + j] = fXmax; //xk[j]
5716  working_space[7 * i + 5] = working_space[shift + j]; //parameter[7*i+5]=xk[j]
5717  j += 1;
5718  }
5719  if (fFixPositionY1[i] == false) {
5720  if (working_space[shift + j] < fYmin) //xk[j]
5721  working_space[shift + j] = fYmin; //xk[j]
5722  if (working_space[shift + j] > fYmax) //xk[j]
5723  working_space[shift + j] = fYmax; //xk[j]
5724  working_space[7 * i + 6] = working_space[shift + j]; //parameter[7*i+6]=xk[j]
5725  j += 1;
5726  }
5727  }
5728  if (fFixSigmaX == false) {
5729  if (working_space[shift + j] < 0.001) { //xk[j]
5730  working_space[shift + j] = 0.001; //xk[j]
5731  }
5732  working_space[peak_vel] = working_space[shift + j]; //parameter[peak_vel]=xk[j]
5733  j += 1;
5734  }
5735  if (fFixSigmaY == false) {
5736  if (working_space[shift + j] < 0.001) { //xk[j]
5737  working_space[shift + j] = 0.001; //xk[j]
5738  }
5739  working_space[peak_vel + 1] = working_space[shift + j]; //parameter[peak_vel+1]=xk[j]
5740  j += 1;
5741  }
5742  if (fFixRo == false) {
5743  if (working_space[shift + j] < -1) { //xk[j]
5744  working_space[shift + j] = -1; //xk[j]
5745  }
5746  if (working_space[shift + j] > 1) { //xk[j]
5747  working_space[shift + j] = 1; //xk[j]
5748  }
5749  working_space[peak_vel + 2] = working_space[shift + j]; //parameter[peak_vel+2]=xk[j]
5750  j += 1;
5751  }
5752  if (fFixA0 == false) {
5753  working_space[peak_vel + 3] = working_space[shift + j]; //parameter[peak_vel+3]=xk[j]
5754  j += 1;
5755  }
5756  if (fFixAx == false) {
5757  working_space[peak_vel + 4] = working_space[shift + j]; //parameter[peak_vel+4]=xk[j]
5758  j += 1;
5759  }
5760  if (fFixAy == false) {
5761  working_space[peak_vel + 5] = working_space[shift + j]; //parameter[peak_vel+5]=xk[j]
5762  j += 1;
5763  }
5764  if (fFixTxy == false) {
5765  working_space[peak_vel + 6] = working_space[shift + j]; //parameter[peak_vel+6]=xk[j]
5766  j += 1;
5767  }
5768  if (fFixSxy == false) {
5769  working_space[peak_vel + 7] = working_space[shift + j]; //parameter[peak_vel+7]=xk[j]
5770  j += 1;
5771  }
5772  if (fFixTx == false) {
5773  working_space[peak_vel + 8] = working_space[shift + j]; //parameter[peak_vel+8]=xk[j]
5774  j += 1;
5775  }
5776  if (fFixTy == false) {
5777  working_space[peak_vel + 9] = working_space[shift + j]; //parameter[peak_vel+9]=xk[j]
5778  j += 1;
5779  }
5780  if (fFixSx == false) {
5781  working_space[peak_vel + 10] = working_space[shift + j]; //parameter[peak_vel+10]=xk[j]
5782  j += 1;
5783  }
5784  if (fFixSy == false) {
5785  working_space[peak_vel + 11] = working_space[shift + j]; //parameter[peak_vel+11]=xk[j]
5786  j += 1;
5787  }
5788  if (fFixBx == false) {
5789  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
5790  if (working_space[shift + j] < 0) //xk[j]
5791  working_space[shift + j] = -0.001; //xk[j]
5792  else
5793  working_space[shift + j] = 0.001; //xk[j]
5794  }
5795  working_space[peak_vel + 12] = working_space[shift + j]; //parameter[peak_vel+12]=xk[j]
5796  j += 1;
5797  }
5798  if (fFixBy == false) {
5799  if (TMath::Abs(working_space[shift + j]) < 0.001) { //xk[j]
5800  if (working_space[shift + j] < 0) //xk[j]
5801  working_space[shift + j] = -0.001; //xk[j]
5802  else
5803  working_space[shift + j] = 0.001; //xk[j]
5804  }
5805  working_space[peak_vel + 13] = working_space[shift + j]; //parameter[peak_vel+13]=xk[j]
5806  j += 1;
5807  }
5808  chi = 0;
5809  for (i1 = fXmin; i1 <= fXmax; i1++) {
5810  for (i2 = fYmin; i2 <= fYmax; i2++) {
5811  yw = source[i1][i2];
5812  ywm = yw;
5813  f = Shape2(fNPeaks, i1, i2,
5814  working_space, working_space[peak_vel],
5815  working_space[peak_vel + 1],
5816  working_space[peak_vel + 2],
5817  working_space[peak_vel + 3],
5818  working_space[peak_vel + 4],
5819  working_space[peak_vel + 5],
5820  working_space[peak_vel + 6],
5821  working_space[peak_vel + 7],
5822  working_space[peak_vel + 8],
5823  working_space[peak_vel + 9],
5824  working_space[peak_vel + 10],
5825  working_space[peak_vel + 11],
5826  working_space[peak_vel + 12],
5827  working_space[peak_vel + 13]);
5829  ywm = f;
5830  if (f < 0.00001)
5831  ywm = 0.00001;
5832  }
5834  if (f > 0.00001)
5835  chi += yw * TMath::Log(f) - f;
5836  }
5837 
5838  else {
5839  if (ywm != 0)
5840  chi += (yw - f) * (yw - f) / ywm;
5841  }
5842  }
5843  }
5844  }
5845  chi2 = chi;
5846  chi = TMath::Sqrt(TMath::Abs(chi));
5847  if (fAlphaOptim == kFitAlphaHalving && chi > 1E-6)
5848  alpha = alpha * chi_opt / (2 * chi);
5849 
5850  else if (fAlphaOptim == kFitAlphaOptimal)
5851  alpha = alpha / 10.0;
5852  iter += 1;
5853  regul_cycle += 1;
5854  } while (((chi > chi_opt
5856  || (chi < chi_opt
5858  && regul_cycle < kFitNumRegulCycles);
5859  for (j = 0; j < size; j++) {
5860  working_space[4 * shift + j] = 0; //temp_xk[j]
5861  working_space[2 * shift + j] = 0; //der[j]
5862  }
5863  for (i1 = fXmin, chi_cel = 0; i1 <= fXmax; i1++) {
5864  for (i2 = fYmin; i2 <= fYmax; i2++) {
5865  yw = source[i1][i2];
5866  if (yw == 0)
5867  yw = 1;
5868  f = Shape2(fNPeaks, i1, i2,
5869  working_space, working_space[peak_vel],
5870  working_space[peak_vel + 1],
5871  working_space[peak_vel + 2],
5872  working_space[peak_vel + 3],
5873  working_space[peak_vel + 4],
5874  working_space[peak_vel + 5],
5875  working_space[peak_vel + 6],
5876  working_space[peak_vel + 7],
5877  working_space[peak_vel + 8],
5878  working_space[peak_vel + 9],
5879  working_space[peak_vel + 10],
5880  working_space[peak_vel + 11],
5881  working_space[peak_vel + 12],
5882  working_space[peak_vel + 13]);
5883  chi_opt = (yw - f) * (yw - f) / yw;
5884  chi_cel += (yw - f) * (yw - f) / yw;
5885 
5886  //calculate gradient vector
5887  for (j = 0, k = 0; j < fNPeaks; j++) {
5888  if (fFixAmp[j] == false) {
5889  a = Deramp2(i1, i2,
5890  working_space[7 * j + 1],
5891  working_space[7 * j + 2],
5892  working_space[peak_vel],
5893  working_space[peak_vel + 1],
5894  working_space[peak_vel + 2],
5895  working_space[peak_vel + 6],
5896  working_space[peak_vel + 7],
5897  working_space[peak_vel + 12],
5898  working_space[peak_vel + 13]);
5899  if (yw != 0) {
5900  working_space[2 * shift + k] += chi_opt; //der[k]
5901  b = a * a / yw;
5902  working_space[4 * shift + k] += b; //temp_xk[k]
5903  }
5904  k += 1;
5905  }
5906  if (fFixPositionX[j] == false) {
5907  a = Deri02(i1, i2,
5908  working_space[7 * j],
5909  working_space[7 * j + 1],
5910  working_space[7 * j + 2],
5911  working_space[peak_vel],
5912  working_space[peak_vel + 1],
5913  working_space[peak_vel + 2],
5914  working_space[peak_vel + 6],
5915  working_space[peak_vel + 7],
5916  working_space[peak_vel + 12],
5917  working_space[peak_vel + 13]);
5918  if (yw != 0) {
5919  working_space[2 * shift + k] += chi_opt; //der[k]
5920  b = a * a / yw;
5921  working_space[4 * shift + k] += b; //temp_xk[k]
5922  }
5923  k += 1;
5924  }
5925  if (fFixPositionY[j] == false) {
5926  a = Derj02(i1, i2,
5927  working_space[7 * j],
5928  working_space[7 * j + 1],
5929  working_space[7 * j + 2],
5930  working_space[peak_vel],
5931  working_space[peak_vel + 1],
5932  working_space[peak_vel + 2],
5933  working_space[peak_vel + 6],
5934  working_space[peak_vel + 7],
5935  working_space[peak_vel + 12],
5936  working_space[peak_vel + 13]);
5937  if (yw != 0) {
5938  working_space[2 * shift + k] += chi_opt; //der[k]
5939  b = a * a / yw;
5940  working_space[4 * shift + k] += b; //temp_xk[k]
5941  }
5942  k += 1;
5943  }
5944  if (fFixAmpX1[j] == false) {
5945  a = Derampx(i1, working_space[7 * j + 5],
5946  working_space[peak_vel],
5947  working_space[peak_vel + 8],
5948  working_space[peak_vel + 10],
5949  working_space[peak_vel + 12]);
5950  if (yw != 0) {
5951  working_space[2 * shift + k] += chi_opt; //der[k]
5952  b = a * a / yw;
5953  working_space[4 * shift + k] += b; //temp_xk[k]
5954  }
5955  k += 1;
5956  }
5957  if (fFixAmpY1[j] == false) {
5958  a = Derampx(i2, working_space[7 * j + 6],
5959  working_space[peak_vel + 1],
5960  working_space[peak_vel + 9],
5961  working_space[peak_vel + 11],
5962  working_space[peak_vel + 13]);
5963  if (yw != 0) {
5964  working_space[2 * shift + k] += chi_opt; //der[k]
5965  b = a * a / yw;
5966  working_space[4 * shift + k] += b; //temp_xk[k]
5967  }
5968  k += 1;
5969  }
5970  if (fFixPositionX1[j] == false) {
5971  a = Deri01(i1, working_space[7 * j + 3],
5972  working_space[7 * j + 5],
5973  working_space[peak_vel],
5974  working_space[peak_vel + 8],
5975  working_space[peak_vel + 10],
5976  working_space[peak_vel + 12]);
5977  if (yw != 0) {
5978  working_space[2 * shift + k] += chi_opt; //der[k]
5979  b = a * a / yw;
5980  working_space[4 * shift + k] += b; //temp_xk[k]
5981  }
5982  k += 1;
5983  }
5984  if (fFixPositionY1[j] == false) {
5985  a = Deri01(i2, working_space[7 * j + 4],
5986  working_space[7 * j + 6],
5987  working_space[peak_vel + 1],
5988  working_space[peak_vel + 9],
5989  working_space[peak_vel + 11],
5990  working_space[peak_vel + 13]);
5991  if (yw != 0) {
5992  working_space[2 * shift + k] += chi_opt; //der[k]
5993  b = a * a / yw;
5994  working_space[4 * shift + k] += b; //temp_xk[k]
5995  }
5996  k += 1;
5997  }
5998  }
5999  if (fFixSigmaX == false) {
6000  a = Dersigmax(fNPeaks, i1, i2,
6001  working_space, working_space[peak_vel],
6002  working_space[peak_vel + 1],
6003  working_space[peak_vel + 2],
6004  working_space[peak_vel + 6],
6005  working_space[peak_vel + 7],
6006  working_space[peak_vel + 8],
6007  working_space[peak_vel + 10],
6008  working_space[peak_vel + 12],
6009  working_space[peak_vel + 13]);
6010  if (yw != 0) {
6011  working_space[2 * shift + k] += chi_opt; //der[k]
6012  b = a * a / yw;
6013  working_space[4 * shift + k] += b; //temp_xk[k]
6014  }
6015  k += 1;
6016  }
6017  if (fFixSigmaY == false) {
6018  a = Dersigmay(fNPeaks, i1, i2,
6019  working_space, working_space[peak_vel],
6020  working_space[peak_vel + 1],
6021  working_space[peak_vel + 2],
6022  working_space[peak_vel + 6],
6023  working_space[peak_vel + 7],
6024  working_space[peak_vel + 9],
6025  working_space[peak_vel + 11],
6026  working_space[peak_vel + 12],
6027  working_space[peak_vel + 13]);
6028  if (yw != 0) {
6029  working_space[2 * shift + k] += chi_opt; //der[k]
6030  b = a * a / yw;
6031  working_space[4 * shift + k] += b; //temp_xk[k]
6032  }
6033  k += 1;
6034  }
6035  if (fFixRo == false) {
6036  a = Derro(fNPeaks, i1, i2,
6037  working_space, working_space[peak_vel],
6038  working_space[peak_vel + 1],
6039  working_space[peak_vel + 2]);
6040  if (yw != 0) {
6041  working_space[2 * shift + k] += chi_opt; //der[k]
6042  b = a * a / yw;
6043  working_space[4 * shift + k] += b; //temp_xk[k]
6044  }
6045  k += 1;
6046  }
6047  if (fFixA0 == false) {
6048  a = 1.;
6049  if (yw != 0) {
6050  working_space[2 * shift + k] += chi_opt; //der[k]
6051  b = a * a / yw;
6052  working_space[4 * shift + k] += b; //temp_xk[k]
6053  }
6054  k += 1;
6055  }
6056  if (fFixAx == false) {
6057  a = i1;
6058  if (yw != 0) {
6059  working_space[2 * shift + k] += chi_opt; //der[k]
6060  b = a * a / yw;
6061  working_space[4 * shift + k] += b; //temp_xk[k]
6062  }
6063  k += 1;
6064  }
6065  if (fFixAy == false) {
6066  a = i2;
6067  if (yw != 0) {
6068  working_space[2 * shift + k] += chi_opt; //der[k]
6069  b = a * a / yw;
6070  working_space[4 * shift + k] += b; //temp_xk[k]
6071  }
6072  k += 1;
6073  }
6074  if (fFixTxy == false) {
6075  a = Dertxy(fNPeaks, i1, i2,
6076  working_space, working_space[peak_vel],
6077  working_space[peak_vel + 1],
6078  working_space[peak_vel + 12],
6079  working_space[peak_vel + 13]);
6080  if (yw != 0) {
6081  working_space[2 * shift + k] += chi_opt; //der[k]
6082  b = a * a / yw;
6083  working_space[4 * shift + k] += b; //temp_xk[k]
6084  }
6085  k += 1;
6086  }
6087  if (fFixSxy == false) {
6088  a = Dersxy(fNPeaks, i1, i2,
6089  working_space, working_space[peak_vel],
6090  working_space[peak_vel + 1]);
6091  if (yw != 0) {
6092  working_space[2 * shift + k] += chi_opt; //der[k]
6093  b = a * a / yw;
6094  working_space[4 * shift + k] += b; //temp_xk[k]
6095  }
6096  k += 1;
6097  }
6098  if (fFixTx == false) {
6099  a = Dertx(fNPeaks, i1, working_space,
6100  working_space[peak_vel],
6101  working_space[peak_vel + 12]);
6102  if (yw != 0) {
6103  working_space[2 * shift + k] += chi_opt; //der[k]
6104  b = a * a / yw;
6105  working_space[4 * shift + k] += b; //temp_xk[k]
6106  }
6107  k += 1;
6108  }
6109  if (fFixTy == false) {
6110  a = Derty(fNPeaks, i2, working_space,
6111  working_space[peak_vel + 1],
6112  working_space[peak_vel + 13]);
6113  if (yw != 0) {
6114  working_space[2 * shift + k] += chi_opt; //der[k]
6115  b = a * a / yw;
6116  working_space[4 * shift + k] += b; //temp_xk[k]
6117  }
6118  k += 1;
6119  }
6120  if (fFixSx == false) {
6121  a = Dersx(fNPeaks, i1, working_space,
6122  working_space[peak_vel]);
6123  if (yw != 0) {
6124  working_space[2 * shift + k] += chi_opt; //der[k]
6125  b = a * a / yw;
6126  working_space[4 * shift + k] += b; //temp_xk[k]
6127  }
6128  k += 1;
6129  }
6130  if (fFixSy == false) {
6131  a = Dersy(fNPeaks, i2, working_space,
6132  working_space[peak_vel + 1]);
6133  if (yw != 0) {
6134  working_space[2 * shift + k] += chi_opt; //der[k]
6135  b = a * a / yw;
6136  working_space[4 * shift + k] += b; //temp_xk[k]
6137  }
6138  k += 1;
6139  }
6140  if (fFixBx == false) {
6141  a = Derbx(fNPeaks, i1, i2,
6142  working_space, working_space[peak_vel],
6143  working_space[peak_vel + 1],
6144  working_space[peak_vel + 6],
6145  working_space[peak_vel + 8],
6146  working_space[peak_vel + 12],
6147  working_space[peak_vel + 13]);
6148  if (yw != 0) {
6149  working_space[2 * shift + k] += chi_opt; //der[k]
6150  b = a * a / yw;
6151  working_space[4 * shift + k] += b; //temp_xk[k]
6152  }
6153  k += 1;
6154  }
6155  if (fFixBy == false) {
6156  a = Derby(fNPeaks, i1, i2,
6157  working_space, working_space[peak_vel],
6158  working_space[peak_vel + 1],
6159  working_space[peak_vel + 6],
6160  working_space[peak_vel + 8],
6161  working_space[peak_vel + 12],
6162  working_space[peak_vel + 13]);
6163  if (yw != 0) {
6164  working_space[2 * shift + k] += chi_opt; //der[k]
6165  b = a * a / yw;
6166  working_space[4 * shift + k] += b; //temp_xk[k]
6167  }
6168  k += 1;
6169  }
6170  }
6171  }
6172  }
6173  b = (fXmax - fXmin + 1) * (fYmax - fYmin + 1) - size;
6174  chi_er = chi_cel / b;
6175  for (i = 0, j = 0; i < fNPeaks; i++) {
6176  fVolume[i] =
6177  Volume(working_space[7 * i], working_space[peak_vel],
6178  working_space[peak_vel + 1], working_space[peak_vel + 2]);
6179  if (fVolume[i] > 0) {
6180  c = 0;
6181  if (fFixAmp[i] == false) {
6182  a = Derpa2(working_space[peak_vel],
6183  working_space[peak_vel + 1],
6184  working_space[peak_vel + 2]);
6185  b = working_space[4 * shift + j]; //temp_xk[j]
6186  if (b == 0)
6187  b = 1;
6188 
6189  else
6190  b = 1 / b;
6191  c = c + a * a * b;
6192  }
6193  if (fFixSigmaX == false) {
6194  a = Derpsigmax(working_space[shift + j],
6195  working_space[peak_vel + 1],
6196  working_space[peak_vel + 2]);
6197  b = working_space[4 * shift + peak_vel]; //temp_xk[j]
6198  if (b == 0)
6199  b = 1;
6200 
6201  else
6202  b = 1 / b;
6203  c = c + a * a * b;
6204  }
6205  if (fFixSigmaY == false) {
6206  a = Derpsigmay(working_space[shift + j],
6207  working_space[peak_vel],
6208  working_space[peak_vel + 2]);
6209  b = working_space[4 * shift + peak_vel + 1]; //temp_xk[j]
6210  if (b == 0)
6211  b = 1;
6212 
6213  else
6214  b = 1 / b;
6215  c = c + a * a * b;
6216  }
6217  if (fFixRo == false) {
6218  a = Derpro(working_space[shift + j], working_space[peak_vel],
6219  working_space[peak_vel + 1],
6220  working_space[peak_vel + 2]);
6221  b = working_space[4 * shift + peak_vel + 2]; //temp_xk[j]
6222  if (b == 0)
6223  b = 1;
6224 
6225  else
6226  b = 1 / b;
6227  c = c + a * a * b;
6228  }
6229  fVolumeErr[i] = TMath::Sqrt(TMath::Abs(chi_er * c));
6230  }
6231 
6232  else {
6233  fVolumeErr[i] = 0;
6234  }
6235  if (fFixAmp[i] == false) {
6236  fAmpCalc[i] = working_space[shift + j]; //xk[j]
6237  if (working_space[3 * shift + j] != 0)
6238  fAmpErr[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6239  j += 1;
6240  }
6241 
6242  else {
6243  fAmpCalc[i] = fAmpInit[i];
6244  fAmpErr[i] = 0;
6245  }
6246  if (fFixPositionX[i] == false) {
6247  fPositionCalcX[i] = working_space[shift + j]; //xk[j]
6248  if (working_space[3 * shift + j] != 0)
6249  fPositionErrX[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6250  j += 1;
6251  }
6252 
6253  else {
6255  fPositionErrX[i] = 0;
6256  }
6257  if (fFixPositionY[i] == false) {
6258  fPositionCalcY[i] = working_space[shift + j]; //xk[j]
6259  if (working_space[3 * shift + j] != 0)
6260  fPositionErrY[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6261  j += 1;
6262  }
6263 
6264  else {
6266  fPositionErrY[i] = 0;
6267  }
6268  if (fFixAmpX1[i] == false) {
6269  fAmpCalcX1[i] = working_space[shift + j]; //xk[j]
6270  if (working_space[3 * shift + j] != 0)
6271  fAmpErrX1[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6272  j += 1;
6273  }
6274 
6275  else {
6276  fAmpCalcX1[i] = fAmpInitX1[i];
6277  fAmpErrX1[i] = 0;
6278  }
6279  if (fFixAmpY1[i] == false) {
6280  fAmpCalcY1[i] = working_space[shift + j]; //xk[j]
6281  if (working_space[3 * shift + j] != 0)
6282  fAmpErrY1[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6283  j += 1;
6284  }
6285 
6286  else {
6287  fAmpCalcY1[i] = fAmpInitY1[i];
6288  fAmpErrY1[i] = 0;
6289  }
6290  if (fFixPositionX1[i] == false) {
6291  fPositionCalcX1[i] = working_space[shift + j]; //xk[j]
6292  if (working_space[3 * shift + j] != 0)
6293  fPositionErrX1[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6294  j += 1;
6295  }
6296 
6297  else {
6299  fPositionErrX1[i] = 0;
6300  }
6301  if (fFixPositionY1[i] == false) {
6302  fPositionCalcY1[i] = working_space[shift + j]; //xk[j]
6303  if (working_space[3 * shift + j] != 0)
6304  fPositionErrY1[i] = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6305  j += 1;
6306  }
6307 
6308  else {
6310  fPositionErrY1[i] = 0;
6311  }
6312  }
6313  if (fFixSigmaX == false) {
6314  fSigmaCalcX = working_space[shift + j]; //xk[j]
6315  if (working_space[3 * shift + j] != 0) //temp[j]
6316  fSigmaErrX = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6317  j += 1;
6318  }
6319 
6320  else {
6322  fSigmaErrX = 0;
6323  }
6324  if (fFixSigmaY == false) {
6325  fSigmaCalcY = working_space[shift + j]; //xk[j]
6326  if (working_space[3 * shift + j] != 0) //temp[j]
6327  fSigmaErrY = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6328  j += 1;
6329  }
6330 
6331  else {
6333  fSigmaErrY = 0;
6334  }
6335  if (fFixRo == false) {
6336  fRoCalc = working_space[shift + j]; //xk[j]
6337  if (working_space[3 * shift + j] != 0) //temp[j]
6338  fRoErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6339  j += 1;
6340  }
6341 
6342  else {
6343  fRoCalc = fRoInit;
6344  fRoErr = 0;
6345  }
6346  if (fFixA0 == false) {
6347  fA0Calc = working_space[shift + j]; //xk[j]
6348  if (working_space[3 * shift + j] != 0) //temp[j]
6349  fA0Err = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6350  j += 1;
6351  }
6352 
6353  else {
6354  fA0Calc = fA0Init;
6355  fA0Err = 0;
6356  }
6357  if (fFixAx == false) {
6358  fAxCalc = working_space[shift + j]; //xk[j]
6359  if (working_space[3 * shift + j] != 0) //temp[j]
6360  fAxErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6361  j += 1;
6362  }
6363 
6364  else {
6365  fAxCalc = fAxInit;
6366  fAxErr = 0;
6367  }
6368  if (fFixAy == false) {
6369  fAyCalc = working_space[shift + j]; //xk[j]
6370  if (working_space[3 * shift + j] != 0) //temp[j]
6371  fAyErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6372  j += 1;
6373  }
6374 
6375  else {
6376  fAyCalc = fAyInit;
6377  fAyErr = 0;
6378  }
6379  if (fFixTxy == false) {
6380  fTxyCalc = working_space[shift + j]; //xk[j]
6381  if (working_space[3 * shift + j] != 0) //temp[j]
6382  fTxyErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6383  j += 1;
6384  }
6385 
6386  else {
6387  fTxyCalc = fTxyInit;
6388  fTxyErr = 0;
6389  }
6390  if (fFixSxy == false) {
6391  fSxyCalc = working_space[shift + j]; //xk[j]
6392  if (working_space[3 * shift + j] != 0) //temp[j]
6393  fSxyErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6394  j += 1;
6395  }
6396 
6397  else {
6398  fSxyCalc = fSxyInit;
6399  fSxyErr = 0;
6400  }
6401  if (fFixTx == false) {
6402  fTxCalc = working_space[shift + j]; //xk[j]
6403  if (working_space[3 * shift + j] != 0) //temp[j]
6404  fTxErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6405  j += 1;
6406  }
6407 
6408  else {
6409  fTxCalc = fTxInit;
6410  fTxErr = 0;
6411  }
6412  if (fFixTy == false) {
6413  fTyCalc = working_space[shift + j]; //xk[j]
6414  if (working_space[3 * shift + j] != 0) //temp[j]
6415  fTyErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6416  j += 1;
6417  }
6418 
6419  else {
6420  fTyCalc = fTyInit;
6421  fTyErr = 0;
6422  }
6423  if (fFixSx == false) {
6424  fSxCalc = working_space[shift + j]; //xk[j]
6425  if (working_space[3 * shift + j] != 0) //temp[j]
6426  fSxErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6427  j += 1;
6428  }
6429 
6430  else {
6431  fSxCalc = fSxInit;
6432  fSxErr = 0;
6433  }
6434  if (fFixSy == false) {
6435  fSyCalc = working_space[shift + j]; //xk[j]
6436  if (working_space[3 * shift + j] != 0) //temp[j]
6437  fSyErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6438  j += 1;
6439  }
6440 
6441  else {
6442  fSyCalc = fSyInit;
6443  fSyErr = 0;
6444  }
6445  if (fFixBx == false) {
6446  fBxCalc = working_space[shift + j]; //xk[j]
6447  if (working_space[3 * shift + j] != 0) //temp[j]
6448  fBxErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6449  j += 1;
6450  }
6451 
6452  else {
6453  fBxCalc = fBxInit;
6454  fBxErr = 0;
6455  }
6456  if (fFixBy == false) {
6457  fByCalc = working_space[shift + j]; //xk[j]
6458  if (working_space[3 * shift + j] != 0) //temp[j]
6459  fByErr = TMath::Sqrt(TMath::Abs(working_space[2 * shift + j])) / TMath::Sqrt(TMath::Abs(working_space[3 * shift + j])); //der[j]/temp[j]
6460  j += 1;
6461  }
6462 
6463  else {
6464  fByCalc = fByInit;
6465  fByErr = 0;
6466  }
6467  b = (fXmax - fXmin + 1) * (fYmax - fYmin + 1) - size;
6468  fChi = chi_cel / b;
6469  for (i1 = fXmin; i1 <= fXmax; i1++) {
6470  for (i2 = fYmin; i2 <= fYmax; i2++) {
6471  f = Shape2(fNPeaks, i1, i2,
6472  working_space, working_space[peak_vel],
6473  working_space[peak_vel + 1],
6474  working_space[peak_vel + 2],
6475  working_space[peak_vel + 3],
6476  working_space[peak_vel + 4],
6477  working_space[peak_vel + 5],
6478  working_space[peak_vel + 6],
6479  working_space[peak_vel + 7],
6480  working_space[peak_vel + 8],
6481  working_space[peak_vel + 9],
6482  working_space[peak_vel + 10],
6483  working_space[peak_vel + 11],
6484  working_space[peak_vel + 12],
6485  working_space[peak_vel + 13]);
6486  source[i1][i2] = f;
6487 
6488  }
6489  }
6490  for (i = 0; i < size; i++) delete [] working_matrix[i];
6491  delete [] working_matrix;
6492  delete [] working_space;
6493  return;
6494 }
6495 
6496 void TSpectrum2Fit::SetFitParameters(Int_t xmin,Int_t xmax,Int_t ymin,Int_t ymax, Int_t numberIterations, Double_t alpha, Int_t statisticType, Int_t alphaOptim, Int_t power, Int_t fitTaylor)
6497 {
6498 //////////////////////////////////////////////////////////////////////////////
6499 // SETTER FUNCTION
6500 //
6501 // This function sets the following fitting parameters:
6502 // -xmin, xmax, ymin, ymax - fitting region
6503 // -numberIterations - # of desired iterations in the fit
6504 // -alpha - convergence coefficient, it should be positive number and <=1, for details see references
6505 // -statisticType - type of statistics, possible values kFitOptimChiCounts (chi square statistics with counts as weighting coefficients), kFitOptimChiFuncValues (chi square statistics with function values as weighting coefficients),kFitOptimMaxLikelihood
6506 // -alphaOptim - optimization of convergence algorithm, possible values kFitAlphaHalving, kFitAlphaOptimal
6507 // -power - possible values kFitPower2,4,6,8,10,12, for details see references. It applies only for Awmi fitting function.
6508 // -fitTaylor - order of Taylor expansion, possible values kFitTaylorOrderFirst, kFitTaylorOrderSecond. It applies only for Awmi fitting function.
6509 //////////////////////////////////////////////////////////////////////////////
6510 
6511  if(xmin<0 || xmax <= xmin || ymin<0 || ymax <= ymin){
6512  Error("SetFitParameters", "Wrong range");
6513  return;
6514  }
6515  if (numberIterations <= 0){
6516  Error("SetFitParameters","Invalid number of iterations, must be positive");
6517  return;
6518  }
6519  if (alpha <= 0 || alpha > 1){
6520  Error ("SetFitParameters","Invalid step coefficient alpha, must be > than 0 and <=1");
6521  return;
6522  }
6523  if (statisticType != kFitOptimChiCounts
6524  && statisticType != kFitOptimChiFuncValues
6525  && statisticType != kFitOptimMaxLikelihood){
6526  Error("SetFitParameters","Wrong type of statistic");
6527  return;
6528  }
6529  if (alphaOptim != kFitAlphaHalving
6530  && alphaOptim != kFitAlphaOptimal){
6531  Error("SetFitParameters","Wrong optimization algorithm");
6532  return;
6533  }
6534  if (power != kFitPower2 && power != kFitPower4
6535  && power != kFitPower6 && power != kFitPower8
6536  && power != kFitPower10 && power != kFitPower12){
6537  Error("SetFitParameters","Wrong power");
6538  return;
6539  }
6540  if (fitTaylor != kFitTaylorOrderFirst
6541  && fitTaylor != kFitTaylorOrderSecond){
6542  Error("SetFitParameters","Wrong order of Taylor development");
6543  return;
6544  }
6545  fXmin=xmin,fXmax=xmax,fYmin=ymin,fYmax=ymax,fNumberIterations=numberIterations,fAlpha=alpha,fStatisticType=statisticType,fAlphaOptim=alphaOptim,fPower=power,fFitTaylor=fitTaylor;
6546 }
6547 
6548 ////////////////////////////////////////////////////////////////////////////////
6549 ///////////////////////////////////////////////////////////////////////////////
6550 /// SETTER FUNCTION
6551 ///
6552 /// This function sets the following fitting parameters of peaks:
6553 /// -sigmaX - initial value of sigma x parameter
6554 /// -fixSigmaX - logical value of sigma x parameter, which allows to fix the parameter (not to fit)
6555 /// -sigmaY - initial value of sigma y parameter
6556 /// -fixSigmaY - logical value of sigma y parameter, which allows to fix the parameter (not to fit)
6557 /// -ro - initial value of ro parameter (correlation coefficient)
6558 /// -fixRo - logical value of ro parameter, which allows to fix the parameter (not to fit)
6559 /// -positionInitX - aray of initial values of peaks x positions
6560 /// -fixPositionX - array of logical values which allow to fix appropriate x positions (not fit). However they are present in the estimated functional.
6561 /// -positionInitY - aray of initial values of peaks y positions
6562 /// -fixPositionY - array of logical values which allow to fix appropriate y positions (not fit). However they are present in the estimated functional.
6563 /// -ampInit - aray of initial values of 2D peaks amplitudes
6564 /// -fixAmp - aray of logical values which allow to fix appropriate amplitudes of 2D peaks (not fit). However they are present in the estimated functional
6565 /// -ampInitX1 - aray of initial values of amplitudes of 1D ridges in x direction
6566 /// -fixAmpX1 - aray of logical values which allow to fix appropriate amplitudes of 1D ridges in x direction (not fit). However they are present in the estimated functional
6567 /// -ampInitY1 - aray of initial values of amplitudes of 1D ridges in y direction
6568 /// -fixAmpY1 - aray of logical values which allow to fix appropriate amplitudes of 1D ridges in y direction (not fit). However they are present in the estimated functional
6569 ///////////////////////////////////////////////////////////////////////////////
6570 
6571 void TSpectrum2Fit::SetPeakParameters(Double_t sigmaX, Bool_t fixSigmaX, Double_t sigmaY, Bool_t fixSigmaY, Double_t ro, Bool_t fixRo, const Double_t *positionInitX, const Bool_t *fixPositionX, const Double_t *positionInitY, const Bool_t *fixPositionY, const Double_t *positionInitX1, const Bool_t *fixPositionX1, const Double_t *positionInitY1, const Bool_t *fixPositionY1, const Double_t *ampInit, const Bool_t *fixAmp, const Double_t *ampInitX1, const Bool_t *fixAmpX1, const Double_t *ampInitY1, const Bool_t *fixAmpY1)
6572 {
6573  if (sigmaX <= 0 || sigmaY <= 0){
6574  Error ("SetPeakParameters","Invalid sigma, must be > than 0");
6575  return;
6576  }
6577  if (ro < -1 || ro > 1){
6578  Error ("SetPeakParameters","Invalid ro, must be from region <-1,1>");
6579  return;
6580  }
6581  Int_t i;
6582  for(i=0; i < fNPeaks; i++){
6583  if(positionInitX[i] < fXmin || positionInitX[i] > fXmax){
6584  Error ("SetPeakParameters","Invalid peak position, must be in the range fXmin, fXmax");
6585  return;
6586  }
6587  if(positionInitY[i] < fYmin || positionInitY[i] > fYmax){
6588  Error ("SetPeakParameters","Invalid peak position, must be in the range fYmin, fYmax");
6589  return;
6590  }
6591  if(positionInitX1[i] < fXmin || positionInitX1[i] > fXmax){
6592  Error ("SetPeakParameters","Invalid ridge position, must be in the range fXmin, fXmax");
6593  return;
6594  }
6595  if(positionInitY1[i] < fYmin || positionInitY1[i] > fYmax){
6596  Error ("SetPeakParameters","Invalid ridge position, must be in the range fYmin, fYmax");
6597  return;
6598  }
6599  if(ampInit[i] < 0){
6600  Error ("SetPeakParameters","Invalid peak amplitude, must be > than 0");
6601  return;
6602  }
6603  if(ampInitX1[i] < 0){
6604  Error ("SetPeakParameters","Invalid x ridge amplitude, must be > than 0");
6605  return;
6606  }
6607  if(ampInitY1[i] < 0){
6608  Error ("SetPeakParameters","Invalid y ridge amplitude, must be > than 0");
6609  return;
6610  }
6611  }
6612  fSigmaInitX = sigmaX, fFixSigmaX = fixSigmaX, fSigmaInitY = sigmaY, fFixSigmaY = fixSigmaY, fRoInit = ro, fFixRo = fixRo;
6613  for(i=0; i < fNPeaks; i++){
6614  fPositionInitX[i] = positionInitX[i];
6615  fFixPositionX[i] = fixPositionX[i];
6616  fPositionInitY[i] = positionInitY[i];
6617  fFixPositionY[i] = fixPositionY[i];
6618  fPositionInitX1[i] = positionInitX1[i];
6619  fFixPositionX1[i] = fixPositionX1[i];
6620  fPositionInitY1[i] = positionInitY1[i];
6621  fFixPositionY1[i] = fixPositionY1[i];
6622  fAmpInit[i] = ampInit[i];
6623  fFixAmp[i] = fixAmp[i];
6624  fAmpInitX1[i] = ampInitX1[i];
6625  fFixAmpX1[i] = fixAmpX1[i];
6626  fAmpInitY1[i] = ampInitY1[i];
6627  fFixAmpY1[i] = fixAmpY1[i];
6628  }
6629 }
6630 
6631 ////////////////////////////////////////////////////////////////////////////////
6632 ///////////////////////////////////////////////////////////////////////////////
6633 /// SETTER FUNCTION
6634 ///
6635 /// This function sets the following fitting parameters of background:
6636 /// -a0Init - initial value of a0 parameter (backgroud is estimated as a0+ax*x+ay*y)
6637 /// -fixA0 - logical value of a0 parameter, which allows to fix the parameter (not to fit)
6638 /// -axInit - initial value of ax parameter
6639 /// -fixAx - logical value of ax parameter, which allows to fix the parameter (not to fit)
6640 /// -ayInit - initial value of ay parameter
6641 /// -fixAy - logical value of ay parameter, which allows to fix the parameter (not to fit)
6642 ///////////////////////////////////////////////////////////////////////////////
6643 
6644 void TSpectrum2Fit::SetBackgroundParameters(Double_t a0Init, Bool_t fixA0, Double_t axInit, Bool_t fixAx, Double_t ayInit, Bool_t fixAy)
6645 {
6646  fA0Init = a0Init;
6647  fFixA0 = fixA0;
6648  fAxInit = axInit;
6649  fFixAx = fixAx;
6650  fAyInit = ayInit;
6651  fFixAy = fixAy;
6652 }
6653 
6654 ////////////////////////////////////////////////////////////////////////////////
6655 ///////////////////////////////////////////////////////////////////////////////
6656 /// SETTER FUNCTION
6657 ///
6658 /// This function sets the following fitting parameters of tails of peaks
6659 /// -tInitXY - initial value of txy parameter
6660 /// -fixTxy - logical value of txy parameter, which allows to fix the parameter (not to fit)
6661 /// -tInitX - initial value of tx parameter
6662 /// -fixTx - logical value of tx parameter, which allows to fix the parameter (not to fit)
6663 /// -tInitY - initial value of ty parameter
6664 /// -fixTy - logical value of ty parameter, which allows to fix the parameter (not to fit)
6665 /// -bInitX - initial value of bx parameter
6666 /// -fixBx - logical value of bx parameter, which allows to fix the parameter (not to fit)
6667 /// -bInitY - initial value of by parameter
6668 /// -fixBy - logical value of by parameter, which allows to fix the parameter (not to fit)
6669 /// -sInitXY - initial value of sxy parameter
6670 /// -fixSxy - logical value of sxy parameter, which allows to fix the parameter (not to fit)
6671 /// -sInitX - initial value of sx parameter
6672 /// -fixSx - logical value of sx parameter, which allows to fix the parameter (not to fit)
6673 /// -sInitY - initial value of sy parameter
6674 /// -fixSy - logical value of sy parameter, which allows to fix the parameter (not to fit)
6675 ///////////////////////////////////////////////////////////////////////////////
6676 
6677 void TSpectrum2Fit::SetTailParameters(Double_t tInitXY, Bool_t fixTxy, Double_t tInitX, Bool_t fixTx, Double_t tInitY, Bool_t fixTy, Double_t bInitX, Bool_t fixBx, Double_t bInitY, Bool_t fixBy, Double_t sInitXY, Bool_t fixSxy, Double_t sInitX, Bool_t fixSx, Double_t sInitY, Bool_t fixSy)
6678 {
6679  fTxyInit = tInitXY;
6680  fFixTxy = fixTxy;
6681  fTxInit = tInitX;
6682  fFixTx = fixTx;
6683  fTyInit = tInitY;
6684  fFixTy = fixTy;
6685  fBxInit = bInitX;
6686  fFixBx = fixBx;
6687  fByInit = bInitY;
6688  fFixBy = fixBy;
6689  fSxyInit = sInitXY;
6690  fFixSxy = fixSxy;
6691  fSxInit = sInitX;
6692  fFixSx = fixSx;
6693  fSyInit = sInitY;
6694  fFixSy = fixSy;
6695 }
6696 
6697 ////////////////////////////////////////////////////////////////////////////////
6698 ///////////////////////////////////////////////////////////////////////////////
6699 /// GETTER FUNCTION
6700 ///
6701 /// This function gets the positions of fitted 2D peaks and 1D ridges
6702 /// -positionX - gets vector of x positions of 2D peaks
6703 /// -positionY - gets vector of y positions of 2D peaks
6704 /// -positionX1 - gets vector of x positions of 1D ridges
6705 /// -positionY1 - gets vector of y positions of 1D ridges
6706 ///////////////////////////////////////////////////////////////////////////////
6707 
6708 void TSpectrum2Fit::GetPositions(Double_t *positionsX, Double_t *positionsY, Double_t *positionsX1, Double_t *positionsY1)
6709 {
6710  for( Int_t i=0; i < fNPeaks; i++){
6711  positionsX[i] = fPositionCalcX[i];
6712  positionsY[i] = fPositionCalcY[i];
6713  positionsX1[i] = fPositionCalcX1[i];
6714  positionsY1[i] = fPositionCalcY1[i];
6715  }
6716 }
6717 
6718 ////////////////////////////////////////////////////////////////////////////////
6719 ///////////////////////////////////////////////////////////////////////////////
6720 /// GETTER FUNCTION
6721 ///
6722 /// This function gets the errors of positions of fitted 2D peaks and 1D ridges
6723 /// -positionErrorsX - gets vector of errors of x positions of 2D peaks
6724 /// -positionErrorsY - gets vector of errors of y positions of 2D peaks
6725 /// -positionErrorsX1 - gets vector of errors of x positions of 1D ridges
6726 /// -positionErrorsY1 - gets vector of errors of y positions of 1D ridges
6727 ///////////////////////////////////////////////////////////////////////////////
6728 
6729 void TSpectrum2Fit::GetPositionErrors(Double_t *positionErrorsX, Double_t *positionErrorsY, Double_t *positionErrorsX1, Double_t *positionErrorsY1)
6730 {
6731  for( Int_t i=0; i < fNPeaks; i++){
6732  positionErrorsX[i] = fPositionErrX[i];
6733  positionErrorsY[i] = fPositionErrY[i];
6734  positionErrorsX1[i] = fPositionErrX1[i];
6735  positionErrorsY1[i] = fPositionErrY1[i];
6736  }
6737 }
6738 
6739 ////////////////////////////////////////////////////////////////////////////////
6740 ///////////////////////////////////////////////////////////////////////////////
6741 /// GETTER FUNCTION
6742 ///
6743 /// This function gets the amplitudes of fitted 2D peaks and 1D ridges
6744 /// -amplitudes - gets vector of amplitudes of 2D peaks
6745 /// -amplitudesX1 - gets vector of amplitudes of 1D ridges in x direction
6746 /// -amplitudesY1 - gets vector of amplitudes of 1D ridges in y direction
6747 ///////////////////////////////////////////////////////////////////////////////
6748 
6749 void TSpectrum2Fit::GetAmplitudes(Double_t *amplitudes, Double_t *amplitudesX1, Double_t *amplitudesY1)
6750 {
6751  for( Int_t i=0; i < fNPeaks; i++){
6752  amplitudes[i] = fAmpCalc[i];
6753  amplitudesX1[i] = fAmpCalcX1[i];
6754  amplitudesY1[i] = fAmpCalcY1[i];
6755  }
6756 }
6757 
6758 ////////////////////////////////////////////////////////////////////////////////
6759 ///////////////////////////////////////////////////////////////////////////////
6760 /// GETTER FUNCTION
6761 ///
6762 /// This function gets the amplitudes of fitted 2D peaks and 1D ridges
6763 /// -amplitudeErrors - gets vector of amplitudes errors of 2D peaks
6764 /// -amplitudeErrorsX1 - gets vector of amplitudes errors of 1D ridges in x direction
6765 /// -amplitudesErrorY1 - gets vector of amplitudes errors of 1D ridges in y direction
6766 ///////////////////////////////////////////////////////////////////////////////
6767 
6768 void TSpectrum2Fit::GetAmplitudeErrors(Double_t *amplitudeErrors, Double_t *amplitudeErrorsX1, Double_t *amplitudeErrorsY1)
6769 {
6770  for( Int_t i=0; i < fNPeaks; i++){
6771  amplitudeErrors[i] = fAmpErr[i];
6772  amplitudeErrorsX1[i] = fAmpErrX1[i];
6773  amplitudeErrorsY1[i] = fAmpErrY1[i];
6774  }
6775 }
6776 
6777 ////////////////////////////////////////////////////////////////////////////////
6778 ///////////////////////////////////////////////////////////////////////////////
6779 /// GETTER FUNCTION
6780 ///
6781 /// This function gets the volumes of fitted 2D peaks
6782 /// -volumes - gets vector of volumes of 2D peaks
6783 ///////////////////////////////////////////////////////////////////////////////
6784 
6786 {
6787  for( Int_t i=0; i < fNPeaks; i++){
6788  volumes[i] = fVolume[i];
6789  }
6790 }
6791 
6792 ////////////////////////////////////////////////////////////////////////////////
6793 ///////////////////////////////////////////////////////////////////////////////
6794 /// GETTER FUNCTION
6795 ///
6796 /// This function gets errors of the volumes of fitted 2D peaks
6797 /// -volumeErrors - gets vector of volumes errors of 2D peaks
6798 ///////////////////////////////////////////////////////////////////////////////
6799 
6801 {
6802  for( Int_t i=0; i < fNPeaks; i++){
6803  volumeErrors[i] = fVolumeErr[i];
6804  }
6805 }
6806 
6807 ////////////////////////////////////////////////////////////////////////////////
6808 ///////////////////////////////////////////////////////////////////////////////
6809 /// GETTER FUNCTION
6810 ///
6811 /// This function gets the sigma x parameter and its error
6812 /// -sigmaX - gets the fitted value of sigma x parameter
6813 /// -sigmaErrX - gets error value of sigma x parameter
6814 ///////////////////////////////////////////////////////////////////////////////
6815 
6816 void TSpectrum2Fit::GetSigmaX(Double_t &sigmaX, Double_t &sigmaErrX)
6817 {
6818  sigmaX=fSigmaCalcX;
6819  sigmaErrX=fSigmaErrX;
6820 }
6821 
6822 ////////////////////////////////////////////////////////////////////////////////
6823 ///////////////////////////////////////////////////////////////////////////////
6824 /// GETTER FUNCTION
6825 ///
6826 /// This function gets the sigma y parameter and its error
6827 /// -sigmaY - gets the fitted value of sigma y parameter
6828 /// -sigmaErrY - gets error value of sigma y parameter
6829 ///////////////////////////////////////////////////////////////////////////////
6830 
6831 void TSpectrum2Fit::GetSigmaY(Double_t &sigmaY, Double_t &sigmaErrY)
6832 {
6833  sigmaY=fSigmaCalcY;
6834  sigmaErrY=fSigmaErrY;
6835 }
6836 
6837 ////////////////////////////////////////////////////////////////////////////////
6838 ///////////////////////////////////////////////////////////////////////////////
6839 /// GETTER FUNCTION
6840 ///
6841 /// This function gets the ro parameter and its error
6842 /// -ro - gets the fitted value of ro parameter
6843 /// -roErr - gets error value of ro parameter
6844 ///////////////////////////////////////////////////////////////////////////////
6845 
6847 {
6848  ro=fRoCalc;
6849  roErr=fRoErr;
6850 }
6851 
6852 ////////////////////////////////////////////////////////////////////////////////
6853 ///////////////////////////////////////////////////////////////////////////////
6854 /// GETTER FUNCTION
6855 ///
6856 /// This function gets the background parameters and their errors
6857 /// -a0 - gets the fitted value of a0 parameter
6858 /// -a0Err - gets error value of a0 parameter
6859 /// -ax - gets the fitted value of ax parameter
6860 /// -axErr - gets error value of ax parameter
6861 /// -ay - gets the fitted value of ay parameter
6862 /// -ayErr - gets error value of ay parameter
6863 ///////////////////////////////////////////////////////////////////////////////
6864 
6866 {
6867  a0 = fA0Calc;
6868  a0Err = fA0Err;
6869  ax = fAxCalc;
6870  axErr = fAxErr;
6871  ay = fAyCalc;
6872  ayErr = fAyErr;
6873 }
6874 
6875 ////////////////////////////////////////////////////////////////////////////////
6876 ///////////////////////////////////////////////////////////////////////////////
6877 /// GETTER FUNCTION
6878 ///
6879 /// This function gets the tail parameters and their errors
6880 /// -txy - gets the fitted value of txy parameter
6881 /// -txyErr - gets error value of txy parameter
6882 /// -tx - gets the fitted value of tx parameter
6883 /// -txErr - gets error value of tx parameter
6884 /// -ty - gets the fitted value of ty parameter
6885 /// -tyErr - gets error value of ty parameter
6886 /// -bx - gets the fitted value of bx parameter
6887 /// -bxErr - gets error value of bx parameter
6888 /// -by - gets the fitted value of by parameter
6889 /// -byErr - gets error value of by parameter
6890 /// -sxy - gets the fitted value of sxy parameter
6891 /// -sxyErr - gets error value of sxy parameter
6892 /// -sx - gets the fitted value of sx parameter
6893 /// -sxErr - gets error value of sx parameter
6894 /// -sy - gets the fitted value of sy parameter
6895 /// -syErr - gets error value of sy parameter
6896 ///////////////////////////////////////////////////////////////////////////////
6897 
6898 void TSpectrum2Fit::GetTailParameters(Double_t &txy, Double_t &txyErr, Double_t &tx, Double_t &txErr, Double_t &ty, Double_t &tyErr, Double_t &bx, Double_t &bxErr, Double_t &by, Double_t &byErr, Double_t &sxy, Double_t &sxyErr, Double_t &sx, Double_t &sxErr, Double_t &sy, Double_t &syErr)
6899 {
6900  txy = fTxyCalc;
6901  txyErr = fTxyErr;
6902  tx = fTxCalc;
6903  txErr = fTxErr;
6904  ty = fTyCalc;
6905  tyErr = fTyErr;
6906  bx = fBxCalc;
6907  bxErr = fBxErr;
6908  by = fByCalc;
6909  byErr = fByErr;
6910  sxy = fSxyCalc;
6911  sxyErr = fSxyErr;
6912  sx = fSxCalc;
6913  sxErr = fSxErr;
6914  sy = fSyCalc;
6915  syErr = fSyErr;
6916 }
6917 
Bool_t * fFixAmp
Double_t Derpsigmay(Double_t a, Double_t sx, Double_t ro)
AUXILIARY FUNCTION // // This function calculates derivative of the volume of a peak // according to ...
Double_t Derpa2(Double_t sx, Double_t sy, Double_t ro)
AUXILIARY FUNCTION // // This function calculates derivative of the volume of a peak // according to ...
Double_t fByCalc
Definition: TSpectrum2Fit.h:98
Double_t Derampx(Double_t x, Double_t x0, Double_t sigmax, Double_t tx, Double_t sx, Double_t bx)
AUXILIARY FUNCTION // // This function calculates derivative of 2D peaks shape function (see manual) ...
Double_t Dersigmay(Int_t numOfFittedPeaks, Double_t x, Double_t y, const Double_t *parameter, Double_t sigmax, Double_t sigmay, Double_t ro, Double_t txy, Double_t sxy, Double_t ty, Double_t sy, Double_t bx, Double_t by)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
Double_t * fAmpCalcY1
Definition: TSpectrum2Fit.h:63
float xmin
Definition: THbookFile.cxx:93
Double_t Dertx(Int_t numOfFittedPeaks, Double_t x, const Double_t *parameter, Double_t sigmax, Double_t bx)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
Double_t * fPositionErrY1
Definition: TSpectrum2Fit.h:55
Double_t Deri01(Double_t x, Double_t ax, Double_t x0, Double_t sigmax, Double_t tx, Double_t sx, Double_t bx)
AUXILIARY FUNCTION // // This function calculates derivative of 2D peaks shape function (see manual) ...
Advanced 2-dimentional spectra fitting functions.
Definition: TSpectrum2Fit.h:30
Double_t * fPositionCalcX1
Definition: TSpectrum2Fit.h:51
Bool_t * fFixPositionY1
Bool_t * fFixAmpY1
Double_t Log(Double_t x)
Definition: TMath.h:526
Double_t fAxErr
Double_t fSxInit
Definition: TSpectrum2Fit.h:88
const double pi
Double_t fTxInit
Definition: TSpectrum2Fit.h:82
float ymin
Definition: THbookFile.cxx:93
Double_t * fPositionInitY
Definition: TSpectrum2Fit.h:47
void GetBackgroundParameters(Double_t &a0, Double_t &a0Err, Double_t &ax, Double_t &axErr, Double_t &ay, Double_t &ayErr)
GETTER FUNCTION.
Double_t Derpsigmax(Double_t a, Double_t sy, Double_t ro)
AUXILIARY FUNCTION // // This function calculates derivative of the volume of a peak // according to ...
Bool_t * fFixAmpX1
Double_t fSyErr
Definition: TSpectrum2Fit.h:93
void GetTailParameters(Double_t &txy, Double_t &txyErr, Double_t &tx, Double_t &txErr, Double_t &ty, Double_t &tyErr, Double_t &bx, Double_t &bxErr, Double_t &by, Double_t &byErr, Double_t &sxy, Double_t &sxyErr, Double_t &sx, Double_t &sxErr, Double_t &sy, Double_t &syErr)
GETTER FUNCTION.
Bool_t * fFixPositionX
Double_t fByInit
Definition: TSpectrum2Fit.h:97
Double_t Derfc(Double_t x)
AUXILIARY FUNCTION // // This function calculates derivative of error function of x...
Double_t fA0Init
Double_t Derpro(Double_t a, Double_t sx, Double_t sy, Double_t ro)
AUXILIARY FUNCTION // // This function calculates derivative of the volume of a peak // according to ...
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t Deri02(Double_t x, Double_t y, Double_t a, Double_t x0, Double_t y0, Double_t sigmax, Double_t sigmay, Double_t ro, Double_t txy, Double_t sxy, Double_t bx, Double_t by)
AUXILIARY FUNCTION // // This function calculates derivative of 2D peaks shape function (see manual) ...
TArc * a
Definition: textangle.C:12
Double_t fSigmaCalcY
Definition: TSpectrum2Fit.h:71
Double_t * fPositionCalcY1
Definition: TSpectrum2Fit.h:54
Double_t * fPositionInitY1
Definition: TSpectrum2Fit.h:53
void GetAmplitudes(Double_t *amplitudes, Double_t *amplitudesX1, Double_t *amplitudesY1)
GETTER FUNCTION.
Double_t * fPositionErrY
Definition: TSpectrum2Fit.h:49
Double_t Derty(Int_t numOfFittedPeaks, Double_t x, const Double_t *parameter, Double_t sigmax, Double_t bx)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
TSpectrum2Fit(void)
default constructor
Double_t fTxyErr
Definition: TSpectrum2Fit.h:78
Double_t * fPositionInitX
Definition: TSpectrum2Fit.h:44
void FitStiefel(Double_t **source)
void GetPositions(Double_t *positionsX, Double_t *positionsY, Double_t *positionsX1, Double_t *positionsY1)
GETTER FUNCTION.
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
Double_t Derdersigmay(Int_t numOfFittedPeaks, Double_t x, Double_t y, const Double_t *parameter, Double_t sigmax, Double_t sigmay, Double_t ro)
AUXILIARY FUNCTION // // This function calculates second derivative of peaks shape function // (see m...
Double_t * fAmpCalc
Definition: TSpectrum2Fit.h:57
Double_t fTxErr
Definition: TSpectrum2Fit.h:84
Double_t * fAmpCalcX1
Definition: TSpectrum2Fit.h:60
Double_t Derby(Int_t numOfFittedPeaks, Double_t x, Double_t y, const Double_t *parameter, Double_t sigmax, Double_t sigmay, Double_t txy, Double_t ty, Double_t bx, Double_t by)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
Double_t fSigmaInitY
Definition: TSpectrum2Fit.h:70
Double_t Derderi01(Double_t x, Double_t ax, Double_t x0, Double_t sigmax)
AUXILIARY FUNCTION // // This function calculates second derivative of 2D peaks shape function // (se...
Double_t fAyInit
Double_t fRoErr
Definition: TSpectrum2Fit.h:75
Double_t Dersx(Int_t numOfFittedPeaks, Double_t x, const Double_t *parameter, Double_t sigmax)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
Double_t Shape2(Int_t numOfFittedPeaks, Double_t x, Double_t y, const Double_t *parameter, Double_t sigmax, Double_t sigmay, Double_t ro, Double_t a0, Double_t ax, Double_t ay, Double_t txy, Double_t sxy, Double_t tx, Double_t ty, Double_t sx, Double_t sy, Double_t bx, Double_t by)
AUXILIARY FUNCTION // // This function calculates 2D peaks shape function (see manual) // Function pa...
Double_t fAxCalc
Double_t * fPositionErrX1
Definition: TSpectrum2Fit.h:52
Double_t x[n]
Definition: legend1.C:17
Double_t * fAmpInitX1
Definition: TSpectrum2Fit.h:59
Double_t * fAmpErrY1
Definition: TSpectrum2Fit.h:64
void FitAwmi(Double_t **source)
TWO-DIMENSIONAL FIT FUNCTION ALGORITHM WITHOUT MATRIX INVERSION This function fits the source spectru...
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
Double_t * fAmpInit
Definition: TSpectrum2Fit.h:56
Double_t Deramp2(Double_t x, Double_t y, Double_t x0, Double_t y0, Double_t sigmax, Double_t sigmay, Double_t ro, Double_t txy, Double_t sxy, Double_t bx, Double_t by)
AUXILIARY FUNCTION // // This function calculates derivative of 2D peaks shape function (see manual) ...
Double_t Ourpowl(Double_t a, Int_t pw)
power function
Double_t fSxCalc
Definition: TSpectrum2Fit.h:89
Double_t fSyInit
Definition: TSpectrum2Fit.h:91
Double_t * fAmpErrX1
Definition: TSpectrum2Fit.h:61
Double_t fBxErr
Definition: TSpectrum2Fit.h:96
void GetSigmaX(Double_t &sigmaX, Double_t &sigmaErrX)
GETTER FUNCTION.
void SetBackgroundParameters(Double_t a0Init, Bool_t fixA0, Double_t axInit, Bool_t fixAx, Double_t ayInit, Bool_t fixAy)
SETTER FUNCTION.
float ymax
Definition: THbookFile.cxx:93
void GetVolumes(Double_t *volumes)
GETTER FUNCTION.
Double_t * fPositionCalcY
Definition: TSpectrum2Fit.h:48
void SetPeakParameters(Double_t sigmaX, Bool_t fixSigmaX, Double_t sigmaY, Bool_t fixSigmaY, Double_t ro, Bool_t fixRo, const Double_t *positionInitX, const Bool_t *fixPositionX, const Double_t *positionInitY, const Bool_t *fixPositionY, const Double_t *positionInitX1, const Bool_t *fixPositionX1, const Double_t *positionInitY1, const Bool_t *fixPositionY1, const Double_t *ampInit, const Bool_t *fixAmp, const Double_t *ampInitX1, const Bool_t *fixAmpX1, const Double_t *ampInitY1, const Bool_t *fixAmpY1)
SETTER FUNCTION.
ROOT::R::TRInterface & r
Definition: Object.C:4
Double_t fTxyInit
Definition: TSpectrum2Fit.h:76
Double_t fAyCalc
void GetPositionErrors(Double_t *positionErrorsX, Double_t *positionErrorsY, Double_t *positionErrorsX1, Double_t *positionErrorsY1)
GETTER FUNCTION.
Double_t * fVolumeErr
Definition: TSpectrum2Fit.h:66
unsigned int r1[N_CITIES]
Definition: simanTSP.cxx:321
Int_t fNumberIterations
Definition: TSpectrum2Fit.h:33
Bool_t * fFixPositionX1
Double_t Derj02(Double_t x, Double_t y, Double_t a, Double_t x0, Double_t y0, Double_t sigmax, Double_t sigmay, Double_t ro, Double_t txy, Double_t sxy, Double_t bx, Double_t by)
Double_t fTyCalc
Definition: TSpectrum2Fit.h:86
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
void GetAmplitudeErrors(Double_t *amplitudeErrors, Double_t *amplitudeErrorsX1, Double_t *amplitudeErrorsY1)
GETTER FUNCTION.
Double_t E()
Definition: TMath.h:54
void SetTailParameters(Double_t tInitXY, Bool_t fixTxy, Double_t tInitX, Bool_t fixTx, Double_t tInitY, Bool_t fixTy, Double_t bInitX, Bool_t fixBx, Double_t bInitY, Bool_t fixBy, Double_t sInitXY, Bool_t fixSxy, Double_t sInitX, Bool_t fixSx, Double_t sInitY, Bool_t fixSy)
SETTER FUNCTION.
float xmax
Definition: THbookFile.cxx:93
void GetSigmaY(Double_t &sigmaY, Double_t &sigmaErrY)
GETTER FUNCTION.
Double_t fSxyErr
Definition: TSpectrum2Fit.h:81
void GetRo(Double_t &ro, Double_t &roErr)
GETTER FUNCTION.
Int_t fStatisticType
Definition: TSpectrum2Fit.h:38
Double_t Derdersigmax(Int_t numOfFittedPeaks, Double_t x, Double_t y, const Double_t *parameter, Double_t sigmax, Double_t sigmay, Double_t ro)
AUXILIARY FUNCTION // // This function calculates second derivative of peaks shape function // (see m...
Double_t fByErr
Definition: TSpectrum2Fit.h:99
Double_t Dertxy(Int_t numOfFittedPeaks, Double_t x, Double_t y, const Double_t *parameter, Double_t sigmax, Double_t sigmay, Double_t bx, Double_t by)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
Double_t fA0Calc
Double_t fTxyCalc
Definition: TSpectrum2Fit.h:77
Double_t Derderi02(Double_t x, Double_t y, Double_t a, Double_t x0, Double_t y0, Double_t sigmax, Double_t sigmay, Double_t ro)
AUXILIARY FUNCTION // // This function calculates second derivative of 2D peaks shape function // (se...
void GetVolumeErrors(Double_t *volumeErrors)
GETTER FUNCTION.
Double_t fSigmaCalcX
Definition: TSpectrum2Fit.h:68
Double_t fAyErr
Double_t fTxCalc
Definition: TSpectrum2Fit.h:83
Double_t fSxyCalc
Definition: TSpectrum2Fit.h:80
Double_t fA0Err
#define ClassImp(name)
Definition: Rtypes.h:279
double f(double x)
Double_t * fAmpErr
Definition: TSpectrum2Fit.h:58
double Double_t
Definition: RtypesCore.h:55
Double_t * fVolume
Definition: TSpectrum2Fit.h:65
Double_t fBxInit
Definition: TSpectrum2Fit.h:94
Double_t fSyCalc
Definition: TSpectrum2Fit.h:92
Double_t Derro(Int_t numOfFittedPeaks, Double_t x, Double_t y, const Double_t *parameter, Double_t sx, Double_t sy, Double_t r)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
Bool_t * fFixPositionY
Double_t y[n]
Definition: legend1.C:17
Double_t ey[n]
Definition: legend1.C:17
Double_t Dersxy(Int_t numOfFittedPeaks, Double_t x, Double_t y, const Double_t *parameter, Double_t sigmax, Double_t sigmay)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
Double_t fRoCalc
Definition: TSpectrum2Fit.h:74
Double_t Erfc(Double_t x)
AUXILIARY FUNCTION // // This function calculates error function of x.
Double_t Derderj02(Double_t x, Double_t y, Double_t a, Double_t x0, Double_t y0, Double_t sigmax, Double_t sigmay, Double_t ro)
AUXILIARY FUNCTION // // This function calculates second derivative of 2D peaks shape function // (se...
Double_t * fPositionErrX
Definition: TSpectrum2Fit.h:46
Double_t fSigmaErrX
Definition: TSpectrum2Fit.h:69
void StiefelInversion(Double_t **a, Int_t size)
Double_t * fPositionCalcX
Definition: TSpectrum2Fit.h:45
void SetFitParameters(Int_t xmin, Int_t xmax, Int_t ymin, Int_t ymax, Int_t numberIterations, Double_t alpha, Int_t statisticType, Int_t alphaOptim, Int_t power, Int_t fitTaylor)
Double_t fBxCalc
Definition: TSpectrum2Fit.h:95
Double_t fSigmaInitX
Definition: TSpectrum2Fit.h:67
Double_t fSxyInit
Definition: TSpectrum2Fit.h:79
Double_t fAxInit
Double_t Volume(Double_t a, Double_t sx, Double_t sy, Double_t ro)
AUXILIARY FUNCTION // // This function calculates volume of a peak // Function parameters: // -a-ampl...
Double_t * fPositionInitX1
Definition: TSpectrum2Fit.h:50
Double_t fSigmaErrY
Definition: TSpectrum2Fit.h:72
Double_t fAlpha
Definition: TSpectrum2Fit.h:42
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
virtual ~TSpectrum2Fit()
destructor
Double_t fTyInit
Definition: TSpectrum2Fit.h:85
double exp(double)
Double_t Dersigmax(Int_t numOfFittedPeaks, Double_t x, Double_t y, const Double_t *parameter, Double_t sigmax, Double_t sigmay, Double_t ro, Double_t txy, Double_t sxy, Double_t tx, Double_t sx, Double_t bx, Double_t by)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
Double_t fRoInit
Definition: TSpectrum2Fit.h:73
Double_t fTyErr
Definition: TSpectrum2Fit.h:87
Double_t Derbx(Int_t numOfFittedPeaks, Double_t x, Double_t y, const Double_t *parameter, Double_t sigmax, Double_t sigmay, Double_t txy, Double_t tx, Double_t bx, Double_t by)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
Double_t ex[n]
Definition: legend1.C:17
Double_t * fAmpInitY1
Definition: TSpectrum2Fit.h:62
Double_t fChi
Definition: TSpectrum2Fit.h:43
Double_t fSxErr
Definition: TSpectrum2Fit.h:90
Double_t Dersy(Int_t numOfFittedPeaks, Double_t x, const Double_t *parameter, Double_t sigmax)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...