I’m trying to make a vector of many histograms. I have a similar set of histograms that I make, but when I try and up the ante it seems to run into problems. Here’s the code issue in question:
void Histogram::Bin_Centering2_Make(std::shared_ptr<Flags> flags_){
//[W][Q2][Var Set][Xij][Bin Xij][W,Q2,Xij projection]
if(!flags_->Plot_Bin_Centering2()){return;}
std::cout<<"Making Bin Centering Correction Histograms\n";
std::vector<long> space_dims(5);
space_dims[3] = 29; //W Bins
space_dims[2] = 5; //Q2 Bins
space_dims[1] = 3; //Var Set
space_dims[0] = 4; //Xij
space_dims[4] = 4;//variable
CartesianGenerator cart(space_dims);
char hname[100];
TH1D_ptr_1d hist_1d;
TH1D_ptr_2d hist_2d;
TH1D_ptr_3d hist_3d;
TH1D_ptr_4d hist_4d;
TH1D_ptr_5d hist_5d;
double bot;
double top;
int num_bins_xij[5] = {_MM_bins_+2*_MM_wider_,_MM_bins_+2*_MM_wider_,_theta_bins_,_alpha_bins_,_phi_bins_};
int num_bins_fin = 0;
int Wbin = 0;
int Q2bin = 0;
int Xij=0;
int var=0;
char proj_name[100];
char* xij_names[] = {"MM1","MM2","theta","alpha","phi"};
while(cart.GetNextCombination()){
Wbin = cart[3];
Q2bin=cart[2];
Xij=cart[0];
var=cart[1];
for(int k=0; k<_phi_bins_; k++){
for(int j=0; j<num_bins_xij[Xij]; j++){
switch(cart[4]){
case 0:
num_bins_fin = 29;//W
sprintf(proj_name,"W");
bot = Histogram::W_bot(Wbin);
top = Histogram::W_top(Wbin);
std::cout<<"Making BC2 Hist1: " <<_Bin_Center2_hist2.size() <<" " <<hist_5d.size() <<" " <<hist_4d.size() <<" " <<hist_3d.size() <<" " <<hist_2d.size() <<" " <<hist_1d.size() <<"\n";
break;
case 1:
num_bins_fin = 5;//Q2
sprintf(proj_name,"Q2");
bot = Histogram::Q2_bot(Q2bin);
top = Histogram::Q2_top(Q2bin);
std::cout<<"Making BC2 Hist2: " <<_Bin_Center2_hist2.size() <<" " <<hist_5d.size() <<" " <<hist_4d.size() <<" " <<hist_3d.size() <<" " <<hist_2d.size() <<" " <<hist_1d.size() <<"\n";
break;
case 2:
num_bins_fin = num_bins_xij[Xij];//Xij
sprintf(proj_name,"%s_%s",_var_names_[var],xij_names[Xij]);
bot = Histogram::Xij_Bin_Min(j,Xij,Wbin,var);
top = Histogram::Xij_Bin_Max(j,Xij,Wbin,var);
std::cout<<"Making BC2 Hist3: " <<_Bin_Center2_hist3.size() <<" " <<hist_5d.size() <<" " <<hist_4d.size() <<" " <<hist_3d.size() <<" " <<hist_2d.size() <<" " <<hist_1d.size() <<"\n";
break;
case 3:
num_bins_fin = num_bins_xij[4];//phi
sprintf(proj_name,"%s_%s",_var_names_[var],xij_names[4]);
bot = Histogram::Xij_Bin_Min(k,4,Wbin,var);
top = Histogram::Xij_Bin_Max(k,4,Wbin,var);
std::cout<<"Making BC2 Hist4: " <<_Bin_Center2_hist4.size() <<" " <<hist_5d.size() <<" " <<hist_4d.size() <<" " <<hist_3d.size() <<" " <<hist_2d.size() <<" " <<hist_1d.size() <<"\n";
break;
default:
std::cout<<"Improper variable choice for bin centering\n";
break;
}
sprintf(hname,"%s_Bin_Center_W:[%.3f,%.3f)_Q2:[%.2f,%.2f)_%s_%s:[%.4f,%.4f)_Phi:[%.4f,%.4f)",proj_name,Histogram::W_bot(Wbin),Histogram::W_top(Wbin),Histogram::Q2_bot(Q2bin),Histogram::Q2_top(Q2bin),_var_names_[var],xij_names[Xij],Histogram::Xij_Bin_Min(j,Xij,Wbin,var),Histogram::Xij_Bin_Max(j,Xij,Wbin,var),Histogram::Xij_Bin_Min(k,4,Wbin,var),Histogram::Xij_Bin_Max(k,4,Wbin,var));
hist_1d.push_back(new TH1D(hname,hname,11,bot,top));
}
if(hist_1d.size()>0){
hist_2d.push_back(hist_1d);
hist_1d.clear();
}
}
if(hist_2d.size()>0){
hist_3d.push_back(hist_2d);
hist_2d.clear();
}
if(cart[0] == space_dims[0]-1){
if(hist_3d.size()>0){
hist_4d.push_back(hist_3d);
hist_3d.clear();
}
if(cart[1] == space_dims[1]-1){
if(hist_4d.size()>0){
hist_5d.push_back(hist_4d);
hist_4d.clear();
}
if(cart[2] == space_dims[2]-1){
if(hist_5d.size()>0){
if(cart[4]==0){
_Bin_Center2_hist1.push_back(hist_5d);
}else if(cart[4]==1){
_Bin_Center2_hist2.push_back(hist_5d);
}else if(cart[4]==2){
_Bin_Center2_hist3.push_back(hist_5d);
}else if(cart[4]==3){
_Bin_Center2_hist4.push_back(hist_5d);
}
//_Bin_Center2_hist.push_back(hist_5d);
hist_5d.clear();
}
}
}
}
}
std::cout<<"\tFinished Making Bin Centering2 Histograms\nbop bop bop\n";
}
For context, CartesianGenerator is a function that loops through different index combinations starting with the first one, cart[0] and goes through them. It’s like nested for-loops, but more functionally variable.
I’ve declared _Bin_Center2_hist1,2,3,4 in the .hpp file as 6 dimensional vectors of TH1Ds. There are other parts in here that are just definitions, but that I left in in case there’s some sort of nuance I’m missing.
Initially, I was running into Abort Trap: 6 errors, and thought maybe there isn’t enough space for so many histograms in a single object, so I split it up into 4 different ones, hoping that would work. Unfortunately, I still run into Abort Trap: 6 errors.
It’s odd though, I can get through the whole function and print out the
" Finished Making Bin Centering2 Histograms
bop bop bop", but then crashes as it exits the function. All this is inside my Histogram class initialization:
Histogram::Histogram(std::shared_ptr<Flags> flags_){
std::cout<<"made it past here1\n";
Histogram::Bin_Centering2_Make(flags_);
std::cout<<"made it past here2\n";
}
where “made it past here1” will print, but not “made it past here2”
For additional context, here is the one that does work:
void Histogram::Bin_Centering_Make(std::shared_ptr<Flags> flags_){
//[W][Q2][Var Set][Xij][Bin Xij][W,Q2,Xij projection]
if(!flags_->Plot_Bin_Centering()){
return;
}
std::cout<<"Making Bin Centering Correction Histograms\n";
std::vector<long> space_dims(4);
space_dims[3] = 29; //W Bins
space_dims[2] = 5; //Q2 Bins
space_dims[1] = 3; //Var Set
space_dims[0] = 5; //Xij
CartesianGenerator cart(space_dims);
char hname[100];
TH1D_ptr_1d hist_1d;
TH1D_ptr_2d hist_2d;
TH1D_ptr_3d hist_3d;
TH1D_ptr_4d hist_4d;
TH1D_ptr_5d hist_5d;
double bot;
double top;
int num_bins_xij[5] = {_MM_bins_+2*_MM_wider_,_MM_bins_+2*_MM_wider_,_theta_bins_,_alpha_bins_,_phi_bins_};
int num_bins_fin = 0;
int Wbin = 0;
int Q2bin = 0;
int Xij=0;
int var=0;
char proj_name[100];
char* xij_names[] = {"MM1","MM2","theta","alpha","phi"};
while(cart.GetNextCombination()){
Wbin = cart[3];
Q2bin=cart[2];
Xij=cart[0];
var=cart[1];
for(int j=0; j<num_bins_xij[Xij]; j++){
for(int i=0; i<3; i++){
switch(i){
case 0:
num_bins_fin = 29;//W
sprintf(proj_name,"W");
bot = Histogram::W_bot(Wbin);
top = Histogram::W_top(Wbin);
break;
case 1:
num_bins_fin = 5;//Q2
sprintf(proj_name,"Q2");
bot = Histogram::Q2_bot(Q2bin);
top = Histogram::Q2_top(Q2bin);
break;
case 2:
num_bins_fin = num_bins_xij[Xij];//Xij
sprintf(proj_name,"%s_%s",_var_names_[var],xij_names[Xij]);
bot = Histogram::Xij_Bin_Min(j,Xij,Wbin,var);
top = Histogram::Xij_Bin_Max(j,Xij,Wbin,var);
break;
default:
std::cout<<"Improper variable choice for bin centering\n";
break;
}
sprintf(hname,"%s_Bin_Center_W:%.3f-%.3f_Q2:%.2f-%.2f_%s_%s:%.4f-%.4f",proj_name,Histogram::W_bot(Wbin),Histogram::W_top(Wbin),Histogram::Q2_bot(Q2bin),Histogram::Q2_top(Q2bin),_var_names_[var],xij_names[Xij],Histogram::Xij_Bin_Min(j,Xij,Wbin,var),Histogram::Xij_Bin_Max(j,Xij,Wbin,var));
hist_1d.push_back(new TH1D(hname,hname,11,bot,top));
}
hist_2d.push_back(hist_1d);
hist_1d.clear();
}
if(hist_2d.size()>0){
hist_3d.push_back(hist_2d);
hist_2d.clear();
}
if(cart[0] == space_dims[0]-1){
if(hist_3d.size()>0){
hist_4d.push_back(hist_3d);
hist_3d.clear();
}
if(cart[1] == space_dims[1]-1){
if(hist_4d.size()>0){
hist_5d.push_back(hist_4d);
hist_4d.clear();
}
if(cart[2] == space_dims[2]-1){
if(hist_5d.size()>0){
_Bin_Center_hist.push_back(hist_5d);
hist_5d.clear();
}
}
}
}
}
std::cout<<"\tFinished Making Bin Centering Histograms\n";
}
Where you can see the dimensionality is slightly less.
Is it an issue where I just need to break the histograms down even more, or is there something I’m missing?
_ROOT Version:_6.26.04
Platform: macOS Ventura 13.0
Compiler: g++