Import Geant4 10.4.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2017-06-30 10:49:55 +02:00
parent 3a5407696b
commit 1a1316fea4
2180 changed files with 237880 additions and 59109 deletions
@@ -79,12 +79,16 @@ TSRun::~TSRun()
{
//--- Clear HitsMap for RUN
for(unsigned i = 0; i < fRunMaps.size(); ++i)
fRunMaps[i]->clear();
delete fRunMaps[i];
if(!G4Threading::IsWorkerThread())
{
for(unsigned i = 0; i < fAtomicRunMaps.size(); ++i)
fAtomicRunMaps[i]->clear();
delete fAtomicRunMaps[i];
fAtomicRunMaps.clear();
fMutexRunMaps.clear();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -103,38 +107,39 @@ void TSRun::ConstructMFD(const G4String& mfdName)
//
if ( mfd )
{
//--- Loop over the registered primitive scorers.
for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
// Get Primitive Scorer object.
G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
// collection name and collectionID for HitsCollection,
// where type of HitsCollection is G4THitsMap in case
// of primitive scorer.
// The collection name is given by <MFD name>/<Primitive
// Scorer name>.
G4String collectionName = scorer->GetName();
G4String fullCollectionName = mfdName+"/"+collectionName;
G4int collectionID = SDman->GetCollectionID(fullCollectionName);
//
if ( collectionID >= 0 ){
G4cout << "++ " << fullCollectionName<< " id " << collectionID
<< G4endl;
// Store obtained HitsCollection information into data members.
// And, creates new G4THitsMap for accumulating quantities during RUN.
fCollNames.push_back(fullCollectionName);
fCollIDs.push_back(collectionID);
fRunMaps.push_back(new G4THitsMap<G4double>(mfdName,
collectionName));
if(!G4Threading::IsWorkerThread())
{
fAtomicRunMaps.push_back(new G4TAtomicHitsMap<G4double>
(mfdName, collectionName));
}
} else {
G4cout << "** collection " << fullCollectionName << " not found. "
<<G4endl;
}
//--- Loop over the registered primitive scorers.
for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
// Get Primitive Scorer object.
G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
// collection name and collectionID for HitsCollection,
// where type of HitsCollection is G4THitsMap in case
// of primitive scorer.
// The collection name is given by <MFD name>/<Primitive
// Scorer name>.
G4String collectionName = scorer->GetName();
G4String fullCollectionName = mfdName+"/"+collectionName;
G4int collectionID = SDman->GetCollectionID(fullCollectionName);
//
if ( collectionID >= 0 ){
G4cout << "++ " << fullCollectionName<< " id " << collectionID
<< G4endl;
// Store obtained HitsCollection information into data members.
// And, creates new G4THitsMap for accumulating quantities during RUN.
fCollNames.push_back(fullCollectionName);
fCollIDs.push_back(collectionID);
fRunMaps.push_back(new G4THitsMap<G4double>(mfdName,
collectionName));
if(!G4Threading::IsWorkerThread())
{
fAtomicRunMaps.push_back(new G4TAtomicHitsMap<G4double>
(mfdName, collectionName));
fMutexRunMaps[fCollNames[collectionID]].clear();
}
} else {
G4cout << "** collection " << fullCollectionName << " not found. "
<<G4endl;
}
}
}
}
@@ -146,7 +151,7 @@ void TSRun::ConstructMFD(const G4String& mfdName)
// is accumulated during a TSRun.
void TSRun::RecordEvent(const G4Event* aEvent)
{
numberOfEvent++; // This is an original line.
G4Run::RecordEvent(aEvent);
//=============================
// HitsCollection of This Event
@@ -176,10 +181,9 @@ void TSRun::RecordEvent(const G4Event* aEvent)
static G4Mutex mtx = G4MUTEX_INITIALIZER;
{
G4AutoLock lock(&mtx);
auto itr = EvtMap->GetMap()->begin();
for(; itr != EvtMap->GetMap()->end(); itr++)
for(const auto& itr : *EvtMap)
{
fMutexRunMaps[fCollNames[fCollID]][itr->first] += *itr->second;
fMutexRunMaps[fCollNames[fCollID]][itr.first] += *itr.second;
}
}
//----------------------------------------------------------------//
@@ -187,8 +191,6 @@ void TSRun::RecordEvent(const G4Event* aEvent)
}
G4Run::RecordEvent(aEvent);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -250,7 +252,7 @@ TSRun::MutexHitsMap_t*
TSRun::GetMutexHitsMap(const G4String& collName) const
{
if(fMutexRunMaps.find(collName) != fMutexRunMaps.end())
return &fMutexRunMaps[collName];
return &fMutexRunMaps[collName];
G4Exception("TSRun", collName.c_str(), JustWarning,
"GetHitsMap failed to locate the requested MutexHitsMap");
@@ -82,192 +82,209 @@ void TSRunAction::EndOfRunAction(const G4Run* aRun)
if(IsMaster())
{
G4cout << " ###### EndOfTSRunAction ###### " << G4endl;
G4cout << " ###### EndOfTSRunAction ###### " << G4endl;
aRun->GetNumberOfEvent();
std::ofstream fileout;
G4String fname = "";
std::stringstream separator;
aRun->GetNumberOfEvent();
std::ofstream fileout;
G4String fname = "";
std::stringstream separator;
separator
<< "============================================================";
separator
<< "============================================================";
typedef std::set<G4int> IDSet_t;
IDSet_t IDs;
typedef std::set<G4int> IDSet_t;
IDSet_t IDs;
//- TSRun object.
const TSRun* tsRun = static_cast<const TSRun*>(aRun);
//--- Dump all scored quantities involved in TSRun.
//- TSRun object.
const TSRun* tsRun = static_cast<const TSRun*>(aRun);
//--- Dump all scored quantities involved in TSRun.
//---------------------------------------------
// Dump accumulated quantities for this RUN.
//---------------------------------------------
std::vector<G4String> primScorerNames { "EnergyDeposit",
"NumberOfSteps" };
std::vector<G4String> fnames { "mfd_tl", "mfd_tg" };
std::vector<G4double> units { CLHEP::eV, CLHEP::keV, 1, 1 };
std::vector<G4String> unitstr { "keV", "steps" };
//---------------------------------------------
// Dump accumulated quantities for this RUN.
//---------------------------------------------
std::vector<G4String> primScorerNames { "EnergyDeposit",
"NumberOfSteps" };
std::vector<G4String> fnames { "mfd_tl", "mfd_tg" };
std::vector<G4double> units { CLHEP::eV, CLHEP::keV, 1, 1 };
std::vector<G4String> unitstr { "keV", "steps" };
for(unsigned i = 0; i < primScorerNames.size(); ++i)
for(unsigned i = 0; i < primScorerNames.size(); ++i)
{
for(unsigned j = 0; j < fnames.size(); ++j)
{
for(unsigned j = 0; j < fnames.size(); ++j)
//----------------------------------------------------------------//
auto print = [] (std::ostream& fout,
G4int first, G4double second,
G4double unit1, G4double unit2, G4String unit2str)
{
//----------------------------------------------------------------//
auto print = [] (std::ostream& fout,
G4int first, G4double second,
G4double unit1, G4double unit2, G4String unit2str)
if(fout)
fout << first
<< " " << second/unit1
<< G4endl;
G4cout
<< " " << std::setw(10) << first
<< " " << std::setw(15) << std::setprecision(6)
<< std::fixed << second/unit2 << " " << unit2str
<< G4endl;
G4cout.unsetf(std::ios::fixed);
};
//----------------------------------------------------------------//
fname = fnames.at(j) + "_" + primScorerNames.at(i) + ".out";
fileout.open(fname);
G4cout << separator.str() << G4endl;
G4cout << " opened file " << fname << " for output" << G4endl;
G4cout << separator.str() << G4endl;
G4bool valid = true;
if(j == 0)
{
G4THitsMap<G4double>* hitmap
= tsRun->GetHitsMap(fName + "/" + primScorerNames.at(i));
if(hitmap && hitmap->GetMap()->size() != 0)
{
if(fout)
fout << first
<< " " << second/unit1
<< G4endl;
G4cout
<< " " << std::setw(10) << first
<< " " << std::setw(15) << std::setprecision(6)
<< std::fixed << second/unit2 << " " << unit2str
<< G4endl;
G4cout.unsetf(std::ios::fixed);
};
//----------------------------------------------------------------//
fname = fnames.at(j) + "_" + primScorerNames.at(i) + ".out";
fileout.open(fname);
G4cout << separator.str() << G4endl;
G4cout << " opened file " << fname << " for output" << G4endl;
G4cout << separator.str() << G4endl;
G4bool valid = true;
if(j == 0)
{
G4THitsMap<G4double>* hitmap
= tsRun->GetHitsMap(fName + "/" + primScorerNames.at(i));
if(hitmap && hitmap->GetMap()->size() != 0)
for(auto itr = hitmap->GetMap()->begin();
itr != hitmap->GetMap()->end(); itr++)
{
for(auto itr = hitmap->GetMap()->begin();
itr != hitmap->GetMap()->end(); itr++)
{
IDs.insert(itr->first);
std::get<0>(fTypeCompare[primScorerNames.at(i)][itr->first])
= *itr->second/units.at(i);
print(fileout, itr->first, *itr->second,
units.at(i), units.at(i+1), unitstr.at(i));
}
} else {
valid = false;
IDs.insert(itr->first);
std::get<0>(fTypeCompare[primScorerNames.at(i)][itr->first])
= *itr->second/units.at(i);
print(fileout, itr->first, *itr->second,
units.at(i), units.at(i+1), unitstr.at(i));
}
} else {
G4TAtomicHitsMap<G4double>* hitmap
= tsRun->GetAtomicHitsMap(fName + "/" +
primScorerNames.at(i));
if(hitmap && hitmap->GetMap()->size() != 0)
{
for(auto itr = hitmap->GetMap()->begin();
itr != hitmap->GetMap()->end(); itr++)
{
IDs.insert(itr->first);
std::get<1>(fTypeCompare[primScorerNames.at(i)][itr->first])
= *itr->second/units.at(i);
print(fileout, itr->first, *itr->second,
units.at(i), units.at(i+1), unitstr.at(i));
}
} else {
valid = false;
}
if(!valid)
{
G4Exception("TSRunAction", "000", JustWarning,
G4String(primScorerNames.at(i) +
" HitsMap is either not "
"created or the HitsMap was empty").c_str());
}
valid = false;
}
fileout.close();
G4cout << separator.str() << G4endl;
G4cout << " closed file " << fname << " for output" << G4endl;
}
// add the mutex data
TSRun::MutexHitsMap_t* hitmap
= tsRun->GetMutexHitsMap(fName + "/" +
primScorerNames.at(i));
if(hitmap && hitmap->size() != 0)
{
for(auto itr = hitmap->begin();
itr != hitmap->end(); itr++)
} else {
G4TAtomicHitsMap<G4double>* hitmap
= tsRun->GetAtomicHitsMap(fName + "/" +
primScorerNames.at(i));
if(hitmap && hitmap->GetMap()->size() != 0)
{
IDs.insert(itr->first);
std::get<2>(fTypeCompare[primScorerNames.at(i)][itr->first])
= itr->second/units.at(i);
for(auto itr = hitmap->GetMap()->begin();
itr != hitmap->GetMap()->end(); itr++)
{
IDs.insert(itr->first);
std::get<1>(fTypeCompare[primScorerNames.at(i)][itr->first])
= *itr->second/units.at(i);
print(fileout, itr->first, *itr->second,
units.at(i), units.at(i+1), unitstr.at(i));
}
} else {
valid = false;
}
if(!valid)
{
G4Exception("TSRunAction", "000", JustWarning,
G4String(primScorerNames.at(i) +
" HitsMap is either not "
"created or the HitsMap was empty").c_str());
}
}
fileout.close();
G4cout << separator.str() << G4endl;
G4cout << " closed file " << fname << " for output" << G4endl;
}
//--------------------------------------------------------------------//
// Check that the values are equivalent and there are no
// IDs in one container that aren't in another
//--------------------------------------------------------------------//
fname = "mfd_diff.out";
fileout.open(fname);
G4cout << separator.str() << G4endl;
G4cout << " opened file " << fname << " for difference output" << G4endl;
G4cout << separator.str() << G4endl;
fileout
<< " " << std::setw(10) << "ID"
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< "MFD value"
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< "Atomic Hits Map value"
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< "Difference"
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< "Diff (MFD - MUTEXED)"
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< "Diff (ATOM_HIT_MAP - MUTEXED)"
<< G4endl << G4endl;
for(auto itr1 = fTypeCompare.begin();
itr1 != fTypeCompare.end(); ++itr1)
// add the mutex data
TSRun::MutexHitsMap_t* hitmap
= tsRun->GetMutexHitsMap(fName + "/" +
primScorerNames.at(i));
if(hitmap && hitmap->size() != 0)
{
fileout << "\n\nType = " << itr1->first << "\n" << G4endl;
for(auto itr2 = itr1->second.begin();
itr2 != itr1->second.end(); ++itr2)
for(auto itr = hitmap->begin();
itr != hitmap->end(); itr++)
{
fileout
<< " " << std::setw(10) << itr2->first
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< std::get<0>(itr2->second)
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< std::get<1>(itr2->second)
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< (std::fabs(std::get<0>(itr2->second) - std::get<1>(itr2->second)))
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< (std::fabs(std::get<0>(itr2->second) - std::get<2>(itr2->second)))
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< (std::fabs(std::get<1>(itr2->second) - std::get<2>(itr2->second)))
<< G4endl;
IDs.insert(itr->first);
std::get<2>(fTypeCompare[primScorerNames.at(i)][itr->first])
= itr->second/units.at(i);
}
}
fileout.close();
G4cout << " closed file " << fname << " for difference output" << G4endl;
G4cout << separator.str() << G4endl;
}
//--------------------------------------------------------------------//
// Check that the values are equivalent and there are no
// IDs in one container that aren't in another
//--------------------------------------------------------------------//
fname = "mfd_diff.out";
fileout.open(fname);
G4cout << separator.str() << G4endl;
G4cout << " opened file " << fname << " for difference output" << G4endl;
G4cout << separator.str() << G4endl;
fileout
<< " " << std::setw(10) << "ID"
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< "MFD value"
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< "Atomic Hits Map value"
<< " "
<< std::setw(30) << std::setprecision(8) << std::scientific
<< "Difference"
<< " "
<< std::setw(30) << std::setprecision(8) << std::scientific
<< "Diff (MFD - MUTEXED)"
<< " "
<< std::setw(30) << std::setprecision(8) << std::scientific
<< "Diff (ATOM_HIT_MAP - MUTEXED)"
<< G4endl << G4endl;
for(auto itr1 = fTypeCompare.begin();
itr1 != fTypeCompare.end(); ++itr1)
{
fileout << "\n\nType = " << itr1->first << "\n" << G4endl;
for(auto itr2 = itr1->second.begin();
itr2 != itr1->second.end(); ++itr2)
{
G4double d01
= std::fabs(std::get<0>(itr2->second) -
std::get<1>(itr2->second));
G4double d02
= std::fabs(std::get<0>(itr2->second) -
std::get<2>(itr2->second));
G4double d03
= std::fabs(std::get<1>(itr2->second) -
std::get<2>(itr2->second));
auto _print_diff = [&] (const G4double& _dval)
{
if(_dval > 0.0)
fileout << std::setprecision(8) << std::scientific
<< std::setw(30) << _dval << " ";
else
fileout << std::setprecision(1) << std::fixed
<< std::setw(30) << _dval << " ";
};
fileout
<< " " << std::setw(10) << itr2->first
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< std::get<0>(itr2->second)
<< " "
<< std::setw(30) << std::setprecision(12) << std::fixed
<< std::get<1>(itr2->second)
<< " ";
_print_diff(d01);
_print_diff(d02);
_print_diff(d03);
fileout << G4endl;
}
}
fileout.close();
G4cout << " closed file " << fname << " for difference output" << G4endl;
G4cout << separator.str() << G4endl;
}