[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)
|
---|
[544] | 36 | // Constructeur. Si "ad == true", l'objet "nt" est détruit par
|
---|
[537] | 37 | // le destructeur de l'objet "PINTuple"
|
---|
[544] | 38 | // Note : "nt" doit être créé par new
|
---|
[537] | 39 | //--
|
---|
[165] | 40 |
|
---|
| 41 | /* --Methode-- */
|
---|
[326] | 42 | PINTuple::PINTuple(NTupleInterface* nt, bool ad)
|
---|
[165] | 43 | : PIDrawer()
|
---|
| 44 | {
|
---|
| 45 | mNT = nt;
|
---|
| 46 | mAdDO = ad;
|
---|
[544] | 47 | SetStats(true);
|
---|
[165] | 48 | SelectXY(NULL, NULL);
|
---|
[336] | 49 | SelectWt(NULL, 1);
|
---|
[165] | 50 | SelectErrBar();
|
---|
[486] | 51 | SelectLabel(NULL);
|
---|
[1856] | 52 | SetName("NTupleDrw");
|
---|
[165] | 53 | }
|
---|
| 54 |
|
---|
| 55 | PINTuple::~PINTuple()
|
---|
| 56 | {
|
---|
| 57 | if (mAdDO && mNT) delete mNT;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[537] | 60 | //++
|
---|
| 61 | // Titre Méthodes
|
---|
| 62 | //--
|
---|
| 63 | //++
|
---|
| 64 | // void SelectXY(const char* px, const char* py)
|
---|
| 65 | // Choix des noms de colonnes X,Y définissant les coordonnées des points.
|
---|
| 66 | // Ces deux colonnes doivent être spécifiées pour obtenir un tracé.
|
---|
| 67 | // void SelectErrBar(const char* erbx=NULL, const char* erby=NULL)
|
---|
| 68 | // Choix des noms de colonnes pour le tracé des barres d'erreur.
|
---|
| 69 | // void SelectWt(const char* pw=NULL, int nbins=10)
|
---|
| 70 | // Choix du nom de colonne poids. Dans ce cas, la taille du signe
|
---|
| 71 | // (marker) sera proportionnel à la valeur de cette colonne pour
|
---|
| 72 | // chaque point.
|
---|
| 73 | // void SelectLabel(const char* plabel=NULL)
|
---|
| 74 | // Choix du nom de colonne correspondant à l'étiquette.
|
---|
| 75 | //--
|
---|
| 76 |
|
---|
[165] | 77 | /* --Methode-- */
|
---|
| 78 | void PINTuple::SelectXY(const char* px, const char* py)
|
---|
| 79 | {
|
---|
[326] | 80 | string name;
|
---|
[165] | 81 | if (mNT == NULL) xK = yK = -1;
|
---|
| 82 | if (px == NULL) xK = -1;
|
---|
[326] | 83 | else { name = px; xK = mNT->ColumnIndex(name); }
|
---|
[165] | 84 | if (py == NULL) yK = -1;
|
---|
[326] | 85 | else { name = py; yK = mNT->ColumnIndex(name); }
|
---|
[165] | 86 | }
|
---|
| 87 |
|
---|
| 88 | /* --Methode-- */
|
---|
[333] | 89 | void PINTuple::SelectWt(const char* pw, int nbins)
|
---|
| 90 | {
|
---|
| 91 | nWbins = (nbins > 0) ? nbins : 10;
|
---|
| 92 | if (pw == NULL) wK = -1;
|
---|
| 93 | else { string name = pw; wK = mNT->ColumnIndex(name); }
|
---|
| 94 |
|
---|
| 95 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
|
---|
| 96 | else { wMin = 0.; wMax = 1.; }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /* --Methode-- */
|
---|
[486] | 100 | void PINTuple::SelectLabel(const char* plabel)
|
---|
| 101 | {
|
---|
| 102 | if (plabel == NULL) lK = -1;
|
---|
| 103 | else { string name = plabel; lK = mNT->ColumnIndex(name); }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /* --Methode-- */
|
---|
[165] | 107 | void PINTuple::SelectErrBar(const char* erbx, const char* erby)
|
---|
| 108 | {
|
---|
[326] | 109 | string name;
|
---|
[165] | 110 | if (mNT == NULL) xebK = yebK = -1;
|
---|
| 111 | if (erbx == NULL) xebK = -1;
|
---|
[326] | 112 | else { name = erbx; xebK = mNT->ColumnIndex(name); }
|
---|
[165] | 113 | if (erby == NULL) yebK = -1;
|
---|
[326] | 114 | else { name = erby; yebK = mNT->ColumnIndex(name); }
|
---|
[165] | 115 | }
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | /* --Methode-- */
|
---|
| 119 | void PINTuple::UpdateLimits()
|
---|
| 120 | {
|
---|
| 121 | if (!mNT) return;
|
---|
[326] | 122 | if (mNT->NbLines() <= 0) return;
|
---|
[165] | 123 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 124 |
|
---|
| 125 | // Commencer par trouver nos limites
|
---|
[326] | 126 | double dx, dy;
|
---|
| 127 | double xmin, xmax, ymin, ymax;
|
---|
[165] | 128 | xmin = ymin = 9.e19;
|
---|
| 129 | xmax = ymax = -9.e19;
|
---|
| 130 | mNT->GetMinMax(xK, xmin, xmax);
|
---|
| 131 | mNT->GetMinMax(yK, ymin, ymax);
|
---|
| 132 |
|
---|
| 133 | dx = 0.02*(xmax-xmin);
|
---|
| 134 | dy = 0.02*(ymax-ymin);
|
---|
| 135 |
|
---|
| 136 | SetLimits(xmin-dx, xmax+dx, ymin-dy, ymax+dy);
|
---|
[548] | 137 | // SetAxesFlags(kBoxAxes | kExtTicks | kLabels); Ne pas faire - Reza 11/99
|
---|
[165] | 138 | }
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | /* --Methode-- */
|
---|
[205] | 142 | void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
[165] | 143 | {
|
---|
[333] | 144 | double xp,yp,xer,yer,wp;
|
---|
[326] | 145 | double xl,yl;
|
---|
[165] | 146 | int nok;
|
---|
| 147 |
|
---|
| 148 | if (!mNT) return;
|
---|
[548] | 149 | if (axesFlags != kAxesNone) DrawAxes(g);
|
---|
[165] | 150 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 151 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
[326] | 152 |
|
---|
[333] | 153 | // Pour tracer des markers avec taille fonction de Wt (poids)
|
---|
| 154 | double dw = (wMax-wMin)/nWbins;
|
---|
| 155 | if (dw < 1.e-19) dw = 1.e19;
|
---|
| 156 | int msz,sz;
|
---|
| 157 |
|
---|
| 158 | PIMarker mrk;
|
---|
| 159 | if (wK >= 0) mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_CircleMarker;
|
---|
| 160 | else mrk = (mMrk != PI_NotDefMarker) ? mMrk : PI_DotMarker;
|
---|
| 161 | msz = mMSz;
|
---|
| 162 | if (msz < 1) msz = 1;
|
---|
[344] | 163 | g->SelMarker(msz, mrk);
|
---|
[333] | 164 |
|
---|
[685] | 165 | PIGrCoord uxmin, uxmax, uymin, uymax;
|
---|
| 166 | g->GetGrSpace(uxmin, uxmax, uymin, uymax);
|
---|
| 167 | double xmin2 = uxmin;
|
---|
| 168 | double ymin2 = uymin;
|
---|
| 169 | double xmax2 = uxmax;
|
---|
| 170 | double ymax2 = uymax;
|
---|
| 171 |
|
---|
[165] | 172 | nok = 0;
|
---|
[326] | 173 | xp = yp = xl = yl = 0;
|
---|
| 174 | for (int i=0; i<mNT->NbLines(); i++) {
|
---|
| 175 | xl = xp; yl = yp;
|
---|
| 176 | xp = mNT->GetCell(i, xK);
|
---|
| 177 | yp = mNT->GetCell(i, yK);
|
---|
[686] | 178 | if ( (xp < xmin2) || (xp > xmax2) || (yp < ymin2) || (yp > ymax2) ) continue;
|
---|
| 179 | nok++;
|
---|
[165] | 180 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
---|
[326] | 181 | if ( (i > 0) && (mLAtt != PI_NotDefLineAtt) ) // On relie les points ...
|
---|
| 182 | g->DrawLine(xl, yl, xp, yp);
|
---|
[165] | 183 | if ( xebK >= 0 ) {
|
---|
[326] | 184 | xer = mNT->GetCell(i, xebK);
|
---|
[165] | 185 | if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
|
---|
| 186 | }
|
---|
| 187 | if ( yebK >= 0 ) {
|
---|
[326] | 188 | yer = mNT->GetCell(i, yebK);
|
---|
[165] | 189 | if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
|
---|
| 190 | }
|
---|
[333] | 191 | if (wK >= 0) { // Taille de marker en fonction du poids
|
---|
| 192 | wp = mNT->GetCell(i, wK);
|
---|
| 193 | sz = (int)((wp-wMin)/dw);
|
---|
| 194 | if (sz < 0) sz = 0;
|
---|
| 195 | if (sz > nWbins) sz = nWbins;
|
---|
| 196 | sz += msz;
|
---|
| 197 | if (sz < 2) g->SelMarker(sz, PI_DotMarker);
|
---|
| 198 | else g->SelMarker(sz, mrk);
|
---|
| 199 | }
|
---|
[486] | 200 | // Trace du marker
|
---|
| 201 | if ((wK >= 0)||(lK < 0)||(mMrk != PI_NotDefMarker)) g->DrawMarker(xp, yp);
|
---|
| 202 | // Trace eventuel du label
|
---|
| 203 | if (lK >= 0) g->DrawString(xp, yp, mNT->GetCelltoString(i, lK).c_str());
|
---|
| 204 |
|
---|
[165] | 205 | }
|
---|
| 206 |
|
---|
[544] | 207 | if (stats) { // Trace de stats
|
---|
[1644] | 208 | g->SelFontSz((YMax() - YMin())/30, mFAtt);
|
---|
[1645] | 209 | // La hauteur de la cellule
|
---|
[544] | 210 | PIGrCoord a,d;
|
---|
| 211 | double cH = (double)g->GetFontHeight(a,d);
|
---|
[1645] | 212 | double cellHeight = 1.2 * cH;
|
---|
| 213 | // Les labels et leurs longueurs -> largeur de la cellule
|
---|
| 214 | char label[64];
|
---|
| 215 | sprintf(label, "Nd= %d / Ntot= %d", nok, mNT->NbLines());
|
---|
[1644] | 216 | double cellWidth = 1.1 * (double)g->CalcStringWidth(label);
|
---|
[1645] | 217 | double xu, yu, cw;
|
---|
| 218 | // Les limites du cadre
|
---|
[548] | 219 | xu = g->DeltaUCX(XMax(), - cellWidth);
|
---|
| 220 | yu = g->DeltaUCY(YMax(), - cellHeight);
|
---|
| 221 | g->DrawLine(xu, YMax(), xu, yu);
|
---|
| 222 | g->DrawLine(xu, yu, XMax(), yu);
|
---|
[1645] | 223 | // L'ecriture des labels (attention aux inversions possibles des axes!)
|
---|
| 224 | cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth;
|
---|
| 225 | xu = g->DeltaUCX(XMax(),cw);
|
---|
| 226 | cw = (g->isAxeYDirUpDown()) ? -0.1*cH : -1.1*cH;
|
---|
| 227 | yu = g->DeltaUCY(YMax(),cw);
|
---|
| 228 | g->DrawString(xu,yu,label);
|
---|
[544] | 229 | }
|
---|
| 230 |
|
---|
[165] | 231 | return;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[344] | 234 | /* --Methode-- */
|
---|
| 235 | void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
|
---|
| 236 | {
|
---|
| 237 | if (!mNT) return;
|
---|
| 238 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 239 |
|
---|
| 240 | int ncnt = 0;
|
---|
| 241 | double xp,yp;
|
---|
| 242 | char buff[128];
|
---|
| 243 | sprintf(buff,"PINTuple: NLines= %d NCol= %d \n", mNT->NbLines(), mNT->NbColumns());
|
---|
| 244 | info += buff;
|
---|
| 245 | info += mNT->LineHeaderToString();
|
---|
| 246 | for (int i=0; i<mNT->NbLines(); i++) {
|
---|
| 247 | xp = mNT->GetCell(i, xK);
|
---|
| 248 | yp = mNT->GetCell(i, yK);
|
---|
| 249 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
---|
| 250 | ncnt++;
|
---|
| 251 | if (ncnt > 101) continue;
|
---|
| 252 | info += mNT->LineToString(i);
|
---|
| 253 | }
|
---|
| 254 | if (ncnt >= 101) info += " .... \n";
|
---|
| 255 | sprintf(buff," %d points inside selected region \n", ncnt);
|
---|
| 256 | info += buff;
|
---|
| 257 | // printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt);
|
---|
| 258 | return;
|
---|
| 259 | }
|
---|