Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/carray is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_carray
0005 #define tools_carray
0006 
0007 //fixed array manips
0008 
0009 namespace tools {
0010 
0011 template <class T>
0012 inline void destroy(T*& a_v){
0013   delete [] a_v;
0014   a_v = 0;
0015 }
0016 
0017 template <class T,class I>
0018 inline bool carray_copy(T*& a_v,I a_n,const T* a_from){
0019   delete [] a_v;
0020   a_v = 0;
0021   if(a_n) {
0022     a_v = new T[a_n];
0023     if(!a_v) return false;
0024   }
0025   for(I i=0;i<a_n;i++) a_v[i] = a_from[i];
0026   return true;
0027 }
0028 
0029 template <class T,class I>
0030 inline bool copy(T*& a_v,I a_n,const T* a_from) {return carray_copy<T,I>(a_v,a_n,a_from);}
0031 
0032 /*
0033 template <class T>
0034 inline T value(const T* a_v,
0035                unsigned int a_q,
0036                unsigned int a_i,unsigned int a_j){
0037   // to get value in the case a x[p][q] is stored in a x[p*q].
0038   // (used in hep/polyhedron_arb8)
0039   // WARNING : no check is done on a_i, a_j
0040   return a_v[a_i*a_q+a_j];
0041 }
0042 
0043 template <class I,class T,class I>
0044 inline bool normalize(I a_n,T*& a_v,T(*a_sqrt)(T)){
0045   T sz = T();
0046   I i;
0047   for(i=0;i<a_n;i++) sz += a_v[i]*a_v[i];
0048   sz = a_sqrt(sz);
0049   if(sz==T()) return false;
0050   for(i=0;i<a_n;i++) a_v[i] /= sz;
0051   return true;
0052 }
0053 
0054 template <class T>
0055 inline T value(const T* a_v,
0056                unsigned int a_q,
0057                unsigned int a_i,unsigned int a_j){
0058   // to get value x[i][j] in the case a x[p][q] is stored in a x[p*q].
0059   // (used in hep/polyhedron_arb8)
0060   // WARNING : no check is done on a_i, a_j
0061   return a_v[a_i*a_q+a_j];
0062 }
0063 */
0064 
0065 }
0066 
0067 #include "mnmx"
0068 
0069 namespace tools {
0070 
0071 template <class I,class T,class TO>
0072 inline bool min_max(I a_n,const void* a_v,TO& a_mn,TO& a_mx){
0073   if(a_n<=I(0)) {a_mn = TO(0);a_mx = TO(0);return false;}
0074   T* pos = (T*)a_v;
0075   a_mn = *pos;
0076   a_mx = *pos;
0077   for(I i=0;i<a_n;i++,pos++) {
0078     a_mn = mn<TO>(a_mn,*pos);
0079     a_mx = mx<TO>(a_mx,*pos);
0080   }
0081   return true;
0082 }
0083 
0084 template <class I,class T,class TO>
0085 inline bool min_max_S_S2(I a_n,const void* a_v,TO& a_mn,TO& a_mx,TO& a_S,TO& a_S2){
0086   if(a_n<=0) {a_mn = TO(0);a_mx = TO(0);a_S=TO(0);a_S2=TO(0);return false;}
0087   T* pos = (T*)a_v;
0088   a_mn = *pos;
0089   a_mx = *pos;
0090   a_S = TO(0);
0091   a_S2 = TO(0);
0092   for(I i=0;i<a_n;i++,pos++) {
0093     a_mn = mn<TO>(a_mn,*pos);
0094     a_mx = mx<TO>(a_mx,*pos);
0095     a_S += TO(*pos);
0096     a_S2 += TO(*pos) * TO(*pos);
0097   }
0098   return true;
0099 }
0100 
0101 template <class I,class T,class TO>
0102 inline bool min_max_mean_rms(I a_n,const void* a_v,TO& a_mn,TO& a_mx,TO& a_mean,TO& a_rms,
0103                              TO(*a_sqrt)(TO),TO(*a_fabs)(TO)){
0104   TO S = TO(0);
0105   TO S2 = TO(0);
0106   if(!min_max_S_S2<I,T,TO>(a_n,a_v,a_mn,a_mx,S,S2)) {
0107     a_mn = TO(0);a_mx = TO(0);a_mean=TO(0);a_rms=TO(0);
0108     return false;
0109   }
0110   a_mean = S/TO(a_n);
0111   a_rms = a_sqrt(a_fabs(S2/TO(a_n) - a_mean * a_mean));
0112   return true;
0113 }
0114 
0115 template <class I,class T,class HISTO>
0116 inline bool h1_fill(I a_n,const void* a_v,HISTO& a_histo) {
0117   a_histo.reset();
0118   if(a_n<=0) return false;
0119   typedef typename HISTO::coordinate_t TC;
0120   T* pos = (T*)a_v;
0121   for(I i=0;i<a_n;i++,pos++) a_histo.fill(TC(*pos));
0122   return true;
0123 }
0124 
0125 template <class T,class I>
0126 inline T* _4s_to_3s(const T* a_4s,const I& a_w,const I& a_h) {
0127   T* _3s = new T[a_w*a_h*3];
0128   if(!_3s) return 0;
0129   T* pfrom = (T*)a_4s;
0130   T* pto = _3s;
0131  {I _sz = a_w*a_h*4;
0132   for(I i=0;i<_sz;i+=4) {
0133     *(pto+0) = *(pfrom+0);
0134     *(pto+1) = *(pfrom+1);
0135     *(pto+2) = *(pfrom+2);
0136     pfrom += 4;
0137     pto += 3;
0138   }}
0139   return _3s;
0140 }
0141 
0142 }
0143 
0144 #endif