File indexing completed on 2024-04-06 12:30:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "SimG4CMS/Forward/interface/TotemNumberMerger.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018
0019
0020
0021
0022 TotemNumberMerger ::TotemNumberMerger() {
0023 #ifdef SCRIVI
0024 LogDebug("ForwardSim") << "Creating TotemNumberMerger";
0025 #endif
0026 }
0027
0028 TotemNumberMerger ::~TotemNumberMerger() {
0029 #ifdef SCRIVI
0030 LogDebug("ForwardSim") << "Destruction of TotemNumberMerger";
0031 #endif
0032 }
0033
0034
0035
0036
0037
0038 unsigned long TotemNumberMerger ::Merge(unsigned long value1, unsigned long value2) const {
0039 unsigned long c(value1 + value2);
0040 unsigned long result(((c * (c + 1)) >> 1) + value1);
0041
0042 #ifdef SCRIVI
0043 LogDebug("ForwardSim") << "Merge(value1=" << value1 << ", value2=" << value2 << ")=" << result;
0044
0045 unsigned long invValue1, invValue2;
0046 Split(result, invValue1, invValue2);
0047
0048 assert(invValue1 == value1);
0049 assert(invValue2 == value2);
0050 #endif
0051
0052 return result;
0053 }
0054
0055 unsigned long TotemNumberMerger ::Merge(unsigned long value1, unsigned long value2, unsigned long value3) const {
0056 return Merge(Merge(value1, value2), value3);
0057 }
0058
0059 unsigned long TotemNumberMerger ::Merge(unsigned long value1,
0060 unsigned long value2,
0061 unsigned long value3,
0062 unsigned long value4) const {
0063 return Merge(Merge(value1, value2), Merge(value3, value4));
0064 }
0065
0066 void TotemNumberMerger ::Split(unsigned long source, unsigned long &value1, unsigned long &value2) const {
0067 unsigned long c(static_cast<unsigned long>(floor(sqrt(1. + 8. * static_cast<float>(source)) * 0.5 - 0.5)));
0068
0069 value1 = source - ((c * (c + 1)) >> 1);
0070 value2 = c - value1;
0071
0072 #ifdef SCRIVI
0073 LogDebug("ForwardSim") << "source=" << source << ", c=" << c << ", value1=" << value1 << ", value2=" << value2;
0074 #endif
0075 }
0076
0077 void TotemNumberMerger ::Split(unsigned long source,
0078 unsigned long &value1,
0079 unsigned long &value2,
0080 unsigned long &value3) const {
0081 unsigned long mix12;
0082
0083 Split(source, mix12, value3);
0084 Split(mix12, value1, value2);
0085 }
0086
0087 void TotemNumberMerger ::Split(unsigned long source,
0088 unsigned long &value1,
0089 unsigned long &value2,
0090 unsigned long &value3,
0091 unsigned long &value4) const {
0092 unsigned long mix12, mix34;
0093
0094 Split(source, mix12, mix34);
0095 Split(mix12, value1, value2);
0096 Split(mix34, value3, value4);
0097 }