How to get the string branch created in geant4

I create a root file in geant4.

analysisManager->CreateNtuple("Basic", "Basic Event Info");
analysisManager->CreateNtupleSColumn("name");	// column Id = 0
analysisManager->CreateNtupleIColumn("pdgID");	// column Id = 1
analysisManager->CreateNtupleDColumn("angle");	// column Id = 2
analysisManager->CreateNtupleDColumn("momentum");// column Id = 3
analysisManager->CreateNtupleDColumn("beta");// column Id = 4
analysisManager->FinishNtuple();

I can use the branch “name” in web UI of ROOT. And the tree is like

root [9] tree->Print()
******************************************************************************
*Tree    :Basic     : Basic Event Info                                       *
*Entries :   156942 : Total =         8459420 bytes  File  Size =    4854549 *
*        :          : Tree compression factor =   1.74                       *
******************************************************************************
*Br    0 :name      : Char_t Basic                                           *
*Entries :   156942 : Total  Size=    1532845 bytes  File Size  =     515992 *
*Baskets :       48 : Basket Size=      32000 bytes  Compression=   2.97     *
*............................................................................*
*Br    1 :pdgID     : Int_t Basic                                            *
*Entries :   156942 : Total  Size=    1260687 bytes  File Size  =     380496 *
*Baskets :       48 : Basket Size=      32000 bytes  Compression=   3.31     *
*............................................................................*
*Br    2 :angle     : Double_t Basic                                         *
*Entries :   156942 : Total  Size=    1888463 bytes  File Size  =    1163968 *
*Baskets :       48 : Basket Size=      32000 bytes  Compression=   1.62     *
*............................................................................*
*Br    3 :momentum  : Double_t Basic                                         *
*Entries :   156942 : Total  Size=    1888616 bytes  File Size  =    1418236 *
*Baskets :       48 : Basket Size=      32000 bytes  Compression=   1.33     *
*............................................................................*
*Br    4 :beta      : Double_t Basic                                         *
*Entries :   156942 : Total  Size=    1888412 bytes  File Size  =    1373347 *
*Baskets :       48 : Basket Size=      32000 bytes  Compression=   1.37     *
*............................................................................*

How can I get the branch “name” using SetBranchAddress?
I have tried TString, string*, Char_t[20] but they didn’t work.

_ROOT Version:6.30/06
Platform: Not Provided
Compiler: Not Provided


OK, I have solved this problem with deepseek.
It is correct to use Char_t[20].

The program break down because I run
file->Close();//this is the input file opened in "read" mode
after for (Long64_t i = 0; i < nEntries; i++){...} and then draw the hist.

It seems that file->Close(); will delete hist.
Even if the ```file`` is opened in read only mode.

Hi,

Can you post here a standalone example that shows the problem?

Cheers,
D

Be_500MeVu_Fe_tower.root (1.6 MB)
get_particle.cpp (1.9 KB)

You can work around the problem by calling hist->SetDirectory(nullptr);