# Merging background hits

Using SAVE_ALL_MOTHERS=2 in the gcard settings, all secondary particles that create hits are recorded into a file labeled "background.dat". These events are recorded even if the generating particle has triggered a hit, thus they are not technically visible to the detector within the time window. This can lead to double counting events/hits, but is also useful in describing where particles are created. A macro is written to compare the background hits to the GEANT4 output from GEMC.

The gamma events corresponding to hits in S1R1 are compared, and the vertex position for the point of the gamma particle creation is recorded. These gamma vertex positions are plotted in the XZ plane to illustrate the relative positions where gammas are created. From this tomography plot, it is assumed that different shielding or clas12 components should help to decrease the gamma hit rate in the detector.

The background hits can be resimulated in GEMC without running through the full LUND file or random number sequence. Creating a Lund-like file, event.dat

1       605      0 0 0 0 0 0 0 0
1       0       1       22      0       13      2.03676e-05     8.11284e-06     -0.000102661    36.8152 0       85.1044 34.1051 231.048


Running this in GEMC:

~/src/CLAS/GEMC/clas12Tags/4a.2.2/source/gemc -USE_GUI=1  -MERGE_LUND_BG="event.dat" -N=1 eg12.gcard


Where the gcard is the same as the initial gcard used in the GEMC simulation. The background event has the information needed to show the gamma event with the same conditions it originally was created under the initial GEMC simulation. Following the LUND format, the last 3 data points are the first hit location in x,y and z.

The pitfall to this method is that the vertex position is accurate only for hits in the detectors. For the generating particle, in this case the scattered electron, no hits are recorded, so the exact same trajectory cannot be reproduced.

Figure 1: The left hand data is from the merge method, while the right side is the same particle from the original GEMC simulation. Both data sets are in good agreement, however the creation vertex point is not shown in the merged data point. The merged method also lacks an accurate representation of the path the generating particle took originally.

To overcome this method limits, the detector construction can be exported from GEMC in a CAD format. For this method, the wrl format(Virtual Reality Modeling Language, where wrl stand for WORLD) is used.

The wrl file needs to be converted to a readable format for Mathematica. Using the freeware program BLENDER, the wrl file is imported:

The file is then exported into a 3ds format