Changeset 653 for trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
- Timestamp:
- 03/01/01 15:42:32 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
r602 r653 2 2 3 3 #include <math.h> 4 4 5 #include <TClonesArray.h> 5 6 #include <TCanvas.h> … … 9 10 10 11 #include "MHexagon.h" 11 #include "M CamGeom.h"12 #include "MGeomCam.h" 12 13 13 14 #include "MCerPhotEvt.h" 14 15 16 #define kITEMS_LEGEND 25 15 17 16 18 ClassImp(MCamDisplay) 17 19 18 MCamDisplay::MCamDisplay (Int_t type ) 20 MCamDisplay::MCamDisplay (Int_t type ) : fAutoScale(kTRUE) 19 21 { 20 // default constructor 21 22 // set the color palette 23 24 gStyle->SetPalette(1,0) ; 25 26 fAutoScale = kTRUE ; 27 28 MCamGeom *geometry = new MCamGeom( type ) ; 29 30 fNbPixels = geometry->GetNbPixels() ; 31 fPixels = new TClonesArray("MHexagon", fNbPixels ) ; 32 33 // create the hexagons of the display 34 35 TClonesArray &obj = *fPixels ; 36 37 for (Int_t i=0; i< fNbPixels; i++ ) 38 { 39 new (obj[i]) MHexagon(geometry->GetX(i) , 40 geometry->GetY(i) , 41 geometry->GetR(i) ) ; 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 } 73 } 22 // default constructor 23 24 // 25 // create a object which contains the camera geometry 26 // 27 MGeomCam geom(type) ; 28 29 // 30 // set the color palette 31 // 32 gStyle->SetPalette(1,0) ; 33 34 // 35 // create the hexagons of the display 36 // 37 fNbPixels = geom.GetNbPixels() ; 38 fPixels = new TClonesArray("MHexagon", fNbPixels ) ; 39 40 for (Int_t i=0; i< fNbPixels; i++ ) 41 { 42 (*fPixels)[i] = new MHexagon(geom[i]) ; 43 } 44 45 // 46 // set the range to default 47 // 48 fMinPhe = -2. ; 49 fMaxPhe = 50. ; 50 51 // 52 // set up the Legend 53 // 54 fLegend = new TClonesArray("TBox", kITEMS_LEGEND ) ; 55 fLegText = new TClonesArray("TText", kITEMS_LEGEND ) ; 56 57 char text[10] ; 58 for ( Int_t il = 0 ; il < kITEMS_LEGEND ; il++ ) 59 { 60 const Int_t y = il*40; 61 62 TBox *newbox = new TBox (650, y-500, 700, y-460 ); 63 TText *newtxt = new TText(720, y-480, text ); 64 65 const Float_t lvl = 50. / kITEMS_LEGEND * il; 66 67 newbox->SetFillColor( GetColor(lvl) ); 68 69 sprintf ( text, "%5.1f", lvl ) ; 70 71 newtxt->SetTextSize (0.025) ; 72 newtxt->SetTextAlign(12) ; 73 74 (*fLegend) [il] = newbox; 75 (*fLegText)[il] = newtxt; 76 } 77 } 74 78 75 79 MCamDisplay::~MCamDisplay() 76 80 { 77 delete fPixels ;78 } 81 delete fPixels ; 82 } 79 83 80 84 81 85 void MCamDisplay::Init() 82 86 { 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 90 for (Int_t i=0; i< fNbPixels; i++) 91 { 92 ( (MHexagon*) fPixels->At(i))->Draw() ; 93 } 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 87 // 88 // Set the right colors 89 // 90 gStyle->SetPalette(1, 0) ; 91 92 // 93 // if no canvas is yet existing to draw into, create a new one 94 // 95 if ( !gPad ) new TCanvas("display", "MAGIC display", 0, 0, 650, 500) ; 96 97 // 98 // draw all pixels of the camera 99 // 100 for (Int_t i=0; i< fNbPixels; i++) 101 (*this)[i].Draw(); 102 103 // 104 // draw legend 105 // 106 for (Int_t i=0; i< kITEMS_LEGEND; i++) 107 { 108 GetBox(i)->Draw(); 109 GetText(i)->Draw(); 110 } 103 111 } 104 112 … … 108 116 // 109 117 110 // check if there a pad exists 111 112 if ( ! gPad ) Init() ; 113 114 gPad->Range (-600, -600, 900, 600) ; 115 gPad->SetFillColor(22) ; 116 117 // 118 119 gPad->Modified() ; 120 gPad->Update() ; 121 122 //gPad->Update() ; 118 // 119 // check if there a pad exists, if not create one 120 // 121 if ( !gPad ) Init() ; 122 123 // 124 // set init values 125 // 126 gPad->Range (-600, -600, 900, 600) ; 127 gPad->SetFillColor(22) ; 128 129 // 130 // mark pad as modified and update screen 131 // 132 gPad->Modified() ; 133 gPad->Update() ; 123 134 } 124 135 125 void MCamDisplay::Draw( MCerPhotEvt *event) 126 { 127 128 // loop over all pixels in the MCerPhotEvt 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 // update the picture 148 149 for (Int_t i=0 ; i<event->GetNbPixels() ; i++ ) 150 { 151 if ( event->IsPixelUsed(i) == kTRUE ) 152 ( (MHexagon*) fPixels->At( event->GetPixelId(i) ))->SetFillColor( GetColor(event->GetPhotons(i))) ; 153 154 } 155 156 Draw() ; 157 136 void MCamDisplay::DrawPhotNum( MCerPhotEvt *event) 137 { 138 139 // 140 // loop over all pixels in the MCerPhotEvt and 141 // determine the Pixel Id and the content 142 // 143 Reset() ; 144 145 // 146 // if the autoscale is true, set the values for the range for 147 // each event 148 // 149 if ( fAutoScale ) 150 { 151 fMinPhe = event->GetMinNumPhotons() ; 152 fMaxPhe = event->GetMaxNumPhotons() ; 153 154 if (fMaxPhe < 20.) 155 fMaxPhe = 20. ; 156 157 UpdateLegend() ; 158 } 159 160 // 161 // update the colors in the picture 162 // 163 const Int_t entries = event->GetNbPixels(); 164 165 for (Int_t i=0 ; i<entries; i++ ) 166 { 167 MCerPhotPix &pix = (*event)[i]; 168 169 if (!pix.IsPixelUsed()) 170 continue; 171 172 SetPixColor(pix); 173 } 174 175 // 176 // update the picture 177 // 178 Draw() ; 158 179 } 159 180 160 void MCamDisplay::DrawError( MCerPhotEvt *event) 161 { 162 // 163 164 // loop over all pixels in the MCerPhotEvt and 165 // determine the Pixel Id and the content 166 Reset() ; 167 168 for (Int_t i=0 ; i<event->GetNbPixels() ; i++ ) 169 { 170 ( (MHexagon*) fPixels->At( event->GetPixelId(i) ))->SetFillColor( GetColor(event->GetErrorPhot(i)) ) ; 171 } 172 173 Draw() ; 174 181 void MCamDisplay::DrawPhotErr( MCerPhotEvt *event) 182 { 183 // 184 // reset the all pixel colors to a default value 185 // 186 Reset() ; 187 188 // 189 // loop over all pixels in the MCerPhotEvt and 190 // determine the Pixel Id and the content 191 // 192 const Int_t entries = event->GetNbPixels() ; 193 194 for (Int_t i=0 ; i<entries; i++ ) 195 { 196 MCerPhotPix &pix = (*event)[i]; 197 198 SetPixColor(pix); 199 } 200 201 // 202 // update display 203 // 204 Draw() ; 175 205 } 176 206 … … 178 208 void MCamDisplay::Reset() 179 209 { 180 for ( Int_t i=0 ; i< fNbPixels ; i++ )181 {182 ( (MHexagon*) fPixels->At(i))->SetFillColor(10) ;183 }184 210 // 211 // reset the all pixel colors to a default value 212 // 213 for ( Int_t i=0 ; i< fNbPixels ; i++ ) 214 (*this)[i].SetFillColor(10) ; 185 215 } 186 216 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 the191 // Color palette inside. We use the command gStyle->SetPalette(1,0)192 // for the display. So we have to convert the value "wert" into193 // a color index that fits the color palette.194 // The range of the color palette is defined by the values fMinPhe195 // and fMaxRange. Between this values we have 50 color index, starting196 // 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 217 Int_t MCamDisplay::GetColor(Float_t val) 218 { 219 // 220 // Here we calculate the color index for the current value. 221 // The color index is defined with the class TStyle and the 222 // Color palette inside. We use the command gStyle->SetPalette(1,0) 223 // for the display. So we have to convert the value "wert" into 224 // a color index that fits the color palette. 225 // The range of the color palette is defined by the values fMinPhe 226 // and fMaxRange. Between this values we have 50 color index, starting 227 // with 0 up to 49. 228 // 229 230 // 231 // first treat the over- and under-flows 232 // 233 const Float_t maxcolidx = 49.0; 234 235 if (val >= fMaxPhe ) 236 return gStyle->GetColorPalette(maxcolidx); 237 238 if (val <= fMinPhe ) 239 return gStyle->GetColorPalette( 0 ); 240 241 // 242 // calculate the color index 243 // 244 const Float_t ratio = (val-fMinPhe) / (fMaxPhe-fMinPhe); 245 const Int_t colidx = (Int_t)(maxcolidx*ratio + .5) ; 246 247 return gStyle->GetColorPalette(colidx) ; 248 } 219 249 220 250 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 } 251 { 252 // 253 // change the text on the legend according to the range of the 254 // Display 255 // 256 257 char text[10] ; 258 259 for (Int_t il=0; il < kITEMS_LEGEND; il++) 260 { 261 const Float_t val = fMinPhe + (Float_t)il/kITEMS_LEGEND * (fMaxPhe-fMinPhe) ; 262 263 sprintf(text, "%5.1f", val); 264 265 TText &txt = *GetText(il); 266 267 txt.SetText(txt.GetX(), txt.GetY(), text) ; 268 } 269 }
Note:
See TracChangeset
for help on using the changeset viewer.