diff --git a/DDG4/examples/CLICSidSimu.py b/DDG4/examples/CLICSidSimu.py index 6f0f15856b7ffa3566c7f7adbbd965e3bd5cfe7f..497fc845dd26bfd874707fd6d0d753f07cc4ca98 100644 --- a/DDG4/examples/CLICSidSimu.py +++ b/DDG4/examples/CLICSidSimu.py @@ -72,15 +72,13 @@ def run(): mc.release() """ # Configure I/O - """ evt_root = DDG4.EventAction(kernel,'Geant4Output2ROOT/RootOutput') evt_root.Control = True evt_root.Output = "CLICSiD_"+time.strftime("%Y-%m-%d_%H-%M")+".root" evt_root.enableUI() kernel.eventAction().add(evt_root) - """ + evt_lcio = DDG4.EventAction(kernel,'Geant4Output2LCIO/LcioOutput') - evt_lcio.Control = True evt_lcio.Output = "CLICSiD_"+time.strftime("%Y-%m-%d_%H-%M") evt_lcio.enableUI() kernel.eventAction().add(evt_lcio) @@ -123,31 +121,31 @@ def run(): # First the tracking detectors seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiVertexBarrel') - act = DDG4.SensitiveAction(kernel,'LcioTestTrackerAction/SiVertexBarrelHandler','SiVertexBarrel') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiVertexBarrelHandler','SiVertexBarrel') seq.add(act) seq.add(f1) #seq.add(f4) act.add(f1) seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiVertexEndcap') - act = DDG4.SensitiveAction(kernel,'LcioTestTrackerAction/SiVertexEndcapHandler','SiVertexEndcap') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiVertexEndcapHandler','SiVertexEndcap') seq.add(act) seq.add(f1) #seq.add(f4) seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerBarrel') - act = DDG4.SensitiveAction(kernel,'LcioTestTrackerAction/SiTrackerBarrelHandler','SiTrackerBarrel') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerBarrelHandler','SiTrackerBarrel') seq.add(act) seq.add(f1) #seq.add(f4) seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerEndcap') - act = DDG4.SensitiveAction(kernel,'LcioTestTrackerAction/SiTrackerEndcapHandler','SiTrackerEndcap') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerEndcapHandler','SiTrackerEndcap') #act.OutputLevel = Output.INFO seq.add(act) seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerForward') - act = DDG4.SensitiveAction(kernel,'LcioTestTrackerAction/SiTrackerForwardHandler','SiTrackerForward') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerForwardHandler','SiTrackerForward') seq.add(act) # Now the calorimeters diff --git a/DDG4/examples/CLICSidSimuLCIO.py b/DDG4/examples/CLICSidSimuLCIO.py new file mode 100644 index 0000000000000000000000000000000000000000..1d4f6bc6254150d67e0a681409a41a291403a91a --- /dev/null +++ b/DDG4/examples/CLICSidSimuLCIO.py @@ -0,0 +1,213 @@ +# +# +import os, time, DDG4 +from DDG4 import OutputLevel as Output +from SystemOfUnits import * +# +# +""" + + DD4hep example setup using the python configuration + + @author M.Frank + @version 1.0 + +""" +def run(): + install_dir = os.environ['DD4hepINSTALL'] + example_dir = install_dir+'/examples/DDG4/examples'; + kernel = DDG4.Kernel() + kernel.UI = "UI" + kernel.loadGeometry("file:"+install_dir+"/examples/CLICSiD/compact/compact.xml") + kernel.loadXML("file:"+example_dir+"/DDG4_field.xml") + + lcdd = kernel.lcdd() + print '+++ List of sensitive detectors:' + for i in lcdd.detectors(): + o = DDG4.DetElement(i.second) + sd = lcdd.sensitiveDetector(o.name()) + if sd.isValid(): + print '+++ %-32s type:%s'%(o.name(), sd.type(), ) + + # Configure UI + ui = DDG4.Action(kernel,"Geant4UIManager/UI") + ui.HaveVIS = True + ui.HaveUI = True + ui.SessionType = 'csh' + kernel.registerGlobalAction(ui) + + + # Configure Run actions + run1 = DDG4.RunAction(kernel,'Geant4TestRunAction/RunInit') + run1.Property_int = 12345 + run1.Property_double = -5e15*keV + run1.Property_string = 'Startrun: Hello_2' + print run1.Property_string, run1.Property_double, run1.Property_int + run1.enableUI() + kernel.registerGlobalAction(run1) + kernel.runAction().add(run1) + + # Configure Event actions + evt2 = DDG4.EventAction(kernel,'Geant4TestEventAction/UserEvent_2') + evt2.Property_int = 123454321 + evt2.Property_double = 5e15*GeV + evt2.Property_string = 'Hello_2 from the python setup' + evt2.enableUI() + kernel.registerGlobalAction(evt2) + + evt1 = DDG4.EventAction(kernel,'Geant4TestEventAction/UserEvent_1') + evt1.Property_int=01234 + evt1.Property_double=1e11 + evt1.Property_string='Hello_1' + evt1.enableUI() + + kernel.eventAction().add(evt1) + kernel.eventAction().add(evt2) + """ + trk = DDG4.Action(kernel,"Geant4TrackPersistency/MonteCarloTruthHandler") + kernel.registerGlobalAction(trk) + trk.release() + mc = DDG4.Action(kernel,"Geant4MonteCarloRecordManager/MonteCarloRecordManager") + kernel.registerGlobalAction(mc) + mc.release() + """ + # Configure I/O + evt_lcio = DDG4.EventAction(kernel,'Geant4Output2LCIO/LcioOutput') + evt_lcio.Control = True + evt_lcio.Output = "CLICSiD_"+time.strftime("%Y-%m-%d_%H-%M") + evt_lcio.enableUI() + kernel.eventAction().add(evt_lcio) + + gen = DDG4.GeneratorAction(kernel,"Geant4TestGeneratorAction/Generate") + kernel.generatorAction().add(gen) + + # Setup particle gun + gun = DDG4.GeneratorAction(kernel,"Geant4ParticleGun/Gun") + gun.energy = 100*GeV + gun.particle = 'pi-' + gun.multiplicity = 1 + gun.position = (0*mm,0*mm,0*cm) + gun.isotrop = True + gun.enableUI() + kernel.generatorAction().add(gun) + """ + rdr = DDG4.GeneratorAction(kernel,"LcioGeneratorAction/Reader") + rdr.zSpread = 0.0 + rdr.lorentzAngle = 0.0 + rdr.OutputLevel = DDG4.OutputLevel.INFO + rdr.Input = "LcioEventReader|test.data" + rdr.enableUI() + kernel.generatorAction().add(rdr) + """ + + # Setup global filters fur use in sensntive detectors + f1 = DDG4.Filter(kernel,'GeantinoRejectFilter/GeantinoRejector') + f2 = DDG4.Filter(kernel,'ParticleRejectFilter/OpticalPhotonRejector') + f2.particle = 'opticalphoton' + f3 = DDG4.Filter(kernel,'ParticleSelectFilter/OpticalPhotonSelector') + f3.particle = 'opticalphoton' + f4 = DDG4.Filter(kernel,'EnergyDepositMinimumCut') + f4.Cut = 10*MeV + f4.enableUI() + kernel.registerGlobalFilter(f1) + kernel.registerGlobalFilter(f2) + kernel.registerGlobalFilter(f3) + kernel.registerGlobalFilter(f4) + + # First the tracking detectors + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiVertexBarrel') + act = DDG4.SensitiveAction(kernel,'LcioTestTrackerAction/SiVertexBarrelHandler','SiVertexBarrel') + seq.add(act) + seq.add(f1) + #seq.add(f4) + act.add(f1) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiVertexEndcap') + act = DDG4.SensitiveAction(kernel,'LcioTestTrackerAction/SiVertexEndcapHandler','SiVertexEndcap') + seq.add(act) + seq.add(f1) + #seq.add(f4) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerBarrel') + act = DDG4.SensitiveAction(kernel,'LcioTestTrackerAction/SiTrackerBarrelHandler','SiTrackerBarrel') + seq.add(act) + seq.add(f1) + #seq.add(f4) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerEndcap') + act = DDG4.SensitiveAction(kernel,'LcioTestTrackerAction/SiTrackerEndcapHandler','SiTrackerEndcap') + #act.OutputLevel = Output.INFO + seq.add(act) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerForward') + act = DDG4.SensitiveAction(kernel,'LcioTestTrackerAction/SiTrackerForwardHandler','SiTrackerForward') + seq.add(act) + + # Now the calorimeters + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/EcalBarrel') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/EcalBarrelHandler','EcalBarrel') + seq.add(act) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/EcalEndcap') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/EcalEndCapHandler','EcalEndcap') + seq.add(act) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/HcalBarrel') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalBarrelHandler','HcalBarrel') + act.adoptFilter(kernel.globalFilter('OpticalPhotonRejector')) + seq.add(act) + + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalBarrelHandler','HcalBarrel') + act.adoptFilter(kernel.globalFilter('OpticalPhotonSelector')) + seq.add(act) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/HcalEndcap') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalEndcapHandler','HcalEndcap') + seq.add(act) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/HcalPlug') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalPlugHandler','HcalPlug') + seq.add(act) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/MuonBarrel') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/MuonBarrelHandler','MuonBarrel') + seq.add(act) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/MuonEndcap') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/MuonEndcapHandler','MuonEndcap') + seq.add(act) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/LumiCal') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/LumiCalHandler','LumiCal') + seq.add(act) + + seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/BeamCal') + act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/BeamCalHandler','BeamCal') + seq.add(act) + + # Now build the physics list: + phys = kernel.physicsList() + phys.extends = 'FTFP_BERT' + #phys.transportation = True + phys.decays = True + phys.enableUI() + + ph = DDG4.PhysicsList(kernel,'Geant4PhysicsList/Myphysics') + ph.addParticleConstructor('G4BosonConstructor') + ph.addParticleConstructor('G4LeptonConstructor') + ph.addParticleProcess('e[+-]','G4eMultipleScattering',-1,1,1) + ph.addPhysicsConstructor('G4OpticalPhysics') + ph.enableUI() + phys.add(ph) + + phys.dump() + + kernel.configure() + kernel.initialize() + + #DDG4.setPrintLevel(Output.DEBUG) + kernel.run() + kernel.terminate() + +if __name__ == "__main__": + run() diff --git a/DDG4/lcio/Geant4Output2LCIO.cpp b/DDG4/lcio/Geant4Output2LCIO.cpp index 0cfa405e6af2287e815fd19a4a8bf29d046675bf..bba5ffdecab52708982578d24fbc25f6d9ade35b 100644 --- a/DDG4/lcio/Geant4Output2LCIO.cpp +++ b/DDG4/lcio/Geant4Output2LCIO.cpp @@ -136,7 +136,7 @@ void Geant4Output2LCIO::endRun(const G4Run* ) { } /// Commit data at end of filling procedure -void Geant4Output2LCIO::commit( OutputContext<G4Event>& ctxt) { +void Geant4Output2LCIO::commit( OutputContext<G4Event>& /* ctxt */) { lcio::LCEventImpl* e = context()->event().extension<lcio::LCEventImpl>(); m_file->writeEvent(e); // std::cout << " ########### Geant4Output2LCIO::commit() : writing LCIO event to file .... " << std::endl ; @@ -152,20 +152,9 @@ void Geant4Output2LCIO::saveRun(const G4Run* run) { } -void Geant4Output2LCIO::begin(const G4Event* event){ - +void Geant4Output2LCIO::begin(const G4Event* /* event */) { lcio::LCEventImpl* e = new lcio::LCEventImpl; - - //fg: fixme: should be this call taking ownership of the LCEvent - // deleting it at the end - however does not seem to work - // see fixme in Geant4Output2LCIO::saveCollection() below -//#define debug_memory_handling -#ifdef debug_memory_handling - context()->event().addExtension<lcio::LCEventImpl>( e , 1 ); -#else - context()->event().addExtension<lcio::LCEventImpl>( e , 0 ); -#endif - + context()->event().addExtension<lcio::LCEventImpl>( e ); } @@ -180,22 +169,15 @@ void Geant4Output2LCIO::saveEvent(OutputContext<G4Event>& ctxt) { } /// Callback to store each Geant4 hit collection -void Geant4Output2LCIO::saveCollection(OutputContext<G4Event>& ctxt, G4VHitsCollection* collection) { +void Geant4Output2LCIO::saveCollection(OutputContext<G4Event>& /* ctxt */, G4VHitsCollection* collection) { size_t nhits = collection->GetSize(); std::string hc_nam = collection->GetName(); if ( nhits > 0 ) { - typedef pair<Geometry::VolumeManager,G4VHitsCollection*> _A; - typedef Geant4Conversion<lcio::LCCollectionVec,_A> _C; + typedef pair<Geometry::VolumeManager,G4VHitsCollection*> _Args; + typedef Geant4Conversion<lcio::LCCollectionVec,_Args> _C; const _C& cnv = _C::converter(typeid(Geant4HitCollection)); lcio::LCEventImpl* evt = context()->event().extension<lcio::LCEventImpl>(); - lcio::LCCollectionVec* col = cnv(_A(m_volMgr,collection)); + lcio::LCCollectionVec* col = cnv(_Args(m_volMgr,collection)); evt->addCollection(col,hc_nam); } -#ifdef debug_memory_handling - //fg: fixme: for the memory handling with LCIO we need to take away the ownership from - // the Geant4HitCollection - however this creates a seg fault at the end of event... - Geant4HitCollection* g4hcol = (Geant4HitCollection* ) collection ; - std::vector<void*> v ; - g4hcol->releaseHitsUnchecked(v) ; -#endif }