BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
Model.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "Model.hh"
19#include "RebdsimTypes.hh"
20
21#include "BDSOutputROOTEventModel.hh"
22
23#include "TTree.h"
24
25#include <iostream>
26#include <string>
27#include <vector>
28
29ClassImp(Model)
30
31Model::Model():
32 Model(false)
33{;}
34
35Model::Model(bool debugIn,
36 int dataVersionIn):
37 model(nullptr),
38 debug(debugIn),
39 dataVersion(dataVersionIn)
40{
41 model = new BDSOutputROOTEventModel();
42}
43
44Model::~Model()
45{
46 delete model;
47}
48
50 bool allBranchesOn,
51 const RBDS::VectorString* branchesToTurnOn)
52{
53 // turn off all branches by default.
54 t->SetBranchStatus("*", false);
55
56 if (allBranchesOn)
57 {t->SetBranchStatus("*", true);}
58 else if (branchesToTurnOn)
59 {
60 for (const auto& name : *branchesToTurnOn)
61 {
62 std::string nameStar = name + ".*"; // necessary because of the splitting
63 if (debug)
64 {std::cout << "Turning on branch \"" << nameStar << "\"" << std::endl;}
65 t->SetBranchStatus(nameStar.c_str(), true);
66 }
67 }
68
69 t->SetBranchAddress("Model.", &model);
70}
71
72std::vector<std::string> Model::SamplerNames() const
73{
74 if (model)
75 {return model->samplerNamesUnique;}
76 else
77 {return std::vector<std::string>();}
78}
79
80std::vector<std::string> Model::SamplerCNames() const
81{
82 return model ? model->samplerCNamesUnique : std::vector<std::string>();
83}
84
85std::vector<std::string> Model::SamplerSNames() const
86{
87 return model ? model->samplerSNamesUnique : std::vector<std::string>();
88}
89
90std::vector<std::string> Model::CollimatorNames() const
91{
92 if (dataVersion > 3)
93 {return model ? model->collimatorBranchNamesUnique : std::vector<std::string>();}
94 else
95 {return std::vector<std::string>();}
96}
Information stored per model representing accelerator.
std::vector< std::string > collimatorBranchNamesUnique
Vector of all collimator branch names in event tree used to load data.
Model loader.
Definition Model.hh:35
BDSOutputROOTEventModel * model
Member that ROOT can map file data to locally.
Definition Model.hh:63
std::vector< std::string > CollimatorNames() const
Access all the sampler branch names from the model.
Definition Model.cc:90
void SetBranchAddress(TTree *t, bool allBranchesOn=true, const RBDS::VectorString *branchesToTurnOn=nullptr)
Set the branch addresses to address the contents of the file.
Definition Model.cc:49
std::vector< std::string > SamplerNames() const
Access all the unique sampler names from the model.
Definition Model.cc:72