| 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 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 31 |
|
|---|
| 32 | #include "MCT1ReadAscii.h"
|
|---|
| 33 |
|
|---|
| 34 | #include <fstream.h>
|
|---|
| 35 |
|
|---|
| 36 | #include <TArrayC.h>
|
|---|
| 37 |
|
|---|
| 38 | #include "MLog.h"
|
|---|
| 39 | #include "MLogManip.h"
|
|---|
| 40 |
|
|---|
| 41 | #include "MParList.h"
|
|---|
| 42 | #include "MCerPhotEvt.h"
|
|---|
| 43 | #include "MPedestalCam.h"
|
|---|
| 44 |
|
|---|
| 45 | ClassImp(MCT1ReadAscii)
|
|---|
| 46 |
|
|---|
| 47 | MCT1ReadAscii::MCT1ReadAscii(const char *fname,
|
|---|
| 48 | const char *name,
|
|---|
| 49 | const char *title)
|
|---|
| 50 | {
|
|---|
| 51 | *fName = name ? name : "MCT1ReadAscii";
|
|---|
| 52 | *fTitle = title ? title : "Task to loop over events in CT1 ascii file";
|
|---|
| 53 |
|
|---|
| 54 | //
|
|---|
| 55 | // remember file name for opening the file in the preprocessor
|
|---|
| 56 | //
|
|---|
| 57 | fFileNames = new TArrayC;
|
|---|
| 58 | if (fname)
|
|---|
| 59 | AddFile(fname);
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | MCT1ReadAscii::~MCT1ReadAscii()
|
|---|
| 63 | {
|
|---|
| 64 | delete fFileNames;
|
|---|
| 65 | if (fIn)
|
|---|
| 66 | delete fIn;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | void MCT1ReadAscii::AddFile(const char *txt)
|
|---|
| 70 | {
|
|---|
| 71 | //
|
|---|
| 72 | // Add this file as the last entry in the chain
|
|---|
| 73 | //
|
|---|
| 74 | const int sz = fFileNames->GetSize();
|
|---|
| 75 | const int tsz = strlen(txt)+1;
|
|---|
| 76 |
|
|---|
| 77 | fFileNames->Set(sz+tsz);
|
|---|
| 78 |
|
|---|
| 79 | memcpy(fFileNames->GetArray()+sz, txt, tsz);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | Bool_t MCT1ReadAscii::OpenNextFile()
|
|---|
| 83 | {
|
|---|
| 84 | //
|
|---|
| 85 | // open the input stream and check if it is really open (file exists?)
|
|---|
| 86 | //
|
|---|
| 87 | if (fIn)
|
|---|
| 88 | delete fIn;
|
|---|
| 89 | fIn = NULL;
|
|---|
| 90 |
|
|---|
| 91 | const int arrsz = fFileNames->GetSize();
|
|---|
| 92 |
|
|---|
| 93 | if (arrsz<1)
|
|---|
| 94 | return kFALSE;
|
|---|
| 95 |
|
|---|
| 96 | //
|
|---|
| 97 | // open the file which is the first one in the chain
|
|---|
| 98 | //
|
|---|
| 99 | const char *name = fFileNames->GetArray();
|
|---|
| 100 |
|
|---|
| 101 | fIn = new ifstream(name);
|
|---|
| 102 | if (!(*fIn))
|
|---|
| 103 | {
|
|---|
| 104 | *fLog << dbginf << "Cannot open file '" << name << "'" << endl;
|
|---|
| 105 | return kFALSE;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | //
|
|---|
| 109 | // remove the first entry from the chain
|
|---|
| 110 | //
|
|---|
| 111 | *fLog << "Open file: '" << name << "'" << endl;
|
|---|
| 112 |
|
|---|
| 113 | //
|
|---|
| 114 | // create the new char array containing the filenames to process
|
|---|
| 115 | //
|
|---|
| 116 | const int sz = strlen(name)+1;
|
|---|
| 117 |
|
|---|
| 118 | char *dummy = new char[arrsz-sz];
|
|---|
| 119 | memcpy(dummy, name+sz, arrsz-sz);
|
|---|
| 120 |
|
|---|
| 121 | //
|
|---|
| 122 | // dummy will be deleted by the destructor of fFileNames
|
|---|
| 123 | //
|
|---|
| 124 | fFileNames->Adopt(arrsz-sz, dummy);
|
|---|
| 125 |
|
|---|
| 126 | return kTRUE;
|
|---|
| 127 |
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | Bool_t MCT1ReadAscii::PreProcess(MParList *pList)
|
|---|
| 131 | {
|
|---|
| 132 | //
|
|---|
| 133 | // Preprocessing
|
|---|
| 134 | //
|
|---|
| 135 |
|
|---|
| 136 | //
|
|---|
| 137 | // Try to open at least one (the first) file
|
|---|
| 138 | //
|
|---|
| 139 | if (!OpenNextFile())
|
|---|
| 140 | return kFALSE;
|
|---|
| 141 |
|
|---|
| 142 | //
|
|---|
| 143 | // look for the MCerPhotEvt class in the plist
|
|---|
| 144 | //
|
|---|
| 145 | fNphot = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
|
|---|
| 146 | if (!fNphot)
|
|---|
| 147 | return kFALSE;
|
|---|
| 148 |
|
|---|
| 149 | //
|
|---|
| 150 | // look for the pedestal class in the plist
|
|---|
| 151 | //
|
|---|
| 152 | fPedest = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
|
|---|
| 153 | if (!fPedest)
|
|---|
| 154 | return kFALSE;
|
|---|
| 155 |
|
|---|
| 156 | fPedest->InitSize(127);
|
|---|
| 157 |
|
|---|
| 158 | return kTRUE;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | void MCT1ReadAscii::ReadPedestals()
|
|---|
| 162 | {
|
|---|
| 163 | *fLog << "MCT1Pedestals::AsciiRead: Reading Pedestals..." << endl;
|
|---|
| 164 |
|
|---|
| 165 | //
|
|---|
| 166 | // skip the next 4 values
|
|---|
| 167 | //
|
|---|
| 168 | Float_t val;
|
|---|
| 169 |
|
|---|
| 170 | *fIn >> val;
|
|---|
| 171 | *fIn >> val;
|
|---|
| 172 | *fIn >> val;
|
|---|
| 173 | *fIn >> val;
|
|---|
| 174 |
|
|---|
| 175 | //
|
|---|
| 176 | // read in the next 127 numbers as the pedestals
|
|---|
| 177 | //
|
|---|
| 178 | for (Int_t i = 0; i<127; i++)
|
|---|
| 179 | {
|
|---|
| 180 | *fIn >> val;
|
|---|
| 181 |
|
|---|
| 182 | if (val > 0.0)
|
|---|
| 183 | (*fPedest)[i].SetMeanRms(val);
|
|---|
| 184 | }
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | void MCT1ReadAscii::ReadData()
|
|---|
| 188 | {
|
|---|
| 189 | //
|
|---|
| 190 | // clear the list of cerphot-events
|
|---|
| 191 | //
|
|---|
| 192 | fNphot->Clear();
|
|---|
| 193 |
|
|---|
| 194 | //
|
|---|
| 195 | // five unsused numbers
|
|---|
| 196 | //
|
|---|
| 197 | Int_t val;
|
|---|
| 198 |
|
|---|
| 199 | *fIn >> val; // ener
|
|---|
| 200 | *fIn >> val; // zenang
|
|---|
| 201 | *fIn >> val; // sec1
|
|---|
| 202 | *fIn >> val; // sec2
|
|---|
| 203 |
|
|---|
| 204 | //
|
|---|
| 205 | // read in the number of cerenkov photons and add the 'new' pixel
|
|---|
| 206 | // too the list with it's id, number of photons and error
|
|---|
| 207 | //
|
|---|
| 208 | for (Int_t i = 0; i<127; i++ )
|
|---|
| 209 | {
|
|---|
| 210 | Float_t nphot;
|
|---|
| 211 |
|
|---|
| 212 | *fIn >> nphot;
|
|---|
| 213 |
|
|---|
| 214 | if (nphot > 0.0)
|
|---|
| 215 | fNphot->AddPixel(i, nphot, (*fPedest)[i].GetMeanRms());
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | Bool_t MCT1ReadAscii::Process()
|
|---|
| 221 | {
|
|---|
| 222 | //
|
|---|
| 223 | // FIXME. This function should switch between reading pedestals and
|
|---|
| 224 | // reading event data by the 'switch entry'.
|
|---|
| 225 | // After reading it should set the InputStreamID correctly.
|
|---|
| 226 | // ( should use MPedestalCam )
|
|---|
| 227 | //
|
|---|
| 228 |
|
|---|
| 229 | //
|
|---|
| 230 | // read in the event nr
|
|---|
| 231 | //
|
|---|
| 232 | Int_t evtnr;
|
|---|
| 233 | *fIn >> evtnr;
|
|---|
| 234 |
|
|---|
| 235 | //
|
|---|
| 236 | // check if we are done. Try to open the next file in chain.
|
|---|
| 237 | // If it was possible start reading. If not break the event loop
|
|---|
| 238 | //
|
|---|
| 239 | if (fIn->eof())
|
|---|
| 240 | return OpenNextFile() ? kCONTINUE : kFALSE;
|
|---|
| 241 |
|
|---|
| 242 | //
|
|---|
| 243 | // if the first number is negativ this is a pedestal line:
|
|---|
| 244 | // read in pedestals
|
|---|
| 245 | //
|
|---|
| 246 | // FIXME! Set InputStreamID
|
|---|
| 247 |
|
|---|
| 248 | if (evtnr < 0)
|
|---|
| 249 | {
|
|---|
| 250 | ReadPedestals();
|
|---|
| 251 | return kCONTINUE;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | ReadData();
|
|---|
| 255 |
|
|---|
| 256 | return kTRUE;
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|