SND@LHC Software
Loading...
Searching...
No Matches
ShipGoliathField.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- ShipGoliathField source file -----
3// -------------------------------------------------------------------------
4#include "ShipGoliathField.h"
5#include "math.h"
6#include "TROOT.h"
7#include "TGeoNavigator.h"
8#include "TGeoNode.h"
9#include "TGeoManager.h"
10#include "TGeoBBox.h"
11#include "TVector3.h"
12#include "TTreeReader.h"
13#include "TTreeReaderValue.h"
14
15#include <iomanip>
16#include <iostream>
17
18using std::cout;
19using std::cerr;
20using std::endl;
21using std::setw;
22using std::div;
23
24
25// ----- Default constructor -------------------------------------------
27 : FairField()
28{
29}
30// -------------------------------------------------------------------------
31
32
33
34// ----- Standard constructor ------------------------------------------
36 : FairField(name)
37{
38}
39// -------------------------------------------------------------------------
40
41
42// ----- Destructor ----------------------------------------------------
44// -------------------------------------------------------------------------
45
46/*void ShipGoliathField::get(const double& posX, const double& posY, const double& posZ, double& Bx, double& By, double& Bz) const {
47 if ((posX < coords[0][0]) && (posX > coords[0][3]) && (posY < coords[0][1]) && (posY > coords[0][4]) && (posZ < coords[0][2]+5.) && (posZ>coords[0][5]+5.) ) {
48 Bx = GetBx(posX, posY, posZ);
49 By = GetBy(posX, posY, posZ);
50 Bz = GetBz(posX, posY, posZ);
51 }
52 else {
53 for (Int_t i=1;i<13;i++){
54 if ((posX < coords[i][0]) && (posX > coords[i][3]) && (posY < coords[i][1]) && (posY > coords[i][4]) && (posZ < coords[i][2]) && (posZ>coords[i][5])) {
55 Bx = 0.;
56 By = 0.5;
57 Bz = 0.;
58 break;
59 }
60 }
61 }
62}
63*/
64
65void ShipGoliathField::Init(const char* fieldfile){
66
67 fieldmap = TFile::Open(fieldfile);
68
69
70 TH3D* histbx= (TH3D*)fieldmap->Get("Bx");
71 TH3D* histby= (TH3D*)fieldmap->Get("By");
72 TH3D* histbz= (TH3D*)fieldmap->Get("Bz");
73 xmin = histbx->GetXaxis()->GetXmin();
74 xmax = histbx->GetXaxis()->GetXmax();
75 ymin = histbx->GetYaxis()->GetXmin();
76 ymax = histbx->GetYaxis()->GetXmax();
77 zmin = histbx->GetZaxis()->GetXmin();
78 zmax = histbx->GetZaxis()->GetXmax();
79
80 ShipGoliathField::sethistbxyz(histbx, histby, histbz);
81
82 /*
83 TVector3 bot,top;
84 std::cout<<"ShipGoliathField::setup: making string vector"<<std::endl;
85 std::vector<TString> volume={"/volGoliath_1/VolVacuum_1","/volGoliath_1/volLateralS1_1","/volGoliath_1/volLateralS2_1","/volGoliath_1/volLateralSurface1low_1",\
86 "/volGoliath_1/volLateralSurface2low_1","/volGoliath_1/volLateralS1_b_1","/volGoliath_1/volLateralS2_b_1","/volGoliath_1/volLateralSurface1blow_1",\
87 "/volGoliath_1/volLateralSurface2blow_1","/volGoliath_1/volLateralS1_d_1","/volGoliath_1/volLateralS2_d_1","/volGoliath_1/volLateralS1_c_1",\
88 "/volGoliath_1/volLateralS2_c_1"};
89 for (Int_t i=0;i<13;i++){
90 std::cout<<"ShipGoliathField::setup: getpos volume "<<volume[i]<<std::endl;
91 ShipGoliathField::getpos(volume[i],bot,top);
92 for (Int_t j=0;j<3;j++) {
93 coords[i][j]=top[j];
94 coords[i][j+3]=bot[j];
95 }
96
97 //std::cout<<volume[i]<<" "<<coords[i][3] << " posX " << posX <<" "<< coords[i][0] << ";" << coords[i][4] << " posY "<< posY <<" "<< coords[i][1] << ";" << coords[i][5] << " posZ " << posZ<<" "<< coords[i][2]<<std::endl;
98 }
99 */
100}
101
102
103void ShipGoliathField::getpos(TString volname, TVector3 &vbot, TVector3 &vtop) const {
104 std::cout<<"ShipGoliathField::getpos: GetCurrentNavigator volname "<<volname<<std::endl;
105 TGeoNavigator* nav;
106 if (gGeoManager) {
107 nav = gGeoManager->GetCurrentNavigator();}
108 else { std::cout<<"No geomanager"<<std::endl;}
109 std::cout<<"ShipGoliathField::getpos: cd to volume "<<volname<<std::endl;
110 Bool_t rc = nav->cd(volname);
111 if (not rc){
112 cout << "ShipGoliathfield::getpos, TGeoNavigator failed "<<volname<<endl;
113 return;
114 }
115 std::cout<<"ShipGoliathField::getpos GetCurrentNode"<<std::endl;
116 TGeoNode* W = nav->GetCurrentNode();
117 TGeoBBox* S = dynamic_cast<TGeoBBox*>(W->GetVolume()->GetShape());
118 Double_t top[3] = {S->GetDX(),S->GetDY(),S->GetDZ()};
119 Double_t bot[3] = {-S->GetDX(),-S->GetDY(),-S->GetDZ()};
120 Double_t Gtop[3],Gbot[3];
121 nav->LocalToMaster(top, Gtop);
122 nav->LocalToMaster(bot, Gbot);
123 vtop.SetXYZ(Gtop[0],Gtop[1],Gtop[2]);
124 vbot.SetXYZ(Gbot[0],Gbot[1],Gbot[2]);
125}
126
127
129 //char* mypath = std::getenv("mySHIPSOFT");
130 //strcat(mypath,"/FairShip/field/GoliathFieldMap.root");
131 //fieldmap->Close(mypath);
132 //gROOT->cd();
133}
134
135// ----- Get x component of field --------------------------------------
136Double_t ShipGoliathField::GetBx(Double_t x, Double_t y, Double_t z) {
137 Double_t bx=0.;
138 TH3D* hbx;
139
140 if ((x < xmin )|| (x> xmax) || (y < ymin) || (y>ymax) || ((z-350.75)<zmin) || ((z-350.75)>zmax)) {
141 return bx;}
142 // FairShip: 0 after absorber -384.5<target<-240 -239.9<absorber<0<T1T2<121<Goliath<481<T3T4<755 766.6<RPC<966.6
144 Int_t binx = hbx->GetXaxis()->FindBin(x);
145 Int_t biny = hbx->GetYaxis()->FindBin(y);
146 Int_t binz = hbx->GetZaxis()->FindBin(z - 350.75);
147 bx=hbx->GetBinContent(binx,biny,binz)*tesla;
148 //cout << "GetBX " << x << ", binx " << binx <<" y "<< y << " biny "<<biny<<" z "<< z << " binz "<<binz<<" Bx= " << bx << endl;
149 return bx;
150}
151
152// -------------------------------------------------------------------------
153
154
155// ----- Get y component of field --------------------------------------
156Double_t ShipGoliathField::GetBy(Double_t x, Double_t y, Double_t z) {
157 Double_t by=0.;
158 TH3D* hby;
159
160 if ((x < xmin )|| (x> xmax) || (y < ymin) || (y>ymax) || ((z-350.75)<zmin) || ((z-350.75)>zmax)) {
161 return by;}
163 Int_t binx = hby->GetXaxis()->FindBin(x);
164 Int_t biny = hby->GetYaxis()->FindBin(y);
165 Int_t binz = hby->GetZaxis()->FindBin(z- 350.75);
166 by=hby->GetBinContent(binx,biny,binz)*tesla;
167 return by;
168}
169
170// -------------------------------------------------------------------------
171
172
173
174// ----- Get z component of field --------------------------------------
175Double_t ShipGoliathField::GetBz(Double_t x, Double_t y, Double_t z) {
176 Double_t bz=0.;
177 TH3D* hbz;
178
179 if ((x < xmin )|| (x> xmax) || (y < ymin) || (y>ymax) || ((z-350.75)<zmin) || ((z-350.75)>zmax)) {
180 return bz;}
181
183 Int_t binx = hbz->GetXaxis()->FindBin(x);
184 Int_t biny = hbz->GetYaxis()->FindBin(y);
185 Int_t binz = hbz->GetZaxis()->FindBin(z- 350.75);
186 bz=hbz->GetBinContent(binx,biny,binz)*tesla;
187 return bz;
188}
189
190
191// -------------------------------------------------------------------------
192
193
194
195// ----- Screen output -------------------------------------------------
197 cout << "======================================================" << endl;
198 cout << "---- " << fTitle << " : " << fName << endl;
199 cout << "----" << endl;
200 cout << "---- Field type : constant" << endl;
201 cout << "----" << endl;
202 cout << "---- Field regions : " << endl;
203 cout.precision(4);
204 cout << "======================================================" << endl;
205}
206// -------------------------------------------------------------------------
207
208
209
211
212
TH3D * gethistby() const
TH3D * gethistbx() const
virtual Double_t GetBx(Double_t x, Double_t y, Double_t z)
void Init(const char *fieldfile)
virtual Double_t GetBz(Double_t x, Double_t y, Double_t z)
void sethistbxyz(TH3D *histbx, TH3D *histby, TH3D *histbz)
TH3D * gethistbz() const
virtual Double_t GetBy(Double_t x, Double_t y, Double_t z)
void getpos(TString vol, TVector3 &bot, TVector3 &top) const
return value at position
ClassImp(ecalContFact) ecalContFact