source: Sophya/trunk/SophyaPI/PIext/pihisto.cc@ 411

Last change on this file since 411 was 295, checked in by ercodmgr, 26 years ago

Mise aux "normes" version DPC/Planck - Gestion des objets a travers

un adaptateur/interface NTuple par NamedObjMgr.
Enregistrement d'objets et de l'adaptateur (I/O PPersist, display, ...)
par ServNobjMgr .... Reza 13/05/99

File size: 3.4 KB
Line 
1#include <stdio.h>
2#include <typeinfo>
3
4#include "pihisto.h"
5#include "hisprof.h"
6
7PIHisto::PIHisto(Histo* histo, bool ad)
8: PIDrawer(), mHisto(histo)
9{
10 mAdDO = ad; // Flag pour suppression automatique de mHisto
11}
12
13PIHisto::~PIHisto()
14{
15 if (mAdDO) delete mHisto;
16}
17
18void
19PIHisto::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
25 if( typeid(*mHisto) == typeid(HProf) ) {
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
41void
42PIHisto::Draw(PIGraphicUC* g, double /*xmin*/, double /*ymin*/, double /*xmax*/, double /*ymax*/)
43{
44 bool oktrace = false;
45 if (!mHisto) return;
46
47 if (mMrk != PI_NotDefMarker || ( typeid(*mHisto) == typeid(HProf) ) ) {
48 // Marqeurs definis OU HBProf => marqueurs+Erreurs si il y en a
49 if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
50 double x1,y1, x2,y2;
51 double bw = mHisto->BinWidth();
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) {
72 double x1,y1, x2, y2;
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++) {
89 double left = mHisto->BinLowEdge(i);
90 double width = mHisto->BinWidth();
91 double bottom = 0;
92 double height = (*mHisto)(i);
93 g->DrawFBox(left,bottom,width,height);
94 g->DrawLine(left, bottom, left, bottom + height); // Au moins une ligne...
95 }
96 }
97 // A faire a la fin - DrawStats change l'attribut de ligne
98 DrawStats(g);
99}
100
101void
102PIHisto::DrawStats(PIGraphicUC* g)
103{
104 if (!mHisto) return;
105 // if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
106 g->SelLine(PI_ThinLine);
107 double cellHeight = (YMax() - YMin()) * 0.05;
108 double cellWidth = (XMax() - XMin()) * 0.23;
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
Note: See TracBrowser for help on using the repository browser.