/* 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 "src/common_cpp/Utils/JsonWrapper.hh" #include "Interface/Squeak.hh" #include "Utils/Exception.hh" #include "Interface/dataCards.hh" #include "src/common_cpp/API/PyWrapMapBase.hh" #include "src/map/MapCppKLCellHits/MapCppKLCellHits.hh" namespace MAUS { PyMODINIT_FUNC init_MapCppKLCellHits(void) { PyWrapMapBase::PyWrapMapBaseModInit ("MapCppKLCellHits", "", "", "", ""); } MapCppKLCellHits::MapCppKLCellHits() : MapBase("MapCppKLCellHits") { } void MapCppKLCellHits::_birth(const std::string& argJsonConfigDocument) { // Check if the JSON document can be parsed, else return error only _stationKeys.push_back("kl"); // JsonCpp setup Json::Value configJSON; configJSON = JsonWrapper::StringToJson(argJsonConfigDocument); } void MapCppKLCellHits::_death() {} void MapCppKLCellHits::_process(Json::Value* data) const { if (!data) { throw MAUS::Exception(Exception::recoverable, "data was NULL", "MapCppKLCellHits::_process"); } Json::Value& root = *data; // JsonCpp setup Json::Value xEventType = JsonWrapper::GetProperty(root, "daq_event_type", JsonWrapper::stringValue); if (xEventType== "physics_event" || xEventType == "calibration_event") { Json::Value events = JsonWrapper::GetProperty(root, "recon_events", JsonWrapper::arrayValue); for (unsigned int n_event = 0; n_event < events.size(); n_event++) { Json::Value xDocKlEvent = JsonWrapper::GetItem(events, n_event, JsonWrapper::objectValue); xDocKlEvent = JsonWrapper::GetProperty(xDocKlEvent, "kl_event", JsonWrapper::objectValue); if (root["recon_events"][n_event]["kl_event"].isMember("kl_digits")) { root["recon_events"][n_event]["kl_event"]["kl_cell_hits"] = Json::Value(Json::objectValue); Json::Value xDocPartEvent = JsonWrapper::GetProperty(xDocKlEvent, "kl_digits", JsonWrapper::objectValue); xDocPartEvent = JsonWrapper::GetProperty(xDocPartEvent, "kl", JsonWrapper::anyValue); Json::Value xDocCellHits = makeCellHits(xDocPartEvent); root["recon_events"][n_event]["kl_event"]["kl_cell_hits"]["kl"] = xDocCellHits; } } } } Json::Value MapCppKLCellHits::makeCellHits(Json::Value xDocPartEvent) const { Json::Value xDocCellHits; if (xDocPartEvent.isArray()) { int n_digits = xDocPartEvent.size(); // Create a map of all hited PMTs. std::map xDigitPos; std::map::iterator it; // Loop ovew the digits. for (int Digit = 0; Digit < n_digits; Digit++) { // Get the digit. Json::Value xThisDigit = JsonWrapper::GetItem(xDocPartEvent, Digit, JsonWrapper::objectValue); std::string xKeyStr = JsonWrapper::GetProperty(xThisDigit, "kl_key", JsonWrapper::stringValue).asString(); KLChannelKey xKey(xKeyStr); // Add this PMT to the map. xDigitPos[xKeyStr] = Digit; } // Now loop over the map of hited PMTs and create Cell hits. while ( xDigitPos.size() > 1 ) { // Get the first element of the map and check if we have a hit // at the opposite side of the cell. it = xDigitPos.begin(); KLChannelKey xKey(it->first); // Get the digit. Json::Value xThisDigit = JsonWrapper::GetItem(xDocPartEvent, it->second, JsonWrapper::objectValue); // Get the opposite PMT coded as string. std::string xOppositPmtKey_str = xKey.GetOppositeSidePMTStr(); if (xDigitPos.find(xOppositPmtKey_str) != xDigitPos.end()) { Json::Value xDocTheCellHit; Json::Value xOtherDigit = JsonWrapper::GetItem(xDocPartEvent, xDigitPos[xOppositPmtKey_str], JsonWrapper::objectValue); // Create Cell hit. if (xKey.pmt() == 0) { xDocTheCellHit = fillCellHit(xThisDigit, xOtherDigit); } if (xKey.pmt() == 1) { xDocTheCellHit = fillCellHit(xOtherDigit, xThisDigit); } xDocCellHits.append(xDocTheCellHit); // Erase both used hits from the map. xDigitPos.erase(it); xDigitPos.erase(xOppositPmtKey_str); } else { // Erese this hit from the map. xDigitPos.erase(it); } } } // std::cout << xDocCellHits <