Canvas showing up empty after trying to automate it


I am trying to automate the canvas making and the stacked histograms to be made in each canvas. But the canvases all show up blank.

void histo(std::vector<vector<Int_t>>&nabove, std::vector<vector<Double_t>>&prelim,std::vector<vector<Double_t>>&prompt){

// auto hs1 = new THStack(“stacked topology”,“PMT N ABOVE THRESHOLD”);
// auto hs2 = new THStack(“stacked topology”,“PRELIM PE”);
// auto hs3 = new THStack(“stacked topology”,“PROMPT PE”);
// auto c1 = new TCanvas(“pmt n above”,“PMT N ABOVE”,900,700);
// c1->Divide(2,2);
// auto c2 = new TCanvas(“prelim pe”,“PRELIM PE”,900,700);
// auto c3 = new TCanvas(“prompt pe”,“PROMPT PE”,900,700);

std::vector topology_names = {“0p1n”,“0p2n”,“1p0n”,“1p1n”,“1p2n”,“2p0n”,“3p,0n”,“4p0n”,“5p0n”};
std::vector metric_names = {“PMT N_ABOVE”,“PRELIM PE”,“PROMPT PE”};
TH1* h[metric_names.size()][nabove.size()];
THStack* stack[metric_names.size()];
TCanvas* canvas[metric_names.size()];
for(size_t k = 0; k<metric_names.size();k++){
for(int f = 0;f<9;f++){
if(k==0){
int xlow = 0;
int xhigh = 120;
int bin_size = 121;
h[k][f] = new TH1F(“nabove”,“PMT ABOVE THRESHOLD”,bin_size,xlow,xhigh);
for(size_t i=0;i<nabove[f].size();i++){
h[k][f]->Fill(nabove[f][i]);
h[k][f]->SetFillColor(f);
stack[k] = new THStack(“stacked topology”,“PMT N ABOVE THRESHOLD”);
stack[k]->Add(h[k][f]);
}
continue;
}
if(k==1){
int xlow = -10000;
int xhigh = 5000;
int bin_size = 100;
h[k][f] = new TH1D(“prelim”,“ALL 3 METRICS”,bin_size,xlow,xhigh);
for(size_t i=0;i<prelim[f].size();i++){
h[k][f]->Fill(prelim[f][i]);
h[k][f]->SetFillColor(f);
stack[k] = new THStack(“stacked topology”,“PRELIM PE”);
stack[k]->Add(h[k][f]);
}
}
if(k==2){
int xlow = -600;
int xhigh = 20000;
int bin_size = 100;
h[k][f] = new TH1D(“prompt”,“PROMPT PE”,bin_size,xlow,xhigh);
for(size_t i=0;i<prompt[f].size();i++){
h[k][f]->Fill(prompt[f][i]);
h[k][f]->SetFillColor(f);
stack[k] = new THStack(“stacked topology”,“PROMPT PE”);
stack[k]->Add(h[k][f]);

        }
        continue;
     }
  }
  stack[k]->Draw();
  canvas[k] = new TCanvas(metric_names[k],metric_names[k],900,700);
  canvas[k]->SaveAs("/sbnd/app/users/ipatel/NC_trigger/plot/"+metric_names[k]+".jpeg","recreate");

}

// c1->cd(1);hs1->Draw();
// c1->cd(2);hs2->Draw();
// c1->cd(3);hs3->Draw();
// c1->SaveAs(“/sbnd/app/users/ipatel/NC_trigger/plot/sum.jpeg”,“recreate”);
return;
}

The 3 loops over i should probably only contain one line:
h[...][...]->Fill(...);
so the other lines should be outside those loops (check well where they belong), and you probably should also delete those continue;, but I don’t know what you’re trying to do there. You should add a histogram to a stack only once, after the histogram has been filled, not every time you fill an entry.

Another thing: you only have new THStack for 3 stacks, so if k>2, there’s an issue with stack[k]->Draw();.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.