Changeset 288 for snovis/trunk/source/G4Lab/cxx/PhysicsTableAccessor.cxx
- Timestamp:
- Sep 25, 2007, 12:24:08 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
snovis/trunk/source/G4Lab/cxx/PhysicsTableAccessor.cxx
r233 r288 24 24 #include <Slash/Data/IIterator.h> 25 25 #include <Lib/Out.h> 26 #include <Lib/sout.h> 26 27 #include <Lib/Value.h> 27 28 #include <Lib/smanip.h> 28 29 #include <Lib/fmanip.h> 29 30 #include <Lib/dirmanip.h> 31 #include <Lib/Cast.h> 30 32 #include <Lib/Debug.h> 31 33 … … 39 41 #include <AIDA/IFunctionFactory.h> 40 42 #include <AIDA/IFunction.h> 43 44 // G4Lab : 45 #include <G4Lab/Interfaces/IGeant4Manager.h> 41 46 42 47 namespace G4Lab { … … 72 77 G4Lab::PhysicsTableAccessor::PhysicsTableAccessor( 73 78 Slash::Core::ISession& aSession 79 ,IGeant4Manager& aManager 74 80 ,AIDA::IAnalysisFactory* aAIDA 75 81 ) 76 82 :Lib::BaseAccessor(aSession.printer()) 77 83 ,fSession(aSession) 84 ,fManager(aManager) 78 85 ,fType("PhysicsTable") 79 86 ,fAIDA(aAIDA) … … 94 101 { 95 102 for(unsigned int index=0;index<fTables.size();index++) delete fTables[index]; 103 } 104 ////////////////////////////////////////////////////////////////////////////// 105 void* G4Lab::PhysicsTableAccessor::cast( 106 const std::string& aClass 107 ) const 108 ////////////////////////////////////////////////////////////////////////////// 109 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 110 { 111 if_Lib_SCast(Slash::Data::IVisualizer) 112 else return Lib::BaseAccessor::cast(aClass); 96 113 } 97 114 ////////////////////////////////////////////////////////////////////////////// … … 129 146 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 130 147 { 131 if(!fTables.size() ) { 132 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); 133 if(particleTable) { 134 G4ParticleTable::G4PTblDicIterator* particleTableIterator = 135 particleTable->GetIterator(); 136 if(particleTableIterator) { 137 particleTableIterator->reset(); 138 while( (*particleTableIterator)() ){ 139 G4ParticleDefinition* particle = particleTableIterator->value(); 140 if(particle) { 141 G4String particleName = particle->GetParticleName(); 142 //Lib::Out out(fSession.printer()); 143 //out << "debug : Particle : " << particleName << Lib::endl; 144 // Processes for this particle : 145 G4ProcessManager* processManager = particle->GetProcessManager(); 146 if(processManager) { 147 G4ProcessVector* processList = processManager->GetProcessList(); 148 if(processList) { 149 int number = processList->entries(); 150 for (int index=0;index<number;index++){ 151 G4VProcess* process = (*processList)(index); 152 std::vector<std::string> names; 153 std::vector<G4PhysicsTable*> tables; 154 if(findProcessTables(particle, 155 process, 156 names, 157 tables)) { 158 for(unsigned int i=0;i<tables.size();i++) { 159 std::vector<std::string> words; 160 Lib::smanip::words(names[i],".",words); 161 if(words.size()==3) { 162 fTables.push_back(new PhysicsTable(words[0], 163 words[1], 164 words[2], 165 tables[i], 166 process, 167 particle)); 168 } 169 } 170 } 171 } 172 } 173 } 174 } 175 } 176 } 177 } 178 } 179 148 if(!fTables.size()) { 149 if(!buildProcessTables()) return 0; 150 } 180 151 return new PhysicsTableIterator(fTables); 181 152 } … … 277 248 G4PhysicsVector* physicsVector = (*(obj->fTable))[count]; 278 249 size_t n = physicsVector->GetVectorLength(); 279 if(n>=2) { 280 std::string name; 281 Lib::smanip::printf(name,1024,"%s.%s.%s.%d", 282 obj->fTableName.c_str(), 283 obj->fProcessName.c_str(), 284 obj->fParticleName.c_str(), 285 count); 286 std::vector<double> params; 287 params.push_back(1); // Dimension of the grid (here one). 288 params.push_back(n); // Number of entries for first grid axis. 289 size_t i; 290 for (i=0;i<n;i++) params.push_back(i); // Xs. 291 for (i=0;i<n;i++) params.push_back((*physicsVector)[i]); //Values. 292 AIDA::IFunction* function = 293 functionFactory->createFunctionByName(name,"Grid1D"); 294 if(!function) { 295 Lib::Out out(fSession.printer()); 296 out << "Can't create \"" << name << "\" function." << Lib::endl; 297 break; 298 } 299 function->setParameters(params); 250 if(n<2) { 251 Lib::Out out(fSession.printer()); 252 out << "PhysicsVector with " << int(n) << " entries. Can't plot." 253 << Lib::endl; 254 continue; 255 } 256 257 std::string name; 258 Lib::smanip::printf(name,1024,"%s.%s.%s.%d", 259 obj->fTableName.c_str(), 260 obj->fProcessName.c_str(), 261 obj->fParticleName.c_str(), 262 count); 263 std::vector<double> params; 264 params.push_back(1); // Dimension of the grid (here one). 265 params.push_back(n); // Number of entries for first grid axis. 266 size_t i; 267 for (i=0;i<n;i++) params.push_back(i); // Xs. 268 for (i=0;i<n;i++) params.push_back((*physicsVector)[i]); //Values. 269 AIDA::IFunction* function = 270 functionFactory->createFunctionByName(name,"Grid1D"); 271 if(!function) { 272 Lib::Out out(fSession.printer()); 273 out << "Can't create \"" << name << "\" function." << Lib::endl; 274 break; 275 } 276 function->setParameters(params); 300 277 301 AIDA::IPlotterRegion& region = plotter->currentRegion(); 302 303 region.plot(*function); 304 region.setParameter("plotter.xAxisAutomated","FALSE"); 305 std::string value1; 306 Lib::smanip::printf(value1,32,"%g",0.); 307 region.setParameter("plotter.xAxisMinimum",value1); 308 std::string value2; 309 Lib::smanip::printf(value2,32,"%g",(double)(n-1)); 310 region.setParameter("plotter.xAxisMaximum",value2); 311 std::string value3; 312 Lib::smanip::printf(value3,32,"%d",4 * n); 313 region.setParameter("plotter.xNumberOfPoints",value3); 314 /* 315 fSession.out().println("debug : min : %s, max : %s, steps : %s\n.", 316 value1.c_str(),value2.c_str(),value3.c_str()); 317 */ 318 319 if(!superpose) plotter->next(); 278 AIDA::IPlotterRegion& region = plotter->currentRegion(); 279 280 region.plot(*function); 281 region.setParameter("plotter.xAxisAutomated","FALSE"); 282 std::string value1; 283 Lib::smanip::printf(value1,32,"%g",0.); 284 region.setParameter("plotter.xAxisMinimum",value1); 285 std::string value2; 286 Lib::smanip::printf(value2,32,"%g",(double)(n-1)); 287 region.setParameter("plotter.xAxisMaximum",value2); 288 //std::string value3; 289 //Lib::smanip::printf(value3,32,"%d",4 * n); 290 //region.setParameter("plotter.xNumberOfPoints",value3); 291 /* 292 fSession.out().println("debug : min : %s, max : %s, steps : %s\n.", 293 value1.c_str(),value2.c_str(),value3.c_str()); 294 */ 295 if(!superpose) plotter->next(); 320 296 321 }322 297 } 323 298 … … 335 310 } 336 311 ////////////////////////////////////////////////////////////////////////////// 312 bool G4Lab::PhysicsTableAccessor::buildProcessTables( 313 ) 314 ////////////////////////////////////////////////////////////////////////////// 315 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 316 { 317 if(fTables.size()) return true; //done. 318 319 if(!fManager.isRunning()) { 320 Lib::Out out(fSession.printer()); 321 out << "G4Lab::PhysicsTableAccessor::buildProcessTables :" 322 << " It is needed to have started a run to get physics tables." 323 << Lib::endl; 324 return false; 325 } 326 327 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); 328 if(!particleTable) { 329 Lib::Out out(fSession.printer()); 330 out << "G4Lab::PhysicsTableAccessor::buildProcessTables :" 331 << " Can't get particle table." 332 << Lib::endl; 333 return false; 334 } 335 336 G4ParticleTable::G4PTblDicIterator* particleTableIterator = 337 particleTable->GetIterator(); 338 if(!particleTableIterator) { 339 Lib::Out out(fSession.printer()); 340 out << "G4Lab::PhysicsTableAccessor::buildProcessTables :" 341 << " Can't get particle table iterator." 342 << Lib::endl; 343 return false; 344 } 345 346 particleTableIterator->reset(); 347 while( (*particleTableIterator)() ){ 348 G4ParticleDefinition* particle = particleTableIterator->value(); 349 if(!particle) { 350 Lib::Out out(fSession.printer()); 351 out << "G4Lab::PhysicsTableAccessor::buildProcessTables :" 352 << " Can't get particle table particle." 353 << Lib::endl; 354 return false; 355 } 356 G4String particleName = particle->GetParticleName(); 357 //Lib::Out out(fSession.printer()); 358 //out << "debug : Particle : " << particleName << Lib::endl; 359 360 // Processes for this particle : 361 G4ProcessManager* processManager = particle->GetProcessManager(); 362 if(!processManager) { 363 Lib::Out out(fSession.printer()); 364 out << "G4Lab::PhysicsTableAccessor::buildProcessTables :" 365 << " Can't get process manager of particle " 366 << particleName << "." 367 << Lib::endl; 368 return false; 369 } 370 371 G4ProcessVector* processList = processManager->GetProcessList(); 372 if(!processList) { 373 Lib::Out out(fSession.printer()); 374 out << "G4Lab::PhysicsTableAccessor::buildProcessTables :" 375 << " Can't get process list for process manager of particle " 376 << particleName << "." 377 << Lib::endl; 378 return false; 379 } 380 381 int number = processList->entries(); 382 for (int index=0;index<number;index++){ 383 G4VProcess* process = (*processList)(index); 384 std::vector<std::string> names; 385 std::vector<G4PhysicsTable*> tables; 386 if(!findProcessTables(particle,process,names,tables)) { 387 return false; 388 } 389 390 for(unsigned int i=0;i<tables.size();i++) { 391 std::vector<std::string> words; 392 Lib::smanip::words(names[i],".",words); 393 if(words.size()!=3) { 394 Lib::Out out(fSession.printer()); 395 out << "G4Lab::PhysicsTableAccessor::buildProcessTables :" 396 << " Three words separted with a dot expected in " 397 << names[i] << " for particle " << particleName << "." 398 << Lib::endl; 399 return false; 400 } 401 fTables.push_back(new PhysicsTable(words[0], 402 words[1], 403 words[2], 404 tables[i], 405 process, 406 particle)); 407 } 408 } 409 } 410 411 return true; 412 } 413 ////////////////////////////////////////////////////////////////////////////// 337 414 bool G4Lab::PhysicsTableAccessor::findProcessTables( 338 415 G4ParticleDefinition* aParticle … … 364 441 #else 365 442 G4bool ascii = false; 443 //G4bool ascii = true; 366 444 #endif 367 aProcess->StorePhysicsTable(aParticle,tmpName,ascii); 368 369 // Analyse the content of the directory : 370 std::vector<std::string> files; 371 if(!Lib::dirmanip::entries(tmpName,files,false)) { 372 Lib::Out out(fSession.printer()); 373 out << "Can't get files in \"" << tmpName << "\" directory." << Lib::endl; 445 446 if(!aProcess->StorePhysicsTable(aParticle,tmpName,ascii)) { 447 Lib::Out out(fSession.printer()); 448 out << "Can't store physics table for particle " 449 << aParticle->GetParticleName() 450 << " and process " << aProcess->GetProcessName() << "." 451 << Lib::endl; 452 //return false; 374 453 } else { 375 // Analyse files : 376 Lib::smanip::remove(files,"."); 377 Lib::smanip::remove(files,".."); 378 for(unsigned int index=0;index<files.size();index++) { 379 std::vector<std::string> words; 380 Lib::smanip::words(files[index],".",words); 381 //Lib::Out out(fSession.printer()); 382 //out << "debug : Analyse \"" << files[index] << "\" ." << Lib::endl; 383 if(words.size()==4) { 454 455 // Analyse the content of the directory : 456 std::vector<std::string> files; 457 if(!Lib::dirmanip::entries(tmpName,files,false)) { 458 Lib::Out out(fSession.printer()); 459 out << "Can't get files in \"" << tmpName << "\" directory." 460 << Lib::endl; 461 } else { 462 // Analyse files : 463 Lib::smanip::remove(files,"."); 464 Lib::smanip::remove(files,".."); 465 /* 466 if(!files.size()) { 467 Lib::Out out(fSession.printer()); 468 out << "No files in \"" << tmpName << "\" directory for particle " 469 << aParticle->GetParticleName() 470 << " and process " << aProcess->GetProcessName() << "." 471 << Lib::endl; 472 //return false; 473 } 474 */ 475 for(unsigned int index=0;index<files.size();index++) { 476 std::vector<std::string> words; 477 Lib::smanip::words(files[index],".",words); 478 //Lib::Out out(fSession.printer()); 479 //out << "debug : Analyse \"" << files[index] << "\" ." << Lib::endl; 480 if(words.size()!=4) { 481 Lib::Out out(fSession.printer()); 482 out << "Bad syntax in file name " << Lib::sout(files[index]) 483 << " for particle " << aParticle->GetParticleName() 484 << " and process " << aProcess->GetProcessName() << "." 485 << Lib::endl; 486 //aTables.clear(); 487 //aPhysicsTables.clear(); 488 //return false; 489 continue; 490 } 384 491 std::string table = words[0]; 385 492 std::string process = words[1]; … … 393 500 G4PhysicsTable* physicsTable = 394 501 new G4PhysicsTable(G4Element::GetNumberOfElements()); 395 if(physicsTable) { 396 G4bool status = physicsTable->RetrievePhysicsTable(filename,ascii); 397 if(!status){ 398 Lib::Out out(fSession.printer()); 399 out << "Unable to read \"" << filename << "\" file." << Lib::endl; 400 delete physicsTable; 401 physicsTable = 0; 402 } 502 G4bool status = physicsTable->RetrievePhysicsTable(filename,ascii); 503 if(!status){ 504 Lib::Out out(fSession.printer()); 505 out << "Unable to read \"" << filename << "\" file." << Lib::endl; 506 delete physicsTable; 507 physicsTable = 0; 403 508 } 404 509 if(physicsTable) { … … 408 513 } 409 514 } 515 410 516 } 411 517
Note: See TracChangeset
for help on using the changeset viewer.