source: trunk/Mars/mpedestal/MHPedestalCor.cc@ 19945

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