| 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 | // MSimAPD
|
|---|
| 28 | //
|
|---|
| 29 | // This tasks simulates the individual APDs. Before starting the APD is
|
|---|
| 30 | // initialized randomly according to the photon rate hitting the APD. Such
|
|---|
| 31 | // it is assumed that the initial condition of the APD is similar to the real
|
|---|
| 32 | // one. In this context it is assumed that the events are independent, so
|
|---|
| 33 | // that the APD is always in the same condition.
|
|---|
| 34 | //
|
|---|
| 35 | // For every photon and event the behaviour of the APD is simulated. The
|
|---|
| 36 | // output is set as weight to the MPhotonData containers.
|
|---|
| 37 | //
|
|---|
| 38 | // Remark:
|
|---|
| 39 | // - The photons MUST be sorted increasing in time.
|
|---|
| 40 | // - The photon rate used to initialize the APD must match the one used
|
|---|
| 41 | // to "fill" the random photons. (FIXME: This should be stored somewhere)
|
|---|
| 42 | //
|
|---|
| 43 | // Input Containers:
|
|---|
| 44 | // fNameGeomCam [MGeomCam]
|
|---|
| 45 | // MPhotonEvent
|
|---|
| 46 | // MPhotonStatistics
|
|---|
| 47 | //
|
|---|
| 48 | // Output Containers:
|
|---|
| 49 | // MPhotonEvent
|
|---|
| 50 | //
|
|---|
| 51 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 52 | #include "MSimAPD.h"
|
|---|
| 53 |
|
|---|
| 54 | #include <TH2.h>
|
|---|
| 55 | #include <TRandom.h>
|
|---|
| 56 |
|
|---|
| 57 | #include "MLog.h"
|
|---|
| 58 | #include "MLogManip.h"
|
|---|
| 59 |
|
|---|
| 60 | #include "MMath.h"
|
|---|
| 61 | #include "MParList.h"
|
|---|
| 62 |
|
|---|
| 63 | #include "MGeomCam.h"
|
|---|
| 64 |
|
|---|
| 65 | #include "MPhotonEvent.h"
|
|---|
| 66 | #include "MPhotonData.h"
|
|---|
| 67 |
|
|---|
| 68 | #include "MAvalanchePhotoDiode.h"
|
|---|
| 69 |
|
|---|
| 70 | ClassImp(MSimAPD);
|
|---|
| 71 |
|
|---|
| 72 | using namespace std;
|
|---|
| 73 |
|
|---|
| 74 | // --------------------------------------------------------------------------
|
|---|
| 75 | //
|
|---|
| 76 | // Default Constructor.
|
|---|
| 77 | //
|
|---|
| 78 | MSimAPD::MSimAPD(const char* name, const char *title)
|
|---|
| 79 | : fGeom(0), fEvt(0), fStat(0), fType(1)
|
|---|
| 80 | {
|
|---|
| 81 | fName = name ? name : "MSimAPD";
|
|---|
| 82 | fTitle = title ? title : " Task to simulate the detection behaviour of APDs";
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | // --------------------------------------------------------------------------
|
|---|
| 86 | //
|
|---|
| 87 | // Get the necessary parameter containers
|
|---|
| 88 | //
|
|---|
| 89 | Int_t MSimAPD::PreProcess(MParList *pList)
|
|---|
| 90 | {
|
|---|
| 91 | if (fNameGeomCam.IsNull())
|
|---|
| 92 | {
|
|---|
| 93 | *fLog << inf << "No geometry container... skipping." << endl;
|
|---|
| 94 | return kSKIP;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | fGeom = (MGeomCam*)pList->FindObject(fNameGeomCam, "MGeomCam");
|
|---|
| 98 | if (!fGeom)
|
|---|
| 99 | {
|
|---|
| 100 | *fLog << inf << fNameGeomCam << " [MGeomCam] not found..." << endl;
|
|---|
| 101 |
|
|---|
| 102 | fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
|
|---|
| 103 | if (!fGeom)
|
|---|
| 104 | {
|
|---|
| 105 | *fLog << err << "MGeomCam not found... aborting." << endl;
|
|---|
| 106 | return kFALSE;
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | fStat = (MPhotonStatistics*)pList->FindObject("MPhotonStatistics");
|
|---|
| 111 | if (!fStat)
|
|---|
| 112 | {
|
|---|
| 113 | *fLog << err << "MPhotonStatistics not found... aborting." << endl;
|
|---|
| 114 | return kFALSE;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
|
|---|
| 118 | if (!fEvt)
|
|---|
| 119 | {
|
|---|
| 120 | *fLog << err << "MPhotonEvent not found... aborting." << endl;
|
|---|
| 121 | return kFALSE;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | return kTRUE;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | // --------------------------------------------------------------------------
|
|---|
| 128 | //
|
|---|
| 129 | // Initialize as many APDs as we have pixels in the fGeomCam
|
|---|
| 130 | //
|
|---|
| 131 | Bool_t MSimAPD::ReInit(MParList *plist)
|
|---|
| 132 | {
|
|---|
| 133 | if (UInt_t(fAPDs.GetEntriesFast())==fGeom->GetNumPixels())
|
|---|
| 134 | return kTRUE;
|
|---|
| 135 |
|
|---|
| 136 | fAPDs.Delete();
|
|---|
| 137 |
|
|---|
| 138 | // FIXME:
|
|---|
| 139 | // * initialize an empty APD and read the APD setup from a file to
|
|---|
| 140 | // allow different APDs.
|
|---|
| 141 | // * Make the arguments a data member of MSimAPD
|
|---|
| 142 |
|
|---|
| 143 | Int_t ncells = 0;
|
|---|
| 144 | Float_t crosstalk = 0;
|
|---|
| 145 | Float_t deadtime = 0;
|
|---|
| 146 | Float_t recovery = 0;
|
|---|
| 147 |
|
|---|
| 148 | switch (fType)
|
|---|
| 149 | {
|
|---|
| 150 | case 1:
|
|---|
| 151 | ncells = 30;
|
|---|
| 152 | crosstalk = 0.2;
|
|---|
| 153 | deadtime = 3;
|
|---|
| 154 | recovery = 8.75*4;
|
|---|
| 155 | break;
|
|---|
| 156 |
|
|---|
| 157 | case 2:
|
|---|
| 158 | ncells = 60;
|
|---|
| 159 | crosstalk = 0.2;
|
|---|
| 160 | deadtime = 3;
|
|---|
| 161 | recovery = 8.75;
|
|---|
| 162 | break;
|
|---|
| 163 |
|
|---|
| 164 | default:
|
|---|
| 165 | *fLog << err << "ERROR - APD type " << fType << " undefined." << endl;
|
|---|
| 166 | return kFALSE;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | for (UInt_t i=0; i<fGeom->GetNumPixels(); i++)
|
|---|
| 170 | fAPDs.Add(new APD(ncells, crosstalk, deadtime, recovery));
|
|---|
| 171 |
|
|---|
| 172 | return kTRUE;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | // --------------------------------------------------------------------------
|
|---|
| 176 | //
|
|---|
| 177 | // Process all photons through the corresponding APD and set the output
|
|---|
| 178 | // (weight) accordingly.
|
|---|
| 179 | //
|
|---|
| 180 | Int_t MSimAPD::Process()
|
|---|
| 181 | {
|
|---|
| 182 | //const Double_t rate = 40e9;
|
|---|
| 183 | // FIXME: Where do we get this number from??
|
|---|
| 184 | // const Double_t rate = 0.04;
|
|---|
| 185 |
|
|---|
| 186 | // Make all APDs look neutral for the first hit by a photon according to the
|
|---|
| 187 | // average hit rate
|
|---|
| 188 | const UInt_t npix = fAPDs.GetEntriesFast();
|
|---|
| 189 |
|
|---|
| 190 | // Check if we can safely proceed (this can fail if we either haven't been
|
|---|
| 191 | // ReInit'ed or the max index in MPhotonStatistics is wrong)
|
|---|
| 192 | if ((Int_t)npix<fStat->GetMaxIndex())
|
|---|
| 193 | {
|
|---|
| 194 | *fLog << err << "ERROR - MSimAPD::Process: Only " << npix << " APDs initialized. At least " << fStat->GetMaxIndex() << " needed... abort." << endl;
|
|---|
| 195 | return kERROR;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | for (UInt_t idx=0; idx<npix; idx++)
|
|---|
| 199 | static_cast<APD*>(fAPDs.UncheckedAt(idx))->FillRandom(fFreq, fStat->GetTimeFirst());
|
|---|
| 200 |
|
|---|
| 201 | // Get number of photons
|
|---|
| 202 | const Int_t num = fEvt->GetNumPhotons();
|
|---|
| 203 |
|
|---|
| 204 | // Loop over all photons
|
|---|
| 205 | for (Int_t i=0; i<num; i++)
|
|---|
| 206 | {
|
|---|
| 207 | // Get i-th photon
|
|---|
| 208 | MPhotonData &ph = (*fEvt)[i];
|
|---|
| 209 |
|
|---|
| 210 | // Get arrival time of photon and idx
|
|---|
| 211 | const Double_t t = ph.GetTime();
|
|---|
| 212 | const Int_t idx = ph.GetTag();
|
|---|
| 213 | if (idx<0)
|
|---|
| 214 | {
|
|---|
| 215 | *fLog << err << "ERROR - MSimAPD: Invalid index -1." << endl;
|
|---|
| 216 | return kERROR;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | if (ph.GetWeight()!=1)
|
|---|
| 220 | {
|
|---|
| 221 | *fLog << err << "ERROR - MSimAPD: Weight of " << i << "-th photon not 1, but " << ph.GetWeight() << endl;
|
|---|
| 222 | ph.Print();
|
|---|
| 223 | return kERROR;
|
|---|
| 224 | }
|
|---|
| 225 | // Simulate hitting the APD (the signal height in effective
|
|---|
| 226 | // "number of photons" is returned)
|
|---|
| 227 | const Double_t hits = static_cast<APD*>(fAPDs.UncheckedAt(idx))->HitRandomCell(t);
|
|---|
| 228 |
|
|---|
| 229 | // FIXME: Make a proper simulation of the excess noise!!!
|
|---|
| 230 | //const Double_t signal = gRandom->Gaus(hits, 0.2*TMath::Sqrt(hits));
|
|---|
| 231 |
|
|---|
| 232 | // Set the weight to the input
|
|---|
| 233 | ph.SetWeight(hits);
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | return kTRUE;
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | // --------------------------------------------------------------------------
|
|---|
| 240 | //
|
|---|
| 241 | // NameGeomCam
|
|---|
| 242 | // Type: 1
|
|---|
| 243 | //
|
|---|
| 244 | Int_t MSimAPD::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
|---|
| 245 | {
|
|---|
| 246 | Bool_t rc = kFALSE;
|
|---|
| 247 | if (IsEnvDefined(env, prefix, "NameGeomCam", print))
|
|---|
| 248 | {
|
|---|
| 249 | rc = kTRUE;
|
|---|
| 250 | fNameGeomCam = GetEnvValue(env, prefix, "NameGeomCam", fNameGeomCam);
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | if (IsEnvDefined(env, prefix, "Type", print))
|
|---|
| 254 | {
|
|---|
| 255 | rc = kTRUE;
|
|---|
| 256 | fType = GetEnvValue(env, prefix, "Type", fType);
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | return rc;
|
|---|
| 260 | }
|
|---|