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;
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++) {