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p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/composite_calorimeter/src/CCalRotationMatrixFactory.cc (Version 11.3.0) and /examples/advanced/composite_calorimeter/src/CCalRotationMatrixFactory.cc (Version 2.0)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //////////////////////////////////////////////    
 27 // File: CCalRotationMatrixFactory.cc             
 28 // Description: CCalRotationFactory is a facto    
 29 //              matrices used in geometry buil    
 30 //////////////////////////////////////////////    
 31 #include <fstream>                                
 32 #include <stdlib.h>                               
 33                                                   
 34 #include "CCalRotationMatrixFactory.hh"           
 35                                                   
 36 #include "CCalutils.hh"                           
 37                                                   
 38 #include "G4SystemOfUnits.hh"                     
 39                                                   
 40 //#define debug                                   
 41 //#define ddebug                                  
 42                                                   
 43 CCalRotationMatrixFactory * CCalRotationMatrix    
 44 G4String CCalRotationMatrixFactory::file="";      
 45                                                   
 46 CCalRotationMatrixFactory* CCalRotationMatrixF    
 47   if (rotfile=="" || rotfile==file)               
 48     return getInstance();                         
 49   else if (file=="") {                            
 50     file=rotfile;                                 
 51     return getInstance();                         
 52   } else {                                        
 53     G4cerr << "ERROR: Trying to get Rotation M    
 54          << " when previously were retrieved f    
 55     return 0;                                     
 56   }                                               
 57 }                                                 
 58                                                   
 59                                                   
 60 CCalRotationMatrixFactory* CCalRotationMatrixF    
 61   if (file=="") {                                 
 62     G4cerr << "ERROR: You haven't defined whic    
 63          << "CCalRotationMatrixFactory::getIns    
 64     return 0;                                     
 65   }                                               
 66                                                   
 67   if (instance==0) {                              
 68     instance = new CCalRotationMatrixFactory;     
 69     return instance;                              
 70   }                                               
 71   else                                            
 72     return instance;                              
 73 }                                                 
 74                                                   
 75 void CCalRotationMatrixFactory::setFileName(co    
 76   if (rotfile!=file && file!="") {                
 77     G4cerr << "ERROR: Trying to change Rotatio    
 78          << rotfile << "." << G4endl;             
 79     G4cerr << "       Using previous file: " <    
 80   }                                               
 81   file=rotfile;                                   
 82 }                                                 
 83                                                   
 84 CCalRotationMatrixFactory::~CCalRotationMatrix    
 85   G4RotationMatrixTableIterator i;                
 86   for(i=theMatrices.begin(); i != theMatrices.    
 87     delete (*i).second;                           
 88   };                                              
 89   theMatrices.clear();                            
 90 }                                                 
 91                                                   
 92 G4RotationMatrix* CCalRotationMatrixFactory::f    
 93   G4RotationMatrix* retrot=0;                     
 94   //Rotation :NULL is no rotation so a null po    
 95   if (rot != ":NULL") {                           
 96     //retrot untouched if rot not found!!!        
 97     G4RotationMatrixTableIterator it = theMatr    
 98     if (it != theMatrices.end())                  
 99       retrot = (*it).second;                      
100   }                                               
101                                                   
102   return retrot; //!!!Maybe a treatment on not    
103 }                                                 
104                                                   
105 G4RotationMatrix* CCalRotationMatrixFactory::A    
106                                                   
107                                                   
108                                                   
109                                                   
110                                                   
111                                                   
112   G4double sinth1, sinth2,  sinth3, costh1, co    
113   G4double sinph1, sinph2, sinph3, cosph1, cos    
114   G4double TH1 = th1/deg, TH2 = th2/deg, TH3 =    
115   G4double PH1 = phi1/deg, PH2 = phi2/deg, PH3    
116                                                   
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;                  
125   } else {                                        
126     sinth1 = std::sin(th1); costh1 = std::cos(    
127   }                                               
128                                                   
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;                  
137   } else {                                        
138     sinth2 = std::sin(th2); costh2 = std::cos(    
139   }                                               
140                                                   
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;                  
149   } else {                                        
150     sinth3 = std::sin(th3); costh3 = std::cos(    
151   }                                               
152                                                   
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;                  
161   } else {                                        
162     sinph1 = std::sin(phi1); cosph1 = std::cos    
163   }                                               
164                                                   
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;                  
173   } else {                                        
174     sinph2 = std::sin(phi2); cosph2 = std::cos    
175   }                                               
176                                                   
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;                  
185   } else {                                        
186     sinph3 = std::sin(phi3); cosph3 = std::cos    
187   }                                               
188                                                   
189   //xprime axis coordinates                       
190   CLHEP::Hep3Vector xprime(sinth1*cosph1,sinth    
191   //yprime axis coordinates                       
192   CLHEP::Hep3Vector yprime(sinth2*cosph2,sinth    
193   //zprime axis coordinates                       
194   CLHEP::Hep3Vector zprime(sinth3*cosph3,sinth    
195                                                   
196 #ifdef ddebug                                     
197   G4cout << xprime << '\t';    G4cout << yprim    
198 #endif                                            
199   G4RotationMatrix *rotMat = new G4RotationMat    
200   rotMat->rotateAxes(xprime, yprime, zprime);     
201   if (*rotMat == G4RotationMatrix()) {            
202     // G4cerr << "WARNING: Matrix " << name <<    
203     // G4cerr << "WARNING: Matrix " << name <<    
204     delete rotMat;                                
205     rotMat=0;                                     
206   } else {                                        
207     rotMat->invert();                             
208     theMatrices[name]=rotMat;                     
209 #ifdef ddebug                                     
210     G4cout << *rotMat << G4endl;                  
211 #endif                                            
212   }                                               
213                                                   
214   return rotMat;                                  
215 }                                                 
216                                                   
217 CCalRotationMatrixFactory::CCalRotationMatrixF    
218                                                   
219   G4String path = "NULL";                         
220   if (std::getenv("CCAL_GLOBALPATH"))             
221     path = std::getenv("CCAL_GLOBALPATH");        
222                                                   
223   G4cout << " ==> Opening file " << file << ".    
224   std::ifstream is;                               
225   G4bool ok = openGeomFile(is, path, file);       
226   if (!ok) {                                      
227     G4ExceptionDescription ed;                    
228     ed << "Could not open file " << file << "     
229     G4Exception("CCalRotationMatrixFactory::CC    
230                 "ccal002",                        
231                 FatalException,ed);               
232   }                                               
233                                                   
234   ////////////////////////////////////////////    
235   // Find *DO ROTM                                
236   findDO(is, G4String("ROTM"));                   
237                                                   
238   char rubish[256];                               
239   G4String name;                                  
240                                                   
241 #ifdef debug                                      
242   G4cout << "     ==> Reading Rotation Matrice    
243   G4cout << "       Name\tTheta1\tPhi1\tTheta2    
244 #endif                                            
245                                                   
246   is >> name;                                     
247   while(name!="*ENDDO") {                         
248     if (name.find("#.")==0) { //It is a commen    
249       is.getline(rubish,256,'\n');                
250     } else {                                      
251 #ifdef debug                                      
252       G4cout << "       " << name <<'\t';         
253 #endif                                            
254       G4double th1, phi1, th2, phi2, th3, phi3    
255       //Get xprime axis angles                    
256       is >> th1 >> phi1;                          
257 #ifdef debug                                      
258       G4cout << th1 << '\t' << phi1 << '\t';      
259 #endif                                            
260       //Get yprime axis angles                    
261       is >> th2 >> phi2;                          
262 #ifdef debug                                      
263       G4cout << th2 << '\t' << phi2 << '\t';      
264 #endif                                            
265       //Get zprime axis angles                    
266       is >> th3 >> phi3;                          
267 #ifdef debug                                      
268       G4cout << th3 << '\t' << phi3 << '\t';      
269 #endif                                            
270                                                   
271       is.getline(rubish,256,'\n');                
272 #ifdef debug                                      
273       G4cout << rubish << G4endl;                 
274 #endif                                            
275                                                   
276       AddMatrix(name, th1*deg, phi1*deg, th2*d    
277     }                                             
278                                                   
279     is >> name;                                   
280   };                                              
281                                                   
282   is.close();                                     
283   G4cout << "       "  << theMatrices.size() <    
284 }                                                 
285                                                   
286                                                   
287 // 29-Jan-2004 A.R. : commented to avoid clash    
288 //                    Streaming operators for     
289 //                    already defined in CLHEP    
290 // std::ostream& operator<<(std::ostream& os ,    
291 //   //  os << "( " << rot.xx() << tab << rot.    
292 //   //  os << "( " << rot.yx() << tab << rot.    
293 //   //  os << "( " << rot.zx() << tab << rot.    
294 //                                                
295 //   os << "["                                    
296 //      << rot.thetaX()/deg << tab << rot.phiX    
297 //      << rot.thetaY()/deg << tab << rot.phiY    
298 //      << rot.thetaZ()/deg << tab << rot.phiZ    
299 //      << G4endl;                                
300 //                                                
301 //   return os;                                   
302 // }                                              
303