00001 // Dear emacs, this is -*- c++ -*- 00002 #ifndef XAODPRIMITIVES_ISOLATIONHELPERS_H 00003 #define XAODPRIMITIVES_ISOLATIONHELPERS_H 00004 00005 #include "xAODPrimitives/IsolationType.h" 00006 #include "xAODPrimitives/IsolationConeSize.h" 00007 #include "xAODPrimitives/IsolationFlavour.h" 00008 #include <cmath> 00009 #include <cassert> 00010 #include <iostream> 00011 00012 namespace xAOD { 00013 00014 namespace Iso { 00015 00017 inline IsolationConeSize enumconeSize( IsolationType type ){ 00018 return static_cast<IsolationConeSize>(type%10); 00019 } 00020 00022 inline float coneSize( IsolationConeSize type ){ 00023 return 0.1 + (static_cast<int>(type))*0.05; 00024 } 00025 00027 inline IsolationConeSize coneSize( float size ){ 00028 int index = static_cast<int>(size*20)-2; // *20 equiv. to /0.05; 00029 assert ( (index>-1) && (index < static_cast<int>(numIsolationConeSizes) ) ); 00030 IsolationConeSize rel = static_cast<IsolationConeSize>(index); 00031 assert ( fabs(size-coneSize(rel) )<0.0001 ); // this will fail if the input size is 0.3001... 00032 return rel; 00033 } 00034 00036 inline float coneSize( IsolationType type ){ 00037 IsolationConeSize size = enumconeSize(type); 00038 return coneSize(size); 00039 } 00040 00042 inline IsolationFlavour isolationFlavour( IsolationType type ){ 00043 int subtype = type/10; 00044 if( subtype >= static_cast<int>(numIsolationFlavours) ) return numIsolationFlavours; 00045 return static_cast<IsolationFlavour>(subtype); 00046 } 00047 00048 // create a IsolationType from IsolationFlavour and IsolationConeSize 00049 inline IsolationType isolationType( IsolationFlavour flavour, IsolationConeSize coneSize ) { 00050 return static_cast<IsolationType>( 10*static_cast<int>(flavour) + static_cast<int>(coneSize) ); 00051 } 00052 00053 } // namespace Iso 00054 00055 00056 } // namespace xAOD 00057 00058 #endif // XAODPRIMITIVES_ISOLATIONHELPERS_H 00059