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), fRunHeader(0), fHeader(0), fSpline(0), fParName("MParSpline"), fUseTheta(kFALSE), fForce(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 | fRunHeader = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
|
---|
121 | if (!fRunHeader)
|
---|
122 | {
|
---|
123 | *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
|
---|
124 | return kFALSE;
|
---|
125 | }
|
---|
126 |
|
---|
127 | if (fRunHeader->Has(MCorsikaRunHeader::kCeffic) && !fForce)
|
---|
128 | *fLog << inf << "CEFFIC enabled... task will be skipped." << endl;
|
---|
129 |
|
---|
130 | if (fRunHeader->GetWavelengthMin()<fSpline->GetXmin())
|
---|
131 | *fLog << warn << "WARNING - Lower bound of wavelength bandwidth exceeds lower bound of spline." << endl;
|
---|
132 |
|
---|
133 | if (fRunHeader->GetWavelengthMax()>fSpline->GetXmax())
|
---|
134 | *fLog << warn << "WARNING - Upper bound of wavelength bandwidth exceeds upper bound of spline." << endl;
|
---|
135 |
|
---|
136 | return kTRUE;
|
---|
137 | }
|
---|
138 |
|
---|
139 | // --------------------------------------------------------------------------
|
---|
140 | //
|
---|
141 | // Throw all events out of the MPhotonEvent which don't survive.
|
---|
142 | // Depending on fUseTheta either the wavelength or the incident angle
|
---|
143 | // is used.
|
---|
144 | //
|
---|
145 | Int_t MSimAbsorption::Process()
|
---|
146 | {
|
---|
147 | // Skip the task if the CEFFIC option has been enabled and
|
---|
148 | // its excution has not been forced by the user
|
---|
149 | if (!fForce && !fUseTheta && fRunHeader->Has(MCorsikaRunHeader::kCeffic))
|
---|
150 | return kTRUE;
|
---|
151 |
|
---|
152 | // Get the number of photons in the list
|
---|
153 | const Int_t num = fEvt->GetNumPhotons();
|
---|
154 |
|
---|
155 | // Counter for number of total and final events
|
---|
156 | Int_t cnt = 0;
|
---|
157 | for (Int_t i=0; i<num; i++)
|
---|
158 | {
|
---|
159 | // Get i-th photon from the list
|
---|
160 | const MPhotonData &ph = (*fEvt)[i];
|
---|
161 |
|
---|
162 | // Depending on fUseTheta get the incident angle of the wavelength
|
---|
163 | const Double_t wl = fUseTheta ? ph.GetTheta()*TMath::RadToDeg() : ph.GetWavelength();
|
---|
164 |
|
---|
165 | // Get the efficiency (the probability that this photon will survive)
|
---|
166 | // from the spline.
|
---|
167 | const Double_t eff = fSpline->Eval(wl);
|
---|
168 |
|
---|
169 | // Get a random value between 0 and 1 to determine whether the photn will survive
|
---|
170 | // gRandom->Rndm() = [0;1[
|
---|
171 | if (gRandom->Rndm()>=eff)
|
---|
172 | continue;
|
---|
173 |
|
---|
174 | // Copy the surviving events bakc in the list
|
---|
175 | (*fEvt)[cnt++] = ph;
|
---|
176 | }
|
---|
177 |
|
---|
178 | // Now we shrink the array to the number of new entries.
|
---|
179 | fEvt->Shrink(cnt);
|
---|
180 |
|
---|
181 | return kTRUE;
|
---|
182 | }
|
---|
183 |
|
---|
184 | // --------------------------------------------------------------------------
|
---|
185 | //
|
---|
186 | // FileName: reflectivity.txt
|
---|
187 | // UseTheta: No
|
---|
188 | //
|
---|
189 | Int_t MSimAbsorption::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
190 | {
|
---|
191 | Bool_t rc = kFALSE;
|
---|
192 | if (IsEnvDefined(env, prefix, "ParName", print))
|
---|
193 | {
|
---|
194 | rc = kTRUE;
|
---|
195 | SetParName(GetEnvValue(env, prefix, "ParName", fParName));
|
---|
196 | }
|
---|
197 |
|
---|
198 | if (IsEnvDefined(env, prefix, "UseTheta", print))
|
---|
199 | {
|
---|
200 | rc = kTRUE;
|
---|
201 | SetUseTheta(GetEnvValue(env, prefix, "UseTheta", fUseTheta));
|
---|
202 | }
|
---|
203 |
|
---|
204 | if (IsEnvDefined(env, prefix, "Force", print))
|
---|
205 | {
|
---|
206 | rc = kTRUE;
|
---|
207 | SetForce(GetEnvValue(env, prefix, "Force", fForce));
|
---|
208 | }
|
---|
209 |
|
---|
210 | return rc;
|
---|
211 | }
|
---|