Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation for merge files #101

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ void ShowUsage();

} // namespace CommandLineOptions

class G4VSteppingVerbose;

class Application {
public:
void Run(const CommandLineOptions::Options& options);

~Application() = default;
~Application();

private:
SimulationManager fSimulationManager;

G4VSteppingVerbose* fSteppingVerbose;
void ValidateOutputFile(const std::string& outputFile) const;
};

Expand Down
5 changes: 4 additions & 1 deletion src/Application.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ void Application::Run(const CommandLineOptions::Options& options) {
long seed = metadata->GetSeed();
CLHEP::HepRandom::setTheSeed(seed);

G4VSteppingVerbose::SetInstance(new SteppingVerbose(&fSimulationManager));
fSteppingVerbose = new SteppingVerbose(&fSimulationManager);
G4VSteppingVerbose::SetInstance(fSteppingVerbose);

#ifndef GEANT4_WITHOUT_G4RunManagerFactory
auto runManagerType = G4RunManagerType::Default;
Expand Down Expand Up @@ -544,3 +545,5 @@ void Application::ValidateOutputFile(const string& filename) const {
exit(1);
}
}

Application::~Application() = default;
77 changes: 77 additions & 0 deletions test/src/examples.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,83 @@ TEST(restG4, Example_04_Muons) {
cout << "Number of entries: " << run.GetEntries() << endl;
}

TEST(restG4, MergeFiles) {
// cd into example
const auto originalPath = fs::current_path();
const auto thisExamplePath = examplesPath / "04.MuonScan";
fs::current_path(thisExamplePath);

CommandLineOptions::Options options;
options.rmlFile = "CosmicMuonsFromWall.rml";

// create "merge" directory
auto mergeDirectory = thisExamplePath / "merge";
fs::create_directory(mergeDirectory);
options.nEvents = 1000;

options.outputFile = mergeDirectory / "muons1.root";
{
string command =
"restG4 CosmicMuonsFromWall.rml -n " + to_string(options.nEvents) + " -o " + options.outputFile;
const auto result = system(command.c_str());
EXPECT_EQ(result, 0);
}

options.nEvents = 500;
options.outputFile = mergeDirectory / "muons2.root";
{
string command =
"restG4 CosmicMuonsFromWall.rml -n " + to_string(options.nEvents) + " -o " + options.outputFile;
const auto result = system(command.c_str());
EXPECT_EQ(result, 0);
}

options.nEvents = 200;
options.outputFile = mergeDirectory / "muons3.root";
{
string command =
"restG4 CosmicMuonsFromWall.rml -n " + to_string(options.nEvents) + " -o " + options.outputFile;
const auto result = system(command.c_str());
EXPECT_EQ(result, 0);
}

int nEntries = 0;
{
TRestRun run(mergeDirectory / "muons1.root");
nEntries += run.GetEntries();
}
{
TRestRun run(mergeDirectory / "muons2.root");
nEntries += run.GetEntries();
}
{
TRestRun run(mergeDirectory / "muons3.root");
nEntries += run.GetEntries();
}

cout << "Computed number of entries: " << nEntries << endl;

// run system command to merge files
const auto command =
"root -b -q \"$REST_PATH/macros/geant4/REST_Geant4_MergeRestG4Files.C(\\\"merge.root\\\", \\\"" +
mergeDirectory.string() + "\\\")\"";
cout << "Running command: " << command << endl;
const auto result = system(command.c_str());
EXPECT_EQ(result, 0);

TRestRun run("merge.root");
TRestGeant4Metadata* metadata = (TRestGeant4Metadata*)run.GetMetadataClass("TRestGeant4Metadata");
if (metadata == nullptr) {
cerr << "TRestGeant4Metadata not found!" << endl;
exit(1);
}
cout << "Number of entries: " << run.GetEntries() << endl;
cout << "Number of primaries: " << metadata->GetNumberOfEvents() << endl;

EXPECT_EQ(metadata->GetNumberOfEvents(), 1700);
EXPECT_EQ(run.GetEntries(), nEntries);
}

TEST(restG4, Example_04_Muons_MT) {
// cd into example
const auto originalPath = fs::current_path();
Expand Down