FairShip
Loading...
Searching...
No Matches
FairShipFields.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
5/*
6generic interface to B fields of FairShip
7assumes that magnetic fields for tracking are global fields, not matched to a
8volume.
9*/
10#include "FairShipFields.h"
11
12#include <iostream>
13
14#include "TVirtualMC.h"
15using std::cout;
16using std::endl;
17
18namespace genfit {
19
20FairShipFields::FairShipFields() : AbsBField() { ; }
21
22TVector3 FairShipFields::get(const TVector3& pos) const {
23 Double_t bx, by, bz;
24 get(pos.X(), pos.Y(), pos.Z(), bx, by, bz);
25 TVector3 field_(bx, by, bz);
26 return field_;
27}
28
29void FairShipFields::get(const double& x, const double& y, const double& z,
30 double& Bx, double& By, double& Bz) const {
31 Double_t X[3] = {x, y, z};
32 Double_t B[3] = {0., 0., 0.};
33 Bx = 0.;
34 By = 0.;
35 Bz = 0.;
36 if (!gMC && !gField_) {
37 cout << "no Field Manager instantiated" << endl;
38 return;
39 }
40 if (gMC) {
41 TVirtualMagField* magField = gMC->GetMagField();
42 if (!magField) {
43 cout << "no magnetic field set in the Virtual MC" << endl;
44 return;
45 }
46 magField->Field(X, B);
47 } else {
48 gField_->Field(X, B);
49 }
50 Bx = B[0];
51 By = B[1];
52 Bz = B[2];
53}
54
55} /* End of namespace genfit */
ShipCompField * gField_
TVector3 get(const TVector3 &pos) const override
return value at position