1 | // Cette classe est maintenant obsolete: generaldata <==> ntuple pour le dessin
|
---|
2 |
|
---|
3 | #include <stdio.h>
|
---|
4 | #include "sopnamsp.h"
|
---|
5 | #include "pigfd1.h"
|
---|
6 |
|
---|
7 | /* --Methode-- */
|
---|
8 | PIGenFitDat::PIGenFitDat(GeneralFitData* gfd, bool ad)
|
---|
9 | : PIDrawer(), mGFD(gfd), mAdDO(ad), VarX(0), ErrX(false), ErrY(false)
|
---|
10 | {
|
---|
11 | SelectX(0);
|
---|
12 | SelectErrBar(false,false);
|
---|
13 | NptDraw = 0;
|
---|
14 | }
|
---|
15 |
|
---|
16 | PIGenFitDat::~PIGenFitDat()
|
---|
17 | {
|
---|
18 | if(mAdDO && mGFD) delete mGFD;
|
---|
19 | }
|
---|
20 |
|
---|
21 | /* --Methode-- */
|
---|
22 | void PIGenFitDat::SelectX(int varx)
|
---|
23 | {
|
---|
24 | VarX = -1;
|
---|
25 | if(mGFD == NULL) return;
|
---|
26 | if(varx<0 || varx>=mGFD->NVar()) return;
|
---|
27 | VarX = varx;
|
---|
28 | }
|
---|
29 |
|
---|
30 | /* --Methode-- */
|
---|
31 | void PIGenFitDat::SelectErrBar(bool erbx,bool erby)
|
---|
32 | {
|
---|
33 | ErrX = erbx; ErrY = erby;
|
---|
34 | if(mGFD == NULL) {ErrX = ErrY = false; return;}
|
---|
35 | if(!mGFD->HasXErrors()) ErrX = false;
|
---|
36 | }
|
---|
37 |
|
---|
38 | /* --Methode-- */
|
---|
39 | void PIGenFitDat::UpdateLimits()
|
---|
40 | {
|
---|
41 | if(!mGFD) return;
|
---|
42 | if(mGFD->NData()<=0) return;
|
---|
43 | if(VarX<0) return;
|
---|
44 | double xmin=9.e19, xmax=-9.e19, ymin=9.e19, ymax=-9.e19;
|
---|
45 | mGFD->GetMnMx(10*VarX+2,xmin,xmax);
|
---|
46 | mGFD->GetMnMx(0,ymin, ymax);
|
---|
47 | if(xmax<=xmin) xmax = xmin+1.;
|
---|
48 | if(ymax<=ymin) ymax = ymin+1.;
|
---|
49 | PIAxes::ReSizeMinMax(isLogScaleX(),xmin,xmax);
|
---|
50 | PIAxes::ReSizeMinMax(isLogScaleY(),ymin,ymax);
|
---|
51 | SetLimits(xmin,xmax,ymin,ymax);
|
---|
52 | SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
|
---|
53 | }
|
---|
54 |
|
---|
55 | /* --Methode-- */
|
---|
56 | void PIGenFitDat::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
57 | {
|
---|
58 | if (!mGFD) return;
|
---|
59 | if(mGFD->NData()<=0) return;
|
---|
60 | if(VarX<0) return;
|
---|
61 | // On plotte les barre d'erreurs ligne demandee explicitement
|
---|
62 | if(GetGraphicAtt().GetLineAtt()!=PI_NotDefLineAtt) SelectErrBar(true,true);
|
---|
63 | double xp,yp,er;
|
---|
64 | NptDraw = 0;
|
---|
65 | for (int i=0; i<mGFD->NData(); i++) {
|
---|
66 | xp = mGFD->Absc(VarX,i);
|
---|
67 | yp = mGFD->Val(i);
|
---|
68 | if(xp<xmin || xp>xmax || yp<ymin || yp>ymax) continue;
|
---|
69 | NptDraw++;
|
---|
70 | if(ErrX) {
|
---|
71 | er = mGFD->EAbsc(VarX,i);
|
---|
72 | if(er>0.) g->DrawLine(xp-er,yp,xp+er,yp);
|
---|
73 | }
|
---|
74 | if(ErrY) {
|
---|
75 | er = mGFD->EVal(i);
|
---|
76 | if(er>0.) g->DrawLine(xp,yp-er,xp,yp+er);
|
---|
77 | }
|
---|
78 | g->DrawMarker(xp, yp);
|
---|
79 | }
|
---|
80 | return;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /* --Methode-- */
|
---|
84 | double PIGenFitDat::GetDistanceToPoint(double x, double y)
|
---|
85 | {
|
---|
86 | if(!mGFD) return 1.e+9;
|
---|
87 | if(mGFD->NData()<=0) return 1.e+9;
|
---|
88 | if(VarX<0) return 1.e+9;
|
---|
89 |
|
---|
90 | const int nessai = 100;
|
---|
91 | long inc = (NptDraw>nessai) ? (long)(NptDraw/nessai)+1 : 1;
|
---|
92 |
|
---|
93 | double dist = -1.e+18;
|
---|
94 | long n = 0;
|
---|
95 | for(long i=0; i<mGFD->NData(); i++) {
|
---|
96 | double xp=mGFD->Absc(VarX,i);
|
---|
97 | if(xp<XMin() || xp>XMax()) continue;
|
---|
98 | double yp=mGFD->Val(i);
|
---|
99 | if(yp<YMin() || yp>YMax()) continue;
|
---|
100 | if(n%inc==0) {
|
---|
101 | xp = (xp-x)/(XMax()-XMin())/0.5;
|
---|
102 | yp = (yp-y)/(YMax()-YMin())/0.5;
|
---|
103 | xp = xp*xp+yp*yp;
|
---|
104 | if(dist<0. || xp<dist) dist = xp;
|
---|
105 | }
|
---|
106 | n++;
|
---|
107 | }
|
---|
108 | dist=sqrt(fabs(dist));
|
---|
109 | //cout<<"PIGenFitDat: xlim="<<XMin()<<","<<XMax()<<" ylim="<<YMin()<<","<<YMax()
|
---|
110 | // <<" NData="<<mGFD->NData()<<" inc="<<inc<<endl;
|
---|
111 | //cout<<"....d="<<dist<<" x="<<x<<" y="<<y<<" NptDraw="<<NptDraw<<endl;
|
---|
112 |
|
---|
113 | return dist;
|
---|
114 | }
|
---|