HighLAND
DataQualityCorrection.cxx
1 #include "DataQualityCorrection.hxx"
2 #include "DataClasses.hxx"
3 #include "Parameters.hxx"
4 #include <iostream>
5 
6 //********************************************************************
8 //********************************************************************
9  _time_periods.clear();
10  _new_values.clear();
11 
12  std::string base = "highlandCorrections.DataQuality.";
13  int pairing = 1;
14 
15  // Read in the periods to apply the correction for
16  std::string curr = GetParamString(base + "NewValue.", pairing);
17 
18  while (ND::params().HasParameter(curr)) {
19  int val = ND::params().GetParameterI(curr);
20 
21  if (val != 0 && val != 1) {
22  std::cerr << "Invalid NewValue set for DataQuality correction in parameters file." << std::endl;
23  std::cerr << "Values must be either 0 or 1 - correct highlandIO.parameters.dat!" << std::endl;
24  exit(EXIT_FAILURE);
25  }
26 
27  curr = GetParamString(base + "Time.Lower.", pairing);
28  int lower = ND::params().GetParameterI(curr);
29  curr = GetParamString(base + "Time.Upper.", pairing);
30  int upper = ND::params().GetParameterI(curr);
31  std::pair<int, int> p(lower, upper);
32  _time_periods.push_back(p);
33  _new_values.push_back(val);
34  pairing++;
35  curr = GetParamString(base + "NewValue.", pairing);
36  }
37 
38 }
39 
40 //********************************************************************
41 std::string DataQualityCorrection::GetParamString(std::string base, int pairing) {
42 //********************************************************************
43  std::stringstream ss;
44  ss << base << pairing;
45  return ss.str();
46 }
47 
48 //********************************************************************
50 //********************************************************************
51 
52  // Correction was applied when making the flat tree.
53  // if (ND::input().InputIsFlatTree()) return;
54 
55  AnaSpill& spill = *static_cast<AnaSpill*>(&spillBB);
56 
57  if (spill.GetIsMC()) {
58  return;
59  }
60 
61  int time = static_cast<AnaEventInfo*>(spill.EventInfo)->EventTime;
62  int new_value = -999;
63 
64  for (unsigned int i = 0; i < _time_periods.size(); i++) {
65  if (time >= _time_periods[i].first && time <= _time_periods[i].second) {
66  new_value = _new_values[i];
67  break;
68  }
69  }
70 
71  if (new_value < 0) {
72  // We shouldn't apply the correction
73  return;
74  }
75 
76  spill.DataQuality->GoodDaq = new_value;
77 }
78 
int GetParameterI(std::string)
Get parameter. Value is returned as integer.
Definition: Parameters.cxx:217
void Apply(AnaSpillC &spill)
Apply the variation to all tracks with TPC info.
AnaEventInfoB * EventInfo
Run, sunrun, event, time stamp, etc.
All corrections should be registered with the CorrectionManager.
bool GetIsMC() const
Return whether this spill is from Monte Carlo or not.
AnaDataQualityB * DataQuality
The ND280 data quality flags for this spill.