source: trunk/MagicSoft/Mars/mjobs/MJCut.cc@ 7579

Last change on this file since 7579 was 7566, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 28.9 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/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJCut
28//
29// FIXME: Preparation for wobble mode missing
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MJCut.h"
33
34// Root
35#include <TEnv.h>
36#include <TFile.h>
37
38// Environment
39#include "MLog.h"
40#include "MLogManip.h"
41
42// Eventloop
43#include "MParList.h"
44#include "MTaskList.h"
45#include "MEvtLoop.h"
46
47// Display
48#include "MStatusDisplay.h"
49
50// Tasks
51#include "MReadReports.h"
52#include "MReadMarsFile.h"
53#include "MPrint.h"
54#include "MContinue.h"
55#include "MTaskEnv.h"
56#include "MPointingDevCalc.h"
57#include "MSrcPosRndm.h"
58#include "MSrcPosCalc.h"
59#include "MSrcPosCorrect.h"
60#include "MHillasCalc.h"
61#include "MFillH.h"
62#include "MWriteRootFile.h"
63
64// Fit signal environment
65#include "../mhflux/MAlphaFitter.h"
66#include "../mhflux/MHAlpha.h"
67
68// Containers
69#include "MH3.h"
70#include "MBinning.h"
71#include "MDataSet.h"
72#include "MParameters.h"
73#include "MPointingPos.h"
74#include "MObservatory.h"
75#include "MHSrcPosCam.h"
76
77ClassImp(MJCut);
78
79using namespace std;
80
81// --------------------------------------------------------------------------
82//
83// Default constructor. Set defaults for fStoreSummary, fStoreresult,
84// fWriteOnly, fIsWobble and fFullDisplay to kFALSE and initialize
85// /*fEstimateEnergy and*/ fCalcHadronness with NULL.
86//
87MJCut::MJCut(const char *name, const char *title)
88 : fStoreSummary(kFALSE), fStoreResult(kTRUE), fWriteOnly(kFALSE),
89 fIsWobble(kFALSE), fIsMonteCarlo(kFALSE), fFullDisplay(kTRUE),
90 fRndmSrcPos(kFALSE), fNameHist("MHThetaSq"), fCalcHadronness(0), fCalcDisp(0)
91{
92 fName = name ? name : "MJCut";
93 fTitle = title ? title : "Standard program to perform g/h-separation cuts";
94}
95
96// --------------------------------------------------------------------------
97//
98// Destructor. Delete fEstimateEnergy and fCalcHadronness if != NULL
99//
100MJCut::~MJCut()
101{
102 //if (fEstimateEnergy)
103 // delete fEstimateEnergy;
104 if (fCalcHadronness)
105 delete fCalcHadronness;
106 if (fCalcDisp)
107 delete fCalcDisp;
108}
109
110// --------------------------------------------------------------------------
111//
112// Set the name of the summary file (events after cut0)
113// If you give a name the storage of this file is enabled implicitly.
114// If you give no filename the storage is neither enabled nor disabled,
115// but the storage file name is reset.
116// If no filename is set the default filename is used.
117// You can explicitly enable or disable the storage using EnableStoreOf*()
118// The default argument is no filename.
119//
120void MJCut::SetNameSummaryFile(const char *name)
121{
122 fNameSummary=name;
123 if (!fNameSummary.IsNull())
124 EnableStorageOfSummary();
125}
126
127// --------------------------------------------------------------------------
128//
129// Set the name of the summary file (events after cut3)
130// If you give a name the storage of this file is enabled implicitly.
131// If you give no filename the storage is neither enabled nor disabled,
132// but the storage file name is reset.
133// If no filename is set the default filename is used.
134// You can explicitly enable or disable the storage using EnableStoreOf*()
135// The default argument is no filename.
136//
137void MJCut::SetNameResultFile(const char *name)
138{
139 fNameResult=name;
140 if (!fNameResult.IsNull())
141 EnableStorageOfResult();
142}
143
144// --------------------------------------------------------------------------
145//
146// Setup a task estimating the energy. The given task is cloned.
147//
148/*
149void MJCut::SetEnergyEstimator(const MTask *task)
150{
151 if (fEstimateEnergy)
152 delete fEstimateEnergy;
153 fEstimateEnergy = task ? (MTask*)task->Clone() : 0;
154}
155*/
156
157// --------------------------------------------------------------------------
158//
159// Setup a task calculating the hadronness. The given task is cloned.
160//
161void MJCut::SetHadronnessCalculator(const MTask *task)
162{
163 if (fCalcHadronness)
164 delete fCalcHadronness;
165 fCalcHadronness = task ? (MTask*)task->Clone() : 0;
166}
167
168// --------------------------------------------------------------------------
169//
170// Setup a task calculating disp. The given task is cloned.
171//
172void MJCut::SetDispCalculator(const MTask *task)
173{
174 if (fCalcDisp)
175 delete fCalcDisp;
176 fCalcDisp = task ? (MTask*)task->Clone() : 0;
177}
178
179// --------------------------------------------------------------------------
180//
181// return fOutputPath+"/ganymed%08d.root", num
182//
183TString MJCut::GetOutputFile(UInt_t num) const
184{
185 TString p(fPathOut);
186 p += "/";
187 p += fNameOutput.IsNull() ? Form("ganymed%08d.root", num) : fNameOutput.Data();
188 gSystem->ExpandPathName(p);
189 return p;
190}
191
192/*
193Bool_t MJCut::ReadTasks(const char *fname, MTask* &env1, MTask* &env2) const
194{
195 // const TString fname = Form("%s/calib%08d.root", fPathIn.Data(), fSequence.GetSequence());
196
197 *fLog << inf << "Reading from file: " << fname << endl;
198
199 TFile file(fname, "READ");
200 if (!file.IsOpen())
201 {
202 *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
203 return kFALSE;
204 }
205
206 TObject *o = file.Get("EstimateEnergy");
207 if (o && !o->InheritsFrom(MTask::Class()))
208 {
209 *fLog << err << dbginf << "ERROR - EstimateEnergy read from " << fname << " doesn't inherit from MTask!" << endl;
210 return kFALSE;
211 }
212 env1 = o ? (MTask*)o->Clone() : FNULL;
213
214 o = file.Get("CalcHadronness");
215 if (o && !o->InheritsFrom(MTask::Class()))
216 {
217 *fLog << err << dbginf << "ERROR - CalcHadronness read from " << fname << " doesn't inherit from MTask!" << endl;
218 return kFALSE;
219 }
220 env2 = o ? (MTask*)o->Clone() : NULL;
221
222 return kTRUE;
223}
224*/
225
226// --------------------------------------------------------------------------
227//
228// Write the tasks in cont to the file corresponding to analysis number num,
229// see GetOutputFile()
230//
231Bool_t MJCut::WriteTasks(UInt_t num, TObjArray &cont) const
232{
233 if (fPathOut.IsNull())
234 {
235 *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
236 return kTRUE;
237 }
238
239 const TString oname(GetOutputFile(num));
240
241 *fLog << inf << "Writing to file: " << oname << endl;
242
243 TFile *file = 0;
244 if (fNameResult.IsNull() && fStoreResult)
245 {
246 file = (TFile*)gROOT->GetListOfFiles()->FindObject(oname);
247 if (file)
248 file->cd();
249 }
250 else
251 file = TFile::Open(oname, fOverwrite?"RECREATE":"NEW", "File created by MJCut", 9);
252
253 if (!file)
254 {
255 *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
256 return kFALSE;
257 }
258
259 const Bool_t rc = WriteContainer(cont);
260
261 if (!(fNameResult.IsNull() && fStoreResult))
262 delete file;
263
264 return rc;
265}
266
267// --------------------------------------------------------------------------
268//
269// Write the result plots and other results to the file corresponding to
270// analysis number num, see GetOutputFile()
271//
272Bool_t MJCut::WriteResult(const MParList &plist, UInt_t num) const
273{
274 TObjArray arr;
275
276 // Save all MBinnings
277 TIter Next(plist);
278 TObject *o=0;
279 while ((o=Next()))
280 if (o->InheritsFrom(MBinning::Class()))
281 arr.Add(o);
282
283 // Save also the result, not only the setup
284 const MHAlpha *halpha = (MHAlpha*)plist.FindObject("Hist", "MHAlpha");
285 if (halpha)
286 arr.Add((TObject*)(&halpha->GetAlphaFitter()));
287
288 const TString fname(fNameOutput.IsNull() ? Form("ganymed%08d.root", num) : fNameOutput.Data());
289
290 // If requested, write to already open output file
291 if (fNameResult.IsNull() && fStoreResult)
292 {
293 TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(fname);
294 if (file)
295 {
296 file->cd();
297 return WriteContainer(arr);
298 }
299 }
300
301 return WriteContainer(arr, fname, "UPDATE");
302}
303
304// --------------------------------------------------------------------------
305//
306// MJCut allows to setup several option by a resource file:
307// MJCut.WriteSummary: yes, no
308// MJCut.SummaryFile: filename
309// MJCut.WriteResult: yes, no
310// MJCut.ResultFile: filename
311// MJCut.HistName: MHAlpha
312//
313Bool_t MJCut::CheckEnvLocal()
314{
315 const TString f0(GetEnv("SummaryFile", ""));
316 const TString f1(GetEnv("ResultFile", ""));
317 if (!f0.IsNull())
318 SetNameSummaryFile(f0);
319 if (!f1.IsNull())
320 SetNameResultFile(f1);
321
322 EnableStorageOfSummary(GetEnv("SummaryFile", fStoreSummary));
323 EnableStorageOfResult(GetEnv("ResultFile", fStoreResult));
324 EnableWobbleMode(GetEnv("WobbleMode", fIsWobble));
325 EnableMonteCarloMode(GetEnv("MonteCarlo", fIsMonteCarlo));
326 EnableFullDisplay(GetEnv("FullDisplay", fFullDisplay));
327 EnableRandomSrcPos(GetEnv("RandomSourcePosition", fRndmSrcPos));
328 //EnableSubstraction(GetEnv("HistogramSubstraction", fSubstraction));
329
330 SetNameHist(GetEnv("NameHist", fNameHist));
331 SetNameHistFS(GetEnv("NameHistFS", fNameHistFS));
332
333 return kTRUE;
334}
335
336// --------------------------------------------------------------------------
337//
338// Setup write to write:
339// container tree optional?
340// -------------- ---------- -----------
341// "MHillas" to "Events"
342// "MHillasSrc" to "Events"
343// "Hadronness" to "Events" yes
344// "MEnergyEst" to "Events" yes
345// "DataType" to "Events"
346//
347void MJCut::SetupWriter(MWriteRootFile *write, const char *name) const
348{
349 if (!write)
350 return;
351
352 write->SetName(name);
353 write->AddContainer("MHillas", "Events");
354 write->AddContainer("MHillasSrc", "Events");
355 write->AddContainer("MHillasExt", "Events");
356 write->AddContainer("MPointingPos", "Events");
357 write->AddContainer("MHillasSrcAnti", "Events", kFALSE);
358 write->AddContainer("MImagePar", "Events", kFALSE);
359 write->AddContainer("MNewImagePar", "Events", kFALSE);
360 write->AddContainer("MNewImagePar2", "Events", kFALSE);
361 write->AddContainer("Hadronness", "Events", kFALSE);
362 write->AddContainer("MSrcPosCam", "Events", kFALSE);
363 write->AddContainer("MSrcPosAnti", "Events", kFALSE);
364 write->AddContainer("ThetaSquared", "Events", kFALSE);
365 write->AddContainer("OpticalAxis", "Events", kFALSE);
366 write->AddContainer("Disp", "Events", kFALSE);
367 write->AddContainer("MTime", "Events", kFALSE);
368 write->AddContainer("MMcEvt", "Events", kFALSE);
369 write->AddContainer("DataType", "Events");
370 // write->AddContainer("MMuonSearchPar", "Events", kFALSE);
371 // write->AddContainer("MMuonCalibPar", "Events", kFALSE);
372}
373
374// --------------------------------------------------------------------------
375//
376// Create a new instance of an object with name name of class
377// type fNameHist in parlist. It must derive from MHAlpha.
378// Call ForceUsingSize for it and return its pointer.
379// If something fails NULL is returned.
380//
381MHAlpha *MJCut::CreateNewHist(MParList &plist, const char *name) const
382{
383 TClass *cls = gROOT->GetClass(fNameHist);
384 if (!cls)
385 {
386 *fLog << err << "Class " << fNameHist << " not found in dictionary... abort." << endl;
387 return NULL;
388 }
389 if (!cls->InheritsFrom(MHAlpha::Class()))
390 {
391 *fLog << err << "Class " << fNameHist << " doesn't inherit from MHAlpha... abort." << endl;
392 return NULL;
393 }
394
395 const TString objname(Form("Hist%s", name));
396 MHAlpha *h = (MHAlpha*)plist.FindCreateObj(fNameHist, objname);
397 if (!h)
398 return NULL;
399
400 h->ForceUsingSize();
401
402 return h;
403}
404
405// --------------------------------------------------------------------------
406//
407// Create a new instance of an object with name name of class
408// type fNameHistFS in parlist. It must derive from MHFalseSource
409// If something fails NULL is returned.
410//
411MH *MJCut::CreateNewHistFS(MParList &plist, const char *name) const
412{
413 const TString cname(fNameHistFS.IsNull()?"MHFalseSource":fNameHistFS);
414
415 TClass *cls = gROOT->GetClass(cname);
416 if (!cls)
417 {
418 *fLog << err << "Class " << cname << " not found in dictionary... abort." << endl;
419 return NULL;
420 }
421 if (!cls->InheritsFrom("MHFalseSource"))
422 {
423 *fLog << err << "Class " << cname << " doesn't inherit from MHFalseSource... abort." << endl;
424 return NULL;
425 }
426
427 const TString objname(Form("FS%s", name));
428 return (MH*)plist.FindCreateObj(cname, objname);
429}
430
431Bool_t MJCut::FillSrcPosCam(const MDataSet &set, MPointingPos &source, MHSrcPosCam &hsrcpos)
432{
433 *fLog << inf;
434 fLog->Separator(GetDescriptor());
435 *fLog << "Filling MHSrcPosCam " << set.GetName() << endl;
436 *fLog << endl;
437
438 // --------------------------------------------------------------------------------
439
440 // Setup Parlist
441 MParList plist;
442 plist.AddToList(this); // take care of fDisplay!
443
444 // Setup Tasklist
445 MTaskList tlist;
446 plist.AddToList(&tlist);
447
448 // La Palma Magic1, Possible source position
449 MObservatory obs;
450 plist.AddToList(&obs);
451 plist.AddToList(&source);
452
453 // Initialize default binnings
454 // MBinning bins1(18, 0, 90, "BinningSrcPosCam", "lin");
455 // plist.AddToList(&bins1);
456
457 // ------------- Loop Off Data --------------------
458 MReadReports read;
459
460 read.EnableAutoScheme();
461 read.AddToBranchList("MTimeEffectiveOnTime.*");
462 read.AddToBranchList("MEffectiveOnTime.*");
463
464 read.AddTree("Events", "MTime.", MReadReports::kMaster);
465 read.AddTree("Drive", MReadReports::kRequired);
466 read.AddTree("Starguider", MReadReports::kRequired);
467 read.AddTree("EffectiveOnTime");
468
469 set.AddFilesOn(read);
470
471 MFillH fill(&hsrcpos, "MSrcPosCam", "FillSrcPosCam");
472 fill.SetNameTab("SrcPos");
473
474 // How to get source position from off- and on-data?
475 MSrcPosCorrect scor;
476 MSrcPosCalc scalc;
477 scalc.SetMode(MSrcPosCalc::kDefault);
478
479 MPointingDevCalc devcalc;
480
481 tlist.AddToList(&read);
482 tlist.AddToList(&devcalc, "Starguider");
483 tlist.AddToList(&scalc, "Events");
484 tlist.AddToList(&scor, "Events");
485 tlist.AddToList(&fill, "Events");
486
487 // by setting it here it is distributed to all consecutive tasks
488 tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
489 read.SetAccelerator();//MTask::kAccDontReset|MTask::kAccDontCount);
490
491 // Create and setup the eventloop
492 MEvtLoop evtloop(fName);
493 evtloop.SetParList(&plist);
494 evtloop.SetDisplay(fDisplay);
495 evtloop.SetLogStream(fLog);
496 if (!SetupEnv(evtloop))
497 return kFALSE;
498
499 // Execute first analysis
500 if (!evtloop.Eventloop(fMaxEvents))
501 {
502 *fLog << err << GetDescriptor() << ": Processing of on-sequences failed." << endl;
503 return kFALSE;
504 }
505
506 if (!evtloop.GetDisplay())
507 {
508 *fLog << err << GetDescriptor() << ": Execution stopped by user." << endl;
509 return kFALSE;
510 }
511
512 *fLog << all << GetDescriptor() << ": Done." << endl;
513 *fLog << endl << endl;
514
515 return kTRUE;
516}
517
518Bool_t MJCut::Process(const MDataSet &set)
519{
520 if (!set.IsValid())
521 {
522 *fLog << err << "ERROR - DataSet invalid!" << endl;
523 return kFALSE;
524 }
525
526 CheckEnv();
527
528 // --------------------------------------------------------------------------------
529
530 // Possible source position (eg. Wobble Mode)
531 MPointingPos source("MSourcePos");
532 if (set.HasSource())
533 {
534 if (!set.GetSourcePos(source))
535 return kFALSE;
536 *fLog << all;
537 source.Print("RaDec");
538 }
539 else
540 *fLog << all << "No source position applied..." << endl;
541
542 MParList plist;
543
544 MHSrcPosCam hsrcpos;
545 if (!fIsWobble && source.IsInitialized() && fRndmSrcPos)
546 {
547 if (!FillSrcPosCam(set, source, hsrcpos))
548 return kFALSE;
549 plist.AddToList(&hsrcpos);
550 }
551
552 // --------------------------------------------------------------------------------
553
554 *fLog << inf;
555 fLog->Separator(GetDescriptor());
556 *fLog << "Perform cuts for data set " << set.GetName() << endl;
557 *fLog << endl;
558
559 // --------------------------------------------------------------------------------
560
561 // Setup Parlist
562 plist.AddToList(this); // take care of fDisplay!
563
564 MParameterI par("DataType");
565 plist.AddToList(&par);
566
567 // Setup Tasklist
568 MTaskList tlist;
569 plist.AddToList(&tlist);
570
571 // La Palma Magic1
572 MObservatory obs;
573 plist.AddToList(&obs);
574
575 if (source.IsInitialized())
576 plist.AddToList(&source);
577
578 // Initialize default binnings
579 MBinning bins1(18, 0, 90, "BinningAlpha", "lin");
580 MBinning bins2(15, 10, 1e6 , "BinningSize", "log");
581 MBinning bins3(67, -0.005, 0.665, "BinningTheta", "asin");
582 MBinning bins4("BinningFalseSource");
583 MBinning bins5("BinningWidth");
584 MBinning bins6("BinningLength");
585 MBinning bins7("BinningDist");
586 MBinning bins8("BinningMaxDist");
587 MBinning bins9("BinningM3Long");
588 MBinning bins0("BinningConc1");
589 plist.AddToList(&bins1);
590 plist.AddToList(&bins2);
591 plist.AddToList(&bins3);
592 plist.AddToList(&bins4);
593 plist.AddToList(&bins5);
594 plist.AddToList(&bins6);
595 plist.AddToList(&bins7);
596 plist.AddToList(&bins8);
597 plist.AddToList(&bins9);
598 plist.AddToList(&bins0);
599 //plist.AddToList(&binsa);
600
601 // --------------------------------------------------------------------------------
602
603 // Setup fitter and histograms
604 MAlphaFitter fit;
605 plist.AddToList(&fit);
606 if (fIsWobble)
607 fit.SetScaleMode(MAlphaFitter::kNone);
608
609 MHAlpha *halphaoff = CreateNewHist(plist, "Off");
610 MFillH falpha(halphaoff, "", "FillHist");
611 MH *hfsoff = CreateNewHistFS(plist, "Off");
612 MFillH ffs(hfsoff, "MHillas", "FillFS");
613
614 // FIXME: If fPathIn read cuts and energy estimator from file!
615 MContinue cont0("", "Cut0");
616 MContinue cont1("", "Cut1");
617 MContinue cont2("", "Cut2");
618 MContinue cont3("", "Cut3");
619 cont0.SetAllowEmpty();
620 cont1.SetAllowEmpty();
621 cont2.SetAllowEmpty();
622 cont3.SetAllowEmpty();
623
624 // ------------- Loop Off Data --------------------
625 MReadReports readoffdata;
626 readoffdata.AddTree("Events", "MTime.", MReadReports::kMaster);
627 readoffdata.AddTree("Drive", MReadReports::kRequired);
628 readoffdata.AddTree("Starguider", MReadReports::kRequired);
629 readoffdata.AddTree("EffectiveOnTime");
630
631 MReadMarsFile readoffmc("Events");
632 readoffmc.DisableAutoScheme();
633
634 MRead &readoff = fIsMonteCarlo ? (MRead&)readoffmc : (MRead&)readoffdata;
635 if (fIsWobble)
636 set.AddFilesOn(readoff);
637 else
638 set.AddFilesOff(readoff);
639
640 const TString path(Form("%s/", fPathOut.Data()));
641 TString fname0(path);
642 TString fname1(path);
643 fname0 += fNameSummary.IsNull() ? (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
644 fname1 += fNameResult.IsNull() ? (TString) Form("ganymed%08d.root", set.GetNumAnalysis()) : fNameResult;
645
646 MWriteRootFile *write0 = CanStoreSummary() ? new MWriteRootFile(fPathOut.IsNull()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW") : 0;
647 MWriteRootFile *write1 = CanStoreResult() ? new MWriteRootFile(fPathOut.IsNull()?0:fname1.Data(), fOverwrite?"RECREATE":"NEW") : 0;
648 SetupWriter(write0, "WriteAfterCut0");
649 SetupWriter(write1, "WriteAfterCut3");
650
651 MTaskEnv taskenv2("CalcHadronness");
652 taskenv2.SetDefault(fCalcHadronness);
653
654 MTaskEnv taskenv3("CalcDisp");
655 taskenv3.SetDefault(fCalcDisp);
656
657 // MFillH fill0a("OnPos [MHSrcPosCam]", "MSrcPosCam", "FillSrcPosCam");
658 MFillH fill1a("MHHillasOffPre [MHHillas]", "MHillas", "FillHillasPre");
659 MFillH fill2a("MHHillasOffPost [MHHillas]", "MHillas", "FillHillasPost");
660 MFillH fill3a("MHVsSizeOffPost [MHVsSize]", "MHillasSrc", "FillVsSizePost");
661 MFillH fill4a("MHHilExtOffPost [MHHillasExt]", "MHillasSrc", "FillHilExtPost");
662 MFillH fill5a("MHHilSrcOffPost [MHHillasSrc]", "MHillasSrc", "FillHilSrcPost");
663 MFillH fill6a("MHImgParOffPost [MHImagePar]", "MImagePar", "FillImgParPost");
664 MFillH fill7a("MHNewParOffPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost");
665 fill1a.SetNameTab("PreCut");
666 fill2a.SetNameTab("PostCut");
667 fill3a.SetNameTab("VsSize");
668 fill4a.SetNameTab("HilExt");
669 fill5a.SetNameTab("HilSrc");
670 fill6a.SetNameTab("ImgPar");
671 fill7a.SetNameTab("NewPar");
672
673 MPrint print2("MEffectiveOnTime");
674 print2.EnableSkip();
675
676 // How to get source position from off- and on-data?
677 MSrcPosCalc scalc;
678 scalc.SetMode(fIsWobble?MSrcPosCalc::kWobble:MSrcPosCalc::kOffData); /********************/
679
680 MSrcPosCorrect scor;
681
682 MHillasCalc hcalc;
683 MHillasCalc hcalc2("MHillasCalcAnti");
684 hcalc.SetFlags(MHillasCalc::kCalcHillasSrc);
685 hcalc2.SetFlags(MHillasCalc::kCalcHillasSrc);
686 hcalc2.SetNameHillasSrc("MHillasSrcAnti");
687 hcalc2.SetNameSrcPosCam("MSrcPosAnti");
688
689 MSrcPosRndm srcrndm;
690
691 MTaskList tlist2;
692 tlist2.AddToList(&scalc);
693 tlist2.AddToList(&scor);
694 tlist2.AddToList(&srcrndm);
695 //if (fRndmSrcPos && !fIsWobble)
696 // tlist2.AddToList(&fill0a);
697 tlist2.AddToList(&hcalc);
698 if (fIsWobble)
699 tlist2.AddToList(&hcalc2);
700 //tlist2.AddToList(&taskenv1);
701 tlist2.AddToList(&taskenv2);
702 tlist2.AddToList(&taskenv3);
703 tlist2.AddToList(&cont0);
704 if (write0)
705 tlist2.AddToList(write0);
706 if (!fWriteOnly)
707 tlist2.AddToList(&fill1a);
708 tlist2.AddToList(&cont1);
709 if (!fWriteOnly && (!fIsWobble || !fNameHistFS.IsNull()))
710 tlist2.AddToList(&ffs);
711 tlist2.AddToList(&cont2);
712 if (!fWriteOnly)
713 {
714 tlist2.AddToList(&fill2a);
715 if (fFullDisplay)
716 {
717 tlist2.AddToList(&fill3a);
718 tlist2.AddToList(&fill4a);
719 tlist2.AddToList(&fill5a);
720 tlist2.AddToList(&fill6a);
721 tlist2.AddToList(&fill7a);
722 }
723 }
724 if (!fWriteOnly)
725 tlist2.AddToList(&falpha);
726 tlist2.AddToList(&cont3);
727 if (write1)
728 tlist2.AddToList(write1);
729
730 MPointingDevCalc devcalc;
731
732 tlist.AddToList(&readoff);
733 if (gLog.GetDebugLevel()>4)
734 tlist.AddToList(&print2, "EffectiveOnTime");
735 tlist.AddToList(&devcalc, "Starguider");
736 tlist.AddToList(&tlist2, "Events");
737
738 // by setting it here it is distributed to all consecutive tasks
739 //tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
740
741 par.SetVal(0);
742
743 // Create and setup the eventloop
744 MEvtLoop evtloop(fName);
745 evtloop.SetParList(&plist);
746 evtloop.SetDisplay(fDisplay);
747 evtloop.SetLogStream(fLog);
748 if (!SetupEnv(evtloop))
749 return kFALSE;
750
751 TObjArray cont;
752 cont.Add(&cont0);
753 cont.Add(&cont1);
754 cont.Add(&cont2);
755 cont.Add(&cont3);
756 //if (taskenv1.GetTask())
757 // cont.Add(taskenv1.GetTask());
758 if (taskenv2.GetTask())
759 cont.Add(taskenv2.GetTask());
760 if (taskenv3.GetTask())
761 cont.Add(taskenv3.GetTask());
762
763 if (!WriteTasks(set.GetNumAnalysis(), cont))
764 return kFALSE;
765
766 if (set.HasOffSequences() || fIsWobble)
767 {
768 // Execute first analysis
769 if (!evtloop.Eventloop(fMaxEvents))
770 {
771 *fLog << err << GetDescriptor() << ": Processing of off-sequences failed." << endl;
772 return kFALSE;
773 }
774
775 if (!evtloop.GetDisplay())
776 {
777 *fLog << err << GetDescriptor() << ": Execution stopped by user." << endl;
778 return kFALSE;
779 }
780
781 //plist.FindObject("MTimeEffectiveOnTime")->Clear();
782 }
783 else
784 {
785 // This is the simplest way to remove the two object from the parlist
786 delete halphaoff;
787 delete hfsoff;
788 }
789
790 // ------------- Loop On Data --------------------
791 MReadReports readondata;
792 readondata.AddTree("Events", "MTime.", MReadReports::kMaster);
793 readondata.AddTree("Drive", MReadReports::kRequired);
794 readondata.AddTree("Starguider", MReadReports::kRequired);
795 readondata.AddTree("EffectiveOnTime");
796
797 MReadMarsFile readonmc("Events");
798 readonmc.DisableAutoScheme();
799
800 MRead &readon = fIsMonteCarlo ? (MRead&)readonmc : (MRead&)readondata;
801 set.AddFilesOn(readon);
802
803 scalc.SetMode(MSrcPosCalc::kDefault);
804
805 MFillH fill1b("MHHillasOnPre [MHHillas]", "MHillas", "FillHillasPre");
806 MFillH fill2b("MHHillasOnPost [MHHillas]", "MHillas", "FillHillasPost");
807 MFillH fill3b("MHVsSizeOnPost [MHVsSize]", "MHillasSrc", "FillVsSizePost");
808 MFillH fill4b("MHHilExtOnPost [MHHillasExt]", "MHillasSrc", "FillHilExtPost");
809 MFillH fill5b("MHHilSrcOnPost [MHHillasSrc]", "MHillasSrc", "FillHilSrcPost");
810 MFillH fill6b("MHImgParOnPost [MHImagePar]", "MImagePar", "FillImgParPost");
811 MFillH fill7b("MHNewParOnPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost");
812 fill1b.SetNameTab("PreCut");
813 fill2b.SetNameTab("PostCut");
814 fill3b.SetNameTab("VsSize");
815 fill4b.SetNameTab("HilExt");
816 fill5b.SetNameTab("HilSrc");
817 fill6b.SetNameTab("ImgPar");
818 fill7b.SetNameTab("NewPar");
819 fill1b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
820 fill2b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
821 fill3b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
822 fill4b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
823 fill5b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
824 fill6b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
825 fill7b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
826
827 /*
828 MHVsTime hvs("MEffectiveOnTime.fVal");
829 hvs.SetTitle("Effective On-Time vs. Time;;T_{on}");
830 MFillH fillvs(&hvs, "MTimeEffectiveOnTime", "FillOnTime");
831 fillvs.SetNameTab("OnTime");
832 */
833 MH3 hvs("MPointingPos.fZd");
834 hvs.SetName("Theta");
835 hvs.SetTitle("Effective On-Time vs. Zenith Angle;\\Theta [\\circ];T_{on} [s]");
836 MFillH fillvs(&hvs, "", "FillOnTime");
837 if (!fIsMonteCarlo)
838 fillvs.SetWeight("MEffectiveOnTime");
839 fillvs.SetNameTab("OnTime");
840
841 /*
842 MParameterD weight;
843 weight.SetVal(-1);
844 fill2a.SetWeight(&weight);
845 fill3a.SetWeight(&weight);
846 fill4a.SetWeight(&weight);
847 fill5a.SetWeight(&weight);
848 fill6a.SetWeight(&weight);
849 fill7a.SetWeight(&weight);
850 if (fSubstraction)
851 {
852 fill2a.SetNameTab("PostCut-");
853 fill3a.SetNameTab("VsSize-");
854 fill4a.SetNameTab("HilExt-");
855 fill5a.SetNameTab("HilSrc-");
856 fill6a.SetNameTab("ImgPar-");
857 fill7a.SetNameTab("NewPar-");
858 }
859 */
860 MHAlpha *halphaon=CreateNewHist(plist);
861 MFillH falpha2(halphaon, "", "FillHist");
862 MH *hfs=CreateNewHistFS(plist);
863 MFillH ffs2(hfs, "MHillas", "FillFS");
864 MFillH fillphi("MHPhi", "", "FillPhi");
865 fillphi.SetDrawOption("anticut");
866
867 tlist.Replace(&readon);
868 if (fRndmSrcPos && !fIsWobble)
869 {
870// tlist2.RemoveFromList(&fill0a);
871 tlist2.RemoveFromList(&srcrndm);
872 }
873 if (!fWriteOnly)
874 {
875 tlist2.Replace(&fill1b);
876/* if (fIsWobble)
877 {
878 tlist2.AddToListAfter(&fill2b, &fill2a);
879 tlist2.AddToListAfter(&fill3b, &fill3a);
880 }
881 else
882 */
883 tlist2.Replace(&fill2b);
884 if (fFullDisplay)
885 {
886 tlist2.Replace(&fill3b);
887 tlist2.Replace(&fill4b);
888 tlist2.Replace(&fill5b);
889 tlist2.Replace(&fill6b);
890 tlist2.Replace(&fill7b);
891 }
892 tlist2.Replace(&falpha2);
893 if (!fIsWobble || !fNameHist.IsNull())
894 tlist2.Replace(&ffs2);
895 if (fIsWobble)
896 {
897 tlist2.AddToListAfter(&fillphi, &falpha2);
898 if (!fNameHist.IsNull())
899 tlist2.RemoveFromList(&ffs);
900 }
901
902 if (!fIsMonteCarlo)
903 tlist.AddToList(&fillvs, "EffectiveOnTime");
904 else
905 tlist2.AddToListBefore(&fillvs, &scalc);
906 }
907
908 // by setting it here it is distributed to all consecutive tasks
909 //tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
910
911 par.SetVal(1);
912
913 // Execute first analysis
914 if (!evtloop.Eventloop(fMaxEvents))
915 {
916 *fLog << err << GetDescriptor() << ": Processing of on-sequences failed." << endl;
917 return kFALSE;
918 }
919
920 if (write0)
921 delete write0;
922 if (write1)
923 delete write1;
924
925 // FIXME: Perform fit and plot energy dependant alpha plots
926 // and fit result to new tabs!
927 if (!WriteResult(plist, set.GetNumAnalysis()))
928 return kFALSE;
929
930 *fLog << all << GetDescriptor() << ": Done." << endl;
931 *fLog << endl << endl;
932
933 return kTRUE;
934}
Note: See TracBrowser for help on using the repository browser.