48 std::string output_message;
50 const std::string reductionManagerName =
getProperty(
"ReductionProperties");
51 std::shared_ptr<PropertyManager> reductionManager;
52 if (PropertyManagerDataService::Instance().doesExist(reductionManagerName)) {
53 reductionManager = PropertyManagerDataService::Instance().retrieve(reductionManagerName);
55 reductionManager = std::make_shared<PropertyManager>();
56 PropertyManagerDataService::Instance().addOrReplace(reductionManagerName, reductionManager);
60 const bool persistent =
getProperty(
"PersistentCorrection");
61 if (!reductionManager->existsProperty(
"DarkCurrentAlgorithm") && persistent) {
62 auto algProp = std::make_unique<AlgorithmProperty>(
"DarkCurrentAlgorithm");
64 reductionManager->declareProperty(std::move(algProp));
74 progress.report(
"Subtracting dark current");
77 Poco::Path path(fileName);
78 const std::string entryName =
"DarkCurrent" + path.getBaseName();
79 std::string darkWSName =
"__dark_current_" + path.getBaseName();
81 if (reductionManager->existsProperty(entryName)) {
82 darkWS = reductionManager->getProperty(entryName);
83 darkWSName = reductionManager->getPropertyValue(entryName);
84 output_message += darkWSName +
'\n';
88 if (!reductionManager->existsProperty(
"LoadAlgorithm")) {
90 loadAlg->setProperty(
"Filename", fileName);
91 if (loadAlg->existsProperty(
"LoadMonitors"))
92 loadAlg->setProperty(
"LoadMonitors",
false);
93 loadAlg->executeAsChildAlg();
94 darkWS = loadAlg->getProperty(
"OutputWorkspace");
98 IAlgorithm_sptr loadAlg0 = reductionManager->getProperty(
"LoadAlgorithm");
99 const std::string loadString = loadAlg0->toString();
101 loadAlg->setChild(
true);
102 loadAlg->setProperty(
"Filename", fileName);
103 if (loadAlg->existsProperty(
"LoadMonitors"))
104 loadAlg->setProperty(
"LoadMonitors",
false);
105 loadAlg->setPropertyValue(
"OutputWorkspace", darkWSName);
107 darkWS = loadAlg->getProperty(
"OutputWorkspace");
110 output_message +=
"\n Loaded " + fileName +
"\n";
111 if (loadAlg->existsProperty(
"OutputMessage")) {
112 std::string msg = loadAlg->getPropertyValue(
"OutputMessage");
113 output_message +=
" |" + Poco::replace(msg,
"\n",
"\n |") +
"\n";
116 std::string darkWSOutputName =
getPropertyValue(
"OutputDarkCurrentWorkspace");
117 if (!darkWSOutputName.empty())
119 AnalysisDataService::Instance().addOrReplace(darkWSName, darkWS);
121 reductionManager->setPropertyValue(entryName, darkWSName);
122 reductionManager->setProperty(entryName, darkWS);
124 progress.report(3,
"Loaded dark current");
127 double scaling_factor = 1.0;
128 if (inputWS->run().hasProperty(
"proton_charge")) {
129 auto dp = inputWS->run().getTimeSeriesProperty<
double>(
"proton_charge");
130 double duration = dp->getStatistics().duration;
132 dp = darkWS->run().getTimeSeriesProperty<
double>(
"proton_charge");
133 double dark_duration = dp->getStatistics().duration;
134 scaling_factor = duration / dark_duration;
135 }
else if (inputWS->run().hasProperty(
"timer")) {
136 auto duration = inputWS->run().getPropertyValueAsType<
double>(
"timer");
137 auto dark_duration = darkWS->run().getPropertyValueAsType<
double>(
"timer");
139 scaling_factor = duration / dark_duration;
141 output_message +=
"\n Could not find proton charge or duration in sample logs";
142 g_log.
error() <<
"ERROR: Could not find proton charge or duration in sample logs\n";
145 progress.report(
"Scaling dark current");
149 rebinAlg->setProperty(
"WorkspaceToRebin", darkWS);
150 rebinAlg->setProperty(
"WorkspaceToMatch", inputWS);
151 rebinAlg->setProperty(
"OutputWorkspace", darkWS);
152 rebinAlg->executeAsChildAlg();
157 scaleAlg->setProperty(
"InputWorkspace", scaledDarkWS);
158 scaleAlg->setProperty(
"Factor", scaling_factor);
159 scaleAlg->setProperty(
"OutputWorkspace", scaledDarkWS);
160 scaleAlg->setProperty(
"Operation",
"Multiply");
161 scaleAlg->executeAsChildAlg();
162 scaledDarkWS = rebinAlg->getProperty(
"OutputWorkspace");
165 minusAlg->setProperty(
"LHSWorkspace", inputWS);
166 minusAlg->setProperty(
"RHSWorkspace", scaledDarkWS);
168 minusAlg->setPropertyValue(
"OutputWorkspace", outputWSname);
169 minusAlg->executeAsChildAlg();
173 setProperty(
"OutputMessage",
"Dark current subtracted: " + output_message);
175 progress.report(
"Subtracted dark current");