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("MNewImagePar", "Events", kFALSE);
|
---|
334 | write->AddContainer("MNewImagePar2", "Events", kFALSE);
|
---|
335 | write->AddContainer("MHadronness", "Events", kFALSE);
|
---|
336 | write->AddContainer("MEnergyEst", "Events", kFALSE);
|
---|
337 | write->AddContainer("ThetaSquared", "Events", kFALSE);
|
---|
338 | write->AddContainer("MMcEvt", "Events", kFALSE);
|
---|
339 | write->AddContainer("DataType", "Events");
|
---|
340 |
|
---|
341 | // Should not be the default: Either as option, or as
|
---|
342 | // setup from resource file
|
---|
343 | // write.AddContainer("MHillasExt", "Events");
|
---|
344 | // write.AddContainer("MImagePar", "Events");
|
---|
345 | // write.AddContainer("MNewImagePar", "Events");
|
---|
346 | }
|
---|
347 |
|
---|
348 | // --------------------------------------------------------------------------
|
---|
349 | //
|
---|
350 | // Create a new instance of an object with name name of class
|
---|
351 | // type fNameHist in parlist. It must derive from MHAlpha.
|
---|
352 | // Call ForceUsingSize for it and return its pointer.
|
---|
353 | // If something fails NULL is returned.
|
---|
354 | //
|
---|
355 | MHAlpha *MJCut::CreateNewHist(MParList &plist, const char *name) const
|
---|
356 | {
|
---|
357 | TClass *cls = gROOT->GetClass(fNameHist);
|
---|
358 | if (!cls)
|
---|
359 | {
|
---|
360 | *fLog << err << "Class " << fNameHist << " not found in dictionary... abort." << endl;
|
---|
361 | return NULL;
|
---|
362 | }
|
---|
363 | if (!cls->InheritsFrom(MHAlpha::Class()))
|
---|
364 | {
|
---|
365 | *fLog << err << "Class " << fNameHist << " doesn't inherit from MHAlpha... abort." << endl;
|
---|
366 | return NULL;
|
---|
367 | }
|
---|
368 |
|
---|
369 | const TString objname(Form("Hist%s", name));
|
---|
370 | MHAlpha *h = (MHAlpha*)plist.FindCreateObj(fNameHist, objname);
|
---|
371 | if (!h)
|
---|
372 | return NULL;
|
---|
373 |
|
---|
374 | h->ForceUsingSize();
|
---|
375 |
|
---|
376 | return h;
|
---|
377 | }
|
---|
378 |
|
---|
379 | // --------------------------------------------------------------------------
|
---|
380 | //
|
---|
381 | // Create a new instance of an object with name name of class
|
---|
382 | // type fNameHistFS in parlist. It must derive from MHFalseSource
|
---|
383 | // If something fails NULL is returned.
|
---|
384 | //
|
---|
385 | MH *MJCut::CreateNewHistFS(MParList &plist, const char *name) const
|
---|
386 | {
|
---|
387 | const TString cname(fNameHistFS.IsNull()?"MHFalseSource":fNameHistFS);
|
---|
388 |
|
---|
389 | TClass *cls = gROOT->GetClass(cname);
|
---|
390 | if (!cls)
|
---|
391 | {
|
---|
392 | *fLog << err << "Class " << cname << " not found in dictionary... abort." << endl;
|
---|
393 | return NULL;
|
---|
394 | }
|
---|
395 | if (!cls->InheritsFrom("MHFalseSource"))
|
---|
396 | {
|
---|
397 | *fLog << err << "Class " << cname << " doesn't inherit from MHFalseSource... abort." << endl;
|
---|
398 | return NULL;
|
---|
399 | }
|
---|
400 |
|
---|
401 | const TString objname(Form("FS%s", name));
|
---|
402 | return (MH*)plist.FindCreateObj(cname, objname);
|
---|
403 | }
|
---|
404 |
|
---|
405 | Bool_t MJCut::Process(const MDataSet &set)
|
---|
406 | {
|
---|
407 | if (!set.IsValid())
|
---|
408 | {
|
---|
409 | *fLog << err << "ERROR - DataSet invalid!" << endl;
|
---|
410 | return kFALSE;
|
---|
411 | }
|
---|
412 |
|
---|
413 | CheckEnv();
|
---|
414 |
|
---|
415 | // --------------------------------------------------------------------------------
|
---|
416 |
|
---|
417 | *fLog << inf;
|
---|
418 | fLog->Separator(GetDescriptor());
|
---|
419 | *fLog << "Perform cuts for data set " << set.GetName() << endl;
|
---|
420 | *fLog << endl;
|
---|
421 |
|
---|
422 | // --------------------------------------------------------------------------------
|
---|
423 |
|
---|
424 | // Setup Parlist
|
---|
425 | MParList plist;
|
---|
426 | plist.AddToList(this); // take care of fDisplay!
|
---|
427 |
|
---|
428 | MParameterI par("DataType");
|
---|
429 | plist.AddToList(&par);
|
---|
430 |
|
---|
431 | // Setup Tasklist
|
---|
432 | MTaskList tlist;
|
---|
433 | plist.AddToList(&tlist);
|
---|
434 |
|
---|
435 | // La Palma Magic1
|
---|
436 | MObservatory obs;
|
---|
437 | plist.AddToList(&obs);
|
---|
438 |
|
---|
439 | // Possible source position (eg. Wobble Mode)
|
---|
440 | MPointingPos source("MSourcePos");
|
---|
441 | if (set.GetSourcePos(source))
|
---|
442 | {
|
---|
443 | plist.AddToList(&source);
|
---|
444 | *fLog << inf << "Using Source Position: " << source.GetTitle() << endl;
|
---|
445 | }
|
---|
446 | else
|
---|
447 | *fLog << inf << "No source position applied..." << endl;
|
---|
448 |
|
---|
449 | // Initialize default binnings
|
---|
450 | MBinning bins1(18, 0, 90, "BinningAlpha", "lin");
|
---|
451 | MBinning bins2(15, 10, 1e6 , "BinningEnergyEst", "log");
|
---|
452 | MBinning bins3(50, 0, 60, "BinningTheta", "cos");
|
---|
453 | MBinning bins4("BinningFalseSource");
|
---|
454 | MBinning bins5("BinningWidth");
|
---|
455 | MBinning bins6("BinningLength");
|
---|
456 | MBinning bins7("BinningDist");
|
---|
457 | MBinning bins8("BinningMaxDist");
|
---|
458 | MBinning bins9("BinningM3Long");
|
---|
459 | MBinning bins0("BinningConc1");
|
---|
460 | plist.AddToList(&bins1);
|
---|
461 | plist.AddToList(&bins2);
|
---|
462 | plist.AddToList(&bins3);
|
---|
463 | plist.AddToList(&bins4);
|
---|
464 | plist.AddToList(&bins5);
|
---|
465 | plist.AddToList(&bins6);
|
---|
466 | plist.AddToList(&bins7);
|
---|
467 | plist.AddToList(&bins8);
|
---|
468 | plist.AddToList(&bins9);
|
---|
469 | plist.AddToList(&bins0);
|
---|
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 | if (fIsWobble)
|
---|
550 | scalc.SetWobbleMode(); /********************/
|
---|
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 | tlist.AddToList(&print2, "EffectiveOnTime");
|
---|
594 | tlist.AddToList(&tlist2, "Events");
|
---|
595 |
|
---|
596 | par.SetVal(0);
|
---|
597 |
|
---|
598 | // Create and setup the eventloop
|
---|
599 | MEvtLoop evtloop(fName);
|
---|
600 | evtloop.SetParList(&plist);
|
---|
601 | evtloop.SetDisplay(fDisplay);
|
---|
602 | evtloop.SetLogStream(fLog);
|
---|
603 | if (!SetupEnv(evtloop))
|
---|
604 | return kFALSE;
|
---|
605 |
|
---|
606 | TObjArray cont;
|
---|
607 | cont.Add(&cont0);
|
---|
608 | cont.Add(&cont1);
|
---|
609 | cont.Add(&cont2);
|
---|
610 | cont.Add(&cont3);
|
---|
611 | //if (taskenv1.GetTask())
|
---|
612 | // cont.Add(taskenv1.GetTask());
|
---|
613 | if (taskenv2.GetTask())
|
---|
614 | cont.Add(taskenv2.GetTask());
|
---|
615 |
|
---|
616 | if (!WriteTasks(set.GetNumAnalysis(), cont))
|
---|
617 | return kFALSE;
|
---|
618 |
|
---|
619 | if (set.HasOffSequences() || fIsWobble)
|
---|
620 | {
|
---|
621 | // Execute first analysis
|
---|
622 | if (!evtloop.Eventloop(fMaxEvents))
|
---|
623 | {
|
---|
624 | *fLog << err << GetDescriptor() << ": Processing of off-sequences failed." << endl;
|
---|
625 | return kFALSE;
|
---|
626 | }
|
---|
627 |
|
---|
628 | if (!evtloop.GetDisplay())
|
---|
629 | {
|
---|
630 | *fLog << err << GetDescriptor() << ": Execution stopped by user." << endl;
|
---|
631 | return kFALSE;
|
---|
632 | }
|
---|
633 |
|
---|
634 | //plist.FindObject("MTimeEffectiveOnTime")->Clear();
|
---|
635 | }
|
---|
636 |
|
---|
637 | // ------------- Loop On Data --------------------
|
---|
638 | MReadReports readondata;
|
---|
639 | readondata.AddTree("Events", "MTime.", MReadReports::kMaster);
|
---|
640 | readondata.AddTree("Drive", MReadReports::kRequired);
|
---|
641 | readondata.AddTree("EffectiveOnTime");
|
---|
642 |
|
---|
643 | MReadMarsFile readonmc("Events");
|
---|
644 | readonmc.DisableAutoScheme();
|
---|
645 |
|
---|
646 | MRead &readon = fIsMonteCarlo ? (MRead&)readonmc : (MRead&)readondata;
|
---|
647 | set.AddFilesOn(readon);
|
---|
648 |
|
---|
649 | if (fIsWobble)
|
---|
650 | scalc.SetWobbleMode(kFALSE); /********************/
|
---|
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 | }
|
---|