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

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

Adapatation a NTupleInterface::GetCelltoString() et ajout trace Label ds PINTuple/3D et Wt ds PINtuple3D - Reza 21/10/99

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