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

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