BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
SamplerAnalysis.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 SAMPLERANALYSIS_H
19#define SAMPLERANALYSIS_H
20
21#include "BDSOutputROOTEventSampler.hh"
22
30{
31public:
33
34 // Note compile time float / double templating.
35#ifndef __ROOTDOUBLE__
37 bool debugIn = false);
38#else
40 bool debugIn = false);
41#endif
43 void CommonCtor();
44 virtual ~SamplerAnalysis();
45
47 void Initialise();
48
50 void Process(bool firstTime = false);
51
53 std::vector<double> Terminate(std::vector<double> emittance,
54 bool useEmittanceFromFirstSampler = true);
55
57 std::vector<std::vector<double> > GetOpticalFunctions() {return optical;}
58
60 static void UpdateMass(SamplerAnalysis* s);
61
63 static void UpdateMass(const std::string& particleName);
64
65#ifndef __ROOTDOUBLE__
67#else
70#endif
71protected:
72
73 static double particleMass;
74
75 // sums - initialised to zero as that's what they start at
76 long long int npart;
77 double S;
78
79 //6d phase space coordinates for each event
80 std::vector<double> coordinates;
81
82 // initial values to use for mean subtraction.
83 std::vector<double> offsets;
84
85 typedef std::vector<std::vector<double>> twoDArray;
86 typedef std::vector<std::vector<std::vector<double>>> threeDArray;
87 typedef std::vector<std::vector<std::vector<std::vector<double>>>> fourDArray;
88
89 fourDArray powSums;
90 fourDArray cenMoms;
91
92 fourDArray powSumsFirst;
93 fourDArray cenMomsFirst;
94
95 threeDArray covMats;
96 threeDArray derivMats;
97 twoDArray optical;
98 twoDArray varOptical;
99
100
101
108 double powSumToCentralMoment(fourDArray& powSum,
109 long long int npartIn,
110 int i,
111 int j,
112 int m,
113 int n);
114
121 double centMomToCovariance(fourDArray& centMoms,
122 long long int npartIn,
123 int k,
124 int i,
125 int j);
126
134 double centMomToDerivative(fourDArray &centMoms, int k, int t, int i);
135
136
137 //Prints out the beam correlation matrix at that sampler to the console
138 //The beam correlation matrix gives good idication of the presence and magnitude of all couplings.
139 void printBeamCorrelationMatrix(fourDArray& centMoms);
140
141private:
142 bool debug;
143};
144
145#endif
Information stored per sampler per event.
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.