FairShip
Loading...
Searching...
No Matches
ShipBellField.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// -------------------------------------------------------------------------
6// ----- ShipBellField source file -----
7// -------------------------------------------------------------------------
8#include "ShipBellField.h"
9
10#include <iomanip>
11#include <iostream>
12
13#include "ShipFieldPar.h"
14#include "math.h"
15
16using std::cerr;
17using std::cout;
18using std::endl;
19using std::setw;
20
21constexpr Double_t kilogauss = 1.;
22constexpr Double_t tesla = 10 * kilogauss;
23
24constexpr Double_t cm = 1; // cm
25constexpr Double_t m = 100 * cm; // m
26
27// ----- Default constructor -------------------------------------------
29 : FairField(), fPeak(0.), fMiddle(0.), fBtube(0.) {
30 fType = 1;
31 fInclTarget = kFALSE;
32}
33// -------------------------------------------------------------------------
34
35// ----- Standard constructor ------------------------------------------
36ShipBellField::ShipBellField(const char* name, Double_t Peak, Double_t Middle,
37 Int_t orientation, Double_t Btube)
38 : FairField(name), fPeak(Peak), fMiddle(Middle), fBtube(Btube) {
39 fType = 1;
40 fInclTarget = kFALSE;
41 fOrient = orientation;
42 fBtube = Btube;
43}
44// -------------------------------------------------------------------------
45
46// -------- Bell constructor from FieldPar -------------------------------
48 : FairField(), fPeak(0.), fMiddle(0.), fBtube(0.), fInclTarget(kFALSE) {
49 if (!fieldPar) {
50 cerr << "-W- ShipBellField::ShipBellField: empty parameter container!"
51 << endl;
52 fType = 0;
53 } else {
54 fPeak = fieldPar->GetPeak();
55 fMiddle = fieldPar->GetMiddle();
56 fBtube = fieldPar->GetBtube();
57 fType = fieldPar->GetType();
58 }
59}
60// -------------------------------------------------------------------------
61
62// ----- Destructor ----------------------------------------------------
64// -------------------------------------------------------------------------
65
66// ----- Get x component of field --------------------------------------
67void ShipBellField::IncludeTarget(Double_t xy, Double_t z, Double_t l) {
68 fInclTarget = kTRUE;
69 targetXY = xy;
70 targetZ0 = z;
71 targetL = l;
72}
73// ----- Get x component of field --------------------------------------
74Double_t ShipBellField::GetBx(Double_t x, Double_t y, Double_t z) {
75 if (fOrient == 1) {
76 return 0.;
77 } else {
78 Double_t zlocal = fabs(z - fMiddle) / 100.; // zlocal: convert cm->m
79 // old Bell field from Wilfried Flegel
80 // Double_t bx= fPeak/(1.+pow(fabs(zlocal)/2.1,6.));
81 // new field based on simulation of Davide Tommasini (22/1/2015)
82
83 Double_t bx = 0.;
84 // field in box 20 cm larger than inner tube.
85 if ((fabs(x) < 2.7 * m) && (fabs(y) < fBtube + 0.2 * m)) {
86 if (zlocal < 3.8) {
87 bx = 0.14361 * exp(-0.5 * pow((zlocal - 0.45479E-01) / 2.5046, 2.));
88 } else if (zlocal < 11.9) {
89 bx = 0.19532 - 0.61512E-01 * zlocal + 0.68447E-02 * pow(zlocal, 2.) -
90 0.25672E-03 * pow(zlocal, 3.);
91 }
92 bx = ((fPeak / tesla) / 0.14361) * bx * tesla;
93 }
94 // cout << "Bell GetBX " << x << ", " << y << ", " << z << ", Bx= " << bx <<
95 // endl;
96 return bx;
97 }
98}
99
100// -------------------------------------------------------------------------
101
102// ----- Get y component of field --------------------------------------
103Double_t ShipBellField::GetBy(Double_t x, Double_t y, Double_t z) {
104 Double_t by = 0.;
105 if (fInclTarget && z < targetZ0 + targetL && z > targetZ0) {
106 // check if in target area
107 if (fabs(x) < targetXY && fabs(y) < targetXY) {
108 by = 1 * tesla;
109 }
110 if (fabs(x) > 2 * targetXY && fabs(x) < 3 * targetXY &&
111 fabs(y) < targetXY) {
112 by = -1 * tesla;
113 }
114 } else if (fOrient == 1) {
115 Double_t zlocal = (z - fMiddle) / 100.;
116 by = fPeak / (1. + pow(fabs(zlocal) / 2.1, 6.));
117 // cout << "Bell GetBY " << z << ", By= " << by << endl;
118 }
119 return by;
120}
121// -------------------------------------------------------------------------
122
123// ----- Get z component of field --------------------------------------
124Double_t ShipBellField::GetBz(Double_t x, Double_t y, Double_t z) { return 0.; }
125// -------------------------------------------------------------------------
126
127// ----- Screen output -------------------------------------------------
128void ShipBellField::Print(Option_t*) const {
129 cout << "======================================================" << endl;
130 cout << "---- " << fTitle << " : " << fName << endl;
131 cout << "----" << endl;
132 cout << "---- Field type : Bell" << endl;
133 cout << "----" << endl;
134 cout.precision(4);
135 cout << "---- Peak field : " << fPeak << " kG" << endl;
136 cout << "---- Middle (z centre) : " << fMiddle << " cm" << endl;
137 cout << "---- Btube : " << fBtube << " cm" << endl;
138 cout << "---- Orientation : " << fOrient << endl;
139 cout << "---- Include target : " << (fInclTarget ? "yes" : "no") << endl;
140 cout << "======================================================" << endl;
141}
142// -------------------------------------------------------------------------
constexpr Double_t kilogauss
constexpr Double_t cm
constexpr Double_t tesla
constexpr Double_t m
Double_t targetL
Double_t targetZ0
void Print(Option_t *="") const override
Double_t GetBz(Double_t x, Double_t y, Double_t z) override
~ShipBellField() override
Double_t GetBx(Double_t x, Double_t y, Double_t z) override
void IncludeTarget(Double_t xy, Double_t z, Double_t l)
Double_t targetXY
Double_t GetBy(Double_t x, Double_t y, Double_t z) override
Double_t fMiddle
Double_t fBtube
Double_t GetMiddle() const
Double_t GetPeak() const
Int_t GetType() const
Double_t GetBtube() const