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

Last change on this file since 2919 was 2237, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.5 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 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
106 if (!runheader)
107 *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
108 else
109 if (runheader->GetRunType() == kRTMonteCarlo)
110 {
111 fPedestals=NULL;
112 return kTRUE;
113 }
114
115 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
116 if (runheader && !fPedestals)
117 return kFALSE;
118
119 return kTRUE;
120}
121
122// --------------------------------------------------------------------------
123//
124// Calculate the integral of the FADC time slices and store them as a new
125// pixel in the MCerPhotEvt container.
126//
127Int_t MCerPhotAnal::Process()
128{
129 //fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
130
131 MRawEvtPixelIter pixel(fRawEvt);
132
133 while (pixel.Next())
134 {
135 Byte_t *ptr = pixel.GetHiGainSamples();
136 const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
137 const Byte_t *limit = end - 5;
138
139 Int_t sum=0;
140 Int_t sumpeak=0;
141 Int_t sumlocal =0;
142 Int_t slice=0;
143 Int_t slicelocal=0;
144
145 do
146 {
147 sumlocal = 0;
148 for (Int_t i = 0; i<5;i++)
149 sumlocal += *(ptr+i);
150
151 if (sumpeak < sumlocal)
152 {
153 slice=slicelocal;
154 sumpeak = sumlocal;
155 }
156
157 slicelocal++;
158 sum += *ptr;
159 } while (++ptr != limit);
160
161 do sum += *ptr;
162 while (++ptr != end);
163
164 Float_t pedes = (Float_t)(sum-sumpeak)/(fRawEvt->GetNumHiGainSamples()-5);
165 Float_t nphot = (Float_t)sumpeak - 5.0*pedes;
166
167 Float_t sigmaped=0;
168
169 slicelocal=0;
170 sumlocal = 0;
171
172 ptr = pixel.GetHiGainSamples();
173 do
174 {
175 if (slicelocal==slice)
176 ptr += 4;
177 else
178 {
179 sumlocal = *ptr;
180
181 const Float_t d = (Float_t)sumlocal-pedes;
182 sigmaped += d*d;
183 }
184 slicelocal++;
185 }
186 while (++ptr != end);
187
188 sigmaped /= (fRawEvt->GetNumHiGainSamples()-5);
189 sigmaped = sqrt((float)sumlocal);
190
191 const UInt_t pixid = pixel.GetPixelId();
192
193 //
194 // sanity check (old MC files sometimes have pixids>577)
195 //
196 if (fPedestals && !fPedestals->CheckBounds(pixid))
197 {
198 *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
199 return kCONTINUE;
200 }
201
202 fCerPhotEvt->AddPixel(pixid, nphot, sigmaped/2.236);
203
204 if (fPedestals)
205 (*fPedestals)[pixid].Set(pedes, sigmaped);
206
207 /*
208 ped.SetPedestalRms(sigmaped/sqrt(fRawEvt->GetNumHiGainSamples()-5.),
209 sigmaped/sqrt(2.*(fRawEvt->GetNumHiGainSamples()-5)));
210 */
211 // FIXME! Handling of Lo Gains is missing!
212 }
213
214 fCerPhotEvt->FixSize();
215 fCerPhotEvt->SetReadyToSave();
216
217 if (fPedestals)
218 fPedestals->SetReadyToSave();
219
220 return kTRUE;
221}
222
Note: See TracBrowser for help on using the repository browser.