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

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