Skip to content

Commit

Permalink
refs #4201 Tests for Units conversion + wsCreationHelper modified
Browse files Browse the repository at this point in the history
spectra-detector ID in wsCreationHelper was strange -> creating complex detectors.
Modified to work with simple detectors.
  • Loading branch information
abuts committed Jan 10, 2012
1 parent 193399a commit 45091f2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ processDetectorsPositions(const API::MatrixWorkspace_sptr inputWS,PreprocessedDe

Geometry::IDetector_const_sptr spDet;
try{
spDet= inputWS->getDetector(i);
// get detector or detector group which corresponds to the spectra i
spDet= inputWS->getDetector(i);
}catch(Kernel::Exception::NotFoundError &){
continue;
}
Expand All @@ -62,7 +63,7 @@ processDetectorsPositions(const API::MatrixWorkspace_sptr inputWS,PreprocessedDe
det_loc.spec2detMap[i]= ic;
det_loc.det_id[ic] = spDet->getID();
det_loc.detIDMap[ic] = i;
det_loc.L2[ic] = spDet->getDistance(*sample);
det_loc.L2[ic] = spDet->getDistance(*sample);


double polar = inputWS->detectorTwoTheta(spDet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ void testEventWS()
pAlg->setRethrows(false);
pAlg->execute();
TSM_ASSERT("Shoud finish succesfully",pAlg->isExecuted());
Mantid::API::Workspace_sptr spws = AnalysisDataService::Instance().retrieve("testMDEvWorkspace");
Mantid::API::Workspace_sptr spws;
TS_ASSERT_THROWS_NOTHING(spws = AnalysisDataService::Instance().retrieve("testMDEvWorkspace"));
TSM_ASSERT(" Worskpace should be retrieved",spws.get());

boost::shared_ptr<MDEvents::MDEventWorkspace<MDEvents::MDEvent<3>,3> > ws = boost::dynamic_pointer_cast<MDEvents::MDEventWorkspace<MDEvents::MDEvent<3>,3> >(spws);
TSM_ASSERT("It shoudl be 3D MD workspace",ws.get());

TS_ASSERT_EQUALS(900,ws->getNPoints());
if(ws.get()){
TS_ASSERT_EQUALS(900,ws->getNPoints());
}else{
TS_FAIL("event workspace has not beed build");
}
AnalysisDataService::Instance().remove("testMDEvWorkspace");


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void destroySuite(ConvertToMDEventsUnitsConvTest * suite) { delete suite

void test_nothing()
{
// std::auto_ptr<NotMD> pD = std::auto_ptr<NotMD>(new NotMD());

pProg = std::auto_ptr<API::Progress >(new API::Progress(dynamic_cast<ConvertToMDEvents *>(this),0.0,1.0,4));

TS_ASSERT_THROWS_NOTHING(processDetectorsPositions(ws2D,det_loc,ConvertToMDEvents::getLogger(),pProg.get()));
Expand All @@ -40,17 +40,19 @@ void test_nothing()
ConvertToMDEventsUnitsConvTest (){


int numHist=10;

ws2D =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(4,10,true);


std::vector<double> L2(5,5);
std::vector<double> polar(5,(30./180.)*3.1415926);
polar[0]=0;
std::vector<double> azimutal(5,0);
azimutal[1]=(45./180.)*3.1415936;
azimutal[2]=(90./180.)*3.1415936;
azimutal[3]=(135./180.)*3.1415936;
azimutal[4]=(180./180.)*3.1415936;

int numBins=10;
ws2D =WorkspaceCreationHelper::createProcessedInelasticWS(L2, polar, azimutal,numBins,-1,3,4);


// wsEv->setInstrument( ComponentCreationHelper::createTestInstrumentCylindrical(numHist) );
// // any inelastic units or unit conversion using TOF needs Ei to be present among properties.
//// wsEv->mutableRun().addProperty("Ei",13.,"meV",true);

}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,14 +743,18 @@ namespace WorkspaceCreationHelper
std::set<int64_t> maskedWorkspaceIndices;
size_t numPixels= L2.size();


Mantid::API::MatrixWorkspace_sptr ws= Create2DWorkspaceWithValues(uint64_t(numPixels), uint64_t(numBins),true, maskedWorkspaceIndices,0, 1, 0.1);


ws->setInstrument( ComponentCreationHelper::createCylInstrumentWithDetInGivenPosisions(L2,polar,azimutal) );
// detectors at L2, sample at 0 and source at -L2_min
ws->setInstrument( ComponentCreationHelper::createCylInstrumentWithDetInGivenPosisions(L2,polar,azimutal) );

for (int g=0; g < static_cast<int>(numPixels); g++)
{
ISpectrum * spec = ws->getSpectrum(g);
spec->addDetectorID(g);
// we just made (in createCylInstrumentWithDetInGivenPosisions) det ID-s to start from 1
spec->setDetectorID(g+1);
// and this is absolutely different nummer, corresponding to det ID just by chance ? -- some uncertainties remain
spec->setSpectrumNo(g+1);
//spec->setSpectrumNo(g+1);
// spec->addDetectorID(g*9);
Expand Down

0 comments on commit 45091f2

Please sign in to comment.