source: tags/Mars-V0.8.7pre/mjobs/MJCalibrateSignal.cc

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