FParametricOpticalEfficiencyLossManager.cc
Go to the documentation of this file.
1 #include <string>
2 #include <sstream>
3 #include <set>
4 #include <map>
5 
6 #include <boost/lexical_cast.hpp>
7 
8 #include <fdet/FParametricOpticalEfficiencyLossManager.h>
9 #include <fwk/CentralConfig.h>
10 #include <det/Detector.h>
11 
12 #include <utl/ErrorLogger.h>
13 #include <utl/TimeStamp.h>
14 #include <utl/UTCDateTime.h>
15 #include <utl/Reader.h>
16 #include <utl/TabulatedFunction.h>
17 #include <utl/AugerException.h>
18 #include <utl/ShadowPtr.h>
19 
20 #include <fdet/FManagerRegister.h>
21 #include <fdet/FDetector.h>
22 #include <fdet/Telescope.h>
23 
24 using namespace std;
25 using namespace fdet;
26 using namespace utl;
27 using namespace det;
28 using namespace fwk;
29 
30 
31 REGISTER_F_MANAGER("FParametricOpticalEfficiencyLossManager", FParametricOpticalEfficiencyLossManager);
32 
33 
34 void
35 FParametricOpticalEfficiencyLossManager::Init(const std::string& configLink)
36 {
37  fHasDefaultOpticalEfficiencyCorrection = false;
38  VManager::Init(configLink);
39  Initialize();
40  ostringstream info;
41  if (fHasDefaultOpticalEfficiencyCorrection)
42  info << "fixed optical efficiency correction is " << fOpticalEfficiencyCorrection;
43  else
44  info << " no default fixed optical efficiency correction";
45 
46  if (!fPerTelescopeOpticalEfficiencyCorrections.empty()) {
47  for (map<int, map<int, vector<double> > >::const_iterator eyeIt = fPerTelescopeOpticalEfficiencyCorrections.begin(),
48  eyeEnd = fPerTelescopeOpticalEfficiencyCorrections.end(); eyeIt != eyeEnd; ++eyeIt) {
49 
50  for (map<int, vector<double> >::const_iterator telIt = eyeIt->second.begin(),
51  telEnd = eyeIt->second.end(); telIt != telEnd; ++telIt) {
52 
53  info << "\n Override eye " << eyeIt->first << " tel " << telIt->first
54  << ": \n epochs :";
55  for (vector<unsigned int>::const_iterator epochIt = fPerTelescopeOpticalEfficiencyEpochs[eyeIt->first][telIt->first].begin(),
56  epochEnd = fPerTelescopeOpticalEfficiencyEpochs[eyeIt->first][telIt->first].end(); epochIt != epochEnd; ++epochIt) {
57  info << " " << *epochIt;
58  }
59  info << "\n corrections :";
60  for (vector<double>::const_iterator corrIt = telIt->second.begin(),
61  corrEnd = telIt->second.end(); corrIt != corrEnd; ++corrIt) {
62  info << " " << *corrIt;
63  }
64 
65  } // end for tels
66  } // end for eyes
67  } // end if have per-tel optical efficiency correction
68 
69  INFO(info);
70 }
71 
72 
73 void
74 FParametricOpticalEfficiencyLossManager::Initialize()
75 {
76  Branch defaultOpticalEffBranch = fBranch.GetChild("fixedOpticalEfficiencyCorrection");
77  if (defaultOpticalEffBranch) {
78  defaultOpticalEffBranch.GetData(fOpticalEfficiencyCorrection);
79  fHasDefaultOpticalEfficiencyCorrection = true;
80  } else
81  fHasDefaultOpticalEfficiencyCorrection = false;
82 
83  const Branch& perTel = fBranch.GetChild("perTelescope");
84  if (perTel) {
85 
86  Branch opticalEffBranch = perTel.GetFirstChild();
87  while (opticalEffBranch) {
88 
89  const AttributeMap& attrs = opticalEffBranch.GetAttributes();
90  AttributeMap::const_iterator attrEnd = attrs.end();
91  AttributeMap::const_iterator eyeIdIt = attrs.find("eyeId");
92  AttributeMap::const_iterator telIdIt = attrs.find("telId");
93  if (eyeIdIt == attrEnd || telIdIt == attrEnd) {
94  ERROR("telescopeOpticalEfficiencyCorrection tag is missing eyeId or telId attributes!");
95  break;
96  }
97  const int eyeId = boost::lexical_cast<int>(eyeIdIt->second);
98  const int telId = boost::lexical_cast<int>(telIdIt->second);
99 
100  vector<unsigned int> epochs;
101  vector<double> corrections;
102  opticalEffBranch.GetChild("opticalEfficiencyEpochs").GetData(epochs);
103  opticalEffBranch.GetChild("opticalEfficiencyCorrections").GetData(corrections);
104  fPerTelescopeOpticalEfficiencyEpochs[eyeId][telId] = epochs;
105  fPerTelescopeOpticalEfficiencyCorrections[eyeId][telId] = corrections;
106 
107  opticalEffBranch = opticalEffBranch.GetNextSibling();
108 
109  }
110 
111  } // end have optical eff correction per-tel
112 
113  // list of properties
114  //fAvailableComponents.insert("pixel_t_offset");
115  fAvailableComponents.insert("pixel_optical_efficiency_corrections");
116  fAvailableComponents.insert("status");
117  fAvailableComponents.insert("start_time");
118  fAvailableComponents.insert("end_time");
119 }
120 
121 
123 FParametricOpticalEfficiencyLossManager::GetData(double& /*returnData*/,
124  const string& /*componentProperty*/,
125  const string& /*componentName*/,
126  const IndexMap& )
127  const
128 {
129  // this manager only knows about fd_optical_efficiency
130  /*if (componentName != "fd_optical_efficiency")
131  return eNotFound;
132 
133  // check property availability
134  if (fAvailableComponents.find(componentProperty) == fAvailableComponents.end())
135  return eNotFound;
136  */
137  return eNotFound;
138 }
139 
140 
142 FParametricOpticalEfficiencyLossManager::GetData(map<int, utl::TabulatedFunction>& returnData,
143  const string& componentProperty,
144  const string& componentName,
145  const IndexMap& componentIndex)
146  const
147 {
148  // this manager only knows about fd_optical_efficiency
149  if (componentName != "fd_optical_efficiency")
150  return eNotFound;
151 
152  // check property availability
153  if (fAvailableComponents.find(componentProperty) == fAvailableComponents.end())
154  return eNotFound;
155 
156  returnData.clear();
157 
158  if (componentProperty == "pixel_optical_efficiency_corrections") {
159  const fdet::FDetector& fdet = det::Detector::GetInstance().GetFDetector();
160  const double wavelength = fdet.GetReferenceLambda();
161 
162  const string& eyeIdString = componentIndex.find("eyeId")->second;
163  const string& telescopeIdString = componentIndex.find("telescopeId")->second;
164  const int eyeId = boost::lexical_cast<int>(eyeIdString);
165  const int telId = boost::lexical_cast<int>(telescopeIdString);
166 
167  double opticalEff = 0;
168  if (GetOpticalEfficiencyCorrectionForTelescope(eyeId, telId, opticalEff)) {
169 
170  for (int iPix = 1; iPix <= 440; ++iPix) {
171  TabulatedFunction effVsWavelength;
172  effVsWavelength.PushBack(wavelength, opticalEff);
173  returnData.insert(make_pair(iPix, effVsWavelength));
174  }
175 
176  return eFound;
177  }
178  }
179 
180  return eNotFound;
181 }
182 
183 
184 bool
185 FParametricOpticalEfficiencyLossManager::GetOpticalEfficiencyCorrectionForTelescope(const unsigned int eyeId,
186  const unsigned int telId,
187  double& value)
188  const
189 {
190  map<int, map<int, vector<double> > >::const_iterator eyeIt = fPerTelescopeOpticalEfficiencyCorrections.find(eyeId);
191  if (eyeIt == fPerTelescopeOpticalEfficiencyCorrections.end()) {
192  if (fHasDefaultOpticalEfficiencyCorrection) {
193  value = fOpticalEfficiencyCorrection;
194  return true;
195  } else
196  return false;
197  }
198 
199  map<int, vector<double> >::const_iterator telIt = eyeIt->second.find(telId);
200  if (telIt == eyeIt->second.end()) {
201  if (fHasDefaultOpticalEfficiencyCorrection) {
202  value = fOpticalEfficiencyCorrection;
203  return true;
204  } else
205  return false;
206  }
207 
208  map<int, map<int, vector<unsigned int> > >::const_iterator eyeEpochIt = fPerTelescopeOpticalEfficiencyEpochs.find(eyeId);
209  map<int, vector<unsigned int> >::const_iterator telEpochIt = eyeEpochIt->second.find(telId);
210 
211  const TimeStamp detTime = Detector::GetInstance().GetTime();
212  const unsigned int gpsSecond = detTime.GetGPSSecond();
213  int thisBin = -1;
214  //for (unsigned int i = 0; i < fPerTelescopeOpticalEfficiencyEpochs[eyeId][telId].size(); ++i) {
215  for (unsigned int i = 0; i < telEpochIt->second.size(); ++i) {
216  //if (fPerTelescopeOpticalEfficiencyEpochs[eyeId][telId][i] > gpsSecond) {
217  if (telEpochIt->second[i] > gpsSecond) {
218  thisBin = i - 1;
219  break;
220  }
221  }
222 
223  //int lastBin = fPerTelescopeOpticalEfficiencyEpochs[eyeId][telId].size() - 2;
224  int lastBin = telEpochIt->second.size() - 2;
225 
226  std::vector<double> p;
227  if (thisBin == -1) {
228  for (unsigned int i = 0; i < 3; ++i)
229  //p.push_back(fPerTelescopeOpticalEfficiencyCorrections[eyeId][telId][3*lastBin + i]);
230  p.push_back(telIt->second[3*lastBin + i]);
231  } else {
232  for (unsigned int i = 0; i < 3; ++i)
233  //p.push_back(fPerTelescopeOpticalEfficiencyCorrections[eyeId][telId][3*thisBin + i]);
234  p.push_back(telIt->second[3*thisBin + i]);
235  }
236 
237  /*
238  cout <<"thisBin: " << thisBin <<"\n";
239  cout << "gpsSecond " << gpsSecond << "\n";
240  cout << p[0] << " " << p[1] << " " << p[2] <<"\n";
241  */
242  //unsigned int lastEpoch = fPerTelescopeOpticalEfficiencyEpochs[eyeId][telId][lastBin+1];
243  unsigned int lastEpoch = telEpochIt->second[lastBin+1];
244  int x;
245 
246  if (thisBin > -1) // means that gpsSecond is within Epoch range
247  x = gpsSecond - 1016048411;
248  else // means that gpsSecond is greater than Epoch range
249  x = lastEpoch - 1016048411;
250 
251  const double cali =
252  p[0] + p[1] * x + p[2] * pow(x, 2);
253 
254  value = cali;
255 
256  return true;
257 }
258 
259 
261 FParametricOpticalEfficiencyLossManager::GetData(vector<int>& returnData,
262  const string& componentProperty,
263  const string& componentName,
264  const IndexMap& /*componentIndex*/)
265  const
266 {
267  if (componentProperty != "status" || componentName != "fd_optical_efficiency")
268  return eNotFound;
269  returnData.clear();
270  returnData.resize(441, 0); // eGood
271  return eFound;
272 }
273 
274 
276 FParametricOpticalEfficiencyLossManager::GetData(int& returnData,
277  const string& componentProperty,
278  const string& componentName,
279  const IndexMap&)
280  const
281 {
282  // this manager only knows about fd_optical_efficiency
283  if (componentName != "fd_optical_efficiency")
284  return eNotFound;
285 
286  // check property availability
287  if (fAvailableComponents.find(componentProperty) == fAvailableComponents.end())
288  return eNotFound;
289 
290  // parametric optical efficiency loss correction is valid only for the given time
291  const TimeStamp detTime = Detector::GetInstance().GetTime();
292  const unsigned int gpsSecond = detTime.GetGPSSecond();
293 
294  if (componentProperty == "start_time") {
295  returnData = gpsSecond-1;
296  return eFound;
297  }
298 
299  if (componentProperty == "end_time") {
300  // +1 as a margin
301  returnData = gpsSecond+1;
302  return eFound;
303  }
304 
305  return eNotFound;
306 }
Class to hold collection (x,y) points and provide interpolation between them.
std::map< std::string, std::string > AttributeMap
Definition: Branch.h:24
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
void PushBack(const double x, const double y)
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
double pow(const double x, const unsigned int i)
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
AttributeMap GetAttributes() const
Get a map&lt;string, string&gt; containing all the attributes of this Branch.
Definition: Branch.cc:267
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
Class representing a document branch.
Definition: Branch.h:107
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
double GetReferenceLambda() const
Definition: FDetector.cc:332
unsigned long GetGPSSecond() const
GPS second.
Definition: TimeStamp.h:124
#define REGISTER_F_MANAGER(_name_, _Type_)
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.