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