Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/8251_SaveIsawPeaks_for_W…
Browse files Browse the repository at this point in the history
…ISH'
  • Loading branch information
wdzhou committed Dec 13, 2013
2 parents b28aeb6 + 1f6465a commit c38ce72
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ namespace Crystal
void init();
/// Run the algorithm
void exec();

/// find position for rectangular and non-rectangular
Kernel::V3D findPixelPos(std::string bankName, int col, int row);
void sizeBanks(std::string bankName, int& NCOLS, int& NROWS, double& xsize, double& ysize);
Geometry::Instrument_const_sptr inst;

};

Expand Down
99 changes: 72 additions & 27 deletions Code/Mantid/Framework/Crystal/src/SaveIsawPeaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ namespace Crystal
// Save the "bank" part once to check whether it really is a bank
if( bankPart == "?") bankPart = bankName.substr(0,4);
// Take out the "bank" part of the bank name and convert to an int
bankName = bankName.substr(4, bankName.size()-4);
if( bankPart == "bank")bankName = bankName.substr(4, bankName.size()-4);
else if( bankPart == "WISH")bankName = bankName.substr(9, bankName.size()-9);
Strings::convert(bankName, bank);

// Save in the map
Expand All @@ -126,10 +127,10 @@ namespace Crystal
uniqueBanks.insert(bank);
}

Instrument_const_sptr inst = ws->getInstrument();
inst = ws->getInstrument();
if (!inst) throw std::runtime_error("No instrument in PeaksWorkspace. Cannot save peaks file.");

if( bankPart != "bank" && bankPart != "?" ) {
if( bankPart != "bank" && bankPart != "WISH" && bankPart != "?" ) {
std::ostringstream mess; mess << "Detector module of type " << bankPart << " not supported in ISAWPeaks. Cannot save peaks file";
throw std::runtime_error( mess.str() );
}
Expand Down Expand Up @@ -180,10 +181,12 @@ namespace Crystal
// Build up the bank name
int bank = *it;
std::ostringstream mess;
mess << "bank" << bank;
if( bankPart == "bank")mess << "bank" << bank;
else if( bankPart == "WISH")mess << "WISHpanel0" << bank;

std::string bankName = mess.str();
// Retrieve it
RectangularDetector_const_sptr det = boost::dynamic_pointer_cast<const RectangularDetector>(inst->getComponentByName(bankName));
boost::shared_ptr<const IComponent> det = inst->getComponentByName(bankName);
if (det)
{
// Center of the detector
Expand All @@ -192,19 +195,22 @@ namespace Crystal
double detd = (center - inst->getSample()->getPos()).norm();

// Base unit vector (along the horizontal, X axis)
V3D base = det->getAtXY(det->xpixels()-1,0)->getPos() - det->getAtXY(0,0)->getPos();
V3D base = findPixelPos(bankName,1,0) - findPixelPos(bankName,0,0);
base.normalize();
// Up unit vector (along the vertical, Y axis)
V3D up = det->getAtXY(0,det->ypixels()-1)->getPos() - det->getAtXY(0,0)->getPos();
V3D up = findPixelPos(bankName,0,1) - findPixelPos(bankName,0,0);
up.normalize();
int NCOLS, NROWS;
double xsize, ysize;
sizeBanks(bankName, NCOLS, NROWS, xsize, ysize);

// Write the line
out << "5 "
<< std::setw(6) << std::right << bank << " "
<< std::setw(6) << std::right << det->xpixels() << " "
<< std::setw(6) << std::right << det->ypixels() << " "
<< std::setw(7) << std::right << std::fixed << std::setprecision(4) << 100.0*det->xsize() << " "
<< std::setw(7) << std::right << std::fixed << std::setprecision(4) << 100.0*det->ysize() << " "
<< std::setw(6) << std::right << NCOLS << " "
<< std::setw(6) << std::right << NROWS << " "
<< std::setw(7) << std::right << std::fixed << std::setprecision(4) << 100.0*xsize << " "
<< std::setw(7) << std::right << std::fixed << std::setprecision(4) << 100.0*ysize << " "
<< " 0.2000 "
<< std::setw(6) << std::right << std::fixed << std::setprecision(2) << 100.0*detd << " "
<< std::setw(9) << std::right << std::fixed << std::setprecision(4) << 100.0*center.X() << " "
Expand Down Expand Up @@ -360,24 +366,63 @@ namespace Crystal
out.flush();
out.close();

// //REMOVE:
// std::string line;
// std::ifstream myfile (filename.c_str());
// if (myfile.is_open())
// {
// while ( myfile.good() )
// {
// getline (myfile,line);
// std::cout << line << std::endl;
// }
// myfile.close();
// }


}



V3D SaveIsawPeaks::findPixelPos(std::string bankName, int col, int row)
{
boost::shared_ptr<const IComponent> parent = inst->getComponentByName(bankName);
if (parent->type().compare("RectangularDetector") == 0)
{
boost::shared_ptr<const RectangularDetector> RDet = boost::dynamic_pointer_cast<
const RectangularDetector>(parent);

boost::shared_ptr<Detector> pixel = RDet->getAtXY(col, row);
return pixel->getPos();
}
else
{
std::vector<Geometry::IComponent_const_sptr> children;
boost::shared_ptr<const Geometry::ICompAssembly> asmb = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(parent);
asmb->getChildren(children, false);
boost::shared_ptr<const Geometry::ICompAssembly> asmb2 = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(children[col]);
std::vector<Geometry::IComponent_const_sptr> grandchildren;
asmb2->getChildren(grandchildren,false);
Geometry::IComponent_const_sptr first = grandchildren[row];
return first->getPos();
}
}
void SaveIsawPeaks::sizeBanks(std::string bankName, int& NCOLS, int& NROWS, double& xsize, double& ysize)
{
if (bankName.compare("None") == 0) return;
boost::shared_ptr<const IComponent> parent = inst->getComponentByName(bankName);
if (parent->type().compare("RectangularDetector") == 0)
{
boost::shared_ptr<const RectangularDetector> RDet = boost::dynamic_pointer_cast<
const RectangularDetector>(parent);

NCOLS = RDet->xpixels();
NROWS = RDet->ypixels();
xsize = RDet->xsize();
ysize = RDet->ysize();
}
else
{
std::vector<Geometry::IComponent_const_sptr> children;
boost::shared_ptr<const Geometry::ICompAssembly> asmb = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(parent);
asmb->getChildren(children, false);
boost::shared_ptr<const Geometry::ICompAssembly> asmb2 = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(children[0]);
std::vector<Geometry::IComponent_const_sptr> grandchildren;
asmb2->getChildren(grandchildren,false);
NROWS = static_cast<int>(grandchildren.size());
NCOLS = static_cast<int>(children.size());
Geometry::IComponent_const_sptr first = children[0];
Geometry::IComponent_const_sptr last = children[NCOLS-1];
xsize = first->getDistance(*last);
first = grandchildren[0];
last = grandchildren[NROWS-1];
ysize = first->getDistance(*last);
}
}


} // namespace Mantid
Expand Down

0 comments on commit c38ce72

Please sign in to comment.