[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: standard units in software



Hi Matt,

how do you treat stored parameters, say the particles' masses?
Do you have also default units in the header in order to treat
the stored variables, something unspecified like "m_unit", 
additionally to "m_GeV"?

Thanks,
Eugene

On Mon, 24 Nov 2008, Matthew Shepherd wrote:

>
> Sorry, there's an (obvious) typo here:
>
> Should be:
>
> bool checkEnergy( double energy ){
>
> return( energy > 30*k_MeV );
> }
>
> Eugene is right -- more CPU cycles and typing.  But I think readability and 
> odds of making a mistake and introducing a bug are greatly reduced.
>
> -Matt
>
> On Nov 24, 2008, at 2:39 PM, Matthew Shepherd wrote:
>
>> 
>> Hi Eugene,
>> 
>> Other routines can use the same global constants.  For example:
>> 
>> suppose showerEnergy is some energy expressed internally in an object in 
>> standard units.  Then:
>> 
>> if( checkEnergy( showerEnergy ) ){
>> ...
>> }
>> 
>> bool checkEnergy( double energy ){
>> 
>> return( energy*k_MeV > 30*k_MeV );
>> }
>> 
>> One just needs to be sure:
>> 
>> #include "units.h"
>> 
>> exists wherever the global constants need to be used.
>> 
>> In other words, the numbers are always expressed in standard units.  Having 
>> the constants just helps alleviate keeping track of what the units are.  If 
>> the standard units are MeV then k_MeV == 1, k_GeV == 0.001, etc..
>> 
>> -Matt
>> 
>