| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of CheObs, the Modular 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 appears 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, 1/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: CheObs Software Development, 2000-2009
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MSimReadout
|
|---|
| 28 | //
|
|---|
| 29 | // Task to convert the analog channels into a digital signal. This should
|
|---|
| 30 | // simulate the conversion and saturation bahaviour of the FADC/readout
|
|---|
| 31 | // system.
|
|---|
| 32 | //
|
|---|
| 33 | //
|
|---|
| 34 | // Input Containers:
|
|---|
| 35 | // MGeomCam
|
|---|
| 36 | // MAnalogChannels
|
|---|
| 37 | // TriggerPos [MParameterD]
|
|---|
| 38 | // IntendedPulsePos [MParameterD]
|
|---|
| 39 | // MRawRunHeader
|
|---|
| 40 | //
|
|---|
| 41 | // Output Containers:
|
|---|
| 42 | // MRawEvtData
|
|---|
| 43 | // MRawEvtHeader
|
|---|
| 44 | //
|
|---|
| 45 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 46 | #include "MSimReadout.h"
|
|---|
| 47 |
|
|---|
| 48 | #include "MLog.h"
|
|---|
| 49 | #include "MLogManip.h"
|
|---|
| 50 |
|
|---|
| 51 | #include "MArrayI.h"
|
|---|
| 52 |
|
|---|
| 53 | #include "MParList.h"
|
|---|
| 54 | #include "MParameters.h"
|
|---|
| 55 |
|
|---|
| 56 | #include "MGeomCam.h"
|
|---|
| 57 |
|
|---|
| 58 | #include "MRawRunHeader.h"
|
|---|
| 59 | #include "MRawEvtHeader.h"
|
|---|
| 60 | #include "MRawEvtData.h"
|
|---|
| 61 |
|
|---|
| 62 | #include "MAnalogSignal.h"
|
|---|
| 63 | #include "MAnalogChannels.h"
|
|---|
| 64 |
|
|---|
| 65 | ClassImp(MSimReadout);
|
|---|
| 66 |
|
|---|
| 67 | using namespace std;
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | // ------------------------------------------------------------------------
|
|---|
| 71 | //
|
|---|
| 72 | // Default constructor
|
|---|
| 73 | //
|
|---|
| 74 | MSimReadout::MSimReadout(const char* name, const char *title)
|
|---|
| 75 | : fRunHeader(0), fEvtHeader(0), fCamera(0), fPulsePos(0), fTrigger(0), fData(0)
|
|---|
| 76 | {
|
|---|
| 77 | fName = name ? name : "MSimReadout";
|
|---|
| 78 | fTitle = title ? title : "Task to simulate the analog readout (FADCs)";
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | // ------------------------------------------------------------------------
|
|---|
| 82 | //
|
|---|
| 83 | // Look for the needed parameter containers.
|
|---|
| 84 | // Initialize MRawEvtData from MRawEvtRunHeader.
|
|---|
| 85 | //
|
|---|
| 86 | Int_t MSimReadout::PreProcess(MParList *pList)
|
|---|
| 87 | {
|
|---|
| 88 | fCamera = (MAnalogChannels*)pList->FindObject("MAnalogChannels");
|
|---|
| 89 | if (!fCamera)
|
|---|
| 90 | {
|
|---|
| 91 | *fLog << err << "MAnalogChannels not found... aborting." << endl;
|
|---|
| 92 | return kFALSE;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | fTrigger = (MParameterD*)pList->FindObject("TriggerPos", "MParameterD");
|
|---|
| 96 | if (!fTrigger)
|
|---|
| 97 | {
|
|---|
| 98 | *fLog << err << "TriggerPos [MParameterD] not found... aborting." << endl;
|
|---|
| 99 | return kFALSE;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD");
|
|---|
| 103 | if (!fPulsePos)
|
|---|
| 104 | {
|
|---|
| 105 | *fLog << err << "IntendedPulsePos [MParameterD] not found... aborting." << endl;
|
|---|
| 106 | return kFALSE;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
|---|
| 110 | if (!fRunHeader)
|
|---|
| 111 | {
|
|---|
| 112 | *fLog << err << "MRawRunHeader not found... aborting." << endl;
|
|---|
| 113 | return kFALSE;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | fEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
|
|---|
| 117 | if (!fEvtHeader)
|
|---|
| 118 | return kFALSE;
|
|---|
| 119 |
|
|---|
| 120 | fData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
|
|---|
| 121 | if (!fData)
|
|---|
| 122 | return kFALSE;
|
|---|
| 123 |
|
|---|
| 124 | return kTRUE;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | Bool_t MSimReadout::ReInit(MParList *plist)
|
|---|
| 128 | {
|
|---|
| 129 | MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
|
|---|
| 130 | if (!cam)
|
|---|
| 131 | {
|
|---|
| 132 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
|---|
| 133 | return kFALSE;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | fRunHeader->InitPixels(cam->GetNumPixels());
|
|---|
| 137 | fRunHeader->SetValidMagicNumber();
|
|---|
| 138 | fRunHeader->SetSourceInfo("MonteCarlo"); // "Muon" from first event??
|
|---|
| 139 | fRunHeader->SetReadyToSave();
|
|---|
| 140 |
|
|---|
| 141 | fData->InitRead(fRunHeader);
|
|---|
| 142 | fData->ResetPixels();
|
|---|
| 143 | fData->SetIndices();
|
|---|
| 144 |
|
|---|
| 145 | return kTRUE;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | // ------------------------------------------------------------------------
|
|---|
| 149 | //
|
|---|
| 150 | // Convert (digitize) the analog channels into digital (FADC) data.
|
|---|
| 151 | //
|
|---|
| 152 | Int_t MSimReadout::Process()
|
|---|
| 153 | {
|
|---|
| 154 | // Sanity checks
|
|---|
| 155 | if (fData->GetNumLoGainSamples()>0)
|
|---|
| 156 | {
|
|---|
| 157 | *fLog << err << "ERROR - MSimReadout: Lo-gains not implemented yet." << endl;
|
|---|
| 158 | return kERROR;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | // Get Number of pixels
|
|---|
| 162 | const UInt_t npix = fData->GetNumPixels();
|
|---|
| 163 |
|
|---|
| 164 | if (npix!=fCamera->GetNumChannels())
|
|---|
| 165 | {
|
|---|
| 166 | *fLog << err;
|
|---|
| 167 | *fLog << "ERROR - Number of analog channels " << fCamera->GetNumChannels();
|
|---|
| 168 | *fLog << " doesn't match number of pixels " << fData->GetNumPixels() << endl;
|
|---|
| 169 | return kERROR;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | if (fTrigger->GetVal()<0)
|
|---|
| 173 | {
|
|---|
| 174 | *fLog << err << "ERROR - MSimReadout: MSimReadout executed for an event which has no trigger." << endl;
|
|---|
| 175 | return kERROR;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | // Get the intended pulse position and convert it to slices
|
|---|
| 179 | const Float_t pulpos = fPulsePos->GetVal()*fRunHeader->GetFreqSampling()/1000.;
|
|---|
| 180 |
|
|---|
| 181 | // Get trigger position and correct for intended pulse position
|
|---|
| 182 | const Int_t trig = TMath::CeilNint(fTrigger->GetVal()-pulpos);
|
|---|
| 183 |
|
|---|
| 184 | // Check if the position is valid
|
|---|
| 185 | if (trig<0)
|
|---|
| 186 | {
|
|---|
| 187 | *fLog << err;
|
|---|
| 188 | *fLog << "ERROR - Trigger position before analog signal." << endl;
|
|---|
| 189 | *fLog << " Trigger: " << fTrigger->GetVal() << endl;
|
|---|
| 190 | *fLog << " PulsePos: " << pulpos << endl;
|
|---|
| 191 | return kERROR;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | // Get Number of samples in analog channels
|
|---|
| 195 | const Int_t nsamp = fCamera->GetNumSamples();
|
|---|
| 196 |
|
|---|
| 197 | // Get number of samples to be digitized
|
|---|
| 198 | const Int_t nslices = fData->GetNumSamples();
|
|---|
| 199 |
|
|---|
| 200 | // Check if the whole requested signal can be digitized
|
|---|
| 201 | if (trig+nslices>=nsamp)
|
|---|
| 202 | {
|
|---|
| 203 | *fLog << err << "ERROR - Trigger position beyond valid analog signal range." << endl;
|
|---|
| 204 | *fLog << " Trigger: " << fTrigger->GetVal() << endl;
|
|---|
| 205 | *fLog << " PulsePos: " << pulpos << endl;
|
|---|
| 206 | *fLog << " SamplesIn: " << nsamp << endl;
|
|---|
| 207 | *fLog << " SamplesOut: " << nslices << endl;
|
|---|
| 208 | return kERROR;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | const Float_t gain = 64./1;
|
|---|
| 212 | const Float_t offset = 128;
|
|---|
| 213 | const UInt_t max = fData->GetMax();
|
|---|
| 214 |
|
|---|
| 215 | // FIXME: Take this into account
|
|---|
| 216 | // const UInt_t scale = 16;
|
|---|
| 217 | // const UInt_t resolution = 12;
|
|---|
| 218 |
|
|---|
| 219 | // Digitize into a buffer
|
|---|
| 220 | MArrayI buffer(nslices*npix);
|
|---|
| 221 |
|
|---|
| 222 | // Loop over all channels/pixels
|
|---|
| 223 | for (UInt_t i=0; i<npix; i++)
|
|---|
| 224 | {
|
|---|
| 225 | // Get i-th canalog hannel
|
|---|
| 226 | const MAnalogSignal &sig = (*fCamera)[i];
|
|---|
| 227 |
|
|---|
| 228 | // Digitize all slices
|
|---|
| 229 | for (Int_t j=0; j<nslices; j++)
|
|---|
| 230 | {
|
|---|
| 231 | Float_t slice = j+trig>=(Int_t)sig.GetSize() ? offset :
|
|---|
| 232 | sig[j+trig] * gain + offset;
|
|---|
| 233 |
|
|---|
| 234 | // FIXME: Handle/Implement saturation!
|
|---|
| 235 | if (slice>max)
|
|---|
| 236 | slice = max;
|
|---|
| 237 | if (slice<0)
|
|---|
| 238 | slice = 0;
|
|---|
| 239 |
|
|---|
| 240 | // We have a 16 bit FADC. The resolution of the DRS4 is just about 11.5 bit.
|
|---|
| 241 | // Therefore the last 4.5 bits (~22.5) are gaussian noise (is this right?)
|
|---|
| 242 | buffer[nslices*i + j] = TMath::Nint(slice);
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | // Set samples as raw-data
|
|---|
| 247 | fData->Set(buffer);
|
|---|
| 248 | fData->SetReadyToSave();
|
|---|
| 249 |
|
|---|
| 250 | // Set the trigger/daq event number
|
|---|
| 251 | fEvtHeader->SetDAQEvtNumber(GetNumExecutions());
|
|---|
| 252 | fEvtHeader->SetReadyToSave();
|
|---|
| 253 |
|
|---|
| 254 | // FIMXE: This will never be stored correctly :(
|
|---|
| 255 | fRunHeader->SetNumEvents(fRunHeader->GetNumEvents()+1);
|
|---|
| 256 |
|
|---|
| 257 | return kTRUE;
|
|---|
| 258 | }
|
|---|