[537] | 1 | // Peida Interactive - PI R. Ansari 97-99
|
---|
| 2 | // Traceur (Drawer) pour NTupleInterface
|
---|
| 3 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
| 4 |
|
---|
[165] | 5 | #include <stdio.h>
|
---|
| 6 | #include "pintuple.h"
|
---|
| 7 |
|
---|
[537] | 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 | //--
|
---|
[165] | 40 |
|
---|
| 41 | /* --Methode-- */
|
---|
[326] | 42 | PINTuple::PINTuple(NTupleInterface* nt, bool ad)
|
---|
[165] | 43 | : PIDrawer()
|
---|
| 44 | {
|
---|
| 45 | mNT = nt;
|
---|
| 46 | mAdDO = ad;
|
---|
| 47 | SelectXY(NULL, NULL);
|
---|
[336] | 48 | SelectWt(NULL, 1);
|
---|
[165] | 49 | SelectErrBar();
|
---|
[486] | 50 | SelectLabel(NULL);
|
---|
[165] | 51 | }
|
---|
| 52 |
|
---|
| 53 | PINTuple::~PINTuple()
|
---|
| 54 | {
|
---|
| 55 | if (mAdDO && mNT) delete mNT;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[537] | 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 |
|
---|
[165] | 75 | /* --Methode-- */
|
---|
| 76 | void PINTuple::SelectXY(const char* px, const char* py)
|
---|
| 77 | {
|
---|
[326] | 78 | string name;
|
---|
[165] | 79 | if (mNT == NULL) xK = yK = -1;
|
---|
| 80 | if (px == NULL) xK = -1;
|
---|
[326] | 81 | else { name = px; xK = mNT->ColumnIndex(name); }
|
---|
[165] | 82 | if (py == NULL) yK = -1;
|
---|
[326] | 83 | else { name = py; yK = mNT->ColumnIndex(name); }
|
---|
[165] | 84 | }
|
---|
| 85 |
|
---|
| 86 | /* --Methode-- */
|
---|
[333] | 87 | void PINTuple::SelectWt(const char* pw, int nbins)
|
---|
| 88 | {
|
---|
| 89 | nWbins = (nbins > 0) ? nbins : 10;
|
---|
| 90 | if (pw == NULL) wK = -1;
|
---|
| 91 | else { string name = pw; wK = mNT->ColumnIndex(name); }
|
---|
| 92 |
|
---|
| 93 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
|
---|
| 94 | else { wMin = 0.; wMax = 1.; }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /* --Methode-- */
|
---|
[486] | 98 | void PINTuple::SelectLabel(const char* plabel)
|
---|
| 99 | {
|
---|
| 100 | if (plabel == NULL) lK = -1;
|
---|
| 101 | else { string name = plabel; lK = mNT->ColumnIndex(name); }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /* --Methode-- */
|
---|
[165] | 105 | void PINTuple::SelectErrBar(const char* erbx, const char* erby)
|
---|
| 106 | {
|
---|
[326] | 107 | string name;
|
---|
[165] | 108 | if (mNT == NULL) xebK = yebK = -1;
|
---|
| 109 | if (erbx == NULL) xebK = -1;
|
---|
[326] | 110 | else { name = erbx; xebK = mNT->ColumnIndex(name); }
|
---|
[165] | 111 | if (erby == NULL) yebK = -1;
|
---|
[326] | 112 | else { name = erby; yebK = mNT->ColumnIndex(name); }
|
---|
[165] | 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | /* --Methode-- */
|
---|
| 117 | void PINTuple::UpdateLimits()
|
---|
| 118 | {
|
---|
| 119 | if (!mNT) return;
|
---|
[326] | 120 | if (mNT->NbLines() <= 0) return;
|
---|
[165] | 121 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 122 |
|
---|
| 123 | // Commencer par trouver nos limites
|
---|
[326] | 124 | double dx, dy;
|
---|
| 125 | double xmin, xmax, ymin, ymax;
|
---|
[165] | 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-- */
|
---|
[205] | 140 | void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
[165] | 141 | {
|
---|
[333] | 142 | double xp,yp,xer,yer,wp;
|
---|
[326] | 143 | double xl,yl;
|
---|
[165] | 144 | int nok;
|
---|
| 145 |
|
---|
| 146 | if (!mNT) return;
|
---|
| 147 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 148 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
[326] | 149 |
|
---|
[333] | 150 | // Pour tracer des markers avec taille fonction de Wt (poids)
|
---|
| 151 | double dw = (wMax-wMin)/nWbins;
|
---|
| 152 | if (dw < 1.e-19) dw = 1.e19;
|
---|
| 153 | int msz,sz;
|
---|
| 154 |
|
---|
| 155 | PIMarker mrk;
|
---|
| 156 | if (wK >= 0) mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_CircleMarker;
|
---|
| 157 | else mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_DotMarker;
|
---|
| 158 | msz = mMSz;
|
---|
| 159 | if (msz < 1) msz = 1;
|
---|
[344] | 160 | g->SelMarker(msz, mrk);
|
---|
[333] | 161 |
|
---|
[165] | 162 | nok = 0;
|
---|
[326] | 163 | xp = yp = xl = yl = 0;
|
---|
| 164 | for (int i=0; i<mNT->NbLines(); i++) {
|
---|
| 165 | xl = xp; yl = yp;
|
---|
| 166 | xp = mNT->GetCell(i, xK);
|
---|
| 167 | yp = mNT->GetCell(i, yK);
|
---|
[165] | 168 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
---|
[326] | 169 | if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) ) // On relie les points ...
|
---|
| 170 | g->DrawLine(xl, yl, xp, yp);
|
---|
[165] | 171 | nok++;
|
---|
| 172 | if ( xebK >= 0 ) {
|
---|
[326] | 173 | xer = mNT->GetCell(i, xebK);
|
---|
[165] | 174 | if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
|
---|
| 175 | }
|
---|
| 176 | if ( yebK >= 0 ) {
|
---|
[326] | 177 | yer = mNT->GetCell(i, yebK);
|
---|
[165] | 178 | if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
|
---|
| 179 | }
|
---|
[333] | 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 | }
|
---|
[486] | 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 |
|
---|
[165] | 194 | }
|
---|
| 195 |
|
---|
| 196 | /*
|
---|
| 197 | sprintf(buff, "NTuple: NEntry= %d NDisp= %d", (int)mNT->NEntry(), nok);
|
---|
| 198 | g->BaseGraphic()->DrawString(15,15,buff);
|
---|
| 199 | */
|
---|
| 200 | return;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[344] | 203 | /* --Methode-- */
|
---|
| 204 | void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
|
---|
| 205 | {
|
---|
| 206 | if (!mNT) return;
|
---|
| 207 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 208 |
|
---|
| 209 | int ncnt = 0;
|
---|
| 210 | double xp,yp;
|
---|
| 211 | char buff[128];
|
---|
| 212 | sprintf(buff,"PINTuple: NLines= %d NCol= %d \n", mNT->NbLines(), mNT->NbColumns());
|
---|
| 213 | info += buff;
|
---|
| 214 | info += mNT->LineHeaderToString();
|
---|
| 215 | for (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 | }
|
---|
| 223 | if (ncnt >= 101) info += " .... \n";
|
---|
| 224 | sprintf(buff," %d points inside selected region \n", ncnt);
|
---|
| 225 | info += buff;
|
---|
| 226 | // printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt);
|
---|
| 227 | return;
|
---|
| 228 | }
|
---|