PelROOT
The Pelletron-Linac data analysis tools for ROOT

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

Histograms are defined in a c++ ROOT compatible code. Some rules should be followed in order to have full compatibility with the acquisition system

Code requirements

  1. Should have at least the following includes
    #include "TH2.h"               
    #include "ScanRoot.h"
    
  2. The histogram pointers (TH1 and TH2) should be external defined
  3. Should have the following functions
    void bookHistograms(ScanRoot* scan)                 
    void init()                 
    void finish()                 
    void fill(short, float*)
    
  4. 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.
  5. 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.

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

  1. Should have at least the following includes (at least)
             
    #include "ScanRoot.h"
    
  2. The histogram pointers (TH1 and TH2) should be external defined
  3. Should have the following functions
    void configureL2(ScanRoot* scan)                 
    void initL2()                 
    void finishL2()                 
    bool l2(short, float*)
    
  4. 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.
  5. 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.

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
  }

26 09 06 - 18:00 |

Last Comments

Options:

Calendar

« May 2024
S M T W T F S
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Last Comments

admin (version 3.01): Both men and women are wo…
Appannababu (Make your questio…): Hello Patrico, Thanks, I …
Patricio Carnelli… (Make your questio…): Hi Appannababu, This scri…
Appannababu (Make your questio…): Hello, I am new t…
cheap nashville p… (Using Graphical C…): Thanks for your sharing.i…
Supra Skytop (version 3.01): This topic was really edu…
Supra Sneakers (Using Graphical C…): Hey, appreciate it for ta…
Patricio Carnelli… (Make your questio…): Hello, I’m a PhD student …
Bob (Pivot 1.30 Beta 2…): And this is what a commen…

Search site

Archives

01 Sep - 30 Sep 2006
01 Dec - 31 Dec 2006
01 Jan - 31 Jan 2007
01 Feb - 28 Feb 2007
01 Mar - 31 Mar 2007
01 Apr - 30 Apr 2007
01 Jun - 30 Jun 2007
01 Oct - 31 Oct 2007
01 May - 31 May 2008
01 Oct - 31 Oct 2008
01 May - 31 May 2013
01 Nov - 30 Nov 2013
01 Jun - 30 Jun 2014

RSS & Atom

XML: RSS Feed XML: Atom Feed