Commit 9c514c33 authored by Valentina Fioretti's avatar Valentina Fioretti
Browse files

seed updated

parent 0ff6d48e
Loading
Loading
Loading
Loading
+34 −3
Original line number Diff line number Diff line
@@ -42,6 +42,10 @@
#include "G4GDMLParser.hh"
#include "G4VPhysicalVolume.hh"

#include <ctime>
#include <cstdlib>
#include <stdexcept>

#include <iostream>
using namespace std;

@@ -58,7 +62,7 @@ int main(int argc, char** argv) {
    
    G4String configFile;
    G4String macroFile;
    G4int seed = 0;
    long seed = 0;

    const struct option longopts[] = {
        {"config", required_argument, nullptr, 'c'},
@@ -73,12 +77,15 @@ int main(int argc, char** argv) {
            case 'c':
                configFile = optarg;
                break;

            case 's':
                seed = stol(optarg);
                seed = std::stol(optarg);
                break;

            case 'm':
                macroFile = optarg;
                break;

            default:
                cerr << "Usage: bogemms -c config.conf [-s seed] -m macro.mac" << endl;
                return EXIT_FAILURE;
@@ -100,6 +107,30 @@ int main(int argc, char** argv) {

    G4Random::setTheEngine(new CLHEP::RanecuEngine);
    
    G4int rank = 0;
    if (G4MPImanager::GetManager() != nullptr) {
        rank = G4MPImanager::GetManager()->GetRank();
    }

    const long seed_stride = 1000003L;

    if (seed > 0) {
        long rank_seed = seed + seed_stride * static_cast<long>(rank);
        G4Random::setTheSeed(rank_seed);

        G4cout << "[Rank " << rank << "] Using user base seed: "
               << seed << " -> rank seed: " << rank_seed << G4endl;
    } else {
        long auto_seed =
            static_cast<long>(std::time(nullptr))
            + seed_stride * static_cast<long>(rank);

        G4Random::setTheSeed(auto_seed);

        G4cout << "[Rank " << rank << "] Using automatically generated seed: "
               << auto_seed << G4endl;
    }
    /*
    if (seed > 0) {
        G4Random::setTheSeed(seed);
        cout << "Using user-specified seed: " << seed << endl;
@@ -118,7 +149,7 @@ int main(int argc, char** argv) {
        } else {
            cout << "[Rank " << rank << "] Seed = " << auto_seed << endl;
        }
    }
    }*/

    G4MTRunManager* runManager;