// Author: David Lawrence June 25, 2004 // // // hd_ana.cc // #include #include #include using namespace std; #include #include #include #include #include #include #include #include int Nr = 81; int Nphi = 1; int Nz = 401; double Rmin = 1.0*2.54; double Rmax = 81.0*2.54; double Phimin = 0.0; double Phimax = 0.0; double Zmin = -126.0*2.54; double Zmax = 274.0*2.54; double Z0 = 0.0; void Usage(void); void ParseCommandLineArgs(int narg, char* argv[]); //----------- // main //----------- int main(int narg, char *argv[]) { // Parse command line arguments and then create a DApplication ParseCommandLineArgs(narg, argv); DApplication *dapp = new DApplication(narg, argv); dapp->Init(); // open ROOT file float val[10]; TFile* ROOTfile = new TFile("bfield.root","RECREATE","Produced by bfield2root"); ROOTfile->SetCompressionLevel(6); cout<<"Opened ROOT file \"bfield.root\""<GetBfield(); // Create Tree TTree *tree = new TTree("Bfield","Magnetic Field"); tree->Branch("B",val,"x/F:y:z:r:phi:Bx:By:Bz:Br:Bphi"); // Loop over cylindrical grid and fill tree double r = Rmin; for(int ir=0; ir1) r = Rmin + (double)ir*(Rmax-Rmin)/(double)(Nr-1); double phi = Phimin; for(int iphi=0; iphi1) phi = Phimin + (double)iphi*(Phimax-Phimin)/(double)(Nphi-1); double z = Zmin; for(int iz=0; iz1) z = Zmin + (double)iz*(Zmax-Zmin)/(double)(Nz-1); double x = r*cos(phi); double y = r*sin(phi); double Bx, By, Bz; bfield->GetField(x, y, z-Z0, Bx, By, Bz); TVector3 B(Bx, By, Bz); double Br = B.Dot(TVector3(x, y, 0.0))/sqrt(x*x + y*y); double Bphi = atan2(By, Bx); val[0] = x; val[1] = y; val[2] = z; val[3] = r; val[4] = phi; val[5] = Bx; val[6] = By; val[7] = Bz; val[8] = Br; val[9] = Bphi; tree->Fill(); } } } // Create 2D histos in R and Z TH2D *Bz_vs_r_vs_z = new TH2D("Bz_vs_r_vs_z", "", 651, -25, 625.0, 200, 0.0, 100.0); Bz_vs_r_vs_z->SetXTitle("z (cm)"); Bz_vs_r_vs_z->SetYTitle("r (cm)"); Bz_vs_r_vs_z->SetStats(0); TH2D *Btot_vs_r_vs_z = (TH2D*)Bz_vs_r_vs_z->Clone("Btot_vs_r_vs_z"); for(int ibin=1; ibin<=Bz_vs_r_vs_z->GetNbinsX(); ibin++){ double z = Bz_vs_r_vs_z->GetXaxis()->GetBinCenter(ibin); for(int jbin=1; jbin<=Bz_vs_r_vs_z->GetNbinsY(); jbin++){ double r = Bz_vs_r_vs_z->GetYaxis()->GetBinCenter(jbin); double Bx, By, Bz; bfield->GetField(r, 0.0, z-Z0, Bx, By, Bz); double Btot = sqrt(Bx*Bx + By*By + Bz*Bz); Bz_vs_r_vs_z->SetBinContent(ibin, jbin, Bz); Btot_vs_r_vs_z->SetBinContent(ibin, jbin, Btot); } } ROOTfile->Write(); delete ROOTfile; cout< than narg, then no value was passed to an "-XXX" argument if(i>narg){ _DBG_<<"No argument given for \""<