| [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 xmin, xmax, ymin, ymax;
 | 
|---|
| [165] | 127 |   xmin = ymin = 9.e19;
 | 
|---|
 | 128 |   xmax = ymax = -9.e19;
 | 
|---|
 | 129 |   mNT->GetMinMax(xK, xmin, xmax);
 | 
|---|
 | 130 |   mNT->GetMinMax(yK, ymin, ymax);
 | 
|---|
| [2115] | 131 |   PIAxes::ReSizeMinMax(isLogScaleX(),xmin,xmax);
 | 
|---|
 | 132 |   PIAxes::ReSizeMinMax(isLogScaleY(),ymin,ymax);
 | 
|---|
 | 133 |   SetLimits(xmin,xmax,ymin,ymax);
 | 
|---|
| [548] | 134 | //  SetAxesFlags(kBoxAxes | kExtTicks | kLabels);  Ne pas faire - Reza 11/99
 | 
|---|
| [165] | 135 | }
 | 
|---|
 | 136 | 
 | 
|---|
 | 137 | 
 | 
|---|
 | 138 | /* --Methode-- */
 | 
|---|
| [205] | 139 | void PINTuple::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
 | 
|---|
| [165] | 140 | {
 | 
|---|
| [333] | 141 | double xp,yp,xer,yer,wp;
 | 
|---|
| [326] | 142 | double xl,yl;
 | 
|---|
| [165] | 143 | int nok;
 | 
|---|
 | 144 | 
 | 
|---|
 | 145 | if (!mNT) return;
 | 
|---|
| [548] | 146 | if (axesFlags != kAxesNone) DrawAxes(g);
 | 
|---|
| [165] | 147 | if ( (xK < 0) || (yK < 0) )  return;
 | 
|---|
| [1905] | 148 | if (GetGraphicAtt().GetLineAtt() == 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 | 
 | 
|---|
| [1905] | 155 | PIMarker mmrk = GetGraphicAtt().GetMarker();
 | 
|---|
| [333] | 156 | PIMarker mrk;
 | 
|---|
| [1905] | 157 | if (wK >= 0)  mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_CircleMarker;
 | 
|---|
 | 158 | else   mrk = (mmrk != PI_NotDefMarker) ? mmrk : PI_DotMarker;
 | 
|---|
| [1920] | 159 |  msz = GetGraphicAtt().GetMarkerSz(); 
 | 
|---|
| [333] | 160 | if (msz < 1) msz = 1;
 | 
|---|
| [344] | 161 | g->SelMarker(msz, mrk);
 | 
|---|
| [333] | 162 | 
 | 
|---|
| [685] | 163 | PIGrCoord uxmin, uxmax, uymin, uymax;
 | 
|---|
 | 164 | g->GetGrSpace(uxmin, uxmax, uymin, uymax);
 | 
|---|
 | 165 | double xmin2 = uxmin;
 | 
|---|
 | 166 | double ymin2 = uymin;
 | 
|---|
 | 167 | double xmax2 = uxmax;
 | 
|---|
 | 168 | double ymax2 = uymax;
 | 
|---|
 | 169 | 
 | 
|---|
| [165] | 170 | nok = 0;  
 | 
|---|
| [326] | 171 | xp = yp = xl = yl = 0;
 | 
|---|
| [2115] | 172 | for (long i=0; i<(long)mNT->NbLines(); i++) {
 | 
|---|
| [326] | 173 |   xl = xp;  yl = yp; 
 | 
|---|
 | 174 |   xp = mNT->GetCell(i, xK);
 | 
|---|
 | 175 |   yp = mNT->GetCell(i, yK);
 | 
|---|
| [686] | 176 |   if ( (xp < xmin2) || (xp > xmax2) || (yp < ymin2) || (yp > ymax2) )  continue;
 | 
|---|
 | 177 |   nok++;
 | 
|---|
| [165] | 178 |   if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) )  continue;
 | 
|---|
| [1905] | 179 |   if ( (i > 0) && (GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) )   
 | 
|---|
 | 180 |     g->DrawLine(xl, yl, xp, yp);  // On relie les points ...
 | 
|---|
| [165] | 181 |   if ( xebK >= 0 ) {
 | 
|---|
| [326] | 182 |     xer = mNT->GetCell(i, xebK);
 | 
|---|
| [165] | 183 |     if(xer>0.) g->DrawLine(xp-xer, yp, xp+xer, yp);
 | 
|---|
 | 184 |   }
 | 
|---|
 | 185 |   if ( yebK >= 0 ) {
 | 
|---|
| [326] | 186 |     yer = mNT->GetCell(i, yebK);
 | 
|---|
| [165] | 187 |     if(yer>0.) g->DrawLine(xp, yp-yer, xp, yp+yer);
 | 
|---|
 | 188 |   }
 | 
|---|
| [333] | 189 |   if (wK >= 0) { // Taille de marker en fonction du poids
 | 
|---|
 | 190 |     wp = mNT->GetCell(i, wK);
 | 
|---|
 | 191 |     sz = (int)((wp-wMin)/dw);
 | 
|---|
 | 192 |     if (sz < 0) sz = 0;
 | 
|---|
 | 193 |     if (sz > nWbins)  sz = nWbins;
 | 
|---|
 | 194 |     sz += msz;
 | 
|---|
 | 195 |     if (sz < 2)  g->SelMarker(sz, PI_DotMarker);
 | 
|---|
 | 196 |     else g->SelMarker(sz, mrk);
 | 
|---|
 | 197 |   }
 | 
|---|
| [486] | 198 |   // Trace du marker
 | 
|---|
| [1905] | 199 |   if ((wK >= 0)||(lK < 0)||(mmrk != PI_NotDefMarker))  g->DrawMarker(xp, yp); 
 | 
|---|
| [486] | 200 |   // Trace eventuel du label
 | 
|---|
 | 201 |   if (lK >= 0) g->DrawString(xp, yp, mNT->GetCelltoString(i, lK).c_str());
 | 
|---|
 | 202 | 
 | 
|---|
| [165] | 203 | }
 | 
|---|
 | 204 | 
 | 
|---|
| [544] | 205 | if (stats) { // Trace de stats 
 | 
|---|
| [1905] | 206 |   g->SelFontSz((YMax() - YMin())/30);  
 | 
|---|
| [1645] | 207 |   // La hauteur de la cellule
 | 
|---|
| [544] | 208 |   PIGrCoord a,d;
 | 
|---|
 | 209 |   double cH = (double)g->GetFontHeight(a,d);
 | 
|---|
| [1645] | 210 |   double cellHeight = 1.2 * cH;
 | 
|---|
 | 211 |   // Les labels et leurs longueurs -> largeur de la cellule
 | 
|---|
 | 212 |   char label[64];
 | 
|---|
 | 213 |   sprintf(label, "Nd= %d / Ntot= %d", nok, mNT->NbLines());
 | 
|---|
| [1644] | 214 |   double cellWidth =   1.1 * (double)g->CalcStringWidth(label);
 | 
|---|
| [1645] | 215 |   double xu, yu, cw;
 | 
|---|
 | 216 |   // Les limites du cadre
 | 
|---|
| [548] | 217 |   xu = g->DeltaUCX(XMax(), - cellWidth);
 | 
|---|
 | 218 |   yu = g->DeltaUCY(YMax(), - cellHeight);
 | 
|---|
 | 219 |   g->DrawLine(xu, YMax(), xu, yu);
 | 
|---|
 | 220 |   g->DrawLine(xu, yu, XMax(), yu);
 | 
|---|
| [1645] | 221 |   // L'ecriture des labels (attention aux inversions possibles des axes!)
 | 
|---|
 | 222 |   cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth;
 | 
|---|
 | 223 |   xu = g->DeltaUCX(XMax(),cw);
 | 
|---|
 | 224 |   cw = (g->isAxeYDirUpDown()) ? -0.1*cH : -1.1*cH;
 | 
|---|
 | 225 |   yu = g->DeltaUCY(YMax(),cw);
 | 
|---|
 | 226 |   g->DrawString(xu,yu,label);
 | 
|---|
| [544] | 227 | }
 | 
|---|
 | 228 | 
 | 
|---|
| [165] | 229 | return;
 | 
|---|
 | 230 | }
 | 
|---|
 | 231 | 
 | 
|---|
| [344] | 232 | /* --Methode-- */
 | 
|---|
 | 233 | void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
 | 
|---|
 | 234 | {
 | 
|---|
 | 235 | if (!mNT) return;
 | 
|---|
 | 236 | if ( (xK < 0) || (yK < 0) )  return;
 | 
|---|
 | 237 | 
 | 
|---|
 | 238 | int ncnt = 0;
 | 
|---|
 | 239 | double xp,yp;
 | 
|---|
 | 240 | char buff[128];
 | 
|---|
 | 241 | sprintf(buff,"PINTuple: NLines= %d  NCol= %d \n", mNT->NbLines(),  mNT->NbColumns());
 | 
|---|
 | 242 | info += buff;
 | 
|---|
 | 243 | info += mNT->LineHeaderToString();
 | 
|---|
| [2115] | 244 | for(long i=0; i<(long)mNT->NbLines(); i++) {
 | 
|---|
| [344] | 245 |   xp = mNT->GetCell(i, xK);
 | 
|---|
 | 246 |   yp = mNT->GetCell(i, yK);
 | 
|---|
 | 247 |   if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) )  continue;
 | 
|---|
 | 248 |   ncnt++;
 | 
|---|
 | 249 |   if (ncnt > 101) continue;
 | 
|---|
 | 250 |   info += mNT->LineToString(i);
 | 
|---|
 | 251 |   }
 | 
|---|
 | 252 | if (ncnt >= 101) info += " .... \n";
 | 
|---|
 | 253 | sprintf(buff," %d points inside selected region \n", ncnt);
 | 
|---|
 | 254 | info += buff;
 | 
|---|
 | 255 | // printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt); 
 | 
|---|
 | 256 | return;
 | 
|---|
 | 257 | }
 | 
|---|
| [1971] | 258 | 
 | 
|---|
 | 259 | /*  La methode DecodeOptionString permet de decoder un ensemble d'options 
 | 
|---|
 | 260 |     et de parametre d'affichage specifie sous forme d'un vecteur de string.
 | 
|---|
 | 261 |     Si rmdecopt == true, les options decodees sont supprimees du vecteur 
 | 
|---|
 | 262 |     de string fourni en entree - ce qui permet l'enchainement eventuel 
 | 
|---|
 | 263 |     de plusieurs decodages de string.
 | 
|---|
 | 264 |     Les options peuvent etre sous forme de flag : "stat" "nostat" 
 | 
|---|
 | 265 |     ou plus complexes, par exemple "dynamic=-3,3"
 | 
|---|
 | 266 |     Rc: La methode renvoie le nombre d'options decodees 
 | 
|---|
 | 267 | */
 | 
|---|
 | 268 | 
 | 
|---|
 | 269 | /* --Methode-- */
 | 
|---|
 | 270 | int PINTuple::DecodeOptionString(vector<string> & opt, bool rmdecopt)
 | 
|---|
 | 271 | {
 | 
|---|
| [2229] | 272 |   int optsz1 = opt.size();
 | 
|---|
 | 273 |   if(optsz1<1)  return(0);  
 | 
|---|
| [1971] | 274 |   // On appelle d'abord le decodage de la classe PIDrawer de laquelle
 | 
|---|
 | 275 |   // on herite. (Pas obligatoire) on decode donc ici les attributs de
 | 
|---|
 | 276 |   // couleur, fontes ...
 | 
|---|
 | 277 |   int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt);
 | 
|---|
| [2229] | 278 |   if(optsz1-ndec1<1) return(ndec1);  // si tout a ete decode
 | 
|---|
| [1971] | 279 | 
 | 
|---|
 | 280 |   vector<string> udopt;  // On gardera ici les options non decodees
 | 
|---|
 | 281 |   unsigned int k = 0;
 | 
|---|
 | 282 |   int ndec = opt.size();
 | 
|---|
 | 283 |   for( k=0; k<opt.size(); k++ ) {
 | 
|---|
 | 284 |     string opts = opt[k];
 | 
|---|
| [2229] | 285 |     if(opts=="sta" || opts=="stat" || opts=="stats") SetStats(true);
 | 
|---|
 | 286 |     else if(  opts=="nsta"   || opts=="nstat"
 | 
|---|
 | 287 |            || opts=="nostat" || opts=="nostats") SetStats(false);
 | 
|---|
| [1971] | 288 |     else {
 | 
|---|
 | 289 |       // Si option non decode
 | 
|---|
 | 290 |       ndec--;
 | 
|---|
 | 291 |       // S'il faut supprimer les options decodees
 | 
|---|
 | 292 |       if (rmdecopt)  udopt.push_back(opts);
 | 
|---|
 | 293 |     }
 | 
|---|
 | 294 |   }  
 | 
|---|
 | 295 |   // S'il faut supprimer les options decodees, on remplace l'argument opt
 | 
|---|
 | 296 |   // par le vecteur des options non decodees.
 | 
|---|
 | 297 |   if (rmdecopt)  opt = udopt;
 | 
|---|
 | 298 |   return(ndec+ndec1);  
 | 
|---|
 | 299 | }
 | 
|---|
| [1975] | 300 | 
 | 
|---|
 | 301 | /* La methode GetOptionsHelpInfo(string& info) renvoie une chaine 
 | 
|---|
 | 302 |    avec la description des options comprises par ce drawer  
 | 
|---|
 | 303 |    Note: Il est preferable de ne pas initialiser la chaine 
 | 
|---|
 | 304 |    string info au depart, afin de permettre de mettre bout a 
 | 
|---|
 | 305 |    bout les aides de differents Drawer */
 | 
|---|
 | 306 | 
 | 
|---|
 | 307 | /* --Methode-- */
 | 
|---|
 | 308 | void PINTuple::GetOptionsHelpInfo(string& info)
 | 
|---|
 | 309 | {
 | 
|---|
| [2229] | 310 | // On recupere d'abord la chaine info de la classe de base
 | 
|---|
 | 311 | PIDrawer::GetOptionsHelpInfo(info);
 | 
|---|
 | 312 | info += " ---- PINTuple options help info : \n" ;
 | 
|---|
 | 313 | info += "- sta,stat,stats:            activate   statistic display\n";
 | 
|---|
 | 314 | info += "  nsta,nstat,nostat,nostats: deactivate statistic display\n";
 | 
|---|
 | 315 | return;
 | 
|---|
| [1975] | 316 | }
 | 
|---|