Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-02 08:02:48

0001 from DDSim.DD4hepSimulation import DD4hepSimulation
0002 from g4units import mm, GeV, MeV, m
0003 import DDG4
0004 import argparse
0005 import sys
0006 
0007 
0008 # This printout is to check this steering file is using
0009 print("== STARTED STEERING FILE ==")
0010 print(f"g4units: mm={mm}, GeV={GeV}, MeV={MeV}")
0011 
0012 
0013 # Determine output file name
0014 # We intercept global dd4hep --outputFile flag to get base name for output file
0015 parser = argparse.ArgumentParser()
0016 parser.add_argument('--outputFile', type=str, default="output", help='Output file name')
0017 args, _ = parser.parse_known_args()
0018 
0019 # Add .firebird.json instead of .edm4hep.root or... whatever is there?
0020 outputFile = args.outputFile if args.outputFile else "output"
0021 if outputFile.endswith('.edm4hep.root'):
0022     outputFile = outputFile[:-len('.edm4hep.root')] + '.firebird.json'
0023 else:
0024     outputFile = outputFile+'.firebird.json' if outputFile else 'output.firebird.json'
0025 
0026 print(f"Steering event display 'outputFile' = {outputFile}")
0027 
0028 # This is needed for stepping file
0029 SIM = DD4hepSimulation()
0030 
0031 # Enable UI in the simulation
0032 #SIM.enableUI()
0033 
0034 # Set UI commands to enable trajectory storage
0035 # (!) It is mandatory to have f'/tracking/storeTrajectory 3' so that RICH points with time info are saved
0036 SIM.ui.commandsConfigure = [
0037     f'/tracking/storeTrajectory 3',
0038 ]
0039 
0040 # Need DDG4 kernel to add stepping
0041 kernel = DDG4.Kernel()
0042 
0043 
0044 # Set UI commands to enable trajectory storage
0045 # These commands need to be executed before the first event
0046 SIM.ui.commandsConfigure = [
0047     f'/tracking/storeTrajectory 3',
0048     # '/tracking/verbose 1',
0049     # Optional: command to draw trajectories in visualization (if used)
0050     #'/vis/scene/add/trajectories rich'
0051 ]
0052 
0053 
0054 # Instantiate the stepping action
0055 event_action = DDG4.EventAction(kernel, 'FirebirdTrajectoryWriterEventAction/TrajectoryWriter')
0056 event_action.ComponentName = "Geant4Trajectories"   # Tracks group name in firebird
0057 #event_action.RequireRichTrajectory = True  # Only use trajectories with time info
0058 #event_action.VerboseTimeExtraction = True  # Log details about time extraction
0059 # stepping = DDG4.SteppingAction(kernel, 'TextDumpingSteppingAction/MyStepper')
0060 event_action.OutputFile = outputFile
0061 # stepping.OnlyPrimary = False           # True = only keep tracks coming from generator/gun (e.g. parent=0)
0062 event_action.MomentumMin = 350               # Only leave tracks with
0063 # stepping.VertexCut = True              # Cut tracks which vertex is outside z_min-z_max range
0064 # stepping.VertexZMin = -5000            # [mm] Min Z for Vertex Cut. Will work only if VertexCut = True
0065 # stepping.VertexZMax = 5000             # [mm] Max Z for Vertex Cut. Will work only if VertexCut = True
0066 
0067 #kernel.steppingAction().add(stepping)
0068 kernel.eventAction().add(event_action)
0069 
0070 
0071 print("== END OF STEERING FILE ==")