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

Last change on this file since 6839 was 6561, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 10.9 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
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
266 // Run Header
267 write.AddContainer("MRawRunHeader", "RunHeaders");
268 write.AddContainer("MBadPixelsCam", "RunHeaders");
269 write.AddContainer("MGeomCam", "RunHeaders");
270 write.AddContainer("MObservatory", "RunHeaders");
271
272 if (ismc)
273 {
274 // Monte Carlo Data
275 write.AddContainer("MMcEvt", "Events");
276 write.AddContainer("MMcTrig", "Events");
277 // Monte Carlo Run Headers
278 write.AddContainer("MMcRunHeader", "RunHeaders");
279 write.AddContainer("MMcTrigHeader", "RunHeaders");
280 write.AddContainer("MMcFadcHeader", "RunHeaders");
281 write.AddContainer("MMcConfigRunHeader", "RunHeaders");
282 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
283 write.AddCopySource("OriginalMC");
284 }
285 else
286 {
287 write.AddContainer("MTime", "Events");
288 // Drive
289 write.AddContainer("MReportDrive", "Drive");
290 write.AddContainer("MTimeDrive", "Drive");
291 // Effective On Time
292 write.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
293 write.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
294 }
295
296 MTaskList tlist2("Events");
297 tlist2.AddToList(&apply);
298 if (!ismc)
299 tlist2.AddToList(&cont);
300 tlist2.AddToList(&contsw);
301 if (!ismc)
302 {
303 tlist2.AddToList(&rate);
304 //tlist2.AddToList(&rate1);
305 tlist2.AddToList(&fillvs);
306 //tlist2.AddToList(&cont1);
307 //tlist2.AddToList(&cont2);
308 tlist2.AddToList(&fill8);
309 tlist2.AddToList(&fill9);
310 }
311 //tlist2.AddToList(&fillb);
312 tlist2.AddToList(&clean);
313 tlist2.AddToList(&fill0a);
314 tlist2.AddToList(&fill0b);
315 //tlist2.AddToList(&fill0r);
316 tlist2.AddToList(&poscalc);
317 tlist2.AddToList(&hcalc);
318 tlist2.AddToList(&fill1);
319 tlist2.AddToList(&fill2);
320 tlist2.AddToList(&fill3);
321 tlist2.AddToList(&fill4);
322 tlist2.AddToList(&fill5);
323 //tlist2.AddToList(&fill6);
324 //tlist2.AddToList(&fill7);
325 //tlist2.AddToList(&fill9);
326
327 MPointingPosCalc pcalc;
328 //MSrcPosFromModel srcpos;
329
330 MTaskList tlist3("Drive");
331 tlist3.AddToList(&pcalc);
332 //tlist3.AddToList(&srcpos);
333
334 tlist.AddToList(ismc ? (MTask*)&readmc : (MTask*)&readreal);
335 tlist.AddToList(&tlist3, "Drive");
336 tlist.AddToList(&tlist2, "Events");
337 tlist.AddToList(&write);
338
339 // Create and setup the eventloop
340 MEvtLoop evtloop(fName);
341 evtloop.SetParList(&plist);
342 evtloop.SetDisplay(fDisplay);
343 evtloop.SetLogStream(fLog);
344 if (!SetupEnv(evtloop))
345 return kFALSE;
346
347 // Execute first analysis
348 if (!evtloop.Eventloop(fMaxEvents))
349 {
350 *fLog << err << GetDescriptor() << ": Failed." << endl;
351 return kFALSE;
352 }
353
354 tlist.PrintStatistics();
355
356 if (!WriteResult())
357 return kFALSE;
358
359 *fLog << all << GetDescriptor() << ": Done." << endl;
360 *fLog << endl << endl;
361
362 return kTRUE;
363}
Note: See TracBrowser for help on using the repository browser.