StatusCode MergeCells::initialize() { if (GaudiAlgorithm::initialize().isFailure()) return StatusCode::FAILURE; if (m_idToMerge.empty()) { error() << "No identifier to merge specified." << endmsg; return StatusCode::FAILURE; } m_geoSvc = service ("GeoSvc"); if (!m_geoSvc) { error() << "Unable to locate Geometry Service. " << "Make sure you have GeoSvc and SimSvc in the right order in the configuration." << endmsg; return StatusCode::FAILURE; } // check if readout exists if (m_geoSvc->lcdd()->readouts().find(m_readoutName) == m_geoSvc->lcdd()->readouts().end()) { error() << "Readout <<" << m_readoutName << ">> does not exist." << endmsg; return StatusCode::FAILURE; } auto readout = m_geoSvc->lcdd()->readout(m_readoutName); m_descriptor = readout.idSpec(); // check if identifier exists in the decoder auto itIdentifier = std::find_if(m_descriptor.fields().begin(), m_descriptor.fields().end(), [this](const std::pair<std::string, DD4hep::Geometry::IDDescriptor::Field>& field) { return bool(field.first.compare(m_idToMerge) == 0); }); if ( itIdentifier == m_descriptor.fields().end()) { error() << "Identifier << " << m_idToMerge << ">> does not exist in the readout <<" << m_readoutName << ">>" << endmsg; return StatusCode::FAILURE; } // check if proper number of cells to be merged was given (>1 and odd for signed fields) // it'd be nice to get max num of cells and warn user if it's not multipicity if(m_numToMerge > std::pow(2,(*itIdentifier).second->width())) { error() << "It is not possible to merge more cells than the maximum number of cells." << endmsg; return StatusCode::FAILURE; } if (m_numToMerge < 2) { error() << "Number of cells to me merged must be larger than 1." << endmsg; return StatusCode::FAILURE; } if ((*itIdentifier).second->isSigned() && (m_numToMerge%2 == 0)) { error() << "If field is signed, merge can only be done for an odd number of cells" << "(to ensure that middle cell is centred at 0)." << endmsg; return StatusCode::FAILURE; } info() << "Field description: " << m_descriptor.fieldDescription() << endmsg; info() << "Merging cells for identifier: " << m_idToMerge << endmsg; info() << "Number of adjacent cells to be merged: " << m_numToMerge << "\n" << endmsg; return StatusCode::SUCCESS; }
StatusCode MergeLayers::initialize() { if (GaudiAlgorithm::initialize().isFailure()) return StatusCode::FAILURE; if (m_idToMerge.empty()) { error() << "No identifier to merge specified." << endmsg; return StatusCode::FAILURE; } m_geoSvc = service("GeoSvc"); if (!m_geoSvc) { error() << "Unable to locate Geometry Service. " << "Make sure you have GeoSvc and SimSvc in the right order in the configuration." << endmsg; return StatusCode::FAILURE; } // check if readout exists if (m_geoSvc->lcdd()->readouts().find(m_readoutName) == m_geoSvc->lcdd()->readouts().end()) { error() << "Readout <<" << m_readoutName << ">> does not exist." << endmsg; return StatusCode::FAILURE; } auto readout = m_geoSvc->lcdd()->readout(m_readoutName); m_descriptor = readout.idSpec(); // check if identifier exists in the decoder auto itIdentifier = std::find_if(m_descriptor.fields().begin(), m_descriptor.fields().end(), [this](const std::pair<std::string, DD4hep::Geometry::IDDescriptor::Field>& field) { return bool(field.first.compare(m_idToMerge) == 0); }); if (itIdentifier == m_descriptor.fields().end()) { error() << "Identifier <<" << m_idToMerge << ">> does not exist in the readout <<" << m_readoutName << ">>" << endmsg; return StatusCode::FAILURE; } // check sizes of new volumes in the list - it must sum to the total number of volumes unsigned int sumCells = std::accumulate(m_listToMerge.begin(), m_listToMerge.end(), 0); auto highestVol = gGeoManager->GetTopVolume(); auto numPlacedVol = det::utils::countPlacedVolumes(highestVol, m_volumeName); if (numPlacedVol != sumCells) { error() << "Total number of volumes named " << m_volumeName << " (" << numPlacedVol << ") " << "is not equal to the sum of volumes from the list 'merge' given in job options (" << sumCells << ")" << endmsg; return StatusCode::FAILURE; } info() << "Field description: " << m_descriptor.fieldDescription() << endmsg; info() << "Merging volumes named: " << m_volumeName << endmsg; info() << "Merging volumes for identifier: " << m_idToMerge << endmsg; info() << "List of number of volumes to be merged: " << m_listToMerge << "\n" << endmsg; return StatusCode::SUCCESS; }
StatusCode FastGaussSmearDigi::initialize() { info() << "initialize" << endmsg; m_geoSvc = service("GeoSvc"); StatusCode sc = GaudiAlgorithm::initialize(); if (sc.isFailure()) return sc; auto lcdd = m_geoSvc->lcdd(); auto readout = lcdd->readout(m_readoutName); m_decoder = readout.idSpec().decoder(); auto segmentationXZ = dynamic_cast<DD4hep::DDSegmentation::CartesianGridXZ*>(readout.segmentation().segmentation()); if (nullptr == segmentationXZ) { error() << "Could not retrieve segmentation!" << endmsg; return StatusCode::FAILURE; } m_segGridSizeX = segmentationXZ->gridSizeX(); m_segGridSizeZ = segmentationXZ->gridSizeZ(); m_volman = lcdd->volumeManager(); return sc; }
StatusCode MergeLayers::initialize() { if (GaudiAlgorithm::initialize().isFailure()) return StatusCode::FAILURE; if (m_idToMerge.empty()) { error() << "No identifier to merge specified." << endmsg; return StatusCode::FAILURE; } m_geoSvc = service("GeoSvc"); if (!m_geoSvc) { error() << "Unable to locate Geometry Service. " << "Make sure you have GeoSvc and SimSvc in the right order in the configuration." << endmsg; return StatusCode::FAILURE; } // check if readout exists if (m_geoSvc->lcdd()->readouts().find(m_readoutName) == m_geoSvc->lcdd()->readouts().end()) { error() << "Readout <<" << m_readoutName << ">> does not exist." << endmsg; return StatusCode::FAILURE; } auto readout = m_geoSvc->lcdd()->readout(m_readoutName); m_descriptor = readout.idSpec(); // check if identifier exists in the decoder auto itIdentifier = std::find_if(m_descriptor.fields().begin(), m_descriptor.fields().end(), [this](const std::pair<std::string, const dd4hep::BitFieldElement*>& field) { return bool(field.first.compare(m_idToMerge) == 0); }); if (itIdentifier == m_descriptor.fields().end()) { error() << "Identifier <<" << m_idToMerge << ">> does not exist in the readout <<" << m_readoutName << ">>" << endmsg; return StatusCode::FAILURE; } info() << "Field description: " << m_descriptor.fieldDescription() << endmsg; info() << "Merging volumes named: " << m_volumeName << endmsg; info() << "Merging volumes for identifier: " << m_idToMerge << endmsg; info() << "List of number of volumes to be merged: " << m_listToMerge << "\n" << endmsg; return StatusCode::SUCCESS; }