void plot_bfield2(void) { // // modify plot_bfield to plot contours of safe work area around the solenoid // gROOT->Reset(); TTree *Bfield = (TTree *) gROOT->FindObject("Bfield"); gStyle->SetPalette(1,0); gStyle->SetOptStat(kFALSE); gStyle->SetPadRightMargin(0.15); gStyle->SetPadLeftMargin(0.15); gStyle->SetPadBottomMargin(0.15); //gStyle->SetTitleFontSize(0.07); //gStyle->SetLabelSize(0.05); //gStyle->SetTextSize(0.05); // // get Bfield into tree // Int_t nentries; struct B_t { Float_t x; Float_t y; Float_t z; Float_t r; Float_t phi; Float_t Bx; Float_t By; Float_t Bz; Float_t Br; Float_t Bphi; }; B_t B; Bfield->SetBranchAddress("B",&B.x); // // Draw fields on the platforms surrounding the magnet for regions of access // Int_t nxbins=160, nybins=1, nzbins=400; Double_t y0=0; Double_t xmin=-201.93; Double_t xmax=204.47; Double_t ymin=y0-2.54/2; Double_t ymax=y0+2.54/2; Double_t zmin=-301, zmax=715; Double_t Bsat=0.016; TH3F *hzmech = new TH3F("hzmech", "MECH Bz (T)", nxbins,xmin,xmax, nzbins,zmin,zmax, 80,-Bsat,Bsat); TH3F *hrmech = new TH3F("hrmech", "MECH Br (T)", nxbins,xmin,xmax, nzbins,zmin,zmax, 80,-Bsat,Bsat); TH3F *hphimech = new TH3F("hphimech","MECH Bphi (T)",nxbins,xmin,xmax, nzbins,zmin,zmax, 80,-0.00001,0.00001); TH3F *htotmech = new TH3F("htotmech","MECH Btot (T)",nxbins,xmin,xmax, nzbins,zmin,zmax, 80,0,Bsat); nentries = Bfield->GetEntries(); Double_t deltax = (xmax-xmin)/nxbins; Double_t deltay = (ymax-ymin)/nybins; Double_t deltaz = (zmax-zmin)/nzbins; printf ("nentries=%d, deltax=%f, deltaz=%f\n",nentries,deltax,deltaz); for (Int_t n=0; nGetEntry(n); // printf ("n=%d, z=%f, r=%f, Bz=%f, Br=%f\n",n,B.z,B.r,B.Bz,B.Br); zbin = B.z; ybin = y0; Double_t Btot = sqrt(B.Bz*B.Bz + B.Br*B.Br + B.Bphi*B.Bphi); Double_t Bz = B.Bz; Double_t Br=B.Br; if (Btot > Bsat) { Btot = Bsat; if(B.Bz != 0) { Bz = fabs(B.Bz)*Bsat/B.Bz; } else { Bz = 0.; } if (B.Br != 0) { Br = fabs(B.Br)*Bsat/B.Br; } else { Br = 0.; } } for (Int_t i=0; i(xbin-deltax/2)) && (B.r*sin(phi)<(ybin+deltay/2) && B.r*sin(phi)>(ybin-deltay/2)) ) { //printf ("Btot=%f, Bz=%f, Br=%f, xbin=%f, ybin=%f, phi=%f, r=%f, r*cosphi=%f\n",Btot,B.Bz,B.Br,xbin,ybin,phi,B.r,B.r*cos(phi)); hzmech->Fill(xbin,zbin,Bz); hrmech->Fill(xbin,zbin,Br); hphimech->Fill(xbin,zbin,B.Bphi); htotmech->Fill(xbin,zbin,Btot); } } } // get new canvas TCanvas *c51 = new TCanvas("c51"); c51->SetBorderMode(0); c51->SetFillColor(0); // project contents TProfile2D *hhzmech =hzmech->Project3DProfile(); hhzmech->GetXaxis()->SetTitle("z(cm)"); hhzmech->GetYaxis()->SetTitle("x(cm)"); hhzmech->SetTitle(""); hhzmech->GetXaxis()->SetLabelSize(0.05); hhzmech->GetXaxis()->SetTitleSize(0.07); hhzmech->GetYaxis()->SetLabelSize(0.05); hhzmech->GetYaxis()->SetTitleSize(0.07); hhzmech->GetZaxis()->SetLabelSize(0.05); hhzmech->GetZaxis()->SetTitleSize(0.07); TProfile2D *hhrmech =hrmech->Project3DProfile(); hhrmech->GetXaxis()->SetTitle("z(cm)"); hhrmech->GetYaxis()->SetTitle("x(cm)"); hhrmech->SetTitle(""); hhrmech->GetXaxis()->SetLabelSize(0.05); hhrmech->GetXaxis()->SetTitleSize(0.07); hhrmech->GetYaxis()->SetLabelSize(0.05); hhrmech->GetYaxis()->SetTitleSize(0.07); hhrmech->GetZaxis()->SetLabelSize(0.05); hhrmech->GetZaxis()->SetTitleSize(0.07); TProfile2D *hhphimech =hphimech->Project3DProfile(); hhphimech->GetXaxis()->SetTitle("z(cm)"); hhphimech->GetYaxis()->SetTitle("x(cm)"); hhphimech->SetTitle(""); hhphimech->GetXaxis()->SetLabelSize(0.05); hhphimech->GetXaxis()->SetTitleSize(0.07); hhphimech->GetYaxis()->SetLabelSize(0.05); hhphimech->GetYaxis()->SetTitleSize(0.07); hhphimech->GetZaxis()->SetLabelSize(0.05); hhphimech->GetZaxis()->SetTitleSize(0.07); TProfile2D *hhtotmech =htotmech->Project3DProfile(); hhtotmech->GetXaxis()->SetTitle("z(cm)"); hhtotmech->GetYaxis()->SetTitle("x(cm)"); hhtotmech->SetTitle(""); hhtotmech->GetXaxis()->SetLabelSize(0.05); hhtotmech->GetXaxis()->SetTitleSize(0.07); hhtotmech->GetYaxis()->SetLabelSize(0.05); hhtotmech->GetYaxis()->SetTitleSize(0.07); hhtotmech->GetZaxis()->SetLabelSize(0.05); hhtotmech->GetZaxis()->SetTitleSize(0.07); // draw projections char string[132]; sprintf(string,"Btot<%.4f T, y=%.1f cm\n",Bsat,y0); printf("string=%s",string); t1 = new TLatex(0.35,0.92,string); hhzmech->Draw("colz"); t1->SetNDC(); t1->SetTextSize(0.05); t1->Draw(); t2 = new TLatex(0.85,0.92,"Bz(T)"); t2->SetNDC(); t2->SetTextSize(0.05); t2->Draw(); TCanvas *c52 = new TCanvas("c52"); c52->SetBorderMode(0); c52->SetFillColor(0); hhrmech->Draw("colz"); t1->Draw(); t2 = new TLatex(0.85,0.92,"Br(T)"); t2->SetNDC(); t2->SetTextSize(0.05); t2->Draw(); TCanvas *c53 = new TCanvas("c53"); c53->SetBorderMode(0); c53->SetFillColor(0); hhphimech->Draw("colz"); t1->Draw(); t2 = new TLatex(0.83,0.92,"Bphi(T)"); t2->SetNDC(); t2->SetTextSize(0.05); t2->Draw(); TCanvas *c54 = new TCanvas("c54"); c54->SetBorderMode(0); c54->SetFillColor(0); hhtotmech->Draw("colz"); t1->Draw(); t2 = new TLatex(0.83,0.92,"Btot(T)"); t2->SetNDC(); t2->SetTextSize(0.05); t2->Draw(); TCanvas *c55 = new TCanvas("c55"); c55->SetBorderMode(0); c55->SetFillColor(0); c55->Divide(2,2); c55->cd(1); hhzmech->Draw("colz"); t1->Draw(); t2 = new TLatex(0.85,0.92,"Bz(T)"); t2->SetNDC(); t2->SetTextSize(0.05); t2->Draw(); c55->cd(2); hhrmech->Draw("colz"); t1->Draw(); t2 = new TLatex(0.85,0.92,"Br(T)"); t2->SetNDC(); t2->SetTextSize(0.05); t2->Draw(); c55->cd(3); hhphimech->Draw("colz"); t1->Draw(); t2 = new TLatex(0.83,0.92,"Bphi(T)"); t2->SetNDC(); t2->SetTextSize(0.05); t2->Draw(); c55->cd(4); hhtotmech->Draw("colz"); t1->Draw(); t2 = new TLatex(0.83,0.92,"Btot(T)"); t2->SetNDC(); t2->SetTextSize(0.05); t2->Draw(); // output to file c55->SaveAs("plot_bfield2_mech.eps"); c55->SaveAs("plot_bfield2_mech.gif"); // output to file c54->SaveAs("plot_bfield2_tot_mech.eps"); c54->SaveAs("plot_bfield2_tot_mech.gif"); }