[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);
|
---|
[2350] | 48 | ConnectPoints(false);
|
---|
[165] | 49 | SelectXY(NULL, NULL);
|
---|
[336] | 50 | SelectWt(NULL, 1);
|
---|
[165] | 51 | SelectErrBar();
|
---|
[486] | 52 | SelectLabel(NULL);
|
---|
[1856] | 53 | SetName("NTupleDrw");
|
---|
[165] | 54 | }
|
---|
| 55 |
|
---|
| 56 | PINTuple::~PINTuple()
|
---|
| 57 | {
|
---|
| 58 | if (mAdDO && mNT) delete mNT;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[537] | 61 | //++
|
---|
| 62 | // Titre Méthodes
|
---|
| 63 | //--
|
---|
| 64 | //++
|
---|
| 65 | // void SelectXY(const char* px, const char* py)
|
---|
| 66 | // Choix des noms de colonnes X,Y définissant les coordonnées des points.
|
---|
| 67 | // Ces deux colonnes doivent être spécifiées pour obtenir un tracé.
|
---|
| 68 | // void SelectErrBar(const char* erbx=NULL, const char* erby=NULL)
|
---|
| 69 | // Choix des noms de colonnes pour le tracé des barres d'erreur.
|
---|
| 70 | // void SelectWt(const char* pw=NULL, int nbins=10)
|
---|
| 71 | // Choix du nom de colonne poids. Dans ce cas, la taille du signe
|
---|
| 72 | // (marker) sera proportionnel à la valeur de cette colonne pour
|
---|
| 73 | // chaque point.
|
---|
| 74 | // void SelectLabel(const char* plabel=NULL)
|
---|
| 75 | // Choix du nom de colonne correspondant à l'étiquette.
|
---|
| 76 | //--
|
---|
| 77 |
|
---|
[165] | 78 | /* --Methode-- */
|
---|
| 79 | void PINTuple::SelectXY(const char* px, const char* py)
|
---|
| 80 | {
|
---|
[326] | 81 | string name;
|
---|
[165] | 82 | if (mNT == NULL) xK = yK = -1;
|
---|
| 83 | if (px == NULL) xK = -1;
|
---|
[326] | 84 | else { name = px; xK = mNT->ColumnIndex(name); }
|
---|
[165] | 85 | if (py == NULL) yK = -1;
|
---|
[326] | 86 | else { name = py; yK = mNT->ColumnIndex(name); }
|
---|
[165] | 87 | }
|
---|
| 88 |
|
---|
| 89 | /* --Methode-- */
|
---|
[333] | 90 | void PINTuple::SelectWt(const char* pw, int nbins)
|
---|
| 91 | {
|
---|
| 92 | nWbins = (nbins > 0) ? nbins : 10;
|
---|
| 93 | if (pw == NULL) wK = -1;
|
---|
| 94 | else { string name = pw; wK = mNT->ColumnIndex(name); }
|
---|
| 95 |
|
---|
| 96 | if (wK >= 0) mNT->GetMinMax(wK, wMin, wMax);
|
---|
| 97 | else { wMin = 0.; wMax = 1.; }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | /* --Methode-- */
|
---|
[486] | 101 | void PINTuple::SelectLabel(const char* plabel)
|
---|
| 102 | {
|
---|
| 103 | if (plabel == NULL) lK = -1;
|
---|
| 104 | else { string name = plabel; lK = mNT->ColumnIndex(name); }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | /* --Methode-- */
|
---|
[165] | 108 | void PINTuple::SelectErrBar(const char* erbx, const char* erby)
|
---|
| 109 | {
|
---|
[326] | 110 | string name;
|
---|
[165] | 111 | if (mNT == NULL) xebK = yebK = -1;
|
---|
| 112 | if (erbx == NULL) xebK = -1;
|
---|
[326] | 113 | else { name = erbx; xebK = mNT->ColumnIndex(name); }
|
---|
[165] | 114 | if (erby == NULL) yebK = -1;
|
---|
[326] | 115 | else { name = erby; yebK = mNT->ColumnIndex(name); }
|
---|
[165] | 116 | }
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 | /* --Methode-- */
|
---|
| 120 | void PINTuple::UpdateLimits()
|
---|
| 121 | {
|
---|
| 122 | if (!mNT) return;
|
---|
[326] | 123 | if (mNT->NbLines() <= 0) return;
|
---|
[165] | 124 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 125 |
|
---|
| 126 | // Commencer par trouver nos limites
|
---|
[326] | 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);
|
---|
[2115] | 132 | PIAxes::ReSizeMinMax(isLogScaleX(),xmin,xmax);
|
---|
| 133 | PIAxes::ReSizeMinMax(isLogScaleY(),ymin,ymax);
|
---|
| 134 | SetLimits(xmin,xmax,ymin,ymax);
|
---|
[548] | 135 | // SetAxesFlags(kBoxAxes | kExtTicks | kLabels); Ne pas faire - Reza 11/99
|
---|
[165] | 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;
|
---|
[548] | 147 | if (axesFlags != kAxesNone) DrawAxes(g);
|
---|
[165] | 148 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
[1905] | 149 | if (GetGraphicAtt().GetLineAtt() == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
[326] | 150 |
|
---|
[333] | 151 | // Pour tracer des markers avec taille fonction de Wt (poids)
|
---|
| 152 | double dw = (wMax-wMin)/nWbins;
|
---|
| 153 | if (dw < 1.e-19) dw = 1.e19;
|
---|
| 154 | int msz,sz;
|
---|
| 155 |
|
---|
[1905] | 156 | PIMarker mmrk = GetGraphicAtt().GetMarker();
|
---|
[333] | 157 | PIMarker mrk;
|
---|
[1905] | 158 | if (wK >= 0) mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
|
---|
| 159 | else mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
|
---|
[1920] | 160 | msz = GetGraphicAtt().GetMarkerSz();
|
---|
[333] | 161 | if (msz < 1) msz = 1;
|
---|
[344] | 162 | g->SelMarker(msz, mrk);
|
---|
[333] | 163 |
|
---|
[685] | 164 | PIGrCoord uxmin, uxmax, uymin, uymax;
|
---|
| 165 | g->GetGrSpace(uxmin, uxmax, uymin, uymax);
|
---|
| 166 | double xmin2 = uxmin;
|
---|
| 167 | double ymin2 = uymin;
|
---|
| 168 | double xmax2 = uxmax;
|
---|
| 169 | double ymax2 = uymax;
|
---|
| 170 |
|
---|
[165] | 171 | nok = 0;
|
---|
[326] | 172 | xp = yp = xl = yl = 0;
|
---|
[2115] | 173 | for (long i=0; i<(long)mNT->NbLines(); i++) {
|
---|
[326] | 174 | xl = xp; yl = yp;
|
---|
| 175 | xp = mNT->GetCell(i, xK);
|
---|
| 176 | yp = mNT->GetCell(i, yK);
|
---|
[686] | 177 | if ( (xp < xmin2) || (xp > xmax2) || (yp < ymin2) || (yp > ymax2) ) continue;
|
---|
| 178 | nok++;
|
---|
[165] | 179 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
---|
[2350] | 180 | if ( (i > 0) && connectPts )
|
---|
[1905] | 181 | g->DrawLine(xl, yl, xp, yp); // On relie les points ...
|
---|
[165] | 182 | if ( xebK >= 0 ) {
|
---|
[326] | 183 | xer = mNT->GetCell(i, xebK);
|
---|
[165] | 184 | if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
|
---|
| 185 | }
|
---|
| 186 | if ( yebK >= 0 ) {
|
---|
[326] | 187 | yer = mNT->GetCell(i, yebK);
|
---|
[165] | 188 | if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
|
---|
| 189 | }
|
---|
[333] | 190 | if (wK >= 0) { // Taille de marker en fonction du poids
|
---|
| 191 | wp = mNT->GetCell(i, wK);
|
---|
| 192 | sz = (int)((wp-wMin)/dw);
|
---|
| 193 | if (sz < 0) sz = 0;
|
---|
| 194 | if (sz > nWbins) sz = nWbins;
|
---|
| 195 | sz += msz;
|
---|
| 196 | if (sz < 2) g->SelMarker(sz, PI_DotMarker);
|
---|
| 197 | else g->SelMarker(sz, mrk);
|
---|
| 198 | }
|
---|
[486] | 199 | // Trace du marker
|
---|
[1905] | 200 | if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker)) g->DrawMarker(xp, yp);
|
---|
[486] | 201 | // Trace eventuel du label
|
---|
| 202 | if (lK >= 0) g->DrawString(xp, yp, mNT->GetCelltoString(i, lK).c_str());
|
---|
| 203 |
|
---|
[165] | 204 | }
|
---|
| 205 |
|
---|
[544] | 206 | if (stats) { // Trace de stats
|
---|
[1905] | 207 | g->SelFontSz((YMax() - YMin())/30);
|
---|
[1645] | 208 | // La hauteur de la cellule
|
---|
[544] | 209 | PIGrCoord a,d;
|
---|
| 210 | double cH = (double)g->GetFontHeight(a,d);
|
---|
[1645] | 211 | double cellHeight = 1.2 * cH;
|
---|
| 212 | // Les labels et leurs longueurs -> largeur de la cellule
|
---|
| 213 | char label[64];
|
---|
| 214 | sprintf(label, "Nd= %d / Ntot= %d", nok, mNT->NbLines());
|
---|
[1644] | 215 | double cellWidth = 1.1 * (double)g->CalcStringWidth(label);
|
---|
[1645] | 216 | double xu, yu, cw;
|
---|
| 217 | // Les limites du cadre
|
---|
[548] | 218 | xu = g->DeltaUCX(XMax(), - cellWidth);
|
---|
| 219 | yu = g->DeltaUCY(YMax(), - cellHeight);
|
---|
| 220 | g->DrawLine(xu, YMax(), xu, yu);
|
---|
| 221 | g->DrawLine(xu, yu, XMax(), yu);
|
---|
[1645] | 222 | // L'ecriture des labels (attention aux inversions possibles des axes!)
|
---|
| 223 | cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth;
|
---|
| 224 | xu = g->DeltaUCX(XMax(),cw);
|
---|
| 225 | cw = (g->isAxeYDirUpDown()) ? -0.1*cH : -1.1*cH;
|
---|
| 226 | yu = g->DeltaUCY(YMax(),cw);
|
---|
| 227 | g->DrawString(xu,yu,label);
|
---|
[544] | 228 | }
|
---|
| 229 |
|
---|
[165] | 230 | return;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
[344] | 233 | /* --Methode-- */
|
---|
| 234 | void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
|
---|
| 235 | {
|
---|
| 236 | if (!mNT) return;
|
---|
| 237 | if ( (xK < 0) || (yK < 0) ) return;
|
---|
| 238 |
|
---|
| 239 | int ncnt = 0;
|
---|
| 240 | double xp,yp;
|
---|
| 241 | char buff[128];
|
---|
| 242 | sprintf(buff,"PINTuple: NLines= %d NCol= %d \n", mNT->NbLines(), mNT->NbColumns());
|
---|
| 243 | info += buff;
|
---|
| 244 | info += mNT->LineHeaderToString();
|
---|
[2115] | 245 | for(long i=0; i<(long)mNT->NbLines(); i++) {
|
---|
[344] | 246 | xp = mNT->GetCell(i, xK);
|
---|
| 247 | yp = mNT->GetCell(i, yK);
|
---|
| 248 | if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) ) continue;
|
---|
| 249 | ncnt++;
|
---|
| 250 | if (ncnt > 101) continue;
|
---|
| 251 | info += mNT->LineToString(i);
|
---|
| 252 | }
|
---|
| 253 | if (ncnt >= 101) info += " .... \n";
|
---|
| 254 | sprintf(buff," %d points inside selected region \n", ncnt);
|
---|
| 255 | info += buff;
|
---|
| 256 | // printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt);
|
---|
| 257 | return;
|
---|
| 258 | }
|
---|
[1971] | 259 |
|
---|
| 260 | /* La methode DecodeOptionString permet de decoder un ensemble d'options
|
---|
| 261 | et de parametre d'affichage specifie sous forme d'un vecteur de string.
|
---|
| 262 | Si rmdecopt == true, les options decodees sont supprimees du vecteur
|
---|
| 263 | de string fourni en entree - ce qui permet l'enchainement eventuel
|
---|
| 264 | de plusieurs decodages de string.
|
---|
| 265 | Les options peuvent etre sous forme de flag : "stat" "nostat"
|
---|
| 266 | ou plus complexes, par exemple "dynamic=-3,3"
|
---|
| 267 | Rc: La methode renvoie le nombre d'options decodees
|
---|
| 268 | */
|
---|
| 269 |
|
---|
| 270 | /* --Methode-- */
|
---|
| 271 | int PINTuple::DecodeOptionString(vector<string> & opt, bool rmdecopt)
|
---|
| 272 | {
|
---|
[2229] | 273 | int optsz1 = opt.size();
|
---|
| 274 | if(optsz1<1) return(0);
|
---|
[1971] | 275 | // On appelle d'abord le decodage de la classe PIDrawer de laquelle
|
---|
| 276 | // on herite. (Pas obligatoire) on decode donc ici les attributs de
|
---|
| 277 | // couleur, fontes ...
|
---|
| 278 | int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt);
|
---|
[2229] | 279 | if(optsz1-ndec1<1) return(ndec1); // si tout a ete decode
|
---|
[1971] | 280 |
|
---|
| 281 | vector<string> udopt; // On gardera ici les options non decodees
|
---|
| 282 | unsigned int k = 0;
|
---|
| 283 | int ndec = opt.size();
|
---|
| 284 | for( k=0; k<opt.size(); k++ ) {
|
---|
| 285 | string opts = opt[k];
|
---|
[2229] | 286 | if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true);
|
---|
| 287 | else if( opts=="nsta" || opts=="nstat"
|
---|
| 288 | || opts=="nostat" || opts=="nostats") SetStats(false);
|
---|
[2350] | 289 | else if (opts == "connectpoints") ConnectPoints(true);
|
---|
| 290 | else if (opts == "noconnectpoints") ConnectPoints(false);
|
---|
[1971] | 291 | else {
|
---|
| 292 | // Si option non decode
|
---|
| 293 | ndec--;
|
---|
| 294 | // S'il faut supprimer les options decodees
|
---|
| 295 | if (rmdecopt) udopt.push_back(opts);
|
---|
| 296 | }
|
---|
| 297 | }
|
---|
| 298 | // S'il faut supprimer les options decodees, on remplace l'argument opt
|
---|
| 299 | // par le vecteur des options non decodees.
|
---|
| 300 | if (rmdecopt) opt = udopt;
|
---|
| 301 | return(ndec+ndec1);
|
---|
| 302 | }
|
---|
[1975] | 303 |
|
---|
| 304 | /* La methode GetOptionsHelpInfo(string& info) renvoie une chaine
|
---|
| 305 | avec la description des options comprises par ce drawer
|
---|
| 306 | Note: Il est preferable de ne pas initialiser la chaine
|
---|
| 307 | string info au depart, afin de permettre de mettre bout a
|
---|
| 308 | bout les aides de differents Drawer */
|
---|
| 309 |
|
---|
| 310 | /* --Methode-- */
|
---|
| 311 | void PINTuple::GetOptionsHelpInfo(string& info)
|
---|
| 312 | {
|
---|
[2229] | 313 | // On recupere d'abord la chaine info de la classe de base
|
---|
| 314 | PIDrawer::GetOptionsHelpInfo(info);
|
---|
| 315 | info += " ---- PINTuple options help info : \n" ;
|
---|
[2350] | 316 | info += " sta,stat,stats: activate statistic display\n";
|
---|
[2229] | 317 | info += " nsta,nstat,nostat,nostats: deactivate statistic display\n";
|
---|
[2350] | 318 | info += " connectpoints: The points are connected by a line \n";
|
---|
| 319 | info += " noconnectpoints (this is the default) \n";
|
---|
| 320 | info += " and usual color/line/marker/... attribute decoding \n";
|
---|
[2229] | 321 | return;
|
---|
[1975] | 322 | }
|
---|