How to pass information to Allpix2 from an external GEANT4 simulation?

Hello,
I am working with a Geant4 setup that simulates the crossing of electromagnetic particles (electrons, positrons and photon) through different sub-detectors of an experiment. So the Geant4 simulation gives the incoming particle’s energy and position. Among the sub-detectors, I have a silicon-based ALPIDE tracker detector. I want to do the simulation of digitization of the tracker hits using the AllPix2 setup. May I know what is the recommendation to pass information from Geant4 setup to AllPix2 for this purpose? The Geant4 setup can output information in form of root tree branches, also in text files. Please advice.

Thank you,
Arka

Dear @asantra

in this case I recommend to use the DepositionReader module which does exactly what you need for your set-up. It reads energy depositions from ROOT trees or text files. The README describes the data format expected and the different configuration parameters.

What you still need to do is to prepare a geometry file with all sensors placed and oriented correctly - this file is used to do the coordinate transformation from global coordinates (in which the Geant4 is provided) to local sensor coordinates as used by Allpix Squared.

Please have a look if this satisfies your requirements and let us know if there is anything that you would need in addition.

All the best,
Simon

Hi @simonspa ,
Thank you very much for the link. I am trying to test this using a simple configuration file with alpide tracker. But for some reason, I do not see any events in the output files. Here are the details:

  1. The simulation conf file (tutorial-sim.conf)

[Allpix]
number_of_events = 1
detectors_file = “tutorial-geometry.conf”
log_level = “WARNING”

[GeometryBuilderGeant4]

#### this is with fixed energy
#[DepositionGeant4]
#particle_type = “e-”
#source_energy = 5GeV
#source_type = “beam”
#beam_size = 3mm
#source_position = 0 0 -200mm
#beam_direction = 0 0 1
#physics_list = FTFP_BERT_EMZ
#output_plots = 1

#### this is with energy from Geant4 simulation
[DepositionReader]
model = “csv”
file_name = “inputValues.csv”
detector_name_chars = 6
unit_length = “mm”
output_plots = 1

[ElectricFieldReader]
model = “linear”
bias_voltage = -50V
depletion_voltage = -30V
output_plots = 1

[ProjectionPropagation]
name = “Stave0”
##, “detector2”, “detector3”, “detector4”, “detector5”, “detector6”
temperature = 293K
charge_per_step = 10
output_plots = 1
output_linegraphs = 1

[VisualizationGeant4]
mode = “gui”
transparency = 0.4
view_style = “surface”
trajectories_color_mode = “charge”
trajectories_color_positive = “blue”
trajectories_color_neutral = “green”
trajectories_color_negative = “red”

[SimpleTransfer]
output_plots = 1

[DefaultDigitizer]
output_plots = 1

[DetectorHistogrammer]
output_plots = 1

[ROOTObjectWriter]
exclude = “PropagatedCharge”

  1. the geometry file (tutorial-geometry.conf)

[Stave0]
type = “alpide”
position = 50.73mm -0.607368mm 3864.51mm
orientation = 0 0 0

  1. The input file (inputValues.csv):

Event: 1
# PID,T,E,X,Y,Z,V,TRK,PRT
-11, 12.8394, 7.85445e-03, 60.6453, -0.607368, 3864.51, Stave0, 1, 0

When I run, I do not see any meaningful histograms from the output/modules.root and output/data.root. Most likely, I am doing some stupid mistake, but unfortunately, I cannot find this out.

One more thing I like to ask: how do I put units on the input CSV files? If I use energy in GeV, should I just write “7.85445e-03GeV” in the csv file?

Thank you very much,
Arka

EDIT 1: For the energy unit to be in GeV, I found out that I just need to write “unit_energy = GeV” in the config file.

EDIT 2: I have another question. How do I add the track orientation for the deposition reader?

Hi @asantra

three questions, three replies :slight_smile:

  1. I would need to have some more information to tell you what goes wrong when reading things in. Would you mind running your simulation with the command line argument -o Depositionreader.log_level=TRACE to generate some debug output that tells us what goes wrong?
  2. The energy you already found it, that’s great. Your idea however is also nice, we could simply parse the values we read from the CSV file through our unit system to resolve units.
  3. The coordinates used in your CSV file are global coordinates. The global-to-local coordinate transformation is defined via your geometry file, so this should be set up such that it represents the external simulation done beforehand. We don’t read (or have) information on the MCTrack objects from your CSV file, so this information you would have to obtain from your original simulation. We do generate MCParticle objects, but they never have a direction, just a begin and end point, which in DepositionReader we define as the earliest and latest appearance of a particle with a certain track id (set in your TRK column).

All the best,
Simon

Hi @simonspa ,
I tried to run the simulation with -o Depositionreader.log_level=TRACE and I see that for some reason, the DepositionReader reads the first event from the CSV file as Event 2, not as Event 1. For example, this is one input CSV file I used

Event: 1
-11, 12.8934, 7.85445e-06, 60.6453, -0.607368, 3864.5125, Stave00
-11, 12.8934, 1.12134e-06, 60.6453, -0.607356, 3864.5125, Stave00
Event: 2
-11, 12.8955, 5.0954e-06, 79.0785, -0.925664, 3864.5125, Stave00

Then when I read this file, the log of the run shows these

|14:10:42.685| (STATUS) Running event 1 of 4
|14:10:42.685| (DEBUG) [R:DepositionReader] Start reading event 1
|14:10:42.685| (TRACE) [R:DepositionReader] Line read: Event: 1
|14:10:42.685| (INFO) [R:DepositionReader] Finished reading event 1
|14:10:42.685| (STATUS) Running event 2 of 4
|14:10:42.686| (DEBUG) [R:DepositionReader] Start reading event 2
|14:10:42.686| (TRACE) [R:DepositionReader] Line read: -11, 12.8934, 7.85445e-06, 60.6453, -0.607368, 3864.5125, Stave00
|14:10:42.686| (TRACE) [R:DepositionReader] Truncated detector name: Stave00
|14:10:42.686| (DEBUG) [R:DepositionReader] Found detector “Stave00”
|14:10:42.687| (DEBUG) [R:DepositionReader] Found deposition of 2149 e/h pairs inside sensor at (7.87156mm,5.64175mm,0mm) in detector Stave00, global (60.6453mm,-607.368um,3864.51mm), particleID -11
|14:10:42.687| (TRACE) [R:DepositionReader] Line read: -11, 12.8934, 1.12134e-06, 60.6453, -0.607356, 3864.5125, Stave00
|14:10:42.687| (TRACE) [R:DepositionReader] Truncated detector name: Stave00
|14:10:42.687| (DEBUG) [R:DepositionReader] Found detector “Stave00”
|14:10:42.687| (DEBUG) [R:DepositionReader] Found deposition of 319 e/h pairs inside sensor at (7.87156mm,5.64176mm,0mm) in detector Stave00, global (60.6453mm,-607.356um,3864.51mm), particleID -11
|14:10:42.688| (TRACE) [R:DepositionReader] Line read: Event: 2
|14:10:42.688| (INFO) [R:DepositionReader] Finished reading event 2
|14:10:42.688| (DEBUG) [R:DepositionReader] Detector Stave00 has 4 deposits
|14:10:42.688| (TRACE) [R:DepositionReader] Sending message Messageallpix::DepositedCharge from DepositionReader to ProjectionPropagation:Stave00
|14:10:42.688| (TRACE) [R:DepositionReader] Sending message Messageallpix::DepositedCharge from DepositionReader to generic listener ROOTObjectWriter
|14:10:42.688| (TRACE) [R:DepositionReader] ROOT object writer received Messageallpix::DepositedCharge without a name
|14:10:42.698| (DEBUG) [R:DepositionReader] Pre-filling new tree of DepositedCharge with 1 empty events
|14:10:42.700| (INFO) [R:ProjectionPropagation:Stave00] Total charge: 2468 (lost: 0, 0%)
|14:10:42.704| (INFO) [R:SimpleTransfer:Stave00] Transferred 2468 charges to 1 pixels
|14:10:42.706| (WARNING) [R:DefaultDigitizer:Stave00] [further messages will be suppressed] Simulation chain does not allow for time-of-arrival calculation
|14:10:42.706| (INFO) [R:DefaultDigitizer:Stave00] Digitized 1 pixel hits
|14:10:42.723| (STATUS) Running event 3 of 4
|14:10:42.723| (DEBUG) [R:DepositionReader] Start reading event 3
|14:10:42.723| (TRACE) [R:DepositionReader] Line read: -11, 12.8955, 5.0954e-06, 79.0785, -0.925664, 3864.5125, Stave00
|14:10:42.723| (TRACE) [R:DepositionReader] Truncated detector name: Stave00
|14:10:42.724| (DEBUG) [R:DepositionReader] Found detector “Stave00”
|14:10:42.724| (DEBUG) [R:DepositionReader] Found deposition of 1420 e/h pairs inside sensor at (26.3048mm,5.32346mm,0mm) in detector Stave00, global (79.0785mm,-925.664um,3864.51mm), particleID -11

The full log is kept here

I think the same issue happens when reading from a root file( this discussion). I am not sure if this is the way it meant to be, but I don’t see any such instruction.

Thank you,
Arka

Hi @asantra

that seems to be an off-by-one error in our code. I will fix this for the next patch release. See here:

Cheers,
Simon