562 if (hout) hout->Reset();
564 if (!hin || !hout)
return 0;
566 Int_t n=hin->GetNbinsX();
572 printf(
" *NcBlocks::GetBlocks* Inconsistent parameter fpr=%-g for histogram treatment. \n",fpr);
582 title.Form(
"Bayesian Block representation with FPR=%-.3g",fpr);
583 hout->SetTitle(title);
615 Double_t oldoptlen=0;
625 for (Int_t i=1; i<=n; i++)
629 xup=hin->GetBinLowEdge(i)+hin->GetBinWidth(i);
633 if (fpr<0 && optj) jstart=optj;
635 for (Int_t j=jstart; j<=i; j++)
637 xlow=hin->GetBinLowEdge(j);
645 bcount=hin->Integral(j,i);
650 for (Int_t k=j; k<=i; k++)
652 yk=hin->GetBinContent(k);
653 sigk=hin->GetBinError(k);
669 if (index>0) pfit+=best.At(index-1);
693 best.SetAt(optfit,i-1);
694 last.SetAt(optj,i-1);
695 lengths.SetAt(optlen,i-1);
696 counts.SetAt(optcount,i-1);
698 if (!ntrig || optj==1)
continue;
701 oldoptj=last.At(i-2);
702 oldoptlen=lengths.At(i-2);
704 if ((
fMode==1 ||
fMode==2) && oldoptlen) oldytrig=counts.At(i-2)/oldoptlen;
705 if (
fMode==3) oldytrig=counts.At(i-2);
707 if ((
fMode==1 ||
fMode==2) && optlen) ytrig=counts.At(i-1)/optlen;
708 if (
fMode==3) ytrig=counts.At(i-1);
710 if (optj>oldoptj && ((ntrig>0 && ytrig>oldytrig) || (ntrig<0 && ytrig<oldytrig)))
713 xtrig=hin->GetBinLowEdge(optj);
717 if (ncp>=abs(ntrig))
break;
729 TArrayD xarr(ncells+1);
730 TArrayD yarr(ncells+1);
736 x=hin->GetBinLowEdge(jcp)+lengths[index];
737 iup=hin->FindFixBin(x);
740 if (
fMode==1 && lengths[index]) y=counts[index]/lengths[index];
745 for (Int_t i=jcp; i<=iup; i++)
747 if (hin->GetBinContent(i)) nfilled++;
749 if (nfilled) y=counts[index]/double(nfilled);
752 if (
fMode==3) y=counts[index];
758 if (jcp==1) xarr.SetAt(hin->GetBinLowEdge(jcp),ncp);
764 Double_t* xbins=
new Double_t[ncp+1];
765 Double_t* yvals=
new Double_t[ncp+1];
767 for (Int_t i=0; i<=ncp; i++)
769 xbins[i]=xarr.At(ncp-i);
770 yvals[i]=yarr.At(ncp-i);
773 hout->SetBins(ncp,xbins);
774 for (Int_t i=1; i<=ncp; i++)
776 hout->SetBinContent(i,yvals[i]);
780 hout->SetEntries(hin->GetEntries());
783 if (!ntrig) xtrig=xbins[1];
785 hout->SetLineWidth(2);
786 hout->SetLineColor(kBlue);
787 hout->SetStats(kFALSE);
791 title=
"Bayesian Block representation for histogram ";
792 title+=hin->GetName();
793 title+=
" with FPR= %-.3g";
795 str=hin->GetXaxis()->GetTitle();
796 if (str==
"") str=
"Recordings (e.g. time)";
799 str=hin->GetYaxis()->GetTitle();
800 if (str==
"") str=
"Counts";
802 str=title.Format(title.Data(),fpr);
803 hout->SetTitle(str.Data());
808 str.Form(
"Requested trigger at : %-.3g",xtrig);
810 TLegend* leg=
new TLegend(0.5,0.85,0.7,0.9,str);
811 leg->SetFillColor(0);
812 leg->SetTextColor(kBlue);
813 leg->SetTextAlign(22);
815 TList* hlist=hout->GetListOfFunctions();
872 cout <<
" *NcBlocks::GetBlocks* Error : Output histogram not specified." << endl;
880 if (n<2 || !store || dim<1 || i<1 || i>dim || fabs(fpr)>1)
882 cout <<
" *NcBlocks::GetBlocks* Inconsistent input for NcSample treatment." << endl;
883 cout <<
" Store Mode:" << store <<
" Entries:" << n <<
" Dimension:" << dim <<
" i:" << i <<
" fpr:" << fpr << endl;
894 for (Int_t idx=1; idx<=n; idx++)
901 if (val-xarr[idstore-1]<=0)
continue;
916 Double_t* xbins=xarr.GetArray();
917 TH1F hin(
"",
"",n-1,xbins);
918 for (Int_t j=1; j<n; j++)
920 hin.SetBinContent(j,1);
923 Double_t xtrig=
GetBlocks(&hin,fpr,hout,ntrig);
926 hout->SetEntries(
double(n));
930 title=
"Bayesian Block representation for NcSample ";
932 title+=
" with FPR=%-.3g";
933 title+=
";Recordings of variable ";
938 title+=
";Count rate";
939 str=title.Format(title.Data(),fpr);
940 hout->SetTitle(str.Data());
1204 cout <<
" *NcBlocks::GetBlocks* Error : Output histogram not specified for TGraphErrors treatment." << endl;
1210 if (n<2 || fabs(fpr)>1)
1212 cout <<
" *NcBlocks::GetBlocks* Inconsistent input for TGraphErrors treatment." << endl;
1213 cout <<
" Entries:" << n <<
" fpr:" << fpr << endl;
1224 Double_t* xbins=
new Double_t[n+1];
1230 for (Int_t i=0; i<n; i++)
1233 err=fabs(gr.GetErrorX(i));
1237 dist=xbins[i]-xbins[i-1];
1238 if (dmin<0 || dist<dmin) dmin=dist;
1242 xbins[n]=xbins[n-1]+dmin;
1244 TH1F hin(
"",
"",n,xbins);
1245 for (Int_t j=1; j<=n; j++)
1247 gr.GetPoint(j-1,x,y);
1248 err=fabs(gr.GetErrorY(j-1));
1249 hin.SetBinContent(j,y);
1250 hin.SetBinError(j,err);
1253 Double_t xtrig=
GetBlocks(&hin,fpr,hout,ntrig);
1256 hout->SetEntries(
double(n));
1260 TString xtitle=
"Samplings (e.g. time)";
1261 TString ytitle=
"Measured value";
1262 TAxis* ax=gr.GetXaxis();
1266 if (str !=
"") xtitle=str;
1272 if (str !=
"") ytitle=str;
1274 title=
"Bayesian Block representation for TGraphErrors ";
1275 title+=gr.GetName();
1276 title+=
" with FPR=%-.3g;";
1280 str=title.Format(title,fpr);
1281 hout->SetTitle(str);
1545 cout <<
" *NcBlocks::GetBlocks* Error : Input histogram not specified." << endl;
1551 cout <<
" *NcBlocks::GetBlocks* Error : Output histogram not specified." << endl;
1555 Int_t nbins=hin->GetNbinsX();
1557 if (!nbins || n<1 || n>nbins || mode<0 || mode>2)
1559 cout <<
" *NcBlocks::GetBlocks* Inconsistent input nbins=" << nbins <<
" n=" << n <<
" mode=" << mode << endl;
1569 Double_t binwidth=0;
1574 TArrayD xarr(nbins);
1575 TArrayD yarr(nbins);
1578 for (Int_t i=0; i<n; i++)
1582 if (jbin>nbins)
break;
1584 x=hin->GetBinCenter(jbin);
1585 y=hin->GetBinContent(jbin);
1586 binwidth=hin->GetBinWidth(jbin);
1587 if (i==0) xlow=hin->GetBinLowEdge(jbin);
1591 if (mode==0) average=s.
GetMean(2);
1593 if (mode==2) average=s.
GetRMS(2);
1595 xarr.SetAt(xlow,nblocks-1);
1596 yarr.SetAt(average,nblocks-1);
1601 Double_t* xbins=
new Double_t[nblocks+1];
1602 Double_t* yvals=
new Double_t[nblocks+1];
1604 for (Int_t i=0; i<nblocks; i++)
1606 xbins[i]=xarr.At(i);
1607 yvals[i]=yarr.At(i);
1610 xbins[nblocks]=(1.+1e-6)*xup;
1611 yvals[nblocks]=yvals[nblocks-1];
1613 hout->SetBins(nblocks,xbins);
1614 for (Int_t i=1; i<=nblocks; i++)
1616 hout->SetBinContent(i,yvals[i-1]);
1620 hout->SetEntries(hin->GetEntries());
1622 hout->SetLineWidth(2);
1623 hout->SetLineColor(kBlue);
1624 hout->SetStats(kFALSE);
1628 title=
"Block representation for histogram ";
1629 title+=hin->GetName();
1630 title+=
" grouped in %-d consecutive bins";
1632 str=hin->GetXaxis()->GetTitle();
1633 if (str==
"") str=
"Recordings (e.g. time)";
1635 if (mode==0) title+=
";Mean ";
1636 if (mode==1) title+=
";Median ";
1637 if (mode==2) title+=
";RMS ";
1638 str=hin->GetYaxis()->GetTitle();
1639 if (str==
"") str=
"Counts";
1641 str=title.Format(title.Data(),n);
1642 hout->SetTitle(str.Data());
1960 cout <<
" *NcBlocks::GetBlocks* Error : Input TGraph not specified." << endl;
1966 cout <<
" *NcBlocks::GetBlocks* Error : Output histogram not specified." << endl;
1970 if (n<1 || mode<0 || mode>2)
1972 cout <<
" *NcBlocks::GetBlocks* Inconsistent input for TGraph treatment : n=" << n <<
" mode=" << mode << endl;
1976 Int_t npoints=gr->GetN();
1978 if (!npoints)
return 0;
1984 Double_t* xbins=
new Double_t[npoints+1];
1987 for (Int_t i=0; i<npoints; i++)
1989 gr->GetPoint(i,x,y);
1993 xbins[npoints]=(1.+1e-6)*xbins[npoints-1];
1995 TH1F hin(
"",
"",npoints,xbins);
1996 for (Int_t j=1; j<=npoints; j++)
1998 gr->GetPoint(j-1,x,y);
1999 hin.SetBinContent(j,y);
2002 Int_t nblocks=
GetBlocks(&hin,hout,n,mode);
2005 hout->SetEntries(
double(npoints));
2009 TString xtitle=
"Samplings (e.g. time)";
2010 TString ytitle=
"Measured value";
2011 TAxis* ax=gr->GetXaxis();
2015 if (str !=
"") xtitle=str;
2021 if (str !=
"") ytitle=str;
2023 title=
"Block representation for TGraph ";
2024 title+=gr->GetName();
2025 title+=
" grouped in %-d consecutive samples;";
2027 if (mode==0) title+=
";Mean ";
2028 if (mode==1) title+=
";Median ";
2029 if (mode==2) title+=
";RMS ";
2031 str=title.Format(title,n);
2032 hout->SetTitle(str);
2039Int_t
NcBlocks::Add(TH1* h1,TH1* h2,TH1* hout,Bool_t scale,Double_t c,Double_t d,Int_t mode)
2082 if (hout) hout->Reset();
2084 if (!h1 || !h2 || !hout)
return 1;
2086 Int_t ndim1=h1->GetDimension();
2087 Int_t ndim2=h2->GetDimension();
2088 Int_t ndimo=hout->GetDimension();
2090 if (ndim1!=1 || ndim2!=1 || ndimo!=1)
2092 cout <<
" *NcBlocks::Add* Error : Histograms should all be 1-dimensional." << endl;
2097 TString name=hout->GetName();
2101 TString name1=h1->GetName();
2102 if (name1==
"") name1=
"h1";
2104 TString name2=h2->GetName();
2105 if (name2==
"") name2=
"h2";
2111 sc.Form(
"%-+.3g",c);
2116 sd.Form(
"%-+.3g",d);
2118 TString title=
"Resulting histogram of: ";
2128 title+=
" (scaled w.r.t. bin size)";
2132 title+=
" (not scaled w.r.t. bin size)";
2135 TAxis* axis1=h1->GetXaxis();
2136 title+=axis1->GetTitle();
2138 axis1=h1->GetYaxis();
2139 title+=axis1->GetTitle();
2141 hout->SetName(name);
2142 hout->SetTitle(title);
2144 Int_t nb1=h1->GetNbinsX();
2145 Int_t nb2=h2->GetNbinsX();
2149 printf(
" *NcBlocks::Add* Error : nbins of h1 is %-i and nbins of h2 is %-i. \n",nb1,nb2);
2154 Double_t x1min=h1->GetXaxis()->GetXmin();
2155 Double_t x1max=h1->GetXaxis()->GetXmax();
2156 Double_t x2min=h2->GetXaxis()->GetXmin();
2157 Double_t x2max=h2->GetXaxis()->GetXmax();
2159 if (x1min>x2max || x1max<x2min)
2161 printf(
" *NcBlocks::Add* Error : The ranges of the input histograms do not overlap. \n");
2170 Double_t bwidth1=h1->GetBinWidth(i1);
2171 Double_t x1low=h1->GetBinLowEdge(i1);
2172 Double_t x1up=x1low+bwidth1;
2187 Double_t epsilon=1e-10;
2192 y1=h1->GetBinContent(i1);
2194 i2=h2->FindFixBin(x1low+fabs(epsilon*x1low));
2195 i2up=h2->FindFixBin(x1up+fabs(epsilon*x1up));
2197 if ((i2<1 && i2up<1) || (i2>nb2 && i2up>nb2) || x1up<=x1low || (mode<0 && c<0 && !y1) || (mode>0 && c>0 && !y1))
2201 if (x1up>x1low) s.
Enter(x1low,y);
2204 x1low=h1->GetBinLowEdge(i1);
2205 bwidth1=h1->GetBinWidth(i1);
2213 x2low=h2->GetBinLowEdge(i2);
2214 bwidth2=h2->GetBinWidth(i2);
2216 y2=h2->GetBinContent(i2);
2224 if (x1up>x1low) s.
Enter(xlow,y);
2227 if (x2up<xup) xup=x2up;
2236 frac1=(xup-xlow)/bwidth1;
2237 frac2=(xup-xlow)/bwidth2;
2244 if (frac1>epsilon && frac2>epsilon) s.
Enter(xlow,y);
2246 i1=h1->FindFixBin(x1low+fabs(epsilon*x1low));
2247 bwidth1=h1->GetBinWidth(i1);
2248 x1up=bwidth1+h1->GetBinLowEdge(i1);
2255 Int_t nbins=s.
GetN();
2256 Double_t* xbins=
new Double_t[nbins+1];
2258 for (Int_t i=0; i<nbins; i++)
2267 hout->SetBins(nbins,xbins);
2269 for (Int_t jbin=1; jbin<=nbins; jbin++)
2272 hout->SetBinContent(jbin,y);
2276 hout->SetEntries(h1->GetEntries());
2307 if (gout) gout->Set(0);
2309 if (!gr || !h || !gout)
return 1;
2311 TString nameg=gr->GetName();
2312 if (nameg==
"") nameg=
"gr";
2314 TString nameh=h->GetName();
2315 if (nameh==
"") nameh=
"h";
2321 sc.Form(
"%-+.3g",c);
2326 sd.Form(
"%-+.3g",d);
2328 TString title=
"Resulting graph of: ";
2338 axis=gr->GetXaxis();
2339 title+=axis->GetTitle();
2341 axis=gr->GetYaxis();
2342 title+=axis->GetTitle();
2344 gout->SetTitle(title);
2346 Int_t ndim=h->GetDimension();
2350 cout <<
" *NcBlocks::Add* Error : Histogram " << nameh <<
" should be 1-dimensional." << endl;
2354 Int_t np=gr->GetN();
2355 Int_t nb=h->GetNbinsX();
2357 if (!np || !nb)
return 1;
2368 for (Int_t i=0; i<np; i++)
2370 gr->GetPoint(i,x,y);
2371 hbin=axis->FindFixBin(x);
2372 hval=h->GetBinContent(hbin);
2375 if (hbin<1 || hbin>nb)
continue;
2378 gout->SetPoint(i,x,ynew);
2380 if (gr->InheritsFrom(
"TGraphErrors") && gout->InheritsFrom(
"TGraphErrors"))
2382 TGraphErrors* gre=(TGraphErrors*)gr;
2383 TGraphErrors* goute=(TGraphErrors*)gout;
2384 ex=gre->GetErrorX(i);
2385 ey=gre->GetErrorY(i);
2386 goute->SetPointError(i,ex,ey);
2428 if (hout) hout->Reset();
2432 printf(
" *NcBlocks::Divide* Error : Invalid value c=0. \n");
2436 if (!h1 || !h2 || !hout)
return 1;
2438 Int_t ndim1=h1->GetDimension();
2439 Int_t ndim2=h2->GetDimension();
2440 Int_t ndimo=hout->GetDimension();
2442 if (ndim1!=1 || ndim2!=1 || ndimo!=1)
2444 cout <<
" *NcBlocks::Divide* Error : Histograms should all be 1-dimensional." << endl;
2449 TString name=hout->GetName();
2453 TString name1=h1->GetName();
2454 if (name1==
"") name1=
"h1";
2456 TString name2=h2->GetName();
2457 if (name2==
"") name2=
"h2";
2460 if (fabs(c)!=1) sc.Form(
"%-.3g*",fabs(c));
2466 if (d) sd.Form(
"%-.3g+",d);
2471 if (d) sd.Form(
"%-.3g-",d);
2474 TString title=
"Resulting histogram of: ";
2475 if (sd!=
"") title+=sd;
2479 if (sc.Contains(
"*")) title+=
"/(";
2482 if (sc.Contains(
"*")) title+=
")";
2486 title+=
" (scaled w.r.t. bin size)";
2490 title+=
" (not scaled w.r.t. bin size)";
2493 TAxis* axis1=h1->GetXaxis();
2494 title+=axis1->GetTitle();
2496 axis1=h1->GetYaxis();
2497 title+=axis1->GetTitle();
2499 hout->SetName(name);
2500 hout->SetTitle(title);
2502 Int_t nb1=h1->GetNbinsX();
2503 Int_t nb2=h2->GetNbinsX();
2507 printf(
" *NcBlocks::Divide* Error : nbins of h1 is %-i and nbins of h2 is %-i. \n",nb1,nb2);
2512 Double_t x1min=h1->GetXaxis()->GetXmin();
2513 Double_t x1max=h1->GetXaxis()->GetXmax();
2514 Double_t x2min=h2->GetXaxis()->GetXmin();
2515 Double_t x2max=h2->GetXaxis()->GetXmax();
2517 if (x1min>x2max || x1max<x2min)
2519 printf(
" *NcBlocks::Divide* Error : The ranges of the input histograms do not overlap. \n");
2528 Double_t bwidth1=h1->GetBinWidth(i1);
2529 Double_t x1low=h1->GetBinLowEdge(i1);
2530 Double_t x1up=x1low+bwidth1;
2546 Double_t epsilon=1e-10;
2549 while (i1<=nb1 && i2<=nb2)
2551 i2=h2->FindFixBin(x1low+fabs(epsilon*x1low));
2552 i2up=h2->FindFixBin(x1up+fabs(epsilon*x1up));
2554 if ((i2<1 && i2up<1) || (i2>nb2 && i2up>nb2) || x1up<=x1low)
2557 x1low=h1->GetBinLowEdge(i1);
2558 bwidth1=h1->GetBinWidth(i1);
2563 y1=h1->GetBinContent(i1);
2570 x1low=h1->GetBinLowEdge(i1);
2571 bwidth1=h1->GetBinWidth(i1);
2579 x2low=h2->GetBinLowEdge(i2);
2580 bwidth2=h2->GetBinWidth(i2);
2582 y2=h2->GetBinContent(i2);
2585 if (x2low>xlow) xlow=x2low;
2586 if (x2up<xup) xup=x2up;
2595 frac1=(xup-xlow)/bwidth1;
2596 frac2=(xup-xlow)/bwidth2;
2604 if (val) y=d+y1/val;
2605 if (frac1>epsilon && frac2>epsilon) s.
Enter(xlow,y);
2607 i1=h1->FindFixBin(x1low+fabs(epsilon*x1low));
2608 bwidth1=h1->GetBinWidth(i1);
2609 x1up=bwidth1+h1->GetBinLowEdge(i1);
2616 Int_t nbins=s.
GetN();
2617 Double_t* xbins=
new Double_t[nbins+1];
2619 for (Int_t i=0; i<nbins; i++)
2626 if (x2max<x1max) xup=x2max;
2629 hout->SetBins(nbins,xbins);
2631 for (Int_t jbin=1; jbin<=nbins; jbin++)
2634 hout->SetBinContent(jbin,y);
2638 hout->SetEntries(h1->GetEntries());
2667 if (gout) gout->Set(0);
2671 printf(
" *NcBlocks::Divide* Error : Invalid value c=0. \n");
2675 if (!gr || !h || !gout)
return 1;
2677 TString nameg=gr->GetName();
2678 if (nameg==
"") nameg=
"gr";
2680 TString nameh=h->GetName();
2681 if (nameh==
"") nameh=
"h";
2684 if (fabs(c)!=1) sc.Form(
"%-.3g*",fabs(c));
2690 if (d) sd.Form(
"%-.3g+",d);
2695 if (d) sd.Form(
"%-.3g-",d);
2698 TString title=
"Resulting graph of: ";
2699 if (sd!=
"") title+=sd;
2703 if (sc.Contains(
"*")) title+=
"/(";
2706 if (sc.Contains(
"*")) title+=
")";
2710 axis=gr->GetXaxis();
2711 title+=axis->GetTitle();
2713 axis=gr->GetYaxis();
2714 title+=axis->GetTitle();
2716 gout->SetTitle(title);
2718 Int_t ndim=h->GetDimension();
2722 cout <<
" *NcBlocks::Divide* Error : Histogram " << nameh <<
" should be 1-dimensional." << endl;
2726 Int_t np=gr->GetN();
2727 Int_t nb=h->GetNbinsX();
2729 if (!np || !nb)
return 1;
2742 for (Int_t i=0; i<np; i++)
2744 gr->GetPoint(i,x,y);
2745 hbin=axis->FindFixBin(x);
2746 hval=h->GetBinContent(hbin);
2749 if (hbin<1 || hbin>nb)
continue;
2755 gout->SetPoint(j,x,ynew);
2757 if (gr->InheritsFrom(
"TGraphErrors") && gout->InheritsFrom(
"TGraphErrors"))
2759 TGraphErrors* gre=(TGraphErrors*)gr;
2760 TGraphErrors* goute=(TGraphErrors*)gout;
2761 ex=gre->GetErrorX(i);
2762 ey=gre->GetErrorY(i);
2763 goute->SetPointError(j,ex,ey);
2807 if (hout) hout->Reset();
2809 if (!h1 || !h2 || !hout)
return 1;
2811 Int_t ndim1=h1->GetDimension();
2812 Int_t ndim2=h2->GetDimension();
2813 Int_t ndimo=hout->GetDimension();
2815 if (ndim1!=1 || ndim2!=1 || ndimo!=1)
2817 cout <<
" *NcBlocks::Multiply* Error : Histograms should all be 1-dimensional." << endl;
2822 TString name=hout->GetName();
2826 TString name1=h1->GetName();
2827 if (name1==
"") name1=
"h1";
2829 TString name2=h2->GetName();
2830 if (name2==
"") name2=
"h2";
2833 if (fabs(c)!=1) sc.Form(
"%-.3g*",fabs(c));
2839 if (d) sd.Form(
"%-.3g+",d);
2844 if (d) sd.Form(
"%-.3g-",d);
2847 TString title=
"Resulting histogram of: ";
2848 if (sd!=
"") title+=sd;
2855 title+=
" (scaled w.r.t. bin size)";
2859 title+=
" (not scaled w.r.t. bin size)";
2862 TAxis* axis1=h1->GetXaxis();
2863 title+=axis1->GetTitle();
2865 axis1=h1->GetYaxis();
2866 title+=axis1->GetTitle();
2868 hout->SetName(name);
2869 hout->SetTitle(title);
2871 Int_t nb1=h1->GetNbinsX();
2872 Int_t nb2=h2->GetNbinsX();
2876 printf(
" *NcBlocks::Multiply* Error : nbins of h1 is %-i and nbins of h2 is %-i. \n",nb1,nb2);
2881 Double_t x1min=h1->GetXaxis()->GetXmin();
2882 Double_t x1max=h1->GetXaxis()->GetXmax();
2883 Double_t x2min=h2->GetXaxis()->GetXmin();
2884 Double_t x2max=h2->GetXaxis()->GetXmax();
2886 if (x1min>x2max || x1max<x2min)
2888 printf(
" *NcBlocks::Multiply* Error : The ranges of the input histograms do not overlap. \n");
2897 Double_t bwidth1=h1->GetBinWidth(i1);
2898 Double_t x1low=h1->GetBinLowEdge(i1);
2899 Double_t x1up=x1low+bwidth1;
2915 Double_t epsilon=1e-10;
2918 while (i1<=nb1 && i2<=nb2)
2920 i2=h2->FindFixBin(x1low+fabs(epsilon*x1low));
2921 i2up=h2->FindFixBin(x1up+fabs(epsilon*x1up));
2923 if ((i2<1 && i2up<1) || (i2>nb2 && i2up>nb2) || x1up<=x1low)
2926 x1low=h1->GetBinLowEdge(i1);
2927 bwidth1=h1->GetBinWidth(i1);
2932 y1=h1->GetBinContent(i1);
2939 x1low=h1->GetBinLowEdge(i1);
2940 bwidth1=h1->GetBinWidth(i1);
2948 x2low=h2->GetBinLowEdge(i2);
2949 bwidth2=h2->GetBinWidth(i2);
2951 y2=h2->GetBinContent(i2);
2954 if (x2low>xlow) xlow=x2low;
2955 if (x2up<xup) xup=x2up;
2964 frac1=(xup-xlow)/bwidth1;
2965 frac2=(xup-xlow)/bwidth2;
2974 if (frac1>epsilon && frac2>epsilon) s.
Enter(xlow,y);
2976 i1=h1->FindFixBin(x1low+fabs(epsilon*x1low));
2977 bwidth1=h1->GetBinWidth(i1);
2978 x1up=bwidth1+h1->GetBinLowEdge(i1);
2985 Int_t nbins=s.
GetN();
2986 Double_t* xbins=
new Double_t[nbins+1];
2988 for (Int_t i=0; i<nbins; i++)
2995 if (x2max<x1max) xup=x2max;
2998 hout->SetBins(nbins,xbins);
3000 for (Int_t jbin=1; jbin<=nbins; jbin++)
3003 hout->SetBinContent(jbin,y);
3007 hout->SetEntries(h1->GetEntries());
3036 if (gout) gout->Set(0);
3038 if (!gr || !h || !gout)
return 1;
3040 TString nameg=gr->GetName();
3041 if (nameg==
"") nameg=
"gr";
3043 TString nameh=h->GetName();
3044 if (nameh==
"") nameh=
"h";
3047 if (fabs(c)!=1) sc.Form(
"%-.3g*",fabs(c));
3053 if (d) sd.Form(
"%-.3g+",d);
3058 if (d) sd.Form(
"%-.3g-",d);
3061 TString title=
"Resulting graph of: ";
3062 if (sd!=
"") title+=sd;
3069 axis=gr->GetXaxis();
3070 title+=axis->GetTitle();
3072 axis=gr->GetYaxis();
3073 title+=axis->GetTitle();
3075 gout->SetTitle(title);
3077 Int_t ndim=h->GetDimension();
3081 cout <<
" *NcBlocks::Multiply* Error : Histogram " << nameh <<
" should be 1-dimensional." << endl;
3085 Int_t np=gr->GetN();
3086 Int_t nb=h->GetNbinsX();
3088 if (!np || !nb)
return 1;
3101 for (Int_t i=0; i<np; i++)
3103 gr->GetPoint(i,x,y);
3104 hbin=axis->FindFixBin(x);
3105 hval=h->GetBinContent(hbin);
3108 if (hbin<1 || hbin>nb)
continue;
3114 gout->SetPoint(j,x,ynew);
3116 if (gr->InheritsFrom(
"TGraphErrors") && gout->InheritsFrom(
"TGraphErrors"))
3118 TGraphErrors* gre=(TGraphErrors*)gr;
3119 TGraphErrors* goute=(TGraphErrors*)gout;
3120 ex=gre->GetErrorX(i);
3121 ey=gre->GetErrorY(i);
3122 goute->SetPointError(j,ex,ey);
3131Int_t
NcBlocks::Rebin(TH1* hin,TH1* hout,Bool_t scale,Int_t nbins,Double_t xmin,Double_t xmax)
3168 if (hout) hout->Reset();
3170 if (!hin || !hout)
return 0;
3172 Int_t ndimi=hin->GetDimension();
3173 Int_t ndimo=hout->GetDimension();
3175 if (ndimi!=1 || ndimo!=1)
3177 cout <<
" *NcBlocks::Rebin* Error : Histograms should both be 1-dimensional." << endl;
3181 Int_t nb1=hin->GetNbinsX();
3185 TAxis* xaxis=hin->GetXaxis();
3186 TAxis* yaxis=hin->GetYaxis();
3190 xmin=xaxis->GetXmin();
3191 xmax=xaxis->GetXmax();
3202 for (Int_t i=1; i<=nb1; i++)
3204 bwidth1=hin->GetBinWidth(i);
3205 xlow1=hin->GetBinLowEdge(i);
3208 if (xlow1>=xmax || xup1<=xmin)
continue;
3210 if (bwmin<0 || bwidth1<bwmin) bwmin=bwidth1;
3215 cout <<
" *NcBlocks::Rebin* Error : Input histogram had no data in requested interval [xmin,xmax]." << endl;
3219 Double_t rnbins=(xmax-xmin)/bwmin;
3221 Double_t diff=rnbins-double(nbins);
3222 if (diff) nbins=nbins+1;
3225 hout->SetBins(nbins,xmin,xmax);
3226 Double_t bwidth=hout->GetBinWidth(1);
3228 TString name=hin->GetName();
3229 if (name==
"") name=
"hin";
3232 snb.Form(
" nbins=%-i",nbins);
3235 smin.Form(
" xmin=%-.3g",xmin);
3238 smax.Form(
" xmax=%-.3g",xmax);
3240 TString title=
"Uniformly binned version of histogram: ";
3247 title+=
" (scaled w.r.t. bin size)";
3251 title+=
" (not scaled w.r.t. bin size)";
3254 title+=xaxis->GetTitle();
3256 title+=yaxis->GetTitle();
3258 hout->SetTitle(title);
3261 for (Int_t i=1; i<=nb1; i++)
3263 bwidth1=hin->GetBinWidth(i);
3264 xlow1=hin->GetBinLowEdge(i);
3267 if (xlow1>=xmax || xup1<=xmin)
continue;
3271 printf(
" *NcBlocks::Rebin* Error : Input histogram had finer binning than output histogram. \n");
3272 printf(
" Input: binwidth=%-g for bin=%-i Output: uniform binwidth=%-g \n",bwidth1,i,bwidth);
3281 for (Int_t i=1; i<=nbins; i++)
3283 x=hout->GetBinCenter(i);
3284 i1=xaxis->FindFixBin(x);
3287 if (i1<1 || i1>nb1)
continue;
3289 y1=hin->GetBinContent(i1);
3290 bwidth1=hin->GetBinWidth(i1);
3291 if (scale) y1=y1*bwidth/bwidth1;
3292 hout->SetBinContent(i,y1);