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>
24 * @defgroup pwglf_forward_corr Corrections
26 * Correction objects used
28 * @ingroup pwglf_forward
31 * Object holding the Energy loss fit 'correction'
33 * These are generated from Monte-Carlo or real ESDs.
35 * @ingroup pwglf_forward_corr
36 * @ingroup pwglf_forward_eloss
38 class AliFMDCorrELossFit : public TObject
42 * POD structure to hold data from fits
44 * @ingroup pwglf_forward_corr
46 struct ELossFit : public TObject
48 Int_t fN; // Number of peaks fitted
49 UShort_t fNu; // Number degrees of freedom
50 Double_t fChi2; // Chi square from fit
51 Double_t fC; // Scaling constant
52 Double_t fDelta; // Most probable value
53 Double_t fXi; // Width parameter of Landau
54 Double_t fSigma; // Sigma on folded gaussian
55 Double_t fSigmaN; // Sigma of detector noise
56 Double_t* fA; // [fN] Weights
57 Double_t fEC; // Error on C
58 Double_t fEDelta; // Error on Delta
59 Double_t fEXi; // Error on Xi
60 Double_t fESigma; // Error on sigma
61 Double_t fESigmaN;// Error on sigma (noise)
62 Double_t* fEA; // [fN] Error on weights
63 Int_t fQuality;// Assigned quality
64 UShort_t fDet; // Detector
66 UShort_t fBin; // Eta bin
68 mutable UShort_t fMaxWeight; //!Cached maximum weight
70 static Double_t fgMaxRelError; // Global default max relative error
71 static Double_t fgLeastWeight; // Global default least weight
72 static Double_t fgMaxChi2nu; // Global default maximum reduced chi^2
79 * Construct from a function
81 * @param quality Quality flag
84 ELossFit(Int_t quality,const TF1& f);
86 * Constructor with full parameter set
88 * @param quality Quality flag
89 * @param n @f$ N@f$ - Number of fitted peaks
90 * @param chi2 @f$ \chi^2 @f$
91 * @param nu @f$ \nu @f$ - number degrees of freedom
92 * @param c @f$ C@f$ - scale constant
93 * @param ec @f$ \delta C@f$ - error on @f$ C@f$
94 * @param delta @f$ \Delta@f$ - Most probable value
95 * @param edelta @f$ \delta\Delta@f$ - error on @f$\Delta@f$
96 * @param xi @f$ \xi@f$ - width
97 * @param exi @f$ \delta\xi@f$ - error on @f$\xi@f$
98 * @param sigma @f$ \sigma@f$ - Width of Gaussian
99 * @param esigma @f$ \delta\sigma@f$ - error on @f$\sigma@f$
100 * @param sigman @f$ \sigma_n@f$ - Noise width
101 * @param esigman @f$ \delta\sigma_n@f$ - error on @f$\sigma_n@f$
102 * @param a Array of @f$ N-1@f$ weights @f$ a_i@f$ for
104 * @param ea Array of @f$ N-1@f$ error on the weights @f$ a_i@f$ for
107 ELossFit(Int_t quality,UShort_t n,
108 Double_t chi2, UShort_t nu,
109 Double_t c, Double_t ec,
110 Double_t delta, Double_t edelta,
111 Double_t xi, Double_t exi,
112 Double_t sigma, Double_t esigma,
113 Double_t sigman, Double_t esigman,
114 const Double_t* a,const Double_t* ea);
118 * @param o Object to copy from
120 ELossFit(const ELossFit& o);
122 * Assignment operator
124 * @param o Object to assign from
126 * @return Reference to this object
128 ELossFit& operator=(const ELossFit& o);
135 * @name Access to parameters
138 * @return Number of peaks fitted
140 Int_t GetN() const { return fN; }
142 * @return Number degrees of freedom
144 UShort_t GetNu() const { return fNu; }
146 * @return Chi square from fit
148 Double_t GetChi2() const { return fChi2; }
150 * @return Scaling constant
152 Double_t GetC() const { return fC; }
154 * @return Most probable value
156 Double_t GetDelta() const { return fDelta; }
158 * @return Width parameter of Landau
160 Double_t GetXi() const { return fXi; }
162 * @return Sigma on folded gaussian
164 Double_t GetSigma() const { return fSigma; }
166 * @return Sigma of detector noise
168 Double_t GetSigmaN() const { return fSigmaN; }
172 Double_t* GetAs() const { return fA; }
174 * @param i Which weight to get
178 Double_t GetA(UShort_t i) const;
182 Double_t GetEC() const { return fEC; }
184 * @return Error on Delta
186 Double_t GetEDelta() const { return fEDelta; }
188 * @return Error on Xi
190 Double_t GetEXi() const { return fEXi; }
192 * @return Error on sigma
194 Double_t GetESigma() const { return fESigma; }
196 * @return Error on sigma (noise)
198 Double_t GetESigmaN() const { return fESigmaN; }
200 * @return Error on weights
202 Double_t* GetEAs() const { return fEA; }
204 * @param i Which weight to get
206 * @return Error on weights
208 Double_t GetEA(UShort_t i) const;
210 * @return Assigned quality
212 Int_t GetQuality() const { return fQuality; }
216 UShort_t GetDet() const { return fDet; }
220 Char_t GetRing() const { return fRing; }
224 UShort_t GetBin() const { return fBin; }
234 * f_N(x;\Delta,\xi,\sigma') =
235 * \sum_{i=1}^{n} a_i f(x;\Delta_i,\xi_i,\sigma_i')
238 * (see AliForwardUtil::NLandauGaus) for the maximum @f$ N @f$
239 * that fulfills the requirements
241 * @param x Where to evaluate
242 * @param maxN @f$ \max{N}@f$
244 * @return @f$ f_N(x;\Delta,\xi,\sigma')@f$
246 Double_t Evaluate(Double_t x,
247 UShort_t maxN=999) const;
251 * f_W(x;\Delta,\xi,\sigma') =
252 * \frac{\sum_{i=1}^{n} i a_i f_i(x;\Delta,\xi,\sigma')}{
253 * f_N(x;\Delta,\xi,\sigma')} =
254 * \frac{\sum_{i=1}^{n} i a_i f(x;\Delta_i,\xi_i,\sigma_i')}{
255 * \sum_{i=1}^{n} a_i f(x;\Delta_i,\xi_i,\sigma_i')}
257 * where @f$ n@f$ fulfills the requirements (see FindMaxWeight).
259 * If the denominator is zero, then 1 is returned.
261 * See also AliForwardUtil::ILandauGaus and AliForwardUtil::NLandauGaus
262 * for more information on the evaluated functions.
264 * @param x Where to evaluate
265 * @param maxN @f$ \max{N}@f$
267 * @return @f$ f_W(x;\Delta,\xi,\sigma')@f$.
269 Double_t EvaluateWeighted(Double_t x,
270 UShort_t maxN=9999) const;
272 * Find the maximum weight to use. The maximum weight is the
273 * largest i for which
275 * - @f$ i \leq \max{N}@f$
276 * - @f$ a_i > \min{a}@f$
277 * - @f$ \delta a_i/a_i > \delta_{max}@f$
279 * @param maxRelError @f$ \min{a}@f$
280 * @param leastWeight @f$ \delta_{max}@f$
281 * @param maxN @f$ \max{N}@f$
283 * @return The largest index @f$ i@f$ for which the above
284 * conditions hold. Will never return less than 1.
286 Int_t FindMaxWeight(Double_t maxRelError=2*fgMaxRelError,
287 Double_t leastWeight=fgLeastWeight,
288 UShort_t maxN=999) const;
292 * @name TObject Sortable interface
295 * Declare this object as sortable
297 * @return Always true
299 Bool_t IsSortable() const { return kTRUE; }
301 * Compare to another ELossFit object.
303 * - +1, if this quality is better (larger) than other objects quality
304 * - -1, if this quality is worse (smaller) than other objects quality
305 * - +1, if this @f$|\chi^2/\nu-1|@f$ is smaller than the same for other
306 * - -1, if this @f$|\chi^2/\nu-1|@f$ is larger than the same for other
309 * @param o Other object to compare to
313 Int_t Compare(const TObject* o) const;
317 * name Auxiliary member functions
320 * Information to standard output
322 * @param option Not used
324 void Print(Option_t* option) const; // *MENU*
328 * @param option Options
329 * - COMP Draw components too
331 void Draw(Option_t* option="comp"); // *MENU*
337 void Browse(TBrowser* b);
339 * Get the name of this object
344 const Char_t* GetName() const;
346 * Calculate the lower bound
348 * @param f Width factor
349 * @param includeSigma Whether to include sigma
351 * @return @f$ \Delta - f (\xi + \sigma)@f$
353 Double_t GetLowerBound(Double_t f, Bool_t includeSigma) const;
355 * Calculate the lower bound
357 * @param f fraction of @f$\Delta@f$
359 * @return @f$ f\Delta@f$
361 Double_t GetLowerBound(Double_t f) const;
363 * Calculate the quality
365 * @param maxChi2nu Maximum reduced @f$\chi^2@f$
366 * @param maxRelError Maximum relative error
367 * @param leastWeight Least weight to use
369 void CalculateQuality(Double_t maxChi2nu=fgMaxChi2nu,
370 Double_t maxRelError=fgMaxRelError,
371 Double_t leastWeight=fgLeastWeight);
373 ClassDef(ELossFit,2); // Result of fit
377 * Default constructor
379 AliFMDCorrELossFit();
383 * @param o Object to copy from
385 AliFMDCorrELossFit(const AliFMDCorrELossFit& o);
389 virtual ~AliFMDCorrELossFit();
391 * Assignment operator
393 * @param o Object to assign from
395 * @return Reference to this object
397 AliFMDCorrELossFit& operator=(const AliFMDCorrELossFit& o);
404 * Set the fit parameters from a function
409 * @param quality Quality flag
410 * @param f Function from fit
412 * @return true on success
414 Bool_t SetFit(UShort_t d, Char_t r, Double_t eta, Int_t quality,
417 * Set the fit parameters from a function
422 * @param f ELoss fit result - note, the object will take ownership
424 * @return true on success
426 Bool_t SetFit(UShort_t d, Char_t r, Double_t eta, ELossFit* f);
428 * Set the fit parameters from a function
432 * @param etaBin Eta (bin number, 1->nBins)
433 * @param f ELoss fit result - note, the object will take ownership
435 * @return true on success
437 Bool_t SetFit(UShort_t d, Char_t r, Int_t etaBin, ELossFit* f);
439 * Set the fit parameters from a function
441 * @param d Detector number
442 * @param r Ring identifier
443 * @param eta Eta value
444 * @param quality Quality flag
445 * @param n @f$ N@f$ - Number of fitted peaks
446 * @param chi2 @f$ \chi^2 @f$
447 * @param nu @f$ \nu @f$ - number degrees of freedom
448 * @param c @f$ C@f$ - scale constant
449 * @param ec @f$ \delta C@f$ - error on @f$ C@f$
450 * @param delta @f$ \Delta@f$ - most probable value
451 * @param edelta @f$ \delta\Delta@f$ - error on @f$\Delta@f$
452 * @param xi @f$ \xi@f$ - Landau width
453 * @param exi @f$ \delta\xi@f$ - error on @f$\xi@f$
454 * @param sigma @f$ \sigma@f$ - Gaussian width
455 * @param esigma @f$ \delta\sigma@f$ - error on @f$\sigma@f$
456 * @param sigman @f$ \sigma_n@f$ - Noise width
457 * @param esigman @f$ \delta\sigma_n@f$ - error on @f$\sigma_n@f$
458 * @param a Array of @f$ N-1@f$ weights @f$ a_i@f$ for
460 * @param ea Array of @f$ N-1@f$ errors on weights @f$ a_i@f$ for
463 * @return true on success
465 Bool_t SetFit(UShort_t d, Char_t r, Double_t eta,
466 Int_t quality,UShort_t n,
467 Double_t chi2, UShort_t nu,
468 Double_t c, Double_t ec,
469 Double_t delta, Double_t edelta,
470 Double_t xi, Double_t exi,
471 Double_t sigma, Double_t esigma,
472 Double_t sigman, Double_t esigman,
473 Double_t* a, Double_t* ea);
478 * @name Set and get eta axis
481 * Set the eta axis to use
483 * @param axis Eta axis
485 void SetEtaAxis(const TAxis& axis);
487 * Set the eta axis to use
489 * @param nBins Number of bins
490 * @param min Minimum @f$ \eta@f$
491 * @param max maximum @f$ \eta@f$
493 void SetEtaAxis(Int_t nBins, Double_t min, Double_t max);
495 * Get the eta axis used
499 const TAxis& GetEtaAxis() const { return fEtaAxis; }
501 * Set the low cut used when fitting
503 * @param cut Cut value
505 void SetLowCut(Double_t cut) { fLowCut = cut; }
507 * Get the low cut used when fitting
509 * @return Low cut used for fitting
511 Double_t GetLowCut() const { return fLowCut; }
513 * Find the eta bin corresponding to the given eta
515 * @param eta Eta value
517 * @return Bin (in @f$[1,N_{bins}]@f$) corresponding to the given
518 * eta, or 0 if out of range.
520 Int_t FindEtaBin(Double_t eta) const;
528 * Find the fit corresponding to the specified parameters
532 * @param eta Eta value
533 * @param minQ Minimum quality
535 * @return Fit parameters or null in case of problems
537 ELossFit* FindFit(UShort_t d, Char_t r, Double_t eta,
538 UShort_t minQ) const;
540 * Find the fit corresponding to the specified parameters
544 * @param etabin Eta bin (1 based)
545 * @param minQ Minimum quality
547 * @return Fit parameters or null in case of problems
549 ELossFit* FindFit(UShort_t d, Char_t r, Int_t etabin,
550 UShort_t minQ) const;
552 * Find the fit corresponding to the specified parameters
556 * @param eta Eta value
558 * @return Fit parameters or null in case of problems
560 ELossFit* GetFit(UShort_t d, Char_t r, Double_t eta) const;
562 * Find the fit corresponding to the specified parameters
566 * @param etabin Eta bin (1 based)
568 * @return Fit parameters or null in case of problems
570 ELossFit* GetFit(UShort_t d, Char_t r, Int_t etabin) const;
575 * @name Lower bounds on fits
578 * Get the lower validity bound of the fit
582 * @param etaBin Eta bin (1-based)
583 * @param f Fraction of @f$\Delta_{mp}@f$
585 * @return @f$ f\Delta_{mp}@f$
587 Double_t GetLowerBound(UShort_t d, Char_t r, Int_t etaBin,
590 * Get the lower validity bound of the fit
594 * @param eta Eta value
595 * @param f Fraction of @f$\Delta_{mp}@f$
597 * @return @f$ f\Delta_{mp}@f$
599 Double_t GetLowerBound(UShort_t d, Char_t r, Double_t eta,
602 * Get the lower validity bound of the fit
606 * @param etaBin Eta bin (1-based)
607 * @param f Factor on xi (and sigma)
608 * @param showErrors Show errors
609 * @param includeSigma Whether to include sigma
611 * @return @f$ \Delta_{mp} - f(\xi+\sigma)@f$
613 Double_t GetLowerBound(UShort_t d, Char_t r, Int_t etaBin,
614 Double_t f, Bool_t showErrors,
615 Bool_t includeSigma) const;
617 * Get the lower validity bound of the fit
621 * @param eta Eta value
622 * @param f Factor on xi (and sigma)
623 * @param showErrors Show errors
624 * @param includeSigma Whether to include sigma
626 * @return @f$ \Delta_{mp} - f(\xi+\sigma)@f$
628 Double_t GetLowerBound(UShort_t d, Char_t r, Double_t eta,
629 Double_t f, Bool_t showErrors,
630 Bool_t includeSigma) const;
635 * @name Miscellaneous
637 void CacheBins(UShort_t minQuality) const;
639 * Get the ring array corresponding to the specified ring
644 * @return Pointer to ring array, or null in case of problems
646 TObjArray* GetRingArray(UShort_t d, Char_t r) const;
648 * Signal that this is a folder
650 * @return Always true
652 Bool_t IsFolder() const { return true; }
658 void Browse(TBrowser* b);
662 * @param option Options. Possible values are
663 * - error Plot error bars
664 * - relative Plot relative errors
666 void Draw(Option_t* option=""); //*MENU*
670 * @param option Options
671 * - R Print recursive
674 void Print(Option_t* option="R") const; //*MENU*
676 * Get a list of THStack - one for each parameter
678 * @param err Show errors
679 * @param rel Show relative errors
680 * @param good Only show good fits
681 * @param maxN Maximum weight to use
683 * @return List of THStack
685 TList* GetStacks(Bool_t err, Bool_t rel, Bool_t good, UShort_t maxN=5) const;
689 * Get the ring array corresponding to the specified ring
694 * @return Pointer to ring array, or newly created container
696 TObjArray* GetOrMakeRingArray(UShort_t d, Char_t r);
698 TObjArray fRings; // Array of rings
699 TAxis fEtaAxis; // Eta axis used
700 Double_t fLowCut; // Low cut used when fitting
701 mutable TArrayI fCache;
703 ClassDef(AliFMDCorrELossFit,3);
706 //____________________________________________________________________
708 AliFMDCorrELossFit::SetEtaAxis(Int_t nBins, Double_t min, Double_t max)
710 fEtaAxis.Set(nBins, min, max);
712 //____________________________________________________________________
714 AliFMDCorrELossFit::SetEtaAxis(const TAxis& e)
716 fEtaAxis.Set(e.GetNbins(), e.GetXmin(), e.GetXmax());
718 //____________________________________________________________________
720 AliFMDCorrELossFit::ELossFit::GetA(UShort_t i) const
723 if (i > fN) return 0;
724 if (i == 1) return 1;
727 //____________________________________________________________________
729 AliFMDCorrELossFit::ELossFit::GetEA(UShort_t i) const
732 if (i > fN) return 0;
733 if (i == 1) return 1;