source: trunk/MagicSoft/Mars/mimage/MHillasCalc.cc@ 3897

Last change on this file since 3897 was 3682, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.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, 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
51// MGeomCam
52// [MHillas]
53//
54// Output Containers:
55// [MHillas]
56// MHillasExt
57// MNewImagePar
58//
59/////////////////////////////////////////////////////////////////////////////
60#include "MHillasCalc.h"
61
62#include "MParList.h"
63
64#include "MHillas.h"
65#include "MHillasExt.h"
66#include "MNewImagePar.h"
67#include "MConcentration.h"
68#include "MCerPhotEvt.h"
69
70#include "MLog.h"
71#include "MLogManip.h"
72
73ClassImp(MHillasCalc);
74
75using namespace std;
76
77// --------------------------------------------------------------------------
78//
79// Default constructor.
80//
81MHillasCalc::MHillasCalc(const char *name, const char *title)
82 : fHilName("MHillas"), fHilExtName("MHillasExt"),
83 fImgParName("MNewImagePar"), fConcName("MConcentration"),
84 fFlags(0xff), fErrors(5)
85{
86 fName = name ? name : "MHillasCalc";
87 fTitle = title ? title : "Calculate Hillas and other image parameters";
88}
89
90// --------------------------------------------------------------------------
91//
92// Check for a MCerPhotEvt object from which the Hillas are calculated.
93// Try to find the Geometry conatiner. Depending on the flags
94// try to find (and maybe create) the containers MHillas, MHillasExt,
95// MNewImagePar, too.
96//
97Int_t MHillasCalc::PreProcess(MParList *pList)
98{
99 // necessary
100 fCerPhotEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
101 if (!fCerPhotEvt)
102 {
103 *fLog << err << "MCerPhotEvt not found... aborting." << endl;
104 return kFALSE;
105 }
106
107 // necessary
108 fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
109 if (!fGeomCam)
110 {
111 *fLog << err << "MGeomCam (Camera Geometry) missing in Parameter List... aborting." << endl;
112 return kFALSE;
113 }
114
115 // depend on whether MHillas is an in- or output container
116 if (TestFlag(kCalcHillas))
117 fHillas = (MHillas*)pList->FindCreateObj("MHillas", AddSerialNumber(fHilName));
118 else
119 {
120 fHillas = (MHillas*)pList->FindObject(AddSerialNumber(fHilName), "MHillas");
121 *fLog << err << fHilName << " [MHillas] not found... aborting." << endl;
122 }
123 if (!fHillas)
124 return kFALSE;
125
126 // if enabled
127 if (TestFlag(kCalcHillasExt))
128 {
129 fHillasExt = (MHillasExt*)pList->FindCreateObj("MHillasExt", AddSerialNumber(fHilExtName));
130 if (!fHillasExt)
131 return kFALSE;
132 }
133
134 // if enabled
135 if (TestFlag(kCalcNewImagePar))
136 {
137 fNewImgPar = (MNewImagePar*)pList->FindCreateObj("MNewImagePar", AddSerialNumber(fImgParName));
138 if (!fNewImgPar)
139 return kFALSE;
140 }
141
142 // if enabled
143 if (TestFlag(kCalcConc))
144 {
145 fConc = (MConcentration*)pList->FindCreateObj("MConcentration", fConcName);
146 if (!fConc)
147 return kFALSE;
148 }
149
150 memset(fErrors.GetArray(), 0, sizeof(Char_t)*fErrors.GetSize());
151
152 return kTRUE;
153}
154
155// --------------------------------------------------------------------------
156//
157// If you want do complex descisions inside the calculations
158// we must move the calculation code inside this function
159//
160// If the calculation wasn't sucessfull skip this event
161//
162Int_t MHillasCalc::Process()
163{
164 if (TestFlag(kCalcHillas))
165 {
166 Int_t rc = fHillas->Calc(*fGeomCam, *fCerPhotEvt);
167 if (rc<0 || rc>4)
168 {
169 *fLog << err << dbginf << "MHillas::Calc returned unknown error code!" << endl;
170 return kFALSE;
171 }
172 fErrors[rc]++;
173 if (rc>0)
174 return kCONTINUE;
175 }
176
177 if (TestFlag(kCalcHillasExt))
178 fHillasExt->Calc(*fGeomCam, *fCerPhotEvt, *fHillas);
179
180 if (TestFlag(kCalcNewImagePar))
181 fNewImgPar->Calc(*fGeomCam, *fCerPhotEvt, *fHillas);
182
183 if (TestFlag(kCalcConc))
184 fConc->Calc(*fGeomCam, *fCerPhotEvt, *fHillas);
185
186 return kTRUE;
187}
188
189// --------------------------------------------------------------------------
190//
191// This is used to print the output in the PostProcess. Later (having
192// millions of events) we may want to improve the output.
193//
194void MHillasCalc::PrintSkipped(int i, const char *str) const
195{
196 *fLog << " " << setw(7) << fErrors[i] << " (";
197 *fLog << setw(3) << (int)(100.*fErrors[i]/GetNumExecutions());
198 *fLog << "%) Evts skipped: " << str << endl;
199}
200
201// --------------------------------------------------------------------------
202//
203// Prints some statistics about the hillas calculation. The percentage
204// is calculated with respect to the number of executions of this task.
205//
206Int_t MHillasCalc::PostProcess()
207{
208 if (GetNumExecutions()==0)
209 return kTRUE;
210
211 *fLog << inf << endl;
212 *fLog << GetDescriptor() << " execution statistics:" << endl;
213 *fLog << dec << setfill(' ');
214 PrintSkipped(1, "Less than 3 pixels (before cleaning)");
215 PrintSkipped(2, "Calculated Size == 0 (after cleaning)");
216 PrintSkipped(3, "Number of used pixels < 3");
217 PrintSkipped(4, "CorrXY==0");
218 *fLog << " " << (int)fErrors[0] << " (" << (int)(100.*fErrors[0]/GetNumExecutions()) << "%) Evts survived Hillas calculation!" << endl;
219 *fLog << endl;
220
221 return kTRUE;
222}
Note: See TracBrowser for help on using the repository browser.