source: trunk/MagicSoft/Mars/mjobs/MJStar.cc@ 6892

Last change on this file since 6892 was 6877, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 11.1 KB
Line 
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
69ClassImp(MJStar);
70
71using namespace std;
72
73// --------------------------------------------------------------------------
74//
75// Default constructor.
76//
77// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
78//
79MJStar::MJStar(const char *name, const char *title)
80{
81 fName = name ? name : "MJStar";
82 fTitle = title ? title : "Standard analysis and reconstruction";
83}
84
85Bool_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
110Bool_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 if (fLog->GetDebugLevel()>4)
145 {
146 *fLog << dbg << "Files which are searched:" << endl;
147 iter.Print();
148 }
149 return kFALSE;
150 }
151
152 // Setup Parlist
153 MParList plist;
154 plist.AddToList(this); // take care of fDisplay!
155
156 MObservatory obs;
157 plist.AddToList(&obs);
158
159 // Setup Tasklist
160 MTaskList tlist;
161 plist.AddToList(&tlist);
162
163 MReadReports readreal;
164 readreal.AddTree("Events", "MTime.", kTRUE);
165 readreal.AddTree("Drive");
166 //read.AddTree("Trigger");
167 //read.AddTree("Camera");
168 //read.AddTree("CC");
169 //read.AddTree("Currents");
170 readreal.AddFiles(iter);
171
172 MReadMarsFile readmc("Events");
173 readmc.DisableAutoScheme();
174 readmc.AddFiles(iter);
175
176 // ------------------ Setup general tasks ----------------
177
178 MFDeltaT fdeltat;
179 MContinue cont(&fdeltat, "FilterDeltaT", "Filter events with wrong timing");
180 cont.SetInverted();
181
182 MGeomApply apply; // Only necessary to craete geometry
183 MEventRateCalc rate;
184 //MEventRateCalc rate1; // 5min
185 rate.SetNumEvents(1200);
186 //rate1.SetNumEvents(60000);
187 //rate1.SetNameEventRate("MEventRate2");
188 //rate1.SetNameTimeRate("MTimeRate2");
189
190 /*
191 MEventRateCalc rate10000;
192 rate10000.SetNameEventRate("MEventRate10000");
193 rate10000.SetNumEvents(10000);
194 */
195 //MBadPixelsMerge merge(&badpix);
196
197 MFSoftwareTrigger swtrig;
198 MContinue contsw(&swtrig, "FilterSwTrigger", "Software trigger");
199 contsw.SetInverted();
200
201
202 MImgCleanStd clean;
203 clean.SetNamePedPhotCam("MPedPhotFromExtractorRndm");
204
205 MSrcPosCalc poscalc;
206 MHillasCalc hcalc;
207 hcalc.Disable(MHillasCalc::kCalcConc);
208
209 // ------------------ Setup histograms and fill tasks ----------------
210 MHCamEvent evt0a(0, "Cleaned", "Signal after Cleaning;;S [\\gamma]");
211 MHCamEvent evt0b(0, "UsedPix", "Fraction of Events in which Pixels are used;;Fraction");
212 evt0b.SetThreshold(0);
213
214 //MHCamEventRot evt0r("UsedRot", "Pixels marked Used (derotated)");
215 //evt0r.SetThreshold(0);
216
217 MH3 h1("MEventRate.fRate");
218 h1.SetName("MHEventRate");
219 h1.SetTitle("Event Rate distribution;R [Hz];Counts");
220 h1.SetLogy();
221/*
222 MH3 h12("MEventRate10000.fRate");
223 h12.SetName("MHEventRate");
224 h12.SetLogy();
225 */
226 MBinning b1("BinningMHEventRate");
227 b1.SetEdges(150, 0, 1500);
228 plist.AddToList(&b1);
229
230 MHVsTime hvs("MEventRate.fRate");
231 hvs.SetTitle("Rate per 500 events;R [Hz];Counts");
232 hvs.SetNumEvents(500);
233
234 //MContinue cont1("MEventRate2.fRate/MEventRate.fRate>1.1");
235 //MContinue cont2("MEventRate.fRate/MEventRate2.fRate>1.1");
236
237 MFillH fillvs(&hvs, "MTime", "FillEventRate10s");
238
239 MFillH fill0a(&evt0a, "MSignalCam", "FillSignalCam");
240 MFillH fill0b(&evt0b, "MSignalCam", "FillCntUsedPixels");
241 //MFillH fill0r(&evt0r, "MCerPhotEvt", "FillCntUsedRotated");
242 MFillH fill1("MHHillas", "MHillas", "FillHillas");
243 MFillH fill2("MHHillasExt", "", "FillHillasExt");
244 MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
245 MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
246 MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
247 //MFillH fill6("MHImageParTime","MImageParTime","FillImageParTime");
248 //MFillH fill7("MHNewImagePar2","MNewImagePar2","FillNewImagePar2");
249 MFillH fill8(&h1, "", "FillEventRate");
250 MFillH fill9("MHEffectiveOnTime", "MTime", "FillEffOnTime");
251 //MFillH fillb(&h12, "", "FillEvtRate2");
252 //MFillH fill9("MHCerPhot");
253
254 //fill0r.SetDrawOption("colz");
255 fill8.SetNameTab("EvtRate");
256 fill9.SetNameTab("EffOnTime");
257
258 // ------------------ Setup write task ----------------
259
260 MWriteRootFile write(2, Form("%s{s/_Y_/_I_}", fPathOut.Data()), fOverwrite?"RECREATE":"NEW");
261 // Data
262 write.AddContainer("MHillas", "Events");
263 write.AddContainer("MHillasExt", "Events");
264 write.AddContainer("MHillasSrc", "Events");
265 write.AddContainer("MImagePar", "Events");
266 write.AddContainer("MNewImagePar", "Events");
267 //write.AddContainer("MNewImagePar2", "Events");
268 //write.AddContainer("MImageParTime", "Events");
269 write.AddContainer("MRawEvtHeader", "Events");
270 write.AddContainer("MPointingPos", "Events");
271
272 // Run Header
273 write.AddContainer("MRawRunHeader", "RunHeaders");
274 write.AddContainer("MBadPixelsCam", "RunHeaders");
275 write.AddContainer("MGeomCam", "RunHeaders");
276 write.AddContainer("MObservatory", "RunHeaders");
277
278 if (ismc)
279 {
280 // Monte Carlo Data
281 write.AddContainer("MMcEvt", "Events");
282 write.AddContainer("MMcTrig", "Events");
283 // Monte Carlo Run Headers
284 write.AddContainer("MMcRunHeader", "RunHeaders");
285 write.AddContainer("MMcTrigHeader", "RunHeaders");
286 write.AddContainer("MMcFadcHeader", "RunHeaders");
287 write.AddContainer("MMcConfigRunHeader", "RunHeaders");
288 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
289 write.AddCopySource("OriginalMC");
290 }
291 else
292 {
293 write.AddContainer("MTime", "Events");
294 // Drive
295 write.AddContainer("MReportDrive", "Drive");
296 write.AddContainer("MTimeDrive", "Drive");
297 // Effective On Time
298 write.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
299 write.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
300 }
301
302 MTaskList tlist2("Events");
303 tlist2.AddToList(&apply);
304 if (!ismc)
305 tlist2.AddToList(&cont);
306 tlist2.AddToList(&contsw);
307 if (!ismc)
308 {
309 tlist2.AddToList(&rate);
310 //tlist2.AddToList(&rate1);
311 tlist2.AddToList(&fillvs);
312 //tlist2.AddToList(&cont1);
313 //tlist2.AddToList(&cont2);
314 tlist2.AddToList(&fill8);
315 tlist2.AddToList(&fill9);
316 }
317 //tlist2.AddToList(&fillb);
318 tlist2.AddToList(&clean);
319 tlist2.AddToList(&fill0a);
320 tlist2.AddToList(&fill0b);
321 //tlist2.AddToList(&fill0r);
322 tlist2.AddToList(&poscalc);
323 tlist2.AddToList(&hcalc);
324 tlist2.AddToList(&fill1);
325 tlist2.AddToList(&fill2);
326 tlist2.AddToList(&fill3);
327 tlist2.AddToList(&fill4);
328 tlist2.AddToList(&fill5);
329 //tlist2.AddToList(&fill6);
330 //tlist2.AddToList(&fill7);
331 //tlist2.AddToList(&fill9);
332
333 MPointingPosCalc pcalc;
334 //MSrcPosFromModel srcpos;
335
336 MTaskList tlist3("Drive");
337 tlist3.AddToList(&pcalc);
338 //tlist3.AddToList(&srcpos);
339
340 tlist.AddToList(ismc ? (MTask*)&readmc : (MTask*)&readreal);
341 tlist.AddToList(&tlist3, "Drive");
342 tlist.AddToList(&tlist2, "Events");
343 tlist.AddToList(&write);
344
345 // Create and setup the eventloop
346 MEvtLoop evtloop(fName);
347 evtloop.SetParList(&plist);
348 evtloop.SetDisplay(fDisplay);
349 evtloop.SetLogStream(fLog);
350 if (!SetupEnv(evtloop))
351 return kFALSE;
352
353 // Execute first analysis
354 if (!evtloop.Eventloop(fMaxEvents))
355 {
356 *fLog << err << GetDescriptor() << ": Failed." << endl;
357 return kFALSE;
358 }
359
360 tlist.PrintStatistics();
361
362 if (!WriteResult())
363 return kFALSE;
364
365 *fLog << all << GetDescriptor() << ": Done." << endl;
366 *fLog << endl << endl;
367
368 return kTRUE;
369}
Note: See TracBrowser for help on using the repository browser.