Export leaf histogram to ascii

Hello,

Let’s say I have a .root file with one TTree. Inside the tree, there are multiple leaves -> each leaf is an histogram. Is there a way to export all the (x,y) of a particular histogram to an ascii file?

I successfully exported TH1D histograms to .dat files with the macro provided in this post:[url]TH1 to ascii question but I didn’t succeed in exporting histograms that are leaves. After building a TFile, I used a command like this to access the wanted TH1D :

Then, I ran the macro and everything went fine. How can I do a similar thing with “Foo” that is not a TH1D but a leaf?

Thank you for any help!

${ROOTSYS}/tutorials/tree/htest.C

I’m still having troubles. I run the following commands :

TFile *f = new TFile("Test.root");
TTree *tree = (TTree*)f->Get("tree");
tree->Print();

and get this output :


*Tree :tree : name *
*Entries : 1 : Total = 28399 bytes File Size = 13653 *

  •    :          : Tree compression factor =   1.00                       *
    

*Br 0 :Run : Run/I *
*Entries : 1 : Total Size= 540 bytes File Size = 74 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 1 :Event : Event/I *
*Entries : 1 : Total Size= 550 bytes File Size = 76 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 2 :process : process/I *
*Entries : 1 : Total Size= 560 bytes File Size = 78 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 3 :NumOptPhotons : NumOptPhotons/I *
*Entries : 1 : Total Size= 590 bytes File Size = 84 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 4 :NumHits : NumHits/I *
*Entries : 1 : Total Size= 580 bytes File Size = 82 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 5 :HitTime : HitTime[NumHits]/F *
*Entries : 1 : Total Size= 2707 bytes File Size = 2094 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 6 :HitPosX : HitPosX[NumHits]/F *
*Entries : 1 : Total Size= 2707 bytes File Size = 2094 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *

I’m not even sure that these are branches or leaves because it says Br X : … but when opening a TBrowser, I have leaves icons under my tree.
And when I do tree->Show(0); I get

======> EVENT:0
Run = 1
Event = 0
process = 2
NumOptPhotons = 10482
NumHits = 501
HitTime = 11.0514,
23.7658, 48.0929, 47.9535, 63.2077, 34.8588,
51.1873, 19.7026, 35.112, 38.8976, 168.523,
29.183, 29.1838, 5.25697, 32.583, 224.024,
6.29403, 48.3486, 40.7605, 40.7607
HitPosX = 2.88363,
1.54243, 2.77936, 2.78162, 2.62347, 2.27631,
2.6302, 1.90532, 1.93602, 1.84789, 1.95114,
2.66717, 2.69829, 2.17591, 2.4879, 2.14833,
2.87775, 2.70806, 2.84763, 2.85643

I tried creating pointers to branch (or leaf?) HitPosX as example, manipulating contents and filling a new TH1D with the contents but without success. Any advices?

Thanks!