Belle II Software  release-08-01-10
eclGammaGammaEAlgorithm Class Reference

Calibrate ecl crystals using gamma pair events. More...

#include <eclGammaGammaEAlgorithm.h>

Inheritance diagram for eclGammaGammaEAlgorithm:
Collaboration diagram for eclGammaGammaEAlgorithm:

Public Types

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

Public Member Functions

 eclGammaGammaEAlgorithm ()
 ..Constructor More...
 
virtual ~eclGammaGammaEAlgorithm ()
 ..Destructor
 
void setOutputName (const std::string &outputName)
 Setter for m_outputName.
 
std::string getOutputName ()
 Getter for m_outputName.
 
void setCellIDLo (int cellIDLo)
 Setter for m_cellIDLo.
 
int getCellIDLo ()
 Getter for m_cellIDLo.
 
void setCellIDHi (int cellIDHi)
 Setter for m_cellIDHi.
 
int getCellIDHi ()
 Getter for m_cellIDHi.
 
void setMinEntries (int minEntries)
 Setter for m_minEntries.
 
int getMinEntries ()
 Getter for m_minEntries.
 
void setMaxIterations (int maxIterations)
 Setter for m_maxIterations.
 
int getMaxIterations ()
 Getter for m_maxIterations.
 
void setTRatioMin (double tRatioMin)
 Setter for m_tRatioMinNom.
 
double getTRatioMin ()
 Getter for m_tRatioMinNom.
 
void setTRatioMax (double tRatioMax)
 Setter for m_tRatioMaxNom.
 
double getTRatioMax ()
 Getter for m_tRatioMaxNom.
 
void setTRatioMinHiStat (double tRatioMin)
 Setter for m_tRatioMinHiStat.
 
double getTRatioMinHiStat ()
 Getter for m_tRatioMinHiStat.
 
void setTRatioMaxHiStat (double tRatioMax)
 Setter for m_tRatioMaxHiStat.
 
double getTRatioMaxHiStat ()
 Getter for m_tRatioMaxHiStat.
 
void setUpperEdgeThresh (double upperEdgeThresh)
 Setter for m_upperEdgeThresh.
 
double getUpperEdgeThresh ()
 Getter for m_upperEdgeThresh.
 
void setPerformFits (bool performFits)
 Setter for m_performFits.
 
bool getPerformFits ()
 Getter for m_performFits.
 
void setFindExpValues (bool findExpValues)
 Setter for m_findExpValues.
 
bool getFindExpValues ()
 Getter for m_findExpValues.
 
void setStoreConst (int storeConst)
 Setter for m_storeConst.
 
int getStoreConst ()
 Getter for m_storeConst.
 
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. More...
 
Calibration::ExpRun convertPyExpRun (PyObject *pyObj)
 Performs the conversion of PyObject to ExpRun. More...
 
std::string getCollectorName () const
 Alias for prefix. More...
 
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. More...
 
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. More...
 
EResult execute (PyObject *runs, int iteration=0, IntervalOfValidity iov=IntervalOfValidity())
 Runs calibration over Python list of runs. Converts to C++ and then calls the other execute() function.
 
std::list< Database::DBImportQuery > & getPayloads ()
 Get constants (in TObjects) for database update from last execution.
 
std::list< Database::DBImportQuerygetPayloadValues ()
 Get constants (in TObjects) for database update from last execution but passed by VALUE.
 
bool commit ()
 Submit constants from last calibration into database.
 
bool commit (std::list< Database::DBImportQuery > payloads)
 Submit constants from a (potentially previous) set of payloads.
 
const std::string & getDescription () const
 Get the description of the algoithm (set by developers in constructor)
 
bool loadInputJson (const std::string &jsonString)
 Load the m_inputJson variable from a string (useful from Python interface). The rturn bool indicates success or failure.
 
const std::string dumpOutputJson () const
 Dump the JSON string of the output JSON object.
 
const std::vector< Calibration::ExpRun > findPayloadBoundaries (std::vector< Calibration::ExpRun > runs, int iteration=0)
 Used to discover the ExpRun boundaries that you want the Python CAF to execute on. This is optional and only used in some.
 
template<>
std::shared_ptr< TTree > getObjectPtr (const std::string &name, const std::vector< Calibration::ExpRun > &requestedRuns)
 Specialization of getObjectPtr<TTree>.
 

Protected Member Functions

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

Protected Attributes

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

Private Member Functions

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

std::string m_outputName = "eclGammaGammaEAlgorithm.root"
 ..Parameters to control Novosibirsk fit to energy deposited in each crystal by mu+mu- events More...
 
int m_cellIDLo = 1
 First cellID to be fit.
 
int m_cellIDHi = ECLElementNumbers::c_NCrystals
 Last cellID to be fit.
 
int m_minEntries = 150
 Minimum entries to fit a crystal.
 
int m_highStatEntries = 25000
 Adjust fit range above this many entries.
 
int m_maxIterations = 10
 no more than maxIteration iterations
 
double m_tRatioMinNom
 Fit range is adjusted so that fit at lower endpoint is between tRatioMin and tRatioMax of peak. More...
 
double m_tRatioMaxNom = 0.70
 Fit range is adjusted so that fit at lower endpoint is between tRatioMin and tRatioMax of peak.
 
double m_tRatioMinHiStat
 Fit range is adjusted so that fit at lower endpoint is between tRatioMin and tRatioMax of peak. More...
 
double m_tRatioMaxHiStat
 Fit range is adjusted so that fit at lower endpoint is between tRatioMin and tRatioMax of peak. More...
 
double m_upperEdgeThresh = 0.02
 Upper edge is where the fit = upperEdgeThresh * peak value.
 
bool m_performFits = true
 if false, input histograms are copied to output, but no fits are done
 
bool m_findExpValues
 if true, fits are used to find expected energy deposit for each crystal instead of the calibration constant More...
 
int m_storeConst = 0
 controls which values are written to the database. More...
 
int fitOK = 16
 Characterize fit status. More...
 
int iterations = 8
 fit reached max number of iterations, but is useable
 
int atLimit = 4
 a parameter is at the limit; upper edge is found from histogram, not fit
 
int poorFit = 3
 low chi square; upper edge is found from histogram, not fit
 
int noPeak = 2
 Novosibirsk component of fit is negligible; upper edge is found from histogram, not fit.
 
int notFit = -1
 no fit performed; no constants found for this crystal
 
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

Calibrate ecl crystals using gamma pair events.

Definition at line 25 of file eclGammaGammaEAlgorithm.h.

Member Enumeration Documentation

◆ EResult

enum EResult
inherited

The result of calibration.

Enumerator
c_OK 

Finished successfuly =0 in Python.

c_Iterate 

Needs iteration =1 in Python.

c_NotEnoughData 

Needs more data =2 in Python.

c_Failure 

Failed =3 in Python.

c_Undefined 

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

Definition at line 40 of file CalibrationAlgorithm.h.

Constructor & Destructor Documentation

◆ eclGammaGammaEAlgorithm()

..Constructor


Definition at line 58 of file eclGammaGammaEAlgorithm.cc.

58  : CalibrationAlgorithm("eclGammaGammaECollector")
59 {
61  "Perform energy calibration of ecl crystals by fitting a Novosibirsk function to energy deposited by photons in e+e- --> gamma gamma"
62  );
63 }
void setDescription(const std::string &description)
Set algorithm description (in constructor)
CalibrationAlgorithm(const std::string &collectorModuleName)
Constructor - sets the prefix for collected objects (won't be accesses until execute(....

Member Function Documentation

◆ calibrate()

CalibrationAlgorithm::EResult calibrate ( )
overrideprotectedvirtual

..Run algorithm on events


ranges of various fit parameters, and tolerance to determine that fit is at the limit

Put root into batch mode so that we don't try to open a graphics window


Write out the job parameters


Clean up existing histograms if necessary


Histograms containing the data collected by eclGammaGammaECollectorModule


Record the number of entries per crystal in the normalized energy histogram and calculate the average expected energy per crystal and calibration constants from Collector


Write out the basic histograms in all cases


If we have not been asked to do fits, we can quit now


Check that every crystal has enough entries, if so requested

Insufficient data. Quit if we are required to have a successful fit for every crystal


Some prep for the many fits about to follow

histograms to store results for database

Diagnostic histograms

1D summary histograms


Fits are requested and there is sufficient data. Loop over specified crystals and performs fits to the amplitude distributions

Project 1D histogram of energy in this crystal

Fit function (xmin, xmax, nparameters) for this histogram

Estimate initial parameters from the histogram. For peak, use maximum bin in the allowed range

Fit range is just below peak to the histogram maximum

eta and constant are nominal values

Parameters to control iterations. dIter checks if we are stuck in a loop

Use a smaller fit range for high statistics histograms


Iterate from this point

Set the initial parameters

Fit

The lower fit range should correspond the specified fraction of the peak. Iterate if necessary.

Check if we are oscillating between two end points

Many iterations may mean we are stuck in a loop. Try a different end point.

Set the constant term to 0 if we are close to the limit

No more than specified number of iterations


..Manually calculate a more meaningful fit probability. Same as P option in fit, which cannot be used with L

only include this bin if meaningful


Fit status

No peak; normalization of Novo component is too small

poor fit, or relatively poor fit with too many iterations

parameter at limit


Find upper edge of Novosibirsk fit, if possible

Look for the fit to drop to specified fraction of peak.

bins on either side of this value

look for the target value between these two points

Fit was not successful despite sufficient statistics; find upper edge from bin contents


fill diagnostic histograms

1D summary histograms

Store histogram with fit


Interpret results of fit as expected energy or calibration constant

if no fit, set upperEdge to -1, so that output calib = -1 * abs(input calib)

Find expected energies from MC, if requested

Otherwise, calibration constant


Write output to DB if requested and successful

Store expected energies

Store calibration constants


Write out diagnostic histograms

Histograms containing values written to DB


Clean up histograms in case Algorithm is called again


Set the return code appropriately

Implements CalibrationAlgorithm.

Definition at line 65 of file eclGammaGammaEAlgorithm.cc.

◆ 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.

◆ 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.

◆ execute()

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.

◆ getCollectorName()

std::string getCollectorName ( ) const
inlineinherited

Alias for prefix.

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

Definition at line 164 of file CalibrationAlgorithm.h.

◆ 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.

◆ 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.

Member Data Documentation

◆ fitOK

int fitOK = 16
private

Characterize fit status.

fit is OK

Definition at line 144 of file eclGammaGammaEAlgorithm.h.

◆ m_findExpValues

bool m_findExpValues
private
Initial value:
=
false

if true, fits are used to find expected energy deposit for each crystal instead of the calibration constant

Definition at line 136 of file eclGammaGammaEAlgorithm.h.

◆ m_outputName

std::string m_outputName = "eclGammaGammaEAlgorithm.root"
private

..Parameters to control Novosibirsk fit to energy deposited in each crystal by mu+mu- events

file name for histogram output

Definition at line 121 of file eclGammaGammaEAlgorithm.h.

◆ m_storeConst

int m_storeConst = 0
private

controls which values are written to the database.

0 : store value found by successful fits, or -|input value| otherwise; -1 : do not store values 1 : store values if every fit for [cellIDLo,cellIDHi] was successful

Definition at line 138 of file eclGammaGammaEAlgorithm.h.

◆ m_tRatioMaxHiStat

double m_tRatioMaxHiStat
private
Initial value:
=
0.95

Fit range is adjusted so that fit at lower endpoint is between tRatioMin and tRatioMax of peak.

Definition at line 132 of file eclGammaGammaEAlgorithm.h.

◆ m_tRatioMinHiStat

double m_tRatioMinHiStat
private
Initial value:
=
0.70

Fit range is adjusted so that fit at lower endpoint is between tRatioMin and tRatioMax of peak.

Definition at line 130 of file eclGammaGammaEAlgorithm.h.

◆ m_tRatioMinNom

double m_tRatioMinNom
private
Initial value:
=
0.45

Fit range is adjusted so that fit at lower endpoint is between tRatioMin and tRatioMax of peak.

Definition at line 127 of file eclGammaGammaEAlgorithm.h.


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