Save plot from compiled macro

Dear all, I have an issue saving histograms on gif files executing my compiled macro from the shell. Perhaps should I include some special setting inside the makefile?
that’s the piece of code (it doesn’t work but it tells me any error…)

// Writing plots
for (int i_station = 1; i_station <= max_station; i_station++){
    h_Strip[i_station]->GetXaxis()->SetTitle("ch #");
    h_Strip[i_station]->GetYaxis()->SetTitle("total counts / channel");
    h_Strip[i_station]->Draw();
    sprintf(hname,"histos/Strip_prof_Station%i.gif",i_station);
    h_Strip[i_station]->Print(hname);
}

thanks!

#include <cstdio> #include "TPad.h" // ... char hname[256]; // ... h_Strip[i_station]->Draw(); snprintf(hname, sizeof(hname), "histos/Strip_prof_Station%i.gif", i_station); gPad->Update(); gPad->Print(hname); // ...

Or simpler:

#include <cstdio>
#include "TPad.h"
// ...
h_Strip[i_station]->Draw();
gPad->Update();
gPad->Print(Form("histos/Strip_prof_Station%i.gif", i_station));

You can even make it simpler … no need to "#include " in this case. :mrgreen:

True :slight_smile:

But I have forgotten that for the “Form” you need to #include "TString.h" :mrgreen:

Hi,

When writing new code, we recommend to use ::Format (which returns a temporary TString object) rather than ::Form (which is not thread safe).

Cheers,
Philippe.