source: releases/Mars.2014.05.26/mfilter/MFSupercuts.cc@ 18459

Last change on this file since 18459 was 6892, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 9.6 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): Wolfgang Wittek, 04/2003 <mailto:wittek@mppmu.mpg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MFSupercuts
28//
29// this class calculates the hadronness for the supercuts
30// the parameters of the supercuts are taken
31// from the container MSupercuts
32//
33//
34/////////////////////////////////////////////////////////////////////////////
35#include "MFSupercuts.h"
36
37#include <math.h>
38#include <fstream>
39
40#include "TFile.h"
41#include "TArrayD.h"
42
43#include "MParList.h"
44#include "MHillasExt.h"
45#include "MHillasSrc.h"
46#include "MNewImagePar.h"
47#include "MGeomCam.h"
48#include "MHMatrix.h"
49
50#include "MLog.h"
51#include "MLogManip.h"
52
53ClassImp(MFSupercuts);
54
55using namespace std;
56
57
58// --------------------------------------------------------------------------
59//
60// constructor
61//
62
63MFSupercuts::MFSupercuts(const char *name, const char *title)
64 : fHil(0), fHilSrc(0), fHilExt(0), fNewPar(0), fMatrix(0), fVariables(84)
65{
66 fName = name ? name : "MFSupercuts";
67 fTitle = title ? title : "Class to evaluate the Supercuts";
68
69 fMatrix = NULL;
70
71 AddToBranchList("MHillas.fWidth");
72 AddToBranchList("MHillas.fLength");
73 AddToBranchList("MHillasSrc.fDist");
74 AddToBranchList("MHillas.fSize");
75}
76
77// --------------------------------------------------------------------------
78//
79Int_t MFSupercuts::PreProcess(MParList *pList)
80{
81 MGeomCam *cam = (MGeomCam*)pList->FindObject("MGeomCam");
82 if (!cam)
83 {
84 *fLog << err << "MGeomCam not found... aborting." << endl;
85 return kFALSE;
86 }
87
88 fMm2Deg = cam->GetConvMm2Deg();
89
90 if (fMatrix)
91 return kTRUE;
92
93 //-----------------------------------------------------------
94 fHil = (MHillas*)pList->FindObject("MHillas");
95 if (!fHil)
96 {
97 *fLog << err << "MHillas not found... aborting." << endl;
98 return kFALSE;
99 }
100
101 fHilExt = (MHillasExt*)pList->FindObject("MHillasExt");
102 if (!fHilExt)
103 {
104 *fLog << err << "MHillasExt not found... aborting." << endl;
105 return kFALSE;
106 }
107
108 fHilSrc = (MHillasSrc*)pList->FindObject("MHillasSrc");
109 if (!fHilSrc)
110 {
111 *fLog << err << "MHillasSrc not found... aborting." << endl;
112 return kFALSE;
113 }
114
115 fNewPar = (MNewImagePar*)pList->FindObject("MNewImagePar");
116 if (!fNewPar)
117 {
118 *fLog << err << "MNewImagePar not found... aborting." << endl;
119 return kFALSE;
120 }
121/*
122 fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
123 if (!fMcEvt)
124 {
125 *fLog << err << "MMcEvt not found... aborting." << endl;
126 return kFALSE;
127 }
128 */
129 return kTRUE;
130}
131
132// --------------------------------------------------------------------------
133//
134// Returns the mapped value from the Matrix
135//
136Double_t MFSupercuts::GetVal(Int_t i) const
137{
138 return (*fMatrix)[fMap[i]];
139}
140
141// --------------------------------------------------------------------------
142//
143// You can use this function if you want to use a MHMatrix instead of the
144// given containers. This function adds all necessary columns to the
145// given matrix. Afterward you should fill the matrix with the corresponding
146// data (eg from a file by using MHMatrix::Fill). If you now loop
147// through the matrix (eg using MMatrixLoop) MEnergyEstParam::Process
148// will take the values from the matrix instead of the containers.
149//
150void MFSupercuts::InitMapping(MHMatrix *mat)
151{
152 if (fMatrix)
153 return;
154
155 fMatrix = mat;
156
157 //fMap[0] = fMatrix->AddColumn("MPointingPos.fZd");
158 fMap[0] = fMatrix->AddColumn("MHillas.fWidth*MGeomCam.fConvMm2Deg");
159 fMap[1] = fMatrix->AddColumn("MHillas.fLength*MGeomCam.fConvMm2Deg");
160 fMap[2] = fMatrix->AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg");
161 fMap[3] = fMatrix->AddColumn("log10(MHillas.fSize)");
162 //fMap[7] = fMatrix->AddColumn("fabs(MHillasSrc.fAlpha)");
163 /*
164 fMap[8] = fMatrix->AddColumn("sgn(MHillasSrc.fCosDeltaAlpha)*(MHillasExt.fM3Long)");
165 fMap[9] = fMatrix->AddColumn("MNewImagePar.fConc");
166 fMap[10] = fMatrix->AddColumn("MNewImagePar.fLeakage1");
167 */
168}
169
170// --------------------------------------------------------------------------
171//
172// Calculation of upper and lower limits
173//
174Double_t MFSupercuts::CtsMCut(const Double_t* a, Double_t ls, Double_t ct,
175 Double_t ls2, Double_t dd2) const
176{
177 // define cut-function
178 //
179 // dNOMLOGSIZE = 5.0 (=log(150.0)
180 // dNOMCOSZA = 1.0
181 //
182 // a: array of cut parameters
183 // ls: log(SIZE) - dNOMLOGSIZE
184 // ls2: ls^2
185 // ct: Cos(ZA.) - dNOMCOSZA
186 // dd2: DIST^2
187 const Double_t limit =
188 a[0] + a[1] * dd2 + a[2] * ct +
189 ls * (a[3] + a[4] * dd2 + a[5] * ct) +
190 ls2 * (a[6] + a[7] * dd2);
191
192 return limit;
193}
194
195// ---------------------------------------------------------------------------
196//
197// Evaluate dynamical supercuts
198//
199// set hadronness to 0.25 if cuts are fullfilled
200// 0.75 otherwise
201//
202Int_t MFSupercuts::Process()
203{
204 // const Double_t kNomLogSize = 4.1;
205 // const Double_t kNomCosZA = 1.0;
206
207 // const Double_t theta = fMatrix ? GetVal(0) : fMcEvt->GetTelescopeTheta();
208 // const Double_t meanx = fMatrix ? GetVal(4) : fHil->GetMeanX()*fMm2Deg;
209 // const Double_t meany = fMatrix ? GetVal(5) : fHil->GetMeanY()*fMm2Deg;
210 // const Double_t asym0 = fMatrix ? GetVal(8) : TMath::Sign(fHilExt->GetM3Long(), fHilSrc->GetCosDeltaAlpha());;
211 // const Double_t conc = fMatrix ? GetVal(9) : fNewPar->GetConc();
212 // const Double_t leakage = fMatrix ? GetVal(10): fNewPar->GetLeakage1();
213 // const Double_t asym = asym0 * fMm2Deg;
214
215 const Double_t width = fMatrix ? GetVal(0) : fHil->GetWidth()*fMm2Deg;
216 const Double_t length = fMatrix ? GetVal(1) : fHil->GetLength()*fMm2Deg;
217 const Double_t dist = fMatrix ? GetVal(2) : fHilSrc->GetDist()*fMm2Deg;
218 const Double_t lgsize = fMatrix ? GetVal(3) : log10(fHil->GetSize());
219
220 const Double_t dist2 = dist*dist;
221 const Double_t lgsize2 = lgsize * lgsize;
222 const Double_t cost = 0; // cos(theta*TMath::DegToRad()) - kNomCosZA;
223
224 fResult =
225 // Length cuts
226 length > CtsMCut(fVariables.GetArray()+ 0, lgsize, cost, lgsize2, dist2) &&
227 length < CtsMCut(fVariables.GetArray()+ 8, lgsize, cost, lgsize2, dist2) &&
228 // Width cuts
229 width > CtsMCut(fVariables.GetArray()+16, lgsize, cost, lgsize2, dist2) &&
230 width < CtsMCut(fVariables.GetArray()+24, lgsize, cost, lgsize2, dist2) &&
231 // Dist cuts
232 dist > CtsMCut(fVariables.GetArray()+32, lgsize, cost, lgsize2, dist2) &&
233 dist < CtsMCut(fVariables.GetArray()+40, lgsize, cost, lgsize2, dist2);
234
235 /*
236 asym < CtsMCut(&fVariables[42], dmls, dmcza, dmls2, dd2) &&
237 asym > CtsMCut(&fVariables[49], dmls, dmcza, dmls2, dd2) &&
238
239 conc < CtsMCut(&fVariables[56], dmls, dmcza, dmls2, dd2) &&
240 conc > CtsMCut(&fVariables[63], dmls, dmcza, dmls2, dd2) &&
241
242 leakage < CtsMCut(&fVariables[70], dmls, dmcza, dmls2, dd2) &&
243 leakage > CtsMCut(&fVariables[77], dmls, dmcza, dmls2, dd2))
244 */
245
246 return kTRUE;
247}
248
249TString MFSupercuts::GetDataMember() const
250{
251 return "MHillas.fWidth,MHillas.fLength,MHillasSrc.fDist,MHillas.fSize";
252}
253
254void MFSupercuts::SetVariables(const TArrayD &arr)
255{
256 fVariables = arr;
257}
258
259Bool_t MFSupercuts::CoefficentsRead(const char *fname)
260{
261 ifstream fin(fname);
262 if (!fin)
263 {
264 *fLog << err << "Cannot open file " << fname << ": ";
265 *fLog << strerror(errno) << endl;
266 return kFALSE;
267 }
268
269 for (int i=0; i<fVariables.GetSize(); i++)
270 {
271 fin >> fVariables[i];
272 if (!fin)
273 {
274 *fLog << err << "ERROR - Not enough coefficients in file " << fname << endl;
275 return kERROR;
276 }
277 }
278 return kTRUE;
279}
280
281Bool_t MFSupercuts::CoefficentsWrite(const char *fname) const
282{
283 ofstream fout(fname);
284 if (!fout)
285 {
286 *fLog << err << "Cannot open file " << fname << ": ";
287 *fLog << strerror(errno) << endl;
288 return kFALSE;
289 }
290
291 for (int i=0; i<fVariables.GetSize(); i++)
292 fout << setw(11) << fVariables[i] << endl;
293
294 return kTRUE;
295}
296
297Int_t MFSupercuts::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
298{
299 if (MFilter::ReadEnv(env, prefix, print)==kERROR)
300 return kERROR;
301
302 if (IsEnvDefined(env, prefix, "File", print))
303 {
304 const TString fname = GetEnvValue(env, prefix, "File", "");
305 if (!CoefficentsRead(fname))
306 return kERROR;
307
308 return kTRUE;
309 }
310
311 Bool_t rc = kFALSE;
312 for (int i=0; i<fVariables.GetSize(); i++)
313 {
314 if (IsEnvDefined(env, prefix, Form("Param%d", i), print))
315 {
316 fVariables[i] = GetEnvValue(env, prefix, Form("Param%d", i), 0);
317 rc = kTRUE;
318 }
319 }
320 return rc;
321}
Note: See TracBrowser for help on using the repository browser.