Index: fact/tools/rootmacros/tpeak.C
===================================================================
--- fact/tools/rootmacros/tpeak.C	(revision 12682)
+++ fact/tools/rootmacros/tpeak.C	(revision 12683)
@@ -34,5 +34,7 @@
 
 #include "fits.h"
-#include "FOpenCalibFile.c"
+
+#include "openFits.h"
+#include "openFits.c"
 
 #include "discriminator.h"
@@ -41,7 +43,4 @@
 #include "zerosearch.C"
 #include "factfir.C"
-
-#include "FOpenDataFile.h"
-#include "FOpenDataFile.c"
 
 #include "DrsCalibration.C"
@@ -64,4 +63,5 @@
 UInt_t NumberOfPixels;
 
+size_t TriggerOffsetROI, RC;
 size_t drs_n;
 vector<float> drs_basemean;
@@ -120,6 +120,6 @@
   int avg1    = 14,
   int avg2    = 8,
-	int OverlayWindowLeft = 50,
-	int OverlayWindowRight = 150,
+  int OverlayWindowLeft = 50,
+  int OverlayWindowRight = 150,
   int verbosityLevel = 1, // different verbosity levels can be implemented here
   bool ProduceGraphic = true
@@ -127,9 +127,9 @@
 
 {
-hPeakOverlayXaxisLeft = OverlayWindowLeft;
-hPeakOverlayXaxisRight = OverlayWindowRight;
-
-	gStyle->SetPalette(1,0);
-	gROOT->SetStyle("Plain");
+  hPeakOverlayXaxisLeft = OverlayWindowLeft;
+  hPeakOverlayXaxisRight = OverlayWindowRight;
+
+  gStyle->SetPalette(1,0);
+  gROOT->SetStyle("Plain");
 
 //-----------------------------------------------------------------------------
@@ -141,10 +141,10 @@
         TCanvas *cFiltered = NULL;
         if (spikeDebug){
-                cFiltered = new TCanvas("cFiltered","filtered DRS Waveforms", 1,310,400,300);
-                cFiltered->Divide(1, 3);
+          cFiltered = new TCanvas("cFiltered","filtered DRS Waveforms", 1,310,400,300);
+          cFiltered->Divide(1, 3);
         }
         // Canvases to show the peak template
         TCanvas *cPeakOverlay = NULL;
-        cPeakOverlay = new TCanvas("cPeakOverlay", "Overlay of detected Peaks", 1, 1, 1200, 600);
+        cPeakOverlay = new TCanvas("cPeakOverlay", "Overlay of detected Peaks", 1, 1, 1200, 800);
         cPeakOverlay->Divide(2,1);
 //        // All peaks of one Pixel
@@ -186,5 +186,5 @@
   // Parameters to the data file. So they are filled with
   // raw data as soon as datafile->GetRow(int) is called.
-  NEvents = OpenDataFile( datafilename, &datafile,
+  NEvents = openDataFits( datafilename, &datafile,
     AllPixelDataVector, StartCellVector, CurrentEventID,
     RegionOfInterest, NumberOfPixels, PXLxROI, verbosityLevel);
@@ -207,95 +207,93 @@
     cout <<"of, which "<< npixel << "will be processed"<< endl;
 //Get the DRS calibration
-        FOpenCalibFile(	drsfilename,
-                                        drs_basemean,
-                                        drs_gainmean,
-                                        drs_triggeroffsetmean,
-                                        drs_n);
-cout << "test4" << endl;
+   RC = openCalibFits( drsfilename, drs_basemean, drs_gainmean, drs_triggeroffsetmean, TriggerOffsetROI);
+   if (RC == 0){
+     cout << "return code of openCalibFits:" << drsfilename << endl;
+     cout << "is zero -> aborting." << endl;
+     return 1;
+   }
 // Book the histograms
-        BookHistos( );
+   BookHistos( );
 
 //-----------------------------------------------------------------------------
 // Loops over Every Event and Pixel
 //-----------------------------------------------------------------------------
-        for ( int ev = firstevent; ev < firstevent + nevents; ev++) {
-                // Get an Event --> consists of 1440 Pixel ...erm....data
-                datafile->GetRow( ev );
-
-        //-------------------------------------
-        // Loop over every Pixel of Event
-        //-------------------------------------
-
-                for ( int pix = firstpixel; pix < firstpixel + npixel; pix++ ){
-
-												if (verbosityLevel > 0){
-									        if (pix == firstpixel){
-									          cout << "Processing Event: " << CurrentEventID << "/" << nevents << endl;
-									        }
-									      }
-
-											applyDrsCalibration( Ameas,pix,12,12,
-								        drs_basemean, drs_gainmean, drs_triggeroffsetmean,
-								        RegionOfInterest, AllPixelDataVector, StartCellVector);
-
-									      // finds spikes in the raw data, and interpolates the value
-									      // spikes are: 1 or 2 slice wide, positive non physical artifacts
-									      removeSpikes (Ameas, Vcorr);
-
-										     // filter Vcorr with sliding average using FIR filter function
-									      sliding_avg(Vcorr, Vslide, avg1);
-									      // filter Vslide with CFD using FIR filter function
-									      factfir(b_cfd , a_cfd, k_cfd, Vslide, Vcfd);
-									      // filter Vcfd with sliding average using FIR filter function
-									      sliding_avg(Vcfd, Vcfd2, avg2);
-
-                        // peaks in Ameas[] are found by searching for zero crossings
-                        // in Vcfd2
-                        // first Argument 1 means ... *rising* edge
-                        // second Argument 1 means ... search with stepsize 1 ... 10 is okay as well
-                        vector<Region> * zXings = zerosearch( Vcfd2 , 1 , 1);
-                        // zXings means "zero cross ings"
-                        EnlargeRegion(*zXings, 10, 10);
-                        findAbsMaxInRegions(*zXings, Vslide);
-									      removeMaximaBelow( *zXings, 3.0);
-									      removeRegionWithMaxOnEdge( *zXings, 2);
-									      removeRegionOnFallingEdge( *zXings, 100);
-
-                        //following Code should produce the Overlay of peaks
-                        vector<Region>::iterator it;
-
-                                for (it = zXings->begin() ; it < zXings->end() ; it++){
-                                  int Left = it->maxPos - OverlayWindowLeft;
-                                  int Right = it->maxPos + OverlayWindowRight;
-                                  if (Left < 0)
-                                    Left =0;
-                                  if (Right > (int)Vcorr.size() )
-                                    Right=Vcorr.size() ;
-                                        for ( int pos = Left; pos < Right; pos++){
-
-                                            hPeakOverlay->Fill( pos - (it->maxPos), Vslide[pos]) ;
-//                                            hPixelPeakOverlay->Fill( pos - (it->maxPos), Vcorr[pos]) ;
-//                                            hEventPeakOverlay->Fill( pos - (it->maxPos), 2*Vcorr[pos]) ;
-                                        }
-                                }
-
-
-                        if ( spikeDebug ){
-
-
-													  // TODO do this correct. The vectors should be the rigt ones... this is just luck 
-									          debugHistos[Ameas_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
-									          debugHistos[Vcorr_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
-									          debugHistos[Vslide_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
-									          debugHistos[Vcfd_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
-									          debugHistos[Vcfd2_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
-
-										        for ( unsigned int sl = 0; sl < RegionOfInterest; sl++){
-										          debugHistos[Ameas_].SetBinContent(sl, Ameas[sl]);
-										          debugHistos[Vcorr_].SetBinContent(sl, Vcorr[sl]);
-										          debugHistos[Vslide_].SetBinContent( sl, Vslide[sl] );
-										          debugHistos[Vcfd_].SetBinContent( sl, Vcfd[sl] );
-										          debugHistos[Vcfd2_].SetBinContent( sl, Vcfd2[sl] );
-										        }
+   for ( int ev = firstevent; ev < firstevent + nevents; ev++) {
+      // Get an Event --> consists of 1440 Pixel ...erm....data
+      datafile->GetRow( ev );
+
+      //-------------------------------------
+      // Loop over every Pixel of Event
+      //-------------------------------------
+
+       for ( int pix = firstpixel; pix < firstpixel + npixel; pix++ ){
+           if (verbosityLevel > 0){
+           if (pix == firstpixel){
+               cout << "Processing Event: " << CurrentEventID << "/" << nevents << endl;
+           }
+       }
+
+       applyDrsCalibration( Ameas,pix,12,12,
+           drs_basemean, drs_gainmean, drs_triggeroffsetmean,
+           RegionOfInterest, AllPixelDataVector, StartCellVector);
+
+       // finds spikes in the raw data, and interpolates the value
+       // spikes are: 1 or 2 slice wide, positive non physical artifacts
+       removeSpikes (Ameas, Vcorr);
+
+       // filter Vcorr with sliding average using FIR filter function
+       sliding_avg(Vcorr, Vslide, avg1);
+       // filter Vslide with CFD using FIR filter function
+       factfir(b_cfd , a_cfd, k_cfd, Vslide, Vcfd);
+       // filter Vcfd with sliding average using FIR filter function
+       sliding_avg(Vcfd, Vcfd2, avg2);
+
+       // peaks in Ameas[] are found by searching for zero crossings
+       // in Vcfd2
+       // first Argument 1 means ... *rising* edge
+       // second Argument 1 means ... search with stepsize 1 ... 10 is okay as well
+       vector<Region> * zXings = zerosearch( Vcfd2 , 1 , 8);
+       // zXings means "zero cross ings"
+       EnlargeRegion(*zXings, 10, 10);
+       findAbsMaxInRegions(*zXings, Vslide);
+       removeMaximaBelow( *zXings, 3.0);
+       removeRegionWithMaxOnEdge( *zXings, 2);
+       removeRegionOnFallingEdge( *zXings, 100);
+
+       //following Code should produce the Overlay of peaks
+       vector<Region>::iterator it;
+       for (it = zXings->begin() ; it < zXings->end() ; it++){
+           if (it->maxPos < 12 || it->maxPos > RegionOfInterest-12)
+             continue;
+           domstest->Fill(it->maxPos);
+           int Left = it->maxPos - OverlayWindowLeft;
+           int Right = it->maxPos + OverlayWindowRight;
+           if (Left < 0)
+               Left =0;
+           if (Right > (int)Vcorr.size() )
+               Right=Vcorr.size() ;
+           for ( int pos = Left; pos < Right; pos++){
+                hPeakOverlay->Fill( pos - (it->maxPos), Vslide[pos]) ;
+//              hPixelPeakOverlay->Fill( pos - (it->maxPos), Vcorr[pos]) ;
+//              hEventPeakOverlay->Fill( pos - (it->maxPos), 2*Vcorr[pos]) ;
+           }
+       }
+
+
+       if ( spikeDebug ){
+          // TODO do this correct. The vectors should be the rigt ones... this is just luck 
+          debugHistos[Ameas_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
+	  debugHistos[Vcorr_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
+	  debugHistos[Vslide_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
+	  debugHistos[Vcfd_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
+	  debugHistos[Vcfd2_].GetXaxis()->Set(Ameas.size() , -0.5 , Ameas.size()-0.5);
+
+	  for ( unsigned int sl = 0; sl < RegionOfInterest; sl++){
+               debugHistos[Ameas_].SetBinContent(sl, Ameas[sl]);
+               debugHistos[Vcorr_].SetBinContent(sl, Vcorr[sl]);
+               debugHistos[Vslide_].SetBinContent( sl, Vslide[sl] );
+               debugHistos[Vcfd_].SetBinContent( sl, Vcfd[sl] );
+               debugHistos[Vcfd2_].SetBinContent( sl, Vcfd2[sl] );
+         }
 
 
