source: trunk/Mars/manalysis/MEnergyEstParamDanielMkn421.cc@ 19344

Last change on this file since 19344 was 8020, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 10.8 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! Wolfgang Wittek 7/2003 <mailto:wittek@mppmu.mpg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2003
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27// //
28// MEnergyEstParamDanielMkn421 //
29// //
30// Task to estimate the energy using a parametrization. //
31// Make sure, that all source dependant containers are based on the same //
32// set of basic hillas parameters //
33// //
34/////////////////////////////////////////////////////////////////////////////
35#include "MEnergyEstParamDanielMkn421.h"
36
37#include "MParList.h"
38
39#include "MGeomCam.h"
40#include "MMcEvt.hxx"
41#include "MHMatrix.h"
42#include "MHillasSrc.h"
43#include "MNewImagePar.h"
44#include "MEnergyEst.h"
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49ClassImp(MEnergyEstParamDanielMkn421);
50
51using namespace std;
52
53// --------------------------------------------------------------------------
54//
55// Initialize the coefficients with Daniel's values
56// for Mkn421
57//
58//
59void MEnergyEstParamDanielMkn421::InitCoefficients()
60{
61 // parameters for the impact parameter
62 fA.Set(4);
63 fA[0] = 12.0322; //
64 fA[1] = 8.29911; //
65 fA[2] = 73.0699; //
66 fA[3] = 0.311375;
67
68
69 // parameters for the energy
70 fB.Set(6);
71 fB[0] = 1.23138; //
72 fB[1] = 0.00276497; //
73 fB[2] = -0.0110667; //
74 fB[3] = 7.47538; //
75 fB[4] = -1.25619; //
76 fB[5] = 0.627699; //
77}
78
79// --------------------------------------------------------------------------
80//
81// Default constructor. Give the name of the parameter container (MHillas)
82// storing width, length and size (Default="MHillas").
83// For the Zenith Angle MMcEvt.fTheta is used.
84//
85MEnergyEstParamDanielMkn421::MEnergyEstParamDanielMkn421(const char *hillas, const char *name, const char *title)
86 : fMatrix(NULL)
87{
88 fName = name ? name : "MEnergyEstParamDanielMkn421";
89 fTitle = title ? title : "Task to estimate the energy (Daniel Mkn421)";
90
91 fHillasName = hillas;
92
93 fPairs = new TList;
94 fEnergy = new TList;
95 fHillasSrc = new TList;
96
97 fPairs->SetOwner();
98
99 InitCoefficients();
100
101 AddToBranchList("MMcEvt.fTelescopeTheta");
102 AddToBranchList(fHillasName+".fSize");
103 AddToBranchList(fHillasName+".fWidth");
104 AddToBranchList(fHillasName+".fLength");
105 AddToBranchList("MNewImagePar.fLeakage1");
106}
107
108
109// --------------------------------------------------------------------------
110//
111// Destructor.
112//
113MEnergyEstParamDanielMkn421::~MEnergyEstParamDanielMkn421()
114{
115 delete fPairs;
116 delete fEnergy;
117 delete fHillasSrc;
118}
119
120// --------------------------------------------------------------------------
121//
122// Check for all necessary parameter containers.
123//
124Int_t MEnergyEstParamDanielMkn421::PreProcess(MParList *plist)
125{
126 const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
127 if (!geom)
128 {
129 *fLog << warn << dbginf << "No Camera Geometry available" << endl;
130 return kFALSE;
131 }
132 else
133 {
134 fMm2Deg = geom->GetConvMm2Deg();
135 }
136
137
138 if (!fMatrix)
139 {
140 fHillas = (MHillas*)plist->FindObject(fHillasName, "MHillas");
141 if (!fHillas)
142 {
143 *fLog << err << dbginf << fHillasName << " [MHillas] not found... aborting." << endl;
144 return kFALSE;
145 }
146
147 fMc = (MMcEvt*)plist->FindObject("MMcEvt");
148 if (!fMc)
149 {
150 *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
151 return kFALSE;
152 }
153
154 fNewImagePar = (MNewImagePar*)plist->FindObject("MNewImagePar");
155 if (!fNewImagePar)
156 {
157 *fLog << err << dbginf << " object 'MNewImagePar' not found... aborting." << endl;
158 return kFALSE;
159 }
160
161 }
162
163
164 TObject *obj = NULL;
165 TIter Next(fPairs);
166
167 while ((obj=Next()))
168 {
169 TObject *o = plist->FindCreateObj(obj->GetTitle(), "MEnergyEst");
170 if (!o)
171 return kFALSE;
172
173 if (!fEnergy->FindObject(obj->GetTitle()))
174 fEnergy->Add(o);
175
176 if (fMatrix)
177 continue;
178
179 o = plist->FindObject(obj->GetName(), "MHillasSrc");
180 if (!o)
181 {
182 *fLog << err << dbginf << obj->GetName() << " not found... aborting." << endl;
183 return kFALSE;
184 }
185 fHillasSrc->Add(o);
186 }
187
188 return kTRUE;
189}
190
191// --------------------------------------------------------------------------
192//
193// Set the five coefficients for the estimation of the impact parameter.
194// Argument must ba a TArrayD of size 5.
195//
196void MEnergyEstParamDanielMkn421::SetCoeffA(const TArrayD &arr)
197{
198 if (arr.GetSize() != fA.GetSize())
199 {
200 *fLog << err << dbginf << "Error - Wrong number of coefficients!" << endl;
201 return;
202 }
203
204 fA = arr;
205}
206
207// --------------------------------------------------------------------------
208//
209// Set the seven coefficients for the estimation of the energy.
210// Argument must ba a TArrayD of size 7.
211//
212void MEnergyEstParamDanielMkn421::SetCoeffB(const TArrayD &arr)
213{
214 if (arr.GetSize() != fB.GetSize())
215 {
216 *fLog << err << dbginf << "Error - Wrong number of coefficients!" << endl;
217 return;
218 }
219
220 fB = arr;
221}
222
223// --------------------------------------------------------------------------
224//
225// Set the twelve coefficients for the estimation of impact and energy.
226// Argument must ba a TArrayD of size 12.
227//
228void MEnergyEstParamDanielMkn421::SetCoeff(const TArrayD &arr)
229{
230 if (arr.GetSize() != fA.GetSize()+fB.GetSize())
231 {
232 *fLog << err << dbginf << "Error - Wrong number of coefficients!" << endl;
233 return;
234 }
235
236 fA = TArrayD(fA.GetSize(), arr.GetArray());
237 fB = TArrayD(fB.GetSize(), arr.GetArray() + fA.GetSize());
238}
239
240// --------------------------------------------------------------------------
241//
242// Returns the mapped value from the Matrix
243//
244Double_t MEnergyEstParamDanielMkn421::GetVal(Int_t i) const
245{
246 return (*fMatrix)[fMap[i]];
247}
248
249// --------------------------------------------------------------------------
250//
251// You can use this function if you want to use a MHMatrix instead of the
252// given containers. This function adds all necessary columns to the
253// given matrix. Afterward you should fill the matrix with the corresponding
254// data (eg from a file by using MHMatrix::Fill). If you now loop
255// through the matrix (eg using MMatrixLoop) MEnergyEstParamDanielMkn421::Process
256// will take the values from the matrix instead of the containers.
257//
258void MEnergyEstParamDanielMkn421::InitMapping(MHMatrix *mat)
259{
260 if (fMatrix)
261 return;
262
263 fMatrix = mat;
264
265 fMap[0] = fMatrix->AddColumn("MMcEvt.fTelescopeTheta");
266 fMap[1] = fMatrix->AddColumn(fHillasName+".fWidth");
267 fMap[2] = fMatrix->AddColumn(fHillasName+".fLength");
268 fMap[3] = fMatrix->AddColumn(fHillasName+".fSize");
269 fMap[4] = fMatrix->AddColumn("MNewImagePar.fLeakage1");
270
271 Int_t col = 5;
272 TIter Next(fPairs);
273 TObject *o = NULL;
274 while ((o=Next()))
275 fMap[col++] = fMatrix->AddColumn(TString(o->GetName())+".fDist");
276}
277
278void MEnergyEstParamDanielMkn421::StopMapping()
279{
280 fMatrix = NULL;
281 fPairs->Clear();
282 fHillasSrc->Clear();
283 fEnergy->Clear();
284}
285
286// --------------------------------------------------------------------------
287//
288// Add a pair of input/output containers.
289// eg. Add("MHillasSrc", "MEnergyEst");
290// Useful if you want to estimate the stuff for the source and antisource
291//
292void MEnergyEstParamDanielMkn421::Add(const TString hillas, const TString energy)
293{
294 fPairs->Add(new TNamed(hillas, energy));
295
296 AddToBranchList(hillas+".fDist");
297}
298
299void MEnergyEstParamDanielMkn421::Print(Option_t *opt) const
300{
301 for (int i=0; i<fA.GetSize(); i++)
302 *fLog << all << "fA[" << i << "]=" << const_cast<TArrayD&>(fA)[i] << endl;
303 for (int i=0; i<fB.GetSize(); i++)
304 *fLog << all << "fB[" << i << "]=" << const_cast<TArrayD&>(fB)[i] << endl;
305}
306
307// --------------------------------------------------------------------------
308//
309// Estimates the impact parameter and energy using a parameterization
310// (see code)
311//
312Int_t MEnergyEstParamDanielMkn421::Process()
313{
314
315 const Double_t theta = fMatrix ? GetVal(0) : fMc->GetTelescopeTheta();
316
317 Double_t width = fMatrix ? GetVal(1) : fHillas->GetWidth();
318 width *= fMm2Deg;
319
320 Double_t length = fMatrix ? GetVal(2) : fHillas->GetLength();
321 length *= fMm2Deg;
322
323 const Double_t size = fMatrix ? GetVal(3) : fHillas->GetSize();
324 Double_t leakage= fMatrix ? GetVal(4) : fNewImagePar->GetLeakage1();
325 leakage = (leakage-0.1)<0. ? 0. : leakage-0.1;
326
327 const Double_t k = 1./cos(theta);
328 const Double_t k2 = k*k;
329
330 const Double_t i0 = k * (fA[3]*k + 1);
331 const Double_t e0 = k2 * (fB[4]*k + fB[5]*k2+1);
332
333 TIter NextH(fHillasSrc);
334 TIter NextE(fEnergy);
335
336 Int_t col = 5;
337
338 while (1)
339 {
340 MEnergyEst *est = (MEnergyEst*)NextE();
341 if (!est)
342 break;
343
344 Double_t dist = fMatrix ? GetVal(col++) : ((MHillasSrc*)NextH())->GetDist();
345 dist *= fMm2Deg;
346
347 Double_t ir = i0 * (fA[0] + fA[1]*dist/width + fA[2]*leakage);
348 Double_t er = e0 * (fB[0] + fB[1]*size/width + fB[2]*ir + fB[3]*leakage);
349 er *= 1000.0; // conversion to GeV
350
351 if (ir<0. || er<0.)
352 {
353 ir = 0.;
354 er = 0.;
355 }
356
357 if (width==0)
358 return kCONTINUE;
359
360 // !Finitite includes IsNaN
361 if (!TMath::Finite(ir))
362 *fLog << all << theta << " " << width << " " << length << " " << size << " " << dist << endl;
363 if (!TMath::Finite(er))
364 {
365 *fLog << all << theta << " " << width << " " << length << " " << size << " " << dist << endl;
366 er = 0;
367 }
368
369 est->SetEnergy(er);
370 est->SetImpact(ir);
371 est->SetReadyToSave();
372
373 }
374
375
376 return kTRUE;
377}
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
Note: See TracBrowser for help on using the repository browser.