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

Last change on this file since 1466 was 1396, checked in by blanch, 22 years ago
Class underdevelopment to get from the FADC slices the number of phe, searching for the 5 neighbour larger slices, and its pedestal event by event.
File size: 5.8 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
56// --------------------------------------------------------------------------
57//
58// Default constructor.
59//
60MCerPhotAnal::MCerPhotAnal(const char *name, const char *title)
61{
62 fName = name ? name : "MCerPhotAnal";
63 fTitle = title ? title : "Task to calculate Cerenkov photons from raw data";
64
65 AddToBranchList("MRawEvtData.fHiGainPixId");
66 AddToBranchList("MRawEvtData.fLoGainPixId");
67 AddToBranchList("MRawEvtData.fHiGainFadcSamples");
68 AddToBranchList("MRawEvtData.fLoGainFadcSamples");
69
70}
71
72// --------------------------------------------------------------------------
73//
74// The PreProcess searches for the following input containers:
75// - MRawRunHeader
76// - MRawEvtData
77// - MPedestalCam
78//
79// The following output containers are also searched and created if
80// they were not found:
81// - MCerPhotEvt
82//
83Bool_t MCerPhotAnal::PreProcess(MParList *pList)
84{
85 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
86 if (!fRunHeader)
87 {
88 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
89 return kFALSE;
90 }
91
92 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
93 if (!fRawEvt)
94 {
95 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
96 return kFALSE;
97 }
98
99 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
100 if (!fPedestals)
101 {
102 *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
103 return kFALSE;
104 }
105
106 fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
107 if (!fCerPhotEvt)
108 return kFALSE;
109
110 return kTRUE;
111}
112
113// --------------------------------------------------------------------------
114//
115// Calculate the integral of the FADC time slices and store them as a new
116// pixel in the MCerPhotEvt container.
117//
118Bool_t MCerPhotAnal::Process()
119{
120 fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
121
122 MRawEvtPixelIter pixel(fRawEvt);
123
124 while (pixel.Next())
125 {
126 Byte_t *ptr = pixel.GetHiGainSamples();
127 const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
128 const Byte_t *limit = end - 5;
129
130 Int_t sum=0;
131 Int_t sumpeak=0;
132 Int_t sumlocal =0;
133 Int_t slice=0;
134 Int_t slicelocal=0;
135
136 Float_t nphot;
137 Float_t pedes, sigmaped;
138
139 do
140 {
141 sumlocal = 0;
142 for(Int_t i = 0; i<5;i++)
143 sumlocal+=*(ptr+i);
144 if (sumpeak < sumlocal){
145 slice=slicelocal;
146 sumpeak = sumlocal;
147 }
148 slicelocal++;
149 sum += *ptr;
150 }
151 while (++ptr != limit);
152
153 do sum += *ptr;
154 while (++ptr != end);
155
156 pedes = (Float_t)(sum-sumpeak)/(fRawEvt->GetNumHiGainSamples()-5);
157 nphot=(Float_t)sumpeak - 5.0*pedes;
158 sigmaped=0;
159 sumlocal=0;
160 slicelocal=0;
161
162 ptr = pixel.GetHiGainSamples();
163 do {
164 if (slicelocal==slice)
165 ptr+=4;
166 else{
167 sumlocal=*ptr;
168 sigmaped+=((Float_t)sumlocal-pedes)*((Float_t)sumlocal-pedes);
169 }
170 slicelocal++;
171 }
172 while(++ptr != end);
173 sigmaped/=(fRawEvt->GetNumHiGainSamples()-5);
174 sigmaped=sqrt(sumlocal);
175
176 const UInt_t pixid = pixel.GetPixelId();
177
178 MPedestalPix &ped = (*fPedestals)[pixid];
179
180 //
181 // sanity check (old MC files sometimes have pixids>577)
182 //
183 if (!fPedestals->CheckBounds(pixid))
184 {
185 *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
186 return kCONTINUE;
187 }
188
189 fCerPhotEvt->AddPixel(pixid, nphot, sigmaped/2.236);
190 ped.SetPedestal(pedes,sigmaped);
191 ped.SetPedestalRms(sigmaped/sqrt(fRawEvt->GetNumHiGainSamples()-5),
192 sigmaped/sqrt(2*(fRawEvt->GetNumHiGainSamples()-5)));
193
194 // FIXME! Handling of Lo Gains is missing!
195 }
196
197 fCerPhotEvt->SetReadyToSave();
198
199 return kTRUE;
200}
201
Note: See TracBrowser for help on using the repository browser.