FairRoot/PandaRoot
DrawField.C
Go to the documentation of this file.
1 DrawField(TString Map, Double_t fBeamMom)
2 {
3  // Macro to plot the magnetic field
4 
5  Map.ToUpper();
6  PndMultiField *fField = new PndMultiField(Map.Data(), fBeamMom);
7 
8  fField->Init();
9 
10  Double_t x=0;
11  Double_t y=0;
12  Double_t z=0;
13  Double_t po[3], BB[3];
14  Double_t Btot=0;
15 
16  TH1F *Bx=new TH1F("Bx(z)","Bx(z)",850,-200,650);
17  TH1F *By=new TH1F("By(z)","By(z)",850,-200,650);
18  TH1F *Bz=new TH1F("Bz(z)","Bz(z)",850,-200,650);
19  TH1F *Btotal=new TH1F("B(z)","B(z)",850,-200,650);
20 
21  for (Int_t iz=0; iz<=850; iz++)
22  {
23  z = -200 + Double_t(iz);
24  po[0]=x; po[1]=y; po[2]=z;
25  BB[0]=0; BB[1]=0; BB[2]=0;
26  fField->GetFieldValue(po,BB); //return valuse in KG (G3)
27  // cout << "Z =" << z <<" Bx "<< BB[0] << " By " << BB[1] <<" Bz " << BB[2] <<endl;
28  Bx->SetBinContent(iz+1,BB[0]/ 10.);
29  By->SetBinContent(iz+1,BB[1]/ 10.);
30  Bz->SetBinContent(iz+1,BB[2]/ 10.);
31  Btot=TMath::Sqrt(BB[0]*BB[0]+BB[1]*BB[1]+BB[2]*BB[2]);
32  Btotal->SetBinContent(iz+1,Btot/ 10.);
33  }
34 
35 
36  THStack *h1= new THStack("B(z)","Panda Field X=Y=0") ;
37 
38  TCanvas *c1 = new TCanvas("c1", "c1",4,31,900,600);
39  c1->Range(-267,-0.285949,403,2.38354);
40  c1->SetBorderSize(2);
41  c1->SetFrameFillColor(0);
42 
43 
44  Bx->SetLineColor(2);
45  By->SetLineColor(3);
46  Bz->SetLineColor(4);
47 
48  h1->Add(Bx);
49  h1->Add(By);
50  h1->Add(Bz);
51  h1->Add(Btotal);
52 
53  h1->Draw("nostack");
54 
55  TPaveText *pt = new TPaveText(0.01,0.945,0.311609,0.995,"blNDC");
56  pt->SetName("title");
57  pt->SetBorderSize(2);
58  pt->SetFillColor(19);
59  TText *text = pt->AddText("Panda Field X=Y=0");
60  pt->Draw();
61 
62  pt = new TPaveText(148.439,1.2000,250.534,1.94786,"br");
63  pt->SetFillColor(19);
64  pt->Draw();
65  TLine *line = new TLine(160.,1.84535,193.685,1.84535);
66  line->Draw();
67 
68  tex = new TLatex(200.,1.81766,"Bz");
69  tex->SetLineWidth(2);
70  line->SetLineColor(4);
71  tex->Draw();
72 
73  line = new TLine(160.,1.6868,196.,1.6868);
74  line->SetLineColor(2);
75  line->Draw();
76 
77  tex = new TLatex(200.,1.64905,"Bx");
78  tex->SetLineWidth(2);
79  tex->Draw();
80 
81  line = new TLine(160.,1.51818,196.,1.51818);
82  line->SetLineColor(3);
83  line->Draw();
84 
85  tex = new TLatex(200.,1.4900,"By");
86  tex->SetLineWidth(2);
87  tex->Draw();
88 
89 
90  line = new TLine(160.,1.31818,196.,1.31818);
91  tex->SetLineWidth(2);
92  line->Draw();
93 
94  tex = new TLatex(200.,1.3100,"Bmod");
95  tex->SetLineWidth(2);
96  tex->Draw();
97 
98 
99 
100  tex = new TLatex(-224.51,0.970725,"Tesla");
101  tex->SetTextSize(0.054717);
102  tex->SetTextAngle(90.0);
103  tex->SetLineWidth(2);
104  tex->Draw();
105 
106  tex = new TLatex(37.0985,-0.200324,"Z (cm)");
107  tex->SetLineWidth(2);
108  tex->Draw();
109 
110  TCanvas *c2 = new TCanvas("c2", "c2",4,31,1200,700);
111  c2->Divide(1,3);
112  c2->cd(1);
113  Bx->Draw();
114  c2->cd(2);
115  By->Draw();
116  c2->cd(3);
117  Bz->Draw();
118  y=0;
119 
120  TH2F *B=new TH2F("B mod","B mod y=0 plane ",425,-200,650,250,-250,250);
121 
122  for (Int_t iz=0; iz<425; iz++)
123  {
124  z = -200 + 2*Double_t(iz) ;
125  po[1]=y; po[2]=z;
126  for (Int_t ix=0; ix<250; ix++) {
127  x= -250 + 2*Double_t(ix) ;
128  // cout << "X = " << x << endl;
129  po[0]=x;
130  fField->GetFieldValue(po,BB); //return valuse in KG (G3)
131  Btot=TMath::Sqrt(BB[0]*BB[0]+BB[1]*BB[1]+BB[2]*BB[2]);
132  B->SetBinContent(iz,ix,Btot/ 10.);
133  }
134  }
135 
136  TCanvas *c3 = new TCanvas("c3", "c3",4,31,1200,700);
137  B->Draw("cont1");
138 
139 };
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
PndMultiField * fField
Definition: sim_emc_apd.C:97
int DrawField(PndMultiField *fField, TH2F *Bfield)
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
c2
Definition: plot_dirc.C:39
void GetFieldValue(const Double_t point[3], Double_t *bField)
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
Double_t
Double_t z
c1
Definition: plot_dirc.C:35
c3
Definition: plot_dirc.C:50
Double_t x
Double_t y