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

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