Using GO4 for data anlysis: creating histograms

The creation of the histograms one wants to use is exactly the same as it is done in ROOT. The histograms have to be declared and defined. The histogram declaration is done in the file TXXXProc.h using the method TXXXProc.cxx. When the analysis includes several hundreds of histograms it is better to outsource the code responsible for defining the histograms in several files. The definition is actually done in the file DefineObjects.C. One can look at this file to see how the syntax for the definition.

When one defines new histograms one should also change the LoadObject.C because this file contains the commands to restore the histograms, parameters and conditions from the autosave file. This is useful to avoid memory problems and, if one has changed conditions and parameters, to restore this changed settings.

An example creating and array of histograms is given in the source code. Just uncomment the lines in the TXXXProc.h , TXXXProc.cxx , DefineObject.C and LoadObjects.C and build the code.

Unpacking MBS data

First one needs to get a picture how the MBS data structure looks like. Every MBS event contains several sub-events (in case of our example this are only two).

Every sub-event contains several hundreds of 32 Bit data words. These data words contain information from the different detectors (geo address, header/trailer information, channels, measurement datas). How the data of the nToF experiment looks like one can see here.

The unpacking of the MBS data structure takes place in the BuildEvent method of the TXXXProc class. When one looks inside the code one can find several command and predefined variables that provide an easy access to the data.

source code:

  TGo4MbsSubEvent* psubevt;

  Int_t *pl_data, l_data;


  fInput = (TGo4MbsEvent* ) GetInputEvent();


  while((psubevt = fInput->NextSubEvent()) != 0) { // loop over subevents   

    pl_data = psubevt->GetDataField(); //pointer to data

    lwords = psubevt->GetIntLen(); //no. of data words


    for(k = 0; k<lwords; k++) { //loop over lwords

    l_data = *pl_data++;


In principle this peace of code gets you two things:

  • the pointer to the first data word:  pl_data = psubevt->GetDataField();
  • and the number of data words in this subevent:  lwords = psubevt->GetIntLen();

In the following loop over the data words l_data is the value of the pointer pl_data. The pointer is increased every cycle what results in providing the next pointer. Now one can work with this value l_data.

For the decoding of the relevant data out of the bit structure of the data words one can either use bit shift operator as shown in the example or on can define a union that serves as a pattern that can be lain over the data words.

Filling histograms

The filling of the histograms is done with normal ROOT commands:

histogram -> Fill(entry)

means: increase bin with the number "entry" by one.