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  detStr = pset.get<std::string>("Detector");
55  det = (detStr.find("Far") != std::string::npos) ? cmf::kFARDET : cmf::kNEARDET;
56 
57  selSet.clear();
58  auto selStrs = pset.get<std::vector<std::string>>("Selections");
59  for(auto& sel: selStrs){
60  selSet.insert(cmf::StringToSelectionType(sel));
61  } // end loop over selection strings
62 
63  fSelectionsToUse.emplace(DetBeamSels(det, beam, selSet));
64  }
65  catch (cet::exception &e) {
66  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  for (auto const &beam : cmf::cBeamTypes){
86  std::set<cmf::SelectionType_t> allSet;
87  if (det == cmf::kFARDET)
88  allSet.insert(cmf::kNuESelectionPeripheral);
89  allSet.insert(cmf::kNuESelectionLowPID);
90  allSet.insert(cmf::kNuESelectionHighPID);
91  if(dbsParSet.get<bool>("FullSetUsesQuantiles", false)){
92  allSet.insert(cmf::kNuMuSelectionQ1);
93  allSet.insert(cmf::kNuMuSelectionQ2);
94  allSet.insert(cmf::kNuMuSelectionQ3);
95  allSet.insert(cmf::kNuMuSelectionQ4);
96  }
97  else
98  allSet.insert(cmf::kNuMuSelection);
99  allSet.insert(cmf::kNCSelection);
100 
101  fAllAvailSelections.emplace(DetBeamSels(det, beam, allSet));
102  }
103  }
104 
106 
107  LOG_VERBATIM("")
108  << "\n-------------------------------------------------------"
109  << "\n SELECTION SUMMARY"
110  << "\n-------------------------------------------------------"
111  << "\n Configured Selections:";
113 
114  LOG_VERBATIM("")
115  << "Unused Selections:";
117 
118  }
119 
120  //---------------------------------------------------------------------------
121  /// determine which selections were not configured from fhicl
123  DetBeamSels dbsAllAvail;
124  DetBeamSels dbsUsed;
125  std::set<cmf::SelectionType_t> sels;
126  std::string detStr;
127  std::string beamStr;
128  for (auto const &det : cmf::cDetIds){
129  for (auto const&beam : cmf::cBeamTypes){
130 
131  // find the structs relevant for this detector and beam
132  dbsAllAvail = (*fAllAvailSelections.find(DetBeamSels(det, beam)));
133  dbsUsed = (*fSelectionsToUse.find(DetBeamSels(det, beam)));
134  detStr = (det == cmf::kNEARDET ) ? "NearDet" : "FarDet";
135  beamStr = (beam == cmf::BeamType_t::kFHC ) ? "FHC" : "RHC";
136 
137  sels.clear();
138  for(auto const &sel : dbsAllAvail.sels){
139  if (dbsUsed.sels.find(sel) == dbsUsed.sels.end())
140  sels.emplace(sel);
141  } // end loop over selections
142 
143  fSelectionsNotUsed.emplace(DetBeamSels(det,beam,sels));
144  }
145  }
146  }
147 
148  //---------------------------------------------------------------------------
149  /// print a given detector-selection map
151 
152  std::string detStr;
153  std::string beamStr;
154  std::string selStr;
155  for (auto const &dbs : dbsSet){
156 
157  detStr = (dbs.det == cmf::kNEARDET ) ? "NearDet" : "FarDet";
158  beamStr = (dbs.beam == cmf::BeamType_t::kFHC ) ? "FHC" : "RHC";
159 
160  for (auto const& sel : dbs.sels){
161  selStr = cmf::cSelectionType_Strings[sel];
162  std::cout << " -- "
163  << detStr << " "
164  << beamStr << " "
165  << selStr << std::endl;
166  }
167  }
168  }
169 
170  //---------------------------------------------------------------------------
172  {
173  return this->UsesDetAndBeam(md.detector,
175  }
176 
177  //---------------------------------------------------------------------------
179  cmf::BeamType_t const& b) const
180  {
181  // loop over the selections to use and see if this detector, beam and
182  // selection combination exists
183  for(auto const& itr : fSelectionsToUse){
184  if(itr.Detector() == d &&
185  itr.BeamType() == b)
186  return true;
187  }
188 
189  return false;
190  }
191 
192  //---------------------------------------------------------------------------
194  {
195  return this->UsesDetBeamAndSel(md.detector,
197  md.selectionType);
198  }
199 
200  //---------------------------------------------------------------------------
202  cmf::BeamType_t const& b,
203  cmf::SelectionType_t const& s) const
204  {
205  // loop over the selections to use and see if this detector, beam and
206  // selection combination exists
207  for(auto const& itr : fSelectionsToUse){
208  if(itr.Detector() == d &&
209  itr.BeamType() == b){
210  for(auto const& selItr : itr.Selections()){
211  if (selItr == s) return true;
212  else if(cmf::IsNuMuQuantiles(s) &&
213  selItr == cmf::kNuMuSelection) return true;
214  else if(cmf::IsNuESelected(s) &&
215  selItr == cmf::kNuESelection ) return true;
216  }
217  }
218  }
219 
220  return false;
221  }
222 
223  //---------------------------------------------------------------------------
225  {
226  // loop over the selections to use and see if this detector, beam and
227  // selection combination exists
228  for(auto const& itr : fSelectionsToUse){
229  for(auto const& selItr : itr.Selections()){
230  if (selItr == s) return true;
231  else if(cmf::IsNuMuQuantiles(s) &&
232  selItr == cmf::kNuMuSelection) return true;
233  else if(cmf::IsNuESelected(s) &&
234  selItr == cmf::kNuESelection ) return true;
235  }
236  }
237  return false;
238  }
239 }
const XML_Char * name
Definition: expat.h:151
static SelectionUtility * gSU
DetBeamSelSet fSelectionsNotUsed
selections which are not configured
const std::string cSelectionType_Strings[12]
Definition: Constants.h:79
cmf::DetType_t detector
Definition: Structs.h:114
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:376
static bool IsNuMuQuantiles(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:369
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:249
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
bool UsesSelection(cmf::SelectionType_t const &s) const
Float_t d
Definition: plot.C:236
static cmf::BeamType_t PeriodToBeamType(std::string const &str)
std::vector< std::string > get_names() const
static const std::set< cmf::DetType_t > cDetIds({cmf::kNEARDET, cmf::kFARDET})
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
DetBeamSelSet fAllAvailSelections
all available selections
bool UsesDetAndBeam(cmf::MetaData const &md) const
enum cmf::beam_type BeamType_t
const hit & b
Definition: hits.cxx:21
#define LOG_VERBATIM(category)
void Initialize(fhicl::ParameterSet const &pset)
std::set< cmf::SelectionUtility::DetBeamSels > DetBeamSelSet
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