11 #include<FairRunSim.h>
13 #include<FairPrimaryGenerator.h>
14 #include<FairBoxGenerator.h>
19 #include<FairParRootFileIo.h>
32 #include "TPolyLine3D.h"
36 #include<TApplication.h>
37 #include "TGLViewer.h"
38 #include <TGeoManager.h>
39 #include "TGeoMaterial.h"
40 #include "TGeoMedium.h"
41 #include "TGeoVolume.h"
44 #include "FairGeoLoader.h"
45 #include "FairGeoInterface.h"
46 #include "FairGeoMedia.h"
47 #include "FairGeoBuilder.h"
48 #include "FairModule.h"
62 gROOT->Macro(
"$VMCWORKDIR/gconfig/rootlogon.C");
64 cout <<
" setup of visualization " << endl;
65 TApplication* myapp = NULL;
66 TCanvas *canvas_fieldlines = NULL;
67 myapp =
new TApplication(
"myapp",0,0);
70 TString vmcWorkdir = gSystem->Getenv(
"VMCWORKDIR");
72 FairGeoLoader*
geoLoad =
new FairGeoLoader(
"TGeo",
"FairGeoLoader");
73 FairGeoInterface*
geoFace = geoLoad->getGeoInterface();
74 geoFace->setMediaFile(vmcWorkdir +
"/geometry/media_pnd.geo");
77 FairGeoMedia*
geoMedia = geoFace->getMedia();
79 FairGeoBuilder*
geoBuild = geoLoad->getGeoBuilder();
80 Int_t
nmed=geoBuild->createMedium(FairMediumAir);
82 top_vol->SetVisibility(0);
84 TFile* solenoid_file =
new TFile(
"$VMCWORKDIR/geometry/FullSolenoid.root" ,
"OPEN");
85 TGeoVolume * solenoid = (TGeoVolume*) solenoid_file->Get(
"topNode");
87 cout <<
" 'Error: no solenoid file found to display " << endl;
89 solenoid->SetLineColor(12);
90 solenoid->SetTransparency(50);
93 TFile* beampipe_file =
new TFile(
"$VMCWORKDIR/geometry/beampipe_201309.root" ,
"OPEN");
94 TGeoVolume * beampipe = (TGeoVolume*) beampipe_file->Get(
"pipeassembly");
96 cout <<
" 'Error: no beam pipe file found to display " << endl;
98 beampipe->SetTransparency(50);
99 top_vol->AddNode(beampipe, 1);
101 TFile* lmd_setup_file =
new TFile(
"$VMCWORKDIR/geometry/Dipole.root" ,
"OPEN");
102 TGeoVolume * lmd_setup = (TGeoVolume*) lmd_setup_file->Get(
"cave");
104 cout <<
" 'Error: no lmd setup found to display " << endl;
107 lmd_setup->SetTransparency(50);
111 top_vol->Draw(
"ogl");
113 cout <<
" loading panda field map for 1.5 GeV/c beam momentum" << endl;
137 const double x_min = -30.;
138 const double x_max = 30.;
139 const double y_min = -30.;
140 const double y_max = 30.;
141 const double z_min = -172.;
142 const double z_max = 660.;
145 cout <<
" drawing the field bounding box" << endl;
151 for (
int ix1 = 0; ix1 < 2; ix1++){
152 if (ix1) x[0] = x_min;
else x[0] = x_max;
153 for (
int ix2 = 0; ix2 < 2; ix2++){
154 if (ix2) x[1] = x_min;
else x[1] = x_max;
155 for (
int iy1 = 0; iy1 < 2; iy1++){
156 if (iy1) y[0] = y_min;
else y[0] = y_max;
157 for (
int iy2 = 0; iy2 < 2; iy2++){
158 if (iy2) y[1] = y_min;
else y[1] = y_max;
159 for (
int iz1 = 0; iz1 < 2; iz1++){
160 if (iz1) z[0] = z_min;
else z[0] = z_max;
161 for (
int iz2 = 0; iz2 < 2; iz2++){
162 if (iz2) z[1] = z_min;
else z[1] = z_max;
163 line =
new TPolyLine3D(2, x, y, z);
164 line->SetLineColor(3);
175 vector<double>xstart_prev;
176 vector<double>ystart_prev;
177 vector<double>zstart_prev;
178 vector<int> line_color;
181 if (xstart_prev.size()==0){
187 double pval[3] = {0.,0.,0.};
188 double Bval[3] = {0.,0.,0.};
192 const double B_strength_init =
fabs(Bval[2]);
193 cout <<
" the solenoid field strength is " << B_strength_init;
195 const double norm_step_size = 0.2;
199 cout <<
" initializing solenoid grid for field lines " << endl;
200 for (
double iy = -2.; iy < 2.; iy += norm_step_size){
201 for (
double ix = -2.; ix < 2.; ix += norm_step_size){
202 xstart_prev.push_back(ix);
203 ystart_prev.push_back(iy);
204 zstart_prev.push_back(0.);
206 line_color.push_back(color);
217 const double dipole_middle_z = 475.;
218 const double iy = 0.;
222 cout <<
" creating variables " << endl;
223 bool print_info =
true;
225 const int max_mods = 250;
226 found_mod =
new bool*[max_mods];
227 for (
int i = 0;
i < max_mods;
i++)
228 found_mod[
i] =
new bool[max_mods];
229 cout <<
" initializing dipole grid for field lines " << endl;
230 for (
int dir_x = -1; dir_x < 2; dir_x += 2){
231 for (
int dir_z = -1; dir_z < 2; dir_z += 2){
232 for (
int i = 0;
i < max_mods;
i++){
233 for (
int j = 0; j < max_mods; j++){
234 found_mod[
i][j] =
false;
237 for (
double _ix = 0.; _ix < 200.; _ix += .1){
238 for (
double _iz = 0.; _iz < 500.; _iz += .1){
240 if ((_ix == 0 && dir_x == -1) || (_iz == 0 && dir_z == -1))
continue;
241 double ix = _ix*dir_x;
242 double iz = _iz*dir_z + dipole_middle_z;
250 if (!(x_min < pval[0] && pval[0] < x_max)||
251 !(y_min < pval[1] && pval[1] < y_max)||
252 !(z_min < pval[2] && pval[2] < z_max)){
260 cout <<
" dipole field strength to normalize to is " << Bval[1] << endl;
262 int mod_x = (int) floor(
fabs(_ix/norm_step_size*Bval[1]/B_strength_init));
263 int mod_z = (int) floor(
fabs(_iz/norm_step_size*Bval[1]/B_strength_init));
264 if (mod_x >= max_mods || mod_z >= max_mods || mod_x < 0 || mod_z < 0){
265 cout <<
" Grid is out of bounds for mod x " << mod_x <<
" mod z " << mod_z << endl;
268 if (!found_mod[mod_x][mod_z]){
269 found_mod[mod_x][mod_z] =
true;
270 xstart_prev.push_back(ix);
271 ystart_prev.push_back(iy);
272 zstart_prev.push_back(iz);
274 line_color.push_back(color);
280 cout <<
" deleting " << endl;
281 for (
int i = 0;
i < max_mods;
i++)
282 delete[] found_mod[
i];
289 cout <<
" drawing field lines " << endl;
292 for (
int direction = 1; direction > -2; direction -= 2){
293 for (
unsigned int istartpoint = 0; istartpoint < xstart_prev.size(); istartpoint++){
295 double stepsize = d_x;
296 if (d_y < stepsize) stepsize = d_y;
297 if (d_z < stepsize) stepsize = d_z;
301 xs.push_back(xstart_prev[istartpoint]);
302 ys.push_back(ystart_prev[istartpoint]);
303 zs.push_back(zstart_prev[istartpoint]);
305 for (
int ipoint = 1; ipoint <
npoints; ipoint++){
307 double pval[3] = {xs[ipoint-1],ys[ipoint-1],zs[ipoint-1]};
312 if (!(x_min < pval[0] && pval[0] < x_max)||
313 !(y_min < pval[1] && pval[1] < y_max)||
314 !(z_min < pval[2] && pval[2] < z_max)){
324 double fieldstrength =
sqrt(Bval[0]*Bval[0]+Bval[1]*Bval[1]+Bval[2]*Bval[2]);
325 pval[0] = pval[0] + stepsize/fieldstrength*Bval[0]*direction;
326 pval[1] = pval[1] + stepsize/fieldstrength*Bval[1]*direction;
327 pval[2] = pval[2] + stepsize/fieldstrength*Bval[2]*direction;
329 xs.push_back(pval[0]);
330 ys.push_back(pval[1]);
331 zs.push_back(pval[2]);
336 TPolyLine3D* fieldline =
new TPolyLine3D(xs.size(), &xs[0], &ys[0], &zs[0]);
337 fieldline->SetLineColor(line_color[istartpoint]);
338 fieldline->Draw(
"same");
340 for (
unsigned int ipoint = 0; ipoint < xs.size(); ipoint++){
341 xs[ipoint] = -xs[ipoint];
350 int main(
int argc,
char **argv) {
int main(int argc, char **argv)
friend F32vec4 sqrt(const F32vec4 &a)
void GetFieldValue(const Double_t point[3], Double_t *bField)
TGeoManager * gGeoManager
FairGeoMedium * FairMediumAir
void visualize_fieldmaps()
friend F32vec4 fabs(const F32vec4 &a)
void AddField(FairField *field)
FairGeoInterface * geoFace
vector< string > fieldmapnames
FairGeoBuilder * geoBuild