Index: fact/tools/rootmacros/DrsCalibration.C
===================================================================
--- fact/tools/rootmacros/DrsCalibration.C	(revision 12512)
+++ fact/tools/rootmacros/DrsCalibration.C	(revision 12513)
@@ -31,4 +31,21 @@
 }
 
+
+
+// FACT raw data is stored in fits files in large vector<int16_t>. these
+// containt the data of the full camera for a single event.
+// in order to work with this data, one needs to extract the part, which
+// belongs to the current pixel and apply a DRS calibration, based on a dedicated
+// DRS calibration file.
+//
+// TODO: The calibration Data as well as the Data and StartCell vectors are a bit
+// massive to give this function as parameters.
+// better to have these vectors somehow bundled in classes like:
+// RawData - class and
+// DrsCalibration - class
+// those classes would be the result of
+// openDataFits() and
+// openCalibFits()
+//
 size_t applyDrsCalibration( vector<float> &destination,
 	int pixel, 
@@ -40,5 +57,6 @@
 	UInt_t RegionOfInterest,
 	vector<int16_t> AllPixelDataVector,
-	vector<int16_t> StartCellVector
+	vector<int16_t> StartCellVector,
+	int verbosityLevel
 ){
 	// In order to minimize mem free and alloc actions
@@ -48,10 +66,4 @@
 	if ( destination.size() < DestinationLength || destination.size() > 2 * DestinationLength ){
 		destination.resize( DestinationLength );
-	}
-
-	// the vector drs_triggeroffsetmean is not 1440 * 1024 entries long
-	// but has hopefully the length 1440 * RegionOfInterest (or longer)
-	if ( drs_triggeroffsetmean.size() < 1440*RegionOfInterest ){
-		return 0;
 	}
 
@@ -103,31 +115,44 @@
 	// TrueValue[c][s] = ( RawValue[c][s] - Offset[c][ (c+t)%1024 ] ) / Gain[c][ (c+t)%1024 ] * 1907.35 - TriggerOffset[c][s] 
 	
-	
-	
-
 	const float dconv = 2000/4096.0;
 	float vraw;
-//	float vcal;
-//	unsigned int pixel_pt;
-//	unsigned int slice_pt;
-//	unsigned int cal_pt;
-//	unsigned int drs_cal_offset;
 
 	if ( RegionOfInterest != AllPixelDataVector.size()/1440 ){
-		cout << "RegionOfInterest != AllPixelDataVector.size()/1440 .. this makes no sense ... I guess ... aborting" << endl;
+		if (verbosityLevel > 0){
+			cout << "RegionOfInterest != AllPixelDataVector.size()/1440" << endl;
+			cout << "RegionOfInterest: " << RegionOfInterest << endl;
+			cout << "AllPixelDataVector.size(): " << AllPixelDataVector.size() << endl;
+			cout << "aborting" << endl;
+		}
 		return 0;
 	}
 
-	int Offset_offset = pixel * drs_basemean.size()/1440;
-	int Gain_offset = pixel * drs_gainmean.size()/1440;
-	int TriggerOffset_offset = pixel * drs_triggeroffsetmean.size()/1440;
-	int Data_offset = pixel * RegionOfInterest;
+	// the vector drs_triggeroffsetmean is not 1440 * 1024 entries long
+	// but has hopefully the length 1440 * RegionOfInterest (or longer)
+	if ( drs_triggeroffsetmean.size() < 1440*RegionOfInterest ){
+		if (verbosityLevel > 0){
+			cout << "Error: drs_triggeroffsetmean.size() < 1440*RegionOfInterest" << endl;
+			cout << "drs_triggeroffsetmean.size():" << drs_triggeroffsetmean.size() << endl;
+			cout << "RegionOfInterest" << RegionOfInterest << endl;
+			cout << "aborting" << endl;
+		}
+		return 0;
+	}
+
+	int DataPos, OffsetPos, TriggerOffsetPos;
 	
 	for ( unsigned int sl = LeaveOutLeft; sl < RegionOfInterest-LeaveOutRight ; sl++){
-		vraw = AllPixelDataVector[ Data_offset + sl ] * dconv;
-		vraw -= drs_basemean[ Offset_offset + (sl + StartCellVector[pixel])%1024 ];
-		vraw /= drs_gainmean[ Gain_offset + (sl + StartCellVector[pixel])%1024 ];
+
+		DataPos = pixel * RegionOfInterest + sl;
+		// Offset and Gain vector *should look the same
+		OffsetPos = pixel * drs_basemean.size()/1440 + (sl + StartCellVector[pixel])%(drs_basemean.size()/1440);
+
+		TriggerOffsetPos = pixel * drs_triggeroffsetmean.size()/1440 + sl
+
+		vraw = AllPixelDataVector[ DataPos ] * dconv;
+		vraw -= drs_basemean[ OffsetPos ];
+		vraw /= drs_gainmean[ OffsetPos ];
 		vraw *= 1907.35;
-		vraw -= drs_triggeroffsetmean[ TriggerOffset_offset + sl ];
+		vraw -= drs_triggeroffsetmean[ TriggerOffsetPos ];
 
 //		slice_pt = pixel_pt + sl;
Index: fact/tools/rootmacros/DrsCalibration.h
===================================================================
--- fact/tools/rootmacros/DrsCalibration.h	(revision 12512)
+++ fact/tools/rootmacros/DrsCalibration.h	(revision 12513)
@@ -20,5 +20,6 @@
 	UInt_t RegionOfInterest,
 	vector<int16_t> AllPixelDataVector,
-	vector<int16_t> StartCellVector
+	vector<int16_t> StartCellVector,
+	int verbosityLevel  = 1
 );
 
