44 G4String CCalRotationMatrixFactory::file=
"";
47 if (rotfile==
"" || rotfile==file)
53 G4cerr <<
"ERROR: Trying to get Rotation Matrices from " << rotfile
54 <<
" when previously were retrieved from " << file <<
"." <<
G4endl;
62 G4cerr <<
"ERROR: You haven't defined which file to use for materials in "
63 <<
"CCalRotationMatrixFactory::getInstance(G4String)" <<
G4endl;
76 if (rotfile!=file && file!=
"") {
77 G4cerr <<
"ERROR: Trying to change Rotation Matrices file name to "
78 << rotfile <<
"." <<
G4endl;
86 for(i=theMatrices.begin(); i != theMatrices.end(); ++i) {
98 if (it != theMatrices.end())
99 retrot = (*it).second;
112 G4double sinth1, sinth2, sinth3, costh1, costh2, costh3;
113 G4double sinph1, sinph2, sinph3, cosph1, cosph2, cosph3;
117 if (TH1 == 0.0 || TH1 == 360) {
118 sinth1 = 0.0; costh1 = 1.0;
119 }
else if (TH1 == 90.0 || TH1 == -270) {
120 sinth1 = 1.0; costh1 = 0.0;
121 }
else if (TH1 == 180.0 || TH1 == -180.0) {
122 sinth1 = 0.0; costh1 = -1.0;
123 }
else if (TH1 == 270.0 || TH1 == -90.0) {
124 sinth1 = -1.0; costh1 = 0.0;
126 sinth1 = std::sin(th1); costh1 = std::cos(th1);
129 if (TH2 == 0.0 || TH2 == 360) {
130 sinth2 = 0.0; costh2 = 1.0;
131 }
else if (TH2 == 90.0 || TH2 == -270) {
132 sinth2 = 1.0; costh2 = 0.0;
133 }
else if (TH2 == 180.0 || TH2 == -180.0) {
134 sinth2 = 0.0; costh2 = -1.0;
135 }
else if (TH2 == 270.0 || TH2 == -90.0) {
136 sinth2 = -1.0; costh2 = 0.0;
138 sinth2 = std::sin(th2); costh2 = std::cos(th2);
141 if (TH3 == 0.0 || TH3 == 360) {
142 sinth3 = 0.0; costh3 = 1.0;
143 }
else if (TH3 == 90.0 || TH2 == -270) {
144 sinth3 = 1.0; costh3 = 0.0;
145 }
else if (TH3 == 180.0 || TH3 == -180.0) {
146 sinth3 = 0.0; costh3 = -1.0;
147 }
else if (TH3 == 270.0 || TH3 == -90.0) {
148 sinth3 = -1.0; costh3 = 0.0;
150 sinth3 = std::sin(th3); costh3 = std::cos(th3);
153 if (PH1 == 0.0 || PH1 == 360) {
154 sinph1 = 0.0; cosph1 = 1.0;
155 }
else if (PH1 == 90.0 || PH1 == -270) {
156 sinph1 = 1.0; cosph1 = 0.0;
157 }
else if (PH1 == 180.0 || PH1 == -180.0) {
158 sinph1 = 0.0; cosph1 = -1.0;
159 }
else if (PH1 == 270.0 || PH1 == -90.0) {
160 sinph1 = -1.0; cosph1 = 0.0;
162 sinph1 = std::sin(phi1); cosph1 = std::cos(phi1);
165 if (PH2 == 0.0 || PH2 == 360) {
166 sinph2 = 0.0; cosph2 = 1.0;
167 }
else if (PH2 == 90.0 || PH2 == -270) {
168 sinph2 = 1.0; cosph2 = 0.0;
169 }
else if (PH2 == 180.0 || PH2 == -180.0) {
170 sinph2 = 0.0; cosph2 = -1.0;
171 }
else if (PH2 == 270.0 || PH2 == -90.0) {
172 sinph2 = -1.0; cosph2 = 0.0;
174 sinph2 = std::sin(phi2); cosph2 = std::cos(phi2);
177 if (PH3 == 0.0 || PH3 == 360) {
178 sinph3 = 0.0; cosph3 = 1.0;
179 }
else if (PH3 == 90.0 || PH3 == -270) {
180 sinph3 = 1.0; cosph3 = 0.0;
181 }
else if (PH3 == 180.0 || PH3 == -180.0) {
182 sinph3 = 0.0; cosph3 = -1.0;
183 }
else if (PH3 == 270.0 || PH3 == -90.0) {
184 sinph3 = -1.0; cosph3 = 0.0;
186 sinph3 = std::sin(phi3); cosph3 = std::cos(phi3);
208 theMatrices[
name]=rotMat;
217 CCalRotationMatrixFactory::CCalRotationMatrixFactory():theMatrices(){
219 G4String path = getenv(
"CCAL_GLOBALPATH");
220 G4cout <<
" ==> Opening file " << file <<
"..." <<
G4endl;
224 G4cerr <<
"ERROR: Could not open file " << file <<
" ... Exiting!" <<
G4endl;
236 G4cout <<
" ==> Reading Rotation Matrices... " <<
G4endl;
237 G4cout <<
" Name\tTheta1\tPhi1\tTheta2\tPhi2\tTheta3\tPhi3"<<
G4endl;
241 while(name!=
"*ENDDO") {
242 if (name.index(
"#.")==0) {
243 is.getline(rubish,256,
'\n');
246 G4cout <<
" " << name <<
'\t';
248 G4double th1, phi1, th2, phi2, th3, phi3;
252 G4cout << th1 <<
'\t' << phi1 <<
'\t';
257 G4cout << th2 <<
'\t' << phi2 <<
'\t';
262 G4cout << th3 <<
'\t' << phi3 <<
'\t';
265 is.getline(rubish,256,
'\n');
270 AddMatrix(name, th1*
deg, phi1*deg, th2*deg, phi2*deg, th3*deg, phi3*deg);
277 G4cout <<
" " << theMatrices.size() <<
" rotation matrices read in." <<
G4endl;
bool openGeomFile(std::ifstream &is, const G4String &pathname, const G4String &filename)
CLHEP::HepRotation G4RotationMatrix
HepRotation & rotateAxes(const Hep3Vector &newX, const Hep3Vector &newY, const Hep3Vector &newZ)
~CCalRotationMatrixFactory()
std::ifstream & findDO(std::ifstream &, const G4String &)
G4RotationMatrix * AddMatrix(const G4String &name, G4double th1, G4double phi1, G4double th2, G4double phi2, G4double th3, G4double phi3)
std::map< G4String, G4RotationMatrixPtr, std::less< G4String > >::iterator G4RotationMatrixTableIterator
G4GLOB_DLL std::ostream G4cout
static CCalRotationMatrixFactory * getInstance()
G4RotationMatrix * findMatrix(const G4String &)
static void setFileName(const G4String &rotfile)
G4GLOB_DLL std::ostream G4cerr