This is not for physics data! Marlin is used in that case with slcio files. Use this only with txt files!
Without event building
The data is saved, by the Labview program that run the electronic setup, in txt ASCII format. This part of the code converts these files to more manageable root files. A choice can be made to perform event building or not (so, no sorting by BXID).
Here are some step-by-step instruction to run the program:
Go to convert_root folder
This folder contains two other folders: src/ and Debug/. The first one contains the source files and the second one contains the executables and the makefile to produce them.
The ASCII files produced by the Labview do not contain any header giving any explanation of what is the format of the data, so you need to know it before hand. The data is usually delivered in two different formats, depending if the data is taking using the HBU DAQ or the HDMI DAQ connexion. For the HBU DAQ Labview, the text file contains 12 columns: BunchXID, CycleNr, ChipID2, ASICNr, EvtNr, chn, TDC, ADC, xPos, yPos, Hit_Bit, Gain_Bit
Bunch crossing ID: clock count
Cycle Number: readout cycle (the readout continues until all memory cells are filled, then the data needs to be processed and another readout cycle starts)
ChipID2: identity of the chips, is not hardcoded in the chip itself but set in the slow control files (don't change it!)
ASICNr: Position of the asic in the HBU (0-3). Not used.
EvtNr: Memory cell.
chn: channel (0-35)
TDC: relative time of the hit within a BunchXID (uncalibrated)
ADC: charge, in ADC counts, collected by the channel/memory cell in one hit (uncalibrated)
xPos, yPos: position of the chip/channel, not filled.
Hit_Bit: 1 if the channel signal was over the threshold, 0 if not. In laboratory mode (forced trigger) is always 1.
Gain_Bit: 1 if the ADC is delivered in High_gain mode or 0 if is in low gain.
The data format which depends of your labview. Here you have the two standard formats.
for HDMI DAQ:
sscanf(line.c_str(), "%i %i %i %i %i %i %i %i %i", &CycleNr, &BunchXID, &ChipID2, &EvtNr, &chn, &TDC, &ADC, &Hit_Bit, &Gain_Bit);
for USB DAQ:
sscanf(line.c_str(), "%i %i %i %i %i %i %i %i %i %i %i %i", &BunchXID, &CycleNr, &ChipID2, &ASICNr, &EvtNr, &chn, &TDC, &ADC, &xPos, &yPos, &Hit_Bit, &Gain_Bit);
Compile the code
Finally, you can run the program. It only needs two arguments: folder where the text files and the folder where the rootfiles will be (you need to create it).
Output data format
The output is a root file with TTree that contains an entry for each line of data (an entry for each channel that has been stored in the data file). In LED runs with forced trigger in high gain mode, the Hit_bit and Gain_Bit will be always 1 and all 16 memory cells are filled for all chips even though the memory cell 0 (16 if we use USB labview) is filled with zeros.
With event building
When analyzing physics data is important to convert the text files into root file performing, at the same time, the Event Building. Due to the characteristics of the Spiroc readouts, the output is not classified by events (noise or real hit events) but by readout cycle. Let's, for the moment, consider that we only have one ASIC and that we are running in autotrigger mode:
- Whenever 1 channel triggers (autotrigger), all 36 channels are stored in the analogue memory cells (at the end of the BxID latest).
- We can have noise events
- We can also, sometimes, miss an event (if one occur at the beginning of the BxID and other at the end, we miss the one at the end)
Acquisition continuous until all memory cells are filled. Then BUSY signal is set and the detector goes blind for up to ~50 ms due to conversion and slow readout. This makes unpredictable the time between readout cycles.
Now, let's consider the more realistic case: we run several chips with the same DAQ interface boards (specifically with same DIF). In this case, the data packets come out-of-order making a bit more complicated the sorting of the events by bunch crossing id.
This is done by the convert_root_eventbuilding code.
Compile the code
Run the program. It only needs two arguments: folder where the text files and the folder where the rootfiles will be (you need to create it).
Output data format
The final tree contains one entry for every event (noise or real event). Most of the objects are vectors with a maximum size of nHits == total number of channels in our setup. Remember that our ASICs, when one single channel is over the threshold all channels are readout. To know if a channel was triggered or not (by autotrigger) you need to check the value of the Hitbit (==1 if autotriggered, ==0 if other channel was triggered).