Hi,
I am trying to draw a tree on multiple pads with different options. However, the results varied when I run the SAME code several times. The first one is what I expected:
But for most of the time, I got the latter one.
Here is the macro I wrote to perform the drawing:
auto DrawT(TTree *const tree, const std::vector<size_t>& nEnts){
auto TC = new TCanvas();
TC->Divide(2, 2);
int colorInd = 0;
size_t tcInd = 0;
auto trd = tree->CloneTree();
auto cBr = trd->Branch("color", &colorInd, "color/i");
std::vector<const char*> nameV;
for(auto branch: *(tree->GetListOfBranches()))
nameV.push_back(branch->GetName());
for(size_t nEnt: nEnts){
for(size_t i = 0; i != nEnt; ++i)
cBr->Fill();
++colorInd;
} //Draw different trees with different colors
trd->SetMarkerStyle(8);
do{
std::stringstream ss;
ss<<nameV[0]<<':'<<nameV[1]<<':'<<nameV[2]<<':'<<"color";
TC->cd(++tcInd); //Draw different combinations on different pads
trd->Draw(ss.str().c_str(), "1");
}while(next_combination(nameV.begin(), nameV.begin()+3, nameV.end()));
return TC;
}
next_combination
is a function I copied from StackOverflow which generates combinations of elements in a collection. I assume it worked just fine since I have tested it in ROOT prompt separately.
Here is the code I entered in the prompt:
.L $PATH_TO_THE_MACRO
TTree *tDat = new TTree("train","data from csv file");
tDat->ReadFile("$PATH_TO_THE_CSV_FILE", "var0/D:var1/D:var2/D:var3/D", ',');
auto cdr = DrawT(tDat, {40, 40, 40}) //(TCanvas *) @0x7fffc008ea00
Additional information may help:
I noticed that 4 graphs were drawn (the expected behavior) only when something was drawn previously, i.e. a TF1 function, but sometimes there were still 3 graphs drawn in this condition.
ROOT Version: 6.20/02
Platform: Arch Linux on WSL
Compiler: I installed the package from Arch community repository.
I have just noticed that the function I called in the prompt is an overloaded one of the macro I posted. I wrote it to pass initializer list literal instead of a vector. To avoid confusion, the overloaded one is posted here:
auto DrawT(TTree *const tree, const std::initializer_list<size_t>& nEnts){
return DrawT(tree, std::vector<size_t>(nEnts));
}