diff --git a/DDG4/examples/CLICSidSimuMarkus.py b/DDG4/examples/CLICSidSimuMarkus.py index 750bca4481ffec21cbff74a211ee6c29ffd630a0..9ca55c861bbd9c8df3c4fc2913e2980986881945 100644 --- a/DDG4/examples/CLICSidSimuMarkus.py +++ b/DDG4/examples/CLICSidSimuMarkus.py @@ -34,21 +34,17 @@ def run(): # Configure Event actions prt = DDG4.EventAction(kernel,'Geant4ParticlePrint/ParticlePrint') - prt.OutputLevel = Output.DEBUG + prt.OutputLevel = Output.WARNING prt.OutputType = 3 # Print both: table and tree kernel.eventAction().adopt(prt) - generator_output_level = Output.DEBUG + generator_output_level = Output.WARNING # Configure I/O ##evt_lcio = simple.setupLCIOOutput('LcioOutput','CLICSiD_'+time.strftime('%Y-%m-%d_%H-%M')) ##evt_lcio.OutputLevel = generator_output_level 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 """ Generation of primary particles from LCIO input files @@ -67,25 +63,12 @@ def run(): #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/geantinos.slcio" - - gen.OutputLevel = generator_output_level gen.MomentumScale = 1.0 gen.Mask = 1 - gen.enableUI() - kernel.generatorAction().adopt(gen) + simple.buildInputStage([gen],output_level=generator_output_level) #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - # Merge all existing interaction records - 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) + #gen = simple.setupGun("Gun",particle='pi+',energy=20*GeV,position=(0.15*mm,0.12*mm,50*cm)) + #gen.OutputLevel = generator_output_level # And handle the simulation particles. part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler") @@ -111,7 +94,7 @@ def run(): kernel.generatorAction().adopt(rdr) """ - seq,act = simple.setupTracker('SiVertexBarrel') + seq,act = simple.setupTracker('SiTrackerBarrel') """ # First the tracking detectors seq,act = simple.setupTracker('SiVertexBarrel') diff --git a/DDG4/include/DDG4/Geant4Output2ROOT.h b/DDG4/include/DDG4/Geant4Output2ROOT.h index 840e51d60d9e0a61f9ef994d6f6b13331d43c87e..e233f7aa87f3d373edb5a5d3a77f0426dfd4af0c 100644 --- a/DDG4/include/DDG4/Geant4Output2ROOT.h +++ b/DDG4/include/DDG4/Geant4Output2ROOT.h @@ -44,6 +44,8 @@ namespace DD4hep { TFile* m_file; /// Reference to the event data tree TTree* m_tree; + /// Flag if Monte-Carlo truth should be followed and checked + bool m_handleMCTruth; public: /// Standard constructor Geant4Output2ROOT(Geant4Context* context, const std::string& nam); diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index c30437a3a7dfde3c534efe184cff98f3cea71b60..5f606ad060d198478a9e8e1e6050cd82e2bd3cd8 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -229,16 +229,26 @@ I am sick of typing the same over and over again. """ class Simple: - def __init__(self, kernel,calo='Geant4CalorimeterAction',tracker='Geant4SimpleTrackerAction'): + def __init__(self, kernel=None,calo='Geant4CalorimeterAction',tracker='Geant4SimpleTrackerAction'): kernel.UI = "UI" kernel.printProperties() self.kernel = kernel + if kernel is None: + self.kernel = Kernel() self.lcdd = self.kernel.lcdd() self.calo = calo self.tracker = tracker self.sensitive_types = {} self.sensitive_types['tracker'] = self.tracker 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): print '+++ List of sensitive detectors:' for i in self.lcdd.detectors(): @@ -246,7 +256,9 @@ class Simple: sd = self.lcdd.sensitiveDetector(o.name()) if sd.isValid(): 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,) def setupDetector(self,name,sensitive_type): @@ -299,8 +311,9 @@ class Simple: def setupCshUI(self,typ='csh',vis=False,ui=True,macro=None): 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.HandleMCTruth = mc_truth evt_root.Control = True evt_root.Output = output+'.root' evt_root.enableUI() @@ -342,3 +355,5 @@ class Simple: gen.OutputLevel = output_level ga.adopt(gen) return self + +Geant4 = Simple diff --git a/DDG4/src/Geant4Output2ROOT.cpp b/DDG4/src/Geant4Output2ROOT.cpp index dc44761191df2ae57d1d098a4eed4324a3b80f9d..5bcc98f0bd1dcda228880144231a0548c5fb2e74 100644 --- a/DDG4/src/Geant4Output2ROOT.cpp +++ b/DDG4/src/Geant4Output2ROOT.cpp @@ -31,6 +31,7 @@ using namespace std; Geant4Output2ROOT::Geant4Output2ROOT(Geant4Context* context, const string& nam) : Geant4OutputAction(context, nam), m_file(0), m_tree(0) { declareProperty("Section", m_section = "EVENT"); + declareProperty("HandleMCTruth", m_handleMCTruth = true); InstanceCount::increment(this); } @@ -158,7 +159,7 @@ void Geant4Output2ROOT::saveCollection(OutputContext<G4Event>& /* ctxt */, G4VHi coll->getHitsUnchecked(hits); size_t nhits = coll->GetSize(); Geant4ParticleMap* truth = context()->event().extension<Geant4ParticleMap>(); - if ( truth && nhits > 0 ) { + if ( m_handleMCTruth && truth && nhits > 0 ) { try { for(size_t i=0; i<nhits; ++i) { Geant4HitData* h = coll->hit(i);