Newbie: Graphing error

Hi, I’m a newbie and I’ve been trying to graph a set of data written in a txt file.
I think Everything has been set up correctly in my program yet whenever I run it on root with .x function, it gives me as a feedback an error message and subsequently ends itself:

Blockquote
root [0] .x rl.C
Assertion failed: isSingleDecl() && “Isn’t a single decl”, file C:\build\ws\BUILDTYPE\Release\LABEL\windows10\V\6-18\root\interpreter\llvm\src\tools\clang\include\clang/AST/DeclGroup.h, line 87

What I’m trying to do is graph my data and also set my error bars. My program is here:

{
	double t=0, Vl=0, Vr=0;

	myGraph1 = new TGraphErrors("Vl.txt");
	myGraph1->SetPoint(myGraph1->GetN(), t, Vl);
	myGraph1->SetPointError(myGraph1->GetN()-1, 0, 0.1);
	myGraph1->SetMarkerStyle(21);
	myGraph1->SetMarkerSize(0.8);
	myGraph1->SetLineColor(kBlue+1);
	myGraph1->SetTitle("Caratterizzazione di un circuito RL; Tempo [ms]; Potenziale V [V] ");
	myGraph1->Draw("AP");
	
	mygraph2 = new TGraphErrors("Vr.txt");
	myGraph2->SetPoint(myGraph2->GetN(), t, Vr);
	myGraph2->SetPointError(myGraph2->GetN()-1, 0, 0.1);
	ci = TColor::GetColor("#66cccc");
	myGraph2->SetMarkerStyle(23);
	myGraph2->SetMarkerSize(0.8);
	myGraph2->SetMarkerColor(ci);
	myGraph2->SetLineColor(kBlue+1);
	myGraph2->Draw("P Same");
	
}

Hope someone can help me, thank you very much in advance.
_
Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Try with:
auto myGraph1 = new ...
auto myGraph2 = new ...
auto ci = ...

if you mean implementing it like this:

{
	double t=0, Vl=0, Vr=0;
	
	auto myGraph1 = new TGraphErrors("Vl.txt");
	myGraph1->SetPoint(myGraph1->GetN(), 0, 0);
	myGraph1->SetPointError(myGraph1->GetN()-1, 0, 0.1);
	myGraph1->SetMarkerStyle(21);
	myGraph1->SetMarkerSize(0.8);
	myGraph1->SetLineColor(kBlue+1);
	myGraph1->SetTitle("Caratterizzazione di un circuito RL; Tempo [ms]; Potenziale V [V] ");
	myGraph1->Draw("AP");
	
	auto mygraph2 = new TGraphErrors("Vr.txt");
	myGraph2->SetPoint(myGraph2->GetN(), 0, 0);
	myGraph2->SetPointError(myGraph2->GetN()-1, 0, 0.1);
	auto ci = TColor::GetColor("#66cccc");
	myGraph2->SetMarkerStyle(23);
	myGraph2->SetMarkerSize(0.8);
	myGraph2->SetMarkerColor(ci);
	myGraph2->SetLineColor(kBlue+1);
	myGraph2->Draw("Same");
	
}

I tried, yet it still gives me the same error :confused:

Try with:
TGraphErrors *myGraph1 = new ...
TGraphErrors *myGraph2 = new ...
Int_t ci = ...

Note that you sometimes use “mygraph...” and sometimes “myGraph...”.

Also, graphs do not have the “SAME” draw option at all (it’s not needed).

It somehow fixed by itself? I am so confused. Yet another problem persists, it doesn’t show me any bar errors.

{
	t=0, Vl=0, Vr=0;
	
	myGraph1 = new TGraphErrors("843931.txt", "%lg %lg %*lg");
	myGraph1->SetPoint(myGraph1->GetN(), t, Vl);
	myGraph1->SetPointError(myGraph1->GetN()-1, 0, 0.1);
	myGraph1->SetMarkerStyle(21);
	myGraph1->SetMarkerSize(0.8);
	myGraph1->SetLineColor(kBlue+1);
	myGraph1->SetTitle("Caratterizzazione di un circuito RL; Tempo [ms]; Potenziale V [V] ");
	myGraph1->Draw("AP");
	
	myGraph2 = new TGraphErrors("843931.txt", "%lg %*lg %lg");
	myGraph2->SetPoint(myGraph2->GetN(), t, Vr);
	myGraph2->SetPointError(myGraph2->GetN()-1, 0, 0.1);
	ci = TColor::GetColor("#66cccc");
	myGraph2->SetMarkerStyle(23);
	myGraph2->SetMarkerSize(0.8);
	myGraph2->SetMarkerColor(ci);
	myGraph2->SetLineColor(kBlue+1);
	myGraph2->Draw("P");
	
}

You do not read errors from your data file.

I am not trying to read them, infact I am trying to associate a fixed Error to the data that my program is reading from the txt file

Thank you so much for your help btw :slight_smile:

You need to loop over all points and set an error for each of them.

So i need to create a while(true), read from the files and set the error right?

No, after you have all points read, just add a for loop which sets errors to your desired value.
for (int i = 0; i < myGraph1->GetN(); i++) myGraph1->SetPointError(i, 0., 0.1);

1 Like

That fixed it! I read the macro and the way it was setup it set my error as 0 non stop.

Thank you so much!