CovarianceBinUtility.cxx
Go to the documentation of this file.
1 //
2 // Created by Brian Rebel on 11/29/18.
3 //
4 
6 #include "cetlib_except/exception.h"
7 
8 #include "NovaDAQConventions/DAQConventions.h"
11 
12 namespace fnex {
13 
14  //-----------------------------------------------------------------------------
16  : fNuMuHighEdges({{1.0, 1},
17  {1.10, 2},
18  {1.2, 3},
19  {1.30, 4},
20  {1.40, 5},
21  {1.5, 6},
22  {1.60, 7},
23  {1.7, 8},
24  {1.80, 9},
25  {1.90, 10},
26  {2.0, 11},
27  {2.25, 12},
28  {2.5, 13},
29  {2.75, 14},
30  {3.00, 15},
31  {3.5, 16},
32  {4.00, 17},
33  {5.0, 18},
34  {10.0, 19}})
35  , fNuEHighEdges({{1.0, 1},
36  {1.5, 2},
37  {2.0, 3},
38  {2.5, 4},
39  {3.0, 5},
40  {3.5, 6},
41  {4.0, 7},
42  {4.5, 8},
43  {5.0, 9}})
44  {
45  int key = 0;
46  int offset = 0;
47  int numSelBins = 0;
48 
49  // loop over detectors, beam type and selection to fill the maps
50  for(int b = fnex::kFHC; b < fnex::k0HC; ++b){
51  for(int d = 1; d < 3; ++d){
53 
54  // there is no MidPID selection for nues any more and no nue peripheral
55  // selection in the nd
56 
57  if(d == 1 && s == fnex::kNuESelectionPeripheral) continue;
58  if(s == fnex::kNuESelectionMidPID) continue;
59 
60  key = 1000 * (b + 1) + 100 * d + s;
61 
63 
64  LOG_DEBUG("CovarianceBinUtility")
66  << " "
68  << " "
70  << " key "
71  << key
72  << " offset "
73  << fOffsetMap[key];
74 
76  numSelBins = fNuEHighEdges.size();
77  }
78  else if(s == fnex::kNuESelectionPeripheral){
79  numSelBins = 1;
80  }
82  numSelBins = fNuMuHighEdges.size();
83  }
84 
85  offset += numSelBins;
86 
87  } // end loop over selections
88  } // end loop over detectors
89  } // end loop over beams
90 
91  // fill the bin to energy maps for fast look up
92  for(auto const& itr : fNuMuHighEdges){
93  fNuMuBinToEnergy[itr.second] = itr.first;
94 
95  LOG_DEBUG("CovarianceBinUtility")
96  << "nu mu energy "
97  << itr.first
98  << " bin "
99  << itr.second
100  << " bin to energy "
101  << fNuMuBinToEnergy.find(itr.second)->second;
102  }
103 
104  for(auto const& itr : fNuEHighEdges){
105  fNuEBinToEnergy[itr.second] = itr.first;
106 
107  LOG_DEBUG("CovarianceBinUtility")
108  << "nu e energy "
109  << itr.first
110  << " bin "
111  << itr.second
112  << " bin to energy "
113  << fNuEBinToEnergy.find(itr.second)->second;
114  }
115 
116  }
117 
118  //-----------------------------------------------------------------------------
120  {
121  fNuMuHighEdges.clear();
122  fNuEHighEdges.clear();
123  fOffsetMap.clear();
124  }
125 
126  // Use the selection type of the meta data to determine how much of an offset
127  // in the energy value is needed.
128  //......................................................................
130  {
131  return (md.BeamType() + 1) * 1000 + md.detector * 100 + md.selectionType;
132  }
133 
134 
135  //......................................................................
137  {
138  if(fOffsetMap.count(key) < 1)
139  throw cet::exception("CovarianceBinUtility")
140  << "could not find offset in map for key "
141  << key;
142 
143  return fOffsetMap.find(key)->second;
144  }
145 
146  //......................................................................
148  fnex::MetaData const& md)
149  {
150  int bin = -1;
151 
153  bin = 1;
154  }
155  else if(md.IsNuESelected()){
156  auto const& itr = fNuEHighEdges.upper_bound(energy);
157  if(itr != fNuEHighEdges.end()) bin = itr->second;
158  }
159  else if(md.IsNuMuSelected()){
160  auto const& itr = fNuMuHighEdges.upper_bound(energy);
161  if(itr != fNuMuHighEdges.end()) bin = itr->second;
162  }
163 
164  return bin;
165  }
166 
167  //......................................................................
169  fnex::MetaData const& md)
170  {
171  double energy = 0.;
172  int offset = this->KeyToOffset(this->MetaDataToKey(md));
173 
174  // first figure out if we have nue or numu
176  energy = 5.;
177  }
178  else if(md.IsNuESelected()){
179  LOG_DEBUG("CovarianceBinUtility")
180  << md.ToString()
181  << " bin is "
182  << bin
183  << " offset "
184  << offset
185  << " energy "
186  << fNuEBinToEnergy.find(bin - offset)->second;
187 
188  energy = fNuEBinToEnergy.find(bin - offset)->second;
189  }
190  else if(md.IsNuMuSelected()){
191  LOG_DEBUG("CovarianceBinUtility")
192  << md.ToString()
193  << " bin is "
194  << bin
195  << " offset "
196  << offset
197  << " energy "
198  << fNuMuBinToEnergy.find(bin - offset)->second;
199 
200  energy = fNuMuBinToEnergy.find(bin - offset)->second;
201  }
202 
203  return energy;
204  }
205 } // fnex namespace
static std::string GetName(int id)
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::map< double, int > fNuEHighEdges
high side of the nue bins
bool IsNuESelected() const
Definition: Structs.cxx:265
bool IsNuMuSelected() const
Definition: Structs.cxx:256
std::map< int, int > fOffsetMap
map of keys to offset for different samples
std::map< int, double > fNuEBinToEnergy
map energy bin to central value
std::map< double, int > fNuMuHighEdges
high side of the numu bins
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
Create a list of fnex::Events to be used in fits.
const XML_Char * s
Definition: expat.h:262
std::string const ToString() const
Definition: Structs.cxx:114
std::map< int, double > fNuMuBinToEnergy
map energy bin to central value
double energy
Definition: plottest35.C:25
Float_t d
Definition: plot.C:236
int MetaDataToKey(fnex::MetaData const &md)
novadaq::cnv::DetId detector
Definition: Structs.h:50
float bin[41]
Definition: plottest35.C:14
int EnergyToBin(double const &energy, fnex::MetaData const &md)
const std::string cBeamType_Strings[4]
Definition: Constants.h:76
fnex::SelectionType_t selectionType
Definition: Structs.h:52
double BinToEnergy(int const &bin, fnex::MetaData const &md)
const hit & b
Definition: hits.cxx:21
fnex::BeamType_t const BeamType() const
Definition: Structs.cxx:165
const std::string cSelectionType_Strings[11]
Definition: Constants.h:101