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 "MDataPhrase.h"
|
---|
43 |
|
---|
44 | #include "MHCompProb.h"
|
---|
45 | #include "MParameters.h"
|
---|
46 |
|
---|
47 | ClassImp(MCompProbCalc);
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | // --------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // Default constructor
|
---|
54 | //
|
---|
55 | MCompProbCalc::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 | //
|
---|
71 | MCompProbCalc::~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 | //
|
---|
82 | Int_t MCompProbCalc::PreProcess(MParList *plist)
|
---|
83 | {
|
---|
84 | MHCompProb *p = (MHCompProb*)plist->FindObject("MHCompProb");
|
---|
85 | if (!p)
|
---|
86 | {
|
---|
87 | *fLog << err << dbginf << "MHCompProb not found... aborting." << endl;
|
---|
88 | return kFALSE;
|
---|
89 | }
|
---|
90 |
|
---|
91 | fHistVar = p->GetHistVar();
|
---|
92 | if (fHistVar->GetSize()==0)
|
---|
93 | {
|
---|
94 | *fLog << err << dbginf << "No Entries in MHCompProb::fHistVar... aborting." << endl;
|
---|
95 | return kFALSE;
|
---|
96 | }
|
---|
97 |
|
---|
98 | const TList *rules = p->GetRules();
|
---|
99 | if (rules->GetSize()==0)
|
---|
100 | {
|
---|
101 | *fLog << err << dbginf << "No Entries in MHCompProb::fRules... aborting." << endl;
|
---|
102 | return kFALSE;
|
---|
103 | }
|
---|
104 |
|
---|
105 | if (fHistVar->GetSize() != rules->GetSize())
|
---|
106 | {
|
---|
107 | *fLog << err << dbginf << "Number of rules doesn't match number of var.bin histograms.. aborting." << endl;
|
---|
108 | return kFALSE;
|
---|
109 | }
|
---|
110 |
|
---|
111 | TIter Next(rules);
|
---|
112 | TObject *data=NULL;
|
---|
113 | while ((data=Next()))
|
---|
114 | {
|
---|
115 | MDataPhrase *chain = new MDataPhrase(data->GetName());
|
---|
116 | if (!chain->PreProcess(plist))
|
---|
117 | {
|
---|
118 | delete chain;
|
---|
119 | return kFALSE;
|
---|
120 | }
|
---|
121 | fData->Add(chain);
|
---|
122 | }
|
---|
123 |
|
---|
124 | fHadronness = (MParameterD*)plist->FindCreateObj("MParameterD", "MHadronness");
|
---|
125 | if (!fHadronness)
|
---|
126 | return kFALSE;
|
---|
127 |
|
---|
128 | return kTRUE;
|
---|
129 | }
|
---|
130 |
|
---|
131 | // --------------------------------------------------------------------------
|
---|
132 | //
|
---|
133 | // Calculate the hadroness (composite propability)
|
---|
134 | // - For each data member search the bin corresponding to the data value.
|
---|
135 | // - The value describes with which probability this value corresponds to
|
---|
136 | // a hadron
|
---|
137 | // - For all data members multiply the probabilities.
|
---|
138 | // - For normalization take the n-th root of the result.
|
---|
139 | // - This is the hadroness stored in the Hadronness container
|
---|
140 | //
|
---|
141 | Int_t MCompProbCalc::Process()
|
---|
142 | {
|
---|
143 | Double_t p = 1;
|
---|
144 |
|
---|
145 | TIter NextH(fHistVar);
|
---|
146 | TIter NextD(fData);
|
---|
147 |
|
---|
148 | TH1D *hist=NULL;
|
---|
149 |
|
---|
150 | Int_t n = 0;
|
---|
151 |
|
---|
152 | while ((hist=(TH1D*)NextH()))
|
---|
153 | {
|
---|
154 | MData *data = (MData*)NextD();
|
---|
155 |
|
---|
156 | Int_t ibin = hist->FindBin(data->GetValue());
|
---|
157 |
|
---|
158 | p *= hist->GetBinContent(ibin) / hist->GetEntries();
|
---|
159 | n++;
|
---|
160 | }
|
---|
161 |
|
---|
162 | fHadronness->SetVal(pow(p, 1./n));
|
---|
163 | return kTRUE;
|
---|
164 | }
|
---|
165 |
|
---|