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

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