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-2005
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MJCut
|
---|
28 | //
|
---|
29 | // FIXME: Preparation for wobble mode missing
|
---|
30 | //
|
---|
31 | /////////////////////////////////////////////////////////////////////////////
|
---|
32 | #include "MJCut.h"
|
---|
33 |
|
---|
34 | // Root
|
---|
35 | #include <TEnv.h>
|
---|
36 | #include <TFile.h>
|
---|
37 |
|
---|
38 | // Environment
|
---|
39 | #include "MLog.h"
|
---|
40 | #include "MLogManip.h"
|
---|
41 |
|
---|
42 | // Eventloop
|
---|
43 | #include "MParList.h"
|
---|
44 | #include "MTaskList.h"
|
---|
45 | #include "MEvtLoop.h"
|
---|
46 |
|
---|
47 | // Display
|
---|
48 | #include "MStatusDisplay.h"
|
---|
49 |
|
---|
50 | // Tasks
|
---|
51 | #include "MReadReports.h"
|
---|
52 | #include "MReadMarsFile.h"
|
---|
53 | #include "MPrint.h"
|
---|
54 | #include "MContinue.h"
|
---|
55 | #include "MTaskEnv.h"
|
---|
56 | #include "MPointingDevCalc.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 | // Fit signal environment
|
---|
65 | #include "../mhflux/MAlphaFitter.h"
|
---|
66 | #include "../mhflux/MHAlpha.h"
|
---|
67 |
|
---|
68 | // Containers
|
---|
69 | #include "MH3.h"
|
---|
70 | #include "MBinning.h"
|
---|
71 | #include "MDataSet.h"
|
---|
72 | #include "MParameters.h"
|
---|
73 | #include "MPointingPos.h"
|
---|
74 | #include "MObservatory.h"
|
---|
75 | #include "MHSrcPosCam.h"
|
---|
76 |
|
---|
77 | ClassImp(MJCut);
|
---|
78 |
|
---|
79 | using namespace std;
|
---|
80 |
|
---|
81 | // --------------------------------------------------------------------------
|
---|
82 | //
|
---|
83 | // Default constructor. Set defaults for fStoreSummary, fStoreresult,
|
---|
84 | // fWriteOnly, fIsWobble and fFullDisplay to kFALSE and initialize
|
---|
85 | // /*fEstimateEnergy and*/ fCalcHadronness with NULL.
|
---|
86 | //
|
---|
87 | MJCut::MJCut(const char *name, const char *title)
|
---|
88 | : fStoreSummary(kFALSE), fStoreResult(kTRUE), fWriteOnly(kFALSE),
|
---|
89 | fIsWobble(kFALSE), fIsMonteCarlo(kFALSE), fFullDisplay(kTRUE),
|
---|
90 | fRndmSrcPos(kFALSE), fNameHist("MHThetaSq"), fCalcHadronness(0), fCalcDisp(0)
|
---|
91 | {
|
---|
92 | fName = name ? name : "MJCut";
|
---|
93 | fTitle = title ? title : "Standard program to perform g/h-separation cuts";
|
---|
94 | }
|
---|
95 |
|
---|
96 | // --------------------------------------------------------------------------
|
---|
97 | //
|
---|
98 | // Destructor. Delete fEstimateEnergy and fCalcHadronness if != NULL
|
---|
99 | //
|
---|
100 | MJCut::~MJCut()
|
---|
101 | {
|
---|
102 | //if (fEstimateEnergy)
|
---|
103 | // delete fEstimateEnergy;
|
---|
104 | if (fCalcHadronness)
|
---|
105 | delete fCalcHadronness;
|
---|
106 | if (fCalcDisp)
|
---|
107 | delete fCalcDisp;
|
---|
108 | }
|
---|
109 |
|
---|
110 | // --------------------------------------------------------------------------
|
---|
111 | //
|
---|
112 | // Set the name of the summary file (events after cut0)
|
---|
113 | // If you give a name the storage of this file is enabled implicitly.
|
---|
114 | // If you give no filename the storage is neither enabled nor disabled,
|
---|
115 | // but the storage file name is reset.
|
---|
116 | // If no filename is set the default filename is used.
|
---|
117 | // You can explicitly enable or disable the storage using EnableStoreOf*()
|
---|
118 | // The default argument is no filename.
|
---|
119 | //
|
---|
120 | void MJCut::SetNameSummaryFile(const char *name)
|
---|
121 | {
|
---|
122 | fNameSummary=name;
|
---|
123 | if (!fNameSummary.IsNull())
|
---|
124 | EnableStorageOfSummary();
|
---|
125 | }
|
---|
126 |
|
---|
127 | // --------------------------------------------------------------------------
|
---|
128 | //
|
---|
129 | // Set the name of the summary file (events after cut3)
|
---|
130 | // If you give a name the storage of this file is enabled implicitly.
|
---|
131 | // If you give no filename the storage is neither enabled nor disabled,
|
---|
132 | // but the storage file name is reset.
|
---|
133 | // If no filename is set the default filename is used.
|
---|
134 | // You can explicitly enable or disable the storage using EnableStoreOf*()
|
---|
135 | // The default argument is no filename.
|
---|
136 | //
|
---|
137 | void MJCut::SetNameResultFile(const char *name)
|
---|
138 | {
|
---|
139 | fNameResult=name;
|
---|
140 | if (!fNameResult.IsNull())
|
---|
141 | EnableStorageOfResult();
|
---|
142 | }
|
---|
143 |
|
---|
144 | // --------------------------------------------------------------------------
|
---|
145 | //
|
---|
146 | // Setup a task estimating the energy. The given task is cloned.
|
---|
147 | //
|
---|
148 | /*
|
---|
149 | void MJCut::SetEnergyEstimator(const MTask *task)
|
---|
150 | {
|
---|
151 | if (fEstimateEnergy)
|
---|
152 | delete fEstimateEnergy;
|
---|
153 | fEstimateEnergy = task ? (MTask*)task->Clone() : 0;
|
---|
154 | }
|
---|
155 | */
|
---|
156 |
|
---|
157 | // --------------------------------------------------------------------------
|
---|
158 | //
|
---|
159 | // Setup a task calculating the hadronness. The given task is cloned.
|
---|
160 | //
|
---|
161 | void MJCut::SetHadronnessCalculator(const MTask *task)
|
---|
162 | {
|
---|
163 | if (fCalcHadronness)
|
---|
164 | delete fCalcHadronness;
|
---|
165 | fCalcHadronness = task ? (MTask*)task->Clone() : 0;
|
---|
166 | }
|
---|
167 |
|
---|
168 | // --------------------------------------------------------------------------
|
---|
169 | //
|
---|
170 | // Setup a task calculating disp. The given task is cloned.
|
---|
171 | //
|
---|
172 | void MJCut::SetDispCalculator(const MTask *task)
|
---|
173 | {
|
---|
174 | if (fCalcDisp)
|
---|
175 | delete fCalcDisp;
|
---|
176 | fCalcDisp = task ? (MTask*)task->Clone() : 0;
|
---|
177 | }
|
---|
178 |
|
---|
179 | // --------------------------------------------------------------------------
|
---|
180 | //
|
---|
181 | // return fOutputPath+"/ganymed%08d.root", num
|
---|
182 | //
|
---|
183 | TString MJCut::GetOutputFile(UInt_t num) const
|
---|
184 | {
|
---|
185 | TString p(fPathOut);
|
---|
186 | p += "/";
|
---|
187 | p += fNameOutput.IsNull() ? Form("ganymed%08d.root", num) : fNameOutput.Data();
|
---|
188 | gSystem->ExpandPathName(p);
|
---|
189 | return p;
|
---|
190 | }
|
---|
191 |
|
---|
192 | /*
|
---|
193 | Bool_t MJCut::ReadTasks(const char *fname, MTask* &env1, MTask* &env2) const
|
---|
194 | {
|
---|
195 | // const TString fname = Form("%s/calib%08d.root", fPathIn.Data(), fSequence.GetSequence());
|
---|
196 |
|
---|
197 | *fLog << inf << "Reading from file: " << fname << endl;
|
---|
198 |
|
---|
199 | TFile file(fname, "READ");
|
---|
200 | if (!file.IsOpen())
|
---|
201 | {
|
---|
202 | *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
|
---|
203 | return kFALSE;
|
---|
204 | }
|
---|
205 |
|
---|
206 | TObject *o = file.Get("EstimateEnergy");
|
---|
207 | if (o && !o->InheritsFrom(MTask::Class()))
|
---|
208 | {
|
---|
209 | *fLog << err << dbginf << "ERROR - EstimateEnergy read from " << fname << " doesn't inherit from MTask!" << endl;
|
---|
210 | return kFALSE;
|
---|
211 | }
|
---|
212 | env1 = o ? (MTask*)o->Clone() : FNULL;
|
---|
213 |
|
---|
214 | o = file.Get("CalcHadronness");
|
---|
215 | if (o && !o->InheritsFrom(MTask::Class()))
|
---|
216 | {
|
---|
217 | *fLog << err << dbginf << "ERROR - CalcHadronness read from " << fname << " doesn't inherit from MTask!" << endl;
|
---|
218 | return kFALSE;
|
---|
219 | }
|
---|
220 | env2 = o ? (MTask*)o->Clone() : NULL;
|
---|
221 |
|
---|
222 | return kTRUE;
|
---|
223 | }
|
---|
224 | */
|
---|
225 |
|
---|
226 | // --------------------------------------------------------------------------
|
---|
227 | //
|
---|
228 | // Write the tasks in cont to the file corresponding to analysis number num,
|
---|
229 | // see GetOutputFile()
|
---|
230 | //
|
---|
231 | Bool_t MJCut::WriteTasks(UInt_t num, TObjArray &cont) const
|
---|
232 | {
|
---|
233 | if (fPathOut.IsNull())
|
---|
234 | {
|
---|
235 | *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
|
---|
236 | return kTRUE;
|
---|
237 | }
|
---|
238 |
|
---|
239 | const TString oname(GetOutputFile(num));
|
---|
240 |
|
---|
241 | *fLog << inf << "Writing to file: " << oname << endl;
|
---|
242 |
|
---|
243 | TFile *file = 0;
|
---|
244 | if (fNameResult.IsNull() && fStoreResult)
|
---|
245 | {
|
---|
246 | file = (TFile*)gROOT->GetListOfFiles()->FindObject(oname);
|
---|
247 | if (file)
|
---|
248 | file->cd();
|
---|
249 | }
|
---|
250 | else
|
---|
251 | file = TFile::Open(oname, fOverwrite?"RECREATE":"NEW", "File created by MJCut", 9);
|
---|
252 |
|
---|
253 | if (!file)
|
---|
254 | {
|
---|
255 | *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
|
---|
256 | return kFALSE;
|
---|
257 | }
|
---|
258 |
|
---|
259 | const Bool_t rc = WriteContainer(cont);
|
---|
260 |
|
---|
261 | if (!(fNameResult.IsNull() && fStoreResult))
|
---|
262 | delete file;
|
---|
263 |
|
---|
264 | return rc;
|
---|
265 | }
|
---|
266 |
|
---|
267 | // --------------------------------------------------------------------------
|
---|
268 | //
|
---|
269 | // Write the result plots and other results to the file corresponding to
|
---|
270 | // analysis number num, see GetOutputFile()
|
---|
271 | //
|
---|
272 | Bool_t MJCut::WriteResult(const MParList &plist, UInt_t num) const
|
---|
273 | {
|
---|
274 | TObjArray arr;
|
---|
275 |
|
---|
276 | // Save all MBinnings
|
---|
277 | TIter Next(plist);
|
---|
278 | TObject *o=0;
|
---|
279 | while ((o=Next()))
|
---|
280 | if (o->InheritsFrom(MBinning::Class()))
|
---|
281 | arr.Add(o);
|
---|
282 |
|
---|
283 | // Save also the result, not only the setup
|
---|
284 | const MHAlpha *halpha = (MHAlpha*)plist.FindObject("Hist", "MHAlpha");
|
---|
285 | if (halpha)
|
---|
286 | arr.Add((TObject*)(&halpha->GetAlphaFitter()));
|
---|
287 |
|
---|
288 | const TString fname(fNameOutput.IsNull() ? Form("ganymed%08d.root", num) : fNameOutput.Data());
|
---|
289 |
|
---|
290 | // If requested, write to already open output file
|
---|
291 | if (fNameResult.IsNull() && fStoreResult)
|
---|
292 | {
|
---|
293 | TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(fname);
|
---|
294 | if (file)
|
---|
295 | {
|
---|
296 | file->cd();
|
---|
297 | return WriteContainer(arr);
|
---|
298 | }
|
---|
299 | }
|
---|
300 |
|
---|
301 | return WriteContainer(arr, fname, "UPDATE");
|
---|
302 | }
|
---|
303 |
|
---|
304 | // --------------------------------------------------------------------------
|
---|
305 | //
|
---|
306 | // MJCut allows to setup several option by a resource file:
|
---|
307 | // MJCut.WriteSummary: yes, no
|
---|
308 | // MJCut.SummaryFile: filename
|
---|
309 | // MJCut.WriteResult: yes, no
|
---|
310 | // MJCut.ResultFile: filename
|
---|
311 | // MJCut.HistName: MHAlpha
|
---|
312 | //
|
---|
313 | Bool_t MJCut::CheckEnvLocal()
|
---|
314 | {
|
---|
315 | const TString f0(GetEnv("SummaryFile", ""));
|
---|
316 | const TString f1(GetEnv("ResultFile", ""));
|
---|
317 | if (!f0.IsNull())
|
---|
318 | SetNameSummaryFile(f0);
|
---|
319 | if (!f1.IsNull())
|
---|
320 | SetNameResultFile(f1);
|
---|
321 |
|
---|
322 | EnableStorageOfSummary(GetEnv("SummaryFile", fStoreSummary));
|
---|
323 | EnableStorageOfResult(GetEnv("ResultFile", fStoreResult));
|
---|
324 | EnableWobbleMode(GetEnv("WobbleMode", fIsWobble));
|
---|
325 | EnableMonteCarloMode(GetEnv("MonteCarlo", fIsMonteCarlo));
|
---|
326 | EnableFullDisplay(GetEnv("FullDisplay", fFullDisplay));
|
---|
327 | EnableRandomSrcPos(GetEnv("RandomSourcePosition", fRndmSrcPos));
|
---|
328 | //EnableSubstraction(GetEnv("HistogramSubstraction", fSubstraction));
|
---|
329 |
|
---|
330 | SetNameHist(GetEnv("NameHist", fNameHist));
|
---|
331 | SetNameHistFS(GetEnv("NameHistFS", fNameHistFS));
|
---|
332 |
|
---|
333 | return kTRUE;
|
---|
334 | }
|
---|
335 |
|
---|
336 | // --------------------------------------------------------------------------
|
---|
337 | //
|
---|
338 | // Setup write to write:
|
---|
339 | // container tree optional?
|
---|
340 | // -------------- ---------- -----------
|
---|
341 | // "MHillas" to "Events"
|
---|
342 | // "MHillasSrc" to "Events"
|
---|
343 | // "Hadronness" to "Events" yes
|
---|
344 | // "MEnergyEst" to "Events" yes
|
---|
345 | // "DataType" to "Events"
|
---|
346 | //
|
---|
347 | void MJCut::SetupWriter(MWriteRootFile *write, const char *name) const
|
---|
348 | {
|
---|
349 | if (!write)
|
---|
350 | return;
|
---|
351 |
|
---|
352 | write->SetName(name);
|
---|
353 | write->AddContainer("MHillas", "Events");
|
---|
354 | write->AddContainer("MHillasSrc", "Events");
|
---|
355 | write->AddContainer("MHillasExt", "Events");
|
---|
356 | write->AddContainer("MPointingPos", "Events");
|
---|
357 | write->AddContainer("MHillasSrcAnti", "Events", kFALSE);
|
---|
358 | write->AddContainer("MImagePar", "Events", kFALSE);
|
---|
359 | write->AddContainer("MNewImagePar", "Events", kFALSE);
|
---|
360 | write->AddContainer("MNewImagePar2", "Events", kFALSE);
|
---|
361 | write->AddContainer("Hadronness", "Events", kFALSE);
|
---|
362 | write->AddContainer("MSrcPosCam", "Events", kFALSE);
|
---|
363 | write->AddContainer("MSrcPosAnti", "Events", kFALSE);
|
---|
364 | write->AddContainer("ThetaSquared", "Events", kFALSE);
|
---|
365 | write->AddContainer("OpticalAxis", "Events", kFALSE);
|
---|
366 | write->AddContainer("Disp", "Events", kFALSE);
|
---|
367 | write->AddContainer("MTime", "Events", kFALSE);
|
---|
368 | write->AddContainer("MMcEvt", "Events", kFALSE);
|
---|
369 | write->AddContainer("DataType", "Events");
|
---|
370 | // write->AddContainer("MMuonSearchPar", "Events", kFALSE);
|
---|
371 | // write->AddContainer("MMuonCalibPar", "Events", kFALSE);
|
---|
372 | }
|
---|
373 |
|
---|
374 | // --------------------------------------------------------------------------
|
---|
375 | //
|
---|
376 | // Create a new instance of an object with name name of class
|
---|
377 | // type fNameHist in parlist. It must derive from MHAlpha.
|
---|
378 | // Call ForceUsingSize for it and return its pointer.
|
---|
379 | // If something fails NULL is returned.
|
---|
380 | //
|
---|
381 | MHAlpha *MJCut::CreateNewHist(MParList &plist, const char *name) const
|
---|
382 | {
|
---|
383 | TClass *cls = gROOT->GetClass(fNameHist);
|
---|
384 | if (!cls)
|
---|
385 | {
|
---|
386 | *fLog << err << "Class " << fNameHist << " not found in dictionary... abort." << endl;
|
---|
387 | return NULL;
|
---|
388 | }
|
---|
389 | if (!cls->InheritsFrom(MHAlpha::Class()))
|
---|
390 | {
|
---|
391 | *fLog << err << "Class " << fNameHist << " doesn't inherit from MHAlpha... abort." << endl;
|
---|
392 | return NULL;
|
---|
393 | }
|
---|
394 |
|
---|
395 | const TString objname(Form("Hist%s", name));
|
---|
396 | MHAlpha *h = (MHAlpha*)plist.FindCreateObj(fNameHist, objname);
|
---|
397 | if (!h)
|
---|
398 | return NULL;
|
---|
399 |
|
---|
400 | h->ForceUsingSize();
|
---|
401 |
|
---|
402 | return h;
|
---|
403 | }
|
---|
404 |
|
---|
405 | // --------------------------------------------------------------------------
|
---|
406 | //
|
---|
407 | // Create a new instance of an object with name name of class
|
---|
408 | // type fNameHistFS in parlist. It must derive from MHFalseSource
|
---|
409 | // If something fails NULL is returned.
|
---|
410 | //
|
---|
411 | MH *MJCut::CreateNewHistFS(MParList &plist, const char *name) const
|
---|
412 | {
|
---|
413 | const TString cname(fNameHistFS.IsNull()?"MHFalseSource":fNameHistFS);
|
---|
414 |
|
---|
415 | TClass *cls = gROOT->GetClass(cname);
|
---|
416 | if (!cls)
|
---|
417 | {
|
---|
418 | *fLog << err << "Class " << cname << " not found in dictionary... abort." << endl;
|
---|
419 | return NULL;
|
---|
420 | }
|
---|
421 | if (!cls->InheritsFrom("MHFalseSource"))
|
---|
422 | {
|
---|
423 | *fLog << err << "Class " << cname << " doesn't inherit from MHFalseSource... abort." << endl;
|
---|
424 | return NULL;
|
---|
425 | }
|
---|
426 |
|
---|
427 | const TString objname(Form("FS%s", name));
|
---|
428 | return (MH*)plist.FindCreateObj(cname, objname);
|
---|
429 | }
|
---|
430 |
|
---|
431 | Bool_t MJCut::FillSrcPosCam(const MDataSet &set, MPointingPos &source, MHSrcPosCam &hsrcpos)
|
---|
432 | {
|
---|
433 | *fLog << inf;
|
---|
434 | fLog->Separator(GetDescriptor());
|
---|
435 | *fLog << "Filling MHSrcPosCam " << set.GetName() << endl;
|
---|
436 | *fLog << endl;
|
---|
437 |
|
---|
438 | // --------------------------------------------------------------------------------
|
---|
439 |
|
---|
440 | // Setup Parlist
|
---|
441 | MParList plist;
|
---|
442 | plist.AddToList(this); // take care of fDisplay!
|
---|
443 |
|
---|
444 | // Setup Tasklist
|
---|
445 | MTaskList tlist;
|
---|
446 | plist.AddToList(&tlist);
|
---|
447 |
|
---|
448 | // La Palma Magic1, Possible source position
|
---|
449 | MObservatory obs;
|
---|
450 | plist.AddToList(&obs);
|
---|
451 | plist.AddToList(&source);
|
---|
452 |
|
---|
453 | // Initialize default binnings
|
---|
454 | // MBinning bins1(18, 0, 90, "BinningSrcPosCam", "lin");
|
---|
455 | // plist.AddToList(&bins1);
|
---|
456 |
|
---|
457 | // ------------- Loop Off Data --------------------
|
---|
458 | MReadReports read;
|
---|
459 |
|
---|
460 | read.EnableAutoScheme();
|
---|
461 | read.AddToBranchList("MTimeEffectiveOnTime.*");
|
---|
462 | read.AddToBranchList("MEffectiveOnTime.*");
|
---|
463 |
|
---|
464 | read.AddTree("Events", "MTime.", MReadReports::kMaster);
|
---|
465 | read.AddTree("Drive", MReadReports::kRequired);
|
---|
466 | read.AddTree("Starguider", MReadReports::kRequired);
|
---|
467 | read.AddTree("EffectiveOnTime");
|
---|
468 |
|
---|
469 | set.AddFilesOn(read);
|
---|
470 |
|
---|
471 | MFillH fill(&hsrcpos, "MSrcPosCam", "FillSrcPosCam");
|
---|
472 | fill.SetNameTab("SrcPos");
|
---|
473 |
|
---|
474 | // How to get source position from off- and on-data?
|
---|
475 | MSrcPosCorrect scor;
|
---|
476 | MSrcPosCalc scalc;
|
---|
477 | scalc.SetMode(MSrcPosCalc::kDefault);
|
---|
478 |
|
---|
479 | MPointingDevCalc devcalc;
|
---|
480 |
|
---|
481 | tlist.AddToList(&read);
|
---|
482 | tlist.AddToList(&devcalc, "Starguider");
|
---|
483 | tlist.AddToList(&scalc, "Events");
|
---|
484 | tlist.AddToList(&scor, "Events");
|
---|
485 | tlist.AddToList(&fill, "Events");
|
---|
486 |
|
---|
487 | // by setting it here it is distributed to all consecutive tasks
|
---|
488 | tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
|
---|
489 | read.SetAccelerator();//MTask::kAccDontReset|MTask::kAccDontCount);
|
---|
490 |
|
---|
491 | // Create and setup the eventloop
|
---|
492 | MEvtLoop evtloop(fName);
|
---|
493 | evtloop.SetParList(&plist);
|
---|
494 | evtloop.SetDisplay(fDisplay);
|
---|
495 | evtloop.SetLogStream(fLog);
|
---|
496 | if (!SetupEnv(evtloop))
|
---|
497 | return kFALSE;
|
---|
498 |
|
---|
499 | // Execute first analysis
|
---|
500 | if (!evtloop.Eventloop(fMaxEvents))
|
---|
501 | {
|
---|
502 | *fLog << err << GetDescriptor() << ": Processing of on-sequences failed." << endl;
|
---|
503 | return kFALSE;
|
---|
504 | }
|
---|
505 |
|
---|
506 | if (!evtloop.GetDisplay())
|
---|
507 | {
|
---|
508 | *fLog << err << GetDescriptor() << ": Execution stopped by user." << endl;
|
---|
509 | return kFALSE;
|
---|
510 | }
|
---|
511 |
|
---|
512 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
---|
513 | *fLog << endl << endl;
|
---|
514 |
|
---|
515 | return kTRUE;
|
---|
516 | }
|
---|
517 |
|
---|
518 | Bool_t MJCut::Process(const MDataSet &set)
|
---|
519 | {
|
---|
520 | if (!set.IsValid())
|
---|
521 | {
|
---|
522 | *fLog << err << "ERROR - DataSet invalid!" << endl;
|
---|
523 | return kFALSE;
|
---|
524 | }
|
---|
525 |
|
---|
526 | CheckEnv();
|
---|
527 |
|
---|
528 | // --------------------------------------------------------------------------------
|
---|
529 |
|
---|
530 | // Possible source position (eg. Wobble Mode)
|
---|
531 | MPointingPos source("MSourcePos");
|
---|
532 | if (set.HasSource())
|
---|
533 | {
|
---|
534 | if (!set.GetSourcePos(source))
|
---|
535 | return kFALSE;
|
---|
536 | *fLog << all;
|
---|
537 | source.Print("RaDec");
|
---|
538 | }
|
---|
539 | else
|
---|
540 | *fLog << all << "No source position applied..." << endl;
|
---|
541 |
|
---|
542 | MParList plist;
|
---|
543 |
|
---|
544 | MHSrcPosCam hsrcpos;
|
---|
545 | if (!fIsWobble && source.IsInitialized() && fRndmSrcPos)
|
---|
546 | {
|
---|
547 | if (!FillSrcPosCam(set, source, hsrcpos))
|
---|
548 | return kFALSE;
|
---|
549 | plist.AddToList(&hsrcpos);
|
---|
550 | }
|
---|
551 |
|
---|
552 | // --------------------------------------------------------------------------------
|
---|
553 |
|
---|
554 | *fLog << inf;
|
---|
555 | fLog->Separator(GetDescriptor());
|
---|
556 | *fLog << "Perform cuts for data set " << set.GetName() << endl;
|
---|
557 | *fLog << endl;
|
---|
558 |
|
---|
559 | // --------------------------------------------------------------------------------
|
---|
560 |
|
---|
561 | // Setup Parlist
|
---|
562 | plist.AddToList(this); // take care of fDisplay!
|
---|
563 |
|
---|
564 | MParameterI par("DataType");
|
---|
565 | plist.AddToList(&par);
|
---|
566 |
|
---|
567 | // Setup Tasklist
|
---|
568 | MTaskList tlist;
|
---|
569 | plist.AddToList(&tlist);
|
---|
570 |
|
---|
571 | // La Palma Magic1
|
---|
572 | MObservatory obs;
|
---|
573 | plist.AddToList(&obs);
|
---|
574 |
|
---|
575 | if (source.IsInitialized())
|
---|
576 | plist.AddToList(&source);
|
---|
577 |
|
---|
578 | // Initialize default binnings
|
---|
579 | MBinning bins1(18, 0, 90, "BinningAlpha", "lin");
|
---|
580 | MBinning bins2(15, 10, 1e6 , "BinningSize", "log");
|
---|
581 | MBinning bins3(67, -0.005, 0.665, "BinningTheta", "asin");
|
---|
582 | MBinning bins4("BinningFalseSource");
|
---|
583 | MBinning bins5("BinningWidth");
|
---|
584 | MBinning bins6("BinningLength");
|
---|
585 | MBinning bins7("BinningDist");
|
---|
586 | MBinning bins8("BinningMaxDist");
|
---|
587 | MBinning bins9("BinningM3Long");
|
---|
588 | MBinning bins0("BinningConc1");
|
---|
589 | plist.AddToList(&bins1);
|
---|
590 | plist.AddToList(&bins2);
|
---|
591 | plist.AddToList(&bins3);
|
---|
592 | plist.AddToList(&bins4);
|
---|
593 | plist.AddToList(&bins5);
|
---|
594 | plist.AddToList(&bins6);
|
---|
595 | plist.AddToList(&bins7);
|
---|
596 | plist.AddToList(&bins8);
|
---|
597 | plist.AddToList(&bins9);
|
---|
598 | plist.AddToList(&bins0);
|
---|
599 | //plist.AddToList(&binsa);
|
---|
600 |
|
---|
601 | // --------------------------------------------------------------------------------
|
---|
602 |
|
---|
603 | // Setup fitter and histograms
|
---|
604 | MAlphaFitter fit;
|
---|
605 | plist.AddToList(&fit);
|
---|
606 | if (fIsWobble)
|
---|
607 | fit.SetScaleMode(MAlphaFitter::kNone);
|
---|
608 |
|
---|
609 | MHAlpha *halphaoff = CreateNewHist(plist, "Off");
|
---|
610 | MFillH falpha(halphaoff, "", "FillHist");
|
---|
611 | MH *hfsoff = CreateNewHistFS(plist, "Off");
|
---|
612 | MFillH ffs(hfsoff, "MHillas", "FillFS");
|
---|
613 |
|
---|
614 | // FIXME: If fPathIn read cuts and energy estimator from file!
|
---|
615 | MContinue cont0("", "Cut0");
|
---|
616 | MContinue cont1("", "Cut1");
|
---|
617 | MContinue cont2("", "Cut2");
|
---|
618 | MContinue cont3("", "Cut3");
|
---|
619 | cont0.SetAllowEmpty();
|
---|
620 | cont1.SetAllowEmpty();
|
---|
621 | cont2.SetAllowEmpty();
|
---|
622 | cont3.SetAllowEmpty();
|
---|
623 |
|
---|
624 | // ------------- Loop Off Data --------------------
|
---|
625 | MReadReports readoffdata;
|
---|
626 | readoffdata.AddTree("Events", "MTime.", MReadReports::kMaster);
|
---|
627 | readoffdata.AddTree("Drive", MReadReports::kRequired);
|
---|
628 | readoffdata.AddTree("Starguider", MReadReports::kRequired);
|
---|
629 | readoffdata.AddTree("EffectiveOnTime");
|
---|
630 |
|
---|
631 | MReadMarsFile readoffmc("Events");
|
---|
632 | readoffmc.DisableAutoScheme();
|
---|
633 |
|
---|
634 | MRead &readoff = fIsMonteCarlo ? (MRead&)readoffmc : (MRead&)readoffdata;
|
---|
635 | if (fIsWobble)
|
---|
636 | set.AddFilesOn(readoff);
|
---|
637 | else
|
---|
638 | set.AddFilesOff(readoff);
|
---|
639 |
|
---|
640 | const TString path(Form("%s/", fPathOut.Data()));
|
---|
641 | TString fname0(path);
|
---|
642 | TString fname1(path);
|
---|
643 | fname0 += fNameSummary.IsNull() ? (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
|
---|
644 | fname1 += fNameResult.IsNull() ? (TString) Form("ganymed%08d.root", set.GetNumAnalysis()) : fNameResult;
|
---|
645 |
|
---|
646 | MWriteRootFile *write0 = CanStoreSummary() ? new MWriteRootFile(fPathOut.IsNull()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW") : 0;
|
---|
647 | MWriteRootFile *write1 = CanStoreResult() ? new MWriteRootFile(fPathOut.IsNull()?0:fname1.Data(), fOverwrite?"RECREATE":"NEW") : 0;
|
---|
648 | SetupWriter(write0, "WriteAfterCut0");
|
---|
649 | SetupWriter(write1, "WriteAfterCut3");
|
---|
650 |
|
---|
651 | MTaskEnv taskenv2("CalcHadronness");
|
---|
652 | taskenv2.SetDefault(fCalcHadronness);
|
---|
653 |
|
---|
654 | MTaskEnv taskenv3("CalcDisp");
|
---|
655 | taskenv3.SetDefault(fCalcDisp);
|
---|
656 |
|
---|
657 | MFillH fill1a("MHHillasOffPre [MHHillas]", "MHillas", "FillHillasPre");
|
---|
658 | MFillH fill2a("MHHillasOffPost [MHHillas]", "MHillas", "FillHillasPost");
|
---|
659 | MFillH fill3a("MHVsSizeOffPost [MHVsSize]", "MHillasSrc", "FillVsSizePost");
|
---|
660 | MFillH fill4a("MHHilExtOffPost [MHHillasExt]", "MHillasSrc", "FillHilExtPost");
|
---|
661 | MFillH fill5a("MHHilSrcOffPost [MHHillasSrc]", "MHillasSrc", "FillHilSrcPost");
|
---|
662 | MFillH fill6a("MHImgParOffPost [MHImagePar]", "MImagePar", "FillImgParPost");
|
---|
663 | MFillH fill7a("MHNewParOffPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost");
|
---|
664 | fill1a.SetNameTab("PreCut");
|
---|
665 | fill2a.SetNameTab("PostCut");
|
---|
666 | fill3a.SetNameTab("VsSize");
|
---|
667 | fill4a.SetNameTab("HilExt");
|
---|
668 | fill5a.SetNameTab("HilSrc");
|
---|
669 | fill6a.SetNameTab("ImgPar");
|
---|
670 | fill7a.SetNameTab("NewPar");
|
---|
671 |
|
---|
672 | MPrint print2("MEffectiveOnTime");
|
---|
673 | print2.EnableSkip();
|
---|
674 |
|
---|
675 | // How to get source position from off- and on-data?
|
---|
676 | MSrcPosCalc scalc;
|
---|
677 | scalc.SetMode(fIsWobble?MSrcPosCalc::kWobble:MSrcPosCalc::kOffData); /********************/
|
---|
678 |
|
---|
679 | MSrcPosCorrect scor;
|
---|
680 |
|
---|
681 | MHillasCalc hcalc;
|
---|
682 | MHillasCalc hcalc2("MHillasCalcAnti");
|
---|
683 | hcalc.SetFlags(MHillasCalc::kCalcHillasSrc);
|
---|
684 | hcalc2.SetFlags(MHillasCalc::kCalcHillasSrc);
|
---|
685 | hcalc2.SetNameHillasSrc("MHillasSrcAnti");
|
---|
686 | hcalc2.SetNameSrcPosCam("MSrcPosAnti");
|
---|
687 |
|
---|
688 | MSrcPosRndm srcrndm;
|
---|
689 |
|
---|
690 | MTaskList tlist2;
|
---|
691 | tlist2.AddToList(&scalc);
|
---|
692 | tlist2.AddToList(&scor);
|
---|
693 | tlist2.AddToList(&srcrndm);
|
---|
694 | tlist2.AddToList(&hcalc);
|
---|
695 | if (fIsWobble)
|
---|
696 | tlist2.AddToList(&hcalc2);
|
---|
697 | //tlist2.AddToList(&taskenv1);
|
---|
698 | tlist2.AddToList(&taskenv2);
|
---|
699 | tlist2.AddToList(&taskenv3);
|
---|
700 | tlist2.AddToList(&cont0);
|
---|
701 | if (write0)
|
---|
702 | tlist2.AddToList(write0);
|
---|
703 | if (!fWriteOnly)
|
---|
704 | tlist2.AddToList(&fill1a);
|
---|
705 | tlist2.AddToList(&cont1);
|
---|
706 | if (!fWriteOnly && (!fIsWobble || !fNameHistFS.IsNull()))
|
---|
707 | tlist2.AddToList(&ffs);
|
---|
708 | tlist2.AddToList(&cont2);
|
---|
709 | if (!fWriteOnly)
|
---|
710 | {
|
---|
711 | tlist2.AddToList(&fill2a);
|
---|
712 | if (fFullDisplay)
|
---|
713 | {
|
---|
714 | tlist2.AddToList(&fill3a);
|
---|
715 | tlist2.AddToList(&fill4a);
|
---|
716 | tlist2.AddToList(&fill5a);
|
---|
717 | tlist2.AddToList(&fill6a);
|
---|
718 | tlist2.AddToList(&fill7a);
|
---|
719 | }
|
---|
720 | }
|
---|
721 | if (!fWriteOnly)
|
---|
722 | tlist2.AddToList(&falpha);
|
---|
723 | tlist2.AddToList(&cont3);
|
---|
724 | if (write1)
|
---|
725 | tlist2.AddToList(write1);
|
---|
726 |
|
---|
727 | MPointingDevCalc devcalc;
|
---|
728 |
|
---|
729 | tlist.AddToList(&readoff);
|
---|
730 | if (gLog.GetDebugLevel()>4)
|
---|
731 | tlist.AddToList(&print2, "EffectiveOnTime");
|
---|
732 | tlist.AddToList(&devcalc, "Starguider");
|
---|
733 | tlist.AddToList(&tlist2, "Events");
|
---|
734 |
|
---|
735 | // by setting it here it is distributed to all consecutive tasks
|
---|
736 | //tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
|
---|
737 |
|
---|
738 | par.SetVal(0);
|
---|
739 |
|
---|
740 | // Create and setup the eventloop
|
---|
741 | MEvtLoop evtloop(fName);
|
---|
742 | evtloop.SetParList(&plist);
|
---|
743 | evtloop.SetDisplay(fDisplay);
|
---|
744 | evtloop.SetLogStream(fLog);
|
---|
745 | if (!SetupEnv(evtloop))
|
---|
746 | return kFALSE;
|
---|
747 |
|
---|
748 | TObjArray cont;
|
---|
749 | cont.Add(&cont0);
|
---|
750 | cont.Add(&cont1);
|
---|
751 | cont.Add(&cont2);
|
---|
752 | cont.Add(&cont3);
|
---|
753 | //if (taskenv1.GetTask())
|
---|
754 | // cont.Add(taskenv1.GetTask());
|
---|
755 | if (taskenv2.GetTask())
|
---|
756 | cont.Add(taskenv2.GetTask());
|
---|
757 | if (taskenv3.GetTask())
|
---|
758 | cont.Add(taskenv3.GetTask());
|
---|
759 |
|
---|
760 | if (!WriteTasks(set.GetNumAnalysis(), cont))
|
---|
761 | return kFALSE;
|
---|
762 |
|
---|
763 | if (set.HasOffSequences() || fIsWobble)
|
---|
764 | {
|
---|
765 | // Execute first analysis
|
---|
766 | if (!evtloop.Eventloop(fMaxEvents))
|
---|
767 | {
|
---|
768 | *fLog << err << GetDescriptor() << ": Processing of off-sequences failed." << endl;
|
---|
769 | return kFALSE;
|
---|
770 | }
|
---|
771 |
|
---|
772 | if (!evtloop.GetDisplay())
|
---|
773 | {
|
---|
774 | *fLog << err << GetDescriptor() << ": Execution stopped by user." << endl;
|
---|
775 | return kFALSE;
|
---|
776 | }
|
---|
777 |
|
---|
778 | //plist.FindObject("MTimeEffectiveOnTime")->Clear();
|
---|
779 | }
|
---|
780 | else
|
---|
781 | {
|
---|
782 | // This is the simplest way to remove the two object from the parlist
|
---|
783 | delete halphaoff;
|
---|
784 | delete hfsoff;
|
---|
785 | }
|
---|
786 |
|
---|
787 | // ------------- Loop On Data --------------------
|
---|
788 | MReadReports readondata;
|
---|
789 | readondata.AddTree("Events", "MTime.", MReadReports::kMaster);
|
---|
790 | readondata.AddTree("Drive", MReadReports::kRequired);
|
---|
791 | readondata.AddTree("Starguider", MReadReports::kRequired);
|
---|
792 | readondata.AddTree("EffectiveOnTime");
|
---|
793 |
|
---|
794 | MReadMarsFile readonmc("Events");
|
---|
795 | readonmc.DisableAutoScheme();
|
---|
796 |
|
---|
797 | MRead &readon = fIsMonteCarlo ? (MRead&)readonmc : (MRead&)readondata;
|
---|
798 | set.AddFilesOn(readon);
|
---|
799 |
|
---|
800 | scalc.SetMode(MSrcPosCalc::kDefault);
|
---|
801 |
|
---|
802 | MFillH fill1b("MHHillasOnPre [MHHillas]", "MHillas", "FillHillasPre");
|
---|
803 | MFillH fill2b("MHHillasOnPost [MHHillas]", "MHillas", "FillHillasPost");
|
---|
804 | MFillH fill3b("MHVsSizeOnPost [MHVsSize]", "MHillasSrc", "FillVsSizePost");
|
---|
805 | MFillH fill4b("MHHilExtOnPost [MHHillasExt]", "MHillasSrc", "FillHilExtPost");
|
---|
806 | MFillH fill5b("MHHilSrcOnPost [MHHillasSrc]", "MHillasSrc", "FillHilSrcPost");
|
---|
807 | MFillH fill6b("MHImgParOnPost [MHImagePar]", "MImagePar", "FillImgParPost");
|
---|
808 | MFillH fill7b("MHNewParOnPost [MHNewImagePar]", "MNewImagePar", "FillNewParPost");
|
---|
809 | fill1b.SetNameTab("PreCut");
|
---|
810 | fill2b.SetNameTab("PostCut");
|
---|
811 | fill3b.SetNameTab("VsSize");
|
---|
812 | fill4b.SetNameTab("HilExt");
|
---|
813 | fill5b.SetNameTab("HilSrc");
|
---|
814 | fill6b.SetNameTab("ImgPar");
|
---|
815 | fill7b.SetNameTab("NewPar");
|
---|
816 | fill1b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
|
---|
817 | fill2b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
|
---|
818 | fill3b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
|
---|
819 | fill4b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
|
---|
820 | fill5b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
|
---|
821 | fill6b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
|
---|
822 | fill7b.SetDrawOption(set.HasOffSequences()||fIsWobble?"same":"");
|
---|
823 |
|
---|
824 | /*
|
---|
825 | MHVsTime hvs("MEffectiveOnTime.fVal");
|
---|
826 | hvs.SetTitle("Effective On-Time vs. Time;;T_{on}");
|
---|
827 | MFillH fillvs(&hvs, "MTimeEffectiveOnTime", "FillOnTime");
|
---|
828 | fillvs.SetNameTab("OnTime");
|
---|
829 | */
|
---|
830 | MH3 hvs("MPointingPos.fZd");
|
---|
831 | hvs.SetName("Theta");
|
---|
832 | hvs.SetTitle("Effective On-Time vs. Zenith Angle;\\Theta [\\circ];T_{on} [s]");
|
---|
833 | MFillH fillvs(&hvs, "", "FillOnTime");
|
---|
834 | if (!fIsMonteCarlo)
|
---|
835 | fillvs.SetWeight("MEffectiveOnTime");
|
---|
836 | fillvs.SetNameTab("OnTime");
|
---|
837 |
|
---|
838 | /*
|
---|
839 | MParameterD weight;
|
---|
840 | weight.SetVal(-1);
|
---|
841 | fill2a.SetWeight(&weight);
|
---|
842 | fill3a.SetWeight(&weight);
|
---|
843 | fill4a.SetWeight(&weight);
|
---|
844 | fill5a.SetWeight(&weight);
|
---|
845 | fill6a.SetWeight(&weight);
|
---|
846 | fill7a.SetWeight(&weight);
|
---|
847 | if (fSubstraction)
|
---|
848 | {
|
---|
849 | fill2a.SetNameTab("PostCut-");
|
---|
850 | fill3a.SetNameTab("VsSize-");
|
---|
851 | fill4a.SetNameTab("HilExt-");
|
---|
852 | fill5a.SetNameTab("HilSrc-");
|
---|
853 | fill6a.SetNameTab("ImgPar-");
|
---|
854 | fill7a.SetNameTab("NewPar-");
|
---|
855 | }
|
---|
856 | */
|
---|
857 | MHAlpha *halphaon=CreateNewHist(plist);
|
---|
858 | MFillH falpha2(halphaon, "", "FillHist");
|
---|
859 | MH *hfs=CreateNewHistFS(plist);
|
---|
860 | MFillH ffs2(hfs, "MHillas", "FillFS");
|
---|
861 | MFillH fillphi("MHPhi", "", "FillPhi");
|
---|
862 | fillphi.SetDrawOption("anticut");
|
---|
863 |
|
---|
864 | tlist.Replace(&readon);
|
---|
865 | if (!fWriteOnly)
|
---|
866 | {
|
---|
867 | tlist2.Replace(&fill1b);
|
---|
868 | /* if (fIsWobble)
|
---|
869 | {
|
---|
870 | tlist2.AddToListAfter(&fill2b, &fill2a);
|
---|
871 | tlist2.AddToListAfter(&fill3b, &fill3a);
|
---|
872 | }
|
---|
873 | else
|
---|
874 | */
|
---|
875 | tlist2.Replace(&fill2b);
|
---|
876 | if (fFullDisplay)
|
---|
877 | {
|
---|
878 | tlist2.Replace(&fill3b);
|
---|
879 | tlist2.Replace(&fill4b);
|
---|
880 | tlist2.Replace(&fill5b);
|
---|
881 | tlist2.Replace(&fill6b);
|
---|
882 | tlist2.Replace(&fill7b);
|
---|
883 | }
|
---|
884 | tlist2.Replace(&falpha2);
|
---|
885 | if (!fIsWobble || !fNameHist.IsNull())
|
---|
886 | tlist2.Replace(&ffs2);
|
---|
887 | if (fIsWobble)
|
---|
888 | {
|
---|
889 | tlist2.AddToListAfter(&fillphi, &falpha2);
|
---|
890 | if (!fNameHist.IsNull())
|
---|
891 | tlist2.RemoveFromList(&ffs);
|
---|
892 | }
|
---|
893 |
|
---|
894 | if (!fIsMonteCarlo)
|
---|
895 | tlist.AddToList(&fillvs, "EffectiveOnTime");
|
---|
896 | else
|
---|
897 | tlist2.AddToListBefore(&fillvs, &scalc);
|
---|
898 | }
|
---|
899 |
|
---|
900 | // by setting it here it is distributed to all consecutive tasks
|
---|
901 | //tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime);
|
---|
902 |
|
---|
903 | par.SetVal(1);
|
---|
904 |
|
---|
905 | // Execute first analysis
|
---|
906 | if (!evtloop.Eventloop(fMaxEvents))
|
---|
907 | {
|
---|
908 | *fLog << err << GetDescriptor() << ": Processing of on-sequences failed." << endl;
|
---|
909 | return kFALSE;
|
---|
910 | }
|
---|
911 |
|
---|
912 | if (write0)
|
---|
913 | delete write0;
|
---|
914 | if (write1)
|
---|
915 | delete write1;
|
---|
916 |
|
---|
917 | // FIXME: Perform fit and plot energy dependant alpha plots
|
---|
918 | // and fit result to new tabs!
|
---|
919 | if (!WriteResult(plist, set.GetNumAnalysis()))
|
---|
920 | return kFALSE;
|
---|
921 |
|
---|
922 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
---|
923 | *fLog << endl << endl;
|
---|
924 |
|
---|
925 | return kTRUE;
|
---|
926 | }
|
---|