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

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