source: trunk/MagicSoft/Mars/mhist/MHCompProb.cc@ 2041

Last change on this file since 2041 was 1992, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 5.9 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): Abelardo Moralejo <mailto:moralejo@pd.infn.it>
19! Author(s): Thomas Bretz, 5/2002 <mailto:moralejo@pd.infn.it>
20!
21! Copyright: MAGIC Software Development, 2000-2002
22!
23!
24\* ======================================================================== */
25
26///////////////////////////////////////////////////////////////////////
27//
28// MHCompProb
29//
30// This class contains different histograms of the Hillas parameters
31// and composite probabilities based on them.
32//
33///////////////////////////////////////////////////////////////////////
34
35#include "MHCompProb.h"
36
37#include <TH2.h>
38#include <TPad.h>
39#include <TText.h>
40#include <TStyle.h>
41#include <TCanvas.h>
42#include <TProfile.h>
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MParList.h"
48#include "MBinning.h"
49#include "MDataChain.h"
50
51#include "MMcEvt.hxx"
52
53ClassImp(MHCompProb);
54
55// --------------------------------------------------------------------------
56//
57// Setup histograms
58//
59MHCompProb::MHCompProb(Int_t nbins, const char *name, const char *title)
60 : fNumLoop(0)
61{
62 //
63 // set the name and title of this object
64 //
65 fName = name ? name : "MHCompProb";
66 fTitle = title ? title : "Gamma/Hadron Separation Quality Histograms";
67
68 fData = new TList;
69 fRules = new TList;
70 fHists = new TList;
71 fHistVar = new TList;
72
73 fData->SetOwner();
74 fRules->SetOwner();
75 fHists->SetOwner();
76 fHistVar->SetOwner();
77}
78
79// --------------------------------------------------------------------------
80//
81// Delete the histograms
82//
83MHCompProb::~MHCompProb()
84{
85 delete fData;
86 delete fRules;
87 delete fHists;
88 delete fHistVar;
89}
90
91// --------------------------------------------------------------------------
92//
93//
94//
95void MHCompProb::Add(const char *rule, Int_t n, Float_t min, Float_t max)
96{
97 MDataChain &chain = *new MDataChain(rule);
98 fData->Add(&chain);
99
100 TNamed &name = *new TNamed(rule, "");
101 fRules->Add(&name);
102
103 TH1D &hist = *new TH1D(Form("Hist_%s", rule), rule, n, min, max);
104 hist.SetXTitle(rule);
105 hist.SetYTitle("Counts");
106 hist.SetDirectory(NULL);
107 fHists->Add(&hist);
108
109 TH1D &varhist = *new TH1D;
110 varhist.SetName(Form("Var_%s", rule));
111 varhist.SetTitle(rule);
112 varhist.SetXTitle(rule);
113 varhist.SetYTitle("Counts");
114 varhist.SetDirectory(NULL);
115 fHistVar->Add(&varhist);
116}
117
118// --------------------------------------------------------------------------
119//
120//
121//
122Bool_t MHCompProb::SetupFill(const MParList *plist)
123{
124 if (fData->GetSize()==0)
125 {
126 *fLog << err << "No data members spcified for usage... aborting." << endl;
127 return kFALSE;
128 }
129
130 TIter Next(fData);
131 MData *data=NULL;
132 while ((data=(MData*)Next()))
133 if (!data->PreProcess(plist))
134 return kFALSE;
135
136 return kTRUE;
137}
138
139// --------------------------------------------------------------------------
140//
141//
142//
143void MHCompProb::Fill(TList &list)
144{
145 MData *data = NULL;
146
147 TIter NextD(fData);
148 TIter NextH(&list);
149
150 while ((data=(MData*)NextD()))
151 {
152 TH1D *hist = (TH1D*)NextH();
153 hist->Fill(data->GetValue());
154 }
155}
156
157// --------------------------------------------------------------------------
158//
159//
160//
161Bool_t MHCompProb::Fill(const MParContainer *par, Double_t w)
162{
163 const MMcEvt &mcevt = *(MMcEvt*)par;
164
165 switch (fNumLoop)
166 {
167 case 0: // First loop : fill the fixed-bin histograms with gammas.
168 if (mcevt.GetPartId() == kGAMMA)
169 Fill(*fHists);
170 return kTRUE;
171
172 case 1: // Second Loop: fill the variable-bin histograms with protons.
173 if (mcevt.GetPartId() != kGAMMA)
174 Fill(*fHistVar);
175 return kTRUE;
176 default:
177 *fLog << err << "Error - Invalid Loop Number... aborting." << endl;
178 return kFALSE;
179 }
180}
181
182// --------------------------------------------------------------------------
183//
184//
185//
186Bool_t MHCompProb::Finalize()
187{
188 switch (fNumLoop++)
189 {
190 case 0:
191 *fLog << inf << "Finished filling fixed bin size histograms with gamma-data." << endl;
192 SetBinningHistVar();
193 fHists->Delete();
194 return kTRUE;
195 case 1:
196 *fLog << inf << "Finished filling variable bin size histogram with proton data." << endl;
197 return kTRUE;
198 default:
199 *fLog << err << "Error - Invalid Loop Number... aborting." << endl;
200 return kFALSE;
201 }
202}
203
204// --------------------------------------------------------------------------
205//
206//
207//
208void MHCompProb::SetBinningHistVar()
209{
210 Int_t nedges = 51; // Number of bins in variable-bin histograms.
211
212 TIter NextH(fHists);
213 TIter NextV(fHistVar);
214 TH1D *hist = NULL;
215 while ((hist=(TH1D*)NextH()))
216 {
217 Int_t n = hist->GetNbinsX();
218
219 TArrayD edges(nedges);
220
221 edges[0] = hist->GetBinLowEdge(1);
222 edges[nedges-1] = hist->GetBinLowEdge(n+1);
223
224 Float_t newwidth = hist->Integral(1, n)/nedges;
225
226 Int_t jbin = 1;
227 for (Int_t j=1; j<n && jbin<nedges-1; j++)
228 {
229 if (hist->Integral(1, j) <= jbin*newwidth)
230 continue;
231
232 edges[jbin++] = hist->GetBinLowEdge(j+1);
233 }
234
235 MBinning bins;
236 bins.SetEdges(edges);
237
238 SetBinning((TH1D*)NextV(), &bins);
239 }
240}
241
Note: See TracBrowser for help on using the repository browser.