Index: fact/tools/rootmacros/fpeak_cdf.C
===================================================================
--- fact/tools/rootmacros/fpeak_cdf.C	(revision 12369)
+++ fact/tools/rootmacros/fpeak_cdf.C	(revision 12371)
@@ -82,12 +82,6 @@
 						// x = pixel id, y = DRS cell id
 
-TH1F *hBaseline[ NPIX ]; // histograms for baseline extraction
-TH1F *hMeanBsl, *hpltMeanBsl;
-TH1F *hRmsBsl, *hpltRmsBsl; 
 TH2F * hAmplSpek_cfd;
-TH2F * hAmplSpek_discri;
-TH2F * hTemp_Array[1441];
 TObjArray hList;
-TObjArray hListBaseline, hListTemplates;
 
 void BookHistos( );
@@ -103,7 +97,7 @@
 //	* compute pulse height and pulse integral spektrum of the peaks
 int fpeak(
-	char *datafilename 		= "../../20111011_055.fits.gz",
-	const char *drsfilename = "../../20111011_054.drs.fits.gz",
-	const char *OutRootFileName = "./fpeak_cdf.Coutput.root",
+	char *datafilename 		= "data/20111016_013.fits.gz",
+	const char *drsfilename = "../../20111016_011.drs.fits.gz",
+	const char *OutRootFileName = "../analysis/fpeak_cdf.Coutput.root",
 	int firstevent 			= 0,
 	int nevents 			= -1,
@@ -111,5 +105,8 @@
 	int npixel				= -1,
 	bool spikeDebug = false,
-	int verbosityLevel = 1 // different verbosity levels can be implemented here
+	int avg1		= 14,
+	int avg2 		= 8,
+	int verbosityLevel = 1, // different verbosity levels can be implemented here
+	bool ProduceGraphic = true
 	)
 {
@@ -117,25 +114,8 @@
 gROOT->SetStyle("Plain");
 
-// Create (pointer to) Canvases, which are used in every run,
-// also in 'non-debug' runs
-	TCanvas * cSpektrum;
-	TCanvas * cStartCell;
-	TCanvas *cTemplate;
-	cSpektrum = new TCanvas("cSpektrum","Amplitude Spektra of different discriminators",10,10,400,400);
-	cSpektrum->Divide(1,2);
-	cStartCell = new TCanvas("cStartCell ", "The Startcells of this run", 10,410,400,400);
-	cTemplate = new TCanvas("cTemplate","Template of current Pixel",1,1,1600,1000);
-
-	// Canvases only need if spike Debug, but I want to deklare
-	// the pointers anyway ...
-	TCanvas *cRawAndSpikeRemoval = NULL;
 	TCanvas *cFiltered = NULL;
-
-
 	if (spikeDebug){
-		cRawAndSpikeRemoval = new TCanvas("cRawAndSpikeRemoval","DRS Waveform",410,10,400,400);
-		cRawAndSpikeRemoval->Divide(1, 2);
 		cFiltered = new TCanvas("cFiltered","filtered DRS Waveforms",410,410,400,400);
-		cFiltered->Divide(1, 2);
+		cFiltered->Divide(1, 3);
 	}
 
@@ -188,7 +168,6 @@
 		for ( int pix = firstpixel; pix < firstpixel+npixel; pix++ ){
 			if (verbosityLevel > 0){
-				if (pix % 20 ==0){
-					cout << "Processing Event number: " << CurrentEventID << "\t"
-						<< "Pixel number: "<< pix << endl;
+				if (pix == firstpixel){
+					cout << "Processing Event: " << CurrentEventID << "/" << nevents << endl;
 				}
 			}
@@ -205,11 +184,9 @@
 
 			// filter Vcorr with sliding average using FIR filter function
-			//factfir(b_slide , a_slide, k_slide, Vcorr, Vslide);
-			sliding_avg(Vcorr, Vslide, 8);
+			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
-			//factfir(bs2 , as2, ks2, Vcfd, Vcfd2);
-			sliding_avg(Vcfd, Vcfd2, 8);
+			sliding_avg(Vcfd, Vcfd2, avg2);
 
 
@@ -220,9 +197,8 @@
 			vector<Region> * zXings = zerosearch( Vcfd2 , 1 , 8);
 			// zXings means "zero cross ings"
-			//ShiftRegionBy(*zXings, -ks2/2);
-			EnlargeRegion(*zXings, 10, 10);
-			findAbsMaxInRegions(*zXings, Vslide);
-			//removeMaximaBelow( *zXings, 11.0, 0);
-			//removeMaximaAbove( *zXings, 14.0, 0);
+			EnlargeRegion( *zXings, 10, 10);
+			findAbsMaxInRegions( *zXings, Vslide);
+			removeMaximaBelow( *zXings, 3.0, 0);
+			removeRegionOnFallingEdge( *zXings, 100);
 
 			// fill maxima in Histogram
@@ -234,9 +210,4 @@
 					}
 					hAmplSpek_cfd->Fill(pix, zXings->at(i).maxVal);
-
-					for (int j=-100; j<150; j++){
-						if (zXings->at(i).maxPos + j >= 0 && zXings->at(i).maxPos + j <= 1023)
-							hTemp_Array[pix]->Fill(j+101, Vslide[zXings->at(i).maxPos + j]);
-					}
 				}
 			}
@@ -250,13 +221,9 @@
 				}
 
-				cRawAndSpikeRemoval->cd( 1);
-				gPad->SetGrid();
-				debugHistos[Ameas_].Draw();
-
-				cRawAndSpikeRemoval->cd( 2);
+				cFiltered->cd(1);
 				gPad->SetGrid();
 				debugHistos[Vcorr_].Draw();
 
-				cFiltered->cd(1);
+				cFiltered->cd(2);
 				gPad->SetGrid();
 				debugHistos[Vslide_].Draw();
@@ -278,5 +245,5 @@
 				}
 
-				cFiltered->cd(2);
+				cFiltered->cd(3);
 				gPad->SetGrid();
 				debugHistos[Vcfd2_].Draw();
@@ -285,12 +252,5 @@
 				zeroline->Draw();
 
-				cRawAndSpikeRemoval->Update();
 				cFiltered->Update();
-
-				cTemplate->cd();
-				hTemp_Array[pix]->Draw("COLZ");
-				cTemplate->Modified();
-				cTemplate->Update();
-
 				//Process gui events asynchronously during input
 				TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
@@ -304,6 +264,4 @@
 				//TODO!!!!!!!!!
 				// do some Garbage collection ...
-				// all the Objects on the heap should be deleted here.
-
 			}// end of if(spikeDebug)
 
@@ -314,34 +272,17 @@
 		} // end of loop over pixels
 
-if (ev % 10 == 0){
-		cSpektrum->cd(1);
-		hAmplSpek_cfd->Draw("COLZ");
-		cSpektrum->cd(2);
-		hAmplSpek_discri->Draw("COLZ");
-		cSpektrum->Modified();
-		cSpektrum->Update();
-
-		// updating seems not to work ..
-		// debug cout
-		cStartCell->cd();
-		hStartCell->Draw();
-		cStartCell->Modified();
-		cStartCell->Update();
-
-		cTemplate->cd();
-		hTemp_Array[firstpixel]->GetYaxis()->SetRangeUser(-10,40);
-		hTemp_Array[firstpixel]->Draw("COLZ");
-		cTemplate->Modified();
-		cTemplate->Update();
-}
-
-
 		if (breakout)
 			break;
 	}	// end of loop over pixels
-
-
+if (ProduceGraphic){
+	TCanvas * cSpektrum;
+	cSpektrum = new TCanvas("cSpektrum","Amplitude Spektra of different discriminators",10,10,400,400);
+	cSpektrum->Divide(1,1);
+  cSpektrum->cd(1);
+  hAmplSpek_cfd->Draw("COLZ");
+  cSpektrum->Modified();
+  cSpektrum->Update();
+}
 	SaveHistograms( OutRootFileName );
-
 	return( 0 );
 }
@@ -412,45 +353,8 @@
 void BookHistos( ){
 	// histograms for baseline extraction
-	char hName[500];
-	char hTitle[500];
 
 	TString name,title;
 	title = "all events all slices of pixel ";
 	name = "base";
-	TH1F *h;
-
-	for( int i = 0; i < NPIX; i++ ) {
-		title += i;
-		name += i;
-//		sprintf(&hTitle[0],"all events all slices of pixel %d", i);
-//		sprintf(&hName[0],"base%d", i);
-
-		h = new TH1F( name, title, 400, -99.5 ,100.5 );
-
-		h->GetXaxis()->SetTitle( "Sample value (mV)" );
-		h->GetYaxis()->SetTitle( "Entries / 0.5 mV" );
-		hListBaseline.Add( h );
-		hBaseline[i] = h;
-	}
-
-    hMeanBsl = new TH1F("histo_mean","Value of maximal probability",400,-99.5,100.5);
-    hMeanBsl->GetXaxis()->SetTitle( "max value (mV)" );
-    hMeanBsl->GetYaxis()->SetTitle( "Entries / 0.5 mV" );
-    hList.Add( hMeanBsl );
-
-    hpltMeanBsl = new TH1F("hplt_mean","Value of maximal probability",1440,-0.5,1439.5);
-    hpltMeanBsl->GetXaxis()->SetTitle( "pixel" );
-    hpltMeanBsl->GetYaxis()->SetTitle( "max value in mV" );
-    hList.Add( hpltMeanBsl );
-
-    hRmsBsl = new TH1F("histo_rms","RMS in mV",2000,-99.5,100.5);
-    hRmsBsl->GetXaxis()->SetTitle( "RMS (mV)" );
-    hRmsBsl->GetYaxis()->SetTitle( "Entries / 0.5 mV" );
-    hList.Add( hRmsBsl );
-
-    hpltRmsBsl = new TH1F("hplt_rms","Value of maximal probability",1440,-0.5,1439.5);
-    hpltRmsBsl->GetXaxis()->SetTitle( "pixel" );
-    hpltRmsBsl->GetYaxis()->SetTitle( "RMS in mV" );
-    hList.Add( hpltRmsBsl );
 
 	hAmplSpek_cfd = new TH2F("hAmplSpek_cfd","amplitude spektrum - CFD",1440,-0.5,1439.5, 256, -27.5, 100.5);
@@ -459,8 +363,4 @@
 	hList.Add( hAmplSpek_cfd );
 
-	hAmplSpek_discri = new TH2F("hAmplSpek_discri","amplitude spektrum - std discriminator",1440,-0.5,1439.5, 256, -27.5, 100.5);
-	hAmplSpek_discri->GetXaxis()->SetTitle( "pixel" );
-	hAmplSpek_discri->GetXaxis()->SetTitle( "amplitude in mV" );
-	hList.Add( hAmplSpek_discri );
 
 	debugHistos = new TH1F[ NumberOfDebugHistoTypes ];
@@ -482,19 +382,4 @@
 		debugHistos[ type ].GetYaxis()->SetTitle("Amplitude (a.u.)");
 	}
-
-	TH2F *temp;
-	for ( int type = 0; type < 1441; type++){
-		sprintf(&hTitle[0],"pulse template of pixel %d", type );
-		sprintf(&hName[0],"template_%d", type );
-
-		temp = new TH2F( hName, hTitle, 256, 0, 255, 256, -10.5, 117.5);
-
-		temp->GetXaxis()->SetTitle( "Time slice (%.1f ns/slice)" );
-		temp->GetYaxis()->SetTitle( "Amplitude (about mV)" );
-		hListTemplates.Add( temp );
-		hTemp_Array[ type ] = temp;
-	}
-
-
 }
 
@@ -504,12 +389,5 @@
 
 	hList.Write(); // write the major histograms into the top level directory
-	tf.mkdir("BaselineHisto");
-	tf.cd("BaselineHisto"); // go to new subdirectory
-	hListBaseline.Write(); // write histos into subdirectory
-	tf.cd("..");
-	tf.mkdir("PulseTempplates");
-	tf.cd("PulseTemplates");
-	hListTemplates.Write(); // write histos into subdirectory
 
 	tf.Close(); // close the file
-} // end of SaveHistograms(const char * loc_fname )
+}
