source: Sophya/trunk/SophyaPI/PIext/nomhistadapter.cc@ 1321

Last change on this file since 1321 was 1321, checked in by ercodmgr, 25 years ago

Adaptateur de TArray et lecture FITS - Reza 13/11/2000

File size: 11.3 KB
Line 
1#include "machdefs.h"
2#include <stdlib.h>
3#include <typeinfo>
4#include <iostream.h>
5#include <string>
6
7#include "nomhistadapter.h"
8#include "pihisto.h"
9#include "pihisto2d.h"
10#include "pipodrw.h"
11#include "servnobjm.h"
12
13#ifndef SANS_EVOLPLANCK
14#include "objfitter.h"
15#include "fitsntuple.h"
16#include "fitsxntuple.h"
17#endif
18
19//-------------------------------------------------------------------------
20// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet Histo / HProf
21//-------------------------------------------------------------------------
22
23/* --Methode-- */
24NOMAdapter_Histo::NOMAdapter_Histo(Histo* o)
25 : NObjMgrAdapter(o)
26{
27mHis = o;
28}
29
30/* --Methode-- */
31NOMAdapter_Histo::~NOMAdapter_Histo()
32{
33}
34
35/* --Methode-- */
36NObjMgrAdapter* NOMAdapter_Histo::Clone(AnyDataObj* o)
37{
38Histo* h = dynamic_cast<Histo *>(o);
39if (h) return ( new NOMAdapter_Histo(h) );
40return ( new NObjMgrAdapter(o) );
41}
42
43/* --Methode-- */
44string NOMAdapter_Histo::GetDataObjType()
45{
46HProf * hp = dynamic_cast<HProf *>(mHis);
47if(hp) return("HProf "); else return("Histo ");
48}
49
50/* --Methode-- */
51AnyDataObj* NOMAdapter_Histo::CloneDataObj(bool /*share*/)
52{
53mHis->UpdateHisto(); // pour le cas ou c'est un HProf
54HProf * hp = dynamic_cast<HProf *>(mHis);
55if(hp==NULL) return( new Histo(*mHis) );
56return( new HProf(*hp) );
57}
58
59/* --Methode-- */
60void NOMAdapter_Histo::SavePPF(POutPersist& pos, string const & nom)
61{
62#ifdef SANS_EVOLPLANCK
63// PEIDA-EROS L'histo est lui-meme PPersist
64string tag = nom; // A cause de const
65mHis->Write(pos,0,tag);
66#else
67ObjFileIO<Histo> fio(mHis);
68fio.Write(pos, nom);
69#endif
70}
71
72/* --Methode-- */
73void NOMAdapter_Histo::Print(ostream& os)
74{
75mHis->Print(60);
76}
77
78/* --Methode-- */
79PIDrawer* NOMAdapter_Histo::GetDrawer(string & dopt)
80{
81if (typeid(*mHis) == typeid(HProf)) dopt = "fcirclemarker5," + dopt;
82else dopt = "thinline," + dopt;
83PIHisto * pih = new PIHisto(mHis, false);
84pih->SetStats(Services2NObjMgr::GetStatsOption(dopt));
85return( pih );
86}
87
88/* --Methode-- */
89NTupleInterface* NOMAdapter_Histo::GetNTupleInterface(bool& adel)
90{
91adel = true;
92return( new NTupInt_Histo(mHis) );
93}
94
95/* --Methode-- */
96GeneralFitData* NOMAdapter_Histo::GetGeneralFitData(bool& adel
97 ,GeneralFitData::FitErrType errtype,double errscale,double errmin
98 ,int i1,int i2,int j1,int j2)
99{
100adel = false;
101if(!mHis) return(NULL);
102
103int nx = mHis->NBins();
104if(nx<=0) return(NULL);
105
106i1 = (i1<0||i1>=nx)? 0: i1;
107i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2;
108
109GeneralFitData* mGData = new GeneralFitData(1,i2-i1+1,0);
110adel = true;
111
112for(int i=i1;i<=i2;i++) {
113 double x = mHis->BinCenter(i);
114 double f = (*mHis)(i);
115 double e = (mHis->HasErrors())? mHis->Error(i) : 1.;
116 e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
117 mGData->AddData1(x,f,e);
118}
119
120return mGData;
121}
122
123AnyDataObj* NOMAdapter_Histo::FitResidusObj(GeneralFit& mfit)
124{
125Histo* h = NULL;
126#ifdef SANS_EVOLPLANCK
127h = mHis->FitResidus(mfit);
128#else
129h = new Histo(ObjectFitter::FitResidus(*mHis,mfit));
130#endif
131return h;
132}
133
134AnyDataObj* NOMAdapter_Histo::FitFunctionObj(GeneralFit& mfit)
135{
136Histo* h = NULL;
137#ifdef SANS_EVOLPLANCK
138h = mHis->FitFunction(mfit);
139#else
140h = new Histo(ObjectFitter::FitFunction(*mHis,mfit));
141#endif
142return h;
143}
144
145// -------------------------------------------------------------
146
147/* --Methode-- */
148NTupInt_Histo::NTupInt_Histo(Histo* h)
149{
150mHis = h;
151}
152
153/* --Methode-- */
154NTupInt_Histo::~NTupInt_Histo()
155{
156}
157
158/* --Methode-- */
159uint_4 NTupInt_Histo::NbLines() const
160{
161return(mHis->NBins());
162}
163
164/* --Methode-- */
165uint_4 NTupInt_Histo::NbColumns() const
166{
167return(4);
168}
169
170/* --Methode-- */
171r_8* NTupInt_Histo::GetLineD(int k) const
172{
173int i;
174if ((k < 0) || (k >= mHis->NBins()))
175 for(i=0; i<4; i++) mRet[i] = 0.;
176else {
177 mRet[0] = k; mRet[1] = mHis->BinCenter(k);
178 mRet[2] = (*mHis)(k); mRet[3] = mHis->Error(k);
179 }
180return(mRet);
181}
182
183/* --Methode-- */
184string NTupInt_Histo::VarList_C(const char* nx) const
185{
186string nomx;
187if (nx) nomx = nx;
188else nomx = "_xh_";
189string vardec = "double i,x,val,err; \n";
190vardec += "i = " + nomx + "[0]; x = " + nomx + "[1]; \n";
191vardec += "val = " + nomx + "[2]; err = " + nomx + "[3]; \n";
192return(vardec);
193}
194
195//-------------------------------------------------------------------------
196// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet Histo2D
197//-------------------------------------------------------------------------
198
199
200/* --Methode-- */
201NOMAdapter_Histo2D::NOMAdapter_Histo2D(Histo2D* o)
202 : NObjMgrAdapter(o)
203{
204mHis = o;
205}
206
207/* --Methode-- */
208NOMAdapter_Histo2D::~NOMAdapter_Histo2D()
209{
210}
211
212/* --Methode-- */
213NObjMgrAdapter* NOMAdapter_Histo2D::Clone(AnyDataObj* o)
214{
215Histo2D* h = dynamic_cast<Histo2D *>(o);
216if (h) return ( new NOMAdapter_Histo2D(h) );
217return ( new NObjMgrAdapter(o) );
218}
219
220/* --Methode-- */
221string NOMAdapter_Histo2D::GetDataObjType()
222{
223return ("Histo2D ");
224}
225
226/* --Methode-- */
227AnyDataObj* NOMAdapter_Histo2D::CloneDataObj(bool /*share*/)
228{
229return ( new Histo2D(*mHis) );
230}
231
232/* --Methode-- */
233void NOMAdapter_Histo2D::SavePPF(POutPersist& pos, string const & nom)
234{
235#ifdef SANS_EVOLPLANCK
236// PEIDA-EROS L'histo est lui-meme PPersist
237string tag = nom; // A cause de const
238mHis->Write(pos,0,tag);
239#else
240ObjFileIO<Histo2D> fio(mHis);
241fio.Write(pos, nom);
242#endif
243}
244
245/* --Methode-- */
246void NOMAdapter_Histo2D::Print(ostream& os)
247{
248mHis->Print();
249}
250
251/* --Methode-- */
252PIDrawer* NOMAdapter_Histo2D::GetDrawer(string & dopt)
253{
254dopt = "thinline," + dopt;
255return( new PIHisto2D(mHis, false) );
256}
257
258/* --Methode-- */
259P2DArrayAdapter* NOMAdapter_Histo2D::Get2DArray(string & dopt)
260{
261return (new POH2DAdapter(mHis, false) );
262}
263
264/* --Methode-- */
265NTupleInterface* NOMAdapter_Histo2D::GetNTupleInterface(bool& adel)
266{
267adel = true;
268return( new NTupInt_Histo2D(mHis) );
269}
270
271
272/* --Methode-- */
273GeneralFitData* NOMAdapter_Histo2D::GetGeneralFitData(bool& adel
274 ,GeneralFitData::FitErrType errtype,double errscale,double errmin
275 ,int i1,int i2,int j1,int j2)
276{
277adel = false;
278if(!mHis) return(NULL);
279
280int nx = mHis->NBinX();
281int ny = mHis->NBinY();
282if(nx<=0 || ny<=0) return(NULL);
283
284i1 = (i1<0||i1>=nx)? 0: i1;
285i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2;
286j1 = (j1<0||j1>=ny)? 0: j1;
287j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2;
288
289GeneralFitData* mGData = new GeneralFitData(2,(i2-i1+1)*(j2-j1+1),0);
290adel = true;
291
292for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) {
293 double x,y; mHis->BinCenter(i,j,x,y);
294 double f = (*mHis)(i,j);
295 double e = (mHis->HasErrors())? mHis->Error(i,j) : 1.;
296 e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
297 mGData->AddData2(x,y,f,e);
298}
299
300return mGData;
301}
302
303AnyDataObj* NOMAdapter_Histo2D::FitResidusObj(GeneralFit& mfit)
304{
305Histo2D* h2 = NULL;
306#ifdef SANS_EVOLPLANCK
307h2 = mHis->FitFunction(mfit);
308#else
309h2 = new Histo2D(ObjectFitter::FitResidus(*mHis,mfit));
310#endif
311return h2;
312}
313
314AnyDataObj* NOMAdapter_Histo2D::FitFunctionObj(GeneralFit& mfit)
315{
316Histo2D* h2 = NULL;
317#ifdef SANS_EVOLPLANCK
318h2 = mHis->FitFunction(mfit);
319#else
320h2 = new Histo2D(ObjectFitter::FitFunction(*mHis,mfit));
321#endif
322return h2;
323}
324
325
326// -------------------------------------------------------------
327
328/* --Methode-- */
329NTupInt_Histo2D::NTupInt_Histo2D(Histo2D* h)
330{
331mHis = h;
332}
333
334/* --Methode-- */
335NTupInt_Histo2D::~NTupInt_Histo2D()
336{
337}
338
339/* --Methode-- */
340uint_4 NTupInt_Histo2D::NbLines() const
341{
342return(mHis->NBinX()*mHis->NBinY());
343}
344
345/* --Methode-- */
346uint_4 NTupInt_Histo2D::NbColumns() const
347{
348return(6);
349}
350
351/* --Methode-- */
352r_8* NTupInt_Histo2D::GetLineD(int n) const
353{
354int i,j;
355r_8 f2,f3;
356if ((n < 0) || (n >= mHis->NBinX()*mHis->NBinY()))
357 for(i=0; i<6; i++) mRet[i] = 0.;
358else {
359 i = n%mHis->NBinX(); j = n/mHis->NBinX();
360 mRet[0] = i; mRet[1] = j;
361 mHis->BinCenter(i,j,f2,f3);
362 mRet[2] = f2; mRet[3] = f3;
363 mRet[4] = (*mHis)(i,j); mRet[5] = mHis->Error(i, j);
364 }
365return(mRet);
366}
367
368/* --Methode-- */
369string NTupInt_Histo2D::VarList_C(const char* nx) const
370{
371string nomx;
372if (nx) nomx = nx;
373else nomx = "_xh_";
374string vardec = "double i,j,x,y,val,err; \n";
375vardec += "i = " + nomx + "[0]; j = " + nomx + "[1]; \n";
376vardec += "x = " + nomx + "[2]; y = " + nomx + "[3]; \n";
377vardec += "val = " + nomx + "[4]; err = " + nomx + "[5]; \n";
378return(vardec);
379}
380
381
382
383//-------------------------------------------------------------------------
384// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet NTuple
385//-------------------------------------------------------------------------
386
387/* --Methode-- */
388NOMAdapter_NTuple::NOMAdapter_NTuple(NTuple* o)
389 : NObjMgrAdapter(o)
390{
391mNt = o;
392}
393
394/* --Methode-- */
395NOMAdapter_NTuple::~NOMAdapter_NTuple()
396{
397}
398
399/* --Methode-- */
400NObjMgrAdapter* NOMAdapter_NTuple::Clone(AnyDataObj* o)
401{
402NTuple* nt = dynamic_cast<NTuple *>(o);
403if (nt) return ( new NOMAdapter_NTuple(nt) );
404return ( new NObjMgrAdapter(o) );
405}
406
407
408/* --Methode-- */
409string NOMAdapter_NTuple::GetDataObjType()
410{
411return ("NTuple ");
412}
413
414/* --Methode-- */
415AnyDataObj* NOMAdapter_NTuple::CloneDataObj(bool /*share*/)
416{
417return ( new NTuple(*mNt) );
418}
419
420/* --Methode-- */
421void NOMAdapter_NTuple::ReadFits(string const & flnm)
422{
423#ifdef SANS_EVOLPLANCK
424 cerr << " NOMAdapter_NTuple::ReadFits() Non disponible !! " << endl;
425#else
426 FitsInFile fis(flnm);
427 fis >> (*mNt);
428#endif
429}
430
431/* --Methode-- */
432void NOMAdapter_NTuple::SaveFits(string const & flnm)
433{
434#ifdef SANS_EVOLPLANCK
435 cerr << " NOMAdapter_NTuple::SaveFits() Non disponible !! " << endl;
436#else
437 FitsOutFile fos(flnm);
438 fos << (*mNt);
439
440#endif
441}
442
443
444/* --Methode-- */
445void NOMAdapter_NTuple::SavePPF(POutPersist& pos, string const & nom)
446{
447#ifdef SANS_EVOLPLANCK
448// PEIDA-EROS L'histo est lui-meme PPersist
449string tag = nom; // A cause de const
450mNt->Write(pos,0,tag);
451#else
452ObjFileIO<NTuple> fio(mNt);
453fio.Write(pos, nom);
454#endif
455}
456
457/* --Methode-- */
458void NOMAdapter_NTuple::Print(ostream& os)
459{
460os << mNt->Info();
461os << *(mNt);
462}
463
464
465/* --Methode-- */
466NTupleInterface* NOMAdapter_NTuple::GetNTupleInterface(bool& adel)
467{
468adel = false;
469return(mNt);
470// return( new NTupInt_NTuple(mNt) );
471}
472
473//-------------------------------------------------------------------------
474// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet XNTuple
475//-------------------------------------------------------------------------
476
477/* --Methode-- */
478NOMAdapter_XNTuple::NOMAdapter_XNTuple(XNTuple* o)
479 : NObjMgrAdapter(o)
480{
481mNt = o;
482}
483
484/* --Methode-- */
485NOMAdapter_XNTuple::~NOMAdapter_XNTuple()
486{
487}
488
489/* --Methode-- */
490NObjMgrAdapter* NOMAdapter_XNTuple::Clone(AnyDataObj* o)
491{
492XNTuple* nt = dynamic_cast<XNTuple *>(o);
493if (nt) return ( new NOMAdapter_XNTuple(nt) );
494return ( new NObjMgrAdapter(o) );
495}
496
497/* --Methode-- */
498string NOMAdapter_XNTuple::GetDataObjType()
499{
500return ("XNTuple ");
501}
502
503/* --Methode-- */
504AnyDataObj* NOMAdapter_XNTuple::CloneDataObj(bool /*share*/)
505{
506return ( new XNTuple(*mNt) );
507}
508
509/* --Methode-- */
510void NOMAdapter_XNTuple::ReadFits(string const & flnm)
511{
512#ifdef SANS_EVOLPLANCK
513 cerr << " NOMAdapter_XNTuple::ReadFits() Non disponible !! " << endl;
514#else
515 FitsInFile fis(flnm);
516 fis >> (*mNt);
517#endif
518}
519
520/* --Methode-- */
521void NOMAdapter_XNTuple::SaveFits(string const & flnm)
522{
523#ifdef SANS_EVOLPLANCK
524 cerr << " NOMAdapter_XNTuple::SaveFits() Non disponible !! " << endl;
525#else
526 FitsOutFile fos(flnm);
527 fos << (*mNt);
528
529#endif
530}
531
532/* --Methode-- */
533void NOMAdapter_XNTuple::SavePPF(POutPersist& pos, string const & nom)
534{
535#ifdef SANS_EVOLPLANCK
536// PEIDA-EROS L'histo est lui-meme PPersist
537string tag = nom; // A cause de const
538mNt->Write(pos,0,tag);
539#else
540ObjFileIO<XNTuple> fio(mNt);
541fio.Write(pos, nom);
542#endif
543}
544
545/* --Methode-- */
546void NOMAdapter_XNTuple::Print(ostream& os)
547{
548// os << mNt->Info();
549mNt->Show(os);
550}
551
552
553/* --Methode-- */
554NTupleInterface* NOMAdapter_XNTuple::GetNTupleInterface(bool& adel)
555{
556adel = false;
557return(mNt);
558}
Note: See TracBrowser for help on using the repository browser.