source: Sophya/trunk/SophyaPI/PIext/pintuple.cc@ 333

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

Trace de NTuple en 2D avec Marker de taille proportionnelle a Weight
Introduction des repertoires dans la gestion d'objets NameObjMgr
Reorganisation NamedObjMgr et Services2NObjMgr, ajout de commandes , ...
Reza 12/7/99

File size: 3.2 KB
Line 
1#include <stdio.h>
2#include "pintuple.h"
3
4
5/* --Methode-- */
6PINTuple::PINTuple(NTupleInterface* nt, bool ad)
7: PIDrawer()
8{
9 mNT = nt;
10 mAdDO = ad;
11 SelectXY(NULL, NULL);
12 SelectErrBar();
13}
14
15PINTuple::~PINTuple()
16{
17 if (mAdDO && mNT) delete mNT;
18}
19
20/* --Methode-- */
21void PINTuple::SelectXY(const char* px, const char* py)
22{
23string name;
24if (mNT == NULL) xK = yK = -1;
25if (px == NULL) xK = -1;
26else { name = px; xK = mNT->ColumnIndex(name); }
27if (py == NULL) yK = -1;
28else { name = py; yK = mNT->ColumnIndex(name); }
29}
30
31/* --Methode-- */
32void PINTuple::SelectWt(const char* pw, int nbins)
33{
34nWbins = (nbins > 0) ? nbins : 10;
35if (pw == NULL) wK = -1;
36else { string name = pw; wK = mNT->ColumnIndex(name); }
37
38if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
39else { wMin = 0.; wMax = 1.; }
40}
41
42/* --Methode-- */
43void PINTuple::SelectErrBar(const char* erbx, const char* erby)
44{
45string name;
46if (mNT == NULL) xebK = yebK = -1;
47if (erbx == NULL) xebK = -1;
48else { name = erbx; xebK = mNT->ColumnIndex(name); }
49if (erby == NULL) yebK = -1;
50else { name = erby; yebK = mNT->ColumnIndex(name); }
51}
52
53
54/* --Methode-- */
55void PINTuple::UpdateLimits()
56{
57 if (!mNT) return;
58 if (mNT->NbLines() <= 0) return;
59 if ( (xK < 0) || (yK < 0) ) return;
60
61 // Commencer par trouver nos limites
62 double dx, dy;
63 double xmin, xmax, ymin, ymax;
64 xmin = ymin = 9.e19;
65 xmax = ymax = -9.e19;
66 mNT->GetMinMax(xK, xmin, xmax);
67 mNT->GetMinMax(yK, ymin, ymax);
68
69 dx = 0.02*(xmax-xmin);
70 dy = 0.02*(ymax-ymin);
71
72 SetLimits(xmin-dx, xmax+dx, ymin-dy, ymax+dy);
73 SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
74}
75
76
77/* --Methode-- */
78void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
79{
80double xp,yp,xer,yer,wp;
81double xl,yl;
82int nok;
83
84if (!mNT) return;
85if ( (xK < 0) || (yK < 0) ) return;
86if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
87
88// Pour tracer des markers avec taille fonction de Wt (poids)
89double dw = (wMax-wMin)/nWbins;
90if (dw < 1.e-19) dw = 1.e19;
91int msz,sz;
92
93PIMarker mrk;
94if (wK >= 0) mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_CircleMarker;
95else mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_DotMarker;
96msz = mMSz;
97if (msz < 1) msz = 1;
98g->SelMarker(sz, mrk);
99
100nok = 0;
101xp = yp = xl = yl = 0;
102for (int i=0; i<mNT->NbLines(); i++) {
103 xl = xp; yl = yp;
104 xp = mNT->GetCell(i, xK);
105 yp = mNT->GetCell(i, yK);
106 if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
107 if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) ) // On relie les points ...
108 g->DrawLine(xl, yl, xp, yp);
109 nok++;
110 if ( xebK >= 0 ) {
111 xer = mNT->GetCell(i, xebK);
112 if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
113 }
114 if ( yebK >= 0 ) {
115 yer = mNT->GetCell(i, yebK);
116 if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
117 }
118 if (wK >= 0) { // Taille de marker en fonction du poids
119 wp = mNT->GetCell(i, wK);
120 sz = (int)((wp-wMin)/dw);
121 if (sz < 0) sz = 0;
122 if (sz > nWbins) sz = nWbins;
123 sz += msz;
124 if (sz < 2) g->SelMarker(sz, PI_DotMarker);
125 else g->SelMarker(sz, mrk);
126 }
127 g->DrawMarker(xp, yp);
128}
129
130/*
131sprintf(buff, "NTuple: NEntry= %d NDisp= %d", (int)mNT->NEntry(), nok);
132g->BaseGraphic()->DrawString(15,15,buff);
133*/
134return;
135}
136
Note: See TracBrowser for help on using the repository browser.