Ignore:
Timestamp:
06/03/03 10:27:05 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r2147 r2153  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz  05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
    19 !   Author(s): Harald Kornmayer 1/2001
     18!   Author(s): Thomas Bretz, 05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
     19!   Author(s): Harald Kornmayer, 1/2001
    2020!
    21 !   Copyright: MAGIC Software Development, 2000-2002
     21!   Copyright: MAGIC Software Development, 2000-2003
    2222!
    2323!
     
    3030// Camera Display. The Pixels are displayed in
    3131// contents/area [somthing/mm^2]
     32//
     33// To change the scale to a logarithmic scale SetLogz() of the Pad.
     34//
    3235//
    3336////////////////////////////////////////////////////////////////////////////
     
    7275//
    7376MCamDisplay::MCamDisplay()
    74     : fGeomCam(NULL), fAutoScale(kTRUE), fW(0), fH(0)
     77    : fGeomCam(NULL), fAutoScale(kTRUE)
    7578{
    7679    fNumPixels = 0;
     
    8487    fLegRadius = NULL;
    8588    fLegDegree = NULL;
     89
     90    fMinimum = 0;
     91    fMaximum = 1;
     92
     93    //fData.Set(0);
    8694}
    8795
     
    9199//
    92100MCamDisplay::MCamDisplay(MGeomCam *geom)
    93     : fGeomCam(NULL), fAutoScale(kTRUE), fW(0), fH(0)
     101    : fGeomCam(NULL), fAutoScale(kTRUE), fData(geom->GetNumPixels()), fMinimum(0), fMaximum(1)
    94102{
    95103    fGeomCam = (MGeomCam*)geom->Clone();
     
    119127#endif
    120128        pix.SetFillColor(16);
     129        pix.ResetBit(kIsUsed);
    121130    }
    122131
     
    176185    SetPalette(51, 0);
    177186#endif
    178 
    179187}
    180188
     
    204212}
    205213
    206 inline void MCamDisplay::SetPixColor(const MCerPhotPix &pix, const UInt_t i, Float_t min, Float_t max)
    207 {
    208     if (i>=fNumPixels)
    209         return;
    210 
    211     //
    212     // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
    213     //
    214     const Float_t ratio = fGeomCam->GetPixRatio(i);
    215     const Float_t pnum  = ratio*pix.GetNumPhotons();
    216 
    217     (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
    218 }
    219 
    220 inline void MCamDisplay::SetPixColorPedestal(const MPedestalPix &pix, const UInt_t i, Float_t min, Float_t max)
    221 {
    222     if (i>=fNumPixels)
    223         return;
    224 
    225     //
    226     // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
    227     //
    228     const Float_t ratio = fGeomCam->GetPixRatio(i);
    229     const Float_t pnum  = ratio*pix.GetMean();
    230 
    231     (*this)[i].SetFillColor(GetColor(pnum, min, max));
    232 }
    233 
    234 inline void MCamDisplay::SetPixColorError(const MCerPhotPix &pix, const UInt_t i, Float_t min, Float_t max)
    235 {
    236     if (i>=fNumPixels)
    237         return;
    238 
    239     //
    240     // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
    241     //
    242     const Float_t ratio = fGeomCam->GetPixRatio(i);
    243     const Float_t pnum  = sqrt(ratio)*pix.GetErrorPhot();
    244 
    245     (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
    246 }
    247 
    248 inline void MCamDisplay::SetPixColorRatio(const MCerPhotPix &pix, Float_t min, Float_t max)
    249 {
    250     //
    251     // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
    252     //
    253     // *OLD* const Float_t r = pix.GetNumPhotons()/pix.GetErrorPhot();
    254     //    if (entry * ratio <= fCleanLvl1 * noise)
    255 
    256     const Float_t  entry = pix.GetNumPhotons();
    257     const Float_t  noise = pix.GetErrorPhot();
    258     const Double_t ratio = TMath::Sqrt(fGeomCam->GetPixRatio(pix.GetPixId()));
    259 
    260     const Float_t r = entry*ratio/noise;
    261     //const Float_t pnum  = pix.GetNumPhotons()/pix.GetErrorPhot();
    262 
    263     (*this)[pix.GetPixId()].SetFillColor(GetColor(r, min, max));
    264 }
    265 
    266 inline void MCamDisplay::SetPixColorLevel(const MCerPhotPix &pix, Float_t lvl1, Float_t lvl2)
    267 {
    268     const Int_t maxcolidx = kItemsLegend-1;
    269 
    270     MHexagon &hex = (*this)[pix.GetPixId()];
    271 
    272     // *OLD* const Float_t r = pix.GetNumPhotons()/pix.GetErrorPhot();
    273     //    if (entry * ratio <= fCleanLvl1 * noise)
    274 
    275     const Float_t  entry = pix.GetNumPhotons();
    276     const Float_t  noise = pix.GetErrorPhot();
    277     const Double_t ratio = TMath::Sqrt(fGeomCam->GetPixRatio(pix.GetPixId()));
    278 
    279     const Float_t r = entry*ratio/noise;
    280 
    281     if (r>lvl1)
    282         hex.SetFillColor(fColors[4*maxcolidx/5]);
    283     else
    284         if (r>lvl2)
    285             hex.SetFillColor(fColors[maxcolidx/2]);
    286         else
    287             hex.SetFillColor(fColors[maxcolidx/5]);
    288 }
    289 
    290214// ------------------------------------------------------------------------
    291215//
     
    300224    // gPad->SetFixedAspectRatio()
    301225
    302     TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 750, 600);
     226    TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 656, 600);
    303227    pad->SetBorderMode(0);
    304228    pad->SetFillColor(16);
     
    326250}
    327251
     252void MCamDisplay::Update(Bool_t islog)
     253{
     254    // FIXME: Don't do this if nothing changed!
     255    if (fAutoScale)
     256    {
     257        fMinimum =  FLT_MAX;
     258        fMaximum = -FLT_MAX;
     259
     260        for (UInt_t i=0; i<fNumPixels; i++)
     261        {
     262            if (!(*this)[i].TestBit(kIsUsed))
     263                continue;
     264
     265            if (fData[i]<fMinimum)
     266                fMinimum = fData[i];
     267            if (fData[i]>fMaximum)
     268                fMaximum = fData[i];
     269        }
     270    }
     271
     272    if (fMinimum==fMaximum)
     273        fMaximum = fMinimum + 1;
     274
     275    UpdateLegend(fMinimum, fMaximum, islog);
     276
     277    for (UInt_t i=0; i<fNumPixels; i++)
     278    {
     279        if ((*this)[i].TestBit(kIsUsed))
     280            (*this)[i].SetFillColor(GetColor(fData[i], fMinimum, fMaximum, islog));
     281        else
     282            (*this)[i].SetFillColor(10);
     283
     284    }
     285}
     286
    328287// ------------------------------------------------------------------------
    329288//
     
    337296        return;
    338297
    339     //
    340298    // Maintain aspect ratio
    341     //
    342299    SetRange();
    343300
    344     //
    345301    // Maintain colors
    346     //
    347302    SetPalette();
    348303
    349     //
     304    // Update Contents of the pixels
     305    Update(gPad->GetLogz());
     306
    350307    // Paint Legend
    351     //
    352308    fArrowX->Paint(">");
    353309    fArrowY->Paint(">");
     
    356312    fLegDegree->Paint();
    357313
    358     //
    359314    // Paint primitives (pixels, color legend, photons, ...)
    360     //
    361315    { fPixels->ForEach(TObject, Paint)(); }
    362316    { fLegend->ForEach(TObject, Paint)(); }
     
    495449void MCamDisplay::FillPhotNum(const MCerPhotEvt &event)
    496450{
    497     //
    498     // Reset pixel colors to default value
    499     //
    500451    Reset();
    501452
    502     //
    503     //  if the autoscale is true, set the values for the range for
    504     //  each event
    505     //
    506     Float_t min = 0;
    507     Float_t max = 50;
    508     if (fAutoScale)
    509     {
    510         min = event.GetNumPhotonsMin(fGeomCam);
    511         max = event.GetNumPhotonsMax(fGeomCam);
    512 
    513         if (max==min)
    514             max = min +1;
    515 
    516         UpdateLegend(min, max);
    517     }
    518 
    519     //
    520     //   update the colors in the picture
    521     //
    522453    const Int_t entries = event.GetNumPixels();
    523454
     
    525456    {
    526457        const MCerPhotPix &pix = event[i];
    527 
    528458        if (!pix.IsPixelUsed())
    529459            continue;
    530460
    531         SetPixColor(pix, i, min, max);
     461        const Int_t id = pix.GetPixId();
     462
     463        fData[id] = pix.GetNumPhotons()*fGeomCam->GetPixRatio(id);
     464        (*this)[id].SetBit(kIsUsed);
    532465    }
    533466}
     
    540473void MCamDisplay::FillPedestals(const MPedestalCam &event)
    541474{
    542     //
    543     // Reset pixel colors to default value
    544     //
    545475    Reset();
    546476
    547     //
    548     //  if the autoscale is true, set the values for the range for
    549     //  each event
    550     //
    551     Float_t min = 0;
    552     Float_t max = 50;
    553     if (fAutoScale)
    554     {
    555         min = event.GetMeanMin(fGeomCam);
    556         max = event.GetMeanMax(fGeomCam);
    557 
    558         if (max==min)
    559             max = min +1;
    560 
    561         UpdateLegend(min, max);
    562     }
    563 
    564     //
    565     //   update the colors in the picture
    566     //
    567477    const Int_t entries = event.GetSize();
    568 
    569478    for (Int_t i=0; i<entries; i++)
    570         SetPixColorPedestal(event[i], i, min, max);
     479    {
     480        fData[i] = event[i].GetMean()*fGeomCam->GetPixRatio(i);
     481        (*this)[i].SetBit(kIsUsed);
     482    }
    571483}
    572484
     
    578490void MCamDisplay::FillErrorPhot(const MCerPhotEvt &event)
    579491{
    580     //
    581     // Reset pixel colors to default value
    582     //
    583492    Reset();
    584493
    585     //
    586     //  if the autoscale is true, set the values for the range for
    587     //  each event
    588     //
    589     Float_t min = 0;
    590     Float_t max = 50;
    591     if (fAutoScale)
    592     {
    593         min = event.GetErrorPhotMin(fGeomCam);
    594         max = event.GetErrorPhotMax(fGeomCam);
    595 
    596         if (max==min)
    597             max = min +1;
    598 
    599         UpdateLegend(min, max);
    600     }
    601 
    602     //
    603     //   update the colors in the picture
    604     //
    605494    const Int_t entries = event.GetNumPixels();
    606495
     
    608497    {
    609498        const MCerPhotPix &pix = event[i];
    610 
    611499        if (!pix.IsPixelUsed())
    612500            continue;
    613501
    614         SetPixColorError(pix, i, min, max);
     502        const Int_t id = pix.GetPixId();
     503
     504        fData[id] = pix.GetErrorPhot()*sqrt(fGeomCam->GetPixRatio(id));
     505        (*this)[id].SetBit(kIsUsed);
    615506    }
    616507}
     
    623514void MCamDisplay::FillRatio(const MCerPhotEvt &event)
    624515{
    625     //
    626     // Reset pixel colors to default value
    627     //
    628516    Reset();
    629517
    630     //
    631     //  if the autoscale is true, set the values for the range for
    632     //  each event
    633     //
    634     Float_t min = 0;
    635     Float_t max = 20;
    636     if (fAutoScale)
    637     {
    638         min = event.GetRatioMin(fGeomCam);
    639         max = event.GetRatioMax(fGeomCam);
    640 
    641         UpdateLegend(min, max);
    642     }
    643 
    644     //
    645     //   update the colors in the picture
    646     //
    647518    const Int_t entries = event.GetNumPixels();
    648519
     
    654525            continue;
    655526
    656         SetPixColorRatio(pix, min, max);
     527        const Int_t id = pix.GetPixId();
     528
     529        const Float_t  entry = pix.GetNumPhotons();
     530        const Float_t  noise = pix.GetErrorPhot();
     531        const Double_t ratio = TMath::Sqrt(fGeomCam->GetPixRatio(id));
     532
     533        fData[id] = entry*ratio/noise;
     534        (*this)[id].SetBit(kIsUsed);
    657535    }
    658536}
     
    664542void MCamDisplay::FillCurrents(const MCurrents &event)
    665543{
    666     //
    667     // Reset pixel colors to default value
    668     //
    669544    Reset();
    670545
    671     //
    672     //  if the autoscale is true, set the values for the range for
    673     //  each event
    674     //
    675     Float_t min = 0;
    676     Float_t max = 20;
    677     if (fAutoScale)
    678     {
    679         min = event.GetMin();
    680         max = event.GetMax();
    681 
    682         UpdateLegend(min, max);
    683     }
    684 
    685     //
    686     //   update the colors in the picture
    687     //
    688546    // FIXME: Security check missing!
    689547    for (UInt_t i=0; i<fNumPixels; i++)
    690548    {
    691         //const Float_t pnum  = pix.GetNumPhotons()/pix.GetErrorPhot();
    692         (*this)[i].SetFillColor(GetColor(event[i], min, max));
     549        if (event[i]<=0)
     550            continue;
     551
     552        (*this)[i].SetBit(kIsUsed);
     553        fData[i] = event[i];
    693554    }
    694555}
     
    700561void MCamDisplay::FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2)
    701562{
    702     //
    703     // Reset pixel colors to default value
    704     //
    705     Reset();
    706 
    707     //
    708     //   update the colors in the picture
    709     //
    710     const Int_t entries = event.GetNumPixels();
    711 
    712     for (Int_t i=0; i<entries; i++)
    713     {
    714         const MCerPhotPix &pix = event[i];
    715 
    716         if (!pix.IsPixelUsed())
     563    FillRatio(event);
     564
     565    for (UInt_t i=0; i<fNumPixels; i++)
     566    {
     567        if (!(*this)[i].TestBit(kIsUsed))
    717568            continue;
    718569
    719         SetPixColorLevel(pix, lvl1, lvl2);
     570        if (fData[i]>lvl1)
     571            fData[i] = 0;
     572        else
     573            if (fData[i]>lvl2)
     574                fData[i] = 1;
     575            else
     576                fData[i] = 2;
    720577    }
    721578}
     
    775632    const Int_t entries = event.GetNumPhotons();
    776633
    777     TArrayF arr(fNumPixels);
    778634    for (Int_t i=0; i<entries; i++)
    779635    {
     
    789645            continue;
    790646
    791         arr[id] += 1;
    792     }
    793 
    794     //
    795     // Scale with the area and determin maximum
    796     //
    797     Float_t max = 0;
     647        fData[id] += fGeomCam->GetPixRatio(id);
     648    }
     649
     650    //
     651    // Set color of pixels
     652    //
    798653    for (UInt_t id=0; id<fNumPixels; id++)
    799     {
    800         arr[id] *= fGeomCam->GetPixRatio(id);
    801         if (arr[id]>max)
    802             max = arr[id];
    803     }
    804 
    805     //
    806     // Update legend
    807     //
     654        if (fData[id]>0)
     655            (*this)[id].SetBit(kIsUsed);
     656}
     657
     658// ------------------------------------------------------------------------
     659//
     660// Reset the all pixel colors to a default value
     661//
     662void MCamDisplay::Reset()
     663{
     664    for (UInt_t i=0; i<fNumPixels; i++)
     665        (*this)[i].ResetBit(kIsUsed);
     666
    808667    if (fAutoScale)
    809         UpdateLegend(0, max==0 ? 1 : max);
    810 
    811     //
    812     // Set color of pixels
    813     //
    814     for (UInt_t id=0; id<fNumPixels; id++)
    815         if (arr[id]>0)
    816             (*this)[id].SetFillColor(GetColor(arr[id], 0, max));
    817 }
    818 
    819 // ------------------------------------------------------------------------
    820 //
    821 // Reset the all pixel colors to a default value
    822 //
    823 void MCamDisplay::Reset()
    824 {
    825     for (UInt_t i=0; i<fNumPixels; i++)
    826         (*this)[i].SetFillColor(10);
     668    {
     669        fMinimum = 0;
     670        fMaximum = 0;
     671    }
    827672}
    828673
     
    838683//  with 0 up to 49.
    839684//
    840 Int_t MCamDisplay::GetColor(Float_t val, Float_t min, Float_t max)
     685Int_t MCamDisplay::GetColor(Float_t val, Float_t min, Float_t max, Bool_t islog)
    841686{
    842687    //
     
    854699    // calculate the color index
    855700    //
    856     const Float_t ratio  = (val-min) / (max-min);
    857     const Int_t   colidx = (Int_t)(ratio*maxcolidx + .5);
    858 
     701    Float_t ratio;
     702    if (islog && min>0)
     703        ratio = log10(val/min) / log10(max/min);
     704    else
     705        ratio = (val-min) / (max-min);
     706    const Int_t colidx = (Int_t)(ratio*maxcolidx + .5);
    859707    return fColors[colidx];
    860708}
     
    864712//  Change the text on the legend according to the range of the Display
    865713//
    866 void MCamDisplay::UpdateLegend(Float_t minphe, Float_t maxphe)
     714void MCamDisplay::UpdateLegend(Float_t minphe, Float_t maxphe, Bool_t islog)
    867715{
    868716    for (Int_t i=0; i<kItemsLegend; i+=3)
    869717    {
    870         const Float_t val = minphe + (Float_t)i/kItemsLegend * (maxphe-minphe) ;
     718        const Float_t pos = (Float_t)i/kItemsLegend;
     719
     720        Float_t val;
     721        if (islog && minphe>0)
     722            val = pow(10, log10(maxphe/minphe)*pos) * minphe;
     723        else
     724            val = minphe + pos * (maxphe-minphe);
    871725
    872726        TText &txt = *GetText(i);
     
    928782// ------------------------------------------------------------------------
    929783//
    930 // Function introduced  (31-01-03)
     784// Function introduced  (31-01-03)  WILL BE REMOVED IN THE FUTURE! DON'T
     785// USE IT!
    931786//
    932787void MCamDisplay::SetPix(const Int_t pixnum, const Int_t color, Float_t min, Float_t max)
    933 {
    934     (*this)[pixnum].SetFillColor(GetColor(color, min, max));
     788{
     789    fData[pixnum] = color;
     790    (*this)[pixnum].SetBit(kIsUsed);
     791    (*this)[pixnum].SetFillColor(GetColor(color, min, max, 0));
    935792}
    936793
Note: See TracChangeset for help on using the changeset viewer.