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