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

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