source: Sophya/trunk/ArchTOIPipe/ProcWSophya/toi2map.cc@ 2076

Last change on this file since 2076 was 2074, checked in by ansari, 23 years ago

Ajout comptage nb d'echantillons utilises ds TOI2Map - Reza 18/6/2002

File size: 7.8 KB
RevLine 
[1738]1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
[2074]5// $Id: toi2map.cc,v 1.28 2002-06-18 20:55:21 ansari Exp $
[1738]6
[1463]7#include "machdefs.h"
8#include "toimanager.h"
9#include "pexceptions.h"
10#include "ctimer.h"
[1807]11#include "toi2map.h"
[1809]12// La valeur "Pi" doit etre celle de smathconst.h a cause du test sur theta
13#include "smathconst.h"
[1463]14
15////////////////////////////////////////////////////////////////////////
[1806]16TOI2Map::TOI2Map(PixelMap<r_8>* map,PixelMap<r_8>* wmap)
[2074]17 : mMap(map), mWMap(wmap), mWMapInternal(false), totnscount(0), usednscount(0)
[1463]18{
[1516]19 SetEquinox();
20 SetCoorIn();
[1809]21 SetCoorMap();
[2058]22 SetCalibrationFactor();
[1530]23 SetTestFlag();
24 SetTestMin();
25 SetTestMax();
[1516]26
[1804]27 if(mMap->NbPixels()<1) {
[1806]28 cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mMap "
[1804]29 <<mMap->NbPixels()<<endl;
[1806]30 throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
[1463]31 }
[1804]32 mMap->SetPixels(0.);
33 int nlat = mMap->SizeIndex();
[1809]34 string typmap = mMap->TypeOfMap();
[1463]35
[1804]36 if(mWMap==NULL) {
37 // We would need a cloning function in maps. $$TBD$$ $CHECK$
38 if (typmap == "LOCAL") {
39 mWMap = new LocalMap<r_8>(*(LocalMap<r_8>*)mMap);
40 } else if (typmap == "RING") {
41 mWMap = new SphereHEALPix<r_8>(nlat);
42 } else {
[1806]43 cout << "TOI2Map::TOI2Map() cannot handle map of type " << typmap << endl;
44 throw ParmError("TOI2Map::TOI2Map() - bad type of map");
[1804]45 }
46 mWMapInternal = true;
[1463]47 } else {
[1804]48 mWMapInternal = false;
49 if(nlat != mWMap->SizeIndex()) {
[1809]50 cout<<"TOI2Map::TOI2Map() Bad size for sphere mWMap, does not "
51 <<"correspond to mMap : "<<mMap->SizeIndex()<<", "<<mWMap->SizeIndex()<<endl;
52 if (typmap == "LOCAL") {
53 throw ParmError("TOI2Map::TOI2Map() - Different sizes for map and wmap");
54 } else if(typmap == "RING") {
55 ((SphereHEALPix<r_8> *)mWMap)->Resize(nlat);
56 cout<<"Resize have been done..."<<endl;
57 } else {
58 cout << "TOI2Map::TOI2Map() cannot handle map of type " << typmap << endl;
59 throw ParmError("TOI2Map::TOI2Map() - bad type of map");
60 }
[1804]61 }
[1463]62 }
[1804]63 if(mWMap->NbPixels()<1) {
[1806]64 cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mWMap "
[1804]65 <<mWMap->NbPixels()<<endl;
[1806]66 throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
[1463]67 }
[1804]68 mWMap->SetPixels(0);
[1463]69}
70
[1806]71TOI2Map::~TOI2Map()
[1463]72{
[1804]73 if(mWMap && mWMapInternal) delete mWMap;
[1463]74}
75
76////////////////////////////////////////////////////////////////////////
[1806]77void TOI2Map::Print(::ostream & os)
[1530]78{
[1809]79 os<<"TOI2Map::Print -- Map type " << mMap->TypeOfMap() << " SizeIndex = "<<mMap->SizeIndex()<<endl
80 <<" - Equinoxe="<<mActualYear<<endl
81 <<" - TypCoorIn: "<<mTypCoorIn<<" = "<<DecodeTypAstro(mTypCoorIn)<<endl
82 <<" - TypCoorMap: "<<mTypCoorMap<<" = "<<DecodeTypAstro(mTypCoorMap)<<endl
83 <<" - Tests: Flag("<<mTFlag<<") bad="<<mBadFlag
84 <<" / Value Min("<<mTMin<<")="<<mValMin
85 <<" , Max("<<mTMax<<")="<<mValMax<<endl;
[2074]86 os<<" TotalProcessedSamples="<<ProcessedSampleCount()
87 <<" UsedSampleCount="<<UsedSampleCount()<<endl;
[1530]88}
89
90////////////////////////////////////////////////////////////////////////
[1806]91void TOI2Map::init() {
92 cout << "TOI2Map::init" << endl;
[1498]93 declareInput("Coord1In"); // input index 0
94 declareInput("Coord2In"); // input index 1
[1516]95 declareInput("BoloIn"); // input index 2
[1463]96}
97
98////////////////////////////////////////////////////////////////////////
[1746]99// define SANS_BUFFER
[1806]100void TOI2Map::run()
[1463]101{
102long snb = getMinIn();
103long sne = getMaxIn();
104
105if(snb>sne) {
[1806]106 cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
107 throw ParmError("TOI2Map::run() - Bad sample interval");
[1463]108}
109if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
[1806]110 cout<<"TOI2Map::run() - Input TOI (Coord1In or Coord2In or BoloIn) not connected! "<<endl;
111 throw ParmError("TOI2Map::run() Output TOI (Coord1In or Coord2In or BoloIn) not connected!");
[1463]112}
[1516]113if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) {
[1806]114 cout<<"TOI2Map::run() - Input Coordinates not Eq or Gal! "<<endl;
115 throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!");
[1516]116}
[1809]117if( !(mTypCoorMap&TypCoordEq || mTypCoorMap&TypCoordGal) ) {
[1806]118 cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
119 throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!");
[1516]120}
[1463]121
122//---------------------------------------------------------
123#define NFILL 25
124try {
125
126int ii;
[1809]127uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL], BadCoorRange=0;
[1463]128for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
[1516]129double mjd = MJDfrYear(mActualYear);
[1463]130
[1806]131cout<<"TOI2Map::run() from "<<snb<<" to "<<sne;
[1746]132#ifndef SANS_BUFFER
133int bufsz = 100;
134uint_8* bfgbolo = new uint_8[bufsz];
135double* bbolo = new double[bufsz];
136double* bc1 = new double[bufsz];
137double* bc2 = new double[bufsz];
138int i0 = -1;
139cout<<" (getData() bufferized)"<<endl;
140#else
141cout<<" (getData() not bufferized)"<<endl;
142#endif
[1744]143
[1463]144// Remplissage des spheres
145for(int s=snb;s<=sne;s++) {
[1536]146 uint_8 fgbolo = 0;
[1746]147 double bolo,coord1,coord2;
[1516]148 // Equatoriales / Galactiques
149 // coord1,2 = alpha,delta / gLon,gLat
[1463]150
[1746]151#ifndef SANS_BUFFER
152 if(i0<0 || s<i0 || s>=i0+bufsz) {
153 i0 = s;
154 int nget = (sne-s+1<bufsz)? nget=sne-s+1: bufsz;
155 getData(0,i0,nget,bc1);
156 getData(1,i0,nget,bc2);
157 getData(2,i0,nget,bbolo,bfgbolo);
[2012]158 totnscount += nget;
[1746]159 }
160 bolo = bbolo[s-i0]; fgbolo = bfgbolo[s-i0];
161 coord1 = bc1[s-i0]; coord2 = bc2[s-i0];
162#else
163 getData(2,s,bolo,fgbolo);
164 coord1 = getData(0,s);
165 coord2 = getData(1,s);
[2012]166 totnscount++;
[1746]167#endif
168
169 // Comme il n'y a pas de toi en sortie, il faut dire
170 // aux processeur/toi que l'on a plus besoin des donnees.
[1724]171 if (s%100 == 0) wontNeedBefore(s-1);
[1530]172 if(mTFlag && fgbolo&mBadFlag) continue;
173 if(mTMin && bolo<mValMin) continue;
174 if(mTMax && bolo>mValMax) continue;
[2074]175 usednscount++;
[1463]176
[1516]177 // sphere phi entre [0,2*Pi] en radians
178 // sphere theta entre [0,Pi] en radians
[1809]179 double phi=-1.;
180 CoordConvertToStd(mTypCoorIn,&coord1,&coord2);
[1786]181
[1809]182 if(mTypCoorIn&TypCoordEq && mTypCoorMap&TypCoordGal) { // Eq -> Gal
[1516]183 EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
[1809]184 phi = coord1 * Pi/180.;
185 } else if(mTypCoorIn&TypCoordGal && mTypCoorMap&TypCoordEq) { // Gal -> Eq
[1516]186 GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
[1809]187 phi = coord1 * Pi/12.;
188 } else if(mTypCoorMap&TypCoordGal) { // Gal -> Gal
189 phi = coord1 * Pi/180.;
190 } else if(mTypCoorMap&TypCoordEq) { // Eq -> Eq
191 phi = coord1 * Pi/12.;
[1498]192 }
[1809]193 ToCoLat(&coord2,TypUniteD);
194 double theta = coord2 * Pi/180.;
[1790]195
[1809]196 if(phi<0. | phi>=2*Pi || theta<0. || theta>Pi)
197 {BadCoorRange++; continue;}
[1786]198
[1804]199 int_4 ipix = mMap->PixIndexSph(theta,phi);
[2054]200 if ((ipix < 0) || (ipix >= mMap->NbPixels()) ) continue;
[2058]201 (*mMap)(ipix) += bolo*mCalibFactor;
[1804]202 ((*mWMap)(ipix)) += 1;
[1516]203 mNSnFill++;
[1463]204}
205
[2074]206 cout<<"TOI2Map::run(): End of SN loop - TotalProcessedSamples="
207 <<ProcessedSampleCount()<<" UsedSampleCount="<<UsedSampleCount()<<endl;
[1633]208
[1463]209// Remplissage des spheres
[1804]210 for(int_4 i=0;i<mMap->NbPixels();i++) {
211 r_8 wf = (*mWMap)(i);
[1809]212 if(wf>0.) {mNpixFill++; (*mMap)(i) /= wf;}
[1463]213 int_4 nf = int_4(wf);
214 if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
215 }
216
[1806]217 cout<<"TOI2Map::run(): mNpixTot="<<mMap->NbPixels()
[1463]218 <<" mNpixFill="<<mNpixFill
219 <<" mNSnFill="<<mNSnFill<<endl
[1804]220 <<" --> FracSky="<<mNpixFill*100./(double)mMap->NbPixels()<<"%"
[1516]221 <<" NFill["<<NFILL<<"] ="<<endl;
222 for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
[1463]223 cout<<endl;
[1809]224 cout<<" BadCoorRange="<<BadCoorRange<<endl;
[1463]225
[1746]226#ifndef SANS_BUFFER
227delete [] bbolo; delete [] bfgbolo;
228delete [] bc1; delete [] bc2;
229#endif
230
[1463]231//---------------------------------------------------------
232} catch (PException & exc) {
[1806]233 cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
[1463]234 <<"\n .... Msg= "<<exc.Msg()<<endl;
235}
236
237return;
238}
Note: See TracBrowser for help on using the repository browser.