[165] | 1 | #include <stdio.h>
|
---|
[295] | 2 | #include <typeinfo>
|
---|
| 3 |
|
---|
[165] | 4 | #include "pihisto.h"
|
---|
| 5 | #include "hisprof.h"
|
---|
| 6 |
|
---|
| 7 | PIHisto::PIHisto(Histo* histo, bool ad)
|
---|
| 8 | : PIDrawer(), mHisto(histo)
|
---|
| 9 | {
|
---|
| 10 | mAdDO = ad; // Flag pour suppression automatique de mHisto
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | PIHisto::~PIHisto()
|
---|
| 14 | {
|
---|
| 15 | if (mAdDO) delete mHisto;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | void
|
---|
| 19 | PIHisto::UpdateLimits()
|
---|
| 20 | {
|
---|
| 21 | if (!mHisto) return;
|
---|
| 22 | float hmin = mHisto->VMin();
|
---|
| 23 | float hmax = mHisto->VMax()+0.2*(mHisto->VMax()-mHisto->VMin());
|
---|
| 24 | // si HBProf min,max calcules en tenant compte des erreurs
|
---|
[295] | 25 | if( typeid(*mHisto) == typeid(HProf) ) {
|
---|
[165] | 26 | float v1,v2;
|
---|
| 27 | for (int i=1; i<mHisto->NBins(); i++) {
|
---|
| 28 | v1 = (*mHisto)(i) - mHisto->Error(i);
|
---|
| 29 | v2 = (*mHisto)(i) + mHisto->Error(i);
|
---|
| 30 | if(v1<hmin) hmin = v1;
|
---|
| 31 | if(v2>hmax) hmax = v2;
|
---|
| 32 | }
|
---|
| 33 | v1 = 0.1*(hmax-hmin);
|
---|
| 34 | hmin -= v1; hmax += v1;
|
---|
| 35 | }
|
---|
| 36 | if(hmax<=hmin) hmax += 1.;
|
---|
| 37 | SetLimits(mHisto->XMin(), mHisto->XMax(), hmin, hmax);
|
---|
| 38 | SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | void
|
---|
[205] | 42 | PIHisto::Draw(PIGraphicUC* g, double /*xmin*/, double /*ymin*/, double /*xmax*/, double /*ymax*/)
|
---|
[165] | 43 | {
|
---|
| 44 | bool oktrace = false;
|
---|
| 45 | if (!mHisto) return;
|
---|
[203] | 46 |
|
---|
[295] | 47 | if (mMrk != PI_NotDefMarker || ( typeid(*mHisto) == typeid(HProf) ) ) {
|
---|
[165] | 48 | // Marqeurs definis OU HBProf => marqueurs+Erreurs si il y en a
|
---|
| 49 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
[205] | 50 | double x1,y1, x2,y2;
|
---|
| 51 | double bw = mHisto->BinWidth();
|
---|
[165] | 52 | for (int i=0; i<mHisto->NBins(); i++) {
|
---|
| 53 | if(mHisto->Error(i)>0.) {
|
---|
| 54 | // barres d'erreur verticales
|
---|
| 55 | x1 = x2 = mHisto->BinCenter(i);
|
---|
| 56 | y1 = (*mHisto)(i) - mHisto->Error(i);
|
---|
| 57 | y2 = (*mHisto)(i) + mHisto->Error(i);
|
---|
| 58 | g->DrawLine(x1,y1, x1, y2);
|
---|
| 59 | // limites de barres d'erreurs (horizontales)
|
---|
| 60 | x1 -= bw/3.; x2 += bw/3.;
|
---|
| 61 | g->DrawLine(x1,y1, x2, y1);
|
---|
| 62 | g->DrawLine(x1,y2, x2, y2);
|
---|
| 63 | }
|
---|
| 64 | // le marqueur
|
---|
| 65 | x1 = mHisto->BinCenter(i);
|
---|
| 66 | y1 = (*mHisto)(i);
|
---|
| 67 | g->DrawMarker(x1,y1);
|
---|
| 68 | }
|
---|
| 69 | oktrace = true;
|
---|
| 70 | }
|
---|
| 71 | if (mLAtt != PI_NotDefLineAtt) {
|
---|
[205] | 72 | double x1,y1, x2, y2;
|
---|
[165] | 73 | x1 = mHisto->BinLowEdge(0);
|
---|
| 74 | y1 = 0;
|
---|
| 75 | for (int i=0; i<mHisto->NBins(); i++) {
|
---|
| 76 | x2 = x1;
|
---|
| 77 | y2 = (*mHisto)(i);
|
---|
| 78 | g->DrawLine(x1,y1, x2, y2);
|
---|
| 79 | y1 = y2;
|
---|
| 80 | x2 = mHisto->BinHighEdge(i);
|
---|
| 81 | g->DrawLine(x1,y1, x2, y2);
|
---|
| 82 | x1 = x2;
|
---|
| 83 | }
|
---|
| 84 | y2 = 0; g->DrawLine(x1,y1, x2, y2);
|
---|
| 85 | oktrace = true;
|
---|
| 86 | }
|
---|
| 87 | if( !oktrace ) {
|
---|
| 88 | for(int i=0; i<mHisto->NBins(); i++) {
|
---|
[205] | 89 | double left = mHisto->BinLowEdge(i);
|
---|
| 90 | double width = mHisto->BinWidth();
|
---|
| 91 | double bottom = 0;
|
---|
| 92 | double height = (*mHisto)(i);
|
---|
[165] | 93 | g->DrawFBox(left,bottom,width,height);
|
---|
| 94 | g->DrawLine(left, bottom, left, bottom + height); // Au moins une ligne...
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
[203] | 97 | // A faire a la fin - DrawStats change l'attribut de ligne
|
---|
[165] | 98 | DrawStats(g);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | void
|
---|
| 102 | PIHisto::DrawStats(PIGraphicUC* g)
|
---|
| 103 | {
|
---|
| 104 | if (!mHisto) return;
|
---|
[203] | 105 | // if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
| 106 | g->SelLine(PI_ThinLine);
|
---|
[205] | 107 | double cellHeight = (YMax() - YMin()) * 0.05;
|
---|
| 108 | double cellWidth = (XMax() - XMin()) * 0.23;
|
---|
[165] | 109 | g->DrawLine(XMax() - cellWidth, YMax(),
|
---|
| 110 | XMax() - cellWidth, YMax() - cellHeight);
|
---|
| 111 | g->DrawLine(XMax() - cellWidth, YMax() - cellHeight,
|
---|
| 112 | XMax() , YMax() - cellHeight);
|
---|
| 113 | char label[50];
|
---|
| 114 | sprintf(label, "N = %.6g", mHisto->NData());
|
---|
| 115 | g->SelFontSz((YMax() - YMin())/30);
|
---|
| 116 | g->DrawString(XMax() - cellWidth*0.9, YMax() - cellHeight*0.8, label);
|
---|
| 117 |
|
---|
| 118 | }
|
---|
| 119 |
|
---|