source: tags/Mars-V0.8.1/mimage/MHillasCalc.cc

Last change on this file was 2209, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 6.3 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, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Harald Kornmayer, 1/2001
20!
21! Copyright: MAGIC Software Development, 2000-2003
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHillasCalc
29//
30// This is a task to calculate the Hillas parameters from each event
31//
32// By default MHillas, MHillasExt and MNewImagePar are calculated
33// with the information from MCerPhotEvt and MGeomCam.
34//
35// To switch of the calculation you may use:
36// - Disable(MHillasCalc::kCalcHillas)
37// - Disable(MHillasCalc::kCalcHillasExt)
38// - Disable(MHillasCalc::kCalcNewImagePar)
39//
40// If the calculation of MHillas is switched off a container MHillas
41// in the parameter list is nevertheless necessary for the calculation
42// of MHillasExt and MNewImagePar.
43//
44// The names of the containers to be used can be set with:
45// - SetNameHillas("NewName")
46// - SetNameHillasExt("NewName")
47// - SetNameNewImgPar("NewName")
48//
49// Input Containers:
50// MCerPhotEvt, MGeomCam[, MHillas]
51//
52// Output Containers:
53// [MHillas,] MHillasExt, MNewImagePar
54//
55/////////////////////////////////////////////////////////////////////////////
56#include "MHillasCalc.h"
57
58#include "MParList.h"
59
60#include "MHillas.h"
61#include "MHillasExt.h"
62#include "MNewImagePar.h"
63
64#include "MCerPhotEvt.h"
65
66#include "MLog.h"
67#include "MLogManip.h"
68
69ClassImp(MHillasCalc);
70
71using namespace std;
72
73// --------------------------------------------------------------------------
74//
75// Default constructor.
76//
77MHillasCalc::MHillasCalc(const char *name, const char *title)
78 : fHilName("MHillas"), fHilExtName("MHillasExt"),
79 fImgParName("MNewImagePar"), fFlags(0xff)
80{
81 fName = name ? name : "MHillasCalc";
82 fTitle = title ? title : "Calculate Hillas and other image parameters";
83}
84
85// --------------------------------------------------------------------------
86//
87// Check for a MCerPhotEvt object from which the Hillas are calculated.
88// Try to find the Geometry conatiner. Depending on the flags
89// try to find (and maybe create) the containers MHillas, MHillasExt,
90// MNewImagePar, too.
91//
92Int_t MHillasCalc::PreProcess(MParList *pList)
93{
94 // necessary
95 fCerPhotEvt = (MCerPhotEvt*)pList->FindObject("MCerPhotEvt");
96 if (!fCerPhotEvt)
97 {
98 *fLog << err << "MCerPhotEvt not found... aborting." << endl;
99 return kFALSE;
100 }
101
102 // necessary
103 fGeomCam = (MGeomCam*)pList->FindObject("MGeomCam");
104 if (!fGeomCam)
105 {
106 *fLog << err << "MGeomCam (Camera Geometry) missing in Parameter List... aborting." << endl;
107 return kFALSE;
108 }
109
110 // depend on whether MHillas is an in- or output container
111 if (TestFlag(kCalcHillas))
112 fHillas = (MHillas*)pList->FindCreateObj("MHillas", fHilName);
113 else
114 {
115 fHillas = (MHillas*)pList->FindObject(fHilName, "MHillas");
116 *fLog << err << fHilName << " [MHillas] not found... aborting." << endl;
117 }
118 if (!fHillas)
119 return kFALSE;
120
121 // if enabled
122 if (TestFlag(kCalcHillasExt))
123 {
124 fHillasExt = (MHillasExt*)pList->FindCreateObj("MHillasExt", fHilExtName);
125 if (!fHillasExt)
126 return kFALSE;
127 }
128
129 // if enabled
130 if (TestFlag(kCalcNewImagePar))
131 {
132 fNewImgPar = (MNewImagePar*)pList->FindCreateObj("MNewImagePar", fImgParName);
133 if (!fNewImgPar)
134 return kFALSE;
135 }
136
137 memset(fErrors, 0, sizeof(fErrors));
138
139 return kTRUE;
140}
141
142// --------------------------------------------------------------------------
143//
144// If you want do complex descisions inside the calculations
145// we must move the calculation code inside this function
146//
147// If the calculation wasn't sucessfull skip this event
148//
149Int_t MHillasCalc::Process()
150{
151 if (TestFlag(kCalcHillas))
152 {
153 Int_t rc = fHillas->Calc(*fGeomCam, *fCerPhotEvt);
154 if (rc<0 || rc>4)
155 {
156 *fLog << err << dbginf << "MHillas::Calc returned unknown error code!" << endl;
157 return kFALSE;
158 }
159 fErrors[rc]++;
160 if (rc>0)
161 return kCONTINUE;
162 }
163
164 if (TestFlag(kCalcHillasExt))
165 fHillasExt->Calc(*fGeomCam, *fCerPhotEvt, *fHillas);
166
167 if (TestFlag(kCalcNewImagePar))
168 fNewImgPar->Calc(*fGeomCam, *fCerPhotEvt, *fHillas);
169
170 return kTRUE;
171}
172
173// --------------------------------------------------------------------------
174//
175// Prints some statistics about the hillas calculation. The percentage
176// is calculated with respect to the number of executions of this task.
177//
178Int_t MHillasCalc::PostProcess()
179{
180 if (GetNumExecutions()==0)
181 return kTRUE;
182
183 *fLog << inf << endl;
184 *fLog << GetDescriptor() << " execution statistics:" << endl;
185 *fLog << dec << setfill(' ');
186 *fLog << " " << setw(7) << fErrors[1] << " (" << setw(3) << (int)(fErrors[1]*100/GetNumExecutions()) << "%) Evts skipped due to: Event has less than 3 pixels" << endl;
187 *fLog << " " << setw(7) << fErrors[2] << " (" << setw(3) << (int)(fErrors[2]*100/GetNumExecutions()) << "%) Evts skipped due to: Calculated Size == 0" << endl;
188 *fLog << " " << setw(7) << fErrors[3] << " (" << setw(3) << (int)(fErrors[3]*100/GetNumExecutions()) << "%) Evts skipped due to: Number of used pixels < 3" << endl;
189 *fLog << " " << setw(7) << fErrors[4] << " (" << setw(3) << (int)(fErrors[4]*100/GetNumExecutions()) << "%) Evts skipped due to: CorrXY==0" << endl;
190 *fLog << " " << fErrors[0] << " (" << (int)(fErrors[0]*100/GetNumExecutions()) << "%) Evts survived Hillas calculation!" << endl;
191 *fLog << endl;
192
193 return kTRUE;
194}
Note: See TracBrowser for help on using the repository browser.