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