Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:01

0001 // -*- C++ -*-
0002 //
0003 // Package:     Forward
0004 // Class  :     TotemNumberMerger
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  R. Capra
0010 //         Created:  Tue May 16 10:14:34 CEST 2006
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "SimG4CMS/Forward/interface/TotemNumberMerger.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 
0019 //
0020 // constructors and destructor
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 // member functions
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 }