VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
E03
read_ttree.C
Go to the documentation of this file.
1
//------------------------------------------------
2
// The Virtual Monte Carlo examples
3
// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4
// All rights reserved.
5
//
6
// For the licensing terms see geant4_vmc/LICENSE.
7
// Contact: root-vmc@cern.ch
8
//-------------------------------------------------
9
10
/// \ingroup E03
11
/// \file E03/read_ttree.C
12
/// \brief Macro for reading the E03d simulated data from Root file
13
/// written with kTTree mode
14
15
void
read_ttree
()
16
{
17
/// Macro for reading the E03d simulated data from Root file
18
/// written with kTTree mode.
19
/// Note that since Root 6 the libraries have to be loaded first
20
/// via load_g4d.C.
21
22
// MC application
23
Int_t threadId = 1;
24
Ex03dMCApplication
* appl
25
=
new
Ex03dMCApplication
(
"Example03"
,
"The example03 MC application"
);
26
27
for
(Int_t i=0; i<5; i++) {
28
cout <<
" Event no "
<< i+1 <<
":"
<< endl;
29
appl->
ReadEvent
(i, TMCRootManager::kTTree, threadId);
30
// appl->GetCalorimeterSD()->Print();
31
appl->
GetCalorimeterSD
()->
PrintTotal
();
32
cout << endl;
33
}
34
}
35
36
// Reading tree without using the Ex03dMCApplication functions
37
void
read_ttree_raw
()
38
{
39
// Open the file and get the TTree
40
TFile* rfile = TFile::Open(
"TExample03_1.root"
,
"READ"
);
41
TTree* tree =
nullptr
;
42
rfile->GetObject(
"TExample03"
, tree);
43
44
// Initialize the pointer to nullptr before reading
45
std::vector<Ex03CalorHit>* hits =
nullptr
;
46
47
// Set the branch address (pass the address of your pointer variable)
48
tree->SetBranchAddress(
"hits"
, &hits);
49
// std::cout << "hits: " << hits << std::endl;
50
51
// Loop over entries
52
Long64_t nEntries = tree->GetEntries();
53
std::cout <<
"3"
<< std::endl;
54
55
// for (Long64_t i = 0; i < nEntries; ++i) {
56
for
(Long64_t i = 0; i < 5; ++i) {
57
tree->GetEntry(i);
58
std::cout <<
"Entry "
<< i <<
" has "
<< hits->size() <<
" hits."
<< std::endl;
59
Ex03dCalorimeterSD::PrintTotal
(hits);
60
}
61
62
// Cleanup
63
// ROOT automatically allocated the vector; delete it when completely done
64
delete
hits;
65
rfile->Close();
66
}
Ex03dCalorimeterSD::PrintTotal
void PrintTotal() const
Definition
Ex03dCalorimeterSD.cxx:223
Ex03dCalorimeterSD::PrintTotal
static void PrintTotal(std::vector< Ex03CalorHit > *collection)
Definition
Ex03dCalorimeterSD.cxx:39
Ex03dMCApplication
Implementation of the TVirtualMCApplication.
Definition
Ex03dMCApplication.h:43
Ex03dMCApplication::GetCalorimeterSD
Ex03dCalorimeterSD * GetCalorimeterSD() const
Definition
Ex03dMCApplication.h:141
Ex03dMCApplication::ReadEvent
void ReadEvent(Int_t i, TMCRootManager::StorageMode storageMode=TMCRootManager::kRNTuple, Int_t threadId=-1)
Definition
Ex03dMCApplication.cxx:273
read_ttree
void read_ttree()
Definition
read_ttree.C:15
read_ttree_raw
void read_ttree_raw()
Definition
read_ttree.C:37
Generated on
for VMC Examples by
1.17.0