Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
cmf::SelectionUtility Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-02/CovarianceMatrixFit/utilities/SelectionUtility.h"

Classes

struct  DetBeamSels
 associates each detector-beam pair to a set of selections More...
 

Public Types

typedef std::set< cmf::SelectionUtility::DetBeamSelsDetBeamSelSet
 

Public Member Functions

void Initialize (fhicl::ParameterSet const &pset)
 
void PrintSelections (DetBeamSelSet dbs)
 print a given detector-selection map More...
 
const DetBeamSelSetAllAvailSelections ()
 
const DetBeamSelSetSelectionsToUse ()
 
std::vector< cmf::MetaDataSelectionsToUseAsMetaData (bool isMC=true) const
 
std::vector< long > SelectionsToUseAsKeys () const
 
const DetBeamSelSetSelectionsNotUsed ()
 
void SelectionsUsedOfType (cmf::SelectionType_t const &sel, DetBeamSelSet &sels)
 
bool UsesDetAndBeam (cmf::MetaData const &md) const
 
bool UsesDetAndBeam (cmf::DetType_t const &d, cmf::BeamType_t const &b) const
 
bool UsesDetBeamAndSel (cmf::MetaData const &md) const
 
bool UsesDetBeamAndSel (cmf::DetType_t const &d, cmf::BeamType_t const &b, cmf::SelectionType_t const &s) const
 
bool UsesSelection (cmf::SelectionType_t const &s) const
 

Static Public Member Functions

static SelectionUtilityInstance ()
 

Private Member Functions

 SelectionUtility ()
 
 ~SelectionUtility ()
 
void DetermineUnusedSelections ()
 determine which selections were not configured from fhicl More...
 

Private Attributes

DetBeamSelSet fAllAvailSelections
 all available selections More...
 
DetBeamSelSet fSelectionsToUse
 selections which are configured More...
 
DetBeamSelSet fSelectionsNotUsed
 selections which are not configured More...
 

Detailed Description

Definition at line 27 of file SelectionUtility.h.

Member Typedef Documentation

Definition at line 63 of file SelectionUtility.h.

Constructor & Destructor Documentation

cmf::SelectionUtility::SelectionUtility ( )
private

Definition at line 20 of file SelectionUtility.cxx.

Referenced by Instance().

21  {
22  }
cmf::SelectionUtility::~SelectionUtility ( )
private

Definition at line 25 of file SelectionUtility.cxx.

26  {
27  }

Member Function Documentation

const cmf::SelectionUtility::DetBeamSelSet & cmf::SelectionUtility::AllAvailSelections ( )
inline

Definition at line 106 of file SelectionUtility.h.

References fAllAvailSelections.

107  {
108  if (fAllAvailSelections.size() == 0)
109  {
110  throw cet::exception("SelectionUtility")
111  << "fAllAvailSelections has size 0, which can't be right.";
112  }
113  return fAllAvailSelections;
114  }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
DetBeamSelSet fAllAvailSelections
all available selections
void cmf::SelectionUtility::DetermineUnusedSelections ( )
private

determine which selections were not configured from fhicl

Definition at line 122 of file SelectionUtility.cxx.

References POTSpillRate::beam, cmf::cBeamTypes(), cmf::cDetIds(), fillBadChanDBTables::det, fAllAvailSelections, fSelectionsNotUsed, fSelectionsToUse, kFHC, cmf::kNEARDET, cmf::SelectionUtility::DetBeamSels::sels, ana::sels, and string.

Referenced by Initialize().

122  {
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  }
DetBeamSelSet fSelectionsNotUsed
selections which are not configured
const Cut sels[kNumSels]
Definition: vars.h:44
DetBeamSelSet fSelectionsToUse
selections which are configured
static const std::set< cmf::DetType_t > cDetIds({cmf::kNEARDET, cmf::kFARDET})
DetBeamSelSet fAllAvailSelections
all available selections
static const std::set< cmf::BeamType_t > cBeamTypes({kFHC, kRHC})
enum BeamMode string
void cmf::SelectionUtility::Initialize ( fhicl::ParameterSet const &  dbsParSet)

from fhicl, define the selections which have been configured, all possible selections, and those which have not been configured

Definition at line 32 of file SelectionUtility.cxx.

References POTSpillRate::beam, cmf::cBeamTypes(), cmf::cDetIds(), fillBadChanDBTables::det, DetermineUnusedSelections(), e, fAllAvailSelections, fSelectionsNotUsed, fSelectionsToUse, fhicl::ParameterSet::get(), fhicl::ParameterSet::get_names(), cmf::kFARDET, cmf::kFHC, cmf::kNCSelection, cmf::kNEARDET, cmf::kNuESelectionHighPID, cmf::kNuESelectionLowPID, cmf::kNuESelectionPeripheral, cmf::kNuMuSelection, cmf::kNuMuSelectionQ1, cmf::kNuMuSelectionQ2, cmf::kNuMuSelectionQ3, cmf::kNuMuSelectionQ4, cmf::kRHC, LOG_VERBATIM, PrintSelections(), string, and cmf::StringToSelectionType().

Referenced by cmf::PredictionLibraryMaker::PredictionLibraryMaker(), cmf::CMFSpectraMaker::reconfigure(), cmf::CovarianceMatrixMaker::reconfigure(), cmf::RandomUniverses::reconfigure(), cmf::FitFeldmanCousinsPoint::reconfigure(), cmf::ContourFromLibrary::reconfigure(), and cmf::CovarianceMatrixFitter::~CovarianceMatrixFitter().

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  }
const XML_Char * name
Definition: expat.h:151
DetBeamSelSet fSelectionsNotUsed
selections which are not configured
enum cmf::det_type DetType_t
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
void DetermineUnusedSelections()
determine which selections were not configured from fhicl
void PrintSelections(DetBeamSelSet dbs)
print a given detector-selection map
static cmf::SelectionType_t StringToSelectionType(std::string const &str)
Definition: StaticFuncs.h:249
T get(std::string const &key) const
Definition: ParameterSet.h:231
DetBeamSelSet fSelectionsToUse
selections which are configured
static const std::set< cmf::DetType_t > cDetIds({cmf::kNEARDET, cmf::kFARDET})
DetBeamSelSet fAllAvailSelections
all available selections
enum cmf::beam_type BeamType_t
#define LOG_VERBATIM(category)
Float_t e
Definition: plot.C:35
static const std::set< cmf::BeamType_t > cBeamTypes({kFHC, kRHC})
enum BeamMode string
SelectionUtility * cmf::SelectionUtility::Instance ( )
static
void cmf::SelectionUtility::PrintSelections ( DetBeamSelSet  dbs)

print a given detector-selection map

Definition at line 150 of file SelectionUtility.cxx.

References om::cout, cmf::cSelectionType_Strings, allTimeWatchdog::endl, kFHC, cmf::kNEARDET, and string.

Referenced by Initialize().

150  {
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  }
const std::string cSelectionType_Strings[12]
Definition: Constants.h:79
OStream cout
Definition: OStream.cxx:6
enum BeamMode string
const cmf::SelectionUtility::DetBeamSelSet & cmf::SelectionUtility::SelectionsNotUsed ( )
inline

Definition at line 183 of file SelectionUtility.h.

References fSelectionsNotUsed.

184  { return fSelectionsNotUsed; }
DetBeamSelSet fSelectionsNotUsed
selections which are not configured
const cmf::SelectionUtility::DetBeamSelSet & cmf::SelectionUtility::SelectionsToUse ( )
inline

Definition at line 117 of file SelectionUtility.h.

References fSelectionsToUse.

Referenced by cmf::CalibSyst::LoadCalibSystRatios(), and cmf::EventListManipulator::SetExposures().

118  {
119  if (fSelectionsToUse.size() == 0)
120  {
121  throw cet::exception("SelectionUtility")
122  << "fSelectionsToUse has size 0. Have you correctly configured SelectionsToUse in fhicl?";
123  }
124 
125  return fSelectionsToUse;
126  }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
DetBeamSelSet fSelectionsToUse
selections which are configured
std::vector< long > cmf::SelectionUtility::SelectionsToUseAsKeys ( ) const
inline

Definition at line 145 of file SelectionUtility.h.

References cmf::DetectorBeamSelectionTypesToKey(), fSelectionsToUse, and caf_analysis::keys.

146  {
147  std::vector<long> keys;
148  for(auto const& itr : fSelectionsToUse){
149  for(auto const& sel : itr.Selections())
150  keys.emplace_back(cmf::DetectorBeamSelectionTypesToKey(itr.Detector(), itr.BeamType(), sel));
151  }
152  return std::move(keys);
153  }
keys
Reco plots.
Definition: caf_analysis.py:46
static long DetectorBeamSelectionTypesToKey(cmf::DetType_t const &det, cmf::BeamType_t const &bt, cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:62
DetBeamSelSet fSelectionsToUse
selections which are configured
std::vector< cmf::MetaData > cmf::SelectionUtility::SelectionsToUseAsMetaData ( bool  isMC = true) const
inline

Definition at line 129 of file SelectionUtility.h.

References cmf::BeamToPeriod(), fSelectionsToUse, cmf::kUnknownFileType, and cmf::kUnknownInteraction.

130  {
131  std::vector<cmf::MetaData> mds;
132  for(auto const& itr : fSelectionsToUse){
133  for(auto const& sel : itr.Selections())
134  mds.emplace_back(isMC,
135  itr.Detector(),
137  sel,
139  cmf::BeamToPeriod(itr.BeamType()));
140  }
141  return std::move(mds);
142  }
DetBeamSelSet fSelectionsToUse
selections which are configured
static int BeamToPeriod(cmf::BeamType_t const &beam)
Definition: StaticFuncs.h:240
void cmf::SelectionUtility::SelectionsUsedOfType ( cmf::SelectionType_t const &  sel,
DetBeamSelSet sels 
)
inline

Definition at line 156 of file SelectionUtility.h.

References fSelectionsToUse, cmf::IsNuESelected(), and cmf::IsNuMuSelected().

Referenced by cmf::CovarianceFitHelper::MakeDataMCCanv().

158  {
159  if (fSelectionsToUse.size() == 0)
160  {
161  throw cet::exception("SelectionUtility")
162  << "fSelectionsToUse has size 0, cannot find any of any type";
163  }
164 
165  // loop over the selections used and return those of the requested type
166  sels.clear();
167  std::set<cmf::SelectionType_t> subSetOfSels;
168  for(auto const& itr : fSelectionsToUse){
169  subSetOfSels.clear();
170  for(auto const& selItr : itr.Selections()){
171  if(cmf::IsNuMuSelected(selItr) && cmf::IsNuMuSelected(sel))
172  subSetOfSels.insert(selItr);
173  else if(cmf::IsNuESelected(selItr) && cmf::IsNuESelected(sel))
174  subSetOfSels.insert(selItr);
175  else if(sel == selItr)
176  subSetOfSels.insert(selItr);
177  }
178  sels.emplace(itr.Detector(), itr.BeamType(), subSetOfSels);
179  }
180  }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
static bool IsNuESelected(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:376
static bool IsNuMuSelected(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:362
const Cut sels[kNumSels]
Definition: vars.h:44
DetBeamSelSet fSelectionsToUse
selections which are configured
bool cmf::SelectionUtility::UsesDetAndBeam ( cmf::MetaData const &  md) const

Definition at line 171 of file SelectionUtility.cxx.

References cmf::MetaData::detector, cmf::MetaData::PeriodString(), and cmf::PeriodToBeamType().

Referenced by cmf::ChiSqrCalculator::FindReducedMatrixBin().

172  {
173  return this->UsesDetAndBeam(md.detector,
174  cmf::PeriodToBeamType(md.PeriodString()));
175  }
static cmf::BeamType_t PeriodToBeamType(std::string const &str)
bool UsesDetAndBeam(cmf::MetaData const &md) const
bool cmf::SelectionUtility::UsesDetAndBeam ( cmf::DetType_t const &  d,
cmf::BeamType_t const &  b 
) const

Definition at line 178 of file SelectionUtility.cxx.

References b, and fSelectionsToUse.

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  }
DetBeamSelSet fSelectionsToUse
selections which are configured
Float_t d
Definition: plot.C:236
const hit & b
Definition: hits.cxx:21
bool cmf::SelectionUtility::UsesDetBeamAndSel ( cmf::MetaData const &  md) const

Definition at line 193 of file SelectionUtility.cxx.

References cmf::MetaData::detector, cmf::MetaData::PeriodString(), cmf::PeriodToBeamType(), and cmf::MetaData::selectionType.

Referenced by cmf::EventListManipulator::UseEventsFromMetaData().

194  {
195  return this->UsesDetBeamAndSel(md.detector,
196  cmf::PeriodToBeamType(md.PeriodString()),
197  md.selectionType);
198  }
static cmf::BeamType_t PeriodToBeamType(std::string const &str)
bool UsesDetBeamAndSel(cmf::MetaData const &md) const
bool cmf::SelectionUtility::UsesDetBeamAndSel ( cmf::DetType_t const &  d,
cmf::BeamType_t const &  b,
cmf::SelectionType_t const &  s 
) const

Definition at line 201 of file SelectionUtility.cxx.

References b, fSelectionsToUse, cmf::IsNuESelected(), cmf::IsNuMuQuantiles(), cmf::kNuESelection, and cmf::kNuMuSelection.

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  }
static bool IsNuESelected(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:376
static bool IsNuMuQuantiles(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:369
const XML_Char * s
Definition: expat.h:262
DetBeamSelSet fSelectionsToUse
selections which are configured
Float_t d
Definition: plot.C:236
const hit & b
Definition: hits.cxx:21
bool cmf::SelectionUtility::UsesSelection ( cmf::SelectionType_t const &  s) const

Definition at line 224 of file SelectionUtility.cxx.

References fSelectionsToUse, cmf::IsNuESelected(), cmf::IsNuMuQuantiles(), cmf::kNuESelection, and cmf::kNuMuSelection.

Referenced by cmf::EventListManipulator::Deserialize(), and cmf::ChiSqrCalculator::FindReducedMatrixBin().

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  }
static bool IsNuESelected(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:376
static bool IsNuMuQuantiles(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:369
const XML_Char * s
Definition: expat.h:262
DetBeamSelSet fSelectionsToUse
selections which are configured

Member Data Documentation

DetBeamSelSet cmf::SelectionUtility::fAllAvailSelections
private

all available selections

Definition at line 99 of file SelectionUtility.h.

Referenced by AllAvailSelections(), DetermineUnusedSelections(), and Initialize().

DetBeamSelSet cmf::SelectionUtility::fSelectionsNotUsed
private

selections which are not configured

Definition at line 101 of file SelectionUtility.h.

Referenced by DetermineUnusedSelections(), Initialize(), and SelectionsNotUsed().

DetBeamSelSet cmf::SelectionUtility::fSelectionsToUse
private

The documentation for this class was generated from the following files: