# Plots are not produced using my macro

**URL:** <https://root-forum.cern.ch/t/plots-are-not-produced-using-my-macro/52438>\
**Category:** Newbie\
**Tags:** graphics, root\
**Created:** [November 19, 2022, 6:05pm UTC](https://root-forum.cern.ch/t/plots-are-not-produced-using-my-macro/52438 "2022-11-19T18:05:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lorenzo\_Mobilia](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lorenzo_mobilia/32/26194_2.png) [@Lorenzo\_Mobilia](https://root-forum.cern.ch/u/Lorenzo_Mobilia)\
**Post date:** [November 19, 2022, 6:05pm UTC](https://root-forum.cern.ch/t/plots-are-not-produced-using-my-macro/52438/1 "2022-11-19T18:05:45Z")

</div>

* * *

_ROOT Version:_ 6.14/06

* * *

Hi everyone!

I am quite new to Root and I am finding some difficulties in approaching the use of this tool in cluster computation. I work in the Virgo collaboration so I use the Cascina farm for the analysis.

In this macro I just want to plot the amplitude of the events vs time, so I read the data, put them in arrays and plot them. The problem is that the Draw() command does not produce anything!

Here is the code:

```auto
#include <stdio.h>
#include <algorithm>
#include <iostream>
void Test1(char *iFileName = (char*)"/data/dev/cbc2/O3-offline/MBTA_Results/chunk1/BBH/DATA-V4r29-repro/MbtaDat_WithExcessRate_WithFAR_Clustered-1238166000-34000.gwf", char *format = (char*)"png"){
  char text[256];

  double amplitude,L1_SNR, H1_SNR, time;
  FrFile *iFile = FrFileINew(iFileName);
  FrEvent *Events = FrEventReadTF1(iFile, (char*)"*", FrFileITStart(iFile), FrFileITEnd(iFile)-FrFileITStart(iFile), 0, (char*)"amplitude", 0, 1000);
  FrEvent *eve = Events;
  int nEve = 0;
  //cout<<eve<<endl;                                                                                                                                                                                                                                             
  //cout<<iFile<<endl;                                                                                                                                                                                                                                           
  //cout<<nEve<<endl;                                                                                                                                                                                                                                            
  vector<double> amp;
  vector<double> t;
  int i =0;
  while(eve){
    nEve++;
    //printf("Event #%d\n", nEve);                                                                                                                                                                                                                               
    L1_SNR = FrEventGetParam(eve, (char*)"L1:SNR");
    H1_SNR = FrEventGetParam(eve, (char*)"H1:SNR");
    amplitude = sqrt(L1_SNR*L1_SNR + H1_SNR + H1_SNR);
    time = FrEventGetParam(eve, (char*)"template duration");
    //cout<<amplitude<<" "<<time<<endl;                                                                                                                                                                                                                         
    amp.push_back(amplitude);
    t.push_back(time);
    eve=eve->next;
  }
  /*                                                                                                                                                                                                                                                             
  for(int i=0; i<nEve; i++){                                                                                                                                                                                                                                     
    cout<<amp[i]<<endl;                                                                                                                                                                                                                                          
    cout<<t[i]<<endl;                                                                                                                                                                                                                                            
  }                                                                                                                                                                                                                                                              
  */
  double amp1[nEve];
  double t1[nEve];

  for(int i =0; i<nEve; i++){
    t1[i] = t[i];
    amp1[i] = amp[i];
    //cout<<i<<" "<<t1[i]<<" "<<amp1[i]<<endl;                                                                                                                                                                                                                   
  }

  //cout<<t.size()<<" "<<amp.size()<<endl;                                                                                                                                                                                                                       

  TCanvas *c1 = new TCanvas("c1", "c1", 1500, 1500);
  TGraph *gr1 = new TGraph(nEve, t1, amp1);
  //gr1->Print();                                                                                                                                                                                                                                                
  c1->SetGrid();
  gr1->Draw("AP");
}

```

The I call the root interpreter and run

`root -b Test1.C`

and my output is:

```auto
root [0] 
Processing Test1.C...
root [1]

```

Where is my plot?

I would really appreciate any help thanks!

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 19, 2022, 7:19pm UTC](https://root-forum.cern.ch/t/plots-are-not-produced-using-my-macro/52438/2 "2022-11-19T19:19:10Z")

</div>

Are you connecting to your cluster using: `ssh -X -Y ...`  
If yes, check: `echo ${DISPLAY}`  
If you get a non-empty output, try to run, e.g.: `xterm`

---

<div class="post-metadata">

**Author:** ![Lorenzo\_Mobilia](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lorenzo_mobilia/32/26194_2.png) [@Lorenzo\_Mobilia](https://root-forum.cern.ch/u/Lorenzo_Mobilia)\
**Post date:** [November 21, 2022, 10:45am UTC](https://root-forum.cern.ch/t/plots-are-not-produced-using-my-macro/52438/3 "2022-11-21T10:45:59Z")

</div>

The output I get from `ssh -X -Y ...` is

```auto
localhost:12.0

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 21, 2022, 11:58am UTC](https://root-forum.cern.ch/t/plots-are-not-produced-using-my-macro/52438/4 "2022-11-21T11:58:46Z")

</div>

Do you get a new window when you run “`xterm`”?

Sorry, I think I see it … you use the “`-b`” ROOT flag, which means: “Run in batch mode without graphics”.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 21, 2022, 1:48pm UTC](https://root-forum.cern.ch/t/plots-are-not-produced-using-my-macro/52438/5 "2022-11-21T13:48:31Z")

</div>

simply do:

```auto
root Test1.C

```

---

<div class="post-metadata">

**Author:** ![Lorenzo\_Mobilia](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lorenzo_mobilia/32/26194_2.png) [@Lorenzo\_Mobilia](https://root-forum.cern.ch/u/Lorenzo_Mobilia)\
**Post date:** [November 21, 2022, 1:50pm UTC](https://root-forum.cern.ch/t/plots-are-not-produced-using-my-macro/52438/6 "2022-11-21T13:50:51Z")

</div>

Thank you both, now it works!

Are there any possibilities to use `root -b Test1.C`? I ask because it is faster than just `root Test1.C`.

Thank you again for your time and effort!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 21, 2022, 1:54pm UTC](https://root-forum.cern.ch/t/plots-are-not-produced-using-my-macro/52438/7 "2022-11-21T13:54:14Z")

</div>

It should not be faster … But yes, you can use `-b`. In that case, the canvas will not display on the screen. But inside your macro, you can save it as a pdf or png file. After:

```auto
gr1->Draw("AP");

```

do:

```auto
c1->Print("myplot.pdf");

```

---

<div class="post-metadata">

**Author:** ![Lorenzo\_Mobilia](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lorenzo_mobilia/32/26194_2.png) [@Lorenzo\_Mobilia](https://root-forum.cern.ch/u/Lorenzo_Mobilia)\
**Post date:** [November 21, 2022, 1:58pm UTC](https://root-forum.cern.ch/t/plots-are-not-produced-using-my-macro/52438/8 "2022-11-21T13:58:35Z")

</div>

Thank you! You saved my day!

Cheers,

Lorenzo.
