Skip to content
Snippets Groups Projects
Commit 564cad51 authored by Markus Frank's avatar Markus Frank
Browse files

Improve configurability

parent aae1b3a1
No related branches found
No related tags found
No related merge requests found
...@@ -34,21 +34,17 @@ def run(): ...@@ -34,21 +34,17 @@ def run():
# Configure Event actions # Configure Event actions
prt = DDG4.EventAction(kernel,'Geant4ParticlePrint/ParticlePrint') prt = DDG4.EventAction(kernel,'Geant4ParticlePrint/ParticlePrint')
prt.OutputLevel = Output.DEBUG prt.OutputLevel = Output.WARNING
prt.OutputType = 3 # Print both: table and tree prt.OutputType = 3 # Print both: table and tree
kernel.eventAction().adopt(prt) kernel.eventAction().adopt(prt)
generator_output_level = Output.DEBUG generator_output_level = Output.WARNING
# Configure I/O # Configure I/O
##evt_lcio = simple.setupLCIOOutput('LcioOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M')) ##evt_lcio = simple.setupLCIOOutput('LcioOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M'))
##evt_lcio.OutputLevel = generator_output_level ##evt_lcio.OutputLevel = generator_output_level
evt_root = simple.setupROOTOutput('RootOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M')) evt_root = simple.setupROOTOutput('RootOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M'))
gen = DDG4.GeneratorAction(kernel,"Geant4GeneratorActionInit/GenerationInit")
gen.OutputLevel = generator_output_level
kernel.generatorAction().adopt(gen)
#VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV #VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
""" """
Generation of primary particles from LCIO input files Generation of primary particles from LCIO input files
...@@ -67,25 +63,12 @@ def run(): ...@@ -67,25 +63,12 @@ def run():
#gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/sherpa-2.1.1_zjets.hepmc2g" #gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/sherpa-2.1.1_zjets.hepmc2g"
gen.Input = "LCIOFileReader|/afs/cern.ch/user/n/nikiforo/public/Markus/muons.slcio" gen.Input = "LCIOFileReader|/afs/cern.ch/user/n/nikiforo/public/Markus/muons.slcio"
#gen.Input = "LCIOFileReader|/afs/cern.ch/user/n/nikiforo/public/Markus/geantinos.slcio" #gen.Input = "LCIOFileReader|/afs/cern.ch/user/n/nikiforo/public/Markus/geantinos.slcio"
gen.OutputLevel = generator_output_level
gen.MomentumScale = 1.0 gen.MomentumScale = 1.0
gen.Mask = 1 gen.Mask = 1
gen.enableUI() simple.buildInputStage([gen],output_level=generator_output_level)
kernel.generatorAction().adopt(gen)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#gen = simple.setupGun("Gun",particle='pi+',energy=20*GeV,position=(0.15*mm,0.12*mm,50*cm))
# Merge all existing interaction records #gen.OutputLevel = generator_output_level
gen = DDG4.GeneratorAction(kernel,"Geant4InteractionMerger/InteractionMerger")
gen.OutputLevel = generator_output_level
gen.enableUI()
kernel.generatorAction().adopt(gen)
# Finally generate Geant4 primaries
gen = DDG4.GeneratorAction(kernel,"Geant4PrimaryHandler/PrimaryHandler")
gen.OutputLevel = generator_output_level
gen.enableUI()
kernel.generatorAction().adopt(gen)
# And handle the simulation particles. # And handle the simulation particles.
part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler") part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler")
...@@ -111,7 +94,7 @@ def run(): ...@@ -111,7 +94,7 @@ def run():
kernel.generatorAction().adopt(rdr) kernel.generatorAction().adopt(rdr)
""" """
seq,act = simple.setupTracker('SiVertexBarrel') seq,act = simple.setupTracker('SiTrackerBarrel')
""" """
# First the tracking detectors # First the tracking detectors
seq,act = simple.setupTracker('SiVertexBarrel') seq,act = simple.setupTracker('SiVertexBarrel')
......
...@@ -44,6 +44,8 @@ namespace DD4hep { ...@@ -44,6 +44,8 @@ namespace DD4hep {
TFile* m_file; TFile* m_file;
/// Reference to the event data tree /// Reference to the event data tree
TTree* m_tree; TTree* m_tree;
/// Flag if Monte-Carlo truth should be followed and checked
bool m_handleMCTruth;
public: public:
/// Standard constructor /// Standard constructor
Geant4Output2ROOT(Geant4Context* context, const std::string& nam); Geant4Output2ROOT(Geant4Context* context, const std::string& nam);
......
...@@ -229,16 +229,26 @@ I am sick of typing the same over and over again. ...@@ -229,16 +229,26 @@ I am sick of typing the same over and over again.
""" """
class Simple: class Simple:
def __init__(self, kernel,calo='Geant4CalorimeterAction',tracker='Geant4SimpleTrackerAction'): def __init__(self, kernel=None,calo='Geant4CalorimeterAction',tracker='Geant4SimpleTrackerAction'):
kernel.UI = "UI" kernel.UI = "UI"
kernel.printProperties() kernel.printProperties()
self.kernel = kernel self.kernel = kernel
if kernel is None:
self.kernel = Kernel()
self.lcdd = self.kernel.lcdd() self.lcdd = self.kernel.lcdd()
self.calo = calo self.calo = calo
self.tracker = tracker self.tracker = tracker
self.sensitive_types = {} self.sensitive_types = {}
self.sensitive_types['tracker'] = self.tracker self.sensitive_types['tracker'] = self.tracker
self.sensitive_types['calorimeter'] = self.calo self.sensitive_types['calorimeter'] = self.calo
def execute(self):
self.kernel.configure()
self.kernel.initialize()
self.kernel.run()
self.kernel.terminate()
return self
def printDetectors(self): def printDetectors(self):
print '+++ List of sensitive detectors:' print '+++ List of sensitive detectors:'
for i in self.lcdd.detectors(): for i in self.lcdd.detectors():
...@@ -246,7 +256,9 @@ class Simple: ...@@ -246,7 +256,9 @@ class Simple:
sd = self.lcdd.sensitiveDetector(o.name()) sd = self.lcdd.sensitiveDetector(o.name())
if sd.isValid(): if sd.isValid():
typ = sd.type() typ = sd.type()
sdtyp = self.sensitive_types[typ] sdtyp = 'Unknown'
if self.sensitive_types.has_key(typ):
sdtyp = self.sensitive_types[typ]
print '+++ %-32s type:%-12s --> Sensitive type: %s'%(o.name(), typ, sdtyp,) print '+++ %-32s type:%-12s --> Sensitive type: %s'%(o.name(), typ, sdtyp,)
def setupDetector(self,name,sensitive_type): def setupDetector(self,name,sensitive_type):
...@@ -299,8 +311,9 @@ class Simple: ...@@ -299,8 +311,9 @@ class Simple:
def setupCshUI(self,typ='csh',vis=False,ui=True,macro=None): def setupCshUI(self,typ='csh',vis=False,ui=True,macro=None):
self.setupUI(typ='csh',vis=vis,ui=ui,macro=macro) self.setupUI(typ='csh',vis=vis,ui=ui,macro=macro)
def setupROOTOutput(self,name,output): def setupROOTOutput(self,name,output,mc_truth=True):
evt_root = EventAction(self.kernel,'Geant4Output2ROOT/'+name) evt_root = EventAction(self.kernel,'Geant4Output2ROOT/'+name)
evt_root.HandleMCTruth = mc_truth
evt_root.Control = True evt_root.Control = True
evt_root.Output = output+'.root' evt_root.Output = output+'.root'
evt_root.enableUI() evt_root.enableUI()
...@@ -342,3 +355,5 @@ class Simple: ...@@ -342,3 +355,5 @@ class Simple:
gen.OutputLevel = output_level gen.OutputLevel = output_level
ga.adopt(gen) ga.adopt(gen)
return self return self
Geant4 = Simple
...@@ -31,6 +31,7 @@ using namespace std; ...@@ -31,6 +31,7 @@ using namespace std;
Geant4Output2ROOT::Geant4Output2ROOT(Geant4Context* context, const string& nam) Geant4Output2ROOT::Geant4Output2ROOT(Geant4Context* context, const string& nam)
: Geant4OutputAction(context, nam), m_file(0), m_tree(0) { : Geant4OutputAction(context, nam), m_file(0), m_tree(0) {
declareProperty("Section", m_section = "EVENT"); declareProperty("Section", m_section = "EVENT");
declareProperty("HandleMCTruth", m_handleMCTruth = true);
InstanceCount::increment(this); InstanceCount::increment(this);
} }
...@@ -158,7 +159,7 @@ void Geant4Output2ROOT::saveCollection(OutputContext<G4Event>& /* ctxt */, G4VHi ...@@ -158,7 +159,7 @@ void Geant4Output2ROOT::saveCollection(OutputContext<G4Event>& /* ctxt */, G4VHi
coll->getHitsUnchecked(hits); coll->getHitsUnchecked(hits);
size_t nhits = coll->GetSize(); size_t nhits = coll->GetSize();
Geant4ParticleMap* truth = context()->event().extension<Geant4ParticleMap>(); Geant4ParticleMap* truth = context()->event().extension<Geant4ParticleMap>();
if ( truth && nhits > 0 ) { if ( m_handleMCTruth && truth && nhits > 0 ) {
try { try {
for(size_t i=0; i<nhits; ++i) { for(size_t i=0; i<nhits; ++i) {
Geant4HitData* h = coll->hit(i); Geant4HitData* h = coll->hit(i);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment