Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-25 09:20:18

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 __future__ import absolute_import, unicode_literals
0020 from ROOT import gRandom
0021 
0022 import logging
0023 
0024 logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
0025 logger = logging.getLogger(__name__)
0026 
0027 if __name__ == "__main__":
0028   import CLICSid
0029   import DDG4
0030   sid = CLICSid.CLICSid()
0031 
0032   logger.info('DEFAULT Engine: %s', DDG4.CLHEP.HepRandom.getTheEngine().name())
0033   # <<-- See this function to know how it's done....
0034   rndm1 = sid.setupRandom('R1', seed=987654321, type='RunluxEngine')
0035   logger.info('R1: %s Default instance: %s', rndm1.name, rndm1.instance().name())
0036   logger.info('   Engine:  %s', rndm1.engine().name())
0037   logger.info('   DEFAULT: %s', DDG4.CLHEP.HepRandom.getTheEngine().name())
0038   rndm1.showStatus()
0039 
0040   rndm2 = sid.setupRandom('R2', seed=1234321, type='MTwistEngine')
0041   logger.info('R2: %s Default instance: %s', rndm2.name, rndm2.instance().name())
0042   logger.info('   Engine:  %s', rndm2.engine().name())
0043   logger.info('   DEFAULT: %s', DDG4.CLHEP.HepRandom.getTheEngine().name())
0044   # rndm2.showStatus()
0045 
0046   DDG4.Geant4Random.setMainInstance(rndm1.get())
0047   rndm1.showStatus()
0048 
0049   # Move main geant random instance from rndm1 to rndm2:
0050   # See how gRandom and HepRandom instances move
0051   DDG4.Geant4Random.setMainInstance(rndm1.get())
0052   logger.info('DEFAULT Engine: %s', DDG4.CLHEP.HepRandom.getTheEngine().name())
0053   logger.info('DDG4   DEFAULT: %s', DDG4.Geant4Random.instance().engine().name())
0054   rndm = DDG4.Geant4Random.instance()
0055 
0056   rndm.setSeed(1234)
0057   rndm.showStatus()
0058   for i in range(10):
0059     logger.info("%s  -- 0 gRandome.Rndm()        -- Shoot random[[%d]= %f", rndm.name(), i, gRandom.Rndm())
0060 
0061   rndm.setSeed(1234)
0062   for i in range(10):
0063     logger.info("%s  -- 1 gRandome.Rndm()        -- Shoot random[[%d]= %f", rndm.name(), i, gRandom.Rndm())
0064 
0065   rndm.setSeed(1234)
0066   for i in range(10):
0067     logger.info("%s  -- 2 Geant4Random(CLHEP)    -- Shoot random[[%d]= %f", rndm.name(), i, rndm.rndm_clhep())
0068 
0069   rndm.setSeed(1234)
0070   for i in range(10):
0071     logger.info("%s  -- 3 Geant4Random(CLHEP)    -- Shoot random[[%d]= %f", rndm.name(), i, rndm.rndm_clhep())
0072 
0073   rndm.setSeed(1234)
0074   for i in range(10):
0075     logger.info("%s  -- 4 HepRandomEngine(CLHEP) -- Shoot random[%d]= %f", rndm.name(), i, rndm.engine().flat())
0076 
0077   sid.test_run(have_geo=False)