TH1* h_var_2D_D1_j1_k1[eta];
TH1* h_var_2D_D1_j1_k2[eta];
TH1* h_var_2D_D1_j1_k3[eta];
TH1* h_var_2D_D1_j1_k4[eta];
TH1* h_var_2D_D1_j1_k5[eta];
TH1* h_var_2D_D1_j1_k6[eta];
TH1* h_var_2D_D1_j1_k7[eta];
TH1* h_var_2D_D1_j1_k8[eta];
TH1* h_var_2D_D1_j1_k9[eta];
TH1* h_var_2D_D1_j1_k10[eta];
and so on …
And then in later stage I want to fill those histograms.
Is there a way to define those histograms using for loop? Basically to avoid writing those histograms multiple times.
for(auto th1_iter = th1s.begin(); th1_iter !=th1s.end(); ++th1_iter){
//The histo name is...
std::string histo_name = static_cast<std::string>(th1_iter->second->GetName());
// The std::map name is in th1_iter->first, so you can access the histogram via...
th1s[th1_iter->first]->Draw();
}
If performance is really paramount, an integer key or different container type might be superior.
TH1F *h_var_2D_D1_j1[10][10];
for (int i=0; i<10; i++)
for (int j=0; j<10; j++)
h_var_2D_D1_j1[i][j] = new TH1F(Form("h_var_2D_D1_j1_%i_%i", i, j), Form("My histogram with k=%i and eta = %i", i, j), nbins, lowX, highX);