// Test to load field map and dump out field at a point #include #include #include #include "ICOMETLog.hxx" #include "IFieldManager.hxx" #include "IFieldMap.hxx" #include "IFieldMapList.hxx" #include "IFieldPlotter.hxx" #include #include "Rtypes.h" #include "TVector3.h" #include "TFile.h" #include "TH1.h" #include "TH2.h" #include "TRotation.h" using std::cout; using std::endl; bool StringToRotation(TRotation& , std::string); std::ostream& operator<<(std::ostream& stream,const TVector3& vect){ stream<<"("< Add a file to the list of fieldmaps. \n" <<" -t Set the translation of the last fieldmap added to the list of inputs. \n" <<" -r Set the rotation of the last fieldmap added to the list of inputs. \n" <<" -s Set the scale factor of the last fieldmap added to the list of inputs. \n" <<" -R Recreate a fieldmap from an existing root file \n" <<"\n" <<"Output file Options: \n" <<" -O Set the output filename. \n" <<" -o Set the centre of the plane to draw from (in input file units, typically mm). \n" <<" -u Set the up-vector for the output plane. Used to define the output plot's y-axis. \n" <<" -N Set the normal of the plane to work in. \n" <<" -n Set the number of steps to used in either direction \n" <<" -d Set the step size (in input file units, typically mm) \n" <<" -p Set the number of planes to scan through \n" <AddFieldmap(optarg); continue; case 't': { if(!field_list->CheckHaveAFile()) return 2; double vect[3]; stream>>vect[0]>>vect[1]>>vect[2]; TVector3 translation(vect[0],vect[1],vect[2]); field_list->GetLastFieldmap()->SetTranslation(translation); break; } case 'r': { if(!field_list->CheckHaveAFile()) return 2; TRotation rotation= field_list->GetLastFieldmap()->GetRotation(); bool all_good = StringToRotation(rotation,optarg); if(!all_good) stream.setstate(std::ios_base::failbit); else { field_list->GetLastFieldmap()->SetRotation(rotation); continue; } break; } case 's': { if(! field_list->CheckHaveAFile()) return 2; double scale; stream>>scale; field_list->GetLastFieldmap()->SetScaling(scale); break; } case 'o': { double vect[3]; stream>>vect[0]>>vect[1]>>vect[2]; plotter.SetOrigin(vect[0],vect[1],vect[2]); break; } case 'N': { double vect[3]; stream>>vect[0]>>vect[1]>>vect[2]; plotter.SetNormal(vect[0],vect[1],vect[2]); break; } case 'u': { double vect[3]; stream>>vect[0]>>vect[1]>>vect[2]; plotter.SetUpVector(vect[0],vect[1],vect[2]); break; } case 'n': { int n_steps=0; stream>>n_steps; plotter.SetNSteps(n_steps); break; } case 'O': { stream>>outfilename; break; } case 'p': { stream>>n_planes; break; } case 'd': { double step_size; stream>>step_size; plotter.SetStepSize(step_size); break; } case 'h':case '?': Usage(argv[0]); return 0; default: cout<<"Error: Unknown option: "<ls(); field_list->InitialiseField(); TFile* outfile=TFile::Open(outfilename.c_str(),"recreate"); plotter.SetDirectory(outfile); bool vectors_ok=plotter.Initialise(); if(!vectors_ok){ return 1; } if(n_planes<=1){ plotter.PlotPlane(); }else { plotter.PlotPlanes(n_planes,plane_sep); } field_list->ls(); field_list->Write(); COMET::IHandle description=mgr->MakeDescription(); description->Write(); description->ls(); outfile->Write(); outfile->Close(); return 0; } bool StringToRotation(TRotation& rotation, std::string input){ // We apply successive rotations OF THE OBJECT around the FIXED // axes of the parent's local coordinates; rotations are applied // left-to-right (rotation="r1,r2,r3" => r1 then r2 then r3). std::stringstream stream(input); char axis='0'; double angle=0.0; while (stream>> axis >>angle){ TRotation thisRotation; switch(axis){ case 'X':case 'x': rotation.RotateX(angle); break; case 'Y':case 'y': rotation.RotateY(angle); break; case 'Z':case 'z': rotation.RotateZ(angle); break; default: COMETError("Bad input axis: "<