BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
SamplerAnalysis.hh
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#ifndef SAMPLERANALYSIS_H
20#define SAMPLERANALYSIS_H
21
22#include "BDSOutputROOTEventSampler.hh"
23
31{
32public:
34
35 // Note compile time float / double templating.
36#ifndef __ROOTDOUBLE__
38 bool debugIn = false);
39#else
41 bool debugIn = false);
42#endif
44 void CommonCtor();
45 virtual ~SamplerAnalysis();
46
48 void Initialise();
49
51 void Process(bool firstTime = false);
52
54 std::vector<double> Terminate(std::vector<double> emittance,
55 bool useEmittanceFromFirstSampler = true);
56
58 std::vector<std::vector<double> > GetOpticalFunctions() {return optical;}
59
61 static void UpdateMass(SamplerAnalysis* s);
62
64 static void UpdateMass(const std::string& particleName);
65
66#ifndef __ROOTDOUBLE__
68#else
71#endif
72protected:
73
74 static double particleMass;
75
76 // sums - initialised to zero as that's what they start at
77 long long int npart;
78 double S;
79
80 //6d phase space coordinates for each event
81 std::vector<double> coordinates;
82
83 // initial values to use for mean subtraction.
84 std::vector<double> offsets;
85
86 typedef std::vector<std::vector<double>> twoDArray;
87 typedef std::vector<std::vector<std::vector<double>>> threeDArray;
88 typedef std::vector<std::vector<std::vector<std::vector<double>>>> fourDArray;
89
90 fourDArray powSums;
91 fourDArray cenMoms;
92
93 fourDArray powSumsFirst;
94 fourDArray cenMomsFirst;
95
96 threeDArray covMats;
97 threeDArray derivMats;
98 twoDArray optical;
99 twoDArray varOptical;
100
101
102
109 double powSumToCentralMoment(fourDArray& powSum,
110 long long int npartIn,
111 int i,
112 int j,
113 int m,
114 int n);
115
122 double centMomToCovariance(fourDArray& centMoms,
123 long long int npartIn,
124 int k,
125 int i,
126 int j);
127
135 double centMomToDerivative(fourDArray &centMoms, int k, int t, int i);
136
137
138 //Prints out the beam correlation matrix at that sampler to the console
139 //The beam correlation matrix gives good idication of the presence and magnitude of all couplings.
140 void printBeamCorrelationMatrix(fourDArray& centMoms);
141
142private:
143 bool debug;
144};
145
146#endif
Analysis routines for an individual sampler.
twoDArray optical
emt, alf, bta, gma, eta, etapr, mean, sigma
twoDArray varOptical
variances of optical functions
double centMomToDerivative(fourDArray &centMoms, int k, int t, int i)
void Initialise()
Initialise variables.
static void UpdateMass(SamplerAnalysis *s)
Set primary particle mass for optical functions from sampler data.
std::vector< std::vector< double > > GetOpticalFunctions()
Accessor for optical functions.
void CommonCtor()
Initialisation of arrays for optical function calculations.
void Process(bool firstTime=false)
Loop over all entries in the sampler and accumulate power sums over variuos moments.
double centMomToCovariance(fourDArray &centMoms, long long int npartIn, int k, int i, int j)
double powSumToCentralMoment(fourDArray &powSum, long long int npartIn, int i, int j, int m, int n)
std::vector< double > Terminate(std::vector< double > emittance, bool useEmittanceFromFirstSampler=true)
Calculate optical functions based on combinations of moments already accumulated.