I need to access several objects of a class called TH2D, which is defined by the program root (https://root.cern.ch/drupal/), with a for loop to use two of its methods.
The name of the objects are in the form run_0, run_1, run_2, etc..
defined like this:
TH2F* run_0 = new TH2F( "runID = 0", "projection during the first run",
COLUMN, -COLUMN_BOUND, COLUMN_BOUND,
RAW, -RAW_BOUND, RAW_BOUND );
inside the for loop for the first object I simply do:
int bin = run_0->FindBin(j, k);
double Nphotons = run_0->GetBinContent(bin);
What do I need to do to have something like this inside a for loop in c++ automatically changing run_0 to run_1 to run_2, etc...?
1st iteration -
int bin = run_0->FindBin(j, k);
double Nphotons = run_0->GetBinContent(bin);
2nd iteration -
int bin = run_1->FindBin(j, k);
double Nphotons = run_1->GetBinContent(bin);
SOLVED WITH:
TH2F* run[8];
run[0] = new TH2F( "runID = 0", "projection during the first run",
COLUMN, -COLUMN_BOUND, COLUMN_BOUND,
RAW, -RAW_BOUND, RAW_BOUND );
....
for( Int_t id = 0; id != 8; ++id)
{
int bin = run[id]->FindBin(j, k);
double Nphotons = run[id]->GetBinContent(bin);
}