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, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MJCalibrateSignal
|
---|
28 | //
|
---|
29 | // This class is reading the output written by callisto. It calibrates
|
---|
30 | // signal and time.
|
---|
31 | //
|
---|
32 | // The signal and time extractors are read from the callisto-output. In
|
---|
33 | // pricipal you could overwrite these default using the resource file,
|
---|
34 | // but this is NOT recommended!
|
---|
35 | //
|
---|
36 | /////////////////////////////////////////////////////////////////////////////
|
---|
37 | #include "MJCalibrateSignal.h"
|
---|
38 |
|
---|
39 | #include <TEnv.h>
|
---|
40 | #include <TFile.h>
|
---|
41 |
|
---|
42 | #include "MLog.h"
|
---|
43 | #include "MLogManip.h"
|
---|
44 |
|
---|
45 | #include "MDirIter.h"
|
---|
46 | #include "MRunIter.h"
|
---|
47 | #include "MParList.h"
|
---|
48 | #include "MTaskList.h"
|
---|
49 | #include "MEvtLoop.h"
|
---|
50 |
|
---|
51 | #include "MStatusDisplay.h"
|
---|
52 |
|
---|
53 | #include "MGeomCam.h"
|
---|
54 | #include "MHCamEvent.h"
|
---|
55 | //#include "MHCamEventTH.h"
|
---|
56 | #include "MPedestalCam.h"
|
---|
57 | #include "MBadPixelsCam.h"
|
---|
58 | #include "MArrivalTimeCam.h"
|
---|
59 |
|
---|
60 | #include "MCalibrationQECam.h"
|
---|
61 | #include "MCalibrationBlindCam.h"
|
---|
62 | #include "MCalibrationChargeCam.h"
|
---|
63 | #include "MCalibrationRelTimeCam.h"
|
---|
64 | #include "MCalibrationChargePINDiode.h"
|
---|
65 | #include "MCalibrationHiLoCam.h"
|
---|
66 | #include "MCalibrationPulseTimeCam.h"
|
---|
67 | #include "MCalibrationPatternDecode.h"
|
---|
68 |
|
---|
69 | #include "MCalibrationChargeCalc.h"
|
---|
70 | #include "MCalibrationRelTimeCalc.h"
|
---|
71 |
|
---|
72 | #include "MCalibrationIntensityChargeCam.h"
|
---|
73 | #include "MCalibrationIntensityBlindCam.h"
|
---|
74 | #include "MCalibrationIntensityRelTimeCam.h"
|
---|
75 | #include "MCalibrationIntensityQECam.h"
|
---|
76 | #include "MCalibrationIntensityConstCam.h"
|
---|
77 | #include "MBadPixelsIntensityCam.h"
|
---|
78 |
|
---|
79 | #include "MHCalibrationChargeCam.h"
|
---|
80 | #include "MHCalibrationChargeBlindCam.h"
|
---|
81 | #include "MHCalibrationChargePINDiode.h"
|
---|
82 | #include "MHCalibrationRelTimeCam.h"
|
---|
83 | #include "MHCalibrationPulseTimeCam.h"
|
---|
84 | #include "MHCalibrationHiLoCam.h"
|
---|
85 | #include "MHCamera.h"
|
---|
86 |
|
---|
87 | #include "MCalibCalcFromPast.h"
|
---|
88 |
|
---|
89 | #include "MReadReports.h"
|
---|
90 | #include "MReadMarsFile.h"
|
---|
91 | #include "MRawFileRead.h"
|
---|
92 | #include "MContinue.h"
|
---|
93 | #include "MTriggerPatternDecode.h"
|
---|
94 | #include "MFTriggerPattern.h"
|
---|
95 | #include "MGeomApply.h"
|
---|
96 | #include "MPedestalSubtract.h"
|
---|
97 | //#include "MMcPedestalCopy.h"
|
---|
98 | #include "MPointingPosCalc.h"
|
---|
99 | #include "MPedCalcFromLoGain.h"
|
---|
100 | #include "MExtractor.h"
|
---|
101 | #include "MExtractTimeAndCharge.h"
|
---|
102 | #include "MExtractPINDiode.h"
|
---|
103 | #include "MExtractBlindPixel.h"
|
---|
104 | #include "MFCosmics.h"
|
---|
105 | #include "MTaskEnv.h"
|
---|
106 | #include "MCalibrateData.h"
|
---|
107 | #include "MCalibrateRelTimes.h"
|
---|
108 | #include "MBadPixelsMerge.h"
|
---|
109 | #include "MBadPixelsCalc.h"
|
---|
110 | #include "MBadPixelsTreat.h"
|
---|
111 | #include "MFillH.h"
|
---|
112 | #include "MWriteRootFile.h"
|
---|
113 |
|
---|
114 | ClassImp(MJCalibrateSignal);
|
---|
115 |
|
---|
116 | using namespace std;
|
---|
117 |
|
---|
118 | // --------------------------------------------------------------------------
|
---|
119 | //
|
---|
120 | // Default constructor.
|
---|
121 | //
|
---|
122 | // Sets:
|
---|
123 | // - fIsInterlaced to kTRUE
|
---|
124 | // - fIsRelTimesUpdate to kFALSE
|
---|
125 | // - fIsHiLoCalibration to kFALSE
|
---|
126 | // - fPulsePosCheck to kTRUE
|
---|
127 | //
|
---|
128 | MJCalibrateSignal::MJCalibrateSignal(const char *name, const char *title)
|
---|
129 | : fExtractor(0), fIsInterlaced(kTRUE), fIsRelTimesUpdate(kFALSE)
|
---|
130 | {
|
---|
131 | fName = name ? name : "MJCalibrateSignal";
|
---|
132 | fTitle = title ? title : "Tool to calibrate data";
|
---|
133 |
|
---|
134 | SetPulsePosCheck();
|
---|
135 | //fCruns = NULL;
|
---|
136 | }
|
---|
137 |
|
---|
138 | MJCalibrateSignal::~MJCalibrateSignal()
|
---|
139 | {
|
---|
140 | if (fExtractor)
|
---|
141 | delete fExtractor;
|
---|
142 | }
|
---|
143 |
|
---|
144 | void MJCalibrateSignal::SetExtractor(const MExtractor *ext)
|
---|
145 | {
|
---|
146 | if (fExtractor)
|
---|
147 | delete fExtractor;
|
---|
148 |
|
---|
149 | fExtractor = ext ? (MExtractor*)ext->Clone() : NULL;
|
---|
150 | }
|
---|
151 |
|
---|
152 | Bool_t MJCalibrateSignal::WriteResult(TObjArray &cont)
|
---|
153 | {
|
---|
154 | if (IsNoStorage())
|
---|
155 | return kTRUE;
|
---|
156 |
|
---|
157 | const TString name(Form("signal%08d.root", fSequence.GetSequence()));
|
---|
158 | return WriteContainer(cont, name);
|
---|
159 | }
|
---|
160 |
|
---|
161 | Bool_t MJCalibrateSignal::ReadCalibration(TObjArray &l, MBadPixelsCam &cam, MExtractor* &ext2, MExtractor* &ext3, TString &geom) const
|
---|
162 | {
|
---|
163 | TString fname = Form("%s/calib%08d.root", fPathIn.Data(), fSequence.GetSequence());
|
---|
164 |
|
---|
165 | *fLog << inf << "Reading from file: " << fname << endl;
|
---|
166 |
|
---|
167 | TFile file(fname, "READ");
|
---|
168 | if (!file.IsOpen())
|
---|
169 | {
|
---|
170 | *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
|
---|
171 | return kFALSE;
|
---|
172 | }
|
---|
173 |
|
---|
174 | TObject *o = file.Get("ExtractSignal");
|
---|
175 | if (o && !o->InheritsFrom(MExtractor::Class()))
|
---|
176 | {
|
---|
177 | *fLog << err << dbginf << "ERROR - ExtractSignal read from " << fname << " doesn't inherit from MExtractor!" << endl;
|
---|
178 | return kFALSE;
|
---|
179 | }
|
---|
180 | ext3 = o ? (MExtractor*)o->Clone() : NULL;
|
---|
181 |
|
---|
182 | o = file.Get("ExtractTime");
|
---|
183 | if (o && !o->InheritsFrom(MExtractor::Class()))
|
---|
184 | {
|
---|
185 | *fLog << err << dbginf << "ERROR - ExtractTime read from " << fname << " doesn't inherit from MExtractor!" << endl;
|
---|
186 | return kFALSE;
|
---|
187 | }
|
---|
188 | ext2 = o ? (MExtractor*)o->Clone() : NULL;
|
---|
189 | if (!ext3 && !ext2)
|
---|
190 | {
|
---|
191 | *fLog << err << dbginf << "ERROR - Neither ExtractSignal nor ExrtractTime found in " << fname << "!" << endl;
|
---|
192 | return kFALSE;
|
---|
193 | }
|
---|
194 |
|
---|
195 | o = file.Get("MGeomCam");
|
---|
196 | if (o && !o->InheritsFrom(MGeomCam::Class()))
|
---|
197 | {
|
---|
198 | *fLog << err << dbginf << "ERROR - MGeomCam read from " << fname << " doesn't inherit from MGeomCam!" << endl;
|
---|
199 | return kFALSE;
|
---|
200 | }
|
---|
201 | geom = o ? o->ClassName() : "";
|
---|
202 |
|
---|
203 | TObjArray cont(l);
|
---|
204 | cont.Add(&cam);
|
---|
205 | return ReadContainer(cont);
|
---|
206 | }
|
---|
207 |
|
---|
208 | // --------------------------------------------------------------------------
|
---|
209 | //
|
---|
210 | // MJCalibration allows to setup several option by a resource file:
|
---|
211 | // MJCalibrateSignal.RawData: yes,no
|
---|
212 | //
|
---|
213 | // For more details see the class description and the corresponding Getters
|
---|
214 | //
|
---|
215 | Bool_t MJCalibrateSignal::CheckEnvLocal()
|
---|
216 | {
|
---|
217 | SetInterlaced(GetEnv("Interlaced", fIsInterlaced));
|
---|
218 | SetRelTimesUpdate(GetEnv("RelTimesUpdate", fIsRelTimesUpdate));
|
---|
219 |
|
---|
220 | return MJCalib::CheckEnvLocal();
|
---|
221 | }
|
---|
222 |
|
---|
223 | Bool_t MJCalibrateSignal::Process(MPedestalCam &pedcamab, MPedestalCam &pedcambias,
|
---|
224 | MPedestalCam &pedcamextr)
|
---|
225 | {
|
---|
226 | if (!fSequence.IsValid())
|
---|
227 | {
|
---|
228 | *fLog << err << "ERROR - Sequence invalid..." << endl;
|
---|
229 | return kFALSE;
|
---|
230 | }
|
---|
231 |
|
---|
232 | *fLog << inf;
|
---|
233 | fLog->Separator(GetDescriptor());
|
---|
234 | *fLog << "Calculate calibrated data from Sequence #";
|
---|
235 | *fLog << fSequence.GetSequence() << endl << endl;
|
---|
236 |
|
---|
237 |
|
---|
238 | //if (!CheckEnv())
|
---|
239 | // return kFALSE;
|
---|
240 |
|
---|
241 | CheckEnv();
|
---|
242 |
|
---|
243 | // --------------------------------------------------------------------------------
|
---|
244 |
|
---|
245 | MDirIter iter;
|
---|
246 | if (fSequence.IsValid())
|
---|
247 | {
|
---|
248 | const Int_t n0 = fSequence.SetupDatRuns(iter, fPathData, IsUseRawData());
|
---|
249 | const Int_t n1 = fSequence.GetNumDatRuns();
|
---|
250 | if (n0==0)
|
---|
251 | {
|
---|
252 | *fLog << err << "ERROR - No input files of sequence found!" << endl;
|
---|
253 | return kFALSE;
|
---|
254 | }
|
---|
255 | if (n0!=n1)
|
---|
256 | {
|
---|
257 | *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
|
---|
258 | if (fLog->GetDebugLevel()>4)
|
---|
259 | {
|
---|
260 | *fLog << dbg << "Files which are searched:" << endl;
|
---|
261 | iter.Print();
|
---|
262 | }
|
---|
263 | return kFALSE;
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | // Read File
|
---|
268 | MCalibrationIntensityChargeCam ichcam;
|
---|
269 | MCalibrationIntensityQECam iqecam;
|
---|
270 | MCalibrationIntensityBlindCam iblcam;
|
---|
271 | MCalibrationIntensityRelTimeCam itmcam;
|
---|
272 | MCalibrationIntensityConstCam icncam;
|
---|
273 | MBadPixelsIntensityCam ibdcam;
|
---|
274 |
|
---|
275 | MHCalibrationChargeCam hchacam;
|
---|
276 | MHCalibrationChargeBlindCam hbndcam;
|
---|
277 | MHCalibrationChargePINDiode hpndiod;
|
---|
278 | MHCalibrationRelTimeCam hrelcam;
|
---|
279 | MHCalibrationHiLoCam hilocam;
|
---|
280 | MHCalibrationPulseTimeCam hpulcam;
|
---|
281 |
|
---|
282 | hchacam.SetOscillations(kFALSE);
|
---|
283 | hbndcam.SetOscillations(kFALSE);
|
---|
284 | hrelcam.SetOscillations(kFALSE);
|
---|
285 |
|
---|
286 | MCalibrationChargeCam calcam;
|
---|
287 | MCalibrationQECam qecam;
|
---|
288 | MCalibrationBlindCam bndcam;
|
---|
289 | MCalibrationChargePINDiode pind;
|
---|
290 | MCalibrationRelTimeCam tmcam;
|
---|
291 | MCalibrationHiLoCam hilcam;
|
---|
292 | MCalibrationPulseTimeCam pulcam;
|
---|
293 |
|
---|
294 | MBadPixelsCam badpix;
|
---|
295 |
|
---|
296 | TObjArray interlacedcont;
|
---|
297 | if (fIsInterlaced)
|
---|
298 | {
|
---|
299 | interlacedcont.Add(&ichcam);
|
---|
300 | interlacedcont.Add(&iqecam);
|
---|
301 | interlacedcont.Add(&iblcam);
|
---|
302 | interlacedcont.Add(&itmcam);
|
---|
303 | interlacedcont.Add(&ibdcam);
|
---|
304 | interlacedcont.Add(&icncam);
|
---|
305 | interlacedcont.Add(&hchacam);
|
---|
306 | if (IsUseBlindPixel())
|
---|
307 | interlacedcont.Add(&hbndcam);
|
---|
308 | if (IsUsePINDiode())
|
---|
309 | interlacedcont.Add(&hpndiod);
|
---|
310 | if (fIsRelTimesUpdate)
|
---|
311 | interlacedcont.Add(&hrelcam);
|
---|
312 | }
|
---|
313 |
|
---|
314 | MExtractor *extractor1=fExtractor;
|
---|
315 | MExtractor *extractor2=0;
|
---|
316 | MExtractor *extractor3=0;
|
---|
317 | TString geom;
|
---|
318 |
|
---|
319 | TObjArray calibcont;
|
---|
320 | calibcont.Add(&calcam);
|
---|
321 | calibcont.Add(&qecam);
|
---|
322 | calibcont.Add(&bndcam);
|
---|
323 | calibcont.Add(&tmcam);
|
---|
324 | if (IsUseBlindPixel())
|
---|
325 | calibcont.Add(&bndcam);
|
---|
326 |
|
---|
327 | if (!ReadCalibration(calibcont, badpix, extractor2, extractor3, geom))
|
---|
328 | return kFALSE;
|
---|
329 |
|
---|
330 | *fLog << all;
|
---|
331 | if (!geom.IsNull())
|
---|
332 | *fLog << inf << "Camera geometry found in file: " << geom << endl;
|
---|
333 | else
|
---|
334 | *fLog << inf << "No Camera geometry found using default <MGeomCamMagic>" << endl;
|
---|
335 |
|
---|
336 | if (extractor3)
|
---|
337 | {
|
---|
338 | *fLog << underline << "Signal Extractor found in calibration file" << endl;
|
---|
339 | extractor3->Print();
|
---|
340 | *fLog << endl;
|
---|
341 | }
|
---|
342 | else
|
---|
343 | *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
|
---|
344 |
|
---|
345 |
|
---|
346 | if (extractor1)
|
---|
347 | {
|
---|
348 | *fLog << underline << "Modified Signal Extractor set by user." << endl;
|
---|
349 | extractor1->Print();
|
---|
350 | *fLog << endl;
|
---|
351 | }
|
---|
352 | else
|
---|
353 | {
|
---|
354 | *fLog << inf << "No modified Signal Extractor set by user... using ExtractSignal." << endl;
|
---|
355 | extractor1 = extractor3 ? (MExtractor*)extractor3->Clone() : 0;
|
---|
356 | }
|
---|
357 |
|
---|
358 | if (extractor2)
|
---|
359 | {
|
---|
360 | *fLog << underline << "Time Extractor found in calibration file" << endl;
|
---|
361 | extractor2->Print();
|
---|
362 | *fLog << endl;
|
---|
363 | }
|
---|
364 | else
|
---|
365 | *fLog << inf << "No Time Extractor: ExtractTime in file." << endl;
|
---|
366 |
|
---|
367 | // This is necessary for the case in which it is not in the files
|
---|
368 | MBadPixelsCam badcam;
|
---|
369 | icncam.SetBadPixels(&badpix);
|
---|
370 |
|
---|
371 | // Setup Parlist
|
---|
372 | MParList plist;
|
---|
373 | plist.AddToList(this); // take care of fDisplay!
|
---|
374 | plist.AddToList(&badcam);
|
---|
375 | plist.AddToList(&hilcam);
|
---|
376 | plist.AddToList(&calibcont); // Using AddToList(TObjArray *)
|
---|
377 | plist.AddToList(&interlacedcont); // Using AddToList(TObjArray *)
|
---|
378 | plist.AddToList(&pulcam);
|
---|
379 |
|
---|
380 | // Setup Tasklist
|
---|
381 | MTaskList tlist;
|
---|
382 | plist.AddToList(&tlist);
|
---|
383 |
|
---|
384 | MReadReports readreal;
|
---|
385 | readreal.AddTree("Events", "MTime.", MReadReports::kMaster);
|
---|
386 | readreal.AddTree("Trigger");
|
---|
387 | readreal.AddTree("Camera");
|
---|
388 | readreal.AddTree("Drive");
|
---|
389 | readreal.AddTree("CC");
|
---|
390 | readreal.AddTree("Currents");
|
---|
391 |
|
---|
392 | MReadMarsFile readmc("Events");
|
---|
393 | readmc.DisableAutoScheme();
|
---|
394 |
|
---|
395 | MRawFileRead rawread(NULL);
|
---|
396 |
|
---|
397 | MRead *read = 0;
|
---|
398 | switch (GetDataFlag())
|
---|
399 | {
|
---|
400 | case kIsUseRawData: read = &rawread; break;
|
---|
401 | case kIsUseMC: read = &readmc; break;
|
---|
402 | case kIsUseRootData: read = &readreal; break;
|
---|
403 | }
|
---|
404 | read->AddFiles(iter);
|
---|
405 |
|
---|
406 | const TString fname(Form("%s{s/_D_/_Y_}{s/\\.raw$/.root}{s/\\.raw\\.gz$/.root}", fPathOut.Data()));
|
---|
407 |
|
---|
408 |
|
---|
409 | // Skips MC which have no contents. This are precisely the
|
---|
410 | // events which fullfilled the MC Lvl1 trigger and an
|
---|
411 | // arbitrary cut (typically at 50phe) to speed up simulation
|
---|
412 | MContinue contmc("MRawEvtData.GetNumPixels<0.5", "ContEmptyMC");
|
---|
413 |
|
---|
414 | //MPointingPosInterpolate pextr;
|
---|
415 | //pextr.AddFiles(&iter);
|
---|
416 |
|
---|
417 | MGeomApply apply; // Only necessary to create geometry
|
---|
418 | if (!geom.IsNull())
|
---|
419 | apply.SetGeometry(geom);
|
---|
420 | MBadPixelsMerge merge(&badpix);
|
---|
421 |
|
---|
422 | // Make sure that pedcamab has the correct name
|
---|
423 | pedcamab.SetName("MPedestalFundamental");
|
---|
424 | pedcamextr.SetName("MPedestalFromExtractorRndm");
|
---|
425 | pedcambias.SetName("MPedestalFromExtractor");
|
---|
426 | plist.AddToList(&pedcamextr);
|
---|
427 | plist.AddToList(&pedcambias);
|
---|
428 | plist.AddToList(&pedcamab);
|
---|
429 |
|
---|
430 | MArrivalTimeCam timecam;
|
---|
431 | plist.AddToList(&timecam);
|
---|
432 |
|
---|
433 | // Check for interleaved events
|
---|
434 | MCalibrationPatternDecode caldec;
|
---|
435 | MTriggerPatternDecode decode;
|
---|
436 |
|
---|
437 | // This will make that for data with version less than 5, where
|
---|
438 | // trigger patterns were not yet correct, all the events in the real
|
---|
439 | // data file will be processed. In any case there are no interleaved
|
---|
440 | // calibration events in such data, so this is fine.
|
---|
441 | MFTriggerPattern ftp;
|
---|
442 | ftp.SetDefault(kTRUE);
|
---|
443 | // ftp.RequireCalibration();
|
---|
444 | ftp.DenyCalibration();
|
---|
445 | ftp.DenyPedestal();
|
---|
446 | // ftp.DenyPinDiode();
|
---|
447 | ftp.SetInverted();
|
---|
448 |
|
---|
449 | // This will skip interleaved calibration events and pedestal events (if any)
|
---|
450 | // --> tlist2
|
---|
451 | MContinue conttp(&ftp, "ContTrigPattern");
|
---|
452 |
|
---|
453 | // Create the pedestal subtracted raw-data
|
---|
454 | MPedestalSubtract pedsub;
|
---|
455 | pedsub.SetPedestalCam(&pedcamab);
|
---|
456 |
|
---|
457 | // Do signal and pedestal calculation
|
---|
458 | MPedCalcFromLoGain pedlo1("MPedCalcFundamental");
|
---|
459 | pedlo1.SetPedestalUpdate(kTRUE);
|
---|
460 | pedlo1.SetNamePedestalCamOut("MPedestalFundamental");
|
---|
461 |
|
---|
462 | MPedCalcFromLoGain pedlo2("MPedCalcWithExtractorRndm");
|
---|
463 | pedlo2.SetPedestalUpdate(kTRUE);
|
---|
464 | pedlo2.SetRandomCalculation(kTRUE);
|
---|
465 | pedlo2.SetNamePedestalCamIn("MPedestalFundamental");
|
---|
466 | pedlo2.SetNamePedestalCamOut("MPedestalFromExtractorRndm");
|
---|
467 |
|
---|
468 | MPedCalcFromLoGain pedlo3("MPedCalcWithExtractor");
|
---|
469 | pedlo3.SetPedestalUpdate(kTRUE);
|
---|
470 | pedlo3.SetRandomCalculation(kFALSE);
|
---|
471 | pedlo3.SetNamePedestalCamIn("MPedestalFundamental");
|
---|
472 | pedlo3.SetNamePedestalCamOut("MPedestalFromExtractor");
|
---|
473 |
|
---|
474 | if (extractor1)
|
---|
475 | {
|
---|
476 | extractor1->SetPedestals(&pedcamab);
|
---|
477 |
|
---|
478 | // Setup to use the hi-gain extraction window in the lo-gain
|
---|
479 | // range (the start of the lo-gain range is added automatically
|
---|
480 | // by MPedCalcFromLoGain)
|
---|
481 | //
|
---|
482 | // The window size of the extractor is not yet initialized,
|
---|
483 | // so we have to stick to the extraction range
|
---|
484 | const Int_t f = extractor1->GetHiGainFirst();
|
---|
485 | const Int_t l = extractor1->GetHiGainLast();
|
---|
486 | const Int_t w = (l-f+1)&~1;
|
---|
487 |
|
---|
488 | pedlo1.SetExtractWindow(f, w);
|
---|
489 |
|
---|
490 | if (extractor1->InheritsFrom("MExtractTimeAndCharge"))
|
---|
491 | {
|
---|
492 | pedlo2.SetExtractor((MExtractTimeAndCharge*)extractor1);
|
---|
493 | pedlo3.SetExtractor((MExtractTimeAndCharge*)extractor1);
|
---|
494 | /*
|
---|
495 | const Int_t win = ((MExtractTimeAndCharge*)extractor1)->GetWindowSizeHiGain();
|
---|
496 | pedlo1.SetExtractWindow(15, win);
|
---|
497 | pedlo2.SetExtractWindow(15, win//obsolete//);
|
---|
498 | pedlo3.SetExtractWindow(15, win//obsolete//);
|
---|
499 | */
|
---|
500 | }
|
---|
501 | else
|
---|
502 | {
|
---|
503 | /*
|
---|
504 | // FIXME: How to get the fixed value 15 automatically?
|
---|
505 | const Int_t f = (Int_t)(15.5+extractor1->GetHiGainFirst());
|
---|
506 | const Int_t n = (Int_t)(15.5+extractor1->GetNumHiGainSamples());
|
---|
507 | pedlo1.SetExtractWindow(f, n);
|
---|
508 | pedlo2.SetExtractWindow(f, n);
|
---|
509 | pedlo3.SetExtractWindow(f, n);
|
---|
510 | */
|
---|
511 | pedlo2.SetExtractWindow(f, w);
|
---|
512 | pedlo3.SetExtractWindow(f, w);
|
---|
513 |
|
---|
514 | }
|
---|
515 | }
|
---|
516 | if (extractor2)
|
---|
517 | extractor2->SetPedestals(&pedcamab);
|
---|
518 |
|
---|
519 | if (extractor3)
|
---|
520 | extractor3->SetPedestals(&pedcamab);
|
---|
521 |
|
---|
522 | MFCosmics fcosmics;
|
---|
523 | fcosmics.SetNamePedestalCam("MPedestalFundamental");
|
---|
524 | MContinue contcos(&fcosmics, "ContTrigEvts");
|
---|
525 | contcos.SetInverted();
|
---|
526 |
|
---|
527 | //MMcPedestalCopy pcopy;
|
---|
528 | MTaskEnv taskenv1("ExtractSignal");
|
---|
529 | MTaskEnv taskenv2("ExtractTime");
|
---|
530 | MTaskEnv taskenv3("ExtractInterlaced");
|
---|
531 | taskenv1.SetDefault(extractor1);
|
---|
532 | taskenv2.SetDefault(extractor2);
|
---|
533 | taskenv3.SetDefault(extractor3);
|
---|
534 |
|
---|
535 | //
|
---|
536 | // This is new calibration to photo-electrons, hard-coded
|
---|
537 | // as decided at the Wuerzburg software meeting 26.01.05
|
---|
538 | //
|
---|
539 | MCalibrateData calib;
|
---|
540 | calib.SetSignalType(MCalibrateData::kPhe);
|
---|
541 | calib.AddPedestal("Fundamental");
|
---|
542 | calib.AddPedestal("FromExtractor");
|
---|
543 | calib.AddPedestal("FromExtractorRndm");
|
---|
544 | calib.SetPedestalFlag(MCalibrateData::kEvent);
|
---|
545 | //----------------------------------------------------------
|
---|
546 |
|
---|
547 | MExtractPINDiode pinext;
|
---|
548 | MExtractBlindPixel bldext;
|
---|
549 |
|
---|
550 | MFTriggerPattern fcalib("CalibFilter");
|
---|
551 | fcalib.SetDefault(kFALSE);
|
---|
552 | fcalib.RequireCalibration();
|
---|
553 |
|
---|
554 | MCalibrationChargeCalc chcalc;
|
---|
555 | chcalc.SetExtractor(extractor3);
|
---|
556 |
|
---|
557 | MCalibrationRelTimeCalc recalc;
|
---|
558 | MCalibCalcFromPast pacalc;
|
---|
559 |
|
---|
560 | pinext.SetPedestals(&pedcamab);
|
---|
561 | bldext.SetPedestals(&pedcamab);
|
---|
562 | chcalc.SetPedestals(&pedcamextr);
|
---|
563 |
|
---|
564 | pacalc.SetChargeCalc(&chcalc);
|
---|
565 | if (fIsRelTimesUpdate)
|
---|
566 | pacalc.SetRelTimeCalc(&recalc);
|
---|
567 | pacalc.SetCalibrate(&calib);
|
---|
568 |
|
---|
569 | //
|
---|
570 | // Intensity Calibration histogramming
|
---|
571 | //
|
---|
572 | MFillH filpin(&hpndiod, "MExtractedSignalPINDiode", "FillPINDiode");
|
---|
573 | MFillH filbnd(&hbndcam, "MExtractedSignalBlindPixel", "FillBlindCam");
|
---|
574 | MFillH filcam(&hchacam, "MExtractedSignalCam", "FillChargeCam");
|
---|
575 | MFillH filtme(&hrelcam, "MArrivalTimeCam", "FillRelTime");
|
---|
576 | MFillH filhil(&hilocam, "MExtractedSignalCam", "FillHiLoRatio");
|
---|
577 | MFillH filpul(&hpulcam, "MRawEvtData", "FillPulseTime");
|
---|
578 | filpin.SetBit(MFillH::kDoNotDisplay);
|
---|
579 | filbnd.SetBit(MFillH::kDoNotDisplay);
|
---|
580 | filcam.SetBit(MFillH::kDoNotDisplay);
|
---|
581 | filtme.SetBit(MFillH::kDoNotDisplay);
|
---|
582 | filhil.SetBit(MFillH::kDoNotDisplay);
|
---|
583 | filpul.SetBit(MFillH::kDoNotDisplay);
|
---|
584 |
|
---|
585 | MCalibrateRelTimes caltm;
|
---|
586 | MBadPixelsCalc bpcal;
|
---|
587 | MBadPixelsTreat treat;
|
---|
588 |
|
---|
589 | bpcal.SetNamePedPhotCam("MPedPhotFromExtractor");
|
---|
590 | treat.AddNamePedPhotCam("MPedPhotFundamental");
|
---|
591 | treat.AddNamePedPhotCam("MPedPhotFromExtractor");
|
---|
592 | treat.AddNamePedPhotCam("MPedPhotFromExtractorRndm");
|
---|
593 | if (!extractor2 && !extractor1->InheritsFrom("MExtractTimeAndCharge"))
|
---|
594 | treat.SetProcessTimes(kFALSE);
|
---|
595 |
|
---|
596 | MHCamEvent evt0( 0, "PedFLG", "Fundamental Pedestal from Lo Gain;;P [cnts/sl]");
|
---|
597 | MHCamEvent evt1( 2, "PedRmsFLG", "RMS from Extractor applied to ped.;;\\sigma_{p} [cnts/sl]");
|
---|
598 | MHCamEvent evt2( 0, "Extra'd", "Extracted Signal;;S [cnts/sl]");
|
---|
599 | // MHCamEvent evt3(4, "PedPhot", "Calibrated Pedestal;;P [phe]");
|
---|
600 | MHCamEvent evt4( 5, "PedRMS", "Calibrated RMS from Extractor applied to ped.;;\\sigma_{p} [phe]");
|
---|
601 | MHCamEvent evt5( 0, "Interp'd", "Interpolated Signal scaled with A/A_{0};;S [phe]");
|
---|
602 | MHCamEvent evt6(102, "Unsuitable", "Fraction of unsuitable events per Pixel;;[1]");
|
---|
603 | // MHCamEvent evt7( 6, "Times", "Calibrated Arrival Time;;T [fadc sl]");
|
---|
604 | MHCamEvent evt8( 0, "Conv", "Calibration Conv. Factors;;[phe/fadc cnts]");
|
---|
605 | MHCamEvent evt9( 7, "PulsePos", "Pulse Position of cosmics (>50phe);;T");
|
---|
606 | MHCamEvent evtR( 4, "HiLoCal", "Hi-/Lo-Gain ratio;;Ratio");
|
---|
607 | MHCamEvent evtO( 7, "HiLoOff", "Lo-/Hi-Gain Offset;;Offset");
|
---|
608 | evt6.SetThreshold();
|
---|
609 |
|
---|
610 | MFillH fill0(&evt0, "MPedestalFundamental", "FillPedFLG");
|
---|
611 | MFillH fill1(&evt1, "MPedestalFromExtractorRndm", "FillPedRmsFLG");
|
---|
612 | MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtracted");
|
---|
613 | // MFillH fill3(&evt3, "MPedPhotFundamental", "FillPedPhot");
|
---|
614 | MFillH fill4(&evt4, "MPedPhotFromExtractorRndm", "FillPedRMS");
|
---|
615 | MFillH fill5(&evt5, "MSignalCam", "FillInterpolated");
|
---|
616 | MFillH fill6(&evt6, "MBadPixelsCam", "FillUnsuitable");
|
---|
617 | // MFillH fill7(&evt7, "MSignalCam", "FillTimes");
|
---|
618 | MFillH fill8(&evt8, "MCalibrationIntensityConstCam", "FillConv");
|
---|
619 | MFillH fill9(&evt9, "MSignalCam", "FillPulse");
|
---|
620 | MFillH fillR(&evtR, "MExtractedSignalCam", "FillHiLoCal");
|
---|
621 | MFillH fillO(&evtO, "MArrivalTimeCam", "FillHiLoOff");
|
---|
622 |
|
---|
623 | MTaskEnv fillflorian("FinalFantasy");
|
---|
624 | fillflorian.SetDefault();
|
---|
625 |
|
---|
626 | // The second rule is for the case reading raw-files!
|
---|
627 | MWriteRootFile write(2, fname, fOverwrite?"RECREATE":"NEW");
|
---|
628 | // Run Header
|
---|
629 | write.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
630 | write.AddContainer("MBadPixelsCam", "RunHeaders");
|
---|
631 | write.AddContainer("MGeomCam", "RunHeaders");
|
---|
632 | // Monte Carlo Headers
|
---|
633 | write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
|
---|
634 | write.AddContainer("MMcFadcHeader", "RunHeaders", kFALSE);
|
---|
635 | write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
|
---|
636 | write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
|
---|
637 | write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
|
---|
638 | // Monte Carlo
|
---|
639 | write.AddContainer("MMcEvt", "Events", kFALSE);
|
---|
640 | write.AddContainer("MMcTrig", "Events", kFALSE);
|
---|
641 | // Data tree
|
---|
642 | write.AddContainer("MSignalCam", "Events");
|
---|
643 | write.AddContainer("MPedPhotFundamental", "Events");
|
---|
644 | write.AddContainer("MPedPhotFromExtractor", "Events");
|
---|
645 | write.AddContainer("MPedPhotFromExtractorRndm", "Events");
|
---|
646 | write.AddContainer("MTime", "Events", kFALSE);
|
---|
647 | write.AddContainer("MRawEvtHeader", "Events");
|
---|
648 | // Slow-Control: Current-tree
|
---|
649 | write.AddContainer("MTimeCurrents", "Currents", kFALSE);
|
---|
650 | write.AddContainer("MCameraDC", "Currents", kFALSE);
|
---|
651 | write.AddContainer("MReportCurrents", "Currents", kFALSE);
|
---|
652 | // Slow-Control: Camera-tree
|
---|
653 | write.AddContainer("MReportCamera", "Camera", kFALSE);
|
---|
654 | write.AddContainer("MTimeCamera", "Camera", kFALSE);
|
---|
655 | write.AddContainer("MCameraAUX", "Camera", kFALSE);
|
---|
656 | write.AddContainer("MCameraCalibration", "Camera", kFALSE);
|
---|
657 | write.AddContainer("MCameraCooling", "Camera", kFALSE);
|
---|
658 | write.AddContainer("MCameraHV", "Camera", kFALSE);
|
---|
659 | write.AddContainer("MCameraLV", "Camera", kFALSE);
|
---|
660 | write.AddContainer("MCameraLids", "Camera", kFALSE);
|
---|
661 | // Slow-Control: Trigger-tree
|
---|
662 | write.AddContainer("MReportTrigger", "Trigger", kFALSE);
|
---|
663 | write.AddContainer("MTimeTrigger", "Trigger", kFALSE);
|
---|
664 | // Slow-Control: Drive-tree
|
---|
665 | write.AddContainer("MReportDrive", "Drive", kFALSE);
|
---|
666 | write.AddContainer("MTimeDrive", "Drive", kFALSE);
|
---|
667 | // Slow-Control: Central Control-tree
|
---|
668 | write.AddContainer("MReportCC", "CC", kFALSE);
|
---|
669 | write.AddContainer("MTimeCC", "CC", kFALSE);
|
---|
670 |
|
---|
671 | // Write the special MC tree
|
---|
672 | MWriteRootFile writemc(2, fname, fOverwrite?"RECREATE":"NEW");
|
---|
673 | writemc.SetName("WriteMC");
|
---|
674 | writemc.AddContainer("MMcEvtBasic", "OriginalMC");
|
---|
675 |
|
---|
676 | // Now setup tasklist for events
|
---|
677 | MTaskList tlist2;
|
---|
678 |
|
---|
679 | tlist2.AddToList(&caldec);
|
---|
680 | tlist2.AddToList(&decode);
|
---|
681 | tlist2.AddToList(&apply);
|
---|
682 | tlist2.AddToList(&merge);
|
---|
683 | tlist2.AddToList(&pedsub);
|
---|
684 | tlist2.AddToList(&pedlo1);
|
---|
685 | tlist2.AddToList(&pedlo2);
|
---|
686 | tlist2.AddToList(&pedlo3);
|
---|
687 | //-----------------------------------------------------------
|
---|
688 |
|
---|
689 | MTaskList tlist3;
|
---|
690 | tlist3.SetFilter(&fcalib);
|
---|
691 |
|
---|
692 | if (fIsInterlaced)
|
---|
693 | {
|
---|
694 | tlist2.AddToList(&fcalib);
|
---|
695 | tlist2.AddToList(&tlist3);
|
---|
696 |
|
---|
697 | if (IsUsePINDiode())
|
---|
698 | tlist3.AddToList(&pinext);
|
---|
699 | if (IsUseBlindPixel())
|
---|
700 | tlist3.AddToList(&bldext);
|
---|
701 | tlist3.AddToList(&taskenv3);
|
---|
702 | tlist3.AddToList(&pacalc);
|
---|
703 | tlist3.AddToList(&filcam);
|
---|
704 | if (fIsRelTimesUpdate)
|
---|
705 | tlist3.AddToList(&filtme);
|
---|
706 | if (IsUseBlindPixel())
|
---|
707 | tlist3.AddToList(&filbnd);
|
---|
708 | if (IsUsePINDiode())
|
---|
709 | tlist3.AddToList(&filpin);
|
---|
710 | tlist3.AddToList(&chcalc);
|
---|
711 | if (fIsRelTimesUpdate)
|
---|
712 | tlist3.AddToList(&recalc);
|
---|
713 | }
|
---|
714 |
|
---|
715 | // Continue for all non-cosmic events
|
---|
716 | tlist2.AddToList(&conttp);
|
---|
717 | if (extractor1)
|
---|
718 | tlist2.AddToList(&taskenv1);
|
---|
719 | if (extractor2)
|
---|
720 | tlist2.AddToList(&taskenv2);
|
---|
721 | tlist2.AddToList(&fill0);
|
---|
722 | tlist2.AddToList(&fill1);
|
---|
723 | tlist2.AddToList(&contcos);
|
---|
724 | if (fIsHiLoCalibration)
|
---|
725 | {
|
---|
726 | plist.AddToList(&hilocam);
|
---|
727 | tlist2.AddToList(&filhil);
|
---|
728 | }
|
---|
729 | if (fIsPulsePosCheck)
|
---|
730 | {
|
---|
731 | plist.AddToList(&hpulcam);
|
---|
732 | tlist2.AddToList(&filpul);
|
---|
733 | }
|
---|
734 |
|
---|
735 | tlist2.AddToList(&fill2);
|
---|
736 | tlist2.AddToList(&calib);
|
---|
737 | if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
|
---|
738 | tlist2.AddToList(&caltm);
|
---|
739 | if (fIsInterlaced)
|
---|
740 | tlist2.AddToList(&fill8);
|
---|
741 | tlist2.AddToList(&bpcal);
|
---|
742 | tlist2.AddToList(&treat);
|
---|
743 | tlist2.AddToList(&fill6);
|
---|
744 | // tlist2.AddToList(&fill3);
|
---|
745 | tlist2.AddToList(&fill4);
|
---|
746 | tlist2.AddToList(&fill5);
|
---|
747 | //if (extractor2 || extractor1->InheritsFrom("MExtractTimeAndCharge"))
|
---|
748 | // tlist2.AddToList(&fill7);
|
---|
749 | tlist2.AddToList(&fill9);
|
---|
750 | tlist2.AddToList(&fillR);
|
---|
751 | tlist2.AddToList(&fillO);
|
---|
752 |
|
---|
753 | tlist2.AddToList(&fillflorian);
|
---|
754 |
|
---|
755 | // Setup List for Drive-tree
|
---|
756 | //MPointingPosCalc pcalc;
|
---|
757 |
|
---|
758 | // Now setup main tasklist
|
---|
759 | tlist.AddToList(read);
|
---|
760 |
|
---|
761 | if (IsUseMC())
|
---|
762 | {
|
---|
763 | tlist.AddToList(&writemc);
|
---|
764 | tlist.AddToList(&contmc);
|
---|
765 | }
|
---|
766 |
|
---|
767 | //if (IsUseRootData())
|
---|
768 | // tlist2.AddToList(&pextr);
|
---|
769 | tlist.AddToList(&tlist2, IsUseRootData() ? "Events" : "All");
|
---|
770 |
|
---|
771 | //if (IsUseMC())
|
---|
772 | // tlist.AddToList(&pcalc, "Drive");
|
---|
773 |
|
---|
774 | tlist.AddToList(&write);
|
---|
775 |
|
---|
776 | // Create and setup the eventloop
|
---|
777 | MEvtLoop evtloop(fName);
|
---|
778 | evtloop.SetParList(&plist);
|
---|
779 | evtloop.SetDisplay(fDisplay);
|
---|
780 | evtloop.SetLogStream(fLog);
|
---|
781 | if (!SetupEnv(evtloop))
|
---|
782 | return kFALSE;
|
---|
783 |
|
---|
784 | // Execute first analysis
|
---|
785 | const Bool_t rc = evtloop.Eventloop(fMaxEvents);
|
---|
786 |
|
---|
787 | // make sure owned object are deleted
|
---|
788 | if (extractor1 && extractor1!=fExtractor)
|
---|
789 | delete extractor1;
|
---|
790 | if (extractor2)
|
---|
791 | delete extractor2;
|
---|
792 | if (extractor3)
|
---|
793 | delete extractor3;
|
---|
794 |
|
---|
795 | // return if job failed
|
---|
796 | if (!rc)
|
---|
797 | {
|
---|
798 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
799 | return kFALSE;
|
---|
800 | }
|
---|
801 |
|
---|
802 | // if everything went ok write and display result
|
---|
803 | DisplayResult(plist);
|
---|
804 |
|
---|
805 | if (fIsPixelCheck)
|
---|
806 | {
|
---|
807 | if (fIsPulsePosCheck)
|
---|
808 | hpulcam[fCheckedPixId].DrawClone("");
|
---|
809 |
|
---|
810 | if (fIsHiLoCalibration)
|
---|
811 | hilocam[fCheckedPixId].DrawClone("");
|
---|
812 | }
|
---|
813 |
|
---|
814 | interlacedcont.Add(&pulcam);
|
---|
815 |
|
---|
816 | if (fIsHiLoCalibration)
|
---|
817 | interlacedcont.Add(&hilcam);
|
---|
818 |
|
---|
819 | if (fIsPulsePosCheck)
|
---|
820 | interlacedcont.Add(plist.FindObject("MHCalibrationPulseTimeCam"));
|
---|
821 |
|
---|
822 | if (fIsHiLoCalibration)
|
---|
823 | interlacedcont.Add(plist.FindObject("MHCalibrationHiLoCam"));
|
---|
824 |
|
---|
825 | if (!WriteResult(interlacedcont))
|
---|
826 | return kFALSE;
|
---|
827 |
|
---|
828 | // return if job went ok
|
---|
829 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
---|
830 | *fLog << endl << endl;
|
---|
831 |
|
---|
832 | return kTRUE;
|
---|
833 | }
|
---|
834 |
|
---|
835 |
|
---|
836 | void MJCalibrateSignal::DisplayResult(MParList &plist)
|
---|
837 | {
|
---|
838 | if (!fDisplay || !fIsHiLoCalibration)
|
---|
839 | return;
|
---|
840 |
|
---|
841 | MCalibrationHiLoCam *hcam = (MCalibrationHiLoCam*)plist.FindObject("MCalibrationHiLoCam");
|
---|
842 | MGeomCam *geom = (MGeomCam*)plist.FindObject("MGeomCam");
|
---|
843 | if (!hcam || !geom)
|
---|
844 | return;
|
---|
845 |
|
---|
846 | // Create histograms to display
|
---|
847 | MHCamera disp1(*geom, "HiLoConv", "Ratio Amplification HiGain vs. LoGain (Charges)");
|
---|
848 | MHCamera disp2(*geom, "HiLoDiff", "Arrival Time Diff. HiGain vs. LoGain (Times)");
|
---|
849 |
|
---|
850 | disp1.SetCamContent(*hcam, 0);
|
---|
851 | disp1.SetCamError( *hcam, 1);
|
---|
852 | disp2.SetCamContent(*hcam, 5);
|
---|
853 | disp2.SetCamError( *hcam, 6);
|
---|
854 |
|
---|
855 | disp1.SetYTitle("R [1]");
|
---|
856 | disp2.SetYTitle("\\Delta T [FADC sl.]");
|
---|
857 |
|
---|
858 | TCanvas &c1 = fDisplay->AddTab("HiLoConv");
|
---|
859 | c1.Divide(2,3);
|
---|
860 |
|
---|
861 | disp1.CamDraw(c1, 1, 2, 1);
|
---|
862 | disp2.CamDraw(c1, 2, 2, 1);
|
---|
863 | }
|
---|
864 |
|
---|