12 #include <klm/eklm/calibration/EKLMAlignmentAlongStripsAlgorithm.h>
15 #include <klm/eklm/geometry/GeometryData.h>
23 static bool compareSegmentSignificance(
24 const std::pair<int, double>& first,
const std::pair<int, double>& second)
26 return first.second > second.second;
42 int i, n, nSections, nSectors, nLayers, nDetectorLayers, nPlanes, nSegments;
44 int segment, segmentGlobal;
45 std::vector<std::pair<int, double> > segmentSignificance;
46 std::vector<std::pair<int, double> >::iterator it;
47 int iSection, iLayer, iSector, iPlane, iSegment;
48 int**** *nHits, *** *averageHits;
49 double nHitsSegment, nHitsAverage, nSigma;
53 struct Event*
event =
nullptr;
54 std::shared_ptr<TTree> t_in = getObjectPtr<TTree>(
"calibration_data");
55 t_in->SetBranchAddress(
"event", &event);
61 nHits =
new int**** [nSections];
62 averageHits =
new int** *[nSections];
63 for (iSection = 0; iSection < nSections; iSection++) {
64 nHits[iSection] =
new int** *[nLayers];
65 averageHits[iSection] =
new int** [nLayers];
66 for (iLayer = 0; iLayer < nLayers; iLayer++) {
67 nHits[iSection][iLayer] =
new int** [nSectors];
68 averageHits[iSection][iLayer] =
new int* [nPlanes];
69 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
70 averageHits[iSection][iLayer][iPlane] =
new int[nSegments];
71 for (iSegment = 0; iSegment < nSegments; iSegment++) {
72 averageHits[iSection][iLayer][iPlane][iSegment] = 0;
75 for (iSector = 0; iSector < nSectors; iSector++) {
76 nHits[iSection][iLayer][iSector] =
new int* [nPlanes];
77 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
78 nHits[iSection][iLayer][iSector][iPlane] =
new int[nSegments];
79 for (iSegment = 0; iSegment < nSegments; iSegment++) {
80 nHits[iSection][iLayer][iSector][iPlane][iSegment] = 0;
86 n = t_in->GetEntries();
87 for (i = 0; i < n; i++) {
90 nHits[
event->section - 1][
event->layer - 1][
event->sector - 1]
91 [
event->plane - 1][segment]++;
92 averageHits[
event->section - 1][
event->layer - 1]
95 for (iSection = 0; iSection < nSections; iSection++) {
96 for (iLayer = 0; iLayer < nLayers; iLayer++) {
97 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
98 for (iSegment = 0; iSegment < nSegments; iSegment++) {
99 averageHits[iSection][iLayer][iPlane][iSegment] /= nSectors;
104 for (iSection = 0; iSection < nSections; iSection++) {
106 for (iLayer = 0; iLayer < nDetectorLayers; iLayer++) {
107 for (iSector = 0; iSector < nSectors; iSector++) {
108 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
109 for (iSegment = 0; iSegment < nSegments; iSegment++) {
111 iSection + 1, iLayer + 1, iSector + 1, iPlane + 1,
113 nHitsSegment = nHits[iSection][iLayer][iSector][iPlane][iSegment];
114 nHitsAverage = averageHits[iSection][iLayer]
117 nSigma = (nHitsSegment - nHitsAverage) /
118 sqrt(nHitsSegment + nHitsAverage -
119 2.0 / nSectors * sqrt(nHitsSegment * nHitsAverage));
120 segmentSignificance.push_back(
121 std::pair<int, double>(segmentGlobal, nSigma));
127 sort(segmentSignificance.begin(), segmentSignificance.end(),
128 compareSegmentSignificance);
129 printf(
"Checking for significantly shifted segments:\n");
131 for (it = segmentSignificance.begin(); it != segmentSignificance.end();
133 if (it->second < 3.0)
136 it->first, &iSection, &iLayer, &iSector, &iPlane, &iSegment);
137 printf(
"Segment %d (section %d, layer %d, sector %d, plane %d, segment %d):"
138 " %.1f sigma\n", it->first, iSection, iLayer, iSector, iPlane,
139 iSegment, it->second);
143 printf(
"none found.\n");
144 for (iSection = 0; iSection < nSections; iSection++) {
145 for (iLayer = 0; iLayer < nLayers; iLayer++) {
146 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
147 delete[] averageHits[iSection][iLayer][iPlane];
149 for (iSector = 0; iSector < nSectors; iSector++) {
150 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
151 delete[] nHits[iSection][iLayer][iSector][iPlane];
153 delete[] nHits[iSection][iLayer][iSector];
155 delete[] nHits[iSection][iLayer];
156 delete[] averageHits[iSection][iLayer];
158 delete[] nHits[iSection];
159 delete[] averageHits[iSection];
162 delete[] averageHits;
164 TFile* f_out =
new TFile(
m_OutputFile.c_str(),
"recreate");
165 TTree* t_out =
new TTree(
"tree",
"");
166 t_out->Branch(
"event", event);
167 n = t_in->GetEntries();
168 for (i = 0; i < n; i++) {
188 if (sector == 1 || sector == 4)