Index: tools/ddd/Functions.cpp
===================================================================
--- tools/ddd/Functions.cpp	(revision 65)
+++ tools/ddd/Functions.cpp	(revision 66)
@@ -56,6 +56,12 @@
   BoardNo->setEnabled(true);
   PixelID->setEnabled(true);
+  M0Start->setEnabled(true);
+  M0Stop->setEnabled(true);
   EventNo->setValue(1);
   EventNo->setRange(1, RD->RHeader->Events);
+  M0Start->setValue(0);
+  M0Stop->setValue((RD->RHeader->Samples)-1);
+  M0Start->setRange(0,(RD->RHeader->Samples)-1);  
+  M0Stop->setRange(0,(RD->RHeader->Samples)-1);
   ChannelNo->setValue(0);
   ChannelNo->setRange(0, RD->RHeader->NChannels*RD->RHeader->NChips-1);
@@ -72,4 +78,6 @@
     BoardNo->setEnabled(false);
     PixelID->setEnabled(false);
+    M0Start->setEnabled(false);
+    M0Stop->setEnabled(false);
     RunHeaderDisplay->clear();
     EventHeaderDisplay->clear();
@@ -150,21 +158,17 @@
 	      int biny = 5-(((superpixel-1)%3)*2)-(int((pixel-1)/2));
 	      
-	      //search maximum sample amplitude within following window -> should not be hardcoded!
-	      int StartBin = 100;
-	      int StopBin = 120;
+	      //search maximum sample amplitude within user specified window
+	      //start bin is always smaller than stop bin (taken care of by updated ranges)
+	      int StartBin = (int)(M0Start->value());
+	      int StopBin = (int)(M0Stop->value());
 	      
-	      for(int l=StartBin; l<(StopBin+1); l++){
+	      for(int l=StartBin; l<=StopBin; l++){
+		  
+		float sample = *((short *) (RD->Data + RD->RHeader->NBoards*RD->RHeader->NChips*sizeof(int)) + 
+				 i*RD->RHeader->NChips*RD->RHeader->NChannels*RD->RHeader->Samples+
+				 j*RD->RHeader->NChannels*RD->RHeader->Samples+
+				 k*RD->RHeader->Samples+
+				 l)*RD->BStruct[i].ScaleFactor;
 		
-/* 		float sample = RD->Data[i*RD->RHeader->NChips*RD->RHeader->NChannels*RD->RHeader->Samples+
-					j*RD->RHeader->NChannels*RD->RHeader->Samples+
-					k*RD->RHeader->Samples+
-					l]*RD->BStruct[i].ScaleFactor;
- */
- 		float sample = *((short *) (RD->Data + RD->RHeader->NBoards*RD->RHeader->NChips*sizeof(int)) + 
-		    	    	    	i*RD->RHeader->NChips*RD->RHeader->NChannels*RD->RHeader->Samples+
-					j*RD->RHeader->NChannels*RD->RHeader->Samples+
-					k*RD->RHeader->Samples+
-					l)*RD->BStruct[i].ScaleFactor;
-				
 		if (sample > z[binx][biny]) {
 		  z[binx][biny]=sample;
@@ -172,5 +176,5 @@
 		
 	      }//sample loop
-	      
+
 	    }//only M0 data
 	    
@@ -185,4 +189,8 @@
       Graph2D->replot();
       //Signal2D->show();
+
+      //update ranges for start and stop bin to avoid startbin > stopbin
+      M0Start->setRange(0, M0Stop->value());  
+      M0Stop->setRange(M0Start->value(),(RD->RHeader->Samples)-1);
 
       delete[] x;	delete[] y;
Index: tools/ddd/GUI.cpp
===================================================================
--- tools/ddd/GUI.cpp	(revision 65)
+++ tools/ddd/GUI.cpp	(revision 66)
@@ -224,6 +224,22 @@
   Graph2D->setCanvasBackground(QColor(Qt::white));
 
+  M0Start = new QSpinBox(M0Window);
+  M0Start->setEnabled(false);
+  connect(M0Start, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
+  M0Start->setToolTip("First bin/sample of time window");
+  M0StartLayout = new QFormLayout;  
+  M0StartLayout->addRow("First Bin", M0Start);
+
+  M0Stop = new QSpinBox(M0Window);
+  M0Stop->setEnabled(false);
+  connect(M0Stop, SIGNAL(valueChanged(int)), this, SLOT(DisplayEvent(int)));
+  M0Stop->setToolTip("Last bin/sample of time window");
+  M0StopLayout = new QFormLayout;  
+  M0StopLayout->addRow("Last Bin", M0Stop);
+
   M0Layout = new QGridLayout(M0Window);
   M0Layout->addWidget(Graph2D, 1,1,3,3);
+  M0Layout->addLayout(M0StartLayout,4,1);
+  M0Layout->addLayout(M0StopLayout,4,2);
 
   Signal2D = new QwtPlotSpectrogram;
@@ -260,4 +276,5 @@
   // Layout items
   delete PortLayout;		delete CommandLayout;
+  delete M0StartLayout;         delete M0StopLayout;
   delete AddressLayout;		delete FormLayout;
   delete SpinLayout;
Index: tools/ddd/GUI.h
===================================================================
--- tools/ddd/GUI.h	(revision 65)
+++ tools/ddd/GUI.h	(revision 66)
@@ -32,5 +32,5 @@
     QToolButton *LoadButton;
     QLineEdit *FilenameBox, *IPAddress, *Command, *PixelID;
-    QSpinBox *EventNo, *ChannelNo, *BoardNo, *Port;
+    QSpinBox *EventNo, *ChannelNo, *BoardNo, *Port, *M0Start, *M0Stop;
     QPlainTextEdit *RunHeaderDisplay, *EventHeaderDisplay, *SocketOutput;
     QTabWidget *TabWidget;
@@ -39,5 +39,5 @@
     QAction *OpenAction, *ConnectAction;
     QGridLayout *SocketLayout, *MainLayout, *M0Layout;
-    QFormLayout *CommandLayout, *PortLayout, *AddressLayout, *FormLayout, *SpinLayout;
+    QFormLayout *CommandLayout, *PortLayout, *AddressLayout, *FormLayout, *SpinLayout, *M0StartLayout, *M0StopLayout;
     
     QwtPlot *Graph, *Graph2D;
