Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 595)
+++ trunk/MagicSoft/Mars/Changelog	(revision 596)
@@ -1,4 +1,17 @@
                                                                   -*-*- END -*-*-
  
+ 2000/02/06: Harald Kornmayer
+
+   *  the first running version with a eventdisplay. Now we are able
+      to display an Event on the photo electron level. To do this, run
+      the macro "macros/readCT1.C" after changing the file name. 
+
+      changed: 
+	macros/readCT1.C
+	manalysis/MNphotEvent.cc, manalysis/MNphotEvent.h
+	analysis/MReadCT1Ascii.cc
+	mgui/MCamDisplay.cc, mgui/MCamDisplay.h
+
+
  2000/01/23: Harald Kornmayer
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 595)
+++ trunk/MagicSoft/Mars/NEWS	(revision 596)
@@ -1,3 +1,10 @@
                                                                -*-*- END -*-*-
+ 2001/02/06:
+ 
+    * Now we are able to display events in a first version of the
+      Camera event display. To do this we must run the macro 
+      "macros/readCT1.C" to read data from CT1. 
+
+
  2001/01/11:
  
@@ -19,2 +26,3 @@
     * Put the first version of the Mars code into the repository
 
+
Index: trunk/MagicSoft/Mars/macros/readCT1.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readCT1.C	(revision 595)
+++ trunk/MagicSoft/Mars/macros/readCT1.C	(revision 596)
@@ -15,7 +15,7 @@
   
 
-  MReadCT1Ascii *readct1 = new MReadCT1Ascii("/hd10/www/Anal_MAGIC/MCCT1_99_ga20.dat") ; 
+  //MReadCT1Ascii *readct1 = new MReadCT1Ascii("/hd10/www/Anal_MAGIC/MCCT1_99_ga20.dat") ; 
 
-  // MReadCT1Ascii *readct1 = new MReadCT1Ascii("/hd10/www/Anal_MAGIC/CT1_99_on1.dat") ; 
+  MReadCT1Ascii *readct1 = new MReadCT1Ascii("/hd10/www/Anal_MAGIC/CT1_99_on1.dat") ; 
 
   cout << readct1->PreProcess(plist) << endl ; 
@@ -25,15 +25,21 @@
   MCamDisplay display(0) ; 
 
+  //display.SetAutoScale(kFALSE) ; 
+
   while ( readct1->Process() == kTRUE )
     {
       cout << "Event: " << icount++  << endl  ;
       
-      if ( icount == 3 ) 
+      if ( icount == 3 ) { 
 	phevt->Print() ;
-      
+      } 
+
       display->Draw( phevt )  ; 
+      // display->DrawError( phevt )  ; 
 
       gClient->HandleInput();   
-      if(getchar()=='e') break;  
+      
+      if(getchar()=='q')
+       	break;
     } 
 
Index: trunk/MagicSoft/Mars/manalysis/MNphotEvent.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MNphotEvent.cc	(revision 595)
+++ trunk/MagicSoft/Mars/manalysis/MNphotEvent.cc	(revision 596)
@@ -111,3 +111,50 @@
 { 
   return ( ( (MNphotPix *) fPixels->At(i))->GetPhotons() ) ; 
+}
+ 
+Float_t MNphotEvent::GetErrorPhot(Int_t i ) 
+{ 
+  return ( ( (MNphotPix *) fPixels->At(i))->GetErrorPhot() ) ; 
 } 
+
+
+Float_t MNphotEvent::GetMinimumPhoton() 
+{ 
+  if ( fNbPixels <= 0 ) 
+    return -5. ; 
+  
+  Float_t minWert ; 
+  minWert = ((MNphotPix *) fPixels->At(0))->GetPhotons() ; 
+
+  Float_t testWert ; 
+
+  for ( Int_t i =0 ; i<fNbPixels ; i++ ) { 
+    testWert = ((MNphotPix *) fPixels->At(i))->GetPhotons() ; 
+    
+    if ( minWert >= testWert ) 
+      minWert = testWert ; 
+  }
+
+  return  minWert ;
+} 
+
+Float_t MNphotEvent::GetMaximumPhoton() 
+{ 
+  if ( fNbPixels <= 0 ) 
+    return 50. ; 
+  
+  Float_t maxWert ; 
+  maxWert = ((MNphotPix *) fPixels->At(0))->GetPhotons() ; 
+
+  Float_t testWert ; 
+
+  for ( Int_t i =0 ; i<fNbPixels ; i++ ) { 
+    testWert = ((MNphotPix *) fPixels->At(i))->GetPhotons() ; 
+    
+    if ( maxWert <= testWert ) 
+      maxWert = testWert ; 
+  }
+
+  return  maxWert ;
+} 
+
Index: trunk/MagicSoft/Mars/manalysis/MNphotEvent.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MNphotEvent.h	(revision 595)
+++ trunk/MagicSoft/Mars/manalysis/MNphotEvent.h	(revision 596)
@@ -74,6 +74,10 @@
   Int_t GetPixelId(Int_t i ) ; 
   Float_t GetPhotons(Int_t i ) ; 
+  Float_t GetErrorPhot(Int_t i ) ; 
   
-    ClassDef(MNphotEvent, 1)    // class for Nphotons Events
+  Float_t GetMinimumPhoton()  ;  
+  Float_t GetMaximumPhoton()  ; 
+ 
+  ClassDef(MNphotEvent, 1)    // class for Nphotons Events
 };
 
Index: trunk/MagicSoft/Mars/manalysis/MReadCT1Ascii.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MReadCT1Ascii.cc	(revision 595)
+++ trunk/MagicSoft/Mars/manalysis/MReadCT1Ascii.cc	(revision 596)
@@ -80,5 +80,5 @@
       
       if ( dummyF > 0.0 ) { 
-	fNphot->AddPixel(i, dummyF, 0. ) ; 
+	fNphot->AddPixel(i, dummyF, sqrt(dummyF) ) ; 
       } 
       
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 595)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 596)
@@ -3,6 +3,8 @@
 #include <math.h>
 #include <TClonesArray.h>
-#include "TCanvas.h"
-#include "TStyle.h"
+#include <TCanvas.h>
+#include <TStyle.h>
+#include <TBox.h>
+#include <TText.h>
 
 #include "MHexagon.h"
@@ -17,6 +19,11 @@
 { 
   //    default constructor
-  
-
+
+  //    set the color palette 
+
+  gStyle->SetPalette(1,0) ; 
+
+  fAutoScale  = kTRUE ; 
+  
   MCamGeom *geometry  = new MCamGeom( type ) ; 
 
@@ -25,5 +32,4 @@
 
   //  create the hexagons of the display
-  // 
   
   TClonesArray &obj = *fPixels ; 
@@ -35,4 +41,34 @@
 			    geometry->GetR(i) ) ; 
     } 
+
+  // set the range to default
+
+  fMinPhe  = -2.  ; 
+  fMaxPhe  = 50. ; 
+
+  // set up the Legend 
+
+  fLegend = new TClonesArray("TBox", ITEMS_LEGEND ) ; 
+  TClonesArray &obj1 = *fLegend ; 
+
+  fLegText = new TClonesArray("TText", ITEMS_LEGEND ) ; 
+  TClonesArray &obj2 = *fLegText ; 
+  
+  char text[100] ; 
+
+  Float_t help ; 
+
+  help = 50. / ITEMS_LEGEND ; 
+
+  for ( Int_t il = 0 ; il < ITEMS_LEGEND ; il++ ) 
+    { 
+      new ( obj1[il] ) TBox(650, il*40-500 , 700, il*40-460 ) ; 
+      ( (TBox*) fLegend->At(il))->SetFillColor( GetColor ( (Float_t) help*il) ) ;
+  
+      sprintf ( text, "%5.1f",  (Float_t) help * il ) ; 
+      new ( obj2[il] ) TText(720, il*40-480, text ) ;
+      ( (TText*) fLegText->At(il))->SetTextSize (0.025) ; 
+      ( (TText*) fLegText->At(il))->SetTextAlign(12) ; 
+  } 
 } 
 
@@ -45,6 +81,11 @@
 void MCamDisplay::Init() 
 { 
-  if ( ! gPad ) new TCanvas("display", "MAGIC display", 0, 0, 600, 500) ;
-
+
+  // Set the right colors
+  
+  gStyle->SetPalette(1, 0) ; 
+
+  if ( ! gPad ) new TCanvas("display", "MAGIC display", 0, 0, 650, 500) ;
+  
   for (Int_t i=0; i< fNbPixels; i++) 
     { 
@@ -52,4 +93,12 @@
     } 
 
+  for (Int_t i=0; i< ITEMS_LEGEND; i++) 
+    { 
+      
+      ( (TBox*) fLegend->At(i))->Draw() ; 
+
+      ( (TText*) fLegText->At(i))->Draw() ; 
+    } 
+  
 } 
 
@@ -63,10 +112,8 @@
   if ( ! gPad ) Init() ; 
 
-  gPad->Range (-600, -600, 600, 600) ; 
+  gPad->Range (-600, -600, 900, 600) ; 
   gPad->SetFillColor(22) ; 
-  
-  gStyle->SetPalette(1, 0) ; 
-
-  
+
+  //
   
   gPad->Modified() ; 
@@ -77,4 +124,39 @@
 
 void MCamDisplay::Draw( MNphotEvent *event) 
+{
+
+  // loop over all pixels in the MNphotEvent and
+  // determine the Pixel Id and the content
+
+  Reset() ; 
+
+  //  if the autoscale is true, set the values for the range for 
+  //  each event 
+  
+  if ( fAutoScale == kTRUE ) 
+    { 
+      fMinPhe = event->GetMinimumPhoton() ; 
+      fMaxPhe = event->GetMaximumPhoton() ;
+
+      if ( fMaxPhe < 20. ) fMaxPhe = 20. ; 
+
+
+      UpdateLegend() ; 
+    }  
+  
+
+ 
+  cout << fMinPhe << "/" << fMaxPhe << endl ; 
+
+  for (Int_t i=0 ; i<event->GetNbPixels() ; i++ )
+    {
+      ( (MHexagon*) fPixels->At( event->GetPixelId(i) ))->SetFillColor( GetColor(event->GetPhotons(i))) ; 
+    } 
+  
+  Draw() ; 
+  
+}  
+
+void MCamDisplay::DrawError( MNphotEvent *event) 
 {
   // 
@@ -86,5 +168,5 @@
   for (Int_t i=0 ; i<event->GetNbPixels() ; i++ )
     {
-      ( (MHexagon*) fPixels->At( event->GetPixelId(i) ))->SetFillColor((Int_t) event->GetPhotons(i)) ; 
+      ( (MHexagon*) fPixels->At( event->GetPixelId(i) ))->SetFillColor( GetColor(event->GetErrorPhot(i)) ) ; 
     } 
   
@@ -103,10 +185,58 @@
 } 
 
-void MCamDisplay::TestColor() 
-{
-  for ( Int_t i=0 ; i< 500 ; i++  )
-    { 
-      ( (MHexagon*) fPixels->At(i))->SetFillColor(i) ;
-    } 
-
-} 
+Int_t MCamDisplay::GetColor(Float_t wert ) 
+{
+  //   Here we calculate the color index for the current value. 
+  //   The color index is defined with the class TStyle and the 
+  //   Color palette inside. We use the command gStyle->SetPalette(1,0) 
+  //   for the display. So we have to convert the value "wert" into
+  //   a color index that fits the color palette. 
+  //   The range of the color palette is defined by the values fMinPhe 
+  //   and fMaxRange. Between this values we have 50 color index, starting
+  //   with 0 up to 49. 
+  // 
+
+  //   first treat the over- and under-flows
+
+  if ( wert >= fMaxPhe ) 
+    return gStyle->GetColorPalette( 49 )   ; 
+
+  if ( wert <= fMinPhe ) 
+    return gStyle->GetColorPalette( 0 )  ;
+
+  // calculate the color index 
+
+  Int_t ColIndex ; 
+
+  ColIndex =  (Int_t) wert ; 
+  
+  ColIndex =  (Int_t) ( .5 + ( (wert-fMinPhe) * 49. / (fMaxPhe-fMinPhe) ) ) ; 
+
+  return (gStyle->GetColorPalette(ColIndex) ) ; 
+
+} 
+
+
+void MCamDisplay::UpdateLegend() 
+{ 
+  //    change the text on the legend according to the range of the 
+  //    Display
+  
+  char text[100] ; 
+  
+  Float_t x, y, wert,  help ;
+  
+  help = 50./ITEMS_LEGEND ;  
+  
+  for (Int_t il=0; il < ITEMS_LEGEND; il++)
+    { 
+      wert = fMinPhe + (il*help)/50 * (fMaxPhe-fMinPhe) ; 
+      
+      sprintf ( text, "%5.1f", wert ) ; 
+      
+      x = ( (TText*) fLegText->At(il))->GetX () ; 
+      y = ( (TText*) fLegText->At(il))->GetY () ; 
+      ( (TText*) fLegText->At(il))->SetText (x, y,  text ) ; 
+    }  
+  
+} 
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 595)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 596)
@@ -6,4 +6,6 @@
 #include "MAGIC.h"
 
+#define   ITEMS_LEGEND         25 
+
 class TClonesArray ; 
 class MNphotEvent  ; 
@@ -12,7 +14,15 @@
 {
  private: 
+  Bool_t        fAutoScale ;  //  indicating the autoscale function
+  
   Int_t         fNbPixels ;   // 
   TClonesArray  *fPixels   ;  //!
-  
+
+  Float_t       fMinPhe ;     //  The minimal number of Phe
+  Float_t       fMaxPhe ;     //  The maximum number of Phe 
+
+  TClonesArray  *fLegend  ;    //! 
+  TClonesArray  *fLegText ;    //! 
+
  public:
   
@@ -24,15 +34,23 @@
 
   void Draw(Option_t *option = "" ) ; 
-  
+
   void Draw( MNphotEvent *event) ; 
+  void DrawError( MNphotEvent *event) ; 
 
   void Reset() ; 
-  void TestColor() ; 
+
+  Int_t GetColor( Float_t wert ) ; 
+
+  void UpdateLegend() ;  
+
+  void SetAutoScale (Bool_t input = kTRUE ) 
+    { 
+      fAutoScale = input ; 
+    } 
 
   //Int_t    GetNbPixels() ; 
-    
+  
   ClassDef(MCamDisplay, 1)		// Base (abstract) class for a task
 };
 
 #endif
-
