Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-02 07:52:03

0001 # ==========================================================================
0002 #  AIDA Detector description implementation
0003 # --------------------------------------------------------------------------
0004 # Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 # All rights reserved.
0006 #
0007 # For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 # For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 #
0010 # ==========================================================================
0011 #
0012 """
0013    Subtest using CLICSid showing how to setup the random number generator
0014 
0015    @author  M.Frank
0016    @version 1.0
0017 
0018 """
0019 from ROOT import gRandom
0020 
0021 import logging
0022 
0023 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0024 logger = logging.getLogger(__name__)
0025 
0026 if __name__ == "__main__":
0027   import CLICSid
0028   import DDG4
0029   sid = CLICSid.CLICSid()
0030 
0031   logger.info('DEFAULT Engine: %s', DDG4.CLHEP.HepRandom.getTheEngine().name())
0032   # <<-- See this function to know how it's done....
0033   rndm1 = sid.setupRandom('R1', seed=987654321, type='RunluxEngine')
0034   logger.info('R1: %s Default instance: %s', rndm1.name, rndm1.instance().name())
0035   logger.info('   Engine:  %s', rndm1.engine().name())
0036   logger.info('   DEFAULT: %s', DDG4.CLHEP.HepRandom.getTheEngine().name())
0037   rndm1.showStatus()
0038 
0039   rndm2 = sid.setupRandom('R2', seed=1234321, type='MTwistEngine')
0040   logger.info('R2: %s Default instance: %s', rndm2.name, rndm2.instance().name())
0041   logger.info('   Engine:  %s', rndm2.engine().name())
0042   logger.info('   DEFAULT: %s', DDG4.CLHEP.HepRandom.getTheEngine().name())
0043   # rndm2.showStatus()
0044 
0045   DDG4.Geant4Random.setMainInstance(rndm1.get())
0046   rndm1.showStatus()
0047 
0048   # Move main geant random instance from rndm1 to rndm2:
0049   # See how gRandom and HepRandom instances move
0050   DDG4.Geant4Random.setMainInstance(rndm1.get())
0051   logger.info('DEFAULT Engine: %s', DDG4.CLHEP.HepRandom.getTheEngine().name())
0052   logger.info('DDG4   DEFAULT: %s', DDG4.Geant4Random.instance().engine().name())
0053   rndm = DDG4.Geant4Random.instance()
0054 
0055   rndm.setSeed(1234)
0056   rndm.showStatus()
0057   for i in range(10):
0058     logger.info("%s  -- 0 gRandome.Rndm()        -- Shoot random[[%d]= %f", rndm.name(), i, gRandom.Rndm())
0059 
0060   rndm.setSeed(1234)
0061   for i in range(10):
0062     logger.info("%s  -- 1 gRandome.Rndm()        -- Shoot random[[%d]= %f", rndm.name(), i, gRandom.Rndm())
0063 
0064   rndm.setSeed(1234)
0065   for i in range(10):
0066     logger.info("%s  -- 2 Geant4Random(CLHEP)    -- Shoot random[[%d]= %f", rndm.name(), i, rndm.rndm_clhep())
0067 
0068   rndm.setSeed(1234)
0069   for i in range(10):
0070     logger.info("%s  -- 3 Geant4Random(CLHEP)    -- Shoot random[[%d]= %f", rndm.name(), i, rndm.rndm_clhep())
0071 
0072   rndm.setSeed(1234)
0073   for i in range(10):
0074     logger.info("%s  -- 4 HepRandomEngine(CLHEP) -- Shoot random[%d]= %f", rndm.name(), i, rndm.engine().flat())
0075 
0076   sid.test_run(have_geo=False)