Skip to content

Commit

Permalink
updaye
Browse files Browse the repository at this point in the history
  • Loading branch information
jodafons committed Oct 18, 2023
1 parent c443b06 commit b1a79f6
Show file tree
Hide file tree
Showing 49 changed files with 469 additions and 1,186 deletions.
465 changes: 0 additions & 465 deletions a

This file was deleted.

1 change: 0 additions & 1 deletion core/G4Kernel/python/CaloPhiRange.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from GaugiKernel import Logger
from GaugiKernel.macros import *
from G4Kernel import treatPropertyValue


class CaloPhiRange( Logger ):
Expand Down
16 changes: 9 additions & 7 deletions core/G4Kernel/python/ComponentAccumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
__all__ = ["ComponentAccumulator"]

from GaugiKernel import Cpp
from GaugiKernel.constants import *
from GaugiKernel.macros import *
import os, time, gc

import ROOT

class ComponentAccumulator( Cpp ):

Expand All @@ -17,24 +18,25 @@ def __init__( self, name , detector,
OutputLevel : int=0
):

Cpp.__init__(self, name, "ROOT.RunManager", OutputLevel=OutputLevel)
Cpp.__init__(self, ROOT.RunManager(name) )
# convert python to geant4
self.__detector = detector
self.__detector.compile()
# set the geant detector into the geant
self.__core.setDetectorConstruction( self.__detector.core() )
self._core.setDetectorConstruction( self.__detector.core() )
self.setProperty( "OutputFile" , OutputFile )
self.setProperty( "VisMac" , self.__detector.VisMac )
self.setProperty( "NumberOfThreads" , NumberOfThreads )
self.setProperty( "Timeout" , Timeout )
self.setProperty( "RunVis" , RunVis )
self.setProperty( "Seed" , Seed )
#self.setProperty( "OutputLevel" , OutputLevel )
# Set the vis mac file into the manager core
self.outputFiles = [ (self.OutputFile+".%d"%thread) for thread in range(self.NumberOfThreads)]


def __del__(self):
del self.__core
del self._core
gc.collect()
time.sleep(2)
self.merge()
Expand All @@ -47,14 +49,14 @@ def run( self, evt=None ):
evt = self.__numberOfEvents
elif evt > self.__numberOfEvents:
evt = self.__numberOfEvents
self.__core.run(evt)
self._core.run(evt)


def __add__( self, algs ):
if type(algs) is not list:
algs =[algs]
for alg in algs:
self.__core.push_back( alg.core() )
self._core.push_back( alg.core() )
return self


Expand All @@ -63,7 +65,7 @@ def __add__( self, algs ):
#
def setGenerator( self, gen ):
self.__numberOfEvents = gen.GetEntries()
self.core().setGenerator( gen.core() )
self._core.setGenerator( gen.core() )


#
Expand Down
8 changes: 4 additions & 4 deletions core/G4Kernel/python/DetectorConstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


from GaugiKernel.constants import *
from GaugiKernel import Cpp
from GaugiKernel import Cpp, Logger
from GaugiKernel.macros import *
from GaugiKernel import EnumStringification

Expand All @@ -17,7 +17,7 @@
import numpy as np
import collections


import ROOT

class Plates(EnumStringification):
Horizontal = 0
Expand All @@ -34,7 +34,7 @@ def __init__( self,
UseMagneticField : bool=False,
CutOnPhi : bool=False ):

Cpp.__init__(self, name, "ROOT.DetectorConstruction")
Cpp.__init__(self, ROOT.DetectorConstruction(name) )

self.setProperty( "UseMagneticField", UseMagneticField )
self.setProperty( "CutOnPhi" , CutOnPhi )
Expand Down Expand Up @@ -63,7 +63,7 @@ def __add__(self, pv):
def compile(self):
# Create all volumes inside of the detector
for pv in tqdm( self.__volumes.values(), desc="Compiling...", ncols=70):
self.__core.AddVolume( pv.name(), pv.Plates, pv.AbsorberMaterial, pv.GapMaterial,
self._core.AddVolume( pv.name(), pv.Plates, pv.AbsorberMaterial, pv.GapMaterial,
# layer
pv.NofLayers, pv.AbsorberThickness, pv.GapThickness,
# dimensions
Expand Down
9 changes: 5 additions & 4 deletions core/G4Kernel/python/EventReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from GaugiKernel import Cpp
from GaugiKernel.macros import *
from ROOT import TFile, TTree

import ROOT, os

class EventReader( Cpp ):

Expand All @@ -16,17 +15,19 @@ def __init__( self, name,
OutputLevel : int = 0
):

Cpp.__init__(self, name, "ROOT.generator.EventReader", OutputLevel=OutputLevel)
Cpp.__init__(self, ROOT.generator.EventReader(name) )

self.setProperty( "InputFileName" , InputFileName )
self.setProperty( "OutputEventKey" , OutputEventKey )
self.setProperty( "OutputSeedKey" , OutputSeedKey )
self.setProperty( "OutputTruthKey" , OutputTruthKey )
self.setProperty( "BunchDuration" , BunchDuration )
#self.setProperty( "OutputLevel" , OutputLevel )

if self.InputFileName != "":
if not os.path.exists(self.InputFileName):
MSG_FATAL(self, f"Input file not found into the system: {self.InputFileName}")
f = TFile( InputFileName )
f = ROOT.TFile( InputFileName )
t = f.Get("particles")
self.__entries = t.GetEntries()
f.Close()
Expand Down
1 change: 0 additions & 1 deletion core/GaugiKernel/python/ComponentAccumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def __init__(self, name, output, detector=None ):
from ROOT import RunManager
from ROOT import Gaugi as GK
self.__acc = GK.ComponentAccumulator( name )

from ROOT import SG
self.__ctx = SG.EventContext("EventContext")
self.__store = SG.StoreGate(output)
Expand Down
21 changes: 8 additions & 13 deletions core/GaugiKernel/python/Cpp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
__all__ = ["CaloCellMerge", "treatPropertyValue"]
__all__ = ["Cpp", "treatPropertyValue"]

from GaugiKernel import Logger
from GaugiKernel.macros import *
from GaugiKernel import list2stdvector

import importlib



def treatPropertyValue( value ):
Expand All @@ -31,25 +29,22 @@ def treatPropertyValue( value ):

class Cpp( Logger ):

def __init__( self, name : str, import_path : str, OutputLevel : int=0 ):

def __init__( self, core ):
Logger.__init__(self)
import ROOT
ROOT.gSystem.Load('liblorenzetti')
from ROOT import CaloCellMerge
cpp = importlib.import_module(import_path)
self.__core = cpp(name)
self._core = core

def __del__(self):
del self._core

def core(self):
return self.__core
return self._core


def setProperty( self, key, value ):
if self.__core.hasProperty(key):
if self._core.hasProperty(key):
setattr( self, key , value )
try:
self.__core.setProperty( key, treatPropertyValue(value) )
self._core.setProperty( key, treatPropertyValue(value) )
except:
MSG_FATAL( self, f"Exception in property with name {key} and value: {value}")
else:
Expand Down
5 changes: 5 additions & 0 deletions core/GaugiKernel/python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
__all__ = []

import ROOT
ROOT.gSystem.Load('liblorenzetti')
from ROOT import RunManager


from . import utils
__all__.extend(utils.__all__)
from .utils import *
Expand Down
4 changes: 3 additions & 1 deletion events/TruthParticle/src/LinkDef.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "TruthParticle/TruthParticleConverter.h"


#ifdef __CINT__
Expand All @@ -6,6 +7,7 @@
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclass;

#pragma link C++ struct xAOD::TruthParticle_t+;
#pragma link C++ class std::vector< xAOD::TruthParticle_t >+;

#endif
52 changes: 14 additions & 38 deletions generator/evtgen/python/Pythia8.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,21 @@
__all__ = ["Pythia8"]

from GaugiKernel import Logger
from GaugiKernel import Cpp
from GaugiKernel.macros import *
from G4Kernel import treatPropertyValue
from ROOT import generator


class Pythia8( Logger ):
class Pythia8( Cpp ):

__allow_keys = [
"File",
"Seed",
"OutputLevel",
"EventNumber",
]

def __init__( self, name, **kw ):
def __init__( self, name,
File : str="",
Seed : int=512,
OutputLevel : int=0,
EventNumber : int=-1,
):

Logger.__init__(self)
import ROOT
ROOT.gSystem.Load('liblorenzetti')
from ROOT import generator
# Create the algorithm
self.__core = generator.Pythia8Gen()
for key, value in kw.items():
self.setProperty( key,value )


def core(self):
return self.__core


def setProperty( self, key, value ):
if key in self.__allow_keys:
setattr( self, '__' + key , value )
self.core().setProperty( key, treatPropertyValue(value) )
else:
MSG_FATAL( self, "Property with name %s is not allow for %s object", key, self.__class__.__name__)


def getProperty( self, key ):
if key in self.__allow_keys:
return getattr( self, '__' + key )
else:
MSG_FATAL( self, "Property with name %s is not allow for %s object", key, self.__class__.__name__)
Cpp.__init__(self, generator.Pythia8Gen())
self.setProperty( "Seed" , Seed )
self.setProperty( "EventNumber" , EventNumber )
#self.setProperty( "OutputLevel" , OutputLevel )
self.setProperty( "File" , File )
48 changes: 12 additions & 36 deletions generator/evtgen/python/hepmc3/RootReader.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
__all__ = ["P8Gun"]

from GaugiKernel import Logger
from GaugiKernel import Cpp
from GaugiKernel.macros import *
from G4Kernel import treatPropertyValue
from ROOT import generator


class P8Gun( Logger ):
class P8Gun( Cpp ):

__allow_keys = [
"File",
"Seed",
"OutputLevel",
]
def __init__( self, name,
File : str="",
Seed : int=512,
OutputLevel : int=0
):

def __init__( self, name, **kw ):

Logger.__init__(self)
import ROOT
ROOT.gSystem.Load('liblorenzetti')
from ROOT import generator
# Create the algorithm
self.__core = generator.P8Gun()
for key, value in kw.items():
self.setProperty( key,value )
Cpp.__init__(self, generator.P8Gun())
self.setProperty( "File" , File )
self.setProperty( "Seed" , Seed )
self.setProperty( "OutputLevel" , OutputLevel )


def core(self):
return self.__core


def setProperty( self, key, value ):
if key in self.__allow_keys:
setattr( self, '__' + key , value )
self.core().setProperty( key, treatPropertyValue(value) )
else:
MSG_FATAL( self, "Property with name %s is not allow for %s object", key, self.__class__.__name__)


def getProperty( self, key ):
if key in self.__allow_keys:
return getattr( self, '__' + key )
else:
MSG_FATAL( self, "Property with name %s is not allow for %s object", key, self.__class__.__name__)
Loading

0 comments on commit b1a79f6

Please sign in to comment.