Project
Loading...
Searching...
No Matches
VMCSeederService.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14#include "TVirtualMC.h"
15#include <fairlogger/Logger.h> // for FairLogger
16#include <TRandom.h>
17
18using namespace o2::base;
19
20void VMCSeederService::initSeederFunction(TVirtualMC const* vmc)
21{
22 if (strcmp(vmc->GetName(), "TGeant3TGeo") == 0) {
23 // Geant3 doesn't need anything special in our context
24 mSeederFcn = [](TRandom*) {};
25 } else if (strcmp(vmc->GetName(), "TGeant4") == 0) {
26 // installed by the Geant4 configuration, so that this library does not link against Geant4
27 mSeederFcn = geant4Seeder();
28 if (!mSeederFcn) {
29 LOG(fatal) << "No Geant4 seeding function installed (VMCSeederService::setGeant4Seeder)";
30 }
31 } else {
32 LOG(warn) << "Unknown VMC engine or unimplemented VMC seeding function";
33 mSeederFcn = [](TRandom*) {};
34 }
35}
36
37// constructor
38VMCSeederService::VMCSeederService()
39{
40 auto vmc = TVirtualMC::GetMC();
41 if (vmc) {
42 LOG(info) << "Seeder initializing for " << vmc->GetName();
43 initSeederFunction(vmc);
44 } else {
45 LOG(fatal) << " Seeder could not be initialized (no VMC instance found)";
46 }
47}
48
50{
51 // Make sure the generator is sufficiently well initialized
52 // by calling Rndm() once.
53 // This is ok since in any case r->SetSeed(seed); r->GetSeed() != seed;
54 auto r = simRandom();
55 r->Rndm();
56 mSeederFcn(r);
57 ++mSeedCount;
58}
TRandom * simRandom()
Definition SimRandom.cxx:22
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"