Changeset 596 for trunk/MagicSoft/Mars/mgui
- Timestamp:
- 02/06/01 09:44:16 (24 years ago)
- Location:
- trunk/MagicSoft/Mars/mgui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
r595 r596 3 3 #include <math.h> 4 4 #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> 7 9 8 10 #include "MHexagon.h" … … 17 19 { 18 20 // default constructor 19 20 21 22 // set the color palette 23 24 gStyle->SetPalette(1,0) ; 25 26 fAutoScale = kTRUE ; 27 21 28 MCamGeom *geometry = new MCamGeom( type ) ; 22 29 … … 25 32 26 33 // create the hexagons of the display 27 //28 34 29 35 TClonesArray &obj = *fPixels ; … … 35 41 geometry->GetR(i) ) ; 36 42 } 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 } 37 73 } 38 74 … … 45 81 void MCamDisplay::Init() 46 82 { 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 49 90 for (Int_t i=0; i< fNbPixels; i++) 50 91 { … … 52 93 } 53 94 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 54 103 } 55 104 … … 63 112 if ( ! gPad ) Init() ; 64 113 65 gPad->Range (-600, -600, 600, 600) ;114 gPad->Range (-600, -600, 900, 600) ; 66 115 gPad->SetFillColor(22) ; 67 68 gStyle->SetPalette(1, 0) ; 69 70 116 117 // 71 118 72 119 gPad->Modified() ; … … 77 124 78 125 void 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 160 void MCamDisplay::DrawError( MNphotEvent *event) 79 161 { 80 162 // … … 86 168 for (Int_t i=0 ; i<event->GetNbPixels() ; i++ ) 87 169 { 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)) ) ; 89 171 } 90 172 … … 103 185 } 104 186 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 } 187 Int_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 220 void 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 6 6 #include "MAGIC.h" 7 7 8 #define ITEMS_LEGEND 25 9 8 10 class TClonesArray ; 9 11 class MNphotEvent ; … … 12 14 { 13 15 private: 16 Bool_t fAutoScale ; // indicating the autoscale function 17 14 18 Int_t fNbPixels ; // 15 19 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 17 27 public: 18 28 … … 24 34 25 35 void Draw(Option_t *option = "" ) ; 26 36 27 37 void Draw( MNphotEvent *event) ; 38 void DrawError( MNphotEvent *event) ; 28 39 29 40 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 } 31 50 32 51 //Int_t GetNbPixels() ; 33 52 34 53 ClassDef(MCamDisplay, 1) // Base (abstract) class for a task 35 54 }; 36 55 37 56 #endif 38
Note:
See TracChangeset
for help on using the changeset viewer.