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

Last change on this file since 4891 was 4889, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 8.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/////////////////////////////////////////////////////////////////////////////
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 "MBinning.h"
49
50#include "MReadReports.h"
51#include "MGeomApply.h"
52#include "MEventRateCalc.h"
53#include "MImgCleanStd.h"
54#include "MHillasCalc.h"
55#include "MFillH.h"
56#include "MWriteRootFile.h"
57
58#include "MPointingPosCalc.h"
59//#include "MSrcPosFromModel.h"
60
61ClassImp(MJStar);
62
63using namespace std;
64
65// --------------------------------------------------------------------------
66//
67// Default constructor.
68//
69// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
70//
71MJStar::MJStar(const char *name, const char *title)
72{
73 fName = name ? name : "MJStar";
74 fTitle = title ? title : "Standard analysis and reconstruction";
75}
76
77Bool_t MJStar::WriteResult()
78{
79 if (fPathOut.IsNull())
80 {
81 *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
82 return kTRUE;
83 }
84
85 const TString oname = Form("%s/star%06d.root", (const char*)fPathOut, fSequence.GetSequence());
86
87 *fLog << inf << "Writing to file: " << oname << endl;
88
89 TFile file(oname, "RECREATE");
90
91 *fLog << inf << " - MStatusDisplay..." << flush;
92 if (fDisplay && fDisplay->Write()<=0)
93 {
94 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
95 return kFALSE;
96 }
97 *fLog << inf << "ok." << endl;
98
99 return kTRUE;
100}
101
102Bool_t MJStar::ProcessFile()
103{
104 if (!fSequence.IsValid())
105 {
106 *fLog << err << "ERROR - Sequence invalid!" << endl;
107 return kFALSE;
108 }
109
110 //if (!CheckEnv())
111 // return kFALSE;
112
113 CheckEnv();
114
115 // --------------------------------------------------------------------------------
116
117 *fLog << inf;
118 fLog->Separator(GetDescriptor());
119 *fLog << "Calculate image parameters from sequence ";
120 *fLog << fSequence.GetName() << endl;
121 *fLog << endl;
122
123 // --------------------------------------------------------------------------------
124
125 MDirIter iter;
126 const Int_t n0 = fSequence.SetupDatRuns(iter, fPathData);
127 const Int_t n1 = fSequence.GetNumDatRuns();
128 if (n0==0)
129 {
130 *fLog << err << "ERROR - No input files of sequence found!" << endl;
131 return kFALSE;
132 }
133 if (n0!=n1)
134 {
135 *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
136 return kFALSE;
137 }
138
139 // Setup Parlist
140 MParList plist;
141 plist.AddToList(this); // take care of fDisplay!
142
143 // Setup Tasklist
144 MTaskList tlist;
145 plist.AddToList(&tlist);
146
147 MReadReports read;
148 read.AddTree("Events", "MTime.", kTRUE);
149 read.AddTree("Drive");
150 //read.AddTree("Trigger");
151 //read.AddTree("Camera");
152 //read.AddTree("CC");
153 //read.AddTree("Currents");
154 read.AddFiles(iter);
155
156 // ------------------ Setup general tasks ----------------
157
158 MGeomApply apply; // Only necessary to craete geometry
159 MEventRateCalc rate;
160/*
161 MEventRateCalc rate10000;
162 rate10000.SetNameEventRate("MEventRate10000");
163 rate10000.SetNumEvents(10000);
164 */
165 //MBadPixelsMerge merge(&badpix);
166 MImgCleanStd clean;
167 MHillasCalc hcalc;
168
169 // ------------------ Setup histograms and fill tasks ----------------
170 MHCamEvent evt0("Cleaned");
171 evt0.SetType(0);
172
173 MH3 h1("MEventRate.fRate");
174 h1.SetName("MHEventRate");
175 h1.SetLogy();
176/*
177 MH3 h12("MEventRate10000.fRate");
178 h12.SetName("MHEventRate");
179 h12.SetLogy();
180 */
181 MBinning b1("BinningMHEventRate");
182 b1.SetEdges(150, 0, 1500);
183 plist.AddToList(&b1);
184
185 MHVsTime h2("MEffectiveOnTime.fVal", "MEffectiveOnTime.fErr");
186 h2.SetAxisTitle("T_{eff}");
187 h2.SetTitle("Effective On-Time T_{eff} vs. Time");
188
189 MFillH fill0(&evt0, "MCerPhotEvt", "FillCerPhotEvt");
190 MFillH fill1("MHHillas", "MHillas", "FillHillas");
191 MFillH fill2("MHHillasExt", "", "FillHillasExt");
192 MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
193 MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
194 MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
195 MFillH fill6("MHImageParTime","MImageParTime","FillImageParTime");
196 MFillH fill7("MHNewImagePar2","MNewImagePar2","FillNewImagePar2");
197 MFillH fill8(&h1, "", "FillEventRate");
198 MFillH fill9("MHEffectiveOnTime", "MTime", "FillEffOnTime");
199 MFillH filla(&h2, "MTimeEffectiveOnTime", "FillEffOnTimeVsTime");
200 //MFillH fillb(&h12, "", "FillEvtRate2");
201 //MFillH fill9("MHCerPhot");
202
203 fill8.SetNameTab("EvtRate");
204 fill9.SetNameTab("EffOnTime");
205 fill9.SetNameTab("EffOnVsTime");
206
207 // ------------------ Setup write task ----------------
208
209 MWriteRootFile write(2, Form("%s{s/_Y_/_I_}", fPathOut.Data()), fOverwrite);
210 // Data
211 write.AddContainer("MHillas", "Events");
212 write.AddContainer("MHillasExt", "Events");
213 write.AddContainer("MHillasSrc", "Events");
214 write.AddContainer("MImagePar", "Events");
215 write.AddContainer("MNewImagePar", "Events");
216 write.AddContainer("MNewImagePar2", "Events");
217 write.AddContainer("MImageParTime", "Events");
218 write.AddContainer("MTime", "Events");
219 write.AddContainer("MRawEvtHeader", "Events");
220 // Monte Carlo
221 write.AddContainer("MMcEvt", "Events", kFALSE);
222 write.AddContainer("MMcTrig", "Events", kFALSE);
223 // Run Header
224 write.AddContainer("MRawRunHeader", "RunHeaders");
225 write.AddContainer("MBadPixelsCam", "RunHeaders");
226 write.AddContainer("MGeomCam", "RunHeaders");
227 //write.AddContainer("MObservatory", "RunHeaders");
228 // Monte Carlo Headers
229 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
230 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
231 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
232 // Drive
233 //write.AddContainer("MSrcPosCam", "Drive");
234 write.AddContainer("MPointingPos", "Drive");
235 write.AddContainer("MReportDrive", "Drive");
236 write.AddContainer("MTimeDrive", "Drive");
237 // Effective On Time
238 write.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
239 write.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
240
241 MTaskList tlist2;
242 tlist2.AddToList(&apply);
243 tlist2.AddToList(&rate);
244 //tlist2.AddToList(&rate10000);
245 tlist2.AddToList(&fill8);
246 tlist2.AddToList(&fill9);
247 tlist2.AddToList(&filla);
248 //tlist2.AddToList(&fillb);
249 tlist2.AddToList(&clean);
250 tlist2.AddToList(&fill0);
251 tlist2.AddToList(&hcalc);
252 tlist2.AddToList(&fill1);
253 tlist2.AddToList(&fill2);
254 tlist2.AddToList(&fill3);
255 tlist2.AddToList(&fill4);
256 tlist2.AddToList(&fill5);
257 tlist2.AddToList(&fill6);
258 tlist2.AddToList(&fill7);
259 //tlist2.AddToList(&fill9);
260
261 MPointingPosCalc pcalc;
262 //MSrcPosFromModel srcpos;
263
264 MTaskList tlist3;
265 tlist3.AddToList(&pcalc);
266 //tlist3.AddToList(&srcpos);
267
268 tlist.AddToList(&read);
269 tlist.AddToList(&tlist3, "Drive");
270 tlist.AddToList(&tlist2, "Events");
271 tlist.AddToList(&write);
272
273 // Create and setup the eventloop
274 MEvtLoop evtloop(fName);
275 evtloop.SetParList(&plist);
276 evtloop.SetDisplay(fDisplay);
277 evtloop.SetLogStream(fLog);
278 if (!SetupEnv(evtloop))
279 return kFALSE;
280
281 // Execute first analysis
282 if (!evtloop.Eventloop(fMaxEvents))
283 {
284 *fLog << err << GetDescriptor() << ": Failed." << endl;
285 return kFALSE;
286 }
287
288 tlist.PrintStatistics();
289
290 if (!WriteResult())
291 return kFALSE;
292
293 *fLog << all << GetDescriptor() << ": Done." << endl;
294 *fLog << endl << endl;
295
296 return kTRUE;
297}
Note: See TracBrowser for help on using the repository browser.