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 Hengstebeck 3/2003 <mailto:hengsteb@alwa02.physik.uni-siegen.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2003
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MHRanForest
|
---|
28 | //
|
---|
29 | // This histogram shows the evolution of the standard deviation
|
---|
30 | // of est. hadronness as the number of trees increases.
|
---|
31 | // It helps you to find out how many trees are really needed in g/h-sep.
|
---|
32 | //
|
---|
33 | ////////////////////////////////////////////////////////////////////////////
|
---|
34 | #include "MHRanForest.h"
|
---|
35 |
|
---|
36 | #include <TH1.h>
|
---|
37 | #include <TPad.h>
|
---|
38 | #include <TMath.h>
|
---|
39 | #include <TGraph.h>
|
---|
40 | #include <TStyle.h>
|
---|
41 | #include <TCanvas.h>
|
---|
42 | #include <TMarker.h>
|
---|
43 |
|
---|
44 | #include "MParList.h"
|
---|
45 | #include "MBinning.h"
|
---|
46 | #include "MRanForest.h"
|
---|
47 |
|
---|
48 | #include "MLog.h"
|
---|
49 | #include "MLogManip.h"
|
---|
50 |
|
---|
51 | #include "MMcEvt.hxx"
|
---|
52 |
|
---|
53 | ClassImp(MHRanForest);
|
---|
54 |
|
---|
55 | using namespace std;
|
---|
56 |
|
---|
57 | // --------------------------------------------------------------------------
|
---|
58 | //
|
---|
59 | // Setup histograms, nbins is the number of bins used for the evaluation.
|
---|
60 | // The default is 100 bins.
|
---|
61 | //
|
---|
62 | MHRanForest::MHRanForest(Int_t nbins, const char *name, const char *title)
|
---|
63 | {
|
---|
64 | //
|
---|
65 | // set the name and title of this object
|
---|
66 | //
|
---|
67 | fName = name ? name : "MHRanForest";
|
---|
68 | fTitle = title ? title : "Histogram showing Standard deviation of estimated hadronness";
|
---|
69 |
|
---|
70 | fGraphSigma = new TGraph;
|
---|
71 | fGraphSigma->SetTitle("Evolution of Standard deviation of estimated hadronness in tree combination");
|
---|
72 | fGraphSigma->SetMarkerStyle(kFullDotSmall);
|
---|
73 | }
|
---|
74 |
|
---|
75 | // --------------------------------------------------------------------------
|
---|
76 | //
|
---|
77 | // Delete the histograms.
|
---|
78 | //
|
---|
79 | MHRanForest::~MHRanForest()
|
---|
80 | {
|
---|
81 | delete fGraphSigma;
|
---|
82 | }
|
---|
83 |
|
---|
84 | // --------------------------------------------------------------------------
|
---|
85 | //
|
---|
86 | // Setup Filling of the histograms. It needs:
|
---|
87 | // MMcEvt and MRanForest
|
---|
88 | //
|
---|
89 | Bool_t MHRanForest::SetupFill(const MParList *plist)
|
---|
90 | {
|
---|
91 | fMcEvt = (MMcEvt*)plist->FindObject(AddSerialNumber("MMcEvt"));
|
---|
92 | if (!fMcEvt)
|
---|
93 | {
|
---|
94 | *fLog << err << AddSerialNumber("MMcEvt") << " not found... aborting." << endl;
|
---|
95 | return kFALSE;
|
---|
96 | }
|
---|
97 |
|
---|
98 | fRanForest = (MRanForest*)plist->FindObject("MRanForest");
|
---|
99 | if (!fRanForest)
|
---|
100 | {
|
---|
101 | *fLog << err << "MRanForest not found... aborting." << endl;
|
---|
102 | return kFALSE;
|
---|
103 | }
|
---|
104 |
|
---|
105 | fSigma.Set(fRanForest->GetNumTrees());
|
---|
106 | fNumEvent=0;
|
---|
107 | return kTRUE;
|
---|
108 | }
|
---|
109 |
|
---|
110 | // --------------------------------------------------------------------------
|
---|
111 | //
|
---|
112 | //
|
---|
113 | Int_t MHRanForest::Fill(const MParContainer *par, const Stat_t w)
|
---|
114 | {
|
---|
115 | fNumEvent++;
|
---|
116 |
|
---|
117 | Double_t hest=0;
|
---|
118 | Double_t htrue=fMcEvt->GetPartId()==MMcEvt::kGAMMA ? 0. : 1.;
|
---|
119 |
|
---|
120 | Int_t ntrees=fRanForest->GetNumTrees();
|
---|
121 |
|
---|
122 | for (Int_t i=0;i<ntrees;i++)
|
---|
123 | {
|
---|
124 | for(Int_t j=0;j<=i;j++)
|
---|
125 | hest+=fRanForest->GetTreeHad(j);
|
---|
126 |
|
---|
127 | hest/=i+1;
|
---|
128 |
|
---|
129 | const Double_t val = htrue-hest;
|
---|
130 | fSigma[i] += val*val;
|
---|
131 | }
|
---|
132 |
|
---|
133 | return kTRUE;
|
---|
134 | }
|
---|
135 |
|
---|
136 | // --------------------------------------------------------------------------
|
---|
137 | //
|
---|
138 | // Finalize the histogram:
|
---|
139 | // calculate standard deviation and set histogram max and min
|
---|
140 | //
|
---|
141 | Bool_t MHRanForest::Finalize()
|
---|
142 | {
|
---|
143 | Int_t n = fSigma.GetSize();
|
---|
144 |
|
---|
145 | fGraphSigma->Set(n);
|
---|
146 |
|
---|
147 | Stat_t max=0.;
|
---|
148 | Stat_t min=0.;
|
---|
149 | for (Int_t i=0; i<n; i++)
|
---|
150 | {
|
---|
151 | fSigma[i] = TMath::Sqrt(fSigma[i]/fNumEvent);
|
---|
152 |
|
---|
153 | const Stat_t ig = fSigma[i];
|
---|
154 | if (ig>max) max = ig;
|
---|
155 | if (ig<min) min = ig;
|
---|
156 | fGraphSigma->SetPoint(i, i+1, ig);
|
---|
157 | }
|
---|
158 |
|
---|
159 | // This is used in root>3.04/? so that SetMaximum/Minimum can succeed
|
---|
160 | fGraphSigma->GetHistogram();
|
---|
161 |
|
---|
162 | fGraphSigma->SetMaximum(1.05*max);
|
---|
163 | fGraphSigma->SetMinimum(0.95*min);
|
---|
164 |
|
---|
165 | return kTRUE;
|
---|
166 | }
|
---|
167 |
|
---|
168 | // --------------------------------------------------------------------------
|
---|
169 | //
|
---|
170 | // Draw histogram. (For the Meaning see class description)
|
---|
171 | //
|
---|
172 | void MHRanForest::Draw(Option_t *)
|
---|
173 | {
|
---|
174 | if (fGraphSigma->GetN()==0)
|
---|
175 | return;
|
---|
176 |
|
---|
177 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
|
---|
178 | pad->SetBorderMode(0);
|
---|
179 |
|
---|
180 | AppendPad("");
|
---|
181 |
|
---|
182 | fGraphSigma->Draw("ALP");
|
---|
183 | pad->Modified();
|
---|
184 | pad->Update();
|
---|
185 |
|
---|
186 | TH1 *h=fGraphSigma->GetHistogram();
|
---|
187 | if (!h)
|
---|
188 | return;
|
---|
189 |
|
---|
190 | //h->GetXaxis()->SetRangeUser(0, fNumEvent+1);
|
---|
191 | h->SetXTitle("No.of Trees");
|
---|
192 | h->SetYTitle("\\sigma of est.hadronness");
|
---|
193 |
|
---|
194 | pad->Modified();
|
---|
195 | pad->Update();
|
---|
196 | }
|
---|