source: trunk/Mars/mbadpixels/MHBadPixels.cc@ 11270

Last change on this file since 11270 was 9851, checked in by tbretz, 14 years ago
Changed MH::SetBinning and similar functions to take references instead of pointers as arguments. For convenience wrappers for the old style functions are provided.
File size: 6.6 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 04/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHBadPixels
28//
29////////////////////////////////////////////////////////////////////////////
30#include "MHBadPixels.h"
31
32#include <TCanvas.h>
33
34#include "MPointingPos.h"
35#include "MBadPixelsCam.h"
36#include "MGeomCam.h"
37#include "MPedPhotCam.h"
38#include "MParList.h"
39#include "MBinning.h"
40
41#include "MLog.h"
42#include "MLogManip.h"
43
44ClassImp(MHBadPixels);
45
46using namespace std;
47
48// -------------------------------------------------------------------------
49//
50// Constructor.
51//
52MHBadPixels::MHBadPixels(const char *name, const char *title)
53{
54 fName = name ? name : "MHBadPixels";
55 fTitle = title ? title : "Histogram for Bad Pixels vs. Theta";
56
57 fBadId = new TH2D;
58 fBadId->SetName("2D-IdBadPixels");
59 fBadId->SetTitle("2D-IdBadPixels");
60 fBadId->SetDirectory(NULL);
61 fBadId->UseCurrentStyle();
62 fBadId->SetXTitle("\\Theta [\\circ]");
63 fBadId->SetYTitle("pixel Id");
64 fBadId->SetTitleOffset(1.2, "Y");
65
66 fBadN = new TH2D;
67 fBadN->SetName("2D-NBadPixels");
68 fBadN->SetTitle("2D-NBadPixels");
69 fBadN->SetDirectory(NULL);
70 fBadN->UseCurrentStyle();
71 fBadN->SetXTitle("\\Theta [\\circ]");
72 fBadN->SetYTitle("number of bad pixels");
73 fBadN->SetTitleOffset(1.2, "Y");
74
75 // define default binnings
76 fBinsTheta = new MBinning;
77 fBinsTheta->SetEdgesCos(10, 0.0, 90.0); // theta
78
79 fBinsPix = new MBinning;
80 fBinsPix->SetEdges(578, -0.5, 577.5); // pixel id
81
82 SetBinning(*fBadId, *fBinsTheta, *fBinsPix);
83 SetBinning(*fBadN, *fBinsTheta, *fBinsPix);
84
85 //-----------------------------------------
86 fNamePedPhotCam = "MPedPhotCamFromData";
87}
88
89
90// -------------------------------------------------------------------------
91//
92// Destructor.
93//
94MHBadPixels::~MHBadPixels()
95{
96 delete fBadId;
97 delete fBadN;
98
99 delete fBinsTheta;
100 delete fBinsPix;
101}
102
103// --------------------------------------------------------------------------
104//
105// Set the binnings and prepare the filling of the histogram
106//
107Bool_t MHBadPixels::SetupFill(const MParList *plist)
108{
109 fCam = (MGeomCam*)plist->FindObject(AddSerialNumber("MGeomCam"));
110 if (!fCam)
111 {
112 *fLog << err << "MHBadPixels::SetupFill; MGeomCam not found... aborting." << endl;
113 return kFALSE;
114 }
115 *fLog << "MHBadPixels::SetupFill; fCam = " << fCam << endl;
116
117 fPointPos = (MPointingPos*)plist->FindObject("MPointingPos");
118 if (!fPointPos)
119 {
120 *fLog << err << "MPointingPos not found... aborting." << endl;
121 return kFALSE;
122 }
123
124 fPedPhot = (MPedPhotCam*)plist->FindObject(AddSerialNumber(fNamePedPhotCam), "MPedPhotCam");
125 if (!fPedPhot)
126 {
127 *fLog << err << AddSerialNumber(fNamePedPhotCam)
128 << "[MPedPhotCam] not found... aborting." << endl;
129 return kFALSE;
130 }
131 fPedPhot->InitSize(fCam->GetNumPixels());
132
133
134 //----------------------------------------------------
135 *fLog << inf << "Name of MPedPhotCam container : " << fNamePedPhotCam
136 << endl;
137
138
139 //----------------------------------------------------
140 // redefine the binnings
141
142 // Get Theta Binning
143 const MBinning* binstheta = (MBinning*)plist->FindObject("BinningTheta", "MBinning");
144 if (!binstheta)
145 {
146 *fLog << err << "Object 'BinningTheta' [MBinning] not found... use default binning." << endl;
147 binstheta = fBinsTheta;
148 }
149
150 // Define binning for pixel number
151 const UInt_t npix1 = fPedPhot->GetSize()+1;
152 //*fLog << "MHBadPixels::SetupFill(); npix1 = " << npix1 << endl;
153 const MBinning binspix(npix1, -0.5, npix1-0.5);
154
155 // Set binnings in histograms
156 SetBinning(*fBadId, *binstheta, binspix);
157 SetBinning(*fBadN, *binstheta, binspix);
158
159 *fLog << "MHBadPixels::SetupFill(); binnings were set" << endl;
160
161
162
163 return kTRUE;
164}
165
166// ------------------------------------------------------------------------
167//
168// Fill the histograms
169//
170
171Int_t MHBadPixels::Fill(const MParContainer *par, const Stat_t w)
172{
173 if (!par)
174 {
175 *fLog << err << "ERROR - par==NULL." << endl;
176 return kERROR;
177 }
178
179 const Double_t theta = fPointPos->GetZd();
180
181 const MBadPixelsCam *fBadPixels = (MBadPixelsCam*)par;
182
183 const UInt_t entries = fPedPhot->GetSize();
184 UInt_t nb = 0;
185 for (UInt_t i=0; i<entries; i++)
186 {
187 //*fLog << "MHBadPixels::Fill; i = " << i << endl;
188
189 if ( (*fBadPixels)[i].IsUnsuitable() )
190 {
191 //*fLog << "MHBadPixels::Fill; (UnSuitable) " << endl;
192
193 fBadId->Fill(theta, i, w);
194 nb++;
195 }
196 }
197 fBadN->Fill(theta, nb, w);
198
199 return kTRUE;
200}
201
202// --------------------------------------------------------------------
203//
204// Draw the histograms
205//
206void MHBadPixels::Draw(Option_t *option)
207{
208 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
209 pad->SetBorderMode(0);
210
211 pad->Divide(2,2);
212
213 TH1D *h;
214
215 pad->cd(1);
216 fBadId->Draw(option);
217
218 pad->cd(2);
219 fBadN->Draw(option);
220
221 pad->cd(3);
222 gPad->SetBorderMode(0);
223 h = ((TH2*)fBadId)->ProjectionY("ProjY-pixId", -1, 9999, "");
224 h->SetDirectory(NULL);
225 h->SetTitle("Distribution of bad pixel Id");
226 h->SetXTitle("Id of bad pixel");
227 h->SetYTitle("No. of events");
228 h->SetTitleOffset(1.2, "Y");
229 h->Draw(option);
230 h->SetBit(kCanDelete);
231
232 pad->cd(4);
233 gPad->SetBorderMode(0);
234 h = ((TH2*)fBadN)->ProjectionY("ProjY-pixN", -1, 9999, "");
235 h->SetDirectory(NULL);
236 h->SetTitle("Distribution of no.of bad pixels");
237 h->SetXTitle("No. of bad pixels");
238 h->SetYTitle("No. of events");
239 h->SetTitleOffset(1.2, "Y");
240 h->Draw(option);
241 h->SetBit(kCanDelete);
242
243 pad->Modified();
244 pad->Update();
245}
246//==========================================================================
247
248
249
250
251
252
253
254
255
256
257
Note: See TracBrowser for help on using the repository browser.