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

Last change on this file since 4966 was 4966, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 9.0 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 MFillH fill0(&evt0, "MCerPhotEvt", "FillCerPhotEvt");
191 MFillH fill1("MHHillas", "MHillas", "FillHillas");
192 MFillH fill2("MHHillasExt", "", "FillHillasExt");
193 MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
194 MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
195 MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
196 MFillH fill6("MHImageParTime","MImageParTime","FillImageParTime");
197 MFillH fill7("MHNewImagePar2","MNewImagePar2","FillNewImagePar2");
198 MFillH fill8(&h1, "", "FillEventRate");
199 MFillH fill9("MHEffectiveOnTime", "MTime", "FillEffOnTime");
200 //MFillH fillb(&h12, "", "FillEvtRate2");
201 //MFillH fill9("MHCerPhot");
202
203 fill8.SetNameTab("EvtRate");
204 fill9.SetNameTab("EffOnTime");
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("MRawEvtHeader", "Events");
218 if (ismc)
219 {
220 write.AddContainer("MPointingPos", "Events");
221 // Monte Carlo
222 write.AddContainer("MMcEvt", "Events");
223 write.AddContainer("MMcTrig", "Events");
224 // Monte Carlo Headers
225 write.AddContainer("MMcTrigHeader", "RunHeaders");
226 write.AddContainer("MMcConfigRunHeader", "RunHeaders");
227 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
228 }
229 else
230 {
231 write.AddContainer("MTime", "Events");
232 // Run Header
233 write.AddContainer("MRawRunHeader", "RunHeaders");
234 write.AddContainer("MBadPixelsCam", "RunHeaders");
235 write.AddContainer("MGeomCam", "RunHeaders");
236 //write.AddContainer("MObservatory", "RunHeaders");
237 // Drive
238 //write.AddContainer("MSrcPosCam", "Drive");
239 write.AddContainer("MPointingPos", "Drive");
240 write.AddContainer("MReportDrive", "Drive");
241 write.AddContainer("MTimeDrive", "Drive");
242 // Effective On Time
243 write.AddContainer("MEffectiveOnTime", "EffectiveOnTime");
244 write.AddContainer("MTimeEffectiveOnTime", "EffectiveOnTime");
245 }
246
247 MTaskList tlist2;
248 tlist2.AddToList(&apply);
249 if (!ismc)
250 {
251 tlist2.AddToList(&rate);
252 //tlist2.AddToList(&rate10000);
253 tlist2.AddToList(&fill8);
254 tlist2.AddToList(&fill9);
255 }
256 //tlist2.AddToList(&fillb);
257 tlist2.AddToList(&clean);
258 tlist2.AddToList(&fill0);
259 tlist2.AddToList(&hcalc);
260 tlist2.AddToList(&fill1);
261 tlist2.AddToList(&fill2);
262 tlist2.AddToList(&fill3);
263 tlist2.AddToList(&fill4);
264 tlist2.AddToList(&fill5);
265 tlist2.AddToList(&fill6);
266 tlist2.AddToList(&fill7);
267 //tlist2.AddToList(&fill9);
268
269 MPointingPosCalc pcalc;
270 //MSrcPosFromModel srcpos;
271
272 MTaskList tlist3;
273 tlist3.AddToList(&pcalc);
274 //tlist3.AddToList(&srcpos);
275
276 tlist.AddToList(ismc ? (MTask*)&readmc : (MTask*)&readreal);
277 tlist.AddToList(&tlist3, "Drive");
278 tlist.AddToList(&tlist2, "Events");
279 tlist.AddToList(&write);
280
281 // Create and setup the eventloop
282 MEvtLoop evtloop(fName);
283 evtloop.SetParList(&plist);
284 evtloop.SetDisplay(fDisplay);
285 evtloop.SetLogStream(fLog);
286 if (!SetupEnv(evtloop))
287 return kFALSE;
288
289 // Execute first analysis
290 if (!evtloop.Eventloop(fMaxEvents))
291 {
292 *fLog << err << GetDescriptor() << ": Failed." << endl;
293 return kFALSE;
294 }
295
296 tlist.PrintStatistics();
297
298 if (!WriteResult())
299 return kFALSE;
300
301 *fLog << all << GetDescriptor() << ": Done." << endl;
302 *fLog << endl << endl;
303
304 return kTRUE;
305}
Note: See TracBrowser for help on using the repository browser.