CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/SimDataFormats/ValidationFormats/interface/MaterialAccountingStep.h

Go to the documentation of this file.
00001 #ifndef MaterialAccountingStep_h
00002 #define MaterialAccountingStep_h
00003 
00004 #include <utility>
00005 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00006 
00007 // struct to keep material accounting informations on a per-step basis
00008 // TODO split segment info (in, out) into separate child class
00009 class MaterialAccountingStep {
00010 public:
00011   MaterialAccountingStep( void ) :
00012     m_length(0.),
00013     m_radiationLengths(0.),
00014     m_energyLoss(0.),
00015     m_in(),
00016     m_out() 
00017   { }
00018 
00019   MaterialAccountingStep( double position, double radlen, double loss, const GlobalPoint & in, const GlobalPoint & out ) :
00020     m_length( position ),
00021     m_radiationLengths( radlen ),
00022     m_energyLoss( loss ),
00023     m_in( in ),
00024     m_out( out )
00025   { }
00026  
00027   void clear( void ) {
00028     m_length           = 0.;
00029     m_radiationLengths = 0.;
00030     m_energyLoss       = 0.;
00031     m_in               = GlobalPoint();
00032     m_out              = GlobalPoint();
00033   }
00034 
00035 private:  
00036   double m_length;
00037   double m_radiationLengths;
00038   double m_energyLoss;
00039   GlobalPoint m_in;
00040   GlobalPoint m_out;
00041 
00042 public:
00043   double length(void) const {
00044     return m_length;
00045   }
00046   
00047   double radiationLengths(void) const {
00048     return m_radiationLengths;
00049   }
00050   
00051   double energyLoss(void) const {
00052     return m_energyLoss;
00053   }
00054 
00055   const GlobalPoint & in(void) const {
00056     return m_in;
00057   }
00058   
00059   const GlobalPoint & out(void) const {
00060     return m_out;
00061   }
00062   
00064   std::pair<MaterialAccountingStep, MaterialAccountingStep> split( double fraction ) const {
00065     // no check is done to ensure that 0 <= f <= 1 !
00066     GlobalPoint limit(
00067         m_in.x() * fraction + m_out.x()  * (1. - fraction),
00068         m_in.y() * fraction + m_out.y()  * (1. - fraction),
00069         m_in.z() * fraction + m_out.z()  * (1. - fraction)
00070     );
00071 
00072     MaterialAccountingStep part1( fraction * m_length,
00073                                   fraction * m_radiationLengths,
00074                                   fraction * m_energyLoss,
00075                                   m_in,
00076                                   limit );
00077 
00078     MaterialAccountingStep part2( (1 - fraction) * m_length,
00079                                   (1 - fraction) * m_radiationLengths,
00080                                   (1 - fraction) * m_energyLoss,
00081                                   limit,
00082                                   m_out );
00083     return std::make_pair( part1, part2 );
00084   }
00085     
00087   MaterialAccountingStep & operator=( const MaterialAccountingStep & step ) {
00088     m_length           = step.m_length;
00089     m_radiationLengths = step.m_radiationLengths;
00090     m_energyLoss       = step.m_energyLoss;
00091     m_in               = step.m_in;
00092     m_out              = step.m_out;
00093     return *this;
00094   }
00095   
00097   MaterialAccountingStep & operator+=( const MaterialAccountingStep & step ) {
00098     m_length           += step.m_length;
00099     m_radiationLengths += step.m_radiationLengths;
00100     m_energyLoss       += step.m_energyLoss;
00101 
00102     // assume that perp2 is 0 only for uninitialized steps
00103     if ((m_in.perp2() == 0.0) or (step.m_in.perp2() < m_in.perp2()))
00104       m_in = step.m_in;
00105 
00106     if ((m_out.perp2() == 0.0) or (step.m_out.perp2() > m_out.perp2()))
00107       m_out = step.m_out;
00108     
00109     return *this;
00110   }
00111   
00113   MaterialAccountingStep & operator-=( const MaterialAccountingStep & step ) {
00114     m_length           -= step.m_length;
00115     m_radiationLengths -= step.m_radiationLengths;
00116     m_energyLoss       -= step.m_energyLoss;
00117 
00118     // can anything more sensible be done for m_in and/or m_out ?
00119     if ((step.m_in.perp2() <= m_in.perp2()) and (step.m_out.perp2() >= m_in.perp2()))
00120       m_in = step.m_out;
00121 
00122     if ((step.m_out.perp2() >= m_out.perp2()) and (step.m_in.perp2() <= m_out.perp2()))
00123       m_out = step.m_in;
00124       
00125     return *this;
00126   }
00127   
00129   MaterialAccountingStep & operator*=( const MaterialAccountingStep & step ) {
00130     m_length           *= step.m_length;
00131     m_radiationLengths *= step.m_radiationLengths;
00132     m_energyLoss       *= step.m_energyLoss;
00133     return *this;
00134   }
00135   
00137   MaterialAccountingStep & operator*=( double x ) {
00138     m_length           *= x;
00139     m_radiationLengths *= x;
00140     m_energyLoss       *= x;
00141     return *this;
00142   }
00143   
00145   MaterialAccountingStep & operator/=( double x ) {
00146     m_length           /= x;
00147     m_radiationLengths /= x;
00148     m_energyLoss       /= x;
00149     return *this;
00150   }
00151 };
00152 
00153 inline 
00154 MaterialAccountingStep operator+( const MaterialAccountingStep & x, const MaterialAccountingStep & y ) {
00155   MaterialAccountingStep step(x);
00156   step += y;
00157   return step;
00158 }
00159 
00160 inline 
00161 MaterialAccountingStep operator-( const MaterialAccountingStep & x, const MaterialAccountingStep & y ) {
00162   MaterialAccountingStep step(x);
00163   step -= y;
00164   return step;
00165 }
00166 
00167 inline 
00168 MaterialAccountingStep operator*( const MaterialAccountingStep & x, const MaterialAccountingStep & y ) {
00169   MaterialAccountingStep step(x);
00170   step *= y;
00171   return step;
00172 }
00173 
00174 inline 
00175 MaterialAccountingStep operator*( const MaterialAccountingStep & x, double y ) {
00176   MaterialAccountingStep step(x);
00177   step *= y;
00178   return step;
00179 }
00180 
00181 inline 
00182 MaterialAccountingStep operator*( double y, const MaterialAccountingStep & x ) {
00183   MaterialAccountingStep step(x);
00184   step *= y;
00185   return step;
00186 }
00187 
00188 inline 
00189 MaterialAccountingStep operator/( const MaterialAccountingStep & x, double y ) {
00190   MaterialAccountingStep step(x);
00191   step /= y;
00192   return step;
00193 }
00194 
00195 #endif // MaterialAccountingStep_h