OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Probe.cpp
Go to the documentation of this file.
1//
2// Class Probe
3// Interface for a probe
4//
5// Copyright (c) 2016-2020, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#include "AbsBeamline/Probe.h"
20#include "PartBunch/PartBunch.h"
21#include "Physics/Physics.h"
22#include "Physics/Units.h"
25
26extern Inform* gmsg;
27
29
30Probe::Probe(const std::string& name) : PluginElement(name), step_m(0.0) {}
31
32Probe::Probe(const Probe& right) : PluginElement(right), step_m(right.step_m) {}
33
35
36void Probe::accept(BeamlineVisitor& visitor) const { visitor.visitProbe(*this); }
37
39 bool singlemode = (bunch->getParticleContainer()->getTotalNum() == 1) ? true : false;
40 peakfinder_m = std::unique_ptr<PeakFinder>(
41 new PeakFinder(getOutputFN(), rmin_m, rend_m, step_m, singlemode));
42}
43
45 *gmsg << "* Probe " << getName() << " goes offline" << endl;
46 if (online_m && peakfinder_m) peakfinder_m->save();
47 peakfinder_m.reset(nullptr);
48}
49
50void Probe::setStep(double step) { step_m = step; }
51
52double Probe::getStep() const { return step_m; }
53
55 Vector_t<double, 3> rmin, rmax;
56 bunch->get_bounds(rmin, rmax);
57 // interested in absolute minimum and maximum
58 double xmin = std::min(std::abs(rmin(0)), std::abs(rmax(0)));
59 double xmax = std::max(std::abs(rmin(0)), std::abs(rmax(0)));
60 double ymin = std::min(std::abs(rmin(1)), std::abs(rmax(1)));
61 double ymax = std::max(std::abs(rmin(1)), std::abs(rmax(1)));
62 double rbunch_min = std::hypot(xmin, ymin);
63 double rbunch_max = std::hypot(xmax, ymax);
64
65 if (rbunch_max > rmin_m - 0.01 && rbunch_min < rend_m + 0.01) {
66 return true;
67 }
68 return false;
69}
70
72 PartBunch_t* bunch, const int turnnumber, const double /*t*/, const double tstep) {
73 *gmsg << "passed t argument not used in Probe::doCheck" << endl;
74 Vector_t<double, 3> probepoint;
75 size_t tempnum = bunch->getParticleContainer()->getLocalNum();
76
77 for (unsigned int i = 0; i < tempnum; ++i) {
78 double tangle = calculateIncidentAngle(bunch->P(i)(0), bunch->P(i)(1));
79 changeWidth(bunch, i, tstep, tangle);
80 int pflag = checkPoint(bunch->R(i)(0), bunch->R(i)(1));
81 if (pflag == 0) continue;
82 // calculate closest point at probe -> better to use momentum direction
83 // probe: y = -A/B * x - C/B or A*X + B*Y + C = 0
84 // perpendicular line through R: y = B/A * x + R(1) - B/A * R(0)
85 // probepoint(0) = (B_m*B_m*bunch->R(i)(0) - A_m*B_m*bunch->R(i)(1) - A_m*C_m) / (R_m*R_m);
86 // probepoint(1) = (A_m*A_m*bunch->R(i)(1) - A_m*B_m*bunch->R(i)(0) - B_m*C_m) / (R_m*R_m);
87 // probepoint(2) = bunch->R(i)(2);
88 // calculate time correction for probepoint
89 // dist1 > 0, right hand, dt > 0; dist1 < 0, left hand, dt < 0
90 double dist1 = (A_m * bunch->R(i)(0) + B_m * bunch->R(i)(1) + C_m) / R_m; // [m]
91 double dist2 = dist1 * std::sqrt(1.0 + 1.0 / tangle / tangle);
92 // double dt =
93 // dist2 / (std::sqrt(1.0 - 1.0 / (1.0 + dot(bunch->P(i), bunch->P(i)))) * Physics::c);
94
95 // ADA probepoint = bunch->R(i) + dist2 * bunch->P(i) / euclidean_norm(bunch->P(i));
96 probepoint = bunch->R(i) + dist2 * bunch->P(i) / std::sqrt(dot(bunch->P(i), bunch->P(i)));
97
98 // peak finder uses millimetre not metre
99 peakfinder_m->addParticle(probepoint * Units::m2mm);
100
101 // ADA lossDs_m->addParticle(
102 // OpalParticle(bunch->ID(i), probepoint, bunch->P(i), t + dt, bunch->Q(i), bunch->M(i)),
103 // std::make_pair(turnnumber, (int)
104 //
105 // 3bunch->bunchNum(i)));
106 }
107
108 peakfinder_m->evaluate(turnnumber);
109
110 // we do not lose particles in the probe
111 return false;
112}
113
Inform * gmsg
Definition changes.cpp:7
ippl::Vector< T, Dim > Vector_t
ElementType
Definition ElementBase.h:94
Template PIC bunch: IPPL PicManager, shared field mesh/solver, and multiple particle containers.
Inform * gmsg
Definition changes.cpp:7
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Definition Vector3D.cpp:95
virtual void visitProbe(const Probe &)=0
Apply the algorithm to a Probe.
bool online_m
Definition Component.h:226
virtual const std::string & getName() const
Get element name.
std::string getOutputFN() const
Get output filename.
Vector_t< double, Dim > R(size_t)
Do not use; throws (access positions via ParticleContainer::R).
Definition PartBunch.h:611
Vector_t< double, Dim > P(size_t)
Do not use; throws (access momenta via ParticleContainer::P).
Definition PartBunch.h:620
void get_bounds(Vector_t< double, Dim > &rmin, Vector_t< double, Dim > &rmax)
Copy cached bunch extent (rmin_m, rmax_m) from calcBeamParameters.
Definition PartBunch.h:633
int checkPoint(const double &x, const double &y) const
Checks if coordinate is within element.
double C_m
Geometric lengths used in calculations.
void changeWidth(PartBunch_t *bunch, int i, const double tstep, const double tangle)
Change probe width depending on step size and angle of particle.
double calculateIncidentAngle(double xp, double yp) const
Calculate angle of particle/bunch wrt to element.
double rmin_m
radius closest to the origin
Definition Probe.h:28
void setStep(double step)
Set probe histogram bin width.
Definition Probe.cpp:50
virtual ~Probe()
Definition Probe.cpp:34
std::unique_ptr< PeakFinder > peakfinder_m
Pointer to Peakfinder instance.
Definition Probe.h:60
virtual void doInitialise(PartBunch_t *bunch) override
Initialise peakfinder file.
Definition Probe.cpp:38
virtual bool doCheck(PartBunch_t *bunch, const int turnnumber, const double t, const double tstep) override
Record probe hits when bunch particles pass.
Definition Probe.cpp:71
virtual bool doPreCheck(PartBunch_t *) override
Virtual hook for preCheck.
Definition Probe.cpp:54
double step_m
Step size of the probe (bin width in histogram file)
Definition Probe.h:59
Probe()
Definition Probe.cpp:28
virtual void doGoOffline() override
Hook for goOffline.
Definition Probe.cpp:44
virtual ElementType getType() const override
Get element type std::string.
Definition Probe.cpp:114
virtual double getStep() const
Member variable access.
Definition Probe.cpp:52
virtual void accept(BeamlineVisitor &) const override
Apply visitor to Probe.
Definition Probe.cpp:36
constexpr double m2mm
Definition Units.h:26