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

Last change on this file since 2493 was 2208, checked in by tbretz, 21 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>
32
33#include "MDataChain.h"
34
35ClassImp(MChisqEval);
36
37using namespace std;
38
39void MChisqEval::StreamPrimitive(ofstream &out) const
40{
41 out << " MChisqEval " << GetUniqueName() << ";";
42 if (fData0)
43 out << " " << GetUniqueName() << ".SetY1(\"" << fData0->GetRule() << "\");" << endl;
44 if (fData1)
45 out << " " << GetUniqueName() << ".SetY1(\"" << fData1->GetRule() << "\");" << endl;
46}
47
48MChisqEval::MChisqEval(const char *name, const char *title) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
49{
50 fName = name ? name : gsDefName.Data();
51 fTitle = title ? title : gsDefTitle.Data();
52}
53
54MChisqEval::MChisqEval(MData *y1, const char *name, const char *title) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
55{
56 fName = name ? name : gsDefName.Data();
57 fTitle = title ? title : gsDefTitle.Data();
58 SetY1(y1);
59}
60
61MChisqEval::MChisqEval(MData *y1, MData *y2, const char *name, const char *title) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
62{
63 fName = name ? name : gsDefName.Data();
64 fTitle = title ? title : gsDefTitle.Data();
65 SetY1(y1);
66 SetY2(y2);
67}
68
69MChisqEval::~MChisqEval()
70{
71 if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
72 delete fData0;
73
74 if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
75 delete fData1;
76}
77
78void MChisqEval::SetY1(MData *data)
79{
80 // Set MC value
81 if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
82 delete fData0;
83 fData0 = data;
84 fData0->SetBit(kCanDelete);
85 AddToBranchList(fData0->GetDataMember());
86}
87
88void MChisqEval::SetY2(MData *data)
89{
90 // Set measured/estimated value
91 if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
92 delete fData1;
93 fData1 = data;
94 fData1->SetBit(kCanDelete);
95 AddToBranchList(fData1->GetDataMember());
96}
97
98void MChisqEval::SetY1(const TString data)
99{
100 SetY1(new MDataChain(data));
101}
102
103void MChisqEval::SetY2(const TString data)
104{
105 SetY2(new MDataChain(data));
106}
107
108Int_t MChisqEval::PreProcess(MParList *plist)
109{
110 fChisq = 0;
111
112 if (!fData0)
113 return kFALSE;
114
115 if (!fData0->PreProcess(plist))
116 return kFALSE;
117
118 if (fData1)
119 if (!fData1->PreProcess(plist))
120 return kFALSE;
121
122 return kTRUE;
123}
124
125Int_t MChisqEval::Process()
126{
127 const Double_t y1 = fData0->GetValue();
128 const Double_t y2 = fData1 ? fData1->GetValue() : 0;
129
130 const Double_t dy = y2-y1;
131 const Double_t err = fData1 ? y1*y1 : 1;
132
133 fChisq += dy*dy/err;
134 return kTRUE;
135}
136
137Int_t MChisqEval::PostProcess()
138{
139 fChisq /= GetNumExecutions();
140 return kTRUE;
141}
142
143const TString MChisqEval::gsDefName = "MChisqEval";
144const TString MChisqEval::gsDefTitle = "Evaluate a chisq";
145
Note: See TracBrowser for help on using the repository browser.