source: trunk/MagicSoft/Mars/mranforest/MHRanForest.cc@ 6724

Last change on this file since 6724 was 3325, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 5.0 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): 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
51ClassImp(MHRanForest);
52
53using namespace std;
54
55// --------------------------------------------------------------------------
56//
57// Setup histograms, nbins is the number of bins used for the evaluation.
58// The default is 100 bins.
59//
60MHRanForest::MHRanForest(Int_t nbins, const char *name, const char *title)
61{
62 //
63 // set the name and title of this object
64 //
65 fName = name ? name : "MHRanForest";
66 fTitle = title ? title : "Histogram showing Standard deviation of estimated hadronness";
67
68 fGraphSigma = new TGraph;
69 fGraphSigma->SetTitle("Evolution of Standard deviation of estimated hadronness in tree combination");
70 fGraphSigma->SetMarkerStyle(kFullDotSmall);
71}
72
73// --------------------------------------------------------------------------
74//
75// Delete the histograms.
76//
77MHRanForest::~MHRanForest()
78{
79 delete fGraphSigma;
80}
81
82// --------------------------------------------------------------------------
83//
84// Setup Filling of the histograms. It needs:
85// MMcEvt and MRanForest
86//
87Bool_t MHRanForest::SetupFill(const MParList *plist)
88{
89 fMcEvt = (MMcEvt*)plist->FindObject(AddSerialNumber("MMcEvt"));
90 if (!fMcEvt)
91 {
92 *fLog << err << AddSerialNumber("MMcEvt") << " not found... aborting." << endl;
93 return kFALSE;
94 }
95
96 fRanForest = (MRanForest*)plist->FindObject("MRanForest");
97 if (!fRanForest)
98 {
99 *fLog << err << "MRanForest not found... aborting." << endl;
100 return kFALSE;
101 }
102
103 fSigma.Set(fRanForest->GetNumTrees());
104 fNumEvent=0;
105 return kTRUE;
106}
107
108// --------------------------------------------------------------------------
109//
110//
111Bool_t MHRanForest::Fill(const MParContainer *par, const Stat_t w)
112{
113 fNumEvent++;
114
115 Double_t hest=0;
116 Double_t htrue=fMcEvt->GetPartId()==MMcEvt::kGAMMA ? 0. : 1.;
117
118 Int_t ntrees=fRanForest->GetNumTrees();
119
120 for (Int_t i=0;i<ntrees;i++)
121 {
122 for(Int_t j=0;j<=i;j++)
123 hest+=fRanForest->GetTreeHad(j);
124
125 hest/=i+1;
126
127 const Double_t val = htrue-hest;
128 fSigma[i] += val*val;
129 }
130
131 return kTRUE;
132}
133
134// --------------------------------------------------------------------------
135//
136// Finalize the histogram:
137// calculate standard deviation and set histogram max and min
138//
139Bool_t MHRanForest::Finalize()
140{
141 Int_t n = fSigma.GetSize();
142
143 fGraphSigma->Set(n);
144
145 Stat_t max=0.;
146 Stat_t min=0.;
147 for (Int_t i=0; i<n; i++)
148 {
149 fSigma[i] = TMath::Sqrt(fSigma[i]/fNumEvent);
150
151 const Stat_t ig = fSigma[i];
152 if (ig>max) max = ig;
153 if (ig<min) min = ig;
154 fGraphSigma->SetPoint(i, i+1, ig);
155 }
156
157 // This is used in root>3.04/? so that SetMaximum/Minimum can succeed
158 fGraphSigma->GetHistogram();
159
160 fGraphSigma->SetMaximum(1.05*max);
161 fGraphSigma->SetMinimum(0.95*min);
162
163 return kTRUE;
164}
165
166// --------------------------------------------------------------------------
167//
168// Draw histogram. (For the Meaning see class description)
169//
170void MHRanForest::Draw(Option_t *)
171{
172 if (fGraphSigma->GetN()==0)
173 return;
174
175 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
176 pad->SetBorderMode(0);
177
178 AppendPad("");
179
180 fGraphSigma->Draw("ALP");
181 pad->Modified();
182 pad->Update();
183
184 TH1 *h=fGraphSigma->GetHistogram();
185 if (!h)
186 return;
187
188 //h->GetXaxis()->SetRangeUser(0, fNumEvent+1);
189 h->SetXTitle("No.of Trees");
190 h->SetYTitle("\\sigma of est.hadronness");
191
192 pad->Modified();
193 pad->Update();
194}
Note: See TracBrowser for help on using the repository browser.