[165] | 1 | #include <stdio.h>
|
---|
| 2 | #include "pintuple.h"
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | /* --Methode-- */
|
---|
[326] | 6 | PINTuple::PINTuple(NTupleInterface* nt, bool ad)
|
---|
[165] | 7 | : PIDrawer()
|
---|
| 8 | {
|
---|
| 9 | mNT = nt;
|
---|
| 10 | mAdDO = ad;
|
---|
| 11 | SelectXY(NULL, NULL);
|
---|
[336] | 12 | SelectWt(NULL, 1);
|
---|
[165] | 13 | SelectErrBar();
|
---|
[486] | 14 | SelectLabel(NULL);
|
---|
[165] | 15 | }
|
---|
| 16 |
|
---|
| 17 | PINTuple::~PINTuple()
|
---|
| 18 | {
|
---|
| 19 | if (mAdDO && mNT) delete mNT;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | /* --Methode-- */
|
---|
| 23 | void PINTuple::SelectXY(const char* px, const char* py)
|
---|
| 24 | {
|
---|
[326] | 25 | string name;
|
---|
[165] | 26 | if (mNT == NULL) xK = yK = -1;
|
---|
| 27 | if (px == NULL) xK = -1;
|
---|
[326] | 28 | else { name = px; xK = mNT->ColumnIndex(name); }
|
---|
[165] | 29 | if (py == NULL) yK = -1;
|
---|
[326] | 30 | else { name = py; yK = mNT->ColumnIndex(name); }
|
---|
[165] | 31 | }
|
---|
| 32 |
|
---|
| 33 | /* --Methode-- */
|
---|
[333] | 34 | void PINTuple::SelectWt(const char* pw, int nbins)
|
---|
| 35 | {
|
---|
| 36 | nWbins = (nbins > 0) ? nbins : 10;
|
---|
| 37 | if (pw == NULL) wK = -1;
|
---|
| 38 | else { string name = pw; wK = mNT->ColumnIndex(name); }
|
---|
| 39 |
|
---|
| 40 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
|
---|
| 41 | else { wMin = 0.; wMax = 1.; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /* --Methode-- */
|
---|
[486] | 45 | void PINTuple::SelectLabel(const char* plabel)
|
---|
| 46 | {
|
---|
| 47 | if (plabel == NULL) lK = -1;
|
---|
| 48 | else { string name = plabel; lK = mNT->ColumnIndex(name); }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /* --Methode-- */
|
---|
[165] | 52 | void PINTuple::SelectErrBar(const char* erbx, const char* erby)
|
---|
| 53 | {
|
---|
[326] | 54 | string name;
|
---|
[165] | 55 | if (mNT == NULL) xebK = yebK = -1;
|
---|
| 56 | if (erbx == NULL) xebK = -1;
|
---|
[326] | 57 | else { name = erbx; xebK = mNT->ColumnIndex(name); }
|
---|
[165] | 58 | if (erby == NULL) yebK = -1;
|
---|
[326] | 59 | else { name = erby; yebK = mNT->ColumnIndex(name); }
|
---|
[165] | 60 | }
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | /* --Methode-- */
|
---|
| 64 | void PINTuple::UpdateLimits()
|
---|
| 65 | {
|
---|
| 66 | if (!mNT) return;
|
---|
[326] | 67 | if (mNT->NbLines() <= 0) return;
|
---|
[165] | 68 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 69 |
|
---|
| 70 | // Commencer par trouver nos limites
|
---|
[326] | 71 | double dx, dy;
|
---|
| 72 | double xmin, xmax, ymin, ymax;
|
---|
[165] | 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-- */
|
---|
[205] | 87 | void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
[165] | 88 | {
|
---|
[333] | 89 | double xp,yp,xer,yer,wp;
|
---|
[326] | 90 | double xl,yl;
|
---|
[165] | 91 | int nok;
|
---|
| 92 |
|
---|
| 93 | if (!mNT) return;
|
---|
| 94 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 95 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
[326] | 96 |
|
---|
[333] | 97 | // Pour tracer des markers avec taille fonction de Wt (poids)
|
---|
| 98 | double dw = (wMax-wMin)/nWbins;
|
---|
| 99 | if (dw < 1.e-19) dw = 1.e19;
|
---|
| 100 | int msz,sz;
|
---|
| 101 |
|
---|
| 102 | PIMarker mrk;
|
---|
| 103 | if (wK >= 0) mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_CircleMarker;
|
---|
| 104 | else mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_DotMarker;
|
---|
| 105 | msz = mMSz;
|
---|
| 106 | if (msz < 1) msz = 1;
|
---|
[344] | 107 | g->SelMarker(msz, mrk);
|
---|
[333] | 108 |
|
---|
[165] | 109 | nok = 0;
|
---|
[326] | 110 | xp = yp = xl = yl = 0;
|
---|
| 111 | for (int i=0; i<mNT->NbLines(); i++) {
|
---|
| 112 | xl = xp; yl = yp;
|
---|
| 113 | xp = mNT->GetCell(i, xK);
|
---|
| 114 | yp = mNT->GetCell(i, yK);
|
---|
[165] | 115 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
---|
[326] | 116 | if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) ) // On relie les points ...
|
---|
| 117 | g->DrawLine(xl, yl, xp, yp);
|
---|
[165] | 118 | nok++;
|
---|
| 119 | if ( xebK >= 0 ) {
|
---|
[326] | 120 | xer = mNT->GetCell(i, xebK);
|
---|
[165] | 121 | if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
|
---|
| 122 | }
|
---|
| 123 | if ( yebK >= 0 ) {
|
---|
[326] | 124 | yer = mNT->GetCell(i, yebK);
|
---|
[165] | 125 | if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
|
---|
| 126 | }
|
---|
[333] | 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 | }
|
---|
[486] | 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 |
|
---|
[165] | 141 | }
|
---|
| 142 |
|
---|
| 143 | /*
|
---|
| 144 | sprintf(buff, "NTuple: NEntry= %d NDisp= %d", (int)mNT->NEntry(), nok);
|
---|
| 145 | g->BaseGraphic()->DrawString(15,15,buff);
|
---|
| 146 | */
|
---|
| 147 | return;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[344] | 150 | /* --Methode-- */
|
---|
| 151 | void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
|
---|
| 152 | {
|
---|
| 153 | if (!mNT) return;
|
---|
| 154 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 155 |
|
---|
| 156 | int ncnt = 0;
|
---|
| 157 | double xp,yp;
|
---|
| 158 | char buff[128];
|
---|
| 159 | sprintf(buff,"PINTuple: NLines= %d NCol= %d \n", mNT->NbLines(), mNT->NbColumns());
|
---|
| 160 | info += buff;
|
---|
| 161 | info += mNT->LineHeaderToString();
|
---|
| 162 | for (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 | }
|
---|
| 170 | if (ncnt >= 101) info += " .... \n";
|
---|
| 171 | sprintf(buff," %d points inside selected region \n", ncnt);
|
---|
| 172 | info += buff;
|
---|
| 173 | // printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt);
|
---|
| 174 | return;
|
---|
| 175 | }
|
---|