[Halld-offline] particle gun revisited, generalized, perl-based

Mark M. Ito marki at jlab.org
Fri Jul 23 12:23:15 EDT 2010


Folks,

I've written a little perl module (48 lines of code) that allows one to 
generate single-particle Monte Carlo events with arbitrary starting 
points and momentum. This is a generalization of the particle gun 
already built into HDGeant. By using a perl module (library of perl 
subroutines) one is able to generate a set of events under control of a 
perl script, which makes for quick and easy generation of a variety of 
test data sets.

Here is an example of a script which uses the perl module (the module is 
named evgen.pm):

===cut here===
#!/usr/bin/perl

use evgen;

$px = 0; $py = 0; $pz = 100;
$x0 = 30; $y0 = 0; $z0 = 170;
$type = "pi+";

$evno_max = 3;
output_header();
for ($evno = 1; $evno <= $evno_max; $evno++) {
     output_event_header();
     output_event($px, $py, $pz, $x0, $y0, $z0, $type);
     output_event_footer();
}
output_footer();

exit;
===cut here===

This example generates three events (set by $evno_max), all containing a 
100 GeV/c pi+, launched parallel to the beam direction, starting at (x, 
y, z) = (30, 0, 170) cm. The output is xml, produced on standard output, 
conforming to the HDDM schema.

Note that the event loop is under control of the script so that any of 
the parameters could be varied from event to event (as is traditional in 
a Monte Carlo). Perl also comes with random number generators of course, 
if those are needed.

The motivation for doing this for me is illustrated in the example. I 
wanted a particle with a known trajectory so I could predict the 
residual in a particular layer of the FDC chamber, in order to test my 
code. The module allows me to put a particle exactly where I want it (it 
misses the CDC, it is normal to the FDC chambers, I know which wires get 
hit) so I know the hit-level answer I should get in advance.

To actually create the hddm data file, suitable for reconstruction, you 
use some of our standard tools. Continuing the example above and 
arbitrarily calling the output files "gun" something:

# run the script above, called evgen.pl, capture the standard output

evgen.pl > gun.xml

# transform gun.xml into an HDDM file (gun.hddm) readable by HDGeant (a 
template file is needed)

xml-hddm -t gluex_template.hddm -o gun gun.xml

# generate the events with HDGeant, let's assume that this produces an 
output file called gun_hdgeant.hddm (a control.in is needed)

hdgeant gun.hddm

# smear the hits, producing gun_hdgeant_smeared.hddm

mcsmear gun_hdgeant.hddm

One final note on this example: although the raw events are identical 
before smearing, after smearing resolution has been introduced 
differently for each event.

There are likely still some rough edges to this, but if you want to fool 
around with the code, find it in the repository under 
trunk/home/marki/gluex/evgen. The example script (evgen.pl) is there, as 
well as the perl module, the template, and a Makefile that runs through 
the steps in the example.

   -- Mark



More information about the Halld-offline mailing list