source: trunk/MagicSoft/Mars/manalysis/MCerPhotAnal.cc@ 5762

Last change on this file since 5762 was 3389, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.4 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 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MCerPhotAnal //
28// //
29// This is a task which calculates the number of photons from the FADC //
30// time slices. At the moment it integrates simply the FADC values. //
31// //
32// Input Containers: //
33// MRawEvtData, MPedesdtalCam //
34// //
35// Output Containers: //
36// MCerPhotEvt //
37// //
38//////////////////////////////////////////////////////////////////////////////
39
40#include "MCerPhotAnal.h"
41
42#include "MParList.h"
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MRawRunHeader.h"
48#include "MRawEvtData.h" // MRawEvtData::GetNumPixels
49#include "MCerPhotEvt.h"
50#include "MPedestalPix.h"
51#include "MPedestalCam.h"
52#include "MRawEvtPixelIter.h"
53
54ClassImp(MCerPhotAnal);
55
56using namespace std;
57
58// --------------------------------------------------------------------------
59//
60// Default constructor.
61//
62MCerPhotAnal::MCerPhotAnal(const char *name, const char *title)
63{
64 fName = name ? name : "MCerPhotAnal";
65 fTitle = title ? title : "Task to calculate Cerenkov photons from raw data";
66
67 AddToBranchList("MRawEvtData.fHiGainPixId");
68 AddToBranchList("MRawEvtData.fLoGainPixId");
69 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
70 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
71
72}
73
74// --------------------------------------------------------------------------
75//
76// The PreProcess searches for the following input containers:
77// - MRawRunHeader
78// - MRawEvtData
79// - MPedestalCam
80//
81// The following output containers are also searched and created if
82// they were not found:
83// - MCerPhotEvt
84//
85Int_t MCerPhotAnal::PreProcess(MParList *pList)
86{
87 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
88 if (!fRunHeader)
89 {
90 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
91 return kFALSE;
92 }
93
94 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
95 if (!fRawEvt)
96 {
97 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
98 return kFALSE;
99 }
100
101 fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
102 if (!fCerPhotEvt)
103 return kFALSE;
104
105 return kTRUE;
106}
107
108Bool_t MCerPhotAnal::ReInit(MParList *pList)
109{
110 fPedestals = NULL;
111
112 // This must be done in ReInit because in PreProcess the
113 // headers are not available
114 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
115 if (!runheader)
116 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
117 else
118 if (runheader->IsMonteCarloRun())
119 return kTRUE;
120
121 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
122 if (runheader && !fPedestals)
123 return kFALSE;
124
125 return kTRUE;
126}
127
128// --------------------------------------------------------------------------
129//
130// Calculate the integral of the FADC time slices and store them as a new
131// pixel in the MCerPhotEvt container.
132//
133Int_t MCerPhotAnal::Process()
134{
135 //fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
136
137 MRawEvtPixelIter pixel(fRawEvt);
138
139 while (pixel.Next())
140 {
141 Byte_t *ptr = pixel.GetHiGainSamples();
142 const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
143 const Byte_t *limit = end - 5;
144
145 Int_t sum=0;
146 Int_t sumpeak=0;
147 Int_t sumlocal =0;
148 Int_t slice=0;
149 Int_t slicelocal=0;
150
151 do
152 {
153 sumlocal = 0;
154 for (Int_t i = 0; i<5;i++)
155 sumlocal += *(ptr+i);
156
157 if (sumpeak < sumlocal)
158 {
159 slice=slicelocal;
160 sumpeak = sumlocal;
161 }
162
163 slicelocal++;
164 sum += *ptr;
165 } while (++ptr != limit);
166
167 do sum += *ptr;
168 while (++ptr != end);
169
170 Float_t pedes = (Float_t)(sum-sumpeak)/(fRawEvt->GetNumHiGainSamples()-5);
171 Float_t nphot = (Float_t)sumpeak - 5.0*pedes;
172
173 Float_t sigmaped=0;
174
175 slicelocal=0;
176 sumlocal = 0;
177
178 ptr = pixel.GetHiGainSamples();
179 do
180 {
181 if (slicelocal==slice)
182 ptr += 4;
183 else
184 {
185 sumlocal = *ptr;
186
187 const Float_t d = (Float_t)sumlocal-pedes;
188 sigmaped += d*d;
189 }
190 slicelocal++;
191 }
192 while (++ptr != end);
193
194 sigmaped /= (fRawEvt->GetNumHiGainSamples()-5);
195 sigmaped = sqrt((float)sumlocal);
196
197 const UInt_t pixid = pixel.GetPixelId();
198
199 fCerPhotEvt->AddPixel(pixid, nphot, sigmaped/2.236);
200
201 if (fPedestals)
202 (*fPedestals)[pixid].Set(pedes, sigmaped);
203
204 /*
205 ped.SetPedestalRms(sigmaped/sqrt(fRawEvt->GetNumHiGainSamples()-5.),
206 sigmaped/sqrt(2.*(fRawEvt->GetNumHiGainSamples()-5)));
207 */
208 // FIXME! Handling of Lo Gains is missing!
209 }
210
211 fCerPhotEvt->FixSize();
212 fCerPhotEvt->SetReadyToSave();
213
214 if (fPedestals)
215 fPedestals->SetReadyToSave();
216
217 return kTRUE;
218}
219
Note: See TracBrowser for help on using the repository browser.