SND@LHC Software
Loading...
Searching...
No Matches
ShipCompField.cxx
Go to the documentation of this file.
1
6#include "ShipCompField.h"
7
8#include <iostream>
9
10ShipCompField::ShipCompField(const std::string& label,
11 TVirtualMagField* firstField) :
12 TVirtualMagField(label.c_str()),
13 theFields_()
14{
15 theFields_.push_back(firstField);
16}
17
18ShipCompField::ShipCompField(const std::string& label,
19 TVirtualMagField* firstField,
20 TVirtualMagField* secondField) :
21 TVirtualMagField(label.c_str()),
22 theFields_()
23{
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()),
31 theFields_(theFields)
32{
33}
34
36{
37 // The destructor does nothing since this class does not own
38 // the various TVirtualMagField pointers
39}
40
41void ShipCompField::Field(const Double_t* position, Double_t* B)
42{
43
44 // Loop over the fields and do a simple linear superposition
45
46 // First initialise the field components to zero
47 B[0] = 0.0, B[1] = 0.0, B[2] = 0.0;
48
49 std::vector<TVirtualMagField*>::const_iterator iter;
50 for (iter = theFields_.begin(); iter != theFields_.end(); ++iter) {
51
52 TVirtualMagField* theField = *iter;
53 if (theField) {
54
55 //std::cout<<"Finding field for "<<theField->GetName()<<std::endl;
56
57 // Find the magnetic field components for this part
58 Double_t BVect[3] = {0.0, 0.0, 0.0};
59 theField->Field(position, BVect);
60
61 // Simple linear superposition of the B field components
62 B[0] += BVect[0];
63 B[1] += BVect[1];
64 B[2] += BVect[2];
65
66 //std::cout<<"B = "<<BVect[0]<<", "<<BVect[1]<<", "<<BVect[2]<<std::endl;
67 //std::cout<<"BSum = "<<B[0]<<", "<<B[1]<<", "<<B[2]<<std::endl;
68
69 }
70
71 }
72
73}
ShipCompField(const std::string &label, TVirtualMagField *firstField)
Main constructor.
std::vector< TVirtualMagField * > theFields_
The vector of the various magnetic field pointers comprising the composite.
virtual void Field(const Double_t *position, Double_t *B)
The total magnetic field from all of the composite sources (linear superposition)
virtual ~ShipCompField()
Destructor.