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