ROOT Version: 6.18/04
Platform: Ubuntu 18.04
Compiler: gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
Dear co-rooters,
I’m trying to initialize a bunch of histograms. What works for my needs is to declare a 2D array h[][]
of histograms in my main
code and then use a function to initialize them. What I’m doing so far is the following
TString paddle[] = { "none", //0
"Cd", //1
"Cd_Bi", //2
"Cd_2Poly", //3
"Cd_Pb_2Poly", //4
"Cd_Pb_Bi_2Poly", //5
"none", //6
"Cd_Bi_2Poly", //7
"Cd", //8
"2Poly", //9
"Pb" //10
};
//detector numbers
int detector[6] = { 200,
2,
3,
4,
6,
7
};
//void define_histograms(TString name, int number_of_detectors, int number_of_paddles, TH1D h[][number_of_paddles] ){
void define_histograms(TH1D *h, TString name, int number_of_detectors, int number_of_paddles, ){
for (int det=0; det<number_of_detectors; ++det){
for (int paddle=0; paddle<number_of_paddles; ++paddle){
h[det][paddle] = new TH1D(name, "", 10, 0, 10);
}
}
//int r[number_of_detectors][number_of_paddles];
//return r;
}
void analyze(){
int number_of_detectors = sizeof(detector)/sizeof(detector[0]);
int number_of_paddles = *(&paddle+1)-paddle;
TString name;
TString title;
TH1D *h_tof_raw[number_of_detectors][number_of_paddles];
name = "h_tof_raw";
//title = "Raw tof; TOF(ns); Counts";
//for (int det=0; det<number_of_detectors; ++det){
//for (int paddle=0; paddle<number_of_paddles; ++paddle){
//h_tof_raw[det][paddle] = new TH1D(name, title, 10, 0, 10);
//}
//}
define_histograms(&h_tof_raw[0][0], name, number_of_detectors, number_of_paddles);
}
However when I do that, I get that cannot convert ‘TH1D*’ to ‘double’ in assignment
to the point where I initialize the histograms i.e. in the function define_histograms(TH1D*, TString, int, int)
at the line
h[det][paddle] = new TH1D(name, "", 10, 0, 10);
Any idea on how to go around that? A similar thing I tried to do in the main code is to initialize the histograms there instead of using a function but eventually I want to create a big amount of different histograms so a function is more convenient.
Any idea on that?
Thanks in advance!