SelectionUtility.cxx
Go to the documentation of this file.
1 //
2 // Created by Adam Lister on 06/02/20.
3 //
4 
6 
7 namespace cmf{
8 
9  static SelectionUtility *gSU = nullptr;
10 
11  //----------------------------------------------------------------------------
13  {
14  if(gSU == nullptr) gSU = new SelectionUtility();
15 
16  return gSU;
17  }
18 
19  //----------------------------------------------------------------------------
21  {
22  }
23 
24  //----------------------------------------------------------------------------
26  {
27  }
28 
29  //----------------------------------------------------------------------------
30  /// from fhicl, define the selections which have been configured, all possible
31  /// selections, and those which have not been configured
33  {
34 
35  fSelectionsToUse.clear();
36 
37  std::string detStr;
38  std::string beamStr;
39  std::string selStr;
40 
43 
44  std::set<cmf::SelectionType_t> selSet;
45 
46  for(auto const& name : dbsParSet.get_names()){
47 
48  try {
49  auto const& pset = dbsParSet.get<fhicl::ParameterSet>(name);
50 
51  beamStr = pset.get<std::string>("Beam");
52  beam = (beamStr.find("FHC") != std::string::npos) ? cmf::kFHC : cmf::kRHC;
53 
54  det = cmf::StringToDetectorType(pset.get<std::string>("Detector"));
55 
56  selSet.clear();
57  auto selStrs = pset.get<std::vector<std::string>>("Selections");
58  for(auto& sel: selStrs){
59  selSet.insert(cmf::StringToSelectionType(sel));
60  } // end loop over selection strings
61 
62  fSelectionsToUse.emplace(DetBeamSels(det, beam, selSet));
63  fDetectorsToUse.insert(det);
64  }
65  catch (cet::exception &e) {
66  MF_LOG_VERBATIM("SelectionUtility")
67  << " -- Parameter "
68  << name
69  << " cannot be cast as a fhicl::ParameterSet."
70  << "\n This is expected for non-detector/beam/selection parameter sets.";
71  continue;
72  }
73  } // end loop over detectors
74 
75  // now deal with getting all selections
76  // really tried to loop over the enums to do this but cpp really doesn't want
77  // you to do that
78 
79  // the default is to concatenate the quantiles, users have to explicitly
80  // set the configuration to not do that
81 
82  fAllAvailSelections.clear();
83 
84  for (auto const &det : cmf::cDetIds){
85  if(det == cmf::kUnknownDet) continue;
86  for (auto const &beam : cmf::cBeamTypes){
87  if(beam == cmf::kUnknownBeam) continue;
88 
89  std::set<cmf::SelectionType_t> allSet;
90  if (det == cmf::kFARDET)
91  allSet.insert(cmf::kNuESelectionPeripheral);
92  allSet.insert(cmf::kNuESelectionLowPID);
93  allSet.insert(cmf::kNuESelectionHighPID);
94  if(dbsParSet.get<bool>("FullSetUsesQuantiles", false)){
95  allSet.insert(cmf::kNuMuSelectionQ1);
96  allSet.insert(cmf::kNuMuSelectionQ2);
97  allSet.insert(cmf::kNuMuSelectionQ3);
98  allSet.insert(cmf::kNuMuSelectionQ4);
99  }
100  else
101  allSet.insert(cmf::kNuMuSelection);
102  allSet.insert(cmf::kNCSelection);
103 
104  fAllAvailSelections.emplace(DetBeamSels(det, beam, allSet));
105  }
106  }
107 
109 
110  MF_LOG_VERBATIM("")
111  << "\n-------------------------------------------------------"
112  << "\n SELECTION SUMMARY"
113  << "\n-------------------------------------------------------"
114  << "\n Configured Selections:";
116 
117  MF_LOG_VERBATIM("")
118  << "Unused Selections:";
120 
121  }
122 
123  //---------------------------------------------------------------------------
124  /// determine which selections were not configured from fhicl
126  DetBeamSels dbsAllAvail;
127  DetBeamSels dbsUsed;
128  std::set<cmf::SelectionType_t> sels;
129  for (auto const &det : cmf::cDetIds){
130  for (auto const&beam : cmf::cBeamTypes){
131 
132  // find the structs relevant for this detector and beam
133  dbsAllAvail = (*fAllAvailSelections.find(DetBeamSels(det, beam)));
134  dbsUsed = (*fSelectionsToUse.find(DetBeamSels(det, beam)));
135 
136  sels.clear();
137  for(auto const &sel : dbsAllAvail.sels){
138  if (dbsUsed.sels.find(sel) == dbsUsed.sels.end())
139  sels.emplace(sel);
140  } // end loop over selections
141 
142  fSelectionsNotUsed.emplace(DetBeamSels(det, beam, sels));
143  }
144  }
145  }
146 
147  //---------------------------------------------------------------------------
148  /// print a given detector-selection map
150 
151  std::string detStr;
152  std::string beamStr;
153  std::string selStr;
154  for (auto const &dbs : dbsSet){
155 
156  detStr = cmf::cDetType_Strings[dbs.det];
157  beamStr = cmf::cBeamType_Strings[dbs.beam];
158 
159  for (auto const& sel : dbs.sels){
160  selStr = cmf::cSelectionType_Strings[sel];
161  std::cout << " -- "
162  << detStr << " "
163  << beamStr << " "
164  << selStr << std::endl;
165  }
166  }
167  }
168 
169  //---------------------------------------------------------------------------
171  {
172  return this->UsesDetAndBeam(md.detector,
174  }
175 
176  //---------------------------------------------------------------------------
178  cmf::BeamType_t const& b) const
179  {
180  // loop over the selections to use and see if this detector, beam and
181  // selection combination exists
182  for(auto const& itr : fSelectionsToUse){
183  if(itr.Detector() == d &&
184  itr.BeamType() == b)
185  return true;
186  }
187 
188  return false;
189  }
190 
191  //---------------------------------------------------------------------------
193  {
194  return this->UsesDetBeamAndSel(md.detector,
196  md.selectionType);
197  }
198 
199  //---------------------------------------------------------------------------
201  cmf::BeamType_t const& b,
202  cmf::SelectionType_t const& s) const
203  {
204  // loop over the selections to use and see if this detector, beam and
205  // selection combination exists
206  for(auto const& itr : fSelectionsToUse){
207  if(itr.Detector() == d &&
208  itr.BeamType() == b){
209  for(auto const& selItr : itr.Selections()){
210  if (selItr == s) return true;
211  else if(cmf::IsNuMuQuantiles(s) &&
212  selItr == cmf::kNuMuSelection) return true;
213  else if(cmf::IsNuESelected(s) &&
214  selItr == cmf::kNuESelection ) return true;
215  }
216  }
217  }
218 
219  return false;
220  }
221 
222  //---------------------------------------------------------------------------
224  {
225  // loop over the selections to use and see if this detector, beam and
226  // selection combination exists
227  for(auto const& itr : fSelectionsToUse){
228  for(auto const& selItr : itr.Selections()){
229  if (selItr == s) return true;
230  else if(cmf::IsNuMuQuantiles(s) &&
231  selItr == cmf::kNuMuSelection) return true;
232  else if(cmf::IsNuESelected(s) &&
233  selItr == cmf::kNuESelection ) return true;
234  }
235  }
236  return false;
237  }
238 
239  //---------------------------------------------------------------------------
241  {
242  // loop over the selections to use and see if this detector, beam and
243  // selection combination exists
244  for(auto const& itr : fSelectionsToUse){
245  if(itr.Detector() == d) return true;
246  }
247  return false;
248  }
249 
250  //---------------------------------------------------------------------------
251  std::set<cmf::DetType_t> const& SelectionUtility::DetectorsToUse()
252  {
253  return fDetectorsToUse;
254  }
255 
256 }
const XML_Char * name
Definition: expat.h:151
static SelectionUtility * gSU
DetBeamSelSet fSelectionsNotUsed
selections which are not configured
cmf::DetType_t detector
Definition: Structs.h:114
bool UsesDetector(cmf::DetType_t const &d) const
const std::vector< std::string > cDetType_Strings({"UnknownDet","NearDet","FarDet","MINOSNear","MINOSFar","AllDetectors"})
static SelectionUtility * Instance()
enum cmf::det_type DetType_t
std::string PeriodString() const
Definition: Structs.h:162
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
std::set< cmf::SelectionType_t > sels
enum cmf::sel_type SelectionType_t
void DetermineUnusedSelections()
determine which selections were not configured from fhicl
static bool IsNuESelected(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:380
static bool IsNuMuQuantiles(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:373
void PrintSelections(DetBeamSelSet dbs)
print a given detector-selection map
const XML_Char * s
Definition: expat.h:262
static cmf::SelectionType_t StringToSelectionType(std::string const &str)
Definition: StaticFuncs.h:248
cmf::SelectionType_t selectionType
Definition: Structs.h:116
const Cut sels[kNumSels]
Definition: vars.h:44
T get(std::string const &key) const
Definition: ParameterSet.h:231
DetBeamSelSet fSelectionsToUse
selections which are configured
static cmf::DetType_t StringToDetectorType(std::string const &str)
Definition: StaticFuncs.h:267
bool UsesSelection(cmf::SelectionType_t const &s) const
Float_t d
Definition: plot.C:236
const std::vector< std::string > cSelectionType_Strings({"NuESel_AllPID","NuESel_LowPID","NuESel_MidPID","NuESel_HighPID","NuESel_Peripheral","NuMuSel","NuMuSelQ1","NuMuSelQ2","NuMuSelQ3","NuMuSelQ4","NCSel","UnknownSel"})
static cmf::BeamType_t PeriodToBeamType(std::string const &str)
const std::vector< std::string > cBeamType_Strings({"FHC","RHC","0HC","UnknownBeam"})
std::vector< std::string > get_names() const
OStream cout
Definition: OStream.cxx:6
associates each detector-beam pair to a set of selections
Module to combine a set of results into a single file currently only does one data product type at a ...
Definition: Event.cxx:24
std::set< cmf::DetType_t > const & DetectorsToUse()
DetBeamSelSet fAllAvailSelections
all available selections
std::set< cmf::DetType_t > fDetectorsToUse
#define MF_LOG_VERBATIM(category)
bool UsesDetAndBeam(cmf::MetaData const &md) const
enum cmf::beam_type BeamType_t
const hit & b
Definition: hits.cxx:21
void Initialize(fhicl::ParameterSet const &pset)
std::set< cmf::SelectionUtility::DetBeamSels > DetBeamSelSet
static const std::set< cmf::DetType_t > cDetIds({cmf::kNEARDET, cmf::kFARDET, cmf::kMINOSNEAR, cmf::kMINOSFAR})
Float_t e
Definition: plot.C:35
static const std::set< cmf::BeamType_t > cBeamTypes({kFHC, kRHC})
enum BeamMode string
bool UsesDetBeamAndSel(cmf::MetaData const &md) const