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

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