Skip to content

Commit

Permalink
refs #4201 Finishing touches.
Browse files Browse the repository at this point in the history
No new code but small modifications, e.g. comments and clarifications.

Added check if the basis instrument, used to preprocess detectors once is the same second time.
  • Loading branch information
abuts committed Jan 18, 2012
1 parent 909324d commit f2fa4cc
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace MDAlgorithms
}
private:
//--------------------------------------------------------------------------------------------------
/// helper class to orginize metaloop over various subalgorithm options dealign with matrix workspace
/// helper class to orginize metaloop instantiating various subalgorithms
template<Q_state Q,size_t N_ALGORITHMS >
friend class LOOP_ALGS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,22 @@ namespace MDAlgorithms
{

struct PreprocessedDetectors{
double L1;
Kernel::V3D minDetPosition; // minimal and
Kernel::V3D maxDetPosition; // maxinal position for the detectors
std::vector<Kernel::V3D> det_dir; // unit vector pointing from the sample to the detector;
std::vector<double> L2;
std::vector<double> TwoTheta;
std::vector<int32_t> det_id; // the detector ID;
std::vector<size_t> detIDMap; // stores spectra index which corresponds to a valid detector index;
std::vector<size_t> spec2detMap; //stores detector index which corresponds to the workspace index;
double L1; //< source-sample distance;
Kernel::V3D minDetPosition; //< minimal and
Kernel::V3D maxDetPosition; //< maxinal position for the detectors
/** shared pointer to the base instrument, which was source of the detector's information. If the instrument changed,
* the detectors positions should be recalculated.
* IT IS USER's RECPONCIBLITY TO RECALCULATE THE DETECTOR's PARAMETERS
* if the derived instrument have changed in a way, which affects the detectors positions and TOF calculations */
boost::shared_ptr< const Geometry::Instrument > pBaseInstr;
std::vector<Kernel::V3D> det_dir; //< unit vector pointing from the sample to the detector;
std::vector<double> L2; //< sample-detector distance
std::vector<double> TwoTheta; //< Diffraction angle
std::vector<int32_t> det_id; //< the detector ID;
std::vector<size_t> detIDMap; //< stores spectra index which corresponds to a valid detector index;
std::vector<size_t> spec2detMap; //< stores detector index which corresponds to the workspace index;
//
bool is_defined(void)const{return det_dir.size()>0;}
bool is_defined(const API::MatrixWorkspace_const_sptr &inputWS)const;
bool is_defined(size_t new_size)const{return det_dir.size()==new_size;}
size_t nDetectors()const{return TwoTheta.size();}
std::vector<double>const & getL2()const{return L2;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class ConvertToMDEvensEventWS: public IConvertToMDEventsMethods
DataObjects::EventWorkspace_sptr pEventWS;
// vector to keep generic part of event coordinates
std::vector<coord_t> Coord;
// index of current run(workspace) for MD WS combining
uint16_t runIndex;
public:
size_t setUPConversion(Mantid::API::MatrixWorkspace_sptr pWS2D, const PreprocessedDetectors &detLoc,
const MDEvents::MDWSDescription &WSD, boost::shared_ptr<MDEvents::MDEventWSWrapper> inWSWrapper)
Expand All @@ -90,18 +88,8 @@ class ConvertToMDEvensEventWS: public IConvertToMDEventsMethods
// Get the box controller
Mantid::API::BoxController_sptr bc = pWSWrapper->pWorkspace()->getBoxController();
size_t lastNumBoxes = bc->getTotalNumMDBoxes();



size_t nValidSpectra = this->pDetLoc->det_id.size();
// copy experiment info into target workspace
API::ExperimentInfo_sptr ExperimentInfo(inWS2D->cloneExperimentInfo());

// set oriented lattice from workspace description, as this lattice can be modified by algorithm settings;
ExperimentInfo->mutableSample().setOrientedLattice(&TWS.Latt);

// run index;
runIndex = this->pWSWrapper->pWorkspace()->addExperimentInfo(ExperimentInfo);


// if any property dimension is outside of the data range requested, the job is done;
if(!trn.calcGenericVariables(Coord,this->n_dims))return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ class ConvertToMDEvensEventWSAutoRebin: public IConvertToMDEventsMethods

const size_t specSize = this->inWS2D->blocksize();
size_t nValidSpectra = pDetLoc->det_id.size();
// copy experiment info into target workspace
API::ExperimentInfo_sptr ExperimentInfo(inWS2D->cloneExperimentInfo());
// run index;
uint16_t runIndex = this->pWSWrapper->pWorkspace()->addExperimentInfo(ExperimentInfo);
// number of dimesnions
std::vector<coord_t> Coord(n_dims); // coordinates for single event
// if any property dimension is outside of the data range requested, the job is done;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,8 @@ class ConvertToMDEvensHistoWS: public IConvertToMDEventsMethods

const size_t specSize = this->inWS2D->blocksize();
size_t nValidSpectra = pDetLoc->det_id.size();
// copy experiment info into target workspace
API::ExperimentInfo_sptr ExperimentInfo(inWS2D->cloneExperimentInfo());
// set oriented lattice from workspace description, as this lattice can be modified by algorithm settings;
ExperimentInfo->mutableSample().setOrientedLattice(&TWS.Latt);
// run index;
uint16_t runIndex = this->pWSWrapper->pWorkspace()->addExperimentInfo(ExperimentInfo);
// number of dimesnions

// number of dimesnions
std::vector<coord_t> Coord(n_dims); // coordinates for single event
// if any property dimension is outside of the data range requested, the job is done;
if(!trn.calcGenericVariables(Coord,n_dims))return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ namespace MDAlgorithms
std::vector<double> dim_min;
/// the array of variables which describe max limits for the target variables;
std::vector<double> dim_max;

// index of current run(workspace) for MD WS combining
uint16_t runIndex;
/// logger -> to provide logging, for MD dataset file operations
static Mantid::Kernel::Logger& convert_log;
private:
Expand Down
40 changes: 23 additions & 17 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void ConvertToMDEvents::exec()
//c) other dim property;
std::vector<std::string> other_dim_names = getProperty("OtherDimensions");

// Identify the algorithm to deploy and identify/set the dimension names to use
// Identify the algorithm to deploy and identify/set the (multi)dimension names to use
algo_id = identifyTheAlg(inWS2D,Q_mod_req,dE_mod_req,other_dim_names,TWS);

// set the min and max values for the dimensions from the input porperties
Expand All @@ -294,7 +294,7 @@ void ConvertToMDEvents::exec()
}

bool reuse_preprocecced_detectors = getProperty("UsePreprocessedDetectors");
if(!(reuse_preprocecced_detectors&&det_loc.is_defined())){
if(!(reuse_preprocecced_detectors&&det_loc.is_defined(inWS2D))){
// amount of work:
const size_t nHist = inWS2D->getNumberHistograms();
pProg = std::auto_ptr<API::Progress >(new API::Progress(this,0.0,1.0,nHist));
Expand Down Expand Up @@ -479,7 +479,7 @@ ConvertToMDEvents::parseDEMode(const std::string &Q_MODE_ID,const std::string &d
// inelastic modes have one additional dimension and need special units on X-axis
if((DE_MODE_ID.compare(dE_modes[Direct])==0)||(DE_MODE_ID.compare(dE_modes[Indir])==0)){
ndE_dims = 1;
out_dim_IDs.push_back("DeltaE");
out_dim_IDs.push_back(default_dim_ID[4]);
out_dim_units.push_back("DeltaE");
// natural units defined in subalgorithm doing the conversion and their ID has to be defined correctly in class constructor
natural_units = native_inelastic_unitID;
Expand Down Expand Up @@ -709,13 +709,15 @@ ConvertToMDEvents::getTransfMatrix(API::MatrixWorkspace_sptr inWS,MDEvents::MDWS
}catch(std::runtime_error &){
if(!is_powder){
convert_log.warning()<<
" Can not obtain transformation matrix from the input workspace: "<<inWS->name()<<" as no oriented lattice has been defined. Use unit transformation matrix anyway\n";
" Can not obtain transformation matrix from the input workspace: "<<inWS->name()<<
" as no oriented lattice has been defined. \n"
" Will use unit transformation matrix\n";
}
}
//
if(has_lattice){
if(TargWSDescription.is_uv_default){
// we need to set up u,v for axis caption as it defined in UB matrix;
// we need to set up u,v for axis caption as it is defined in workspace UB matrix;
TargWSDescription.u = TargWSDescription.Latt.getuVector();
TargWSDescription.v = TargWSDescription.Latt.getvVector();
umat = TargWSDescription.Latt.getU();
Expand Down Expand Up @@ -803,7 +805,8 @@ ConvertToMDEvents::checkUVsettings(const std::vector<double> &ut,const std::vect
// }
//----------------------------------------------------------------------------------------------
// AUTOINSTANSIATION OF EXISTING CODE:
// Templated loop over dependant templated arguments
/** helper class to orginize metaloop instantiating various subalgorithms dealing with particular
* workspaces and implementing particular user requests */
template<Q_state Q, size_t NumAlgorithms=0>
class LOOP_ALGS{
private:
Expand All @@ -829,7 +832,7 @@ class LOOP_ALGS{
}
};

// Templated loop specialization for the noQ case
/** Templated metaloop specialization for noQ case */
template< size_t NumAlgorithms>
class LOOP_ALGS<NoQ,NumAlgorithms>{
private:
Expand Down Expand Up @@ -858,14 +861,14 @@ class LOOP_ALGS<NoQ,NumAlgorithms>{
}
};

// Q3d and modQ terminator
/** Q3d and modQ metaloop terminator */
template<Q_state Q >
class LOOP_ALGS<Q,static_cast<size_t>(ANY_Mode*NConvUintsStates) >{
public:
static inline void EXEC(ConvertToMDEvents *pH){UNUSED_ARG(pH);}
};

// any mode terminator
/** ANY_Mode (NoQ) metaloop terminator */
template<>
class LOOP_ALGS<NoQ,static_cast<size_t>(NConvUintsStates) >{
public:
Expand All @@ -889,17 +892,11 @@ default_dim_ID(5),
// initiate target ws description to be not empty and have 4 dimensions (It will be redefined later, but defailt_qNames are defined only when it is not empty)
TWS(4)
{
// strings to indentify possible momentum analysis modes
Q_modes[modQ] = "|Q|";
Q_modes[Q3D] = "QhQkQl";
Q_modes[NoQ] = ""; // no Q dimension (does it have any interest&relevance to ISIS/SNS?)
// for modQ transformation:
default_dim_ID[0]="|Q|";
// for Q3D transformation
default_dim_ID[1]="Q1";
default_dim_ID[2]="Q2";
default_dim_ID[3]="Q3";
default_dim_ID[4]="DeltaE";

// strings to indentify possible energy conversion modes
dE_modes[ANY_Mode] = ""; // no Q uses it to run without conversion.
dE_modes[Direct] = "Direct";
dE_modes[Indir] = "Indirect";
Expand All @@ -913,6 +910,15 @@ TWS(4)
SupportedWS[Workspace2DType] = "WS2D";
SupportedWS[EventWSType] = "WSEvent";

// this defines default dimension ID-s which are used to indentify dimensions when using the target MD workspace later
// for modQ transformation:
default_dim_ID[0]="|Q|";
// for Q3D transformation
default_dim_ID[1]="Q1";
default_dim_ID[2]="Q2";
default_dim_ID[3]="Q3";
default_dim_ID[4]="DeltaE";

// Subalgorithm factories:
// NoQ --> any Analysis mode will do as it does not depend on it; we may want to convert unuts
LOOP_ALGS<NoQ,0>::EXEC(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ IConvertToMDEventsMethods::setUPConversion(Mantid::API::MatrixWorkspace_sptr pWS

size_t n_spectra =inWS2D->getNumberHistograms();
return n_spectra;

// copy experiment info into target workspace
API::ExperimentInfo_sptr ExperimentInfo(inWS2D->cloneExperimentInfo());
// set oriented lattice from workspace description, as this lattice can be modified by algorithm settings;
ExperimentInfo->mutableSample().setOrientedLattice(&TWS.Latt);
// run index;
runIndex = this->pWSWrapper->pWorkspace()->addExperimentInfo(ExperimentInfo);

};

IConvertToMDEventsMethods::IConvertToMDEventsMethods()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ namespace Mantid
{
namespace MDAlgorithms
{
bool
PreprocessedDetectors::is_defined(const API::MatrixWorkspace_const_sptr &inputWS)const
{
if(det_dir.empty())return false;

if(pBaseInstr !=inputWS->getInstrument()->baseInstrument())return false;
return true;
}

/** helper function, does preliminary calculations of the detectors positions to convert results into k-dE space ;
and places the resutls into static cash to be used in subsequent calls to this algorithm */
Expand All @@ -19,6 +26,7 @@ processDetectorsPositions(const API::MatrixWorkspace_sptr inputWS,PreprocessedDe
convert_log.information()<<" Preprocessing detectors locations in a target reciprocal space\n";
//
Instrument_const_sptr instrument = inputWS->getInstrument();
det_loc.pBaseInstr = instrument->baseInstrument();
//
IObjComponent_const_sptr source = instrument->getSource();
IObjComponent_const_sptr sample = instrument->getSample();
Expand Down

0 comments on commit f2fa4cc

Please sign in to comment.