# Draw problem : command terminal draw a different graph compare to my programm

**URL:** <https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282>\
**Category:** Newbie\
**Created:** [June 7, 2021, 10:19am UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282 "2021-06-07T10:19:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![IKoro](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@IKoro](https://root-forum.cern.ch/u/IKoro)\
**Post date:** [June 7, 2021, 10:19am UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/1 "2021-06-07T10:19:29Z")

</div>

Hello, i have a problem with my draw, because he work for the 9 graphs but for one he didn’t function.

void OMline2() {  
//gStyle-\>SetOptStat(0);  
//gStyle-\>SetOptFit(1111);

TCanvas \*c1 = new TCanvas();

TFile \*input = new TFile("/home/kdupuy/Documents/code\_final/fichier\_root/valeurspicstest.root",“READ”);

TTree _tree = (TTree_)input-\>Get(“valeurspicstest\_tree;1”);

double Constant1, Mean1, Sigma1, om\_number1;  
int pics, intensity, Entries;  
Double\_t error1, error2, error3;  
Double\_t x[6], y[6],ex[6],ey[6];  
Int\_t n = 6;  
Double\_t fquality;

tree-\>SetBranchAddress(“om\_number1”, &om\_number1);  
tree-\>SetBranchAddress(“Constant1”, &Constant1);  
tree-\>SetBranchAddress(“Mean1”, &Mean1);  
tree-\>SetBranchAddress(“Sigma1”, &Sigma1);  
tree-\>SetBranchAddress(“pics”, &pics);  
tree-\>SetBranchAddress(“intensity”, &intensity);  
tree-\>SetBranchAddress(“error1”, &error1);  
tree-\>SetBranchAddress(“error2”, &error2);  
tree-\>SetBranchAddress(“error3”, &error3);  
tree-\>SetBranchAddress(“fquality”, &fquality);  
tree-\>SetBranchAddress(“Entries”, &Entries);

int entries = tree-\>GetEntries();

for (int j = 0; j \<=12; j++ )  
{  
TF1 _fit7 = new TF1(“fit7”, “pol2”, 60,130);  
TGraph_ gr = new TGraphErrors(n,x,y,ex,ey);  
for (int i=0; i \< entries; i++)  
{  
tree-\>GetEntry(i);

```
  if (om_number1 == j && Entries > 600 ) //&& fquality < 2.2)
  {
        cout << "pics" << pics<< endl;
        x[pics] = intensity;
        cout <<"itensity ==" << intensity << endl;
        cout <<"Mean ==" << Mean1 << endl;

        y[pics] = Mean1;

        cout << "Mean2" << y[pics] << endl;
        cout << error2 << endl;
        ey[pics] = error2;

        ex[pics] = 0;

   }
   if (om_number1 == j && Entries < 600)
   {
     gr->RemovePoint(pics);
   }

```

}

//printf(“Number of points before RemovePoint: %d\n”, gr-\>GetN());  
//printf(“Number of points after RemovePoint: %d\n”, gr-\>GetN());

gr-\>SetTitle(“Linearite “);  
gr-\>SetMarkerColor(4);  
gr-\>SetMarkerStyle(20);  
gr-\>Draw(“AP”);  
gr-\>Fit(“fit7”,“R”);  
c1-\>Print(Form(”/home/kdupuy/Documents/code\_final/Line2/%03i.png”, j));  
//delete gr;  
}

}

* * *

[valeurspicstest.root](https://root-forum.cern.ch/uploads/short-url/4p2B6Mtb139nnjolDxAc7zzcxOi.root) (11.3 KB)

When i draw i see that for the problem’s draw :

 ![010](https://root-forum.cern.ch/uploads/default/original/3X/f/4/f40cd28800e797f122a1c75eb96bad2a28896ee7.png)

But when i draw with the command : valeurspicstest\_tree-\>Draw(“Mean1:intensity”,“om\_number1 == 10 && Entries \< 600”), in can draw it without problem

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 7, 2021, 11:55am UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/2 "2021-06-07T11:55:41Z")

</div>

Hi,

could you maybe explain what you think is wrong with this plot of yours? What did you expect and what did you get?

For what it’s worth, I get a different plot when running your code:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/1/c/1c624f25dd4562bdf2225e5167398f39841eb807.png)

And when I do the following

```auto
valeurspicstest_tree->Draw("Mean1:intensity", "om_number1 == 10 && Entries < 600")

```

from CLI I get

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/3/8/385590837e8de520ab5e73d556fd1c2906889f6f.png)

---

<div class="post-metadata">

**Author:** ![IKoro](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@IKoro](https://root-forum.cern.ch/u/IKoro)\
**Post date:** [June 7, 2021, 12:12pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/3 "2021-06-07T12:12:16Z")

</div>

When i run my code i get this :

 ![010](https://root-forum.cern.ch/uploads/default/original/3X/f/4/f40cd28800e797f122a1c75eb96bad2a28896ee7.png)  
for j = 10 and i don’t understand why.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 7, 2021, 12:17pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/4 "2021-06-07T12:17:15Z")

</div>

Ah, this is for `j=10` only. I didn’t understand it from your initial question. Yes, I reproduced this plot now. I’ll try to figure out what’s wrong here.

---

<div class="post-metadata">

**Author:** ![IKoro](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@IKoro](https://root-forum.cern.ch/u/IKoro)\
**Post date:** [June 7, 2021, 12:22pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/5 "2021-06-07T12:22:03Z")

</div>

Thank you sorry for my bad explanation

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 7, 2021, 12:42pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/6 "2021-06-07T12:42:49Z")

</div>

I think I sorted it out. In your code you call the constructor

```auto
TGraph* gr = new TGraphErrors(n,x,y,ex,ey);

```

**before** you defined the `n`, `x`, `y`, `ex`, and `ey`. This does not make sense. The graph probably takes the values from the previous tree entry this way. To fix it, you have to move the constructor to where your

```auto
for (int i=0; i < entries; i++)
{...}

```

loop finishes. This way I get the following for `j=10`:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/e/d/ed1cda8e02429072d012f2126c838e7b2f6c9d30.png)

I didn’t remove the point at (0, 0) since this removal is now before the constructor, and it will take a few moments from your side to fix this one, too.

I think that all your plots were incorrect because of this issue, not only the one for `j=10`.

---

<div class="post-metadata">

**Author:** ![IKoro](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@IKoro](https://root-forum.cern.ch/u/IKoro)\
**Post date:** [June 7, 2021, 12:51pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/7 "2021-06-07T12:51:22Z")

</div>

Thank you, yes it works well for all my plots now.

---

<div class="post-metadata">

**Author:** ![IKoro](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@IKoro](https://root-forum.cern.ch/u/IKoro)\
**Post date:** [June 7, 2021, 1:05pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/8 "2021-06-07T13:05:19Z")

</div>

Sorry but if you draw j = 0 ; j\<=10 the problem moves to the previous one.  
I get this for j = 9

 ![009](https://root-forum.cern.ch/uploads/default/original/3X/2/4/24d0a67263ddc5a12983e3459948b66c8af68c1e.png)

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 7, 2021, 1:15pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/9 "2021-06-07T13:15:43Z")

</div>

Right, this is because for `om_number1 == 9` you should only have 4 points:

- x=0 (`pics=0`; should be removed as `Entries < 600`)
- x=80 (`pics=1`; should be removed as `Entries < 600`)
- x=110 (`pics=4`)
- x=120 (`pics=5`)

But somehow you have additional points with `pics=2` and `3`. These guys probably come from the previous entry, as you don’t clear the `x` and `y` arrays between the entries.

---

<div class="post-metadata">

**Author:** ![IKoro](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@IKoro](https://root-forum.cern.ch/u/IKoro)\
**Post date:** [June 7, 2021, 1:52pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/10 "2021-06-07T13:52:38Z")

</div>

Oh yes thank you so i use that for clean x and y :

> for (int i=0; i \<= 5; i++)  
> {  
> x[i] = 0;  
> y[i] = 0;  
> }

So now i search a solution for remove the point 0,0

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 7, 2021, 2:00pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/11 "2021-06-07T14:00:46Z")

</div>

> [@IKoro](#):
>
> So now i search a solution for remove the point 0,0

Usually this point appears when you have one point left uninitialized, so its coordinates default to (0, 0). In the constructor you have

```c++
Int_t n = 6;
...
TGraph* gr = new TGraphErrors(n,x,y,ex,ey);

```

, so all your graphs must have exaclty 6 points. Is that the case really? Can’t you have less points for some particular `j`? Also, are you sure `pics` can equal 0? If not, there goes your uninitialized point.

---

<div class="post-metadata">

**Author:** ![IKoro](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/3e96dc/32.png) [@IKoro](https://root-forum.cern.ch/u/IKoro)\
**Post date:** [June 7, 2021, 2:13pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/12 "2021-06-07T14:13:39Z")

</div>

All graphs have 6 points because i save 6 Mean1 for one “j”. J in my case is a detector.  
But when i draw Mean1 as function of intensity i apply a condition :

`if (om_number1 == j && Entries > 600 )`

But in certain case Entries is \< 600 so he didn’t take account of them and he draw this coordinates.  
For resolve this problem i use :

```auto
if (om_number1 == j && Entries < 600)

       {
         gr->RemovePoint(pics);
       }

```

But if we use Tgraph gr after that i can’t use them. So i search a solution for exclude this.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [June 7, 2021, 2:28pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/13 "2021-06-07T14:28:37Z")

</div>

```auto
TGraph* gr = new TGraphErrors(n,x,y,ex,ey);

```

Note that n doesn’t _have to_ be the same size as x (y…); it can be smaller, to use the first n elements. You can take advantage of that if you do it carefully.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 7, 2021, 3:09pm UTC](https://root-forum.cern.ch/t/draw-problem-command-terminal-draw-a-different-graph-compare-to-my-programm/45282/14 "2021-06-07T15:09:04Z")

</div>

> [@IKoro](#):
>
> So i search a solution for exclude this.

I guess you can save the point numbers you wish to exclude in a vector while you calculate the point coordinates, and as soon as your graph is ready (as soon as the constructor is called), you can loop over that vector and remove each point by its number. And then you draw your graph. Just be careful and make sure you clear that vector when you go to the next entry or you’ll end up without any points left on the plot by the time you come to `j=12`.
