|
musrfit 1.10.0
|
Utility class for msr2data: template-based msr-file generation and parameter extraction. More...
#include <PMsr2Data.h>
Public Member Functions | |
| PMsr2Data (const std::string &fileExtension) | |
| Constructor that initializes the msr2data handler. | |
| ~PMsr2Data () | |
| Destructor that cleans up resources. | |
| int | SetRunNumbers (unsigned int runNumber) |
| Sets a single run number for processing. | |
| int | SetRunNumbers (unsigned int firstRun, unsigned int lastRun) |
| Sets a range of run numbers (from first to last, inclusive). | |
| int | SetRunNumbers (const std::string &runListFileName) |
| Sets run numbers from a run list file. | |
| int | SetRunNumbers (const std::vector< unsigned int > &runVector) |
| Sets run numbers from an explicit vector. | |
| unsigned int | GetPresentRun () const |
| Gets the current run number being processed. | |
| int | DetermineRunNumberDigits (unsigned int maxRunNumber, bool templateFile) const |
| Determines the number of digits needed for run number formatting. | |
| int | CheckRunNumbersInRange () const |
| Validates that all run numbers are within acceptable ranges. | |
| int | ParseXmlStartupFile () |
| Parses the XML startup file for configuration. | |
| int | ReadMsrFile (const std::string &msrFileName) const |
| Reads and parses an msr-file. | |
| int | ReadRunDataFile () |
| Reads the run data file for the current run. | |
| bool | PrepareNewInputFile (unsigned int templateNumber, bool sorted) const |
| Generates a new msr-file from a template. | |
| bool | PrepareGlobalInputFile (unsigned int templateNumber, const std::string &globalOutputFile, unsigned int runListSize) const |
| Generates an msr-file for global (multi-run) fitting. | |
| int | WriteOutput (const std::string &outputFileName, const std::vector< unsigned int > ¶meters, bool dbFormat, unsigned int precision, bool global=false, unsigned int counter=0) const |
| Writes extracted parameters to output file. | |
Private Member Functions | |
| bool | PrepareNewSortedInputFile (unsigned int templateNumber) const |
| Generates a sorted msr-file from a template. | |
| PMsrHandler * | GetSingleRunMsrFile () const |
| Retrieves msr-file handler for a single run. | |
| void | WriteValue (std::fstream &outFile, const double &value, const unsigned int &width) const |
| Writes a single numeric value to output stream. | |
| void | WriteValue (std::fstream &outFile, const double &value, const double &errValue, const unsigned int &width, const bool &db) const |
| Writes a value with its error to output stream. | |
| int | GetFirstSignificantDigit (const double &value) const |
| Determines the first significant digit position of a value. | |
| bool | InParameterList (const unsigned int ¶mValue, const std::vector< unsigned int > ¶mList) const |
| Checks if a parameter is in the output parameter list. | |
Private Attributes | |
| std::string | fFileExtension |
| File extension for data files (e.g., "bin", "root") | |
| std::vector< unsigned int > | fRunVector |
| Vector of run numbers to process. | |
| std::vector< unsignedint >::const_iterator | fRunVectorIter |
| Iterator for current position in run vector. | |
| bool | fRunListFile |
| Flag indicating if run list is from a file. | |
| std::vector< std::string > | fIndVar |
| Independent variables for output. | |
| std::unique_ptr< std::ifstream > | fRunListFileStream |
| Stream for reading run list file. | |
| std::unique_ptr< TSAXParser > | fSaxParser |
| XML SAX parser for startup file. | |
| std::unique_ptr< PStartupHandler > | fStartupHandler |
| Handler for XML startup file configuration. | |
| std::unique_ptr< PRunDataHandler > | fDataHandler |
| Handler for run data files. | |
| std::unique_ptr< PMsrHandler > | fMsrHandler |
| Handler for msr-file parsing and generation. | |
| unsigned int | fNumGlobalParam |
| Number of global parameters in fit. | |
| unsigned int | fNumSpecParam |
| Number of spectrum-specific parameters. | |
| unsigned int | fNumTempRunBlocks |
| Number of temporary run blocks. | |
| unsigned int | fRunNumberDigits |
| Number of digits for run number formatting. | |
| bool | fHeaderWritten |
| Flag tracking if output header has been written. | |
Utility class for msr2data: template-based msr-file generation and parameter extraction.
PMsr2Data provides comprehensive functionality for the msr2data tool, which is used to:
Key Features:
Implementation Note: This class uses std::string and standard C++ string handling exclusively (rather than ROOT's TString) to demonstrate modern C++ practices, though this occasionally requires conversions when interfacing with PMusr classes.
Typical Workflow:
Definition at line 80 of file PMsr2Data.h.
| PMsr2Data::PMsr2Data | ( | const std::string & | ext | ) |
Constructor that initializes the msr2data handler.
| fileExtension | File extension for data files (e.g., "bin", "root", "mdu") |
Initializes all member variables and prepares the object for processing. Sets default values:
All handler pointers (SAX parser, startup handler, data handler, msr handler) are initialized to nullptr and will be created as needed during processing.
| ext | File extension for data files (e.g., ".bin", ".root", ".mdu") This extension is used to locate corresponding data files for each run |
Definition at line 73 of file PMsr2Data.cpp.
References fDataHandler, fFileExtension, fHeaderWritten, fMsrHandler, fNumGlobalParam, fNumSpecParam, fNumTempRunBlocks, fRunListFile, fRunNumberDigits, fRunVector, fRunVectorIter, fSaxParser, and fStartupHandler.
| PMsr2Data::~PMsr2Data | ( | ) |
Destructor that cleans up resources.
Clears all vectors and resets iterators. The unique_ptr members (fRunListFileStream, fSaxParser, fStartupHandler, fDataHandler, fMsrHandler) are automatically cleaned up through their destructors.
Definition at line 93 of file PMsr2Data.cpp.
References fIndVar, fRunVector, and fRunVectorIter.
| int PMsr2Data::CheckRunNumbersInRange | ( | ) | const |
Validates that all run numbers are within acceptable ranges.
Validates that all run numbers fit within the determined digit width.
Checks if all run numbers in the run vector can be represented with the number of digits determined from the data file naming convention. This prevents formatting errors when generating file names.
The check has been loosened since 2023 to accommodate LEM run numbers exceeding 9999 by allowing one extra digit beyond the determined width.
Maximum allowed run number = 10^(fRunNumberDigits+1) - 1
Definition at line 238 of file PMsr2Data.cpp.
References fRunNumberDigits, and fRunVector.
| int PMsr2Data::DetermineRunNumberDigits | ( | unsigned int | runNo, |
| bool | normalMode ) const |
Determines the number of digits needed for run number formatting.
Determines the number of digits used for run number formatting.
Analyzes run numbers to determine zero-padding requirements for consistent file naming.
| maxRunNumber | Maximum run number to consider |
| templateFile | Whether processing a template file |
Analyzes the first processable msr-file to determine how many digits are used for run number formatting in data file names. This ensures consistent zero-padding when generating new msr-files from templates.
The algorithm:
Example: If the data file is "run_0042.bin", this determines 4 digits.
| runNo | Run number to analyze |
| normalMode | true for normal mode, false for global fitting mode |
Definition at line 131 of file PMsr2Data.cpp.
References DetermineRunNumberDigits(), fFileExtension, fRunNumberDigits, fRunVector, and fRunVectorIter.
Referenced by DetermineRunNumberDigits().
|
private |
Determines the first significant digit position of a value.
Determines the position of the first significant digit.
Used for intelligent formatting and precision control.
| value | Value to analyze |
Calculates how many decimal places are needed to reach the first significant digit by repeatedly multiplying by 10 until the value is >= 1.0. This is used for precision control in output formatting.
Examples:
| value | Value to analyze (typically an error/uncertainty) |
Definition at line 2692 of file PMsr2Data.cpp.
Referenced by WriteValue().
| unsigned int PMsr2Data::GetPresentRun | ( | ) | const |
Gets the current run number being processed.
Returns the current run number being processed.
Retrieves the run number pointed to by the internal iterator. Used to track progress through the run list during processing.
Definition at line 267 of file PMsr2Data.cpp.
References fRunVector, and fRunVectorIter.
|
private |
Retrieves msr-file handler for a single run.
Retrieves msr-file handler for a single-run fit file.
Reads the "-OneRunFit" variant of the msr-file for the current run. This is used when extracting individual run results from global fits.
The file name format: "<runNumber>-OneRunFit<extension>.msr"
Definition at line 556 of file PMsr2Data.cpp.
References fFileExtension, fRunVectorIter, PMUSR_MSR_FILE_NOT_FOUND, PMUSR_MSR_SYNTAX_ERROR, PMUSR_SUCCESS, PMsrHandler::ReadMsrFile(), and status.
Referenced by PrepareGlobalInputFile().
|
private |
Checks if a parameter is in the output parameter list.
Checks if a parameter index should be included in output.
| paramValue | Parameter index to check |
| paramList | List of parameters to output |
Determines whether a given parameter should be written to the output file based on the user-specified parameter list. If the parameter list is empty, all parameters are included by default.
| paramValue | Zero-based parameter index to check |
| paramList | Vector of one-based parameter numbers to output (empty vector means output all parameters) |
Definition at line 2733 of file PMsr2Data.cpp.
Referenced by WriteOutput().
| int PMsr2Data::ParseXmlStartupFile | ( | ) |
Parses the XML startup file for configuration.
Parses the musrfit XML startup file for configuration.
Reads and processes the msr2data XML startup file containing paths, templates, and other configuration settings.
Creates a SAX parser and startup handler to read the musrfit_startup.xml configuration file. This file contains paths, templates, and other settings needed for msr2data operation.
The parseXmlFile function is used instead of ParseFile to avoid environment-specific issues encountered with direct parsing.
Definition at line 482 of file PMsr2Data.cpp.
References fSaxParser, fStartupHandler, parseXmlFile(), startup_path_name, and status.
| bool PMsr2Data::PrepareGlobalInputFile | ( | unsigned int | tempRun, |
| const std::string & | msrOutFile, | ||
| unsigned int | globalPlus ) const |
Generates an msr-file for global (multi-run) fitting.
Creates a combined msr-file for global fits across multiple runs.
| templateNumber | Template identifier number |
| globalOutputFile | Path to output global msr-file |
| runListSize | Number of runs in the global fit |
Generate a new global msr-file from a template
return:
| tempRun | template run number |
| msrOutFile | name of the global msr-file to be written |
| globalPlus | tag of the global mode to be used:
|
Definition at line 779 of file PMsr2Data.cpp.
References compare_parameters(), fFileExtension, fMsrHandler, fNumGlobalParam, fNumSpecParam, fNumTempRunBlocks, fRunNumberDigits, fRunVector, fRunVectorIter, PMsrHandler::GetMsrParamList(), GetSingleRunMsrFile(), MSR_PARAM_FUN_OFFSET, PMUSR_SUCCESS, PrepareNewInputFile(), PrepareNewSortedInputFile(), ReadMsrFile(), and status.
| bool PMsr2Data::PrepareNewInputFile | ( | unsigned int | tempRun, |
| bool | calledFromGlobalMode ) const |
Generates a new msr-file from a template.
Creates an msr-file by substituting run number placeholders in the template with actual run numbers.
| templateNumber | Template identifier number |
| sorted | Whether to generate sorted output |
Generate a new single-run msr file from a template
return:
| tempRun | template run number |
| calledFromGlobalMode | tag specifying if the routine is called as part of the global msr-file generation |
Definition at line 628 of file PMsr2Data.cpp.
References fFileExtension, fRunNumberDigits, fRunVector, and fRunVectorIter.
Referenced by PrepareGlobalInputFile().
|
private |
Generates a sorted msr-file from a template.
Internal helper for creating sorted msr-files with proper histogram ordering.
| templateNumber | Template identifier number |
Generate a new msr-file for a single run in which the parameters are sorted for a global fit An internal sorted msr-file data structure has to be present.
return:
| tempRun | template run number |
Definition at line 1669 of file PMsr2Data.cpp.
References fFileExtension, fMsrHandler, fNumGlobalParam, fNumTempRunBlocks, fRunNumberDigits, fRunVectorIter, PMUSR_SUCCESS, and status.
Referenced by PrepareGlobalInputFile().
| int PMsr2Data::ReadMsrFile | ( | const std::string & | infile | ) | const |
Reads and parses an msr-file.
| msrFileName | Path to the msr-file to read |
Creates a new PMsrHandler and uses it to read and parse the specified msr-file into the internal data structure.
| infile | Path to the msr-file to read |
Definition at line 517 of file PMsr2Data.cpp.
References fMsrHandler, PMUSR_MSR_FILE_NOT_FOUND, PMUSR_MSR_SYNTAX_ERROR, PMUSR_SUCCESS, and status.
Referenced by PrepareGlobalInputFile().
| int PMsr2Data::ReadRunDataFile | ( | ) |
Reads the run data file for the current run.
Creates a PRunDataHandler and reads the experimental data file associated with the current msr-file. Uses data paths from the startup handler if available, otherwise uses defaults.
Definition at line 599 of file PMsr2Data.cpp.
References fDataHandler, fMsrHandler, and fStartupHandler.
| int PMsr2Data::SetRunNumbers | ( | const std::string & | runListFile | ) |
Sets run numbers from a run list file.
Reads run numbers from a text file, one run number per line.
| runListFileName | Path to file containing run numbers |
Reads run numbers from a text file with the following format:
Example run list file:
* RUN FIELD TEMP * 1234 0.5 295.0 * 1235 1.0 295.0 # This is a comment * 1236 1.5 295.0 *
| runListFile | Path to run list file |
Definition at line 400 of file PMsr2Data.cpp.
References fIndVar, fRunListFile, fRunListFileStream, fRunVector, and fRunVectorIter.
| int PMsr2Data::SetRunNumbers | ( | const std::vector< unsigned int > & | runListVector | ) |
Sets run numbers from an explicit vector.
| runVector | Vector of run numbers to process |
Clears any existing run list and copies the provided vector of run numbers. All run numbers in the vector must be valid (>= 1).
| runListVector | Vector containing run numbers to process |
Definition at line 355 of file PMsr2Data.cpp.
References fRunVector, and fRunVectorIter.
| int PMsr2Data::SetRunNumbers | ( | unsigned int | runNoStart, |
| unsigned int | runNoEnd ) |
Sets a range of run numbers (from first to last, inclusive).
Sets a range of run numbers for processing.
| firstRun | First run number in the range |
| lastRun | Last run number in the range |
Clears any existing run list and populates it with all run numbers from runNoStart to runNoEnd (inclusive). Handles both ascending and descending ranges automatically.
| runNoStart | First run number in the range (must be >= 1) |
| runNoEnd | Last run number in the range (must be >= 1) |
Definition at line 321 of file PMsr2Data.cpp.
References fRunVector, and fRunVectorIter.
| int PMsr2Data::SetRunNumbers | ( | unsigned int | runNo | ) |
Sets a single run number for processing.
| runNumber | Single run number to process |
Clears any existing run list and initializes with a single run number. The internal iterator is reset to point to the beginning.
| runNo | Run number to process (must be >= 1) |
Definition at line 290 of file PMsr2Data.cpp.
References fRunVector, and fRunVectorIter.
| int PMsr2Data::WriteOutput | ( | const std::string & | outfile, |
| const std::vector< unsigned int > & | paramList, | ||
| bool | db, | ||
| unsigned int | withHeader, | ||
| bool | global = false, | ||
| unsigned int | counter = 0 ) const |
Writes extracted parameters to output file.
Outputs fit parameters in either DB format or ASCII table format.
| outputFileName | Output file path |
| parameters | Vector of parameter indices to output |
| dbFormat | Whether to use DB format (true) or ASCII (false) |
| precision | Number of significant digits for output |
| global | Whether this is global fit output |
| counter | Counter for global fit indexing |
Append fit parameters of a msr file to the DB or ASCII file
return:
| outfile | name of the DB/ASCII output file |
| paramList | parameter list which shall be written to the output file |
| db | DB or plain ASCII output |
| withHeader | write output file header or not |
| global | global mode or not |
| counter | counter used within the global mode to determine how many runs have been processed already |
Definition at line 1775 of file PMsr2Data.cpp.
References PMsrStatisticStructure::fChisq, fDataHandler, fHeaderWritten, fIndVar, PMsrStatisticStructure::fMin, fMsrHandler, PMsrStatisticStructure::fNdf, fNumGlobalParam, fNumSpecParam, fNumTempRunBlocks, fRunListFile, fRunListFileStream, fRunNumberDigits, fRunVector, fRunVectorIter, PMsrStatisticStructure::fValid, PRawRunData::GetEnergy(), PRawRunData::GetField(), PRawRunData::GetMuonSpinAngle(), PRawRunData::GetNoOfTemperatures(), PRawRunData::GetRingAnode(), PRawRunData::GetTemperature(), PRawRunData::GetTempError(), PRawRunData::GetTransport(), InParameterList(), PMUSR_SUCCESS, PMUSR_UNDEFINED, and WriteValue().
|
private |
Writes a value with its error to output stream.
Writes a value with error-based precision formatting.
Formats output based on DB or ASCII mode.
| outFile | Output file stream |
| value | Value to write |
| errValue | Error/uncertainty value |
| width | Field width for formatting |
| db | Whether to use DB format (true) or ASCII (false) |
Formats output with precision determined by the error value, ensuring significant digits are preserved appropriately. The precision is calculated based on the first significant digit of the error.
Examples:
Formatting rules:
| outFile | Output file stream |
| value | Numeric value to write |
| errValue | Error/uncertainty value (determines precision) |
| width | Field width for formatted output |
| db | true for DB format, false for ASCII format (adds extra space) |
Definition at line 2645 of file PMsr2Data.cpp.
References GetFirstSignificantDigit().
|
private |
Writes a single numeric value to output stream.
Writes a formatted numeric value to output stream.
| outFile | Output file stream |
| value | Value to write |
| width | Field width for formatting |
Formats the value for column-aligned ASCII output with automatic selection of scientific notation for very large or very small numbers.
Formatting rules:
| outFile | Output file stream |
| value | Numeric value to write |
| width | Column width for formatting |
Definition at line 2609 of file PMsr2Data.cpp.
Referenced by WriteOutput().
|
mutableprivate |
Handler for run data files.
Definition at line 308 of file PMsr2Data.h.
Referenced by PMsr2Data(), ReadRunDataFile(), and WriteOutput().
|
private |
File extension for data files (e.g., "bin", "root")
Definition at line 300 of file PMsr2Data.h.
Referenced by DetermineRunNumberDigits(), GetSingleRunMsrFile(), PMsr2Data(), PrepareGlobalInputFile(), PrepareNewInputFile(), and PrepareNewSortedInputFile().
|
mutableprivate |
Flag tracking if output header has been written.
Definition at line 314 of file PMsr2Data.h.
Referenced by PMsr2Data(), and WriteOutput().
|
private |
Independent variables for output.
Definition at line 304 of file PMsr2Data.h.
Referenced by SetRunNumbers(), WriteOutput(), and ~PMsr2Data().
|
mutableprivate |
Handler for msr-file parsing and generation.
Definition at line 309 of file PMsr2Data.h.
Referenced by PMsr2Data(), PrepareGlobalInputFile(), PrepareNewSortedInputFile(), ReadMsrFile(), ReadRunDataFile(), and WriteOutput().
|
mutableprivate |
Number of global parameters in fit.
Definition at line 310 of file PMsr2Data.h.
Referenced by PMsr2Data(), PrepareGlobalInputFile(), PrepareNewSortedInputFile(), and WriteOutput().
|
mutableprivate |
Number of spectrum-specific parameters.
Definition at line 311 of file PMsr2Data.h.
Referenced by PMsr2Data(), PrepareGlobalInputFile(), and WriteOutput().
|
mutableprivate |
Number of temporary run blocks.
Definition at line 312 of file PMsr2Data.h.
Referenced by PMsr2Data(), PrepareGlobalInputFile(), PrepareNewSortedInputFile(), and WriteOutput().
|
private |
Flag indicating if run list is from a file.
Definition at line 303 of file PMsr2Data.h.
Referenced by PMsr2Data(), SetRunNumbers(), and WriteOutput().
|
private |
Stream for reading run list file.
Definition at line 305 of file PMsr2Data.h.
Referenced by SetRunNumbers(), and WriteOutput().
|
mutableprivate |
Number of digits for run number formatting.
Definition at line 313 of file PMsr2Data.h.
Referenced by CheckRunNumbersInRange(), DetermineRunNumberDigits(), PMsr2Data(), PrepareGlobalInputFile(), PrepareNewInputFile(), PrepareNewSortedInputFile(), and WriteOutput().
|
private |
Vector of run numbers to process.
Definition at line 301 of file PMsr2Data.h.
Referenced by CheckRunNumbersInRange(), DetermineRunNumberDigits(), GetPresentRun(), PMsr2Data(), PrepareGlobalInputFile(), PrepareNewInputFile(), SetRunNumbers(), SetRunNumbers(), SetRunNumbers(), SetRunNumbers(), WriteOutput(), and ~PMsr2Data().
|
mutableprivate |
Iterator for current position in run vector.
Definition at line 302 of file PMsr2Data.h.
Referenced by DetermineRunNumberDigits(), GetPresentRun(), GetSingleRunMsrFile(), PMsr2Data(), PrepareGlobalInputFile(), PrepareNewInputFile(), PrepareNewSortedInputFile(), SetRunNumbers(), SetRunNumbers(), SetRunNumbers(), SetRunNumbers(), WriteOutput(), and ~PMsr2Data().
|
private |
XML SAX parser for startup file.
Definition at line 306 of file PMsr2Data.h.
Referenced by ParseXmlStartupFile(), and PMsr2Data().
|
private |
Handler for XML startup file configuration.
Definition at line 307 of file PMsr2Data.h.
Referenced by ParseXmlStartupFile(), PMsr2Data(), and ReadRunDataFile().