| 1 |                         // Dominique YVON, CEA/DAPNIA/SPP 02/2000
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #include <math.h>
 | 
|---|
| 4 | #include <iostream>
 | 
|---|
| 5 | #include <fstream>
 | 
|---|
| 6 | #ifdef __MWERKS__
 | 
|---|
| 7 |    #include "mwerksmath.h"
 | 
|---|
| 8 |    #include "unixmac.h"
 | 
|---|
| 9 | #endif
 | 
|---|
| 10 | 
 | 
|---|
| 11 | #include "sigcalctools.h"
 | 
|---|
| 12 | //#include "integ.h"
 | 
|---|
| 13 |  
 | 
|---|
| 14 | template <class T> void addToSkyMap(PixelMap<T>& Map, SigCalcTool& Tool) 
 | 
|---|
| 15 | {
 | 
|---|
| 16 |   double theta, phi;
 | 
|---|
| 17 |   long PixelNumber= Map.NbPixels();
 | 
|---|
| 18 |   cout<<"Nbre de pIxel a calculer dans addToSkyMap: "<<PixelNumber<<endl;
 | 
|---|
| 19 |   T temp;
 | 
|---|
| 20 |   for(long k=0; k<PixelNumber; k++)
 | 
|---|
| 21 |   { 
 | 
|---|
| 22 |     Map.PixThetaPhi(k,theta,phi);
 | 
|---|
| 23 |     temp=(T) Tool.compPixel(theta,phi); 
 | 
|---|
| 24 | //    if (temp<1.e-35) temp=0.;         // BUGG XXXXXX
 | 
|---|
| 25 |                                                                 // pour vivre avec les pb de fichiers fits D.Y. 
 | 
|---|
| 26 |      Map(k)+=temp;
 | 
|---|
| 27 |      if((k%500)==0) cout<<"500 points calculs "<<"NbPoint Total= "<<k<<endl;
 | 
|---|
| 28 |   }
 | 
|---|
| 29 |    return;
 | 
|---|
| 30 | }
 | 
|---|
| 31 | 
 | 
|---|
| 32 | template <class T> void compSkyMap(PixelMap<T>& Map, SigCalcTool& Tool)
 | 
|---|
| 33 | {
 | 
|---|
| 34 |   double theta, phi;
 | 
|---|
| 35 |   long PixelNumber= Map.NbPixels();
 | 
|---|
| 36 |   cout<<"Nbre de pIxel a calculer dans compSkyMap: "<<PixelNumber<<endl;
 | 
|---|
| 37 |   T temp;
 | 
|---|
| 38 |   for(long k=0; k<PixelNumber; k++)
 | 
|---|
| 39 |   { 
 | 
|---|
| 40 |     Map.PixThetaPhi(k,theta,phi);
 | 
|---|
| 41 |         temp= (T) Tool.compPixel(theta,phi);
 | 
|---|
| 42 | //    if (temp<1.e-35) temp=0.;
 | 
|---|
| 43 |                                 // BUGG XXXXXX
 | 
|---|
| 44 |                         // pour vivre avec les pb de fichiers fits D.Y.
 | 
|---|
| 45 |         //if (out!=0.) cout<< out <<'\t'<< temp<<endl;           
 | 
|---|
| 46 |     Map(k)= temp;
 | 
|---|
| 47 |     if((k%500)==0) cout<<"500 points calculs "<<"NbPoint Total= "<<k<<endl;
 | 
|---|
| 48 |   }
 | 
|---|
| 49 |    return;
 | 
|---|
| 50 | }
 | 
|---|
| 51 | 
 | 
|---|
| 52 | template <class T1, class T2> void addMap(PixelMap<T1>& Map, PixelMap<T2>& Map2)
 | 
|---|
| 53 | {
 | 
|---|
| 54 |   double theta, phi;
 | 
|---|
| 55 |   long PixelNumber= Map.NbPixels();
 | 
|---|
| 56 |   //T1 temp;
 | 
|---|
| 57 |   for(long k=0; k<PixelNumber; k++)
 | 
|---|
| 58 |   { 
 | 
|---|
| 59 |     Map.PixThetaPhi(k,theta,phi);
 | 
|---|
| 60 |    // temp=(T1) Map2.PixValSph(theta,phi);
 | 
|---|
| 61 |     if(Map2.ContainsSph(theta,phi)) Map(k) += (T1) Map2.PixValSph(theta,phi);
 | 
|---|
| 62 |   }
 | 
|---|
| 63 |    return;
 | 
|---|
| 64 | }
 | 
|---|
| 65 | 
 | 
|---|
| 66 | template <class T1, class T2> void substractMap(PixelMap<T1>& Map, PixelMap<T2>& Map2)
 | 
|---|
| 67 | {
 | 
|---|
| 68 |   double theta, phi;
 | 
|---|
| 69 |   long PixelNumber= Map.NbPixels();
 | 
|---|
| 70 |   //T1 temp;
 | 
|---|
| 71 |   for(long k=0; k<PixelNumber; k++)
 | 
|---|
| 72 |   { 
 | 
|---|
| 73 |     Map.PixThetaPhi(k,theta,phi);
 | 
|---|
| 74 |  //   temp=(T1) Map2.PixValSph(theta,phi); cout<<" Map2.PixValSph(theta,phi): "<<temp<<endl;
 | 
|---|
| 75 |     if(Map2.ContainsSph(theta,phi)) Map(k) = Map(k)-(T1) Map2.PixValSph(theta,phi);
 | 
|---|
| 76 |   }
 | 
|---|
| 77 |    return;
 | 
|---|
| 78 | }
 | 
|---|
| 79 | 
 | 
|---|
| 80 | template <class T1, class T2> void divMap1WithMap2(PixelMap<T1>& Map, PixelMap<T2>& Map2)
 | 
|---|
| 81 | {
 | 
|---|
| 82 |   double theta, phi;
 | 
|---|
| 83 |   long PixelNumber= Map.NbPixels();
 | 
|---|
| 84 |   //T1 temp;
 | 
|---|
| 85 |   for(long k=0; k<PixelNumber; k++)
 | 
|---|
| 86 |   { 
 | 
|---|
| 87 |      Map.PixThetaPhi(k,theta,phi);
 | 
|---|
| 88 |  //   temp=(T1) Map2.PixValSph(theta,phi); cout<<" Map2.PixValSph(theta,phi): "<<temp<<endl;
 | 
|---|
| 89 |      if(Map2.ContainsSph(theta,phi)) 
 | 
|---|
| 90 |          if (Map2.PixValSph(theta,phi)!=0.) 
 | 
|---|
| 91 |                  Map(k) = Map(k)/(T1) Map2.PixValSph(theta,phi);
 | 
|---|
| 92 |   }
 | 
|---|
| 93 |    return;
 | 
|---|
| 94 | }
 | 
|---|
| 95 | 
 | 
|---|
| 96 | template <class T> void scaleMap(double scalefactor, PixelMap<T>& Map)
 | 
|---|
| 97 | {
 | 
|---|
| 98 |         long PixelNumber= Map.NbPixels();
 | 
|---|
| 99 |         //T temp;
 | 
|---|
| 100 |         for(long k=0; k<PixelNumber; k++) 
 | 
|---|
| 101 |         {       
 | 
|---|
| 102 | //              temp= (T) ( scalefactor*Map2(k) );
 | 
|---|
| 103 |                 Map(k) = (T) ( scalefactor*Map(k) );    
 | 
|---|
| 104 |         }
 | 
|---|
| 105 | }
 | 
|---|
| 106 | 
 | 
|---|
| 107 | 
 | 
|---|
| 108 | template <class T> int MinMaxSigMap(PixelMap<T>& Map, double& Min, 
 | 
|---|
| 109 |         double& Max, double& Moy, double& sigma)
 | 
|---|
| 110 | {       
 | 
|---|
| 111 |         long PixelNumber= Map.NbPixels();
 | 
|---|
| 112 |         double val=0.;
 | 
|---|
| 113 |         double variance=0;
 | 
|---|
| 114 |         Moy=0.;
 | 
|---|
| 115 |         Min=1.e36;
 | 
|---|
| 116 |         Max=-1.e-36;
 | 
|---|
| 117 |         sigma=0.;
 | 
|---|
| 118 |         
 | 
|---|
| 119 |         for(long k=0; k<PixelNumber; k++) 
 | 
|---|
| 120 |         {       val=Map(k); // cout<<k<<'\t'<<val<<'\n';
 | 
|---|
| 121 |             if(val>Max) Max=val;
 | 
|---|
| 122 |                 if(val<Min) Min=val;
 | 
|---|
| 123 |                 Moy+=val;       
 | 
|---|
| 124 |         }
 | 
|---|
| 125 |         
 | 
|---|
| 126 |         Moy/=PixelNumber;
 | 
|---|
| 127 |         for(long k=0; k<PixelNumber; k++) variance+=(val-Moy)*(val-Moy);
 | 
|---|
| 128 |         variance/=PixelNumber;
 | 
|---|
| 129 |         sigma=sqrt(variance);
 | 
|---|
| 130 |         
 | 
|---|
| 131 |         if(Min==Max) 
 | 
|---|
| 132 |         {       cerr<< "bizarre, une carte vide ou uniforme"<<endl;
 | 
|---|
| 133 |                 return 1;
 | 
|---|
| 134 |         }
 | 
|---|
| 135 |         return 0;
 | 
|---|
| 136 | }
 | 
|---|
| 137 | 
 | 
|---|
| 138 | // On instancie les plus courants
 | 
|---|
| 139 | template void addToSkyMap(PixelMap<double>& Map, SigCalcTool& Tool);
 | 
|---|
| 140 | template void addToSkyMap(PixelMap<float>& Map, SigCalcTool& Tool);
 | 
|---|
| 141 | template void compSkyMap(PixelMap<double>& Map, SigCalcTool& Tool);
 | 
|---|
| 142 | template void compSkyMap(PixelMap<float>& Map, SigCalcTool& Tool);      
 | 
|---|
| 143 | 
 | 
|---|
| 144 | // Idem pour les outils de cartes
 | 
|---|
| 145 | 
 | 
|---|
| 146 | template void scaleMap(double scalefactor, PixelMap<double>& Map2);
 | 
|---|
| 147 | template void scaleMap(double scalefactor, PixelMap<float>& Map2);
 | 
|---|
| 148 | 
 | 
|---|
| 149 | template int MinMaxSigMap(PixelMap<float>& Map, double& Min, 
 | 
|---|
| 150 |         double& Max, double& Moy, double& sigma);
 | 
|---|
| 151 | template int MinMaxSigMap(PixelMap<double>& Map, double& Min, 
 | 
|---|
| 152 |         double& Max, double& Moy, double& sigma);
 | 
|---|
| 153 | 
 | 
|---|
| 154 | 
 | 
|---|
| 155 | template void substractMap(PixelMap<float>& Map, PixelMap<float>& Map2);
 | 
|---|
| 156 | template void addMap(PixelMap<float>& Map, PixelMap<float>& Map2);
 | 
|---|
| 157 | template  void divMap1WithMap2(PixelMap<float>& Map, PixelMap<float>& Map2);
 | 
|---|
| 158 | 
 | 
|---|
| 159 | template void substractMap(PixelMap<float>& Map, PixelMap<double>& Map2);
 | 
|---|
| 160 | template void addMap(PixelMap<float>& Map, PixelMap<double>& Map2);
 | 
|---|
| 161 | template void divMap1WithMap2(PixelMap<float>& Map, PixelMap<double>& Map2);
 | 
|---|
| 162 | 
 | 
|---|
| 163 | template void substractMap(PixelMap<double>& Map, PixelMap<float>& Map2);
 | 
|---|
| 164 | template void addMap(PixelMap<double>& Map, PixelMap<float>& Map2);
 | 
|---|
| 165 | template  void divMap1WithMap2(PixelMap<double>& Map, PixelMap<float>& Map2);
 | 
|---|
| 166 | 
 | 
|---|
| 167 | template void substractMap(PixelMap<double>& Map, PixelMap<double>& Map2);
 | 
|---|
| 168 | template void addMap(PixelMap<double>& Map, PixelMap<double>& Map2);
 | 
|---|
| 169 | template  void divMap1WithMap2(PixelMap<double>& Map, PixelMap<double>& Map2);
 | 
|---|
| 170 | 
 | 
|---|