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

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