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

Last change on this file since 6875 was 6875, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 11.0 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 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 hcalc.Disable(MHillasCalc::kConc);
203
204 // ------------------ Setup histograms and fill tasks ----------------
205 MHCamEvent evt0a(0, "Cleaned", "Signal after Cleaning;;S [\\gamma]");
206 MHCamEvent evt0b(0, "UsedPix", "Fraction of Events in which Pixels are used;;Fraction");
207 evt0b.SetThreshold(0);
208
209 //MHCamEventRot evt0r("UsedRot", "Pixels marked Used (derotated)");
210 //evt0r.SetThreshold(0);
211
212 MH3 h1("MEventRate.fRate");
213 h1.SetName("MHEventRate");
214 h1.SetTitle("Event Rate distribution;R [Hz];Counts");
215 h1.SetLogy();
216/*
217 MH3 h12("MEventRate10000.fRate");
218 h12.SetName("MHEventRate");
219 h12.SetLogy();
220 */
221 MBinning b1("BinningMHEventRate");
222 b1.SetEdges(150, 0, 1500);
223 plist.AddToList(&b1);
224
225 MHVsTime hvs("MEventRate.fRate");
226 hvs.SetTitle("Rate per 500 events;R [Hz];Counts");
227 hvs.SetNumEvents(500);
228
229 //MContinue cont1("MEventRate2.fRate/MEventRate.fRate>1.1");
230 //MContinue cont2("MEventRate.fRate/MEventRate2.fRate>1.1");
231
232 MFillH fillvs(&hvs, "MTime", "FillEventRate10s");
233
234 MFillH fill0a(&evt0a, "MSignalCam", "FillSignalCam");
235 MFillH fill0b(&evt0b, "MSignalCam", "FillCntUsedPixels");
236 //MFillH fill0r(&evt0r, "MCerPhotEvt", "FillCntUsedRotated");
237 MFillH fill1("MHHillas", "MHillas", "FillHillas");
238 MFillH fill2("MHHillasExt", "", "FillHillasExt");
239 MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
240 MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
241 MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
242 //MFillH fill6("MHImageParTime","MImageParTime","FillImageParTime");
243 //MFillH fill7("MHNewImagePar2","MNewImagePar2","FillNewImagePar2");
244 MFillH fill8(&h1, "", "FillEventRate");
245 MFillH fill9("MHEffectiveOnTime", "MTime", "FillEffOnTime");
246 //MFillH fillb(&h12, "", "FillEvtRate2");
247 //MFillH fill9("MHCerPhot");
248
249 //fill0r.SetDrawOption("colz");
250 fill8.SetNameTab("EvtRate");
251 fill9.SetNameTab("EffOnTime");
252
253 // ------------------ Setup write task ----------------
254
255 MWriteRootFile write(2, Form("%s{s/_Y_/_I_}", fPathOut.Data()), fOverwrite?"RECREATE":"NEW");
256 // Data
257 write.AddContainer("MHillas", "Events");
258 write.AddContainer("MHillasExt", "Events");
259 write.AddContainer("MHillasSrc", "Events");
260 write.AddContainer("MImagePar", "Events");
261 write.AddContainer("MNewImagePar", "Events");
262 //write.AddContainer("MNewImagePar2", "Events");
263 //write.AddContainer("MImageParTime", "Events");
264 write.AddContainer("MRawEvtHeader", "Events");
265 write.AddContainer("MPointingPos", "Events");
266
267 // Run Header
268 write.AddContainer("MRawRunHeader", "RunHeaders");
269 write.AddContainer("MBadPixelsCam", "RunHeaders");
270 write.AddContainer("MGeomCam", "RunHeaders");
271 write.AddContainer("MObservatory", "RunHeaders");
272
273 if (ismc)
274 {
275 // Monte Carlo Data
276 write.AddContainer("MMcEvt", "Events");
277 write.AddContainer("MMcTrig", "Events");
278 // Monte Carlo Run Headers
279 write.AddContainer("MMcRunHeader", "RunHeaders");
280 write.AddContainer("MMcTrigHeader", "RunHeaders");
281 write.AddContainer("MMcFadcHeader", "RunHeaders");
282 write.AddContainer("MMcConfigRunHeader", "RunHeaders");
283 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
284 write.AddCopySource("OriginalMC");
285 }
286 else
287 {
288 write.AddContainer("MTime", "Events");
289 // Drive
290 write.AddContainer("MReportDrive", "Drive");
291 write.AddContainer("MTimeDrive", "Drive");
292 // Effective On Time
293 write.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
294 write.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
295 }
296
297 MTaskList tlist2("Events");
298 tlist2.AddToList(&apply);
299 if (!ismc)
300 tlist2.AddToList(&cont);
301 tlist2.AddToList(&contsw);
302 if (!ismc)
303 {
304 tlist2.AddToList(&rate);
305 //tlist2.AddToList(&rate1);
306 tlist2.AddToList(&fillvs);
307 //tlist2.AddToList(&cont1);
308 //tlist2.AddToList(&cont2);
309 tlist2.AddToList(&fill8);
310 tlist2.AddToList(&fill9);
311 }
312 //tlist2.AddToList(&fillb);
313 tlist2.AddToList(&clean);
314 tlist2.AddToList(&fill0a);
315 tlist2.AddToList(&fill0b);
316 //tlist2.AddToList(&fill0r);
317 tlist2.AddToList(&poscalc);
318 tlist2.AddToList(&hcalc);
319 tlist2.AddToList(&fill1);
320 tlist2.AddToList(&fill2);
321 tlist2.AddToList(&fill3);
322 tlist2.AddToList(&fill4);
323 tlist2.AddToList(&fill5);
324 //tlist2.AddToList(&fill6);
325 //tlist2.AddToList(&fill7);
326 //tlist2.AddToList(&fill9);
327
328 MPointingPosCalc pcalc;
329 //MSrcPosFromModel srcpos;
330
331 MTaskList tlist3("Drive");
332 tlist3.AddToList(&pcalc);
333 //tlist3.AddToList(&srcpos);
334
335 tlist.AddToList(ismc ? (MTask*)&readmc : (MTask*)&readreal);
336 tlist.AddToList(&tlist3, "Drive");
337 tlist.AddToList(&tlist2, "Events");
338 tlist.AddToList(&write);
339
340 // Create and setup the eventloop
341 MEvtLoop evtloop(fName);
342 evtloop.SetParList(&plist);
343 evtloop.SetDisplay(fDisplay);
344 evtloop.SetLogStream(fLog);
345 if (!SetupEnv(evtloop))
346 return kFALSE;
347
348 // Execute first analysis
349 if (!evtloop.Eventloop(fMaxEvents))
350 {
351 *fLog << err << GetDescriptor() << ": Failed." << endl;
352 return kFALSE;
353 }
354
355 tlist.PrintStatistics();
356
357 if (!WriteResult())
358 return kFALSE;
359
360 *fLog << all << GetDescriptor() << ": Done." << endl;
361 *fLog << endl << endl;
362
363 return kTRUE;
364}
Note: See TracBrowser for help on using the repository browser.