Skip to content

Commit

Permalink
Re #9445. Integrated PoldiInstrumentAdapter into PoldiAutoCorrelation
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Jun 25, 2014
1 parent 12e9079 commit 951f296
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 64 deletions.
Expand Up @@ -12,6 +12,7 @@

#include "MantidKernel/PhysicalConstants.h"
#include "MantidSINQ/PoldiUtilities/PoldiAutoCorrelationCore.h"
#include "MantidSINQ/PoldiUtilities/PoldiDeadWireDecorator.h"



Expand Down Expand Up @@ -76,15 +77,11 @@ class MANTID_SINQ_DLL PoldiAutoCorrelation5 : public API::Algorithm
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "SINQ\\Poldi"; }



protected:
/// Overwrites Algorithm method
void exec();




void logConfigurationInformation(boost::shared_ptr<PoldiDeadWireDecorator> cleanDetector, PoldiAbstractChopper_sptr chopper);

private:
/// Overwrites Algorithm method.
Expand Down
102 changes: 43 additions & 59 deletions Code/Mantid/Framework/SINQ/src/PoldiAutoCorrelation5.cpp
Expand Up @@ -7,15 +7,8 @@
#include "MantidDataObjects/MaskWorkspace.h"
#include "MantidDataObjects/TableWorkspace.h"

#include "MantidSINQ/PoldiUtilities/PoldiDetectorFactory.h"
#include "MantidSINQ/PoldiUtilities/PoldiDeadWireDecorator.h"
#include "MantidSINQ/PoldiUtilities/PoldiAutoCorrelationCore.h"
#include "MantidSINQ/PoldiUtilities/PoldiChopperFactory.h"

#include "MantidGeometry/IComponent.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/FitParameter.h"
#include "MantidGeometry/Instrument/DetectorGroup.h"
#include "MantidSINQ/PoldiUtilities/PoldiInstrumentAdapter.h"

#include <boost/shared_ptr.hpp>

Expand Down Expand Up @@ -84,60 +77,15 @@ void PoldiAutoCorrelation5::exec()
double wlen_min = this->getProperty("wlenmin");
double wlen_max = this->getProperty("wlenmax");

double chopperSpeed = 0.0;

try {
chopperSpeed = localWorkspace->run().getPropertyValueAsType<std::vector<double> >("chopperspeed").front();
} catch(std::invalid_argument&) {
throw(std::runtime_error("Chopper speed could not be extracted from Workspace '" + localWorkspace->name() + "'. Aborting."));
}

// Instrument definition
Instrument_const_sptr poldiInstrument = localWorkspace->getInstrument();

// Chopper configuration
PoldiChopperFactory chopperFactory;
boost::shared_ptr<PoldiAbstractChopper> chopper(chopperFactory.createChopper(std::string("default-chopper")));
chopper->loadConfiguration(poldiInstrument);
chopper->setRotationSpeed(chopperSpeed);

g_log.information() << "____________________________________________________ " << std::endl;
g_log.information() << "_Poldi chopper conf ------------------------------ " << std::endl;
g_log.information() << "_Poldi - Chopper speed: " << chopper->rotationSpeed() << " rpm" << std::endl;
g_log.information() << "_Poldi - Number of slits: " << chopper->slitPositions().size() << std::endl;
g_log.information() << "_Poldi - Cycle time: " << chopper->cycleTime() << " µs" << std::endl;
g_log.information() << "_Poldi - Zero offset: " << chopper->zeroOffset() << " µs" << std::endl;
g_log.information() << "_Poldi - Distance: " << chopper->distanceFromSample() << " mm" << std::endl;

if(g_log.is(Poco::Message::PRIO_DEBUG)) {
for(size_t i = 0; i < chopper->slitPositions().size(); ++i) {
g_log.information() << "_Poldi - Slits: " << i
<< ": Position = " << chopper->slitPositions()[i]
<< "\t Time = " << chopper->slitTimes()[i] << " µs" << std::endl;
}
}
PoldiInstrumentAdapter instrumentAdapter(localWorkspace);
PoldiAbstractChopper_sptr chopper = instrumentAdapter.chopper();

// Detector configuration
PoldiDetectorFactory detectorFactory;
boost::shared_ptr<PoldiAbstractDetector> detector(detectorFactory.createDetector(std::string("helium3-detector")));
detector->loadConfiguration(poldiInstrument);

g_log.information() << "_Poldi detector conf ------------------------------ " << std::endl;
g_log.information() << "_Poldi - Element count: " << detector->elementCount() << std::endl;
g_log.information() << "_Poldi - Central element: " << detector->centralElement() << std::endl;
g_log.information() << "_Poldi - 2Theta(central): " << detector->twoTheta(199) / M_PI * 180.0 << "°" << std::endl;
g_log.information() << "_Poldi - Distance(central): " << detector->distanceFromSample(199) << " mm" << std::endl;

boost::shared_ptr<PoldiDeadWireDecorator> cleanDetector(new PoldiDeadWireDecorator(poldiInstrument, detector));

std::set<int> deadWires = cleanDetector->deadWires();
g_log.information() << "_Poldi - Number of dead wires: " << deadWires.size() << std::endl;
g_log.information() << "_Poldi - Wire indices: ";
for(std::set<int>::const_iterator dw = deadWires.begin(); dw != deadWires.end(); ++dw) {
g_log.information() << *dw << " ";
}
g_log.information() << std::endl;
PoldiAbstractDetector_sptr detector = instrumentAdapter.detector();
boost::shared_ptr<PoldiDeadWireDecorator> cleanDetector(new PoldiDeadWireDecorator(localWorkspace->getInstrument(), detector));

// log configuration information
logConfigurationInformation(cleanDetector, chopper);

// putting together POLDI instrument for calculations
m_core->setInstrument(cleanDetector, chopper);
Expand All @@ -160,5 +108,41 @@ void PoldiAutoCorrelation5::exec()
}
}

void PoldiAutoCorrelation5::logConfigurationInformation(boost::shared_ptr<PoldiDeadWireDecorator> cleanDetector, PoldiAbstractChopper_sptr chopper)
{
if(cleanDetector && chopper) {
g_log.information() << "____________________________________________________ " << std::endl;
g_log.information() << "_Poldi chopper conf ------------------------------ " << std::endl;
g_log.information() << "_Poldi - Chopper speed: " << chopper->rotationSpeed() << " rpm" << std::endl;
g_log.information() << "_Poldi - Number of slits: " << chopper->slitPositions().size() << std::endl;
g_log.information() << "_Poldi - Cycle time: " << chopper->cycleTime() << " µs" << std::endl;
g_log.information() << "_Poldi - Zero offset: " << chopper->zeroOffset() << " µs" << std::endl;
g_log.information() << "_Poldi - Distance: " << chopper->distanceFromSample() << " mm" << std::endl;

if(g_log.is(Poco::Message::PRIO_DEBUG)) {
for(size_t i = 0; i < chopper->slitPositions().size(); ++i) {
g_log.information() << "_Poldi - Slits: " << i
<< ": Position = " << chopper->slitPositions()[i]
<< "\t Time = " << chopper->slitTimes()[i] << " µs" << std::endl;
}
}

g_log.information() << "_Poldi detector conf ------------------------------ " << std::endl;
g_log.information() << "_Poldi - Element count: " << cleanDetector->elementCount() << std::endl;
g_log.information() << "_Poldi - Central element: " << cleanDetector->centralElement() << std::endl;
g_log.information() << "_Poldi - 2Theta(central): " << cleanDetector->twoTheta(199) / M_PI * 180.0 << "°" << std::endl;
g_log.information() << "_Poldi - Distance(central): " << cleanDetector->distanceFromSample(199) << " mm" << std::endl;


std::set<int> deadWires = cleanDetector->deadWires();
g_log.information() << "_Poldi - Number of dead wires: " << deadWires.size() << std::endl;
g_log.information() << "_Poldi - Wire indices: ";
for(std::set<int>::const_iterator dw = deadWires.begin(); dw != deadWires.end(); ++dw) {
g_log.information() << *dw << " ";
}
g_log.information() << std::endl;
}
}

} // namespace Poldi
} // namespace Mantid

0 comments on commit 951f296

Please sign in to comment.