Skip to content
Dave Elofson edited this page Jun 7, 2023 · 15 revisions

Welcome to the Q_PIX_RTD wiki!

An introduction

The code base for generating the Reset Time Delay (RTD) is described in this wiki. This code is specifically formulated to accept the input form QPIX_G4 and produce the appropriate response. Such response takes into account the physics of the electron propagation in liquid argon, the charge lost due to recombination, as well as the response of the front end electronics which are responsible for integrating the charge and producing the resets.

WIKI Guide

Here in the main page of the wiki we will go through grabbing the project, building, and running the example. For details about the classes/CPP files please see the pages on the right.

Software Requirements

This package requires ROOT to be setup, and uses C++17 and Boost. The software versions this was developed with are

cmake version 3.15.5
make  version 3.81
ROOT  Version: 6.18/04

Building

Firstly we need to clone the directory, so you should open a terminal and go to a directory you want the project to be in

git clone git@github.com:Q-Pix/qpixrtd.git

Once cloned you should go into the directory (e.g. cd qpixrtd), and now we will build the project.

Building and sourcing the relevant paths are controlled using the 'build.sh' script and the 'setup.sh' script. When using for the first time, you must build the project by running

./build.sh

This will call 'source setup.sh' as part of the script so you don't have to. This will define the paths then move into the build directory and run cmake and make etc.. From there it should just compile, If it does not there is likely something not installed.

If it isn't your first time using the repository since cloning, you need only run

source setup.sh

before doing any work as this will define your paths each time you use it in a new terminal. By only running 'setup.sh' you avoid having to run through cmake every time you want to use the repository.

If you are having an issue here reach out to Austin or Johnny and we can set this sorted out.

Make the Example

The example will run through 100 marley events that were generated with the geant4 package. It will run through all functions to produce a QPIX response. It takes an input file fom the geant4 step and outputs a file that is similar to an expected output with a pixel location and reset time. and output a new root file.

Once the environment is sourced (the previous step) the example can be made and ran via

cd EXAMPLE/build
cmake ..
make 
cd ..
./build/EXAMPLE

The data file used in the EXAMPLE is located HERE. You can either download it directly and place it in the EXAMPLE folder or you can grab it with wget (brew install wget if you dont have it). Then form the Q_PIX_RTD directory

cd EXAMPLE/
wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1XH48pZrZCLwkNKSq5EbOsYYNtIiUFGhp' -O MARLEY_100Events.root

The example can be ran from the EXAMPLE directory via

./EXAMPLE MARLEY_100Events.root MARLEY_100Events_RTD.root

Here lets quickly walk through the EXAMPLE and point to where relevant code lives.

After the includes and clocking (so we know how long it takes) we get into the actual RTD setups. The first thing is to set up the random generator, with a given seed, then generate the noise vector. The noise vector is used so we can call the generator less.

// changing the seed for the random numbergenerator and generating the noise vector 
constexpr std::uint64_t Seed = 777;
Qpix::Random_Set_Seed(Seed);
std::vector<double> Gaussian_Noise = Qpix::Make_Gaussian_Noise(0, (int) 1e7);

Te next step is to set up the input and output files. These can be hard coded but then need to be recompiled when they are changed. The implementation below has them as command line arguments e.g. ./EXAMPLE IN_FILE.ROOT OUT_FILE.ROOT.

// In and out files
std::string file_in = argv[1];
std::string file_out = argv[2];

Now we move on to setting up the "Qpix Paramaters", this includes the diffusion, velocity, dead time, charge loss etc. See Structures.h for more.

// Qpix paramaters 
Qpix::Qpix_Paramaters * Qpix_params = new Qpix::Qpix_Paramaters();
set_Qpix_Paramaters(Qpix_params);
print_Qpix_Paramaters(Qpix_params);

Now we set up the files. For redundancy the input file is completely copied into the output file, this is done so the raw G4 files never become corrupted (at least that is the goal). After the file is copied the "meta data" is added, which is just the Qpix Paramaters we just set up. Then the number of events in the file is determined and we can now move on to reading the file.

// root file manager
int number_entries = -1;
Qpix::ROOTFileManager rfm = Qpix::ROOTFileManager(file_in, file_out);
rfm.AddMetadata(Qpix_params);  // add parameters to metadata
number_entries = rfm.NumberEntries();
rfm.EventReset();

Now we loop over the events!

The first thing is to define the vector of ELECTRON and produce the "real" electrons with Get_Event (see ROOTFileManager for more details).

std::vector<Qpix::ELECTRON> hit_e;
// turn the Geant4 hits into electrons
rfm.Get_Event( evt, Qpix_params, hit_e);

Now with the "real" electrons made we start the Pixel_Functions class, the vector of Pixel_Info, and then run Pixelize_Event which groups the electrons by pixel (see PixelResponse for more details).

Qpix::Pixel_Functions PixFunc = Qpix::Pixel_Functions();
std::vector<Qpix::Pixel_Info> Pixel;
// Pixelize the electrons 
PixFunc.Pixelize_Event( hit_e, Pixel );

Now with the electrons grouped by pixel the reset function is called (see PixelResponse for more details).

// the reset function
PixFunc.Reset(Qpix_params, Gaussian_Noise, Pixel);

After each event the pixel info is stored into the root tree, the event is cleared and we go back around!

rfm.AddEvent( Pixel );
rfm.EventFill();
rfm.EventReset();

Once the events have been looped over the new root file is saved.

// save and close
rfm.Save();