Using a variable from a loop when saving a histogram

Hello, everyone.

I have the following situation:

A for loop where I vary a certain variable which contains another loop where I fill the histogram. Then I would like to store the histogram (by means of SaveAs). As I will have many of these histograms due to a variation of the parameter in my first loop, I wanted to add the value of the this variable in the name to be saved. How does one do this?

for (Int_t a = 0; a <11; a ++ ){
for (){
//Here the  histogram is being filled.
}
//Saving the histogram containing the current value of a.
}

_ROOT Version: 6.26/02
_Platform: Ubuntu 22.04.1 LTS
_Compiler: 11.2.0

“SaveAs” what (e.g., a “.root” file, a “.C++” macro file)?
“name to be saved” of what (the histogram itself or the file)?

You need to define the name (of whatever) using Form().
There are many examples on this forum.

Hello, Wile_E_Coyte.

I would like to save my histogram as png, so something of the form:

c1->SaveAs("InvMass.png");

With kind regards,
Ramin

Hello,

Thank you very much. I will take a look.

With kind regards,
Ramin

c1->SaveAs(Form("InvMass.%d.png", a));

Hello, Wile_E_Coyte.

That worked like a charm. Thank you very much.

With kind regards,
Ramin