Hi Ivana,
thanks a lot for your help! I changed your code slightly to:
{
std::unique_ptr myFile( TFile::Open(“output.root”));
auto tree = myFile->Get(“toy_ex”);
Double_t partEdep;
Double_t energy;
tree->SetBranchAddress(“partEdep”, &partEdep);
tree->SetBranchAddress(“totEnergy”, &energy);
auto hdepE = new TH1D(“HpartEdep”, “Histo depE”, 100, 0., 100.);
auto htotE = new TH1D(“HtotEnergy”, “Histo totE”, 100, 0., 200.);
for (int iEntry = 0; iEntry < tree->GetEntriesFast(); ++iEntry)
{
// Load the data for the given tree entry
tree->GetEntry(iEntry);
// Now, `variable` is set to the value of the branch
// "branchName" in tree entry `iEntry`
// printf("%d\n", variable);
HpartEdep->Fill(partEdep);
HtotEnergy->Fill(energy);
}
// Create a canvas and divide it into 2x2 pads
TCanvas* c1 = new TCanvas(“c1”, “”, 20, 20, 1000, 500);
c1->Divide(2);
c1->cd(1);
hdepE->Draw(“HIST”);
c1->cd(2);
htotE->Draw(“HIST”);
}
I believe I only changed the names. When I run the macro via
root -l
.x plot.C
I’m receiving only this response:
C:\geant4\sim>
C:\geant4\sim>root -l
root [0] .x plot.C
==========================================
=============== STACKTRACE ===============
================ Thread 0 ================
libCling!cling::runtime::internal::EvaluateDynamicExpression()
libCling!cling_runtime_internal_throwIfInvalidPointer()
0x23e43d116be ??
0x23e504ea3a0 ??
================ Thread 1 ================
ntdll!ZwWaitForWorkViaWorkerFactory()
ntdll!TpReleaseCleanupGroupMembers()
KERNEL32!BaseThreadInitThunk()
ntdll!RtlUserThreadStart()
================ Thread 2 ================
ntdll!ZwWaitForWorkViaWorkerFactory()
ntdll!TpReleaseCleanupGroupMembers()
KERNEL32!BaseThreadInitThunk()
ntdll!RtlUserThreadStart()
================ Thread 3 ================
ntdll!ZwWaitForWorkViaWorkerFactory()
ntdll!TpReleaseCleanupGroupMembers()
KERNEL32!BaseThreadInitThunk()
ntdll!RtlUserThreadStart()
================ Thread 4 ================
ntdll!NtDelayExecution()
KERNELBASE!SleepEx()
libCore!TWinNTSystem::TimerThread()
libCore!TWinNTSystem::ThreadStub()
KERNEL32!BaseThreadInitThunk()
ntdll!RtlUserThreadStart()
================ Thread 5 ================
win32u!NtUserGetMessage()
USER32!GetMessageA()
libCore!TWinNTSystem::FreeDirectory()
KERNEL32!BaseThreadInitThunk()
ntdll!RtlUserThreadStart()
================ Thread 6 ================
ntdll!ZwWaitForMultipleObjects()
KERNELBASE!WaitForMultipleObjectsEx()
KERNELBASE!WaitForMultipleObjects()
tmmon64!??
tmmon64!??
tmmon64!??
KERNEL32!BaseThreadInitThunk()
ntdll!RtlUserThreadStart()
==========================================
============= END STACKTRACE =============
C:\geant4\sim>
but no plot, window or the like pops up. Could you tell me whether I’m doing things correctly?
So far, I only notice that at the beginning of your code the line
auto tree = myFile->Get<TTree>("B4");
seems suspicious to me. In my simulation there is no TTree created but this line tries to read a TTree stored in the output file, or?