/* This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
*
* MAUS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MAUS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MAUS. If not, see .
*/
/* Total number of cuts */
int nCuts = 12;
#include "src/common_cpp/DataStructure/Cuts.hh"
#include "src/common_cpp/Utils/Exception.hh"
namespace MAUS {
/** Constructor - Cuts are set initially to false. */
Cuts::Cuts()
: _cut_store(0) {
}
/** Copy constructor */
Cuts::Cuts(const Cuts& _cuts_data)
: _cut_store(0) {
*this = _cuts_data;
}
/** Copy assignment operator */
Cuts& Cuts::operator=(const Cuts& _cuts_data) {
if(this == &_cuts_data) {
return *this;
}
SetCutStore(_cuts_data._cut_store);
return *this;
}
/** Destructor */
Cuts::~Cuts() {}
/** Mapper that maps strings to integers. */
std::map Cuts::map_to_int = Cuts::Init_map_to_int();
std::map Cuts::Init_map_to_int() {
std::map map_to_int;
map_to_int["cut_TOF0_singleHit"] = 0;
map_to_int["cut_TOF1_singleHit"] = 1;
map_to_int["cut_TimeOfFlight"] = 2;
map_to_int["cut_singleTrack"] = 3;
map_to_int["cut_TKU_hitAllStations"] = 4;
map_to_int["cut_TKU_momentum"] = 5;
map_to_int["cut_momentumLoss"] = 6;
map_to_int["cut_TKU_PValue"] = 7;
map_to_int["cut_Mass"] = 8;
map_to_int["cut_allPassed"] = 9;
map_to_int["cut_TKD_hitAllStations"] = 10;
map_to_int["cut_TKD_momentum"] = 11;
return map_to_int;
}
/** Mapper that maps integers to strings. */
std::map Cuts::Init_map_to_name() {
std::map map_to_name;
map_to_name[0] = "cut_TOF0_singleHit";
map_to_name[1] = "cut_TOF1_singleHit";
map_to_name[2] = "cut_TimeOfFlight";
map_to_name[3] = "cut_singleTrack";
map_to_name[4] = "cut_TKU_hitAllStations";
map_to_name[5] = "cut_TKU_momentum";
map_to_name[6] = "cut_momentumLoss";
map_to_name[7] = "cut_TKU_PValue";
map_to_name[8] = "cut_Mass";
map_to_name[9] = "cut_allPassed";
map_to_name[10] = "cut_TKU_hitAllStations";
map_to_name[11] = "cut_TKD_momentum";
return map_to_name;
}
std::map Cuts::map_to_name = Cuts::Init_map_to_name();
/** Error if cut number is invalid - it does not exist in the mapper */
bool Cuts::errorindex(std::map map_to_name, int cut_variable) {
std::map ::iterator search = map_to_name.find(cut_variable);
if (search != map_to_name.end()) {
return true;
} else {
MAUS::Exceptions::Exception(
MAUS::Exceptions::recoverable,
"Input could not be identified.",
"Cuts::errorindex()");
return false;
}
}
/** Error if cut name is invalid - it does not exist in the mapper */
bool Cuts::errorname(std::map map_to_int, std::string cut_variable) {
std::map ::iterator search = map_to_int.find(cut_variable);
if (search != map_to_int.end()) {
return true;
} else {
MAUS::Exceptions::Exception(
MAUS::Exceptions::recoverable,
"Input could not be identified.",
"Cuts::errorname()");
return false;
}
}
/** User sets cut values by passing a vector of booleans */
void Cuts::SetCutStore(std::vector cut_store) {
_cut_store = cut_store;
}
/** User selects the cut by passing the index 'cut_variable' of the cut
* 'will_cut' sets the value of the cut */
void Cuts::SetWillCut(int cut_variable, bool will_cut) {
/** Exception raised if index invalid */
if (errorindex(map_to_name, cut_variable) == true) {
std::cout << "Cut index " << cut_variable << " is set to " << will_cut << std::endl;
if (will_cut == true) {
_cut_store[cut_variable] = true;
} else {
_cut_store[cut_variable] = false;
}
};
}
/** User selects the cut by passing the name 'cut_variable' of the cut
* 'will_cut' sets the value of the cut */
void Cuts::SetWillCut(std::string cut_variable, bool will_cut) {
/** Exception raised if name invalid */
if (errorname(map_to_int, cut_variable) == true) {
std::map ::iterator search = map_to_int.find(cut_variable);
if (search != map_to_int.end()) {
int cut_value = search->second;
if (will_cut == true) {
_cut_store[cut_value] = true;
} else {
_cut_store[cut_value] = false;
}
std::cout << "Cut '" << search->first << "' is set to " << will_cut << std::endl;
}
};
}
/** Retrieve vector that stores the cuts */
std::vector Cuts::GetCutStore() const {
return _cut_store;
}
/** Retrieve cut value by passing an integer associated with the cut */
bool Cuts::GetWillCut(int cut_variable) {
if (errorindex(map_to_name, cut_variable) == true) {
return _cut_store[cut_variable];
} else {
errorindex(map_to_name, cut_variable) == false;
return false;
};
}
/** Retrieve cut value by passing a string associated with the cut */
bool Cuts::GetWillCut(std::string cut_variable) {
std::map ::iterator search = map_to_int.find(cut_variable);
if (errorname(map_to_int, cut_variable) == true) {
if (search != map_to_int.end()) {
int cut_value = search->second;
return _cut_store[cut_value];
} else {
return false;
}
} else {
errorname(map_to_int, cut_variable) == false;
return false;
};
}
/** Returns cut index by passing a string associated with the cut */
int Cuts::VariableIndex(std::string cut_variable) {
int var_index_return = 0;
/** Exception is raised if name is invalid */
if (errorname(map_to_int, cut_variable) == true) {
std::map ::iterator search = map_to_int.find(cut_variable);
if (search != map_to_int.end()) {
var_index_return = search->second;
}
}
return var_index_return;
}
/** Returns cut name by passing an integer associated with the cut */
std::string Cuts::VariableName(int cut_variable) {
std::string var_name_return;
/** Exception is raised if index is invalid */
if (errorindex(map_to_name, cut_variable) == true) {
std::map ::iterator search = map_to_name.find(cut_variable);
if (search != map_to_name.end()) {
var_name_return = search->second;
} else {
var_name_return = "NaN";
}
}
return var_name_return;
}
} // ~ namespace MAUS