source: ZHANGProjects/ICOSIM/CPP/trunk/source/simulation.h @ 2

Last change on this file since 2 was 2, checked in by zhangj, 10 years ago

Initial import

File size: 5.7 KB
Line 
1#ifndef SIMULATION_H
2#define SIMULATION_H
3#include <iostream>
4#include <iomanip>
5#include <fstream>
6#include <sstream>
7#include <vector>
8#include <algorithm>
9#include <string>
10
11#include <unistd.h>
12#include <signal.h>
13#include <assert.h>
14
15#if defined(FLUKA)
16#include "FlukaIO.h"
17#endif
18
19#include "lattice.h"
20using namespace std;
21/*
22##########################################################################################################
23
24This class contains all the tools that are necessary to run a simulation. It is called in the main.
25It is also where the link is made with Fluka when the lattice contains a Fluka Collimator.
26
27##########################################################################################################
28 */
29
30
31class Simulation
32{
33
34
35public:
36
37    //========================Constructors, destructor=====================
38
39    Simulation() {};
40
41    Simulation(int size_bunch, int nbre_elts, string genere = "standard");
42
43    virtual ~Simulation();
44
45    //=============================== Other methods ===============================
46
47
48    //base method simulating a run, it is called in the main and it calls the other functions
49
50    void run(string inputfile, string outputpath);
51
52
53    //method used to read the parameters in the collimator file
54
55    void readInputFile(string inputfile, double& Apr, double& Zpr, double& mass, double& energyPerIon, double& emix, double& emiy, int& npart, int& kbunch, double& sigdpp, int& taubeam, int& nparti, string& partdistr, double& r1r2skin, int& nrev1, int& nrev2, double& blowup2, int& blowupperiod, string& stoplineartracking, int& scaleorbit, double& wecolli, double& nsigi, string& opticsFile, double& thicknessmagneticfield, double& Bmax, double& deltaGap, int& beamflag, int& RunWithFluka, int& RunWithCrystal, double& freqrf, double& rfvoltage, double& rfharmonic, int& RunningFlag, int& idpart, int& idelt, int& outcoord, double& momentum, string& plotflag, string& inputpath, int& RFflag);
56
57
58    //method used to extract the parameters of the lattice in the optics file
59
60    void extractOpticsParameters(string opticsFile, const int& beamflag);
61
62
63    //method used to end a connection with an external server (e.g. Fluka)
64
65    void die(const char* msg);
66
67
68    //method used to initialize most of the parameters read in the input files
69
70    void defineParameters(string opticsFile, const int& beamflag,  int& JohnJaperFlag);
71
72
73    //method to read the parameters of a particles from a file
74
75    void readParticle(const double& Apr, const double& Zpr, string inputfile);
76
77
78    //linear interpolation method
79
80    double interp1(double x1, double y1, double x2, double y2, double x);
81
82
83    //method generating an initial bunch of particles
84
85    void genbunch(const int& i0, const int& npart, const string& partdistr, const double& r1r2skin, const double& emx, const double& emy, const double& sigdpp, const double& bx, const double& ax, const double& dx, const double& dpx, const double& by, const double& ay, const double& dy, const double& dpy, const double& nsigi);
86
87
88    //method used to display the coordinates of all particles in a bunch at a precise time (mostly used for tests)
89
90    void affichebunch();
91
92
93    //method used to write the file output_<inputfile>.txt
94
95    void writeoutput(string outputfile, const double& emix, const double& emiy, const double& Apr, const double& Zpr, const double& nparti, const double& beamflag, const double& PlossPb, const int& i0, const int& im, const int& npart, const int& kbunch, const vector <int>& asumrem, const vector <int>& asumhitcolli, const vector <int>& asumhits, const int& taubeam, vector <double>& hitso, const vector <int>& nhitcollio, vector <double>& Aphito, vector <double>& Zphito, const int& ibeg, const int& iend, vector <vector <double> >& xco, vector <vector <double> >& yco, const string& plotflag, string outputpath, string inputpath);
96
97
98    //method making three plots illustrating the result of an ICOSIM run:
99    // 1) the power load on each collimator (averagely during the beam lifetime)
100    // 2) the power loss in the ring as a function of s
101    // 3) how many particles there are left in the beam, how many particles that
102    // have been lost on a collimator, and how many particles that have been
103    // lost on the aperture, as a function of the number of revolutions.
104
105    void PlotRunSummary(const vector <int>& asumrem, const vector <int>& asumhitcolli, const vector <int>& asumhits, const vector <int>& nhitcollio, vector <double>& hitso, const double& PlossPb, string outputpath);
106
107
108    //makes plots that shows particle trajectories, trajectory of the reference particle, the beam envelope, the aperture and the collimators.
109
110    void PlotTrajectory(const double& emix, const double& emiy, const int& ibeg, const int& iend, vector <vector <double> >& xco, vector <vector <double> >& yco, string outputpath);
111
112
113    //makes a histogram that shows the losses on the aperture along the ring
114
115    void PlotLossSpectra(const double& beamflag, const double& nparti, const vector <int>& asumrem, const double& Apr, const double& Zpr, vector <double>& hitso, vector <double>& Aphito, vector <double>& Zphito, const double& PlossPb, const int& npart, const int& kbunch, const int& taubeam, const vector <int>& nhitcollio, string outputpath, string inputpath);
116
117
118    //====================================== Attributs  ======================================================
119
120private:
121
122    int sizeBunch; // size of the bunch
123    vector <Particle> bunch; //bunch of particles
124    vector <Particle> bunchhit; //contains the particles that hit a primary collimator during the linear tracking; input bunch for the non-linear tracking
125    int nbre_elts; //number of elements in the lattice
126    Lattice lat; //lattice (see class lattice)
127
128
129};
130
131#endif
Note: See TracBrowser for help on using the repository browser.