| 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 | // MSimAbsorption
|
|---|
| 28 | //
|
|---|
| 29 | // Task to calculate wavelength or incident angle dependent absorption
|
|---|
| 30 | //
|
|---|
| 31 | // Input Containers:
|
|---|
| 32 | // fParName [MParSpline]
|
|---|
| 33 | // MPhotonEvent
|
|---|
| 34 | // MCorsikaEvtHeader
|
|---|
| 35 | // MCorsikaRunHeader
|
|---|
| 36 | //
|
|---|
| 37 | // Output Containers:
|
|---|
| 38 | // MPhotonEvent
|
|---|
| 39 | //
|
|---|
| 40 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 41 | #include "MSimAbsorption.h"
|
|---|
| 42 |
|
|---|
| 43 | #include <fstream>
|
|---|
| 44 |
|
|---|
| 45 | #include <TRandom.h>
|
|---|
| 46 |
|
|---|
| 47 | #include "MLog.h"
|
|---|
| 48 | #include "MLogManip.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "MParList.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "MParSpline.h"
|
|---|
| 53 |
|
|---|
| 54 | #include "MCorsikaEvtHeader.h"
|
|---|
| 55 | #include "MCorsikaRunHeader.h"
|
|---|
| 56 | #include "MPhotonEvent.h"
|
|---|
| 57 | #include "MPhotonData.h"
|
|---|
| 58 |
|
|---|
| 59 | ClassImp(MSimAbsorption);
|
|---|
| 60 |
|
|---|
| 61 | using namespace std;
|
|---|
| 62 |
|
|---|
| 63 | // --------------------------------------------------------------------------
|
|---|
| 64 | //
|
|---|
| 65 | // Default Constructor.
|
|---|
| 66 | //
|
|---|
| 67 | MSimAbsorption::MSimAbsorption(const char* name, const char *title)
|
|---|
| 68 | : fEvt(0), fHeader(0), fSpline(0), fParName("MParSpline"), fUseTheta(kFALSE)
|
|---|
| 69 | {
|
|---|
| 70 | fName = name ? name : "MSimAbsorption";
|
|---|
| 71 | fTitle = title ? title : "Task to calculate wavelength dependent absorption";
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | // --------------------------------------------------------------------------
|
|---|
| 75 | //
|
|---|
| 76 | // Search for the needed parameter containers. Read spline from file
|
|---|
| 77 | // calling ReadFile();
|
|---|
| 78 | //
|
|---|
| 79 | Int_t MSimAbsorption::PreProcess(MParList *pList)
|
|---|
| 80 | {
|
|---|
| 81 | fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
|
|---|
| 82 | if (!fEvt)
|
|---|
| 83 | {
|
|---|
| 84 | *fLog << err << "MPhotonEvent not found... aborting." << endl;
|
|---|
| 85 | return kFALSE;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | fSpline = (MParSpline*)pList->FindObject(fParName, "MParSpline");
|
|---|
| 89 | if (!fSpline)
|
|---|
| 90 | {
|
|---|
| 91 | *fLog << err << fParName << " [MParSpline] not found... aborting." << endl;
|
|---|
| 92 | return kFALSE;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | if (!fSpline->IsValid())
|
|---|
| 96 | {
|
|---|
| 97 | *fLog << err << "Spline in " << fParName << " is inavlid... aborting." << endl;
|
|---|
| 98 | return kFALSE;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | fHeader = (MCorsikaEvtHeader*)pList->FindObject("MCorsikaEvtHeader");
|
|---|
| 102 | if (!fHeader)
|
|---|
| 103 | {
|
|---|
| 104 | *fLog << err << "MCorsikaEvtHeader not found... aborting." << endl;
|
|---|
| 105 | return kFALSE;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | *fLog << inf << "Using " << (fUseTheta?"Theta":"Wavelength") << " for absorption." << endl;
|
|---|
| 109 |
|
|---|
| 110 | return kTRUE;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | // --------------------------------------------------------------------------
|
|---|
| 114 | //
|
|---|
| 115 | Bool_t MSimAbsorption::ReInit(MParList *pList)
|
|---|
| 116 | {
|
|---|
| 117 | if (fUseTheta)
|
|---|
| 118 | return kTRUE;
|
|---|
| 119 |
|
|---|
| 120 | MCorsikaRunHeader *h = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
|
|---|
| 121 | if (!h)
|
|---|
| 122 | {
|
|---|
| 123 | *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
|
|---|
| 124 | return kFALSE;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | if (h->GetWavelengthMin()<fSpline->GetXmin())
|
|---|
| 128 | *fLog << warn << "WARNING - Lower bound of wavelength bandwidth exceeds lower bound of spline." << endl;
|
|---|
| 129 |
|
|---|
| 130 | if (h->GetWavelengthMax()>fSpline->GetXmax())
|
|---|
| 131 | *fLog << warn << "WARNING - Upper bound of wavelength bandwidth exceeds upper bound of spline." << endl;
|
|---|
| 132 |
|
|---|
| 133 | return kTRUE;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | // --------------------------------------------------------------------------
|
|---|
| 137 | //
|
|---|
| 138 | // Throw all events out of the MPhotonEvent which don't survive.
|
|---|
| 139 | // Depending on fUseTheta either the wavelength or the incident angle
|
|---|
| 140 | // is used.
|
|---|
| 141 | //
|
|---|
| 142 | Int_t MSimAbsorption::Process()
|
|---|
| 143 | {
|
|---|
| 144 | // Get the number of photons in the list
|
|---|
| 145 | const Int_t num = fEvt->GetNumPhotons();
|
|---|
| 146 |
|
|---|
| 147 | // Counter for number of total and final events
|
|---|
| 148 | Int_t cnt = 0;
|
|---|
| 149 | for (Int_t i=0; i<num; i++)
|
|---|
| 150 | {
|
|---|
| 151 | // Get i-th photon from the list
|
|---|
| 152 | const MPhotonData &ph = (*fEvt)[i];
|
|---|
| 153 |
|
|---|
| 154 | // Depending on fUseTheta get the incident angle of the wavelength
|
|---|
| 155 | const Double_t wl = fUseTheta ? ph.GetTheta()*TMath::RadToDeg() : ph.GetWavelength();
|
|---|
| 156 |
|
|---|
| 157 | // Get the efficiency (the probability that this photon will survive)
|
|---|
| 158 | // from the spline.
|
|---|
| 159 | const Double_t eff = fSpline->Eval(wl);
|
|---|
| 160 |
|
|---|
| 161 | // Get a random value between 0 and 1 to determine whether the photn will survive
|
|---|
| 162 | // gRandom->Rndm() = [0;1[
|
|---|
| 163 | if (gRandom->Rndm()>=eff)
|
|---|
| 164 | continue;
|
|---|
| 165 |
|
|---|
| 166 | // Copy the surviving events bakc in the list
|
|---|
| 167 | (*fEvt)[cnt++] = ph;
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | // Now we shrink the array to the number of new entries.
|
|---|
| 171 | fEvt->Shrink(cnt);
|
|---|
| 172 |
|
|---|
| 173 | return kTRUE;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | // --------------------------------------------------------------------------
|
|---|
| 177 | //
|
|---|
| 178 | // FileName: reflectivity.txt
|
|---|
| 179 | // UseTheta: No
|
|---|
| 180 | //
|
|---|
| 181 | Int_t MSimAbsorption::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
|---|
| 182 | {
|
|---|
| 183 | Bool_t rc = kFALSE;
|
|---|
| 184 | if (IsEnvDefined(env, prefix, "ParName", print))
|
|---|
| 185 | {
|
|---|
| 186 | rc = kTRUE;
|
|---|
| 187 | SetParName(GetEnvValue(env, prefix, "ParName", fParName));
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | if (IsEnvDefined(env, prefix, "UseTheta", print))
|
|---|
| 191 | {
|
|---|
| 192 | rc = kTRUE;
|
|---|
| 193 | SetUseTheta(GetEnvValue(env, prefix, "UseTheta", fUseTheta));
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | return rc;
|
|---|
| 197 | }
|
|---|