Plots are not produced using my macro


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:

#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:

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

Where is my plot?

I would really appreciate any help thanks!

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

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

localhost:12.0

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”.

1 Like

simply do:

root Test1.C
1 Like

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!

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:

gr1->Draw("AP");

do:

c1->Print("myplot.pdf");
1 Like

Thank you! You saved my day!

Cheers,

Lorenzo.

1 Like