Structs.cxx
Go to the documentation of this file.
1 //
2 // Structs.cxx
3 // novasoft-mrb
4 //
5 // Created by Brian Rebel on 5/21/16.
6 // Copyright © 2016 Brian Rebel. All rights reserved.
7 //
8 
11 
12 namespace cmf{
13 
14  //----------------------------------------------------------------------------
16  {
17  long key = 0;
18 
19  // check for the detector
20  if (str.find("MINOSNear") != std::string::npos) key += cmf::DetectorTypeKey(cmf::kMINOSNEAR);
21  else if(str.find("MINOSFar" ) != std::string::npos) key += cmf::DetectorTypeKey(cmf::kMINOSFAR );
22  else if(str.find("Near") != std::string::npos) key += cmf::DetectorTypeKey(cmf::kNEARDET );
23  else if(str.find("Far" ) != std::string::npos) key += cmf::DetectorTypeKey(cmf::kFARDET );
24 
25  // check the period
26  if(str.find("Period") != std::string::npos)
27  key += cmf::PeriodKey(std::stol(str.substr(str.find("Period") + 6, std::string::npos)));
28  else if(str.find("P") != std::string::npos)
29  key += cmf::PeriodKey(std::stol(str.substr(str.find("P") + 1, std::string::npos)));
30 
31  // check the file type
32  if (str.find("Beam" ) != std::string::npos) key += cmf::FileTypeKey(cmf::kBeam );
33  else if(str.find("TauSwap" ) != std::string::npos) key += cmf::FileTypeKey(cmf::kTauSwap );
34  else if(str.find("FluxSwap" ) != std::string::npos) key += cmf::FileTypeKey(cmf::kSwap );
35  else if(str.find("RockFluxSwap") != std::string::npos) key += cmf::FileTypeKey(cmf::kRockFluxSwap);
36  else if(str.find("RockNonSwap" ) != std::string::npos) key += cmf::FileTypeKey(cmf::kRockNonSwap );
37  else if(str.find("Data" ) != std::string::npos) key += cmf::FileTypeKey(cmf::kDataFile );
38 
39  // check for a selection
40  if (str.find("NuMuSelQ1" ) != std::string::npos) key += cmf::SelectionTypeKey(cmf::kNuMuSelectionQ1 );
41  else if(str.find("NuMuSelQ2" ) != std::string::npos) key += cmf::SelectionTypeKey(cmf::kNuMuSelectionQ2 );
42  else if(str.find("NuMuSelQ3" ) != std::string::npos) key += cmf::SelectionTypeKey(cmf::kNuMuSelectionQ3 );
43  else if(str.find("NuMuSelQ4" ) != std::string::npos) key += cmf::SelectionTypeKey(cmf::kNuMuSelectionQ4 );
44  else if(str.find("NuMuSel" ) != std::string::npos) key += cmf::SelectionTypeKey(cmf::kNuMuSelection );
45  else if(str.find("NuESel_AllPID" ) != std::string::npos) key += cmf::SelectionTypeKey(cmf::kNuESelection );
46  else if(str.find("NuESel_LowPID" ) != std::string::npos) key += cmf::SelectionTypeKey(cmf::kNuESelectionLowPID );
47  else if(str.find("NuESel_MidPID" ) != std::string::npos) key += cmf::SelectionTypeKey(cmf::kNuESelectionMidPID );
48  else if(str.find("NuESel_HighPID" ) != std::string::npos) key += cmf::SelectionTypeKey(cmf::kNuESelectionHighPID );
49  else if(str.find("NuESel_Peripheral") != std::string::npos) key += cmf::SelectionTypeKey(cmf::kNuESelectionPeripheral);
50 
51  // check for an interaction type
52  if (str.find("NuMuCC" ) != std::string::npos) key += cmf::InteractionTypeKey(cmf::kNuMuCC );
53  else if(str.find("NuMuBarCC" ) != std::string::npos) key += cmf::InteractionTypeKey(cmf::kNuMuBarCC );
54  else if(str.find("NuECC" ) != std::string::npos) key += cmf::InteractionTypeKey(cmf::kNuECC );
55  else if(str.find("NuEBarCC" ) != std::string::npos) key += cmf::InteractionTypeKey(cmf::kNuEBarCC );
56  else if(str.find("NuTauCC" ) != std::string::npos) key += cmf::InteractionTypeKey(cmf::kNuTauCC );
57  else if(str.find("NuTauBarCC") != std::string::npos) key += cmf::InteractionTypeKey(cmf::kNuTauBarCC);
58  else if(str.find("NC" ) != std::string::npos) key += cmf::InteractionTypeKey(cmf::kNC );
59  else if(str.find("CosmicMuon") != std::string::npos) key += cmf::InteractionTypeKey(cmf::kCosmicMuon);
60 
61  // check if this is data or MC, multiply by +/- 1 depending on the answer
62  if (str.find("MC") != std::string::npos) key *= 1;
63  else if(str.find("Data") != std::string::npos) key *= -1;
64 
65  return key;
66  }
67 
68  //---------------------------------------------------------------------------
69  long PeriodStringToInt(std::string const& epochStr){
70  size_t first = epochStr.find_first_of("abcdefghijklmnopqrstuvwxyz");
71  if(first != std::string::npos){
72  LOG_WARNING("MetaData")
73  << "use of subperiods is deprecated, only full periods are used";
74 
75  //auto alpha = epochStr.substr(first, first + 1);
76  //return (std::stol(epochStr.substr(0, first).c_str(), nullptr, 0) * 1000 + static_cast<int>(*(alpha.c_str())));
77  }
78 
79  LOG_DEBUG("MetaData")
80  << epochStr
81  << " "
82  << std::stol(epochStr.substr(0, epochStr.length()).c_str(), nullptr, 0);
83 
84  return std::stol(epochStr.substr(0, epochStr.length()).c_str(), nullptr, 0);
85  }
86 
87  //----------------------------------------------------------------------------
89  : isMC (false)
92  , selectionType (kUnknownSelection)
93  , interactionType(kUnknownInteraction)
94  , period (0)
95  {}
96 
97  //----------------------------------------------------------------------------
98  MetaData::MetaData(bool const& mc,
99  cmf::DetType_t const& det,
100  cmf::FileType_t const& ft,
101  cmf::SelectionType_t const& st,
102  cmf::InteractionType_t const& it,
103  std::string const& ep)
104  : isMC (mc)
105  , detector (det)
106  , fileType (ft)
107  , selectionType (st)
108  , interactionType(it)
109  {
111  }
112 
113  //----------------------------------------------------------------------------
114  MetaData::MetaData(bool const& mc,
115  cmf::DetType_t const& det,
116  cmf::FileType_t const& ft,
117  cmf::SelectionType_t const& st,
118  cmf::InteractionType_t const& it,
119  int const& ep)
120  : isMC (mc)
121  , detector (det)
122  , fileType (ft)
123  , selectionType (st)
124  , interactionType(it)
125  , period (ep)
126  {}
127 
128  //----------------------------------------------------------------------------
130  {
131  return MetaDataLite(this->detector, this->selectionType, this->Period());
132  }
133 
134  //----------------------------------------------------------------------------
136  {
137  std::string outType = (this->DetectorString() +
138  this->PeriodString() +
140 
141  if(this->isMC){
142  outType.insert(0, "MC");
143  outType += cmf::cFileTypeStrings[fileType];
144  }
145  else
146  outType.insert(0, "Data");
147 
149 
150  // this is not grouped with the other MC test to have the interaction type
151  // be the last thing in the string
152  if(this->isMC)
154 
155  return outType;
156  }
157 
158  //----------------------------------------------------------------------------
160  {
161  std::string outType("Data");
162  if(this->isMC){
163  outType = "MC";
164  outType += " " + cmf::cFileTypeStrings_Latex[fileType];
167  }
168 
169  if(detector == cmf::kFARDET ||
170  detector == cmf::kNEARDET ||
172  detector == cmf::kMINOSFAR ) outType += " " + cmf::cDetType_Strings[detector];
173  else outType += " " + cmf::cDetType_Strings[cmf::kUnknownDet];
174 
175  outType += this->PeriodString();
176 
177  outType += " " + cmf::cBeamType_LatexStrings[this->BeamType()];
178 
179  return outType;
180  }
181 
182 
183  //----------------------------------------------------------------------------
185  {
186 
187  // NOvA Period and Epoch naming scheme from:
188  // https://cdcvs.fnal.gov/redmine/projects/novaart/wiki/Period_and_Epoch_Naming
190 
191  LOG_DEBUG("UnknownBeamType")
192  << "period : "
193  << period
194  << " Cannot identify beam type";
195 
196  return beam;
197  }
198 
199  //----------------------------------------------------------------------------
201  {
203  }
204 
205  //----------------------------------------------------------------------------
206  long MetaData::Key() const
207  {
208  return ( this->MCKey() *
209  (this->DetectorKey() +
210  this->FileKey() +
211  this->SelectionKey() +
212  this->InteractionKey() +
213  this->PeriodKey()
214  )
215  );
216  }
217 
218  //----------------------------------------------------------------------------
220  {
221  return cmf::IsNuMuQuantiles(this->selectionType);
222  }
223 
224  //----------------------------------------------------------------------------
226  {
227  return cmf::IsNuMuSelected(this->selectionType);
228  }
229 
230  //----------------------------------------------------------------------------
232  {
233  return cmf::IsNuESelected(this->selectionType);
234  }
235 
236  //----------------------------------------------------------------------------
238  {
239  return (this->selectionType == cmf::kNCSelection);
240  }
241 
242  //----------------------------------------------------------------------------
244  {
245  return (other.isMC == this->isMC &&
246  other.detector == this->detector &&
247  other.fileType == this->fileType &&
248  other.selectionType == this->selectionType &&
249  other.interactionType == this->interactionType &&
250  other.period == this->period);
251  }
252 
253  //----------------------------------------------------------------------------
254  bool MetaData::operator<(const MetaData& other) const
255  {
256  return this->Key() < other.Key();
257  }
258 
259  //----------------------------------------------------------------------------
263  , period(0)
264  {}
265 
266  //----------------------------------------------------------------------------
268  cmf::SelectionType_t const& st,
269  std::string const& ep)
270  : detector (det)
271  , selectionType (st)
272  {
274  }
275 
276  //----------------------------------------------------------------------------
278  {
279  return ("Period" + std::to_string(period));
280  }
281 
282  //----------------------------------------------------------------------------
284  {
285  std::string outType;
286 
287  if(detector == cmf::kFARDET ||
288  detector == cmf::kNEARDET ||
291  else outType += cmf::cDetType_Strings[cmf::kUnknownDet];
292 
294  outType += this->PeriodString();
295 
296  return outType;
297  }
298 
299  //----------------------------------------------------------------------------
301  {
302  return (other.detector == this->detector &&
303  other.selectionType == this->selectionType &&
304  other.period == this->period);
305  }
306 
307  //----------------------------------------------------------------------------
309  {
310  long thisNum = (this->detector * 10000000 +
311  this->selectionType * 100000 +
312  this->period);
313  long otherNum = (other.detector * 10000000 +
314  other.selectionType * 100000 +
315  other.period);
316 
317  return thisNum < otherNum;
318  }
319 
320  //----------------------------------------------------------------------------
322  : totalPOT (0.)
323  , goodPOT (0.)
324  , liveTime (0.)
325  , totalNumSpills(0)
326  , numGoodSpills (0)
327  {}
328 
329  //----------------------------------------------------------------------------
330  SpillSummary::SpillSummary(double const& totPOT,
331  double const& gPOT,
332  double const& lt,
333  unsigned long int const& totSpill,
334  unsigned long int const& goodSpill)
335  : totalPOT (totPOT )
336  , goodPOT (gPOT )
337  , liveTime (lt )
338  , totalNumSpills(totSpill )
339  , numGoodSpills (goodSpill)
340  {}
341 
342  //----------------------------------------------------------------------------
344  {
345  totalPOT = 0.;
346  goodPOT = 0.;
347  liveTime = 0.;
348  totalNumSpills = 0;
349  numGoodSpills = 0;
350  }
351 
352  //----------------------------------------------------------------------------
354  {
355  totalPOT += o.totalPOT;
356  goodPOT += o.goodPOT;
357  liveTime += o.liveTime;
360  }
361 
362  //----------------------------------------------------------------------------
364  {
365  totalPOT *= f;
366  goodPOT *= f;
367  liveTime *= f;
368  totalNumSpills *= f;
369  numGoodSpills *= f;
370  }
371 
372 } // end namespace
long StringToKey(std::string const &str)
Definition: Structs.cxx:15
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::string ToStringLatex() const
Definition: Structs.cxx:159
void operator+=(SpillSummary const &o)
Definition: Structs.cxx:353
enum cmf::interaction_type InteractionType_t
long DetectorKey() const
Definition: Structs.h:121
double lt
static long SelectionTypeKey(cmf::SelectionType_t const &st)
Definition: StaticFuncs.h:19
set< int >::iterator it
const std::string cSelectionType_Strings[12]
Definition: Constants.h:93
long Period() const
Definition: Structs.h:128
cmf::DetType_t detector
Definition: Structs.h:114
static long DetectorTypeKey(cmf::DetType_t const &det)
Definition: StaticFuncs.h:15
unsigned long int totalNumSpills
Definition: Structs.h:188
double liveTime
Definition: Structs.h:187
cmf::MetaDataLite LiteMD() const
Definition: Structs.cxx:129
static long DetectorBeamSelectionTypesToKey(cmf::DetType_t const &det, cmf::BeamType_t const &bt, cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:58
long DetectorBeamSelectionKey() const
Definition: Structs.cxx:200
long PeriodKey() const
Definition: Structs.h:122
enum cmf::det_type DetType_t
std::string PeriodString() const
Definition: Structs.h:162
const std::string cFileTypeStrings_Latex[10]
Definition: Constants.h:187
long SelectionKey() const
Definition: Structs.h:124
cmf::SelectionType_t selectionType
Definition: Structs.h:84
enum cmf::sel_type SelectionType_t
void operator*=(float f)
Definition: Structs.cxx:363
long MCKey() const
Definition: Structs.h:120
const std::string cInteractionType_LatexStrings[11]
Definition: Constants.h:137
long PeriodStringToInt(std::string const &epochStr)
Definition: Structs.cxx:69
static bool IsNuESelected(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:374
static bool IsNuMuQuantiles(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:367
fileType
Definition: mkDefs.py:113
std::string DetectorString() const
Definition: Structs.h:151
long Key() const
Definition: Structs.cxx:206
bool operator<(const MetaDataLite &other) const
Definition: Structs.cxx:308
bool operator==(MetaData const &other) const
Definition: Structs.cxx:243
static bool IsNuMuSelected(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:360
const std::string cInteractionType_Strings[11]
Definition: Constants.h:149
const std::string cFileTypeStrings[10]
Definition: Constants.h:176
std::string PeriodString() const
Definition: Structs.cxx:277
long FileKey() const
Definition: Structs.h:123
cmf::SelectionType_t selectionType
Definition: Structs.h:116
static long PeriodKey(long const &ep)
Definition: StaticFuncs.h:16
unsigned long int numGoodSpills
Definition: Structs.h:189
bool IsNuMuSelected() const
Definition: Structs.cxx:225
bool operator<(MetaData const &other) const
Definition: Structs.cxx:254
static cmf::BeamType_t PeriodToBeamType(std::string const &str)
cmf::DetType_t detector
Definition: Structs.h:83
bool IsNuMuQuantiles() const
Definition: Structs.cxx:219
static long InteractionTypeKey(cmf::InteractionType_t const &it)
Definition: StaticFuncs.h:20
std::string ToString() const
Definition: Structs.cxx:283
#define LOG_WARNING(category)
std::string ToString() const
Definition: Structs.cxx:135
Module to combine a set of results into a single file currently only does one data product type at a ...
Definition: Event.cxx:24
cmf::FileType_t fileType
Definition: Structs.h:115
double goodPOT
Definition: Structs.h:186
long InteractionKey() const
Definition: Structs.h:125
static long FileTypeKey(cmf::FileType_t const &ft)
Definition: StaticFuncs.h:17
enum cmf::beam_type BeamType_t
long period
Definition: Structs.h:118
cmf::BeamType_t BeamType() const
Definition: Structs.cxx:184
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
const std::string cBeamType_LatexStrings[4]
Definition: Constants.h:56
cmf::InteractionType_t interactionType
Definition: Structs.h:117
const std::string cDetType_Strings[5]
Definition: Constants.h:29
const std::string cBeamType_Strings[4]
Definition: Constants.h:51
const std::string cSelectionType_LatexStrings[12]
Definition: Constants.h:106
double totalPOT
Definition: Structs.h:185
bool IsNuESelected() const
Definition: Structs.cxx:231
bool IsNCSelected() const
Definition: Structs.cxx:237
bool operator==(const MetaDataLite &other) const
Definition: Structs.cxx:300
enum cmf::file_type FileType_t
enum BeamMode string