Sample.cxx
Go to the documentation of this file.
1 // CAFAna includes
2 #include "CAFAna/Core/Sample.h"
3 
4 #include "CAFAna/Core/Registry.h"
5 
6 // c++ includes
7 #include <iostream>
8 
9 using std::ostringstream;
10 using std::runtime_error;
11 using std::string;
12 using std::vector;
13 
14 namespace ana {
15  namespace covmx {
16 
17  //-------------------------------------------------------------------------
19  : selection(s), polarity(p), detector(d), quantile(q), axis(nullptr),
20  cut(nullptr), pot(-1), livetime(-1), prediction(nullptr),
21  data(nullptr), cosmic(nullptr) {}
22 
23  //-------------------------------------------------------------------------
24  Sample::Sample(Sample const& sample)
25  : selection(sample.selection), polarity(sample.polarity),
26  detector(sample.detector), quantile(sample.quantile),
27  axis(sample.axis), cut(sample.cut), pot(sample.pot),
28  livetime(sample.livetime), prediction(sample.prediction),
29  data(sample.data), cosmic(sample.cosmic), systMap(sample.systMap)
30  {}
31 
32  //-------------------------------------------------------------------------
33  Sample::Sample(unsigned int id)
34  : axis(nullptr), cut(nullptr), pot(-1), livetime(-1),\
35  prediction(nullptr), data(nullptr), cosmic(nullptr) {
36  selection = (covmx::Selection)((id & (3 << 7)) >> 7);
37  polarity = (covmx::Polarity) ((id & (3 << 5)) >> 5);
38  detector = (covmx::Detector) ((id & (3 << 3)) >> 3);
39  quantile = (covmx::Quantile) (id & 7);
40  }
41 
42  //-------------------------------------------------------------------------
44 
45  //-------------------------------------------------------------------------
46  string Sample::GetSelection() const {
47  vector<string> sel = { "numusel", "nuesel", "ncsel" };
48  return sel[selection];
49  }
50 
51  //-------------------------------------------------------------------------
52  string Sample::GetPolarity() const {
53  vector<string> pol = { "fhc", "rhc" };
54  return pol[polarity];
55  }
56 
57  //-------------------------------------------------------------------------
58  string Sample::GetDetector() const {
59  vector<string> pol = { "neardet", "fardet" };
60  return pol[detector];
61  }
62 
63  //-------------------------------------------------------------------------
64  string Sample::GetQuantile() const {
65  if (quantile == Quantile::kNoQ)
66  throw runtime_error("This sample does not have quantiles.");
67  vector<string> qnt = { "q0", "q1", "q2", "q3" };
68  return qnt[quantile];
69  }
70 
71  //-------------------------------------------------------------------------
72  string Sample::GetName() const {
73  ostringstream name;
74  name << GetSelection() << " " << GetPolarity() << " " << GetDetector();
75  if (quantile != Quantile::kNoQ)
76  name << " " << GetQuantile();
77  return name.str();
78  }
79 
80  //-------------------------------------------------------------------------
81  string Sample::GetLatexName() const {
82  ostringstream name;
83  vector<string> sel = { "CC $\\nu_{\\mu}$", "CC $\\nu_{e}$", "NC" };
84  name << sel[selection];
85  vector<string> pol = { "FHC", "RHC" };
86  name << " " << pol[polarity];
87  vector<string> det = { "ND", "FD" };
88  name << " " << det[detector];
89  if (quantile != kNoQ) name << " Quantile " << quantile+1;
90  return name.str();
91  }
92 
93  //-------------------------------------------------------------------------
94  string Sample::GetTag() const {
95  ostringstream tag;
96  tag << GetSelection() << "_" << GetPolarity() << "_" << GetDetector();
97  if (quantile != Quantile::kNoQ)
98  tag << "_" << GetQuantile();
99  return tag.str();
100  }
101 
102  //-------------------------------------------------------------------------
104  prediction = p;
105  }
106 
107  //-------------------------------------------------------------------------
109  cosmic = s;
110  }
111 
112  //-------------------------------------------------------------------------
114  data = s;
115  }
116 
117  //-------------------------------------------------------------------------
118  const HistAxis* Sample::GetAxis() const {
119  if (!axis) throw runtime_error("Axis not set in sample!");
120  return axis;
121  }
122 
123  //-------------------------------------------------------------------------
125  if (!axis) throw runtime_error("Axis not set in sample!");
126  return axis->GetBinnings()[0];
127  }
128 
129  //-------------------------------------------------------------------------
130  const Cut* Sample::GetCut() const {
131  if (!cut) throw runtime_error("Cut not set in sample!");
132  return cut;
133  }
134 
135  //-------------------------------------------------------------------------
136  double Sample::GetPOT() const {
137  if (pot == -1) throw runtime_error("POT not set in sample!");
138  return pot;
139  }
140 
141  //-------------------------------------------------------------------------
142  double Sample::GetLivetime() const {
143  if (livetime == -1) throw runtime_error("Livetime not set in sample!");
144  return livetime;
145  }
146 
147  //-------------------------------------------------------------------------
149  // For what it's worth, I know having a const member function that
150  // returns a bare pointer to a member is extremely not good. If you
151  // feel strongly about this, please come yell at me and perhaps you'll
152  // inspire me to be better
153  if (!prediction) throw runtime_error("Prediction not set in sample!");
154  return prediction;
155  }
156 
157  //-------------------------------------------------------------------------
159  if (!cosmic) throw runtime_error("Cosmic spectrum not set in sample!");
160  return cosmic;
161  }
162 
163  //-------------------------------------------------------------------------
165  if (!data) throw runtime_error("Data spectrum not set in sample!");
166  return data;
167  }
168 
169  //-------------------------------------------------------------------------
171  SystShifts ret;
172  for (const ISyst* syst : shifts.ActiveSysts()) {
173  if (systMap.count(syst)) {
174  if (systMap.at(syst)) { // If there's a nullptr here, skip it
175  ret.SetShift(systMap.at(syst), shifts.GetShift(syst));
176  }
177  } else {
178  ret.SetShift(syst, shifts.GetShift(syst));
179  }
180  }
181  return ret;
182  } // function Sample::GetSystShifts
183 
184  //-------------------------------------------------------------------------
185  unsigned int Sample::GetID() const
186  {
187  unsigned int id = selection;
188  id <<= 2;
189  id += polarity;
190  id <<= 2;
191  id += detector;
192  id <<= 3;
193  id += quantile;
194  return id;
195 
196  } // function Sample::GetID
197 
198  //-------------------------------------------------------------------------
199  } // namespace covmx
200 } // namespace ana
201 
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
const XML_Char * name
Definition: expat.h:151
std::map< const ISyst *, const ISyst * > systMap
Definition: Sample.h:112
IPrediction * prediction
Definition: Sample.h:108
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
std::string GetQuantile() const
Definition: Sample.cxx:64
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
const HistAxis * axis
Definition: Sample.h:103
const char * p
Definition: xmltok.h:285
std::string GetTag() const
Definition: Sample.cxx:94
Spectrum * data
Definition: Sample.h:109
Encapsulate code to systematically shift a caf::SRProxy.
Definition: ISyst.h:14
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const XML_Char const XML_Char * data
Definition: expat.h:268
std::string GetLatexName() const
Definition: Sample.cxx:81
const XML_Char * s
Definition: expat.h:262
std::string GetPolarity() const
Definition: Sample.cxx:52
Sum up livetimes from individual cosmic triggers.
void SetPrediction(IPrediction *p)
Definition: Sample.cxx:103
Selection selection
Definition: Sample.h:95
std::string GetSelection() const
Definition: Sample.cxx:46
Detector detector
Definition: Sample.h:97
#define pot
T GetShift(const ISyst *syst) const
Float_t d
Definition: plot.C:236
void SetCosmic(Spectrum *s)
Definition: Sample.cxx:108
Sample(Selection s, Polarity p, Detector d, Quantile q=kNoQ)
Definition: Sample.cxx:18
const Cut * cut
Definition: Sample.h:104
unsigned int quantile(std::vector< std::vector< double >> v, float E, float hadEfrac)
Definition: Toy_analyses.C:480
Spectrum * GetCosmic() const
Definition: Sample.cxx:158
double GetPOT() const
Definition: Sample.cxx:136
const std::vector< Binning > & GetBinnings() const
Definition: LabelsAndBins.h:69
const Cut * GetCut() const
Definition: Sample.cxx:130
const Cut cut
Definition: exporter_fd.C:30
std::string GetDetector() const
Definition: Sample.cxx:58
unsigned int GetID() const
Definition: Sample.cxx:185
Binning GetBinning() const
Definition: Sample.cxx:124
Quantile quantile
Definition: Sample.h:98
double livetime
Definition: saveFDMCHists.C:21
double livetime
Definition: Sample.h:106
std::string GetName() const
Definition: Sample.cxx:72
Spectrum * cosmic
Definition: Sample.h:110
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
Spectrum * GetData() const
Definition: Sample.cxx:164
std::vector< const ISyst * > ActiveSysts() const
Definition: SystShifts.cxx:221
void SetData(Spectrum *s)
Definition: Sample.cxx:113
double GetLivetime() const
Definition: Sample.cxx:142
Polarity polarity
Definition: Sample.h:96
IPrediction * GetPrediction() const
Definition: Sample.cxx:148
void SetShift(const ISyst *syst, double shift, bool force=false)
Definition: SystShifts.cxx:81
const HistAxis * GetAxis() const
Definition: Sample.cxx:118
SystShifts GetSystShifts(SystShifts shifts) const
Definition: Sample.cxx:170
enum BeamMode string