0
  • Note: This is my first time posting and very new to C++ programming language, so please bear with me.
  • Goal: To find a terminal command, OR, code to be included in the Macro that auto opens the .png files (Ex: Figures/pure_comb_4_fits_100logy.png) after the program is run.
  • Actual Results: Terminal produces the following message Info in : file Figures/pure_comb_2_fits_100logy.png has been created, which I then need to manually enter open Figures/pure_comb_2_fits_100logy.png to view the file.
  • Desired/Expected: Want the code to auto open without the need for manually entering into the terminal. It is alright if the solution is either more code added to the C file, or syntax simply entered into the terminal command (preferred).
  • Code Block:

    void drawpc_4()
    {
    
    TFile* f4 = TFile::Open("OutputFiles/OutFile_BinaryC_20191011-1551_k4.root");
    TProfile* tp1f_4 = (TProfile*)f4->Get("hmult_recursion_0_2");
    
    TCanvas* c1 = new TCanvas("c1","");
    
    tp1f_4->SetMarkerStyle(kFullCircle);
    tp1f_4->SetMarkerColor(kBlack);
    tp1f_4->Draw("ex0p");
    tp1f_4->GetXaxis()->SetRangeUser(0,100);
    tp1f_4->GetXaxis()->SetTitle("Number of particles");
    tp1f_4->GetYaxis()->SetTitle("C_{4}");
    
    c1->SetLogy();
    c1->SetLogx();                                                                                           
    
    TF1* fun1 = new TF1("fun1","[0]/pow(x,3)",3.0,99.9);
    fun1->SetParameter(0,6);                                                                                                                                   
    TF1* fun2 = new TF1("fun2","[0]/((x-1)*(x-2)*(x-3))",3.0,99.9);
    fun2->SetParameter(0,6);                                                                                 
    fun2->SetLineColor(kBlue);
    
    fun1->Draw("same");
    fun2->Draw("same");                                                                                                                  
    
    TLegend* leg = new TLegend(0.2,0.2,0.46,0.4);
    leg->AddEntry(fun2,"combinatoric function","l");
    leg->AddEntry(fun1,"power law function","l");
    leg->Draw();
    
    **c1->Print("Figures/pure_comb_4_fits_100logxlogy.png");**
    c1->SetLogx(0);
    
    TLegend* leg4 = new TLegend(0.48,0.68,0.84,0.88);
    leg4->AddEntry(fun2,"combinatoric function","l");
    leg4->AddEntry(fun1,"power law function","l");
    leg4->Draw();
    
    delete leg;
    c1->Print("Figures/pure_comb_4_fits_100logy.png");
    
    delete c1;
    
    }
    
Keldorn
  • 1,980
  • 15
  • 25
Nooch
  • 1
  • Since you're new, I'll point this out - your code is definitely C++ **and** definitely not the language called C. – Drew Dormann May 18 '20 at 02:37
  • 1
    Unfortunately, I didn't understand your question fully. However... If you want to run the image view after your application, then I would just write a little `bash` script. If you want to run the view command with something which is produced by your app. and not known beforehand then I would emit these info (file names) and process that info in the `bash` script. If you want to start the viewer out of your C++ program (like you would from console) then you might have a look at [system()](https://linux.die.net/man/3/system). The latter option should be used with care - due to security issues. – Scheff's Cat May 18 '20 at 06:09
  • How do you run this code? Specifically: do you use the `root` command line program (something like `root drawpc_4.C` or start root and then `.L drawpc_4.C`) or do you compile it to an executable program (`g++ ... drawpc_4.C` or `make`) and then start it as an executable `./drawpc_4`)? … Unfortunately the answers are rather different in the two cases. In the latter case you can have a look at [this answer](https://stackoverflow.com/a/36341590/4588453) – pseyfert May 21 '20 at 17:38
  • @pseyfert I do use the root command line – Nooch May 27 '20 at 02:11

1 Answers1

0

Assuming you run the code with

root drawpc_4.C

, I think you should consider running it with

root -l -b -q drawpc_4.C; open Figures/pure_comb_2_fits_100logy.png

instead. This will open your png file as soon as drawpc_4.C is done executing.

Yury
  • 423
  • 2
  • 7