As a first step, you should do the Pedestal calibration!


An important characteristic parameter of a SiPM is the gain. The gain value is solely dependent on the distance between the peaks.

  • This software performs the gain calibration for the AHCAL.  It takes rootfiles from the standard LED runs (with applied LED voltages) as input and also the pedestal file (.tsv) which is acquired from pedestal extraction, in order to produce ADC Spectrums for individual channels.
  • Then it performs a MultiGaussian Fit on the Spectra.

For doing this we need to take several LED runs in forced trigger mode for several LED Voltages. The optimal voltage is priori unknown and varies for every channel. One reasonable range is [5700-6000 mV] since each SiPM response may vary.  

Program flow:

  1. Filling the histograms and making the Pedestal Offset correction

    int VarToFill = ADC;
    if (VarToFill > 0 && Gain_Bit == 1 ){
       if (takePedestal) {
          histos[thisRun->vCalib][ChipID2][chn]->Fill(VarToFill+b.getOffset(ChipID2, chn, EvtNr));
      } else

and the offset correction is done memory cell by memory cell in this part:

b.getOffset(ChipID2, chn, EvtNr)

2. Check the spectrum to see if it is fitable or not

TSpectrum * spectrum = new 
TSpectrum(5,1);//searching for peaks 
spectrum->Search((*it)->histoAll,5,"",0.15); Int_t nPeaks = 
spectrum->GetNPeaks(); cout << "nPeaks CheckSpectrum = " 
<< nPeaks << endl;//Check if the initial spectrum is okay 
bool SpectrumIsOK = CheckSpectrum(spectrum);

The position of the peaks is found via TSpectrum . The TSpectrum is class from ROOT which is able to study any spectrum and find the maximum number of candidates to be peaks in the data (pseudo-peaks).

The CheckSpectrum function checks if there are minimum number of pseudo-peaks needed for the gain calibration and the pseudo-peaks are well resolved and if the distance between two pseudo peaks is of similar distances. If this is the case, then a full fit to the data of a multigaussian is performed(approximately) using the output information of the checks as input information to start the fit.

Another check that is done is the called "Mean Condition" which basically ask for ADC spectrums no saturated (mean < 1000-3000 ADC ticks depending of the tiles/SiPMs/boards...)

3. Fitting method

The Fit is in the form :

mg += par[2*i+3]*TMath::Gaus(xx,gain*i+p0,par[2*i+4]);

par[2*i+3] is the normalisation of the peak i
gain is the distance between peaks -> knowledge input there (as we know that it should be like that)
p0 is the 1st peak position (pedestal value)
par[2*i+4] is the width of the peak at position i

It also performs a Fast Fourier Transform (FFT) fit in order to get a comparison with another method.

Instructions to run the code

The input file names need to have the LED voltage value in the name in order to read it and use it to create the output files. This is done in the GainRunFolderParser.h, in this line:

t = file.substr(file.find("mV")-4,4);

since the program is expecting a file name like *LEDXXXXmV*.root where XXXX is the LED voltage in mV.

To run the program:

cd YourDestinationFolderName/Extraction_Gain

and execute by:


The third last argument tells us whether we are running in HG/LG mode.

If there is a VCALIB, the runnumber is not needed.

If you want to use the runnumber, put VCALIB to -1.

Output files

The output consist in several files:

  1. TestXXXX.root : contains results related to the quality of the fits

  2. HighSignalXXXX.root: contains all the ADC histograms (for all channels and chips)

  3. Plot_compXXXX.root: contains the fitted histograms and the histograms that satisfy some minimum requirements .

  4. gainfits_XXXX.tsv: text file with the gain values. Five rows: Chip, channel, gain (multigaussian), gain (FFT), errorgain (FFT)

Where XXXX is the LED voltage in mV.

Example of results

Here I show an example of gain fit for channel 29 of chip 7691 for a specific LED voltage of 6000mV, X-axis: ADC ticks and Y-axis: Entries.