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] = {Bx, By, Bz};
33 if (!gMC && !gField_) {
34 cout << "no Field Manager instantiated" << endl;
35 return;
36 }
37 if (gMC) {
38 gMC->GetMagField()->Field(X, B);
39 } else {
40 gField_->Field(X, B);
41 }
42 Bx = B[0];
43 By = B[1];
44 Bz = B[2];
45}
46
47} /* End of namespace genfit */
Definition: diagrams_b.h:4
virtual void Field(const Double_t *position, Double_t *B)
TVector3 get(const TVector3 &pos) const
return value at position
ShipCompField * gField_