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/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MJStar
|
---|
28 | //
|
---|
29 | // Resource file entries are case sensitive!
|
---|
30 | //
|
---|
31 | /////////////////////////////////////////////////////////////////////////////
|
---|
32 | #include "MJStar.h"
|
---|
33 |
|
---|
34 | #include <TEnv.h>
|
---|
35 | #include <TFile.h>
|
---|
36 |
|
---|
37 | #include "MLog.h"
|
---|
38 | #include "MLogManip.h"
|
---|
39 |
|
---|
40 | #include "MDirIter.h"
|
---|
41 | #include "MParList.h"
|
---|
42 | #include "MTaskList.h"
|
---|
43 | #include "MEvtLoop.h"
|
---|
44 |
|
---|
45 | #include "MStatusDisplay.h"
|
---|
46 |
|
---|
47 | #include "MH3.h"
|
---|
48 | #include "MHVsTime.h"
|
---|
49 | #include "MHCamEvent.h"
|
---|
50 | #include "MHCamEventRot.h"
|
---|
51 | #include "MBinning.h"
|
---|
52 |
|
---|
53 | #include "MReadReports.h"
|
---|
54 | #include "MReadMarsFile.h"
|
---|
55 | #include "MFDeltaT.h"
|
---|
56 | #include "MFSoftwareTrigger.h"
|
---|
57 | #include "MContinue.h"
|
---|
58 | #include "MGeomApply.h"
|
---|
59 | #include "MEventRateCalc.h"
|
---|
60 | #include "MImgCleanStd.h"
|
---|
61 | #include "MSrcPosCalc.h"
|
---|
62 | #include "MHillasCalc.h"
|
---|
63 | #include "MFillH.h"
|
---|
64 | #include "MWriteRootFile.h"
|
---|
65 |
|
---|
66 | #include "MObservatory.h"
|
---|
67 | #include "MPointingPosCalc.h"
|
---|
68 |
|
---|
69 | ClassImp(MJStar);
|
---|
70 |
|
---|
71 | using namespace std;
|
---|
72 |
|
---|
73 | // --------------------------------------------------------------------------
|
---|
74 | //
|
---|
75 | // Default constructor.
|
---|
76 | //
|
---|
77 | // Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
|
---|
78 | //
|
---|
79 | MJStar::MJStar(const char *name, const char *title)
|
---|
80 | {
|
---|
81 | fName = name ? name : "MJStar";
|
---|
82 | fTitle = title ? title : "Standard analysis and reconstruction";
|
---|
83 | }
|
---|
84 |
|
---|
85 | Bool_t MJStar::WriteResult()
|
---|
86 | {
|
---|
87 | if (fPathOut.IsNull())
|
---|
88 | {
|
---|
89 | *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
|
---|
90 | return kTRUE;
|
---|
91 | }
|
---|
92 |
|
---|
93 | const TString oname = Form("%s/star%08d.root", (const char*)fPathOut, fSequence.GetSequence());
|
---|
94 |
|
---|
95 | *fLog << inf << "Writing to file: " << oname << endl;
|
---|
96 |
|
---|
97 | TFile file(oname, "RECREATE");
|
---|
98 |
|
---|
99 | *fLog << inf << " - MStatusDisplay..." << flush;
|
---|
100 | if (fDisplay && fDisplay->Write()<=0)
|
---|
101 | {
|
---|
102 | *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
|
---|
103 | return kFALSE;
|
---|
104 | }
|
---|
105 | *fLog << inf << "ok." << endl;
|
---|
106 |
|
---|
107 | return kTRUE;
|
---|
108 | }
|
---|
109 |
|
---|
110 | Bool_t MJStar::ProcessFile(Bool_t ismc)
|
---|
111 | {
|
---|
112 | if (!fSequence.IsValid())
|
---|
113 | {
|
---|
114 | *fLog << err << "ERROR - Sequence invalid!" << endl;
|
---|
115 | return kFALSE;
|
---|
116 | }
|
---|
117 |
|
---|
118 | //if (!CheckEnv())
|
---|
119 | // return kFALSE;
|
---|
120 |
|
---|
121 | CheckEnv();
|
---|
122 |
|
---|
123 | // --------------------------------------------------------------------------------
|
---|
124 |
|
---|
125 | *fLog << inf;
|
---|
126 | fLog->Separator(GetDescriptor());
|
---|
127 | *fLog << "Calculate image parameters of sequence ";
|
---|
128 | *fLog << fSequence.GetName() << endl;
|
---|
129 | *fLog << endl;
|
---|
130 |
|
---|
131 | // --------------------------------------------------------------------------------
|
---|
132 |
|
---|
133 | MDirIter iter;
|
---|
134 | const Int_t n0 = fSequence.SetupDatRuns(iter, fPathData, "Y");
|
---|
135 | const Int_t n1 = fSequence.GetNumDatRuns();
|
---|
136 | if (n0==0)
|
---|
137 | {
|
---|
138 | *fLog << err << "ERROR - No input files of sequence found!" << endl;
|
---|
139 | return kFALSE;
|
---|
140 | }
|
---|
141 | if (n0!=n1)
|
---|
142 | {
|
---|
143 | *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
|
---|
144 | return kFALSE;
|
---|
145 | }
|
---|
146 |
|
---|
147 | // Setup Parlist
|
---|
148 | MParList plist;
|
---|
149 | plist.AddToList(this); // take care of fDisplay!
|
---|
150 |
|
---|
151 | MObservatory obs;
|
---|
152 | plist.AddToList(&obs);
|
---|
153 |
|
---|
154 | // Setup Tasklist
|
---|
155 | MTaskList tlist;
|
---|
156 | plist.AddToList(&tlist);
|
---|
157 |
|
---|
158 | MReadReports readreal;
|
---|
159 | readreal.AddTree("Events", "MTime.", kTRUE);
|
---|
160 | readreal.AddTree("Drive");
|
---|
161 | //read.AddTree("Trigger");
|
---|
162 | //read.AddTree("Camera");
|
---|
163 | //read.AddTree("CC");
|
---|
164 | //read.AddTree("Currents");
|
---|
165 | readreal.AddFiles(iter);
|
---|
166 |
|
---|
167 | MReadMarsFile readmc("Events");
|
---|
168 | readmc.DisableAutoScheme();
|
---|
169 | readmc.AddFiles(iter);
|
---|
170 |
|
---|
171 | // ------------------ Setup general tasks ----------------
|
---|
172 |
|
---|
173 | MFDeltaT fdeltat;
|
---|
174 | MContinue cont(&fdeltat, "FilterDeltaT", "Filter events with wrong timing");
|
---|
175 | cont.SetInverted();
|
---|
176 |
|
---|
177 | MGeomApply apply; // Only necessary to craete geometry
|
---|
178 | MEventRateCalc rate;
|
---|
179 | //MEventRateCalc rate1; // 5min
|
---|
180 | rate.SetNumEvents(1200);
|
---|
181 | //rate1.SetNumEvents(60000);
|
---|
182 | //rate1.SetNameEventRate("MEventRate2");
|
---|
183 | //rate1.SetNameTimeRate("MTimeRate2");
|
---|
184 |
|
---|
185 | /*
|
---|
186 | MEventRateCalc rate10000;
|
---|
187 | rate10000.SetNameEventRate("MEventRate10000");
|
---|
188 | rate10000.SetNumEvents(10000);
|
---|
189 | */
|
---|
190 | //MBadPixelsMerge merge(&badpix);
|
---|
191 |
|
---|
192 | MFSoftwareTrigger swtrig;
|
---|
193 | MContinue contsw(&swtrig, "FilterSwTrigger", "Software trigger");
|
---|
194 | contsw.SetInverted();
|
---|
195 |
|
---|
196 |
|
---|
197 | MImgCleanStd clean;
|
---|
198 | clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
|
---|
199 |
|
---|
200 | MSrcPosCalc poscalc;
|
---|
201 | MHillasCalc hcalc;
|
---|
202 |
|
---|
203 | // ------------------ Setup histograms and fill tasks ----------------
|
---|
204 | MHCamEvent evt0a(0, "Cleaned", "Signal after Cleaning;;S [\\gamma]");
|
---|
205 | MHCamEvent evt0b(0, "UsedPix", "Pixels marked Used;;Used [%]");
|
---|
206 | evt0b.SetThreshold(0);
|
---|
207 |
|
---|
208 | //MHCamEventRot evt0r("UsedRot", "Pixels marked Used (derotated)");
|
---|
209 | //evt0r.SetThreshold(0);
|
---|
210 |
|
---|
211 | MH3 h1("MEventRate.fRate");
|
---|
212 | h1.SetName("MHEventRate");
|
---|
213 | h1.SetTitle("Event Rate distribution;R [Hz];Counts");
|
---|
214 | h1.SetLogy();
|
---|
215 | /*
|
---|
216 | MH3 h12("MEventRate10000.fRate");
|
---|
217 | h12.SetName("MHEventRate");
|
---|
218 | h12.SetLogy();
|
---|
219 | */
|
---|
220 | MBinning b1("BinningMHEventRate");
|
---|
221 | b1.SetEdges(150, 0, 1500);
|
---|
222 | plist.AddToList(&b1);
|
---|
223 |
|
---|
224 | MHVsTime hvs("MEventRate.fRate");
|
---|
225 | hvs.SetTitle("Rate per 500 events;R [Hz];Counts");
|
---|
226 | hvs.SetNumEvents(500);
|
---|
227 |
|
---|
228 | //MContinue cont1("MEventRate2.fRate/MEventRate.fRate>1.1");
|
---|
229 | //MContinue cont2("MEventRate.fRate/MEventRate2.fRate>1.1");
|
---|
230 |
|
---|
231 | MFillH fillvs(&hvs, "MTime", "FillEventRate10s");
|
---|
232 |
|
---|
233 | MFillH fill0a(&evt0a, "MCerPhotEvt", "FillCerPhotEvt");
|
---|
234 | MFillH fill0b(&evt0b, "MCerPhotEvt", "FillCntUsedPixels");
|
---|
235 | //MFillH fill0r(&evt0r, "MCerPhotEvt", "FillCntUsedRotated");
|
---|
236 | MFillH fill1("MHHillas", "MHillas", "FillHillas");
|
---|
237 | MFillH fill2("MHHillasExt", "", "FillHillasExt");
|
---|
238 | MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
|
---|
239 | MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
|
---|
240 | MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
|
---|
241 | //MFillH fill6("MHImageParTime","MImageParTime","FillImageParTime");
|
---|
242 | //MFillH fill7("MHNewImagePar2","MNewImagePar2","FillNewImagePar2");
|
---|
243 | MFillH fill8(&h1, "", "FillEventRate");
|
---|
244 | MFillH fill9("MHEffectiveOnTime", "MTime", "FillEffOnTime");
|
---|
245 | //MFillH fillb(&h12, "", "FillEvtRate2");
|
---|
246 | //MFillH fill9("MHCerPhot");
|
---|
247 |
|
---|
248 | //fill0r.SetDrawOption("colz");
|
---|
249 | fill8.SetNameTab("EvtRate");
|
---|
250 | fill9.SetNameTab("EffOnTime");
|
---|
251 |
|
---|
252 | // ------------------ Setup write task ----------------
|
---|
253 |
|
---|
254 | MWriteRootFile write(2, Form("%s{s/_Y_/_I_}", fPathOut.Data()), fOverwrite?"RECREATE":"NEW");
|
---|
255 | // Data
|
---|
256 | write.AddContainer("MHillas", "Events");
|
---|
257 | write.AddContainer("MHillasExt", "Events");
|
---|
258 | write.AddContainer("MHillasSrc", "Events");
|
---|
259 | write.AddContainer("MImagePar", "Events");
|
---|
260 | write.AddContainer("MNewImagePar", "Events");
|
---|
261 | //write.AddContainer("MNewImagePar2", "Events");
|
---|
262 | //write.AddContainer("MImageParTime", "Events");
|
---|
263 | write.AddContainer("MRawEvtHeader", "Events");
|
---|
264 | write.AddContainer("MPointingPos", "Events");
|
---|
265 | if (ismc)
|
---|
266 | {
|
---|
267 | // Monte Carlo
|
---|
268 | write.AddContainer("MMcEvt", "Events");
|
---|
269 | write.AddContainer("MMcTrig", "Events");
|
---|
270 | // Monte Carlo Headers
|
---|
271 | write.AddContainer("MMcRunHeader", "RunHeaders");
|
---|
272 | write.AddContainer("MMcTrigHeader", "RunHeaders");
|
---|
273 | write.AddContainer("MMcConfigRunHeader", "RunHeaders");
|
---|
274 | write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
|
---|
275 | write.AddCopySource("OriginalMC");
|
---|
276 | }
|
---|
277 | else
|
---|
278 | {
|
---|
279 | write.AddContainer("MTime", "Events");
|
---|
280 | // Run Header
|
---|
281 | write.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
282 | write.AddContainer("MBadPixelsCam", "RunHeaders");
|
---|
283 | write.AddContainer("MGeomCam", "RunHeaders");
|
---|
284 | //write.AddContainer("MObservatory", "RunHeaders");
|
---|
285 | // Drive
|
---|
286 | //write.AddContainer("MSrcPosCam", "Drive");
|
---|
287 | write.AddContainer("MReportDrive", "Drive");
|
---|
288 | write.AddContainer("MTimeDrive", "Drive");
|
---|
289 | // Effective On Time
|
---|
290 | write.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
|
---|
291 | write.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
|
---|
292 | }
|
---|
293 |
|
---|
294 | MTaskList tlist2("Events");
|
---|
295 | tlist2.AddToList(&apply);
|
---|
296 | if (!ismc)
|
---|
297 | tlist2.AddToList(&cont);
|
---|
298 | tlist2.AddToList(&contsw);
|
---|
299 | if (!ismc)
|
---|
300 | {
|
---|
301 | tlist2.AddToList(&rate);
|
---|
302 | //tlist2.AddToList(&rate1);
|
---|
303 | tlist2.AddToList(&fillvs);
|
---|
304 | //tlist2.AddToList(&cont1);
|
---|
305 | //tlist2.AddToList(&cont2);
|
---|
306 | tlist2.AddToList(&fill8);
|
---|
307 | tlist2.AddToList(&fill9);
|
---|
308 | }
|
---|
309 | //tlist2.AddToList(&fillb);
|
---|
310 | tlist2.AddToList(&clean);
|
---|
311 | tlist2.AddToList(&fill0a);
|
---|
312 | tlist2.AddToList(&fill0b);
|
---|
313 | //tlist2.AddToList(&fill0r);
|
---|
314 | tlist2.AddToList(&poscalc);
|
---|
315 | tlist2.AddToList(&hcalc);
|
---|
316 | tlist2.AddToList(&fill1);
|
---|
317 | tlist2.AddToList(&fill2);
|
---|
318 | tlist2.AddToList(&fill3);
|
---|
319 | tlist2.AddToList(&fill4);
|
---|
320 | tlist2.AddToList(&fill5);
|
---|
321 | //tlist2.AddToList(&fill6);
|
---|
322 | //tlist2.AddToList(&fill7);
|
---|
323 | //tlist2.AddToList(&fill9);
|
---|
324 |
|
---|
325 | MPointingPosCalc pcalc;
|
---|
326 | //MSrcPosFromModel srcpos;
|
---|
327 |
|
---|
328 | MTaskList tlist3("Drive");
|
---|
329 | tlist3.AddToList(&pcalc);
|
---|
330 | //tlist3.AddToList(&srcpos);
|
---|
331 |
|
---|
332 | tlist.AddToList(ismc ? (MTask*)&readmc : (MTask*)&readreal);
|
---|
333 | tlist.AddToList(&tlist3, "Drive");
|
---|
334 | tlist.AddToList(&tlist2, "Events");
|
---|
335 | tlist.AddToList(&write);
|
---|
336 |
|
---|
337 | // Create and setup the eventloop
|
---|
338 | MEvtLoop evtloop(fName);
|
---|
339 | evtloop.SetParList(&plist);
|
---|
340 | evtloop.SetDisplay(fDisplay);
|
---|
341 | evtloop.SetLogStream(fLog);
|
---|
342 | if (!SetupEnv(evtloop))
|
---|
343 | return kFALSE;
|
---|
344 |
|
---|
345 | // Execute first analysis
|
---|
346 | if (!evtloop.Eventloop(fMaxEvents))
|
---|
347 | {
|
---|
348 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
349 | return kFALSE;
|
---|
350 | }
|
---|
351 |
|
---|
352 | tlist.PrintStatistics();
|
---|
353 |
|
---|
354 | if (!WriteResult())
|
---|
355 | return kFALSE;
|
---|
356 |
|
---|
357 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
---|
358 | *fLog << endl << endl;
|
---|
359 |
|
---|
360 | return kTRUE;
|
---|
361 | }
|
---|