Index: fact/tools/rootmacros/tpeak.C
===================================================================
--- fact/tools/rootmacros/tpeak.C	(revision 12392)
+++ fact/tools/rootmacros/tpeak.C	(revision 12545)
@@ -74,7 +74,12 @@
 vector<float> Vcfd(FAD_MAX_SAMPLES);    // CDF result
 vector<float> Vcfd2(FAD_MAX_SAMPLES);    // CDF result + 2nd sliding average
-
+typedef struct{
+  float maxAmpl;
+  float countOfMax;
+  } OverlayMaximum;
+vector<OverlayMaximum> SingleMaximum;
 // histograms
 const int NumberOfDebugHistoTypes = 7;
+
 const unsigned int
         Ameas_ 	= 0,
@@ -89,4 +94,7 @@
 TH1F *debugHistos;
 TH2F *hPeakOverlay;  //histogrammm for overlay of detected Peaks
+TH1F *hMaxPeakOverlay;
+//TH2F *hPixelPeakOverlay;
+TH2F *hEventPeakOverlay;
 int hPeakOverlayXaxisLeft,hPeakOverlayXaxisRight; 
 
@@ -103,5 +111,5 @@
   char *datafilename    = "data/20111016_013.fits.gz",
   const char *drsfilename = "../../20111016_011.drs.fits.gz",
-  const char *OutRootFileName = "../analysis/fpeak_cdf.Coutput.root",
+  const char *OutRootFileName = "../analysis/tpeak_cdf.Coutput.root",
   int firstevent      = 0,
   int nevents       = -1,
@@ -137,5 +145,13 @@
         // Canvases to show the peak template
         TCanvas *cPeakOverlay = NULL;
-        cPeakOverlay = new TCanvas("cPeakOverlay", "Overlay of detected Peaks", 1, 310, 400, 400);
+        cPeakOverlay = new TCanvas("cPeakOverlay", "Overlay of detected Peaks", 1, 1, 400, 600);
+        cPeakOverlay->Divide(1,2);
+        // All peaks of one Pixel
+        TCanvas *cPixelPeakOverlay = NULL;
+        cPixelPeakOverlay = new TCanvas("cPixelPeakOverlay", "Overlay of detected Peaks of all Events of one Pixel", 401, 1, 400, 400);
+        // All Peaks of one Event
+        TCanvas *cYProjection = NULL;
+        cYProjection = new TCanvas("cYProjection", "Y Projection of peak overlay for each bin ", 802, 1, 400, 400);
+
 
 
@@ -258,5 +274,7 @@
                                         for ( int pos = Left; pos < Right; pos++){
 
-                                            hPeakOverlay->Fill( pos - (it->maxPos), Vcorr[pos]) ;
+                                            hPeakOverlay->Fill( pos - (it->maxPos), Vslide[pos]) ;
+//                                            hPixelPeakOverlay->Fill( pos - (it->maxPos), Vcorr[pos]) ;
+                                            hEventPeakOverlay->Fill( pos - (it->maxPos), 2*Vcorr[pos]) ;
                                         }
                                 }
@@ -316,5 +334,5 @@
 
                                 //OVERLAY PEAKS
-                                cPeakOverlay->cd();
+                                cPeakOverlay->cd(1);
                                 hPeakOverlay->Draw("COLZ");
                                 cPeakOverlay->Modified();
@@ -347,23 +365,59 @@
 						if (ev % 50 == 0){
                 //OVERLAY PEAKS
-                cPeakOverlay->cd();
+                cPeakOverlay->cd(1);
                 hPeakOverlay->Draw("COLZ");
+                cPeakOverlay->cd(2);
+                hMaxPeakOverlay->Draw("COLZ");
                 cPeakOverlay->Modified();
                 cPeakOverlay->Update();
-						}
+
+//                cPixelPeakOverlay->cd();
+//                hPixelPeakOverlay->Draw("COLZ");
+//                cPixelPeakOverlay->Modified();
+//                cPixelPeakOverlay->Update();
+                  }
 				}
                 if (breakout)
                         break;
         }
+
 //-------------------------------------
 // end of loop over Events
 //-------------------------------------
-				if (ProduceGraphic){
-                //OVERLAY PEAKS
-                cPeakOverlay->cd();
-                hPeakOverlay->Draw("COLZ");
-                cPeakOverlay->Modified();
-                cPeakOverlay->Update();
-				}
+        //TH1D* hProjPeak =	TH2::ProjectionY(const char* name = "proj_py", Int_t firstxbin = 0, Int_t lastxbin = -1, Option_t* option = "");
+         SingleMaximum.resize(hPeakOverlay->GetNbinsX());
+         for (int TimeSlice = 0; TimeSlice <= hPeakOverlay->GetNbinsX(); TimeSlice++ ){
+               TH1D* hProjPeak =	hPeakOverlay->ProjectionY("proj_py", TimeSlice, TimeSlice, "");
+               SingleMaximum[ TimeSlice ].maxAmpl = (hProjPeak->GetMaximumBin() * 0.5) - 55.5;
+               SingleMaximum[ TimeSlice ].countOfMax = hProjPeak->GetBinContent( hProjPeak->GetMaximumBin() );
+//               cout << "Timeslice:" << "\t" << "MaxAmplitude" << "\t" << "Counts" << "\t" << "max. Value on X Axis: " << endl;
+//               cout << TimeSlice << "\t \t" << SingleMaximum[ TimeSlice ].maxAmpl << "\t \t" << SingleMaximum[ TimeSlice ].countOfMax<< "\t \t"  << ((hProjPeak->GetNbinsX() * 0.5) -55.5)<< endl;
+               hMaxPeakOverlay->SetBinContent(TimeSlice, SingleMaximum[ TimeSlice ].maxAmpl );
+
+                 }
+
+        if (ProduceGraphic){
+            //OVERLAY PEAKS
+            cPeakOverlay->cd(1);
+            hPeakOverlay->Draw("COLZ");
+//            cPeakOverlay->Modified();
+//            cPeakOverlay->Update();
+            cPeakOverlay->cd(2);
+            hMaxPeakOverlay->Draw("");
+            cPeakOverlay->Modified();
+            cPeakOverlay->Update();
+
+//            cPixelPeakOverlay->cd();
+//            hPixelPeakOverlay->Draw("COLZ");
+//            cPixelPeakOverlay->Modified();
+//            cPixelPeakOverlay->Update();
+
+        }
+
+
+//        cPixelPeakOverlay->cd();
+//        hPixelPeakOverlay->Draw();
+//        cPixelPeakOverlay->Modified();
+//        cPixelPeakOverlay->Update();
 
         SaveHistograms( OutRootFileName );
@@ -393,10 +447,55 @@
                 debugHistos[ type ].GetYaxis()->SetTitle("Amplitude (a.u.)");
         }
-        hPeakOverlay = new TH2F("hPeakOverlay", "Overlay of detected Peaks", 
-					hPeakOverlayXaxisLeft + hPeakOverlayXaxisRight , (-1*hPeakOverlayXaxisLeft)-0.5, hPeakOverlayXaxisRight-0.5 ,
-					4096, -48.5, 1999.5 );
+/*
+        ProjHistos = new TH1D[ NumberOfTimeSlices ];
+        for ( int type = 0; type < NumberOfTimeSlices; type++){
+                ProjHistos[ type ].SetBins(1024, 0, 1024);
+                ProjHistos[ type ].SetLineColor(1);
+                ProjHistos[ type ].SetLineWidth(2);
+
+                // set X axis paras
+                ProjHistos[ type ].GetXaxis()->SetLabelSize(0.1);
+                ProjHistos[ type ].GetXaxis()->SetTitleSize(0.1);
+                ProjHistos[ type ].GetXaxis()->SetTitleOffset(1.2);
+                ProjHistos[ type ].GetXaxis()->SetTitle(Form("Time slice (%.1f ns/slice)", 1./2.));
+
+                // set Y axis paras
+                ProjHistos[ type ].GetYaxis()->SetLabelSize(0.1);
+                ProjHistos[ type ].GetYaxis()->SetTitleSize(0.1);
+                ProjHistos[ type ].GetYaxis()->SetTitleOffset(0.3);
+                ProjHistos[ type ].GetYaxis()->SetTitle("Amplitude (a.u.)");
+        }
+*/
+      hPeakOverlay = new TH2F("hPeakOverlay", "Overlay of detected Peaks",
+               hPeakOverlayXaxisLeft + hPeakOverlayXaxisRight , (-1*hPeakOverlayXaxisLeft)-0.5, hPeakOverlayXaxisRight-0.5 ,
+               512, -55.5, 200.5 );
         hPeakOverlay->GetXaxis()->SetTitle( "Timeslices" );
         hPeakOverlay->GetYaxis()->SetTitle( "Amplitude [a.u.]" );
+        //hPeakOverlay->SetBit(TH2F::kCanRebin);
         hList.Add( hPeakOverlay );
+
+      hMaxPeakOverlay = new TH1F("hMaxPeakOverlay", "Single Peak derived with Maximum of above Spektrum",
+               hPeakOverlayXaxisLeft + hPeakOverlayXaxisRight ,
+               (-1*hPeakOverlayXaxisLeft)-0.5,
+               hPeakOverlayXaxisRight-0.5
+                );
+        hMaxPeakOverlay->GetXaxis()->SetTitle( "Timeslices" );
+        hMaxPeakOverlay->GetYaxis()->SetTitle( "Amplitude [a.u.]" );
+        //hMaxPeakOverlay->SetBit(TH2F::kCanRebin);
+        hList.Add( hMaxPeakOverlay );
+
+//        hPixelPeakOverlay = new TH2F("hPixelPeakOverlay", "Maximum of Statistic of overlayed Peaks",
+//               hPeakOverlayXaxisLeft + hPeakOverlayXaxisRight , (-1*hPeakOverlayXaxisLeft)-0.5, hPeakOverlayXaxisRight-0.5 ,
+//               512, -55.5, 200.5 );
+//        hPixelPeakOverlay->GetXaxis()->SetTitle( "Timeslices" );
+//        hPixelPeakOverlay->GetYaxis()->SetTitle( "Amplitude [a.u.]" );
+//        hList.Add( hPixelPeakOverlay );
+
+        hEventPeakOverlay = new TH2F("hEventPeakOverlay", "Overlay of detected Peaks of all Pixel of one Event",
+               hPeakOverlayXaxisLeft + hPeakOverlayXaxisRight , (-1*hPeakOverlayXaxisLeft)-0.5, hPeakOverlayXaxisRight-0.5 ,
+               4096, -48.5, 200.5 );
+        hEventPeakOverlay->GetXaxis()->SetTitle( "Timeslices" );
+        hEventPeakOverlay->GetYaxis()->SetTitle( "Amplitude [a.u.]" );
+        hList.Add( hEventPeakOverlay );
 
 }
