1 | #include <TSystem.h>
|
---|
2 |
|
---|
3 | #include "MParList.h"
|
---|
4 | #include "MTaskList.h"
|
---|
5 | #include "MEvtLoop.h"
|
---|
6 | /*'
|
---|
7 | #include "MLog.h"
|
---|
8 | */
|
---|
9 | #include "MLogManip.h"
|
---|
10 |
|
---|
11 | #include "MArgs.h"
|
---|
12 |
|
---|
13 | #include "MArray.h"
|
---|
14 | #include "MReadMarsFile.h"
|
---|
15 | #include "MGeomApply.h"
|
---|
16 | #include "MMcPedestalCopy.h"
|
---|
17 | #include "MMcPedestalNSBAdd.h"
|
---|
18 | #include "MCerPhotCalc.h"
|
---|
19 | #include "MCerPhotAnal2.h"
|
---|
20 | #include "MSigmabarCalc.h"
|
---|
21 | #include "MImgCleanStd.h"
|
---|
22 | #include "MHillasCalc.h"
|
---|
23 | #include "MHillasSrcCalc.h"
|
---|
24 | #include "MWriteRootFile.h"
|
---|
25 | #include "MFDataMember.h"
|
---|
26 | #include "MFillH.h"
|
---|
27 | #include "MReportDrive.h" // PRELIMINARY:
|
---|
28 | //#include "MPointingPos.h" // PRELIMINARY:
|
---|
29 | //#include "MPointingPosCalc.h"
|
---|
30 |
|
---|
31 | using namespace std;
|
---|
32 |
|
---|
33 | //////////////////////////////////////////////////////////////////////////////
|
---|
34 | //
|
---|
35 | // This is an easy implementation of the Star process
|
---|
36 | // (as compilable prog)
|
---|
37 | //
|
---|
38 | //////////////////////////////////////////////////////////////////////////////
|
---|
39 |
|
---|
40 | static void StartUpMessage()
|
---|
41 | {
|
---|
42 | gLog << all << endl;
|
---|
43 |
|
---|
44 | // 1 2 3 4 5
|
---|
45 | // 12345678901234567890123456789012345678901234567890
|
---|
46 | gLog << "==================================================" << endl;
|
---|
47 | gLog << " STAR - MARS V" << MARSVER << endl;
|
---|
48 | gLog << " MARS - STandard Analysis and Reconstruction" << endl;
|
---|
49 | gLog << " Compiled on <" << __DATE__ << ">" << endl;
|
---|
50 | gLog << " Using ROOT v" << ROOTVER << endl;
|
---|
51 | gLog << "==================================================" << endl;
|
---|
52 | gLog << endl;
|
---|
53 | }
|
---|
54 |
|
---|
55 | static void Usage()
|
---|
56 | {
|
---|
57 | gLog << all << endl;
|
---|
58 | gLog << "Sorry the usage is:" << endl;
|
---|
59 | gLog << " star [-a0] [-vn] [-cn] inputfile[.root] outputfile[.root]" << endl << endl;
|
---|
60 | gLog << " input file: Merpped or MC root file." << endl;
|
---|
61 | gLog << " ouput file: Star-file (image parameter file)" << endl;
|
---|
62 | gLog << " -a0: Do not use Ansii codes." << endl;
|
---|
63 | gLog << " -cn: Compression level n=1..9 [default=2]" << endl;
|
---|
64 | gLog << " -vn: Verbosity level n [default=2]" << endl;
|
---|
65 | gLog << " -u1: Update File (instead of Recreate)" << endl;
|
---|
66 | gLog << " -tn: Telescope Serial Number n [default=0]" << endl << endl;
|
---|
67 | gLog << " -> Further setup is not possible at the moment, please use" << endl;
|
---|
68 | gLog << " the star.C root macro instead. Using an input card will" << endl;
|
---|
69 | gLog << " be implemented in the future." << endl << endl;
|
---|
70 | }
|
---|
71 |
|
---|
72 | class MJStar : public MParContainer
|
---|
73 | {
|
---|
74 | private:
|
---|
75 | TString fInputFile;
|
---|
76 | TString fOutputFile;
|
---|
77 |
|
---|
78 | Bool_t fIsUpdate;
|
---|
79 | Byte_t fComprLevel;
|
---|
80 |
|
---|
81 | Byte_t fSerialIdx;
|
---|
82 |
|
---|
83 | Bool_t CheckFiles()
|
---|
84 | {
|
---|
85 | if (fOutputFile.IsNull())
|
---|
86 | {
|
---|
87 | fOutputFile = fInputFile;
|
---|
88 |
|
---|
89 | if (fOutputFile.EndsWith(".raw"))
|
---|
90 | fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
|
---|
91 |
|
---|
92 | if (fOutputFile.EndsWith(".rep"))
|
---|
93 | fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
|
---|
94 |
|
---|
95 | if (fOutputFile.EndsWith(".txt"))
|
---|
96 | fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
|
---|
97 | }
|
---|
98 |
|
---|
99 | if (fInputFile.IsNull())
|
---|
100 | {
|
---|
101 | *fLog << err << "Sorry, no input file." << endl;
|
---|
102 | return kFALSE;
|
---|
103 | }
|
---|
104 |
|
---|
105 | if (fOutputFile.IsNull())
|
---|
106 | {
|
---|
107 | *fLog << err << "Sorry, no output file." << endl;
|
---|
108 | return kFALSE;
|
---|
109 | }
|
---|
110 |
|
---|
111 | if (!fInputFile.EndsWith(".root"))
|
---|
112 | fInputFile += ".root";
|
---|
113 |
|
---|
114 | if (!fOutputFile.EndsWith(".root"))
|
---|
115 | fOutputFile += ".root";
|
---|
116 |
|
---|
117 | //
|
---|
118 | // check whether the given files are OK.
|
---|
119 | //
|
---|
120 | if (gSystem->AccessPathName(fInputFile, kFileExists))
|
---|
121 | {
|
---|
122 | *fLog << err << "Sorry, the input file '" << fInputFile << "' doesn't exist." << endl;
|
---|
123 | return kFALSE;
|
---|
124 | }
|
---|
125 |
|
---|
126 | if (!gSystem->AccessPathName(fOutputFile, kFileExists))
|
---|
127 | {
|
---|
128 | if (fIsUpdate)
|
---|
129 | gLog << warn << "Warning: File doesn't '" << fOutputFile << "' exist... recreating." << endl;
|
---|
130 | }
|
---|
131 |
|
---|
132 | if (fIsUpdate || gSystem->AccessPathName(fOutputFile, kFileExists))
|
---|
133 | if (!gSystem->AccessPathName(fOutputFile, kWritePermission))
|
---|
134 | {
|
---|
135 | gLog << err << "Sorry, you don't have write permission for '" << fOutputFile << "'." << endl;
|
---|
136 | return kFALSE;
|
---|
137 | }
|
---|
138 | return kTRUE;
|
---|
139 | }
|
---|
140 |
|
---|
141 | public:
|
---|
142 | MJStar(const char *name=0, const char *title=0)
|
---|
143 | : fIsUpdate(kFALSE), fComprLevel(1), fSerialIdx(0)
|
---|
144 | {
|
---|
145 | fName = name;
|
---|
146 | fTitle = title;
|
---|
147 | }
|
---|
148 |
|
---|
149 | void SetInputFile(const char *f) { fInputFile = f; }
|
---|
150 | void SetOutputFile(const char *f) { fOutputFile = f; }
|
---|
151 | void SetSerialIdx(Byte_t i) { fSerialIdx = i; }
|
---|
152 | void SetComprLevel(Byte_t l) { fComprLevel = l; }
|
---|
153 | void SetUpdate(Bool_t u=kTRUE) { fIsUpdate = u; }
|
---|
154 |
|
---|
155 | Bool_t Process()
|
---|
156 | {
|
---|
157 | if (!CheckFiles())
|
---|
158 | return kFALSE;
|
---|
159 |
|
---|
160 | //
|
---|
161 | // Create a empty Parameter List and an empty Task List
|
---|
162 | // The tasklist is identified in the eventloop by its name
|
---|
163 | //
|
---|
164 | MParList plist;
|
---|
165 |
|
---|
166 | MTaskList tlist;
|
---|
167 | plist.AddToList(&tlist);
|
---|
168 |
|
---|
169 | // PRELIMINARY:
|
---|
170 | /*
|
---|
171 | MReportDrive rep;
|
---|
172 | plist.AddToList(&rep);
|
---|
173 | MPointingPos pos;
|
---|
174 | plist.AddToList(&pos);
|
---|
175 | */
|
---|
176 |
|
---|
177 | //
|
---|
178 | // Now setup the tasks and tasklist:
|
---|
179 | // ---------------------------------
|
---|
180 | //
|
---|
181 | MReadMarsFile read("Events", fInputFile);
|
---|
182 | read.DisableAutoScheme();
|
---|
183 |
|
---|
184 | MGeomApply apply;
|
---|
185 | MMcPedestalCopy pcopy;
|
---|
186 | MMcPedestalNSBAdd pnsb;
|
---|
187 |
|
---|
188 | //MPointingPosCalc pcalc;
|
---|
189 |
|
---|
190 | MCerPhotCalc ncalc;
|
---|
191 | MCerPhotAnal2 nanal;
|
---|
192 |
|
---|
193 | MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);
|
---|
194 | MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);
|
---|
195 |
|
---|
196 | ncalc.SetFilter(&f1);
|
---|
197 | nanal.SetFilter(&f2);
|
---|
198 |
|
---|
199 | MSigmabarCalc sgcal;
|
---|
200 | //MFillH fills("MHSigmaTheta", "", "FillSigmaTheta");
|
---|
201 | //MFillH fillb("MHBlindPixels", "", "FillBlindPixels");
|
---|
202 | MImgCleanStd clean;
|
---|
203 | MHillasCalc hcalc;
|
---|
204 | MHillasSrcCalc scalc; // !!Preliminary!! Will be removed later!
|
---|
205 | MWriteRootFile write(fOutputFile, fIsUpdate?"UPDATE":"RECREATE", "Star output", fComprLevel);
|
---|
206 |
|
---|
207 | tlist.AddToList(&read);
|
---|
208 | tlist.AddToList(&f1);
|
---|
209 | tlist.AddToList(&f2);
|
---|
210 | tlist.AddToList(&apply);
|
---|
211 | tlist.AddToList(&pcopy);
|
---|
212 | tlist.AddToList(&pnsb);
|
---|
213 | //tlist.AddToList(&pcalc);
|
---|
214 | tlist.AddToList(&ncalc);
|
---|
215 | tlist.AddToList(&nanal);
|
---|
216 | tlist.AddToList(&sgcal);
|
---|
217 | //tlist.AddToList(&fills);
|
---|
218 | //tlist.AddToList(&fillb);
|
---|
219 | tlist.AddToList(&clean);
|
---|
220 | tlist.AddToList(&hcalc);
|
---|
221 | tlist.AddToList(&scalc);
|
---|
222 | tlist.AddToList(&write);
|
---|
223 |
|
---|
224 | //
|
---|
225 | // Set the serial number for all tasks in the current tasklist
|
---|
226 | //
|
---|
227 | tlist.SetSerialNumber(fSerialIdx);
|
---|
228 |
|
---|
229 | //
|
---|
230 | // Setup tasks
|
---|
231 | //
|
---|
232 | write.AddContainer(write.AddSerialNumber("MMcEvt"), "Events", kFALSE);
|
---|
233 | write.AddContainer(write.AddSerialNumber("MSigmabar"), "Events");
|
---|
234 | write.AddContainer(write.AddSerialNumber("MHillas"), "Events");
|
---|
235 | write.AddContainer(write.AddSerialNumber("MHillasExt"), "Events");
|
---|
236 | write.AddContainer(write.AddSerialNumber("MHillasSrc"), "Events");
|
---|
237 | write.AddContainer(write.AddSerialNumber("MNewImagePar"), "Events");
|
---|
238 | write.AddContainer(write.AddSerialNumber("MSrcPosCam"), "RunHeaders");
|
---|
239 | //write.AddContainer(write.AddSerialNumber("MHSigmaTheta"), "RunHeaders");
|
---|
240 | if (!fIsUpdate)
|
---|
241 | {
|
---|
242 | write.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
243 | write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
|
---|
244 | }
|
---|
245 |
|
---|
246 | //
|
---|
247 | // Create and set up the eventloop
|
---|
248 | //
|
---|
249 | MEvtLoop evtloop;
|
---|
250 | evtloop.SetParList(&plist);
|
---|
251 |
|
---|
252 | //
|
---|
253 | // Execute your analysis
|
---|
254 | //
|
---|
255 | if (!evtloop.Eventloop())
|
---|
256 | {
|
---|
257 | gLog << err << "ERROR: Star eventloop failed!" << endl;
|
---|
258 | return kFALSE;
|
---|
259 | }
|
---|
260 |
|
---|
261 | tlist.PrintStatistics();
|
---|
262 |
|
---|
263 | //plist.FindObject("MHSigmaTheta")->Write();
|
---|
264 |
|
---|
265 | gLog << all << "Star finished successfull!" << endl;
|
---|
266 |
|
---|
267 | return kTRUE;
|
---|
268 | }
|
---|
269 | // ClassDef(MJStar, 0)
|
---|
270 | };
|
---|
271 |
|
---|
272 | //ClassImp(MJStar);
|
---|
273 |
|
---|
274 |
|
---|
275 | int main(const int argc, char **argv)
|
---|
276 | {
|
---|
277 | StartUpMessage();
|
---|
278 |
|
---|
279 | //
|
---|
280 | // Evaluate arguments
|
---|
281 | //
|
---|
282 | MArgs arg(argc, argv);
|
---|
283 |
|
---|
284 | //
|
---|
285 | // Set verbosity to highest level.
|
---|
286 | //
|
---|
287 | gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
|
---|
288 |
|
---|
289 | if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
|
---|
290 | gLog.SetNoColors();
|
---|
291 |
|
---|
292 | const int kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
|
---|
293 | const int kTelIndex = arg.HasOption("-t") ? arg.GetIntAndRemove("-t") : 0;
|
---|
294 | const bool kUpdate = arg.HasOption("-u") && arg.GetIntAndRemove("-u")==1;
|
---|
295 |
|
---|
296 | //
|
---|
297 | // check for the right usage of the program
|
---|
298 | //
|
---|
299 | if (arg.GetNumArguments()!=2)
|
---|
300 | {
|
---|
301 | Usage();
|
---|
302 | return -1;
|
---|
303 | }
|
---|
304 |
|
---|
305 | //
|
---|
306 | // Initialize Non-GUI (batch) mode
|
---|
307 | //
|
---|
308 | gROOT->SetBatch();
|
---|
309 |
|
---|
310 | MArray::Class()->IgnoreTObjectStreamer();
|
---|
311 | MParContainer::Class()->IgnoreTObjectStreamer();
|
---|
312 |
|
---|
313 | MJStar star;
|
---|
314 | star.SetInputFile(arg.GetArgumentStr(0));
|
---|
315 | star.SetOutputFile(arg.GetArgumentStr(1));
|
---|
316 | star.SetComprLevel(kComprlvl);
|
---|
317 | star.SetSerialIdx(kTelIndex);
|
---|
318 | star.SetUpdate(kUpdate);
|
---|
319 |
|
---|
320 | if (!star.Process())
|
---|
321 | {
|
---|
322 | gLog << err << "Star failed!" << endl;
|
---|
323 | return -1;
|
---|
324 | }
|
---|
325 |
|
---|
326 | gLog << inf << "Star finished successfull!" << endl;
|
---|
327 |
|
---|
328 | return 0;
|
---|
329 | /*
|
---|
330 | //
|
---|
331 | // This is to make argv[i] more readable inside the code
|
---|
332 | //
|
---|
333 | TString kNamein = arg.GetArgumentStr(0);
|
---|
334 | TString kNameout = arg.GetArgumentStr(1);
|
---|
335 |
|
---|
336 | if (!kNamein.EndsWith(".root"))
|
---|
337 | kNamein += ".root";
|
---|
338 |
|
---|
339 | if (!kNameout.EndsWith(".root"))
|
---|
340 | kNameout += ".root";
|
---|
341 |
|
---|
342 | //
|
---|
343 | // check whether the given files are OK.
|
---|
344 | //
|
---|
345 | if (gSystem->AccessPathName(kNamein, kFileExists))
|
---|
346 | {
|
---|
347 | gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
|
---|
348 | return -1;
|
---|
349 | }
|
---|
350 |
|
---|
351 | if (!gSystem->AccessPathName(kNameout, kFileExists))
|
---|
352 | {
|
---|
353 | if (kUpdate)
|
---|
354 | gLog << warn << "Warning: File doesn't '" << kNameout << "' exist... recreating." << endl;
|
---|
355 | }
|
---|
356 |
|
---|
357 | if (kUpdate || gSystem->AccessPathName(kNameout, kFileExists))
|
---|
358 | if (!gSystem->AccessPathName(kNameout, kWritePermission))
|
---|
359 | {
|
---|
360 | gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
|
---|
361 | return -1;
|
---|
362 | }
|
---|
363 |
|
---|
364 | //
|
---|
365 | // Create a empty Parameter List and an empty Task List
|
---|
366 | // The tasklist is identified in the eventloop by its name
|
---|
367 | //
|
---|
368 | MParList plist;
|
---|
369 |
|
---|
370 | MTaskList tlist;
|
---|
371 | plist.AddToList(&tlist);
|
---|
372 |
|
---|
373 | // PRELIMINARY:
|
---|
374 | // MReportDrive rep;
|
---|
375 | // plist.AddToList(&rep);
|
---|
376 | // MPointingPos pos;
|
---|
377 | // plist.AddToList(&pos);
|
---|
378 |
|
---|
379 | //
|
---|
380 | // Now setup the tasks and tasklist:
|
---|
381 | // ---------------------------------
|
---|
382 | //
|
---|
383 | MReadMarsFile read("Events", kNamein);
|
---|
384 | read.DisableAutoScheme();
|
---|
385 |
|
---|
386 | MGeomApply apply;
|
---|
387 | MMcPedestalCopy pcopy;
|
---|
388 | MMcPedestalNSBAdd pnsb;
|
---|
389 |
|
---|
390 | //MPointingPosCalc pcalc;
|
---|
391 |
|
---|
392 | MCerPhotCalc ncalc;
|
---|
393 | MCerPhotAnal2 nanal;
|
---|
394 |
|
---|
395 | MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);
|
---|
396 | MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);
|
---|
397 |
|
---|
398 | ncalc.SetFilter(&f1);
|
---|
399 | nanal.SetFilter(&f2);
|
---|
400 |
|
---|
401 | MSigmabarCalc sgcal;
|
---|
402 | //MFillH fills("MHSigmaTheta", "", "FillSigmaTheta");
|
---|
403 | MImgCleanStd clean;
|
---|
404 | MHillasCalc hcalc;
|
---|
405 | MHillasSrcCalc scalc; // !!Preliminary!! Will be removed later!
|
---|
406 | MWriteRootFile write(kNameout, kUpdate?"UPDATE":"RECREATE", "Star output", kComprlvl);
|
---|
407 |
|
---|
408 | tlist.AddToList(&read);
|
---|
409 | tlist.AddToList(&f1);
|
---|
410 | tlist.AddToList(&f2);
|
---|
411 | tlist.AddToList(&apply);
|
---|
412 | tlist.AddToList(&pcopy);
|
---|
413 | tlist.AddToList(&pnsb);
|
---|
414 | //tlist.AddToList(&pcalc);
|
---|
415 | tlist.AddToList(&ncalc);
|
---|
416 | tlist.AddToList(&nanal);
|
---|
417 | tlist.AddToList(&sgcal);
|
---|
418 | //tlist.AddToList(&fills);
|
---|
419 | //tlist.AddToList(&fillb);
|
---|
420 | tlist.AddToList(&clean);
|
---|
421 | tlist.AddToList(&hcalc);
|
---|
422 | tlist.AddToList(&scalc);
|
---|
423 | tlist.AddToList(&write);
|
---|
424 |
|
---|
425 | //
|
---|
426 | // Set the serial number for all tasks in the current tasklist
|
---|
427 | //
|
---|
428 | tlist.SetSerialNumber(kTelIndex);
|
---|
429 |
|
---|
430 | //
|
---|
431 | // Setup tasks
|
---|
432 | //
|
---|
433 |
|
---|
434 | write.AddContainer(write.AddSerialNumber("MMcEvt"), "Events", kFALSE);
|
---|
435 | write.AddContainer(write.AddSerialNumber("MSigmabar"), "Events");
|
---|
436 | write.AddContainer(write.AddSerialNumber("MHillas"), "Events");
|
---|
437 | write.AddContainer(write.AddSerialNumber("MHillasExt"), "Events");
|
---|
438 | write.AddContainer(write.AddSerialNumber("MHillasSrc"), "Events");
|
---|
439 | write.AddContainer(write.AddSerialNumber("MNewImagePar"), "Events");
|
---|
440 | write.AddContainer(write.AddSerialNumber("MSrcPosCam"), "RunHeaders");
|
---|
441 | //write.AddContainer(write.AddSerialNumber("MHSigmaTheta"), "RunHeaders");
|
---|
442 | if (!kUpdate)
|
---|
443 | {
|
---|
444 | write.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
445 | write.AddContainer("MMcRunHeader", "RunHeaders", kFALSE);
|
---|
446 | }
|
---|
447 |
|
---|
448 | //
|
---|
449 | // Create and set up the eventloop
|
---|
450 | //
|
---|
451 | MEvtLoop evtloop;
|
---|
452 | evtloop.SetParList(&plist);
|
---|
453 |
|
---|
454 | //
|
---|
455 | // Execute your analysis
|
---|
456 | //
|
---|
457 | if (!evtloop.Eventloop())
|
---|
458 | {
|
---|
459 | gLog << err << "ERROR: Star eventloop failed!" << endl;
|
---|
460 | return -1;
|
---|
461 | }
|
---|
462 |
|
---|
463 | tlist.PrintStatistics();
|
---|
464 |
|
---|
465 | //plist.FindObject("MHSigmaTheta")->Write();
|
---|
466 |
|
---|
467 | gLog << all << "Star finished successfull!" << endl;
|
---|
468 | return 0;
|
---|
469 | */
|
---|
470 | }
|
---|