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

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

Documentation PI - Reza 2/11/99

File size: 5.9 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// Cosntructeur. 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 SelectXY(NULL, NULL);
48 SelectWt(NULL, 1);
49 SelectErrBar();
50 SelectLabel(NULL);
51}
52
53PINTuple::~PINTuple()
54{
55 if (mAdDO && mNT) delete mNT;
56}
57
58//++
59// Titre Méthodes
60//--
61//++
62// void SelectXY(const char* px, const char* py)
63// Choix des noms de colonnes X,Y définissant les coordonnées des points.
64// Ces deux colonnes doivent être spécifiées pour obtenir un tracé.
65// void SelectErrBar(const char* erbx=NULL, const char* erby=NULL)
66// Choix des noms de colonnes pour le tracé des barres d'erreur.
67// void SelectWt(const char* pw=NULL, int nbins=10)
68// Choix du nom de colonne poids. Dans ce cas, la taille du signe
69// (marker) sera proportionnel à la valeur de cette colonne pour
70// chaque point.
71// void SelectLabel(const char* plabel=NULL)
72// Choix du nom de colonne correspondant à l'étiquette.
73//--
74
75/* --Methode-- */
76void PINTuple::SelectXY(const char* px, const char* py)
77{
78string name;
79if (mNT == NULL) xK = yK = -1;
80if (px == NULL) xK = -1;
81else { name = px; xK = mNT->ColumnIndex(name); }
82if (py == NULL) yK = -1;
83else { name = py; yK = mNT->ColumnIndex(name); }
84}
85
86/* --Methode-- */
87void PINTuple::SelectWt(const char* pw, int nbins)
88{
89nWbins = (nbins > 0) ? nbins : 10;
90if (pw == NULL) wK = -1;
91else { string name = pw; wK = mNT->ColumnIndex(name); }
92
93if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
94else { wMin = 0.; wMax = 1.; }
95}
96
97/* --Methode-- */
98void PINTuple::SelectLabel(const char* plabel)
99{
100if (plabel == NULL) lK = -1;
101else { string name = plabel; lK = mNT->ColumnIndex(name); }
102}
103
104/* --Methode-- */
105void PINTuple::SelectErrBar(const char* erbx, const char* erby)
106{
107string name;
108if (mNT == NULL) xebK = yebK = -1;
109if (erbx == NULL) xebK = -1;
110else { name = erbx; xebK = mNT->ColumnIndex(name); }
111if (erby == NULL) yebK = -1;
112else { name = erby; yebK = mNT->ColumnIndex(name); }
113}
114
115
116/* --Methode-- */
117void PINTuple::UpdateLimits()
118{
119 if (!mNT) return;
120 if (mNT->NbLines() <= 0) return;
121 if ( (xK < 0) || (yK < 0) ) return;
122
123 // Commencer par trouver nos limites
124 double dx, dy;
125 double xmin, xmax, ymin, ymax;
126 xmin = ymin = 9.e19;
127 xmax = ymax = -9.e19;
128 mNT->GetMinMax(xK, xmin, xmax);
129 mNT->GetMinMax(yK, ymin, ymax);
130
131 dx = 0.02*(xmax-xmin);
132 dy = 0.02*(ymax-ymin);
133
134 SetLimits(xmin-dx, xmax+dx, ymin-dy, ymax+dy);
135 SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
136}
137
138
139/* --Methode-- */
140void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
141{
142double xp,yp,xer,yer,wp;
143double xl,yl;
144int nok;
145
146if (!mNT) return;
147if ( (xK < 0) || (yK < 0) ) return;
148if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
149
150// Pour tracer des markers avec taille fonction de Wt (poids)
151double dw = (wMax-wMin)/nWbins;
152if (dw < 1.e-19) dw = 1.e19;
153int msz,sz;
154
155PIMarker mrk;
156if (wK >= 0) mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_CircleMarker;
157else mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_DotMarker;
158msz = mMSz;
159if (msz < 1) msz = 1;
160g->SelMarker(msz, mrk);
161
162nok = 0;
163xp = yp = xl = yl = 0;
164for (int i=0; i<mNT->NbLines(); i++) {
165 xl = xp; yl = yp;
166 xp = mNT->GetCell(i, xK);
167 yp = mNT->GetCell(i, yK);
168 if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
169 if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) ) // On relie les points ...
170 g->DrawLine(xl, yl, xp, yp);
171 nok++;
172 if ( xebK >= 0 ) {
173 xer = mNT->GetCell(i, xebK);
174 if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
175 }
176 if ( yebK >= 0 ) {
177 yer = mNT->GetCell(i, yebK);
178 if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
179 }
180 if (wK >= 0) { // Taille de marker en fonction du poids
181 wp = mNT->GetCell(i, wK);
182 sz = (int)((wp-wMin)/dw);
183 if (sz < 0) sz = 0;
184 if (sz > nWbins) sz = nWbins;
185 sz += msz;
186 if (sz < 2) g->SelMarker(sz, PI_DotMarker);
187 else g->SelMarker(sz, mrk);
188 }
189 // Trace du marker
190 if ((wK >= 0)||(lK < 0)||(mMrk != PI_NotDefMarker)) g->DrawMarker(xp, yp);
191 // Trace eventuel du label
192 if (lK >= 0) g->DrawString(xp, yp, mNT->GetCelltoString(i, lK).c_str());
193
194}
195
196/*
197sprintf(buff, "NTuple: NEntry= %d NDisp= %d", (int)mNT->NEntry(), nok);
198g->BaseGraphic()->DrawString(15,15,buff);
199*/
200return;
201}
202
203/* --Methode-- */
204void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
205{
206if (!mNT) return;
207if ( (xK < 0) || (yK < 0) ) return;
208
209int ncnt = 0;
210double xp,yp;
211char buff[128];
212sprintf(buff,"PINTuple: NLines= %d NCol= %d \n", mNT->NbLines(), mNT->NbColumns());
213info += buff;
214info += mNT->LineHeaderToString();
215for (int i=0; i<mNT->NbLines(); i++) {
216 xp = mNT->GetCell(i, xK);
217 yp = mNT->GetCell(i, yK);
218 if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
219 ncnt++;
220 if (ncnt > 101) continue;
221 info += mNT->LineToString(i);
222 }
223if (ncnt >= 101) info += " .... \n";
224sprintf(buff," %d points inside selected region \n", ncnt);
225info += buff;
226// printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt);
227return;
228}
Note: See TracBrowser for help on using the repository browser.