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

Last change on this file since 2173 was 2173, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.8 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->SetMaximum(1);
71 fGraphSigma->SetMarkerStyle(kFullDotSmall);
72}
73
74// --------------------------------------------------------------------------
75//
76// Delete the histograms.
77//
78MHRanForest::~MHRanForest()
79{
80 delete fGraphSigma;
81}
82
83// --------------------------------------------------------------------------
84//
85// Setup Filling of the histograms. It needs:
86// MMcEvt and MRanForest
87//
88Bool_t MHRanForest::SetupFill(const MParList *plist)
89{
90 fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
91 if (!fMcEvt)
92 {
93 *fLog << err << dbginf << "MMcEvt not found... aborting." << endl;
94 return kFALSE;
95 }
96
97 fRanForest = (MRanForest*)plist->FindObject("MRanForest");
98 if (!fRanForest)
99 {
100 *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
101 return kFALSE;
102 }
103
104 fSigma.Set(fRanForest->GetNumTrees());
105 fNumEvent=0;
106 return kTRUE;
107}
108
109// --------------------------------------------------------------------------
110//
111//
112Bool_t MHRanForest::Fill(const MParContainer *par, const Stat_t w)
113{
114 fNumEvent++;
115 Double_t hest=0;
116 Double_t htrue=fMcEvt->GetPartId()==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 fSigma[i]+=(htrue-hest)*(htrue-hest);
127 }
128
129 return kTRUE;
130}
131
132// --------------------------------------------------------------------------
133//
134// Finalize the histogram:
135// calculate standard deviation and set histogram max and min
136//
137Bool_t MHRanForest::Finalize()
138{
139 Int_t n = fSigma.GetSize();
140
141 fGraphSigma->Set(n);
142
143 Stat_t max=0.;
144 Stat_t min=0.;
145 for (Int_t i=0; i<n; i++)
146 {
147 Stat_t ip = i+1.;
148 fSigma[i] = TMath::Sqrt(fSigma[i]/Stat_t(fNumEvent));
149 Stat_t ig = fSigma[i];
150 max=TMath::Max(max,ig);
151 min=TMath::Min(min,ig);
152 fGraphSigma->SetPoint(i,ip,ig);
153 }
154 fGraphSigma->SetMaximum(1.05*max);
155 fGraphSigma->SetMinimum(0.95*min);
156
157 return kTRUE;
158}
159
160// --------------------------------------------------------------------------
161//
162// Draw histogram. (For the Meaning see class description)
163//
164void MHRanForest::Draw(Option_t *)
165{
166 if (fGraphSigma->GetN()==0)
167 return;
168
169 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
170 pad->SetBorderMode(0);
171
172 AppendPad("");
173
174 fGraphSigma->Draw("ALP");
175 pad->Modified();
176 pad->Update();
177
178 TH1 *h=fGraphSigma->GetHistogram();
179 if (!h)
180 return;
181
182 h->GetXaxis()->SetRangeUser(0, 1);
183 h->SetXTitle("No.of Trees");
184 h->SetYTitle("\\sigma of est.hadronness");
185
186 pad->Modified();
187 pad->Update();
188}
Note: See TracBrowser for help on using the repository browser.