// Classe traceur d histogramme 96-99 // CEA-DAPNIA LAL-IN2P3/CNRS #include #include #include "pihisto.h" #include "hisprof.h" //++ // Class PIHisto // Lib PIext // include pihisto.h // // Classe traceur d'objet histogramme (classe *Histo*) //-- //++ // Links Parents // PIDrawer //-- //++ // Titre Constructeur, méthodes //-- //++ // PIHisto(Histo* histo, bool ad=false) // Constructeur. Si "ad == true", l'objet "histo" est détruit par // le destructeur de l'objet "PIHisto" // Note : "histo" doit être créé par new // // void SetStats(bool fg=true) // Active/ désactive l'indication des statistiques d'histogramme //-- PIHisto::PIHisto(Histo* histo, bool ad) : PIDrawer(), mHisto(histo) { mAdDO = ad; // Flag pour suppression automatique de mHisto SetStats(true); } PIHisto::~PIHisto() { if (mAdDO) delete mHisto; } void PIHisto::UpdateLimits() { if (!mHisto) return; float hmin = mHisto->VMin(); float hmax = mHisto->VMax()+0.2*(mHisto->VMax()-mHisto->VMin()); // si HBProf min,max calcules en tenant compte des erreurs if( typeid(*mHisto) == typeid(HProf) ) { float v1,v2; for (int i=1; iNBins(); i++) { v1 = (*mHisto)(i) - mHisto->Error(i); v2 = (*mHisto)(i) + mHisto->Error(i); if(v1hmax) hmax = v2; } v1 = 0.1*(hmax-hmin); hmin -= v1; hmax += v1; } if(hmax<=hmin) hmax += 1.; SetLimits(mHisto->XMin(), mHisto->XMax(), hmin, hmax); SetAxesFlags(kBoxAxes | kExtTicks | kLabels); } void PIHisto::Draw(PIGraphicUC* g, double /*xmin*/, double /*ymin*/, double /*xmax*/, double /*ymax*/) { bool oktrace = false; if (!mHisto) return; if (mMrk != PI_NotDefMarker || ( typeid(*mHisto) == typeid(HProf) ) ) { // Marqeurs definis OU HBProf => marqueurs+Erreurs si il y en a if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine); double x1,y1, x2,y2; double bw = mHisto->BinWidth(); for (int i=0; iNBins(); i++) { if(mHisto->Error(i)>0.) { // barres d'erreur verticales x1 = x2 = mHisto->BinCenter(i); y1 = (*mHisto)(i) - mHisto->Error(i); y2 = (*mHisto)(i) + mHisto->Error(i); g->DrawLine(x1,y1, x1, y2); // limites de barres d'erreurs (horizontales) x1 -= bw/3.; x2 += bw/3.; g->DrawLine(x1,y1, x2, y1); g->DrawLine(x1,y2, x2, y2); } // le marqueur x1 = mHisto->BinCenter(i); y1 = (*mHisto)(i); g->DrawMarker(x1,y1); } oktrace = true; } if (mLAtt != PI_NotDefLineAtt) { double x1,y1, x2, y2; x1 = mHisto->BinLowEdge(0); y1 = 0; for (int i=0; iNBins(); i++) { x2 = x1; y2 = (*mHisto)(i); g->DrawLine(x1,y1, x2, y2); y1 = y2; x2 = mHisto->BinHighEdge(i); g->DrawLine(x1,y1, x2, y2); x1 = x2; } y2 = 0; g->DrawLine(x1,y1, x2, y2); oktrace = true; } if( !oktrace ) { for(int i=0; iNBins(); i++) { double left = mHisto->BinLowEdge(i); double width = mHisto->BinWidth(); double bottom = 0; double height = (*mHisto)(i); g->DrawFBox(left,bottom,width,height); g->DrawLine(left, bottom, left, bottom + height); // Au moins une ligne... } } // A faire a la fin - DrawStats change l'attribut de ligne if (stats) DrawStats(g); } void PIHisto::DrawStats(PIGraphicUC* g) { if (!mHisto) return; // if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine); g->SelLine(PI_ThinLine); g->SelFontSz((YMax() - YMin())/25, mFAtt); // double cellHeight = (YMax() - YMin()) * 0.05; PIGrCoord a, d; double cH = (double)g->GetFontHeight(a,d); double cellHeight = cH * 3.8; // double cellWidth = (XMax() - XMin()) * 0.23; char label[50]; sprintf(label, "N= %.8g ", mHisto->NData()); label[11] ='\0'; double cellWidth = (double)g->CalcStringWidth(label) * 1.1; g->DrawLine(XMax() - cellWidth, YMax(), XMax() - cellWidth, YMax() - cellHeight); g->DrawLine(XMax() - cellWidth, YMax() - cellHeight, XMax() , YMax() - cellHeight); g->DrawString(XMax() - cellWidth*0.95, YMax() - cH*1.2, label); sprintf(label, "m= %.8g", mHisto->Mean()); g->DrawString(XMax() - cellWidth*0.95, YMax() - cH*2.4, label); sprintf(label, "s= %.8g", mHisto->Sigma()); g->DrawString(XMax() - cellWidth*0.95, YMax() - cH*3.6, label); }