summaryrefslogtreecommitdiff
path: root/src/main/Quadrupole.cc
blob: 9b1c3e942b7690b3a337aaba8743eb8e4dd7bacd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Quadrupole.cc
 *
 *  Created on: Mar 29, 2011
 *      Author: jakob
 */

#include <iostream>
#include <sstream>
#include "Quadrupole.h"

namespace vhc {

Quadrupole::Quadrupole(const Vector3D& entry, const Vector3D& exit, double sectionRadius, double focalizingCoefficient, Element* next):
		StraightElement(entry, exit, sectionRadius, next),
		focalizingCoefficient(focalizingCoefficient)
	{};

Quadrupole::~Quadrupole() {};

Vector3D Quadrupole::magneticFieldAt(const Vector3D& position) const {
	Vector3D x = position - getEntryPosition();
	Vector3D d = getDiagonal().unit();
	Vector3D y = x - x.dot(d) * d;
	Vector3D u = Vector3D::k.cross(d);
	return focalizingCoefficient * (y.dot(u) * Vector3D::k + position.getZ() * u);
}

double Quadrupole::getFocalizingCoefficient() const {
	return focalizingCoefficient;
}

void Quadrupole::setFocalizingCoefficient(double value) {
	focalizingCoefficient = value;
}

std::string Quadrupole::getType() const {return "Quadrupole";}
std::string Quadrupole::toString() const {
	std::stringstream s;
	s << Element::toString() << "\n";
	s << "\tfocalizing coefficient: " << focalizingCoefficient;
	return s.str();
}

void Quadrupole::accept(const ElementVisitor& v) const {v.visit(this);}

Quadrupole* Quadrupole::clone() const {return new Quadrupole(getEntryPosition(), getExitPosition(), getSectionRadius(), focalizingCoefficient);}


}