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

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

1/ Extension de fonctionalites de gestion de repertoires (Lock, ...)
2/ Plus de NTupIntf_Adapter quand les objets heritent de NTupleInterface
3/ Support pour affichage info texte, ds PINtuple et PIStarList

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