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

Last change on this file since 2533 was 2533, checked in by gaug, 21 years ago
*** empty log message ***
File size: 4.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): 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 "MRawRunHeader.h"
46#include "MRawEvtPixelIter.h"
47#include "MRawEvtData.h"
48
49#include "MPedestalPix.h"
50#include "MPedestalCam.h"
51
52ClassImp(MPedCalcPedRun);
53
54using namespace std;
55
56MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title)
57{
58 fName = name ? name : "MPedCalcPedRun";
59 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
60
61 AddToBranchList("fHiGainPixId");
62 //AddToBranchList("fLoGainPixId");
63 AddToBranchList("fHiGainFadcSamples");
64 //AddToBranchList("fLoGainFadcSamples");
65}
66
67Int_t MPedCalcPedRun::PreProcess( MParList *pList )
68{
69 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
70 if (!fRawEvt)
71 {
72 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
73 return kFALSE;
74 }
75
76 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
77 if (!fPedestals)
78 return kFALSE;
79
80 return kTRUE;
81}
82
83Bool_t MPedCalcPedRun::ReInit(MParList *pList )
84{
85
86 fRunheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
87 if (!fRunheader)
88 {
89 *fLog << warn << dbginf <<
90 "Warning - cannot check file type, MRawRunHeader not found." << endl;
91 }
92 else
93 if (fRunheader->GetRunType() == kRTMonteCarlo)
94 {
95 return kTRUE;
96 }
97
98 fNumHiGainSamples = fRunheader->GetNumSamplesHiGain();
99
100 return kTRUE;
101
102}
103
104
105Int_t MPedCalcPedRun::Process()
106{
107 MRawEvtPixelIter pixel(fRawEvt);
108
109 while (pixel.Next())
110 {
111 Byte_t *ptr = pixel.GetHiGainSamples();
112 const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
113
114 const Float_t higainped = CalcHiGainMean(ptr, end);
115 const Float_t higainrms = CalcHiGainRms(ptr, end, higainped);
116
117 //const Float_t higainpederr = CalcHiGainMeanErr(higainrms);
118 //const Float_t higainrmserr = CalcHiGainRmsErr(higainrms);
119
120 const UInt_t pixid = pixel.GetPixelId();
121 MPedestalPix &pix = (*fPedestals)[pixid];
122
123 pix.Set(higainped, higainrms);
124 *fLog << dbg << higainped << " " << higainrms << endl;
125 //pix.SetPedestalRms(higainpederr, higainrmserr);
126 }
127
128 fPedestals->SetReadyToSave();
129
130 return kTRUE;
131}
132
133Float_t MPedCalcPedRun::CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const
134{
135 Int_t sum=0;
136
137 do sum += *ptr;
138 while (++ptr != end);
139
140 return (Float_t)sum/fNumHiGainSamples;
141}
142
143
144Float_t MPedCalcPedRun::CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const
145{
146 Float_t rms = 0;
147
148 do
149 {
150 const Float_t diff = (Float_t)(*ptr)-higainped;
151
152 rms += diff*diff;
153 } while (++ptr != end);
154
155 return sqrt(rms/fNumHiGainSamples);
156}
157/*
158Float_t MPedCalcPedRun::CalcHiGainMeanErr(Float_t higainrms) const
159{
160 return higainrms/sqrt((float)fNumHiGainSamples);
161}
162
163Float_t MPedCalcPedRun::CalcHiGainRmsErr(Float_t higainrms) const
164{
165 return higainrms/sqrt(2.*fNumHiGainSamples);
166}
167*/
Note: See TracBrowser for help on using the repository browser.