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

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