1 // Object holding the Energy loss fit 'correction'
3 // These are generated from Monte-Carlo or real ESDs.
4 #ifndef ALIFMDCORRELOSSFIT_H
5 #define ALIFMDCORRELOSSFIT_H
7 * @file AliFMDCorrELossFit.h
8 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
9 * @date Wed Mar 23 14:01:15 2011
13 * @ingroup pwglf_forward_eloss
18 #include <TObjArray.h>
23 * @defgroup pwglf_forward_corr Corrections
25 * Correction objects used
27 * @ingroup pwglf_forward
30 * Object holding the Energy loss fit 'correction'
32 * These are generated from Monte-Carlo or real ESDs.
34 * @ingroup pwglf_forward_corr
35 * @ingroup pwglf_forward_eloss
37 class AliFMDCorrELossFit : public TObject
41 * POD structure to hold data from fits
43 * @ingroup pwglf_forward_corr
45 struct ELossFit : public TObject
47 Int_t fN; // Number of peaks fitted
48 UShort_t fNu; // Number degrees of freedom
49 Double_t fChi2; // Chi square from fit
50 Double_t fC; // Scaling constant
51 Double_t fDelta; // Most probable value
52 Double_t fXi; // Width parameter of Landau
53 Double_t fSigma; // Sigma on folded gaussian
54 Double_t fSigmaN; // Sigma of detector noise
55 Double_t* fA; // [fN] Weights
56 Double_t fEC; // Error on C
57 Double_t fEDelta; // Error on Delta
58 Double_t fEXi; // Error on Xi
59 Double_t fESigma; // Error on sigma
60 Double_t fESigmaN;// Error on sigma (noise)
61 Double_t* fEA; // [fN] Error on weights
62 Int_t fQuality;// Assigned quality
63 UShort_t fDet; // Detector
65 UShort_t fBin; // Eta bin
67 static Double_t fgMaxRelError; // Global default max relative error
68 static Double_t fgLeastWeight; // Global default least weight
69 static Double_t fgMaxChi2nu; // Global default maximum reduced chi^2
76 * Construct from a function
78 * @param quality Quality flag
81 ELossFit(Int_t quality,const TF1& f);
83 * Constructor with full parameter set
85 * @param quality Quality flag
86 * @param n @f$ N@f$ - Number of fitted peaks
87 * @param chi2 @f$ \chi^2 @f$
88 * @param nu @f$ \nu @f$ - number degrees of freedom
89 * @param c @f$ C@f$ - scale constant
90 * @param ec @f$ \delta C@f$ - error on @f$ C@f$
91 * @param delta @f$ \Delta@f$ - Most probable value
92 * @param edelta @f$ \delta\Delta@f$ - error on @f$\Delta@f$
93 * @param xi @f$ \xi@f$ - width
94 * @param exi @f$ \delta\xi@f$ - error on @f$\xi@f$
95 * @param sigma @f$ \sigma@f$ - Width of Gaussian
96 * @param esigma @f$ \delta\sigma@f$ - error on @f$\sigma@f$
97 * @param sigman @f$ \sigma_n@f$ - Noise width
98 * @param esigman @f$ \delta\sigma_n@f$ - error on @f$\sigma_n@f$
99 * @param a Array of @f$ N-1@f$ weights @f$ a_i@f$ for
101 * @param ea Array of @f$ N-1@f$ error on the weights @f$ a_i@f$ for
104 ELossFit(Int_t quality,UShort_t n,
105 Double_t chi2, UShort_t nu,
106 Double_t c, Double_t ec,
107 Double_t delta, Double_t edelta,
108 Double_t xi, Double_t exi,
109 Double_t sigma, Double_t esigma,
110 Double_t sigman, Double_t esigman,
111 const Double_t* a,const Double_t* ea);
115 * @param o Object to copy from
117 ELossFit(const ELossFit& o);
119 * Assignment operator
121 * @param o Object to assign from
123 * @return Reference to this object
125 ELossFit& operator=(const ELossFit& o);
132 * @name Access to parameters
135 * @return Number of peaks fitted
137 Int_t GetN() const { return fN; }
139 * @return Number degrees of freedom
141 UShort_t GetNu() const { return fNu; }
143 * @return Chi square from fit
145 Double_t GetChi2() const { return fChi2; }
147 * @return Scaling constant
149 Double_t GetC() const { return fC; }
151 * @return Most probable value
153 Double_t GetDelta() const { return fDelta; }
155 * @return Width parameter of Landau
157 Double_t GetXi() const { return fXi; }
159 * @return Sigma on folded gaussian
161 Double_t GetSigma() const { return fSigma; }
163 * @return Sigma of detector noise
165 Double_t GetSigmaN() const { return fSigmaN; }
169 Double_t* GetAs() const { return fA; }
171 * @param i Which weight to get
175 Double_t GetA(UShort_t i) const;
179 Double_t GetEC() const { return fEC; }
181 * @return Error on Delta
183 Double_t GetEDelta() const { return fEDelta; }
185 * @return Error on Xi
187 Double_t GetEXi() const { return fEXi; }
189 * @return Error on sigma
191 Double_t GetESigma() const { return fESigma; }
193 * @return Error on sigma (noise)
195 Double_t GetESigmaN() const { return fESigmaN; }
197 * @return Error on weights
199 Double_t* GetEAs() const { return fEA; }
201 * @param i Which weight to get
203 * @return Error on weights
205 Double_t GetEA(UShort_t i) const;
207 * @return Assigned quality
209 Int_t GetQuality() const { return fQuality; }
213 UShort_t GetDet() const { return fDet; }
217 Char_t GetRing() const { return fRing; }
221 UShort_t GetBin() const { return fBin; }
231 * f_N(x;\Delta,\xi,\sigma') =
232 * \sum_{i=1}^{n} a_i f(x;\Delta_i,\xi_i,\sigma_i')
235 * (see AliForwardUtil::NLandauGaus) for the maximum @f$ N @f$
236 * that fulfills the requirements
238 * @param x Where to evaluate
239 * @param maxN @f$ \max{N}@f$
241 * @return @f$ f_N(x;\Delta,\xi,\sigma')@f$
243 Double_t Evaluate(Double_t x,
244 UShort_t maxN=999) const;
248 * f_W(x;\Delta,\xi,\sigma') =
249 * \frac{\sum_{i=1}^{n} i a_i f_i(x;\Delta,\xi,\sigma')}{
250 * f_N(x;\Delta,\xi,\sigma')} =
251 * \frac{\sum_{i=1}^{n} i a_i f(x;\Delta_i,\xi_i,\sigma_i')}{
252 * \sum_{i=1}^{n} a_i f(x;\Delta_i,\xi_i,\sigma_i')}
254 * where @f$ n@f$ fulfills the requirements (see FindMaxWeight).
256 * If the denominator is zero, then 1 is returned.
258 * See also AliForwardUtil::ILandauGaus and AliForwardUtil::NLandauGaus
259 * for more information on the evaluated functions.
261 * @param x Where to evaluate
262 * @param maxN @f$ \max{N}@f$
264 * @return @f$ f_W(x;\Delta,\xi,\sigma')@f$.
266 Double_t EvaluateWeighted(Double_t x,
267 UShort_t maxN=9999) const;
269 * Find the maximum weight to use. The maximum weight is the
270 * largest i for which
272 * - @f$ i \leq \max{N}@f$
273 * - @f$ a_i > \min{a}@f$
274 * - @f$ \delta a_i/a_i > \delta_{max}@f$
276 * @param maxRelError @f$ \min{a}@f$
277 * @param leastWeight @f$ \delta_{max}@f$
278 * @param maxN @f$ \max{N}@f$
280 * @return The largest index @f$ i@f$ for which the above
281 * conditions hold. Will never return less than 1.
283 Int_t FindMaxWeight(Double_t maxRelError=2*fgMaxRelError,
284 Double_t leastWeight=fgLeastWeight,
285 UShort_t maxN=999) const;
289 * @name TObject Sortable interface
292 * Declare this object as sortable
294 * @return Always true
296 Bool_t IsSortable() const { return kTRUE; }
298 * Compare to another ELossFit object.
300 * - +1, if this quality is better (larger) than other objects quality
301 * - -1, if this quality is worse (smaller) than other objects quality
302 * - +1, if this @f$|\chi^2/\nu-1|@f$ is smaller than the same for other
303 * - -1, if this @f$|\chi^2/\nu-1|@f$ is larger than the same for other
306 * @param o Other object to compare to
310 Int_t Compare(const TObject* o) const;
314 * name Auxiliary member functions
317 * Information to standard output
319 * @param option Not used
321 void Print(Option_t* option) const; // *MENU*
325 * @param option Options
326 * - COMP Draw components too
328 void Draw(Option_t* option="comp"); // *MENU*
334 void Browse(TBrowser* b);
336 * Get the name of this object
341 const Char_t* GetName() const;
343 * Calculate the lower bound
345 * @param f Width factor
346 * @param includeSigma Whether to include sigma
348 * @return @f$ \Delta - f (\xi + \sigma)@f$
350 Double_t GetLowerBound(Double_t f, Bool_t includeSigma) const;
352 * Calculate the lower bound
354 * @param f fraction of @f$\Delta@f$
356 * @return @f$ f\Delta@f$
358 Double_t GetLowerBound(Double_t f) const;
360 * Calculate the quality
362 * @param maxChi2nu Maximum reduced @f$\chi^2@f$
363 * @param maxRelError Maximum relative error
364 * @param leastWeight Least weight to use
366 void CalculateQuality(Double_t maxChi2nu=fgMaxChi2nu,
367 Double_t maxRelError=fgMaxRelError,
368 Double_t leastWeight=fgLeastWeight);
370 ClassDef(ELossFit,1); // Result of fit
374 * Default constructor
376 AliFMDCorrELossFit();
380 * @param o Object to copy from
382 AliFMDCorrELossFit(const AliFMDCorrELossFit& o);
386 virtual ~AliFMDCorrELossFit();
388 * Assignment operator
390 * @param o Object to assign from
392 * @return Reference to this object
394 AliFMDCorrELossFit& operator=(const AliFMDCorrELossFit& o);
401 * Set the fit parameters from a function
406 * @param quality Quality flag
407 * @param f Function from fit
409 * @return true on success
411 Bool_t SetFit(UShort_t d, Char_t r, Double_t eta, Int_t quality,
414 * Set the fit parameters from a function
419 * @param f ELoss fit result - note, the object will take ownership
421 * @return true on success
423 Bool_t SetFit(UShort_t d, Char_t r, Double_t eta, ELossFit* f);
425 * Set the fit parameters from a function
429 * @param etaBin Eta (bin number, 1->nBins)
430 * @param f ELoss fit result - note, the object will take ownership
432 * @return true on success
434 Bool_t SetFit(UShort_t d, Char_t r, Int_t etaBin, ELossFit* f);
436 * Set the fit parameters from a function
438 * @param d Detector number
439 * @param r Ring identifier
440 * @param eta Eta value
441 * @param quality Quality flag
442 * @param n @f$ N@f$ - Number of fitted peaks
443 * @param chi2 @f$ \chi^2 @f$
444 * @param nu @f$ \nu @f$ - number degrees of freedom
445 * @param c @f$ C@f$ - scale constant
446 * @param ec @f$ \delta C@f$ - error on @f$ C@f$
447 * @param delta @f$ \Delta@f$ - most probable value
448 * @param edelta @f$ \delta\Delta@f$ - error on @f$\Delta@f$
449 * @param xi @f$ \xi@f$ - Landau width
450 * @param exi @f$ \delta\xi@f$ - error on @f$\xi@f$
451 * @param sigma @f$ \sigma@f$ - Gaussian width
452 * @param esigma @f$ \delta\sigma@f$ - error on @f$\sigma@f$
453 * @param sigman @f$ \sigma_n@f$ - Noise width
454 * @param esigman @f$ \delta\sigma_n@f$ - error on @f$\sigma_n@f$
455 * @param a Array of @f$ N-1@f$ weights @f$ a_i@f$ for
457 * @param ea Array of @f$ N-1@f$ errors on weights @f$ a_i@f$ for
460 * @return true on success
462 Bool_t SetFit(UShort_t d, Char_t r, Double_t eta,
463 Int_t quality,UShort_t n,
464 Double_t chi2, UShort_t nu,
465 Double_t c, Double_t ec,
466 Double_t delta, Double_t edelta,
467 Double_t xi, Double_t exi,
468 Double_t sigma, Double_t esigma,
469 Double_t sigman, Double_t esigman,
470 Double_t* a, Double_t* ea);
475 * @name Set and get eta axis
478 * Set the eta axis to use
480 * @param axis Eta axis
482 void SetEtaAxis(const TAxis& axis);
484 * Set the eta axis to use
486 * @param nBins Number of bins
487 * @param min Minimum @f$ \eta@f$
488 * @param max maximum @f$ \eta@f$
490 void SetEtaAxis(Int_t nBins, Double_t min, Double_t max);
492 * Get the eta axis used
496 const TAxis& GetEtaAxis() const { return fEtaAxis; }
498 * Set the low cut used when fitting
500 * @param cut Cut value
502 void SetLowCut(Double_t cut) { fLowCut = cut; }
504 * Get the low cut used when fitting
506 * @return Low cut used for fitting
508 Double_t GetLowCut() const { return fLowCut; }
510 * Find the eta bin corresponding to the given eta
512 * @param eta Eta value
514 * @return Bin (in @f$[1,N_{bins}]@f$) corresponding to the given
515 * eta, or 0 if out of range.
517 Int_t FindEtaBin(Double_t eta) const;
525 * Find the fit corresponding to the specified parameters
529 * @param eta Eta value
531 * @return Fit parameters or null in case of problems
533 ELossFit* FindFit(UShort_t d, Char_t r, Double_t eta) const;
535 * Find the fit corresponding to the specified parameters
539 * @param etabin Eta bin (1 based)
541 * @return Fit parameters or null in case of problems
543 ELossFit* FindFit(UShort_t d, Char_t r, Int_t etabin) const;
545 * Find the fit corresponding to the specified parameters
549 * @param eta Eta value
551 * @return Fit parameters or null in case of problems
553 ELossFit* GetFit(UShort_t d, Char_t r, Double_t eta) const;
555 * Find the fit corresponding to the specified parameters
559 * @param etabin Eta bin (1 based)
561 * @return Fit parameters or null in case of problems
563 ELossFit* GetFit(UShort_t d, Char_t r, Int_t etabin) const;
568 * @name Lower bounds on fits
571 * Get the lower validity bound of the fit
575 * @param etaBin Eta bin (1-based)
576 * @param f Fraction of @f$\Delta_{mp}@f$
578 * @return @f$ f\Delta_{mp}@f$
580 Double_t GetLowerBound(UShort_t d, Char_t r, Int_t etaBin,
583 * Get the lower validity bound of the fit
587 * @param eta Eta value
588 * @param f Fraction of @f$\Delta_{mp}@f$
590 * @return @f$ f\Delta_{mp}@f$
592 Double_t GetLowerBound(UShort_t d, Char_t r, Double_t eta,
595 * Get the lower validity bound of the fit
599 * @param etaBin Eta bin (1-based)
600 * @param f Factor on xi (and sigma)
601 * @param showErrors Show errors
602 * @param includeSigma Whether to include sigma
604 * @return @f$ \Delta_{mp} - f(\xi+\sigma)@f$
606 Double_t GetLowerBound(UShort_t d, Char_t r, Int_t etaBin,
607 Double_t f, Bool_t showErrors,
608 Bool_t includeSigma) const;
610 * Get the lower validity bound of the fit
614 * @param eta Eta value
615 * @param f Factor on xi (and sigma)
616 * @param showErrors Show errors
617 * @param includeSigma Whether to include sigma
619 * @return @f$ \Delta_{mp} - f(\xi+\sigma)@f$
621 Double_t GetLowerBound(UShort_t d, Char_t r, Double_t eta,
622 Double_t f, Bool_t showErrors,
623 Bool_t includeSigma) const;
628 * @name Miscellaneous
631 * Get the ring array corresponding to the specified ring
636 * @return Pointer to ring array, or null in case of problems
638 TObjArray* GetRingArray(UShort_t d, Char_t r) const;
640 * Signal that this is a folder
642 * @return Always true
644 Bool_t IsFolder() const { return true; }
650 void Browse(TBrowser* b);
654 * @param option Options. Possible values are
655 * - error Plot error bars
656 * - relative Plot relative errors
658 void Draw(Option_t* option=""); //*MENU*
662 * @param option Options
663 * - R Print recursive
666 void Print(Option_t* option="R") const; //*MENU*
668 * Get a list of THStack - one for each parameter
670 * @param err Show errors
671 * @param rel Show relative errors
672 * @param maxN Maximum weight to use
674 * @return List of THStack
676 TList* GetStacks(Bool_t err, Bool_t rel, UShort_t maxN=5) const;
680 * Get the ring array corresponding to the specified ring
685 * @return Pointer to ring array, or newly created container
687 TObjArray* GetOrMakeRingArray(UShort_t d, Char_t r);
689 TObjArray fRings; // Array of rings
690 TAxis fEtaAxis; // Eta axis used
691 Double_t fLowCut; // Low cut used when fitting
693 ClassDef(AliFMDCorrELossFit,2);
696 //____________________________________________________________________
698 AliFMDCorrELossFit::SetEtaAxis(Int_t nBins, Double_t min, Double_t max)
700 fEtaAxis.Set(nBins, min, max);
702 //____________________________________________________________________
704 AliFMDCorrELossFit::SetEtaAxis(const TAxis& e)
706 fEtaAxis.Set(e.GetNbins(), e.GetXmin(), e.GetXmax());
708 //____________________________________________________________________
710 AliFMDCorrELossFit::ELossFit::GetA(UShort_t i) const
713 if (i > fN) return 0;
714 if (i == 1) return 1;
717 //____________________________________________________________________
719 AliFMDCorrELossFit::ELossFit::GetEA(UShort_t i) const
722 if (i > fN) return 0;
723 if (i == 1) return 1;