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;
46 std::vector<std::string> tags;
53 tags =
_samplesConfig[samp][
"tags"].as<std::vector<std::string>>();
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 ==
"exect" )
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 std::vector<std::string> testLLHRawLocations =
350 testLLHConfig[
"location"].as<std::vector<std::string>>();
352 std::string LLHObjType = thisFitterSpec_config[
"LLHObjectType"].as<std::string>();
355 std::shared_ptr<TObject> LLHObj =
nullptr;
356 for (std::string rawLocation : testLLHRawLocations)
360 if (LLHObj !=
nullptr)
367 if (LLHObj ==
nullptr)
371 if (setInputFileScan)
373 std::shared_ptr<TGraph> LLHGraph = std::make_shared<TGraph>();
375 if (LLHObjType ==
"TH1D")
377 LLHGraph = std::make_shared<TGraph>(
static_cast<TH1D*
>(LLHObj.get()));
378 }
else if (LLHObjType ==
"TGraph")
380 LLHGraph = std::shared_ptr<TGraph>(
static_cast<TGraph*
>(LLHObj->Clone()));
383 throw MaCh3Exception(__FILE__ , __LINE__,
"uknown type of LLH object specified: " + LLHObjType);
394 bool wasFound =
false;
404 for (
int paramIdx = 0; paramIdx < inputFileDef.
mcmcProc->
GetNParams() -1 ; paramIdx ++ )
407 double prior, priorError;
413 if ( setInputBranch )
428 bool wasFound =
false;
432 if ( thisFitterSpec_config[
"1dPosteriors"] ) {
433 std::vector<std::string> rawLocations = thisFitterSpec_config[
"1dPosteriors"][
"location"].as<std::vector<std::string>>();
435 for (
const std::string &rawLoc : rawLocations)
439 if ( posterior1d !=
nullptr )
445 inputFileDef.
posteriors1d_map[parameter] = std::make_shared<TGraph>(posterior1d.get());
455 std::string &fitter,
const std::string &errorType,
456 bool setInputFileError) {
461 YAML::Node postFitErrorTypes = thisFitterSpec_config[
"postFitErrorTypes"];
462 YAML::Node specificErrorType = postFitErrorTypes[errorType];
463 std::vector<std::string> postFitLocations =
464 specificErrorType[
"location"].as<std::vector<std::string>>();
467 std::vector<std::string> postFitLocations_override;
469 postFitLocations_override, parameter))
471 postFitLocations = postFitLocations_override;
474 for (std::string postFitLoc : postFitLocations)
479 if (postFitErrors ==
nullptr)
483 for (
int binIdx = 0; binIdx <= postFitErrors->GetNbinsX(); binIdx++)
485 std::string binLabel = std::string(postFitErrors->GetXaxis()->GetBinLabel(binIdx));
488 if (setInputFileError)
491 inputFileDef.
postFitErrors[errorType][parameter] = postFitErrors->GetBinError(binIdx);
492 inputFileDef.
postFitValues[errorType][parameter] = postFitErrors->GetBinContent(binIdx);
518 bool foundFitter =
false;
525 throw MaCh3Exception(__FILE__ , __LINE__,
"translation config doesnt contain a definition for fitter " + fitter);
534 for (std::string LLHType : {
"sample",
"penalty",
"total"})
537 MACH3LOG_INFO(
".... searching for {} LLH scans... ", LLHType);
540 YAML::Node testLLHConfig = thisFitterSpec_config[LLHType +
"_LLH"];
541 std::vector<std::string> testLLHRawLocations =
542 testLLHConfig[
"location"].as<std::vector<std::string>>();
547 std::vector<std::string> enabledLLHParams;
555 for (
const std::string &rawLocation : testLLHRawLocations)
561 enabledLLHParams.push_back(parameter);
572 if (numLLHParams > 0)
592 if (thisFitterSpec_config[
"defaultPostFitErrorType"])
594 MACH3LOG_DEBUG(
" Default type specified with possible locations: ");
595 YAML::Node postFitErrorSpec = thisFitterSpec_config[
"postFitErrorTypes"];
596 YAML::Node defaultErrorType =
597 postFitErrorSpec[thisFitterSpec_config[
"defaultPostFitErrorType"].as<std::string>()];
598 std::vector<std::string> locations = defaultErrorType[
"location"].as<std::vector<std::string>>();
599 for (std::string loc : locations)
608 int numPostFitParams = 0;
609 std::vector<std::string> enabledPostFitParams;
611 std::string defaultErrorType =
612 thisFitterSpec_config[
"defaultPostFitErrorType"].as<std::string>();
618 enabledPostFitParams.push_back(parameter);
625 if (numPostFitParams > 0)
636 MACH3LOG_INFO(
"....Searching for LLH scans broken down by sample");
640 size_t numLLHBySampleParams = 0;
647 numLLHBySampleParams++;
651 if (numLLHBySampleParams != 0)
656 MACH3LOG_INFO(
"........ Found {} LLH scans for sample {}", numLLHBySampleParams, sample);
658 if ((numLLHParams != numLLHBySampleParams))
661 MACH3LOG_ERROR(
" I have {} LLH scans for sample {}", numLLHBySampleParams, sample);
662 MACH3LOG_ERROR(
" But {} parameters with Total_LLH scals", numLLHParams);
673 if ( thisFitterSpec_config[
"MCMCsteps"] )
676 std::vector<std::string> posteriorTreeRawLocations = thisFitterSpec_config[
"MCMCsteps"][
"location"].as<std::vector<std::string>>();
678 TTree *postTree =
nullptr;
679 for (
const std::string &rawLoc: posteriorTreeRawLocations )
681 MACH3LOG_DEBUG(
" - Looking for MCMC chain parameter values at: {}", rawLoc);
683 postTree = inputFileDef.
file->Get<TTree>(rawLoc.c_str());
685 if ( postTree !=
nullptr )
695 if ( postTree !=
nullptr )
698 inputFileDef.
nMCMCentries = int(postTree->GetEntries());
707 size_t num1dPosteriors = 0;
708 std::vector<std::string> enabled1dPosteriorParams;
710 size_t numMCMCchainParams = 0;
711 std::vector<std::string> enabledMCMCchainParams;
718 if ( thisFitterSpec_config[
"1dPosteriors"] &&
find1dPosterior(inputFileDef, parameter, fitter) )
721 enabled1dPosteriorParams.push_back(parameter);
727 if ( thisFitterSpec_config[
"MCMCsteps"] &&
findRawChainSteps(inputFileDef, parameter, fitter) )
730 enabledMCMCchainParams.push_back(parameter);
731 numMCMCchainParams++;
736 if (num1dPosteriors > 0 )
743 MACH3LOG_INFO(
"........ Found {} 1d processed posteriors", num1dPosteriors);
745 if ( numMCMCchainParams > 0 )
752 MACH3LOG_INFO(
"........ Found {} parameters in MCMC chain", numMCMCchainParams);
767 inputFileDef.
fitter = fitter;
774 MACH3LOG_WARN(
"I don't know what kinda fitter this came from, will proceed with caution");
775 inputFileDef.
fitter =
"UNKNOWN_FITTER";
788 thisFitterSpec_config[
"defaultPostFitErrorType"].as<std::string>();
791 for (
const std::string LLHType : {
"sample",
"penalty",
"total"})
797 YAML::Node testLLHConfig = thisFitterSpec_config[LLHType +
"_LLH"];
798 const std::vector<std::string> testLLHRawLocations =
799 testLLHConfig[
"location"].as<std::vector<std::string>>();
802 std::string LLHObjType = thisFitterSpec_config[
"LLHObjectType"].as<std::string>();
807 std::shared_ptr<TObject> LLHObj =
nullptr;
810 for (
const std::string &rawLocation : testLLHRawLocations)
815 if (LLHObj !=
nullptr)
820 if (LLHObj ==
nullptr)
822 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);
823 MACH3LOG_ERROR(
"This will very likely cause segfaults and sadness");
827 std::shared_ptr<TGraph> LLHGraph = std::make_shared<TGraph>();
831 if (LLHObjType ==
"TH1D")
833 LLHGraph = std::make_shared<TGraph>(
static_cast<TH1D*
>(LLHObj.get()));
836 else if (LLHObjType ==
"TGraph")
838 LLHGraph = std::shared_ptr<TGraph>(
static_cast<TGraph*
>(LLHObj->Clone()));
847 inputFileDef.
LLHScans_map[LLHType][parameter] = LLHGraph;
863 std::vector<std::string> availableErrorTypes =
864 thisFitterSpec_config[
"AvailablePostFitErrorTypes"].as<std::vector<std::string>>();
865 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.
void Initialise()
Scan chain, what parameters we have and load information from covariance matrices.
const std::vector< TString > & GetBranchNames() const
Get the vector of branch names from root file.
int GetNParams()
Get total number of used parameters.
Custom exception class for MaCh3 errors.
static constexpr 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.