source: trunk/MagicSoft/Mars/manalysis/MCompProbCalc.cc@ 3188

Last change on this file since 3188 was 2206, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.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): Abelardo Moralejo <mailto:moralejo@pd.infn.it>
19! Author(s): Thomas Bretz, 5/2002 <mailto:moralejo@pd.infn.it>
20!
21! Copyright: MAGIC Software Development, 2000-2002
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MCompProbCalc
29//
30// FIXME: Use A huge matrix to evaluate variable bins instead of a
31// histogram
32//
33////////////////////////////////////////////////////////////////////////////
34#include "MCompProbCalc.h"
35
36#include <TH1.h>
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MParList.h"
42#include "MDataChain.h"
43
44#include "MHCompProb.h"
45#include "MHadronness.h"
46
47ClassImp(MCompProbCalc);
48
49using namespace std;
50
51// --------------------------------------------------------------------------
52//
53// Default constructor
54//
55MCompProbCalc::MCompProbCalc(const char *name, const char *title)
56{
57 //
58 // set the name and title of this object
59 //
60 fName = name ? name : "MCompProbCalc";
61 fTitle = title ? title : "Composite Probabilities Loop 1/2";
62
63 fData = new TList;
64 fData->SetOwner();
65}
66
67// --------------------------------------------------------------------------
68//
69// Destructor
70//
71MCompProbCalc::~MCompProbCalc()
72{
73 delete fData;
74}
75
76// --------------------------------------------------------------------------
77//
78// Needs:
79// - MHCompProb
80// - all data values which were used to build the MHCompProb
81// - MHadronness
82//
83Int_t MCompProbCalc::PreProcess(MParList *plist)
84{
85 MHCompProb *p = (MHCompProb*)plist->FindObject("MHCompProb");
86 if (!p)
87 {
88 *fLog << err << dbginf << "MHCompProb not found... aborting." << endl;
89 return kFALSE;
90 }
91
92 fHistVar = p->GetHistVar();
93 if (fHistVar->GetSize()==0)
94 {
95 *fLog << err << dbginf << "No Entries in MHCompProb::fHistVar... aborting." << endl;
96 return kFALSE;
97 }
98
99 const TList *rules = p->GetRules();
100 if (rules->GetSize()==0)
101 {
102 *fLog << err << dbginf << "No Entries in MHCompProb::fRules... aborting." << endl;
103 return kFALSE;
104 }
105
106 if (fHistVar->GetSize() != rules->GetSize())
107 {
108 *fLog << err << dbginf << "Number of rules doesn't match number of var.bin histograms.. aborting." << endl;
109 return kFALSE;
110 }
111
112 TIter Next(rules);
113 TObject *data=NULL;
114 while ((data=Next()))
115 {
116 MDataChain *chain = new MDataChain(data->GetName());
117 if (!chain->PreProcess(plist))
118 {
119 delete chain;
120 return kFALSE;
121 }
122 fData->Add(chain);
123 }
124
125 fHadronness = (MHadronness*)plist->FindCreateObj("MHadronness");
126 if (!fHadronness)
127 return kFALSE;
128
129 return kTRUE;
130}
131
132// --------------------------------------------------------------------------
133//
134// Calculate the hadroness (composite propability)
135// - For each data member search the bin corresponding to the data value.
136// - The value describes with which probability this value corresponds to
137// a hadron
138// - For all data members multiply the probabilities.
139// - For normalization take the n-th root of the result.
140// - This is the hadroness stored in the MHadronness container
141//
142Int_t MCompProbCalc::Process()
143{
144 Double_t p = 1;
145
146 TIter NextH(fHistVar);
147 TIter NextD(fData);
148
149 TH1D *hist=NULL;
150
151 Int_t n = 0;
152
153 while ((hist=(TH1D*)NextH()))
154 {
155 MData *data = (MData*)NextD();
156
157 Int_t ibin = hist->FindBin(data->GetValue());
158
159 p *= hist->GetBinContent(ibin) / hist->GetEntries();
160 n++;
161 }
162
163 fHadronness->SetHadronness(pow(p, 1./n));
164 return kTRUE;
165}
166
Note: See TracBrowser for help on using the repository browser.