Belle II Software development
SVDdEdxValidationAlgorithm Class Reference

Class implementing the SVD dEdx calibration algorithm. More...

#include <SVDdEdxValidationAlgorithm.h>

Inheritance diagram for SVDdEdxValidationAlgorithm:
CalibrationAlgorithm

Public Types

enum  EResult {
  c_OK ,
  c_Iterate ,
  c_NotEnoughData ,
  c_Failure ,
  c_Undefined
}
 The result of calibration. More...
 

Public Member Functions

 SVDdEdxValidationAlgorithm ()
 Constructor.
 
virtual ~SVDdEdxValidationAlgorithm ()
 Destructor.
 
void setMonitoringPlots (bool value=false)
 function to enable plotting
 
void setNumROCpoints (const unsigned int &value)
 set the number of points for ROC curve plotting
 
void setMinROCMomentum (const double &value)
 set the lower edge of the momentum range for ROC curve plotting
 
void setMaxROCMomentum (const double &value)
 set the lower edge of the momentum range for ROC curve plotting
 
void setNumEffBins (const unsigned int &value)
 set the number of bins for the efficiency scan
 
void setMaxEffMomentum (const double &value)
 set the upper edge of the momentum range for the efficiency scan
 
void setMinEvtsPerTree (const double &value)
 set the upper edge of the dEdx binning for the payloads
 
std::string getPrefix () const
 Get the prefix used for getting calibration data.
 
bool checkPyExpRun (PyObject *pyObj)
 Checks that a PyObject can be successfully converted to an ExpRun type.
 
Calibration::ExpRun convertPyExpRun (PyObject *pyObj)
 Performs the conversion of PyObject to ExpRun.
 
std::string getCollectorName () const
 Alias for prefix.
 
void setPrefix (const std::string &prefix)
 Set the prefix used to identify datastore objects.
 
void setInputFileNames (PyObject *inputFileNames)
 Set the input file names used for this algorithm from a Python list.
 
PyObject * getInputFileNames ()
 Get the input file names used for this algorithm and pass them out as a Python list of unicode strings.
 
std::vector< Calibration::ExpRun > getRunListFromAllData () const
 Get the complete list of runs from inspection of collected data.
 
RunRange getRunRangeFromAllData () const
 Get the complete RunRange from inspection of collected data.
 
IntervalOfValidity getIovFromAllData () const
 Get the complete IoV from inspection of collected data.
 
void fillRunToInputFilesMap ()
 Fill the mapping of ExpRun -> Files.
 
std::string getGranularity () const
 Get the granularity of collected data.
 
EResult execute (std::vector< Calibration::ExpRun > runs={}, int iteration=0, IntervalOfValidity iov=IntervalOfValidity())
 Runs calibration over vector of runs for a given iteration.
 
EResult execute (PyObject *runs, int iteration=0, IntervalOfValidity iov=IntervalOfValidity())
 Runs calibration over Python list of runs. Converts to C++ and then calls the other execute() function.
 
std::list< Database::DBImportQuery > & getPayloads ()
 Get constants (in TObjects) for database update from last execution.
 
std::list< Database::DBImportQuerygetPayloadValues ()
 Get constants (in TObjects) for database update from last execution but passed by VALUE.
 
bool commit ()
 Submit constants from last calibration into database.
 
bool commit (std::list< Database::DBImportQuery > payloads)
 Submit constants from a (potentially previous) set of payloads.
 
const std::string & getDescription () const
 Get the description of the algoithm (set by developers in constructor)
 
bool loadInputJson (const std::string &jsonString)
 Load the m_inputJson variable from a string (useful from Python interface). The rturn bool indicates success or failure.
 
const std::string dumpOutputJson () const
 Dump the JSON string of the output JSON object.
 
const std::vector< Calibration::ExpRun > findPayloadBoundaries (std::vector< Calibration::ExpRun > runs, int iteration=0)
 Used to discover the ExpRun boundaries that you want the Python CAF to execute on. This is optional and only used in some.
 
template<>
std::shared_ptr< TTree > getObjectPtr (const std::string &name, const std::vector< Calibration::ExpRun > &requestedRuns)
 Specialization of getObjectPtr<TTree>.
 

Protected Member Functions

virtual EResult calibrate () override
 run algorithm on data
 
void setInputFileNames (std::vector< std::string > inputFileNames)
 Set the input file names used for this algorithm.
 
virtual bool isBoundaryRequired (const Calibration::ExpRun &)
 Given the current collector data, make a decision about whether or not this run should be the start of a payload boundary.
 
virtual void boundaryFindingSetup (std::vector< Calibration::ExpRun >, int)
 If you need to make some changes to your algorithm class before 'findPayloadBoundaries' is run, make them in this function.
 
virtual void boundaryFindingTearDown ()
 Put your algorithm back into a state ready for normal execution if you need to.
 
const std::vector< Calibration::ExpRun > & getRunList () const
 Get the list of runs for which calibration is called.
 
int getIteration () const
 Get current iteration.
 
std::vector< std::string > getVecInputFileNames () const
 Get the input file names used for this algorithm as a STL vector.
 
template<class T >
std::shared_ptr< T > getObjectPtr (const std::string &name, const std::vector< Calibration::ExpRun > &requestedRuns)
 Get calibration data object by name and list of runs, the Merge function will be called to generate the overall object.
 
template<class T >
std::shared_ptr< T > getObjectPtr (std::string name)
 Get calibration data object (for all runs the calibration is requested for) This function will only work during or after execute() has been called once.
 
template<>
shared_ptr< TTree > getObjectPtr (const string &name, const vector< ExpRun > &requestedRuns)
 We cheekily cast the TChain to TTree for the returned pointer so that the user never knows Hopefully this doesn't cause issues if people do low level stuff to the tree...
 
std::string getGranularityFromData () const
 Get the granularity of collected data.
 
void saveCalibration (TClonesArray *data, const std::string &name)
 Store DBArray payload with given name with default IOV.
 
void saveCalibration (TClonesArray *data, const std::string &name, const IntervalOfValidity &iov)
 Store DBArray with given name and custom IOV.
 
void saveCalibration (TObject *data)
 Store DB payload with default name and default IOV.
 
void saveCalibration (TObject *data, const IntervalOfValidity &iov)
 Store DB payload with default name and custom IOV.
 
void saveCalibration (TObject *data, const std::string &name)
 Store DB payload with given name with default IOV.
 
void saveCalibration (TObject *data, const std::string &name, const IntervalOfValidity &iov)
 Store DB payload with given name and custom IOV.
 
void updateDBObjPtrs (const unsigned int event, const int run, const int experiment)
 Updates any DBObjPtrs by calling update(event) for DBStore.
 
void setDescription (const std::string &description)
 Set algorithm description (in constructor)
 
void clearCalibrationData ()
 Clear calibration data.
 
Calibration::ExpRun getAllGranularityExpRun () const
 Returns the Exp,Run pair that means 'Everything'. Currently unused.
 
void resetInputJson ()
 Clears the m_inputJson member variable.
 
void resetOutputJson ()
 Clears the m_outputJson member variable.
 
template<class T >
void setOutputJsonValue (const std::string &key, const T &value)
 Set a key:value pair for the outputJson object, expected to used interally during calibrate()
 
template<class T >
const T getOutputJsonValue (const std::string &key) const
 Get a value using a key from the JSON output object, not sure why you would want to do this.
 
template<class T >
const T getInputJsonValue (const std::string &key) const
 Get an input JSON value using a key. The normal exceptions are raised when the key doesn't exist.
 
const nlohmann::json & getInputJsonObject () const
 Get the entire top level JSON object. We explicitly say this must be of object type so that we might pick.
 
bool inputJsonKeyExists (const std::string &key) const
 Test for a key in the input JSON object.
 

Protected Attributes

std::vector< Calibration::ExpRun > m_boundaries
 When using the boundaries functionality from isBoundaryRequired, this is used to store the boundaries. It is cleared when.
 

Private Member Functions

void PlotEfficiencyPlots (const TString &PIDDetectorsName, TTree *SignalTree, TString SignalWeightName, TString SignalVarName, TString SignalVarNameFull, TTree *FakeTree, TString FakeWeightName, TString FakeVarName, TString FakeVarNameFull, TString PIDVarName, TString PIDCut, unsigned int nbins, double MomLow, double MomHigh)
 a generic function to produce efficiency plots
 
void PlotROCCurve (TTree *SignalTree, TString SignalWeightName, TString SignalVarName, TString SignalVarNameFull, TTree *FakeTree, TString FakeWeightName, TString FakeVarName, TString FakeVarNameFull, TString PIDVarName)
 a generic function to produce ROC curves
 
TTree * LambdaMassFit (std::shared_ptr< TTree > preselTree)
 produce histograms for protons
 
TTree * DstarMassFit (std::shared_ptr< TTree > preselTree)
 produce histograms for K/pi(/mu)
 
std::string getExpRunString (Calibration::ExpRun &expRun) const
 Gets the "exp.run" string repr. of (exp,run)
 
std::string getFullObjectPath (const std::string &name, Calibration::ExpRun expRun) const
 constructs the full TDirectory + Key name of an object in a TFile based on its name and exprun
 

Private Attributes

bool m_isMakePlots
 produce plots for monitoring of the fit quality
 
int m_MinEvtsPerTree = 100
 number of events in TTree below which we don't try to fit
 
unsigned int m_NumROCpoints = 250
 number of points for the ROC curve plotting
 
double m_MomLowROC = 0.
 lower edge of the momentum interval considered for the ROC curve
 
double m_MomHighROC = 7.
 upper edge of the momentum interval considered for the ROC curve
 
unsigned int m_NumEffBins = 30
 number of bins for the efficiency/fake rate plot
 
double m_MomHighEff = 2.5
 upper edge of the momentum interval for the efficiency/fake rate plot
 
std::vector< std::string > m_inputFileNames
 List of input files to the Algorithm, will initially be user defined but then gets the wildcards expanded during execute()
 
std::map< Calibration::ExpRun, std::vector< std::string > > m_runsToInputFiles
 Map of Runs to input files. Gets filled when you call getRunRangeFromAllData, gets cleared when setting input files again.
 
std::string m_granularityOfData
 Granularity of input data. This only changes when the input files change so it isn't specific to an execution.
 
ExecutionData m_data
 Data specific to a SINGLE execution of the algorithm. Gets reset at the beginning of execution.
 
std::string m_description {""}
 Description of the algorithm.
 
std::string m_prefix {""}
 The name of the TDirectory the collector objects are contained within.
 
nlohmann::json m_jsonExecutionInput = nlohmann::json::object()
 Optional input JSON object used to make decisions about how to execute the algorithm code.
 
nlohmann::json m_jsonExecutionOutput = nlohmann::json::object()
 Optional output JSON object that can be set during the execution by the underlying algorithm code.
 

Static Private Attributes

static const Calibration::ExpRun m_allExpRun = make_pair(-1, -1)
 allExpRun
 

Detailed Description

Class implementing the SVD dEdx calibration algorithm.

Definition at line 23 of file SVDdEdxValidationAlgorithm.h.

Member Enumeration Documentation

◆ EResult

enum EResult
inherited

The result of calibration.

Enumerator
c_OK 

Finished successfuly =0 in Python.

c_Iterate 

Needs iteration =1 in Python.

c_NotEnoughData 

Needs more data =2 in Python.

c_Failure 

Failed =3 in Python.

c_Undefined 

Not yet known (before execution) =4 in Python.

Definition at line 40 of file CalibrationAlgorithm.h.

40 {
41 c_OK,
42 c_Iterate,
44 c_Failure,
46 };
@ c_OK
Finished successfuly =0 in Python.
@ c_Iterate
Needs iteration =1 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
@ c_Failure
Failed =3 in Python.
@ c_Undefined
Not yet known (before execution) =4 in Python.

Constructor & Destructor Documentation

◆ SVDdEdxValidationAlgorithm()

Constructor.

Definition at line 44 of file SVDdEdxValidationAlgorithm.cc.

44 : CalibrationAlgorithm("SVDdEdxValidationCollector"),
45 m_isMakePlots(true)
46{
47 setDescription("SVD dE/dx validation algorithm");
48}
Base class for calibration algorithms.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
bool m_isMakePlots
produce plots for monitoring of the fit quality

◆ ~SVDdEdxValidationAlgorithm()

virtual ~SVDdEdxValidationAlgorithm ( )
inlinevirtual

Destructor.

Definition at line 35 of file SVDdEdxValidationAlgorithm.h.

35{}

Member Function Documentation

◆ boundaryFindingSetup()

virtual void boundaryFindingSetup ( std::vector< Calibration::ExpRun >  ,
int   
)
inlineprotectedvirtualinherited

If you need to make some changes to your algorithm class before 'findPayloadBoundaries' is run, make them in this function.

Reimplemented in TestBoundarySettingAlgorithm, TestCalibrationAlgorithm, PXDAnalyticGainCalibrationAlgorithm, PXDValidationAlgorithm, SVD3SampleCoGTimeCalibrationAlgorithm, SVD3SampleELSTimeCalibrationAlgorithm, and SVDCoGTimeCalibrationAlgorithm.

Definition at line 252 of file CalibrationAlgorithm.h.

252{};

◆ boundaryFindingTearDown()

virtual void boundaryFindingTearDown ( )
inlineprotectedvirtualinherited

Put your algorithm back into a state ready for normal execution if you need to.

Definition at line 257 of file CalibrationAlgorithm.h.

257{};

◆ calibrate()

CalibrationAlgorithm::EResult calibrate ( )
overrideprotectedvirtual

run algorithm on data

Implements CalibrationAlgorithm.

Definition at line 51 of file SVDdEdxValidationAlgorithm.cc.

52{
53 gROOT->SetBatch(true);
54
55 // const auto exprun = getRunList()[0];
56 // B2INFO("ExpRun used for calibration: " << exprun.first << " " << exprun.second);
57
58 // Get data objects
59 auto TTreeLambda = getObjectPtr<TTree>("Lambda");
60 auto TTreeDstar = getObjectPtr<TTree>("Dstar");
61 auto TTreeGamma = getObjectPtr<TTree>("Gamma");
62
63 if (TTreeLambda->GetEntries() < m_MinEvtsPerTree) {
64 B2WARNING("Not enough data for calibration.");
65 return c_NotEnoughData;
66 }
67
68 // call the calibration functions
69 TTree* TTreeLambdaSW = LambdaMassFit(TTreeLambda);
70 TTree* TTreeDstarSW = DstarMassFit(TTreeDstar);
71 TTree* TTreeGammaWrap = TTreeGamma.get();
72
73 std::vector<TString> PIDDetectors;
74 PIDDetectors.push_back("ALL");
75 PIDDetectors.push_back("SVDonly");
76 PIDDetectors.push_back("noSVD");
77
78 std::map<TTree*, TString> SWeightNameMap = {
79 {TTreeGammaWrap, "1"},
80 {TTreeDstarSW, "nSignalDstar_sw"},
81 {TTreeLambdaSW, "nSignalLambda_sw"}
82 };
83
84 for (const TString& PIDDetectorsName : PIDDetectors) {
85 PlotEfficiencyPlots(PIDDetectorsName, TTreeGammaWrap, SWeightNameMap[TTreeGammaWrap], "FirstElectron", "electron", TTreeDstarSW,
86 SWeightNameMap[TTreeDstarSW], "PionD", "pion",
87 "BinaryElectronPionID",
88 "0.5", m_NumEffBins, 0., m_MomHighEff);
89 PlotEfficiencyPlots(PIDDetectorsName, TTreeGammaWrap, SWeightNameMap[TTreeGammaWrap], "FirstElectron", "electron", TTreeDstarSW,
90 SWeightNameMap[TTreeDstarSW], "Kaon", "kaon",
91 "BinaryElectronKaonID", "0.5",
93 PlotEfficiencyPlots(PIDDetectorsName, TTreeLambdaSW, SWeightNameMap[TTreeLambdaSW], "Proton", "proton", TTreeDstarSW,
94 SWeightNameMap[TTreeDstarSW], "PionD", "pion",
95 "BinaryProtonPionID", "0.5",
97 PlotEfficiencyPlots(PIDDetectorsName, TTreeLambdaSW, SWeightNameMap[TTreeLambdaSW], "Proton", "proton", TTreeDstarSW,
98 SWeightNameMap[TTreeDstarSW], "Kaon", "kaon",
99 "BinaryProtonKaonID", "0.5",
101 PlotEfficiencyPlots(PIDDetectorsName, TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "PionD", "pion", TTreeDstarSW,
102 SWeightNameMap[TTreeDstarSW],
103 "Kaon", "kaon",
104 "BinaryPionKaonID", "0.5", m_NumEffBins,
105 0., m_MomHighEff);
106 PlotEfficiencyPlots(PIDDetectorsName, TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "Kaon", "kaon", TTreeDstarSW,
107 SWeightNameMap[TTreeDstarSW],
108 "PionD", "pion",
109 "BinaryKaonPionID", "0.5", m_NumEffBins,
110 0., m_MomHighEff);
111 }
112
113 PlotROCCurve(TTreeGammaWrap, SWeightNameMap[TTreeGammaWrap], "FirstElectron", "electron", TTreeDstarSW,
114 SWeightNameMap[TTreeDstarSW], "PionD",
115 "pion", "BinaryElectronPionID");
116 PlotROCCurve(TTreeGammaWrap, SWeightNameMap[TTreeGammaWrap], "FirstElectron", "electron", TTreeDstarSW,
117 SWeightNameMap[TTreeDstarSW], "Kaon",
118 "kaon", "BinaryElectronKaonID");
119 PlotROCCurve(TTreeLambdaSW, SWeightNameMap[TTreeLambdaSW], "Proton", "proton", TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "PionD",
120 "pion",
121 "BinaryProtonPionID");
122 PlotROCCurve(TTreeLambdaSW, SWeightNameMap[TTreeLambdaSW], "Proton", "proton", TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "Kaon",
123 "kaon",
124 "BinaryProtonKaonID");
125 PlotROCCurve(TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "PionD", "pion", TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "Kaon",
126 "kaon",
127 "BinaryPionKaonID");
128 PlotROCCurve(TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "Kaon", "kaon", TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "PionD",
129 "pion",
130 "BinaryKaonPionID");
131
132 B2INFO("SVD dE/dx validation done!");
133
134 return c_OK;
135}
void PlotROCCurve(TTree *SignalTree, TString SignalWeightName, TString SignalVarName, TString SignalVarNameFull, TTree *FakeTree, TString FakeWeightName, TString FakeVarName, TString FakeVarNameFull, TString PIDVarName)
a generic function to produce ROC curves
unsigned int m_NumEffBins
number of bins for the efficiency/fake rate plot
int m_MinEvtsPerTree
number of events in TTree below which we don't try to fit
TTree * LambdaMassFit(std::shared_ptr< TTree > preselTree)
produce histograms for protons
double m_MomHighEff
upper edge of the momentum interval for the efficiency/fake rate plot
TTree * DstarMassFit(std::shared_ptr< TTree > preselTree)
produce histograms for K/pi(/mu)
void PlotEfficiencyPlots(const TString &PIDDetectorsName, TTree *SignalTree, TString SignalWeightName, TString SignalVarName, TString SignalVarNameFull, TTree *FakeTree, TString FakeWeightName, TString FakeVarName, TString FakeVarNameFull, TString PIDVarName, TString PIDCut, unsigned int nbins, double MomLow, double MomHigh)
a generic function to produce efficiency plots

◆ checkPyExpRun()

bool checkPyExpRun ( PyObject *  pyObj)
inherited

Checks that a PyObject can be successfully converted to an ExpRun type.

Checks if the PyObject can be converted to ExpRun.

Definition at line 28 of file CalibrationAlgorithm.cc.

29{
30 // Is it a sequence?
31 if (PySequence_Check(pyObj)) {
32 Py_ssize_t nObj = PySequence_Length(pyObj);
33 // Does it have 2 objects in it?
34 if (nObj != 2) {
35 B2DEBUG(29, "ExpRun was a Python sequence which didn't have exactly 2 entries!");
36 return false;
37 }
38 PyObject* item1, *item2;
39 item1 = PySequence_GetItem(pyObj, 0);
40 item2 = PySequence_GetItem(pyObj, 1);
41 // Did the GetItem work?
42 if ((item1 == NULL) || (item2 == NULL)) {
43 B2DEBUG(29, "A PyObject pointer was NULL in the sequence");
44 return false;
45 }
46 // Are they longs?
47 if (PyLong_Check(item1) && PyLong_Check(item2)) {
48 long value1, value2;
49 value1 = PyLong_AsLong(item1);
50 value2 = PyLong_AsLong(item2);
51 if (((value1 == -1) || (value2 == -1)) && PyErr_Occurred()) {
52 B2DEBUG(29, "An error occurred while converting the PyLong to long");
53 return false;
54 }
55 } else {
56 B2DEBUG(29, "One or more of the PyObjects in the ExpRun wasn't a long");
57 return false;
58 }
59 // Make sure to kill off the reference GetItem gave us responsibility for
60 Py_DECREF(item1);
61 Py_DECREF(item2);
62 } else {
63 B2DEBUG(29, "ExpRun was not a Python sequence.");
64 return false;
65 }
66 return true;
67}

◆ clearCalibrationData()

void clearCalibrationData ( )
inlineprotectedinherited

Clear calibration data.

Definition at line 324 of file CalibrationAlgorithm.h.

void clearCalibrationData()
Clear calibration data.
ExecutionData m_data
Data specific to a SINGLE execution of the algorithm. Gets reset at the beginning of execution.

◆ commit() [1/2]

bool commit ( )
inherited

Submit constants from last calibration into database.

Definition at line 302 of file CalibrationAlgorithm.cc.

303{
304 if (getPayloads().empty())
305 return false;
306 list<Database::DBImportQuery> payloads = getPayloads();
307 B2INFO("Committing " << payloads.size() << " payloads to database.");
308 return Database::Instance().storeData(payloads);
309}
std::list< Database::DBImportQuery > & getPayloads()
Get constants (in TObjects) for database update from last execution.
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:42
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
Definition: Database.cc:141

◆ commit() [2/2]

bool commit ( std::list< Database::DBImportQuery payloads)
inherited

Submit constants from a (potentially previous) set of payloads.

Definition at line 311 of file CalibrationAlgorithm.cc.

312{
313 if (payloads.empty())
314 return false;
315 return Database::Instance().storeData(payloads);
316}

◆ convertPyExpRun()

ExpRun convertPyExpRun ( PyObject *  pyObj)
inherited

Performs the conversion of PyObject to ExpRun.

Converts the PyObject to an ExpRun. We've preoviously checked the object so this assumes a lot about the PyObject.

Definition at line 70 of file CalibrationAlgorithm.cc.

71{
72 ExpRun expRun;
73 PyObject* itemExp, *itemRun;
74 itemExp = PySequence_GetItem(pyObj, 0);
75 itemRun = PySequence_GetItem(pyObj, 1);
76 expRun.first = PyLong_AsLong(itemExp);
77 Py_DECREF(itemExp);
78 expRun.second = PyLong_AsLong(itemRun);
79 Py_DECREF(itemRun);
80 return expRun;
81}
Struct containing exp number and run number.
Definition: Splitter.h:51

◆ DstarMassFit()

TTree * DstarMassFit ( std::shared_ptr< TTree >  preselTree)
private

produce histograms for K/pi(/mu)

Definition at line 661 of file SVDdEdxValidationAlgorithm.cc.

662{
663 B2INFO("Configuring the Dstar fit...");
664 gROOT->SetBatch(true);
665 RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING);
666
667 RooRealVar deltaM("deltaM", "m(D*)-m(D^{0})", 0.139545, 0.151, "GeV/c^{2}");
668
669 RooRealVar KaonMomentum("KaonMomentum", "momentum for Kaon(GeV)", -1.e8, 1.e8);
670 RooRealVar KaonSVDdEdx("KaonSVDdEdx", "", -1.e8, 1.e8);
671 RooRealVar PionDMomentum("PionDMomentum", "momentum for pion(GeV)", -1.e8, 1.e8);
672 RooRealVar PionDSVDdEdx("PionDSVDdEdx", "", -1.e8, 1.e8);
673 RooRealVar SlowPionMomentum("SlowPionMomentum", "momentum for slow pion(GeV)", -1.e8, 1.e8);
674 RooRealVar SlowPionSVDdEdx("SlowPionSVDdEdx", "", -1.e8, 1.e8);
675
676 RooRealVar exp("exp", "experiment number", 0, 1.e5);
677 RooRealVar run("run", "run number", 0, 1.e8);
678
679 RooRealVar KaonKaonIDALL("KaonKaonIDALL", "", -1.e8, 1.e8);
680 RooRealVar KaonKaonIDSVDonly("KaonKaonIDSVDonly", "", -1.e8, 1.e8);
681 RooRealVar KaonKaonIDnoSVD("KaonKaonIDnoSVD", "", -1.e8, 1.e8);
682
683 RooRealVar KaonPionIDALL("KaonPionIDALL", "", -1.e8, 1.e8);
684 RooRealVar KaonPionIDSVDonly("KaonPionIDSVDonly", "", -1.e8, 1.e8);
685 RooRealVar KaonPionIDnoSVD("KaonPionIDnoSVD", "", -1.e8, 1.e8);
686
687 RooRealVar KaonProtonIDALL("KaonProtonIDALL", "", -1.e8, 1.e8);
688 RooRealVar KaonProtonIDSVDonly("KaonProtonIDSVDonly", "", -1.e8, 1.e8);
689 RooRealVar KaonProtonIDnoSVD("KaonProtonIDnoSVD", "", -1.e8, 1.e8);
690
691 RooRealVar KaonElectronIDALL("KaonElectronIDALL", "", -1.e8, 1.e8);
692 RooRealVar KaonElectronIDSVDonly("KaonElectronIDSVDonly", "", -1.e8, 1.e8);
693 RooRealVar KaonElectronIDnoSVD("KaonElectronIDnoSVD", "", -1.e8, 1.e8);
694
695 RooRealVar KaonBinaryKaonPionIDALL("KaonBinaryKaonPionIDALL", "", -1.e8, 1.e8);
696 RooRealVar KaonBinaryKaonPionIDSVDonly("KaonBinaryKaonPionIDSVDonly", "", -1.e8, 1.e8);
697 RooRealVar KaonBinaryKaonPionIDnoSVD("KaonBinaryKaonPionIDnoSVD", "", -1.e8, 1.e8);
698
699 RooRealVar KaonBinaryPionKaonIDALL("KaonBinaryPionKaonIDALL", "", -1.e8, 1.e8);
700 RooRealVar KaonBinaryPionKaonIDSVDonly("KaonBinaryPionKaonIDSVDonly", "", -1.e8, 1.e8);
701 RooRealVar KaonBinaryPionKaonIDnoSVD("KaonBinaryPionKaonIDnoSVD", "", -1.e8, 1.e8);
702
703 RooRealVar KaonBinaryProtonKaonIDALL("KaonBinaryProtonKaonIDALL", "", -1.e8, 1.e8);
704 RooRealVar KaonBinaryProtonKaonIDSVDonly("KaonBinaryProtonKaonIDSVDonly", "", -1.e8, 1.e8);
705 RooRealVar KaonBinaryProtonKaonIDnoSVD("KaonBinaryProtonKaonIDnoSVD", "", -1.e8, 1.e8);
706
707 RooRealVar KaonBinaryElectronKaonIDALL("KaonBinaryElectronKaonIDALL", "", -1.e8, 1.e8);
708 RooRealVar KaonBinaryElectronKaonIDSVDonly("KaonBinaryElectronKaonIDSVDonly", "", -1.e8, 1.e8);
709 RooRealVar KaonBinaryElectronKaonIDnoSVD("KaonBinaryElectronKaonIDnoSVD", "", -1.e8, 1.e8);
710
711 RooRealVar PionDKaonIDALL("PionDKaonIDALL", "", -1.e8, 1.e8);
712 RooRealVar PionDKaonIDSVDonly("PionDKaonIDSVDonly", "", -1.e8, 1.e8);
713 RooRealVar PionDKaonIDnoSVD("PionDKaonIDnoSVD", "", -1.e8, 1.e8);
714
715 RooRealVar PionDPionIDALL("PionDPionIDALL", "", -1.e8, 1.e8);
716 RooRealVar PionDPionIDSVDonly("PionDPionIDSVDonly", "", -1.e8, 1.e8);
717 RooRealVar PionDPionIDnoSVD("PionDPionIDnoSVD", "", -1.e8, 1.e8);
718
719 RooRealVar PionDElectronIDALL("PionDElectronIDALL", "", -1.e8, 1.e8);
720 RooRealVar PionDElectronIDSVDonly("PionDElectronIDSVDonly", "", -1.e8, 1.e8);
721 RooRealVar PionDElectronIDnoSVD("PionDElectronIDnoSVD", "", -1.e8, 1.e8);
722
723 RooRealVar PionDProtonIDALL("PionDProtonIDALL", "", -1.e8, 1.e8);
724 RooRealVar PionDProtonIDSVDonly("PionDProtonIDSVDonly", "", -1.e8, 1.e8);
725 RooRealVar PionDProtonIDnoSVD("PionDProtonIDnoSVD", "", -1.e8, 1.e8);
726
727 RooRealVar PionDBinaryPionKaonIDALL("PionDBinaryPionKaonIDALL", "", -1.e8, 1.e8);
728 RooRealVar PionDBinaryPionKaonIDSVDonly("PionDBinaryPionKaonIDSVDonly", "", -1.e8, 1.e8);
729 RooRealVar PionDBinaryPionKaonIDnoSVD("PionDBinaryPionKaonIDnoSVD", "", -1.e8, 1.e8);
730
731 RooRealVar PionDBinaryKaonPionIDALL("PionDBinaryKaonPionIDALL", "", -1.e8, 1.e8);
732 RooRealVar PionDBinaryKaonPionIDSVDonly("PionDBinaryKaonPionIDSVDonly", "", -1.e8, 1.e8);
733 RooRealVar PionDBinaryKaonPionIDnoSVD("PionDBinaryKaonPionIDnoSVD", "", -1.e8, 1.e8);
734
735 RooRealVar PionDBinaryProtonPionIDALL("PionDBinaryProtonPionIDALL", "", -1.e8, 1.e8);
736 RooRealVar PionDBinaryProtonPionIDSVDonly("PionDBinaryProtonPionIDSVDonly", "", -1.e8, 1.e8);
737 RooRealVar PionDBinaryProtonPionIDnoSVD("PionDBinaryProtonPionIDnoSVD", "", -1.e8, 1.e8);
738
739 RooRealVar PionDBinaryElectronPionIDALL("PionDBinaryElectronPionIDALL", "", -1.e8, 1.e8);
740 RooRealVar PionDBinaryElectronPionIDSVDonly("PionDBinaryElectronPionIDSVDonly", "", -1.e8, 1.e8);
741 RooRealVar PionDBinaryElectronPionIDnoSVD("PionDBinaryElectronPionIDnoSVD", "", -1.e8, 1.e8);
742
743 RooRealVar SlowPionKaonIDALL("SlowPionKaonIDALL", "", -1.e8, 1.e8);
744 RooRealVar SlowPionKaonIDSVDonly("SlowPionKaonIDSVDonly", "", -1.e8, 1.e8);
745 RooRealVar SlowPionKaonIDnoSVD("SlowPionKaonIDnoSVD", "", -1.e8, 1.e8);
746
747 RooRealVar SlowPionPionIDALL("SlowPionPionIDALL", "", -1.e8, 1.e8);
748 RooRealVar SlowPionPionIDSVDonly("SlowPionPionIDSVDonly", "", -1.e8, 1.e8);
749 RooRealVar SlowPionPionIDnoSVD("SlowPionPionIDnoSVD", "", -1.e8, 1.e8);
750
751 RooRealVar SlowPionElectronIDALL("SlowPionElectronIDALL", "", -1.e8, 1.e8);
752 RooRealVar SlowPionElectronIDSVDonly("SlowPionElectronIDSVDonly", "", -1.e8, 1.e8);
753 RooRealVar SlowPionElectronIDnoSVD("SlowPionElectronIDnoSVD", "", -1.e8, 1.e8);
754
755 RooRealVar SlowPionProtonIDALL("SlowPionProtonIDALL", "", -1.e8, 1.e8);
756 RooRealVar SlowPionProtonIDSVDonly("SlowPionProtonIDSVDonly", "", -1.e8, 1.e8);
757 RooRealVar SlowPionProtonIDnoSVD("SlowPionProtonIDnoSVD", "", -1.e8, 1.e8);
758
759 RooRealVar SlowPionBinaryPionKaonIDALL("SlowPionBinaryPionKaonIDALL", "", -1.e8, 1.e8);
760 RooRealVar SlowPionBinaryPionKaonIDSVDonly("SlowPionBinaryPionKaonIDSVDonly", "", -1.e8, 1.e8);
761 RooRealVar SlowPionBinaryPionKaonIDnoSVD("SlowPionBinaryPionKaonIDnoSVD", "", -1.e8, 1.e8);
762
763 RooRealVar SlowPionBinaryKaonPionIDALL("SlowPionBinaryKaonPionIDALL", "", -1.e8, 1.e8);
764 RooRealVar SlowPionBinaryKaonPionIDSVDonly("SlowPionBinaryKaonPionIDSVDonly", "", -1.e8, 1.e8);
765 RooRealVar SlowPionBinaryKaonPionIDnoSVD("SlowPionBinaryKaonPionIDnoSVD", "", -1.e8, 1.e8);
766
767 RooRealVar SlowPionBinaryProtonPionIDALL("SlowPionBinaryProtonPionIDALL", "", -1.e8, 1.e8);
768 RooRealVar SlowPionBinaryProtonPionIDSVDonly("SlowPionBinaryProtonPionIDSVDonly", "", -1.e8, 1.e8);
769 RooRealVar SlowPionBinaryProtonPionIDnoSVD("SlowPionBinaryProtonPionIDnoSVD", "", -1.e8, 1.e8);
770
771 RooRealVar SlowPionBinaryElectronPionIDALL("SlowPionBinaryElectronPionIDALL", "", -1.e8, 1.e8);
772 RooRealVar SlowPionBinaryElectronPionIDSVDonly("SlowPionBinaryElectronPionIDSVDonly", "", -1.e8, 1.e8);
773 RooRealVar SlowPionBinaryElectronPionIDnoSVD("SlowPionBinaryElectronPionIDnoSVD", "", -1.e8, 1.e8);
774
775 auto variables = new RooArgSet();
776 variables->add(deltaM);
777 variables->add(KaonMomentum);
778 variables->add(KaonSVDdEdx);
779 variables->add(PionDMomentum);
780 variables->add(PionDSVDdEdx);
781 variables->add(SlowPionMomentum);
782 variables->add(SlowPionSVDdEdx);
783 variables->add(exp);
784 variables->add(run);
785
786 variables->add(KaonKaonIDALL);
787 variables->add(KaonKaonIDSVDonly);
788 variables->add(KaonKaonIDnoSVD);
789 variables->add(KaonPionIDALL);
790 variables->add(KaonPionIDSVDonly);
791 variables->add(KaonPionIDnoSVD);
792 variables->add(KaonProtonIDALL);
793 variables->add(KaonProtonIDSVDonly);
794 variables->add(KaonProtonIDnoSVD);
795 variables->add(KaonElectronIDALL);
796 variables->add(KaonElectronIDSVDonly);
797 variables->add(KaonElectronIDnoSVD);
798 variables->add(KaonBinaryKaonPionIDALL);
799 variables->add(KaonBinaryKaonPionIDSVDonly);
800 variables->add(KaonBinaryKaonPionIDnoSVD);
801 variables->add(KaonBinaryPionKaonIDALL);
802 variables->add(KaonBinaryPionKaonIDSVDonly);
803 variables->add(KaonBinaryPionKaonIDnoSVD);
804 variables->add(KaonBinaryProtonKaonIDALL);
805 variables->add(KaonBinaryProtonKaonIDSVDonly);
806 variables->add(KaonBinaryProtonKaonIDnoSVD);
807 variables->add(KaonBinaryElectronKaonIDALL);
808 variables->add(KaonBinaryElectronKaonIDSVDonly);
809 variables->add(KaonBinaryElectronKaonIDnoSVD);
810
811 variables->add(PionDPionIDALL);
812 variables->add(PionDPionIDSVDonly);
813 variables->add(PionDPionIDnoSVD);
814 variables->add(PionDKaonIDALL);
815 variables->add(PionDKaonIDSVDonly);
816 variables->add(PionDKaonIDnoSVD);
817 variables->add(PionDElectronIDALL);
818 variables->add(PionDElectronIDSVDonly);
819 variables->add(PionDElectronIDnoSVD);
820 variables->add(PionDProtonIDALL);
821 variables->add(PionDProtonIDSVDonly);
822 variables->add(PionDProtonIDnoSVD);
823 variables->add(PionDBinaryPionKaonIDALL);
824 variables->add(PionDBinaryPionKaonIDSVDonly);
825 variables->add(PionDBinaryPionKaonIDnoSVD);
826 variables->add(PionDBinaryKaonPionIDALL);
827 variables->add(PionDBinaryKaonPionIDSVDonly);
828 variables->add(PionDBinaryKaonPionIDnoSVD);
829 variables->add(PionDBinaryProtonPionIDALL);
830 variables->add(PionDBinaryProtonPionIDSVDonly);
831 variables->add(PionDBinaryProtonPionIDnoSVD);
832 variables->add(PionDBinaryElectronPionIDALL);
833 variables->add(PionDBinaryElectronPionIDSVDonly);
834 variables->add(PionDBinaryElectronPionIDnoSVD);
835
836 variables->add(SlowPionPionIDALL);
837 variables->add(SlowPionPionIDSVDonly);
838 variables->add(SlowPionPionIDnoSVD);
839 variables->add(SlowPionKaonIDALL);
840 variables->add(SlowPionKaonIDSVDonly);
841 variables->add(SlowPionKaonIDnoSVD);
842 variables->add(SlowPionElectronIDALL);
843 variables->add(SlowPionElectronIDSVDonly);
844 variables->add(SlowPionElectronIDnoSVD);
845 variables->add(SlowPionProtonIDALL);
846 variables->add(SlowPionProtonIDSVDonly);
847 variables->add(SlowPionProtonIDnoSVD);
848 variables->add(SlowPionBinaryPionKaonIDALL);
849 variables->add(SlowPionBinaryPionKaonIDSVDonly);
850 variables->add(SlowPionBinaryPionKaonIDnoSVD);
851 variables->add(SlowPionBinaryKaonPionIDALL);
852 variables->add(SlowPionBinaryKaonPionIDSVDonly);
853 variables->add(SlowPionBinaryKaonPionIDnoSVD);
854 variables->add(SlowPionBinaryProtonPionIDALL);
855 variables->add(SlowPionBinaryProtonPionIDSVDonly);
856 variables->add(SlowPionBinaryProtonPionIDnoSVD);
857 variables->add(SlowPionBinaryElectronPionIDALL);
858 variables->add(SlowPionBinaryElectronPionIDSVDonly);
859 variables->add(SlowPionBinaryElectronPionIDnoSVD);
860
861 RooDataSet* DstarDataset = new RooDataSet("DstarDataset", "DstarDataset", preselTree.get(), *variables);
862
863 if (DstarDataset->sumEntries() == 0) {
864 B2FATAL("The Dstar dataset is empty, stopping here");
865 }
866
867 RooPlot* DstarFitFrame = DstarDataset->plotOn(deltaM.frame());
868
869 RooRealVar GaussMean("GaussMean", "GaussMean", 0.145, 0.140, 0.150);
870 RooRealVar GaussSigma1("GaussSigma1", "GaussSigma1", 0.01, 1.e-4, 1.0);
871 RooGaussian DstarGauss1("DstarGauss1", "DstarGauss1", deltaM, GaussMean, GaussSigma1);
872 RooRealVar GaussSigma2("GaussSigma2", "GaussSigma2", 0.001, 1.e-4, 1.0);
873 RooGaussian DstarGauss2("DstarGauss2", "DstarGauss2", deltaM, GaussMean, GaussSigma2);
874 RooRealVar fracGaussYield("fracGaussYield", "Fraction of two Gaussians", 0.75, 0.0, 1.0);
875 RooAddPdf DstarSignalPDF("DstarSignalPDF", "DstarGauss1+DstarGauss2", RooArgList(DstarGauss1, DstarGauss2), fracGaussYield);
876
877 RooRealVar dm0Bkg("dm0Bkg", "dm0", 0.13957018, 0.130, 0.140);
878 RooRealVar aBkg("aBkg", "a", -0.0784, -0.08, 3.0);
879 RooRealVar bBkg("bBkg", "b", -0.444713, -0.5, 0.4);
880 RooRealVar cBkg("cBkg", "c", 0.3);
881 RooDstD0BG DstarBkgPDF("DstarBkgPDF", "DstarBkgPDF", deltaM, dm0Bkg, cBkg, aBkg, bBkg);
882 RooRealVar nSignalDstar("nSignalDstar", "signal yield", 0.5 * preselTree->GetEntries(), 0, preselTree->GetEntries());
883 RooRealVar nBkgDstar("nBkgDstar", "background yield", 0.5 * preselTree->GetEntries(), 0, preselTree->GetEntries());
884 RooAddPdf totalPDFDstar("totalPDFDstar", "totalPDFDstar pdf", RooArgList(DstarSignalPDF, DstarBkgPDF),
885 RooArgList(nSignalDstar, nBkgDstar));
886
887 B2INFO("Dstar: Start fitting...");
888 RooFitResult* DstarFitResult = totalPDFDstar.fitTo(*DstarDataset, Save(kTRUE), PrintLevel(-1));
889
890 int status = DstarFitResult->status();
891 int covqual = DstarFitResult->covQual();
892 double diff = nSignalDstar.getValV() + nBkgDstar.getValV() - DstarDataset->sumEntries();
893
894 B2INFO("Dstar: Fit status: " << status << "; covariance quality: " << covqual);
895 // if the fit is not healthy, try again once before giving up, with a slightly different setup:
896 if ((status > 0) || (TMath::Abs(diff) > 1.) || (nSignalDstar.getError() < sqrt(nSignalDstar.getValV()))
897 || (nSignalDstar.getError() > (nSignalDstar.getValV()))) {
898
899 DstarFitResult = totalPDFDstar.fitTo(*DstarDataset, Save(), Strategy(2), Offset(1));
900 status = DstarFitResult->status();
901 covqual = DstarFitResult->covQual();
902 diff = nSignalDstar.getValV() + nBkgDstar.getValV() - DstarDataset->sumEntries();
903 }
904
905 if ((status > 0) || (TMath::Abs(diff) > 1.) || (nSignalDstar.getError() < sqrt(nSignalDstar.getValV()))
906 || (nSignalDstar.getError() > (nSignalDstar.getValV()))) {
907 B2WARNING("Dstar: Fit problem: fit status " << status << "; sum of component yields minus the dataset yield is " << diff <<
908 "; signal yield is " << nSignalDstar.getValV() << ", while its uncertainty is " << nSignalDstar.getError());
909 }
910 if (covqual < 2) {
911 B2INFO("Dstar: Fit warning: covariance quality " << covqual);
912 }
913
914 totalPDFDstar.plotOn(DstarFitFrame, LineColor(TColor::GetColor("#4575b4")));
915
916 double chisquare = DstarFitFrame->chiSquare();
917 B2INFO("Dstar: Fit chi2 = " << chisquare);
918 totalPDFDstar.paramOn(DstarFitFrame, Layout(0.63, 0.96, 0.93), Format("NEU", AutoPrecision(2)));
919 DstarFitFrame->getAttText()->SetTextSize(0.03);
920
921 totalPDFDstar.plotOn(DstarFitFrame, Components("DstarSignalPDF"), LineColor(TColor::GetColor("#d73027")));
922 totalPDFDstar.plotOn(DstarFitFrame, Components("DstarBkgPDF"), LineColor(TColor::GetColor("#fc8d59")));
923 totalPDFDstar.plotOn(DstarFitFrame, LineColor(TColor::GetColor("#4575b4")));
924
925 DstarFitFrame->GetXaxis()->SetTitle("#Deltam [GeV/c^{2}]");
926 TCanvas* canvDstar = new TCanvas("canvDstar", "canvDstar");
927 canvDstar->cd();
928
929 DstarFitFrame->Draw();
930
931 if (m_isMakePlots) {
932 canvDstar->Print("SVDdEdxValidationFitDstar.pdf");
933 TFile DstarFitPlotFile("SVDdEdxValidationDstarFitPlotFile.root", "RECREATE");
934 canvDstar->Write();
935 DstarFitPlotFile.Close();
936 }
937
939
940 RooStats::SPlot* sPlotDatasetDstar = new RooStats::SPlot("sData", "An SPlot", *DstarDataset, &totalPDFDstar,
941 RooArgList(nSignalDstar, nBkgDstar));
942
943 for (int iEvt = 0; iEvt < 5; iEvt++) {
944 if (TMath::Abs(sPlotDatasetDstar->GetSWeight(iEvt, "nSignalDstar") + sPlotDatasetDstar->GetSWeight(iEvt, "nBkgDstar") - 1) > 5.e-3)
945 B2FATAL("Dstar: sPlot error: sum of weights not equal to 1");
946 }
947
948 RooDataSet* DstarDatasetSWeighted = new RooDataSet(DstarDataset->GetName(), DstarDataset->GetTitle(), DstarDataset,
949 *DstarDataset->get());
950
951 RooDataSet::setDefaultStorageType(RooAbsData::Tree);
952 ((RooTreeDataStore*)(DstarDatasetSWeighted->store())->tree())->SetName("treeDstar_sw");
953 TTree* treeDstar_sw = DstarDatasetSWeighted->GetClonedTree();
954
955 B2INFO("Dstar: sPlot done. ");
956
957 return treeDstar_sw;
958}
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28

◆ dumpOutputJson()

const std::string dumpOutputJson ( ) const
inlineinherited

Dump the JSON string of the output JSON object.

Definition at line 223 of file CalibrationAlgorithm.h.

223{return m_jsonExecutionOutput.dump();}
nlohmann::json m_jsonExecutionOutput
Optional output JSON object that can be set during the execution by the underlying algorithm code.

◆ execute() [1/2]

CalibrationAlgorithm::EResult execute ( PyObject *  runs,
int  iteration = 0,
IntervalOfValidity  iov = IntervalOfValidity() 
)
inherited

Runs calibration over Python list of runs. Converts to C++ and then calls the other execute() function.

Definition at line 83 of file CalibrationAlgorithm.cc.

84{
85 B2DEBUG(29, "Running execute() using Python Object as input argument");
86 // Reset the execution specific data in case the algorithm was previously called
87 m_data.reset();
88 m_data.setIteration(iteration);
89 vector<ExpRun> vecRuns;
90 // Is it a list?
91 if (PySequence_Check(runs)) {
92 boost::python::handle<> handle(boost::python::borrowed(runs));
93 boost::python::list listRuns(handle);
94
95 int nList = boost::python::len(listRuns);
96 for (int iList = 0; iList < nList; ++iList) {
97 boost::python::object pyExpRun(listRuns[iList]);
98 if (!checkPyExpRun(pyExpRun.ptr())) {
99 B2ERROR("Received Python ExpRuns couldn't be converted to C++");
101 return c_Failure;
102 } else {
103 vecRuns.push_back(convertPyExpRun(pyExpRun.ptr()));
104 }
105 }
106 } else {
107 B2ERROR("Tried to set the input runs but we didn't receive a Python sequence object (list,tuple).");
109 return c_Failure;
110 }
111 return execute(vecRuns, iteration, iov);
112}
void setResult(EResult result)
Setter for current iteration.
void setIteration(int iteration)
Setter for current iteration.
void reset()
Resets this class back to what is needed at the beginning of an execution.
bool checkPyExpRun(PyObject *pyObj)
Checks that a PyObject can be successfully converted to an ExpRun type.
EResult execute(std::vector< Calibration::ExpRun > runs={}, int iteration=0, IntervalOfValidity iov=IntervalOfValidity())
Runs calibration over vector of runs for a given iteration.
Calibration::ExpRun convertPyExpRun(PyObject *pyObj)
Performs the conversion of PyObject to ExpRun.

◆ execute() [2/2]

CalibrationAlgorithm::EResult execute ( std::vector< Calibration::ExpRun >  runs = {},
int  iteration = 0,
IntervalOfValidity  iov = IntervalOfValidity() 
)
inherited

Runs calibration over vector of runs for a given iteration.

You can also specify the IoV to save the database payload as. By default the Algorithm will create an IoV from your requested ExpRuns, or from the overall ExpRuns of the input data if you haven't specified ExpRuns in this function.

No checks are performed to make sure that a IoV you specify matches the data you ran over, it simply labels the IoV to commit to the database later.

Definition at line 114 of file CalibrationAlgorithm.cc.

115{
116 // Check if we are calling this function directly and need to reset, or through Python where it was already done.
117 if (m_data.getResult() != c_Undefined) {
118 m_data.reset();
119 m_data.setIteration(iteration);
120 }
121
122 if (m_inputFileNames.empty()) {
123 B2ERROR("There aren't any input files set. Please use CalibrationAlgorithm::setInputFiles()");
125 return c_Failure;
126 }
127
128 // Did we receive runs to execute over explicitly?
129 if (!(runs.empty())) {
130 for (auto expRun : runs) {
131 B2DEBUG(29, "ExpRun requested = (" << expRun.first << ", " << expRun.second << ")");
132 }
133 // We've asked explicitly for certain runs, but we should check if the data granularity is 'run'
134 if (strcmp(getGranularity().c_str(), "all") == 0) {
135 B2ERROR(("The data is collected with granularity=all (exp=-1,run=-1), but you seem to request calibration for specific runs."
136 " We'll continue but using ALL the input data given instead of the specific runs requested."));
137 }
138 } else {
139 // If no runs are provided, infer the runs from all collected data
140 runs = getRunListFromAllData();
141 // Let's check that we have some now
142 if (runs.empty()) {
143 B2ERROR("No collected data in input files.");
145 return c_Failure;
146 }
147 for (auto expRun : runs) {
148 B2DEBUG(29, "ExpRun requested = (" << expRun.first << ", " << expRun.second << ")");
149 }
150 }
151
153 if (iov.empty()) {
154 // If no user specified IoV we use the IoV from the executed run list
155 iov = IntervalOfValidity(runs[0].first, runs[0].second, runs[runs.size() - 1].first, runs[runs.size() - 1].second);
156 }
158 // After here, the getObject<...>(...) helpers start to work
159
161 m_data.setResult(result);
162 return result;
163}
void setRequestedIov(const IntervalOfValidity &iov=IntervalOfValidity(0, 0, -1, -1))
Sets the requested IoV for this execution, based on the.
void setRequestedRuns(const std::vector< Calibration::ExpRun > &requestedRuns)
Sets the vector of ExpRuns.
EResult getResult() const
Getter for current result.
std::vector< Calibration::ExpRun > getRunListFromAllData() const
Get the complete list of runs from inspection of collected data.
std::vector< std::string > m_inputFileNames
List of input files to the Algorithm, will initially be user defined but then gets the wildcards expa...
EResult
The result of calibration.
virtual EResult calibrate()=0
Run algo on data - pure virtual: needs to be implemented.
std::string getGranularity() const
Get the granularity of collected data.
A class that describes the interval of experiments/runs for which an object in the database is valid.

◆ fillRunToInputFilesMap()

void fillRunToInputFilesMap ( )
inherited

Fill the mapping of ExpRun -> Files.

Definition at line 330 of file CalibrationAlgorithm.cc.

331{
332 m_runsToInputFiles.clear();
333 // Save TDirectory to change back at the end
334 TDirectory* dir = gDirectory;
335 RunRange* runRange;
336 // Construct the TDirectory name where we expect our objects to be
337 string runRangeObjName(getPrefix() + "/" + RUN_RANGE_OBJ_NAME);
338 for (const auto& fileName : m_inputFileNames) {
339 //Open TFile to get the objects
340 unique_ptr<TFile> f;
341 f.reset(TFile::Open(fileName.c_str(), "READ"));
342 runRange = dynamic_cast<RunRange*>(f->Get(runRangeObjName.c_str()));
343 if (runRange) {
344 // Insert or extend the run -> file mapping for this ExpRun
345 auto expRuns = runRange->getExpRunSet();
346 for (const auto& expRun : expRuns) {
347 auto runFiles = m_runsToInputFiles.find(expRun);
348 if (runFiles != m_runsToInputFiles.end()) {
349 (runFiles->second).push_back(fileName);
350 } else {
351 m_runsToInputFiles.insert(std::make_pair(expRun, std::vector<std::string> {fileName}));
352 }
353 }
354 } else {
355 B2WARNING("Missing a RunRange object for file: " << fileName);
356 }
357 }
358 dir->cd();
359}
std::string getPrefix() const
Get the prefix used for getting calibration data.
std::map< Calibration::ExpRun, std::vector< std::string > > m_runsToInputFiles
Map of Runs to input files. Gets filled when you call getRunRangeFromAllData, gets cleared when setti...
Mergeable object holding (unique) set of (exp,run) pairs.
Definition: RunRange.h:25
const std::set< Calibration::ExpRun > & getExpRunSet()
Get access to the stored set.
Definition: RunRange.h:64

◆ findPayloadBoundaries()

const std::vector< ExpRun > findPayloadBoundaries ( std::vector< Calibration::ExpRun >  runs,
int  iteration = 0 
)
inherited

Used to discover the ExpRun boundaries that you want the Python CAF to execute on. This is optional and only used in some.

Definition at line 520 of file CalibrationAlgorithm.cc.

521{
522 m_boundaries.clear();
523 if (m_inputFileNames.empty()) {
524 B2ERROR("There aren't any input files set. Please use CalibrationAlgorithm::setInputFiles()");
525 return m_boundaries;
526 }
527 // Reset the internal execution data just in case something is hanging around
528 m_data.reset();
529 if (runs.empty()) {
530 // Want to loop over all runs we could possibly know about
531 runs = getRunListFromAllData();
532 }
533 // Let's check that we have some now
534 if (runs.empty()) {
535 B2ERROR("No collected data in input files.");
536 return m_boundaries;
537 }
538 // In order to find run boundaries we must have collected with data granularity == 'run'
539 if (strcmp(getGranularity().c_str(), "all") == 0) {
540 B2ERROR("The data is collected with granularity='all' (exp=-1,run=-1), and we can't use that to find run boundaries.");
541 return m_boundaries;
542 }
543 m_data.setIteration(iteration);
544 // User defined setup function
545 boundaryFindingSetup(runs, iteration);
546 std::vector<ExpRun> runList;
547 // Loop over run list and call derived class "isBoundaryRequired" member function
548 for (auto currentRun : runs) {
549 runList.push_back(currentRun);
550 m_data.setRequestedRuns(runList);
551 // After here, the getObject<...>(...) helpers start to work
552 if (isBoundaryRequired(currentRun)) {
553 m_boundaries.push_back(currentRun);
554 }
555 // Only want run-by-run
556 runList.clear();
557 // Don't want memory hanging around
559 }
560 m_data.reset();
562 return m_boundaries;
563}
std::vector< Calibration::ExpRun > m_boundaries
When using the boundaries functionality from isBoundaryRequired, this is used to store the boundaries...
virtual void boundaryFindingTearDown()
Put your algorithm back into a state ready for normal execution if you need to.
virtual void boundaryFindingSetup(std::vector< Calibration::ExpRun >, int)
If you need to make some changes to your algorithm class before 'findPayloadBoundaries' is run,...
virtual bool isBoundaryRequired(const Calibration::ExpRun &)
Given the current collector data, make a decision about whether or not this run should be the start o...

◆ getAllGranularityExpRun()

Calibration::ExpRun getAllGranularityExpRun ( ) const
inlineprotectedinherited

Returns the Exp,Run pair that means 'Everything'. Currently unused.

Definition at line 327 of file CalibrationAlgorithm.h.

327{return m_allExpRun;}
static const Calibration::ExpRun m_allExpRun
allExpRun

◆ getCollectorName()

std::string getCollectorName ( ) const
inlineinherited

Alias for prefix.

For convenience and less writing, we say developers to set this to default collector module name in constructor of base class. One can however use the dublets of collector+algorithm multiple times with different settings. To bind these together correctly, the prefix has to be set the same for algo and collector. So we call the setter setPrefix rather than setModuleName or whatever. This getter will work out of the box for default cases -> return the name of module you have to add to your path to collect data for this algorihtm.

Definition at line 164 of file CalibrationAlgorithm.h.

164{return getPrefix();}

◆ getDescription()

const std::string & getDescription ( ) const
inlineinherited

Get the description of the algoithm (set by developers in constructor)

Definition at line 216 of file CalibrationAlgorithm.h.

216{return m_description;}
std::string m_description
Description of the algorithm.

◆ getExpRunString()

string getExpRunString ( Calibration::ExpRun &  expRun) const
privateinherited

Gets the "exp.run" string repr. of (exp,run)

Definition at line 254 of file CalibrationAlgorithm.cc.

255{
256 string expRunString;
257 expRunString += to_string(expRun.first);
258 expRunString += ".";
259 expRunString += to_string(expRun.second);
260 return expRunString;
261}

◆ getFullObjectPath()

string getFullObjectPath ( const std::string &  name,
Calibration::ExpRun  expRun 
) const
privateinherited

constructs the full TDirectory + Key name of an object in a TFile based on its name and exprun

Definition at line 263 of file CalibrationAlgorithm.cc.

264{
265 string dirName = getPrefix() + "/" + name;
266 string objName = name + "_" + getExpRunString(expRun);
267 return dirName + "/" + objName;
268}
std::string getExpRunString(Calibration::ExpRun &expRun) const
Gets the "exp.run" string repr. of (exp,run)

◆ getGranularity()

std::string getGranularity ( ) const
inlineinherited

Get the granularity of collected data.

Definition at line 188 of file CalibrationAlgorithm.h.

188{return m_granularityOfData;};
std::string m_granularityOfData
Granularity of input data. This only changes when the input files change so it isn't specific to an e...

◆ getGranularityFromData()

string getGranularityFromData ( ) const
protectedinherited

Get the granularity of collected data.

Definition at line 383 of file CalibrationAlgorithm.cc.

384{
385 // Save TDirectory to change back at the end
386 TDirectory* dir = gDirectory;
387 RunRange* runRange;
388 string runRangeObjName(getPrefix() + "/" + RUN_RANGE_OBJ_NAME);
389 // We only check the first file
390 string fileName = m_inputFileNames[0];
391 unique_ptr<TFile> f;
392 f.reset(TFile::Open(fileName.c_str(), "READ"));
393 runRange = dynamic_cast<RunRange*>(f->Get(runRangeObjName.c_str()));
394 if (!runRange) {
395 B2FATAL("The input file " << fileName << " does not contain a RunRange object at "
396 << runRangeObjName << ". Please set your input files to exclude it.");
397 return "";
398 }
399 string granularity = runRange->getGranularity();
400 dir->cd();
401 return granularity;
402}
std::string getGranularity() const
Gets the m_granularity.
Definition: RunRange.h:110

◆ getInputFileNames()

PyObject * getInputFileNames ( )
inherited

Get the input file names used for this algorithm and pass them out as a Python list of unicode strings.

Definition at line 245 of file CalibrationAlgorithm.cc.

246{
247 PyObject* objInputFileNames = PyList_New(m_inputFileNames.size());
248 for (size_t i = 0; i < m_inputFileNames.size(); ++i) {
249 PyList_SetItem(objInputFileNames, i, Py_BuildValue("s", m_inputFileNames[i].c_str()));
250 }
251 return objInputFileNames;
252}

◆ getInputJsonObject()

const nlohmann::json & getInputJsonObject ( ) const
inlineprotectedinherited

Get the entire top level JSON object. We explicitly say this must be of object type so that we might pick.

Definition at line 357 of file CalibrationAlgorithm.h.

357{return m_jsonExecutionInput;}
nlohmann::json m_jsonExecutionInput
Optional input JSON object used to make decisions about how to execute the algorithm code.

◆ getInputJsonValue()

const T getInputJsonValue ( const std::string &  key) const
inlineprotectedinherited

Get an input JSON value using a key. The normal exceptions are raised when the key doesn't exist.

Definition at line 350 of file CalibrationAlgorithm.h.

351 {
352 return m_jsonExecutionInput.at(key);
353 }

◆ getIovFromAllData()

IntervalOfValidity getIovFromAllData ( ) const
inherited

Get the complete IoV from inspection of collected data.

Definition at line 325 of file CalibrationAlgorithm.cc.

326{
328}
RunRange getRunRangeFromAllData() const
Get the complete RunRange from inspection of collected data.
IntervalOfValidity getIntervalOfValidity()
Make IntervalOfValidity from the set, spanning all runs. Works because sets are sorted by default.
Definition: RunRange.h:70

◆ getIteration()

int getIteration ( ) const
inlineprotectedinherited

Get current iteration.

Definition at line 269 of file CalibrationAlgorithm.h.

269{ return m_data.getIteration(); }
int getIteration() const
Getter for current iteration.

◆ getObjectPtr()

std::shared_ptr< T > getObjectPtr ( std::string  name)
inlineprotectedinherited

Get calibration data object (for all runs the calibration is requested for) This function will only work during or after execute() has been called once.

Definition at line 285 of file CalibrationAlgorithm.h.

286 {
287 if (m_runsToInputFiles.size() == 0)
289 return getObjectPtr<T>(name, m_data.getRequestedRuns());
290 }
const std::vector< Calibration::ExpRun > & getRequestedRuns() const
Returns the vector of ExpRuns.
void fillRunToInputFilesMap()
Fill the mapping of ExpRun -> Files.

◆ getOutputJsonValue()

const T getOutputJsonValue ( const std::string &  key) const
inlineprotectedinherited

Get a value using a key from the JSON output object, not sure why you would want to do this.

Definition at line 342 of file CalibrationAlgorithm.h.

343 {
344 return m_jsonExecutionOutput.at(key);
345 }

◆ getPayloads()

std::list< Database::DBImportQuery > & getPayloads ( )
inlineinherited

Get constants (in TObjects) for database update from last execution.

Definition at line 204 of file CalibrationAlgorithm.h.

204{return m_data.getPayloads();}
std::list< Database::DBImportQuery > & getPayloads()
Get constants (in TObjects) for database update from last calibration.

◆ getPayloadValues()

std::list< Database::DBImportQuery > getPayloadValues ( )
inlineinherited

Get constants (in TObjects) for database update from last execution but passed by VALUE.

Definition at line 207 of file CalibrationAlgorithm.h.

207{return m_data.getPayloadValues();}
std::list< Database::DBImportQuery > getPayloadValues()
Get constants (in TObjects) for database update from last calibration but passed by VALUE.

◆ getPrefix()

std::string getPrefix ( ) const
inlineinherited

Get the prefix used for getting calibration data.

Definition at line 146 of file CalibrationAlgorithm.h.

146{return m_prefix;}
std::string m_prefix
The name of the TDirectory the collector objects are contained within.

◆ getRunList()

const std::vector< Calibration::ExpRun > & getRunList ( ) const
inlineprotectedinherited

Get the list of runs for which calibration is called.

Definition at line 266 of file CalibrationAlgorithm.h.

266{return m_data.getRequestedRuns();}

◆ getRunListFromAllData()

vector< ExpRun > getRunListFromAllData ( ) const
inherited

Get the complete list of runs from inspection of collected data.

Definition at line 318 of file CalibrationAlgorithm.cc.

319{
320 RunRange runRange = getRunRangeFromAllData();
321 set<ExpRun> expRunSet = runRange.getExpRunSet();
322 return vector<ExpRun>(expRunSet.begin(), expRunSet.end());
323}

◆ getRunRangeFromAllData()

RunRange getRunRangeFromAllData ( ) const
inherited

Get the complete RunRange from inspection of collected data.

Definition at line 361 of file CalibrationAlgorithm.cc.

362{
363 // Save TDirectory to change back at the end
364 TDirectory* dir = gDirectory;
365 RunRange runRange;
366 // Construct the TDirectory name where we expect our objects to be
367 string runRangeObjName(getPrefix() + "/" + RUN_RANGE_OBJ_NAME);
368 for (const auto& fileName : m_inputFileNames) {
369 //Open TFile to get the objects
370 unique_ptr<TFile> f;
371 f.reset(TFile::Open(fileName.c_str(), "READ"));
372 RunRange* runRangeOther = dynamic_cast<RunRange*>(f->Get(runRangeObjName.c_str()));
373 if (runRangeOther) {
374 runRange.merge(runRangeOther);
375 } else {
376 B2WARNING("Missing a RunRange object for file: " << fileName);
377 }
378 }
379 dir->cd();
380 return runRange;
381}
virtual void merge(const RunRange *other)
Implementation of merging - other is added to the set (union)
Definition: RunRange.h:52

◆ getVecInputFileNames()

std::vector< std::string > getVecInputFileNames ( ) const
inlineprotectedinherited

Get the input file names used for this algorithm as a STL vector.

Definition at line 275 of file CalibrationAlgorithm.h.

275{return m_inputFileNames;}

◆ inputJsonKeyExists()

bool inputJsonKeyExists ( const std::string &  key) const
inlineprotectedinherited

Test for a key in the input JSON object.

Definition at line 360 of file CalibrationAlgorithm.h.

360{return m_jsonExecutionInput.count(key);}

◆ isBoundaryRequired()

virtual bool isBoundaryRequired ( const Calibration::ExpRun &  )
inlineprotectedvirtualinherited

Given the current collector data, make a decision about whether or not this run should be the start of a payload boundary.

Reimplemented in TestBoundarySettingAlgorithm, PXDAnalyticGainCalibrationAlgorithm, PXDValidationAlgorithm, TestCalibrationAlgorithm, SVD3SampleCoGTimeCalibrationAlgorithm, SVD3SampleELSTimeCalibrationAlgorithm, and SVDCoGTimeCalibrationAlgorithm.

Definition at line 243 of file CalibrationAlgorithm.h.

244 {
245 B2ERROR("You didn't implement a isBoundaryRequired() member function in your CalibrationAlgorithm but you are calling it!");
246 return false;
247 }

◆ LambdaMassFit()

TTree * LambdaMassFit ( std::shared_ptr< TTree >  preselTree)
private

produce histograms for protons

Definition at line 469 of file SVDdEdxValidationAlgorithm.cc.

470{
471 B2INFO("Configuring the Lambda fit...");
472 gROOT->SetBatch(true);
473 RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING);
474
475 RooRealVar InvM("InvM", "m(p^{+}#pi^{-})", 1.1, 1.13, "GeV/c^{2}");
476
477 RooRealVar ProtonMomentum("ProtonMomentum", "momentum for p", -1.e8, 1.e8);
478 RooRealVar ProtonSVDdEdx("ProtonSVDdEdx", "", -1.e8, 1.e8);
479
480 RooRealVar exp("exp", "experiment number", 0, 1.e5);
481 RooRealVar run("run", "run number", 0, 1.e7);
482
483 RooRealVar ProtonProtonIDALL("ProtonProtonIDALL", "", -1.e8, 1.e8);
484 RooRealVar ProtonProtonIDSVDonly("ProtonProtonIDSVDonly", "", -1.e8, 1.e8);
485 RooRealVar ProtonProtonIDnoSVD("ProtonProtonIDnoSVD", "", -1.e8, 1.e8);
486
487 RooRealVar ProtonBinaryProtonPionIDALL("ProtonBinaryProtonPionIDALL", "", -1.e8, 1.e8);
488 RooRealVar ProtonBinaryProtonPionIDSVDonly("ProtonBinaryProtonPionIDSVDonly", "", -1.e8, 1.e8);
489 RooRealVar ProtonBinaryProtonPionIDnoSVD("ProtonBinaryProtonPionIDnoSVD", "", -1.e8, 1.e8);
490
491 RooRealVar ProtonBinaryProtonKaonIDALL("ProtonBinaryProtonKaonIDALL", "", -1.e8, 1.e8);
492 RooRealVar ProtonBinaryProtonKaonIDSVDonly("ProtonBinaryProtonKaonIDSVDonly", "", -1.e8, 1.e8);
493 RooRealVar ProtonBinaryProtonKaonIDnoSVD("ProtonBinaryProtonKaonIDnoSVD", "", -1.e8, 1.e8);
494
495 RooRealVar ProtonBinaryProtonElectronIDALL("ProtonBinaryProtonElectronIDALL", "", -1.e8, 1.e8);
496 RooRealVar ProtonBinaryProtonElectronIDSVDonly("ProtonBinaryProtonElectronIDSVDonly", "", -1.e8, 1.e8);
497 RooRealVar ProtonBinaryProtonElectronIDnoSVD("ProtonBinaryProtonElectronIDnoSVD", "", -1.e8, 1.e8);
498
499 RooRealVar ProtonBinaryPionProtonIDALL("ProtonBinaryPionProtonIDALL", "", -1.e8, 1.e8);
500 RooRealVar ProtonBinaryPionProtonIDSVDonly("ProtonBinaryPionProtonIDSVDonly", "", -1.e8, 1.e8);
501 RooRealVar ProtonBinaryPionProtonIDnoSVD("ProtonBinaryPionProtonIDnoSVD", "", -1.e8, 1.e8);
502
503 RooRealVar ProtonBinaryKaonProtonIDALL("ProtonBinaryKaonProtonIDALL", "", -1.e8, 1.e8);
504 RooRealVar ProtonBinaryKaonProtonIDSVDonly("ProtonBinaryKaonProtonIDSVDonly", "", -1.e8, 1.e8);
505 RooRealVar ProtonBinaryKaonProtonIDnoSVD("ProtonBinaryKaonProtonIDnoSVD", "", -1.e8, 1.e8);
506
507 RooRealVar ProtonBinaryElectronProtonIDALL("ProtonBinaryElectronProtonIDALL", "", -1.e8, 1.e8);
508 RooRealVar ProtonBinaryElectronProtonIDSVDonly("ProtonBinaryElectronProtonIDSVDonly", "", -1.e8, 1.e8);
509 RooRealVar ProtonBinaryElectronProtonIDnoSVD("ProtonBinaryElectronProtonIDnoSVD", "", -1.e8, 1.e8);
510
511 auto variables = new RooArgSet();
512
513 variables->add(InvM);
514
515 variables->add(ProtonMomentum);
516 variables->add(ProtonSVDdEdx);
517 variables->add(exp);
518 variables->add(run);
519
520 variables->add(ProtonProtonIDALL);
521 variables->add(ProtonProtonIDSVDonly);
522 variables->add(ProtonProtonIDnoSVD);
523 variables->add(ProtonBinaryProtonPionIDALL);
524 variables->add(ProtonBinaryProtonPionIDSVDonly);
525 variables->add(ProtonBinaryProtonPionIDnoSVD);
526 variables->add(ProtonBinaryProtonKaonIDALL);
527 variables->add(ProtonBinaryProtonKaonIDSVDonly);
528 variables->add(ProtonBinaryProtonKaonIDnoSVD);
529 variables->add(ProtonBinaryProtonElectronIDALL);
530 variables->add(ProtonBinaryProtonElectronIDSVDonly);
531 variables->add(ProtonBinaryProtonElectronIDnoSVD);
532 variables->add(ProtonBinaryPionProtonIDALL);
533 variables->add(ProtonBinaryPionProtonIDSVDonly);
534 variables->add(ProtonBinaryPionProtonIDnoSVD);
535 variables->add(ProtonBinaryKaonProtonIDALL);
536 variables->add(ProtonBinaryKaonProtonIDSVDonly);
537 variables->add(ProtonBinaryKaonProtonIDnoSVD);
538 variables->add(ProtonBinaryElectronProtonIDALL);
539 variables->add(ProtonBinaryElectronProtonIDSVDonly);
540 variables->add(ProtonBinaryElectronProtonIDnoSVD);
541
542 RooDataSet* LambdaDataset = new RooDataSet("LambdaDataset", "LambdaDataset", preselTree.get(), *variables);
543
544 if (LambdaDataset->sumEntries() == 0) {
545 B2FATAL("The Lambda dataset is empty, stopping here");
546 }
547
548 // the signal PDF; might be revisited at a later point
549
550 RooRealVar GaussMean("GaussMean", " GaussMean", 1.116, 1.111, 1.12);
551 RooRealVar GaussSigma("GaussSigma", "#sigma_{1}", 3.e-3, 3.e-5, 10.e-3);
552 RooGaussian LambdaGauss("LambdaGauss", "LambdaGauss", InvM, GaussMean, GaussSigma);
553
554 /* temporary RooRealVar sigmaBifurGaussL1 and sigmaBifurGaussR1 to replace
555 * RooRealVar resolutionParamL("resolutionParamL", "resolutionParamL", 0.4, 5.e-4, 1.0);
556 * RooRealVar resolutionParamR("resolutionParamR", "resolutionParamR", 0.4, 5.e-4, 1.0);
557 * RooFormulaVar sigmaBifurGaussL1("sigmaBifurGaussL1", "resolutionParamL*GaussSigma", RooArgSet(resolutionParamL, GaussSigma));
558 * RooFormulaVar sigmaBifurGaussR1("sigmaBifurGaussR1", "resolutionParamR*GaussSigma", RooArgSet(resolutionParamR, GaussSigma));
559 */
560 RooRealVar sigmaBifurGaussL1("sigmaBifurGaussL1", "sigma left", 0.4 * 3.e-3, 3.e-5, 10.e-3);
561 RooRealVar sigmaBifurGaussR1("sigmaBifurGaussR1", "sigma right", 0.4 * 3.e-3, 3.e-5, 10.e-3);
562 RooBifurGauss LambdaBifurGauss("LambdaBifurGauss", "LambdaBifurGauss", InvM, GaussMean, sigmaBifurGaussL1, sigmaBifurGaussR1);
563
564 /* temporary RooRealVar sigmaBifurGaussL2 to replace
565 * RooRealVar resolutionParam2("resolutionParam2", "resolutionParam2", 0.2, 5.e-4, 1.0);
566 * sigmaBifurGaussL2("sigmaBifurGaussL2", "resolutionParam2*GaussSigma", RooArgSet(resolutionParam2, GaussSigma));
567 */
568 RooRealVar sigmaBifurGaussL2("sigmaBifurGaussL2", "sigmaBifurGaussL2", 0.2 * 3.e-3, 3.e-5, 10.e-3);
569 RooGaussian LambdaBifurGauss2("LambdaBifurGauss2", "LambdaBifurGauss2", InvM, GaussMean, sigmaBifurGaussL2);
570
571 RooRealVar fracBifurGaussYield("fracBifurGaussYield", "fracBifurGaussYield", 0.3, 5.e-4, 1.0);
572 RooRealVar fracGaussYield("fracGaussYield", "fracGaussYield", 0.8, 5.e-4, 1.0);
573
574 RooAddPdf LambdaCombinedBifurGauss("LambdaCombinedBifurGauss", "LambdaBifurGauss + LambdaBifurGauss2 ", RooArgList(LambdaBifurGauss,
575 LambdaBifurGauss2), RooArgList(fracBifurGaussYield));
576
577 RooAddPdf LambdaSignalPDF("LambdaSignalPDF", "LambdaCombinedBifurGauss + LambdaGauss", RooArgList(LambdaCombinedBifurGauss,
578 LambdaGauss), RooArgList(fracGaussYield));
579
580 // Background PDF
581 RooRealVar BkgPolyCoef0("BkgPolyCoef0", "BkgPolyCoef0", 0.1, 0., 1.5);
582 RooRealVar BkgPolyCoef1("BkgPolyCoef1", "BkgPolyCoef1", -0.5, -1.5, -1.e-3);
583 RooChebychev BkgPolyPDF("BkgPolyPDF", "BkgPolyPDF", InvM, RooArgList(BkgPolyCoef0, BkgPolyCoef1));
584
585 RooRealVar nSignalLambda("nSignalLambda", "nSignalLambda", 0.6 * preselTree->GetEntries(), 0., 0.99 * preselTree->GetEntries());
586 RooRealVar nBkgLambda("nBkgLambda", "nBkgLambda", 0.4 * preselTree->GetEntries(), 0., 0.99 * preselTree->GetEntries());
587 RooAddPdf totalPDFLambda("totalPDFLambda", "totalPDFLambda pdf", RooArgList(LambdaSignalPDF, BkgPolyPDF),
588 RooArgList(nSignalLambda, nBkgLambda));
589
590 B2INFO("Lambda: Start fitting...");
591 RooFitResult* LambdaFitResult = totalPDFLambda.fitTo(*LambdaDataset, Save(kTRUE), PrintLevel(-1));
592
593 int status = LambdaFitResult->status();
594 int covqual = LambdaFitResult->covQual();
595 double diff = nSignalLambda.getValV() + nBkgLambda.getValV() - LambdaDataset->sumEntries();
596
597 B2INFO("Lambda: Fit status: " << status << "; covariance quality: " << covqual);
598 // if the fit is not healthy, try again once before giving up, with a slightly different setup:
599 if ((status > 0) || (TMath::Abs(diff) > 1.) || (nSignalLambda.getError() < sqrt(nSignalLambda.getValV()))
600 || (nSignalLambda.getError() > (nSignalLambda.getValV()))) {
601
602 LambdaFitResult = totalPDFLambda.fitTo(*LambdaDataset, Save(), Strategy(2), Offset(1));
603 status = LambdaFitResult->status();
604 covqual = LambdaFitResult->covQual();
605 diff = nSignalLambda.getValV() + nBkgLambda.getValV() - LambdaDataset->sumEntries();
606 }
607
608 if ((status > 0) || (TMath::Abs(diff) > 1.) || (nSignalLambda.getError() < sqrt(nSignalLambda.getValV()))
609 || (nSignalLambda.getError() > (nSignalLambda.getValV()))) {
610 B2WARNING("Lambda: Fit problem: fit status " << status << "; sum of component yields minus the dataset yield is " << diff <<
611 "; signal yield is " << nSignalLambda.getValV() << ", while its uncertainty is " << nSignalLambda.getError());
612 }
613 if (covqual < 2) {
614 B2INFO("Lambda: Fit warning: covariance quality " << covqual);
615 }
616
617 TCanvas* canvLambda = new TCanvas("canvLambda", "canvLambda");
618 RooPlot* LambdaFitFrame = LambdaDataset->plotOn(InvM.frame(130));
619 totalPDFLambda.plotOn(LambdaFitFrame, LineColor(TColor::GetColor("#4575b4")));
620
621 double chisquare = LambdaFitFrame->chiSquare();
622 B2INFO("Lambda: Fit chi2 = " << chisquare);
623 totalPDFLambda.paramOn(LambdaFitFrame, Layout(0.6, 0.96, 0.93), Format("NEU", AutoPrecision(2)));
624 LambdaFitFrame->getAttText()->SetTextSize(0.03);
625
626 totalPDFLambda.plotOn(LambdaFitFrame, Components("LambdaSignalPDF"), LineColor(TColor::GetColor("#d73027")));
627 totalPDFLambda.plotOn(LambdaFitFrame, Components("BkgPolyPDF"), LineColor(TColor::GetColor("#fc8d59")));
628 totalPDFLambda.plotOn(LambdaFitFrame, LineColor(TColor::GetColor("#4575b4")));
629
630 LambdaFitFrame->GetXaxis()->SetTitle("m(p#pi^{-}) (GeV/c^{2})");
631
632 LambdaFitFrame->Draw();
633
634 if (m_isMakePlots) {
635 canvLambda->Print("SVDdEdxValidationFitLambda.pdf");
636 TFile LambdaFitPlotFile("SVDdEdxValidationLambdaFitPlotFile.root", "RECREATE");
637 canvLambda->Write();
638 LambdaFitPlotFile.Close();
639 }
640 RooStats::SPlot* sPlotDatasetLambda = new RooStats::SPlot("sData", "An SPlot", *LambdaDataset, &totalPDFLambda,
641 RooArgList(nSignalLambda, nBkgLambda));
642
643 for (int iEvt = 0; iEvt < 5; iEvt++) {
644 if (TMath::Abs(sPlotDatasetLambda->GetSWeight(iEvt, "nSignalLambda") + sPlotDatasetLambda->GetSWeight(iEvt,
645 "nBkgLambda") - 1) > 5.e-3)
646 B2FATAL("Lambda: sPlot error: sum of weights not equal to 1");
647 }
648
649 RooDataSet* LambdaDatasetSWeighted = new RooDataSet(LambdaDataset->GetName(), LambdaDataset->GetTitle(), LambdaDataset,
650 *LambdaDataset->get());
651
652 RooDataSet::setDefaultStorageType(RooAbsData::Tree);
653 ((RooTreeDataStore*)(LambdaDatasetSWeighted->store())->tree())->SetName("treeLambda_sw");
654 TTree* treeLambda_sw = LambdaDatasetSWeighted->GetClonedTree();
655
656 B2INFO("Lambda: sPlot done. ");
657
658 return treeLambda_sw;
659}

◆ loadInputJson()

bool loadInputJson ( const std::string &  jsonString)
inherited

Load the m_inputJson variable from a string (useful from Python interface). The rturn bool indicates success or failure.

Definition at line 502 of file CalibrationAlgorithm.cc.

503{
504 try {
505 auto jsonInput = nlohmann::json::parse(jsonString);
506 // Input string has an object (dict) as the top level object?
507 if (jsonInput.is_object()) {
508 m_jsonExecutionInput = jsonInput;
509 return true;
510 } else {
511 B2ERROR("JSON input string isn't an object type i.e. not a '{}' at the top level.");
512 return false;
513 }
514 } catch (nlohmann::json::parse_error&) {
515 B2ERROR("Parsing of JSON input string failed");
516 return false;
517 }
518}

◆ PlotEfficiencyPlots()

void PlotEfficiencyPlots ( const TString &  PIDDetectorsName,
TTree *  SignalTree,
TString  SignalWeightName,
TString  SignalVarName,
TString  SignalVarNameFull,
TTree *  FakeTree,
TString  FakeWeightName,
TString  FakeVarName,
TString  FakeVarNameFull,
TString  PIDVarName,
TString  PIDCut,
unsigned int  nbins,
double  MomLow,
double  MomHigh 
)
private

a generic function to produce efficiency plots

Definition at line 138 of file SVDdEdxValidationAlgorithm.cc.

141{
142
143 if ((SignalTree == nullptr) || (FakeTree == nullptr)) {
144 B2FATAL("Invalid dataset, stopping here");
145 }
146
147 if ((SignalTree->GetEntries() == 0) || (FakeTree->GetEntries() == 0)) {
148 B2FATAL("The dataset is empty, stopping here");
149 }
150
151 if ((SignalTree->GetBranch(Form("%sMomentum", SignalVarName.Data())) == nullptr)
152 || (FakeTree->GetBranch(Form("%sMomentum", FakeVarName.Data())) == nullptr)) {
153 B2FATAL("Check the provided branch name, stopping here");
154 }
155
156 TString SignalFiducialCut = "(1>0)"; // placeholder for a possible sanity cut
157 TString FakesFiducialCut = "(1>0)";
158
159 // Produce the plots of the SVD PID distribution
160 if (PIDDetectorsName == "SVDonly") {
161 SignalTree->Draw(Form("%s%s%s>>hSignalPIDDistribution(100,0.,1.)", SignalVarName.Data(), PIDVarName.Data(),
162 PIDDetectorsName.Data()),
163 SignalWeightName + Form("* (%sMomentum>%f && %sMomentum<%f)", SignalVarName.Data(), MomLow, SignalVarName.Data(), MomHigh), "goff");
164 TH1F* hSignalPIDDistribution = (TH1F*)gDirectory->Get("hSignalPIDDistribution");
165 hSignalPIDDistribution->Scale(1. / hSignalPIDDistribution->Integral());
166 hSignalPIDDistribution->GetXaxis()->SetTitle(PIDVarName + PIDDetectorsName + " for " + SignalVarNameFull);
167 hSignalPIDDistribution->GetYaxis()->SetTitle("Candidates, normalised");
168 hSignalPIDDistribution->SetMaximum(1.35 * hSignalPIDDistribution->GetMaximum());
169
170 TCanvas* DistribCanvas = new TCanvas("DistribCanvas", "", 600, 600);
171 gPad->SetTopMargin(0.05);
172 gPad->SetRightMargin(0.05);
173 gPad->SetLeftMargin(0.13);
174 gPad->SetBottomMargin(0.12);
175
176 hSignalPIDDistribution->SetLineWidth(2);
177 hSignalPIDDistribution->SetLineColor(TColor::GetColor("#2166ac"));
178 hSignalPIDDistribution->Draw("hist ");
179
180 DistribCanvas->Print("SVDdEdxValidation_Distribution_" + SignalVarNameFull + PIDVarName + PIDDetectorsName +
181 "_MomRange_" +
182 std::to_string(
183 MomLow)
184 .substr(0, 3) +
185 "_" + std::to_string(MomHigh).substr(0, 3) + ".pdf");
186 TFile DistribFile("SVDdEdxValidation_Distribution_" + SignalVarNameFull + PIDVarName + PIDDetectorsName +
187 "_MomRange_" +
188 std::to_string(
189 MomLow)
190 .substr(0, 3) +
191 "_" + std::to_string(MomHigh).substr(0, 3) + ".root", "RECREATE");
192 hSignalPIDDistribution->SetLineColor(kBlack);
193 hSignalPIDDistribution->Write();
194 DistribFile.Close();
195 delete DistribCanvas;
196 }
197
198 // ---------- Momentum distributions (for efficiency determination) ----------
199
200 SignalTree->Draw(Form("%sMomentum>>hAllSignal(%i,%f,%f)", SignalVarName.Data(), nbins, MomLow, MomHigh),
201 SignalWeightName + " * (" + SignalFiducialCut + ")", "goff");
202 SignalTree->Draw(Form("%sMomentum>>hSelectedSignal(%i,%f,%f)", SignalVarName.Data(), nbins, MomLow, MomHigh),
203 SignalWeightName + " * (" + SignalVarName + PIDVarName + PIDDetectorsName + ">" + PIDCut + "&&" + SignalFiducialCut +
204 ")",
205 "goff");
206
207 FakeTree->Draw(Form("%sMomentum>>hAllFakes(%i,%f,%f)", FakeVarName.Data(), nbins, MomLow, MomHigh),
208 FakeWeightName + " * (" + FakesFiducialCut + ")", "goff");
209 FakeTree->Draw(Form("%sMomentum>>hSelectedFakes(%i,%f,%f)", FakeVarName.Data(), nbins, MomLow, MomHigh),
210 FakeWeightName + " * (" + FakeVarName + PIDVarName + PIDDetectorsName + ">" + PIDCut + "&&" + FakesFiducialCut + ")",
211 "goff");
212
213 TH1F* hAllSignal = (TH1F*)gDirectory->Get("hAllSignal");
214 TH1F* hSelectedSignal = (TH1F*)gDirectory->Get("hSelectedSignal");
215 TH1F* hAllFakes = (TH1F*)gDirectory->Get("hAllFakes");
216 TH1F* hSelectedFakes = (TH1F*)gDirectory->Get("hSelectedFakes");
217
218 // ---------- Add slow pions to the pion dataset ----------
219 if (strncmp(SignalVarName.Data(), "PionD", 5) == 0) {
220 SignalTree->Draw(Form("SlowPionMomentum>>hAllSignalSlow(%i,%f,%f)", nbins, MomLow, MomHigh),
221 SignalWeightName + " * (" + SignalFiducialCut + ")", "goff");
222 SignalTree->Draw(Form("SlowPionMomentum>>hSelectedSignalSlow(%i,%f,%f)", nbins, MomLow, MomHigh),
223 SignalWeightName + " * (SlowPion" + PIDVarName + PIDDetectorsName + ">" + PIDCut + "&&" + SignalFiducialCut + ")", "goff");
224 TH1F* hAllSignalSlow = (TH1F*)gDirectory->Get("hAllSignalSlow");
225 TH1F* hSelectedSignalSlow = (TH1F*)gDirectory->Get("hSelectedSignalSlow");
226 hAllSignal->Add(hAllSignalSlow);
227 hSelectedSignal->Add(hSelectedSignalSlow);
228 }
229
230 if (strncmp(FakeVarName.Data(), "PionD", 5) == 0) {
231 FakeTree->Draw(Form("SlowPionMomentum>>hAllFakesSlow(%i,%f,%f)", nbins, MomLow, MomHigh),
232 FakeWeightName + " * (" + FakesFiducialCut + ")",
233 "goff");
234 FakeTree->Draw(Form("SlowPionMomentum>>hSelectedFakesSlow(%i,%f,%f)", nbins, MomLow, MomHigh),
235 FakeWeightName + " * (SlowPion" + PIDVarName + PIDDetectorsName + ">" + PIDCut + "&&" + FakesFiducialCut + ")", "goff");
236 TH1F* hAllFakesSlow = (TH1F*)gDirectory->Get("hAllFakesSlow");
237 TH1F* hSelectedFakesSlow = (TH1F*)gDirectory->Get("hSelectedFakesSlow");
238 hAllFakes->Add(hAllFakesSlow);
239 hSelectedFakes->Add(hSelectedFakesSlow);
240 }
241
242 TH1F* EffHistoSig = (TH1F*)hAllSignal->Clone("EffHistoSig"); // signal efficiency
243 TH1F* EffHistoFake = (TH1F*)hAllFakes->Clone("EffHistoFake"); // fakes efficiency
244
245 EffHistoSig->Divide(hSelectedSignal, hAllSignal, 1, 1, "B");
246 EffHistoFake->Divide(hSelectedFakes, hAllFakes, 1, 1, "B");
247
248 // PID plots
249 TH1F* hBase = new TH1F("hBase", "", 100, 0.0, MomHigh);
250 hBase->SetTitle(";Momentum [GeV];Efficiency");
251 hBase->SetMaximum(1.20);
252 hBase->SetMinimum(0.0);
253
254 TLegend* tleg1 = new TLegend(0.63, 0.82, 0.93, 0.94);
255 tleg1->AddEntry(EffHistoSig, SignalVarNameFull + " efficiency", "pl");
256 tleg1->AddEntry(EffHistoFake, FakeVarNameFull + " fake rate", "pl");
257
258 TCanvas* ResultCanvas = new TCanvas("ResultCanvas", "", 600, 600);
259 gPad->SetTopMargin(0.05);
260 gPad->SetRightMargin(0.05);
261 gPad->SetLeftMargin(0.13);
262 gPad->SetBottomMargin(0.12);
263
264 ResultCanvas->SetGrid();
265 hBase->Draw();
266 EffHistoSig->SetMarkerSize(1.5);
267 EffHistoSig->SetMarkerStyle(22);
268 EffHistoSig->SetMarkerColor(TColor::GetColor("#2166ac"));
269 EffHistoSig->SetLineColor(TColor::GetColor("#2166ac"));
270 EffHistoSig->Draw("P,same");
271
272 EffHistoFake->SetMarkerSize(1.5);
273 EffHistoFake->SetMarkerStyle(23);
274 EffHistoFake->SetMarkerColor(TColor::GetColor("#ef8a62"));
275 EffHistoFake->SetLineColor(TColor::GetColor("#ef8a62"));
276 EffHistoFake->Draw("P,same");
277
278 tleg1->Draw("same");
279
280 hBase->SetStats(0);
281 hBase->GetXaxis()->SetTitleSize(0.04);
282 hBase->GetYaxis()->SetTitleSize(0.04);
283 hBase->GetXaxis()->SetTitleOffset(1.0);
284 hBase->GetYaxis()->SetTitleOffset(1.3);
285 hBase->GetYaxis()->SetLabelSize(0.04);
286 hBase->GetXaxis()->SetLabelSize(0.04);
287
288 // std::setprecision(2);
289 ResultCanvas->Print("SVDdEdxValidation_Efficiency_" + SignalVarNameFull + "_vs_" + FakeVarNameFull + PIDVarName + "_" +
290 PIDDetectorsName +
291 "_Cut" +
292 PIDCut + "_MomRange_" + std::to_string(MomLow).substr(0, 3) + "_" + std::to_string(MomHigh).substr(0, 3) + ".pdf");
293 TFile ResultFile("SVDdEdxValidation_Efficiency_" + SignalVarNameFull + "_vs_" + FakeVarNameFull + PIDVarName + "_" +
294 PIDDetectorsName +
295 "_Cut" +
296 PIDCut + "_MomRange_" + std::to_string(MomLow).substr(0, 3) + "_" + std::to_string(MomHigh).substr(0, 3) + ".root", "RECREATE");
297 EffHistoSig->SetLineColor(kBlack);
298 EffHistoSig->SetMarkerColor(kBlack);
299 EffHistoFake->SetLineColor(kBlack);
300 EffHistoFake->SetMarkerColor(kBlack);
301 EffHistoSig->Write();
302 EffHistoFake->Write();
303 ResultFile.Close();
304 delete ResultCanvas;
305 delete hBase;
306}

◆ PlotROCCurve()

void PlotROCCurve ( TTree *  SignalTree,
TString  SignalWeightName,
TString  SignalVarName,
TString  SignalVarNameFull,
TTree *  FakeTree,
TString  FakeWeightName,
TString  FakeVarName,
TString  FakeVarNameFull,
TString  PIDVarName 
)
private

a generic function to produce ROC curves

Definition at line 308 of file SVDdEdxValidationAlgorithm.cc.

311{
312
313 if ((SignalTree == nullptr) || (FakeTree == nullptr)) {
314 B2FATAL("Invalid dataset, stopping here");
315 }
316
317 if ((SignalTree->GetEntries() == 0) || (FakeTree->GetEntries() == 0)) {
318 B2FATAL("The dataset is empty, stopping here");
319 }
320
321 if ((SignalTree->GetBranch(Form("%sMomentum", SignalVarName.Data())) == nullptr)
322 || (FakeTree->GetBranch(Form("%sMomentum", FakeVarName.Data())) == nullptr)) {
323 B2FATAL("Check the provided branch name, stopping here");
324 }
325
326 std::vector<TString> PIDDetectors;
327 PIDDetectors.clear();
328 PIDDetectors.push_back("ALL");
329 PIDDetectors.push_back("noSVD");
330
331 std::vector<double> SignalEfficiencyALL, FakeEfficiencyALL;
332 SignalEfficiencyALL.reserve(m_NumROCpoints);
333 FakeEfficiencyALL.reserve(m_NumROCpoints);
334 std::vector<double> SignalEfficiencynoSVD, FakeEfficiencynoSVD;
335 SignalEfficiencynoSVD.reserve(m_NumROCpoints);
336 FakeEfficiencynoSVD.reserve(m_NumROCpoints);
337
338 TString SignalFiducialCut = SignalVarName + PIDVarName + "noSVD>=0"; // sanity cuts to reject events with NaN
339 TString FakesFiducialCut = FakeVarName + PIDVarName + "noSVD>=0";
340
341 // calculate efficiencies
342 for (unsigned int i = 0; i < PIDDetectors.size(); i++) {
343 for (unsigned int j = 0; j < m_NumROCpoints; ++j) {
344 delete gROOT->FindObject("PIDCut");
345 delete gROOT->FindObject("hAllSignal");
346 delete gROOT->FindObject("hSelectedSignal");
347
348 // scan cut values from 0 to 1, with a denser scan closer to 0 or 1, to get a nicer ROC curve
349 double x = 1. / m_NumROCpoints * j;
350 TString PIDCut = TString::Format("%f", 1. / (1 + TMath::Power(x / (1 - x), -3)));
351
352 // TString PIDCut = TString::Format("%f", 0. + 1. / m_NumROCpoints * j);
353
354 SignalTree->Draw(Form("%sMomentum>>hAllSignal(1,%f,%f)", SignalVarName.Data(), m_MomLowROC, m_MomHighROC),
355 SignalWeightName + " * (" + SignalFiducialCut + ")", "goff");
356 SignalTree->Draw(Form("%sMomentum>>hSelectedSignal(1,%f,%f)", SignalVarName.Data(), m_MomLowROC, m_MomHighROC),
357 SignalWeightName + " * (" + SignalVarName + PIDVarName + PIDDetectors[i] + ">" + PIDCut + "&&" + SignalFiducialCut + ")",
358 "goff");
359
360 TH1F* hAllSignal = (TH1F*)gDirectory->Get("hAllSignal");
361 TH1F* hSelectedSignal = (TH1F*)gDirectory->Get("hSelectedSignal");
362
363 if (strncmp(SignalVarName.Data(), "PionD", 5) == 0) {
364 SignalTree->Draw(Form("SlowPionMomentum>>hAllSignalSlow(1,%f,%f)", m_MomLowROC, m_MomHighROC),
365 SignalWeightName + " * (" + SignalFiducialCut + "&& SlowPion" + PIDVarName + "noSVD>=0" + ")", "goff");
366 SignalTree->Draw(Form("SlowPionMomentum>>hSelectedSignalSlow(1,%f,%f)", m_MomLowROC, m_MomHighROC),
367 SignalWeightName + " * (SlowPion" + PIDVarName + PIDDetectors[i] + ">" + PIDCut + "&&" + SignalFiducialCut + "&& SlowPion" +
368 PIDVarName +
369 "noSVD>=0" + ")", "goff");
370 TH1F* hAllSignalSlow = (TH1F*)gDirectory->Get("hAllSignalSlow");
371 TH1F* hSelectedSignalSlow = (TH1F*)gDirectory->Get("hSelectedSignalSlow");
372 hAllSignal->Add(hAllSignalSlow);
373 hSelectedSignal->Add(hSelectedSignalSlow);
374 }
375
376 if (PIDDetectors[i] == "ALL") {
377 SignalEfficiencyALL.push_back(hSelectedSignal->Integral() / hAllSignal->Integral());
378 }
379
380 if (PIDDetectors[i] == "noSVD") {
381 SignalEfficiencynoSVD.push_back(hSelectedSignal->Integral() / hAllSignal->Integral());
382 }
383 }
384 }
385
386 // calculate fake rates
387
388 for (unsigned int i = 0; i < PIDDetectors.size(); i++) {
389 for (unsigned int j = 0; j < m_NumROCpoints; ++j) {
390 delete gROOT->FindObject("PIDCut");
391 delete gROOT->FindObject("hAllFakes");
392 delete gROOT->FindObject("hSelectedFakes");
393
394 // scan cut values from 0 to 1, with a denser scan closer to 0 or 1, to get a nicer ROC curve
395 double x = 1. / m_NumROCpoints * j;
396 TString PIDCut = TString::Format("%f", 1. / (1 + TMath::Power(x / (1 - x), -3)));
397
398 FakeTree->Draw(Form("%sMomentum>>hAllFakes(1,%f,%f)", FakeVarName.Data(), m_MomLowROC, m_MomHighROC),
399 FakeWeightName + " * (" + FakesFiducialCut + ")", "goff");
400 FakeTree->Draw(Form("%sMomentum>>hSelectedFakes(1,%f,%f)", FakeVarName.Data(), m_MomLowROC, m_MomHighROC),
401 FakeWeightName + " * (" + FakeVarName + PIDVarName + PIDDetectors[i] + ">" + PIDCut + "&&" + FakesFiducialCut + ")", "goff");
402
403 TH1F* hSelectedFakes = (TH1F*)gDirectory->Get("hSelectedFakes");
404 TH1F* hAllFakes = (TH1F*)gDirectory->Get("hAllFakes");
405
406 if (strncmp(FakeVarName.Data(), "PionD", 5) == 0) {
407 FakeTree->Draw(Form("SlowPionMomentum>>hAllFakesSlow(1,%f,%f)", m_MomLowROC, m_MomHighROC),
408 FakeWeightName + " * (" + FakesFiducialCut + "&& SlowPion" + PIDVarName + "noSVD>=0" + ")", "goff");
409 FakeTree->Draw(Form("SlowPionMomentum>>hSelectedFakesSlow(1,%f,%f)", m_MomLowROC, m_MomHighROC),
410 FakeWeightName + " * (SlowPion" + PIDVarName + PIDDetectors[i] + ">" + PIDCut + "&&" + FakesFiducialCut + "&& SlowPion" + PIDVarName
411 +
412 "noSVD>=0" + ")", "goff");
413 TH1F* hAllFakesSlow = (TH1F*)gDirectory->Get("hAllFakesSlow");
414 TH1F* hSelectedFakesSlow = (TH1F*)gDirectory->Get("hSelectedFakesSlow");
415 hAllFakes->Add(hAllFakesSlow);
416 hSelectedFakes->Add(hSelectedFakesSlow);
417 }
418
419 if (PIDDetectors[i] == "ALL") {
420 FakeEfficiencyALL.push_back(hSelectedFakes->Integral() / hAllFakes->Integral());
421 }
422
423 if (PIDDetectors[i] == "noSVD") {
424 FakeEfficiencynoSVD.push_back(hSelectedFakes->Integral() / hAllFakes->Integral());
425 }
426 }
427 }
428
429 auto ResultCanvas = new TCanvas("ResultCanvas", "", 600, 400);
430 TMultiGraph* hmgraph = new TMultiGraph();
431
432 // efficiency and kaon fake rate
433 TGraph* hgraphALL = new TGraph(m_NumROCpoints, FakeEfficiencyALL.data(), SignalEfficiencyALL.data());
434 hgraphALL->SetMarkerColor(TColor::GetColor("#2166ac"));
435 hgraphALL->SetMarkerStyle(20);
436 hgraphALL->SetLineColor(TColor::GetColor("#2166ac"));
437 hgraphALL->SetLineWidth(3);
438 hgraphALL->SetDrawOption("AP*");
439 hgraphALL->SetTitle("with SVD");
440
441 TGraph* hgraphnoSVD = new TGraph(m_NumROCpoints, FakeEfficiencynoSVD.data(), SignalEfficiencynoSVD.data());
442 hgraphnoSVD->SetMarkerColor(TColor::GetColor("#ef8a62"));
443 hgraphnoSVD->SetLineColor(TColor::GetColor("#ef8a62"));
444 hgraphnoSVD->SetLineWidth(3);
445 hgraphnoSVD->SetMarkerStyle(22);
446 hgraphnoSVD->SetDrawOption("P*");
447 hgraphnoSVD->SetTitle("without SVD");
448
449 hmgraph->Add(hgraphALL);
450 hmgraph->Add(hgraphnoSVD);
451 hmgraph->Draw("A");
452 hmgraph->GetHistogram()->GetXaxis()->SetTitle(FakeVarNameFull + " fake rate");
453 hmgraph->GetHistogram()->GetYaxis()->SetTitle(SignalVarNameFull + " signal efficiency");
454
455 ResultCanvas->BuildLegend(0.6, 0.25, 0.9, 0.5);
456 ResultCanvas->SetGrid();
457
458 ResultCanvas->Print("SVDdEdxValidation_ROC_curve_" + SignalVarNameFull + "_vs_" + FakeVarNameFull + PIDVarName + "_MomRange" +
459 std::to_string(m_MomLowROC).substr(0, 3) + "_" + std::to_string(m_MomHighROC).substr(0, 3) + ".pdf");
460
461 TFile ResultFile("SVDdEdxValidation_ROC_curve_" + SignalVarNameFull + "_vs_" + FakeVarNameFull + PIDVarName + "_MomRange" +
462 std::to_string(m_MomLowROC).substr(0, 3) + "_" + std::to_string(m_MomHighROC).substr(0, 3) + ".root", "RECREATE");
463 hmgraph->Write();
464 ResultFile.Close();
465
466 delete ResultCanvas;
467}
double m_MomLowROC
lower edge of the momentum interval considered for the ROC curve
double m_MomHighROC
upper edge of the momentum interval considered for the ROC curve
unsigned int m_NumROCpoints
number of points for the ROC curve plotting

◆ resetInputJson()

void resetInputJson ( )
inlineprotectedinherited

Clears the m_inputJson member variable.

Definition at line 330 of file CalibrationAlgorithm.h.

330{m_jsonExecutionInput.clear();}

◆ resetOutputJson()

void resetOutputJson ( )
inlineprotectedinherited

Clears the m_outputJson member variable.

Definition at line 333 of file CalibrationAlgorithm.h.

333{m_jsonExecutionOutput.clear();}

◆ saveCalibration() [1/6]

void saveCalibration ( TClonesArray *  data,
const std::string &  name 
)
protectedinherited

Store DBArray payload with given name with default IOV.

Definition at line 297 of file CalibrationAlgorithm.cc.

298{
300}
const IntervalOfValidity & getRequestedIov() const
Getter for requested IOV.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.

◆ saveCalibration() [2/6]

void saveCalibration ( TClonesArray *  data,
const std::string &  name,
const IntervalOfValidity iov 
)
protectedinherited

Store DBArray with given name and custom IOV.

Definition at line 276 of file CalibrationAlgorithm.cc.

277{
278 B2DEBUG(29, "Saving calibration TClonesArray '" << name << "' to payloads list.");
279 getPayloads().emplace_back(name, data, iov);
280}

◆ saveCalibration() [3/6]

void saveCalibration ( TObject *  data)
protectedinherited

Store DB payload with default name and default IOV.

Definition at line 287 of file CalibrationAlgorithm.cc.

288{
289 saveCalibration(data, DataStore::objectName(data->IsA(), ""));
290}
static std::string objectName(const TClass *t, const std::string &name)
Return the storage name for an object of the given TClass and name.
Definition: DataStore.cc:151

◆ saveCalibration() [4/6]

void saveCalibration ( TObject *  data,
const IntervalOfValidity iov 
)
protectedinherited

Store DB payload with default name and custom IOV.

Definition at line 282 of file CalibrationAlgorithm.cc.

283{
284 saveCalibration(data, DataStore::objectName(data->IsA(), ""), iov);
285}

◆ saveCalibration() [5/6]

void saveCalibration ( TObject *  data,
const std::string &  name 
)
protectedinherited

Store DB payload with given name with default IOV.

Definition at line 292 of file CalibrationAlgorithm.cc.

293{
295}

◆ saveCalibration() [6/6]

void saveCalibration ( TObject *  data,
const std::string &  name,
const IntervalOfValidity iov 
)
protectedinherited

Store DB payload with given name and custom IOV.

Definition at line 270 of file CalibrationAlgorithm.cc.

271{
272 B2DEBUG(29, "Saving calibration TObject = '" << name << "' to payloads list.");
273 getPayloads().emplace_back(name, data, iov);
274}

◆ setDescription()

void setDescription ( const std::string &  description)
inlineprotectedinherited

Set algorithm description (in constructor)

Definition at line 321 of file CalibrationAlgorithm.h.

321{m_description = description;}

◆ setInputFileNames() [1/2]

void setInputFileNames ( PyObject *  inputFileNames)
inherited

Set the input file names used for this algorithm from a Python list.

Set the input file names used for this algorithm and resolve the wildcards.

Definition at line 166 of file CalibrationAlgorithm.cc.

167{
168 // The reasoning for this very 'manual' approach to extending the Python interface
169 // (instead of using boost::python) is down to my fear of putting off final users with
170 // complexity on their side.
171 //
172 // I didn't want users that inherit from this class to be forced to use boost and
173 // to have to define a new python module just to use the CAF. A derived class from
174 // from a boost exposed class would need to have its own boost python module definition
175 // to allow access from a steering file and to the base class functions (I think).
176 // I also couldn't be bothered to write a full framework to get around the issue in a similar
177 // way to Module()...maybe there's an easy way.
178 //
179 // But this way we can allow people to continue using their ROOT implemented classes and inherit
180 // easily from this one. But add in a few helper functions that work with Python objects
181 // created in their steering file i.e. instead of being forced to use STL objects as input
182 // to the algorithm.
183 if (PyList_Check(inputFileNames)) {
184 boost::python::handle<> handle(boost::python::borrowed(inputFileNames));
185 boost::python::list listInputFileNames(handle);
186 auto vecInputFileNames = PyObjConvUtils::convertPythonObject(listInputFileNames, vector<string>());
187 setInputFileNames(vecInputFileNames);
188 } else {
189 B2ERROR("Tried to set the input files but we didn't receive a Python list.");
190 }
191}
void setInputFileNames(PyObject *inputFileNames)
Set the input file names used for this algorithm from a Python list.
Scalar convertPythonObject(const boost::python::object &pyObject, Scalar)
Convert from Python to given type.

◆ setInputFileNames() [2/2]

void setInputFileNames ( std::vector< std::string >  inputFileNames)
protectedinherited

Set the input file names used for this algorithm.

Set the input file names used for this algorithm and resolve the wildcards.

Definition at line 194 of file CalibrationAlgorithm.cc.

195{
196 // A lot of code below is tweaked from RootInputModule::initialize,
197 // since we're basically copying the functionality anyway.
198 if (inputFileNames.empty()) {
199 B2WARNING("You have called setInputFileNames() with an empty list. Did you mean to do that?");
200 return;
201 }
202 auto tmpInputFileNames = RootIOUtilities::expandWordExpansions(inputFileNames);
203
204 // We'll use a set to enforce sorted unique file paths as we check them
205 set<string> setInputFileNames;
206 // Check that files exist and convert to absolute paths
207 for (auto path : tmpInputFileNames) {
208 string fullPath = fs::absolute(path).string();
209 if (fs::exists(fullPath)) {
210 setInputFileNames.insert(fs::canonical(fullPath).string());
211 } else {
212 B2WARNING("Couldn't find the file " << path);
213 }
214 }
215
216 if (setInputFileNames.empty()) {
217 B2WARNING("No valid files specified!");
218 return;
219 } else {
220 // Reset the run -> files map as our files are likely different
221 m_runsToInputFiles.clear();
222 }
223
224 // Open TFile to check they can be accessed by ROOT
225 TDirectory* dir = gDirectory;
226 for (const string& fileName : setInputFileNames) {
227 unique_ptr<TFile> f;
228 try {
229 f.reset(TFile::Open(fileName.c_str(), "READ"));
230 } catch (logic_error&) {
231 //this might happen for ~invaliduser/foo.root
232 //actually undefined behaviour per standard, reported as ROOT-8490 in JIRA
233 }
234 if (!f || !f->IsOpen()) {
235 B2FATAL("Couldn't open input file " + fileName);
236 }
237 }
238 dir->cd();
239
240 // Copy the entries of the set to a vector
241 m_inputFileNames = vector<string>(setInputFileNames.begin(), setInputFileNames.end());
243}
std::string getGranularityFromData() const
Get the granularity of collected data.
std::vector< std::string > expandWordExpansions(const std::vector< std::string > &filenames)
Performs wildcard expansion using wordexp(), returns matches.

◆ setMaxEffMomentum()

void setMaxEffMomentum ( const double &  value)
inline

set the upper edge of the momentum range for the efficiency scan

Definition at line 65 of file SVDdEdxValidationAlgorithm.h.

65{ m_MomHighEff = value; }

◆ setMaxROCMomentum()

void setMaxROCMomentum ( const double &  value)
inline

set the lower edge of the momentum range for ROC curve plotting

Definition at line 55 of file SVDdEdxValidationAlgorithm.h.

55{ m_MomHighROC = value; }

◆ setMinEvtsPerTree()

void setMinEvtsPerTree ( const double &  value)
inline

set the upper edge of the dEdx binning for the payloads

Definition at line 70 of file SVDdEdxValidationAlgorithm.h.

70{ m_MinEvtsPerTree = value; }

◆ setMinROCMomentum()

void setMinROCMomentum ( const double &  value)
inline

set the lower edge of the momentum range for ROC curve plotting

Definition at line 50 of file SVDdEdxValidationAlgorithm.h.

50{ m_MomLowROC = value; }

◆ setMonitoringPlots()

void setMonitoringPlots ( bool  value = false)
inline

function to enable plotting

Definition at line 40 of file SVDdEdxValidationAlgorithm.h.

40{ m_isMakePlots = value; }

◆ setNumEffBins()

void setNumEffBins ( const unsigned int &  value)
inline

set the number of bins for the efficiency scan

Definition at line 60 of file SVDdEdxValidationAlgorithm.h.

60{ m_NumEffBins = value; }

◆ setNumROCpoints()

void setNumROCpoints ( const unsigned int &  value)
inline

set the number of points for ROC curve plotting

Definition at line 45 of file SVDdEdxValidationAlgorithm.h.

45{ m_NumROCpoints = value; }

◆ setOutputJsonValue()

void setOutputJsonValue ( const std::string &  key,
const T &  value 
)
inlineprotectedinherited

Set a key:value pair for the outputJson object, expected to used interally during calibrate()

Definition at line 337 of file CalibrationAlgorithm.h.

337{m_jsonExecutionOutput[key] = value;}

◆ setPrefix()

void setPrefix ( const std::string &  prefix)
inlineinherited

Set the prefix used to identify datastore objects.

Definition at line 167 of file CalibrationAlgorithm.h.

167{m_prefix = prefix;}

◆ updateDBObjPtrs()

void updateDBObjPtrs ( const unsigned int  event = 1,
const int  run = 0,
const int  experiment = 0 
)
protectedinherited

Updates any DBObjPtrs by calling update(event) for DBStore.

Definition at line 404 of file CalibrationAlgorithm.cc.

405{
406 // Construct an EventMetaData object but NOT in the Datastore
407 EventMetaData emd(event, run, experiment);
408 // Explicitly update while avoiding registering a Datastore object
410 // Also update the intra-run objects to the event at the same time (maybe unnessary...)
412}
Store event, run, and experiment numbers.
Definition: EventMetaData.h:33
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:28
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:142
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:79

Member Data Documentation

◆ m_allExpRun

const ExpRun m_allExpRun = make_pair(-1, -1)
staticprivateinherited

allExpRun

Definition at line 364 of file CalibrationAlgorithm.h.

◆ m_boundaries

std::vector<Calibration::ExpRun> m_boundaries
protectedinherited

When using the boundaries functionality from isBoundaryRequired, this is used to store the boundaries. It is cleared when.

Definition at line 261 of file CalibrationAlgorithm.h.

◆ m_data

ExecutionData m_data
privateinherited

Data specific to a SINGLE execution of the algorithm. Gets reset at the beginning of execution.

Definition at line 382 of file CalibrationAlgorithm.h.

◆ m_description

std::string m_description {""}
privateinherited

Description of the algorithm.

Definition at line 385 of file CalibrationAlgorithm.h.

◆ m_granularityOfData

std::string m_granularityOfData
privateinherited

Granularity of input data. This only changes when the input files change so it isn't specific to an execution.

Definition at line 379 of file CalibrationAlgorithm.h.

◆ m_inputFileNames

std::vector<std::string> m_inputFileNames
privateinherited

List of input files to the Algorithm, will initially be user defined but then gets the wildcards expanded during execute()

Definition at line 373 of file CalibrationAlgorithm.h.

◆ m_isMakePlots

bool m_isMakePlots
private

produce plots for monitoring of the fit quality

Definition at line 79 of file SVDdEdxValidationAlgorithm.h.

◆ m_jsonExecutionInput

nlohmann::json m_jsonExecutionInput = nlohmann::json::object()
privateinherited

Optional input JSON object used to make decisions about how to execute the algorithm code.

Definition at line 397 of file CalibrationAlgorithm.h.

◆ m_jsonExecutionOutput

nlohmann::json m_jsonExecutionOutput = nlohmann::json::object()
privateinherited

Optional output JSON object that can be set during the execution by the underlying algorithm code.

Definition at line 403 of file CalibrationAlgorithm.h.

◆ m_MinEvtsPerTree

int m_MinEvtsPerTree = 100
private

number of events in TTree below which we don't try to fit

Definition at line 96 of file SVDdEdxValidationAlgorithm.h.

◆ m_MomHighEff

double m_MomHighEff = 2.5
private

upper edge of the momentum interval for the efficiency/fake rate plot

Definition at line 101 of file SVDdEdxValidationAlgorithm.h.

◆ m_MomHighROC

double m_MomHighROC = 7.
private

upper edge of the momentum interval considered for the ROC curve

Definition at line 99 of file SVDdEdxValidationAlgorithm.h.

◆ m_MomLowROC

double m_MomLowROC = 0.
private

lower edge of the momentum interval considered for the ROC curve

Definition at line 98 of file SVDdEdxValidationAlgorithm.h.

◆ m_NumEffBins

unsigned int m_NumEffBins = 30
private

number of bins for the efficiency/fake rate plot

Definition at line 100 of file SVDdEdxValidationAlgorithm.h.

◆ m_NumROCpoints

unsigned int m_NumROCpoints = 250
private

number of points for the ROC curve plotting

Definition at line 97 of file SVDdEdxValidationAlgorithm.h.

◆ m_prefix

std::string m_prefix {""}
privateinherited

The name of the TDirectory the collector objects are contained within.

Definition at line 388 of file CalibrationAlgorithm.h.

◆ m_runsToInputFiles

std::map<Calibration::ExpRun, std::vector<std::string> > m_runsToInputFiles
privateinherited

Map of Runs to input files. Gets filled when you call getRunRangeFromAllData, gets cleared when setting input files again.

Definition at line 376 of file CalibrationAlgorithm.h.


The documentation for this class was generated from the following files: