Ignore:
Timestamp:
02/06/01 09:44:16 (24 years ago)
Author:
harald
Message:
Now the first version of the Camera eventdisplay is running.
Run the macro "readCT1.C" to have a look.
Location:
trunk/MagicSoft/Mars/mgui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mgui/MCamDisplay.cc

    r595 r596  
    33#include <math.h>
    44#include <TClonesArray.h>
    5 #include "TCanvas.h"
    6 #include "TStyle.h"
     5#include <TCanvas.h>
     6#include <TStyle.h>
     7#include <TBox.h>
     8#include <TText.h>
    79
    810#include "MHexagon.h"
     
    1719{
    1820  //    default constructor
    19  
    20 
     21
     22  //    set the color palette
     23
     24  gStyle->SetPalette(1,0) ;
     25
     26  fAutoScale  = kTRUE ;
     27 
    2128  MCamGeom *geometry  = new MCamGeom( type ) ;
    2229
     
    2532
    2633  //  create the hexagons of the display
    27   //
    2834 
    2935  TClonesArray &obj = *fPixels ;
     
    3541                            geometry->GetR(i) ) ;
    3642    }
     43
     44  // set the range to default
     45
     46  fMinPhe  = -2.  ;
     47  fMaxPhe  = 50. ;
     48
     49  // set up the Legend
     50
     51  fLegend = new TClonesArray("TBox", ITEMS_LEGEND ) ;
     52  TClonesArray &obj1 = *fLegend ;
     53
     54  fLegText = new TClonesArray("TText", ITEMS_LEGEND ) ;
     55  TClonesArray &obj2 = *fLegText ;
     56 
     57  char text[100] ;
     58
     59  Float_t help ;
     60
     61  help = 50. / ITEMS_LEGEND ;
     62
     63  for ( Int_t il = 0 ; il < ITEMS_LEGEND ; il++ )
     64    {
     65      new ( obj1[il] ) TBox(650, il*40-500 , 700, il*40-460 ) ;
     66      ( (TBox*) fLegend->At(il))->SetFillColor( GetColor ( (Float_t) help*il) ) ;
     67 
     68      sprintf ( text, "%5.1f",  (Float_t) help * il ) ;
     69      new ( obj2[il] ) TText(720, il*40-480, text ) ;
     70      ( (TText*) fLegText->At(il))->SetTextSize (0.025) ;
     71      ( (TText*) fLegText->At(il))->SetTextAlign(12) ;
     72  }
    3773}
    3874
     
    4581void MCamDisplay::Init()
    4682{
    47   if ( ! gPad ) new TCanvas("display", "MAGIC display", 0, 0, 600, 500) ;
    48 
     83
     84  // Set the right colors
     85 
     86  gStyle->SetPalette(1, 0) ;
     87
     88  if ( ! gPad ) new TCanvas("display", "MAGIC display", 0, 0, 650, 500) ;
     89 
    4990  for (Int_t i=0; i< fNbPixels; i++)
    5091    {
     
    5293    }
    5394
     95  for (Int_t i=0; i< ITEMS_LEGEND; i++)
     96    {
     97     
     98      ( (TBox*) fLegend->At(i))->Draw() ;
     99
     100      ( (TText*) fLegText->At(i))->Draw() ;
     101    }
     102 
    54103}
    55104
     
    63112  if ( ! gPad ) Init() ;
    64113
    65   gPad->Range (-600, -600, 600, 600) ;
     114  gPad->Range (-600, -600, 900, 600) ;
    66115  gPad->SetFillColor(22) ;
    67  
    68   gStyle->SetPalette(1, 0) ;
    69 
    70  
     116
     117  //
    71118 
    72119  gPad->Modified() ;
     
    77124
    78125void MCamDisplay::Draw( MNphotEvent *event)
     126{
     127
     128  // loop over all pixels in the MNphotEvent and
     129  // determine the Pixel Id and the content
     130
     131  Reset() ;
     132
     133  //  if the autoscale is true, set the values for the range for
     134  //  each event
     135 
     136  if ( fAutoScale == kTRUE )
     137    {
     138      fMinPhe = event->GetMinimumPhoton() ;
     139      fMaxPhe = event->GetMaximumPhoton() ;
     140
     141      if ( fMaxPhe < 20. ) fMaxPhe = 20. ;
     142
     143
     144      UpdateLegend() ;
     145    } 
     146 
     147
     148 
     149  cout << fMinPhe << "/" << fMaxPhe << endl ;
     150
     151  for (Int_t i=0 ; i<event->GetNbPixels() ; i++ )
     152    {
     153      ( (MHexagon*) fPixels->At( event->GetPixelId(i) ))->SetFillColor( GetColor(event->GetPhotons(i))) ;
     154    }
     155 
     156  Draw() ;
     157 
     158
     159
     160void MCamDisplay::DrawError( MNphotEvent *event)
    79161{
    80162  //
     
    86168  for (Int_t i=0 ; i<event->GetNbPixels() ; i++ )
    87169    {
    88       ( (MHexagon*) fPixels->At( event->GetPixelId(i) ))->SetFillColor((Int_t) event->GetPhotons(i)) ;
     170      ( (MHexagon*) fPixels->At( event->GetPixelId(i) ))->SetFillColor( GetColor(event->GetErrorPhot(i)) ) ;
    89171    }
    90172 
     
    103185}
    104186
    105 void MCamDisplay::TestColor()
    106 {
    107   for ( Int_t i=0 ; i< 500 ; i++  )
    108     {
    109       ( (MHexagon*) fPixels->At(i))->SetFillColor(i) ;
    110     }
    111 
    112 }
     187Int_t MCamDisplay::GetColor(Float_t wert )
     188{
     189  //   Here we calculate the color index for the current value.
     190  //   The color index is defined with the class TStyle and the
     191  //   Color palette inside. We use the command gStyle->SetPalette(1,0)
     192  //   for the display. So we have to convert the value "wert" into
     193  //   a color index that fits the color palette.
     194  //   The range of the color palette is defined by the values fMinPhe
     195  //   and fMaxRange. Between this values we have 50 color index, starting
     196  //   with 0 up to 49.
     197  //
     198
     199  //   first treat the over- and under-flows
     200
     201  if ( wert >= fMaxPhe )
     202    return gStyle->GetColorPalette( 49 )   ;
     203
     204  if ( wert <= fMinPhe )
     205    return gStyle->GetColorPalette( 0 )  ;
     206
     207  // calculate the color index
     208
     209  Int_t ColIndex ;
     210
     211  ColIndex =  (Int_t) wert ;
     212 
     213  ColIndex =  (Int_t) ( .5 + ( (wert-fMinPhe) * 49. / (fMaxPhe-fMinPhe) ) ) ;
     214
     215  return (gStyle->GetColorPalette(ColIndex) ) ;
     216
     217}
     218
     219
     220void MCamDisplay::UpdateLegend()
     221{
     222  //    change the text on the legend according to the range of the
     223  //    Display
     224 
     225  char text[100] ;
     226 
     227  Float_t x, y, wert,  help ;
     228 
     229  help = 50./ITEMS_LEGEND ; 
     230 
     231  for (Int_t il=0; il < ITEMS_LEGEND; il++)
     232    {
     233      wert = fMinPhe + (il*help)/50 * (fMaxPhe-fMinPhe) ;
     234     
     235      sprintf ( text, "%5.1f", wert ) ;
     236     
     237      x = ( (TText*) fLegText->At(il))->GetX () ;
     238      y = ( (TText*) fLegText->At(il))->GetY () ;
     239      ( (TText*) fLegText->At(il))->SetText (x, y,  text ) ;
     240    } 
     241 
     242}
  • trunk/MagicSoft/Mars/mgui/MCamDisplay.h

    r595 r596  
    66#include "MAGIC.h"
    77
     8#define   ITEMS_LEGEND         25
     9
    810class TClonesArray ;
    911class MNphotEvent  ;
     
    1214{
    1315 private:
     16  Bool_t        fAutoScale ;  //  indicating the autoscale function
     17 
    1418  Int_t         fNbPixels ;   //
    1519  TClonesArray  *fPixels   ;  //!
    16  
     20
     21  Float_t       fMinPhe ;     //  The minimal number of Phe
     22  Float_t       fMaxPhe ;     //  The maximum number of Phe
     23
     24  TClonesArray  *fLegend  ;    //!
     25  TClonesArray  *fLegText ;    //!
     26
    1727 public:
    1828 
     
    2434
    2535  void Draw(Option_t *option = "" ) ;
    26  
     36
    2737  void Draw( MNphotEvent *event) ;
     38  void DrawError( MNphotEvent *event) ;
    2839
    2940  void Reset() ;
    30   void TestColor() ;
     41
     42  Int_t GetColor( Float_t wert ) ;
     43
     44  void UpdateLegend() ; 
     45
     46  void SetAutoScale (Bool_t input = kTRUE )
     47    {
     48      fAutoScale = input ;
     49    }
    3150
    3251  //Int_t    GetNbPixels() ;
    33    
     52 
    3453  ClassDef(MCamDisplay, 1)              // Base (abstract) class for a task
    3554};
    3655
    3756#endif
    38 
Note: See TracChangeset for help on using the changeset viewer.