source: trunk/MagicSoft/Mars/manalysis/MMultiDimDistCalc.cc@ 1466

Last change on this file since 1466 was 1337, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 4.7 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, 5/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Rudy Bock, 5/2002 <mailto:rkb@mppmu.mpg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2002
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MMultiDimDistCalc
29//
30// Calculated a multidimensional distance. It calculates the distance to
31// all vectors in a given matrix describing Gammas and another one
32// describing Hadrons (non gammas). The shortest distances are avaraged.
33// How many distances are used for avaraging can be specified in the
34// constructor.
35//
36////////////////////////////////////////////////////////////////////////////
37#include "MMultiDimDistCalc.h"
38
39#include "MHMatrix.h" // must be before MLogManip.h
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44#include "MParList.h"
45#include "MDataChain.h"
46
47#include "MHadroness.h"
48
49ClassImp(MMultiDimDistCalc);
50
51// --------------------------------------------------------------------------
52//
53// Setup histograms and the number of distances which are used for
54// avaraging in CalcDist
55//
56MMultiDimDistCalc::MMultiDimDistCalc(Int_t num, const char *name, const char *title)
57 : fNum(num)
58{
59 //
60 // set the name and title of this object
61 //
62 fName = name ? name : "MMultiDimDistCalc";
63 fTitle = title ? title : "Composite Probabilities Loop 1/2";
64
65 fData = new TList;
66 fData->SetOwner();
67}
68
69// --------------------------------------------------------------------------
70//
71// Delete the data chains
72//
73MMultiDimDistCalc::~MMultiDimDistCalc()
74{
75 delete fData;
76}
77
78// --------------------------------------------------------------------------
79//
80// Needs:
81// - MatrixGammas [MHMatrix]
82// - MatrixHadrons {MHMatrix]
83// - MHadroness
84// - all data containers used to build the matrixes
85//
86// The matrix object can be filles using MFillH. And must be of the same
87// number of columns (with the same meaning).
88//
89Bool_t MMultiDimDistCalc::PreProcess(MParList *plist)
90{
91 fMGammas = (MHMatrix*)plist->FindObject("MatrixGammas", "MHMatrix");
92 if (!fMGammas)
93 {
94 *fLog << err << dbginf << "MatrixGammas [MHMatrix] not found... aborting." << endl;
95 return kFALSE;
96 }
97
98 fMHadrons = (MHMatrix*)plist->FindObject("MatrixHadrons", "MHMatrix");
99 if (!fMHadrons)
100 {
101 *fLog << err << dbginf << "MatrixHadrons [MHMatrix] not found... aborting." << endl;
102 return kFALSE;
103 }
104
105 if (fMGammas->GetM().GetNcols() != fMHadrons->GetM().GetNcols())
106 {
107 *fLog << err << dbginf << "Error matrices have different numbers of columns... aborting." << endl;
108 return kFALSE;
109 }
110
111 TIter Next(fMGammas->GetRules());
112 TObject *data=NULL;
113 while ((data=Next()))
114 {
115 MDataChain *chain = new MDataChain(data->GetName());
116 if (!chain->PreProcess(plist))
117 {
118 delete chain;
119 return kFALSE;
120 }
121 fData->Add(chain);
122 }
123
124 fHadroness = (MHadroness*)plist->FindCreateObj("MHadroness");
125 if (!fHadroness)
126 return kFALSE;
127
128 return kTRUE;
129}
130
131// --------------------------------------------------------------------------
132//
133// Evaluates the avarage over the fNum shortest distances in a
134// multidimensional space to a matrix (set of vectors) describing
135// gammas and hadrons.
136// The hadroness of the event is defines as the avarage distance to the
137// set of gammas (dg) divided by the avarage distance to the set of
138// hadrons (dh). Because this value is in teh range [0, inf] it is
139// transformed into [0,1] by:
140// H = exp(-dh/dg);
141//
142Bool_t MMultiDimDistCalc::Process()
143{
144 const Double_t ncols = fMGammas->GetM().GetNcols();
145
146 TVector event(ncols);
147
148 Int_t n=0;
149 TIter Next(fData);
150 MData *data = NULL;
151 while ((data=(MData*)Next()))
152 event(n++) = data->GetValue();
153
154 Double_t dg = fMGammas->CalcDist(event, fNum);
155 Double_t dh = fMHadrons->CalcDist(event, fNum);
156
157 fHadroness->SetHadroness(exp(-dh/dg));
158
159 return kTRUE;
160}
161
Note: See TracBrowser for help on using the repository browser.