10 #include <klm/calibration/KLMLikelihoodParametersImporter.h>
13 #include <klm/dbobjects/KLMLikelihoodParameters.h>
14 #include <klm/muid/MuidElementNumbers.h>
17 #include <framework/database/DBImportObjPtr.h>
18 #include <framework/database/DBObjPtr.h>
19 #include <framework/gearbox/GearDir.h>
20 #include <framework/database/IntervalOfValidity.h>
21 #include <framework/logging/Logger.h>
31 void KLMLikelihoodParametersImporter::writeLikelihoodParameters()
33 B2WARNING(
"The method KLMLikelihoodParametersImporter::writeMuidParameters() is temporary unavailable, sorry! :(");
38 vector<string>
const hypotheses = {
"Positron",
"Electron" ,
"Deuteron",
"Antideuteron",
"Proton",
"Antiproton",
"PionPlus",
"PionMinus",
"KaonPlus",
"KaonMinus",
"MuonPlus",
"MuonMinus" };
39 for (
unsigned int hypothesis = 0; hypothesis < hypotheses.size(); hypothesis++) {
40 GearDir content(
"/Detector/Muid/MuidParameters//Experiment[@exp=\"0\"]/");
41 content.append(hypotheses[hypothesis]);
42 for (
int outcome = 1; outcome <= MuidElementNumbers::getMaximalOutcome(); ++outcome) {
43 GearDir outcomeContent(content);
44 outcomeContent.
append((boost::format(
"/LayerProfile/Outcome[@outcome=\"%1%\"]/") % (outcome)).str());
45 for (
int lastLayer = 0; lastLayer <= MuidElementNumbers::getMaximalBarrelLayer(); ++lastLayer) {
46 if (!(MuidElementNumbers::checkExtrapolationOutcome(outcome, lastLayer)))
48 std::vector<double> layerPDF = outcomeContent.
getArray((boost::format(
"LastLayer[@layer=\"%1%\"]") % (lastLayer)).str());
49 likelihoodParameters->setLongitudinalPDF(hypothesis, outcome, lastLayer, layerPDF);
52 for (
int detector = 0; detector <= MuidElementNumbers::getMaximalDetector(); ++detector) {
53 GearDir detectorContent(content);
55 detectorContent.
append(
"/TransversePDF/BarrelAndEndcap");
57 detectorContent.
append(
"/TransversePDF/BarrelOnly");
59 detectorContent.
append(
"/TransversePDF/EndcapOnly");
60 for (
int halfNdof = 1; halfNdof <= MuidElementNumbers::getMaximalHalfNdof(); ++halfNdof) {
61 double reducedChiSquaredThreshold = detectorContent.
getDouble((boost::format(
"DegreesOfFreedom[@ndof=\"%1%\"]/Tail/Threshold") %
62 (2 * halfNdof)).str());
63 double reducedChiSquaredScaleY = detectorContent.
getDouble((boost::format(
"DegreesOfFreedom[@ndof=\"%1%\"]/Tail/ScaleY") %
64 (2 * halfNdof)).str());
65 double reducedChiSquaredScaleX = detectorContent.
getDouble((boost::format(
"DegreesOfFreedom[@ndof=\"%1%\"]/Tail/ScaleX") %
66 (2 * halfNdof)).str());
67 std::vector<double> reducedChiSquaredPDF = detectorContent.
getArray((boost::format(
"DegreesOfFreedom[@ndof=\"%1%\"]/Histogram") %
68 (2 * halfNdof)).str());
69 likelihoodParameters->setTransversePDF(hypothesis, detector, halfNdof * 2, reducedChiSquaredPDF);
70 likelihoodParameters->setTransverseThreshold(hypothesis, detector, halfNdof * 2, reducedChiSquaredThreshold);
71 likelihoodParameters->setTransverseScaleY(hypothesis, detector, halfNdof * 2, reducedChiSquaredScaleY);
72 likelihoodParameters->setTransverseScaleX(hypothesis, detector, halfNdof * 2, reducedChiSquaredScaleX);
77 likelihoodParameters.
import(Iov);
80 void KLMLikelihoodParametersImporter::readLikelihoodParameters()
83 vector<string>
const hypotheses = {
"Positron",
"Electron" ,
"Deuteron",
"Antideuteron",
"Proton",
"Antiproton",
"PionPlus",
"PionMinus",
"KaonPlus",
"KaonMinus",
"MuonPlus",
"MuonMinus" };
84 for (
unsigned int hypothesis = 0; hypothesis < hypotheses.size(); hypothesis++) {
85 B2INFO(
" hypothesisName " << hypotheses[hypothesis]);
86 for (
int outcome = 1; outcome <= MuidElementNumbers::getMaximalOutcome(); ++outcome) {
87 B2INFO(
" outcome " << outcome);
88 for (
int lastLayer = 0; lastLayer <= MuidElementNumbers::getMaximalBarrelLayer(); ++lastLayer) {
89 B2INFO(
" lastLayer " << lastLayer);
90 if (!(MuidElementNumbers::checkExtrapolationOutcome(outcome, lastLayer)))
92 std::vector<double> layerPDF = likelihoodParameters->getLongitudinalPDF(hypothesis, outcome, lastLayer);
93 B2INFO(
" layerPDF: ");
94 for (
unsigned int layer = 0; layer < layerPDF.size(); ++layer) {
95 B2INFO(layerPDF[layer] <<
" , ");
99 const char* detectorNames[] = {
"BarrelAndEndcap",
"BarrelOnly",
"EndcapOnly"};
100 for (
int detector = 0; detector <= MuidElementNumbers::getMaximalDetector(); ++detector) {
101 B2INFO(
" detectorName " << detectorNames[detector]);
102 for (
int halfNdof = 1; halfNdof <= MuidElementNumbers::getMaximalHalfNdof(); ++halfNdof) {
103 B2INFO(
" Ndof " << halfNdof * 2);
104 B2INFO(
" ReducedChiSquaredThreshold " << likelihoodParameters->getTransverseThreshold(hypothesis, detector, halfNdof * 2));
105 B2INFO(
" ReducedChiSquaredScaleY " << likelihoodParameters->getTransverseScaleY(hypothesis, detector, halfNdof * 2));
106 B2INFO(
" ReducedChiSquaredScaleX " << likelihoodParameters->getTransverseScaleX(hypothesis, detector, halfNdof * 2));
107 std::vector<double> reducedChiSquaredPDF = likelihoodParameters->getTransversePDF(hypothesis, detector, halfNdof * 2);
108 if (reducedChiSquaredPDF.size() != MuidElementNumbers::getSizeReducedChiSquared()) {
109 B2ERROR(
"KLMLikelihoodParametersImporter::TransversePDF vector for hypothesis " << hypotheses[hypothesis] <<
" detector " <<
110 detectorNames[detector]
111 <<
" has " << reducedChiSquaredPDF.size() <<
" entries; should be " << MuidElementNumbers::getSizeReducedChiSquared());
113 for (
int i = 0; i < MuidElementNumbers::getSizeReducedChiSquared(); ++i) {
114 B2INFO(
" PDF " << reducedChiSquaredPDF[i]);
bool import(const IntervalOfValidity &iov)
Import the object to database.
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
Class for accessing objects in the database.
GearDir is the basic class used for accessing the parameter store.
void append(const std::string &path)
Append something to the current path, modifying the GearDir in place.
A class that describes the interval of experiments/runs for which an object in the database is valid.
std::vector< double > getArray(const std::string &path) const noexcept(false)
Get the parameter path as a list of double values converted to the standard unit.
double getDouble(const std::string &path="") const noexcept(false)
Get the parameter path as a double.
Abstract base class for different kinds of events.