Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algorithm to calibrate detector phases #13840

Merged
merged 56 commits into from
Oct 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
731710d
Re #11588 Remove unnecessary stuff
raquelalvarezbanos Sep 11, 2015
9004709
Re #11588 Remove more unnecessary stuff
raquelalvarezbanos Sep 11, 2015
58d29ce
Re #11588 And more...
raquelalvarezbanos Sep 11, 2015
5c41b32
Re #11588 Update PhaseQuad methods
raquelalvarezbanos Sep 14, 2015
e96f965
Re #11588 Use previous loseExpDecay method
raquelalvarezbanos Sep 16, 2015
75f7a73
Re #11588 Set the correct errors for the asymm + other minor changes
raquelalvarezbanos Sep 16, 2015
e72329e
Re #11588 Set the correct number of X values in outupt ws
raquelalvarezbanos Sep 16, 2015
f713d2e
Re #11588 Refactor how the exponential decay is removed
raquelalvarezbanos Sep 16, 2015
0286ade
Re #11588 Rename some variables
raquelalvarezbanos Sep 17, 2015
9b8a768
Re #11588 Don't need a separate method to regain exp decay
raquelalvarezbanos Sep 17, 2015
8956be5
Re #11588 Update comments + clang format
raquelalvarezbanos Sep 17, 2015
7e61a69
Re #11588 Remove unnecessary stuff and validate inputs
raquelalvarezbanos Sep 17, 2015
99e3946
Re #11588 Get rid of #defines, use PhysicalConstants
raquelalvarezbanos Sep 17, 2015
fc9b464
Re #11588 Set output units
raquelalvarezbanos Sep 17, 2015
6798bef
Re #11588 Update doc and set the output axis correctly
raquelalvarezbanos Sep 17, 2015
f7c502b
Re #11588 Remove test which uses phase list as input
raquelalvarezbanos Sep 17, 2015
950cb45
Re #11588 Update unit test results
raquelalvarezbanos Sep 17, 2015
84d3eaa
Re #11588 Use alg manager, don't use ADS
raquelalvarezbanos Sep 17, 2015
1472c8e
Re #11588 Rename DetectorTable to PhaseTable
raquelalvarezbanos Sep 17, 2015
a013be0
Re #11588 Fix compiler warnings
raquelalvarezbanos Sep 18, 2015
79b33a5
Re #11588 Need a third column for the asymmetries
raquelalvarezbanos Sep 23, 2015
b63a975
Re #11588 Updated unit test
raquelalvarezbanos Sep 23, 2015
06697a2
Re #11588 Update algorithm's documentation
raquelalvarezbanos Sep 23, 2015
bd9ac6f
Re #11868 Create necessary classes with class_maker
raquelalvarezbanos Sep 28, 2015
073fa52
Re #11868 Added necessary properties
raquelalvarezbanos Sep 28, 2015
5e35b04
Re #11868 Prepare the ws for the fit
raquelalvarezbanos Sep 28, 2015
1b3a9de
Re #11868 Trying different options for the fit. This one seems to work
raquelalvarezbanos Sep 29, 2015
5db9c36
Re #11868 Use fitWorkspace() method on tempWS
raquelalvarezbanos Sep 29, 2015
421a796
Re #11868 Added a method to extract the relevant information
raquelalvarezbanos Sep 29, 2015
c98e9bb
Re #11868 Handle negative amplitudes
raquelalvarezbanos Sep 29, 2015
90b3972
Re #11868 Validate inputs and change asymmetry and phase init values
raquelalvarezbanos Sep 29, 2015
eaee012
Merge branch '11588_PhaseQuad_improvements' into 11868_New_CalMuonDet…
raquelalvarezbanos Sep 29, 2015
f4b6d6a
Re #11868 Minor update + descriptions
raquelalvarezbanos Sep 29, 2015
8ff84f8
Re #11868 Return the fitting results as a ws group
raquelalvarezbanos Sep 29, 2015
4e5ebeb
Re #11868 Handle detector phases in a more compact way
raquelalvarezbanos Sep 29, 2015
7977784
Re #11868 Add a test to make sure all omega values are the same
raquelalvarezbanos Sep 29, 2015
592c38b
Re #11868 Report progress
raquelalvarezbanos Sep 29, 2015
048a372
Re #11588 Fixed an important bug
raquelalvarezbanos Sep 30, 2015
f66f5c7
Re #11588 Handle possible negative X values
raquelalvarezbanos Sep 30, 2015
8f775dd
Re #11588 Update unit test results
raquelalvarezbanos Sep 30, 2015
48a575b
Re #11588 Correct the phase table order, first asymmetry then phase
raquelalvarezbanos Sep 30, 2015
54df6e6
Merge branch '11588_PhaseQuad_improvements' into 11868_New_CalMuonDet…
raquelalvarezbanos Sep 30, 2015
65995ba
Re #11868 Updated documentation
raquelalvarezbanos Sep 30, 2015
05e8000
Re #13819 Added FirstGoodData and updated unit test
raquelalvarezbanos Oct 1, 2015
deccf3c
Merge branch '13819_Add_FirstGoodData_to_log_values' into 11868_New_C…
raquelalvarezbanos Oct 1, 2015
e75758c
Re #11868 Set startTime to 0 when FirstGoodData can't be read
raquelalvarezbanos Oct 1, 2015
e6682c3
Re #11868 Read sample_magn_field when frequency is left blank
raquelalvarezbanos Oct 1, 2015
44e98cd
Re #11868 Use the workspace name provided by the user
raquelalvarezbanos Oct 1, 2015
10e6f1a
Re #11868 Added user example
raquelalvarezbanos Oct 1, 2015
df62b11
Re #11868 Minor updates to documentation
raquelalvarezbanos Oct 2, 2015
1b26541
Re #11868 Added a unit test
raquelalvarezbanos Oct 2, 2015
b7f8c42
Re #11868 Update unit test
raquelalvarezbanos Oct 2, 2015
0898098
Re #11868 Added to more tests
raquelalvarezbanos Oct 2, 2015
71769ec
Re #11868 Minor updates
raquelalvarezbanos Oct 2, 2015
8fabc55
Re #11868 Fix warnings
raquelalvarezbanos Oct 2, 2015
b4807b2
Re #11868 Second attempt
raquelalvarezbanos Oct 2, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set ( SRC_FILES
src/BinaryOperateMasks.cpp
src/BinaryOperation.cpp
src/CalMuonDeadTime.cpp
src/CalMuonDetectorPhases.cpp
src/CalculateDIFC.cpp
src/CalculateEfficiency.cpp
src/CalculateFlatBackground.cpp
Expand Down Expand Up @@ -155,7 +156,7 @@ set ( SRC_FILES
src/Minus.cpp
src/ModeratorTzero.cpp
src/ModeratorTzeroLinear.cpp
src/MonitorEfficiencyCorUser.cpp
src/MonitorEfficiencyCorUser.cpp
src/MonteCarloAbsorption.cpp
src/MultipleScatteringCylinderAbsorption.cpp
src/Multiply.cpp
Expand Down Expand Up @@ -294,6 +295,7 @@ set ( INC_FILES
inc/MantidAlgorithms/BinaryOperateMasks.h
inc/MantidAlgorithms/BinaryOperation.h
inc/MantidAlgorithms/CalMuonDeadTime.h
inc/MantidAlgorithms/CalMuonDetectorPhases.h
inc/MantidAlgorithms/CalculateDIFC.h
inc/MantidAlgorithms/CalculateEfficiency.h
inc/MantidAlgorithms/CalculateFlatBackground.h
Expand Down Expand Up @@ -428,7 +430,7 @@ set ( INC_FILES
inc/MantidAlgorithms/Minus.h
inc/MantidAlgorithms/ModeratorTzero.h
inc/MantidAlgorithms/ModeratorTzeroLinear.h
inc/MantidAlgorithms/MonitorEfficiencyCorUser.h
inc/MantidAlgorithms/MonitorEfficiencyCorUser.h
inc/MantidAlgorithms/MonteCarloAbsorption.h
inc/MantidAlgorithms/MultipleScatteringCylinderAbsorption.h
inc/MantidAlgorithms/Multiply.h
Expand Down Expand Up @@ -578,6 +580,7 @@ set ( TEST_FILES
BinaryOperateMasksTest.h
BinaryOperationTest.h
CalMuonDeadTimeTest.h
CalMuonDetectorPhasesTest.h
CalculateDIFCTest.h
CalculateEfficiencyTest.h
CalculateFlatBackgroundTest.h
Expand Down Expand Up @@ -701,7 +704,7 @@ set ( TEST_FILES
MinusTest.h
ModeratorTzeroLinearTest.h
ModeratorTzeroTest.h
MonitorEfficiencyCorUserTest.h
MonitorEfficiencyCorUserTest.h
MonteCarloAbsorptionTest.h
MultipleScatteringCylinderAbsorptionTest.h
MultiplyRangeTest.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef MANTID_ALGORITHMS_CALMUONDETECTORPHASES_H_
#define MANTID_ALGORITHMS_CALMUONDETECTORPHASES_H_

#include "MantidAlgorithms/DllConfig.h"
#include "MantidAPI/Algorithm.h"
namespace Mantid {
namespace Algorithms {

/** CalMuonDetectorPhases : Calculates asymmetry and phase for each spectra in a workspace

Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source

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://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport CalMuonDetectorPhases : public API::Algorithm {
public:
/// Default constructor
CalMuonDetectorPhases() : API::Algorithm(){};
/// Destructor
virtual ~CalMuonDetectorPhases(){};
/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "CalMuonDetectorPhases"; }
/// Summary of algorithms purpose
virtual const std::string summary() const {
return "Calculates the asymmetry and phase for each detector in a workspace.";
}

/// Algorithm's version for identification overriding a virtual method
virtual int version() const { return 1; }
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "Muon"; }

private:
/// Initialise the algorithm
void init();
/// Execute the algorithm
void exec();
/// Validate the inputs
std::map<std::string, std::string> validateInputs();
/// Prepare workspace for fit
API::MatrixWorkspace_sptr
prepareWorkspace(const API::MatrixWorkspace_sptr &ws, double startTime,
double endTime);
/// Fit the workspace
void fitWorkspace(const API::MatrixWorkspace_sptr &ws, double freq,
std::string groupName, API::ITableWorkspace_sptr &resTab,
API::WorkspaceGroup_sptr &resGroup);
/// Create the fitting function as string
std::string createFittingFunction(int nspec, double freq);
/// Extract asymmetry and phase from fitting results
API::ITableWorkspace_sptr
extractDetectorInfo(const API::ITableWorkspace_sptr &paramTab, size_t nspec);
};
} // namespace Algorithms
} // namespace Mantid

#endif /* MANTID_ALGORITHMS_CALMUONDETECTORPHASES_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ Code Documentation is available at: <http://doxygen.mantidproject.org>
class DLLExport PhaseQuadMuon : public API::Algorithm {
public:
/// Default constructor
PhaseQuadMuon()
: API::Algorithm(), m_muLife(2.19703), m_bigNumber(1e10), m_tPulseOver(0),
m_pulseTail(182), m_poissonLim(30), m_pulseTwo(0.325), m_nHist(0),
m_nData(0), m_res(0.0), m_meanLag(0.0), m_tValid(0), m_isDouble(false),
m_tMin(0.0){};
PhaseQuadMuon() {};
/// Destructor
virtual ~PhaseQuadMuon(){};
/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "PhaseQuad"; }
/// Summary of algorithm's purpose
virtual const std::string summary() const {
return "Calculate Muon squashograms from InputWorkspace and PhaseTable/PhaseList.";
return "Generates a quadrature phase signal.";
}

/// Algorithm's version for identification overriding a virtual method
Expand All @@ -57,71 +53,18 @@ class DLLExport PhaseQuadMuon : public API::Algorithm {
virtual const std::string category() const { return "Muon"; }

private:
class HistData {
public:
bool detOK; // Detector is OK
double n0; // Detector n0
double alpha; // Detector efficiency
double phi; // Detector phase
};

/// Initialise the properties
void init();
/// Run the algorithm
void exec();
/// Convert X units from micro-secs to nano-secs and shift to start at t=0
void convertToNanoSecs(API::MatrixWorkspace_sptr inputWs);
/// Convert X units from nano-secs to micro-secs and shift back
void convertToMicroSecs(API::MatrixWorkspace_sptr inputWs);
/// Load the Phase Table
void loadPhaseTable(API::ITableWorkspace_sptr phaseTable,
API::ITableWorkspace_sptr deadTimeTable);
/// Load the Phase List
void loadPhaseList(const std::string &filename,
API::ITableWorkspace_sptr deadTimeTable);
/// Apply dead time correction
void deadTimeCorrection(API::MatrixWorkspace_sptr inputWs,
API::ITableWorkspace_sptr deadTimeTable,
API::MatrixWorkspace_sptr &tempWs);
/// Rescale detector efficiency to maximum value
void normaliseAlphas(std::vector<HistData> &m_histData);
/// Remove exponential decay from input histograms
void loseExponentialDecay(API::MatrixWorkspace_sptr tempWs);
/// Validate inputs
std::map<std::string, std::string> validateInputs();
/// Calculate the normalization constants
std::vector<double> getExponentialDecay(const API::MatrixWorkspace_sptr &ws);
/// Create squashograms
void squash(const API::MatrixWorkspace_sptr tempWs,
API::MatrixWorkspace_sptr outputWs);
/// Put back in exponential decay
void regainExponential(API::MatrixWorkspace_sptr outputWs);
/// Muon lifetime
double m_muLife;
/// Maximum counts expected
double m_bigNumber;
/// Pulse definitely finished by here (bin no)
int m_tPulseOver;
/// Number of bins to exclude after lag-time (ie pulse arrival time)
double m_pulseTail;
/// Poisson limit
double m_poissonLim;
/// Time (microsec) by which a well-def'd point in the first proton/pion pulse
/// leads its counterpart in the second
double m_pulseTwo;
/// Number of input histograms
int m_nHist;
/// Number of datapoints per histogram
int m_nData;
/// Time resolution
double m_res;
/// Mean of time-shifts
double m_meanLag;
/// Good muons from here on (bin no). Unused now but can be needed in the
/// future
int m_tValid;
/// Double-pulse flag
bool m_isDouble;
/// Minimum value of t
double m_tMin;
/// Vector of detector data
std::vector<HistData> m_histData;
API::MatrixWorkspace_sptr squash(const API::MatrixWorkspace_sptr &ws,
const API::ITableWorkspace_sptr &phase,
const std::vector<double> &n0);
};

} // namespace Algorithms
Expand Down