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

Last change on this file since 2777 was 2516, checked in by moralejo, 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 TString str = AddSerialNumber("MMcEvt");
93 str += " not found... aborting.";
94 *fLog << err << dbginf << str << endl;
95 return kFALSE;
96 }
97
98 fRanForest = (MRanForest*)plist->FindObject("MRanForest");
99 if (!fRanForest)
100 {
101 *fLog << err << dbginf << "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//
113Bool_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()==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//
141Bool_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//
172void 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}
Note: See TracBrowser for help on using the repository browser.