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

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