source: trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc@ 854

Last change on this file since 854 was 845, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 3.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): Josep Flix 04/2001 (jflix@ifae.es)
19! Thomas Bretz 05/2001 (tbretz@uni-sw.gwdg.de)
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27// //
28// MPedCalcPedRun //
29// //
30/////////////////////////////////////////////////////////////////////////////
31
32#include "MPedCalcPedRun.h"
33
34#include "MParList.h"
35
36#include "MLog.h"
37#include "MLogManip.h"
38
39#include "MRawEvtPixelIter.h"
40#include "MRawEvtData.h"
41
42#include "MPedestalPix.h"
43#include "MPedestalCam.h"
44
45ClassImp(MPedCalcPedRun)
46
47MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title)
48{
49 *fName = name ? name : "MPedCalcPedRun";
50 *fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
51}
52
53Bool_t MPedCalcPedRun::PreProcess( MParList *pList )
54{
55 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
56 if (!fRawEvt)
57 {
58 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
59 return kFALSE;
60 }
61
62 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
63 if (!fPedestals)
64 return kFALSE;
65
66 fNumHiGainSamples = fRawEvt->GetNumHiGainSamples();
67
68 return kTRUE;
69}
70
71
72Bool_t MPedCalcPedRun::Process()
73{
74 MRawEvtPixelIter pixel(fRawEvt);
75
76 while (pixel.Next())
77 {
78 Byte_t *ptr = pixel.GetHiGainFadcSamples();
79 const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
80
81 const Float_t higainped = CalcHiGainMean(ptr, end);
82 const Float_t higainrms = CalcHiGainRms(ptr, end, higainped);
83
84 const Float_t higainpederr = CalcHiGainMeanErr(higainrms);
85 const Float_t higainrmserr = CalcHiGainRmsErr(higainrms);
86
87 const UInt_t pixid = pixel.GetPixelId();
88 MPedestalPix &pix = (*fPedestals)[pixid];
89
90 pix.SetPedestal(higainped, higainrms);
91 pix.SetPedestalRms(higainpederr, higainrmserr);
92 }
93
94 fPedestals->SetHasChanged();
95
96 return kTRUE;
97}
98
99Float_t MPedCalcPedRun::CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const
100{
101 Int_t sum=0;
102
103 do sum += *ptr;
104 while (++ptr != end);
105
106 return (Float_t)sum/fNumHiGainSamples;
107}
108
109
110Float_t MPedCalcPedRun::CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const
111{
112 Float_t rms = 0;
113
114 do
115 {
116 const Float_t diff = (Float_t)(*ptr)-higainped;
117
118 rms += diff*diff;
119 } while (++ptr != end);
120
121 return sqrt(rms/(fNumHiGainSamples-1));
122}
123
124Float_t MPedCalcPedRun::CalcHiGainMeanErr(Float_t higainrms) const
125{
126 return higainrms/sqrt(fNumHiGainSamples);
127}
128
129Float_t MPedCalcPedRun::CalcHiGainRmsErr(Float_t higainrms) const
130{
131 return higainrms/sqrt(2.*fNumHiGainSamples);
132}
133
Note: See TracBrowser for help on using the repository browser.