8 : fDistance(distance), fFolding(folding), fGrouping(grouping), fAddback(addback)
10 SetName(
"GriffinAngles");
14 if(settings !=
nullptr) {
18 }
catch(std::out_of_range&) {}
21 }
catch(std::out_of_range&) {}
25 }
catch(std::out_of_range&) {}
27 std::cout <<
"Failed to find user settings in TGRSIOptions, can't get user settings for excluded detectors/crystals" << std::endl;
30 std::cout <<
"Failed to find TGRSIOptions, can't get user settings for excluded detectors/crystals" << std::endl;
35 std::cout <<
DRED <<
"Warning, grouping is only possible if folding is also active. Setting folding to true!" <<
RESET_COLOR << std::endl;
39 std::cout <<
"Creating angles for detectors " <<
fDistance <<
" mm from center of array, " << (
fAddback ?
"" :
"not ") <<
"using addback, " << (
fFolding ?
"" :
"not ") <<
"using folding, and " << (
fGrouping ?
"" :
"not ") <<
"using grouping. Any angles less than " <<
fRounding <<
" degrees apart will be considered the same." << std::endl;
42 for(
int firstDet = 1; firstDet <= 16; ++firstDet) {
44 for(
int firstCry = 0; firstCry < 4; ++firstCry) {
46 for(
int secondDet = 1; secondDet <= 16; ++secondDet) {
48 for(
int secondCry = 0; secondCry < 4; ++secondCry) {
51 if(firstDet == secondDet && (firstCry == secondCry ||
fAddback)) {
continue; }
89 std::ostringstream str;
91 throw std::runtime_error(str.str());
94 std::ostringstream str;
96 throw std::runtime_error(str.str());
99 std::ostringstream str;
101 throw std::runtime_error(str.str());
104 auto end = std::unique(tmp.begin(), tmp.end());
106 std::ostringstream str;
107 str <<
DRED <<
"Custom grouping with " <<
fCustomGrouping.size() <<
" entries supplied, but the last entry is " <<
fCustomGrouping[0] <<
" which does not match the number of unique groups minus one (" <<
end - tmp.begin() - 1 <<
")!" <<
RESET_COLOR;
108 throw std::runtime_error(str.str());
111 fCustomGrouping = {0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10};
113 fCustomGrouping = {0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11};
115 std::ostringstream str;
116 str <<
DRED <<
"No custom grouping supplied and distance is not 110 mm or 145 mm, but " <<
fDistance <<
"!" <<
RESET_COLOR;
117 throw std::runtime_error(str.str());
122 std::set<double> groupedAngles;
124 double previousAngle = *angle;
127 groupedAngles.insert(previousAngle);
130 previousAngle = *angle;
133 groupedAngles.insert(previousAngle);
175#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
177 std::cout <<
"-------------------- original --------------------" << std::endl;
178 for(
int i = 0; i < z0->GetN(); ++i) {
179 std::cout << std::setw(8) << z0->GetPointX(i) <<
": " << std::setw(8) << z0->GetPointY(i) <<
" " << std::setw(8) << z2->GetPointY(i) <<
" " << std::setw(8) << z4->GetPointY(i) << std::endl;
181 std::cout <<
"--------------------------------------------------" << std::endl;
188 auto* angle0 = z0->GetX();
189 auto* angle2 = z2->GetX();
190 auto* angle4 = z4->GetX();
191 for(
int i = 0; i < z0->GetN(); ++i) {
192 if(angle0[i] > 90.) {
193#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
195 std::cout << i <<
": Folding from " << std::setw(8) << z0->GetPointX(i) <<
" " << std::setw(8) << z2->GetPointX(i) <<
" " << std::setw(8) << z4->GetPointX(i);
198 angle0[i] = 180. - angle0[i];
199 angle2[i] = angle0[i];
200 angle4[i] = angle0[i];
201#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
203 std::cout <<
" to " << std::setw(8) << z0->GetPointX(i) <<
" " << std::setw(8) << z2->GetPointX(i) <<
" " << std::setw(8) << z4->GetPointX(i) << std::endl;
211#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
213 std::cout <<
"-------------------- sorted --------------------" << std::endl;
214 for(
int i = 0; i < z0->GetN(); ++i) {
215 std::cout << std::setw(8) << z0->GetPointX(i) <<
": " << std::setw(8) << z0->GetPointY(i) <<
" " << std::setw(8) << z2->GetPointY(i) <<
" " << std::setw(8) << z4->GetPointY(i) << std::endl;
217 std::cout <<
"------------------------------------------------" << std::endl;
221 auto* counts0 = z0->GetY();
222 auto* errors0 = z0->GetEY();
223 auto* counts2 = z2->GetY();
224 auto* errors2 = z2->GetEY();
225 auto* counts4 = z4->GetY();
226 auto* errors4 = z4->GetEY();
227 for(
int i = 1; i < z0->GetN(); ++i) {
228 if(std::abs(angle0[i] - angle0[i - 1]) <
fRounding) {
230 std::cout << i <<
": Adding angles " << angle0[i - 1] <<
" and " << angle0[i] << std::endl;
233 counts0[i - 1] += counts0[i];
234 counts0[i - 1] /= 2.;
235 errors0[i - 1] = TMath::Sqrt(TMath::Power(errors0[i - 1], 2) + TMath::Power(errors0[i], 2)) / 2.;
236 counts2[i - 1] += counts2[i];
237 counts2[i - 1] /= 2.;
238 errors2[i - 1] = TMath::Sqrt(TMath::Power(errors2[i - 1], 2) + TMath::Power(errors2[i], 2)) / 2.;
239 counts4[i - 1] += counts4[i];
240 counts4[i - 1] /= 2.;
241 errors4[i - 1] = TMath::Sqrt(TMath::Power(errors4[i - 1], 2) + TMath::Power(errors4[i], 2)) / 2.;
246 counts0 = z0->GetY();
247 errors0 = z0->GetEY();
248 counts2 = z2->GetY();
249 errors2 = z2->GetEY();
250 counts4 = z4->GetY();
251 errors4 = z4->GetEY();
255 std::cout << i <<
": Not adding angles " << angle0[i - 1] <<
" and " << angle0[i] << std::endl;
260#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
262 std::cout <<
"-------------------- after folding --------------------" << std::endl;
263 for(
int i = 0; i < z0->GetN(); ++i) {
264 std::cout << std::setw(8) << z0->GetPointX(i) <<
": " << std::setw(8) << z0->GetPointY(i) <<
" " << std::setw(8) << z2->GetPointY(i) <<
" " << std::setw(8) << z4->GetPointY(i) << std::endl;
266 std::cout <<
"-------------------------------------------------------" << std::endl;
274 auto* counts0 = z0->GetY();
275 auto* errors0 = z0->GetEY();
276 auto* counts2 = z2->GetY();
277 auto* errors2 = z2->GetEY();
278 auto* counts4 = z4->GetY();
279 auto* errors4 = z4->GetEY();
280 for(
int i = 0; i < z0->GetN(); ++i) {
284#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
286 std::cout << i <<
": Leaving as is " << z0->GetPointX(i) <<
": " << std::setw(8) << z0->GetPointY(i) <<
" " << std::setw(8) << z2->GetPointY(i) <<
" " << std::setw(8) << z4->GetPointY(i) << std::endl;
295#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
297 std::cout << i <<
": Grouping " << z0->GetPointX(i) <<
" and " << z0->GetPointX(i + 1) <<
" from " << std::setw(8) << z0->GetPointY(i) <<
" " << std::setw(8) << z2->GetPointY(i) <<
" " << std::setw(8) << z4->GetPointY(i);
300 counts0[i + 1] += counts0[i];
301 counts0[i + 1] /= 2.;
302 errors0[i + 1] = TMath::Sqrt(TMath::Power(errors0[i], 2) + TMath::Power(errors0[i + 1], 2)) / 2.;
303 counts2[i + 1] += counts2[i];
304 counts2[i + 1] /= 2.;
305 errors2[i + 1] = TMath::Sqrt(TMath::Power(errors2[i], 2) + TMath::Power(errors2[i + 1], 2)) / 2.;
306 counts4[i + 1] += counts4[i];
307 counts4[i + 1] /= 2.;
308 errors4[i + 1] = TMath::Sqrt(TMath::Power(errors4[i], 2) + TMath::Power(errors4[i + 1], 2)) / 2.;
312 counts0 = z0->GetY();
313 errors0 = z0->GetEY();
314 counts2 = z2->GetY();
315 errors2 = z2->GetEY();
316 counts4 = z4->GetY();
317 errors4 = z4->GetEY();
318#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
320 std::cout <<
" to " << z0->GetPointX(i) <<
" with " << std::setw(8) << z0->GetPointY(i) <<
" " << std::setw(8) << z2->GetPointY(i) <<
" " << std::setw(8) << z4->GetPointY(i) << std::endl;
327#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
329 std::cout << i <<
": Grouping " << z0->GetPointX(i) <<
", " << z0->GetPointX(i + 1) <<
", and " << z0->GetPointX(i + 2) <<
" from " << std::setw(8) << z0->GetPointY(i) <<
" " << std::setw(8) << z2->GetPointY(i) <<
" " << std::setw(8) << z4->GetPointY(i);
332 counts0[i + 2] += counts0[i] + counts0[i + 1];
333 counts0[i + 2] /= 3.;
334 errors0[i + 2] = TMath::Sqrt(TMath::Power(errors0[i], 2) + TMath::Power(errors0[i + 1], 2) + TMath::Power(errors0[i + 2], 2)) / 3.;
335 counts2[i + 2] += counts2[i] + counts2[i + 1];
336 counts2[i + 2] /= 3.;
337 errors2[i + 2] = TMath::Sqrt(TMath::Power(errors2[i], 2) + TMath::Power(errors2[i + 1], 2) + TMath::Power(errors0[i + 2], 2)) / 3.;
338 counts4[i + 2] += counts4[i] + counts4[i + 1];
339 counts4[i + 2] /= 3.;
340 errors4[i + 2] = TMath::Sqrt(TMath::Power(errors4[i], 2) + TMath::Power(errors4[i + 1], 2) + TMath::Power(errors0[i + 2], 2)) / 3.;
344 z0->RemovePoint(i + 1);
345 z2->RemovePoint(i + 1);
346 z4->RemovePoint(i + 1);
347 counts0 = z0->GetY();
348 errors0 = z0->GetEY();
349 counts2 = z2->GetY();
350 errors2 = z2->GetEY();
351 counts4 = z4->GetY();
352 errors4 = z4->GetEY();
353#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
355 std::cout <<
" to " << z0->GetPointX(i) <<
" with " << std::setw(8) << z0->GetPointY(i) <<
" " << std::setw(8) << z2->GetPointY(i) <<
" " << std::setw(8) << z4->GetPointY(i) << std::endl;
363#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 20, 0)
365 std::cout <<
"-------------------- after folding and grouping --------------------" << std::endl;
366 for(
int i = 0; i < z0->GetN(); ++i) {
367 std::cout << std::setw(8) << z0->GetPointX(i) <<
": " << std::setw(8) << z0->GetPointY(i) <<
" " << std::setw(8) << z2->GetPointY(i) <<
" " << std::setw(8) << z4->GetPointY(i) << std::endl;
369 std::cout <<
"--------------------------------------------------------------------" << std::endl;