VMC Examples Version 6.8
Loading...
Searching...
No Matches
read_ttree.C File Reference

Macro for reading the E03d simulated data from Root file written with kTTree mode. More...

Go to the source code of this file.

Functions

void read_ttree ()
void read_ttree_raw ()

Detailed Description

Macro for reading the E03d simulated data from Root file written with kTTree mode.

Definition in file read_ttree.C.

Function Documentation

◆ read_ttree()

void read_ttree ( )

Macro for reading the E03d simulated data from Root file written with kTTree mode. Note that since Root 6 the libraries have to be loaded first via load_g4d.C.

Definition at line 15 of file read_ttree.C.

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;
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();
32 cout << endl;
33 }
34}
static void PrintTotal(std::vector< Ex03CalorHit > *collection)
Implementation of the TVirtualMCApplication.
Ex03dCalorimeterSD * GetCalorimeterSD() const
void ReadEvent(Int_t i, TMCRootManager::StorageMode storageMode=TMCRootManager::kRNTuple, Int_t threadId=-1)

◆ read_ttree_raw()

void read_ttree_raw ( )

Definition at line 37 of file read_ttree.C.

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;
60 }
61
62 // Cleanup
63 // ROOT automatically allocated the vector; delete it when completely done
64 delete hits;
65 rfile->Close();
66}