Index: /fact/tools/rootmacros/gainanalysis.C
===================================================================
--- /fact/tools/rootmacros/gainanalysis.C	(revision 12274)
+++ /fact/tools/rootmacros/gainanalysis.C	(revision 12275)
@@ -21,6 +21,7 @@
 {
 //******************************************************************************
-//Read a datafile and plot the DRS-calibrated data
-//ATTENTION: only works for ROI=1024
+//Read a file with G-APD singles, analyse them and plot the spectra
+//This source code is best read with a wide editor (>100 characters per line) or a horizontal scroll bar.
+//ATTENTION: this script only works for ROI=1024
 // (array indices of the calibration wrong otherwise)
 //******************************************************************************
@@ -92,5 +93,4 @@
 	Double_t par_init[5+2*n_peaks] = {70,90,100,15,10,15,10,30,30};
 	Double_t parread_tmp[5+2*n_peaks];
-	Double_t parread[data_px][5+2*n_peaks];
 //	TF1 *f_peaks = new TF1("total","[2]*TMath::Exp(-(x-[0])*(x-[0])/(2*[3]*[3])) + [4]*TMath::Exp(-(x-[0]-[1])*(x-[0]-[1])/(2*[5]*[5])) + [6]*TMath::Exp(-(x-[0]-2*[1])*(x-[0]-2*[1])/(2*[7]*[7])) + [8]*TMath::Exp(-(x-[0]-3*[1])*(x-[0]-3*[1])/(2*[9]*[9])) + [10]*TMath::Exp(-(x-[12])*(x-[12])/(2*[11]*[11]))",fit_start,fit_end);
 //	Double_t par_init[3+2*n_peaks] = {70,90,500000,15,50000,15,5000,15,500,15,800000,20,0};
@@ -120,5 +120,5 @@
 	
 //-------------------------------------------
-//Oscilloscope
+//Oscilloscope (search for peaks and fill integral into the histograms)
 //-------------------------------------------
 //	float threshold = pedestal_mean+pedestal_rms;
@@ -174,4 +174,10 @@
 //	canv_spect->Update();
 //***********************
+	
+//-------------------------------------------
+//Fit the histograms and store the parameters into parread
+//parread_dist: peak difference (gain) per pixel, parread_x: x-Values for the TGraph
+//-------------------------------------------
+	Double_t parread[data_px][5+2*n_peaks];
 	Double_t parread_dist[data_px];
 	Double_t parread_x[data_px];
@@ -196,4 +202,7 @@
 	}
 	
+//-------------------------------------------
+//Plot the gain of all pixel
+//-------------------------------------------
 	canv_gain->cd();
 	TGraph* plot_gain = new TGraph(data_px,parread_x,parread_dist);
@@ -207,5 +216,6 @@
 	
 //-------------------------------------------
-//Draw the data where the gain is out of limits
+//Draw the spectrum of pixel where the gain is out of limits
+//Drawn are the fitted function (f_peaks) and its components (f_peak[i], f_pedestal)
 //-------------------------------------------
 	char temp = 'x';
@@ -238,6 +248,7 @@
 		}
 	}
-//-------------------------------------------
-//Draw the data
+	
+//-------------------------------------------
+//Give the possibility to draw the spectrum of any pixel
 //-------------------------------------------
 	canv_spect->cd();
