FFixCalibManager.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/FFixCalibManager.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("FFixCalibManager", FFixCalibManager);
32 
33 
34 void
35 FFixCalibManager::Init(const std::string& configLink)
36 {
37  fHasDefaultCalibConst = false;
38  VManager::Init(configLink);
39  Initialize();
40  ostringstream info;
41  if (fHasDefaultCalibConst)
42  info << "fixed calibration constant is " << fCalibConst << " ph/ADC";
43  else
44  info << " no default fixed calibration constant";
45 
46  if (!fPerTelescopeCalibConst.empty()) {
47  for (map<int, map<int, double> >::const_iterator eyeIt = fPerTelescopeCalibConst.begin(),
48  eyeEnd = fPerTelescopeCalibConst.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 << " ph/ADC";
55 
56  } // end for tels
57  } // end for eyes
58  } // end if have per-tel calib
59  INFO(info);
60 }
61 
62 
63 void
64 FFixCalibManager::Initialize()
65 {
66  Branch defaultCalConstBranch = fBranch.GetChild("fixedCalibrationConstant");
67  if (defaultCalConstBranch) {
68  defaultCalConstBranch.GetData(fCalibConst);
69  fHasDefaultCalibConst = true;
70  } else
71  fHasDefaultCalibConst = false;
72 
73  const Branch& perTel = fBranch.GetChild("perTelescope");
74  if (perTel) {
75 
76  Branch caliBranch = perTel.GetFirstChild();
77  while (caliBranch) {
78  double caliConst = 0;
79  caliBranch.GetData(caliConst);
80 
81  const AttributeMap& attrs = caliBranch.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("telescopeCalibrationConstant 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  fPerTelescopeCalibConst[eyeId][telId] = caliConst;
92 
93  caliBranch = caliBranch.GetNextSibling();
94  }
95 
96  } // end have calib per-tel
97 
98  // list of properties
99  //fAvailableComponents.insert("pixel_t_offset");
100  fAvailableComponents.insert("pixel_calibs");
101  fAvailableComponents.insert("status");
102  fAvailableComponents.insert("start_time");
103  fAvailableComponents.insert("end_time");
104  // elecgain
105  // status
106 }
107 
108 
110 FFixCalibManager::GetData(double& /*returnData*/,
111  const string& componentProperty,
112  const string& componentName,
113  const IndexMap&)
114  const
115 {
116  // this manager only knows about fd_calib
117  if (componentName != "fd_calib")
118  return eNotFound;
119 
120  // check property availability
121  if (fAvailableComponents.find(componentProperty) == fAvailableComponents.end())
122  return eNotFound;
123 
124  return eNotFound;
125 }
126 
127 
129 FFixCalibManager::GetData(map<int, utl::TabulatedFunction>& returnData,
130  const string& componentProperty,
131  const string& componentName,
132  const IndexMap& componentIndex)
133  const
134 {
135  // this manager only knows about fd_calib
136  if (componentName != "fd_calib")
137  return eNotFound;
138 
139  // check property availability
140  if (fAvailableComponents.find(componentProperty) == fAvailableComponents.end())
141  return eNotFound;
142 
143  returnData.clear();
144 
145  if (componentProperty == "pixel_calibs") {
146  const fdet::FDetector& fdet = det::Detector::GetInstance().GetFDetector();
147  const double wavelength = fdet.GetReferenceLambda();
148 
149  const string& eyeIdString = componentIndex.find("eyeId")->second;
150  const string& telescopeIdString = componentIndex.find("telescopeId")->second;
151  const int eyeId = boost::lexical_cast<int>(eyeIdString);
152  const int telId = boost::lexical_cast<int>(telescopeIdString);
153 
154  double calibConst = 0;
155  if (GetCalibConstForTelescope(eyeId, telId, calibConst)) {
156 
157  for (int iPix = 1; iPix <= 440; ++iPix) {
158  TabulatedFunction calVsWavelength;
159  calVsWavelength.PushBack(wavelength, calibConst);
160  returnData.insert(make_pair(iPix, calVsWavelength));
161  }
162 
163  return eFound;
164  }
165  }
166 
167  return eNotFound;
168 }
169 
170 
171 bool
172 FFixCalibManager::GetCalibConstForTelescope(const unsigned int eyeId,
173  const unsigned int telId,
174  double& value)
175  const
176 {
177  map<int, map<int, double> >::const_iterator eyeIt = fPerTelescopeCalibConst.find(eyeId);
178  if (eyeIt == fPerTelescopeCalibConst.end()) {
179  if (fHasDefaultCalibConst) {
180  value = fCalibConst;
181  return true;
182  } else
183  return false;
184  }
185 
186  map<int, double>::const_iterator telIt = eyeIt->second.find(telId);
187  if (telIt == eyeIt->second.end()) {
188  if (fHasDefaultCalibConst) {
189  value = fCalibConst;
190  return true;
191  } else
192  return false;
193  }
194 
195  value = telIt->second;
196  return true;
197 }
198 
199 
201 FFixCalibManager::GetData(vector<int>& returnData,
202  const string& componentProperty,
203  const string& componentName,
204  const IndexMap& /*componentIndex*/)
205  const
206 {
207  if (componentProperty != "status" || componentName != "fd_calib")
208  return eNotFound;
209  returnData.clear();
210  returnData.resize(441, 0); // eGood
211  return eFound;
212 }
213 
214 
216 FFixCalibManager::GetData(int& returnData,
217  const string& componentProperty,
218  const string& componentName,
219  const IndexMap&)
220  const
221 {
222  // this manager only knows about fd_calib
223  if (componentName != "fd_calib")
224  return eNotFound;
225 
226  // check property availability
227  if (fAvailableComponents.find(componentProperty) == fAvailableComponents.end())
228  return eNotFound;
229 
230  if (componentProperty == "start_time") {
231  // very early
232  returnData = UTCDateTime(2000, 1, 1).GetTimeStamp().GetGPSSecond();
233  return eFound;
234  }
235 
236  if (componentProperty == "end_time") {
237  // very late
238  returnData = UTCDateTime(2037, 11, 30).GetTimeStamp().GetGPSSecond();
239  return eFound;
240  }
241 
242  return eNotFound;
243 }
244 
245 
246 // Configure (x)emacs for this file ...
247 // Local Variables:
248 // mode: c++
249 // compile-command: "make -C .. FDetector/FFixCalibManager.o -k"
250 // 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
Manager for FD calibration with fixed constants.
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
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.