The purpose of the frontend code is to produce a midas file of identical format to the ones used in the 2008-10 PEN experiment. We're using c++. The initial implementation of the code was done by Pete Alonzi (alonzi@virginia.edu). It was designed to take an input that was the output of a geant4 simulation. Since the experiment stores information in MIDAS file banks the geant code was also configured to store the information in a midas file bank, named GSIM. The method of reading and writing files is gzopen, gzread, gzwrite, and gzclose. Everyone likes to learn code in a different way. I will provide an outline of frontend.cc (the location of main). Preamble: Includes, and defines, function prototyping Please note that most functions are functions that fill the different banks in an event. Main: I'm pretty sloppy at programming so there is no proper header file and everything is the main function except for a few routines. 1: call set_complexity(...) This function puts the code into simple or complex mode depending on the type of event to be packaged. Simple events are straightforward pion decays, etc. Complex events are things like accidental events where multiple simulated events are superimposed on eachother. 2: Open necessary files, this part of the code opens the input and output files. 3: The random engine being used is the standard gsl engine, this part could be made more robust with something like a twister. 4: THE DO LOOP, this is where all the action happens. a: establish pointers to files and GSIM bank in files b: read in GSIM bank for one event (or two events if complex). The relevant pointer is PGSIMP every subsequent part of the code that references the input file does so through PGSIMP c: set up MIDAS file writing Variables. the process to write a midas file is complex and a helpful graphic was produced by pete to explain the process (path/midasfile.pdf it is in the repository that you already have checked out and uses the same pointers as the frontend.cc code). d: compose event header (midas overhead) e: initialize bank (midas overhead) f: the next section is geometry dependent and uses a linux environment vairable. this is not necessary but implemented to permit switiching between different sets of banks and filling without a need to recompile. g: a series of function calls to fill the banks. what is done in each function is to decide what the contens of the bank should be and then write that info at the location of PBUF, PBUF is then returned and passed to the next function after being incremented (remember pevent_copy knows the start of data writing. h: after all of the function calls gzwrite puts the contents of pevent_copy into the output file. 5: print out some statistics for the run and close the necessary files 6: The details for each individual function. The basic structure of the bank filling functions is to do some calculations then use bk_create to open a bank at pbuf and bk_close when done writing. the pointer pdataw or pdatadw is usually used for writing the info into the bank. Additional Notes: All funtions starting in bk_ are midas functions and the documentation is best found through google (at least at time of writing)