9#include <pxd/calibration/PXDValidationAlgorithm.h>
18#include <boost/format.hpp>
34 void getNumberOfBins(
const std::shared_ptr<TH1I>& histo_ptr,
unsigned short& nBinsU,
unsigned short& nBinsV)
36 set<unsigned short> uBinSet;
37 set<unsigned short> vBinSet;
40 for (
auto histoBin = 1; histoBin <= histo_ptr->GetXaxis()->GetNbins(); histoBin++) {
42 string label = histo_ptr->GetXaxis()->GetBinLabel(histoBin);
45 istringstream stream(label);
47 getline(stream, token,
'_');
48 getline(stream, token,
'_');
49 unsigned short uBin = std::stoi(token);
51 getline(stream, token,
'_');
52 unsigned short vBin = std::stoi(token);
58 if (uBinSet.empty() || vBinSet.empty()) {
59 B2FATAL(
"Not able to determine the grid size. Something is wrong with collected data.");
61 nBinsU = *uBinSet.rbegin() + 1;
62 nBinsV = *vBinSet.rbegin() + 1;
69 set<unsigned short> sensorSet;
72 for (
auto histoBin = 1; histoBin <= histo_ptr->GetXaxis()->GetNbins(); histoBin++) {
74 string label = histo_ptr->GetXaxis()->GetBinLabel(histoBin);
77 istringstream stream(label);
79 getline(stream, token,
'_');
80 VxdID sensorID(token);
81 sensorSet.insert(sensorID.getID());
83 return sensorSet.size();
97 " -------------------------- PXDValidationAlgorithm ---------------------------------\n"
99 " Algorithm for filling validation histograms. \n"
100 " ----------------------------------------------------------------------------------------\n"
122 m_exp = expRuns.back().first;
123 m_run = expRuns.back().second;
124 B2INFO(
"Current ExpRuns: [("
125 << expRuns.front().first <<
", " << expRuns.front().second <<
"), ("
137 auto nSensors = getNumberOfSensors(cluster_counter);
140 unsigned short nBinsU = 0;
141 unsigned short nBinsV = 0;
142 getNumberOfBins(cluster_counter, nBinsU, nBinsV);
145 B2INFO(
"Start info collection using a " << nBinsU <<
"x" << nBinsV <<
" grid per sensor.");
146 B2INFO(
"Number of collected track points is " << point_counter->GetEntries()
147 <<
" in " << nSensors <<
" sensors.");
150 B2WARNING(
"Not enough Data: Only " << point_counter->GetEntries() <<
" hits were collected but " <<
minTrackPoints
166 TDirectory* currentDir = gDirectory;
171 std::string fileName = (this->
getPrefix()) +
"Validation.root";
172 B2INFO(
"Creating file " << fileName);
173 m_file = std::make_shared<TFile>(fileName.c_str(),
"RECREATE");
179 B2INFO(
"Creating TTree.");
180 m_tree = std::make_shared<TTree>(
"tree",
"PXD validation data");
183 m_hD0 =
new TH1F(
"hD0",
"Corrected d0;#Delta d0/#sqrt{2} [cm];Counts",
binsD0Z0, -0.03, 0.03);
184 m_hZ0 =
new TH1F(
"hZ0",
"Corrected z0;#Delta z0/#sqrt{2} [cm];Counts",
binsD0Z0, -0.03, 0.03);
244 tree_d0z0->SetBranchAddress(
"d0", &d0);
245 tree_d0z0->SetBranchAddress(
"z0", &z0);
250 for (
int i = 0; i < tree_d0z0->GetEntries(); i++) {
251 tree_d0z0->GetEntry(i);
253 m_d0.emplace_back(d0);
254 m_z0.emplace_back(z0);
256 if (fabs(d0) > 0.03 || fabs(z0) > 0.03)
264 for (
auto histoBin = 1; histoBin <= cluster_counter->GetXaxis()->GetNbins(); histoBin++) {
266 string label = cluster_counter->GetXaxis()->GetBinLabel(histoBin);
269 istringstream stream(label);
271 getline(stream, token,
'_');
272 VxdID sensorID(token);
274 getline(stream, token,
'_');
275 unsigned short uBin = std::stoi(token);
277 getline(stream, token,
'_');
278 unsigned short vBin = std::stoi(token);
281 int numberOfClusters = cluster_counter->GetBinContent(histoBin);
282 int numberOfPoints = point_counter->GetBinContent(histoBin);
285 m_uBin.emplace_back(uBin);
286 m_vBin.emplace_back(vBin);
296 if (
m_exp == expRunsAll.back().first &&
297 m_run == expRunsAll.back().second) {
298 B2INFO(
"Reached Final ExpRun: (" <<
m_exp <<
", " <<
m_run <<
")");
301 B2INFO(
"Writing Successful.");
326 B2INFO(
"This is the first run encountered, let's say it is a boundary.");
std::vector< Calibration::ExpRun > m_boundaries
When using the boundaries functionality from isBoundaryRequired, this is used to store the boundaries...
std::vector< Calibration::ExpRun > getRunListFromAllData() const
Get the complete list of runs from inspection of collected data.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
std::string getPrefix() const
Get the prefix used for getting calibration data.
EResult
The result of calibration.
@ c_OK
Finished successfully =0 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
@ c_Failure
Failed =3 in Python.
CalibrationAlgorithm(const std::string &collectorModuleName)
Constructor - sets the prefix for collected objects (won't be accesses until execute(....
TH1F * m_hD0
Histogram of corrected d0 for each 2-track event.
TH2F * m_hTrackPointsLayer2
Histogram of intersection points for layer 2.
TH2F * m_hTrackClustersLayer1
Histogram of track matched clusters for layer 1.
TH2F * m_hTrackPointsLayer1
Histogram of intersection points for layer 1.
std::vector< unsigned long > m_nTrackClusters
Vector of number of track matched clusters.
virtual ~PXDValidationAlgorithm() override
Destructor.
TH2F * m_hTrackClustersLayer2
Histogram of track matched clusters for layer 2.
std::vector< unsigned long > m_nTrackPoints
Vector of number of track points.
std::vector< float > m_z0
Vector of delta z0 over sqrt(2)
bool saveD0Z0
Flag to save delta d0 (z0) over sqrt(2) to TTree;.
int m_exp
Experiment number.
std::vector< unsigned long > m_nSelTrackPoints
Vector of number of track points outside of defective pixels.
PXDValidationAlgorithm()
Constructor set the prefix to PXDValidationAlgorithm.
int minTrackPoints
Minimum number of track points per sensor.
std::shared_ptr< TFile > m_file
Pointer for TFile.
bool save2DHists
Flag to save 2D histograms for efficiency;.
std::vector< unsigned short > m_uBin
Vector of uBin.
std::vector< float > m_d0
Vector of delta d0 over sqrt(2)
virtual EResult calibrate() override
Run algo on data.
int binsD0Z0
Bin size for d0/z0 histogram.
std::vector< unsigned long > m_nSelTrackClusters
Vector of number of track clusters outside of defective pixels.
std::vector< unsigned short > m_vBin
Vector of vBin.
std::shared_ptr< TTree > m_tree
Pointer for TTree of the validation info.
virtual bool isBoundaryRequired(const Calibration::ExpRun &) override
Decide if a run should be a payload boundary. Only used in certain Python Algorithm Starategies.
TH1F * m_hZ0
Histogram of corrected z0 for each 2-track event.
std::vector< unsigned short > m_pxdid
Vector of PXD module id (DHE id)
Class to uniquely identify a any structure of the PXD and SVD.
baseType getSensorNumber() const
Get the sensor id.
baseType getLadderNumber() const
Get the ladder id.
baseType getLayerNumber() const
Get the layer id.
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 t...
unsigned short getNumberOfSensors(const std::shared_ptr< TH1I > &histo_ptr)
Helper function to extract number of sensors from counter histogram labels.
void getNumberOfBins(const std::shared_ptr< TH1I > &histo_ptr, unsigned short &nBinsU, unsigned short &nBinsV)
Helper function to extract number of bins along u side and v side from counter histogram labels.
Abstract base class for different kinds of events.