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

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

Documentation + ameliorations DrawStats + vector->tvector pour Planck - Reza 3/11/99

File size: 6.4 KB
Line 
1// Peida Interactive - PI R. Ansari 97-99
2// Traceur (Drawer) pour NTupleInterface
3// LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
4
5#include <stdio.h>
6#include "pintuple.h"
7
8//++
9// Class PINTuple
10// Lib PIext
11// include pintuple.h
12//
13// Classe de traceur 2D (dans un plan) à partir des données
14// d'un objet implémentant l'interface *NTupleInterface*.
15// Les objets "PINTuple" peuvent tracer des signes (markers)
16// éventuellement avec des barres d'erreur et une étiquette
17// pour chaque point. Si un attribut de ligne, autre que
18// "PI_NotDefLineAtt" est spécifié, les points sont connectés
19// par une ligne.
20//--
21//++
22// Links Parents
23// PIDrawer
24//--
25//++
26// Links Voir aussi
27// NTupleInterface
28// PINTuple3D
29//--
30
31//++
32// Titre Constructeur
33//--
34//++
35// PINTuple(NTupleInterface* nt, bool ad)
36// Constructeur. Si "ad == true", l'objet "nt" est détruit par
37// le destructeur de l'objet "PINTuple"
38// Note : "nt" doit être créé par new
39//--
40
41/* --Methode-- */
42PINTuple::PINTuple(NTupleInterface* nt, bool ad)
43: PIDrawer()
44{
45 mNT = nt;
46 mAdDO = ad;
47 SetStats(true);
48 SelectXY(NULL, NULL);
49 SelectWt(NULL, 1);
50 SelectErrBar();
51 SelectLabel(NULL);
52}
53
54PINTuple::~PINTuple()
55{
56 if (mAdDO && mNT) delete mNT;
57}
58
59//++
60// Titre Méthodes
61//--
62//++
63// void SelectXY(const char* px, const char* py)
64// Choix des noms de colonnes X,Y définissant les coordonnées des points.
65// Ces deux colonnes doivent être spécifiées pour obtenir un tracé.
66// void SelectErrBar(const char* erbx=NULL, const char* erby=NULL)
67// Choix des noms de colonnes pour le tracé des barres d'erreur.
68// void SelectWt(const char* pw=NULL, int nbins=10)
69// Choix du nom de colonne poids. Dans ce cas, la taille du signe
70// (marker) sera proportionnel à la valeur de cette colonne pour
71// chaque point.
72// void SelectLabel(const char* plabel=NULL)
73// Choix du nom de colonne correspondant à l'étiquette.
74//--
75
76/* --Methode-- */
77void PINTuple::SelectXY(const char* px, const char* py)
78{
79string name;
80if (mNT == NULL) xK = yK = -1;
81if (px == NULL) xK = -1;
82else { name = px; xK = mNT->ColumnIndex(name); }
83if (py == NULL) yK = -1;
84else { name = py; yK = mNT->ColumnIndex(name); }
85}
86
87/* --Methode-- */
88void PINTuple::SelectWt(const char* pw, int nbins)
89{
90nWbins = (nbins > 0) ? nbins : 10;
91if (pw == NULL) wK = -1;
92else { string name = pw; wK = mNT->ColumnIndex(name); }
93
94if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
95else { wMin = 0.; wMax = 1.; }
96}
97
98/* --Methode-- */
99void PINTuple::SelectLabel(const char* plabel)
100{
101if (plabel == NULL) lK = -1;
102else { string name = plabel; lK = mNT->ColumnIndex(name); }
103}
104
105/* --Methode-- */
106void PINTuple::SelectErrBar(const char* erbx, const char* erby)
107{
108string name;
109if (mNT == NULL) xebK = yebK = -1;
110if (erbx == NULL) xebK = -1;
111else { name = erbx; xebK = mNT->ColumnIndex(name); }
112if (erby == NULL) yebK = -1;
113else { name = erby; yebK = mNT->ColumnIndex(name); }
114}
115
116
117/* --Methode-- */
118void PINTuple::UpdateLimits()
119{
120 if (!mNT) return;
121 if (mNT->NbLines() <= 0) return;
122 if ( (xK < 0) || (yK < 0) ) return;
123
124 // Commencer par trouver nos limites
125 double dx, dy;
126 double xmin, xmax, ymin, ymax;
127 xmin = ymin = 9.e19;
128 xmax = ymax = -9.e19;
129 mNT->GetMinMax(xK, xmin, xmax);
130 mNT->GetMinMax(yK, ymin, ymax);
131
132 dx = 0.02*(xmax-xmin);
133 dy = 0.02*(ymax-ymin);
134
135 SetLimits(xmin-dx, xmax+dx, ymin-dy, ymax+dy);
136 SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
137}
138
139
140/* --Methode-- */
141void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
142{
143double xp,yp,xer,yer,wp;
144double xl,yl;
145int nok;
146
147if (!mNT) return;
148if ( (xK < 0) || (yK < 0) ) return;
149if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
150
151// Pour tracer des markers avec taille fonction de Wt (poids)
152double dw = (wMax-wMin)/nWbins;
153if (dw < 1.e-19) dw = 1.e19;
154int msz,sz;
155
156PIMarker mrk;
157if (wK >= 0) mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_CircleMarker;
158else mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_DotMarker;
159msz = mMSz;
160if (msz < 1) msz = 1;
161g->SelMarker(msz, mrk);
162
163nok = 0;
164xp = yp = xl = yl = 0;
165for (int i=0; i<mNT->NbLines(); i++) {
166 xl = xp; yl = yp;
167 xp = mNT->GetCell(i, xK);
168 yp = mNT->GetCell(i, yK);
169 if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
170 if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) ) // On relie les points ...
171 g->DrawLine(xl, yl, xp, yp);
172 nok++;
173 if ( xebK >= 0 ) {
174 xer = mNT->GetCell(i, xebK);
175 if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
176 }
177 if ( yebK >= 0 ) {
178 yer = mNT->GetCell(i, yebK);
179 if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
180 }
181 if (wK >= 0) { // Taille de marker en fonction du poids
182 wp = mNT->GetCell(i, wK);
183 sz = (int)((wp-wMin)/dw);
184 if (sz < 0) sz = 0;
185 if (sz > nWbins) sz = nWbins;
186 sz += msz;
187 if (sz < 2) g->SelMarker(sz, PI_DotMarker);
188 else g->SelMarker(sz, mrk);
189 }
190 // Trace du marker
191 if ((wK >= 0)||(lK < 0)||(mMrk != PI_NotDefMarker)) g->DrawMarker(xp, yp);
192 // Trace eventuel du label
193 if (lK >= 0) g->DrawString(xp, yp, mNT->GetCelltoString(i, lK).c_str());
194
195}
196
197if (stats) { // Trace de stats
198 char label[64];
199 sprintf(label, "Nd= %d/ Ntot= %d", nok, mNT->NbLines());
200 g->SelFontSz((YMax() - YMin())/25, mFAtt);
201 PIGrCoord a,d;
202 double cH = (double)g->GetFontHeight(a,d);
203 double cellHeight = cH * 1.4;
204 double cellWidth = (double)g->CalcStringWidth(label) * 1.1;
205 g->DrawLine(XMax() - cellWidth, YMax(),
206 XMax() - cellWidth, YMax() - cellHeight);
207 g->DrawLine(XMax() - cellWidth, YMax() - cellHeight,
208 XMax() , YMax() - cellHeight);
209 g->DrawString(XMax() - cellWidth*0.95, YMax() - cH*1.2, label);
210}
211
212return;
213}
214
215/* --Methode-- */
216void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
217{
218if (!mNT) return;
219if ( (xK < 0) || (yK < 0) ) return;
220
221int ncnt = 0;
222double xp,yp;
223char buff[128];
224sprintf(buff,"PINTuple: NLines= %d NCol= %d \n", mNT->NbLines(), mNT->NbColumns());
225info += buff;
226info += mNT->LineHeaderToString();
227for (int i=0; i<mNT->NbLines(); i++) {
228 xp = mNT->GetCell(i, xK);
229 yp = mNT->GetCell(i, yK);
230 if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
231 ncnt++;
232 if (ncnt > 101) continue;
233 info += mNT->LineToString(i);
234 }
235if (ncnt >= 101) info += " .... \n";
236sprintf(buff," %d points inside selected region \n", ncnt);
237info += buff;
238// printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt);
239return;
240}
Note: See TracBrowser for help on using the repository browser.