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

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