I am having a multigraph, in which I am plotting 3 curves.
I want each plot to have an expo fit and each stat box to be printed in different color. The code I am using is
[code]# include “TCanvas.h”
include “TROOT.h”
include “TGraphErrors.h”
include “TStyle.h”
include “TMultiGraph.h”
include “TF1.h”
include “TLegend.h”
include “TPaveStats.h”
include “TArrow.h”
include “TLatex.h”
include “TPaveText.h”
include “TText.h”
include “TPavesText.h”
void gainCurves(){
gROOT->Reset();
TCanvas *mycanvas = new TCanvas("c","c",600, 400);
mycanvas->SetFillColor(kSpring-8);
mycanvas->SetFrameFillColor(10);
TMultiGraph * mg = new TMultiGraph("gain curves","GAIN CURVES");
// The values on the X,Y axes and error on Y axis
//Vdrift=700V
const int n_700=15;
double x_700[n_700]={500,505,510,515,520,525,530,535,540,545,550,555,560,565,570};
double y_700[n_700]={1409,1648.5,1918.5,2188,2578,2937.5,3417,3837,4796,5695.5,6924,8183,9712,11660.5,13728.5};
double errorY_700[n_700];
for (int i=0; i<n_700; i++){
errorY_700[i]=300;
}
//Vdrift=750V
const int n_750=15;
double x_750[n_750]={500,505,510,515,520,525,530,535,540,545,550,555,560,565,570};
double y_750[n_750]={1349,1648.5,1918.5,2128,2518,3027.5,3567,4196.5,4916,5605.5,6864.5,8872.5,9622,11420.5,13608.5};
double errorY_750[n_750];
for (int i=0; i<n_750; i++){
errorY_750[i]=300;
}
//Vdrift=850V
const int n_850=11;
double x_850[n_850]={500,510,520,530,540,550,555,560,565,570,575};
double y_850[n_850]={1259,1768.5,2398,3327,4616,6564.5,7733.5,9322,11061,13489,16366.5};
double errorY_850[n_850];
for (int i=0; i<n_850; i++){
errorY_850[i]=300;
}
gROOT->SetStyle("Plain");
// See: http://root.cern.ch/root/html/TStyle.html#TStyle:SetOptFit
gStyle->SetOptFit(1111);
TGraphErrors * gr1 = new TGraphErrors( n_700, x_700, y_700, NULL, errorY_700);
gr1->SetName(“gr1”);
gr1->SetTitle(“V_{drift}=700VV”);
gr1->SetMarkerStyle(20);
gr1->SetMarkerColor(4);
gr1->SetDrawOption(“AP”);
gr1->SetLineColor(4);
gr1->SetLineWidth(1);
gr1->SetFillStyle(0);
TGraphErrors * gr2 = new TGraphErrors( n_750, x_750, y_750, NULL, errorY_750);
gr2->SetName(“gr2”);
gr2->SetTitle(“V_{drift}=750V”);
gr2->SetMarkerStyle(20);
gr2->SetMarkerColor(2);
gr2->SetDrawOption(“AP”);
gr2->SetLineColor(2);
gr2->SetLineWidth(1);
gr2->SetFillStyle(0);
TGraphErrors * gr3 = new TGraphErrors( n_850, x_850, y_850, NULL, errorY_850);
gr3->SetName(“gr3”);
gr3->SetTitle(“V_{drift}=850V”);
gr3->SetMarkerStyle(20);
gr3->SetMarkerColor(3);
gr3->SetDrawOption(“AP”);
gr3->SetLineColor(3);
gr3->SetLineWidth(1);
gr3->SetFillStyle(0);
gr1->Fit(“expo”);
gr1->GetFunction(“expo”)->SetLineColor(gr1->GetLineColor());
gr1->GetFunction(“expo”)->SetLineWidth(2);
//gr1->Print(“all”);
gr2->Fit(“expo”);
gr2->GetFunction(“expo”)->SetLineColor(gr2->GetLineColor());
gr2->GetFunction(“expo”)->SetLineWidth(2);
gr3->Fit(“expo”);
gr3->GetFunction(“expo”)->SetLineColor(gr3->GetLineColor());
gr3->GetFunction(“expo”)->SetLineWidth(2);
TPaveStats st = ((TPaveStats)(gr1->GetListOfFunctions()->FindObject(“stats”)));
if (st) {
st->SetTextColor(gr1->GetLineColor());
st->SetX1NDC(0.3); st->SetX2NDC(0.7);
st->SetY1NDC(0.3); st->SetY2NDC(0.7);
}
st = ((TPaveStats*)(gr2->GetListOfFunctions()->FindObject(“stats”)));
if (st) {
st->SetTextColor(gr2->GetLineColor());
st->SetX1NDC(0.64); st->SetX2NDC(0.99);
st->SetY1NDC(0.15); st->SetY2NDC(0.35);
}
st = ((TPaveStats*)(gr3->GetListOfFunctions()->FindObject(“stats”)));
if (st) {
st->SetTextColor(gr3->GetLineColor());
st->SetX1NDC(0.64); st->SetX2NDC(0.99);
st->SetY1NDC(0.45); st->SetY2NDC(0.55);
}
mg->Add(gr2);
mg->Add(gr1);
mg->Add(gr3);
mg->Draw(“AP”);
mg->SetTitle(“Gain Curves for NTUASmm1;V_{mesh}[V];Gain”);
mycanvas->BuildLegend(0.85, 0.8, 0.99, 0.99,“Ar-CO2–>93%-7%”);
mycanvas->SetLogy(1);
mycanvas->Modified();
mycanvas->Update(); // make sure it’s really (re)drawn
mycanvas->Print(“gainCurves.pdf”);
}
[/code]
This code was working with 2 curves. Do you think that it cannot work with 3(I don’t really think so…)?
How can this be fixed?
Thank you in advance!