Commit d932a482 authored by yannick legoc's avatar yannick legoc
Browse files

Added controller VEXPDetectorSimulator

parent b0bc80b2
<module name="vexp">
<controller class="vexp::VEXPController"/>
<controller class="vexp::DetectorSimulator"/>
<include path="$(NOMAD_HOME)/../NomadModules/src"/>
<link path="/usr/local/lib" lib="vexplib"/>
</module>
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "VEXPDetectorSimulator.h"
#include <fstream>
#include <boost/algorithm/string.hpp>
using namespace std;
using namespace boost;
namespace vexp {
const string DetectorSimulator::TYPE = "vexp_detector_simulator";
DetectorSimulator::DetectorSimulator(const string& name) :
ExperimentController(name), m_dataHandle(0), m_coef(1.0) {
setFamily(family::HIDDEN);
m_detector.init(this, "detector");
m_scattering.init(this, "scattering");
simulationFile.init(this, SAVE, "simulation_file");
intensity.init(this, NOSAVE, "intensity");
}
DetectorSimulator::DetectorSimulator(const DetectorSimulator& controller) :
ExperimentController(controller), m_dataHandle(0), m_coef(1.0) {
}
DetectorSimulator::~DetectorSimulator() {
}
void DetectorSimulator::postConfiguration() {
registerUpdater(m_detector->detSum, &DetectorSimulator::updateData, this);
loadSimulationFile();
}
void DetectorSimulator::loadSimulationFile() {
// Open the file.
ifstream file(simulationFile().c_str());
if (!file) {
cerr << "Cannot open simulation file " << simulationFile() << endl;
return;
}
// Create a tree.
m_dataHandle = m_accessor.createSqwTree();
// Calculate the max intensity.
float64 maxIntensity = 0.0;
float64 mh, mk, ml, me;
typedef tokenizer<char_separator<char> > tokenizer;
char_separator<char> sep(" ");
// Read the file.
while (!file.eof()) {
string line;
getline(file, line);
if (line != "") {
try {
tokenizer tokens(line, sep);
tokenizer::iterator iter = tokens.begin();
float64 qh(stod(*iter));
++iter;
float64 qk(stod(*iter));
++iter;
float64 ql(stod(*iter));
++iter;
float64 qe(stod(*iter));
++iter;
float64 qs(stod(*iter));
//cout << "found " << qh << " " << qk << " " << ql << " " << qe << " " << qs << endl;
// Add the point.
m_accessor.addSqwValue(m_dataHandle, qh, qk, ql, qe, qs);
// Update the max intensity.
//maxIntensity = max(qs, maxIntensity);
if (qs > maxIntensity) {
maxIntensity = qs;
mh = qh;
mk = qk;
ml = ql;
me = qe;
}
}
catch (...) {
// Line with bad characters are excluded.
}
}
}
m_coef = 1000.0 / maxIntensity;
cout << "Created the simulation data, max intensity is " << maxIntensity << " at " << mh << ", " << mk << ", " << ml << ", " << me << endl;
}
void DetectorSimulator::updateData() {
// Query the s value from the data.
float64 h, k, l, e, s;
h = m_scattering->qh();
k = m_scattering->qk();
l = m_scattering->ql();
e = m_scattering->en();
m_accessor.querySqwTree(m_dataHandle, h, k, l, e, s);
//detector->detSum = (scattering->qh() + scattering->qk() + scattering->ql()) * 10.0;
//m_detector->detSum = 200.0 - ((m_scattering->qh() - 1.0) * 1000.0);
m_detector->detSum = s * m_coef;
cout << "updateData " << m_detector->detSum()
<< ", scattering " << m_scattering->qh() << ", " << m_scattering->qk() << ", " << m_scattering->ql() << ", " << m_scattering->en() << endl;
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef VEXP_DETECTORSIMULATOR_H
#define VEXP_DETECTORSIMULATOR_H
#include "controllers/tas/common/Scattering.h"
#include "controllers/common/acquisition/detector/DetectorElement.h"
#include <vexplib.h>
namespace vexp {
class DetectorSimulator : public ExperimentController {
public:
//! Type of controller
static const std::string TYPE;
DetectorSimulator(const std::string& name);
DetectorSimulator(const DetectorSimulator& controller);
virtual ~DetectorSimulator();
virtual void postConfiguration();
Property<std::string> simulationFile;
Property<float64> intensity;
private:
void loadSimulationFile();
void updateData();
VEXPLib m_accessor;
int m_dataHandle;
float64 m_coef;
// Controllers.
ControllerPtr<acquisition::DetectorElement> m_detector;
ControllerPtr<tas::Scattering> m_scattering;
};
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment