| 1 | // Classe traceur d histogramme                 96-99
 | 
|---|
| 2 | // CEA-DAPNIA      LAL-IN2P3/CNRS
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include <stdio.h>
 | 
|---|
| 5 | #include <typeinfo>
 | 
|---|
| 6 | 
 | 
|---|
| 7 | #include "pihisto.h"
 | 
|---|
| 8 | #include "hisprof.h"
 | 
|---|
| 9 | 
 | 
|---|
| 10 | //++
 | 
|---|
| 11 | // Class        PIHisto
 | 
|---|
| 12 | // Lib          PIext
 | 
|---|
| 13 | // include      pihisto.h
 | 
|---|
| 14 | //
 | 
|---|
| 15 | //      Classe traceur d'objet histogramme (classe *Histo*)
 | 
|---|
| 16 | //--
 | 
|---|
| 17 | //++
 | 
|---|
| 18 | // Links        Parents
 | 
|---|
| 19 | // PIDrawer
 | 
|---|
| 20 | //--
 | 
|---|
| 21 | //++
 | 
|---|
| 22 | // Titre        Constructeur, méthodes
 | 
|---|
| 23 | //--
 | 
|---|
| 24 | //++
 | 
|---|
| 25 | // PIHisto(Histo* histo, bool ad=false)
 | 
|---|
| 26 | //      Constructeur. Si "ad == true", l'objet "histo" est détruit par 
 | 
|---|
| 27 | //      le destructeur de l'objet "PIHisto"
 | 
|---|
| 28 | //      Note : "histo" doit être créé par new
 | 
|---|
| 29 | //
 | 
|---|
| 30 | // void  SetStats(bool fg=true) 
 | 
|---|
| 31 | //      Active/ désactive l'indication des statistiques d'histogramme
 | 
|---|
| 32 | //--
 | 
|---|
| 33 | 
 | 
|---|
| 34 | 
 | 
|---|
| 35 | PIHisto::PIHisto(Histo* histo, bool ad)
 | 
|---|
| 36 | : PIDrawer(), mHisto(histo)
 | 
|---|
| 37 | {
 | 
|---|
| 38 |   mAdDO = ad;     // Flag pour suppression automatique de mHisto
 | 
|---|
| 39 |   SetStats(true);
 | 
|---|
| 40 | }
 | 
|---|
| 41 | 
 | 
|---|
| 42 | PIHisto::~PIHisto()
 | 
|---|
| 43 | {
 | 
|---|
| 44 |   if (mAdDO) delete mHisto;
 | 
|---|
| 45 | }
 | 
|---|
| 46 | 
 | 
|---|
| 47 | void
 | 
|---|
| 48 | PIHisto::UpdateLimits()
 | 
|---|
| 49 | {
 | 
|---|
| 50 |   if (!mHisto)  return;
 | 
|---|
| 51 |   float hmin = mHisto->VMin();
 | 
|---|
| 52 |   float hmax = mHisto->VMax()+0.2*(mHisto->VMax()-mHisto->VMin());
 | 
|---|
| 53 |   // si HBProf min,max calcules en tenant compte des erreurs
 | 
|---|
| 54 |   if( typeid(*mHisto) == typeid(HProf) ) {
 | 
|---|
| 55 |     float v1,v2;
 | 
|---|
| 56 |     for (int i=1; i<mHisto->NBins(); i++) {
 | 
|---|
| 57 |       v1 = (*mHisto)(i) - mHisto->Error(i);
 | 
|---|
| 58 |       v2 = (*mHisto)(i) + mHisto->Error(i);
 | 
|---|
| 59 |       if(v1<hmin) hmin = v1;
 | 
|---|
| 60 |       if(v2>hmax) hmax = v2;
 | 
|---|
| 61 |     }
 | 
|---|
| 62 |     v1 = 0.1*(hmax-hmin);
 | 
|---|
| 63 |     hmin -= v1;   hmax += v1;
 | 
|---|
| 64 |   }
 | 
|---|
| 65 |   if(hmax<=hmin) hmax += 1.;
 | 
|---|
| 66 |   SetLimits(mHisto->XMin(), mHisto->XMax(), hmin, hmax);
 | 
|---|
| 67 | //  SetAxesFlags(kBoxAxes | kExtTicks | kLabels);   NE PAS faire Reza 11/99
 | 
|---|
| 68 | }
 | 
|---|
| 69 | 
 | 
|---|
| 70 | void
 | 
|---|
| 71 | PIHisto::Draw(PIGraphicUC* g, double /*xmin*/, double /*ymin*/, double /*xmax*/, double /*ymax*/)
 | 
|---|
| 72 | {
 | 
|---|
| 73 |   if (axesFlags != kAxesNone) DrawAxes(g);
 | 
|---|
| 74 | 
 | 
|---|
| 75 |   bool oktrace = false;
 | 
|---|
| 76 |   if (!mHisto)  return;  
 | 
|---|
| 77 | 
 | 
|---|
| 78 |   if (mMrk != PI_NotDefMarker ||  ( typeid(*mHisto) == typeid(HProf) ) )  {
 | 
|---|
| 79 |     // Marqeurs definis OU HBProf => marqueurs+Erreurs si il y en a
 | 
|---|
| 80 |     if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
 | 
|---|
| 81 |     double x1,y1, x2,y2;
 | 
|---|
| 82 |     double bw = mHisto->BinWidth();
 | 
|---|
| 83 |     for (int i=0; i<mHisto->NBins(); i++) {
 | 
|---|
| 84 |       if(mHisto->Error(i)>0.) {
 | 
|---|
| 85 |         // barres d'erreur verticales
 | 
|---|
| 86 |         x1 = x2 = mHisto->BinCenter(i);
 | 
|---|
| 87 |         y1 = (*mHisto)(i) - mHisto->Error(i);
 | 
|---|
| 88 |         y2 = (*mHisto)(i) + mHisto->Error(i);
 | 
|---|
| 89 |         g->DrawLine(x1,y1, x1, y2);
 | 
|---|
| 90 |         // limites de barres d'erreurs (horizontales)
 | 
|---|
| 91 |         x1 -= bw/3.;  x2 += bw/3.;
 | 
|---|
| 92 |         g->DrawLine(x1,y1, x2, y1);
 | 
|---|
| 93 |         g->DrawLine(x1,y2, x2, y2);
 | 
|---|
| 94 |       }
 | 
|---|
| 95 |       // le marqueur
 | 
|---|
| 96 |       x1 = mHisto->BinCenter(i);
 | 
|---|
| 97 |       y1 = (*mHisto)(i);
 | 
|---|
| 98 |       g->DrawMarker(x1,y1);
 | 
|---|
| 99 |     }
 | 
|---|
| 100 |     oktrace = true;
 | 
|---|
| 101 |   }
 | 
|---|
| 102 |   if (mLAtt != PI_NotDefLineAtt) {
 | 
|---|
| 103 |     double x1,y1, x2, y2;
 | 
|---|
| 104 |     x1 = mHisto->BinLowEdge(0);
 | 
|---|
| 105 |     y1 = 0;
 | 
|---|
| 106 |     for (int i=0; i<mHisto->NBins(); i++) {
 | 
|---|
| 107 |       x2 = x1;
 | 
|---|
| 108 |       y2 = (*mHisto)(i);
 | 
|---|
| 109 |       g->DrawLine(x1,y1, x2, y2);
 | 
|---|
| 110 |       y1 = y2;
 | 
|---|
| 111 |       x2 = mHisto->BinHighEdge(i);
 | 
|---|
| 112 |       g->DrawLine(x1,y1, x2, y2);
 | 
|---|
| 113 |       x1 = x2;
 | 
|---|
| 114 |     }
 | 
|---|
| 115 |     y2 = 0; g->DrawLine(x1,y1, x2, y2);
 | 
|---|
| 116 |     oktrace = true;
 | 
|---|
| 117 |   }
 | 
|---|
| 118 |   if( !oktrace ) {
 | 
|---|
| 119 |     for(int i=0; i<mHisto->NBins(); i++) {
 | 
|---|
| 120 |       double left   = mHisto->BinLowEdge(i);
 | 
|---|
| 121 |       double width  = mHisto->BinWidth();
 | 
|---|
| 122 |       double bottom = 0;
 | 
|---|
| 123 |       double height = (*mHisto)(i);
 | 
|---|
| 124 |       g->DrawFBox(left,bottom,width,height);
 | 
|---|
| 125 |       g->DrawLine(left, bottom, left, bottom + height); // Au moins une ligne...
 | 
|---|
| 126 |     }
 | 
|---|
| 127 |   }
 | 
|---|
| 128 |   // A faire a la fin - DrawStats change l'attribut de ligne 
 | 
|---|
| 129 |   if (stats) DrawStats(g);
 | 
|---|
| 130 | }
 | 
|---|
| 131 | 
 | 
|---|
| 132 | void
 | 
|---|
| 133 | PIHisto::DrawStats(PIGraphicUC* g)
 | 
|---|
| 134 | {
 | 
|---|
| 135 |   if (!mHisto) return;
 | 
|---|
| 136 |   //  if (mLAtt == PI_NotDefLineAtt)  g->SelLine(PI_ThinLine);
 | 
|---|
| 137 |   g->SelLine(PI_ThinLine);
 | 
|---|
| 138 |   g->SelFontSz((YMax() - YMin())/25, mFAtt);
 | 
|---|
| 139 | //  double cellHeight = (YMax() - YMin()) * 0.05;
 | 
|---|
| 140 |   PIGrCoord a, d;
 | 
|---|
| 141 |   double cH = (double)g->GetFontHeight(a,d);
 | 
|---|
| 142 |   double cellHeight = cH * 3.6;
 | 
|---|
| 143 | //  double cellWidth  = (XMax() - XMin()) * 0.23;
 | 
|---|
| 144 |   char label[50];
 | 
|---|
| 145 |   sprintf(label, "N= %8g    ", mHisto->NData());   label[11] ='\0';
 | 
|---|
| 146 |   double cellWidth =  (double)g->CalcStringWidth(label) * 1.1;
 | 
|---|
| 147 |   double xu, yu;
 | 
|---|
| 148 |   xu = g->DeltaUCX(XMax(), - cellWidth);
 | 
|---|
| 149 |   yu = g->DeltaUCY(YMax(), - cellHeight);
 | 
|---|
| 150 |   g->DrawLine(xu, YMax(), xu, yu);
 | 
|---|
| 151 |   g->DrawLine(xu, yu, XMax(), yu);
 | 
|---|
| 152 |   xu = g->DeltaUCX(XMax(), - cellWidth*0.95);
 | 
|---|
| 153 |   yu = g->DeltaUCY(YMax(), - cH*1.15);
 | 
|---|
| 154 |   g->DrawString(xu, yu, label);
 | 
|---|
| 155 |   sprintf(label, "m= %8g", mHisto->Mean());  label[11] ='\0';
 | 
|---|
| 156 |   yu = g->DeltaUCY(YMax(), - cH*2.3);
 | 
|---|
| 157 |   g->DrawString(xu, yu, label);
 | 
|---|
| 158 |   sprintf(label, "s= %8g", mHisto->Sigma());  label[11] ='\0';
 | 
|---|
| 159 |   yu = g->DeltaUCY(YMax(), - cH*3.45);
 | 
|---|
| 160 |   g->DrawString(xu, yu, label);
 | 
|---|
| 161 |                        
 | 
|---|
| 162 | }
 | 
|---|
| 163 | 
 | 
|---|