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