]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/AliFMDCorrELossFit.h
Small updates
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliFMDCorrELossFit.h
CommitLineData
0bd4b00f 1#ifndef ALIROOT_PWG2_FORWARD_ALIFMDCORRELOSSFIT_H
2#define ALIROOT_PWG2_FORWARD_ALIFMDCORRELOSSFIT_H
3#include <TObject.h>
4#include <TAxis.h>
5#include <TObjArray.h>
6class TF1;
7class TBrowser;
8
7c1a1f1d 9/**
10 * @defgroup pwg2_forward_corr Corrections
11 *
12 * @ingroup pwg2_forward
13 */
0bd4b00f 14/**
15 * Object holding the Energy loss fit 'correction'
16 *
17 * These are generated from Monte-Carlo or real ESDs.
18 *
19 * @ingroup pwg2_forward_corr
20 */
21class AliFMDCorrELossFit : public TObject
22{
23public:
24 /**
25 * POD structure to hold data from fits
26 *
7c1a1f1d 27 * @ingroup pwg2_forward_corr
0bd4b00f 28 */
29 struct ELossFit : public TObject
30 {
31 Int_t fN; // Number of peaks fitted
32 UShort_t fNu; // Number degrees of freedom
33 Double_t fChi2; // Chi square from fit
34 Double_t fC; // Scaling constant
35 Double_t fDelta; // Most probable value
36 Double_t fXi; // Width parameter of Landau
37 Double_t fSigma; // Sigma on folded gaussian
38 Double_t fSigmaN; // Sigma of detector noise
39 Double_t* fA; // [fN] Weights
40 Double_t fEC; // Error on C
41 Double_t fEDelta; // Error on Delta
42 Double_t fEXi; // Error on Xi
43 Double_t fESigma; // Error on sigma
44 Double_t fESigmaN;// Error on sigma (noise)
45 Double_t* fEA; // [fN] Error on weights
46 Int_t fQuality;// Assigned quality
47 UShort_t fDet; // Detector
48 Char_t fRing; // Ring
49 UShort_t fBin; // Eta bin
50
51 static Double_t fgMaxRelError; // Global default max relative error
52 static Double_t fgLeastWeight; // Global default least weight
53 static Double_t fgMaxChi2nu; // Global default maximum reduced chi^2
54 /**
55 * Default constructor
56 *
57 */
58 ELossFit();
59 /**
60 * Construct from a function
61 *
62 * @param quality Quality flag
63 * @param f Function
64 */
65 ELossFit(Int_t quality,const TF1& f);
66 /**
67 * Constructor with full parameter set
68 *
0bd4b00f 69 * @param quality Quality flag
70 * @param n @f$ N@f$ - Number of fitted peaks
71 * @param chi2 @f$ \chi^2 @f$
72 * @param nu @f$ \nu @f$ - number degrees of freedom
7c1a1f1d 73 * @param c @f$ C@f$ - scale constant
0bd4b00f 74 * @param ec @f$ \delta C@f$ - error on @f$ C@f$
7c1a1f1d 75 * @param delta @f$ \Delta@f$ - Most probable value
0bd4b00f 76 * @param edelta @f$ \delta\Delta@f$ - error on @f$\Delta@f$
7c1a1f1d 77 * @param xi @f$ \xi@f$ - width
0bd4b00f 78 * @param exi @f$ \delta\xi@f$ - error on @f$\xi@f$
7c1a1f1d 79 * @param sigma @f$ \sigma@f$ - Width of Gaussian
0bd4b00f 80 * @param esigma @f$ \delta\sigma@f$ - error on @f$\sigma@f$
7c1a1f1d 81 * @param sigman @f$ \sigma_n@f$ - Noise width
0bd4b00f 82 * @param esigman @f$ \delta\sigma_n@f$ - error on @f$\sigma_n@f$
83 * @param a Array of @f$ N-1@f$ weights @f$ a_i@f$ for
84 * @f$ i=2,\ldots@f$
7c1a1f1d 85 * @param ea Array of @f$ N-1@f$ error on the weights @f$ a_i@f$ for
86 * @f$ i=2,\ldots@f$
0bd4b00f 87 */
88 ELossFit(Int_t quality,UShort_t n,
89 Double_t chi2, UShort_t nu,
90 Double_t c, Double_t ec,
91 Double_t delta, Double_t edelta,
92 Double_t xi, Double_t exi,
93 Double_t sigma, Double_t esigma,
94 Double_t sigman, Double_t esigman,
95 Double_t* a, Double_t* ea);
96 /**
97 * Copy constructor
98 *
99 * @param o Object to copy from
100 */
101 ELossFit(const ELossFit& o);
102 /**
103 * Assignment operator
104 *
105 * @param o Object to assign from
106 *
107 * @return Reference to this object
108 */
109 ELossFit& operator=(const ELossFit& o);
110 /**
111 * Destructor
112 */
113 ~ELossFit();
114 /**
115 * @{
116 * @name Access to parameters
117 */
118 /**
119 * @return Number of peaks fitted
120 */
121 Int_t GetN() const { return fN; }
122 /**
123 * @return Number degrees of freedom
124 */
125 UShort_t GetNu() const { return fNu; }
126 /**
127 * @return Chi square from fit
128 */
129 Double_t GetChi2() const { return fChi2; }
130 /**
131 * @return Scaling constant
132 */
133 Double_t GetC() const { return fC; }
134 /**
135 * @return Most probable value
136 */
137 Double_t GetDelta() const { return fDelta; }
138 /**
139 * @return Width parameter of Landau
140 */
141 Double_t GetXi() const { return fXi; }
142 /**
143 * @return Sigma on folded gaussian
144 */
145 Double_t GetSigma() const { return fSigma; }
146 /**
147 * @return Sigma of detector noise
148 */
149 Double_t GetSigmaN() const { return fSigmaN; }
150 /**
151 * @return Weights
152 */
153 Double_t* GetAs() const { return fA; }
154 /**
155 * @return Weights
156 */
157 Double_t GetA(UShort_t i) const;
158 /**
159 * @return Error on C
160 */
161 Double_t GetEC() const { return fEC; }
162 /**
163 * @return Error on Delta
164 */
165 Double_t GetEDelta() const { return fEDelta; }
166 /**
167 * @return Error on Xi
168 */
169 Double_t GetEXi() const { return fEXi; }
170 /**
171 * @return Error on sigma
172 */
173 Double_t GetESigma() const { return fESigma; }
174 /**
175 * @return Error on sigma (noise)
176 */
177 Double_t GetESigmaN() const { return fESigmaN; }
178 /**
179 * @return Error on weights
180 */
181 Double_t* GetEAs() const { return fEA; }
182 /**
183 * @return Error on weights
184 */
185 Double_t GetEA(UShort_t i) const;
186 /**
187 * @return Assigned quality
188 */
189 Int_t GetQuality() const { return fQuality; }
190 /**
191 * @return Detector
192 */
193 UShort_t GetDet() const { return fDet; }
194 /**
195 * @return Ring
196 */
197 Char_t GetRing() const { return fRing; }
198 /**
199 * @return Eta bin
200 */
201 UShort_t GetBin() const { return fBin; }
202 /* @} */
203
204 /**
205 * @{
206 * @name Evaluation
207 */
208 /**
209 * Evaluate
210 * @f[
211 * f_N(x;\Delta,\xi,\sigma') =
212 * \sum_{i=1}^{n} a_i f(x;\Delta_i,\xi_i,\sigma_i')
213 * @f]
214 *
215 * (see AliForwardUtil::NLandauGaus) for the maximum @f$ N @f$
216 * that fulfills the requirements
217 *
218 * @param x Where to evaluate
219 * @param maxN @f$ \max{N}@f$
220 *
221 * @return @f$ f_N(x;\Delta,\xi,\sigma')@f$
222 */
223 Double_t Evaluate(Double_t x,
224 UShort_t maxN=999) const;
225 /**
226 * Evaluate
227 * @f[
228 * f_W(x;\Delta,\xi,\sigma') =
229 * \frac{\sum_{i=1}^{n} i a_i f_i(x;\Delta,\xi,\sigma')}{
230 * f_N(x;\Delta,\xi,\sigma')} =
231 * \frac{\sum_{i=1}^{n} i a_i f(x;\Delta_i,\xi_i,\sigma_i')}{
232 * \sum_{i=1}^{n} a_i f(x;\Delta_i,\xi_i,\sigma_i')}
233 * @f]
234 * where @f$ n@f$ fulfills the requirements (see FindMaxWeight).
235 *
236 * If the denominator is zero, then 1 is returned.
237 *
238 * See also AliForwardUtil::ILandauGaus and AliForwardUtil::NLandauGaus
239 * for more information on the evaluated functions.
240 *
241 * @param x Where to evaluate
242 * @param maxN @f$ \max{N}@f$
243 *
244 * @return @f$ f_W(x;\Delta,\xi,\sigma')@f$.
245 */
246 Double_t EvaluateWeighted(Double_t x,
247 UShort_t maxN=9999) const;
248 /**
249 * Find the maximum weight to use. The maximum weight is the
250 * largest i for which
251 *
252 * - @f$ i \leq \max{N}@f$
253 * - @f$ a_i > \min{a}@f$
254 * - @f$ \delta a_i/a_i > \delta_{max}@f$
255 *
256 * @param maxRelError @f$ \min{a}@f$
257 * @param leastWeight @f$ \delta_{max}@f$
258 * @param maxN @f$ \max{N}@f$
259 *
260 * @return The largest index @f$ i@f$ for which the above
261 * conditions hold. Will never return less than 1.
262 */
263 Int_t FindMaxWeight(Double_t maxRelError=2*fgMaxRelError,
264 Double_t leastWeight=fgLeastWeight,
265 UShort_t maxN=999) const;
266 /* @} */
267 /**
268 * @{
269 * @name TObject Sortable interface
270 */
271 /**
272 * Declare this object as sortable
273 *
274 * @return Always true
275 */
276 Bool_t IsSortable() const { return kTRUE; }
277 /**
278 * Compare to another ELossFit object.
279 *
280 * - +1, if this quality is better (larger) than other objects quality
281 * - -1, if this quality is worse (smaller) than other objects quality
282 * - +1, if this @f$|\chi^2/\nu-1|@f$ is smaller than the same for other
283 * - -1, if this @f$|\chi^2/\nu-1|@f$ is larger than the same for other
284 * - 0 otherwise
285 *
286 * @param o Other object to compare to
287 */
288 Int_t Compare(const TObject* o) const;
289 /* @} */
290 /**
291 * @{
292 * name Auxiliary member functions
293 */
294 /**
295 * Information to standard output
296 *
297 * @param option Not used
298 */
299 void Print(Option_t* option) const; // *MENU*
300 /**
301 * Draw this fit
302 *
303 * @param option Options
304 * - COMP Draw components too
305 */
306 void Draw(Option_t* option="comp"); // *MENU*
307 /**
308 * Browse this object
309 *
310 * @param b Browser
311 */
312 void Browse(TBrowser* b);
313 /**
314 * Get the name of this object
315 *
316 *
317 * @return
318 */
319 const Char_t* GetName() const;
320 /**
321 * Calculate the quality
322 */
323 void CalculateQuality(Double_t maxChi2nu=fgMaxChi2nu,
324 Double_t maxRelError=fgMaxRelError,
325 Double_t leastWeight=fgLeastWeight);
326 /* @} */
327 ClassDef(ELossFit,1); // Result of fit
328 };
329
330 /**
331 * Default constructor
332 */
333 AliFMDCorrELossFit();
334 /**
335 * Copy constructor
336 *
337 * @param o Object to copy from
338 */
339 AliFMDCorrELossFit(const AliFMDCorrELossFit& o);
340 /**
341 * Destructor
342 */
343 virtual ~AliFMDCorrELossFit();
344 /**
345 * Assignment operator
346 *
347 * @param o Object to assign from
348 *
349 * @return Reference to this object
350 */
351 AliFMDCorrELossFit& operator=(const AliFMDCorrELossFit& o);
352
353 /**
354 * @{
355 * @name Set fits
356 */
357 /**
358 * Set the fit parameters from a function
359 *
360 * @param d Detector
361 * @param r Ring
362 * @param eta Eta
363 * @param quality Quality flag
364 * @param f Function from fit
365 */
366 Bool_t SetFit(UShort_t d, Char_t r, Double_t eta, Int_t quality,
367 const TF1& f);
368 /**
369 * Set the fit parameters from a function
370 *
371 * @param d Detector
372 * @param r Ring
373 * @param eta Eta
374 * @param f ELoss fit result - note, the object will take ownership
375 */
376 Bool_t SetFit(UShort_t d, Char_t r, Double_t eta, ELossFit* f);
377 /**
378 * Set the fit parameters from a function
379 *
7c1a1f1d 380 * @param d Detector
381 * @param r Ring
382 * @param etaBin Eta (bin number, 1->nBins)
383 * @param f ELoss fit result - note, the object will take ownership
0bd4b00f 384 */
385 Bool_t SetFit(UShort_t d, Char_t r, Int_t etaBin, ELossFit* f);
386 /**
387 * Set the fit parameters from a function
388 *
389 * @param d Detector number
390 * @param r Ring identifier
7c1a1f1d 391 * @param eta Eta value
0bd4b00f 392 * @param quality Quality flag
393 * @param n @f$ N@f$ - Number of fitted peaks
394 * @param chi2 @f$ \chi^2 @f$
395 * @param nu @f$ \nu @f$ - number degrees of freedom
7c1a1f1d 396 * @param c @f$ C@f$ - scale constant
0bd4b00f 397 * @param ec @f$ \delta C@f$ - error on @f$ C@f$
7c1a1f1d 398 * @param delta @f$ \Delta@f$ - most probable value
0bd4b00f 399 * @param edelta @f$ \delta\Delta@f$ - error on @f$\Delta@f$
7c1a1f1d 400 * @param xi @f$ \xi@f$ - Landau width
0bd4b00f 401 * @param exi @f$ \delta\xi@f$ - error on @f$\xi@f$
7c1a1f1d 402 * @param sigma @f$ \sigma@f$ - Gaussian width
0bd4b00f 403 * @param esigma @f$ \delta\sigma@f$ - error on @f$\sigma@f$
7c1a1f1d 404 * @param sigman @f$ \sigma_n@f$ - Noise width
0bd4b00f 405 * @param esigman @f$ \delta\sigma_n@f$ - error on @f$\sigma_n@f$
406 * @param a Array of @f$ N-1@f$ weights @f$ a_i@f$ for
407 * @f$ i=2,\ldots@f$
7c1a1f1d 408 * @param ea Array of @f$ N-1@f$ errors on weights @f$ a_i@f$ for
409 * @f$ i=2,\ldots@f$
0bd4b00f 410 */
411 Bool_t SetFit(UShort_t d, Char_t r, Double_t eta,
412 Int_t quality,UShort_t n,
413 Double_t chi2, UShort_t nu,
414 Double_t c, Double_t ec,
415 Double_t delta, Double_t edelta,
416 Double_t xi, Double_t exi,
417 Double_t sigma, Double_t esigma,
418 Double_t sigman, Double_t esigman,
419 Double_t* a, Double_t* ea);
420 /* @} */
421
422 /**
423 * @{
424 * @name Set and get eta axis
425 */
426 /**
427 * Set the eta axis to use
428 *
429 * @param axis Eta axis
430 */
431 void SetEtaAxis(const TAxis& axis);
432 /**
433 * Set the eta axis to use
434 *
7c1a1f1d 435 * @param nBins Number of bins
436 * @param min Minimum @f$ \eta@f$
437 * @param max maximum @f$ \eta@f$
0bd4b00f 438 */
439 void SetEtaAxis(Int_t nBins, Double_t min, Double_t max);
440 /**
441 * Get the eta axis used
442 *
443 * @return
444 */
445 const TAxis& GetEtaAxis() const { return fEtaAxis; }
446 /**
447 * Set the low cut used when fitting
448 *
449 * @param cut Cut value
450 */
451 void SetLowCut(Double_t cut) { fLowCut = cut; }
452 /**
453 * Get the low cut used when fitting
454 *
455 * @return Low cut used for fitting
456 */
457 Double_t GetLowCut() const { return fLowCut; }
458 /**
459 * Find the eta bin corresponding to the given eta
460 *
461 * @param eta Eta value
462 *
463 * @return Bin (in @f$[1,N_{bins}]@f$) corresponding to the given
464 * eta, or 0 if out of range.
465 */
466 Int_t FindEtaBin(Double_t eta) const;
467 /* @} */
468
469 /**
470 * @{
471 * @name Find fits
472 */
473 /**
474 * Find the fit corresponding to the specified parameters
475 *
476 * @param d Detector
477 * @param r Ring
478 * @param eta Eta value
479 *
480 * @return Fit parameters or null in case of problems
481 */
482 ELossFit* FindFit(UShort_t d, Char_t r, Double_t eta) const;
483 /**
484 * Find the fit corresponding to the specified parameters
485 *
486 * @param d Detector
487 * @param r Ring
488 * @param etabin Eta bin (1 based)
489 *
490 * @return Fit parameters or null in case of problems
491 */
492 ELossFit* FindFit(UShort_t d, Char_t r, Int_t etabin) const;
493 /* @} */
494
495 /**
496 * @{
497 * @name Miscellaneous
498 */
499 /**
500 * Get the ring array corresponding to the specified ring
501 *
502 * @param d Detector
503 * @param r Ring
504 *
505 * @return Pointer to ring array, or null in case of problems
506 */
507 TObjArray* GetRingArray(UShort_t d, Char_t r) const;
508 /**
509 * Signal that this is a folder
510 *
511 * @return Always true
512 */
513 Bool_t IsFolder() const { return true; }
514 /**
515 * Browse this object
516 *
517 * @param b
518 */
519 void Browse(TBrowser* b);
520 /**
521 * Draw this object
522 *
523 * @param option Options. Possible values are
524 * - err Plot error bars
525 */
526 void Draw(Option_t* option=""); //*MENU*
527 /**
528 * Print this object.
529 *
530 * @param option Options
531 * - R Print recursive
532 *
533 */
534 void Print(Option_t* option="R") const; //*MENU*
535 /* @} */
536protected:
537 /**
538 * Get the ring array corresponding to the specified ring
539 *
540 * @param d Detector
541 * @param r Ring
542 *
543 * @return Pointer to ring array, or newly created container
544 */
545 TObjArray* GetOrMakeRingArray(UShort_t d, Char_t r);
546
547 TObjArray fRings; // Array of rings
548 TAxis fEtaAxis; // Eta axis used
549 Double_t fLowCut; // Low cut used when fitting
550
551 ClassDef(AliFMDCorrELossFit,2);
552};
553
554//____________________________________________________________________
555inline void
556AliFMDCorrELossFit::SetEtaAxis(Int_t nBins, Double_t min, Double_t max)
557{
558 fEtaAxis.Set(nBins, min, max);
559}
560//____________________________________________________________________
561inline void
562AliFMDCorrELossFit::SetEtaAxis(const TAxis& e)
563{
564 fEtaAxis.Set(e.GetNbins(), e.GetXmin(), e.GetXmax());
565}
566//____________________________________________________________________
567inline Double_t
568AliFMDCorrELossFit::ELossFit::GetA(UShort_t i) const
569{
570 if (i < 1) return 0;
571 if (i > fN) return 0;
572 if (i == 1) return 1;
573 return fA[i-2];
574}
575//____________________________________________________________________
576inline Double_t
577AliFMDCorrELossFit::ELossFit::GetEA(UShort_t i) const
578{
579 if (i < 1) return 0;
580 if (i > fN) return 0;
581 if (i == 1) return 1;
582 return fEA[i-2];
583}
584
585
586#endif
587// Local Variables:
588// mode: C++
589// End:
590