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

Last change on this file since 8704 was 8695, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 33.1 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 1/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2007
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJCut
28//
29/////////////////////////////////////////////////////////////////////////////
30#include "MJCut.h"
31
32// Root
33#include <TEnv.h>
34#include <TFile.h>
35
36// Environment
37#include "MLog.h"
38#include "MLogManip.h"
39
40// Eventloop
41#include "MParList.h"
42#include "MTaskList.h"
43#include "MEvtLoop.h"
44
45// Display
46#include "MStatusDisplay.h"
47
48// Tasks
49#include "MReadReports.h"
50#include "MReadMarsFile.h"
51#include "MPrint.h"
52#include "MContinue.h"
53#include "MTaskEnv.h"
54#include "MPointingDevCalc.h"
55#include "MParameterCalc.h"
56#include "MSrcPosRndm.h"
57#include "MSrcPosCalc.h"
58#include "MSrcPosCorrect.h"
59#include "MHillasCalc.h"
60#include "MFillH.h"
61#include "MWriteRootFile.h"
62
63// Filter
64#include "MFDataPhrase.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 // Filter for VsSize
668 MFDataPhrase ftheta("", "CutT");
669 ftheta.SetAllowEmpty();
670
671 // ------------- Loop Off Data --------------------
672 MReadReports readoffdata;
673 readoffdata.AddTree("Events", "MTime.", MReadReports::kMaster);
674 readoffdata.AddTree("Drive", MReadReports::kRequired);
675 readoffdata.AddTree("Starguider", MReadReports::kRequired);
676 readoffdata.AddTree("EffectiveOnTime");
677
678 MReadMarsFile readoffmc("Events");
679 readoffmc.DisableAutoScheme();
680
681 MRead &readoff = set.IsMonteCarlo() ? (MRead&)readoffmc : (MRead&)readoffdata;
682 const Bool_t setrc = set.IsWobbleMode() ? set.AddFilesOn(readoff) : set.AddFilesOff(readoff);
683 if (!setrc && set.HasOffSequences())
684 {
685 *fLog << err << "MDataSet::AddFiles" << (set.IsWobbleMode()?"On":"Off") << " failed." << endl;
686 return kFALSE;
687 }
688
689 const TString path(Form("%s/", fPathOut.Data()));
690 TString fname0(path);
691 TString fname1(path);
692 fname0 += fNameSummary.IsNull() ? (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
693 fname1 += fNameResult.IsNull() ? (TString) Form("ganymed%08d.root", set.GetNumAnalysis()) : fNameResult;
694
695 MWriteRootFile *write0 = CanStoreSummary() ? new MWriteRootFile(fPathOut.IsNull()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW") : 0;
696 MWriteRootFile *write1 = CanStoreResult() ? new MWriteRootFile(fPathOut.IsNull()?0:fname1.Data(), fOverwrite?"RECREATE":"NEW") : 0;
697 SetupWriter(write0, "WriteAfterCut0");
698 SetupWriter(write1, "WriteAfterCut3");
699
700 MTaskEnv taskenv2("CalcHadronness");
701 taskenv2.SetDefault(fCalcHadronness);
702
703 MTaskEnv taskenv3("CalcDisp");
704 taskenv3.SetDefault(fCalcDisp);
705
706 MTaskEnv taskenv4("EstimateEnergy");
707 taskenv4.SetDefault(fEstimateEnergy);
708
709 MParameterCalc setevtnum("MRawEvtHeader.fDAQEvtNumber", "SetEvtNumber");
710 setevtnum.SetNameParameter("EvtNumber");
711
712 MParameterCalc setrunnum("MRawRunHeader.fRunNumber", "SetRunNumber");
713 setrunnum.SetNameParameter("RunNumber");
714
715 MFillH fill1a("MHHillasOffPre [MHHillas]", "MHillas", "FillHillasPre");
716 MFillH fill2a("MHHillasOffPost [MHHillas]", "MHillas", "FillHillasPost");
717 MFillH fill3a("MHVsSizeOffPost [MHVsSize]", "MHillasSrc", "FillVsSizePost");
718 MFillH fill3c("MHVsSizeOffTheta [MHVsSize]", "MHillasSrc", "FillVsSizeTheta");
719 MFillH fill4a("MHHilExtOffPost [MHHillasExt]", "MHillasSrc", "FillHilExtPost");
720 MFillH fill5a("MHHilSrcOffPost [MHHillasSrc]", "MHillasSrc", "FillHilSrcPost");
721 MFillH fill6a("MHImgParOffPost [MHImagePar]", "MImagePar", "FillImgParPost");
722 MFillH fill7a("MHNewParOffPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost");
723 //MFillH fill9a("MHEffOffTime [MHEffectiveOnTime]", "MTime", "FillEffOnTime");
724 fill1a.SetNameTab("PreCut");
725 fill2a.SetNameTab("PostCut");
726 fill3a.SetNameTab("VsSize");
727 fill3c.SetNameTab("CutT");
728 fill4a.SetNameTab("HilExt");
729 fill5a.SetNameTab("HilSrc");
730 fill6a.SetNameTab("ImgPar");
731 fill7a.SetNameTab("NewPar");
732 //fill9a.SetNameTab("EffOffT");
733
734 fill3c.SetFilter(&ftheta);
735
736 //MFDataMember fbin("Bin.fVal", '>', 0);
737 //fill9a.SetFilter(&fbin);
738
739 MPrint print2("MEffectiveOnTime");
740 print2.EnableSkip();
741
742 MTaskList tlist2;
743 if (set.IsWobbleMode())
744 {
745 tlist2.SetNumPasses(fNumOffSourcePos);
746 fill2a.SetWeight(&scale);
747 fill3a.SetWeight(&scale);
748 fill3c.SetWeight(&scale);
749 fill4a.SetWeight(&scale);
750 fill5a.SetWeight(&scale);
751 fill6a.SetWeight(&scale);
752 fill7a.SetWeight(&scale);
753 }
754
755 // How to get source position from off- and on-data?
756 MSrcPosCalc scalc;
757 scalc.SetMode(set.IsWobbleMode()?MSrcPosCalc::kWobble:MSrcPosCalc::kOffData); /********************/
758 scalc.SetCallback(&tlist2);
759
760 MSrcPosCorrect scor;
761
762 MHillasCalc hcalc;
763 MHillasCalc hcalc2("MHillasCalcAnti");
764 hcalc.SetFlags(MHillasCalc::kCalcHillasSrc);
765 hcalc2.SetFlags(MHillasCalc::kCalcHillasSrc);
766 hcalc2.SetNameHillasSrc("MHillasSrcAnti");
767 hcalc2.SetNameSrcPosCam("MSrcPosAnti");
768
769 MSrcPosRndm srcrndm;
770
771 MH3 hvs("MPointingPos.fZd");
772 hvs.SetName("ThetaOff;Theta");
773 hvs.SetTitle("Effective On-Time vs. Zenith Angle;\\Theta [\\circ];T_{on} [s]");
774
775 MFillH fillvs(&hvs, "", "FillOnTime");
776 if (!set.IsMonteCarlo())
777 fillvs.SetWeight("MEffectiveOnTime");
778 fillvs.SetNameTab("OnTime");
779
780 // It is not really necessary to re-calculate the image parameters
781 // for the the on-source for MCs, but it is done for symmetry reasons
782 if (set.IsMonteCarlo())
783 tlist2.AddToList(&fillvs);
784
785 tlist2.AddToList(&scalc);
786 tlist2.AddToList(&scor);
787 tlist2.AddToList(&srcrndm);
788 tlist2.AddToList(&hcalc);
789 if (set.IsWobbleMode())
790 tlist2.AddToList(&hcalc2);
791 //tlist2.AddToList(&taskenv1);
792 tlist2.AddToList(&cont0);
793 tlist2.AddToList(&taskenv2);
794 tlist2.AddToList(&taskenv3);
795 tlist2.AddToList(&setrunnum);
796 tlist2.AddToList(&setevtnum);
797 if (write0)
798 tlist2.AddToList(write0);
799 tlist2.AddToList(&cont1);
800 if (!fWriteOnly && (!set.IsWobbleMode() || !fNameHistFS.IsNull()))
801 tlist2.AddToList(&ffs);
802 tlist2.AddToList(&cont2);
803 if (!fWriteOnly)
804 {
805 tlist2.AddToList(&fill2a);
806 if (fFullDisplay)
807 {
808 tlist2.AddToList(&ftheta);
809 tlist2.AddToList(&fill3a);
810 tlist2.AddToList(&fill3c);
811 tlist2.AddToList(&fill4a);
812 tlist2.AddToList(&fill5a);
813 tlist2.AddToList(&fill6a);
814 tlist2.AddToList(&fill7a);
815 }
816 }
817 if (!fWriteOnly)
818 {
819 tlist2.AddToList(&falpha);
820 /* if (!fIsMonteCarlo)
821 {
822 tlist2.AddToList(&fbin);
823 tlist2.AddToList(&fill9a);
824 } */
825 }
826 tlist2.AddToList(&cont3);
827 tlist2.AddToList(&taskenv4);
828
829 if (write1)
830 tlist2.AddToList(write1);
831
832 MPointingDevCalc devcalc;
833
834 tlist.AddToList(&readoff);
835 if (!set.IsMonteCarlo())
836 tlist.AddToList(&fillvs, "EffectiveOnTime");
837 if (gLog.GetDebugLevel()>4)
838 tlist.AddToList(&print2, "EffectiveOnTime");
839 tlist.AddToList(&devcalc, "Starguider");
840 tlist.AddToList(&contq, "Events");
841 if (!fWriteOnly)
842 tlist.AddToList(&fill1a, "Events");
843 tlist.AddToList(&tlist2, "Events");
844
845 // by setting it here it is distributed to all consecutive tasks
846 tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
847
848 par.SetVal(0);
849
850 // Create and setup the eventloop
851 MEvtLoop evtloop(fName);
852 evtloop.SetParList(&plist);
853 evtloop.SetDisplay(fDisplay);
854 evtloop.SetLogStream(fLog);
855 if (!SetupEnv(evtloop))
856 return kFALSE;
857
858 TObjArray cont;
859 cont.Add(&contq);
860 cont.Add(&cont0);
861 cont.Add(&cont1);
862 cont.Add(&cont2);
863 cont.Add(&cont3);
864 //if (taskenv1.GetTask())
865 // cont.Add(taskenv1.GetTask());
866 if (taskenv2.GetTask())
867 cont.Add(taskenv2.GetTask());
868 if (taskenv3.GetTask())
869 cont.Add(taskenv3.GetTask());
870
871 if (!WriteTasks(set.GetNumAnalysis(), cont))
872 return kFALSE;
873
874 if (set.HasOffSequences() || set.IsWobbleMode())
875 {
876 // Execute first analysis
877 if (!evtloop.Eventloop(fMaxEvents))
878 {
879 *fLog << err << GetDescriptor() << ": Processing of off-sequences failed." << endl;
880 return -3;
881 }
882
883 if (!evtloop.GetDisplay())
884 {
885 *fLog << err << GetDescriptor() << ": Execution stopped by user." << endl;
886 return kFALSE;
887 }
888
889 //plist.FindObject("MTimeEffectiveOnTime")->Clear();
890 }
891 else
892 {
893 // This is the simplest way to remove the two object from the parlist
894 delete halphaoff;
895 delete hfsoff;
896 }
897
898 // ------------- Loop On Data --------------------
899 MReadReports readondata;
900 readondata.AddTree("Events", "MTime.", MReadReports::kMaster);
901 readondata.AddTree("Drive", MReadReports::kRequired);
902 readondata.AddTree("Starguider", MReadReports::kRequired);
903 readondata.AddTree("EffectiveOnTime");
904
905 MReadMarsFile readonmc("Events");
906 readonmc.DisableAutoScheme();
907
908 MRead &readon = set.IsMonteCarlo() ? (MRead&)readonmc : (MRead&)readondata;
909 if (!set.AddFilesOn(readon))
910 return kFALSE;
911
912 scalc.SetMode(MSrcPosCalc::kDefault);
913 scalc.SetNumRandomOffPositions(fNumOffSourcePos);
914
915 MFillH fill1b("MHHillasOnPre [MHHillas]", "MHillas", "FillHillasPre");
916 MFillH fill2b("MHHillasOnPost [MHHillas]", "MHillas", "FillHillasPost");
917 MFillH fill3b("MHVsSizeOnPost [MHVsSize]", "MHillasSrc", "FillVsSizePost");
918 MFillH fill3d("MHVsSizeOnTheta [MHVsSize]", "MHillasSrc", "FillVsSizeTheta");
919 MFillH fill4b("MHHilExtOnPost [MHHillasExt]", "MHillasSrc", "FillHilExtPost");
920 MFillH fill5b("MHHilSrcOnPost [MHHillasSrc]", "MHillasSrc", "FillHilSrcPost");
921 MFillH fill6b("MHImgParOnPost [MHImagePar]", "MImagePar", "FillImgParPost");
922 MFillH fill7b("MHNewParOnPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost");
923 //MFillH fill9b("MHEffOnTime [MHEffectiveOnTime]", "MTime", "FillEffOnTime");
924 fill1b.SetNameTab("PreCut");
925 fill2b.SetNameTab("PostCut");
926 fill3b.SetNameTab("VsSize");
927 fill3d.SetNameTab("CutT");
928 fill4b.SetNameTab("HilExt");
929 fill5b.SetNameTab("HilSrc");
930 fill6b.SetNameTab("ImgPar");
931 fill7b.SetNameTab("NewPar");
932 //fill9b.SetNameTab("EffOnT");
933 fill1b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
934 fill2b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
935 fill3b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
936 fill3d.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
937 fill4b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
938 fill5b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
939 fill6b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
940 fill7b.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
941 //fill9b.SetFilter(&fbin);
942
943 fill3d.SetFilter(&ftheta);
944
945 /*
946 MHVsTime hvs("MEffectiveOnTime.fVal");
947 hvs.SetTitle("Effective On-Time vs. Time;;T_{on}");
948 MFillH fillvs(&hvs, "MTimeEffectiveOnTime", "FillOnTime");
949 fillvs.SetNameTab("OnTime");
950 */
951
952 /*
953 MParameterD weight;
954 weight.SetVal(-1);
955 fill2a.SetWeight(&weight);
956 fill3a.SetWeight(&weight);
957 fill4a.SetWeight(&weight);
958 fill5a.SetWeight(&weight);
959 fill6a.SetWeight(&weight);
960 fill7a.SetWeight(&weight);
961 if (fSubstraction)
962 {
963 fill2a.SetNameTab("PostCut-");
964 fill3a.SetNameTab("VsSize-");
965 fill4a.SetNameTab("HilExt-");
966 fill5a.SetNameTab("HilSrc-");
967 fill6a.SetNameTab("ImgPar-");
968 fill7a.SetNameTab("NewPar-");
969 }
970 */
971 MHAlpha *halphaon=CreateNewHist(plist);
972 MFillH falpha2(halphaon, "", "FillHist");
973 MH *hfs=CreateNewHistFS(plist);
974 MFillH ffs2(hfs, "MHillas", "FillFS");
975 MFillH fillphi("MHPhi", "", "FillPhi");
976 fillphi.SetDrawOption("anticut");
977
978 tlist2.SetNumPasses();
979
980 tlist.Replace(&readon);
981 if (fRndmSrcPos && !set.IsWobbleMode())
982 tlist2.RemoveFromList(&srcrndm);
983
984 MFillH fillsrc(&hsrcpos, "MSrcPosCam", "FillSrcPosCam");
985 fillsrc.SetNameTab("SrcPos");
986
987 if (set.IsWobbleMode() && !set.IsMonteCarlo())
988 tlist2.AddToListBefore(&fillsrc, &hcalc);
989
990 MH3 hvs2("MPointingPos.fZd");
991 hvs2.SetName("Theta");
992 hvs2.SetTitle("Effective On-Time vs. Zenith Angle;\\Theta [\\circ];T_{on} [s]");
993
994 MFillH fillvs2(&hvs2, "", "FillOnTime");
995 if (!set.IsMonteCarlo())
996 fillvs2.SetWeight("MEffectiveOnTime");
997 fillvs2.SetNameTab("OnTime");
998 fillvs2.SetDrawOption(set.HasOffSequences()||set.IsWobbleMode()?"same":"");
999
1000 if (!fWriteOnly)
1001 {
1002 tlist.Replace(&fill1b);
1003
1004 tlist2.Replace(&fill2b);
1005 if (fFullDisplay)
1006 {
1007 tlist2.Replace(&fill3b);
1008 tlist2.Replace(&fill3d);
1009 tlist2.Replace(&fill4b);
1010 tlist2.Replace(&fill5b);
1011 tlist2.Replace(&fill6b);
1012 tlist2.Replace(&fill7b);
1013 }
1014 tlist2.Replace(&falpha2);
1015 //if (!fIsMonteCarlo)
1016 // tlist2.Replace(&fill9b);
1017 if (!set.IsWobbleMode() || !fNameHist.IsNull())
1018 tlist2.Replace(&ffs2);
1019 if (set.IsWobbleMode())
1020 {
1021 tlist2.AddToListAfter(&fillphi, &falpha2);
1022 if (!fNameHist.IsNull())
1023 tlist2.RemoveFromList(&ffs);
1024 }
1025
1026 if (!set.IsMonteCarlo())
1027 tlist.Replace(&fillvs2);
1028 else
1029 tlist2.Replace(&fillvs2);
1030 }
1031
1032 // by setting it here it is distributed to all consecutive tasks
1033 tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
1034
1035 par.SetVal(1);
1036
1037 // Execute first analysis
1038 if (!evtloop.Eventloop(fMaxEvents))
1039 {
1040 *fLog << err << GetDescriptor() << ": Processing of on-sequences failed." << endl;
1041 return -4;
1042 }
1043
1044 if (write0)
1045 delete write0;
1046 if (write1)
1047 delete write1;
1048
1049 // FIXME: Perform fit and plot energy dependant alpha plots
1050 // and fit result to new tabs!
1051 if (!WriteResult(plist, set))
1052 return kFALSE;
1053
1054 *fLog << all << GetDescriptor() << ": Done." << endl;
1055 *fLog << endl << endl;
1056
1057 return kTRUE;
1058}
Note: See TracBrowser for help on using the repository browser.