source: trunk/MagicSoft/Mars/mtemp/mifae/library/MGainFluctuationCam.cc@ 9463

Last change on this file since 9463 was 6192, checked in by blanch, 20 years ago
*** empty log message ***
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): Oscar Blanch 1/2005 <mailto:blanch@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MGainFluctuationCam
28//
29/////////////////////////////////////////////////////////////////////////////
30#include "MGainFluctuationCam.h"
31
32#include <math.h>
33#include <limits.h>
34#include <fstream>
35
36#include <TArrayD.h>
37#include <TCanvas.h>
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42#include "MGeomCam.h"
43#include "MGeomPix.h"
44
45ClassImp(MGainFluctuationCam);
46ClassImp(MGainFluctuationCamIter);
47
48using namespace std;
49
50// --------------------------------------------------------------------------
51//
52// Creates a MGainFluctuationPix object for each pixel in the event
53//
54MGainFluctuationCam::MGainFluctuationCam(const char *name, const char *title) : fNumPixels(0)
55{
56 fName = name ? name : "MGainFluctuationCam";
57 fTitle = title ? title : "(Gain Fluctuation)-Event Information";
58
59 fPixels = new TClonesArray("MGainFluctuationPix", 0);
60}
61
62
63// --------------------------------------------------------------------------
64//
65// reset counter and delete netries in list.
66//
67void MGainFluctuationCam::Reset()
68{
69 fNumPixels = 0;
70 fMaxIndex = -1;
71 fLut.Set(0);
72 // fPixels->Delete();
73}
74
75void MGainFluctuationCam::FixSize()
76{
77 fLut.Set(fMaxIndex+1);
78
79 if (fPixels->GetEntriesFast() == (Int_t)fNumPixels)
80 return;
81
82 fPixels->ExpandCreateFast(fNumPixels);
83}
84
85// --------------------------------------------------------------------------
86//
87// Dump the gain fluctuation event to *fLog
88//
89void MGainFluctuationCam::Print(Option_t *) const
90{
91 const Int_t entries = fPixels->GetEntries();
92
93 *fLog << GetDescriptor() << dec << endl;
94 *fLog << " Number of Pixels: " << fNumPixels << "(" << entries << ")" << endl;
95
96 for (Int_t i=0; i<entries; i++ )
97 (*this)[i].Print();
98}
99
100Float_t MGainFluctuationCam::GetGain(int i) const
101{
102 const MGainFluctuationPix &pix = (*this)[i];
103
104 return pix.GetGain();
105}
106
107// --------------------------------------------------------------------------
108//
109// get the minimum number of photons of all valid pixels in the list
110// If you specify a geometry the number of photons is weighted with the
111// area of the pixel
112//
113Float_t MGainFluctuationCam::GetGainMin(const MGeomCam *geom) const
114{
115 if (fNumPixels <= 0)
116 return -5.;
117
118 const UInt_t n = geom->GetNumPixels();
119
120 Float_t minval = FLT_MAX;
121
122 for (UInt_t i=0; i<fNumPixels; i++)
123 {
124 const MGainFluctuationPix &pix = (*this)[i];
125
126 const UInt_t id = pix.GetPixId();
127 if (id<0 || id>=n)
128 continue;
129
130 Float_t testval = pix.GetGain();
131
132 if (testval < minval)
133 minval = testval;
134 }
135
136 return minval;
137}
138
139// --------------------------------------------------------------------------
140//
141// get the maximum number of photons of all valid pixels in the list
142// If you specify a geometry the number of photons is weighted with the
143// area of the pixel
144//
145Float_t MGainFluctuationCam::GetGainMax(const MGeomCam *geom) const
146{
147 if (fNumPixels <= 0)
148 return 50.;
149
150 const UInt_t n = geom->GetNumPixels();
151
152 Float_t maxval = -FLT_MAX;
153
154 for (UInt_t i=0; i<fNumPixels; i++)
155 {
156 const MGainFluctuationPix &pix = (*this)[i];
157
158 const UInt_t id = pix.GetPixId();
159 if (id<0 || id>=n)
160 continue;
161
162 Float_t testval = pix.GetGain();
163
164 if (testval > maxval)
165 maxval = testval;
166 }
167 return maxval;
168}
169
170
171// --------------------------------------------------------------------------
172//
173// Return a pointer to the pixel with the requested idx. NULL if it doesn't
174// exist. The Look-up-table fLut is used. If its size is zero (according
175// to Rene this will happen if an old class object is loaded) we still
176// try to search in the array.
177//
178MGainFluctuationPix *MGainFluctuationCam::GetPixById(Int_t idx) const
179{
180 if (idx<0)
181 return 0;
182
183 if (fLut.GetSize()>0)
184 {
185 if (idx>=fLut.GetSize())
186 return 0;
187 return fLut[idx]<0 ? 0 : (MGainFluctuationPix*)(fPixels->UncheckedAt(fLut[idx]));
188 }
189
190 TIter Next(fPixels);
191 MGainFluctuationPix *pix = NULL;
192
193 while ((pix=(MGainFluctuationPix*)Next()))
194 if (pix->GetPixId()==idx)
195 return pix;
196
197 return NULL;
198}
199
200MGainFluctuationPix *MGainFluctuationCam::AddPixel(Int_t idx, Float_t gain)
201 {
202 //
203 // If this is too slow or takes to much space we might use
204 // MGeomApply and an InitSize member function instead.
205 //
206 if (idx>=fLut.GetSize())
207 {
208 const Int_t n = fLut.GetSize();
209 fLut.Set(idx*2+1); //idx+1 is slower than idx*2+1
210 for (int i=n; i<idx*2+1; i++)
211 fLut[i] = -1;
212 }
213
214 fLut[idx] = fNumPixels;
215 if (idx>fMaxIndex)
216 fMaxIndex=idx;
217
218 return new ((*fPixels)[fNumPixels++]) MGainFluctuationPix(idx, gain);
219 }
220
221// --------------------------------------------------------------------------
222//
223// Returns, depending on the type flag:
224//
225// 0: Number of Photons*PixRatio
226// 1: Error*sqrt(PixRatio)
227// 2: Cleaning level = Num Photons*sqrt(PixRatio)/Error
228// 3: Number of Photons
229// 4: Error
230// 5: Island index
231//
232Bool_t MGainFluctuationCam::GetPixelContent(Double_t &val, Int_t idx,const MGeomCam&, Int_t type) const
233{
234 MGainFluctuationPix *pix = GetPixById(idx);
235
236 switch (type)
237 {
238 case 1:
239 val = pix->GetGain();
240 return kTRUE;
241 }
242 return kTRUE;
243}
244
245void MGainFluctuationCam::DrawPixelContent(Int_t num) const
246{
247 *fLog << warn << "MGainFluctuationCam::DrawPixelContent - not available." << endl;
248}
249
250TObject *MGainFluctuationCamIter::Next()
251{
252 if (!fUsedOnly)
253 return TObjArrayIter::Next();
254
255 MGainFluctuationPix *pix;
256 while ((pix = (MGainFluctuationPix*)TObjArrayIter::Next()))
257 return pix;
258 return pix;
259}
Note: See TracBrowser for help on using the repository browser.