10 #include "CAFAna/Core/Binning.h" 11 #include "CAFAna/Core/Var.h" 13 #include "CAFAna/Core/Cut.h" 34 throw std::runtime_error(
"Attempt to set loaders while SpecHelper is not unloaded.");
36 if (datasets.size() != dataset_labels.size()){
37 std::cerr <<
"Number of datasets not equal to number of dataset labels. Please fix that." <<
std::endl;
42 for (
unsigned int idataset = 0; idataset <
fNLoaders; idataset++){
54 throw std::runtime_error(
"Attempt to set loaders while SpecHelper is not unloaded.");
56 if (loaders.size() != loader_labels.size()){
62 for (
unsigned int iloader = 0; iloader <
fNLoaders; iloader++){
64 if (!loader || loader == NULL)
65 throw std::runtime_error(
"Attempt to use a non-existent loader: " + loader_labels[iloader]);
75 throw std::runtime_error(
"Attempt to set spill cuts sometime NOT right after setting loaders. Only allow setting spill cuts IMMEDIATELY after setting loaders.");
82 for (
unsigned int iloader = 0; iloader <
fNLoaders; iloader++)
83 fLoaders[iloader]->SetSpillCut(spillcuts[iloader]);
90 throw std::runtime_error(
"Attempt to set spill cuts sometime NOT right after setting loaders. Only allow setting spill cuts IMMEDIATELY after setting loaders.");
92 for (
unsigned int iloader = 0; iloader <
fNLoaders; iloader++)
99 for (
unsigned int iloader = 0; iloader <
fNLoaders; iloader++)
106 std::vector<SpectrumLoaderBase*> loaderList;
107 for (
unsigned int ilabel = 0; ilabel < loader_labels.size(); ilabel++){
110 throw std::runtime_error(
"Could not find loader with label \"" + loader_labels[ilabel] +
"\". Skipping.");
111 loaderList.push_back(loader);
116 bool ana::SpectrumHandler::SetVars(
const std::vector<Var>
vars,
const std::vector<std::string> var_labels,
const std::vector<std::string> var_titles,
const std::vector<Binning> var_bins){
118 throw std::runtime_error(
"Attempt to set the vars too late. The spectrums are either ready, or already had go() called on them.");
120 if (vars.size() != var_labels.size() || vars.size() != var_titles.size() || vars.size() != var_bins.size()){
121 std::cerr <<
"Number of vars not equal to number of var labels / titles. Fix that." <<
std::endl;
137 throw std::runtime_error(
"Attempt to set the vars too late. The spectrums are either ready, or already had go() called on them.");
139 if (cuts.size() != cut_labels.size()){
140 std::cerr <<
"Number of cuts not equal to number of cut labels. Fix that." <<
std::endl;
154 throw std::runtime_error(
"Attempt to set the vars too late. The spectrums are either ready, or already had go() called on them.");
156 if (weights.size() != weight_labels.size()){
157 std::cerr <<
"Number of Weights not equal to number of weight labels. Fix that." <<
std::endl;
171 throw std::runtime_error(
"Attempt to set the vars too late. The spectrums are either ready, or already had go() called on them.");
173 if (shifts.size() != shift_labels.size()){
174 std::cerr <<
"Number of shifts not equal to number of shift labels. Ignoring shifts." <<
std::endl;
188 throw std::runtime_error(
"Attempt to set the vars too late. The spectrums are either ready, or already had go() called on them.");
190 if (haxes.size() != haxis_labels.size()){
191 std::cerr <<
"Number of HistAxis not equal to number of HistAxis labels. Ignoring HistAxes." <<
std::endl;
213 bool allready = loadersgood && (varsgood || histaxesgood) && cutsgood && weightsgood && shiftsgood;
229 std::cout <<
"Spectrum Helper: Creating all spectrum definitions.\n\tThere are a total of " <<
std::to_string(numSpec) <<
" Spectrums from:" <<
247 for (
unsigned int iloader = 0; iloader <
fNLoaders; iloader++){
248 std::vector<std::vector<std::vector<std::vector<Spectrum* > > > > lspecs;
250 for (
unsigned int ivar = 0; ivar <
fNVars; ivar++){
251 std::vector<std::vector<std::vector<Spectrum* > > > vspecs;
253 for (
unsigned int icut = 0; icut <
fNCuts; icut++){
254 std::vector<std::vector<Spectrum* > > cspecs;
256 for (
unsigned int iweight = 0; iweight <
fNWeights; iweight++){
257 std::vector<Spectrum* > wspecs;
259 for (
unsigned int ishift = 0; ishift <
fNShifts; ishift++)
268 cspecs.push_back(wspecs);
270 vspecs.push_back(cspecs);
272 lspecs.push_back(vspecs);
280 for (
unsigned int iloader = 0; iloader <
fNLoaders; iloader++){
281 std::vector<std::vector<std::vector<std::vector<Spectrum* > > > > lspecs;
283 for (
unsigned int ihaxis = 0; ihaxis <
fNHistAxes; ihaxis++){
284 std::vector<std::vector<std::vector<Spectrum* > > > hspecs;
286 for (
unsigned int icut = 0; icut <
fNCuts; icut++){
287 std::vector<std::vector<Spectrum* > > cspecs;
289 for (
unsigned int iweight = 0; iweight <
fNWeights; iweight++){
290 std::vector<Spectrum* > wspecs;
292 for (
unsigned int ishift = 0; ishift <
fNShifts; ishift++)
299 cspecs.push_back(wspecs);
301 hspecs.push_back(cspecs);
303 lspecs.push_back(hspecs);
314 for (
unsigned int iloader = 0; iloader <
fNLoaders; iloader++){
316 if (!loader || loader == NULL)
317 throw std::runtime_error(
"Trying to call Go() on Loader[" +
std::to_string(iloader) +
"], which was not defined.");
318 else if (loader->
Gone()){
346 std::cerr <<
"You didn't create the spectrums and fill them yet!!! Create them, and call Go() on loaders." <<
std::endl;
350 if (!fout || fout == NULL || fout->IsZombie()){
356 for (
unsigned int iloader = 0; iloader <
fNLoaders; iloader++){
359 TDirectory* loaderDir = fout->GetDirectory(
"/");
375 for (
unsigned int ivar = 0; ivar <
fNVars; ivar++){
379 for (
unsigned int icut = 0; icut <
fNCuts; icut++){
383 for (
unsigned int iweight = 0; iweight <
fNWeights; iweight++){
387 for (
unsigned int ishift = 0; ishift <
fNShifts; ishift++){
392 specname = specname +
"_" + wlabel;
394 specname = specname +
"_" + slabel;
396 fSpecs[iloader][ivar][icut][iweight][ishift]->SaveTo(loaderDir, specname);
407 for (
unsigned int ihaxis = 0; ihaxis <
fNHistAxes; ihaxis++){
411 for (
unsigned int icut = 0; icut <
fNCuts; icut++){
415 for (
unsigned int iweight = 0; iweight <
fNWeights; iweight++){
419 for (
unsigned int ishift = 0; ishift <
fNShifts; ishift++){
424 specname = specname +
"_" + wlabel;
426 specname = specname +
"_" + slabel;
428 fHistAxisSpecs[iloader][ihaxis][icut][iweight][ishift]->SaveTo(loaderDir, specname);
std::vector< std::string > fHistAxis_labels
std::vector< Binning > fVar_bins
std::vector< Var > fWeights
SpectrumLoaderBase * GetLoader(const std::string label)
bool SaveSpectrums(TFile *f)
bool SetVars(const std::vector< Var > v, const std::vector< std::string > vl, const std::vector< std::string > vt, const std::vector< Binning > vb)
std::vector< Dataset > datasets
bool SetShifts(const std::vector< SystShifts > s, const std::vector< std::string > sl)
std::vector< SpectrumLoaderBase * > fLoaders
std::vector< std::string > fWeight_labels
bool SetSpillCuts(const std::vector< SpillCut > spillcuts)
std::vector< std::string > cut_labels
Representation of a spectrum in any variable, with associated POT.
void CreateHistAxisSpectrums()
void SaveVarSpectrums(TDirectory *d, unsigned int il)
std::vector< std::string > fShift_labels
std::vector< SpectrumLoaderBase * > GetLoaders(const std::vector< std::string > labels)
std::vector< std::string > fVar_titles
void SaveHistAxisSpectrums(TDirectory *d, unsigned int il)
bool SetHistAxes(const std::vector< HistAxis > h, const std::vector< std::string > hl)
void CreateVarSpectrums()
std::vector< SystShifts > fShifts
std::vector< std::string > fVar_labels
bool SetLoaders(const std::vector< std::string > &ds, const std::vector< std::string > &dsnames)
Base class for the various types of spectrum loader.
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
std::vector< std::vector< std::vector< std::vector< std::vector< Spectrum * > > > > > fSpecs
assert(nhit_max >=nhit_nbins)
std::vector< std::vector< std::vector< std::vector< std::vector< Spectrum * > > > > > fHistAxisSpecs
std::vector< std::string > fLoader_labels
std::vector< HistAxis > fHistAxes
std::string to_string(ModuleType mt)
Template for Cut and SpillCut.
std::vector< std::string > fCut_labels
bool SetCuts(const std::vector< Cut > c, const std::vector< std::string > cl)
virtual bool Gone() const
Indicate whether or not Go has been called.
bool SetWeights(const std::vector< Var > w, const std::vector< std::string > wl)