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