/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/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 .
*
*/
#include
#include
#include
#include
#include "Utils/Squeak.hh"
#include "src/common_cpp/Utils/JsonWrapper.hh"
#include "src/common_cpp/Utils/CppErrorHandler.hh"
#include "src/common_cpp/Utils/Exception.hh"
#include "src/legacy/Interface/dataCards.hh"
#include "src/common_cpp/API/PyWrapMapBase.hh"
#include "src/map/MapCppReconCuts/MapCppReconCuts.hh"
#include "src/map/MapCppReconCuts/ReconCutBase.hh"
#include "src/map/MapCppReconCuts/ReconTOFCuts.hh"
#include "src/map/MapCppReconCuts/ReconTrackerCuts.hh"
#include "src/map/MapCppReconCuts/ReconMiscCuts.hh"
namespace MAUS {
std::string class_docstring =
std::string("MapCppReconCuts is the mapper for the MAUS Cuts class.\n");
std::string birth_docstring =
std::string("Checks if the right configuration is passed to the processor.\n");
std::string process_docstring =
std::string("Set up event(s) with some cut_event data and\n")+
std::string("check if mapper sets the correct cut values.\n");
std::string death_docstring =
std::string("Does nothing.\n");
PyMODINIT_FUNC init_MapCppReconCuts(void) {
PyWrapMapBase::PyWrapMapBaseModInit
("MapCppReconCuts", class_docstring, birth_docstring, process_docstring, death_docstring);
}
MapCppReconCuts::MapCppReconCuts()
: MapBase("MapCppReconCuts") {
_cuts_list = new ReconCutBasePArray();
}
MapCppReconCuts::~MapCppReconCuts() {
if (_cuts_list != NULL) {
for (size_t i = 0; i < _cuts_list->size(); ++i) {
delete (*_cuts_list)[i];
}
delete _cuts_list;
}
}
void MapCppReconCuts::_birth(const std::string& argJsonConfigDocument) {
// Called at the beginning of each run.
// Check if the JSON document can be parsed, else return error
// JsonCpp setup
_configJSON = JsonWrapper::StringToJson(argJsonConfigDocument);
_set_Cut_params =
JsonWrapper::GetProperty(_configJSON, "recon_cuts", JsonWrapper::objectValue);
// Squeak::mout(Squeak::debug) << "in MapCppReconCuts::_birth" << std::endl;
// Squeak::mout(Squeak::warning) << "in MapCppReconCuts::_birth" << std::endl;
// Initialise cuts from cuts_parameters
Json::Value tof_config;
// TOF cuts
try {
tof_config = JsonWrapper::GetProperty(_set_Cut_params,
"TOF_cuts", JsonWrapper::objectValue);
}
catch (const MAUS::Exceptions::Exception& e) {
Squeak::mout(Squeak::warning)
<< "MapCppReconCuts::_birth Error finding TOF_cuts" << std::endl;
}
ReconTOFCuts* tof_cuts = new ReconTOFCuts(tof_config);
_cuts_list->push_back(tof_cuts);
// Tracker cuts
Json::Value tracker_config;
try {
tracker_config = JsonWrapper::GetProperty(_set_Cut_params,
"Tracker_cuts", JsonWrapper::objectValue);
}
catch (const MAUS::Exceptions::Exception& e) {
Squeak::mout(Squeak::warning)
<< "MapCppReconCuts::_birth Error finding Tracker_cuts" << std::endl;
}
ReconTrackerCuts* tracker_cuts = new ReconTrackerCuts(tracker_config);
_cuts_list->push_back(tracker_cuts);
// Misc cuts
Json::Value misc_config;
try {
misc_config = JsonWrapper::GetProperty(_set_Cut_params,
"Misc_cuts", JsonWrapper::objectValue);
}
catch (const MAUS::Exceptions::Exception& e) {
Squeak::mout(Squeak::warning)
<< "MapCppReconCuts::_birth Error finding Misc_cuts" << std::endl;
}
ReconMiscCuts* misc_cuts = new ReconMiscCuts(misc_config);
_cuts_list->push_back(misc_cuts);
}
void MapCppReconCuts::_process(MAUS::Data *data) const {
// Squeak::mout(Squeak::warning) << "in MapCppReconCuts::_process" << std::endl;
if (!data) {
throw MAUS::Exceptions::Exception(Exceptions::recoverable,
"data was NULL", "MapCppReconCuts::_process");
}
// Get spill, return if there's no DAQ data or not a physics event
Spill *spill = data->GetSpill();
if (spill->GetDAQData() == NULL || (spill->GetDaqEventType() != "physics_event"))
return;
// Squeak::mout(Squeak::warning) << "get recon events" << std::endl;
ReconEventPArray *events = spill->GetReconEvents();
// Squeak::mout(Squeak::warning) << "events->size() " << events->size() << std::endl;
for (size_t j = 0; j < events->size(); ++j) {
// Squeak::mout(Squeak::warning) << "in event loop " << j << std::endl;
// If Cuts list does not exist create a new one
if (events->at(j)->GetCutsList() == NULL) {
events->at(j)->SetCutsList(new ReconCutDataBasePArray());
}
for (size_t i = 0; i < _cuts_list->size(); ++i) {
// Squeak::mout(Squeak::warning) << "in cuts loop " << i << std::endl;
(*_cuts_list)[i]->DoCuts(events->at(j));
}
/*
// Compare Cuts and ReconCuts
std::vector all_cut_values = events->at(j)->GetCutEvent()->GetCutStore();
MAUS::ReconCutBasePArray* cutsList=events->at(j)->GetCutsList();
if (cutsList->at(0)->GetCutPass()!= all_cut_values[0]){
Squeak::mout(Squeak::warning) << "TOF0 cut does not match for recon event " << j << std::endl;
}
if (cutsList->at(1)->GetCutPass()!= all_cut_values[1]){
Squeak::mout(Squeak::warning) << "TOF1 cut does not match for recon event " << j << std::endl;
}
if (cutsList->at(2)->GetCutPass()!= all_cut_values[2]){
Squeak::mout(Squeak::warning) << "TOFDT cut does not match for recon event " << j << std::endl;
}
if (cutsList->at(3)->GetCutPass()!= all_cut_values[3]){
Squeak::mout(Squeak::warning) << "Single track cut does not match for recon event " << j << std::endl;
}
if (cutsList->at(4)->GetCutPass()!= all_cut_values[7]){
Squeak::mout(Squeak::warning) << "Track p-value cut does not match for recon event " << j << std::endl;
Squeak::mout(Squeak::warning) << cutsList->at(4)->GetCutPass() << " " << all_cut_values[7] << " " << cutsList->at(4)->GetCutValue() << std::endl;
}
if (cutsList->at(5)->GetCutPass()!= all_cut_values[4]){
Squeak::mout(Squeak::warning) << "TKU hits cut does not match for recon event " << j << std::endl;
}
if (cutsList->at(6)->GetCutPass()!= all_cut_values[10]){
Squeak::mout(Squeak::warning) << "TKD hits cut does not match for recon event " << j << std::endl;
}
if (cutsList->at(7)->GetCutPass()!= all_cut_values[5]){
Squeak::mout(Squeak::warning) << "TKU mom cut " << cutsList->at(7)->GetCutDescription() << " does not match for recon event " << j << std::endl;
Squeak::mout(Squeak::warning) << cutsList->at(7)->GetCutPass() << " " << all_cut_values[5] << " " << cutsList->at(7)->GetCutValue() << std::endl;
}
if (cutsList->at(8)->GetCutPass()!= all_cut_values[11]){
Squeak::mout(Squeak::warning) << "TKD mom cut " << cutsList->at(8)->GetCutDescription() << " does not match for recon event " << j << std::endl;
Squeak::mout(Squeak::warning) << cutsList->at(8)->GetCutPass() << " " << all_cut_values[11] << " " << cutsList->at(8)->GetCutValue() << std::endl;
}
if (cutsList->at(9)->GetCutPass()!= all_cut_values[6]){
Squeak::mout(Squeak::warning) << "Mom loss cut does not match for recon event " << j << std::endl;
}
if (cutsList->at(10)->GetCutPass()!= all_cut_values[8]){
Squeak::mout(Squeak::warning) << "Mass cut does not match for recon event " << j << std::endl;
Squeak::mout(Squeak::warning) << cutsList->at(10)->GetCutPass() << " " << all_cut_values[8] << " " << cutsList->at(10)->GetCutValue() << std::endl;
}
if (cutsList->at(11)->GetCutPass()!= all_cut_values[9]){
Squeak::mout(Squeak::warning) << "Good particle cut does not match for recon event " << j << std::endl;
}
*/
} // fetching events
} // process
void MapCppReconCuts::_death() {
}
} // namespace MAUS