[2047] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
| 5 |
|
---|
| 6 | /* Calcul de statistique simples sur TOI
|
---|
| 7 |
|
---|
| 8 | ---------------- Exemple d'appel ---------------------
|
---|
| 9 | csh> toistat -start 104385384 -end 104399964 -range -500,500 \
|
---|
| 10 | -intoi boloMuV_26 -wtoi 8192 -wclean 512,5 \
|
---|
| 11 | inputbolo.fits filt.fits xx.ppf
|
---|
| 12 | */
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | #include "machdefs.h"
|
---|
| 17 | #include <math.h>
|
---|
| 18 | #include <unistd.h>
|
---|
| 19 |
|
---|
| 20 | #include "toimanager.h"
|
---|
| 21 | #include "cgt.h"
|
---|
| 22 | #include "fitstoirdr.h"
|
---|
| 23 | #include "fitstoiwtr.h"
|
---|
| 24 | #include "simtoipr.h"
|
---|
| 25 | #include "simoffset.h"
|
---|
| 26 | #include "simcleaner.h"
|
---|
| 27 | #include "nooppr.h"
|
---|
| 28 | #include "timing.h"
|
---|
| 29 | #include "histinit.h"
|
---|
| 30 | #include "ntuple.h"
|
---|
| 31 | #include "fitsntuple.h"
|
---|
| 32 |
|
---|
| 33 | #include "psighand.h"
|
---|
| 34 | #include <stdexcept>
|
---|
| 35 |
|
---|
| 36 | void Usage(bool fgerr)
|
---|
| 37 | {
|
---|
| 38 | cout << endl;
|
---|
| 39 | if (fgerr) {
|
---|
| 40 | cout << " toistat : Argument Error ! toistat -h for usage " << endl;
|
---|
| 41 | exit(1);
|
---|
| 42 | }
|
---|
| 43 | else {
|
---|
| 44 | cout << " toistat : produce a stat NTuple (mean,sigma) from a TOI" << endl;
|
---|
[2059] | 45 | cout << "\n Usage : toistat [-intoi toiname] \n "
|
---|
| 46 | << " [-start snb] [-end sne] [-snimplicit] \n"
|
---|
[2054] | 47 | << " [-wtoi sz] [-wclean wsz,nbw] [-range min,max] [-cleannsig nsig] \n"
|
---|
[2058] | 48 | << " [-sepflg sepFlagFile] [-outppf] [-noprstat] [-useseqbuff] \n"
|
---|
[2047] | 49 | << " inFitsName outFileName \n"
|
---|
| 50 | << " -start snb : sets the start sample num \n"
|
---|
| 51 | << " -end sne : sets the end sample num \n"
|
---|
[2059] | 52 | << " -snimplicit : sampleNum are implicit in fits files (def=no) \n"
|
---|
[2047] | 53 | << " -range min,max : sets the acceptable range for intoi \n"
|
---|
| 54 | << " default= -16000,16000\n"
|
---|
| 55 | << " -intoi toiName : select input TOI name (def bolo)\n"
|
---|
[2058] | 56 | << " -sepflg sepFlagFileName: sets separate flag file (Level2)\n"
|
---|
[2047] | 57 | << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
|
---|
| 58 | << " -wclean wsz,nbw : sets cleaner window parameters (256,5) \n"
|
---|
[2054] | 59 | << " -cleannsig nsig : Sets cleanner ThrNSig (default = 999999.) \n"
|
---|
[2047] | 60 | << " -outppf : Write the NTuple in PPF format (default: FITS) \n"
|
---|
| 61 | << " -noprstat : DO NOT PrintStat with ProcSampleCounter \n"
|
---|
| 62 | << " -useseqbuff : Use TOISeqBuffered TOI's (default: TOISegmented) \n"
|
---|
| 63 | << endl;
|
---|
| 64 | }
|
---|
| 65 | if (fgerr) exit(1);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | int main(int narg, char** arg) {
|
---|
| 69 |
|
---|
| 70 | if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
|
---|
| 71 |
|
---|
| 72 | cout << "toistat starting - Decoding arguments " << " narg=" << narg << endl;
|
---|
| 73 |
|
---|
| 74 | bool fgsetstart = false;
|
---|
| 75 |
|
---|
| 76 | bool fgprstat = true;
|
---|
| 77 | bool fgsegmented = true;
|
---|
| 78 | bool fgoutppf = false;
|
---|
[2059] | 79 | bool snimplicit = false;
|
---|
[2047] | 80 |
|
---|
| 81 | int dbglev = 0;
|
---|
| 82 |
|
---|
| 83 | int wtoi = 8192;
|
---|
| 84 |
|
---|
| 85 | int nmax = 10;
|
---|
| 86 | int istart = 0;
|
---|
| 87 | int iend = 0;
|
---|
| 88 |
|
---|
| 89 | double range_min = -16000;
|
---|
| 90 | double range_max = 16000.;
|
---|
| 91 |
|
---|
| 92 | // cleaner parameters
|
---|
| 93 | int clean_wsz = 256;
|
---|
| 94 | int clean_nbw = 5;
|
---|
[2054] | 95 | double clean_nsig = 999999.;
|
---|
[2047] | 96 |
|
---|
[2058] | 97 | // Fichier de flag separe / Level2 / Reza 18/6/2002
|
---|
| 98 | string sepflagfile;
|
---|
| 99 | bool sepflg = false;
|
---|
| 100 |
|
---|
[2047] | 101 | // File names
|
---|
| 102 | string infile;
|
---|
| 103 | string outfile;
|
---|
| 104 | string intoi = "bolo";
|
---|
| 105 |
|
---|
| 106 | if (narg < 3) Usage(true);
|
---|
| 107 | int ko=1;
|
---|
| 108 | // decoding arguments
|
---|
| 109 | for(int ia=1; ia<narg; ia++) {
|
---|
| 110 | if (strcmp(arg[ia],"-start") == 0) {
|
---|
| 111 | if (ia == narg-1) Usage(true); // -start est suivi d'un argument
|
---|
| 112 | istart = atoi(arg[ia+1]); ia++;
|
---|
| 113 | fgsetstart = true;
|
---|
| 114 | }
|
---|
| 115 | else if (strcmp(arg[ia],"-end") == 0) {
|
---|
| 116 | if (ia == narg-1) Usage(true);
|
---|
| 117 | iend = atoi(arg[ia+1]); ia++;
|
---|
| 118 | }
|
---|
[2059] | 119 | else if (strcmp(arg[ia],"-snimplicit") == 0) snimplicit = true;
|
---|
[2047] | 120 | else if (strcmp(arg[ia],"-wtoi") == 0) {
|
---|
| 121 | if (ia == narg-1) Usage(true);
|
---|
| 122 | wtoi = atoi(arg[ia+1]); ia++;
|
---|
| 123 | }
|
---|
| 124 | else if (strcmp(arg[ia],"-wclean") == 0) {
|
---|
| 125 | if (ia == narg-1) Usage(true);
|
---|
| 126 | sscanf(arg[ia+1],"%d,%d", &clean_wsz, &clean_nbw);
|
---|
| 127 | }
|
---|
[2054] | 128 | else if (strcmp(arg[ia],"-cleannsig") == 0) {
|
---|
| 129 | if (ia == narg-1) Usage(true);
|
---|
| 130 | clean_nsig = atof(arg[ia+1]); ia++;
|
---|
| 131 | }
|
---|
[2047] | 132 | else if (strcmp(arg[ia],"-range") == 0) {
|
---|
| 133 | if (ia == narg-1) Usage(true);
|
---|
| 134 | sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
|
---|
| 135 | ia++;
|
---|
| 136 | }
|
---|
| 137 | else if (strcmp(arg[ia],"-intoi") == 0) {
|
---|
| 138 | if (ia == narg-1) Usage(true);
|
---|
| 139 | intoi = arg[ia+1]; ia++;
|
---|
| 140 | }
|
---|
[2058] | 141 | else if (strcmp(arg[ia],"-sepflg") == 0) {
|
---|
| 142 | if (ia == narg-1) Usage(true);
|
---|
| 143 | sepflagfile = arg[ia+1];
|
---|
| 144 | sepflg = true; ia++;
|
---|
| 145 | }
|
---|
[2047] | 146 | else if (strcmp(arg[ia],"-outppf") == 0) fgoutppf = true;
|
---|
| 147 |
|
---|
| 148 | else if (strcmp(arg[ia],"-noprstat") == 0) fgprstat = false;
|
---|
[2054] | 149 | else if (strcmp(arg[ia],"-prstat") == 0) fgprstat = true;
|
---|
[2047] | 150 | else if (strcmp(arg[ia],"-useseqbuff") == 0) fgsegmented = false;
|
---|
| 151 |
|
---|
| 152 | else { ko = ia; break; } // Debut des noms
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | if (iend < istart) iend = istart+wtoi*(nmax+5);
|
---|
| 156 | if ((narg-ko) < 2) Usage(true);
|
---|
| 157 | infile = arg[ko];
|
---|
| 158 | outfile = arg[ko+1];
|
---|
| 159 | // outppfname = arg[ko+2];
|
---|
| 160 |
|
---|
| 161 | cout << " Initializing SOPHYA ... " << endl;
|
---|
| 162 | SophyaInit();
|
---|
| 163 | // SophyaConfigureSignalhandling(true);
|
---|
| 164 |
|
---|
| 165 | InitTim();
|
---|
| 166 |
|
---|
| 167 | cout << ">>>> toistat: Infile= " << infile << " outFile="
|
---|
| 168 | << outfile << endl;
|
---|
| 169 | cout << " iStart= " << istart << " iEnd= " << iend << endl;
|
---|
| 170 | cout << ">>>> InTOIName= " << intoi << endl;
|
---|
| 171 |
|
---|
| 172 | try {
|
---|
| 173 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 174 |
|
---|
| 175 | // mgr->setRequestedSample(11680920,11710584);
|
---|
| 176 | // mgr->setRequestedSample(104121000, 104946120);
|
---|
| 177 | if (fgsetstart)
|
---|
| 178 | mgr->setRequestedSample(istart, iend);
|
---|
| 179 |
|
---|
| 180 | cout << "> Creating FITSTOIReader object - InFile=" << infile << endl;
|
---|
| 181 | FITSTOIReader r(infile);
|
---|
[2059] | 182 | if (snimplicit) {
|
---|
| 183 | cout << " Setting Implicit SN flag for reader: r.setImplicitSN()" << endl;
|
---|
| 184 | r.setImplicitSN();
|
---|
| 185 | }
|
---|
[2058] | 186 | if (sepflg) {
|
---|
| 187 | cout << " Setting separate flag file for InTOI_bolo File=" << sepflagfile
|
---|
| 188 | << " (Flags=FlgToiSpike, FlgToiSource)" << endl;
|
---|
| 189 | vector<FlagToiDef> flgcol;
|
---|
| 190 | flgcol.push_back(FlgToiSpike);
|
---|
| 191 | flgcol.push_back(FlgToiSource);
|
---|
| 192 | r.setFlagFile(sepflagfile, flgcol);
|
---|
| 193 | }
|
---|
[2047] | 194 |
|
---|
| 195 | cout << "> Creating SimpleCleaner() " << endl;
|
---|
| 196 | SimpleCleaner cleaner(clean_wsz, clean_nbw);
|
---|
| 197 | cout << " Setting Range for cleaner: " << range_min
|
---|
| 198 | << " - " << range_max << endl;
|
---|
| 199 | cleaner.SetRange(range_min, range_max);
|
---|
[2054] | 200 | cleaner.SetCleanForMeanThrNSig(clean_nsig);
|
---|
[2047] | 201 | cleaner.FillMeanSigNTuple(true);
|
---|
| 202 |
|
---|
| 203 | CGT plombier(fgsegmented, wtoi);
|
---|
| 204 | // plombier.SetDebugLevel(dbglev);
|
---|
| 205 |
|
---|
| 206 | cout << "> Connecting Processors through plombier ... " << endl;
|
---|
| 207 | string inname = "in";
|
---|
| 208 | string outname = "out";
|
---|
| 209 | plombier.Connect(r, intoi, cleaner, inname);
|
---|
| 210 |
|
---|
| 211 | cout << "> Plombier status before start" << endl;
|
---|
| 212 | cout << plombier ;
|
---|
| 213 |
|
---|
| 214 | cout << cleaner;
|
---|
| 215 |
|
---|
| 216 | PrtTim("starting processors");
|
---|
| 217 | plombier.Start();
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 | // ------------------- Impression continu de stat ------------------------
|
---|
| 221 | if (fgprstat) {
|
---|
| 222 | ProcSampleCounter<SimpleCleaner> stats(cleaner);
|
---|
| 223 | stats.InfoMessage() = "toistat/Info";
|
---|
| 224 | stats.PrintStats();
|
---|
| 225 | }
|
---|
| 226 | // -----------------------------------------------------------------------
|
---|
| 227 |
|
---|
[2060] | 228 | mgr->joinAll();
|
---|
| 229 | PrtTim("End threads");
|
---|
| 230 |
|
---|
[2047] | 231 | cout << cleaner;
|
---|
| 232 |
|
---|
| 233 | cleaner.GetMeanSigNTuple().Info()["TOIFILE"] = infile;
|
---|
| 234 | cleaner.GetMeanSigNTuple().Info()["TOINAME"] = intoi;
|
---|
| 235 |
|
---|
| 236 | if (fgoutppf) {
|
---|
| 237 | cout << " \n --------------------------------------------------------- " << endl;
|
---|
| 238 | cout << " Saving Stats (mean-sigma) NTuple to PPF file " << outfile << endl;
|
---|
| 239 | POutPersist pos(outfile);
|
---|
| 240 | pos << cleaner.GetMeanSigNTuple();
|
---|
| 241 | cout << " \n --------------------------------------------------------- " << endl;
|
---|
| 242 | }
|
---|
| 243 | else {
|
---|
| 244 | cout << " \n --------------------------------------------------------- " << endl;
|
---|
| 245 | cout << " Saving Stats (mean-sigma NTuple to FITS file " << outfile << endl;
|
---|
| 246 | FitsOutFile fos(outfile, FitsFile::clear);
|
---|
| 247 | fos << cleaner.GetMeanSigNTuple();
|
---|
| 248 | cout << " \n --------------------------------------------------------- " << endl;
|
---|
| 249 | }
|
---|
| 250 | }
|
---|
| 251 | catch (PThrowable & exc) {
|
---|
| 252 | cerr << "\n toistat: Catched Exception \n" << (string)typeid(exc).name()
|
---|
| 253 | << " - Msg= " << exc.Msg() << endl;
|
---|
| 254 | }
|
---|
| 255 | catch (const std::exception & sex) {
|
---|
| 256 | cerr << "\n toistat: Catched std::exception \n"
|
---|
| 257 | << (string)typeid(sex).name() << endl;
|
---|
| 258 | }
|
---|
| 259 | catch (...) {
|
---|
| 260 | cerr << "\n toistat: some other exception was caught ! " << endl;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | return(0);
|
---|
| 264 | }
|
---|