source: branches/Corsika7405Compatibility/mdrs/MHDrsCalibrationTime.cc@ 18459

Last change on this file since 18459 was 18155, checked in by tbretz, 10 years ago
We now precalculate the DRS offsets. This is faster and allows to read and write them directly to a fits file.
File size: 5.7 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 2013 <mailto:tbretz@physik.rwth-aachen.de>
19!
20! Copyright: MAGIC Software Development, 2000-2015
21!
22!
23\* ======================================================================== */
24
25///////////////////////////////////////////////////////////////////////
26//
27// MHDrsCalibrationTime
28//
29///////////////////////////////////////////////////////////////////////
30#include "MHDrsCalibrationTime.h"
31
32#include <TCanvas.h>
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MStatusDisplay.h"
38
39#include "MDrsCalibrationTime.h"
40#include "MPedestalSubtractedEvt.h"
41
42#include "MParList.h"
43#include "MRawEvtData.h"
44
45#include "MBinning.h"
46
47ClassImp(MHDrsCalibrationTime);
48
49using namespace std;
50
51MHDrsCalibrationTime::MHDrsCalibrationTime(const char *name, const char *title) :
52fRaw(0), fEvt(0), fCal(0)
53
54{
55 //
56 // set the name and title of this object
57 //
58 fName = name ? name : "MHDrsCalibrationTime";
59 fTitle = title ? title : "Container for ADC spectra histograms";
60
61 MBinning bx( 160, -0.5, 159.5);
62 MBinning by(1024, -0.5, 1023.5);
63
64 MH::SetBinning(&fHist, &by, &bx);
65
66 fHist.SetName("Offset");
67 fHist.SetTitle("DRS cell time offset");
68
69 fHist.SetXTitle("Absolute position in pipeline");
70 fHist.SetYTitle("DRS time marker channel");
71 fHist.SetZTitle("\\Delta t / slices");
72
73 fHist.SetStats(kFALSE);
74 fHist.SetContour(99);
75 fHist.SetDirectory(0);
76}
77
78Bool_t MHDrsCalibrationTime::SetupFill(const MParList *pList)
79{
80 /*
81 SetTitle("DRS bla bla;;ADC signal [mV];");
82
83 if (!MHCamEvent::SetupFill(pList))
84 return kFALSE;
85
86 fSum->ResetBit(MHCamera::kProfile);
87 */
88
89
90 fData.Reset();
91
92 return kTRUE;
93}
94
95Bool_t MHDrsCalibrationTime::ReInit(MParList *pList)
96{
97 fRaw = (MRawEvtData*)pList->FindObject("MRawEvtData");
98 if (!fRaw)
99 {
100 *fLog << err << "MRawEvtData not found... aborting." << endl;
101 return kFALSE;
102 }
103
104 if (!fRaw->HasStartCells())
105 {
106 *fLog << err << "MRawEvtData has no start cells stored... aborting." << endl;
107 return kFALSE;
108 }
109
110 if (fRaw->GetNumPixels()==0 || fRaw->GetNumSamples()==0)
111 {
112 *fLog << err << "MRawEvtData contains either no pixels or no samples... aborting." << endl;
113 return kFALSE;
114 }
115
116 fEvt = (MPedestalSubtractedEvt*)pList->FindObject("MPedestalSubtractedEvt");
117 if (!fEvt)
118 {
119 *fLog << err << "MPedestalSubtractedEvt not found... aborting." << endl;
120 return kFALSE;
121 }
122
123 if (fRaw->GetNumSamples()!=1024)
124 {
125 *fLog << err << "Only 1024 samples are supported for the time calibration" << endl;
126 return kFALSE;
127 }
128
129 fCal = (MDrsCalibrationTime*)pList->FindCreateObj("MDrsCalibrationTime");
130 if (!fCal)
131 return kFALSE;
132
133 fData.InitSize(160, 1024);
134
135 return kTRUE;
136}
137
138Int_t MHDrsCalibrationTime::Fill(const MParContainer *par, const Stat_t w)
139{
140 fData.AddT(fEvt->GetSamples(0),
141 reinterpret_cast<int16_t*>(fRaw->GetStartCells()), +1);
142
143 return kTRUE;
144}
145
146void MHDrsCalibrationTime::InitHistogram()
147{
148 DrsCalibrateTime t = fData.GetResult();
149 if (t.fNumEntries==0)
150 return;
151
152 for (int p=0; p<160; p++)
153 for (int s=0; s<1024; s++)
154 fHist.SetBinContent(s+1, p+1, t.fStat[p*t.fNumSamples+s].first);
155}
156
157void MHDrsCalibrationTime::PlotAll()
158{
159 if (!fDisplay)
160 return;
161
162 InitHistogram();
163
164 for (int b=0; b<10; b++)
165 {
166 TCanvas &c = fDisplay->AddTab(Form("B%d", b));
167
168 c.Divide(2,2);
169
170 for (int i=0; i<4; i++)
171 {
172 c.cd(i+1);
173
174 gPad->SetGrid();
175 gPad->SetBorderMode(0);
176 gPad->SetFrameBorderMode(0);
177 gPad->SetRightMargin(0.01);
178
179 const int col[] = { kBlack, kRed, kBlue, kGreen };
180
181 for (int crate=0; crate<4; crate++)
182 {
183 TH1 *h = fHist.ProjectionX(Form("%d-%d-%d", crate, b, i), crate*40+b*4+i+1, crate*40+b*4+i+1);
184 h->SetName(Form("Crate%d", crate));
185 h->SetTitle(Form("Board %d, Chip %d (All four crates)", b, i));
186 h->SetXTitle("Slice");
187 h->SetYTitle("\\Delta t / slices");
188 h->SetMinimum(-10);
189 h->SetMaximum(10);
190 h->SetStats(kFALSE);
191 h->SetDirectory(0);
192 h->SetMarkerStyle(kFullDotMedium);
193 h->SetMarkerColor(col[crate]);
194 h->SetLineColor(col[crate]);
195 h->DrawCopy(crate==0 ? "hist p" : "hist P same");
196 }
197 }
198 }
199
200 // 4 crates
201 // 10 boards
202 // 4 chips
203}
204
205void MHDrsCalibrationTime::Draw(Option_t *o)
206{
207 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
208
209 AppendPad("");
210
211 pad->Divide(1,1);
212
213 pad->cd(1);
214
215 gPad->SetBorderMode(0);
216 gPad->SetFrameBorderMode(0);
217
218 fHist.Draw("colz");
219}
220
221
222void MHDrsCalibrationTime::Paint(Option_t *o)
223{
224 MH::SetPalette();
225 InitHistogram();
226}
227
228Bool_t MHDrsCalibrationTime::Finalize()
229{
230 // InitHistogram();
231 fCal->SetCalibration(fData.GetResult());
232 return kTRUE;
233}
Note: See TracBrowser for help on using the repository browser.