I think you are improperly using “strcat” in “createTreeName” (the “treeName” will be equal to the “token[0]”), unless you really know what you are doing there (see “man strcat” for details). One cannot check another places as it’s not clear what the “filename” in “tokenOfFileName” nor the “line[0]” in “createTreeName” are.
I believe you should stop using C strings (i.e. “chat *”, “char *[]”, …) and rewrite your code so that it solely uses C++ strings (i.e. std::string and/or TString).
Also, always try to pre-compile your source code using ACLiC (the compiler will find many possible source code bugs) … root [0] .L MySourceCode.cxx++
Thanks for the guidance. I made changes to my program and its working. But I am facing another problem. I am creating one .root file and under .root file trying to create many trees. But its only creating 2 trees instead I wants to create many trees. One tree having 20480 records of data each.
Is more number of records in data file affecting to create many trees under one .root file ? Its not showing any error or warnings.
Make sure that these trees have unique (unambiguous) “names” (their “titles” can be the same, though) and make sure that for every tree you call “MyTree->Write();”.
Thanks. Yes, I am assigning unique name to each tree and also doing MyTree->Write(). I am trying to read data from .data files to fill a tree. But it works for only two .data files.
Its not working for more than two data files. Means its creating only 2 trees for any .data file.
I did some modifications to the original code but I am having a problem adding the histogram “hist”. I can see the correct histogram for each file but I was expecting to see the sum of all of them since I am using >>+. In fact the >> is not working at all because when the program finish, the histogram “hist” is empty.
How can I fix this? Thanks
Try this “brutal fix”: // ...
if (!vertex) {cout<< "No Vertex" << endl; continue;}
hist->SetDirectory(gDirectory); // "attach" it to the current root file
vertex->Draw("Mass>>+hist","");
hist->SetDirectory(gROOT); // "detach" it from the current root file
count++;
// ... or that one (note: instead of f.FindObject you can also try gPad->FindObject): // ...
if (!vertex) {cout<< "No Vertex" << endl; continue;}
vertex->Draw("Mass>>+hist","");
delete hist; // get rid of the old histogram
hist = ((TH1D*)(f.FindObject("hist"))); // resume the new one
hist->SetDirectory(gROOT); // "detach" it from the current root file
count++;
// ...
Hello, I have used this code from a long time without any problems, but recently I got something not working. All the files in the folder I read are label Hist_1.root, Hist_2.root, Hist_3.root … Before the files were being read in order (1,2,3,4,…), but now the are read in a random order. I tried in both linux and Mac, and Root 6 and 5 but it is not reading the files in order. Hope somebody knows what happen.