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