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
10#include "ShipCompField.h"
11
12#include <iostream>
13
14ShipCompField::ShipCompField(const std::string& label,
15 TVirtualMagField* firstField)
16 : TVirtualMagField(label.c_str()), theFields_() {
17 theFields_.push_back(firstField);
18}
19
20ShipCompField::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
28ShipCompField::ShipCompField(const std::string& label,
29 const std::vector<TVirtualMagField*>& theFields)
30 : TVirtualMagField(label.c_str()), theFields_(theFields) {}
31
33 // The destructor does nothing since this class does not own
34 // the various TVirtualMagField pointers
35}
36
37void ShipCompField::Field(const Double_t* position, Double_t* B) {
38 // Loop over the fields and do a simple linear superposition
39
40 // First initialise the field components to zero
41 B[0] = 0.0, B[1] = 0.0, B[2] = 0.0;
42
43 for (auto* theField : theFields_) {
44 if (theField) {
45 // std::cout<<"Finding field for "<<theField->GetName()<<std::endl;
46
47 // Find the magnetic field components for this part
48 Double_t BVect[3] = {0.0, 0.0, 0.0};
49 theField->Field(position, BVect);
50
51 // Simple linear superposition of the B field components
52 B[0] += BVect[0];
53 B[1] += BVect[1];
54 B[2] += BVect[2];
55
56 // std::cout<<"B = "<<BVect[0]<<", "<<BVect[1]<<", "<<BVect[2]<<std::endl;
57 // std::cout<<"BSum = "<<B[0]<<", "<<B[1]<<", "<<B[2]<<std::endl;
58 }
59 }
60}
Definition: diagrams_b.h:4
ShipCompField(const std::string &label, TVirtualMagField *firstField)
Main constructor.
std::vector< TVirtualMagField * > theFields_
The vector of the various magnetic field pointers comprising the composite.
Definition: ShipCompField.h:80
virtual void Field(const Double_t *position, Double_t *B)
virtual ~ShipCompField()
Destructor.