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

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