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

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