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

Last change on this file since 4905 was 4894, 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.SetTitle("Effective On-Time T_{eff} vs. Time;;T_{eff}");
187
188 MFillH fill0(&evt0, "MCerPhotEvt", "FillCerPhotEvt");
189 MFillH fill1("MHHillas", "MHillas", "FillHillas");
190 MFillH fill2("MHHillasExt", "", "FillHillasExt");
191 MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
192 MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
193 MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
194 MFillH fill6("MHImageParTime","MImageParTime","FillImageParTime");
195 MFillH fill7("MHNewImagePar2","MNewImagePar2","FillNewImagePar2");
196 MFillH fill8(&h1, "", "FillEventRate");
197 MFillH fill9("MHEffectiveOnTime", "MTime", "FillEffOnTime");
198 MFillH filla(&h2, "MTimeEffectiveOnTime", "FillEffOnTimeVsTime");
199 //MFillH fillb(&h12, "", "FillEvtRate2");
200 //MFillH fill9("MHCerPhot");
201
202 fill8.SetNameTab("EvtRate");
203 fill9.SetNameTab("EffOnTime");
204 fill9.SetNameTab("EffOnVsTime");
205
206 // ------------------ Setup write task ----------------
207
208 MWriteRootFile write(2, Form("%s{s/_Y_/_I_}", fPathOut.Data()), fOverwrite);
209 // Data
210 write.AddContainer("MHillas", "Events");
211 write.AddContainer("MHillasExt", "Events");
212 write.AddContainer("MHillasSrc", "Events");
213 write.AddContainer("MImagePar", "Events");
214 write.AddContainer("MNewImagePar", "Events");
215 write.AddContainer("MNewImagePar2", "Events");
216 write.AddContainer("MImageParTime", "Events");
217 write.AddContainer("MTime", "Events");
218 write.AddContainer("MRawEvtHeader", "Events");
219 // Monte Carlo
220 write.AddContainer("MMcEvt", "Events", kFALSE);
221 write.AddContainer("MMcTrig", "Events", kFALSE);
222 // Run Header
223 write.AddContainer("MRawRunHeader", "RunHeaders");
224 write.AddContainer("MBadPixelsCam", "RunHeaders");
225 write.AddContainer("MGeomCam", "RunHeaders");
226 //write.AddContainer("MObservatory", "RunHeaders");
227 // Monte Carlo Headers
228 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
229 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
230 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
231 // Drive
232 //write.AddContainer("MSrcPosCam", "Drive");
233 write.AddContainer("MPointingPos", "Drive");
234 write.AddContainer("MReportDrive", "Drive");
235 write.AddContainer("MTimeDrive", "Drive");
236 // Effective On Time
237 write.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
238 write.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
239
240 MTaskList tlist2;
241 tlist2.AddToList(&apply);
242 tlist2.AddToList(&rate);
243 //tlist2.AddToList(&rate10000);
244 tlist2.AddToList(&fill8);
245 tlist2.AddToList(&fill9);
246 tlist2.AddToList(&filla);
247 //tlist2.AddToList(&fillb);
248 tlist2.AddToList(&clean);
249 tlist2.AddToList(&fill0);
250 tlist2.AddToList(&hcalc);
251 tlist2.AddToList(&fill1);
252 tlist2.AddToList(&fill2);
253 tlist2.AddToList(&fill3);
254 tlist2.AddToList(&fill4);
255 tlist2.AddToList(&fill5);
256 tlist2.AddToList(&fill6);
257 tlist2.AddToList(&fill7);
258 //tlist2.AddToList(&fill9);
259
260 MPointingPosCalc pcalc;
261 //MSrcPosFromModel srcpos;
262
263 MTaskList tlist3;
264 tlist3.AddToList(&pcalc);
265 //tlist3.AddToList(&srcpos);
266
267 tlist.AddToList(&read);
268 tlist.AddToList(&tlist3, "Drive");
269 tlist.AddToList(&tlist2, "Events");
270 tlist.AddToList(&write);
271
272 // Create and setup the eventloop
273 MEvtLoop evtloop(fName);
274 evtloop.SetParList(&plist);
275 evtloop.SetDisplay(fDisplay);
276 evtloop.SetLogStream(fLog);
277 if (!SetupEnv(evtloop))
278 return kFALSE;
279
280 // Execute first analysis
281 if (!evtloop.Eventloop(fMaxEvents))
282 {
283 *fLog << err << GetDescriptor() << ": Failed." << endl;
284 return kFALSE;
285 }
286
287 tlist.PrintStatistics();
288
289 if (!WriteResult())
290 return kFALSE;
291
292 *fLog << all << GetDescriptor() << ": Done." << endl;
293 *fLog << endl << endl;
294
295 return kTRUE;
296}
Note: See TracBrowser for help on using the repository browser.