10 #include <TFitResult.h> 18 #include <TPaveStats.h> 42 : src(static_cast<TF1*>(o.src ? o.src->Clone() : 0)) {}
51 if (&o ==
this)
return *
this;
52 if (o.
src) src =
static_cast<TF1*
>(o.
src->Clone());
75 printf(
"%8.4f | %8.4f | %8.4f | ", delta, xi, sigma);
79 src->SetLineColor(kBlack);
85 src->SetParameter(0, c/max);
163 virtual void DoRun() = 0;
169 virtual void WriteOut(TDirectory* d) = 0;
175 virtual void DrawInPad(TVirtualPad* p) = 0;
197 TLine* l =
new TLine(x,low,x,high);
199 l->SetLineColor(col);
236 t->
Run(c, delta, xi, sigma, n, a, xMin, xMax);
241 TCanvas* can =
new TCanvas(name, title, 1200, 900);
271 Double_t up = idelta + ixi + isigma;
274 for (
Int_t i = 1; i < n; i++)
275 a[i] = TMath::Exp(0.5 - TMath::Sqrt(2)*(i+1));
277 return DoOne(c,delta,xi,sigma,n,a,-3,up, pad);
293 Double_t a[] = {1, 0.1179, 0.0333, 0.0068, 0.0012 };
295 return DoOne(c, delta, xi, sigma, n, a, 0.02, n, pad);
303 virtual const char*
Prefix()
const = 0;
324 (mode == 0 ?
"SigmaXi" :
325 mode == 1 ?
"Sigma" :
"Xi"));
326 file = TFile::Open(Form(
"%s.root", base.Data()),
"RECREATE");
328 canvas =
new TCanvas(base, Form(
"%s.pdf", base.Data()),
329 TMath::Sqrt(2)*900, 900);
331 gSystem->RedirectOutput(
"/dev/null");
332 canvas->Print(Form(
"%s[", canvas->GetTitle()), title);
345 TString tit =
"pdf Landscape Title:";
347 if (xi > 0 && sigma > 0) {
348 tit.Append(Form(
"xi=%8.4f sigma=%8.4f", xi, sigma));
351 tit.Append(
"Results");
354 gSystem->RedirectOutput(
"/dev/null");
355 c->Print(c->GetTitle(), tit);
358 c->Print(Form(
"%s]", c->GetTitle()), tit);
362 ::Info(
"",
"Plots saved in %s", c->GetTitle());
413 Scan(mod, n, values, maxN);
426 ScanOne(scanSigma, values.GetSize(), values.GetArray(), maxN);
439 Scan(0, n, values, maxN);
449 ScanTwo(values.GetSize(), values.GetArray(), maxN);
471 t->
WriteOut(out->mkdir(
"realistic"));
475 if (mode == 0)
LoopTwo(n, values, maxN, can, nt, out);
476 else LoopOne(mode, n, values, maxN, can, nt, out);
501 Bool_t scanSigma = mode == 1;
502 const char* var = (scanSigma ?
"sigma" :
"xi");
504 for (
Int_t i = 0; i < n; i++) {
509 StepIt(mode, xi, sigma, maxN, 0, i, n, can, nt, out, var, v);
530 for (
Int_t i = 0; i < n; i++) {
532 TDirectory* d = out->mkdir(Form(
"xi%04d",
Int_t(100*xi)));
533 for (
Int_t j = 0; j < n; j++) {
535 StepIt(mode, xi, sigma, maxN, i, j, n, can, nt, d,
"sigma", sigma);
568 TDirectory* d = p->mkdir(Form(
"%s%04d", pre,
Int_t(100*v)));
574 Step(mode, i, j, n, t, nt);
581 #include <TGraphErrors.h> 582 #include <TGraph2DErrors.h> 583 #include <TMultiGraph.h> 584 #include <Math/RootFinder.h> 586 struct TestShift :
public TestF 612 Double_t b = p * u * TMath::Sqrt(u);
614 return a / TMath::Power(1+1./x, b);
625 if (scale == 1)
return;
626 for (
Int_t i = 0; i < g->GetN(); i++)
627 g->SetPoint(i,g->GetX()[i], g->GetY()[i] * scale);
639 comps.SetName(
"components");
640 derivs.SetName(
"derivatives");
651 zeros->SetName(
"zeros");
652 zeros->SetTitle(
"Zeros of derivatives");
653 zeros->SetMarkerStyle(25);
654 zeros->SetMarkerSize(1.2);
655 zeros->SetMarkerColor(kRed+1);
658 diff->SetName(
"diff");
659 diff->SetTitle(
"#delta#Delta_{p}");
660 diff->SetMarkerStyle(20);
661 diff->SetMarkerColor(kBlue+1);
665 for (
Int_t i = 1; i <= n; i++, j++)
666 if (!MakeComp(i))
break;
671 fit =
new TF1(
"fit", &fitFunc, 1, j, 4);
672 fit->SetParNames(
"c",
"p",
"#xi",
"#sigma");
673 fit->SetParameter(0, .5);
674 fit->SetParameter(1, .5);
675 fit->FixParameter(2,
Xi());
676 fit->FixParameter(3,
Sigma());
684 gSystem->RedirectOutput(
"/dev/null");
685 diff->Fit(fit, Form(
"MR%s", ifit == 0 ?
"Q" :
"Q"));
689 Printf(
"%8.4f | %8.4f %9.5f | %8.4f %9.5f",
690 fit->GetChisquare() / fit->GetNDF(),
691 fit->GetParameter(0), fit->GetParError(0),
692 fit->GetParameter(1), fit->GetParError(1));
702 fi->SetNpx(
src->GetNpx());
706 dF->SetName(Form(
"d%s", fi->GetName()));
707 dF->SetTitle(Form(
"d%s/d#Delta", fi->GetTitle()));
708 dF->SetMarkerStyle(1);
710 dF->SetMarkerColor(fi->GetLineColor());
711 dF->SetLineColor(fi->GetLineColor());
713 Double_t max = TMath::MaxElement(dF->GetN(), dF->GetY());
714 if (max < 1e-6)
return false;
716 ScaleGraph(dF, 1./max);
719 Double_t deltaI = i * (delta + xi * TMath::Log(i));
721 Double_t xR = FindRoot(dF, deltaI-2*xiI, deltaI+2*xiI);
728 zeros->SetPoint(i-1, xR, dF->Eval(xR));
729 diff->SetPoint(i-1, i, xR - deltaI);
744 ROOT::Math::RootFinder rfb(ROOT::Math::RootFinder::kBRENT);
745 rfb.SetFunction(*wG, xMin, xMax);
756 body->SetTopMargin(0.01);
757 body->SetRightMargin(0.01);
760 TVirtualPad* p = body->cd(1);
761 p->SetTopMargin(0.01);
762 p->SetRightMargin(0.01);
765 TVirtualPad* q = p->cd(1);
766 q->SetRightMargin(0.01);
772 fmin = TMath::Max(fmin, fmax/1e8);
773 src->GetHistogram()->SetMinimum(fmin);
774 TLatex* ltx =
new TLatex(q->GetLeftMargin()+.02,
775 1-q->GetTopMargin()-.02,
776 Form(
"#Delta_{p}=%f, #xi=%f, #sigma=%f",
779 ltx->SetTextFont(42);
781 ltx->SetTextAlign(13);
785 q->SetRightMargin(0.01);
788 Double_t x = 1-q->GetRightMargin()-.02;
789 Double_t y = 1-q->GetTopMargin()-.1;
790 for (
Int_t i = 1; i <= comps.GetEntries(); i++) {
792 TF1* fi =
static_cast<TF1*
>(comps.At(i-1));
795 Double_t deltaR = zeros->GetX()[i-1];
798 Color_t col = fi->GetLineColor();
802 ltx =
new TLatex(x,y,Form(
"#Delta_{p,%2d}=%8.4f %8.4f",
804 ltx->SetTextAlign(33);
805 ltx->SetTextFont(42);
808 y -= ltx->GetTextSize() + .01;
813 df->Draw(i == 1 ?
"alp" :
"lp");
814 df->GetHistogram()->GetXaxis()->SetRangeUser(
XMin(),
XMax());
821 gStyle->SetOptFit(111111);
822 gStyle->SetStatY(.6);
824 p->SetRightMargin(0.02);
825 p->SetTopMargin(0.02);
827 diff->GetHistogram()->GetListOfFunctions()->Add(fit);
828 diff->GetHistogram()->SetXTitle(
"N_{particle}");
829 diff->GetHistogram()->SetYTitle(
"#Delta_{r}-#Delta_{p}");
847 comps.Write(comps.GetName(), TObject::kSingleKey);
848 derivs.Write(derivs.GetName(), TObject::kSingleKey);
871 virtual const char*
Prefix()
const {
return "shift"; }
879 return new TNtuple(
"shift",
"Shift scan",
880 "Delta:xi:sigma:chi2nu:p:ep:c:ec");
891 c2s =
new TGraph2DErrors(n*n);c2s->SetName(
"cs");
892 p2s =
new TGraph2DErrors(n*n);p2s->SetName(
"ps");
893 mcs =
new TMultiGraph(
"mcs",
"C as function of #sigma/#xi");
894 mps =
new TMultiGraph(
"mps",
"P as function of #sigma/#xi");
895 c2s->SetDirectory(0);
896 p2s->SetDirectory(0);
897 c2s->SetMarkerStyle(20);
898 p2s->SetMarkerStyle(20);
899 c2s->SetTitle(
"c(#xi,#sigma)");
900 p2s->SetTitle(
"p(#xi,#sigma)");
903 const char* var = (mode == 1 ?
"#sigma" :
"#xi");
906 cs->SetMarkerStyle(20);
907 ps->SetMarkerStyle(20);
908 cs->SetTitle(Form(
"c(%s)", var));
909 ps->SetTitle(Form(
"p(%s)", var));
911 Printf(
"%-8s | %-8s | %-8s | %-8s | %-8s %-9s | %-8s %-9s",
912 "Delta_p",
"xi",
"sigma",
"chi^2/nu",
"c",
"error",
"p",
"error");
925 void FillMG(TMultiGraph* mg,
933 TList* l = mg->GetListOfGraphs();
937 ge->SetName(Form(
"%s%02d", mg->GetName(), i));
938 ge->SetTitle(Form(Form(
"%d", i)));
941 ge->SetMarkerStyle(20);
944 ge->SetPoint(j, u, y);
945 ge->SetPointError(j, 0, e);
967 Double_t p = t->fit->GetParameter(1);
968 Double_t ec = t->fit->GetParError(0);
969 Double_t ep = t->fit->GetParError(1);
970 Int_t idx = i * n + j;
972 c2s->SetPoint(idx, xi, sigma, c);
973 p2s->SetPoint(idx, xi, sigma, p);
974 c2s->SetPointError(idx, 0, 0, ec);
975 p2s->SetPointError(idx, 0, 0, ep);
976 FillMG(mcs, i, j, n, sigma/xi, c, ec);
977 FillMG(mps, i, j, n, sigma/xi, p, ep);
980 cs->SetPoint(idx, (mode==1 ? sigma : xi), c);
981 ps->SetPoint(idx, (mode==1 ? sigma : xi), p);
982 cs->SetPointError(idx, 0, ec);
983 ps->SetPointError(idx, 0, ep);
985 nt->Fill(1,xi,sigma,t->fit->GetChisquare()/t->fit->GetNDF(),
c,ec,p,ep);
1000 can->cd(1); c2s->Draw(
"TRI2Z");
1001 can->cd(2); p2s->Draw(
"TRI2Z");
1002 can->cd(3); mcs->Draw(
"APL");
1003 can->cd(4); mps->Draw(
"APL");
1004 c2s->GetHistogram()->SetXTitle(
"#xi");
1005 p2s->GetHistogram()->SetXTitle(
"#xi");
1006 c2s->GetHistogram()->SetYTitle(
"#sigma");
1007 p2s->GetHistogram()->SetYTitle(
"#sigma");
1008 c2s->GetHistogram()->SetZTitle(
"c");
1009 p2s->GetHistogram()->SetZTitle(
"p");
1010 mcs->GetHistogram()->SetXTitle(
"#sigma/#xi");
1011 mps->GetHistogram()->SetXTitle(
"#sigma/#xi");
1012 mcs->GetHistogram()->SetYTitle(
"c");
1013 mps->GetHistogram()->SetYTitle(
"p");
1024 can->cd(1); cs->Draw(
"APL");
1025 can->cd(2); ps->Draw(
"APL");
1040 #include <TRandom.h> 1042 struct TestFit :
public TestF 1058 static void FillRandom(
TH1* h, TF1* f,
Int_t n=1000000) {
1059 TAxis* xAxis = h->GetXaxis();
1061 Int_t first = xAxis->GetFirst();
1062 Int_t last = xAxis->GetLast();
1068 Double_t fint = f->Integral(xAxis->GetBinLowEdge(i+first-1),
1069 xAxis->GetBinUpEdge(i+first-1));
1070 integral[i] = integral[i-1] + fint;
1074 if (integral[nbinsx] == 0) {
1075 Error(
"FillRandom",
"Integral = zero");
1079 integral[i] /= integral[nbinsx];
1082 for (
Int_t i = 0; i < n; i++) {
1084 Int_t j = TMath::BinarySearch(nbinsx,&integral[0],r1);
1085 Double_t x = (xAxis->GetBinLowEdge(j+first) +
1086 xAxis->GetBinWidth(j+first) *
1087 (r1-integral[j])/(integral[j+1] - integral[j]));
1100 src->SetLineColor(kBlue);
1101 src->SetLineStyle(2);
1102 dist =
new TH1D(
"dist",
"Landau-Gaus distribution",500,xMin,xMax);
1103 dist->SetXTitle(
"#Delta");
1104 dist->SetYTitle(
"dN/d#Delta");
1105 dist->SetFillStyle(3001);
1106 dist->SetFillColor(kMagenta+1);
1108 dist->SetDirectory(0);
1109 FillRandom(dist,
src);
1111 Int_t peakBin = dist->GetMaximumBin();
1112 Double_t max = dist->GetBinContent(peakBin);
1129 static_cast<TFitResult*
>(f.
GetFitResults().At(n-1))->CovMatrixStatus();
1130 if (covStatus < 2) ::Warning(
"",
"Fit may not be good");
1132 r->SetRange(xMin, xMax);
1133 res =
static_cast<TF1*
>(r->Clone());
1134 res->SetLineColor(kPink+10);
1135 res->SetLineStyle(1);
1136 res->SetLineWidth(3);
1137 dist->GetListOfFunctions()->Add(res);
1139 Double_t min = 0.1*dist->GetMinimum();
1142 for (
Int_t i = 1; i <= n; i++) {
1147 comp->SetLineWidth(2);
1148 comp->SetLineStyle(1);
1152 TLine* l =
VerticalLine(1, comp->GetLineColor(), rDelta, min,
1153 1.1*old->Eval(rDelta));
1154 dist->GetListOfFunctions()->Add(comp);
1155 dist->GetListOfFunctions()->Add(l);
1170 p->SetTopMargin(0.0);
1171 p->SetRightMargin(0.0);
1172 p->SetBottomMargin(0.0);
1173 p->SetLeftMargin(0.0);
1174 p->SetFillColor(kGray);
1175 p->Divide(2,1,0.001,0.001);
1176 TVirtualPad* q = p->cd(1);
1178 q->SetTopMargin(0.01);
1179 q->SetRightMargin(0.02);
1180 q->SetFillColor(kWhite);
1181 gStyle->SetOptStat(0);
1182 gStyle->SetOptFit(11111);
1183 gStyle->SetOptTitle(
false);
1184 gStyle->SetStatY(1-q->GetTopMargin());
1186 dist->DrawCopy(
"hist");
1187 dist->DrawCopy(
"e same");
1189 src->DrawClone(
"same");
1195 q->SetTopMargin(0.01);
1196 q->SetRightMargin(0.02);
1197 q->SetFillColor(kWhite);
1199 pars =
new TH1D(
"pars",
"#chi^{2}/#nu & #Deltap_{i}/#deltap_{i}",
1201 pars->SetDirectory(0);
1202 pars->SetFillColor(kCyan+2);
1203 pars->SetFillStyle(3001);
1204 pars->SetYTitle(
"#Deltap_{i}/#deltap_{i}");
1206 TPaveStats* stats =
new TPaveStats(0,0,0,0);
1207 stats->SetX1NDC(gStyle->GetStatX()-gStyle->GetStatW());
1208 stats->SetY1NDC(gStyle->GetStatY()-gStyle->GetStatH());
1209 stats->SetX2NDC(gStyle->GetStatX());
1210 stats->SetY2NDC(gStyle->GetStatY());
1211 stats->SetTextFont(42);
1213 stats->SetBorderSize(1);
1214 stats->SetFillColor(kWhite);
1216 pars->GetListOfFunctions()->Add(stats);
1217 TString fmt(Form(
"%%s = %%%s", stats->GetFitFormat()));
1218 for (
Int_t i = 0; i < nPar; i++) {
1220 res->GetParLimits(i, low, high);
1222 Double_t pRes = res->GetParameter(i);
1223 Double_t eRes = res->GetParError(i);
1224 Bool_t fix = (low == high && ((pRes == 0 && low == 1) || low==pRes));
1225 Double_t diff = fix ? 0 : TMath::Abs(pSrc-pRes)/eRes;
1226 pars->GetXaxis()->SetBinLabel(i+1,res->GetParName(i));
1227 pars->SetBinContent(i+1, diff);
1228 stats->AddText(Form(fmt.Data(), res->GetParName(i), pSrc));
1230 pars->GetXaxis()->SetBinLabel(nPar+1,
"#chi^{2}/#nu");
1231 pars->SetBinContent(nPar+1,res->GetChisquare() / res->GetNDF());
1247 void PrintFs(
Bool_t full=
false) {
1250 Printf(
"%-2s %-10s | %-8s | %8s %-9s | %9.5s",
1251 "#",
"Name",
"Source",
"Fit",
"Error",
"delta");
1252 for (
Int_t i = 0; i < nPar; i++) {
1254 res->GetParLimits(i, low, high);
1256 Double_t pRes = res->GetParameter(i);
1257 Double_t eRes = res->GetParError(i);
1258 Bool_t fix = (low == high && ((pRes == 0 && low==1) || low==pRes));
1259 Double_t diff = fix ? 0 : TMath::Abs(pSrc-pRes)/eRes;
1260 Printf(
"%2d %10s | %8.4f | %8.4f %9.5f | %9.5f %s",
1261 i,
src->GetParName(i), pSrc, pRes, eRes, diff,
1262 (fix ?
"fixed" : (diff < 2 ?
"ok" :
"bad")));
1264 Printf(
"chi^2/nu = %8.4f/%-3d = %9.5f",
1265 res->GetChisquare(), res->GetNDF(),
1266 res->GetChisquare() / res->GetNDF());
1269 Printf(
"%8.4f", res->GetChisquare() / res->GetNDF());
1276 virtual void WriteOut(TDirectory* d)
1281 if (res) res->Write();
1282 if (pars) pars->Write();
1288 const char*
Prefix()
const {
return "fit"; }
1290 Printf(
"%-8s | %-8s | %-8s | %-8s ",
"Delta_p",
"xi",
"sigma",
"chi^2/nu");
void ScanOne(Bool_t scanSigma, Int_t n, const Double_t *values, Int_t maxN=10)
static TF1 * MakeFn(Double_t c, Double_t delta, Double_t xi, Double_t sigma, Double_t sigma_n, Int_t n, const Double_t *a, Double_t xmin, Double_t xmax)
static TLine * VerticalLine(Int_t i, Color_t col, Double_t x, Double_t low, Double_t high)
virtual void PreLoop(UShort_t mode, Int_t nVal)=0
TF1 * Fi(Double_t c, Double_t delta, Double_t xi, Double_t sigma, Double_t sigmaN, Int_t i) const
virtual void WriteOut(TDirectory *d)=0
void ScanOne(Bool_t scanSigma, const TArrayD &values, Int_t maxN)
const TObjArray & GetFitResults() const
Test * DoRealistic(TVirtualPad *pad=0)
void Scan(UShort_t mode, Int_t n, const Double_t *values, Int_t maxN)
Declaration and implementation of Landau-Gauss distributions.
virtual TNtuple * MakeNTuple()
virtual void DrawInPad(TVirtualPad *p)=0
virtual const char * Prefix() const =0
Test * DoOne(const Double_t c, const Double_t delta, const Double_t xi, const Double_t sigma, const Int_t n, const Double_t *a, const Double_t xMin, const Double_t xMax, TVirtualPad *pad=0)
static TF1 * MakeFi(Double_t c, Double_t delta, Double_t xi, Double_t sigma, Double_t sigma_n, Int_t i, Double_t xmin, Double_t xmax)
void StepIt(UShort_t mode, Double_t xi, Double_t sigma, Int_t maxN, Int_t i, Int_t j, Int_t n, TCanvas *can, TNtuple *nt, TDirectory *p, const char *pre, Double_t v)
static Color_t GetIColor(Int_t i)
virtual void PostLoop(UShort_t mode, TCanvas *can, TNtuple *nt, TFile *out)=0
static void IPars(Int_t i, Double_t &delta, Double_t &xi, Double_t &sigma)
void LoopOne(UShort_t mode, Int_t n, const Double_t *values, Int_t maxN, TCanvas *can, TNtuple *nt, TFile *out)
void LoopTwo(Int_t n, const Double_t *values, Int_t maxN, TCanvas *can, TNtuple *nt, TFile *out)
void ScanTwo(Int_t n, const Double_t *values, Int_t maxN=10)
void PrintCanvas(TCanvas *c, Double_t xi, Double_t sigma)
virtual void Step(UShort_t mode, Int_t i, Int_t j, Int_t n, Test *test, TNtuple *nt)=0
static Bool_t EnableSigmaShift(Short_t val=-1)
TFile * file
TList with histograms for a given trigger.
Test * DoUnit(const Double_t sigma, const Double_t xi=1, const Int_t n=10, TVirtualPad *pad=0)
TF1 * FitNParticle(TH1 *dist, UShort_t n, Double_t sigman=-1)
Double_t A(Int_t i) const
void test(int runnumber=195345)
virtual void SetupScan(UShort_t mode, TFile *&file, TCanvas *&canvas, TNtuple *&nt)
Test & operator=(const Test &o)
virtual Test * MakeTest()=0
void Run(const Double_t c, const Double_t delta, const Double_t xi, const Double_t sigma, const Int_t n, const Double_t *a, const Double_t xMin, const Double_t xMax)
void ScanTwo(const TArrayD &values, Int_t maxN)
Declaration and implementation of fitter of Landau-Gauss distributions to energy loss spectra...