Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/examples/advanced/composite_calorimeter/src/CCalMaterialFactory.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.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/CCalMaterialFactory.cc (Version 11.3.0) and /examples/advanced/composite_calorimeter/src/CCalMaterialFactory.cc (Version 9.2.p4)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //////////////////////////////////////////////     26 ///////////////////////////////////////////////////////////////////////////////
 27 // File: CCalMaterialFactory.cc                    27 // File: CCalMaterialFactory.cc
 28 // Description: CCalMaterialFactory is a facto     28 // Description: CCalMaterialFactory is a factory class to vuild G4Material 
 29 //              from CCalMaterial and CCalAmat     29 //              from CCalMaterial and CCalAmaterial
 30 //////////////////////////////////////////////     30 ///////////////////////////////////////////////////////////////////////////////
 31 #include <fstream>                             << 
 32 #include <stdlib.h>                            << 
 33                                                << 
 34 #include "CCalMaterialFactory.hh"                  31 #include "CCalMaterialFactory.hh"
 35 #include "CCalutils.hh"                            32 #include "CCalutils.hh"
                                                   >>  33 #include <fstream>
                                                   >>  34 #include <stdlib.h>
 36                                                    35 
 37 #include "G4PhysicalConstants.hh"              << 
 38 #include "G4SystemOfUnits.hh"                  << 
 39 #include "G4Material.hh"                           36 #include "G4Material.hh"
 40                                                    37 
 41 //#define ddebug                                   38 //#define ddebug
 42 //#define debug                                    39 //#define debug
 43                                                    40 
 44 typedef CCalMaterial*  ptrCCalMaterial;            41 typedef CCalMaterial*  ptrCCalMaterial;
 45 typedef CCalAMaterial* ptrCCalAMaterial;           42 typedef CCalAMaterial* ptrCCalAMaterial;
 46                                                    43 
 47                                                    44 
 48 CCalMaterialFactory * CCalMaterialFactory::ins     45 CCalMaterialFactory * CCalMaterialFactory::instance = 0;
 49 G4String CCalMaterialFactory::elementfile = ""     46 G4String CCalMaterialFactory::elementfile = "";
 50 G4String CCalMaterialFactory::mixturefile = ""     47 G4String CCalMaterialFactory::mixturefile = "";
 51                                                    48 
 52                                                    49 
 53 CCalMaterialFactory* CCalMaterialFactory::getI     50 CCalMaterialFactory* CCalMaterialFactory::getInstance(const G4String& matfile,
 54                                                <<  51                   const G4String& mixfile){
 55   if ((matfile=="" || matfile==elementfile) &&     52   if ((matfile=="" || matfile==elementfile) &&
 56       (mixfile=="" || mixfile==mixturefile))       53       (mixfile=="" || mixfile==mixturefile))
 57     return getInstance();                          54     return getInstance();
 58   else if ((matfile != "" && elementfile != ""     55   else if ((matfile != "" && elementfile != "" && matfile != elementfile) ||
 59            (mixfile != "" && mixturefile != ""     56            (mixfile != "" && mixturefile != "" && mixfile != mixturefile)) {
 60     G4cerr << "ERROR: Trying to get materials      57     G4cerr << "ERROR: Trying to get materials from " << matfile << " and " 
 61          << mixfile << " while previously were     58          << mixfile << " while previously were retrieved from " 
 62          << elementfile << " and " << mixturef     59          << elementfile << " and " << mixturefile << "." << G4endl;
 63     return 0;                                      60     return 0;
 64   } else {                                         61   } else {
 65     if (elementfile == "")                         62     if (elementfile == "") 
 66       elementfile=matfile;                         63       elementfile=matfile;
 67     if (mixturefile == "")                         64     if (mixturefile == "") 
 68       mixturefile=mixfile;                         65       mixturefile=mixfile;
 69     return getInstance();                          66     return getInstance();
 70   }                                                67   }
 71 }                                                  68 }
 72                                                    69 
 73                                                    70 
 74 CCalMaterialFactory* CCalMaterialFactory::getI     71 CCalMaterialFactory* CCalMaterialFactory::getInstance(const G4String& matfile){
 75   return getInstance(matfile,matfile);             72   return getInstance(matfile,matfile);
 76 }                                                  73 }
 77                                                    74 
 78                                                    75 
 79 CCalMaterialFactory* CCalMaterialFactory::getI     76 CCalMaterialFactory* CCalMaterialFactory::getInstance(){
 80   if (elementfile=="" || mixturefile=="") {        77   if (elementfile=="" || mixturefile=="") {
 81     G4cerr << "ERROR: You haven't defined file     78     G4cerr << "ERROR: You haven't defined files to be used for materials in "
 82          << "CCalMaterialFactory::getInstance( <<  79    << "CCalMaterialFactory::getInstance(const G4String&,const G4String&)"
 83          << G4endl;                            <<  80    << G4endl;
 84     return 0;                                      81     return 0;
 85   }                                                82   }
 86                                                    83 
 87   if (instance==0) {                               84   if (instance==0) {
 88     instance = new CCalMaterialFactory;            85     instance = new CCalMaterialFactory;
 89     return instance;                               86     return instance;
 90   }                                                87   }
 91   else                                             88   else
 92     return instance;                               89     return instance;
 93 }                                                  90 }
 94                                                    91 
 95                                                    92 
 96 CCalMaterialFactory::~CCalMaterialFactory(){       93 CCalMaterialFactory::~CCalMaterialFactory(){
 97   CCalMaterialTable::iterator ite;                 94   CCalMaterialTable::iterator ite;
 98   for(ite = theCCalMaterials.begin(); ite != t     95   for(ite = theCCalMaterials.begin(); ite != theCCalMaterials.end(); ite++ ){
 99     delete *ite;                                   96     delete *ite;
100   }                                                97   }
101   theCCalMaterials.clear();                        98   theCCalMaterials.clear();
102   CCalAMaterialTable::iterator itea;               99   CCalAMaterialTable::iterator itea;
103   for(itea = theCCalAMaterials.begin(); itea !    100   for(itea = theCCalAMaterials.begin(); itea != theCCalAMaterials.end(); 
104       itea++ ){                                   101       itea++ ){
105     delete *itea;                                 102     delete *itea;
106   }                                               103   }
107   theCCalAMaterials.clear();                      104   theCCalAMaterials.clear();
108 }                                                 105 }
109                                                   106 
110                                                   107   
111 G4Material* CCalMaterialFactory::findMaterial(    108 G4Material* CCalMaterialFactory::findMaterial(const G4String & mat) const {
112   G4Material* theMat=findG4Material(mat);         109   G4Material* theMat=findG4Material(mat);
113                                                   110 
114   if (theMat) {                                   111   if (theMat) {
115 #ifdef ddebug                                     112 #ifdef ddebug
116     G4cout << "Material " << mat << " already     113     G4cout << "Material " << mat << " already defined. Returning previous "
117          << "instance." << G4endl;             << 114    << "instance." << G4endl;
118 #endif                                            115 #endif
119     return theMat;                                116     return theMat;
120   } else {                                        117   } else { 
121     CCalMaterial* CCalmat=findCCalMaterial(mat    118     CCalMaterial* CCalmat=findCCalMaterial(mat);
122     if (CCalmat){                                 119     if (CCalmat){
123       G4Material* G4Mat = new G4Material(CCalm    120       G4Material* G4Mat = new G4Material(CCalmat->Name(),
124                                          CCalm << 121            CCalmat->Density()*g/cm3, 
125                                          CCalm << 122            CCalmat->NElements());
126       for(G4int i=0; i<CCalmat->NElements(); i    123       for(G4int i=0; i<CCalmat->NElements(); i++) {
127         G4Element* elem = findElement(CCalmat- << 124   G4Element* elem = findElement(CCalmat->Element(i));
128         if (!elem) {                           << 125   if (!elem) {
129           G4ExceptionDescription ed;           << 126     G4cerr << "       Could not build material " << mat << "." << G4endl;
130           ed << "   Could not build material " << 127     exit(-10);
131           G4Exception("CCalMaterialFactory::fi << 128   }
132                       FatalException,ed);      << 129   G4Mat->AddElement(elem, CCalmat->Weight(i));
133         }                                      << 
134         G4Mat->AddElement(elem, CCalmat->Weigh << 
135       }                                           130       }
136 #ifdef ddebug                                     131 #ifdef ddebug
137     G4cout << "Material " << mat << " has been    132     G4cout << "Material " << mat << " has been built successfully." << G4endl;
138 #endif                                            133 #endif
139       return G4Mat;                               134       return G4Mat;
140     } else {                                      135     } else {
141       G4cerr << "ERROR: Material " << mat << "    136       G4cerr << "ERROR: Material " << mat << " not found in CCal database!!!" 
142            << G4endl;                          << 137      << G4endl;
143       return 0;                                   138       return 0;
144     }                                             139     }
145   }                                               140   }
146 }                                                 141 }
147                                                   142 
148                                                   143 
149 G4Element* CCalMaterialFactory::findElement(co    144 G4Element* CCalMaterialFactory::findElement(const G4String & mat) const {
150   const G4ElementTable  theElements = *(G4Elem    145   const G4ElementTable  theElements = *(G4Element::GetElementTable());
151   for (unsigned int i=0; i<theElements.size();    146   for (unsigned int i=0; i<theElements.size(); i++)
152     if (theElements[i]->GetName()==mat){          147     if (theElements[i]->GetName()==mat){
153 #ifdef ddebug                                     148 #ifdef ddebug
154       G4cout << "Element " << mat << " found!"    149       G4cout << "Element " << mat << " found!" << G4endl;
155 #endif                                            150 #endif
156       return theElements[i];                      151       return theElements[i];
157     }                                             152     }
158   return 0;                                       153   return 0;
159 }                                                 154 }
160                                                   155 
161                                                   156 
162 G4Element* CCalMaterialFactory::addElement(con    157 G4Element* CCalMaterialFactory::addElement(const G4String & name,
163                                            con << 158              const G4String & symbol,
164                                            G4d << 159              G4double Z, G4double A,
165                                            G4d << 160              G4double density) {
166                                                   161 
167   G4Element* theEl = new G4Element(name, symbo    162   G4Element* theEl = new G4Element(name, symbol, Z, A*g/mole);
168   //Make it also as a material.                   163   //Make it also as a material.
169   CCalAMaterial* theMat = new CCalAMaterial(na    164   CCalAMaterial* theMat = new CCalAMaterial(name,A,density);
170   theCCalAMaterials.push_back(theMat);            165   theCCalAMaterials.push_back(theMat);
171                                                   166 
172 #ifdef ddebug                                     167 #ifdef ddebug
173   G4cout << "Element " << name << " created!"     168   G4cout << "Element " << name << " created!" << G4endl;
174 #endif                                            169 #endif
175   return theEl;                                   170   return theEl;
176 }                                                 171 }
177                                                   172 
178                                                   173 
179 G4Material* CCalMaterialFactory::addMaterial(c    174 G4Material* CCalMaterialFactory::addMaterial(const G4String& name,
180                                              G << 175                G4double density,
181                                              G << 176                G4int nconst,
182                                              G << 177                G4String mats[],
183                                              G << 178                G4double prop[],
184                                              M << 179                MatDescription md){
185   addCCalMaterial(name, density, nconst, mats,    180   addCCalMaterial(name, density, nconst, mats, prop, md);
186   return findMaterial(name);                      181   return findMaterial(name);
187 }                                                 182 }
188                                                   183 
189                                                   184 
190 void CCalMaterialFactory::readElements(const G    185 void CCalMaterialFactory::readElements(const G4String& matfile) {
191                                                   186 
192   G4String path = "NULL";                      << 187   G4String path = getenv("CCAL_GLOBALPATH");
193   if (std::getenv("CCAL_GLOBALPATH"))          << 
194     path = std::getenv("CCAL_GLOBALPATH");     << 
195                                                << 
196   G4cout << " ==> Opening file " << matfile <<    188   G4cout << " ==> Opening file " << matfile << " to read elements..." << G4endl;
197   std::ifstream is;                               189   std::ifstream is;
198   G4bool ok = openGeomFile(is, path, matfile); << 190   bool ok = openGeomFile(is, path, matfile);
199   if (!ok) {                                      191   if (!ok) {
200     G4cerr << "ERROR: Could not open file " <<    192     G4cerr << "ERROR: Could not open file " << matfile << G4endl;
201     return;                                       193     return;
202   }                                               194   }
203                                                   195 
204   // Find *DO GMAT                                196   // Find *DO GMAT
205   findDO(is, G4String("GMAT"));                   197   findDO(is, G4String("GMAT"));
206                                                   198   
207   readElements(is);                               199   readElements(is);
208                                                   200   
209   is.close();                                     201   is.close();
210 }                                                 202 }
211                                                   203 
212                                                   204 
213 void CCalMaterialFactory::readMaterials(const     205 void CCalMaterialFactory::readMaterials(const G4String& matfile) {
214                                                   206 
215   G4String path = "NULL";                      << 207   G4String path = getenv("CCAL_GLOBALPATH");
216   if (std::getenv("CCAL_GLOBALPATH"))          << 
217     path = std::getenv("CCAL_GLOBALPATH");     << 
218                                                << 
219   G4cout << " ==> Opening file " << matfile <<    208   G4cout << " ==> Opening file " << matfile << " to read materials..." << G4endl;
220   std::ifstream is;                               209   std::ifstream is;
221   bool ok = openGeomFile(is, path, matfile);      210   bool ok = openGeomFile(is, path, matfile);
222   if (!ok) {                                      211   if (!ok) {
223     G4cerr << "ERROR: Could not open file " <<    212     G4cerr << "ERROR: Could not open file " << matfile << G4endl;
224     return;                                       213     return;
225   }                                               214   }
226                                                   215 
227   // Find *DO GMIX                                216   // Find *DO GMIX
228   findDO(is, G4String("GMIX"));                   217   findDO(is, G4String("GMIX"));
229                                                   218 
230   readMaterials(is);                              219   readMaterials(is);
231                                                   220 
232   is.close();                                     221   is.close();
233 }                                                 222 }
234                                                   223 
235                                                   224 
236 //============================================    225 //===========================================================================
237 // Protected & private methods ===============    226 // Protected & private methods ==============================================
238                                                   227 
239                                                   228 
240 G4Material* CCalMaterialFactory::findG4Materia    229 G4Material* CCalMaterialFactory::findG4Material(const G4String & mat) const {
241   const G4MaterialTable theG4Materials = *(G4M    230   const G4MaterialTable theG4Materials = *(G4Material::GetMaterialTable());
242   for (unsigned int i=0; i<theG4Materials.size    231   for (unsigned int i=0; i<theG4Materials.size(); i++) {
243     if (theG4Materials[i]->GetName()==mat){       232     if (theG4Materials[i]->GetName()==mat){
244       return theG4Materials[i];                   233       return theG4Materials[i];
245     }                                             234     }
246   }                                               235   }
247   return 0;                                       236   return 0;
248 }                                                 237 }
249                                                   238 
250                                                   239 
251 CCalMaterial* CCalMaterialFactory::findCCalMat    240 CCalMaterial* CCalMaterialFactory::findCCalMaterial(const G4String & mat) 
252   const {                                         241   const {
253   for (unsigned int i=0; i<theCCalMaterials.si    242   for (unsigned int i=0; i<theCCalMaterials.size(); i++)
254     if (theCCalMaterials[i]->Name()==mat){        243     if (theCCalMaterials[i]->Name()==mat){
255 #ifdef ddebug                                     244 #ifdef ddebug
256       G4cout << "CCalMaterial " << mat << " fo    245       G4cout << "CCalMaterial " << mat << " found!" << G4endl;
257 #endif                                            246 #endif
258       return theCCalMaterials[i];                 247       return theCCalMaterials[i];
259     }                                             248     }
260   return (CCalMaterial*) findCCalAMaterial(mat    249   return (CCalMaterial*) findCCalAMaterial(mat);
261 }                                                 250 }
262                                                   251 
263                                                   252 
264 CCalAMaterial* CCalMaterialFactory::findCCalAM    253 CCalAMaterial* CCalMaterialFactory::findCCalAMaterial(const G4String & mat) 
265   const {                                         254   const {
266   for (unsigned int i=0; i<theCCalAMaterials.s    255   for (unsigned int i=0; i<theCCalAMaterials.size(); i++)
267     if (theCCalAMaterials[i]->Name()==mat){       256     if (theCCalAMaterials[i]->Name()==mat){
268 #ifdef ddebug                                     257 #ifdef ddebug
269       G4cout << "CCalMaterial " << mat << " fo    258       G4cout << "CCalMaterial " << mat << " found!" << G4endl;
270 #endif                                            259 #endif
271       return theCCalAMaterials[i];                260       return theCCalAMaterials[i];
272     }                                             261     }
273   return 0;                                       262   return 0;
274 }                                                 263 }
275                                                   264 
276                                                   265 
277 CCalMaterial* CCalMaterialFactory::addCCalMate    266 CCalMaterial* CCalMaterialFactory::addCCalMaterial(const G4String& name, 
278                                                << 267                G4double density,
279                                                << 268                G4int nconst,
280                                                << 269                G4String mats[], 
281                                                << 270                G4double prop[],
282                                                << 271                MatDescription md){
283   ptrCCalMaterial* matcol=0;                      272   ptrCCalMaterial* matcol=0;
284   ptrCCalAMaterial* amatcol=0;                    273   ptrCCalAMaterial* amatcol=0;
285                                                   274 
286   if (md==byAtomic)                               275   if (md==byAtomic)
287     amatcol = new ptrCCalAMaterial[nconst];       276     amatcol = new ptrCCalAMaterial[nconst];
288   else                                            277   else
289     matcol = new ptrCCalMaterial[nconst];         278     matcol = new ptrCCalMaterial[nconst];
290                                                   279 
291   for (G4int i=0; i<nconst; i++){                 280   for (G4int i=0; i<nconst; i++){
292     if (md==byAtomic) {                           281     if (md==byAtomic) {
293       CCalAMaterial* amat = findCCalAMaterial(    282       CCalAMaterial* amat = findCCalAMaterial(mats[i]);
294       if (amat)                                   283       if (amat)
295         amatcol[i]=amat;                       << 284   amatcol[i]=amat;
296       else {                                      285       else {
297         G4cerr << "ERROR: Trying to build" <<  << 286   G4cerr << "ERROR: Trying to build" << name << " out of unknown " 
298              << mats[i] << "." << G4endl       << 287        << mats[i] << "." << G4endl 
299              << "Skiping this material!" << G4 << 288        << "Skiping this material!" << G4endl;
300         delete[] amatcol;                      << 289   delete[] amatcol;
301         return 0;                              << 290   return 0;
302       }                                           291       }
303     } //by Atomic fractions                       292     } //by Atomic fractions
304     else {                                        293     else {
305       CCalMaterial* mat = findCCalMaterial(mat    294       CCalMaterial* mat = findCCalMaterial(mats[i]);
306       if (mat)                                    295       if (mat)
307         matcol[i]=mat;                         << 296   matcol[i]=mat;
308       else {                                      297       else {
309         G4cerr << "ERROR: Trying to build" <<n << 298   G4cerr << "ERROR: Trying to build" <<name << " out of unknown " 
310              << mats[i] << "." << G4endl       << 299        << mats[i] << "." << G4endl 
311              << "Skiping this material!" << G4 << 300        << "Skiping this material!" << G4endl;
312         delete[] matcol;                       << 301   delete[] matcol;
313         return 0;                              << 302   return 0;
314       }                                           303       }
315     }                                             304     }
316   } //for                                         305   } //for
317                                                   306 
318   //Let's do the CCalMaterial!                    307   //Let's do the CCalMaterial!
319   if (md==byAtomic) {                             308   if (md==byAtomic) {
320     CCalAMaterial* amaterial = new CCalAMateri    309     CCalAMaterial* amaterial = new CCalAMaterial(name, density, nconst, 
321                                                << 310              amatcol, prop);
322     delete[] amatcol;                             311     delete[] amatcol;
323     theCCalAMaterials.push_back(amaterial);       312     theCCalAMaterials.push_back(amaterial);
324 #ifdef ddebug                                     313 #ifdef ddebug
325     G4cout << *amaterial << G4endl;               314     G4cout << *amaterial << G4endl;
326 #endif                                            315 #endif
327     return amaterial;                             316     return amaterial;
328   } else {                                        317   } else {
329     CCalMaterial::FractionType ft;                318     CCalMaterial::FractionType ft;
330     if (md == byWeight)                           319     if (md == byWeight)
331       ft=CCalMaterial::FTWeight;                  320       ft=CCalMaterial::FTWeight;
332     else                                          321     else
333       ft=CCalMaterial::FTVolume;                  322       ft=CCalMaterial::FTVolume;
334     CCalMaterial* material = new CCalMaterial(    323     CCalMaterial* material = new CCalMaterial(name, density, nconst, 
335                                             ma << 324               matcol, prop, ft);
336     delete[] matcol;                              325     delete[] matcol;
337     theCCalMaterials.push_back(material);         326     theCCalMaterials.push_back(material);
338 #ifdef ddebug                                     327 #ifdef ddebug
339     G4cout << *material << G4endl;                328     G4cout << *material << G4endl;
340 #endif                                            329 #endif
341     return material;                              330     return material;
342   }                                               331   }  
343 }                                                 332 }
344                                                   333 
345                                                   334 
346 void CCalMaterialFactory::readElements(std::if    335 void CCalMaterialFactory::readElements(std::ifstream& is){
347   G4String name, symbol;                          336   G4String name, symbol;
348                                                   337   
349   G4cout << "     ==> Reading elements... " <<    338   G4cout << "     ==> Reading elements... " << G4endl;
350 #ifdef debug                                      339 #ifdef debug
351   G4cout << "       Element    \tsymbol\tA\tZ\    340   G4cout << "       Element    \tsymbol\tA\tZ\tdensity\tX_0          abs_l"<< G4endl;
352 #endif                                            341 #endif
353   //There should come the list of materials. #    342   //There should come the list of materials. #. Defines a comment
354   //*DO defines the beguining of the Mixes blo    343   //*DO defines the beguining of the Mixes block.
355                                                   344 
356   readName(is,name);                              345   readName(is,name);
357   while (name != "*ENDDO") {                      346   while (name != "*ENDDO") {
358     //It should be an element definition          347     //It should be an element definition
359     G4double A, Z, density;                       348     G4double A, Z, density;
360     is >> symbol >> A >> Z >> density >> jump;    349     is >> symbol >> A >> Z >> density >> jump;    
361 #ifdef debug                                      350 #ifdef debug
362     G4cout << "       " << name << "    \t" <<    351     G4cout << "       " << name << "    \t" << symbol << "\t" 
363          << A << "\t" << Z << "\t" << density  << 352    << A << "\t" << Z << "\t" << density << G4endl;
364 #endif                                            353 #endif    
365     addElement(name, symbol, Z, A, density);      354     addElement(name, symbol, Z, A, density);
366     readName(is,name);                            355     readName(is,name);
367   };                                              356   };
368   G4cout << "     " << G4Element::GetElementTa    357   G4cout << "     " << G4Element::GetElementTable()->size() 
369        << " elements read from file" << G4endl    358        << " elements read from file" << G4endl << G4endl;
370 }                                                 359 }
371                                                   360 
372                                                   361 
373 void CCalMaterialFactory::readMaterials(std::i    362 void CCalMaterialFactory::readMaterials(std::ifstream& is){
374   G4String name, matname;                         363   G4String name, matname;
375                                                   364 
376   G4cout << "     ==> Reading materials... " <    365   G4cout << "     ==> Reading materials... " << G4endl;
377                                                   366 
378   //Take into account the special case of vacu    367   //Take into account the special case of vacuum...
379 #ifdef debug                                      368 #ifdef debug
380   G4cout <<"       \"Vacuum\"" << G4endl;         369   G4cout <<"       \"Vacuum\"" << G4endl;
381 #endif                                            370 #endif
382   G4double density  = universe_mean_density;      371   G4double density  = universe_mean_density;   //from PhysicalConstants.h
383   G4double pressure = 1.E-19*pascal;              372   G4double pressure = 1.E-19*pascal;
384   G4double temperature = 0.1*kelvin;              373   G4double temperature = 0.1*kelvin;
385   new G4Material("Vacuum", /*Z=*/ 1., /*A=*/ 1    374   new G4Material("Vacuum", /*Z=*/ 1., /*A=*/ 1.01*g/mole,
386                  density, kStateGas, temperatu << 375      density, kStateGas, temperature, pressure);
387                                                   376 
388   //There should come the list of materials. #    377   //There should come the list of materials. #. Defines a comment
389   //*ENDDO defines the block.                     378   //*ENDDO defines the block.
390   readName(is,name);                              379   readName(is,name);
391   while (name != "*ENDDO") {                      380   while (name != "*ENDDO") {
392     //It should be a material definition          381     //It should be a material definition
393     matname=name;                                 382     matname=name;
394     G4int nElem;                                  383     G4int nElem;
395     G4double dens;                             << 384     G4double density;
396     is >> nElem >> dens >> jump;               << 385     is >> nElem >> density >> jump;
397                                                   386 
398 #ifdef debug                                      387 #ifdef debug
399     G4cout <<"       " << matname                 388     G4cout <<"       " << matname
400            << " made of " << nElem             << 389      << " made of " << nElem 
401            << " elements. Density=" << dens    << 390      << " elements. Density=" << density 
402            << G4endl;                          << 391      << G4endl;
403 #endif                                            392 #endif
404                                                   393 
405     G4int absnelem = std::abs(nElem);             394     G4int absnelem = std::abs(nElem);
406                                                   395 
407     G4String* mats    = new G4String[absnelem]    396     G4String* mats    = new G4String[absnelem];
408     G4double* weights = new G4double[absnelem]    397     G4double* weights = new G4double[absnelem];
409                                                   398     
410     G4double prop;                                399     G4double prop;
411     for(int i=0; i<absnelem; i++) {               400     for(int i=0; i<absnelem; i++) {
412       readName(is, name);                         401       readName(is, name);
413       is >> prop >> jump;                         402       is >> prop >> jump;
414       mats[i]=name;                               403       mats[i]=name;
415       weights[i]=std::abs(prop);                  404       weights[i]=std::abs(prop);
416     } //for...                                    405     } //for...
417     MatDescription md;                            406     MatDescription md;
418     if (nElem>0 && prop<0)                        407     if (nElem>0 && prop<0)
419       md = byAtomic;                              408       md = byAtomic;
420     else if (nElem>0)                             409     else if (nElem>0)
421       md = byWeight;                              410       md = byWeight;
422     else                                          411     else
423       md = byVolume;                              412       md = byVolume;
424                                                   413 
425     addCCalMaterial(matname, dens, absnelem, m << 414     addCCalMaterial(matname, density, absnelem, mats, weights, md);
426     delete[] mats;                                415     delete[] mats;
427     delete[] weights;                             416     delete[] weights;
428                                                   417     
429     readName(is,name);                            418     readName(is,name);
430   };  //while                                     419   };  //while
431                                                   420 
432   G4cout << "     " << theCCalMaterials.size()    421   G4cout << "     " << theCCalMaterials.size() << " materials read from " 
433        << mixturefile << G4endl << G4endl;        422        << mixturefile << G4endl << G4endl;
434 }                                                 423 }
435                                                   424 
436                                                   425 
437 CCalMaterialFactory::CCalMaterialFactory() {      426 CCalMaterialFactory::CCalMaterialFactory() {
438   readElements (elementfile);                     427   readElements (elementfile);
439   readMaterials(mixturefile);                     428   readMaterials(mixturefile);
440 }                                                 429 }
441                                                   430