// this : #include // Inventor : #include #include #include #ifdef WIN32 #undef pascal // Clash between windef.h and Geant4/SystemOfUnits.hh #endif // Geant4 : #include #include #include #include #include #include #include // Lib : #include #include #include #include #include #include #include #include // AIDA : #include #include #include #include #include #include #include #include namespace G4Lab { class PhysicsTable { public: PhysicsTable(const std::string& aTableName, const std::string& aProcessName, const std::string& aParticleName, G4PhysicsTable* aTable, G4VProcess* aProcess, G4ParticleDefinition* aParticle) :fTableName(aTableName) ,fProcessName(aProcessName) ,fParticleName(aParticleName) ,fTable(aTable) ,fProcess(aProcess) ,fParticle(aParticle){} virtual ~PhysicsTable() { delete fTable; } public: std::string fTableName; std::string fProcessName; std::string fParticleName; G4PhysicsTable* fTable; G4VProcess* fProcess; G4ParticleDefinition* fParticle; Lib::Debug fDebug; }; } ////////////////////////////////////////////////////////////////////////////// G4Lab::PhysicsTableAccessor::PhysicsTableAccessor( Slash::Core::ISession& aSession ,AIDA::IAnalysisFactory* aAIDA ) :Lib::BaseAccessor(aSession.printer()) ,fSession(aSession) ,fType("PhysicsTable") ,fAIDA(aAIDA) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { addProperty("table",Lib::Property::STRING); addProperty("process",Lib::Property::STRING); addProperty("particle",Lib::Property::STRING); addProperty("number",Lib::Property::INTEGER); addProperty("name",Lib::Property::STRING); } ////////////////////////////////////////////////////////////////////////////// G4Lab::PhysicsTableAccessor::~PhysicsTableAccessor( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { for(unsigned int index=0;index& aVector) :fVector(aVector) { fIterator = fVector.begin(); } virtual ~PhysicsTableIterator() {} private: std::vector& fVector; std::vector::iterator fIterator; }; } ////////////////////////////////////////////////////////////////////////////// Slash::Data::IIterator* G4Lab::PhysicsTableAccessor::iterator( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { if(!fTables.size() ) { G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); if(particleTable) { G4ParticleTable::G4PTblDicIterator* particleTableIterator = particleTable->GetIterator(); if(particleTableIterator) { particleTableIterator->reset(); while( (*particleTableIterator)() ){ G4ParticleDefinition* particle = particleTableIterator->value(); if(particle) { G4String particleName = particle->GetParticleName(); //Lib::Out out(fSession.printer()); //out << "debug : Particle : " << particleName << Lib::endl; // Processes for this particle : G4ProcessManager* processManager = particle->GetProcessManager(); if(processManager) { G4ProcessVector* processList = processManager->GetProcessList(); if(processList) { int number = processList->entries(); for (int index=0;index names; std::vector tables; if(findProcessTables(particle, process, names, tables)) { for(unsigned int i=0;i words; Lib::smanip::words(names[i],".",words); if(words.size()==3) { fTables.push_back(new PhysicsTable(words[0], words[1], words[2], tables[i], process, particle)); } } } } } } } } } } } return new PhysicsTableIterator(fTables); } ////////////////////////////////////////////////////////////////////////////// Slash::Core::IValue* G4Lab::PhysicsTableAccessor::findValue( Slash::Data::IAccessor::Data aData ,const std::string& aName ,void* ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { PhysicsTable* obj = (PhysicsTable*)aData; if(aName=="table") { return new Lib::Value(obj->fTableName); } else if(aName=="process") { return new Lib::Value(obj->fProcessName); } else if(aName=="particle") { return new Lib::Value(obj->fParticleName); } else if(aName=="number") { return new Lib::Value((int)obj->fTable->size()); } else if(aName=="name") { std::string name = obj->fTableName + "." + obj->fProcessName + "." + obj->fParticleName; return new Lib::Value(name); } else { return new Lib::Value(); } } ////////////////////////////////////////////////////////////////////////////// void G4Lab::PhysicsTableAccessor::beginVisualize( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { if(!fAIDA) { Lib::Out out(fSession.printer()); out << "G4Lab::PhysicsTableAccessor::beginVisualize :" << " AIDA not found. Can't then find an AIDA plotter." << Lib::endl; } } ////////////////////////////////////////////////////////////////////////////// void G4Lab::PhysicsTableAccessor::visualize( Slash::Data::IAccessor::Data aData ,void* ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { PhysicsTable* obj = (PhysicsTable*)aData; std::string value; bool superpose = true; if(fSession.parameterValue("modeling.superpose",value)) if(!Lib::smanip::tobool(value,superpose)) superpose = true; if(!fAIDA) return; AIDA::ITreeFactory* tf = fAIDA->createTreeFactory(); if(!tf) return; AIDA::ITree* memoryTree = tf->create(); delete tf; if(!memoryTree) return; AIDA::IFunctionFactory* functionFactory = fAIDA->createFunctionFactory(*memoryTree); if(!functionFactory) { Lib::Out out(fSession.printer()); out << "Can't create an function factory." << Lib::endl; return; } AIDA::IPlotterFactory* plotterFactory = fAIDA->createPlotterFactory(); if(!plotterFactory) { Lib::Out out(fSession.printer()); out << "Can't create a plotter factory." << Lib::endl; delete functionFactory; return; } AIDA::IPlotter* plotter = plotterFactory->create(); if(!plotter) { Lib::Out out(fSession.printer()); out << "Can't create a plotter factory." << Lib::endl; delete functionFactory; delete plotterFactory; return; } int number = obj->fTable->entries(); if(!superpose) { if(number>0) plotter->createRegions(1,number,0); else plotter->createRegions(1,1,0); } for (int count=0;countfTable))[count]; size_t n = physicsVector->GetVectorLength(); if(n>=2) { std::string name; Lib::smanip::printf(name,1024,"%s.%s.%s.%d", obj->fTableName.c_str(), obj->fProcessName.c_str(), obj->fParticleName.c_str(), count); std::vector params; params.push_back(1); // Dimension of the grid (here one). params.push_back(n); // Number of entries for first grid axis. size_t i; for (i=0;icreateFunctionByName(name,"Grid1D"); if(!function) { Lib::Out out(fSession.printer()); out << "Can't create \"" << name << "\" function." << Lib::endl; break; } function->setParameters(params); AIDA::IPlotterRegion& region = plotter->currentRegion(); region.plot(*function); region.setParameter("plotter.xAxisAutomated","FALSE"); std::string value1; Lib::smanip::printf(value1,32,"%g",0.); region.setParameter("plotter.xAxisMinimum",value1); std::string value2; Lib::smanip::printf(value2,32,"%g",(double)(n-1)); region.setParameter("plotter.xAxisMaximum",value2); std::string value3; Lib::smanip::printf(value3,32,"%d",4 * n); region.setParameter("plotter.xNumberOfPoints",value3); /* fSession.out().println("debug : min : %s, max : %s, steps : %s\n.", value1.c_str(),value2.c_str(),value3.c_str()); */ if(!superpose) plotter->next(); } } delete plotter; delete functionFactory; delete plotterFactory; } ////////////////////////////////////////////////////////////////////////////// void G4Lab::PhysicsTableAccessor::endVisualize( ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { } ////////////////////////////////////////////////////////////////////////////// bool G4Lab::PhysicsTableAccessor::findProcessTables( G4ParticleDefinition* aParticle ,G4VProcess* aProcess ,std::vector& aTables ,std::vector& aPhysicsTables ) ////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// { aTables.clear(); aPhysicsTables.clear(); std::string tmpName; if(!Lib::fmanip::tmpname(tmpName,".","G4Lab_tmp","")) { Lib::Out out(fSession.printer()); out << "Can't build a temporary directory name." << Lib::endl; return false; } if(!Lib::dirmanip::create(tmpName)) { Lib::Out out(fSession.printer()); out << "Can't create \"" << tmpName << "\" directory." << Lib::endl; return false; } #ifdef WIN32 //binary mode out on Windows. G4bool ascii = true; #else G4bool ascii = false; #endif aProcess->StorePhysicsTable(aParticle,tmpName,ascii); // Analyse the content of the directory : std::vector files; if(!Lib::dirmanip::entries(tmpName,files,false)) { Lib::Out out(fSession.printer()); out << "Can't get files in \"" << tmpName << "\" directory." << Lib::endl; } else { // Analyse files : Lib::smanip::remove(files,"."); Lib::smanip::remove(files,".."); for(unsigned int index=0;index words; Lib::smanip::words(files[index],".",words); //Lib::Out out(fSession.printer()); //out << "debug : Analyse \"" << files[index] << "\" ." << Lib::endl; if(words.size()==4) { std::string table = words[0]; std::string process = words[1]; std::string particle = words[2]; //Lib::smanip::replace(aTables[i],".dat",""); std::string filename = aProcess->GetPhysicsTableFileName(aParticle, tmpName, table, ascii); G4PhysicsTable* physicsTable = new G4PhysicsTable(G4Element::GetNumberOfElements()); if(physicsTable) { G4bool status = physicsTable->RetrievePhysicsTable(filename,ascii); if(!status){ Lib::Out out(fSession.printer()); out << "Unable to read \"" << filename << "\" file." << Lib::endl; delete physicsTable; physicsTable = 0; } } if(physicsTable) { aTables.push_back(table+"."+process+"."+particle); aPhysicsTables.push_back(physicsTable); } } } } // Remove the temporary directory : if(!Lib::dirmanip::remove(tmpName)) { Lib::Out out(fSession.printer()); out << "Can't remove \"" << tmpName << "\" directory." << Lib::endl; aTables.clear(); aPhysicsTables.clear(); return false; } return true; }