source: trunk/Mars/mdrs/MHDrsCalibrationCheck.cc@ 18679

Last change on this file since 18679 was 14922, checked in by tbretz, 12 years ago
New classes for DRS calibration.
File size: 4.2 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 2012 <mailto:thomas.bretz@epfl.ch>
19!
20! Copyright: MAGIC Software Development, 2000-2013
21!
22!
23\* ======================================================================== */
24
25///////////////////////////////////////////////////////////////////////
26//
27// MHDrsCalibration
28//
29///////////////////////////////////////////////////////////////////////
30#include "MHDrsCalibrationCheck.h"
31
32#include "MLog.h"
33#include "MLogManip.h"
34
35#include "MParList.h"
36
37#include "MRawRunHeader.h"
38#include "MHCamera.h"
39#include "MPedestalSubtractedEvt.h"
40
41ClassImp(MHDrsCalibrationCheck);
42
43using namespace std;
44
45// --------------------------------------------------------------------------
46//
47// default constructor
48// creates an a list of histograms for all pixels and both gain channels
49//
50MHDrsCalibrationCheck::MHDrsCalibrationCheck(const char *name, const char *title) :
51 fEvt(0)
52{
53 //
54 // set the name and title of this object
55 //
56 fName = name ? name : "MHDrsCalibrationCheck";
57 fTitle = title ? title : "Container for ADC spectra histograms";
58}
59
60// --------------------------------------------------------------------------
61//
62// To setup the object we get the number of pixels from a MGeomCam object
63// in the Parameter list.
64//
65Bool_t MHDrsCalibrationCheck::SetupFill(const MParList *pList)
66{
67 SetTitle("Noise (DRS calibration applied);;ADC signal [mV];");
68
69 if (!MHCamEvent::SetupFill(pList))
70 return kFALSE;
71
72 fSum->ResetBit(MHCamera::kProfile);
73
74 *fLog << warn << "WARNING --- oulier detection needed!" << endl;
75
76 return kTRUE;
77}
78
79Bool_t MHDrsCalibrationCheck::ReInit(MParList *pList)
80{
81 MRawRunHeader *h = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
82 if (!h)
83 {
84 *fLog << err << "MRawRunHeader not found... aborting." << endl;
85 return kFALSE;
86 }
87
88 fNumSamples = h->GetNumSamples();
89 fNumPixels = h->GetNumPixel();
90
91 fEvt = (MPedestalSubtractedEvt*)pList->FindObject("MPedestalSubtractedEvt");
92 if (!fEvt)
93 {
94 *fLog << err << "MPedestalSubtractedEvt not found... aborting." << endl;
95 return kFALSE;
96 }
97
98 fSum1.resize(fNumPixels*fNumSamples);
99 fSum2.resize(fNumPixels*fNumSamples);
100
101 return kTRUE;
102}
103
104// --------------------------------------------------------------------------
105
106Int_t MHDrsCalibrationCheck::Fill(const MParContainer *par, const Stat_t w)
107{
108 for (size_t ch=0; ch<fNumPixels*fNumSamples; ch++)
109 {
110 const double val = fEvt->GetSamples(0)[ch];
111
112 fSum1[ch] += val;
113 fSum2[ch] += val*val;
114 }
115
116 return kTRUE;
117}
118
119
120void MHDrsCalibrationCheck::InitHistogram()
121{
122 if (!fEvt)
123 return;
124
125 fSum->Reset();
126
127 for (size_t ch=0; ch<fNumPixels; ch++)
128 {
129 double m = 0;
130 double r = 0;
131 for (size_t i=0; i<fNumSamples; i++)
132 {
133 const int idx = i + ch*fNumSamples;
134
135 const double avg = fSum1[idx] / GetNumExecutions();
136 const double avg2 = fSum2[idx] / GetNumExecutions();
137 const double rms = sqrt(avg2 - avg*avg);
138
139 m += avg;
140 r += rms;
141 }
142
143 fSum->AddBinContent(ch+1, m);
144 fSum->SetBinError(ch+1, r);
145 }
146
147 fSum->Scale(1./fNumSamples); // 0.5mV/ADC count
148 fSum->SetEntries(GetNumExecutions());
149 fSum->SetAllUsed();
150}
151
152Bool_t MHDrsCalibrationCheck::Finalize()
153{
154 InitHistogram();
155
156 return kTRUE;
157}
158
159void MHDrsCalibrationCheck::Paint(Option_t *o)
160{
161 InitHistogram();
162 MHCamEvent::Paint(o);
163}
Note: See TracBrowser for help on using the repository browser.