| 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 | // MSimCamera
|
|---|
| 28 | //
|
|---|
| 29 | // This task initializes the analog channels with analog noise and simulated
|
|---|
| 30 | // the analog pulses from the photon signal.
|
|---|
| 31 | //
|
|---|
| 32 | // Input Containers:
|
|---|
| 33 | // MPhotonEvent
|
|---|
| 34 | // MPhotonStatistics
|
|---|
| 35 | // MRawRunHeader
|
|---|
| 36 | //
|
|---|
| 37 | // Output Containers:
|
|---|
| 38 | // MAnalogChannels
|
|---|
| 39 | //
|
|---|
| 40 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 41 | #include "MSimCamera.h"
|
|---|
| 42 |
|
|---|
| 43 | #include <TF1.h>
|
|---|
| 44 | #include <TRandom.h>
|
|---|
| 45 |
|
|---|
| 46 | #include "MLog.h"
|
|---|
| 47 | #include "MLogManip.h"
|
|---|
| 48 |
|
|---|
| 49 | #include "MSpline3.h"
|
|---|
| 50 | #include "MPulseShape.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "MParList.h"
|
|---|
| 53 | //#include "MParameters.h"
|
|---|
| 54 |
|
|---|
| 55 | #include "MPhotonEvent.h"
|
|---|
| 56 | #include "MPhotonData.h"
|
|---|
| 57 |
|
|---|
| 58 | #include "MAnalogSignal.h"
|
|---|
| 59 | #include "MAnalogChannels.h"
|
|---|
| 60 |
|
|---|
| 61 | #include "MRawRunHeader.h"
|
|---|
| 62 |
|
|---|
| 63 | ClassImp(MSimCamera);
|
|---|
| 64 |
|
|---|
| 65 | using namespace std;
|
|---|
| 66 |
|
|---|
| 67 | // --------------------------------------------------------------------------
|
|---|
| 68 | //
|
|---|
| 69 | // Default Constructor.
|
|---|
| 70 | //
|
|---|
| 71 | MSimCamera::MSimCamera(const char* name, const char *title)
|
|---|
| 72 | : fEvt(0), fStat(0), fRunHeader(0), fCamera(0), fSpline(0)//, fPulsePos(0)
|
|---|
| 73 | {
|
|---|
| 74 | fName = name ? name : "MSimCamera";
|
|---|
| 75 | fTitle = title ? title : "Task to simulate the electronic noise and to convert photons into pulses";
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | // --------------------------------------------------------------------------
|
|---|
| 79 | //
|
|---|
| 80 | // Search for the necessayr parameter containers.
|
|---|
| 81 | // Setup spline for pulse shape.
|
|---|
| 82 | //
|
|---|
| 83 | Int_t MSimCamera::PreProcess(MParList *pList)
|
|---|
| 84 | {
|
|---|
| 85 | fCamera = (MAnalogChannels*)pList->FindCreateObj("MAnalogChannels");
|
|---|
| 86 | if (!fCamera)
|
|---|
| 87 | return kFALSE;
|
|---|
| 88 |
|
|---|
| 89 | fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
|
|---|
| 90 | if (!fEvt)
|
|---|
| 91 | {
|
|---|
| 92 | *fLog << err << "MPhotonEvent not found... aborting." << endl;
|
|---|
| 93 | return kFALSE;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | fStat = (MPhotonStatistics*)pList->FindObject("MPhotonStatistics");
|
|---|
| 97 | if (!fStat)
|
|---|
| 98 | {
|
|---|
| 99 | *fLog << err << "MPhotonStatistics not found... aborting." << endl;
|
|---|
| 100 | return kFALSE;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | fRunHeader = (MRawRunHeader *)pList->FindObject("MRawRunHeader");
|
|---|
| 104 | if (!fRunHeader)
|
|---|
| 105 | {
|
|---|
| 106 | *fLog << err << "MRawRunHeader not found... aborting." << endl;
|
|---|
| 107 | return kFALSE;
|
|---|
| 108 | }
|
|---|
| 109 | /*
|
|---|
| 110 | fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD");
|
|---|
| 111 | if (!fPulsePos)
|
|---|
| 112 | {
|
|---|
| 113 | *fLog << err << "IntendedPulsePos [MParameterD] not found... aborting." << endl;
|
|---|
| 114 | return kFALSE;
|
|---|
| 115 | }
|
|---|
| 116 | */
|
|---|
| 117 | MPulseShape *pulse = (MPulseShape*)pList->FindObject("MPulseShape");
|
|---|
| 118 | if (!pulse)
|
|---|
| 119 | {
|
|---|
| 120 | *fLog << err << "MPulseShape not found... aborting." << endl;
|
|---|
| 121 | return kFALSE;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | *fLog << warn << "FIXME - SCALE WITH THE SAMPLING FREQUENCY." << endl;
|
|---|
| 125 |
|
|---|
| 126 | fSpline = pulse->GetSpline();
|
|---|
| 127 | if (!fSpline)
|
|---|
| 128 | {
|
|---|
| 129 | *fLog << err << "No spline initialized." << endl;
|
|---|
| 130 | return kFALSE;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | return kTRUE;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | // --------------------------------------------------------------------------
|
|---|
| 137 | //
|
|---|
| 138 | // fStat->GetMaxIndex must return the maximum index possible
|
|---|
| 139 | // (equiv. number of pixels) not just the maximum index stored!
|
|---|
| 140 | //
|
|---|
| 141 | Int_t MSimCamera::Process()
|
|---|
| 142 | {
|
|---|
| 143 | // Calculate start time, end time and corresponding number of samples
|
|---|
| 144 | const Double_t freq = fRunHeader->GetFreqSampling()/1000.;
|
|---|
| 145 |
|
|---|
| 146 | const Double_t start = fStat->GetTimeFirst()*freq;
|
|---|
| 147 | const Double_t end = fStat->GetTimeLast() *freq;
|
|---|
| 148 |
|
|---|
| 149 | const UInt_t nlen = TMath::CeilNint(end-start);
|
|---|
| 150 |
|
|---|
| 151 | // FIXME: Jitter the start point of digitization by one sample [0;1]
|
|---|
| 152 | // FIXME: TAKE PULSE WIDTH out of the calculation and start at TimeFirst
|
|---|
| 153 |
|
|---|
| 154 | // Get number of pixels/channels
|
|---|
| 155 | const UInt_t npix = fStat->GetMaxIndex()+1;
|
|---|
| 156 |
|
|---|
| 157 | const Double_t pl = fSpline->GetXmin()*freq;
|
|---|
| 158 | const Double_t pr = fSpline->GetXmax()*freq;
|
|---|
| 159 |
|
|---|
| 160 | // Init the arrays and set the range which will contain valid data
|
|---|
| 161 | fCamera->Init(npix, nlen);
|
|---|
| 162 | fCamera->SetValidRange(TMath::FloorNint(pr), TMath::CeilNint(nlen+pl));
|
|---|
| 163 |
|
|---|
| 164 | // Add electronic noise to empty channels
|
|---|
| 165 | for (UInt_t i=0; i<npix; i++)
|
|---|
| 166 | {
|
|---|
| 167 | // FIXME: We might add the base line here already.
|
|---|
| 168 | (*fCamera)[i].AddGaussianNoise(22.5/64);
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | // FIXME: Simulate correlations with neighboring pixels
|
|---|
| 172 |
|
|---|
| 173 | const Int_t num = fEvt->GetNumPhotons();
|
|---|
| 174 |
|
|---|
| 175 | // A random shift, uniformely distributed within one slice, to make sure that
|
|---|
| 176 | // the first photon is not always aligned identically with a sample edge.
|
|---|
| 177 | // FIXME: Make it switchable
|
|---|
| 178 | const Float_t rndm = gRandom->Uniform();
|
|---|
| 179 |
|
|---|
| 180 | // FIXME: Shell we add a random shift of [0,1] samples per channel?
|
|---|
| 181 | // Or maybe per channel and run?
|
|---|
| 182 |
|
|---|
| 183 | // Simulate pulses
|
|---|
| 184 | for (Int_t i=0; i<num; i++)
|
|---|
| 185 | {
|
|---|
| 186 | const MPhotonData &ph = (*fEvt)[i];
|
|---|
| 187 |
|
|---|
| 188 | const UInt_t idx = ph.GetTag();
|
|---|
| 189 | const Double_t t = (ph.GetTime()-fStat->GetTimeFirst())*freq+rndm;// - fSpline->GetXmin();
|
|---|
| 190 |
|
|---|
| 191 | // FIXME: Time jitter?
|
|---|
| 192 | // FIXME: Add additional routing here?
|
|---|
| 193 |
|
|---|
| 194 | // === FIXME === FIXME === FIXME === Frequency!!!!
|
|---|
| 195 | (*fCamera)[idx].AddPulse(*fSpline, t, ph.GetWeight());
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | return kTRUE;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | /*
|
|---|
| 202 | MSimCameraFiles::Process()
|
|---|
| 203 | {
|
|---|
| 204 | // fCorsikaHeader->GetEvtNumber() --> fMcEvt->SetEvtNumber()
|
|---|
| 205 | // fCorsikaHeader->GetTotalEnergy() --> fMcEvt->SetEnergy()
|
|---|
| 206 | // fCorsikaHeader->GetParticleID() --> fMcEvt->SetParticleID()
|
|---|
| 207 | // fCorsikaHeader->GetImpact() --> fMcEvt->SetImpact()
|
|---|
| 208 | // fCorsikaHeader->GetTheta() --> fMcEvt->SetTheta()
|
|---|
| 209 | // fCorsikaHeader->GetPhi() --> fMcEvt->SetPhi()
|
|---|
| 210 | // fPointingPos->GetTheta() --> fMcEvt->SetTelescopeTheta()
|
|---|
| 211 | // fPointingPos->GetPhi() --> fMcEvt->SetTelescopePhi()
|
|---|
| 212 | // fStats->GetTimeFirst() --> fMcEvt->SetTimeFirst()
|
|---|
| 213 | // fStats->GetTimeLast() --> fMcEvt->SetTimeLast()
|
|---|
| 214 | // fMcEvt->SetReuse()
|
|---|
| 215 | // MMcCorsikaRunHeader: fSlopeSpec, fELowLim, fEUppLim;
|
|---|
| 216 |
|
|---|
| 217 | fMcEvt->Fill(*fCorsikaHeader, *fPointingPos, *fStats);
|
|---|
| 218 |
|
|---|
| 219 | return kTRUE;
|
|---|
| 220 | }
|
|---|
| 221 | */
|
|---|
| 222 |
|
|---|