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

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