Hey All,
I fill multiple histograms manually, e.g.:
EDep_1->Fill(x1);
EDep_2->Fill(x2);
...
EDep_100->Fill(x100);
I am wondering if it is possible to automate and loop this instead of manually occupying multiple (100 lines)? I am not an expert in ROOT/C++ and will appreciate any assistance please?
Resolved using this post . Here is full working code:
int numOfDetectors=5; // number of desired histograms
// create histograms
TH1F** EDep=new TH1F*[numOfDetectors];
for (int i=0; i<numOfDetectors;i++) {
EDep[i] = new TH1F(TString::Format("%i_EDep_gm", i+1), TString::Format("Energy deposited by gamma events in det-%i", i+1), 1000, 0., 1000.);
}
// fill-in histograms
for (int i=0; i<numOfDetectors;i++){
EDep[i]->Fill(i+10);
}
system
Closed
December 3, 2021, 7:16pm
3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.