| 1 | //  Adaptateurs et Drawers divers pour Outils PEIDA++
 | 
|---|
| 2 | //                             R. Ansari  06-08/98
 | 
|---|
| 3 | // LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
 | 
|---|
| 4 | 
 | 
|---|
| 5 | #include "pipodrw.h"
 | 
|---|
| 6 | #include "generalfit.h"
 | 
|---|
| 7 | 
 | 
|---|
| 8 | 
 | 
|---|
| 9 | //================================================================
 | 
|---|
| 10 | // PIGFFDrawer
 | 
|---|
| 11 | //================================================================
 | 
|---|
| 12 | 
 | 
|---|
| 13 | PIGFFDrawer::PIGFFDrawer(GeneralFunction* f)
 | 
|---|
| 14 | : mFunc(f), mNParms(f->NPar()), mParms(new double[mNParms])
 | 
|---|
| 15 | {
 | 
|---|
| 16 |   ASSERT(f->NVar() == 1);
 | 
|---|
| 17 | }
 | 
|---|
| 18 | 
 | 
|---|
| 19 | PIGFFDrawer::~PIGFFDrawer()
 | 
|---|
| 20 | {
 | 
|---|
| 21 |   delete[] mParms;
 | 
|---|
| 22 | }
 | 
|---|
| 23 | 
 | 
|---|
| 24 | void
 | 
|---|
| 25 | PIGFFDrawer::SetParms(double const* p)
 | 
|---|
| 26 | {
 | 
|---|
| 27 |   for (int i=0; i<mNParms; i++)
 | 
|---|
| 28 |     mParms[i] = p[i];
 | 
|---|
| 29 | }
 | 
|---|
| 30 | 
 | 
|---|
| 31 | 
 | 
|---|
| 32 | void
 | 
|---|
| 33 | PIGFFDrawer::Draw(PIGraphicUC* g, double /*xmin*/, double/*ymin*/, double/*xmax*/, double/*ymax*/)
 | 
|---|
| 34 | {
 | 
|---|
| 35 |   PIGrCoord x1, x2, y1, y2;
 | 
|---|
| 36 |   g->GetGrSpace(x1, x2, y1, y2);
 | 
|---|
| 37 |   double xMax = x2;
 | 
|---|
| 38 |   double xMin = x1;
 | 
|---|
| 39 |   double yMax = y2;
 | 
|---|
| 40 |   double yMin = y1;
 | 
|---|
| 41 |   double xStep = (xMax - xMin)/100;
 | 
|---|
| 42 |   double xOld = xMin;
 | 
|---|
| 43 |   double yOld = 0;
 | 
|---|
| 44 | //  double yOld = f->Value(&xMin, mParms);
 | 
|---|
| 45 |   for (double x = xMin+xStep; x<xMax; x+=xStep) {
 | 
|---|
| 46 |    double y = 0; // $CHECK$
 | 
|---|
| 47 | //    double y = f->Value(&x, mParms);
 | 
|---|
| 48 |     if (y>yMin && yOld>yMin && 
 | 
|---|
| 49 |         y<yMax && yOld<yMax) 
 | 
|---|
| 50 |            g->DrawLine(xOld, yOld, x, y);
 | 
|---|
| 51 |     xOld = x;
 | 
|---|
| 52 |     yOld = y;
 | 
|---|
| 53 |   }
 | 
|---|
| 54 | }
 | 
|---|
| 55 | 
 | 
|---|
| 56 | // ----------------------------------------------------------
 | 
|---|
| 57 | // Adaptateur de vecteurs Peida++ a P1DArrayAdapter
 | 
|---|
| 58 | // ----------------------------------------------------------
 | 
|---|
| 59 | 
 | 
|---|
| 60 | /* --Methode-- */
 | 
|---|
| 61 | POVectorAdapter::POVectorAdapter(Vector* v, bool ad)
 | 
|---|
| 62 |         : P1DArrayAdapter(v->NElts())
 | 
|---|
| 63 | {
 | 
|---|
| 64 | aDel = ad; mVec = v;
 | 
|---|
| 65 | }
 | 
|---|
| 66 | 
 | 
|---|
| 67 | /* --Methode-- */
 | 
|---|
| 68 | POVectorAdapter::~POVectorAdapter()
 | 
|---|
| 69 | {
 | 
|---|
| 70 | if (aDel) delete mVec;
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | /* --Methode-- */
 | 
|---|
| 74 | double POVectorAdapter::Value(int i)
 | 
|---|
| 75 | { 
 | 
|---|
| 76 | return((*mVec)(i)); 
 | 
|---|
| 77 | }
 | 
|---|
| 78 | 
 | 
|---|
| 79 | // ----------------------------------------------------------
 | 
|---|
| 80 | // Adaptateur d'Histo-2D Peida++ a P2DArrayAdapter
 | 
|---|
| 81 | // ----------------------------------------------------------
 | 
|---|
| 82 | 
 | 
|---|
| 83 | /* --Methode-- */
 | 
|---|
| 84 | POH2DAdapter::POH2DAdapter(Histo2D* h2d, bool ad)
 | 
|---|
| 85 |         : P2DArrayAdapter(h2d->NBinX(), h2d->NBinY())
 | 
|---|
| 86 | {
 | 
|---|
| 87 | aDel = ad; mH2d = h2d;
 | 
|---|
| 88 | DefineXYCoordinates(h2d->XMin(), h2d->YMin(), h2d->WBinX(), h2d->WBinY() );
 | 
|---|
| 89 | }
 | 
|---|
| 90 | 
 | 
|---|
| 91 | /* --Methode-- */
 | 
|---|
| 92 | POH2DAdapter::~POH2DAdapter()
 | 
|---|
| 93 | {
 | 
|---|
| 94 | if (aDel)  delete mH2d;
 | 
|---|
| 95 | }
 | 
|---|
| 96 | 
 | 
|---|
| 97 | /* --Methode-- */
 | 
|---|
| 98 | double POH2DAdapter::Value(int ix, int iy)
 | 
|---|
| 99 | {
 | 
|---|
| 100 | return((*mH2d)(ix, iy));
 | 
|---|
| 101 | }
 | 
|---|
| 102 | 
 | 
|---|
| 103 | // ----------------------------------------------------------
 | 
|---|
| 104 | // Adaptateur de matrice Peida++ a P2DArrayAdapter
 | 
|---|
| 105 | // Attention  Y: Lignes (rows)  X: Colonnes
 | 
|---|
| 106 | // ----------------------------------------------------------
 | 
|---|
| 107 | 
 | 
|---|
| 108 | /* --Methode-- */
 | 
|---|
| 109 | POMatrixAdapter::POMatrixAdapter(Matrix* mtx, bool ad)
 | 
|---|
| 110 |         : P2DArrayAdapter(mtx->NCol(), mtx->NRows())
 | 
|---|
| 111 | {
 | 
|---|
| 112 | aDel = ad; mMtx = mtx;
 | 
|---|
| 113 | }
 | 
|---|
| 114 | 
 | 
|---|
| 115 | /* --Methode-- */
 | 
|---|
| 116 | POMatrixAdapter::~POMatrixAdapter()
 | 
|---|
| 117 | {
 | 
|---|
| 118 | if (aDel)  delete mMtx;
 | 
|---|
| 119 | }
 | 
|---|
| 120 | 
 | 
|---|
| 121 | /* --Methode-- */
 | 
|---|
| 122 | double POMatrixAdapter::Value(int ix, int iy)
 | 
|---|
| 123 | {
 | 
|---|
| 124 | // Attention MatrixAdapter(X=Colonne, Y= Row) = Matrix(row, col)  
 | 
|---|
| 125 | return((*mMtx)(iy, ix));
 | 
|---|
| 126 | }
 | 
|---|
| 127 | 
 | 
|---|
| 128 | 
 | 
|---|