#include #include #include #include #include #include "geometry.hh" double const Constants::inchToMeter=0.0254; double const Constants::mmToMeter=0.001; double const Constants::degreeToRadian=3.1415927/180; double const Constants::radianToDegree=1./degreeToRadian; Detector* Detector::_instance = 0; Detector* Detector::Instance(char* initName, istream& is) { if (_instance == 0) { _instance = new Detector(initName, is); } return _instance; } Detector::Detector(char* initName, istream& is) { const unsigned int bufferSize=120; char buf[bufferSize]; char* comment; innerBoundary = 0; outerBoundary = 0; numberLayers = 0; int thisLayer = 0; strcpy(name, initName); while ( is.getline(buf, bufferSize, '\n')) { if ( (comment=strchr(buf, '#')) ) *comment='\0'; if (buf[0]) { istrstream ist(buf, bufferSize); if (innerBoundary==0) { innerBoundary = new Boundary; outerBoundary = new Boundary; ist >> *this->innerBoundary; ist >> *this->outerBoundary; } else if (numberLayers==0) { ist >> numberLayers; layer = new Layer[numberLayers]; } else { ist >> this->layer[thisLayer++]; } } } } istream& operator>> (istream& is, Layer& l) { is >> l.layerNumber >> l._numberWires >> l._offsetFirstWire >> l._radius >> l._halfLength >> l._dCellDz; l._offsetFirstWire = l._offsetFirstWire*Constants::degreeToRadian; l._radius = l._radius*Constants::mmToMeter; l._halfLength = l._halfLength*Constants::inchToMeter; l._isStereo = l._dCellDz != 0.0; l._isStereo = fabs(l._dCellDz) > 1.0; // temp til dCellDz understood return is; } ostream& operator<< (ostream& os, Layer& l) { os << "layer: " << l.layerNumber << ", " << "Wires: " << l._numberWires << ", " << "offset: " << l._offsetFirstWire << ", " << "radius: " << l._radius << ", " << "halfLength: " << l._halfLength << ", " << "dCellDz: " << l._dCellDz << ", " << "isStereo: " << l._isStereo << endl; return os; } ostream& operator<< (ostream& os, Detector& d) { os << "Detector "<< d.name<< " has "<< d.numberLayers<< " layers."<< endl; os << "Inner Boundary\n " << *d.innerBoundary; for (int l=0; l> (istream& is, Boundary& b) { is >> b._radius; b._thickness = 0.002; // *** temp b._radLength = 0.001; // *** temp return is; } ostream& operator<< (ostream& os, Boundary& b) { os << "Radius: " << b._radius << ", Thichness: " << b._thickness \ << ", Radiation lengths: " << b._radLength << endl; return os; } void Detector::PostScript(ostream& os) { const int BoundingBox = 612; const float CrossHair = 8; const float wireRadius= 0.001; // *** temp const float scaleFactor = BoundingBox*0.45 / outerBoundary->radius(); os << "%!PS-Adobe-2.0 EPSF-2.0" << endl; os << "%%BoundingBox: 0 0 " << BoundingBox << " " << BoundingBox << endl; os << "%%Title: detector" << endl; os << "%%Creator: Michael Ogg" << endl; os << "%%CreationDate: January, 1996" << endl; os << "%%EndComments" << endl << endl; os << "/m {moveto} def" << endl; os << "/l {lineto} def" << endl; os << "/CrossHair " << CrossHair << " def" << endl; os << "/circle {" << endl; os << " newpath 0 0 3 -1 roll 0 360 arc stroke" << endl; os << "} def" << endl; os << "/dot {" << endl; os << " newpath 0 360 arc fill" << endl; os << "} def" << endl; os << "/layer {" << endl; os << " /radius exch def" << endl; os << " 0 exch 360 exch div 360" << endl; os << " {dup cos radius mul exch sin radius mul " \ << wireRadius << " dot} for" << endl; os << "} def" << endl; os << "/crosshair {" << endl; os << " currentpoint 3 -1 roll" << endl; os << " dup 2 div neg 0 rmoveto dup 0 rlineto stroke" << endl; os << " 3 1 roll moveto" << endl; os << " dup 2 div neg 0 exch rmoveto 0 exch rlineto stroke" << endl; os << "} def" << endl; os << "%%EndProlog" << endl << endl; os << BoundingBox/2 << " " << BoundingBox/2 << " translate" << endl; os << "0 0 0 setrgbcolor" << endl; os << "0.5 setlinewidth" << endl; os << "0 0 moveto" << endl; os << "CrossHair crosshair" << endl << endl; os << scaleFactor << " " << scaleFactor << " scale" << endl; os << "0 0 0 setrgbcolor" << endl; os << outerBoundary->thickness() << " setlinewidth" << endl; os << outerBoundary->radius() << " circle" << endl << endl; os << innerBoundary->thickness() << " setlinewidth" << endl; os << innerBoundary->radius() << " circle" << endl << endl; for (int i=0; i 0) os << "1 0 0 setrgbcolor" << endl; else os << "0 0 1 setrgbcolor" << endl; os << layer[i].offsetFirstWire()*Constants::radianToDegree << " rotate "; os << layer[i].numberWires() << " " << layer[i].radius() << " layer "; os << -layer[i].offsetFirstWire()*Constants::radianToDegree << " rotate"\ << endl; } os << "showpage" << endl; }