Belle II Software  release-08-02-06
CDCDedx1DCellAlgorithm Class Reference

A calibration algorithm for CDC dE/dx electron: 1D enta cleanup correction. More...

#include <CDCDedx1DCellAlgorithm.h>

Inheritance diagram for CDCDedx1DCellAlgorithm:
Collaboration diagram for CDCDedx1DCellAlgorithm:

Public Types

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

Public Member Functions

 CDCDedx1DCellAlgorithm ()
 Constructor: Sets the description, the properties and the parameters of the algorithm.
 
virtual ~CDCDedx1DCellAlgorithm ()
 Destructor.
 
void setSuffix (const std::string &value)
 adding suffix to control plots
 
void setVariableBins (bool value)
 Set Var bins flag to on or off.
 
void setLayerTrunc (bool value=false)
 funtion to set truncation method (local vs global)
 
void setMergePayload (bool value)
 set false if generating absoulte (not relative) payload
 
void setSplitFactor (int value)
 set bin split factor for all range
 
void setRotSymmetry (bool value)
 set rotation sys to copy constants from one region to other
 
void setTrucationBins (double lowedge, double upedge)
 function to set bins of trunction from histogram
 
void enableExtraPlots (bool value=false)
 funtion to set flag active for plotting
 
void setPtLimit (double value)
 funtion to set pt limit
 
void setCosLimit (double value)
 funtion to set cos #theta limit
 
void setBaselineFactor (double charge, double factor)
 adjust baseline based on charge or global overall works for only single charge or both
 
int rotationalBin (int nbin, int ibin)
 class funtion to set rotation symmetry
 
void getExpRunInfo ()
 function to get extract calibration run/exp
 
void CreateBinMapping ()
 class function to create vectors for bin mappping (Var->symm)
 
void defineHisto (std::vector< TH1D * > hdedxhit[2], TH1D *hdedxlay[2], TH1D *hentalay[2])
 function to define histograms
 
void getTruncatedBins (TH1D *hist, int &binlow, int &binhigh)
 function to get bins of trunction from histogram
 
double getTruncationMean (TH1D *hist, int binlow, int binhigh)
 function to get truncated mean
 
void createPayload ()
 funtion to generate final constants
 
void plotMergeFactor (std::map< int, std::vector< double >> bounds, const std::array< int, 2 > nDev, std::map< int, std::vector< int >> steps)
 funtion to plot merging factor
 
void plotdedxHist (std::vector< TH1D * > hdedxhit[2])
 function to draw the dE/dx histrogram in enta bins
 
void plotLayerDist (TH1D *hdedxL[2])
 funtion to draw dedx dist. More...
 
void plotQaPars (TH1D *hentalay[2], TH2D *hptcosth)
 funtion to draw pt vs costh and entrance angle distribution for Inner/Outer layer
 
void plotRelConst (std::vector< double >tempconst, std::vector< double >layerconst, int il)
 function to draw symm/Var layer constant
 
void plotConstants ()
 function to draw the old/new final constants
 
void plotEventStats ()
 function to draw the stats plots
 
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
 1D cell algorithm
 
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

double m_eaMin
 lower edge of enta angle
 
double m_eaMax
 upper edge of enta angle
 
double m_eaBW
 binwdith of enta angle bin
 
int m_eaBin
 
double m_dedxMin
 lower edge of dedxhit
 
double m_dedxMax
 upper edge of dedxhit
 
int m_dedxBin
 
double m_ptMax
 a limit on transverse momentum

 
double m_cosMax
 a limit on cos theta

 
double m_truncMin
 lower thershold on truncation
 
double m_truncMax
 uppr thershold on truncation
 
int m_binSplit
 multiply nbins by this factor in full range
 
int m_binMerge
 merge bins by this factor in (-pi/2 <-> -pi/4) and (pi/4 <-> pi/2) region
 
double m_chargeType
 charge type for baseline adj
 
double m_adjustFac
 faactor with that one what to adjust baseline
 
bool isFixTrunc
 true = fix window for all out/inner layers
 
bool isVarBins
 true: if variable bin size is requested
 
bool isRotSymm
 if rotation symmtery requested
 
bool isMakePlots
 produce plots for status
 
bool isPrintLog
 print more debug information
 
bool isMerge
 print more debug information
 
std::string m_suffix
 add suffix to all plot name

 
std::string m_runExp
 add suffix to all plot name

 
std::string m_label [2] = {"IL", "OL"}
 add inner/outer layer label
 
std::vector< int > m_eaBinLocal
 
std::array< std::vector< int >, 2 > m_binIndex
 symm/Var bin numebrs
 
std::array< std::vector< double >, 2 > m_binValue
 etna Var bin values
 
std::vector< std::vector< double > > m_onedcors
 final vectors of calibration

 
DBObjPtr< CDCDedx1DCellm_DBOneDCell
 One cell correction DB object.
 
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

A calibration algorithm for CDC dE/dx electron: 1D enta cleanup correction.

Definition at line 39 of file CDCDedx1DCellAlgorithm.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.

Member Function Documentation

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

◆ plotLayerDist()

void plotLayerDist ( TH1D *  hdedxL[2])

funtion to draw dedx dist.

for Inner/outer layer

Definition at line 470 of file CDCDedx1DCellAlgorithm.cc.

471 {
472 
473  TCanvas cdedxlayer("layerdedxhit", "Inner and Outer Layer dedxhit dist", 900, 400);
474  cdedxlayer.Divide(2, 1);
475 
476  for (int il = 0; il < 2; il++) {
477  int minlay = 0, maxlay = 0;
478  if (isFixTrunc) {
479  minlay = std::stoi(hdedxlay[il]->GetXaxis()->GetTitle());
480  maxlay = std::stoi(hdedxlay[il]->GetYaxis()->GetTitle());
481  double lowedge = hdedxlay[il]->GetXaxis()->GetBinLowEdge(minlay);
482  double upedge = hdedxlay[il]->GetXaxis()->GetBinUpEdge(maxlay);
483  hdedxlay[il]->SetTitle(Form("%s, trunc #rightarrow: %0.02f - %0.02f;dedxhit;entries", hdedxlay[il]->GetTitle(), lowedge, upedge));
484  }
485 
486  cdedxlayer.cd(il + 1);
487  hdedxlay[il]->SetFillColor(kYellow);
488  hdedxlay[il]->Draw("histo");
489 
490  if (isFixTrunc) {
491  TH1D* hdedxlayC = (TH1D*)hdedxlay[il]->Clone(Form("hdedxlayC%d", il));
492  hdedxlayC->GetXaxis()->SetRange(minlay, maxlay);
493  hdedxlayC->SetFillColor(kAzure + 1);
494  hdedxlayC->Draw("same histo");
495  }
496  }
497 
498  cdedxlayer.SaveAs(Form("cdcdedx_1dcell_dedxlay%s.pdf", m_suffix.data()));
499  cdedxlayer.SaveAs(Form("cdcdedx_1dcell_dedxlay%s.root", m_suffix.data()));
500 }
std::string m_suffix
add suffix to all plot name
bool isFixTrunc
true = fix window for all out/inner layers

◆ 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

◆ m_dedxBin

int m_dedxBin
private

of bins for dedxhit range

Definition at line 216 of file CDCDedx1DCellAlgorithm.h.

◆ m_eaBin

int m_eaBin
private

of bins for etna angle

Definition at line 212 of file CDCDedx1DCellAlgorithm.h.

◆ m_eaBinLocal

std::vector<int> m_eaBinLocal
private

of var bins for etna angle

Definition at line 241 of file CDCDedx1DCellAlgorithm.h.


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