"Automatize" a macro

Hi, I wrote a macro (see attachment). In this macro I open a root file and I plot some graphs. As you can see by the macro, I plot 20 graphs, and I have to use the macro for more root files.
I’d like to simplify the use by:

  1. To write just one time the root file name (in the macro I used si-500330 and to write a code so that if for example I use the file si-500314, I just change the name in a row, and it automatically changes the name in each other ones.

  2. In each part of the canvas I wrote somthing like this

	c->cd(1);
	 	t->SetLineColor(kBlue);
	 	t->Draw (caloname0);
 		t->GetHistogram()->SetTitle(cd0name);
 		TH1F *htemp0 = (TH1F*)gPad->GetPrimitive("htemp"); 
		htemp0->GetXaxis()->SetTitle(cdXname); 
		htemp0->GetYaxis()->SetTitle(cdYname);
		htemp0->GetYaxis()->SetTitleSize(10);
  		htemp0->GetYaxis()->SetTitleFont(43);
   		htemp0->GetYaxis()->SetTitleOffset(1);
   		htemp0->GetYaxis()->SetLabelFont(43); 
   		htemp0->GetYaxis()->SetLabelSize(10);
   		htemp0->GetXaxis()->SetTitleSize(10);
   		htemp0->GetXaxis()->SetTitleFont(43);
   		htemp0->GetXaxis()->SetTitleOffset(1);
   		htemp0->GetXaxis()->SetLabelFont(43); 
   		htemp0->GetXaxis()->SetLabelSize(10);
   		htemp0->Draw(); 
		gPad->Update();

Then if I want to change something (for example the label font), I’ve to change it in all the canvas parts…I’d like to write a code so that I just write this code at the begin of the macro and after it will change for all the plots.

thanks


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


The piece of code you posted is a bit short to understand what you are doing.

Basically you should make a macro with parameters you can set when calling it.

Hi couet, thanks for your reply. You are right…I forgot to add the attachment!
Now I’m adding it.
What I mean is

  1. In the code you can read a lot of time the “si-500330” , if I change the data file, I’ve to change the name each one that I wrote it (for example writing “si-500314”)…I’d like to use a code so that I just write the name one time, it stores the name in a variable and it change the name in each row!
  2. in each part of the canvas I wrote something like this
c->cd(1);
	 	t->SetLineColor(kBlue);
	 	t->Draw (caloname0);
 		t->GetHistogram()->SetTitle(cd0name);
 		TH1F *htemp0 = (TH1F*)gPad->GetPrimitive("htemp"); 
		htemp0->GetXaxis()->SetTitle(cdXname); 
		htemp0->GetYaxis()->SetTitle(cdYname);
		htemp0->GetYaxis()->SetTitleSize(10);
  		htemp0->GetYaxis()->SetTitleFont(43);
   		htemp0->GetYaxis()->SetTitleOffset(1);
   		htemp0->GetYaxis()->SetLabelFont(43); 
   		htemp0->GetYaxis()->SetLabelSize(10);
   		htemp0->GetXaxis()->SetTitleSize(10);
   		htemp0->GetXaxis()->SetTitleFont(43);
   		htemp0->GetXaxis()->SetTitleOffset(1);
   		htemp0->GetXaxis()->SetLabelFont(43); 
   		htemp0->GetXaxis()->SetLabelSize(10);
   		htemp0->Draw(); 
		gPad->Update();

So that, if I want to change the value “43” of this line

htemp0->GetXaxis()->SetLabelFont(43); 

I’ve to change it in all the 20 plots. I’d like a waye so that I write the code just one time but I can use the options for all the plots!

EDIT: I solved the second question in this way:

htemp->GetYaxis()->SetTitleSize(c_YTitleSize);
  		htemp->GetYaxis()->SetTitleFont(c_YTitleFont);
   		htemp->GetYaxis()->SetTitleOffset(c_YTitleOffset);
   		htemp->GetYaxis()->SetLabelFont(c_YLabelFont); 
   		htemp->GetYaxis()->SetLabelSize(c_YLabelSize);
   		htemp->GetXaxis()->SetTitleSize(c_XTitleSize);
   		htemp->GetXaxis()->SetTitleFont(c_XTitleFont);
   		htemp->GetXaxis()->SetTitleOffset(c_XTitleOffset);
   		htemp->GetXaxis()->SetLabelFont(c_XLabelFont); 
   		htemp->GetXaxis()->SetLabelSize(c_XLabelSize);

caloene.cpp (17.2 KB)

Use TString::Format like so:

for (int ifile = 500300 /*or whatever*/; ifile < 50350 /*or whatever*/; ++ifile) {
   TString myfilein = TString::Format("D:/si-%d.root", ifile);
   TString myplottimeout = TString::Format("D:/si-%d_time.pdf", ifile);
   TString cdname = TString::Format("si-%d: Time_{scint}_{8}-Time_{scint}_{9}", ifile);
   // etc...
}

Thank you axel! It works!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.