source: trunk/MagicSoft/Mars/mtools/MChisqEval.cc@ 2031

Last change on this file since 2031 was 1840, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 3.9 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 07/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27//
28/////////////////////////////////////////////////////////////////////////////
29#include "MChisqEval.h"
30
31#include <fstream.h>
32
33#include "MDataChain.h"
34
35ClassImp(MChisqEval);
36
37void MChisqEval::StreamPrimitive(ofstream &out) const
38{
39 out << " MChisqEval " << GetUniqueName() << ";";
40 if (fData0)
41 out << " " << GetUniqueName() << ".SetY1(\"" << fData0->GetRule() << "\");" << endl;
42 if (fData1)
43 out << " " << GetUniqueName() << ".SetY1(\"" << fData1->GetRule() << "\");" << endl;
44}
45
46MChisqEval::MChisqEval(const char *name, const char *title) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
47{
48 fName = name ? name : gsDefName.Data();
49 fTitle = title ? title : gsDefTitle.Data();
50}
51
52MChisqEval::MChisqEval(MData *y1, const char *name, const char *title) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
53{
54 fName = name ? name : gsDefName.Data();
55 fTitle = title ? title : gsDefTitle.Data();
56 SetY1(y1);
57}
58
59MChisqEval::MChisqEval(MData *y1, MData *y2, const char *name, const char *title) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
60{
61 fName = name ? name : gsDefName.Data();
62 fTitle = title ? title : gsDefTitle.Data();
63 SetY1(y1);
64 SetY2(y2);
65}
66
67MChisqEval::~MChisqEval()
68{
69 if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
70 delete fData0;
71
72 if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
73 delete fData1;
74}
75
76void MChisqEval::SetY1(MData *data)
77{
78 // Set MC value
79 if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
80 delete fData0;
81 fData0 = data;
82 fData0->SetBit(kCanDelete);
83 AddToBranchList(fData0->GetDataMember());
84}
85
86void MChisqEval::SetY2(MData *data)
87{
88 // Set measured/estimated value
89 if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
90 delete fData1;
91 fData1 = data;
92 fData1->SetBit(kCanDelete);
93 AddToBranchList(fData1->GetDataMember());
94}
95
96void MChisqEval::SetY1(const TString data)
97{
98 SetY1(new MDataChain(data));
99}
100
101void MChisqEval::SetY2(const TString data)
102{
103 SetY2(new MDataChain(data));
104}
105
106Bool_t MChisqEval::PreProcess(MParList *plist)
107{
108 fChisq = 0;
109
110 if (!fData0)
111 return kFALSE;
112
113 if (!fData0->PreProcess(plist))
114 return kFALSE;
115
116 if (fData1)
117 if (!fData1->PreProcess(plist))
118 return kFALSE;
119
120 return kTRUE;
121}
122
123Bool_t MChisqEval::Process()
124{
125 const Double_t y1 = fData0->GetValue();
126 const Double_t y2 = fData1 ? fData1->GetValue() : 0;
127
128 const Double_t dy = y2-y1;
129 const Double_t err = fData1 ? y1*y1 : 1;
130
131 fChisq += dy*dy/err;
132 return kTRUE;
133}
134
135Bool_t MChisqEval::PostProcess()
136{
137 fChisq /= GetNumExecutions();
138 return kTRUE;
139}
140
141const TString MChisqEval::gsDefName = "MChisqEval";
142const TString MChisqEval::gsDefTitle = "Evaluate a chisq";
143
Note: See TracBrowser for help on using the repository browser.