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 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
|
---|
19 | ! Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | // //
|
---|
28 | // MCT1ReadAscii //
|
---|
29 | // //
|
---|
30 | // Reads a ascii file with CT1 data. The file description and some example //
|
---|
31 | // files can be found on the Magic homepage. //
|
---|
32 | // //
|
---|
33 | // Input Containers: //
|
---|
34 | // -/- //
|
---|
35 | // //
|
---|
36 | // Output Containers: //
|
---|
37 | // MCerPhotEvt //
|
---|
38 | // //
|
---|
39 | /////////////////////////////////////////////////////////////////////////////
|
---|
40 |
|
---|
41 | #include "MCT1ReadAscii.h"
|
---|
42 |
|
---|
43 | #include <fstream.h>
|
---|
44 |
|
---|
45 | #include <TList.h>
|
---|
46 | #include <TSystem.h>
|
---|
47 |
|
---|
48 | #include "MLog.h"
|
---|
49 | #include "MLogManip.h"
|
---|
50 |
|
---|
51 | #include "MParList.h"
|
---|
52 | #include "MCerPhotEvt.h"
|
---|
53 | #include "MPedestalCam.h"
|
---|
54 |
|
---|
55 | ClassImp(MCT1ReadAscii);
|
---|
56 |
|
---|
57 | // --------------------------------------------------------------------------
|
---|
58 | //
|
---|
59 | // Default constructor. Creates an array which stores the file names of
|
---|
60 | // the files which should be read. If a filename is given it is added
|
---|
61 | // to the list.
|
---|
62 | //
|
---|
63 | MCT1ReadAscii::MCT1ReadAscii(const char *fname,
|
---|
64 | const char *name,
|
---|
65 | const char *title)
|
---|
66 | : fIn(NULL)
|
---|
67 | {
|
---|
68 | fName = name ? name : "MCT1ReadAscii";
|
---|
69 | fTitle = title ? title : "Task to loop over events in CT1 ascii file";
|
---|
70 |
|
---|
71 | //
|
---|
72 | // remember file name for opening the file in the preprocessor
|
---|
73 | //
|
---|
74 | fFileNames = new TList;
|
---|
75 | fFileNames->SetOwner();
|
---|
76 |
|
---|
77 | if (fname)
|
---|
78 | AddFile(fname);
|
---|
79 | }
|
---|
80 |
|
---|
81 | // --------------------------------------------------------------------------
|
---|
82 | //
|
---|
83 | // Delete the filename list and the input stream if one exists.
|
---|
84 | //
|
---|
85 | MCT1ReadAscii::~MCT1ReadAscii()
|
---|
86 | {
|
---|
87 | delete fFileNames;
|
---|
88 | if (fIn)
|
---|
89 | delete fIn;
|
---|
90 | }
|
---|
91 |
|
---|
92 | // --------------------------------------------------------------------------
|
---|
93 | //
|
---|
94 | // Add this file as the last entry in the chain
|
---|
95 | //
|
---|
96 | void MCT1ReadAscii::AddFile(const char *txt)
|
---|
97 | {
|
---|
98 | TNamed *name = new TNamed(txt, "");
|
---|
99 | fFileNames->AddLast(name);
|
---|
100 | }
|
---|
101 |
|
---|
102 | // --------------------------------------------------------------------------
|
---|
103 | //
|
---|
104 | // This opens the next file in the list and deletes its name from the list.
|
---|
105 | //
|
---|
106 | Bool_t MCT1ReadAscii::OpenNextFile()
|
---|
107 | {
|
---|
108 | //
|
---|
109 | // open the input stream and check if it is really open (file exists?)
|
---|
110 | //
|
---|
111 | if (fIn)
|
---|
112 | delete fIn;
|
---|
113 | fIn = NULL;
|
---|
114 |
|
---|
115 | //
|
---|
116 | // Check for the existance of a next file to read
|
---|
117 | //
|
---|
118 | TNamed *file = (TNamed*)fFileNames->First();
|
---|
119 | if (!file)
|
---|
120 | return kFALSE;
|
---|
121 |
|
---|
122 | //
|
---|
123 | // open the file which is the first one in the chain
|
---|
124 | //
|
---|
125 | const char *name = file->GetName();
|
---|
126 |
|
---|
127 | fIn = new ifstream(gSystem->ExpandPathName(name));
|
---|
128 |
|
---|
129 | const Bool_t noexist = !(*fIn);
|
---|
130 |
|
---|
131 | if (noexist)
|
---|
132 | *fLog << dbginf << "Cannot open file '" << name << "'" << endl;
|
---|
133 | else
|
---|
134 | *fLog << "Open file: '" << name << "'" << endl;
|
---|
135 |
|
---|
136 | //
|
---|
137 | // Remove this file from the list of pending files
|
---|
138 | //
|
---|
139 | fFileNames->Remove(file);
|
---|
140 |
|
---|
141 | return !noexist;
|
---|
142 | }
|
---|
143 |
|
---|
144 | // --------------------------------------------------------------------------
|
---|
145 | //
|
---|
146 | // Open the first file in the list. Check for the output containers or create
|
---|
147 | // them if they don't exist.
|
---|
148 | //
|
---|
149 | // Initialize the size of the MPedestalCam container to 127 pixels (CT1 camera)
|
---|
150 | //
|
---|
151 | Bool_t MCT1ReadAscii::PreProcess(MParList *pList)
|
---|
152 | {
|
---|
153 | //
|
---|
154 | // Preprocessing
|
---|
155 | //
|
---|
156 |
|
---|
157 | //
|
---|
158 | // Try to open at least one (the first) file
|
---|
159 | //
|
---|
160 | if (!OpenNextFile())
|
---|
161 | return kFALSE;
|
---|
162 |
|
---|
163 | //
|
---|
164 | // look for the MCerPhotEvt class in the plist
|
---|
165 | //
|
---|
166 | fNphot = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
|
---|
167 | if (!fNphot)
|
---|
168 | return kFALSE;
|
---|
169 |
|
---|
170 | //
|
---|
171 | // look for the pedestal class in the plist
|
---|
172 | //
|
---|
173 | fPedest = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
|
---|
174 | if (!fPedest)
|
---|
175 | return kFALSE;
|
---|
176 |
|
---|
177 | fPedest->InitSize(127);
|
---|
178 |
|
---|
179 | return kTRUE;
|
---|
180 | }
|
---|
181 |
|
---|
182 | // --------------------------------------------------------------------------
|
---|
183 | //
|
---|
184 | // Read apedestal entry (line) from the file
|
---|
185 | //
|
---|
186 | void MCT1ReadAscii::ReadPedestals()
|
---|
187 | {
|
---|
188 | //
|
---|
189 | // skip the next 4 values
|
---|
190 | //
|
---|
191 | Float_t val;
|
---|
192 |
|
---|
193 | *fIn >> val;
|
---|
194 | *fIn >> val;
|
---|
195 | *fIn >> val;
|
---|
196 | *fIn >> val;
|
---|
197 |
|
---|
198 | //
|
---|
199 | // read in the next 127 numbers as the pedestals
|
---|
200 | //
|
---|
201 | for (Int_t i = 0; i<127; i++)
|
---|
202 | {
|
---|
203 | *fIn >> val;
|
---|
204 |
|
---|
205 | if (val > 0.0)
|
---|
206 | (*fPedest)[i].SetMeanRms(val);
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | // --------------------------------------------------------------------------
|
---|
211 | //
|
---|
212 | // Read a data entry (line) from the file
|
---|
213 | //
|
---|
214 | void MCT1ReadAscii::ReadData()
|
---|
215 | {
|
---|
216 | //
|
---|
217 | // clear the list of cerphot-events
|
---|
218 | //
|
---|
219 | fNphot->Clear();
|
---|
220 |
|
---|
221 | //
|
---|
222 | // five unsused numbers
|
---|
223 | //
|
---|
224 | Int_t val;
|
---|
225 |
|
---|
226 | *fIn >> val; // ener
|
---|
227 | *fIn >> val; // zenang
|
---|
228 | *fIn >> val; // sec1
|
---|
229 | *fIn >> val; // sec2
|
---|
230 |
|
---|
231 | //
|
---|
232 | // read in the number of cerenkov photons and add the 'new' pixel
|
---|
233 | // too the list with it's id, number of photons and error
|
---|
234 | //
|
---|
235 | fNphot->InitSize(127);
|
---|
236 |
|
---|
237 | for (Int_t i = 0; i<127; i++ )
|
---|
238 | {
|
---|
239 | Float_t nphot;
|
---|
240 |
|
---|
241 | *fIn >> nphot;
|
---|
242 |
|
---|
243 | if (nphot > 0.0)
|
---|
244 | fNphot->AddPixel(i, nphot, (*fPedest)[i].GetMeanRms());
|
---|
245 | }
|
---|
246 |
|
---|
247 | }
|
---|
248 |
|
---|
249 | // --------------------------------------------------------------------------
|
---|
250 | //
|
---|
251 | // Check for the event number and depending on this number decide if
|
---|
252 | // pedestals or event data has to be read.
|
---|
253 | //
|
---|
254 | // If the end of the file is reached try to open the next in the list. If
|
---|
255 | // there is now next file stop the eventloop.
|
---|
256 | //
|
---|
257 | Bool_t MCT1ReadAscii::Process()
|
---|
258 | {
|
---|
259 | //
|
---|
260 | // FIXME. This function should switch between reading pedestals and
|
---|
261 | // reading event data by the 'switch entry'.
|
---|
262 | // After reading it should set the InputStreamID correctly.
|
---|
263 | // ( should use MPedestalCam )
|
---|
264 | //
|
---|
265 |
|
---|
266 | //
|
---|
267 | // read in the event nr
|
---|
268 | //
|
---|
269 | Int_t evtnr;
|
---|
270 | *fIn >> evtnr;
|
---|
271 |
|
---|
272 | //
|
---|
273 | // check if we are done. Try to open the next file in chain.
|
---|
274 | // If it was possible start reading. If not break the event loop
|
---|
275 | //
|
---|
276 | if (fIn->eof())
|
---|
277 | return OpenNextFile() ? kCONTINUE : kFALSE;
|
---|
278 |
|
---|
279 | //
|
---|
280 | // if the first number is negativ this is a pedestal line:
|
---|
281 | // read in pedestals
|
---|
282 | //
|
---|
283 | // FIXME! Set InputStreamID
|
---|
284 |
|
---|
285 | if (evtnr < 0)
|
---|
286 | {
|
---|
287 | ReadPedestals();
|
---|
288 | return kCONTINUE;
|
---|
289 | }
|
---|
290 |
|
---|
291 | ReadData();
|
---|
292 |
|
---|
293 | return kTRUE;
|
---|
294 | }
|
---|
295 |
|
---|