source: trunk/Mars/mjobs/MJCut.cc@ 10009

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