Writing your own program - Merlin++ user script fundamentals
Merlin++ follows a relatively simple overarching design in that a user script can be thought of in just five parts.
- Defining the lattice
- Defining the beam
- Defining the tracker
- Running the simulation
- Post-processing & output of results
The following provides a code snippet corresponding to each part. Note that this is simply an example of the most basic implementation and more advanced methods can be found in the tutorials.
-
Defining the Lattice (A or B)
A) Define lattice apertures manually within Merlin++
AcceleratorModelConstructor newModel();
newModel.NewModel();
newModel.AppendComponent(new Quadrupole( QF ,1.0,5.5));
newModel.AppendComponent(new Drift( D1 ,12.55));
newModel.AppendComponent(new SectorBend( BFD ,5.0,0.0255,11.23));
newModel.AppendComponent(new Drift( D1 ,12.55));
newModel.AppendComponent(new Quadrupole( QD ,1.0,-5.5));
// etc..
AcceleratorModel* theModel = newModel.GetModel();
B) Importing MAD optices/lattice apertures file
MADInterface madInterface("/path/to/lattice.tfs", beamenergy);
AcceleratorModel* theModel = madInterface.ConstructModel();
-
Defining the Beam
ParticleBunch* theBunch = new ParticleBunch(beamenergy);
particleBunch->AddParticle(co);
-
Defining the Tracker
ParticleTracker tracker(theModel->GetBeamline(), theBunch);
-
Running the Simulation
tracker.Run();
-
Processing & Output of Results
// Prior to running the tracker:
ofstream trackingLog("build/trackinginfo.out");
// Post running the tracker:
ParticleBunch& tracked = tracker.GetTrackedBunch();
tracked.Output(trackingLog);
// Tracking data can be imported and plotted in python/octave etc