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

Last change on this file since 1750 was 1574, checked in by tbretz, 22 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
49// --------------------------------------------------------------------------
50//
51// Default constructor
52//
53MCompProbCalc::MCompProbCalc(const char *name, const char *title)
54{
55 //
56 // set the name and title of this object
57 //
58 fName = name ? name : "MCompProbCalc";
59 fTitle = title ? title : "Composite Probabilities Loop 1/2";
60
61 fData = new TList;
62 fData->SetOwner();
63}
64
65// --------------------------------------------------------------------------
66//
67// Destructor
68//
69MCompProbCalc::~MCompProbCalc()
70{
71 delete fData;
72}
73
74// --------------------------------------------------------------------------
75//
76// Needs:
77// - MHCompProb
78// - all data values which were used to build the MHCompProb
79// - MHadronness
80//
81Bool_t MCompProbCalc::PreProcess(MParList *plist)
82{
83 MHCompProb *p = (MHCompProb*)plist->FindObject("MHCompProb");
84 if (!p)
85 {
86 *fLog << err << dbginf << "MHCompProb not found... aborting." << endl;
87 return kFALSE;
88 }
89
90 fHistVar = p->GetHistVar();
91 if (fHistVar->GetSize()==0)
92 {
93 *fLog << err << dbginf << "No Entries in MHCompProb::fHistVar... aborting." << endl;
94 return kFALSE;
95 }
96
97 const TList *rules = p->GetRules();
98 if (rules->GetSize()==0)
99 {
100 *fLog << err << dbginf << "No Entries in MHCompProb::fRules... aborting." << endl;
101 return kFALSE;
102 }
103
104 if (fHistVar->GetSize() != rules->GetSize())
105 {
106 *fLog << err << dbginf << "Number of rules doesn't match number of var.bin histograms.. aborting." << endl;
107 return kFALSE;
108 }
109
110 TIter Next(rules);
111 TObject *data=NULL;
112 while ((data=Next()))
113 {
114 MDataChain *chain = new MDataChain(data->GetName());
115 if (!chain->PreProcess(plist))
116 {
117 delete chain;
118 return kFALSE;
119 }
120 fData->Add(chain);
121 }
122
123 fHadronness = (MHadronness*)plist->FindCreateObj("MHadronness");
124 if (!fHadronness)
125 return kFALSE;
126
127 return kTRUE;
128}
129
130// --------------------------------------------------------------------------
131//
132// Calculate the hadroness (composite propability)
133// - For each data member search the bin corresponding to the data value.
134// - The value describes with which probability this value corresponds to
135// a hadron
136// - For all data members multiply the probabilities.
137// - For normalization take the n-th root of the result.
138// - This is the hadroness stored in the MHadronness container
139//
140Bool_t MCompProbCalc::Process()
141{
142 Double_t p = 1;
143
144 TIter NextH(fHistVar);
145 TIter NextD(fData);
146
147 TH1D *hist=NULL;
148
149 Int_t n = 0;
150
151 while ((hist=(TH1D*)NextH()))
152 {
153 MData *data = (MData*)NextD();
154
155 Int_t ibin = hist->FindBin(data->GetValue());
156
157 p *= hist->GetBinContent(ibin) / hist->GetEntries();
158 n++;
159 }
160
161 fHadronness->SetHadronness(pow(p, 1./n));
162 return kTRUE;
163}
164
Note: See TracBrowser for help on using the repository browser.