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