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