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
RevLine 
[165]1#include <stdio.h>
2#include "pintuple.h"
3
4
5/* --Methode-- */
[326]6PINTuple::PINTuple(NTupleInterface* nt, bool ad)
[165]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{
[326]23string name;
[165]24if (mNT == NULL) xK = yK = -1;
25if (px == NULL) xK = -1;
[326]26else { name = px; xK = mNT->ColumnIndex(name); }
[165]27if (py == NULL) yK = -1;
[326]28else { name = py; yK = mNT->ColumnIndex(name); }
[165]29}
30
31/* --Methode-- */
[333]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-- */
[165]43void PINTuple::SelectErrBar(const char* erbx, const char* erby)
44{
[326]45string name;
[165]46if (mNT == NULL) xebK = yebK = -1;
47if (erbx == NULL) xebK = -1;
[326]48else { name = erbx; xebK = mNT->ColumnIndex(name); }
[165]49if (erby == NULL) yebK = -1;
[326]50else { name = erby; yebK = mNT->ColumnIndex(name); }
[165]51}
52
53
54/* --Methode-- */
55void PINTuple::UpdateLimits()
56{
57 if (!mNT) return;
[326]58 if (mNT->NbLines() <= 0) return;
[165]59 if ( (xK < 0) || (yK < 0) ) return;
60
61 // Commencer par trouver nos limites
[326]62 double dx, dy;
63 double xmin, xmax, ymin, ymax;
[165]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-- */
[205]78void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
[165]79{
[333]80double xp,yp,xer,yer,wp;
[326]81double xl,yl;
[165]82int nok;
83
84if (!mNT) return;
85if ( (xK < 0) || (yK < 0) ) return;
86if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
[326]87
[333]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
[165]100nok = 0;
[326]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);
[165]106 if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
[326]107 if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) ) // On relie les points ...
108 g->DrawLine(xl, yl, xp, yp);
[165]109 nok++;
110 if ( xebK >= 0 ) {
[326]111 xer = mNT->GetCell(i, xebK);
[165]112 if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
113 }
114 if ( yebK >= 0 ) {
[326]115 yer = mNT->GetCell(i, yebK);
[165]116 if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
117 }
[333]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 }
[165]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.