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 "MHCamEvent.h"
|
---|
46 |
|
---|
47 | #include "MReadMarsFile.h"
|
---|
48 | #include "MGeomApply.h"
|
---|
49 | #include "MImgCleanStd.h"
|
---|
50 | #include "MHillasCalc.h"
|
---|
51 | #include "MFillH.h"
|
---|
52 | #include "MWriteRootFile.h"
|
---|
53 |
|
---|
54 | ClassImp(MJStar);
|
---|
55 |
|
---|
56 | using namespace std;
|
---|
57 |
|
---|
58 | // --------------------------------------------------------------------------
|
---|
59 | //
|
---|
60 | // Default constructor.
|
---|
61 | //
|
---|
62 | // Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
|
---|
63 | //
|
---|
64 | MJStar::MJStar(const char *name, const char *title)
|
---|
65 | {
|
---|
66 | fName = name ? name : "MJStar";
|
---|
67 | fTitle = title ? title : "Standard analysis and reconstruction";
|
---|
68 | }
|
---|
69 |
|
---|
70 | Bool_t MJStar::WriteResult()
|
---|
71 | {
|
---|
72 | if (fPathOut.IsNull())
|
---|
73 | {
|
---|
74 | *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
|
---|
75 | return kTRUE;
|
---|
76 | }
|
---|
77 |
|
---|
78 | const TString oname = Form("%s/star%06d.root", (const char*)fPathOut, fSequence.GetSequence());
|
---|
79 |
|
---|
80 | *fLog << inf << "Writing to file: " << oname << endl;
|
---|
81 |
|
---|
82 | TFile file(oname, "RECREATE");
|
---|
83 |
|
---|
84 | *fLog << inf << " - MStatusDisplay..." << flush;
|
---|
85 | if (fDisplay && fDisplay->Write()<=0)
|
---|
86 | {
|
---|
87 | *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
|
---|
88 | return kFALSE;
|
---|
89 | }
|
---|
90 | *fLog << inf << "ok." << endl;
|
---|
91 |
|
---|
92 | return kTRUE;
|
---|
93 | }
|
---|
94 |
|
---|
95 | Bool_t MJStar::ProcessFile()
|
---|
96 | {
|
---|
97 | if (!fSequence.IsValid())
|
---|
98 | {
|
---|
99 | *fLog << err << "ERROR - Sequence invalid!" << endl;
|
---|
100 | return kFALSE;
|
---|
101 | }
|
---|
102 |
|
---|
103 | //if (!CheckEnv())
|
---|
104 | // return kFALSE;
|
---|
105 |
|
---|
106 | CheckEnv();
|
---|
107 |
|
---|
108 | // --------------------------------------------------------------------------------
|
---|
109 |
|
---|
110 | *fLog << inf;
|
---|
111 | fLog->Separator(GetDescriptor());
|
---|
112 | *fLog << "Calculate image parameters from sequence ";
|
---|
113 | *fLog << fSequence.GetName() << endl;
|
---|
114 | *fLog << endl;
|
---|
115 |
|
---|
116 | // --------------------------------------------------------------------------------
|
---|
117 |
|
---|
118 | MDirIter iter;
|
---|
119 | const Int_t n0 = fSequence.SetupDatRuns(iter, fPathData);
|
---|
120 | const Int_t n1 = fSequence.GetNumDatRuns();
|
---|
121 | if (n0==0)
|
---|
122 | {
|
---|
123 | *fLog << err << "ERROR - No input files of sequence found!" << endl;
|
---|
124 | return kFALSE;
|
---|
125 | }
|
---|
126 | if (n0!=n1)
|
---|
127 | {
|
---|
128 | *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
|
---|
129 | return kFALSE;
|
---|
130 | }
|
---|
131 |
|
---|
132 | // Setup Parlist
|
---|
133 | MParList plist;
|
---|
134 | plist.AddToList(this); // take care of fDisplay!
|
---|
135 |
|
---|
136 | // Setup Tasklist
|
---|
137 | MTaskList tlist;
|
---|
138 | plist.AddToList(&tlist);
|
---|
139 |
|
---|
140 | MReadMarsFile read("Events");
|
---|
141 | read.DisableAutoScheme();
|
---|
142 | read.AddFiles(iter);
|
---|
143 | //read.AddFiles(fnamein);
|
---|
144 |
|
---|
145 | MGeomApply apply; // Only necessary to craete geometry
|
---|
146 | //MBadPixelsMerge merge(&badpix);
|
---|
147 | MImgCleanStd clean;
|
---|
148 | MHillasCalc hcalc;
|
---|
149 |
|
---|
150 | MHCamEvent evt0("Cleaned");
|
---|
151 | evt0.SetType(0);
|
---|
152 | MFillH fill0(&evt0, "MCerPhotEvt", "FillCerPhotEvt");
|
---|
153 | MFillH fill1("MHHillas", "MHillas", "FillHillas");
|
---|
154 | MFillH fill2("MHHillasExt", "MHillasExt", "FillHillasExt");
|
---|
155 | MFillH fill3("MHHillasSrc", "MHillasSrc", "FillHillasSrc");
|
---|
156 | MFillH fill4("MHImagePar", "MImagePar", "FillImagePar");
|
---|
157 | MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
|
---|
158 | MFillH fill6("MHCerPhot");
|
---|
159 |
|
---|
160 | MWriteRootFile write(2, "images/{s/_Y_/_I_}");
|
---|
161 | write.AddContainer("MMcEvt", "Events", kFALSE);
|
---|
162 | write.AddContainer("MHillas", "Events");
|
---|
163 | write.AddContainer("MHillasExt", "Events");
|
---|
164 | write.AddContainer("MHillasSrc", "Events");
|
---|
165 | write.AddContainer("MImagePar", "Events");
|
---|
166 | write.AddContainer("MNewImagePar", "Events");
|
---|
167 | write.AddContainer("MTime", "Events");
|
---|
168 | write.AddContainer("MRawEvtHeader", "Events");
|
---|
169 | write.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
170 | write.AddContainer("MBadPixelsCam", "RunHeaders");
|
---|
171 | write.AddContainer("MGeomCam", "RunHeaders");
|
---|
172 | //write.AddContainer("MObservatory", "RunHeaders");
|
---|
173 |
|
---|
174 | tlist.AddToList(&read);
|
---|
175 | tlist.AddToList(&apply);
|
---|
176 | tlist.AddToList(&clean);
|
---|
177 | tlist.AddToList(&fill0);
|
---|
178 | tlist.AddToList(&hcalc);
|
---|
179 | tlist.AddToList(&fill1);
|
---|
180 | tlist.AddToList(&fill2);
|
---|
181 | tlist.AddToList(&fill3);
|
---|
182 | tlist.AddToList(&fill4);
|
---|
183 | tlist.AddToList(&fill5);
|
---|
184 | //tlist.AddToList(&fill6);
|
---|
185 | tlist.AddToList(&write);
|
---|
186 |
|
---|
187 | // Create and setup the eventloop
|
---|
188 | MEvtLoop evtloop(fName);
|
---|
189 | evtloop.SetParList(&plist);
|
---|
190 | evtloop.SetDisplay(fDisplay);
|
---|
191 | evtloop.SetLogStream(fLog);
|
---|
192 | if (!SetupEnv(evtloop))
|
---|
193 | return kFALSE;
|
---|
194 |
|
---|
195 | // Execute first analysis
|
---|
196 | if (!evtloop.Eventloop(fMaxEvents))
|
---|
197 | {
|
---|
198 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
199 | return kFALSE;
|
---|
200 | }
|
---|
201 |
|
---|
202 | tlist.PrintStatistics();
|
---|
203 |
|
---|
204 | if (!WriteResult())
|
---|
205 | return kFALSE;
|
---|
206 |
|
---|
207 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
---|
208 | *fLog << endl << endl;
|
---|
209 |
|
---|
210 | return kTRUE;
|
---|
211 | }
|
---|