source: trunk/Mars/mdrs/MHDrsCalibrationTime.cc@ 15658

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