FairShip
Loading...
Searching...
No Matches
ShipCompField.cxx
Go to the documentation of this file.
1
// SPDX-License-Identifier: LGPL-3.0-or-later
2
// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3
// Collaboration
4
9
10
#include "
ShipCompField.h
"
11
12
#include <iostream>
13
14
ShipCompField::ShipCompField
(
const
std::string& label,
15
TVirtualMagField* firstField)
16
: TVirtualMagField(label.c_str()),
theFields_
() {
17
theFields_
.push_back(firstField);
18
}
19
20
ShipCompField::ShipCompField
(
const
std::string& label,
21
TVirtualMagField* firstField,
22
TVirtualMagField* secondField)
23
: TVirtualMagField(label.c_str()),
theFields_
() {
24
theFields_
.push_back(firstField);
25
theFields_
.push_back(secondField);
26
}
27
28
ShipCompField::ShipCompField
(
const
std::string& label,
29
const
std::vector<TVirtualMagField*>& theFields)
30
: TVirtualMagField(label.c_str()),
theFields_
(theFields) {}
31
32
// Default destructor: the TVirtualMagField pointers are not owned by this
33
// class.
34
ShipCompField::~ShipCompField
() =
default
;
35
36
void
ShipCompField::Field
(
const
Double_t* position, Double_t* B) {
37
// Loop over the fields and do a simple linear superposition
38
39
// First initialise the field components to zero
40
B[0] = 0.0, B[1] = 0.0, B[2] = 0.0;
41
42
for
(
auto
* theField :
theFields_
) {
43
if
(theField) {
44
// std::cout<<"Finding field for "<<theField->GetName()<<std::endl;
45
46
// Find the magnetic field components for this part
47
Double_t BVect[3] = {0.0, 0.0, 0.0};
48
theField->Field(position, BVect);
49
50
// Simple linear superposition of the B field components
51
B[0] += BVect[0];
52
B[1] += BVect[1];
53
B[2] += BVect[2];
54
55
// std::cout<<"B = "<<BVect[0]<<", "<<BVect[1]<<", "<<BVect[2]<<std::endl;
56
// std::cout<<"BSum = "<<B[0]<<", "<<B[1]<<", "<<B[2]<<std::endl;
57
}
58
}
59
}
ShipCompField.h
ShipCompField::ShipCompField
ShipCompField(const std::string &label, TVirtualMagField *firstField)
Main constructor.
Definition
ShipCompField.cxx:14
ShipCompField::theFields_
std::vector< TVirtualMagField * > theFields_
The vector of the various magnetic field pointers comprising the composite.
Definition
ShipCompField.h:80
ShipCompField::~ShipCompField
~ShipCompField() override
Destructor.
ShipCompField::Field
void Field(const Double_t *position, Double_t *B) override
Definition
ShipCompField.cxx:36
field
ShipCompField.cxx
Generated by
Doxygen
1.15.0