source: branches/Mars_McMismatchStudy/mdrs/MHDrsCalibrationTime.cc@ 18165

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