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

Last change on this file since 705 was 705, checked in by tbretz, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 3.4 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2// //
3// MCT1ReadAscii //
4// //
5/////////////////////////////////////////////////////////////////////////////
6
7#include "MCT1ReadAscii.h"
8
9#include <fstream.h>
10
11#include "MLog.h"
12#include "MLogManip.h"
13
14#include "MParList.h"
15#include "MCerPhotEvt.h"
16#include "MPedestalCam.h"
17
18ClassImp(MCT1ReadAscii)
19
20MCT1ReadAscii::MCT1ReadAscii(const char *fname,
21 const char *name,
22 const char *title)
23{
24 *fName = name ? name : "MCT1ReadAscii";
25 *fTitle = title ? title : "Task to loop over events in CT1 ascii file";
26
27 //
28 // remember file name for opening the file in the preprocessor
29 //
30 fFileName = fname;
31}
32
33Bool_t MCT1ReadAscii::PreProcess(MParList *pList)
34{
35 //
36 // Preprocessing
37 //
38
39 //
40 // open the input stream and check if it is really open (file exists?)
41 //
42 fIn = new ifstream(fFileName);
43 if (!(*fIn))
44 {
45 *fLog << dbginf << "Cannot open file." << endl;
46 return kFALSE;
47 }
48
49 //
50 // look for the MCerPhotEvt class in the plist
51 //
52 fNphot = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
53 if (!fNphot)
54 return kFALSE;
55
56 //
57 // look for the pedestal class in the plist
58 //
59 fPedest = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
60 if (!fPedest)
61 return kFALSE;
62
63 fPedest->InitSize(127);
64
65 return kTRUE;
66}
67
68void MCT1ReadAscii::ReadPedestals()
69{
70 *fLog << "MCT1Pedestals::AsciiRead: Reading Pedestals..." << endl;
71
72 //
73 // skip the next 4 values
74 //
75 Float_t val;
76
77 *fIn >> val;
78 *fIn >> val;
79 *fIn >> val;
80 *fIn >> val;
81
82 //
83 // read in the next 127 numbers as the pedestals
84 //
85 for (Int_t i = 0; i<127; i++)
86 {
87 *fIn >> val;
88
89 if (val > 0.0)
90 (*fPedest)[i].SetSigma(val);
91 }
92}
93
94void MCT1ReadAscii::ReadData()
95{
96 //
97 // clear the list of cerphot-events
98 //
99 fNphot->Clear();
100
101 //
102 // five unsused numbers
103 //
104 Int_t val;
105
106 *fIn >> val; // ener
107 *fIn >> val; // zenang
108 *fIn >> val; // sec1
109 *fIn >> val; // sec2
110
111 //
112 // read in the number of cerenkov photons and add the 'new' pixel
113 // too the list with it's id, number of photons and error
114 //
115 for (Int_t i = 0; i<127; i++ )
116 {
117 Float_t nphot;
118
119 *fIn >> nphot;
120
121 if (nphot > 0.0)
122 fNphot->AddPixel(i, nphot, (*fPedest)[i].GetSigma());
123 }
124
125}
126
127Bool_t MCT1ReadAscii::Process()
128{
129 //
130 // FIXME. This function should switch between reading pedestals and
131 // reading event data by the 'switch entry'.
132 // After reading it should set the InputStreamID correctly.
133 // ( should use MPedestalCam )
134 //
135
136 //
137 // read in the event nr
138 //
139 Int_t evtnr;
140 *fIn >> evtnr;
141
142 //
143 // check if we are done
144 //
145 if (fIn->eof())
146 return kFALSE;
147
148 //
149 // if the first number is negativ this is a pedestal line:
150 // read in pedestals
151 //
152 // FIXME! Set InputStreamID
153
154 if (evtnr < 0)
155 {
156 ReadPedestals();
157 return kCONTINUE;
158 }
159
160 ReadData();
161
162 return kTRUE;
163}
164
165Bool_t MCT1ReadAscii::PostProcess()
166{
167 //
168 // close and delete the input stream
169 //
170 delete fIn;
171
172 return kTRUE;
173}
174
Note: See TracBrowser for help on using the repository browser.