source: trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.cc@ 1013

Last change on this file since 1013 was 1011, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.5 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): 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
54ClassImp(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//
62MCT1ReadAscii::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//
84MCT1ReadAscii::~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//
95void 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//
105Bool_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//
150Bool_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//
185void MCT1ReadAscii::ReadPedestals()
186{
187 //
188 // skip the next 4 values
189 //
190 Float_t val;
191
192 *fIn >> val;
193 *fIn >> val;
194 *fIn >> val;
195 *fIn >> val;
196
197 //
198 // read in the next 127 numbers as the pedestals
199 //
200 for (Int_t i = 0; i<127; i++)
201 {
202 *fIn >> val;
203
204 if (val > 0.0)
205 (*fPedest)[i].SetMeanRms(val);
206 }
207}
208
209// --------------------------------------------------------------------------
210//
211// Read a data entry (line) from the file
212//
213void MCT1ReadAscii::ReadData()
214{
215 //
216 // clear the list of cerphot-events
217 //
218 fNphot->Clear();
219
220 //
221 // five unsused numbers
222 //
223 Int_t val;
224
225 *fIn >> val; // ener
226 *fIn >> val; // zenang
227 *fIn >> val; // sec1
228 *fIn >> val; // sec2
229
230 //
231 // read in the number of cerenkov photons and add the 'new' pixel
232 // too the list with it's id, number of photons and error
233 //
234 for (Int_t i = 0; i<127; i++ )
235 {
236 Float_t nphot;
237
238 *fIn >> nphot;
239
240 if (nphot > 0.0)
241 fNphot->AddPixel(i, nphot, (*fPedest)[i].GetMeanRms());
242 }
243
244}
245
246// --------------------------------------------------------------------------
247//
248// Check for the event number and depending on this number decide if
249// pedestals or event data has to be read.
250//
251// If the end of the file is reached try to open the next in the list. If
252// there is now next file stop the eventloop.
253//
254Bool_t MCT1ReadAscii::Process()
255{
256 //
257 // FIXME. This function should switch between reading pedestals and
258 // reading event data by the 'switch entry'.
259 // After reading it should set the InputStreamID correctly.
260 // ( should use MPedestalCam )
261 //
262
263 //
264 // read in the event nr
265 //
266 Int_t evtnr;
267 *fIn >> evtnr;
268
269 //
270 // check if we are done. Try to open the next file in chain.
271 // If it was possible start reading. If not break the event loop
272 //
273 if (fIn->eof())
274 return OpenNextFile() ? kCONTINUE : kFALSE;
275
276 //
277 // if the first number is negativ this is a pedestal line:
278 // read in pedestals
279 //
280 // FIXME! Set InputStreamID
281
282 if (evtnr < 0)
283 {
284 ReadPedestals();
285 return kCONTINUE;
286 }
287
288 ReadData();
289
290 return kTRUE;
291}
292
Note: See TracBrowser for help on using the repository browser.