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