10 MACH3LOG_DEBUG(
"InputManager: have loaded translation config file");
22 MACH3LOG_DEBUG(
"Will now check the specified parameters for tags");
27 std::vector<std::string> tags;
34 tags = Get<std::vector<std::string>>(
_parametersConfig[param][
"tags"], __FILE__, __LINE__);
46 std::vector<std::string> tags;
53 tags = Get<std::vector<std::string>>(
_samplesConfig[samp][
"tags"], __FILE__, __LINE__);
85 if (printLevel ==
"dump")
98 if (printLevel ==
"summary")
101 }
else if (printLevel ==
"dump")
110 std::string errorType)
const {
119 MACH3LOG_CRITICAL(
"Requested error type, {} does not exist in the specified file: ", errorType);
126 if (inputFileDef.
postFitErrors.at(errorType).find(paramName) !=
129 return inputFileDef.
postFitErrors.at(errorType).at(paramName);
138 std::string errorType)
const {
147 MACH3LOG_CRITICAL(
"Requested error type, {} does not exist in the specified file: ", errorType);
154 if (inputFileDef.
postFitValues.at(errorType).find(paramName) !=
157 return inputFileDef.
postFitValues.at(errorType).at(paramName);
171 const std::unordered_map<std::string, std::vector<std::string>> &tagMap,
172 const std::vector<std::string> &tags, std::string checkType)
const {
175 checkType !=
"all" &&
176 checkType !=
"any" &&
180 MACH3LOG_ERROR(
"Invalid tag check type specified: {}. Will instead use the default type: 'all'", checkType);
185 if (tags.size() == 0)
return values;
187 std::vector<std::string> retVec;
189 MACH3LOG_DEBUG(
"Getting tagged values using checkType {}", checkType);
190 for ( std::string val: values )
194 const std::vector<std::string> &valTags = tagMap.at(val);
197 if (valTags.size() == 0)
continue;
200 unsigned int tagCount = 0;
201 for (
const std::string &tag: tags )
203 if ( std::find( valTags.begin(), valTags.end(), tag ) != valTags.end() )
211 if ( checkType ==
"all" )
213 if ( tagCount == tags.size() ) retVec.push_back(val);
215 else if ( checkType ==
"any" )
217 if ( tagCount > 0 ) retVec.push_back(val);
219 else if ( checkType ==
"exact" )
222 if ( tagCount == valTags.size() ) retVec.push_back(val);
225 MACH3LOG_DEBUG(
"Found {} values matching the specified tags", retVec.size());
231 const std::string &sample,
const std::string ¶meter2)
const {
232 std::string locationString(rawLocationString);
233 std::vector<std::string> tokens;
236 std::string toReplace =
"";
240 toReplace =
"{PARAMETER}";
241 while ((pos = locationString.find(toReplace)) != std::string::npos)
243 locationString.replace(pos, toReplace.length(),
248 toReplace =
"{SAMPLE}";
249 while ((pos = locationString.find(toReplace)) != std::string::npos)
251 locationString.replace(pos, toReplace.length(),
257 toReplace =
"{PARAMETER2}";
258 while ((pos = locationString.find(toReplace)) != std::string::npos)
260 locationString.replace(pos, toReplace.length(),
268 std::string delimiter =
":";
269 while ((pos = locationString.find(delimiter)) != std::string::npos)
271 token = locationString.substr(0, pos);
272 tokens.push_back(token);
273 locationString.erase(0, pos + delimiter.length());
275 tokens.push_back(locationString);
279 if (tokens.size() > 2)
281 throw MaCh3Exception(__FILE__ , __LINE__,
"Too many : tokens in location string: " + rawLocationString);
288 const std::vector<std::string> &locationVec)
const {
289 std::shared_ptr<TObject>
object =
nullptr;
292 if (locationVec.size() == 1)
294 object = std::shared_ptr<TObject>(fileDef.
file->Get(locationVec[0].c_str()));
299 else if (locationVec.size() == 2)
301 TDirectoryFile *directory = fileDef.
file->Get<TDirectoryFile>(locationVec[0].c_str());
302 size_t nMatchingObjects = 0;
305 if (directory ==
nullptr)
313 TIter next(directory->GetListOfKeys());
314 while (TKey *key =
static_cast<TKey*
>(next()))
316 if (
strEndsWith(std::string(key->GetName()), locationVec[1]))
318 object = std::shared_ptr<TObject>(directory->Get(key->GetName()));
324 if (nMatchingObjects > 1)
326 MACH3LOG_CRITICAL(
"Too many objects match the pattern specified by {} {}", locationVec[0], locationVec.size()==2 ? locationVec[1] :
"");
327 MACH3LOG_CRITICAL(
"Found {} matching objects, should just be one", nMatchingObjects);
335 MACH3LOG_CRITICAL(
"Should have two elements: [ (directory to look in), (end of the name of the object) ]");
336 MACH3LOG_CRITICAL(
"Or one element that is just the absolute path to the object");
344 std::string &fitter,
const std::string &sample,
bool setInputFileScan) {
348 YAML::Node testLLHConfig = thisFitterSpec_config[
"bySample_LLH"];
349 auto testLLHRawLocations = Get<std::vector<std::string>>(testLLHConfig[
"location"], __FILE__, __LINE__);
351 auto LLHObjType = Get<std::string>(thisFitterSpec_config[
"LLHObjectType"], __FILE__, __LINE__);
353 std::shared_ptr<TObject> LLHObj =
nullptr;
354 for (std::string rawLocation : testLLHRawLocations)
358 if (LLHObj !=
nullptr)
365 if (LLHObj ==
nullptr)
369 if (setInputFileScan)
371 std::shared_ptr<TGraph> LLHGraph = std::make_shared<TGraph>();
373 if (LLHObjType ==
"TH1D")
375 LLHGraph = std::make_shared<TGraph>(
static_cast<TH1D*
>(LLHObj.get()));
376 }
else if (LLHObjType ==
"TGraph")
378 LLHGraph = std::shared_ptr<TGraph>(
static_cast<TGraph*
>(LLHObj->Clone()));
381 throw MaCh3Exception(__FILE__ , __LINE__,
"uknown type of LLH object specified: " + LLHObjType);
392 bool wasFound =
false;
402 for (
int paramIdx = 0; paramIdx < inputFileDef.
mcmcProc->
GetNParams() -1 ; paramIdx ++ )
405 double prior, priorError;
411 if ( setInputBranch )
426 bool wasFound =
false;
430 if ( thisFitterSpec_config[
"1dPosteriors"] ) {
431 auto rawLocations = Get<std::vector<std::string>>(thisFitterSpec_config[
"1dPosteriors"][
"location"],
433 for (
const std::string &rawLoc : rawLocations)
437 if ( posterior1d !=
nullptr )
443 inputFileDef.
posteriors1d_map[parameter] = std::make_shared<TGraph>(posterior1d.get());
453 std::string &fitter,
const std::string &errorType,
454 const bool setInputFileError) {
459 YAML::Node postFitErrorTypes = thisFitterSpec_config[
"postFitErrorTypes"];
460 YAML::Node specificErrorType = postFitErrorTypes[errorType];
461 auto postFitLocations = Get<std::vector<std::string>>(specificErrorType[
"location"], __FILE__, __LINE__);
464 std::vector<std::string> postFitLocations_override;
466 postFitLocations_override, parameter))
468 postFitLocations = postFitLocations_override;
471 for (std::string postFitLoc : postFitLocations)
476 if (postFitErrors ==
nullptr)
480 for (
int binIdx = 0; binIdx <= postFitErrors->GetNbinsX(); binIdx++)
482 std::string binLabel = std::string(postFitErrors->GetXaxis()->GetBinLabel(binIdx));
485 if (setInputFileError)
488 inputFileDef.
postFitErrors[errorType][parameter] = postFitErrors->GetBinError(binIdx);
489 inputFileDef.
postFitValues[errorType][parameter] = postFitErrors->GetBinContent(binIdx);
515 bool foundFitter =
false;
522 throw MaCh3Exception(__FILE__ , __LINE__,
"translation config doesnt contain a definition for fitter " + fitter);
531 for (std::string LLHType : {
"sample",
"penalty",
"total"})
534 MACH3LOG_INFO(
".... searching for {} LLH scans... ", LLHType);
537 YAML::Node testLLHConfig = thisFitterSpec_config[LLHType +
"_LLH"];
538 auto testLLHRawLocations = Get<std::vector<std::string>>(testLLHConfig[
"location"], __FILE__, __LINE__);
543 std::vector<std::string> enabledLLHParams;
551 for (
const std::string &rawLocation : testLLHRawLocations)
557 enabledLLHParams.push_back(parameter);
568 if (numLLHParams > 0)
588 if (thisFitterSpec_config[
"defaultPostFitErrorType"])
590 MACH3LOG_DEBUG(
" Default type specified with possible locations: ");
591 YAML::Node postFitErrorSpec = thisFitterSpec_config[
"postFitErrorTypes"];
592 YAML::Node defaultErrorType =
593 postFitErrorSpec[thisFitterSpec_config[
"defaultPostFitErrorType"].as<std::string>()];
594 auto locations = Get<std::vector<std::string>>(defaultErrorType[
"location"], __FILE__, __LINE__);
595 for (std::string loc : locations)
604 int numPostFitParams = 0;
605 std::vector<std::string> enabledPostFitParams;
607 auto defaultErrorType =
608 Get<std::string>(thisFitterSpec_config[
"defaultPostFitErrorType"], __FILE__, __LINE__);
614 enabledPostFitParams.push_back(parameter);
621 if (numPostFitParams > 0)
632 MACH3LOG_INFO(
"....Searching for LLH scans broken down by sample");
636 size_t numLLHBySampleParams = 0;
643 numLLHBySampleParams++;
647 if (numLLHBySampleParams != 0)
652 MACH3LOG_INFO(
"........ Found {} LLH scans for sample {}", numLLHBySampleParams, sample);
654 if ((numLLHParams != numLLHBySampleParams))
657 MACH3LOG_ERROR(
" I have {} LLH scans for sample {}", numLLHBySampleParams, sample);
658 MACH3LOG_ERROR(
" But {} parameters with Total_LLH scals", numLLHParams);
669 if ( thisFitterSpec_config[
"MCMCsteps"] )
672 auto posteriorTreeRawLocations =
673 Get<std::vector<std::string>>(thisFitterSpec_config[
"MCMCsteps"][
"location"], __FILE__, __LINE__);
675 TTree *postTree =
nullptr;
676 for (
const std::string &rawLoc: posteriorTreeRawLocations )
678 MACH3LOG_DEBUG(
" - Looking for MCMC chain parameter values at: {}", rawLoc);
680 postTree = inputFileDef.
file->Get<TTree>(rawLoc.c_str());
682 if ( postTree !=
nullptr )
692 if ( postTree !=
nullptr )
695 inputFileDef.
nMCMCentries = int(postTree->GetEntries());
704 size_t num1dPosteriors = 0;
705 std::vector<std::string> enabled1dPosteriorParams;
707 size_t numMCMCchainParams = 0;
708 std::vector<std::string> enabledMCMCchainParams;
715 if ( thisFitterSpec_config[
"1dPosteriors"] &&
find1dPosterior(inputFileDef, parameter, fitter) )
718 enabled1dPosteriorParams.push_back(parameter);
724 if ( thisFitterSpec_config[
"MCMCsteps"] &&
findRawChainSteps(inputFileDef, parameter, fitter) )
727 enabledMCMCchainParams.push_back(parameter);
728 numMCMCchainParams++;
733 if (num1dPosteriors > 0 )
740 MACH3LOG_INFO(
"........ Found {} 1d processed posteriors", num1dPosteriors);
742 if ( numMCMCchainParams > 0 )
749 MACH3LOG_INFO(
"........ Found {} parameters in MCMC chain", numMCMCchainParams);
764 inputFileDef.
fitter = fitter;
771 MACH3LOG_WARN(
"I don't know what kinda fitter this came from, will proceed with caution");
772 inputFileDef.
fitter =
"UNKNOWN_FITTER";
785 Get<std::string>(thisFitterSpec_config[
"defaultPostFitErrorType"], __FILE__, __LINE__);
788 for (
const std::string LLHType : {
"sample",
"penalty",
"total"})
794 YAML::Node testLLHConfig = thisFitterSpec_config[LLHType +
"_LLH"];
795 const std::vector<std::string> testLLHRawLocations =
796 Get<std::vector<std::string>>(testLLHConfig[
"location"], __FILE__, __LINE__);
799 auto LLHObjType = Get<std::string>(thisFitterSpec_config[
"LLHObjectType"], __FILE__, __LINE__);
803 std::shared_ptr<TObject> LLHObj =
nullptr;
806 for (
const std::string &rawLocation : testLLHRawLocations)
811 if (LLHObj !=
nullptr)
816 if (LLHObj ==
nullptr)
818 MACH3LOG_ERROR(
"Hmmm, something seems to have gone wrong and I couldnt find the {} LLH scan for {} when attempting to read the data for it", LLHType, parameter);
819 MACH3LOG_ERROR(
"This will very likely cause segfaults and sadness");
823 std::shared_ptr<TGraph> LLHGraph = std::make_shared<TGraph>();
827 if (LLHObjType ==
"TH1D")
829 LLHGraph = std::make_shared<TGraph>(
static_cast<TH1D*
>(LLHObj.get()));
832 else if (LLHObjType ==
"TGraph")
834 LLHGraph = std::shared_ptr<TGraph>(
static_cast<TGraph*
>(LLHObj->Clone()));
843 inputFileDef.
LLHScans_map[LLHType][parameter] = LLHGraph;
859 auto availableErrorTypes = Get<std::vector<std::string>>(thisFitterSpec_config[
"AvailablePostFitErrorTypes"],
862 for (
const std::string &errorType : availableErrorTypes)
#define MACH3LOG_CRITICAL
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Class responsible for processing MCMC chains, performing diagnostics, generating plots,...
void GetNthParameter(const int param, double &Prior, double &PriorError, TString &Title) const
Get properties of parameter by passing it number.
const std::vector< TString > & GetBranchNames() const
Get the vector of branch names from root file.
void Initialise()
Scan chain, what parameters we have and load information from covariance matrices.
int GetNParams() const
Get total number of used parameters.
Custom exception class for MaCh3 errors.
constexpr static const double _BAD_DOUBLE_
Default value used for double initialisation.
fileTypeEnum
Types of possible file that can be read.
@ kPostFit
Processed post fit errors.
@ kLLH
Log Likelihood scan.