124 const std::string reductionManagerName =
getProperty(
"ReductionProperties");
125 std::shared_ptr<PropertyManager> reductionManager;
126 if (PropertyManagerDataService::Instance().doesExist(reductionManagerName)) {
127 reductionManager = PropertyManagerDataService::Instance().retrieve(reductionManagerName);
129 reductionManager = std::make_shared<PropertyManager>();
130 PropertyManagerDataService::Instance().addOrReplace(reductionManagerName, reductionManager);
133 if (!reductionManager->existsProperty(
"SensitivityAlgorithm")) {
134 auto algProp = std::make_unique<AlgorithmProperty>(
"SensitivityAlgorithm");
136 reductionManager->declareProperty(std::move(algProp));
139 progress.report(
"Loading sensitivity file");
143 Poco::Path path(fileName);
144 const std::string entryName =
"Sensitivity" + path.getBaseName();
146 std::string floodWSName =
"__sensitivity_" + path.getBaseName();
148 if (reductionManager->existsProperty(entryName)) {
149 std::string wsName = reductionManager->getPropertyValue(entryName);
151 std::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(wsName));
153 g_log.
debug() <<
"SANSSensitivityCorrection :: Using sensitivity workspace: " << wsName <<
"\n";
159 g_log.
debug() <<
"SANSSensitivityCorrection :: Loading sensitivity file: " << fileName <<
"\n";
161 loadAlg->setProperty(
"Filename", fileName);
162 loadAlg->executeAsChildAlg();
163 Workspace_sptr floodWS_ws = loadAlg->getProperty(
"OutputWorkspace");
164 floodWS = std::dynamic_pointer_cast<MatrixWorkspace>(floodWS_ws);
167 if (!floodWS->run().hasProperty(
"is_sensitivity")) {
170 g_log.
error() <<
"A processed Mantid workspace was loaded but it "
171 "wasn't a sensitivity file!\n";
181 if (reductionManager->existsProperty(
"LatestBeamCenterX") &&
182 reductionManager->existsProperty(
"LatestBeamCenterY")) {
183 center_x = reductionManager->getProperty(
"LatestBeamCenterX");
184 center_y = reductionManager->getProperty(
"LatestBeamCenterY");
185 m_output_message +=
" |Setting beam center to [" + Poco::NumberFormatter::format(center_x, 1) +
", " +
186 Poco::NumberFormatter::format(center_y, 1) +
"]\n";
191 const std::string rawFloodWSName =
"__flood_data_" + path.getBaseName();
193 if (!reductionManager->existsProperty(
"LoadAlgorithm")) {
195 loadAlg->setProperty(
"Filename", fileName);
196 if (!
isEmpty(center_x) && loadAlg->existsProperty(
"BeamCenterX"))
197 loadAlg->setProperty(
"BeamCenterX", center_x);
198 if (!
isEmpty(center_y) && loadAlg->existsProperty(
"BeamCenterY"))
199 loadAlg->setProperty(
"BeamCenterY", center_y);
200 loadAlg->setPropertyValue(
"OutputWorkspace", rawFloodWSName);
201 loadAlg->executeAsChildAlg();
203 rawFloodWS = std::dynamic_pointer_cast<MatrixWorkspace>(tmpWS);
208 IAlgorithm_sptr loadAlg0 = reductionManager->getProperty(
"LoadAlgorithm");
209 const std::string loadString = loadAlg0->toString();
211 loadAlg->setChild(
true);
212 loadAlg->setProperty(
"Filename", fileName);
213 loadAlg->setPropertyValue(
"OutputWorkspace", rawFloodWSName);
214 if (!
isEmpty(center_x) && loadAlg->existsProperty(
"BeamCenterX"))
215 loadAlg->setProperty(
"BeamCenterX", center_x);
216 if (!
isEmpty(center_y) && loadAlg->existsProperty(
"BeamCenterY"))
217 loadAlg->setProperty(
"BeamCenterY", center_y);
219 rawFloodWS = loadAlg->getProperty(
"OutputWorkspace");
221 if (loadAlg->existsProperty(
"OutputMessage")) {
222 std::string msg = loadAlg->getPropertyValue(
"OutputMessage");
229 if (!rawFloodWS->run().hasProperty(
"is_sensitivity")) {
233 std::string dark_result;
234 if (reductionManager->existsProperty(
"DarkCurrentAlgorithm")) {
235 IAlgorithm_sptr darkAlg = reductionManager->getProperty(
"DarkCurrentAlgorithm");
236 darkAlg->setChild(
true);
237 darkAlg->setProperty(
"InputWorkspace", rawFloodWS);
238 darkAlg->setProperty(
"OutputWorkspace", rawFloodWS);
245 if (darkAlg->existsProperty(
"OutputMessage"))
246 dark_result = darkAlg->getPropertyValue(
"OutputMessage");
247 }
else if (!darkCurrentFile.empty()) {
248 darkAlg->setProperty(
"Filename", darkCurrentFile);
249 darkAlg->setProperty(
"PersistentCorrection",
false);
251 if (darkAlg->existsProperty(
"OutputMessage"))
252 dark_result = darkAlg->getPropertyValue(
"OutputMessage");
254 dark_result =
" Dark current subtracted\n";
256 }
else if (!darkCurrentFile.empty()) {
261 if (reductionManager->existsProperty(
"DefaultDarkCurrentAlgorithm")) {
262 IAlgorithm_sptr darkAlg = reductionManager->getProperty(
"DefaultDarkCurrentAlgorithm");
263 darkAlg->setChild(
true);
264 darkAlg->setProperty(
"InputWorkspace", rawFloodWS);
265 darkAlg->setProperty(
"OutputWorkspace", rawFloodWS);
266 darkAlg->setProperty(
"Filename", darkCurrentFile);
267 darkAlg->setProperty(
"PersistentCorrection",
false);
269 if (darkAlg->existsProperty(
"OutputMessage"))
270 dark_result = darkAlg->getPropertyValue(
"OutputMessage");
275 dark_result =
" No dark current algorithm provided: skipped\n";
281 if (reductionManager->existsProperty(
"SANSSolidAngleCorrection")) {
282 IAlgorithm_sptr solidAlg = reductionManager->getProperty(
"SANSSolidAngleCorrection");
283 solidAlg->setChild(
true);
284 solidAlg->setProperty(
"InputWorkspace", rawFloodWS);
285 solidAlg->setProperty(
"OutputWorkspace", rawFloodWS);
287 std::string msg =
"Solid angle correction applied\n";
288 if (solidAlg->existsProperty(
"OutputMessage"))
289 msg = solidAlg->getPropertyValue(
"OutputMessage");
294 double floodTransmissionValue =
getProperty(
"FloodTransmissionValue");
295 double floodTransmissionError =
getProperty(
"FloodTransmissionError");
297 if (!
isEmpty(floodTransmissionValue)) {
298 g_log.
debug() <<
"SANSSensitivityCorrection :: Applying transmission "
301 transAlg->setProperty(
"InputWorkspace", rawFloodWS);
302 transAlg->setProperty(
"OutputWorkspace", rawFloodWS);
303 transAlg->setProperty(
"TransmissionValue", floodTransmissionValue);
304 transAlg->setProperty(
"TransmissionError", floodTransmissionError);
305 transAlg->setProperty(
"ThetaDependent",
true);
307 rawFloodWS = transAlg->getProperty(
"OutputWorkspace");
313 effAlg->setProperty(
"InputWorkspace", rawFloodWS);
315 const double minEff =
getProperty(
"MinEfficiency");
316 const double maxEff =
getProperty(
"MaxEfficiency");
317 const std::string maskFullComponent =
getPropertyValue(
"MaskedFullComponent");
321 effAlg->setProperty(
"MinEfficiency", minEff);
322 effAlg->setProperty(
"MaxEfficiency", maxEff);
323 effAlg->setProperty(
"MaskedFullComponent", maskFullComponent);
324 effAlg->setProperty(
"MaskedEdges", maskEdges);
325 effAlg->setProperty(
"MaskedComponent", maskComponent);
327 floodWS = effAlg->getProperty(
"OutputWorkspace");
329 floodWS = rawFloodWS;
332 if (reductionManager->existsProperty(
"SensitivityPatchAlgorithm")) {
333 IAlgorithm_sptr patchAlg = reductionManager->getProperty(
"SensitivityPatchAlgorithm");
334 patchAlg->setChild(
true);
335 patchAlg->setProperty(
"Workspace", floodWS);
340 floodWS->mutableRun().addProperty(
"is_sensitivity", 1,
"",
true);
342 std::string floodWSOutputName =
getPropertyValue(
"OutputSensitivityWorkspace");
343 if (floodWSOutputName.empty()) {
345 AnalysisDataService::Instance().addOrReplace(floodWSName, floodWS);
346 reductionManager->declareProperty(
348 reductionManager->setPropertyValue(entryName, floodWSName);
349 reductionManager->setProperty(entryName, floodWS);
351 setProperty(
"OutputSensitivityWorkspace", floodWS);
354 progress.report(3,
"Loaded flood field");
361 divideAlg->setProperty(
"LHSWorkspace", inputWS);
362 divideAlg->setProperty(
"RHSWorkspace", floodWS);
363 divideAlg->executeAsChildAlg();
368 maskAlg->setProperty(
"Workspace", outputWS);
369 maskAlg->setProperty(
"MaskedWorkspace", floodWS);
370 maskAlg->executeAsChildAlg();
376 progress.report(
"Performed sensitivity correction");