10#include <klm/eklm/calibration/EKLMAlignmentAlongStripsAlgorithm.h>
13#include <klm/eklm/geometry/GeometryData.h>
21static bool compareSegmentSignificance(
22 const std::pair<int, double>& first,
const std::pair<int, double>& second)
24 return first.second > second.second;
40 int i, n, nSections, nSectors, nLayers, nDetectorLayers, nPlanes, nSegments;
42 int segment, segmentGlobal;
43 std::vector<std::pair<int, double> > segmentSignificance;
44 std::vector<std::pair<int, double> >::iterator it;
45 int iSection, iLayer, iSector, iPlane, iSegment;
46 int**** *nHits, *** *averageHits;
47 double nHitsSegment, nHitsAverage, nSigma;
51 struct Event*
event =
nullptr;
52 std::shared_ptr<TTree> t_in = getObjectPtr<TTree>(
"calibration_data");
53 t_in->SetBranchAddress(
"event", &event);
59 nHits =
new int**** [nSections];
60 averageHits =
new int** *[nSections];
61 for (iSection = 0; iSection < nSections; iSection++) {
62 nHits[iSection] =
new int** *[nLayers];
63 averageHits[iSection] =
new int** [nLayers];
64 for (iLayer = 0; iLayer < nLayers; iLayer++) {
65 nHits[iSection][iLayer] =
new int** [nSectors];
66 averageHits[iSection][iLayer] =
new int* [nPlanes];
67 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
68 averageHits[iSection][iLayer][iPlane] =
new int[nSegments];
69 for (iSegment = 0; iSegment < nSegments; iSegment++) {
70 averageHits[iSection][iLayer][iPlane][iSegment] = 0;
73 for (iSector = 0; iSector < nSectors; iSector++) {
74 nHits[iSection][iLayer][iSector] =
new int* [nPlanes];
75 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
76 nHits[iSection][iLayer][iSector][iPlane] =
new int[nSegments];
77 for (iSegment = 0; iSegment < nSegments; iSegment++) {
78 nHits[iSection][iLayer][iSector][iPlane][iSegment] = 0;
84 n = t_in->GetEntries();
85 for (i = 0; i < n; i++) {
88 nHits[
event->section - 1][
event->layer - 1][
event->sector - 1]
89 [
event->plane - 1][segment]++;
90 averageHits[
event->section - 1][
event->layer - 1]
93 for (iSection = 0; iSection < nSections; iSection++) {
94 for (iLayer = 0; iLayer < nLayers; iLayer++) {
95 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
96 for (iSegment = 0; iSegment < nSegments; iSegment++) {
97 averageHits[iSection][iLayer][iPlane][iSegment] /= nSectors;
102 for (iSection = 0; iSection < nSections; iSection++) {
104 for (iLayer = 0; iLayer < nDetectorLayers; iLayer++) {
105 for (iSector = 0; iSector < nSectors; iSector++) {
106 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
107 for (iSegment = 0; iSegment < nSegments; iSegment++) {
109 iSection + 1, iLayer + 1, iSector + 1, iPlane + 1,
111 nHitsSegment = nHits[iSection][iLayer][iSector][iPlane][iSegment];
112 nHitsAverage = averageHits[iSection][iLayer]
115 nSigma = (nHitsSegment - nHitsAverage) /
116 sqrt(nHitsSegment + nHitsAverage -
117 2.0 / nSectors *
sqrt(nHitsSegment * nHitsAverage));
118 segmentSignificance.push_back(
119 std::pair<int, double>(segmentGlobal, nSigma));
125 sort(segmentSignificance.begin(), segmentSignificance.end(),
126 compareSegmentSignificance);
127 printf(
"Checking for significantly shifted segments:\n");
129 for (it = segmentSignificance.begin(); it != segmentSignificance.end();
131 if (it->second < 3.0)
134 it->first, &iSection, &iLayer, &iSector, &iPlane, &iSegment);
135 printf(
"Segment %d (section %d, layer %d, sector %d, plane %d, segment %d):"
136 " %.1f sigma\n", it->first, iSection, iLayer, iSector, iPlane,
137 iSegment, it->second);
141 printf(
"none found.\n");
142 for (iSection = 0; iSection < nSections; iSection++) {
143 for (iLayer = 0; iLayer < nLayers; iLayer++) {
144 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
145 delete[] averageHits[iSection][iLayer][iPlane];
147 for (iSector = 0; iSector < nSectors; iSector++) {
148 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
149 delete[] nHits[iSection][iLayer][iSector][iPlane];
151 delete[] nHits[iSection][iLayer][iSector];
153 delete[] nHits[iSection][iLayer];
154 delete[] averageHits[iSection][iLayer];
156 delete[] nHits[iSection];
157 delete[] averageHits[iSection];
160 delete[] averageHits;
162 TFile* f_out =
new TFile(
m_OutputFile.c_str(),
"recreate");
163 TTree* t_out =
new TTree(
"tree",
"");
164 t_out->Branch(
"event", event);
165 n = t_in->GetEntries();
166 for (i = 0; i < n; i++) {
186 if (sector == 1 || sector == 4)
Base class for calibration algorithms.
EResult
The result of calibration.
@ c_OK
Finished successfully =0 in Python.
std::string m_OutputFile
Output file name.
EKLMAlignmentAlongStripsAlgorithm()
Constructor.
~EKLMAlignmentAlongStripsAlgorithm()
Destructor.
void setOutputFile(const char *outputFile)
Set output file name.
CalibrationAlgorithm::EResult calibrate() override
Calibration.
int getAveragedPlane(int sector, int plane) const
Get plane number for average values (0-based).
static const EKLMElementNumbers & Instance()
Instantiation.
static constexpr int getNStripsSegment()
Get number of strips in a segment.
int segmentNumber(int section, int layer, int sector, int plane, int segment) const
Get segment number.
void segmentNumberToElementNumbers(int segmentGlobal, int *section, int *layer, int *sector, int *plane, int *segment) const
Get element numbers by segment global number.
int getNPlanes() const
Get number of planes.
int getNSections() const
Get number of sections.
int getNLayers() const
Get number of layers.
int getNDetectorLayers(int section) const
Get number of detector layers.
int getNSegments() const
Get number of segments.
int getNSectors() const
Get number of sectors.
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.
Event: time, distance from hit to SiPM.