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

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