Skip to content

Commit

Permalink
refs #4201 Added Mslice-type axis caption generator
Browse files Browse the repository at this point in the history
Added also default/non-default u-v settings (need verification)

and attempted to use UB matrix instead of U-matrix.

The later produce just rubbish -- so commented for the time being -- until clarified.
  • Loading branch information
abuts committed Jan 16, 2012
1 parent 7705390 commit 0757045
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace MDAlgorithms
/// string -Key to identify the algorithm -- rather for testing and debugging, though may be reliet upon somewhere by bad practice
std::string algo_id;
// the vector describes default dimension names, specified along the axis if nothing explicitly requested;
std::vector<std::string> default_dimension_names;
std::vector<std::string> default_dim_ID;

protected: //for testing
static Mantid::Kernel::Logger & getLogger();
Expand All @@ -109,7 +109,7 @@ namespace MDAlgorithms
void getAddDimensionNames(API::MatrixWorkspace_const_sptr inMatrixWS,Strings &add_dim_names,Strings &add_dim_units)const;
/** function parses arguments entered by user, and identifies, which subalgorithm should be deployed on WS as function of the input artuments and the WS format */
std::string identifyMatrixAlg(API::MatrixWorkspace_const_sptr inMatrixWS,const std::string &Q_mode_req, const std::string &dE_mode_req,
Strings &out_dim_names,Strings &out_dim_units);
Strings &out_dim_IDs,Strings &out_dim_units);
//>---> Parts of the identifyMatrixAlg, separated for unit testing:
// identify Q - mode
std::string parseQMode(const std::string &Q_mode_req,const Strings &ws_dim_names,const Strings &ws_dim_units,Strings &out_dim_names,Strings &out_dim_units, int &nQdims);
Expand All @@ -129,10 +129,12 @@ namespace MDAlgorithms


/** function provides the linear representation for the transformation matrix, which translate momentums from laboratory to notional (fractional) coordinate system */
std::vector<double> getTransfMatrix(API::MatrixWorkspace_sptr inWS2D,const Kernel::V3D &u=Kernel::V3D(1,0,0), const Kernel::V3D &v=Kernel::V3D(0,1,0),
std::vector<double> getTransfMatrix(API::MatrixWorkspace_sptr inWS2D,MDEvents::MDWSDescription &TargWSDescription,
bool is_powder=false)const;
/// get transformation matrix currently defined for the algorithm
std::vector<double> getTransfMatrix()const{return TWS.rotMatrix;}
/// construct meaningful dimension names:
void buildDimNames(MDEvents::MDWSDescription &TargWSDescription);

/// map to select an algorithm as function of the key, which describes it
std::map<std::string, IConvertToMDEventsMethods *> alg_selector;
Expand All @@ -158,8 +160,8 @@ namespace MDAlgorithms


/** helper function which verifies if projection vectors are specified and if their values are correct when present.
* sets defaults [1,0,0] and [0,1,0] if not present or any error. */
void checkUVsettings(const std::vector<double> &ut,const std::vector<double> &vt,Kernel::V3D &u,Kernel::V3D &v)const;
* sets default values u and v to [1,0,0] and [0,1,0] if not present or any error. */
void checkUVsettings(const std::vector<double> &ut,const std::vector<double> &vt,MDEvents::MDWSDescription &TargWSDescription)const;
};

} // namespace Mantid
Expand Down
172 changes: 118 additions & 54 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDEvents.cpp

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDEventsTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ void testParseQMode_Q3D()
TS_ASSERT_THROWS_NOTHING(MODE=pAlg->parseQMode("QhQkQl",ws_dim_names,ws_dim_units,out_dim_names,out_dim_units, nQ_dims));
TS_ASSERT_EQUALS(3,nQ_dims);
TS_ASSERT_EQUALS("QhQkQl",MODE);
TS_ASSERT_EQUALS("[Q_h,0,0]",out_dim_names[0]);
TS_ASSERT_EQUALS("[0,Q_k,0]",out_dim_names[1]);
TS_ASSERT_EQUALS("[0,0,Q_l]",out_dim_names[2]);
TS_ASSERT_EQUALS("Q1",out_dim_names[0]);
TS_ASSERT_EQUALS("Q2",out_dim_names[1]);
TS_ASSERT_EQUALS("Q3",out_dim_names[2]);
TS_ASSERT_EQUALS("Momentum",out_dim_units[0]);
TS_ASSERT_EQUALS("Momentum",out_dim_units[1]);
TS_ASSERT_EQUALS("Momentum",out_dim_units[2]);
Expand Down Expand Up @@ -539,9 +539,9 @@ void testIdentifyMatrixAlg_5()

TS_ASSERT_EQUALS("WS2DQhQkQlIndirectCnvNo",pAlg->identifyMatrixAlg(ws2D,"QhQkQl","Indirect",dim_names,dim_units));
TSM_ASSERT_EQUALS("One dim name came from Q (this can be wrong)",4,dim_names.size());
TS_ASSERT_EQUALS(dim_names[0],"[Q_h,0,0]");
TS_ASSERT_EQUALS(dim_names[1],"[0,Q_k,0]");
TS_ASSERT_EQUALS(dim_names[2],"[0,0,Q_l]");
TS_ASSERT_EQUALS(dim_names[0],"Q1");
TS_ASSERT_EQUALS(dim_names[1],"Q2");
TS_ASSERT_EQUALS(dim_names[2],"Q3");
TS_ASSERT_EQUALS(dim_names[3],"DeltaE");
}

Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/MDEvents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ set ( TEST_FILES
test/MDEventTest.h
test/MDEventWorkspaceTest.h
test/MDEventWSWrapperTest.h
test/MDWSDescriptionTest.h
test/MDGridBoxTest.h
test/MDHistoWorkspaceIteratorTest.h
test/MDHistoWorkspaceTest.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class DLLExport MDEventWSWrapper

/// minimal and maximal values for the workspace dimensions:
std::vector<double> dim_min,dim_max;
/// the ID-s for the target workspace dimensions, which allow to address these dimesnions by name
Strings targ_dim_ID;
/// the names for the target workspace dimensions and properties of input MD workspace
Strings targ_dim_names;
/// the units of target workspace dimensions and properties of input MD workspace dimensions
Expand Down Expand Up @@ -111,7 +113,7 @@ class DLLExport MDEventWSWrapper
// Give all the dimensions
for (size_t d=0; d<nd; d++)
{
Geometry::MDHistoDimension * dim = new Geometry::MDHistoDimension(this->targ_dim_names[d], this->targ_dim_names[d], this->targ_dim_units[d],
Geometry::MDHistoDimension * dim = new Geometry::MDHistoDimension(this->targ_dim_names[d], this->targ_dim_ID[d], this->targ_dim_units[d],
this->dim_min[d], this->dim_max[d], 10);
ws->addDimension(Geometry::MDHistoDimension_sptr(dim));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,25 @@ namespace MDEvents
std::vector<double> dim_min,dim_max;
/// the names for the target workspace dimensions and properties of input MD workspace
std::vector<std::string> dim_names;
/// the ID-s for the target workspace, which allow to identify the dimensions according to their ID
std::vector<std::string> dim_IDs;
/// the units of target workspace dimensions and properties of input MD workspace dimensions
std::vector<std::string> dim_units;
/** vectors, which describe the projection plain the target ws is based on (notional coordinate system). The transformation matrix below
* should bring the momentums from lab coordinate system into notional coordinate system */
Kernel::V3D u,v;
/// the indicator, informing if the uv plain has been set. If they are not, the UB matrix from the source workspace has to be used unaltered
bool is_uv_default;
/// the matrix to transform momentums of the workspace into notional target coordinate system
std::vector<double> rotMatrix; // should it be the Quat?
/// helper function checks if min values are less them max values and are consistent between each other
void checkMinMaxNdimConsistent(Mantid::Kernel::Logger& log)const;

};
/// the vector of default names for Q-directrions in reciprocal space;
std::vector<std::string> defailt_qNames;

};
/** function to build mslice-like axis name from the vector, which describes crystallographic direction along this axis*/
std::string DLLExport makeAxisName(const Kernel::V3D &vector,const std::vector<std::string> &Q1Names);

}
}
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDEventWSWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ MDEventWSWrapper::createEmptyMDWS(const MDWSDescription &WSD)
this->dim_max.resize(n_dim);
this->targ_dim_names.resize(n_dim);
this->targ_dim_units.resize(n_dim);
this->targ_dim_ID.resize(n_dim);

for(size_t i=0;i<n_dim;i++){
this->dim_min[i]=WSD.dim_min[i];
this->dim_max[i]=WSD.dim_max[i];
this->targ_dim_names[i]= WSD.dim_names[i];
this->targ_dim_units[i]= WSD.dim_units[i];
this->targ_dim_ID[i] = WSD.dim_IDs[i];
}

wsCreator[n_dimensions]();
Expand Down
44 changes: 42 additions & 2 deletions Code/Mantid/Framework/MDEvents/src/MDWSDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,49 @@ n_dims(nDimesnions),
emode(-1),
Ei(std::numeric_limits<double>::quiet_NaN()),
dim_names(nDimesnions,"mdn"),
dim_IDs(nDimesnions,"mdn_"),
dim_units(nDimesnions,"Momentum"),
dim_min(nDimesnions,-1),
dim_max(nDimesnions,1)
{}
dim_max(nDimesnions,1),
is_uv_default(true),
u(1,0,0),
v(0,1,0),
defailt_qNames(3)
{
for(size_t i=0;i<nDimesnions;i++){
dim_IDs[i]= dim_IDs[i]+boost::lexical_cast<std::string>(i);
}
defailt_qNames[0]="Qh";
defailt_qNames[1]="Qk";
defailt_qNames[2]="Ql";

}

std::string makeAxisName(const Kernel::V3D &Dir,const std::vector<std::string> &QNames)
{
double eps(1.e-3);
std::string name("["),separator=",";
for(size_t i=0;i<3;i++){
double dist=abs(Dir[i]);
if(i==2)separator="]";
if(dist<eps){
name+="0"+separator;
continue;
}
if(Dir[i]<0){
name+="-";
}
if(abs(dist-1)<eps){
name+=QNames[i]+separator;
continue;
}
// truncate to eps decimal points
dist = float(int(dist/eps+0.5))*eps;
name+= boost::str(boost::format("%d")%dist)+QNames[i]+separator;
}

return name;
}

}
}

0 comments on commit 0757045

Please sign in to comment.