BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
ParticleSet.hh
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#ifndef PARTICLESET_H
19#define PARTICLESET_H
20
21#include <cmath>
22#include <map>
23
31{
32public:
33 BinValue():
34 value(0),
35 sumOfWeightsSquared(0)
36 {;}
37
38 inline void Fill(double weight = 1)
39 {
40 value += weight;
41 sumOfWeightsSquared += weight*weight;
42 };
43
44 inline void Reset() {value = 0; sumOfWeightsSquared = 0;}
45 inline double Error() const {return std::sqrt(sumOfWeightsSquared);}
46
47 double value;
48 double sumOfWeightsSquared;
49};
50
62{
63public:
64 void Fill(long int x,
65 double weight = 1)
66 {data[x].Fill(weight);}
67
68 std::map<long int,BinValue>::iterator begin() {return data.begin();}
69 std::map<long int,BinValue>::iterator end() {return data.end();}
70 std::map<long int,BinValue>::const_iterator begin() const {return data.begin();}
71 std::map<long int,BinValue>::const_iterator end() const {return data.end();}
72 bool empty() const {return data.empty();}
73
74 BinValue& operator[](const long int key) {return data[key];}
75 const BinValue& operator[](const long int key) const {return data.at(key);}
76
77 std::map<long int, BinValue> data;
78 unsigned long nEntries;
79};
80
81#endif
A simple bin definition for a histogram.
A very simple 'map' type histogram axis.