DetPedestalDUNE.cxx
Go to the documentation of this file.
1 #ifndef DETPEDESTALDUNE_CXX
2 #define DETPEDESTALDUNE_CXX
3 
5 #include <string>
6 #include <iostream>
7 #include "nuevdb/IFDatabase/Table.h"
8 
9 using std::string;
10 using std::cout;
11 using std::endl;
12 
13 namespace dune {
14 
16  fDetName = detName;
17  fVldTime = fVldTimeUsed = 0;
18  fMeanMap.clear();
19  fRmsMap.clear();
20  fMeanErrMap.clear();
21  fRmsErrMap.clear();
22  fUseDB = false;
23  fAbortIfNoPeds = false;
24  }
25 
26  //------------------------------------------------------------
27 
29  fVldTime = fVldTimeUsed = 0;
30  fMeanMap.clear();
31  fRmsMap.clear();
32  fMeanErrMap.clear();
33  fRmsErrMap.clear();
34  fUseDB = false;
35  fAbortIfNoPeds = false;
36  fDetName = "";
37  Configure(pset);
38  }
39 
40  //------------------------------------------------------------
41 
43  const string myname = "DetPedestalDUNE::Configure: ";
44  fUseDB = p.get<bool>("UseDB",false);
45  if (!fUseDB) {
46  fVldTime = p.get<int>("Run",0);
47  }
48  fAbortIfNoPeds = p.get<bool>("AbortIfNoPeds",false);
49  fCSVFileName = p.get<std::string>("CSVFile","");
50  fUseDefaults = p.get<bool>("UseDefaults",false);
51  fDefaultMean[geo::kU] = p.get<float>("DefaultMeanU",0.);
52  fDefaultMeanErr[geo::kU] = p.get<float>("DefaultMeanErrU",0.);
53  fDefaultRms[geo::kU] = p.get<float>("DefaultRmsU",0.);
54  fDefaultRmsErr[geo::kU] = p.get<float>("DefaultRmsErrU",0.);
55  fDefaultMean[geo::kV] = p.get<float>("DefaultMeanV",0.);
56  fDefaultMeanErr[geo::kV] = p.get<float>("DefaultMeanErrV",0.);
57  fDefaultRms[geo::kV] = p.get<float>("DefaultRmsV",0.);
58  fDefaultRmsErr[geo::kV] = p.get<float>("DefaultRmsErrV",0.);
59  fDefaultMean[geo::kZ] = p.get<float>("DefaultMeanZ",0.);
60  fDefaultMeanErr[geo::kZ] = p.get<float>("DefaultMeanErrZ",0.);
61  fDefaultRms[geo::kZ] = p.get<float>("DefaultRmsZ",0.);
62  fDefaultRmsErr[geo::kZ] = p.get<float>("DefaultRmsErrZ",0.);
63  fDefaultMean[geo::kUnknown] = p.get<float>("DefaultMean",0.);
64  fDefaultMeanErr[geo::kUnknown] = p.get<float>("DefaultMeanErr",0.);
65  fDefaultRms[geo::kUnknown] = p.get<float>("DefaultRms",0.);
66  fDefaultRmsErr[geo::kUnknown] = p.get<float>("DefaultRmsErr",0.);
67 
68  fLogLevel = p.get<int>("LogLevel", 1);
69  if ( fLogLevel > 0 ) {
70  std::cout << myname << " UseDB: " << fUseDB << std::endl;
71  std::cout << myname << " Run: " << fVldTime << std::endl;
72  std::cout << myname << " CSVFile: " << fCSVFileName << std::endl;
73  std::cout << myname << " UseDefaults: " << fUseDefaults << std::endl;
74  std::cout << myname << " DefaultMean[U]: " << fDefaultMean[geo::kU] << std::endl;
75  std::cout << myname << "DefaultMeanErr[U]: " << fDefaultMeanErr[geo::kU] << std::endl;
76  std::cout << myname << " DefaultRms[U]: " << fDefaultRms[geo::kU] << std::endl;
77  std::cout << myname << " DefaultRmsErr[U]: " << fDefaultRmsErr[geo::kU] << std::endl;
78  std::cout << myname << " DefaultMean[V]: " << fDefaultMean[geo::kV] << std::endl;
79  std::cout << myname << "DefaultMeanErr[V]: " << fDefaultMeanErr[geo::kV] << std::endl;
80  std::cout << myname << " DefaultRms[V]: " << fDefaultRms[geo::kV] << std::endl;
81  std::cout << myname << " DefaultRmsErr[V]: " << fDefaultRmsErr[geo::kV] << std::endl;
82  std::cout << myname << " DefaultMean[Z]: " << fDefaultMean[geo::kZ] << std::endl;
83  std::cout << myname << "DefaultMeanErr[Z]: " << fDefaultMeanErr[geo::kZ] << std::endl;
84  std::cout << myname << " DefaultRms[Z]: " << fDefaultRms[geo::kZ] << std::endl;
85  std::cout << myname << " DefaultRmsErr[Z]: " << fDefaultRmsErr[geo::kZ] << std::endl;
86  std::cout << myname << " LogLevel: " << fLogLevel << std::endl;
87  }
88 
89  return true;
90  }
91 
92  //------------------------------------------------------------
93 
95  {
96  if (fUseDefaults) return true;
97 
98  if ( fLogLevel > 0 )
99  std::cout << __PRETTY_FUNCTION__ << " Called with run " << ts << std::endl;
100 
101  if (!fUseDB && fCSVFileName.empty()) {
102  std::cout << __PRETTY_FUNCTION__ << " Method of determining pedestals is undefined! Either set UseDB or CSVFileName in fhicl. ";
103  if (fAbortIfNoPeds) {
104  std::cout << "Aborting per request." << std::endl;
105  abort();
106  }
107  return false;
108  }
109 
110  if (ts == fVldTime)
111  return true;
112  else
113  fVldTime = ts;
114 
115  fMeanMap.clear();
116  fMeanErrMap.clear();
117  fRmsMap.clear();
118  fRmsErrMap.clear();
119 
120  std::string tableName = "pedestals";
122 
123  if (fDetName.empty()) {
124  std::cerr << "Detector name is undefined. Aborting." << std::endl;
125  std::abort();
126  }
127 
129  t.SetTableName(tableName);
132 
133  int meanIdx = t.AddCol("mean","float");
134  int rmsIdx = t.AddCol("rms","float");
135  int meanErrIdx = t.AddCol("meanerr","float");
136  int rmsErrIdx = t.AddCol("rmserr","float");
137 
138  t.SetMinTSVld(ts);
139  t.SetMaxTSVld(ts);
140 
141  t.SetVerbosity(100);
142  if (fUseDB)
143  t.Load();
144  else
146 
147  if (t.NRow() == 0) {
148  std::cout << "Number of pedestals from database/CSV file is 0. This should never be the case! ";
149  if (fAbortIfNoPeds) {
150  std::cout << "Aborting, per request." << std::endl;
151  abort();
152  }
153  return false;
154  }
155 
157  float mean, rms, meanerr, rmserr;
158  uint64_t chan, offlineChan;
159  for (int i=0; i<t.NRow(); ++i) {
160  mean = rms = meanerr = rmserr = 0.;
161  row = t.GetRow(i);
162  chan = row->Channel(); // MW: as of 3/1/16, this is now an online channel number
163  offlineChan = fChannelMap->Offline(chan); // Need to map to an offline channel at this point
164  //offlineChan = chan;
165  row->Col(meanIdx).Get(mean);
166  row->Col(meanErrIdx).Get(meanerr);
167  row->Col(rmsIdx).Get(rms);
168  row->Col(rmsErrIdx).Get(rmserr);
169  fMeanMap[offlineChan] = mean;
170  fMeanErrMap[offlineChan] = meanerr;
171  fRmsMap[offlineChan] = rms;
172  fRmsErrMap[offlineChan] = rmserr;
173  if (i==0) { // print out
174  fVldTimeUsed = row->VldTime();
175  if (fLogLevel > 0) {
176  std::cout << __PRETTY_FUNCTION__ << ": using run " << row->VldTime()
177  << " for pedestals." << std::endl;
178  }
179  }
180  }
181 
182  return true;
183  }
184 
185 
186  //------------------------------------------------------------
187 
189  float retVal=-1.;
190  auto it = fDefaultMean.find(v);
191  if (it != fDefaultMean.end())
192  return it->second;
193  else
194  return retVal;
195 
196  }
197 
198  //------------------------------------------------------------
199 
201  float retVal=-1.;
202  auto it = fDefaultMeanErr.find(v);
203  if (it != fDefaultMeanErr.end())
204  return it->second;
205  else
206  return retVal;
207 
208  }
209 
210  //------------------------------------------------------------
211 
213  float retVal=-1.;
214  auto it = fDefaultRms.find(v);
215  if (it != fDefaultRms.end())
216  return it->second;
217  else
218  return retVal;
219 
220  }
221 
222  //------------------------------------------------------------
223 
225  float retVal=-1.;
226  auto it = fDefaultRmsErr.find(v);
227  if (it != fDefaultRmsErr.end())
228  return it->second;
229  else
230  return retVal;
231 
232  }
233 
234  //------------------------------------------------------------
235 
237  float retVal=-1.;
238  if (fUseDefaults) {
239  auto it = fDefaultMean.find(geo::kUnknown);
240  if (it != fDefaultMean.end())
241  return it->second;
242  else
243  return retVal;
244  }
245  if (fVldTime == 0) {
246  std::cerr << "DetPedestalDUNE: Validity time is not set! Aborting." << std::endl;
247  abort();
248  }
249  auto it = fMeanMap.find(ch);
250  if (it != fMeanMap.end())
251  retVal = it->second;
252 
253  return retVal;
254  }
255 
256  //------------------------------------------------------------
257 
259  float retVal=0.;
260  if (fUseDefaults) {
261  auto it = fDefaultMeanErr.find(geo::kUnknown);
262  if (it != fDefaultMeanErr.end())
263  return it->second;
264  else
265  return retVal;
266  }
267 
268  if (fVldTime == 0) {
269  std::cerr << "DetPedestalDUNE: Validity time is not set! Aborting." << std::endl;
270  abort();
271  }
272  auto it = fMeanErrMap.find(ch);
273  if (it != fMeanErrMap.end())
274  retVal = it->second;
275 
276  return retVal;
277  }
278 
279  //------------------------------------------------------------
280 
282  float retVal=-1;
283  if (fUseDefaults) {
284  auto it = fDefaultRms.find(geo::kUnknown);
285  if (it != fDefaultRms.end())
286  return it->second;
287  else
288  return retVal;
289  }
290  if (fVldTime == 0) {
291  std::cerr << "DetPedestalDUNE: Validity time is not set! Aborting." << std::endl;
292  abort();
293  }
294  auto it = fRmsMap.find(ch);
295  if (it != fRmsMap.end())
296  retVal = it->second;
297 
298  return retVal;
299  }
300 
301  //------------------------------------------------------------
302 
304  float retVal=0.;
305  if (fUseDefaults) {
306  auto it = fDefaultRmsErr.find(geo::kUnknown);
307  if (it != fDefaultRmsErr.end())
308  return it->second;
309  else
310  return retVal;
311  }
312  if (fVldTime == 0) {
313  std::cerr << "DetPedestalDUNE: Validity time is not set! Aborting." << std::endl;
314  abort();
315  }
316  auto it = fRmsErrMap.find(ch);
317  if (it != fRmsErrMap.end())
318  retVal = it->second;
319 
320  return retVal;
321  }
322 
323  //------------------------------------------------------------
324 
326  auto itMean = fMeanMap.begin();
327  for (; itMean != fMeanMap.end(); ++itMean) {
328  std::cout << "Channel: " << itMean->first << ", Mean = " << itMean->second
329  << ", RMS = " << fRmsMap[itMean->first] << std::endl;
330  }
331 
332  }
333 
334 } // end namespace dune
335 
336 #endif
Pedestal provider class for DUNE.
float VldTime()
Definition: Row.h:56
std::map< geo::View_t, float > fDefaultRmsErr
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:39
std::unordered_map< raw::ChannelID_t, float > fRmsMap
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::string string
Definition: nybbler.cc:12
Planes which measure V.
Definition: geo_types.h:126
Unknown view.
Definition: geo_types.h:132
std::unordered_map< raw::ChannelID_t, float > fRmsErrMap
std::unordered_map< raw::ChannelID_t, float > fMeanMap
void SetMaxTSVld(float t)
Definition: Table.h:272
uint64_t Channel()
Definition: Row.h:55
Planes which measure Z direction.
Definition: geo_types.h:128
bool Get(T &val) const
Definition: Column.h:72
bool LoadFromCSV(std::string fname)
Definition: Table.cpp:1291
virtual float PedRmsErr(raw::ChannelID_t ch) const
float DefaultRms(geo::View_t v) const
Planes which measure U.
Definition: geo_types.h:125
virtual float PedMean(raw::ChannelID_t ch) const
Retrieve pedestal information.
virtual float PedRms(raw::ChannelID_t ch) const
DetPedestalDUNE(std::string detName="")
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::map< geo::View_t, float > fDefaultMeanErr
bool SetDetector(std::string det)
Definition: Table.cpp:493
void SetTableName(std::string tname)
Definition: Table.cpp:517
unsigned __int64 uint64_t
Definition: stdint.h:136
float DefaultRmsErr(geo::View_t v) const
bool Configure(fhicl::ParameterSet const &pset)
int AddCol(std::string cname, std::string ctype)
Definition: Table.cpp:326
std::map< geo::View_t, float > fDefaultRms
p
Definition: test.py:223
float DefaultMean(geo::View_t v) const
std::unordered_map< raw::ChannelID_t, float > fMeanErrMap
std::map< geo::View_t, float > fDefaultMean
nutools::dbi::Row *const GetRow(int i)
Definition: Table.cpp:406
void SetMinTSVld(float t)
Definition: Table.h:271
art::ServiceHandle< lbne::ChannelMapService > fChannelMap
void SetVerbosity(int i)
Definition: Table.h:100
bool SetTableType(int t)
Definition: Table.cpp:451
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
float DefaultMeanErr(geo::View_t v) const
Column & Col(int i)
Definition: Row.h:53
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:15
virtual float PedMeanErr(raw::ChannelID_t ch) const
bool Update(uint64_t ts)
QTextStream & endl(QTextStream &s)
void SetDataTypeMask(int mask)
Definition: Table.h:76
std::string tableName