1 // Object holding the Energy loss fit 'correction'
3 // These are generated from Monte-Carlo or real ESDs.
5 #include "AliFMDCorrELossFit.h"
6 #include "AliForwardUtil.h"
9 #include <TVirtualPad.h>
20 Double_t AliFMDCorrELossFit::ELossFit::fgMaxRelError = .25;
21 Double_t AliFMDCorrELossFit::ELossFit::fgLeastWeight = 1e-7;
22 Double_t AliFMDCorrELossFit::ELossFit::fgMaxChi2nu = 20;
24 //____________________________________________________________________
25 AliFMDCorrELossFit::ELossFit::ELossFit()
48 // Default constructor
52 //____________________________________________________________________
53 AliFMDCorrELossFit::ELossFit::ELossFit(Int_t quality, const TF1& f)
54 : fN(f.GetNpar() > AliForwardUtil::ELossFitter::kN ?
55 Int_t(f.GetParameter(AliForwardUtil::ELossFitter::kN)) :
58 fChi2(f.GetChisquare()),
59 fC(f.GetParameter(AliForwardUtil::ELossFitter::kC)),
60 fDelta(f.GetParameter(AliForwardUtil::ELossFitter::kDelta)),
61 fXi(f.GetParameter(AliForwardUtil::ELossFitter::kXi)),
62 fSigma(f.GetParameter(AliForwardUtil::ELossFitter::kSigma)),
63 fSigmaN(f.GetParameter(AliForwardUtil::ELossFitter::kSigmaN)),
65 fEC(f.GetParError(AliForwardUtil::ELossFitter::kC)),
66 fEDelta(f.GetParError(AliForwardUtil::ELossFitter::kDelta)),
67 fEXi(f.GetParError(AliForwardUtil::ELossFitter::kXi)),
68 fESigma(f.GetParError(AliForwardUtil::ELossFitter::kSigma)),
69 fESigmaN(f.GetParError(AliForwardUtil::ELossFitter::kSigmaN)),
78 // Construct from a function
81 // quality Quality flag
85 fA = new Double_t[fN];
86 fEA = new Double_t[fN];
87 for (Int_t i = 0; i < fN-1; i++) {
88 fA[i] = f.GetParameter(AliForwardUtil::ELossFitter::kA+i);
89 fEA[i] = f.GetParError(AliForwardUtil::ELossFitter::kA+i);
95 //____________________________________________________________________
96 AliFMDCorrELossFit::ELossFit::ELossFit(Int_t quality,UShort_t n,
97 Double_t chi2, UShort_t nu,
98 Double_t c, Double_t ec,
99 Double_t delta, Double_t edelta,
100 Double_t xi, Double_t exi,
101 Double_t sigma, Double_t esigma,
102 Double_t sigman, Double_t esigman,
103 const Double_t* a,const Double_t* ea)
126 // Constructor with full parameter set
129 // quality Quality flag
130 // n @f$ N@f$ - Number of fitted peaks
131 // chi2 @f$ \chi^2 @f$
132 // nu @f$ \nu @f$ - number degrees of freedom
133 // c @f$ C@f$ - scale constant
134 // ec @f$ \delta C@f$ - error on @f$ C@f$
135 // delta @f$ \Delta@f$ - Most probable value
136 // edelta @f$ \delta\Delta@f$ - error on @f$\Delta@f$
137 // xi @f$ \xi@f$ - width
138 // exi @f$ \delta\xi@f$ - error on @f$\xi@f$
139 // sigma @f$ \sigma@f$ - Width of Gaussian
140 // esigma @f$ \delta\sigma@f$ - error on @f$\sigma@f$
141 // sigman @f$ \sigma_n@f$ - Noise width
142 // esigman @f$ \delta\sigma_n@f$ - error on @f$\sigma_n@f$
143 // a Array of @f$ N-1@f$ weights @f$ a_i@f$ for
145 // ea Array of @f$ N-1@f$ error on the weights @f$ a_i@f$ for
149 fA = new Double_t[fN];
150 fEA = new Double_t[fN];
151 for (Int_t i = 0; i < fN-1; i++) {
158 //____________________________________________________________________
159 AliFMDCorrELossFit::ELossFit::ELossFit(const ELossFit& o)
174 fESigmaN(o.fESigmaN),
176 fQuality(o.fQuality),
180 fMaxWeight(o.fMaxWeight)
186 // o Object to copy from
189 fA = new Double_t[fN];
190 fEA = new Double_t[fN];
191 for (Int_t i = 0; i < fN-1; i++) {
199 //____________________________________________________________________
200 AliFMDCorrELossFit::ELossFit&
201 AliFMDCorrELossFit::ELossFit::operator=(const ELossFit& o)
204 // Assignment operator
207 // o Object to assign from
210 // Reference to this object
212 if (&o == this) return *this;
225 fESigmaN = o.fESigmaN;
226 fQuality = o.fQuality;
230 fMaxWeight = o.fMaxWeight;
231 if (fA) delete [] fA;
232 if (fEA) delete [] fEA;
236 if (fN <= 0) return *this;
237 fA = new Double_t[fN];
238 fEA = new Double_t[fN];
239 for (Int_t i = 0; i < fN; i++) {
247 //____________________________________________________________________
248 AliFMDCorrELossFit::ELossFit::~ELossFit()
251 if (fEA) delete[] fEA;
255 //____________________________________________________________________
257 AliFMDCorrELossFit::ELossFit::FindMaxWeight(Double_t maxRelError,
258 Double_t leastWeight,
262 // Find the maximum weight to use. The maximum weight is the
263 // largest i for which
265 // - @f$ i \leq \max{N}@f$
266 // - @f$ a_i > \min{a}@f$
267 // - @f$ \delta a_i/a_i > \delta_{max}@f$
270 // maxRelError @f$ \min{a}@f$
271 // leastWeight @f$ \delta_{max}@f$
272 // maxN @f$ \max{N}@f$
275 // The largest index @f$ i@f$ for which the above
276 // conditions hold. Will never return less than 1.
278 if (fMaxWeight > 0) return fMaxWeight;
279 Int_t n = TMath::Min(maxN, UShort_t(fN-1));
281 // fN is one larger than we have data
282 for (Int_t i = 0; i < n-1; i++, m++) {
283 if (fA[i] < leastWeight) break;
284 if (fEA[i] / fA[i] > maxRelError) break;
286 return fMaxWeight = m;
289 //____________________________________________________________________
291 AliFMDCorrELossFit::ELossFit::Evaluate(Double_t x,
297 // f_N(x;\Delta,\xi,\sigma') =
298 // \sum_{i=1}^{n} a_i f(x;\Delta_i,\xi_i,\sigma_i')
301 // (see AliForwardUtil::NLandauGaus) for the maximum @f$ N @f$
302 // that fulfills the requirements
305 // x Where to evaluate
306 // maxN @f$ \max{N}@f$
309 // @f$ f_N(x;\Delta,\xi,\sigma')@f$
311 return AliForwardUtil::NLandauGaus(x, fDelta, fXi, fSigma, fSigmaN,
312 TMath::Min(maxN, UShort_t(fN)), fA);
315 //____________________________________________________________________
317 AliFMDCorrELossFit::ELossFit::EvaluateWeighted(Double_t x,
323 // f_W(x;\Delta,\xi,\sigma') =
324 // \frac{\sum_{i=1}^{n} i a_i f_i(x;\Delta,\xi,\sigma')}{
325 // f_N(x;\Delta,\xi,\sigma')} =
326 // \frac{\sum_{i=1}^{n} i a_i f(x;\Delta_i,\xi_i,\sigma_i')}{
327 // \sum_{i=1}^{n} a_i f(x;\Delta_i,\xi_i,\sigma_i')}
329 // where @f$ n@f$ fulfills the requirements (see FindMaxWeight).
331 // If the denominator is zero, then 1 is returned.
333 // See also AliForwardUtil::ILandauGaus and AliForwardUtil::NLandauGaus
334 // for more information on the evaluated functions.
337 // x Where to evaluate
338 // maxN @f$ \max{N}@f$
341 // @f$ f_W(x;\Delta,\xi,\sigma')@f$.
343 UShort_t n = TMath::Min(maxN, UShort_t(fN-1));
346 for (Int_t i = 1; i <= n; i++) {
347 Double_t a = (i == 1 ? 1 : fA[i-1]);
348 if (fA[i-1] < 0) break;
349 Double_t f = AliForwardUtil::ILandauGaus(x,fDelta,fXi,fSigma,fSigmaN,i);
353 if (den <= 0) return 1;
358 #define OUTPAR(N,V,E) \
359 std::setprecision(9) << \
360 std::setw(12) << N << ": " << \
361 std::setw(14) << V << " +/- " << \
362 std::setw(14) << E << " (" << \
363 std::setprecision(-1) << \
364 std::setw(5) << 100*(V>0?E/V:1) << "%)\n"
367 //____________________________________________________________________
369 AliFMDCorrELossFit::ELossFit::Compare(const TObject* o) const
372 // Compare to another ELossFit object.
374 // - +1, if this quality is better (larger) than other objects quality
375 // - -1, if this quality is worse (smaller) than other objects quality
376 // - +1, if this @f$|\chi^2/\nu-1|@f$ is smaller than the same for other
377 // - -1, if this @f$|\chi^2/\nu-1|@f$ is larger than the same for other
381 // o Other object to compare to
383 const ELossFit* other = static_cast<const ELossFit*>(o);
384 if (this->fQuality < other->fQuality) return -1;
385 if (this->fQuality > other->fQuality) return +1;
386 Double_t chi2nu = (fNu == 0 ? 1000 : fChi2 / fNu);
387 Double_t oChi2nu = (other->fNu == 0 ? 1000 : other->fChi2 / other->fNu);
388 if (TMath::Abs(chi2nu-1) < TMath::Abs(oChi2nu-1)) return +1;
389 if (TMath::Abs(chi2nu-1) > TMath::Abs(oChi2nu-1)) return -1;
393 //____________________________________________________________________
395 AliFMDCorrELossFit::ELossFit::Print(Option_t* option) const
398 // Information to standard output
404 if (o.Contains("S", TString::kIgnoreCase)) {
405 Printf("%15s: q=%2d n=%1d chi2/nu=%6.3f",
406 GetName(), fQuality, fN, (fNu <= 0 ? 999 : fChi2 / fNu));
410 std::cout << GetName() << ":\n"
411 << " chi^2/nu = " << fChi2 << "/" << fNu << " = "
412 << (fNu == 0 ? 999 : fChi2 / fNu) << "\n"
413 << " Quality: " << fQuality << "\n"
414 << " NParticles: " << fN << " (" << FindMaxWeight() << ")\n"
415 << OUTPAR("Delta", fDelta, fEDelta)
416 << OUTPAR("xi", fXi, fEXi)
417 << OUTPAR("sigma", fSigma, fESigma)
418 << OUTPAR("sigma_n", fSigmaN, fESigmaN);
419 for (Int_t i = 0; i < fN-1; i++)
420 std::cout << OUTPAR(Form("a%d", i+2), fA[i], fEA[i]);
421 std::cout << std::flush;
424 //____________________________________________________________________
426 AliFMDCorrELossFit::ELossFit::GetName() const
429 // Get the name of this object
435 return Form("FMD%d%c_etabin%03d", fDet, fRing, fBin);
438 //____________________________________________________________________
440 AliFMDCorrELossFit::ELossFit::Browse(TBrowser* b)
443 // Browse this object
448 Draw(b ? b->GetDrawOption() : "comp values");
453 //____________________________________________________________________
455 AliFMDCorrELossFit::ELossFit::Draw(Option_t* option)
462 // - COMP Draw components too
470 if (opt.Contains("COMP")) {
471 opt.ReplaceAll("COMP","");
474 if (opt.Contains("GOOD")) {
475 opt.ReplaceAll("GOOD","");
478 if (opt.Contains("VALUES")) {
479 opt.ReplaceAll("VALUES","");
482 if (opt.Contains("LEGEND")) {
483 opt.ReplaceAll("LEGEND","");
486 if (!opt.Contains("SAME")) {
492 l = new TLegend(.3, .5, .59, .94);
498 Int_t maxW = FindMaxWeight();
499 TF1* tot = AliForwardUtil::MakeNLandauGaus(fC * 1,
504 tot->SetLineColor(kBlack);
505 tot->SetLineWidth(2);
506 tot->SetLineStyle(1);
507 tot->SetTitle(GetName());
508 if (l) l->AddEntry(tot, "Total", "l");
509 Double_t max = tot->GetMaximum();
512 if (!opt.Contains("SAME")) {
513 TH1* frame = new TH1F(GetName(),
514 Form("FMD%d%c, eta bin %d",fDet,fRing,fBin),
516 frame->SetMinimum(max/10000);
517 frame->SetMaximum(max*1.4);
518 frame->SetXTitle("#Delta / #Delta_{mip}");
522 tot->DrawCopy(opt.Data());
530 TLatex* ltx1 = new TLatex(x1, y, "");
531 TLatex* ltx2 = new TLatex(x2, y, "");
533 ltx1->SetTextAlign(33);
534 ltx1->SetTextFont(132);
535 ltx1->SetTextSize(dy-.01);
537 ltx2->SetTextAlign(13);
538 ltx2->SetTextFont(132);
539 ltx2->SetTextSize(dy-.01);
541 ltx1->DrawLatex(x1, y, "Quality");
542 ltx2->DrawLatex(x2, y, Form("%d", fQuality));
545 ltx1->DrawLatex(x1, y, "#chi^{2}/#nu");
546 ltx2->DrawLatex(x2, y, Form("%7.3f", (fNu > 0 ? fChi2 / fNu : -1)));
549 const Char_t* pn[] = { "C", "#Delta", "#xi", "#sigma" };
550 Double_t pv[] = { fC, fDelta, fXi, fSigma };
551 Double_t pe[] = { fEC, fEDelta, fEXi, fESigma };
552 for (Int_t i = 0; i < 4; i++) {
553 ltx1->DrawLatex(x1, y, pn[i]);
554 ltx2->DrawLatex(x2, y, Form("%6.4f#pm%6.4f", pv[i], pe[i]));
557 for (Int_t i=2; i <= fN; i++) {
559 ltx1->SetTextColor(kRed+3);
560 ltx2->SetTextColor(kRed+3);
562 ltx1->DrawLatex(x1, y, Form("a_{%d}", i));
563 ltx2->DrawLatex(x2, y, Form("%6.4f#pm%6.4f", fA[i-2], fEA[i-2]));
576 for (Int_t i=1; i <= fN; i++) {
577 if (good && i > maxW) break;
578 TF1* f = AliForwardUtil::MakeILandauGaus(fC*(i == 1 ? 1 : fA[i-2]),
583 f->SetLineStyle(i > maxW ? 2 : 1);
584 min = TMath::Min(f->GetMaximum(), min);
585 f->DrawCopy(opt.Data());
586 if (l) l->AddEntry(f, Form("%d MIP%s", i, (i>1 ? "s" : "")), "l");
591 tot->GetHistogram()->SetMaximum(max);
592 tot->GetHistogram()->SetMinimum(min);
593 tot->GetHistogram()->GetYaxis()->SetRangeUser(min, max);
600 //____________________________________________________________________
601 #define CHECKPAR(V,E,T) ((V > 0) && (E / V < T))
603 //____________________________________________________________________
605 AliFMDCorrELossFit::ELossFit::GetLowerBound(Double_t f) const
612 //____________________________________________________________________
614 AliFMDCorrELossFit::ELossFit::GetLowerBound(Double_t f,
615 Bool_t includeSigma) const
619 // Delta - f * (xi + sigma)
620 return fDelta - f * (fXi + (includeSigma ? fSigma : 0));
623 //____________________________________________________________________
625 AliFMDCorrELossFit::ELossFit::CalculateQuality(Double_t maxChi2nu,
626 Double_t maxRelError,
627 Double_t leastWeight)
630 // Calculate the quality
632 Double_t decline = maxChi2nu;
635 Double_t red = fChi2 / fNu;
636 if (red < maxChi2nu) qual += 4;
638 Int_t q = (maxChi2nu+decline - red) / decline * 4;
639 if (q > 0) qual += q;
642 if (CHECKPAR(fDelta, fEDelta, maxRelError)) qual++;
643 if (CHECKPAR(fXi, fEXi, maxRelError)) qual++;
644 if (CHECKPAR(fSigma, fESigma, maxRelError)) qual++;
645 if (CHECKPAR(fSigmaN, fESigmaN, maxRelError)) qual++;
646 qual += FindMaxWeight(2*maxRelError, leastWeight, fN);
650 //____________________________________________________________________
651 AliFMDCorrELossFit::AliFMDCorrELossFit()
659 // Default constructor
661 fRings.SetOwner(kTRUE);
662 fEtaAxis.SetTitle("#eta");
663 fEtaAxis.SetName("etaAxis");
664 fRings.SetName("rings");
667 //____________________________________________________________________
668 AliFMDCorrELossFit::AliFMDCorrELossFit(const AliFMDCorrELossFit& o)
671 fEtaAxis(o.fEtaAxis.GetNbins(),o.fEtaAxis.GetXmin(),o.fEtaAxis.GetXmax()),
679 // o Object to copy from
681 fEtaAxis.SetTitle("#eta");
682 fEtaAxis.SetName("etaAxis");
685 //____________________________________________________________________
686 AliFMDCorrELossFit::~AliFMDCorrELossFit()
694 //____________________________________________________________________
696 AliFMDCorrELossFit::operator=(const AliFMDCorrELossFit& o)
699 // Assignment operator
702 // o Object to assign from
705 // Reference to this object
707 if (&o == this) return *this;
711 SetEtaAxis(o.fEtaAxis.GetNbins(), o.fEtaAxis.GetXmin(), o.fEtaAxis.GetXmax());
715 #define CACHE(BIN,IDX,OFFSET) fCache[IDX*OFFSET+BIN-1]
717 //____________________________________________________________________
719 AliFMDCorrELossFit::CacheBins(UShort_t minQuality) const
721 if (fCache.GetSize() > 0) return;
723 Int_t nRings = fRings.GetEntriesFast();
724 Int_t offset = fEtaAxis.GetNbins();
726 fCache.Set(nRings*offset);
729 for (Int_t i = 0; i < nRings; i++) {
730 TObjArray* ringArray = static_cast<TObjArray*>(fRings.At(i));
732 // First loop to find where we actually have fits
735 Int_t minBin = offset+1;
737 Int_t realMinBin = offset+1;
738 Int_t realMaxBin = -1;
739 for (Int_t j = 1; j < ringArray->GetEntriesFast(); j++) {
740 ELossFit* fit = static_cast<ELossFit*>(ringArray->At(j));
744 // Update our range off possible fits
745 realMinBin = TMath::Min(j, realMinBin);
746 realMaxBin = TMath::Max(j, realMaxBin);
748 // Check the quality of the fit
749 fit->CalculateQuality(AliFMDCorrELossFit::ELossFit::fgMaxChi2nu,
750 AliFMDCorrELossFit::ELossFit::fgMaxRelError,
751 AliFMDCorrELossFit::ELossFit::fgLeastWeight);
752 if (minQuality > 0 && fit->fQuality < minQuality) continue;
756 CACHE(j,i,offset) = j;
757 minBin = TMath::Min(j, minBin);
758 maxBin = TMath::Max(j, maxBin);
760 AliInfoF("Out of %d bins, %d had fits, of which %d are good (%5.1f%%)",
761 offset, nFits, nGood, (nFits > 0 ? 100*float(nGood)/nFits : 0));
763 // Now loop and set neighbors
764 realMinBin = TMath::Max(1, realMinBin-1); // Include one more
765 realMaxBin = TMath::Min(offset, realMaxBin+1); // Include one more
766 for (Int_t j = realMinBin; j <= realMaxBin; j++) {
767 if (CACHE(j,i,offset) > 0) continue;
769 Int_t nK = TMath::Max(realMaxBin - j, j - realMinBin);
771 for (Int_t k = 1; k <= nK; k++) {
774 if (left > realMinBin &&
775 CACHE(left,i,offset) == left) found = left;
776 else if (right < realMaxBin &&
777 CACHE(right,i,offset) == right) found = right;
778 if (found > 0) break;
780 // Now check that we found something
781 if (found) CACHE(j,i,offset) = CACHE(found,i,offset);
782 else AliWarningF("No fit found for etabin=%d in ring=%d", j, i);
788 //____________________________________________________________________
790 AliFMDCorrELossFit::FindEtaBin(Double_t eta) const
793 // Find the eta bin corresponding to the given eta
799 // Bin (in @f$[1,N_{bins}]@f$) corresponding to the given
800 // eta, or 0 if out of range.
802 if (TMath::Abs(fEtaAxis.GetXmin() - fEtaAxis.GetXmax()) < 1e-6
803 || fEtaAxis.GetNbins() == 0) {
804 AliWarning("No eta axis defined");
807 Int_t bin = const_cast<TAxis&>(fEtaAxis).FindBin(eta);
808 if (bin <= 0 || bin > fEtaAxis.GetNbins()) return 0;
812 //____________________________________________________________________
814 AliFMDCorrELossFit::SetFit(UShort_t d, Char_t r, Int_t etaBin, ELossFit* fit)
817 // Set the fit parameters from a function
822 // etaBin Eta (bin number, 1->nBins)
823 // f ELoss fit result - note, the object will take ownership
825 TObjArray* ringArray = GetOrMakeRingArray(d, r);
827 AliError(Form("Failed to make ring array for FMD%d%c", d, r));
830 if (etaBin <= 0 || etaBin >= fEtaAxis.GetNbins()+1) {
831 AliError(Form("bin=%d is out of range [%d,%d]",
832 etaBin, 1, fEtaAxis.GetNbins()));
835 // AliInfo(Form("Adding fit %p at %3d", fit, etaBin));
836 ringArray->AddAtAndExpand(fit, etaBin);
840 //____________________________________________________________________
842 AliFMDCorrELossFit::SetFit(UShort_t d, Char_t r, Double_t eta, ELossFit* fit)
845 // Set the fit parameters from a function
851 // f ELoss fit result - note, the object will take ownership
853 Int_t bin = FindEtaBin(eta);
855 AliError(Form("eta=%f is out of range [%f,%f]",
856 eta, fEtaAxis.GetXmin(), fEtaAxis.GetXmax()));
860 return SetFit(d, r, bin, fit);
862 //____________________________________________________________________
864 AliFMDCorrELossFit::SetFit(UShort_t d, Char_t r,
866 Int_t quality,UShort_t n,
867 Double_t chi2, UShort_t nu,
868 Double_t c, Double_t ec,
869 Double_t delta, Double_t edelta,
870 Double_t xi, Double_t exi,
871 Double_t sigma, Double_t esigma,
872 Double_t sigman, Double_t esigman,
873 Double_t* a, Double_t* ea)
876 // Set the fit parameters from a function
882 // quality Quality flag
883 // n @f$ N@f$ - Number of fitted peaks
884 // chi2 @f$ \chi^2 @f$
885 // nu @f$ \nu @f$ - number degrees of freedom
886 // c @f$ C@f$ - scale constant
887 // ec @f$ \delta C@f$ - error on @f$ C@f$
888 // delta @f$ \Delta@f$ - most probable value
889 // edelta @f$ \delta\Delta@f$ - error on @f$\Delta@f$
890 // xi @f$ \xi@f$ - Landau width
891 // exi @f$ \delta\xi@f$ - error on @f$\xi@f$
892 // sigma @f$ \sigma@f$ - Gaussian width
893 // esigma @f$ \delta\sigma@f$ - error on @f$\sigma@f$
894 // sigman @f$ \sigma_n@f$ - Noise width
895 // esigman @f$ \delta\sigma_n@f$ - error on @f$\sigma_n@f$
896 // a Array of @f$ N-1@f$ weights @f$ a_i@f$ for
898 // ea Array of @f$ N-1@f$ errors on weights @f$ a_i@f$ for
901 ELossFit* e = new ELossFit(quality, n,
909 if (!SetFit(d, r, eta, e)) {
915 //____________________________________________________________________
917 AliFMDCorrELossFit::SetFit(UShort_t d, Char_t r, Double_t eta,
918 Int_t quality, const TF1& f)
921 // Set the fit parameters from a function
927 // quality Quality flag
928 // f Function from fit
930 ELossFit* e = new ELossFit(quality, f);
931 if (!SetFit(d, r, eta, e)) {
937 //____________________________________________________________________
938 AliFMDCorrELossFit::ELossFit*
939 AliFMDCorrELossFit::GetFit(UShort_t d, Char_t r, Int_t etabin) const
942 // Get the fit corresponding to the specified parameters
947 // etabin Eta bin (1 based)
950 // Fit parameters or null in case of problems
952 TObjArray* ringArray = GetRingArray(d, r);
953 if (!ringArray) return 0;
954 if (etabin <= 0 || etabin >= fEtaAxis.GetNbins()) return 0;
955 if (etabin > ringArray->GetEntriesFast()) return 0;
956 else if (etabin >= ringArray->GetEntriesFast()) etabin--;
957 else if (!ringArray->At(etabin)) etabin++;
958 return static_cast<ELossFit*>(ringArray->At(etabin));
960 //____________________________________________________________________
961 AliFMDCorrELossFit::ELossFit*
962 AliFMDCorrELossFit::GetFit(UShort_t d, Char_t r, Double_t eta) const
965 // Find the fit corresponding to the specified parameters
973 // Fit parameters or null in case of problems
975 Int_t etabin = FindEtaBin(eta);
976 return GetFit(d, r, etabin);
979 //____________________________________________________________________
980 AliFMDCorrELossFit::ELossFit*
981 AliFMDCorrELossFit::FindFit(UShort_t d, Char_t r, Int_t etabin,
985 // Find the fit corresponding to the specified parameters
990 // etabin Eta bin (1 based)
993 // Fit parameters or null in case of problems
995 if (etabin <= 0 || etabin >= fEtaAxis.GetNbins()) {
996 // AliError(Form("Eta bin=%3d out of bounds [%d,%d] for FMD%d%c",
997 // etabin, 1, fEtaAxis.GetNbins(), d, r));
1001 TObjArray* ringArray = GetRingArray(d, r);
1003 AliError(Form("Failed to make ring array for FMD%d%c", d, r));
1006 if (fCache.GetSize() <= 0) CacheBins(minQ);
1007 Int_t idx = (d == 1 ? 0 :
1008 (d - 2) * 2 + 1 + (r=='I' || r=='i' ? 0 : 1));
1009 Int_t bin = CACHE(etabin, idx, fEtaAxis.GetNbins());
1011 if (bin < 0 || bin > ringArray->GetEntriesFast()) return 0;
1013 return static_cast<ELossFit*>(ringArray->At(bin));
1015 //____________________________________________________________________
1016 AliFMDCorrELossFit::ELossFit*
1017 AliFMDCorrELossFit::FindFit(UShort_t d, Char_t r, Double_t eta,
1018 UShort_t minQ) const
1021 // Find the fit corresponding to the specified parameters
1029 // Fit parameters or null in case of problems
1031 Int_t etabin = FindEtaBin(eta);
1032 return FindFit(d, r, etabin, minQ);
1034 //____________________________________________________________________
1036 AliFMDCorrELossFit::GetRingArray(UShort_t d, Char_t r) const
1039 // Get the ring array corresponding to the specified ring
1046 // Pointer to ring array, or null in case of problems
1050 case 1: idx = 0; break;
1051 case 2: idx = (r == 'i' || r == 'I') ? 1 : 2; break;
1052 case 3: idx = (r == 'o' || r == 'I') ? 3 : 4; break;
1054 if (idx < 0 || idx >= fRings.GetEntriesFast()) return 0;
1055 return static_cast<TObjArray*>(fRings.At(idx));
1057 //____________________________________________________________________
1059 AliFMDCorrELossFit::GetOrMakeRingArray(UShort_t d, Char_t r)
1062 // Get the ring array corresponding to the specified ring
1069 // Pointer to ring array, or newly created container
1073 case 1: idx = 0; break;
1074 case 2: idx = (r == 'i' || r == 'I') ? 1 : 2; break;
1075 case 3: idx = (r == 'o' || r == 'I') ? 3 : 4; break;
1077 if (idx < 0) return 0;
1078 if (idx >= fRings.GetEntriesFast() || !fRings.At(idx)) {
1079 TObjArray* a = new TObjArray(0);
1080 // TOrdCollection* a = new TOrdCollection(fEtaAxis.GetNbins());
1081 a->SetName(Form("FMD%d%c", d, r));
1083 fRings.AddAtAndExpand(a, idx);
1085 return static_cast<TObjArray*>(fRings.At(idx));
1088 //____________________________________________________________________
1090 AliFMDCorrELossFit::GetLowerBound(UShort_t d, Char_t r, Int_t etabin,
1093 ELossFit* fit = FindFit(d, r, etabin, 20);
1094 if (!fit) return -1024;
1095 return fit->GetLowerBound(f);
1097 //____________________________________________________________________
1099 AliFMDCorrELossFit::GetLowerBound(UShort_t d, Char_t r, Double_t eta,
1102 Int_t bin = FindEtaBin(eta);
1103 if (bin <= 0) return -1024;
1104 return GetLowerBound(d, r, Int_t(bin), f);
1106 //____________________________________________________________________
1108 AliFMDCorrELossFit::GetLowerBound(UShort_t d, Char_t r, Int_t etabin,
1109 Double_t f, Bool_t showErrors,
1110 Bool_t includeSigma) const
1112 ELossFit* fit = FindFit(d, r, etabin, 20);
1115 AliWarning(Form("No fit for FMD%d%c @ etabin=%d", d, r, etabin));
1119 return fit->GetLowerBound(f, includeSigma);
1122 //____________________________________________________________________
1124 AliFMDCorrELossFit::GetLowerBound(UShort_t d, Char_t r, Double_t eta,
1125 Double_t f, Bool_t showErrors,
1126 Bool_t includeSigma) const
1128 Int_t bin = FindEtaBin(eta);
1131 AliError(Form("eta=%f out of bounds for FMD%d%c", eta, d, r));
1134 return GetLowerBound(d, r, bin, f, showErrors, includeSigma);
1137 //____________________________________________________________________
1139 TH1D* MakeHist(const TAxis& axis, const char* name, const char* title,
1142 TH1D* h = new TH1D(Form("%s_%s", name, title),
1143 Form("%s %s", name, title),
1144 axis.GetNbins(), axis.GetXmin(), axis.GetXmax());
1146 h->SetMarkerStyle(20);
1147 h->SetMarkerColor(color);
1148 h->SetMarkerSize(0.5);
1149 h->SetFillColor(color);
1150 h->SetFillStyle(3001);
1151 h->SetLineColor(color);
1158 #define IDX2RING(I) (i == 0 || i == 1 || i == 3 ? 'I' : 'O')
1159 #define IDX2DET(I) (i == 0 ? 1 : (i == 1 || i == 2 ? 2 : 3))
1160 //____________________________________________________________________
1162 AliFMDCorrELossFit::GetStacks(Bool_t err,
1165 UShort_t maxN) const
1167 // Get a list of THStacks
1168 Int_t nRings = fRings.GetEntriesFast();
1169 // Int_t nPad = 6+maxN-1; // 7 regular params, and maxN-1 weights
1187 TList* stacks = new TList;
1188 stacks->AddAt(sChi2nu= new THStack("chi2", "#chi^{2}/#nu"), kChi2nu);
1189 stacks->AddAt(sC = new THStack("c", "C"), kC);
1190 stacks->AddAt(sDelta = new THStack("delta", "#Delta_{mp}"), kDelta);
1191 stacks->AddAt(sXi = new THStack("xi", "#xi"), kXi);
1192 stacks->AddAt(sSigma = new THStack("sigma", "#sigma"), kSigma);
1193 //stacks->AddAt(sigman= new THStack("sigman", "#sigma_{n}"), 5);
1194 stacks->AddAt(n = new THStack("n", "N"), kN);
1196 sChi2nu->SetName("qual");
1197 sChi2nu->SetTitle("Quality");
1199 n->SetTitle("Bin map");
1201 for (Int_t i = 1; i <= maxN; i++) {
1202 stacks->AddAt(new THStack(Form("a_%02d", i+1), Form("a_{%d}", i+1)), kN+i);
1205 // TArrayD min(nPad);
1206 // TArrayD max(nPad);
1207 // min.Reset(100000);
1208 // max.Reset(-100000);
1210 for (Int_t i = 0; i < nRings; i++) {
1211 if (!fRings.At(i)) continue;
1212 TObjArray* a = static_cast<TObjArray*>(fRings.At(i));
1213 Int_t nFits = a->GetEntriesFast();
1214 Int_t color = AliForwardUtil::RingColor(IDX2DET(i), IDX2RING(i));
1216 TH1D* hChi = MakeHist(fEtaAxis,a->GetName(), "chi2", color);
1217 TH1D* hC = MakeHist(fEtaAxis,a->GetName(), "c", color);
1218 TH1D* hDelta = MakeHist(fEtaAxis,a->GetName(), "delta", color);
1219 TH1D* hXi = MakeHist(fEtaAxis,a->GetName(), "xi", color);
1220 TH1D* hSigma = MakeHist(fEtaAxis,a->GetName(), "sigma", color);
1221 // TH1D* hSigmaN = MakeHist(fEtaAxis,a->GetName(), "sigman", color);
1222 TH1D* hN = MakeHist(fEtaAxis,a->GetName(), "n", color);
1224 const char* ho = (rel || !err ? "hist" : "e");
1225 sChi2nu->Add(hChi, "hist"); // 0
1226 sC ->Add(hC, ho); // 1
1227 sDelta ->Add(hDelta, ho); // 2
1228 sXi ->Add(hXi, ho); // 3
1229 sSigma ->Add(hSigma, ho); // 4
1230 // sigman->Add(hSigmaN,ho); // 5
1231 n ->Add(hN, "hist"); // 5
1232 hChi->SetFillColor(color);
1233 hChi->SetFillStyle(3001);
1234 hN->SetFillColor(color);
1235 hN->SetFillStyle(3001);
1237 for (Int_t k = 1; k <= maxN; k++) {
1238 hA[k-1] = MakeHist(fEtaAxis,a->GetName(), Form("a%02d",k+1), color);
1239 static_cast<THStack*>(stacks->At(kN+k))->Add(hA[k-1], ho);
1242 for (Int_t j = 0; j < nFits; j++) {
1243 ELossFit* f = static_cast<ELossFit*>(a->At(j));
1247 Double_t vChi2nu = (rel ? f->fQuality
1248 : (f->fNu <= 0 ? 0 : f->fChi2 / f->fNu));
1249 Double_t vC = (rel ? (f->fC >0 ?f->fEC /f->fC :0)
1251 Double_t vDelta = (rel ? (f->fDelta >0 ?f->fEDelta /f->fDelta :0)
1253 Double_t vXi = (rel ? (f->fXi >0 ?f->fEXi /f->fXi :0)
1255 Double_t vSigma = (rel ? (f->fSigma >0 ?f->fESigma /f->fSigma :0)
1257 Int_t nW = (rel ? CACHE(j,i,fEtaAxis.GetNbins()) :
1258 f->FindMaxWeight());
1259 // Double_t sigman = (rel ? (f->fSigmaN>0 ?f->fESigmaN/f->fSigmaN :0)
1261 hChi ->SetBinContent(b, vChi2nu);
1262 hN ->SetBinContent(b, nW);
1263 hC ->SetBinContent(b, vC);
1264 hDelta ->SetBinContent(b, vDelta);
1265 hXi ->SetBinContent(b, vXi);
1266 hSigma ->SetBinContent(b, vSigma);
1267 // if (vChi2nu > 1e-12) {
1268 // min[kChi2nu] = TMath::Min(min[kChi2nu], vChi2nu);
1269 // max[kChi2nu] = TMath::Max(max[kChi2nu], vChi2nu);
1271 // if (vC > 1e-12) {
1272 // min[kC] = TMath::Min(min[kC], vC);
1273 // max[kC] = TMath::Max(max[kC], vC);
1275 // if (vDelta > 1e-12) {
1276 // min[kDelta] = TMath::Min(min[kDelta], vDelta);
1277 // max[kDelta] = TMath::Max(max[kDelta], vDelta);
1279 // if (vXi > 1e-12) {
1280 // min[kXi] = TMath::Min(min[kXi], vXi);
1281 // max[kXi] = TMath::Max(max[kXi], vXi);
1283 // if (vSigma > 1e-12) {
1284 // min[kSigma] = TMath::Min(min[kSigma], vSigma);
1285 // max[kSigma] = TMath::Max(max[kSigma], vSigma);
1287 // if (nW > 1e-12) {
1288 // min[kN] = TMath::Min(min[kN], Double_t(nW));
1289 // max[kN] = TMath::Max(max[kN], Double_t(nW));
1291 // hSigmaN->SetBinContent(b, sigman);
1293 hC ->SetBinError(b, f->fEC);
1294 hDelta ->SetBinError(b, f->fEDelta);
1295 hXi ->SetBinError(b, f->fEXi);
1296 hSigma ->SetBinError(b, f->fESigma);
1297 // hSigmaN->SetBinError(b, f->fESigmaN);
1299 for (Int_t k = 0; k < f->fN-1 && k < maxN; k++) {
1300 Double_t vA = (rel ? (f->fA[k] > 0 ? f->fEA[k] / f->fA[k] : 0)
1302 hA[k]->SetBinContent(b, vA);
1303 if (!rel) hA[k]->SetBinError(b, f->fEA[k]);
1304 // if (vA > 1e-12) {
1305 // min[kN+1+k] = TMath::Min(min[kN+1+k], vA);
1306 // max[kN+1+k] = TMath::Max(max[kN+1+k], vA);
1314 //____________________________________________________________________
1316 AliFMDCorrELossFit::Draw(Option_t* option)
1322 // option Options. Possible values are
1323 // - err Plot error bars
1325 TString opt(Form("nostack %s", option));
1327 Bool_t rel = (opt.Contains("relative"));
1328 Bool_t err = (opt.Contains("error"));
1329 Bool_t clr = (opt.Contains("clear"));
1330 Bool_t gdd = (opt.Contains("good"));
1331 if (rel) opt.ReplaceAll("relative","");
1332 if (err) opt.ReplaceAll("error","");
1333 if (clr) opt.ReplaceAll("clear", "");
1334 if (gdd) opt.ReplaceAll("good", "");
1337 Int_t nRings = fRings.GetEntriesFast();
1338 for (Int_t i = 0; i < nRings; i++) {
1339 if (!fRings.At(i)) continue;
1340 TObjArray* a = static_cast<TObjArray*>(fRings.At(i));
1341 Int_t nFits = a->GetEntriesFast();
1343 for (Int_t j = 0; j < nFits; j++) {
1344 ELossFit* fit = static_cast<ELossFit*>(a->At(j));
1346 maxN = TMath::Max(maxN, UShort_t(fit->fN));
1349 // AliInfo(Form("Maximum N is %d", maxN));
1350 Int_t nPad = 6+maxN-1; // 7 regular params, and maxN-1 weights
1351 TVirtualPad* pad = gPad;
1354 pad->SetTopMargin(0.02);
1355 pad->SetRightMargin(0.02);
1356 pad->SetBottomMargin(0.15);
1357 pad->SetLeftMargin(0.10);
1359 pad->Divide(2, (nPad+1)/2, 0.1, 0, 0);
1361 TList* stacks = GetStacks(err, rel, gdd, maxN);
1363 Int_t nPad2 = (nPad+1) / 2;
1364 for (Int_t i = 0; i < nPad; i++) {
1365 Int_t iPad = 1 + i/nPad2 + 2 * (i % nPad2);
1366 TVirtualPad* p = pad->cd(iPad);
1367 p->SetLeftMargin(.15);
1372 if (rel && i != 0 && i != 6 && i != 5 && i != 4) p->SetLogy();
1375 THStack* stack = static_cast<THStack*>(stacks->At(i));
1377 // Double_t powMax = TMath::Log10(max[i]);
1378 // Double_t powMin = min[i] <= 0 ? powMax : TMath::Log10(min[i]);
1379 // if (powMax-powMin > 2. && min[i] != 0) p->SetLogy();
1381 // stack->SetMinimum(min[i]);
1382 // stack->SetMaximum(max[i]);
1383 stack->Draw(opt.Data());
1385 TString tit(stack->GetTitle());
1386 if (rel && i != 0 && i != 5)
1387 tit = Form("#delta %s/%s", tit.Data(), tit.Data());
1388 TH1* hist = stack->GetHistogram();
1389 TAxis* yaxis = hist->GetYaxis();
1390 yaxis->SetTitle(tit.Data());
1391 yaxis->SetTitleSize(0.15);
1392 yaxis->SetLabelSize(0.08);
1393 yaxis->SetTitleOffset(0.35);
1394 yaxis->SetTitleFont(132);
1395 yaxis->SetLabelFont(132);
1396 yaxis->SetNdivisions(5);
1399 TAxis* xaxis = stack->GetHistogram()->GetXaxis();
1400 xaxis->SetTitle("#eta");
1401 xaxis->SetTitleSize(0.15);
1402 xaxis->SetLabelSize(0.08);
1403 xaxis->SetTitleOffset(0.35);
1404 xaxis->SetTitleFont(132);
1405 xaxis->SetLabelFont(132);
1406 xaxis->SetNdivisions(10);
1408 stack->Draw(opt.Data());
1413 //____________________________________________________________________
1415 AliFMDCorrELossFit::Print(Option_t* option) const
1418 // Print this object.
1422 // - R Print recursive
1425 TString opt(option);
1427 Int_t nRings = fRings.GetEntriesFast();
1428 bool recurse = opt.Contains("R");
1429 bool cache = opt.Contains("C") && fCache.GetSize() > 0;
1430 Int_t nBins = fEtaAxis.GetNbins();
1432 std::cout << "Low cut in fit range: " << fLowCut << "\n"
1433 << "Eta axis: " << nBins
1434 << " bins, range [" << fEtaAxis.GetXmin() << ","
1435 << fEtaAxis.GetXmax() << "]" << std::endl;
1437 for (Int_t i = 0; i < nRings; i++) {
1438 if (!fRings.At(i)) continue;
1439 TObjArray* a = static_cast<TObjArray*>(fRings.At(i));
1440 Int_t nFits = a->GetEntriesFast();
1442 std::cout << a->GetName() << " [" << nFits << " entries]"
1443 << (recurse ? ":\n" : "\t");
1444 Int_t min = fEtaAxis.GetNbins()+1;
1446 for (Int_t j = 0; j < nFits; j++) {
1447 if (!a->At(j)) continue;
1449 min = TMath::Min(j, min);
1450 max = TMath::Max(j, max);
1453 std::cout << "Bin # " << j << "\t";
1454 ELossFit* fit = static_cast<ELossFit*>(a->At(j));
1459 std::cout << " bin range: " << std::setw(3) << min
1460 << "-" << std::setw(3) << max << " " << std::setw(3)
1461 << (max-min+1) << " bins" << std::endl;
1466 std::cout << " eta bin | Fit bin \n"
1467 << " # range | FMD1i FMD2i FMD2o FMD3i FMD3o"
1468 // << "----+-----+++------+-----------------------------------"
1470 size_t oldPrec = std::cout.precision();
1471 std::cout.precision(3);
1472 for (Int_t i = 1; i <= nBins; i++) {
1473 std::cout << std::setw(4) << i << " "
1474 << std::setw(5) << std::showpos << fEtaAxis.GetBinLowEdge(i)
1475 << " - " << std::setw(5) << fEtaAxis.GetBinUpEdge(i)
1476 << std::noshowpos << " | ";
1477 for (Int_t j = 0; j < 5; j++) {
1478 Int_t bin = CACHE(i,j,nBins);
1479 if (bin <= 0) std::cout << " ";
1480 else std::cout << std::setw(5) << bin
1481 << (bin == i ? ' ' : '*') << ' ';
1483 std::cout << std::endl;
1485 std::cout.precision(oldPrec);
1488 //____________________________________________________________________
1490 AliFMDCorrELossFit::Browse(TBrowser* b)
1493 // Browse this object
1504 //____________________________________________________________________