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

Last change on this file since 8590 was 8590, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 31.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/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 arr.Add(const_cast<TEnv*>(GetEnv()));
323
324 return WriteContainer(arr, fname, "UPDATE");
325}
326
327// --------------------------------------------------------------------------
328//
329// MJCut allows to setup several option by a resource file:
330// MJCut.WriteSummary: yes, no
331// MJCut.SummaryFile: filename
332// MJCut.WriteResult: yes, no
333// MJCut.ResultFile: filename
334// MJCut.HistName: MHAlpha
335//
336Bool_t MJCut::CheckEnvLocal()
337{
338 const TString f0(GetEnv("SummaryFile", ""));
339 const TString f1(GetEnv("ResultFile", ""));
340 if (!f0.IsNull())
341 SetNameSummaryFile(f0);
342 if (!f1.IsNull())
343 SetNameResultFile(f1);
344
345 EnableStorageOfSummary(GetEnv("SummaryFile", fStoreSummary));
346 EnableStorageOfResult(GetEnv("ResultFile", fStoreResult));
347 EnableFullDisplay(GetEnv("FullDisplay", fFullDisplay));
348 EnableRandomSrcPos(GetEnv("RandomSourcePosition", fRndmSrcPos));
349 //EnableSubstraction(GetEnv("HistogramSubstraction", fSubstraction));
350
351 SetNameHist(GetEnv("NameHist", fNameHist));
352 SetNameHistFS(GetEnv("NameHistFS", fNameHistFS));
353
354 return kTRUE;
355}
356
357// --------------------------------------------------------------------------
358//
359// Setup write to write:
360// container tree optional?
361// -------------- ---------- -----------
362// "MHillas" to "Events"
363// "MHillasSrc" to "Events"
364// "Hadronness" to "Events" yes
365// "MEnergyEst" to "Events" yes
366// "DataType" to "Events"
367//
368void MJCut::SetupWriter(MWriteRootFile *write, const char *name) const
369{
370 if (!write)
371 return;
372
373 write->SetName(name);
374 write->AddContainer("MHillas", "Events");
375 write->AddContainer("MHillasSrc", "Events");
376 write->AddContainer("MHillasExt", "Events");
377 write->AddContainer("MPointingPos", "Events");
378 write->AddContainer("MHillasSrcAnti", "Events", kFALSE);
379 write->AddContainer("MImagePar", "Events", kFALSE);
380 write->AddContainer("MNewImagePar", "Events", kFALSE);
381 write->AddContainer("MNewImagePar2", "Events", kFALSE);
382 write->AddContainer("Hadronness", "Events", kFALSE);
383 write->AddContainer("MSrcPosCam", "Events", kFALSE);
384 write->AddContainer("MSrcPosAnti", "Events", kFALSE);
385 write->AddContainer("ThetaSquared", "Events", kFALSE);
386 write->AddContainer("OpticalAxis", "Events", kFALSE);
387 write->AddContainer("Disp", "Events", kFALSE);
388 write->AddContainer("MEnergyEst", "Events", kFALSE);
389 write->AddContainer("MTime", "Events", kFALSE);
390 write->AddContainer("MMcEvt", "Events", kFALSE);
391 write->AddContainer("DataType", "Events");
392 write->AddContainer("RunNumber", "Events");
393 write->AddContainer("EvtNumber", "Events");
394 // write->AddContainer("MMuonSearchPar", "Events", kFALSE);
395 // write->AddContainer("MMuonCalibPar", "Events", kFALSE);
396}
397
398// --------------------------------------------------------------------------
399//
400// Create a new instance of an object with name name of class
401// type fNameHist in parlist. It must derive from MHAlpha.
402// Call ForceUsingSize for it and return its pointer.
403// If something fails NULL is returned.
404//
405MHAlpha *MJCut::CreateNewHist(MParList &plist, const char *name) const
406{
407 TClass *cls = gROOT->GetClass(fNameHist);
408 if (!cls)
409 {
410 *fLog << err << "Class " << fNameHist << " not found in dictionary... abort." << endl;
411 return NULL;
412 }
413 if (!cls->InheritsFrom(MHAlpha::Class()))
414 {
415 *fLog << err << "Class " << fNameHist << " doesn't inherit from MHAlpha... abort." << endl;
416 return NULL;
417 }
418
419 const TString objname(Form("Hist%s", name));
420 MHAlpha *h = (MHAlpha*)plist.FindCreateObj(fNameHist, objname);
421 if (!h)
422 return NULL;
423
424 h->ForceUsingSize();
425
426 return h;
427}
428
429// --------------------------------------------------------------------------
430//
431// Create a new instance of an object with name name of class
432// type fNameHistFS in parlist. It must derive from MHFalseSource
433// If something fails NULL is returned.
434//
435MH *MJCut::CreateNewHistFS(MParList &plist, const char *name) const
436{
437 const TString cname(fNameHistFS.IsNull()?"MHFalseSource":fNameHistFS.Data());
438
439 TClass *cls = gROOT->GetClass(cname);
440 if (!cls)
441 {
442 *fLog << err << "Class " << cname << " not found in dictionary... abort." << endl;
443 return NULL;
444 }
445 if (!cls->InheritsFrom("MHFalseSource"))
446 {
447 *fLog << err << "Class " << cname << " doesn't inherit from MHFalseSource... abort." << endl;
448 return NULL;
449 }
450
451 const TString objname(Form("FS%s", name));
452 return (MH*)plist.FindCreateObj(cname, objname);
453}
454
455Bool_t MJCut::FillSrcPosCam(const MDataSet &set, MPointingPos &source, MHSrcPosCam &hsrcpos)
456{
457 *fLog << inf;
458 fLog->Separator(GetDescriptor());
459 *fLog << "Filling MHSrcPosCam " << set.GetName() << endl;
460 *fLog << endl;
461
462 // --------------------------------------------------------------------------------
463
464 // Setup Parlist
465 MParList plist;
466 plist.AddToList(this); // take care of fDisplay!
467
468 // Setup Tasklist
469 MTaskList tlist;
470 plist.AddToList(&tlist);
471
472 // La Palma Magic1, Possible source position
473 MObservatory obs;
474 plist.AddToList(&obs);
475 plist.AddToList(&source);
476
477 // Initialize default binnings
478 // MBinning bins1(18, 0, 90, "BinningSrcPosCam", "lin");
479 // plist.AddToList(&bins1);
480
481 // ------------- Loop Off Data --------------------
482 MReadReports read;
483
484 read.EnableAutoScheme();
485 read.AddToBranchList("MTimeEffectiveOnTime.*");
486 read.AddToBranchList("MEffectiveOnTime.*");
487
488 read.AddTree("Events", "MTime.", MReadReports::kMaster);
489 read.AddTree("Drive", MReadReports::kRequired);
490 read.AddTree("Starguider", MReadReports::kRequired);
491 read.AddTree("EffectiveOnTime");
492
493 if (!set.AddFilesOn(read))
494 return kFALSE;
495
496 MFillH fill(&hsrcpos, "MSrcPosCam", "FillSrcPosCam");
497 fill.SetNameTab("SrcPos");
498
499 // How to get source position from off- and on-data?
500 MSrcPosCorrect scor;
501 MSrcPosCalc scalc;
502 scalc.SetMode(MSrcPosCalc::kDefault);
503
504 MPointingDevCalc devcalc;
505
506 tlist.AddToList(&read);
507 tlist.AddToList(&devcalc, "Starguider");
508 tlist.AddToList(&scalc, "Events");
509 tlist.AddToList(&scor, "Events");
510 tlist.AddToList(&fill, "Events");
511
512 // by setting it here it is distributed to all consecutive tasks
513 tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
514
515 // Create and setup the eventloop
516 MEvtLoop evtloop(fName);
517 evtloop.SetParList(&plist);
518 evtloop.SetDisplay(fDisplay);
519 evtloop.SetLogStream(fLog);
520 if (!SetupEnv(evtloop))
521 return kFALSE;
522
523 // Execute first analysis
524 if (!evtloop.Eventloop(fMaxEvents))
525 {
526 *fLog << err << GetDescriptor() << ": Processing of on-sequences to fill SrcPosCam failed." << endl;
527 return kFALSE;
528 }
529
530 if (!evtloop.GetDisplay())
531 {
532 *fLog << err << GetDescriptor() << ": Execution stopped by user." << endl;
533 return kFALSE;
534 }
535
536 *fLog << all << GetDescriptor() << ": Done." << endl;
537 *fLog << endl << endl;
538
539 return kTRUE;
540}
541
542Int_t MJCut::Process(const MDataSet &set)
543{
544 if (!set.IsValid())
545 {
546 *fLog << err << "ERROR - DataSet invalid!" << endl;
547 return kFALSE;
548 }
549
550 CheckEnv();
551
552 // --------------------------------------------------------------------------------
553
554 // Possible source position (eg. Wobble Mode)
555 MPointingPos source("MSourcePos");
556 if (set.HasSource())
557 {
558 if (!set.GetSourcePos(source))
559 return -1;
560 *fLog << all;
561 source.Print("RaDec");
562 }
563 else
564 *fLog << all << "No source position applied..." << endl;
565
566 MParList plist;
567
568 MHSrcPosCam hsrcpos(set.IsWobbleMode());
569 if (!set.IsWobbleMode() && source.IsInitialized() && fRndmSrcPos)
570 {
571 if (!FillSrcPosCam(set, source, hsrcpos))
572 return -2;
573 plist.AddToList(&hsrcpos);
574 }
575
576 // --------------------------------------------------------------------------------
577
578 *fLog << inf;
579 fLog->Separator(GetDescriptor());
580 *fLog << "Perform cuts for data set " << set.GetName() << endl;
581 *fLog << endl;
582
583 // --------------------------------------------------------------------------------
584
585 // Setup Parlist
586 plist.AddToList(this); // take care of fDisplay!
587
588 MParameterI par("DataType");
589 plist.AddToList(&par);
590
591 // Setup Tasklist
592 MTaskList tlist;
593 plist.AddToList(&tlist);
594
595 // La Palma Magic1
596 MObservatory obs;
597 plist.AddToList(&obs);
598
599 if (source.IsInitialized())
600 plist.AddToList(&source);
601
602 // Initialize default binnings
603 MBinning bins1( 18, 0, 90, "BinningAlpha", "lin");
604 MBinning bins2( 15, 10, 1e6 , "BinningSize", "log");
605 MBinning bins3( 67, -0.005, 0.665, "BinningTheta", "asin");
606 //MBinning binsT(150, 0, 150, "BinningDeltaT", "lin");
607 MBinning bins4("BinningFalseSource");
608 MBinning bins5("BinningWidth");
609 MBinning bins6("BinningLength");
610 MBinning bins7("BinningDist");
611 MBinning bins8("BinningMaxDist");
612 MBinning bins9("BinningM3Long");
613 MBinning bins0("BinningConc1");
614 plist.AddToList(&bins1);
615 plist.AddToList(&bins2);
616 plist.AddToList(&bins3);
617 plist.AddToList(&bins4);
618 plist.AddToList(&bins5);
619 plist.AddToList(&bins6);
620 plist.AddToList(&bins7);
621 plist.AddToList(&bins8);
622 plist.AddToList(&bins9);
623 plist.AddToList(&bins0);
624 //plist.AddToList(&binsT);
625
626 // --------------------------------------------------------------------------------
627
628 // Setup fitter and histograms
629 MAlphaFitter fit;
630 plist.AddToList(&fit);
631 if (set.IsWobbleMode())
632 fit.SetScaleMode(MAlphaFitter::kNone);
633
634 MHAlpha *halphaoff = CreateNewHist(plist, "Off");
635 MFillH falpha(halphaoff, "", "FillHist");
636 MH *hfsoff = CreateNewHistFS(plist, "Off");
637 MFillH ffs(hfsoff, "MHillas", "FillFS");
638
639 // FIXME: If fPathIn read cuts and energy estimator from file!
640 MContinue cont0("", "Cut0");
641 MContinue cont1("", "Cut1");
642 MContinue cont2("", "Cut2");
643 MContinue cont3("", "Cut3");
644 cont0.SetAllowEmpty();
645 cont1.SetAllowEmpty();
646 cont2.SetAllowEmpty();
647 cont3.SetAllowEmpty();
648
649 // ------------- Loop Off Data --------------------
650 MReadReports readoffdata;
651 readoffdata.AddTree("Events", "MTime.", MReadReports::kMaster);
652 readoffdata.AddTree("Drive", MReadReports::kRequired);
653 readoffdata.AddTree("Starguider", MReadReports::kRequired);
654 readoffdata.AddTree("EffectiveOnTime");
655
656 MReadMarsFile readoffmc("Events");
657 readoffmc.DisableAutoScheme();
658
659 MRead &readoff = set.IsMonteCarlo() ? (MRead&)readoffmc : (MRead&)readoffdata;
660 const Bool_t setrc = set.IsWobbleMode() ? set.AddFilesOn(readoff) : set.AddFilesOff(readoff);
661 if (!setrc && set.HasOffSequences())
662 {
663 *fLog << err << "MDataSet::AddFiles" << (set.IsWobbleMode()?"On":"Off") << " failed." << endl;
664 return kFALSE;
665 }
666
667 const TString path(Form("%s/", fPathOut.Data()));
668 TString fname0(path);
669 TString fname1(path);
670 fname0 += fNameSummary.IsNull() ? (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
671 fname1 += fNameResult.IsNull() ? (TString) Form("ganymed%08d.root", set.GetNumAnalysis()) : fNameResult;
672
673 MWriteRootFile *write0 = CanStoreSummary() ? new MWriteRootFile(fPathOut.IsNull()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW") : 0;
674 MWriteRootFile *write1 = CanStoreResult() ? new MWriteRootFile(fPathOut.IsNull()?0:fname1.Data(), fOverwrite?"RECREATE":"NEW") : 0;
675 SetupWriter(write0, "WriteAfterCut0");
676 SetupWriter(write1, "WriteAfterCut3");
677
678 MTaskEnv taskenv2("CalcHadronness");
679 taskenv2.SetDefault(fCalcHadronness);
680
681 MTaskEnv taskenv3("CalcDisp");
682 taskenv3.SetDefault(fCalcDisp);
683
684 MTaskEnv taskenv4("EstimateEnergy");
685 taskenv4.SetDefault(fEstimateEnergy);
686
687 MParameterCalc setevtnum("MRawEvtHeader.fDAQEvtNumber", "SetEvtNumber");
688 setevtnum.SetNameParameter("EvtNumber");
689
690 MParameterCalc setrunnum("MRawRunHeader.fRunNumber", "SetRunNumber");
691 setrunnum.SetNameParameter("RunNumber");
692
693 // MFillH fill0a("OnPos [MHSrcPosCam]", "MSrcPosCam", "FillSrcPosCam");
694 MFillH fill1a("MHHillasOffPre [MHHillas]", "MHillas", "FillHillasPre");
695 MFillH fill2a("MHHillasOffPost [MHHillas]", "MHillas", "FillHillasPost");
696 MFillH fill3a("MHVsSizeOffPost [MHVsSize]", "MHillasSrc", "FillVsSizePost");
697 MFillH fill4a("MHHilExtOffPost [MHHillasExt]", "MHillasSrc", "FillHilExtPost");
698 MFillH fill5a("MHHilSrcOffPost [MHHillasSrc]", "MHillasSrc", "FillHilSrcPost");
699 MFillH fill6a("MHImgParOffPost [MHImagePar]", "MImagePar", "FillImgParPost");
700 MFillH fill7a("MHNewParOffPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost");
701 //MFillH fill9a("MHEffOffTime [MHEffectiveOnTime]", "MTime", "FillEffOnTime");
702 fill1a.SetNameTab("PreCut");
703 fill2a.SetNameTab("PostCut");
704 fill3a.SetNameTab("VsSize");
705 fill4a.SetNameTab("HilExt");
706 fill5a.SetNameTab("HilSrc");
707 fill6a.SetNameTab("ImgPar");
708 fill7a.SetNameTab("NewPar");
709 //fill9a.SetNameTab("EffOffT");
710
711 //MFDataMember fbin("Bin.fVal", '>', 0);
712 //fill9a.SetFilter(&fbin);
713
714 MPrint print2("MEffectiveOnTime");
715 print2.EnableSkip();
716
717 // How to get source position from off- and on-data?
718 MSrcPosCalc scalc;
719 scalc.SetMode(set.IsWobbleMode()?MSrcPosCalc::kWobble:MSrcPosCalc::kOffData); /********************/
720
721 MSrcPosCorrect scor;
722
723 MHillasCalc hcalc;
724 MHillasCalc hcalc2("MHillasCalcAnti");
725 hcalc.SetFlags(MHillasCalc::kCalcHillasSrc);
726 hcalc2.SetFlags(MHillasCalc::kCalcHillasSrc);
727 hcalc2.SetNameHillasSrc("MHillasSrcAnti");
728 hcalc2.SetNameSrcPosCam("MSrcPosAnti");
729
730 MSrcPosRndm srcrndm;
731
732 MTaskList tlist2;
733 tlist2.AddToList(&scalc);
734 tlist2.AddToList(&scor);
735 tlist2.AddToList(&srcrndm);
736 //if (fRndmSrcPos && !set.IsWobbleMode())
737 // tlist2.AddToList(&fill0a);
738 tlist2.AddToList(&hcalc);
739 if (set.IsWobbleMode())
740 tlist2.AddToList(&hcalc2);
741 //tlist2.AddToList(&taskenv1);
742 tlist2.AddToList(&cont0);
743 tlist2.AddToList(&taskenv2);
744 tlist2.AddToList(&taskenv3);
745 tlist2.AddToList(&setrunnum);
746 tlist2.AddToList(&setevtnum);
747 if (write0)
748 tlist2.AddToList(write0);
749 if (!fWriteOnly)
750 tlist2.AddToList(&fill1a);
751 tlist2.AddToList(&cont1);
752 if (!fWriteOnly && (!set.IsWobbleMode() || !fNameHistFS.IsNull()))
753 tlist2.AddToList(&ffs);
754 tlist2.AddToList(&cont2);
755 if (!fWriteOnly)
756 {
757 tlist2.AddToList(&fill2a);
758 if (fFullDisplay)
759 {
760 tlist2.AddToList(&fill3a);
761 tlist2.AddToList(&fill4a);
762 tlist2.AddToList(&fill5a);
763 tlist2.AddToList(&fill6a);
764 tlist2.AddToList(&fill7a);
765 }
766 }
767 if (!fWriteOnly)
768 {
769 tlist2.AddToList(&falpha);
770 /* if (!fIsMonteCarlo)
771 {
772 tlist2.AddToList(&fbin);
773 tlist2.AddToList(&fill9a);
774 } */
775 }
776 tlist2.AddToList(&cont3);
777 tlist2.AddToList(&taskenv4);
778
779 if (write1)
780 tlist2.AddToList(write1);
781
782 MPointingDevCalc devcalc;
783
784 tlist.AddToList(&readoff);
785 if (gLog.GetDebugLevel()>4)
786 tlist.AddToList(&print2, "EffectiveOnTime");
787 tlist.AddToList(&devcalc, "Starguider");
788 tlist.AddToList(&tlist2, "Events");
789
790 // by setting it here it is distributed to all consecutive tasks
791 tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
792
793 par.SetVal(0);
794
795 // Create and setup the eventloop
796 MEvtLoop evtloop(fName);
797 evtloop.SetParList(&plist);
798 evtloop.SetDisplay(fDisplay);
799 evtloop.SetLogStream(fLog);
800 if (!SetupEnv(evtloop))
801 return kFALSE;
802
803 TObjArray cont;
804 cont.Add(&cont0);
805 cont.Add(&cont1);
806 cont.Add(&cont2);
807 cont.Add(&cont3);
808 //if (taskenv1.GetTask())
809 // cont.Add(taskenv1.GetTask());
810 if (taskenv2.GetTask())
811 cont.Add(taskenv2.GetTask());
812 if (taskenv3.GetTask())
813 cont.Add(taskenv3.GetTask());
814
815 if (!WriteTasks(set.GetNumAnalysis(), cont))
816 return kFALSE;
817
818 if (set.HasOffSequences() || set.IsWobbleMode())
819 {
820 // Execute first analysis
821 if (!evtloop.Eventloop(fMaxEvents))
822 {
823 *fLog << err << GetDescriptor() << ": Processing of off-sequences failed." << endl;
824 return -3;
825 }
826
827 if (!evtloop.GetDisplay())
828 {
829 *fLog << err << GetDescriptor() << ": Execution stopped by user." << endl;
830 return kFALSE;
831 }
832
833 //plist.FindObject("MTimeEffectiveOnTime")->Clear();
834 }
835 else
836 {
837 // This is the simplest way to remove the two object from the parlist
838 delete halphaoff;
839 delete hfsoff;
840 }
841
842 // ------------- Loop On Data --------------------
843 MReadReports readondata;
844 readondata.AddTree("Events", "MTime.", MReadReports::kMaster);
845 readondata.AddTree("Drive", MReadReports::kRequired);
846 readondata.AddTree("Starguider", MReadReports::kRequired);
847 readondata.AddTree("EffectiveOnTime");
848
849 MReadMarsFile readonmc("Events");
850 readonmc.DisableAutoScheme();
851
852 MRead &readon = set.IsMonteCarlo() ? (MRead&)readonmc : (MRead&)readondata;
853 if (!set.AddFilesOn(readon))
854 return kFALSE;
855
856 scalc.SetMode(MSrcPosCalc::kDefault);
857
858 MFillH fill1b("MHHillasOnPre [MHHillas]", "MHillas", "FillHillasPre");
859 MFillH fill2b("MHHillasOnPost [MHHillas]", "MHillas", "FillHillasPost");
860 MFillH fill3b("MHVsSizeOnPost [MHVsSize]", "MHillasSrc", "FillVsSizePost");
861 MFillH fill4b("MHHilExtOnPost [MHHillasExt]", "MHillasSrc", "FillHilExtPost");
862 MFillH fill5b("MHHilSrcOnPost [MHHillasSrc]", "MHillasSrc", "FillHilSrcPost");
863 MFillH fill6b("MHImgParOnPost [MHImagePar]", "MImagePar", "FillImgParPost");
864 MFillH fill7b("MHNewParOnPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost");
865 //MFillH fill9b("MHEffOnTime [MHEffectiveOnTime]", "MTime", "FillEffOnTime");
866 fill1b.SetNameTab("PreCut");
867 fill2b.SetNameTab("PostCut");
868 fill3b.SetNameTab("VsSize");
869 fill4b.SetNameTab("HilExt");
870 fill5b.SetNameTab("HilSrc");
871 fill6b.SetNameTab("ImgPar");
872 fill7b.SetNameTab("NewPar");
873 //fill9b.SetNameTab("EffOnT");
874 fill1b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
875 fill2b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
876 fill3b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
877 fill4b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
878 fill5b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
879 fill6b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
880 fill7b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
881
882 //fill9b.SetFilter(&fbin);
883
884 /*
885 MHVsTime hvs("MEffectiveOnTime.fVal");
886 hvs.SetTitle("Effective On-Time vs. Time;;T_{on}");
887 MFillH fillvs(&hvs, "MTimeEffectiveOnTime", "FillOnTime");
888 fillvs.SetNameTab("OnTime");
889 */
890 MH3 hvs("MPointingPos.fZd");
891 hvs.SetName("Theta");
892 hvs.SetTitle("Effective On-Time vs. Zenith Angle;\\Theta [\\circ];T_{on} [s]");
893 MFillH fillvs(&hvs, "", "FillOnTime");
894 if (!set.IsMonteCarlo())
895 fillvs.SetWeight("MEffectiveOnTime");
896 fillvs.SetNameTab("OnTime");
897
898 /*
899 MParameterD weight;
900 weight.SetVal(-1);
901 fill2a.SetWeight(&weight);
902 fill3a.SetWeight(&weight);
903 fill4a.SetWeight(&weight);
904 fill5a.SetWeight(&weight);
905 fill6a.SetWeight(&weight);
906 fill7a.SetWeight(&weight);
907 if (fSubstraction)
908 {
909 fill2a.SetNameTab("PostCut-");
910 fill3a.SetNameTab("VsSize-");
911 fill4a.SetNameTab("HilExt-");
912 fill5a.SetNameTab("HilSrc-");
913 fill6a.SetNameTab("ImgPar-");
914 fill7a.SetNameTab("NewPar-");
915 }
916 */
917 MHAlpha *halphaon=CreateNewHist(plist);
918 MFillH falpha2(halphaon, "", "FillHist");
919 MH *hfs=CreateNewHistFS(plist);
920 MFillH ffs2(hfs, "MHillas", "FillFS");
921 MFillH fillphi("MHPhi", "", "FillPhi");
922 fillphi.SetDrawOption("anticut");
923
924 tlist.Replace(&readon);
925 if (fRndmSrcPos && !set.IsWobbleMode())
926 {
927// tlist2.RemoveFromList(&fill0a);
928 tlist2.RemoveFromList(&srcrndm);
929 }
930
931 MFillH fillsrc(&hsrcpos, "MSrcPosCam", "FillSrcPosCam");
932 fillsrc.SetNameTab("SrcPos");
933 if (set.IsWobbleMode() & !set.IsMonteCarlo())
934 tlist2.AddToListBefore(&fillsrc, &hcalc);
935
936 if (!fWriteOnly)
937 {
938 tlist2.Replace(&fill1b);
939/* if (fIsWobble)
940 {
941 tlist2.AddToListAfter(&fill2b, &fill2a);
942 tlist2.AddToListAfter(&fill3b, &fill3a);
943 }
944 else
945 */
946 tlist2.Replace(&fill2b);
947 if (fFullDisplay)
948 {
949 tlist2.Replace(&fill3b);
950 tlist2.Replace(&fill4b);
951 tlist2.Replace(&fill5b);
952 tlist2.Replace(&fill6b);
953 tlist2.Replace(&fill7b);
954 }
955 tlist2.Replace(&falpha2);
956 //if (!fIsMonteCarlo)
957 // tlist2.Replace(&fill9b);
958 if (!set.IsWobbleMode() || !fNameHist.IsNull())
959 tlist2.Replace(&ffs2);
960 if (set.IsWobbleMode())
961 {
962 tlist2.AddToListAfter(&fillphi, &falpha2);
963 if (!fNameHist.IsNull())
964 tlist2.RemoveFromList(&ffs);
965 }
966
967 if (!set.IsMonteCarlo())
968 tlist.AddToList(&fillvs, "EffectiveOnTime");
969 else
970 tlist2.AddToListBefore(&fillvs, &scalc);
971 }
972
973 // by setting it here it is distributed to all consecutive tasks
974 tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
975
976 par.SetVal(1);
977
978 // Execute first analysis
979 if (!evtloop.Eventloop(fMaxEvents))
980 {
981 *fLog << err << GetDescriptor() << ": Processing of on-sequences failed." << endl;
982 return -4;
983 }
984
985 if (write0)
986 delete write0;
987 if (write1)
988 delete write1;
989
990 // FIXME: Perform fit and plot energy dependant alpha plots
991 // and fit result to new tabs!
992 if (!WriteResult(plist, set))
993 return kFALSE;
994
995 *fLog << all << GetDescriptor() << ": Done." << endl;
996 *fLog << endl << endl;
997
998 return kTRUE;
999}
Note: See TracBrowser for help on using the repository browser.