#include "StandardLabels.C" void dBz_rel_vs_z2(void) { gROOT->Reset(); TColor::CreateColorWheel(); // Get tree from file // TFile *f = new TFile("bfield_20090814_01.root"); TFile *f = new TFile("bfield_20100701_03.root"); TTree *Bfield = (TTree*)gROOT->FindObject("Bfield"); // MIT conceptual design field - concept 1 /* TFile *f1 = new TFile("bfield_MIT20111104_01.root"); TTree *Bfield1 = (TTree*)gROOT->FindObject("Bfield");*/ // Design concept 2 TFile *f1 = new TFile("concept2_v1.root"); TTree *Bfield1 = (TTree*)gROOT->FindObject("Bfield"); // Make Canvas TCanvas *c1 = new TCanvas("c1", "boundaries canvas"); c1->SetTicks(); c1->SetGrid(); // Make empty axes TH2D *axes = new TH2D("axes", "Maximum #DeltaB_{z}/B_{z} vs. z", 100, -85.0, 650.0, 100, -0.85, 0.85); axes->SetStats(0); axes->SetXTitle("Z (cm)"); axes->SetYTitle("[B_{z}(r)-B_{z}(0)] /B_{z}(0)"); double zmin = -85.0; double zmax = 650.0; axes->GetXaxis()->SetRangeUser(0,360); // axes->GetXaxis()->SetRangeUser(zmin,zmax); axes->GetYaxis()->SetRangeUser(0,1); axes->Draw(); // Make a histo to project into int Nbins = (zmax-zmin)/2.54; zmax = zmin + (double)(Nbins)*2.54; TH1D *Bz_vs_z_r0 = new TH1D("Bz_vs_z_r0", "", Nbins, zmin, zmax); TH1D *Bzabs_vs_z_r0 = new TH1D("Bzabs_vs_z_r0", "", Nbins, zmin, zmax); Bfield->Project("Bz_vs_z_r0", "z","Bz*(abs(r-2.54)<(0.1))"); Bfield->Project("Bzabs_vs_z_r0", "z","abs(Bz)*(abs(r-2.54)<(0.1))"); TH1D *Bz_vs_z_r01 = new TH1D("Bz_vs_z_r01", "", Nbins, zmin, zmax); TH1D *Bzabs_vs_z_r01 = new TH1D("Bzabs_vs_z_r01", "", Nbins, zmin, zmax); Bfield1->Project("Bz_vs_z_r01", "z","Bz*(abs(r-2.54)<(0.1))"); Bfield1->Project("Bzabs_vs_z_r01", "z","abs(Bz)*(abs(r-2.54)<(0.1))"); // Make legend TLegend *leg = new TLegend(0.60, 0.75, 0.80, 0.85); leg->SetFillColor(kWhite); // Make histos for r=2.54-55 cm in 1 inch steps int Ncolors=9; int color[]={kRed,kYellow,kOrange,kSpring, kGreen, kCyan,kBlue,kMagenta,kBlack}; TH1D *Bz_vs_z[100]; TH1D *Bz_vs_z_upper; double r_upper = 0.0; int Nhists=0; for(double r=5.08; r<=69.0; r+=60.92){ char hname[256]; sprintf(hname, "Bz_vs_z_r%d", (int)(r/2.54+0.5)); TH1D *h = Bz_vs_z[Nhists++] = (TH1D*)Bz_vs_z_r0->Clone(hname); h->Reset(); char weight[256]; sprintf(weight, "(Bz-0.15*r/66.)*(abs(r-%3.2f)<(0.1))", r); // sprintf(weight, "(Bz-0.10*r/66.)*(abs(r-%3.2f)<(0.1))", r); // Original specification // sprintf(weight, "Bz*(abs(r-%3.2f)<(0.1))", r); Bfield->Project(hname, "z",weight); h->Add(Bz_vs_z_r0,-1.0); h->Divide(Bzabs_vs_z_r0); h->Scale(-1.0); // h->SetLineColor(color[Nhists%Ncolors]); if (r <30) h->SetLineColor(4); if (r >30) h->SetLineColor(4); h->Draw("same"); char lab[256]; sprintf(lab, "r=%3.1f cm", r); leg->AddEntry(h, lab); if(r<=67.0){ Bz_vs_z_upper = h; r_upper = r; } if (r > 65) { // plot data from identified file sprintf(hname, "concept2"); TH1D *h1 = (TH1D*)Bz_vs_z_r0->Clone(hname); h1->Reset(); // sprintf(weight, "(Bz-0.1*r/66.)*(abs(r-%3.2f)<(0.1))", r); sprintf(weight, "Bz*(abs(r-%3.2f)<(0.1))", r); Bfield1->Project(hname, "z",weight); h1->Add(Bz_vs_z_r01,-1.0); h1->Divide(Bzabs_vs_z_r01); h1->Scale(-1.0); h1->SetLineColor(2); h1->Draw("same"); } } leg->Draw(); // Add standard Labels // StandardLabels(axes,"","","solenoid_1500_poisson_090814_01"); // StandardLabels(axes,"","","solenoid_1500_poisson_20100701_03"); StandardLabels(axes,"","","solenoid_poisson_concept2"); c1->SaveAs("dBz_rel_vs_z2.png"); c1->SaveAs("dBz_rel_vs_z2.pdf"); // Print table of values at selected Z ofstream ofile("dBz_rel_vs_z2.txt"); ofile<<"# For r="<GetXaxis()->GetBinCenter(bin); double Bz_nominal = Bz_vs_z_r0->GetBinContent(bin); double dBz_max = Bz_vs_z_upper->GetBinContent(bin); sprintf(line, "%3.0f\t%3.2f\t%3.2f", z, Bz_nominal, dBz_max); ofile<