source: trunk/MagicSoft/Mars/manalysis/MEnergyEstParam.cc@ 1778

Last change on this file since 1778 was 1525, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 8.2 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 9/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MEnergyEstParam //
28// //
29// Task to estimate the energy using a parametrization. //
30// Make sure, that all source dependant containers are based on the same //
31// set of basic hillas parameters //
32// //
33/////////////////////////////////////////////////////////////////////////////
34#include "MEnergyEstParam.h"
35
36#include "MParList.h"
37
38#include "MMcEvt.hxx"
39#include "MHMatrix.h"
40#include "MHillasSrc.h"
41#include "MEnergyEst.h"
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46ClassImp(MEnergyEstParam);
47
48// --------------------------------------------------------------------------
49//
50// Initialize the coefficients with (nonsense) values
51//
52void MEnergyEstParam::InitCoefficients()
53{
54 fA[0] = 39.667402; // [cm]
55 fA[1] = 143.081912; // [cm]
56 fA[2] = -395.501677; // [cm]
57 fA[3] = 0.006193;
58
59 fB[0] = 45.037867; // [GeV]
60 fB[1] = 0.087222; // [GeV]
61 fB[2] = -0.208065; // [GeV/cm]
62 fB[3] = 78.164942; // [GeV]
63 fB[4] = -159.361283; // [GeV]
64 fB[5] = -0.130455; // [GeV/cm]
65 fB[6] = 0.051139;
66}
67
68// --------------------------------------------------------------------------
69//
70// Default constructor. Give the name of the parameter container (MHillas)
71// storing wisth, length and size (Default="MHillas").
72// For the Zenith Angle MMcEvt.fTheta is used.
73//
74MEnergyEstParam::MEnergyEstParam(const char *hillas, const char *name, const char *title)
75 : fMatrix(NULL), fA(4), fB(7)
76{
77 fName = name ? name : "MEnergyEstParam";
78 fTitle = title ? title : "Task to estimate the energy";
79
80 fHillasName = hillas;
81
82 fPairs = new TList;
83 fEnergy = new TList;
84 fHillasSrc = new TList;
85
86 fPairs->SetOwner();
87
88 InitCoefficients();
89
90 AddToBranchList("MMcEvt.fTheta");
91 AddToBranchList(fHillasName+"fSize");
92 AddToBranchList(fHillasName+"fWidth");
93 AddToBranchList(fHillasName+"fLength");
94}
95
96
97// --------------------------------------------------------------------------
98//
99// Destructor.
100//
101MEnergyEstParam::~MEnergyEstParam()
102{
103 delete fPairs;
104 delete fEnergy;
105 delete fHillasSrc;
106}
107
108// --------------------------------------------------------------------------
109//
110// Check for all necessary parameter containers.
111//
112Bool_t MEnergyEstParam::PreProcess(MParList *plist)
113{
114 if (!fMatrix)
115 {
116 fHillas = (MHillas*)plist->FindObject(fHillasName, "MHillas");
117 if (!fHillas)
118 {
119 *fLog << err << dbginf << fHillasName << " [MHillas] not found... aborting." << endl;
120 return kFALSE;
121 }
122
123 fMc = (MMcEvt*)plist->FindObject("MMcEvt");
124 if (!fMc)
125 {
126 *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
127 return kFALSE;
128 }
129 }
130
131 TObject *obj = NULL;
132 TIter Next(fPairs);
133
134 while ((obj=Next()))
135 {
136 TObject *o = plist->FindCreateObj(obj->GetTitle(), "MEnergyEst");
137 if (!o)
138 return kFALSE;
139
140 if (!fEnergy->FindObject(obj->GetTitle()))
141 fEnergy->Add(o);
142
143 if (fMatrix)
144 continue;
145
146 o = plist->FindObject(obj->GetName(), "MHillasSrc");
147 if (!o)
148 {
149 *fLog << err << dbginf << obj->GetName() << " not found... aborting." << endl;
150 return kFALSE;
151 }
152 fHillasSrc->Add(o);
153 }
154
155 return kTRUE;
156}
157
158// --------------------------------------------------------------------------
159//
160// Set the four coefficients for the estimation of the impact parameter.
161// Argument must ba a TArrayD of size 4.
162//
163void MEnergyEstParam::SetCoeffA(TArrayD arr)
164{
165 if (arr.GetSize() != fA.GetSize())
166 {
167 *fLog << err << dbginf << "Error - Wrong number of coefficients!" << endl;
168 return;
169 }
170
171 fA = arr;
172}
173
174// --------------------------------------------------------------------------
175//
176// Set the four coefficients for the estimation of the energy.
177// Argument must ba a TArrayD of size 7.
178//
179void MEnergyEstParam::SetCoeffB(TArrayD arr)
180{
181 if (arr.GetSize() != fB.GetSize())
182 {
183 *fLog << err << dbginf << "Error - Wrong number of coefficients!" << endl;
184 return;
185 }
186
187 fB = arr;
188}
189
190// --------------------------------------------------------------------------
191//
192// Returns the mapped value from the Matrix
193//
194Double_t MEnergyEstParam::GetVal(Int_t i) const
195{
196 return (*fMatrix)[fMap[i]];
197}
198
199// --------------------------------------------------------------------------
200//
201// You can use this function if you want to use a MHMatrix instead of the
202// given containers. This function adds all necessary columns to the
203// given matrix. Afterward you should fill the matrix with the corresponding
204// data (eg from a file by using MHMatrix::Fill). If you now loop
205// through the matrix (eg using MMatrixLoop) MEnergyEstParam::Process
206// will take the values from the matrix instead of the containers.
207//
208void MEnergyEstParam::InitMapping(MHMatrix *mat)
209{
210 if (fMatrix)
211 return;
212
213 fMatrix = mat;
214
215 fMap[0] = fMatrix->AddColumn("MMcEvt.fTheta");
216 fMap[1] = fMatrix->AddColumn(fHillasName+".fWidth");
217 fMap[2] = fMatrix->AddColumn(fHillasName+".fLength");
218 fMap[3] = fMatrix->AddColumn(fHillasName+".fSize");
219
220 Int_t col = 4;
221 TIter Next(fPairs);
222 TObject *o = NULL;
223 while ((o=Next()))
224 fMap[col++] = fMatrix->AddColumn(TString(o->GetName())+".fDist");
225}
226
227// --------------------------------------------------------------------------
228//
229// Add a pair of input/output containers.
230// eg. Add("MHillasSrc", "MEnergyEst");
231// Usefull if you want to estimate the stuff for the source and antisource
232//
233void MEnergyEstParam::Add(const TString hillas, const TString energy)
234{
235 fPairs->Add(new TNamed(hillas, energy));
236
237 AddToBranchList(hillas+".fDist");
238}
239
240// --------------------------------------------------------------------------
241//
242// Estimates the impact parameter and energy using a parameterization
243// (see code)
244//
245Bool_t MEnergyEstParam::Process()
246{
247 const Double_t theta = fMatrix ? GetVal(0) : fMc->GetTheta();
248 const Double_t width = fMatrix ? GetVal(1) : fHillas->GetWidth();
249 const Double_t length = fMatrix ? GetVal(2) : fHillas->GetLength();
250 const Double_t size = fMatrix ? GetVal(3) : fHillas->GetSize();
251
252 const Double_t k = 1/cos(theta);
253 const Double_t k2 = k*k;
254
255 const Double_t i0 = k * (1+fA[3]*k)/(1+fA[3]);
256 const Double_t i1 = fA[0] + fA[2]*width;
257
258 const Double_t e0 = k2 * (1+fB[6]*k2)/(1+fB[6]);
259 const Double_t e1 = fB[0] + fB[1]*size + fB[3]*length + fB[4]*size*length;
260 const Double_t e2 = fB[2] + fB[5]*length;
261
262 TIter NextH(fHillasSrc);
263 TIter NextE(fEnergy);
264
265 Int_t col = 4;
266
267 while (1)
268 {
269 MEnergyEst *est = (MEnergyEst*)NextE();
270 if (!est)
271 break;
272
273 const Double_t dist = fMatrix ? GetVal(col++) : ((MHillasSrc*)NextH())->GetDist();
274
275 const Double_t ir = i0 * (i1 + fA[1]*dist); // [cm]
276 const Double_t er = -e0 * (e1 + e2*ir); // [GeV]
277
278 est->SetEnergy(er);
279 est->SetImpact(ir);
280 }
281
282 return kTRUE;
283}
284
Note: See TracBrowser for help on using the repository browser.