FFixOpticalEfficiencyLossManager.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/FFixOpticalEfficiencyLossManager.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("FFixOpticalEfficiencyLossManager", FFixOpticalEfficiencyLossManager);
32 
33 
34 void
35 FFixOpticalEfficiencyLossManager::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 (!fPerTelescopeOpticalEfficiencyCorrection.empty()) {
47  for (map<int, map<int, double> >::const_iterator eyeIt = fPerTelescopeOpticalEfficiencyCorrection.begin(),
48  eyeEnd = fPerTelescopeOpticalEfficiencyCorrection.end(); eyeIt != eyeEnd; ++eyeIt) {
49 
50  for (map<int, 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  << ": " << telIt->second;
55 
56  } // end for tels
57  } // end for eyes
58  } // end if have per-tel optical efficiency correction
59  INFO(info);
60 }
61 
62 
63 void
64 FFixOpticalEfficiencyLossManager::Initialize()
65 {
66  Branch defaultOpticalEffBranch = fBranch.GetChild("fixedOpticalEfficiencyCorrection");
67  if (defaultOpticalEffBranch) {
68  defaultOpticalEffBranch.GetData(fOpticalEfficiencyCorrection);
69  fHasDefaultOpticalEfficiencyCorrection = true;
70  } else
71  fHasDefaultOpticalEfficiencyCorrection = false;
72 
73  const Branch& perTel = fBranch.GetChild("perTelescope");
74  if (perTel) {
75 
76  Branch opticalEffBranch = perTel.GetFirstChild();
77  while (opticalEffBranch) {
78  double opticalEff = 0;
79  opticalEffBranch.GetData(opticalEff);
80 
81  const AttributeMap& attrs = opticalEffBranch.GetAttributes();
82  AttributeMap::const_iterator attrEnd = attrs.end();
83  AttributeMap::const_iterator eyeIdIt = attrs.find("eyeId");
84  AttributeMap::const_iterator telIdIt = attrs.find("telId");
85  if (eyeIdIt == attrEnd || telIdIt == attrEnd) {
86  ERROR("telescopeOpticalEfficiencyCorrection tag is missing eyeId or telId attributes!");
87  break;
88  }
89  const int eyeId = boost::lexical_cast<int>(eyeIdIt->second);
90  const int telId = boost::lexical_cast<int>(telIdIt->second);
91  fPerTelescopeOpticalEfficiencyCorrection[eyeId][telId] = opticalEff;
92 
93  opticalEffBranch = opticalEffBranch.GetNextSibling();
94  }
95 
96  } // end have optical eff correction per-tel
97 
98  // list of properties
99  //fAvailableComponents.insert("pixel_t_offset");
100  fAvailableComponents.insert("pixel_optical_efficiency_corrections");
101  fAvailableComponents.insert("status");
102  fAvailableComponents.insert("start_time");
103  fAvailableComponents.insert("end_time");
104 }
105 
106 
108 FFixOpticalEfficiencyLossManager::GetData(double& /*returnData*/,
109  const string& /*componentProperty*/,
110  const string& /*componentName*/,
111  const IndexMap& )
112  const
113 {
114  // this manager only knows about fd_optical_efficiency
115  /*if (componentName != "fd_optical_efficiency")
116  return eNotFound;
117 
118  // check property availability
119  if (fAvailableComponents.find(componentProperty) == fAvailableComponents.end())
120  return eNotFound;
121  */
122  return eNotFound;
123 }
124 
125 
127 FFixOpticalEfficiencyLossManager::GetData(map<int, utl::TabulatedFunction>& returnData,
128  const string& componentProperty,
129  const string& componentName,
130  const IndexMap& componentIndex)
131  const
132 {
133  // this manager only knows about fd_optical_efficiency
134  if (componentName != "fd_optical_efficiency")
135  return eNotFound;
136 
137  // check property availability
138  if (fAvailableComponents.find(componentProperty) == fAvailableComponents.end())
139  return eNotFound;
140 
141  returnData.clear();
142 
143  if (componentProperty == "pixel_optical_efficiency_corrections") {
144  const fdet::FDetector& fdet = det::Detector::GetInstance().GetFDetector();
145  const double wavelength = fdet.GetReferenceLambda();
146 
147  const string& eyeIdString = componentIndex.find("eyeId")->second;
148  const string& telescopeIdString = componentIndex.find("telescopeId")->second;
149  const int eyeId = boost::lexical_cast<int>(eyeIdString);
150  const int telId = boost::lexical_cast<int>(telescopeIdString);
151 
152  double opticalEff = 0;
153  if (GetOpticalEfficiencyCorrectionForTelescope(eyeId, telId, opticalEff)) {
154 
155  for (int iPix = 1; iPix <= 440; ++iPix) {
156  TabulatedFunction effVsWavelength;
157  effVsWavelength.PushBack(wavelength, opticalEff);
158  returnData.insert(make_pair(iPix, effVsWavelength));
159  }
160 
161  return eFound;
162  }
163  }
164 
165  return eNotFound;
166 }
167 
168 
169 bool
170 FFixOpticalEfficiencyLossManager::GetOpticalEfficiencyCorrectionForTelescope(const unsigned int eyeId,
171  const unsigned int telId,
172  double& value)
173  const
174 {
175  map<int, map<int, double> >::const_iterator eyeIt = fPerTelescopeOpticalEfficiencyCorrection.find(eyeId);
176  if (eyeIt == fPerTelescopeOpticalEfficiencyCorrection.end()) {
177  if (fHasDefaultOpticalEfficiencyCorrection) {
178  value = fOpticalEfficiencyCorrection;
179  return true;
180  } else
181  return false;
182  }
183 
184  map<int, double>::const_iterator telIt = eyeIt->second.find(telId);
185  if (telIt == eyeIt->second.end()) {
186  if (fHasDefaultOpticalEfficiencyCorrection) {
187  value = fOpticalEfficiencyCorrection;
188  return true;
189  } else
190  return false;
191  }
192 
193  value = telIt->second;
194  return true;
195 }
196 
197 
199 FFixOpticalEfficiencyLossManager::GetData(vector<int>& returnData,
200  const string& componentProperty,
201  const string& componentName,
202  const IndexMap& /*componentIndex*/)
203  const
204 {
205  if (componentProperty != "status" || componentName != "fd_optical_efficiency")
206  return eNotFound;
207  returnData.clear();
208  returnData.resize(441, 0); // eGood
209  return eFound;
210 }
211 
212 
214 FFixOpticalEfficiencyLossManager::GetData(int& returnData,
215  const string& componentProperty,
216  const string& componentName,
217  const IndexMap&)
218  const
219 {
220  // this manager only knows about fd_optical_efficiency
221  if (componentName != "fd_optical_efficiency")
222  return eNotFound;
223 
224  // check property availability
225  if (fAvailableComponents.find(componentProperty) == fAvailableComponents.end())
226  return eNotFound;
227 
228  if (componentProperty == "start_time") {
229  // very early
230  returnData = UTCDateTime(2000, 1, 1).GetTimeStamp().GetGPSSecond();
231  return eFound;
232  }
233 
234  if (componentProperty == "end_time") {
235  // very late
236  returnData = UTCDateTime(2037, 11, 30).GetTimeStamp().GetGPSSecond();
237  return eFound;
238  }
239 
240  return eNotFound;
241 }
242 
243 
244 // Configure (x)emacs for this file ...
245 // Local Variables:
246 // mode: c++
247 // compile-command: "make -C .. FDetector/FFixOpticalEfficiencyLossManager.o -k"
248 // End:
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
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
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
Manager for FD optical efficiency correction with fixed constants.
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
TimeStamp GetTimeStamp() const
Definition: UTCDateTime.cc:115
Status
Specifies success or (eventually) various possible failure modes.
Definition: VManager.h:127

, generated on Tue Sep 26 2023.