source: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc@ 7072

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