Skip to content

Commit

Permalink
refs #4201 added missing commit
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Dec 22, 2011
1 parent c9db2b3 commit 2387422
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef H_CONV2_MDEVENTS_DET_INFO
#define H_CONV2_MDEVENTS_DET_INFO
/** This structure is the basis and temporary replacement for future subalgorithm, which calculates
* matrix worrkspace with various precprocessed detectors parameters
*
* @date 22-12-2011
Copyright © 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
#include "MantidKernel/System.h"
#include "MantidKernel/PhysicalConstants.h"
#include "MantidKernel/V3D.h"
#include "MantidDataObjects/Workspace2D.h"
/** the lightweight class below contain 3D uint vectors, pointing to the positions of the detectors
This vector used to preprocess and catch the partial positions of the detectors in Q-space
to avoid repetative calculations, and (possibly) to write these data as part of the physical compression scheme
in a very common situation when the physical instrument does not change in all runs, contributed into MD workspace
*/
namespace Mantid
{
namespace MDAlgorithms
{

struct preprocessed_detectors{
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;
//
bool is_defined(void)const{return det_dir.size()>0;}
bool is_defined(size_t new_size)const{return det_dir.size()==new_size;}
double * pL2(){return &L2[0];}
double * pTwoTheta(){return &TwoTheta[0];}
size_t * iDetIDMap(){return &detIDMap[0];}
Kernel::V3D * pDetDir(){return &det_dir[0];}
};

/** 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 */
void DLLExport processDetectorsPositions(const DataObjects::Workspace2D_const_sptr inputWS,preprocessed_detectors &det,Kernel::Logger& convert_log);
} // end MDAlgorithms
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "MantidMDAlgorithms/ConvertToMDEventsDetInfo.h"
#include "MantidKernel/Exception.h"

using namespace Mantid::Kernel;
using namespace Mantid::DataObjects;
using namespace Mantid::Geometry;

namespace Mantid
{
namespace MDAlgorithms
{


/** 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 */
void DLLExport
processDetectorsPositions(const DataObjects::Workspace2D_const_sptr inputWS,preprocessed_detectors &det_loc,Kernel::Logger& convert_log)
{
//
Instrument_const_sptr instrument = inputWS->getInstrument();
//
IObjComponent_const_sptr source = instrument->getSource();
IObjComponent_const_sptr sample = instrument->getSample();
if ((!source) || (!sample)) {
convert_log.error()<<" Instrument is not fully defined. Can not identify source or sample\n";
throw Exception::InstrumentDefinitionError("Instrubment not sufficiently defined: failed to get source and/or sample");
}

// L1
try{
det_loc.L1 = source->getDistance(*sample);
convert_log.debug() << "Source-sample distance: " << det_loc.L1 << std::endl;
}catch (Exception::NotFoundError &) {
convert_log.error("Unable to calculate source-sample distance");
throw Exception::InstrumentDefinitionError("Unable to calculate source-sample distance", inputWS->getTitle());
}
//
const size_t nHist = inputWS->getNumberHistograms();

det_loc.det_dir.resize(nHist);
det_loc.det_id.resize(nHist);
det_loc.L2.resize(nHist);
det_loc.TwoTheta.resize(nHist);
det_loc.detIDMap.resize(nHist);
// Loop over the spectra
size_t ic(0);
for (size_t i = 0; i < nHist; i++){

Geometry::IDetector_const_sptr spDet;
try{
spDet= inputWS->getDetector(i);
}catch(Kernel::Exception::NotFoundError &){
continue;
}

// Check that we aren't dealing with monitor...
if (spDet->isMonitor())continue;

det_loc.det_id[ic] = spDet->getID();
det_loc.detIDMap[ic]= i;
det_loc.L2[ic] = spDet->getDistance(*sample);


double polar = inputWS->detectorTwoTheta(spDet);
det_loc.TwoTheta[ic]= polar;
double azim = spDet->getPhi();

double sPhi=sin(polar);
double ez = cos(polar);
double ex = sPhi*cos(azim);
double ey = sPhi*sin(azim);

det_loc.det_dir[ic].setX(ex);
det_loc.det_dir[ic].setY(ey);
det_loc.det_dir[ic].setZ(ez);

ic++;
}
//
if(ic<nHist){
det_loc.det_dir.resize(ic);
det_loc.det_id.resize(ic);
det_loc.L2.resize(ic);
det_loc.TwoTheta.resize(ic);
det_loc.detIDMap.resize(ic);
}
}

} // END MDAlgorithms ns
} // end Mantid ns

0 comments on commit 2387422

Please sign in to comment.