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