# Trouble with TFile

**URL:** <https://root-forum.cern.ch/t/trouble-with-tfile/50590>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [June 29, 2022, 7:45am UTC](https://root-forum.cern.ch/t/trouble-with-tfile/50590 "2022-06-29T07:45:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nisha](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nisha/32/28801_2.png) [@Nisha](https://root-forum.cern.ch/u/Nisha)\
**Post date:** [June 29, 2022, 7:45am UTC](https://root-forum.cern.ch/t/trouble-with-tfile/50590/1 "2022-06-29T07:45:26Z")

</div>

Hello Experts,

I have multiple .ROOT files that I want to open and plot. Since I have many files, I am trying to write a separate function that I can call every time I need, instead of repeating the same process over and over again. Here is a macro that I have. If I copy-paste the following part in the main program, it works fine, ‘’’

TFile\* inp = TFile::Open("/root\_v6.18.04/macros/HandOff/AlThin/Next steps/27Al(d,n)/DataSets/Disk118.ROOT");

inp-\>ls();

hdetTOF118 = (TH1F\*)inp-\>Get(“Disk118”);

cdetTOF118-\>cd();

hdetTOF118-\>Draw();

But in a function, it somehow crashes and displays StackTrace something and exits root. Can anybody please help with what is it that I am doing wrong? I am sure it must be a simple fix with a minute detail that I am missing.

edit- Here is the macro I have written and one of the files that I need to plot.

[Troubleshooting.cc](https://root-forum.cern.ch/uploads/short-url/im8OhxmyAYOAMrVbBZeZPlIddjA.cc) (3.0 KB)  
[Disk118.ROOT](https://root-forum.cern.ch/uploads/short-url/pHtwzRmYFyoovFHD6hDtsfqIjtP.ROOT) (7.0 KB)

Please help! Thank you for your time!

_ROOT Version:_ 6.18/04  
_Platform:_ C++  
_Compiler:_ Visual Studio Code

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 29, 2022, 8:23am UTC](https://root-forum.cern.ch/t/trouble-with-tfile/50590/2 "2022-06-29T08:23:53Z")

</div>

`TFile *inp = TFile::Open(path_to_file.c_str());`

`const char *Disk118 = "Disk118";`

---

<div class="post-metadata">

**Author:** ![Nisha](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nisha/32/28801_2.png) [@Nisha](https://root-forum.cern.ch/u/Nisha)\
**Post date:** [June 30, 2022, 2:54am UTC](https://root-forum.cern.ch/t/trouble-with-tfile/50590/3 "2022-06-30T02:54:26Z")

</div>

Thank you @Wile_E_Coyote. Worked like a charm!
