Hi,
I am trying to create multiple TCanvases. I have tried using vector format, and string manipulation, however I am unable to achieve my desired functionality.
The number of canvas is dependent on a variable nBinsX which is extract from the x bins of a 2 dimensional histogram. Since I would like to view my data in 24 bins I want 2 canvases of 12, each canvas to have 3 rows 4 columns.
Below is am attempt at using strings
[code]
int can_num = (nBinsX/12.)+1;
vector<TCanvas*> Can2;
Int_t canvasrow = 3;
Int_t canvascolu = 4;
TString CanVas[10] = {“Can1”, “Can2”, “Can3”, “Can4”, “Can5”, “Can6”, “Can7”, “Can8”, “Can9”, “Can10”};
for(int ds=0; ds<can_num; ds++){
TCanvas *CanVas[ds].Data();
//CanVas[ds].Data() = new TCanvas();
CanVas[ds].Data()->Divide(canvascolu,canvasrow);
}[/code]
This gives error:
below is trying to use arrays
[code]
int can_num = (nBinsX/12.)+1;
TCanvas *Can2[can_num];
Int_t canvasrow = 3;
Int_t canvascolu = 4;
for(int ds=0; ds<can_num; ds++){
char pt2[50];
sprintf(pt2,"%s%i%s","Can2",ds,"\0");
Can2[ds]=new TCanvas(pt2,pt2,800,650);
Can2[ds]->Divide(canvascolu,canvasrow);
}[/code]
But his method will not work because the number of canvases must be know at the time of compile with using ALciC. Without direct input, this gives the normal Error: Non-static-const variable in array dimension
Below is trying to use vectors
[code]
int can_num = (nBinsX/12.)+1;
vector<TCanvas*> Can2;
Int_t canvasrow = 3;
Int_t canvascolu = 4;
for(int ds=0; ds<can_num; ds++){
char pt2[50];
sprintf(pt2,"%s","Can2");
//Can2.emplace_back( new TCanvas(pt2,pt2,800,650));
Can2.push_back(new TCanvas(pt2,pt2,800,650));
Can2[ds]->Divide(canvascolu,canvasrow);
}[/code]
This does not work because of how TCanvas is stored in the vector.
Any suggestions?
Thanks