source: trunk/MagicSoft/Mars/mpedestal/MHPedestalCor.cc@ 8158

Last change on this file since 8158 was 8152, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 7.2 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MHPedestalCor.cc,v 1.1 2006-10-24 08:09:26 tbretz Exp $
3! --------------------------------------------------------------------------
4!
5! *
6! * This file is part of MARS, the MAGIC Analysis and Reconstruction
7! * Software. It is distributed to you in the hope that it can be a useful
8! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9! * It is distributed WITHOUT ANY WARRANTY.
10! *
11! * Permission to use, copy, modify and distribute this software and its
12! * documentation for any purpose is hereby granted without fee,
13! * provided that the above copyright notice appear in all copies and
14! * that both that copyright notice and this permission notice appear
15! * in supporting documentation. It is provided "as is" without express
16! * or implied warranty.
17! *
18!
19!
20! Author(s): Thomas Bretz, 10/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2006
23!
24!
25\* ======================================================================== */
26
27/////////////////////////////////////////////////////////////////////////////
28//
29// MHPedestalCor
30//
31// A histogram to get the pedestal autocorrelation matrix. Tests have shown
32// the the autocorrelation does not depend on the actual slice so a profile
33// with the autocorrelation depeding on the distance between two slices
34// is filled.
35//
36// Functions to provide the autocorrelation as a TH2D or a TMatrix are
37// provided.
38//
39// Input:
40// - MPedestalSubtractedEvt (from MFillH)
41//
42/////////////////////////////////////////////////////////////////////////////
43#include "MHPedestalCor.h"
44
45#include <TH2.h>
46#include <TCanvas.h>
47
48#include "MLog.h"
49#include "MLogManip.h"
50
51#include "MParList.h"
52#include "MCamEvent.h"
53
54#include "MGeomCam.h"
55
56#include "MBinning.h"
57#include "MPedestalSubtractedEvt.h"
58
59ClassImp(MHPedestalCor);
60
61using namespace std;
62
63const TString MHPedestalCor::gsDefName = "MHPedestalCor";
64const TString MHPedestalCor::gsDefTitle = "Histogram for autocorrelation";
65
66// --------------------------------------------------------------------------
67//
68// Initialize the name and title of the task. Set fType to 0
69//
70MHPedestalCor::MHPedestalCor(const char *name, const char *title)
71{
72 //
73 // set the name and title of this object
74 //
75 fName = name ? name : gsDefName.Data();
76 fTitle = title ? title : gsDefTitle.Data();
77 /*
78 fHist.SetNameTitle("AutoCor", "Autocorrelation of slices");
79 fHist.SetDirectory(0);
80
81 fHist2.SetNameTitle("AutoCorProf", "Autocorrelation from Profile");
82 fHist2.SetDirectory(0);
83
84 fHist3.SetNameTitle("Dev", "Deviation of Profile from plain correlation");
85 fHist3.SetDirectory(0);
86
87 MBinning binsx(61, -30.5, 30.5);
88 MBinning binsy(30, -0.5, 29.5);
89
90 MH::SetBinning(&fHist, &binsy, &binsy);
91 MH::SetBinning(&fHist2, &binsy, &binsy);
92 MH::SetBinning(&fHist3, &binsy, &binsy);
93 */
94 fProf.SetNameTitle("AutoCorP", "Profile of auto correlation");
95 fProf.SetDirectory(0);
96
97 MBinning binsx(15, -0.5, 14.5);
98 MH::SetBinning(&fProf, &binsx);
99}
100
101// --------------------------------------------------------------------------
102//
103// Fill the histograms with data from a MCamEvent-Container.
104//
105Bool_t MHPedestalCor::Fill(const MParContainer *par, const Stat_t w)
106{
107 const MPedestalSubtractedEvt *evt = dynamic_cast<const MPedestalSubtractedEvt*>(par);
108 if (!evt)
109 {
110 *fLog << err << dbginf << "Got no MCamEvent as argument of Fill()..." << endl;
111 return kFALSE;
112 }
113
114 // Implement an extraction range
115 // Implement a check as in PedCalcFromLoGain
116
117 const Int_t np = evt->GetNumPixels();
118 const Int_t ns = evt->GetNumSamples();
119
120 Int_t fCheckWinFirst = 0;
121 Int_t fCheckWinLast = (ns-1)+1;
122
123 Int_t fExtractWinFirst = 17;
124 Int_t fExtractWinLast = (ns-1)+1;
125
126 Float_t fMaxSignalVar = 40;
127
128 for (int k=0; k<np; k++)
129 {
130 // This is the fast workaround to put hi- and lo-gains together
131 Byte_t *slices = evt->GetSamplesRaw(k);//pixel.GetSamples();
132
133 UShort_t max = 0;
134 UShort_t min = (UShort_t)-1;
135
136 // Find the maximum and minimum signal per slice in the high gain window
137 for (Byte_t *slice=slices+fCheckWinFirst; slice<=slices+fCheckWinLast; slice++)
138 {
139 if (*slice > max)
140 max = *slice;
141 if (*slice < min)
142 min = *slice;
143 }
144
145 // If the maximum in the high gain window is smaller than
146 if (max-min>=fMaxSignalVar || max>=250)
147 continue;
148
149 const Float_t *sig = evt->GetSamples(k);
150
151 for (int i=fExtractWinFirst; i<fExtractWinLast; i++)
152 {
153 const Double_t s2 = sig[i]*sig[i];
154 // fHist.Fill(i, i, s2);
155 fProf.Fill(0., s2);
156
157 for (int j=fExtractWinFirst; j<fExtractWinLast; j++)
158 {
159 const Double_t sij = sig[i]*sig[j];
160
161// fHist.Fill(i, j, sij);
162// fHist.Fill(j, i, sij);
163
164 fProf.Fill(i-j, sij);
165// fProf.Fill(j-i, sij);
166 }
167 }
168 }
169
170 return kTRUE;
171}
172
173// --------------------------------------------------------------------------
174//
175// Return the autocorrelation matrix as a TH2D
176//
177void MHPedestalCor::GetAutoCorrelation(TH2 &h) const
178{
179 const Int_t n = fProf.GetNbinsX()*2+1;
180
181 const Axis_t xmax = fProf.GetXaxis()->GetXmax();
182 MBinning bins(n, -xmax, xmax);
183
184 MH::SetBinning(&h, &bins, &bins);
185
186 for (int x=0; x<n; x++)
187 for (int y=0; y<n; y++)
188 h.SetBinContent(x+1, y+1, fProf.GetBinContent(TMath::Abs(x-y)));
189
190}
191
192// --------------------------------------------------------------------------
193//
194// Return the autocorrelation into the TMatrix
195//
196void MHPedestalCor::GetAutoCorrelation(TMatrix &m) const
197{
198 const Int_t n = fProf.GetNbinsX()*2+1;
199 m.ResizeTo(n, n);
200
201 for (int x=0; x<n; x++)
202 for (int y=0; y<n; y++)
203 m[x][y] = fProf.GetBinContent(TMath::Abs(x-y));
204}
205
206/*
207void MHPedestalCor::Paint(Option_t *)
208{
209 MH::SetPalette("pretty");
210
211 for (int x=0; x<fHist.GetNbinsX(); x++)
212 for (int y=0; y<fHist.GetNbinsX(); y++)
213 fHist2.SetBinContent(x+1, y+1, fProf.GetBinContent(fProf.GetXaxis()->FindFixBin(x-y)));
214
215 fHist.Copy(fHist3);
216 fHist3.Add(&fHist2, -(fHist.GetEntries()/30/30));
217 fHist3.Divide(&fHist);
218 fHist3.Scale(100);
219 fHist3.SetMaximum();
220}
221*/
222
223void MHPedestalCor::Draw(Option_t *)
224{
225 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
226 pad->SetBorderMode(0);
227 pad->SetFrameBorderMode(0);
228
229 pad->Divide(2, 2, 0.001, 0.001);
230
231 AppendPad();
232/*
233 pad->cd(1);
234 gPad->SetBorderMode(0);
235 gPad->SetFrameBorderMode(0);
236 gPad->SetGridx();
237 gPad->SetGridy();
238 fHist.Draw("colz");
239
240 pad->cd(2);
241 gPad->SetBorderMode(0);
242 gPad->SetFrameBorderMode(0);
243 gPad->SetGridx();
244 gPad->SetGridy();
245 fHist2.Draw("colz");
246
247 pad->cd(3);
248 gPad->SetBorderMode(0);
249 gPad->SetFrameBorderMode(0);
250 gPad->SetGridx();
251 gPad->SetGridy();
252 fHist3.Draw("colz");
253
254 pad->cd(4);*/
255 gPad->SetBorderMode(0);
256 gPad->SetFrameBorderMode(0);
257 gPad->SetGridx();
258 gPad->SetGridy();
259 fProf.Draw();
260}
Note: See TracBrowser for help on using the repository browser.