Histogramming and trigger software
Histogramming and trigger (event filter) software is an essential part of data acquisition and analysis with SPMRoot and ScanRoot.Both software are defined in a c++ ROOT compatible code. Some rules should be followed to have them working in the PelROOT scheme. Click on one of the links bellow for more information:
- Histogramming software
- Level-2 trigger software
Histogramming software
Histograms are defined in a c++ ROOT compatible code. Some rules should be followed in order to have full compatibility with the acquisition systemCode requirements
- Should have at least the following includes
#include "TH2.h" #include "ScanRoot.h"
- The histogram pointers (TH1 and TH2) should be external defined
- Should have the following functions
void bookHistograms(ScanRoot* scan) void init() void finish() void fill(short, float*)
- The function bookHistograms(ScanRoot* scan) should have the following line in order to link the acquisition program to the histogram filling function:
scan->fillHistograms = &fill;
where fill is the pointer to the filling histogram function. - The filling histogram method should have the following format
void fill(short npar, float *par)
where npar is the number of parameters in the event, index is an array with the parameters index and par is an array with the parameters value.
Functions
The function bookHistograms(ScanRoot* scan)This function is always necessary in the code and it runs ONLY when the histogram library is loaded. It creates the histograms in the memory and assign to the SPMRoot program a pointer to the function that will be called each event to fill the histograms.
The assignment of this pointer is essential and it is done with the following line
scan->fillHistograms = &fill;
The function init()
This function is optional and it is used to initialize the code every run. It is called in the beginning of each run and can be used to initialize variables or counters, for instance
The function finish()
This function is optional and it is used to finish the code every run. It is called in the end of each run and can be used to make final calculations with the histograms before they are saved, for instance
The function fill(short npar, float* par)
This is extremely important. This function is called for every event and we can use this to make calculations with the parameters in the event and to fill the histograms. This is a c++ code, so this function, and all the others above, can call different functions and perform any type of calculations with the data.
- npar has the number of parameters in the event
- par is a vector with the parameter values.
Example
The following code is an example of the histogram library:#include "TH2.h" #include "ScanRoot.h" TH1F* h1[100]; TH2F* h2[100]; // this function is called every event and it fills the histograms // defined in the memory void fill(short npar, float *par) { // checks if par[1] (DE) exists and fill it if (par[1]>0) h1[0]->Fill(par[1]); // idem for par[2] (E) if (par[2]>0) h1[1]->Fill(par[2]); // idem for De x E if(par[1]>0 && par[2]>0) h2[0]->Fill(par[2],par[1]); return; } // this function is called when the library is loaded and it creates // the histograms in the memory void bookHistograms(ScanRoot* scan) { // in order to set the correct directory, do scan->cd(); // these are examples of 1D histograms. // the syntax is: // // h1[X] = new TH1F(name, title, number of bins, // first bin value, last bin value); // // name is the name the histogram will appear in the TBrowser window // title is the title of the histogram in the canvas h1[0] = new TH1F("DE-Det1","Delta E for det 1",1024,0,4096); h1[1] = new TH1F("E-Det1", "E for det 1",1024,0,4096); // these are examples of 2D histograms. // the syntax is: // // h2[X] = new TH2F(name, title, // number of bins X, first bin value X, last bin value X, // number of bins Y, first bin value Y, last bin value Y); // h2[0] = new TH2F("DE-E-Det1","Delta E x E for det 1",512,0,4096,512,0,4096); // this sets the pointer of the SPMRoot function to the function // used to fill the histograms scan->fillHistograms = &fill; return; } // this function is called every time a new run starts void init() { return; // does nothing } // this function is called every time a run stops void finish() { return; // does nothing }
Level-2 trigger (event filter)
The Level 2 trigger is a software trigger that runs each event and returns a true/false statement that is used to decide if the current event has to be saved/histogrammed. This opens new possibilities for data taking such as saving only coincidence events or downscale particular events.Level 2 code is defined in a c++ ROOT compatible code. Some rules should be followed in order to have full compatibility with the acquisition system:
Code requirements
- Should have at least the following includes (at least)
#include "ScanRoot.h"
- The histogram pointers (TH1 and TH2) should be external defined
- Should have the following functions
void configureL2(ScanRoot* scan) void initL2() void finishL2() bool l2(short, float*)
- The function configureL2(ScanRoot* scan) should have the following line in order to link the acquisition program to the histogram filling function:
scan->l2trigger = &l2;
where fill is the pointer to the filling histogram function. - The l2 method should have the following format
bool l2(short npar, float *par)
where npar is the number of parameters in the event, index is an array with the parameters index and par is an array with the parameters value. This method returns true if the event is accepted and false if the event is rejected.
Functions
The function configureL2(ScanRoot* scan)This function is always necessary in the code and it runs ONLY when the event filtering library is loaded. It sets any necessary environment and assigns to the SPMRoot/ScanRoot program a pointer to the function that will be called each event to fill the histograms.
The assignment of this pointer is essential and it is done with the following line
scan->l2 = &l2;
The function initL2()
This function is optional and it is used to initialize the code every run. It is called in the beginning of each run and can be used to initialize variables or counters, for instance
The function finishL2()
This function is optional and it is used to finish the code every run. It is called in the end of each run and can be used to make final calculations with the code before they are saved, for instance
The function l2(short npar, float* par)
This is extremely important. This function is called for every event and we can use this to make calculations with the parameters in the event and to decide if the event has to be accepted or not. This is a c++ code, so this function, and all the others above, can call different functions and perform any type of calculations with the data. This function should return true in the case the event is accepted and false to reject the event.
- npar has the number of parameters in the event
- par is a vector with the parameter values.
Example
#include "ScanRoot.h" int n; // this function is called every event and it decides if // the event has to be saved or not bool l2(short npar, float *par) { n++; if(n%2==0) return false; // do not save even events return true; } // this function is called when the library is loaded and it creates // the histograms in the memory void configureL2(ScanRoot* scan) { // in order to set the correct directory, do scan->cd(); // this sets the pointer of the SPMRoot function to the function // used to fill the histograms scan->l2trigger = &l2; return; } // this function is called every time a new run starts void initL2() { n = 0; return; } // this function is called every time a run stops void finishL2() { return; // does nothing }