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

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