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

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