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 validationMode (bool value=false)
 decide between full or basic validation mode.
 
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 algorithm (set by developers in constructor)
 
bool loadInputJson (const std::string &jsonString)
 Load the m_inputJson variable from a string (useful from Python interface). The return 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 internally 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_fullValidation
 decide between full or basic validation mode.
 
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 successfully =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 successfully =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 47 of file SVDdEdxValidationAlgorithm.cc.

47 : CalibrationAlgorithm("SVDdEdxValidationCollector"),
48 m_isMakePlots(true)
49{
50 setDescription("SVD dE/dx validation algorithm");
51}
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 54 of file SVDdEdxValidationAlgorithm.cc.

55{
56 gROOT->SetBatch(true);
57
58 // const auto exprun = getRunList()[0];
59 // B2INFO("ExpRun used for calibration: " << exprun.first << " " << exprun.second);
60
61 // Get data objects
62 auto TTreeLambda = getObjectPtr<TTree>("Lambda");
63 auto TTreeDstar = getObjectPtr<TTree>("Dstar");
64 auto TTreeGamma = getObjectPtr<TTree>("Gamma");
65
66 if (TTreeLambda->GetEntries() < m_MinEvtsPerTree) {
67 B2WARNING("Not enough data for calibration.");
68 return c_NotEnoughData;
69 }
70
71 // call the calibration functions
72 TTree* TTreeLambdaSW = LambdaMassFit(TTreeLambda);
73 TTree* TTreeDstarSW = DstarMassFit(TTreeDstar);
74 TTree* TTreeGammaWrap = TTreeGamma.get();
75
76 std::vector<TString> PIDDetectors;
77 PIDDetectors.push_back("SVDonly");
78 if (m_fullValidation) {
79 PIDDetectors.push_back("ALL");
80 PIDDetectors.push_back("noSVD");
81 }
82
83 std::map<TTree*, TString> SWeightNameMap = {
84 {TTreeGammaWrap, "1"},
85 {TTreeDstarSW, "nSignalDstar_sw"},
86 {TTreeLambdaSW, "nSignalLambda_sw"}
87 };
88
89 for (const TString& PIDDetectorsName : PIDDetectors) {
90 PlotEfficiencyPlots(PIDDetectorsName, TTreeGammaWrap, SWeightNameMap[TTreeGammaWrap], "FirstElectron", "electron", TTreeDstarSW,
91 SWeightNameMap[TTreeDstarSW], "PionD", "pion",
92 "BinaryElectronPionID",
93 "0.5", m_NumEffBins, 0., m_MomHighEff);
94 PlotEfficiencyPlots(PIDDetectorsName, TTreeGammaWrap, SWeightNameMap[TTreeGammaWrap], "FirstElectron", "electron", TTreeDstarSW,
95 SWeightNameMap[TTreeDstarSW], "Kaon", "kaon",
96 "BinaryElectronKaonID", "0.5",
98 PlotEfficiencyPlots(PIDDetectorsName, TTreeLambdaSW, SWeightNameMap[TTreeLambdaSW], "Proton", "proton", TTreeDstarSW,
99 SWeightNameMap[TTreeDstarSW], "PionD", "pion",
100 "BinaryProtonPionID", "0.5",
102 PlotEfficiencyPlots(PIDDetectorsName, TTreeLambdaSW, SWeightNameMap[TTreeLambdaSW], "Proton", "proton", TTreeDstarSW,
103 SWeightNameMap[TTreeDstarSW], "Kaon", "kaon",
104 "BinaryProtonKaonID", "0.5",
106 PlotEfficiencyPlots(PIDDetectorsName, TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "PionD", "pion", TTreeDstarSW,
107 SWeightNameMap[TTreeDstarSW],
108 "Kaon", "kaon",
109 "BinaryPionKaonID", "0.5", m_NumEffBins,
110 0., m_MomHighEff);
111 PlotEfficiencyPlots(PIDDetectorsName, TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "Kaon", "kaon", TTreeDstarSW,
112 SWeightNameMap[TTreeDstarSW],
113 "PionD", "pion",
114 "BinaryKaonPionID", "0.5", m_NumEffBins,
115 0., m_MomHighEff);
116 }
117
118 if (m_fullValidation) {
119 PlotROCCurve(TTreeGammaWrap, SWeightNameMap[TTreeGammaWrap], "FirstElectron", "electron", TTreeDstarSW,
120 SWeightNameMap[TTreeDstarSW], "PionD",
121 "pion", "BinaryElectronPionID");
122 PlotROCCurve(TTreeGammaWrap, SWeightNameMap[TTreeGammaWrap], "FirstElectron", "electron", TTreeDstarSW,
123 SWeightNameMap[TTreeDstarSW], "Kaon",
124 "kaon", "BinaryElectronKaonID");
125 PlotROCCurve(TTreeLambdaSW, SWeightNameMap[TTreeLambdaSW], "Proton", "proton", TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "PionD",
126 "pion",
127 "BinaryProtonPionID");
128 PlotROCCurve(TTreeLambdaSW, SWeightNameMap[TTreeLambdaSW], "Proton", "proton", TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "Kaon",
129 "kaon",
130 "BinaryProtonKaonID");
131 PlotROCCurve(TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "PionD", "pion", TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "Kaon",
132 "kaon",
133 "BinaryPionKaonID");
134 PlotROCCurve(TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "Kaon", "kaon", TTreeDstarSW, SWeightNameMap[TTreeDstarSW], "PionD",
135 "pion",
136 "BinaryKaonPionID");
137 }
138 B2INFO("SVD dE/dx validation done!");
139
140 return c_OK;
141}
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
bool m_fullValidation
decide between full or basic validation mode.
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 922 of file SVDdEdxValidationAlgorithm.cc.

923{
924 B2INFO("Configuring the Dstar fit...");
925 gROOT->SetBatch(true);
926 RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING);
927
928 RooRealVar deltaM("deltaM", "m(D*)-m(D^{0})", 0.139545, 0.151, "GeV/c^{2}");
929
930 RooRealVar KaonMomentum("KaonMomentum", "momentum for Kaon(GeV)", -1.e8, 1.e8);
931 RooRealVar KaonSVDdEdx("KaonSVDdEdx", "", -1.e8, 1.e8);
932 RooRealVar PionDMomentum("PionDMomentum", "momentum for pion(GeV)", -1.e8, 1.e8);
933 RooRealVar PionDSVDdEdx("PionDSVDdEdx", "", -1.e8, 1.e8);
934 RooRealVar SlowPionMomentum("SlowPionMomentum", "momentum for slow pion(GeV)", -1.e8, 1.e8);
935 RooRealVar SlowPionSVDdEdx("SlowPionSVDdEdx", "", -1.e8, 1.e8);
936
937 RooRealVar exp("exp", "experiment number", 0, 1.e5);
938 RooRealVar run("run", "run number", 0, 1.e8);
939
940 RooRealVar KaonKaonIDALL("KaonKaonIDALL", "", -1.e8, 1.e8);
941 RooRealVar KaonKaonIDSVDonly("KaonKaonIDSVDonly", "", -1.e8, 1.e8);
942 RooRealVar KaonKaonIDnoSVD("KaonKaonIDnoSVD", "", -1.e8, 1.e8);
943
944 RooRealVar KaonPionIDALL("KaonPionIDALL", "", -1.e8, 1.e8);
945 RooRealVar KaonPionIDSVDonly("KaonPionIDSVDonly", "", -1.e8, 1.e8);
946 RooRealVar KaonPionIDnoSVD("KaonPionIDnoSVD", "", -1.e8, 1.e8);
947
948 RooRealVar KaonProtonIDALL("KaonProtonIDALL", "", -1.e8, 1.e8);
949 RooRealVar KaonProtonIDSVDonly("KaonProtonIDSVDonly", "", -1.e8, 1.e8);
950 RooRealVar KaonProtonIDnoSVD("KaonProtonIDnoSVD", "", -1.e8, 1.e8);
951
952 RooRealVar KaonElectronIDALL("KaonElectronIDALL", "", -1.e8, 1.e8);
953 RooRealVar KaonElectronIDSVDonly("KaonElectronIDSVDonly", "", -1.e8, 1.e8);
954 RooRealVar KaonElectronIDnoSVD("KaonElectronIDnoSVD", "", -1.e8, 1.e8);
955
956 RooRealVar KaonElectronLLSVDonly("KaonElectronLLSVDonly", "", -1.e8, 1.e8);
957 RooRealVar KaonPionLLSVDonly("KaonPionLLSVDonly", "", -1.e8, 1.e8);
958 RooRealVar KaonKaonLLSVDonly("KaonKaonLLSVDonly", "", -1.e8, 1.e8);
959 RooRealVar KaonProtonLLSVDonly("KaonProtonLLSVDonly", "", -1.e8, 1.e8);
960
961 RooRealVar KaonBinaryKaonPionIDALL("KaonBinaryKaonPionIDALL", "", -1.e8, 1.e8);
962 RooRealVar KaonBinaryKaonPionIDSVDonly("KaonBinaryKaonPionIDSVDonly", "", -1.e8, 1.e8);
963 RooRealVar KaonBinaryKaonPionIDnoSVD("KaonBinaryKaonPionIDnoSVD", "", -1.e8, 1.e8);
964
965 RooRealVar KaonBinaryPionKaonIDALL("KaonBinaryPionKaonIDALL", "", -1.e8, 1.e8);
966 RooRealVar KaonBinaryPionKaonIDSVDonly("KaonBinaryPionKaonIDSVDonly", "", -1.e8, 1.e8);
967 RooRealVar KaonBinaryPionKaonIDnoSVD("KaonBinaryPionKaonIDnoSVD", "", -1.e8, 1.e8);
968
969 RooRealVar KaonBinaryProtonKaonIDALL("KaonBinaryProtonKaonIDALL", "", -1.e8, 1.e8);
970 RooRealVar KaonBinaryProtonKaonIDSVDonly("KaonBinaryProtonKaonIDSVDonly", "", -1.e8, 1.e8);
971 RooRealVar KaonBinaryProtonKaonIDnoSVD("KaonBinaryProtonKaonIDnoSVD", "", -1.e8, 1.e8);
972
973 RooRealVar KaonBinaryElectronKaonIDALL("KaonBinaryElectronKaonIDALL", "", -1.e8, 1.e8);
974 RooRealVar KaonBinaryElectronKaonIDSVDonly("KaonBinaryElectronKaonIDSVDonly", "", -1.e8, 1.e8);
975 RooRealVar KaonBinaryElectronKaonIDnoSVD("KaonBinaryElectronKaonIDnoSVD", "", -1.e8, 1.e8);
976
977 RooRealVar PionDKaonIDALL("PionDKaonIDALL", "", -1.e8, 1.e8);
978 RooRealVar PionDKaonIDSVDonly("PionDKaonIDSVDonly", "", -1.e8, 1.e8);
979 RooRealVar PionDKaonIDnoSVD("PionDKaonIDnoSVD", "", -1.e8, 1.e8);
980
981 RooRealVar PionDPionIDALL("PionDPionIDALL", "", -1.e8, 1.e8);
982 RooRealVar PionDPionIDSVDonly("PionDPionIDSVDonly", "", -1.e8, 1.e8);
983 RooRealVar PionDPionIDnoSVD("PionDPionIDnoSVD", "", -1.e8, 1.e8);
984
985 RooRealVar PionDElectronIDALL("PionDElectronIDALL", "", -1.e8, 1.e8);
986 RooRealVar PionDElectronIDSVDonly("PionDElectronIDSVDonly", "", -1.e8, 1.e8);
987 RooRealVar PionDElectronIDnoSVD("PionDElectronIDnoSVD", "", -1.e8, 1.e8);
988
989 RooRealVar PionDProtonIDALL("PionDProtonIDALL", "", -1.e8, 1.e8);
990 RooRealVar PionDProtonIDSVDonly("PionDProtonIDSVDonly", "", -1.e8, 1.e8);
991 RooRealVar PionDProtonIDnoSVD("PionDProtonIDnoSVD", "", -1.e8, 1.e8);
992
993 RooRealVar PionDElectronLLSVDonly("PionDElectronLLSVDonly", "", -1.e8, 1.e8);
994 RooRealVar PionDPionLLSVDonly("PionDPionLLSVDonly", "", -1.e8, 1.e8);
995 RooRealVar PionDKaonLLSVDonly("PionDKaonLLSVDonly", "", -1.e8, 1.e8);
996 RooRealVar PionDProtonLLSVDonly("PionDProtonLLSVDonly", "", -1.e8, 1.e8);
997
998 RooRealVar PionDBinaryPionKaonIDALL("PionDBinaryPionKaonIDALL", "", -1.e8, 1.e8);
999 RooRealVar PionDBinaryPionKaonIDSVDonly("PionDBinaryPionKaonIDSVDonly", "", -1.e8, 1.e8);
1000 RooRealVar PionDBinaryPionKaonIDnoSVD("PionDBinaryPionKaonIDnoSVD", "", -1.e8, 1.e8);
1001
1002 RooRealVar PionDBinaryKaonPionIDALL("PionDBinaryKaonPionIDALL", "", -1.e8, 1.e8);
1003 RooRealVar PionDBinaryKaonPionIDSVDonly("PionDBinaryKaonPionIDSVDonly", "", -1.e8, 1.e8);
1004 RooRealVar PionDBinaryKaonPionIDnoSVD("PionDBinaryKaonPionIDnoSVD", "", -1.e8, 1.e8);
1005
1006 RooRealVar PionDBinaryProtonPionIDALL("PionDBinaryProtonPionIDALL", "", -1.e8, 1.e8);
1007 RooRealVar PionDBinaryProtonPionIDSVDonly("PionDBinaryProtonPionIDSVDonly", "", -1.e8, 1.e8);
1008 RooRealVar PionDBinaryProtonPionIDnoSVD("PionDBinaryProtonPionIDnoSVD", "", -1.e8, 1.e8);
1009
1010 RooRealVar PionDBinaryElectronPionIDALL("PionDBinaryElectronPionIDALL", "", -1.e8, 1.e8);
1011 RooRealVar PionDBinaryElectronPionIDSVDonly("PionDBinaryElectronPionIDSVDonly", "", -1.e8, 1.e8);
1012 RooRealVar PionDBinaryElectronPionIDnoSVD("PionDBinaryElectronPionIDnoSVD", "", -1.e8, 1.e8);
1013
1014 RooRealVar SlowPionKaonIDALL("SlowPionKaonIDALL", "", -1.e8, 1.e8);
1015 RooRealVar SlowPionKaonIDSVDonly("SlowPionKaonIDSVDonly", "", -1.e8, 1.e8);
1016 RooRealVar SlowPionKaonIDnoSVD("SlowPionKaonIDnoSVD", "", -1.e8, 1.e8);
1017
1018 RooRealVar SlowPionPionIDALL("SlowPionPionIDALL", "", -1.e8, 1.e8);
1019 RooRealVar SlowPionPionIDSVDonly("SlowPionPionIDSVDonly", "", -1.e8, 1.e8);
1020 RooRealVar SlowPionPionIDnoSVD("SlowPionPionIDnoSVD", "", -1.e8, 1.e8);
1021
1022 RooRealVar SlowPionElectronIDALL("SlowPionElectronIDALL", "", -1.e8, 1.e8);
1023 RooRealVar SlowPionElectronIDSVDonly("SlowPionElectronIDSVDonly", "", -1.e8, 1.e8);
1024 RooRealVar SlowPionElectronIDnoSVD("SlowPionElectronIDnoSVD", "", -1.e8, 1.e8);
1025
1026 RooRealVar SlowPionProtonIDALL("SlowPionProtonIDALL", "", -1.e8, 1.e8);
1027 RooRealVar SlowPionProtonIDSVDonly("SlowPionProtonIDSVDonly", "", -1.e8, 1.e8);
1028 RooRealVar SlowPionProtonIDnoSVD("SlowPionProtonIDnoSVD", "", -1.e8, 1.e8);
1029
1030 RooRealVar SlowPionElectronLLSVDonly("SlowPionElectronLLSVDonly", "", -1.e8, 1.e8);
1031 RooRealVar SlowPionPionLLSVDonly("SlowPionPionLLSVDonly", "", -1.e8, 1.e8);
1032 RooRealVar SlowPionKaonLLSVDonly("SlowPionKaonLLSVDonly", "", -1.e8, 1.e8);
1033 RooRealVar SlowPionProtonLLSVDonly("SlowPionProtonLLSVDonly", "", -1.e8, 1.e8);
1034
1035 RooRealVar SlowPionBinaryPionKaonIDALL("SlowPionBinaryPionKaonIDALL", "", -1.e8, 1.e8);
1036 RooRealVar SlowPionBinaryPionKaonIDSVDonly("SlowPionBinaryPionKaonIDSVDonly", "", -1.e8, 1.e8);
1037 RooRealVar SlowPionBinaryPionKaonIDnoSVD("SlowPionBinaryPionKaonIDnoSVD", "", -1.e8, 1.e8);
1038
1039 RooRealVar SlowPionBinaryKaonPionIDALL("SlowPionBinaryKaonPionIDALL", "", -1.e8, 1.e8);
1040 RooRealVar SlowPionBinaryKaonPionIDSVDonly("SlowPionBinaryKaonPionIDSVDonly", "", -1.e8, 1.e8);
1041 RooRealVar SlowPionBinaryKaonPionIDnoSVD("SlowPionBinaryKaonPionIDnoSVD", "", -1.e8, 1.e8);
1042
1043 RooRealVar SlowPionBinaryProtonPionIDALL("SlowPionBinaryProtonPionIDALL", "", -1.e8, 1.e8);
1044 RooRealVar SlowPionBinaryProtonPionIDSVDonly("SlowPionBinaryProtonPionIDSVDonly", "", -1.e8, 1.e8);
1045 RooRealVar SlowPionBinaryProtonPionIDnoSVD("SlowPionBinaryProtonPionIDnoSVD", "", -1.e8, 1.e8);
1046
1047 RooRealVar SlowPionBinaryElectronPionIDALL("SlowPionBinaryElectronPionIDALL", "", -1.e8, 1.e8);
1048 RooRealVar SlowPionBinaryElectronPionIDSVDonly("SlowPionBinaryElectronPionIDSVDonly", "", -1.e8, 1.e8);
1049 RooRealVar SlowPionBinaryElectronPionIDnoSVD("SlowPionBinaryElectronPionIDnoSVD", "", -1.e8, 1.e8);
1050
1051 auto variables = new RooArgSet();
1052 variables->add(deltaM);
1053 variables->add(KaonMomentum);
1054 variables->add(KaonSVDdEdx);
1055 variables->add(PionDMomentum);
1056 variables->add(PionDSVDdEdx);
1057 variables->add(SlowPionMomentum);
1058 variables->add(SlowPionSVDdEdx);
1059 variables->add(exp);
1060 variables->add(run);
1061
1062 variables->add(KaonKaonIDALL);
1063 variables->add(KaonKaonIDSVDonly);
1064 variables->add(KaonKaonIDnoSVD);
1065 variables->add(KaonPionIDALL);
1066 variables->add(KaonPionIDSVDonly);
1067 variables->add(KaonPionIDnoSVD);
1068 variables->add(KaonProtonIDALL);
1069 variables->add(KaonProtonIDSVDonly);
1070 variables->add(KaonProtonIDnoSVD);
1071 variables->add(KaonElectronIDALL);
1072 variables->add(KaonElectronIDSVDonly);
1073 variables->add(KaonElectronIDnoSVD);
1074
1075 variables->add(KaonElectronLLSVDonly);
1076 variables->add(KaonPionLLSVDonly);
1077 variables->add(KaonKaonLLSVDonly);
1078 variables->add(KaonProtonLLSVDonly);
1079
1080 variables->add(KaonBinaryKaonPionIDALL);
1081 variables->add(KaonBinaryKaonPionIDSVDonly);
1082 variables->add(KaonBinaryKaonPionIDnoSVD);
1083 variables->add(KaonBinaryPionKaonIDALL);
1084 variables->add(KaonBinaryPionKaonIDSVDonly);
1085 variables->add(KaonBinaryPionKaonIDnoSVD);
1086 variables->add(KaonBinaryProtonKaonIDALL);
1087 variables->add(KaonBinaryProtonKaonIDSVDonly);
1088 variables->add(KaonBinaryProtonKaonIDnoSVD);
1089 variables->add(KaonBinaryElectronKaonIDALL);
1090 variables->add(KaonBinaryElectronKaonIDSVDonly);
1091 variables->add(KaonBinaryElectronKaonIDnoSVD);
1092
1093 variables->add(PionDPionIDALL);
1094 variables->add(PionDPionIDSVDonly);
1095 variables->add(PionDPionIDnoSVD);
1096 variables->add(PionDKaonIDALL);
1097 variables->add(PionDKaonIDSVDonly);
1098 variables->add(PionDKaonIDnoSVD);
1099 variables->add(PionDElectronIDALL);
1100 variables->add(PionDElectronIDSVDonly);
1101 variables->add(PionDElectronIDnoSVD);
1102 variables->add(PionDProtonIDALL);
1103 variables->add(PionDProtonIDSVDonly);
1104 variables->add(PionDProtonIDnoSVD);
1105
1106 variables->add(PionDElectronLLSVDonly);
1107 variables->add(PionDPionLLSVDonly);
1108 variables->add(PionDKaonLLSVDonly);
1109 variables->add(PionDProtonLLSVDonly);
1110
1111 variables->add(PionDBinaryPionKaonIDALL);
1112 variables->add(PionDBinaryPionKaonIDSVDonly);
1113 variables->add(PionDBinaryPionKaonIDnoSVD);
1114 variables->add(PionDBinaryKaonPionIDALL);
1115 variables->add(PionDBinaryKaonPionIDSVDonly);
1116 variables->add(PionDBinaryKaonPionIDnoSVD);
1117 variables->add(PionDBinaryProtonPionIDALL);
1118 variables->add(PionDBinaryProtonPionIDSVDonly);
1119 variables->add(PionDBinaryProtonPionIDnoSVD);
1120 variables->add(PionDBinaryElectronPionIDALL);
1121 variables->add(PionDBinaryElectronPionIDSVDonly);
1122 variables->add(PionDBinaryElectronPionIDnoSVD);
1123
1124 variables->add(SlowPionPionIDALL);
1125 variables->add(SlowPionPionIDSVDonly);
1126 variables->add(SlowPionPionIDnoSVD);
1127 variables->add(SlowPionKaonIDALL);
1128 variables->add(SlowPionKaonIDSVDonly);
1129 variables->add(SlowPionKaonIDnoSVD);
1130 variables->add(SlowPionElectronIDALL);
1131 variables->add(SlowPionElectronIDSVDonly);
1132 variables->add(SlowPionElectronIDnoSVD);
1133 variables->add(SlowPionProtonIDALL);
1134 variables->add(SlowPionProtonIDSVDonly);
1135 variables->add(SlowPionProtonIDnoSVD);
1136
1137 variables->add(SlowPionElectronLLSVDonly);
1138 variables->add(SlowPionPionLLSVDonly);
1139 variables->add(SlowPionKaonLLSVDonly);
1140 variables->add(SlowPionProtonLLSVDonly);
1141
1142 variables->add(SlowPionBinaryPionKaonIDALL);
1143 variables->add(SlowPionBinaryPionKaonIDSVDonly);
1144 variables->add(SlowPionBinaryPionKaonIDnoSVD);
1145 variables->add(SlowPionBinaryKaonPionIDALL);
1146 variables->add(SlowPionBinaryKaonPionIDSVDonly);
1147 variables->add(SlowPionBinaryKaonPionIDnoSVD);
1148 variables->add(SlowPionBinaryProtonPionIDALL);
1149 variables->add(SlowPionBinaryProtonPionIDSVDonly);
1150 variables->add(SlowPionBinaryProtonPionIDnoSVD);
1151 variables->add(SlowPionBinaryElectronPionIDALL);
1152 variables->add(SlowPionBinaryElectronPionIDSVDonly);
1153 variables->add(SlowPionBinaryElectronPionIDnoSVD);
1154
1155 RooDataSet* DstarDataset = new RooDataSet("DstarDataset", "DstarDataset", preselTree.get(), *variables);
1156
1157 if (DstarDataset->sumEntries() == 0) {
1158 B2FATAL("The Dstar dataset is empty, stopping here");
1159 }
1160
1161 RooPlot* DstarFitFrame = DstarDataset->plotOn(deltaM.frame());
1162
1163 RooRealVar GaussMean("GaussMean", "GaussMean", 0.145, 0.140, 0.150);
1164 RooRealVar GaussSigma1("GaussSigma1", "GaussSigma1", 0.01, 1.e-4, 1.0);
1165 RooGaussian DstarGauss1("DstarGauss1", "DstarGauss1", deltaM, GaussMean, GaussSigma1);
1166 RooRealVar GaussSigma2("GaussSigma2", "GaussSigma2", 0.001, 1.e-4, 1.0);
1167 RooGaussian DstarGauss2("DstarGauss2", "DstarGauss2", deltaM, GaussMean, GaussSigma2);
1168 RooRealVar fracGaussYield("fracGaussYield", "Fraction of two Gaussians", 0.75, 0.0, 1.0);
1169 RooAddPdf DstarSignalPDF("DstarSignalPDF", "DstarGauss1+DstarGauss2", RooArgList(DstarGauss1, DstarGauss2), fracGaussYield);
1170
1171 RooRealVar dm0Bkg("dm0Bkg", "dm0", 0.13957018, 0.130, 0.140);
1172 RooRealVar aBkg("aBkg", "a", -0.0784, -0.08, 3.0);
1173 RooRealVar bBkg("bBkg", "b", -0.444713, -0.5, 0.4);
1174 RooRealVar cBkg("cBkg", "c", 0.3);
1175 RooDstD0BG DstarBkgPDF("DstarBkgPDF", "DstarBkgPDF", deltaM, dm0Bkg, cBkg, aBkg, bBkg);
1176 RooRealVar nSignalDstar("nSignalDstar", "signal yield", 0.5 * preselTree->GetEntries(), 0, preselTree->GetEntries());
1177 RooRealVar nBkgDstar("nBkgDstar", "background yield", 0.5 * preselTree->GetEntries(), 0, preselTree->GetEntries());
1178 RooAddPdf totalPDFDstar("totalPDFDstar", "totalPDFDstar pdf", RooArgList(DstarSignalPDF, DstarBkgPDF),
1179 RooArgList(nSignalDstar, nBkgDstar));
1180
1181 B2INFO("Dstar: Start fitting...");
1182 RooFitResult* DstarFitResult = totalPDFDstar.fitTo(*DstarDataset, Save(kTRUE), PrintLevel(-1));
1183
1184 int status = DstarFitResult->status();
1185 int covqual = DstarFitResult->covQual();
1186 double diff = nSignalDstar.getValV() + nBkgDstar.getValV() - DstarDataset->sumEntries();
1187
1188 B2INFO("Dstar: Fit status: " << status << "; covariance quality: " << covqual);
1189 // if the fit is not healthy, try again once before giving up, with a slightly different setup:
1190 if ((status > 0) || (TMath::Abs(diff) > 1.) || (nSignalDstar.getError() < sqrt(nSignalDstar.getValV()))
1191 || (nSignalDstar.getError() > (nSignalDstar.getValV()))) {
1192
1193 DstarFitResult = totalPDFDstar.fitTo(*DstarDataset, Save(), Strategy(2), Offset(1));
1194 status = DstarFitResult->status();
1195 covqual = DstarFitResult->covQual();
1196 diff = nSignalDstar.getValV() + nBkgDstar.getValV() - DstarDataset->sumEntries();
1197 }
1198
1199 if ((status > 0) || (TMath::Abs(diff) > 1.) || (nSignalDstar.getError() < sqrt(nSignalDstar.getValV()))
1200 || (nSignalDstar.getError() > (nSignalDstar.getValV()))) {
1201 B2WARNING("Dstar: Fit problem: fit status " << status << "; sum of component yields minus the dataset yield is " << diff <<
1202 "; signal yield is " << nSignalDstar.getValV() << ", while its uncertainty is " << nSignalDstar.getError());
1203 }
1204 if (covqual < 2) {
1205 B2INFO("Dstar: Fit warning: covariance quality " << covqual);
1206 }
1207
1208 totalPDFDstar.plotOn(DstarFitFrame, LineColor(TColor::GetColor("#4575b4")));
1209
1210 double chisquare = DstarFitFrame->chiSquare();
1211 B2INFO("Dstar: Fit chi2 = " << chisquare);
1212 totalPDFDstar.paramOn(DstarFitFrame, Layout(0.63, 0.96, 0.93), Format("NEU", AutoPrecision(2)));
1213 DstarFitFrame->getAttText()->SetTextSize(0.03);
1214
1215 totalPDFDstar.plotOn(DstarFitFrame, Components("DstarSignalPDF"), LineColor(TColor::GetColor("#d73027")));
1216 totalPDFDstar.plotOn(DstarFitFrame, Components("DstarBkgPDF"), LineColor(TColor::GetColor("#fc8d59")));
1217 totalPDFDstar.plotOn(DstarFitFrame, LineColor(TColor::GetColor("#4575b4")));
1218
1219 DstarFitFrame->GetXaxis()->SetTitle("#Deltam [GeV/c^{2}]");
1220 TCanvas* canvDstar = new TCanvas("canvDstar", "canvDstar");
1221 canvDstar->cd();
1222
1223 DstarFitFrame->Draw();
1224
1225 if (m_isMakePlots) {
1226 canvDstar->Print("SVDdEdxValidationFitDstar.pdf");
1227 TFile DstarFitPlotFile("SVDdEdxValidationDstarFitPlotFile.root", "RECREATE");
1228 canvDstar->Write();
1229 DstarFitPlotFile.Close();
1230 }
1231
1233
1234 RooStats::SPlot* sPlotDatasetDstar = new RooStats::SPlot("sData", "An SPlot", *DstarDataset, &totalPDFDstar,
1235 RooArgList(nSignalDstar, nBkgDstar));
1236
1237 for (int iEvt = 0; iEvt < 5; iEvt++) {
1238 if (TMath::Abs(sPlotDatasetDstar->GetSWeight(iEvt, "nSignalDstar") + sPlotDatasetDstar->GetSWeight(iEvt, "nBkgDstar") - 1) > 5.e-3)
1239 B2FATAL("Dstar: sPlot error: sum of weights not equal to 1");
1240 }
1241
1242 RooDataSet* DstarDatasetSWeighted = new RooDataSet(DstarDataset->GetName(), DstarDataset->GetTitle(), DstarDataset,
1243 *DstarDataset->get());
1244
1245 TTree* treeDstar_sw = DstarDatasetSWeighted->GetClonedTree();
1246 treeDstar_sw->SetName("treeDstar_sw");
1247
1248 B2INFO("Dstar: sPlot done. ");
1249
1250 return treeDstar_sw;
1251}
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 algorithm.

Definition at line 164 of file CalibrationAlgorithm.h.

164{return getPrefix();}

◆ getDescription()

const std::string & getDescription ( ) const
inlineinherited

Get the description of the algorithm (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 722 of file SVDdEdxValidationAlgorithm.cc.

723{
724 B2INFO("Configuring the Lambda fit...");
725 gROOT->SetBatch(true);
726 RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING);
727
728 RooRealVar InvM("InvM", "m(p^{+}#pi^{-})", 1.1, 1.13, "GeV/c^{2}");
729
730 RooRealVar ProtonMomentum("ProtonMomentum", "momentum for p", -1.e8, 1.e8);
731 RooRealVar ProtonSVDdEdx("ProtonSVDdEdx", "", -1.e8, 1.e8);
732
733 RooRealVar exp("exp", "experiment number", 0, 1.e5);
734 RooRealVar run("run", "run number", 0, 1.e7);
735
736 RooRealVar ProtonProtonIDALL("ProtonProtonIDALL", "", -1.e8, 1.e8);
737 RooRealVar ProtonProtonIDSVDonly("ProtonProtonIDSVDonly", "", -1.e8, 1.e8);
738 RooRealVar ProtonProtonIDnoSVD("ProtonProtonIDnoSVD", "", -1.e8, 1.e8);
739
740 RooRealVar ProtonElectronLLSVDonly("ProtonElectronLLSVDonly", "", -1.e8, 1.e8);
741 RooRealVar ProtonPionLLSVDonly("ProtonPionLLSVDonly", "", -1.e8, 1.e8);
742 RooRealVar ProtonKaonLLSVDonly("ProtonKaonLLSVDonly", "", -1.e8, 1.e8);
743 RooRealVar ProtonProtonLLSVDonly("ProtonProtonLLSVDonly", "", -1.e8, 1.e8);
744
745 RooRealVar ProtonBinaryProtonPionIDALL("ProtonBinaryProtonPionIDALL", "", -1.e8, 1.e8);
746 RooRealVar ProtonBinaryProtonPionIDSVDonly("ProtonBinaryProtonPionIDSVDonly", "", -1.e8, 1.e8);
747 RooRealVar ProtonBinaryProtonPionIDnoSVD("ProtonBinaryProtonPionIDnoSVD", "", -1.e8, 1.e8);
748
749 RooRealVar ProtonBinaryProtonKaonIDALL("ProtonBinaryProtonKaonIDALL", "", -1.e8, 1.e8);
750 RooRealVar ProtonBinaryProtonKaonIDSVDonly("ProtonBinaryProtonKaonIDSVDonly", "", -1.e8, 1.e8);
751 RooRealVar ProtonBinaryProtonKaonIDnoSVD("ProtonBinaryProtonKaonIDnoSVD", "", -1.e8, 1.e8);
752
753 RooRealVar ProtonBinaryProtonElectronIDALL("ProtonBinaryProtonElectronIDALL", "", -1.e8, 1.e8);
754 RooRealVar ProtonBinaryProtonElectronIDSVDonly("ProtonBinaryProtonElectronIDSVDonly", "", -1.e8, 1.e8);
755 RooRealVar ProtonBinaryProtonElectronIDnoSVD("ProtonBinaryProtonElectronIDnoSVD", "", -1.e8, 1.e8);
756
757 RooRealVar ProtonBinaryPionProtonIDALL("ProtonBinaryPionProtonIDALL", "", -1.e8, 1.e8);
758 RooRealVar ProtonBinaryPionProtonIDSVDonly("ProtonBinaryPionProtonIDSVDonly", "", -1.e8, 1.e8);
759 RooRealVar ProtonBinaryPionProtonIDnoSVD("ProtonBinaryPionProtonIDnoSVD", "", -1.e8, 1.e8);
760
761 RooRealVar ProtonBinaryKaonProtonIDALL("ProtonBinaryKaonProtonIDALL", "", -1.e8, 1.e8);
762 RooRealVar ProtonBinaryKaonProtonIDSVDonly("ProtonBinaryKaonProtonIDSVDonly", "", -1.e8, 1.e8);
763 RooRealVar ProtonBinaryKaonProtonIDnoSVD("ProtonBinaryKaonProtonIDnoSVD", "", -1.e8, 1.e8);
764
765 RooRealVar ProtonBinaryElectronProtonIDALL("ProtonBinaryElectronProtonIDALL", "", -1.e8, 1.e8);
766 RooRealVar ProtonBinaryElectronProtonIDSVDonly("ProtonBinaryElectronProtonIDSVDonly", "", -1.e8, 1.e8);
767 RooRealVar ProtonBinaryElectronProtonIDnoSVD("ProtonBinaryElectronProtonIDnoSVD", "", -1.e8, 1.e8);
768
769 auto variables = new RooArgSet();
770
771 variables->add(InvM);
772
773 variables->add(ProtonMomentum);
774 variables->add(ProtonSVDdEdx);
775 variables->add(exp);
776 variables->add(run);
777
778 variables->add(ProtonProtonIDALL);
779 variables->add(ProtonProtonIDSVDonly);
780 variables->add(ProtonProtonIDnoSVD);
781 variables->add(ProtonElectronLLSVDonly);
782 variables->add(ProtonPionLLSVDonly);
783 variables->add(ProtonKaonLLSVDonly);
784 variables->add(ProtonProtonLLSVDonly);
785 variables->add(ProtonBinaryProtonPionIDALL);
786 variables->add(ProtonBinaryProtonPionIDSVDonly);
787 variables->add(ProtonBinaryProtonPionIDnoSVD);
788 variables->add(ProtonBinaryProtonKaonIDALL);
789 variables->add(ProtonBinaryProtonKaonIDSVDonly);
790 variables->add(ProtonBinaryProtonKaonIDnoSVD);
791 variables->add(ProtonBinaryProtonElectronIDALL);
792 variables->add(ProtonBinaryProtonElectronIDSVDonly);
793 variables->add(ProtonBinaryProtonElectronIDnoSVD);
794 variables->add(ProtonBinaryPionProtonIDALL);
795 variables->add(ProtonBinaryPionProtonIDSVDonly);
796 variables->add(ProtonBinaryPionProtonIDnoSVD);
797 variables->add(ProtonBinaryKaonProtonIDALL);
798 variables->add(ProtonBinaryKaonProtonIDSVDonly);
799 variables->add(ProtonBinaryKaonProtonIDnoSVD);
800 variables->add(ProtonBinaryElectronProtonIDALL);
801 variables->add(ProtonBinaryElectronProtonIDSVDonly);
802 variables->add(ProtonBinaryElectronProtonIDnoSVD);
803
804 RooDataSet* LambdaDataset = new RooDataSet("LambdaDataset", "LambdaDataset", preselTree.get(), *variables);
805
806 if (LambdaDataset->sumEntries() == 0) {
807 B2FATAL("The Lambda dataset is empty, stopping here");
808 }
809
810 // the signal PDF; might be revisited at a later point
811
812 RooRealVar GaussMean("GaussMean", " GaussMean", 1.116, 1.111, 1.12);
813 RooRealVar GaussSigma("GaussSigma", "#sigma_{1}", 3.e-3, 3.e-5, 10.e-3);
814 RooGaussian LambdaGauss("LambdaGauss", "LambdaGauss", InvM, GaussMean, GaussSigma);
815
816 /* temporary RooRealVar sigmaBifurGaussL1 and sigmaBifurGaussR1 to replace
817 * RooRealVar resolutionParamL("resolutionParamL", "resolutionParamL", 0.4, 5.e-4, 1.0);
818 * RooRealVar resolutionParamR("resolutionParamR", "resolutionParamR", 0.4, 5.e-4, 1.0);
819 * RooFormulaVar sigmaBifurGaussL1("sigmaBifurGaussL1", "resolutionParamL*GaussSigma", RooArgSet(resolutionParamL, GaussSigma));
820 * RooFormulaVar sigmaBifurGaussR1("sigmaBifurGaussR1", "resolutionParamR*GaussSigma", RooArgSet(resolutionParamR, GaussSigma));
821 */
822 RooRealVar sigmaBifurGaussL1("sigmaBifurGaussL1", "sigma left", 0.4 * 3.e-3, 3.e-5, 10.e-3);
823 RooRealVar sigmaBifurGaussR1("sigmaBifurGaussR1", "sigma right", 0.4 * 3.e-3, 3.e-5, 10.e-3);
824 RooBifurGauss LambdaBifurGauss("LambdaBifurGauss", "LambdaBifurGauss", InvM, GaussMean, sigmaBifurGaussL1, sigmaBifurGaussR1);
825
826 /* temporary RooRealVar sigmaBifurGaussL2 to replace
827 * RooRealVar resolutionParam2("resolutionParam2", "resolutionParam2", 0.2, 5.e-4, 1.0);
828 * sigmaBifurGaussL2("sigmaBifurGaussL2", "resolutionParam2*GaussSigma", RooArgSet(resolutionParam2, GaussSigma));
829 */
830 RooRealVar sigmaBifurGaussL2("sigmaBifurGaussL2", "sigmaBifurGaussL2", 0.2 * 3.e-3, 3.e-5, 10.e-3);
831 RooGaussian LambdaBifurGauss2("LambdaBifurGauss2", "LambdaBifurGauss2", InvM, GaussMean, sigmaBifurGaussL2);
832
833 RooRealVar fracBifurGaussYield("fracBifurGaussYield", "fracBifurGaussYield", 0.3, 5.e-4, 1.0);
834 RooRealVar fracGaussYield("fracGaussYield", "fracGaussYield", 0.8, 5.e-4, 1.0);
835
836 RooAddPdf LambdaCombinedBifurGauss("LambdaCombinedBifurGauss", "LambdaBifurGauss + LambdaBifurGauss2 ", RooArgList(LambdaBifurGauss,
837 LambdaBifurGauss2), RooArgList(fracBifurGaussYield));
838
839 RooAddPdf LambdaSignalPDF("LambdaSignalPDF", "LambdaCombinedBifurGauss + LambdaGauss", RooArgList(LambdaCombinedBifurGauss,
840 LambdaGauss), RooArgList(fracGaussYield));
841
842 // Background PDF
843 RooRealVar BkgPolyCoef0("BkgPolyCoef0", "BkgPolyCoef0", 0.1, 0., 1.5);
844 RooRealVar BkgPolyCoef1("BkgPolyCoef1", "BkgPolyCoef1", -0.5, -1.5, -1.e-3);
845 RooChebychev BkgPolyPDF("BkgPolyPDF", "BkgPolyPDF", InvM, RooArgList(BkgPolyCoef0, BkgPolyCoef1));
846
847 RooRealVar nSignalLambda("nSignalLambda", "nSignalLambda", 0.6 * preselTree->GetEntries(), 0., 0.99 * preselTree->GetEntries());
848 RooRealVar nBkgLambda("nBkgLambda", "nBkgLambda", 0.4 * preselTree->GetEntries(), 0., 0.99 * preselTree->GetEntries());
849 RooAddPdf totalPDFLambda("totalPDFLambda", "totalPDFLambda pdf", RooArgList(LambdaSignalPDF, BkgPolyPDF),
850 RooArgList(nSignalLambda, nBkgLambda));
851
852 B2INFO("Lambda: Start fitting...");
853 RooFitResult* LambdaFitResult = totalPDFLambda.fitTo(*LambdaDataset, Save(kTRUE), PrintLevel(-1));
854
855 int status = LambdaFitResult->status();
856 int covqual = LambdaFitResult->covQual();
857 double diff = nSignalLambda.getValV() + nBkgLambda.getValV() - LambdaDataset->sumEntries();
858
859 B2INFO("Lambda: Fit status: " << status << "; covariance quality: " << covqual);
860 // if the fit is not healthy, try again once before giving up, with a slightly different setup:
861 if ((status > 0) || (TMath::Abs(diff) > 1.) || (nSignalLambda.getError() < sqrt(nSignalLambda.getValV()))
862 || (nSignalLambda.getError() > (nSignalLambda.getValV()))) {
863
864 LambdaFitResult = totalPDFLambda.fitTo(*LambdaDataset, Save(), Strategy(2), Offset(1));
865 status = LambdaFitResult->status();
866 covqual = LambdaFitResult->covQual();
867 diff = nSignalLambda.getValV() + nBkgLambda.getValV() - LambdaDataset->sumEntries();
868 }
869
870 if ((status > 0) || (TMath::Abs(diff) > 1.) || (nSignalLambda.getError() < sqrt(nSignalLambda.getValV()))
871 || (nSignalLambda.getError() > (nSignalLambda.getValV()))) {
872 B2WARNING("Lambda: Fit problem: fit status " << status << "; sum of component yields minus the dataset yield is " << diff <<
873 "; signal yield is " << nSignalLambda.getValV() << ", while its uncertainty is " << nSignalLambda.getError());
874 }
875 if (covqual < 2) {
876 B2INFO("Lambda: Fit warning: covariance quality " << covqual);
877 }
878
879 TCanvas* canvLambda = new TCanvas("canvLambda", "canvLambda");
880 RooPlot* LambdaFitFrame = LambdaDataset->plotOn(InvM.frame(130));
881 totalPDFLambda.plotOn(LambdaFitFrame, LineColor(TColor::GetColor("#4575b4")));
882
883 double chisquare = LambdaFitFrame->chiSquare();
884 B2INFO("Lambda: Fit chi2 = " << chisquare);
885 totalPDFLambda.paramOn(LambdaFitFrame, Layout(0.6, 0.96, 0.93), Format("NEU", AutoPrecision(2)));
886 LambdaFitFrame->getAttText()->SetTextSize(0.03);
887
888 totalPDFLambda.plotOn(LambdaFitFrame, Components("LambdaSignalPDF"), LineColor(TColor::GetColor("#d73027")));
889 totalPDFLambda.plotOn(LambdaFitFrame, Components("BkgPolyPDF"), LineColor(TColor::GetColor("#fc8d59")));
890 totalPDFLambda.plotOn(LambdaFitFrame, LineColor(TColor::GetColor("#4575b4")));
891
892 LambdaFitFrame->GetXaxis()->SetTitle("m(p#pi^{-}) (GeV/c^{2})");
893
894 LambdaFitFrame->Draw();
895
896 if (m_isMakePlots) {
897 canvLambda->Print("SVDdEdxValidationFitLambda.pdf");
898 TFile LambdaFitPlotFile("SVDdEdxValidationLambdaFitPlotFile.root", "RECREATE");
899 canvLambda->Write();
900 LambdaFitPlotFile.Close();
901 }
902 RooStats::SPlot* sPlotDatasetLambda = new RooStats::SPlot("sData", "An SPlot", *LambdaDataset, &totalPDFLambda,
903 RooArgList(nSignalLambda, nBkgLambda));
904
905 for (int iEvt = 0; iEvt < 5; iEvt++) {
906 if (TMath::Abs(sPlotDatasetLambda->GetSWeight(iEvt, "nSignalLambda") + sPlotDatasetLambda->GetSWeight(iEvt,
907 "nBkgLambda") - 1) > 5.e-3)
908 B2FATAL("Lambda: sPlot error: sum of weights not equal to 1");
909 }
910
911 RooDataSet* LambdaDatasetSWeighted = new RooDataSet(LambdaDataset->GetName(), LambdaDataset->GetTitle(), LambdaDataset,
912 *LambdaDataset->get());
913
914 TTree* treeLambda_sw = LambdaDatasetSWeighted->GetClonedTree();
915 treeLambda_sw->SetName("treeLambda_sw");
916
917 B2INFO("Lambda: sPlot done. ");
918
919 return treeLambda_sw;
920}

◆ loadInputJson()

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

Load the m_inputJson variable from a string (useful from Python interface). The return 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 144 of file SVDdEdxValidationAlgorithm.cc.

147{
148
149 if ((SignalTree == nullptr) || (FakeTree == nullptr)) {
150 B2FATAL("Invalid dataset, stopping here");
151 }
152
153 if ((SignalTree->GetEntries() == 0) || (FakeTree->GetEntries() == 0)) {
154 B2FATAL("The dataset is empty, stopping here");
155 }
156
157 if ((SignalTree->GetBranch(Form("%sMomentum", SignalVarName.Data())) == nullptr)
158 || (FakeTree->GetBranch(Form("%sMomentum", FakeVarName.Data())) == nullptr)) {
159 B2FATAL("Check the provided branch name, stopping here");
160 }
161
162 TString SignalFiducialCut = "(1>0)"; // placeholder for a possible sanity cut
163 TString FakesFiducialCut = "(1>0)";
164
165 // Produce the plots of the SVD PID distribution
166 if (PIDDetectorsName == "SVDonly") {
167 SignalTree->Draw(Form("%s%s%s>>hSignalPIDDistribution(100,0.,1.)", SignalVarName.Data(), PIDVarName.Data(),
168 PIDDetectorsName.Data()),
169 SignalWeightName + Form("* (%sMomentum>%f && %sMomentum<%f)", SignalVarName.Data(), MomLow, SignalVarName.Data(), MomHigh), "goff");
170 TH1F* hSignalPIDDistribution = (TH1F*)gDirectory->Get("hSignalPIDDistribution");
171 hSignalPIDDistribution->Scale(1. / hSignalPIDDistribution->Integral());
172 hSignalPIDDistribution->GetXaxis()->SetTitle(PIDVarName + PIDDetectorsName + " for " + SignalVarNameFull);
173 hSignalPIDDistribution->GetYaxis()->SetTitle("Candidates, normalised");
174 hSignalPIDDistribution->SetMaximum(1.35 * hSignalPIDDistribution->GetMaximum());
175
176 SignalTree->Draw(Form("%sElectronLLSVDonly>>hSignalElectronLLDistribution(100,-17.,3.)", SignalVarName.Data()),
177 SignalWeightName + Form("* (%sMomentum>%f && %sMomentum<%f)", SignalVarName.Data(), MomLow, SignalVarName.Data(), MomHigh), "goff");
178 TH1F* hSignalElectronLLDistribution = (TH1F*)gDirectory->Get("hSignalElectronLLDistribution");
179 SignalTree->Draw(Form("%sPionLLSVDonly>>hSignalPionLLDistribution(100,-17.,3.)", SignalVarName.Data()),
180 SignalWeightName + Form("* (%sMomentum>%f && %sMomentum<%f)", SignalVarName.Data(), MomLow, SignalVarName.Data(), MomHigh), "goff");
181 TH1F* hSignalPionLLDistribution = (TH1F*)gDirectory->Get("hSignalPionLLDistribution");
182 SignalTree->Draw(Form("%sKaonLLSVDonly>>hSignalKaonLLDistribution(100,-17.,3.)", SignalVarName.Data()),
183 SignalWeightName + Form("* (%sMomentum>%f && %sMomentum<%f)", SignalVarName.Data(), MomLow, SignalVarName.Data(), MomHigh), "goff");
184 TH1F* hSignalKaonLLDistribution = (TH1F*)gDirectory->Get("hSignalKaonLLDistribution");
185 SignalTree->Draw(Form("%sProtonLLSVDonly>>hSignalProtonLLDistribution(100,-17.,3.)", SignalVarName.Data()),
186 SignalWeightName + Form("* (%sMomentum>%f && %sMomentum<%f)", SignalVarName.Data(), MomLow, SignalVarName.Data(), MomHigh), "goff");
187 TH1F* hSignalProtonLLDistribution = (TH1F*)gDirectory->Get("hSignalProtonLLDistribution");
188
189 // same but only for tracks that are expected to actually have SVD dEdx info
190 SignalTree->Draw(Form("%sElectronLLSVDonly>>hSignalElectronLLDistributionGood(100,-17.,3.)", SignalVarName.Data()),
191 SignalWeightName + Form("* (%sSVDdEdx>0) * (%sMomentum>%f && %sMomentum<%f)", SignalVarName.Data(), SignalVarName.Data(), MomLow,
192 SignalVarName.Data(), MomHigh), "goff");
193 TH1F* hSignalElectronLLDistributionGood = (TH1F*)gDirectory->Get("hSignalElectronLLDistributionGood");
194 SignalTree->Draw(Form("%sPionLLSVDonly>>hSignalPionLLDistributionGood(100,-17.,3.)", SignalVarName.Data()),
195 SignalWeightName + Form("* (%sSVDdEdx>0) * (%sMomentum>%f && %sMomentum<%f)", SignalVarName.Data(), SignalVarName.Data(), MomLow,
196 SignalVarName.Data(), MomHigh), "goff");
197 TH1F* hSignalPionLLDistributionGood = (TH1F*)gDirectory->Get("hSignalPionLLDistributionGood");
198 SignalTree->Draw(Form("%sKaonLLSVDonly>>hSignalKaonLLDistributionGood(100,-17.,3.)", SignalVarName.Data()),
199 SignalWeightName + Form("* (%sSVDdEdx>0) * (%sMomentum>%f && %sMomentum<%f)", SignalVarName.Data(), SignalVarName.Data(), MomLow,
200 SignalVarName.Data(), MomHigh), "goff");
201 TH1F* hSignalKaonLLDistributionGood = (TH1F*)gDirectory->Get("hSignalKaonLLDistributionGood");
202 SignalTree->Draw(Form("%sProtonLLSVDonly>>hSignalProtonLLDistributionGood(100,-17.,3.)", SignalVarName.Data()),
203 SignalWeightName + Form("* (%sSVDdEdx>0) * (%sMomentum>%f && %sMomentum<%f)", SignalVarName.Data(), SignalVarName.Data(), MomLow,
204 SignalVarName.Data(), MomHigh), "goff");
205 TH1F* hSignalProtonLLDistributionGood = (TH1F*)gDirectory->Get("hSignalProtonLLDistributionGood");
206
207
208 hSignalElectronLLDistribution->Scale(1. / hSignalElectronLLDistribution->Integral());
209 hSignalPionLLDistribution->Scale(1. / hSignalPionLLDistribution->Integral());
210 hSignalKaonLLDistribution->Scale(1. / hSignalKaonLLDistribution->Integral());
211 hSignalProtonLLDistribution->Scale(1. / hSignalProtonLLDistribution->Integral());
212
213 hSignalElectronLLDistributionGood->Scale(1. / hSignalElectronLLDistributionGood->Integral());
214 hSignalPionLLDistributionGood->Scale(1. / hSignalPionLLDistributionGood->Integral());
215 hSignalKaonLLDistributionGood->Scale(1. / hSignalKaonLLDistributionGood->Integral());
216 hSignalProtonLLDistributionGood->Scale(1. / hSignalProtonLLDistributionGood->Integral());
217
218 hSignalElectronLLDistribution->GetXaxis()->SetTitle(PIDVarName + "ElectronLLSVDonly");
219 hSignalElectronLLDistribution->GetYaxis()->SetTitle("Candidates, normalised");
220 hSignalElectronLLDistribution->SetMaximum(1.35 * hSignalElectronLLDistribution->GetMaximum());
221
222 hSignalPionLLDistribution->GetXaxis()->SetTitle(PIDVarName + "PionLLSVDonly");
223 hSignalPionLLDistribution->GetYaxis()->SetTitle("Candidates, normalised");
224 hSignalPionLLDistribution->SetMaximum(1.35 * hSignalPionLLDistribution->GetMaximum());
225
226 hSignalKaonLLDistribution->GetXaxis()->SetTitle(PIDVarName + "KaonLLSVDonly");
227 hSignalKaonLLDistribution->GetYaxis()->SetTitle("Candidates, normalised");
228 hSignalKaonLLDistribution->SetMaximum(1.35 * hSignalKaonLLDistribution->GetMaximum());
229
230 hSignalProtonLLDistribution->GetXaxis()->SetTitle(PIDVarName + "ProtonLLSVDonly");
231 hSignalProtonLLDistribution->GetYaxis()->SetTitle("Candidates, normalised");
232 hSignalProtonLLDistribution->SetMaximum(1.35 * hSignalProtonLLDistribution->GetMaximum());
233
234 hSignalElectronLLDistributionGood->GetXaxis()->SetTitle(PIDVarName + "ElectronLLSVDonly");
235 hSignalElectronLLDistributionGood->GetYaxis()->SetTitle("Candidates, normalised");
236 hSignalElectronLLDistributionGood->SetMaximum(1.35 * hSignalElectronLLDistributionGood->GetMaximum());
237
238 hSignalPionLLDistributionGood->GetXaxis()->SetTitle(PIDVarName + "PionLLSVDonly");
239 hSignalPionLLDistributionGood->GetYaxis()->SetTitle("Candidates, normalised");
240 hSignalPionLLDistributionGood->SetMaximum(1.35 * hSignalPionLLDistributionGood->GetMaximum());
241
242 hSignalKaonLLDistributionGood->GetXaxis()->SetTitle(PIDVarName + "KaonLLSVDonly");
243 hSignalKaonLLDistributionGood->GetYaxis()->SetTitle("Candidates, normalised");
244 hSignalKaonLLDistributionGood->SetMaximum(1.35 * hSignalKaonLLDistributionGood->GetMaximum());
245
246 hSignalProtonLLDistributionGood->GetXaxis()->SetTitle(PIDVarName + "ProtonLLSVDonly");
247 hSignalProtonLLDistributionGood->GetYaxis()->SetTitle("Candidates, normalised");
248 hSignalProtonLLDistributionGood->SetMaximum(1.35 * hSignalProtonLLDistributionGood->GetMaximum());
249
250 TCanvas* DistribCanvas = new TCanvas("DistribCanvas", "", 600, 600);
251 gPad->SetTopMargin(0.05);
252 gPad->SetRightMargin(0.05);
253 gPad->SetLeftMargin(0.13);
254 gPad->SetBottomMargin(0.12);
255
256 hSignalPIDDistribution->SetLineWidth(2);
257 hSignalPIDDistribution->SetLineColor(TColor::GetColor("#2166ac"));
258 hSignalPIDDistribution->Draw("hist");
259
260 DistribCanvas->Print("SVDdEdxValidation_Distribution_" + SignalVarNameFull + PIDVarName + PIDDetectorsName +
261 "_MomRange_" +
262 std::to_string(
263 MomLow)
264 .substr(0, 3) +
265 "_" + std::to_string(MomHigh).substr(0, 3) + ".pdf");
266
267 hSignalElectronLLDistribution->SetLineWidth(2);
268 hSignalPionLLDistribution->SetLineWidth(2);
269 hSignalKaonLLDistribution->SetLineWidth(2);
270 hSignalProtonLLDistribution->SetLineWidth(2);
271
272 hSignalElectronLLDistributionGood->SetLineWidth(2);
273 hSignalPionLLDistributionGood->SetLineWidth(2);
274 hSignalKaonLLDistributionGood->SetLineWidth(2);
275 hSignalProtonLLDistributionGood->SetLineWidth(2);
276
277 hSignalElectronLLDistributionGood->SetLineColor(kBlack);
278 hSignalPionLLDistributionGood->SetLineColor(kBlack);
279 hSignalKaonLLDistributionGood->SetLineColor(kBlack);
280 hSignalProtonLLDistributionGood->SetLineColor(kBlack);
281
282 hSignalElectronLLDistribution->SetTitle("ElectronLL (SVD), all tracks");
283 hSignalPionLLDistribution->SetTitle("PionLL (SVD), all tracks");
284 hSignalKaonLLDistribution->SetTitle("KaonLL (SVD), all tracks");
285 hSignalProtonLLDistribution->SetTitle("ProtonLL (SVD), all tracks");
286
287 hSignalElectronLLDistributionGood->SetTitle("ElectronLL (SVD), tracks with dEdx info");
288 hSignalPionLLDistributionGood->SetTitle("PionLL (SVD), tracks with dEdx info");
289 hSignalKaonLLDistributionGood->SetTitle("KaonLL (SVD), tracks with dEdx info");
290 hSignalProtonLLDistributionGood->SetTitle("ProtonLL (SVD), tracks with dEdx info");
291
292 hSignalElectronLLDistribution->GetXaxis()->SetTitleSize(0.04);
293 hSignalElectronLLDistribution->GetYaxis()->SetTitleSize(0.04);
294 hSignalElectronLLDistribution->GetXaxis()->SetTitleOffset(1.0);
295 hSignalElectronLLDistribution->GetYaxis()->SetTitleOffset(1.3);
296 hSignalElectronLLDistribution->GetYaxis()->SetLabelSize(0.04);
297 hSignalElectronLLDistribution->GetXaxis()->SetLabelSize(0.04);
298
299 hSignalPionLLDistribution->GetXaxis()->SetTitleSize(0.04);
300 hSignalPionLLDistribution->GetYaxis()->SetTitleSize(0.04);
301 hSignalPionLLDistribution->GetXaxis()->SetTitleOffset(1.0);
302 hSignalPionLLDistribution->GetYaxis()->SetTitleOffset(1.3);
303 hSignalPionLLDistribution->GetYaxis()->SetLabelSize(0.04);
304 hSignalPionLLDistribution->GetXaxis()->SetLabelSize(0.04);
305
306 hSignalKaonLLDistribution->GetXaxis()->SetTitleSize(0.04);
307 hSignalKaonLLDistribution->GetYaxis()->SetTitleSize(0.04);
308 hSignalKaonLLDistribution->GetXaxis()->SetTitleOffset(1.0);
309 hSignalKaonLLDistribution->GetYaxis()->SetTitleOffset(1.3);
310 hSignalKaonLLDistribution->GetYaxis()->SetLabelSize(0.04);
311 hSignalKaonLLDistribution->GetXaxis()->SetLabelSize(0.04);
312
313 hSignalProtonLLDistribution->GetXaxis()->SetTitleSize(0.04);
314 hSignalProtonLLDistribution->GetYaxis()->SetTitleSize(0.04);
315 hSignalProtonLLDistribution->GetXaxis()->SetTitleOffset(1.0);
316 hSignalProtonLLDistribution->GetYaxis()->SetTitleOffset(1.3);
317 hSignalProtonLLDistribution->GetYaxis()->SetLabelSize(0.04);
318 hSignalProtonLLDistribution->GetXaxis()->SetLabelSize(0.04);
319
320 TCanvas* LLCanvas = new TCanvas("LLCanvas", "", 900, 700);
321
322 gPad->SetTopMargin(0.05);
323 gPad->SetRightMargin(0.05);
324 gPad->SetLeftMargin(0.13);
325 gPad->SetBottomMargin(0.12);
326
327 LLCanvas->Divide(2, 2, 0.01, 0.01);
328 LLCanvas->cd(1);
329 hSignalElectronLLDistribution->Draw("hist");
330 LLCanvas->cd(2);
331 hSignalPionLLDistribution->Draw("hist");
332 LLCanvas->cd(3);
333 hSignalKaonLLDistribution->Draw("hist");
334 LLCanvas->cd(4);
335 hSignalProtonLLDistribution->Draw("hist");
336
337 TCanvas* LLCanvasGood = new TCanvas("LLCanvasGood", "", 900, 700);
338
339 gPad->SetTopMargin(0.05);
340 gPad->SetRightMargin(0.05);
341 gPad->SetLeftMargin(0.13);
342 gPad->SetBottomMargin(0.12);
343
344 LLCanvasGood->Divide(2, 2, 0.01, 0.01);
345 LLCanvasGood->cd(1);
346 hSignalElectronLLDistributionGood->Draw("hist");
347 LLCanvasGood->cd(2);
348 hSignalPionLLDistributionGood->Draw("hist");
349 LLCanvasGood->cd(3);
350 hSignalKaonLLDistributionGood->Draw("hist");
351 LLCanvasGood->cd(4);
352 hSignalProtonLLDistributionGood->Draw("hist");
353
354 LLCanvas->Print("SVDdEdxValidation_LLDistributions_" + SignalVarNameFull +
355 "_SVDonly_MomRange_" +
356 std::to_string(
357 MomLow)
358 .substr(0, 3) +
359 "_" + std::to_string(MomHigh).substr(0, 3) + ".pdf");
360
361 LLCanvasGood->Print("SVDdEdxValidation_LLDistributions_GoodSVDTracks_" + SignalVarNameFull +
362 "_SVDonly_MomRange_" +
363 std::to_string(
364 MomLow)
365 .substr(0, 3) +
366 "_" + std::to_string(MomHigh).substr(0, 3) + ".pdf");
367
368 TFile DistribFile("SVDdEdxValidation_Distribution_" + SignalVarNameFull + PIDVarName + PIDDetectorsName +
369 "_MomRange_" +
370 std::to_string(
371 MomLow)
372 .substr(0, 3) +
373 "_" + std::to_string(MomHigh).substr(0, 3) + ".root",
374 "RECREATE");
375 hSignalPIDDistribution->SetLineColor(kBlack);
376 hSignalPIDDistribution->Write();
377 DistribFile.Close();
378 delete DistribCanvas;
379
380 TFile LLDistribFile(TString("SVDdEdxValidation_LLDistributions_" + SignalVarNameFull + "_SVDonly_MomRange_" +
381 std::to_string(
382 MomLow)
383 .substr(0, 3) +
384 "_" + std::to_string(MomHigh).substr(0, 3) + ".root"),
385 "RECREATE");
386 hSignalElectronLLDistribution->Write();
387 hSignalPionLLDistribution->Write();
388 hSignalKaonLLDistribution->Write();
389 hSignalProtonLLDistribution->Write();
390 LLDistribFile.Close();
391 delete LLCanvas;
392 delete LLCanvasGood;
393 }
394
395 // ---------- Momentum distributions (for efficiency determination) ----------
396
397 SignalTree->Draw(Form("%sMomentum>>hAllSignal(%i,%f,%f)", SignalVarName.Data(), nbins, MomLow, MomHigh),
398 SignalWeightName + " * (" + SignalFiducialCut + ")", "goff");
399 SignalTree->Draw(Form("%sMomentum>>hSelectedSignal(%i,%f,%f)", SignalVarName.Data(), nbins, MomLow, MomHigh),
400 SignalWeightName + " * (" + SignalVarName + PIDVarName + PIDDetectorsName + ">" + PIDCut + "&&" + SignalFiducialCut +
401 ")",
402 "goff");
403
404 FakeTree->Draw(Form("%sMomentum>>hAllFakes(%i,%f,%f)", FakeVarName.Data(), nbins, MomLow, MomHigh),
405 FakeWeightName + " * (" + FakesFiducialCut + ")", "goff");
406 FakeTree->Draw(Form("%sMomentum>>hSelectedFakes(%i,%f,%f)", FakeVarName.Data(), nbins, MomLow, MomHigh),
407 FakeWeightName + " * (" + FakeVarName + PIDVarName + PIDDetectorsName + ">" + PIDCut + "&&" + FakesFiducialCut + ")",
408 "goff");
409
410 TH1F* hAllSignal = (TH1F*)gDirectory->Get("hAllSignal");
411 TH1F* hSelectedSignal = (TH1F*)gDirectory->Get("hSelectedSignal");
412 TH1F* hAllFakes = (TH1F*)gDirectory->Get("hAllFakes");
413 TH1F* hSelectedFakes = (TH1F*)gDirectory->Get("hSelectedFakes");
414
415 // ---------- Add slow pions to the pion dataset ----------
416 if (strncmp(SignalVarName.Data(), "PionD", 5) == 0) {
417 SignalTree->Draw(Form("SlowPionMomentum>>hAllSignalSlow(%i,%f,%f)", nbins, MomLow, MomHigh),
418 SignalWeightName + " * (" + SignalFiducialCut + ")", "goff");
419 SignalTree->Draw(Form("SlowPionMomentum>>hSelectedSignalSlow(%i,%f,%f)", nbins, MomLow, MomHigh),
420 SignalWeightName + " * (SlowPion" + PIDVarName + PIDDetectorsName + ">" + PIDCut + "&&" + SignalFiducialCut + ")", "goff");
421 TH1F* hAllSignalSlow = (TH1F*)gDirectory->Get("hAllSignalSlow");
422 TH1F* hSelectedSignalSlow = (TH1F*)gDirectory->Get("hSelectedSignalSlow");
423 hAllSignal->Add(hAllSignalSlow);
424 hSelectedSignal->Add(hSelectedSignalSlow);
425 }
426
427 if (strncmp(FakeVarName.Data(), "PionD", 5) == 0) {
428 FakeTree->Draw(Form("SlowPionMomentum>>hAllFakesSlow(%i,%f,%f)", nbins, MomLow, MomHigh),
429 FakeWeightName + " * (" + FakesFiducialCut + ")",
430 "goff");
431 FakeTree->Draw(Form("SlowPionMomentum>>hSelectedFakesSlow(%i,%f,%f)", nbins, MomLow, MomHigh),
432 FakeWeightName + " * (SlowPion" + PIDVarName + PIDDetectorsName + ">" + PIDCut + "&&" + FakesFiducialCut + ")", "goff");
433 TH1F* hAllFakesSlow = (TH1F*)gDirectory->Get("hAllFakesSlow");
434 TH1F* hSelectedFakesSlow = (TH1F*)gDirectory->Get("hSelectedFakesSlow");
435 hAllFakes->Add(hAllFakesSlow);
436 hSelectedFakes->Add(hSelectedFakesSlow);
437 }
438
439 TH1F* EffHistoSig = (TH1F*)hAllSignal->Clone("EffHistoSig"); // signal efficiency
440 TH1F* EffHistoFake = (TH1F*)hAllFakes->Clone("EffHistoFake"); // fakes efficiency
441
442 EffHistoSig->Divide(hSelectedSignal, hAllSignal);//, 1, 1, "B");
443 EffHistoFake->Divide(hSelectedFakes, hAllFakes);//, 1, 1, "B");
444
445 // PID plots
446 TH1F* hBase = new TH1F("hBase", "", 100, 0.0, MomHigh);
447 hBase->SetTitle(";Momentum [GeV];Efficiency");
448 hBase->SetMaximum(1.20);
449 hBase->SetMinimum(0.0);
450
451 TLegend* tleg1 = new TLegend(0.63, 0.82, 0.93, 0.94);
452 tleg1->AddEntry(EffHistoSig, SignalVarNameFull + " efficiency", "pl");
453 tleg1->AddEntry(EffHistoFake, FakeVarNameFull + " fake rate", "pl");
454
455 TCanvas* ResultCanvas = new TCanvas("ResultCanvas", "", 600, 600);
456 gPad->SetTopMargin(0.05);
457 gPad->SetRightMargin(0.05);
458 gPad->SetLeftMargin(0.13);
459 gPad->SetBottomMargin(0.12);
460
461 ResultCanvas->SetGrid();
462 hBase->Draw();
463 EffHistoSig->SetMarkerSize(1.5);
464 EffHistoSig->SetMarkerStyle(22);
465 EffHistoSig->SetMarkerColor(TColor::GetColor("#2166ac"));
466 EffHistoSig->SetLineColor(TColor::GetColor("#2166ac"));
467 EffHistoSig->Draw("P,same");
468
469 EffHistoFake->SetMarkerSize(1.5);
470 EffHistoFake->SetMarkerStyle(23);
471 EffHistoFake->SetMarkerColor(TColor::GetColor("#ef8a62"));
472 EffHistoFake->SetLineColor(TColor::GetColor("#ef8a62"));
473 EffHistoFake->Draw("P,same");
474
475 tleg1->Draw("same");
476
477 hBase->SetStats(0);
478 hBase->GetXaxis()->SetTitleSize(0.04);
479 hBase->GetYaxis()->SetTitleSize(0.04);
480 hBase->GetXaxis()->SetTitleOffset(1.0);
481 hBase->GetYaxis()->SetTitleOffset(1.3);
482 hBase->GetYaxis()->SetLabelSize(0.04);
483 hBase->GetXaxis()->SetLabelSize(0.04);
484
485 // std::setprecision(2);
486 ResultCanvas->Print("SVDdEdxValidation_Efficiency_" + SignalVarNameFull + "_vs_" + FakeVarNameFull + PIDVarName + "_" +
487 PIDDetectorsName +
488 "_Cut" +
489 PIDCut + "_MomRange_" + std::to_string(MomLow).substr(0, 3) + "_" + std::to_string(MomHigh).substr(0, 3) + ".pdf");
490 TFile ResultFile("SVDdEdxValidation_Efficiency_" + SignalVarNameFull + "_vs_" + FakeVarNameFull + PIDVarName + "_" +
491 PIDDetectorsName +
492 "_Cut" +
493 PIDCut + "_MomRange_" + std::to_string(MomLow).substr(0, 3) + "_" + std::to_string(MomHigh).substr(0, 3) + ".root",
494 "RECREATE");
495 EffHistoSig->SetLineColor(kBlack);
496 EffHistoSig->SetMarkerColor(kBlack);
497 EffHistoFake->SetLineColor(kBlack);
498 EffHistoFake->SetMarkerColor(kBlack);
499 EffHistoSig->Write();
500 EffHistoFake->Write();
501 ResultFile.Close();
502 delete ResultCanvas;
503 delete hBase;
504}

◆ 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 506 of file SVDdEdxValidationAlgorithm.cc.

509{
510
511 if ((SignalTree == nullptr) || (FakeTree == nullptr)) {
512 B2FATAL("Invalid dataset, stopping here");
513 }
514
515 if ((SignalTree->GetEntries() == 0) || (FakeTree->GetEntries() == 0)) {
516 B2FATAL("The dataset is empty, stopping here");
517 }
518
519 if ((SignalTree->GetBranch(Form("%sMomentum", SignalVarName.Data())) == nullptr)
520 || (FakeTree->GetBranch(Form("%sMomentum", FakeVarName.Data())) == nullptr)) {
521 B2FATAL("Check the provided branch name, stopping here");
522 }
523
524 std::vector<TString> PIDDetectors;
525 PIDDetectors.clear();
526 PIDDetectors.push_back("ALL");
527 PIDDetectors.push_back("noSVD");
528
529 std::vector<double> SignalEfficiencyALL, FakeEfficiencyALL;
530 SignalEfficiencyALL.reserve(m_NumROCpoints);
531 FakeEfficiencyALL.reserve(m_NumROCpoints);
532 std::vector<double> SignalEfficiencynoSVD, FakeEfficiencynoSVD;
533 SignalEfficiencynoSVD.reserve(m_NumROCpoints);
534 FakeEfficiencynoSVD.reserve(m_NumROCpoints);
535
536 TString SignalFiducialCut = SignalVarName + PIDVarName + "noSVD>=0"; // sanity cuts to reject events with NaN
537 TString FakesFiducialCut = FakeVarName + PIDVarName + "noSVD>=0";
538 TString SignalFiducialCutSlow = "SlowPion" + PIDVarName + "noSVD>=0";
539 TString FakesFiducialCutSlow = "SlowPion" + PIDVarName + "noSVD>=0";
540
541 // calculate efficiencies
542
543 TCut AllSignalCut = SignalFiducialCut * Form("%sMomentum>%f && %sMomentum<%f", SignalVarName.Data(), m_MomLowROC,
544 SignalVarName.Data(), m_MomHighROC);
545
546 double AllSignalIntegral, SelectedSignalIntegral;
547
548 auto DataFrameSignalAll = RDataFrame(*SignalTree).Filter(AllSignalCut.GetTitle());
549
550 if (SignalWeightName == "1") {
551 AllSignalIntegral = DataFrameSignalAll.Count().GetValue();
552 } else {
553 AllSignalIntegral = DataFrameSignalAll.Sum(SignalWeightName).GetValue();
554 }
555
556 std::unique_ptr<ROOT::RDF::RNode> DataFrameSlowSignalAll;
557
558 if (strncmp(SignalVarName.Data(), "PionD", 5) == 0) {
559 TString SignalVarNameSlow = "SlowPion";
560 TCut AllSignalCutSlow = TCut(SignalFiducialCut) * TCut(SignalFiducialCutSlow) * Form("(%sMomentum>%f && %sMomentum<%f)",
561 SignalVarNameSlow.Data(), m_MomLowROC, SignalVarNameSlow.Data(), m_MomHighROC);
562 DataFrameSlowSignalAll = std::make_unique<ROOT::RDF::RNode>(RDataFrame(*SignalTree).Filter(AllSignalCutSlow.GetTitle()));
563
564 if (SignalWeightName == "1") {
565 AllSignalIntegral += DataFrameSlowSignalAll->Count().GetValue();
566 } else {
567 AllSignalIntegral += DataFrameSlowSignalAll->Sum(SignalWeightName).GetValue();
568 }
569 }
570
571 for (unsigned int i = 0; i < PIDDetectors.size(); i++) {
572 for (unsigned int j = 0; j < m_NumROCpoints; ++j) {
573 delete gROOT->FindObject("PIDCut");
574
575 // scan cut values from 0 to 1, with a denser scan closer to 0 or 1, to get a nicer ROC curve
576 double x = 1. / m_NumROCpoints * j;
577 TString PIDCut = TString::Format("%f", 1. / (1 + TMath::Power(x / (1 - x), -3)));
578
579 TCut SelectedSignalCut = Form("(%s%s%s > %s)", SignalVarName.Data(), PIDVarName.Data(), PIDDetectors[i].Data(), PIDCut.Data());
580
581 if (SignalWeightName == "1") {
582 SelectedSignalIntegral = DataFrameSignalAll.Filter(SelectedSignalCut.GetTitle()).Count().GetValue();
583 } else {
584 SelectedSignalIntegral = DataFrameSignalAll.Filter(SelectedSignalCut.GetTitle()).Sum(SignalWeightName).GetValue();
585 }
586
587 // special treatment for pions: add also the slow pions from Dstar to gain low-momentum coverage
588 if (strncmp(SignalVarName.Data(), "PionD", 5) == 0) {
589 TString SignalVarNameSlow = "SlowPion";
590 TCut SelectedSignalCutSlow = Form("(%s%s%s > %s)", SignalVarNameSlow.Data(), PIDVarName.Data(), PIDDetectors[i].Data(),
591 PIDCut.Data());
592
593 if (SignalWeightName == "1") {
594 SelectedSignalIntegral += DataFrameSlowSignalAll->Filter(SelectedSignalCutSlow.GetTitle()).Count().GetValue();
595 } else {
596 SelectedSignalIntegral += DataFrameSlowSignalAll->Filter(SelectedSignalCutSlow.GetTitle()).Sum(SignalWeightName).GetValue();
597 }
598 }
599
600 if (PIDDetectors[i] == "ALL") {
601 SignalEfficiencyALL.push_back(SelectedSignalIntegral / AllSignalIntegral);
602 }
603
604 if (PIDDetectors[i] == "noSVD") {
605 SignalEfficiencynoSVD.push_back(SelectedSignalIntegral / AllSignalIntegral);
606 }
607 }
608 }
609
610 // calculate fake rates
611
612 TCut AllFakeCut = FakesFiducialCut * Form("%sMomentum>%f && %sMomentum<%f", FakeVarName.Data(), m_MomLowROC, FakeVarName.Data(),
614
615 double AllFakeIntegral, SelectedFakeIntegral;
616 auto DataFrameFakeAll = RDataFrame(*FakeTree).Filter(AllFakeCut.GetTitle());
617
618 if (FakeWeightName == "1") {
619 AllFakeIntegral = DataFrameFakeAll.Count().GetValue();
620 } else {
621 AllFakeIntegral = DataFrameFakeAll.Sum(FakeWeightName).GetValue();
622 }
623
624 std::unique_ptr<ROOT::RDF::RNode> DataFrameSlowFakeAll;
625
626 // special treatment for pions: add also the slow pions from Dstar to gain low-momentum coverage
627 if (strncmp(FakeVarName.Data(), "PionD", 5) == 0) {
628
629 TString FakeVarNameSlow = "SlowPion";
630 TCut AllFakeCutSlow = TCut(FakesFiducialCut) * TCut(FakesFiducialCutSlow) * Form("(%sMomentum>%f && %sMomentum<%f)",
631 FakeVarNameSlow.Data(), m_MomLowROC, FakeVarNameSlow.Data(), m_MomHighROC);
632 DataFrameSlowFakeAll = std::make_unique<ROOT::RDF::RNode>(RDataFrame(*FakeTree).Filter(AllFakeCutSlow.GetTitle()));
633
634 if (FakeWeightName == "1") {
635 AllFakeIntegral += DataFrameSlowFakeAll->Count().GetValue();
636 } else {
637 AllFakeIntegral += DataFrameSlowFakeAll->Sum(FakeWeightName).GetValue();
638 }
639 }
640
641 for (unsigned int i = 0; i < PIDDetectors.size(); i++) {
642 for (unsigned int j = 0; j < m_NumROCpoints; ++j) {
643 delete gROOT->FindObject("PIDCut");
644 delete gROOT->FindObject("hAllFakes");
645 delete gROOT->FindObject("hSelectedFakes");
646
647 // scan cut values from 0 to 1, with a denser scan closer to 0 or 1, to get a nicer ROC curve
648 double x = 1. / m_NumROCpoints * j;
649 TString PIDCut = TString::Format("%f", 1. / (1 + TMath::Power(x / (1 - x), -3)));
650
651 TCut SelectedFakeCut = Form("(%s%s%s > %s)", FakeVarName.Data(), PIDVarName.Data(), PIDDetectors[i].Data(), PIDCut.Data());
652
653 if (FakeWeightName == "1") {
654 SelectedFakeIntegral = DataFrameFakeAll.Filter(SelectedFakeCut.GetTitle()).Count().GetValue();
655 } else {
656 SelectedFakeIntegral = DataFrameFakeAll.Filter(SelectedFakeCut.GetTitle()).Sum(FakeWeightName).GetValue();
657 }
658
659 if (strncmp(FakeVarName.Data(), "PionD", 5) == 0) {
660 TString FakeVarNameSlow = "SlowPion";
661
662 TCut SelectedFakeCutSlow = Form("(%s%s%s > %s)", FakeVarNameSlow.Data(), PIDVarName.Data(), PIDDetectors[i].Data(), PIDCut.Data());
663
664 if (FakeWeightName == "1") {
665 SelectedFakeIntegral += DataFrameSlowFakeAll->Filter(SelectedFakeCutSlow.GetTitle()).Count().GetValue();
666 } else {
667 SelectedFakeIntegral += DataFrameSlowFakeAll->Filter(SelectedFakeCutSlow.GetTitle()).Sum(FakeWeightName).GetValue();
668 }
669 }
670
671 if (PIDDetectors[i] == "ALL") {
672 FakeEfficiencyALL.push_back(SelectedFakeIntegral / AllFakeIntegral);
673 }
674
675 if (PIDDetectors[i] == "noSVD") {
676 FakeEfficiencynoSVD.push_back(SelectedFakeIntegral / AllFakeIntegral);
677 }
678 }
679 }
680
681 auto ResultCanvas = new TCanvas("ResultCanvas", "", 600, 400);
682 TMultiGraph* hmgraph = new TMultiGraph();
683
684 // efficiency vs fake rate graph
685 TGraph* hgraphALL = new TGraph(m_NumROCpoints, FakeEfficiencyALL.data(), SignalEfficiencyALL.data());
686 hgraphALL->SetMarkerColor(TColor::GetColor("#2166ac"));
687 hgraphALL->SetMarkerStyle(20);
688 hgraphALL->SetLineColor(TColor::GetColor("#2166ac"));
689 hgraphALL->SetLineWidth(3);
690 hgraphALL->SetDrawOption("AP*");
691 hgraphALL->SetTitle("with SVD");
692
693 TGraph* hgraphnoSVD = new TGraph(m_NumROCpoints, FakeEfficiencynoSVD.data(), SignalEfficiencynoSVD.data());
694 hgraphnoSVD->SetMarkerColor(TColor::GetColor("#ef8a62"));
695 hgraphnoSVD->SetLineColor(TColor::GetColor("#ef8a62"));
696 hgraphnoSVD->SetLineWidth(3);
697 hgraphnoSVD->SetMarkerStyle(22);
698 hgraphnoSVD->SetDrawOption("P*");
699 hgraphnoSVD->SetTitle("without SVD");
700
701 hmgraph->Add(hgraphALL);
702 hmgraph->Add(hgraphnoSVD);
703 hmgraph->Draw("A");
704 hmgraph->GetHistogram()->GetXaxis()->SetTitle(FakeVarNameFull + " fake rate");
705 hmgraph->GetHistogram()->GetYaxis()->SetTitle(SignalVarNameFull + " signal efficiency");
706
707 ResultCanvas->BuildLegend(0.6, 0.25, 0.9, 0.5);
708 ResultCanvas->SetGrid();
709
710 ResultCanvas->Print("SVDdEdxValidation_ROC_curve_" + SignalVarNameFull + "_vs_" + FakeVarNameFull + PIDVarName + "_MomRange" +
711 std::to_string(m_MomLowROC).substr(0, 3) + "_" + std::to_string(m_MomHighROC).substr(0, 3) + ".pdf");
712
713 TFile ResultFile("SVDdEdxValidation_ROC_curve_" + SignalVarNameFull + "_vs_" + FakeVarNameFull + PIDVarName + "_MomRange" +
714 std::to_string(m_MomLowROC).substr(0, 3) + "_" + std::to_string(m_MomHighROC).substr(0, 3) + ".root",
715 "RECREATE");
716 hmgraph->Write();
717 ResultFile.Close();
718
719 delete ResultCanvas;
720}
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 70 of file SVDdEdxValidationAlgorithm.h.

70{ 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 60 of file SVDdEdxValidationAlgorithm.h.

60{ m_MomHighROC = value; }

◆ setMinEvtsPerTree()

void setMinEvtsPerTree ( const double &  value)
inline

set the upper edge of the dEdx binning for the payloads

Definition at line 75 of file SVDdEdxValidationAlgorithm.h.

75{ 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 55 of file SVDdEdxValidationAlgorithm.h.

55{ m_MomLowROC = value; }

◆ setMonitoringPlots()

void setMonitoringPlots ( bool  value = false)
inline

function to enable plotting

Definition at line 45 of file SVDdEdxValidationAlgorithm.h.

45{ m_isMakePlots = value; }

◆ setNumEffBins()

void setNumEffBins ( const unsigned int &  value)
inline

set the number of bins for the efficiency scan

Definition at line 65 of file SVDdEdxValidationAlgorithm.h.

65{ m_NumEffBins = value; }

◆ setNumROCpoints()

void setNumROCpoints ( const unsigned int &  value)
inline

set the number of points for ROC curve plotting

Definition at line 50 of file SVDdEdxValidationAlgorithm.h.

50{ 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 internally 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 unnecessary...)
412}
Store event, run, and experiment numbers.
Definition: EventMetaData.h:33
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:26
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:140
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:77

◆ validationMode()

void validationMode ( bool  value = false)
inline

decide between full or basic validation mode.

full validation also produces global PID performance plots.

Definition at line 40 of file SVDdEdxValidationAlgorithm.h.

40{ m_fullValidation = value; }

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_fullValidation

bool m_fullValidation
private

decide between full or basic validation mode.

full validation also produces global PID performance plots.

Definition at line 84 of file SVDdEdxValidationAlgorithm.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 85 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 102 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 107 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 105 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 104 of file SVDdEdxValidationAlgorithm.h.

◆ m_NumEffBins

unsigned int m_NumEffBins = 30
private

number of bins for the efficiency/fake rate plot

Definition at line 106 of file SVDdEdxValidationAlgorithm.h.

◆ m_NumROCpoints

unsigned int m_NumROCpoints = 250
private

number of points for the ROC curve plotting

Definition at line 103 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: