Getting different "Average graph" using root and coral-draw

Hello,

I am trying to draw “Averge graph” with all other branches data in TTree using ROOT. Please find the attachment of “ApproxAverage.pdf”.

I am trying to draw a same graph with CORAL-DRAW. Please find the attachement of “Graph.pdf”. By using CORAL-DRAW the Average Graph is exactly in middle of S1 and S4.

But with ROOT all the graphs are same but “Average graph” is lying approximately on S4 graph.

My code for calculating Average graph is as follows:

     TFile *f1 = TFile::Open("graph.root");
 TTree *T1 = (TTree*)f1->Get("abc");
     T1->Draw("((S0+S1+S2+S3+S4)/5):T", cut3, "same");  
	 TGraph *gr1 = new TGraph(T1->GetSelectedRows(),T1->GetV2(), T1->GetV1());
     gr1->SetLineColor(kRed);

It is calculating average correctly. But while plotting a graph in ROOT why it is the difference? I am expecting a graph which getting with Coral-Draw. How to do it?

I am looking for the guidance.

Thank you.
Graph.pdf (145 KB)
ApproxAverage.pdf (19.3 KB)

Before you “T1->Draw(…);”, try to add:
T1->SetEstimate(T1->GetEntries() + 1);
Also, instead of drawing a “smooth curve”, draw a “simple polyline” plus a “star at each point” (i.e. try the “L*” TGraph drawing options). I think the shape of the “smooth curve” may be influenced by some very first points of your TGraph for which the “Sx” value is 0, for “Time” < 0 (try to get rid of these points adding appropriate conditions into your “cut”).

Hello,

Thanks for the reply.

I tried to add T1->SetEstimate(T1->GetEntries() + 1); before T1->Draw(). But it’s not helping. Also, I tried to use TCut method but still not working. Would you recommend some other option? My .data file is attached here with.

Thank you.
DATA.txt (12.3 KB)

I would need a description of “variables” that appear in your data file (so that I can use TTree::ReadFile to create a TTree out of it) plus a definition of your “cut3” (so that I can reproduce your picture).

As a starting point, try this: [code]{
TTree *T1 = new TTree(“T1”, “T1”);
T1->ReadFile(“DATA.txt”,
“T:S0:S1:S2:S3:S4:S5:S6:S7:S8:S9:S10:S11:S12:S13:S14”);
// T1->SetEstimate(T1->GetEntries() + 1); // if n_entries > 1000000

TCut cut3 = “1”; // “1” = “take all”

TGraph g0, g1, g2, g3, g4, g5, ga;
T1->Draw(“S0:T”, cut3);
g0 = (TGraph
)gPad->GetPrimitive(“Graph”)->Clone(“g0”);
g0->SetMarkerStyle(kFullSquare); g0->SetMarkerSize(0.5);
g0->SetLineColor(kRed); g0->SetMarkerColor(g0->GetLineColor());
T1->Draw(“S1:T”, cut3);
g1 = (TGraph
)gPad->GetPrimitive(“Graph”)->Clone(“g1”);
g1->SetMarkerStyle(kFullSquare); g1->SetMarkerSize(0.5);
g1->SetLineColor(kGreen); g1->SetMarkerColor(g1->GetLineColor());
T1->Draw(“S2:T”, cut3);
g2 = (TGraph
)gPad->GetPrimitive(“Graph”)->Clone(“g2”);
g2->SetMarkerStyle(kFullSquare); g2->SetMarkerSize(0.5);
g2->SetLineColor(kBlue); g2->SetMarkerColor(g2->GetLineColor());
T1->Draw(“S3:T”, cut3);
g3 = (TGraph
)gPad->GetPrimitive(“Graph”)->Clone(“g3”);
g3->SetMarkerStyle(kFullSquare); g3->SetMarkerSize(0.5);
g3->SetLineColor(kMagenta); g3->SetMarkerColor(g3->GetLineColor());
T1->Draw(“S4:T”, cut3);
g4 = (TGraph
)gPad->GetPrimitive(“Graph”)->Clone(“g4”);
g4->SetMarkerStyle(kFullSquare); g4->SetMarkerSize(0.5);
g4->SetLineColor(kCyan); g4->SetMarkerColor(g4->GetLineColor());
T1->Draw(“S5:T”, cut3);
g5 = (TGraph
)gPad->GetPrimitive(“Graph”)->Clone(“g5”);
g5->SetMarkerStyle(kFullSquare); g5->SetMarkerSize(0.5);
g5->SetLineColor(kBlack); g5->SetMarkerColor(g5->GetLineColor());
T1->Draw("(S0+S1+S2+S3+S4)/5.0:T", cut3);
ga = (TGraph
)gPad->GetPrimitive(“Graph”)->Clone(“ga”);
ga->SetMarkerStyle(kFullSquare); ga->SetMarkerSize(0.5);
ga->SetLineColor(46); ga->SetMarkerColor(ga->GetLineColor()); // 46 = brown

gPad->Clear();

TMultiGraph *mg = new TMultiGraph(“mg”, “”);
mg->Add(g0);
mg->Add(g1);
mg->Add(g2);
mg->Add(g3);
mg->Add(g4);
mg->Add(g5);
mg->Add(ga);
mg->Draw(“APL”); // “APL” or “APC”
}[/code]

Hello,

Thanks. It works.