-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRootFileManager.cc
More file actions
209 lines (187 loc) · 7.02 KB
/
Copy pathRootFileManager.cc
File metadata and controls
209 lines (187 loc) · 7.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// -----------------------------------------------------------------------------
// ROOTFileManager.cpp
//
// Class definition of the ROOT file manager
// * Author: Everybody is an author!
// * Creation date: 31 August 2020
// -----------------------------------------------------------------------------
#include "RootFileManager.h"
// ROOT includes
#include "TObject.h"
// math includes
#include <math.h>
//--------------------------------------------------------------------------
ROOTFileManager::ROOTFileManager(char* inputFileName, char* outputFileName, std::string TreeName)
{
Initialize(inputFileName, outputFileName, TreeName);
}
//--------------------------------------------------------------------------
ROOTFileManager::~ROOTFileManager()
{}
//--------------------------------------------------------------------------
void ROOTFileManager::Initialize(char* inputFileName, char* outputFileName, std::string TreeName)
{
TreeName_=TreeName;
const char* TreeName__ = TreeName_.c_str();
//Input file:
input_file = new TFile(inputFileName);
input_tree = (TTree*)input_file->Get(TreeName__);
//TFile *OutputFile = TFile::Open(outputFileName, "RECREATE");
set_branch_addresses(input_tree);
}
//--------------------------------------------------------------------------
void ROOTFileManager::set_branch_addresses(TTree *input_tree)
{
if(TreeName_=="InitialParticle")
{
input_tree->SetBranchAddress("InitialParticlePDG", &InitialPDG_);
input_tree->SetBranchAddress("InteractionTime", &InteractionTime_);
input_tree->SetBranchAddress("InitialParticleEnergy", &InitialEnergy_);
input_tree->SetBranchAddress("InteractionVertexX", &InteractionVertexX_);
input_tree->SetBranchAddress("InteractionVertexY", &InteractionVertexY_);
input_tree->SetBranchAddress("InteractionVertexZ", &InteractionVertexZ_);
}
else if(TreeName_=="Hits")
{
input_tree->SetBranchAddress("run",&run);
input_tree->SetBranchAddress("hit_start_x",&hitX_start);
input_tree->SetBranchAddress("hit_end_x",&hitX_end);
input_tree->SetBranchAddress("hit_start_y",&hitY_start);
input_tree->SetBranchAddress("hit_end_y",&hitY_end);
input_tree->SetBranchAddress("hit_start_z",&hitZ_start);
input_tree->SetBranchAddress("hit_end_z",&hitZ_end);
input_tree->SetBranchAddress("hit_energy_deposit",&edep);
input_tree->SetBranchAddress("hit_start_t",&time_start);
input_tree->SetBranchAddress("hit_end_t",&time_end);
input_tree->SetBranchAddress("hit_length",&length);
input_tree->SetBranchAddress("hit_pdg",&pdg);
}
else if(TreeName_=="PrimaryParticle")
{
input_tree->SetBranchAddress("PrimaryParticlePDG", &PrimaryPDG_);
input_tree->SetBranchAddress("PrimaryParticleEnergy", &PrimaryEnergy_);
input_tree->SetBranchAddress("PrimaryParticlePx", &PrimaryPx_);
input_tree->SetBranchAddress("PrimaryParticlePy", &PrimaryPy_);
input_tree->SetBranchAddress("PrimaryParticlePz", &PrimaryPz_);
}
else if(TreeName_=="Background")
{
input_tree->SetBranchAddress("DecayTime", &BackgroundDecayTime_);
input_tree->SetBranchAddress("AtomicNumber", &BackgroundAtomicNumber_);
input_tree->SetBranchAddress("AtomicMass", &BackgroundAtomicMass_);
input_tree->SetBranchAddress("BackgroundVertexX", &BackgroundVertexX_);
input_tree->SetBranchAddress("BackgroundVertexY", &BackgroundVertexY_);
input_tree->SetBranchAddress("BackgroundVertexZ", &BackgroundVertexZ_);
}
}
void ROOTFileManager::EventFill()
{
// OutputTree->Branch("eventID", &runID);
// OutputTree->Branch("SimPhotonsperOpChVUV",&SavePhotons);
// OutputTree->Branch("GeneratedPhotons",&generated_counter);
// OutputTree->Branch("DetectedPhotons",&nPhotons);
// OutputTree->Fill();
// OutputFile->cd();
}
//--------------------------------------------------------------------------
void ROOTFileManager::Save()
{
// OutputFile->Write();
// OutputFile->Close();
}
//--------------------------------------------------------------------------
// Get event. The number of run is in case we have several events in the same file, so we can loop over them.
void ROOTFileManager::GetEvent(int nRun)
{
input_tree->GetEntry(nRun);
}//Get_Event
//--------------------------------------------------------------------------
//Get event in case we dont have an argument. It is for information on the intial and primary particles
void ROOTFileManager::GetEvent()
{
if(TreeName_=="InitialParticle")
{
for(int i = 0; i < input_tree->GetEntries(); i++)
{
input_tree->GetEntry(i);
InitialPDG.push_back(InitialPDG_);
InitialEnergy->push_back(InitialEnergy_);
InteractionTime->push_back(InteractionTime_);
InteractionVertexX->push_back(InteractionVertexX_);
InteractionVertexY->push_back(InteractionVertexY_);
InteractionVertexZ->push_back(InteractionVertexZ_);
}
}
else if(TreeName_=="PrimaryParticle")
{
for(int i = 0; i < input_tree->GetEntries(); i++)
{
input_tree->GetEntry(i);
PrimaryPDG.push_back(PrimaryPDG_);
PrimaryEnergy->push_back(PrimaryEnergy_);
PrimaryPx->push_back(PrimaryPx_);
PrimaryPy->push_back(PrimaryPy_);
PrimaryPz->push_back(PrimaryPz_);
}
}
else if(TreeName_=="Background")
{
for(int i = 0; i < input_tree->GetEntries(); i++)
{
input_tree->GetEntry(i);
BackgroundDecayTime->push_back(BackgroundDecayTime_);
BackgroundAtomicNumber->push_back(BackgroundAtomicNumber_);
BackgroundAtomicMass->push_back(BackgroundAtomicMass_);
BackgroundVertexX->push_back(BackgroundVertexX_);
BackgroundVertexY->push_back(BackgroundVertexY_);
BackgroundVertexZ->push_back(BackgroundVertexZ_);
}
}
}//Get_Event
//--------------------------------------------------------------------------
// Reset the event
void ROOTFileManager::EventReset()
{
int run=-1;
hitX_start->clear();
hitX_end->clear();
hitY_start->clear();
hitY_end->clear();
hitZ_start->clear();
hitZ_end->clear();
time_start->clear();
time_end->clear();
edep->clear();
length->clear();
pdg->clear();
InitialPDG.clear();
InteractionTime->clear();
InitialEnergy->clear();
InteractionVertexX->clear();
InteractionVertexY->clear();
InteractionVertexZ->clear();
PrimaryPDG.clear();
PrimaryEnergy->clear();
PrimaryPx->clear();
PrimaryPy->clear();
PrimaryPz->clear();
BackgroundDecayTime->clear();
BackgroundAtomicMass->clear();
BackgroundAtomicNumber->clear();
BackgroundVertexX->clear();
BackgroundVertexY->clear();
BackgroundVertexZ->clear();
}
//--------------------------------------------------------------------------
// Get number of entries
int ROOTFileManager::NEntries()
{
return input_tree->GetEntries();
}
//--------------------------------------------------------------------------
// Close input file
void ROOTFileManager::CloseInput()
{
input_file->Close();
delete input_file;
}