1 | // Utilisation de SOPHYA pour faciliter les tests ...
|
---|
2 | #include "sopnamsp.h"
|
---|
3 | #include "machdefs.h"
|
---|
4 | #include <dirent.h>
|
---|
5 | #include <matharr.h>
|
---|
6 |
|
---|
7 | // include standard c/c++
|
---|
8 | #include <regex.h>
|
---|
9 | #include <stdio.h>
|
---|
10 | #include <stdlib.h>
|
---|
11 | #include <limits>
|
---|
12 | #include <iostream>
|
---|
13 | #include <fstream>
|
---|
14 | #include <string>
|
---|
15 | #include <vector>
|
---|
16 | #include <map>
|
---|
17 | #include <functional>
|
---|
18 | #include <algorithm>
|
---|
19 | #include <numeric>
|
---|
20 | #include <list>
|
---|
21 | #include <exception>
|
---|
22 |
|
---|
23 | // include sophya mesure ressource CPU/memoire ...
|
---|
24 | #include "resusage.h"
|
---|
25 | #include "ctimer.h"
|
---|
26 | #include "timing.h"
|
---|
27 | #include "timestamp.h"
|
---|
28 | #include "strutilxx.h"
|
---|
29 | #include "ntuple.h"
|
---|
30 | #include "fioarr.h"
|
---|
31 | #include "tarrinit.h"
|
---|
32 | #include "histinit.h"
|
---|
33 | #include "fitsioserver.h"
|
---|
34 | #include "fiosinit.h"
|
---|
35 | #include "ppersist.h"
|
---|
36 |
|
---|
37 | //-----------------------------------------------
|
---|
38 | //Usage
|
---|
39 | //
|
---|
40 | //./Objs/mergeAnaFiles -act meanRawDiffOnOff -inPath /sps/baoradio/AmasNancay/JEC/ -src NGC4383 -ppfFile dataRaw -debug 1000 -mxcycles 10
|
---|
41 | //./Objs/mergeAnaFiles -src Abell85 -act meanCalibBAODiffOnOff -mxcycles 500 -calibfreq 1410 -inPath /sps/baoradio/AmasNancay/JEC/ -ppfFile dataRaw -debug 1 >& mergeAna-500.log
|
---|
42 | //
|
---|
43 | //
|
---|
44 | //-----------------------------------------------
|
---|
45 | const sa_size_t NUMBER_OF_CHANNELS = 2;
|
---|
46 | const sa_size_t NUMBER_OF_FREQ = 8192;
|
---|
47 | const r_4 LOWER_FREQUENCY = 1250.0; //MHz
|
---|
48 | const r_4 TOTAL_BANDWIDTH = 250.0; //MHz
|
---|
49 | //Input parameters
|
---|
50 | struct Param {
|
---|
51 | int debuglev_; //debug
|
---|
52 | string inPath_; //root directory of the input files
|
---|
53 | string outPath_; //output files are located here
|
---|
54 | string sourceName_; //source name & subdirectory of the input files
|
---|
55 | string ppfFile_; //generic name of the input files
|
---|
56 | int nSliceInFreq_; //used by reduceSpectra() fnc
|
---|
57 | string calibFreq_; //freq. value used for calibration
|
---|
58 | r_4 rcalibFreq_; //float version
|
---|
59 | string calibBandFreq_; //band of freq. used for calibration
|
---|
60 | r_4 rcalibBandFreq_; //float version
|
---|
61 | int maxNumberCycles_;//(int)maximum number of cycles to be treated
|
---|
62 | string maxNumberCyclesStr_;//(string)maximum number of cycles to be treated
|
---|
63 | } para;
|
---|
64 | //--------------------------------------------------------------
|
---|
65 | //Utility functions
|
---|
66 | // template <class T>
|
---|
67 | // void MeanSigma(TArray<T> const & a, T & mean, T & sig){
|
---|
68 | // if (a.NbDimensions() < 1)
|
---|
69 | // throw RangeCheckError("MathArray<T>::MeanSigma(TArray<T> const & a..) Not Allocated Array a !");
|
---|
70 | // const T * pe;
|
---|
71 | // sa_size_t j,k;
|
---|
72 | // mean=0.;
|
---|
73 | // sig = 0.;
|
---|
74 | // T valok;
|
---|
75 | // if (a.AvgStep() > 0) { // regularly spaced elements
|
---|
76 | // sa_size_t step = a.AvgStep();
|
---|
77 | // sa_size_t maxx = a.Size()*step;
|
---|
78 | // pe = a.Data();
|
---|
79 | // for(k=0; k<maxx; k+=step ) {
|
---|
80 | // valok = pe[k];
|
---|
81 | // mean += valok; sig += valok*valok;
|
---|
82 | // }
|
---|
83 | // }
|
---|
84 | // else { // Non regular data spacing ...
|
---|
85 | // int_4 ka = a.MaxSizeKA();
|
---|
86 | // sa_size_t step = a.Step(ka);
|
---|
87 | // sa_size_t gpas = a.Size(ka)*step;
|
---|
88 | // sa_size_t naxa = a.Size()/a.Size(ka);
|
---|
89 | // for(j=0; j<naxa; j++) {
|
---|
90 | // pe = a.DataBlock().Begin()+a.Offset(ka,j);
|
---|
91 | // for(k=0; k<gpas; k+=step) {
|
---|
92 | // valok = pe[k];
|
---|
93 | // mean += valok; sig += valok*valok;
|
---|
94 | // }
|
---|
95 | // }
|
---|
96 | // }
|
---|
97 | // T dsz = (T)(a.Size());
|
---|
98 | // mean /= dsz;
|
---|
99 | // if (dsz > 1.5) {
|
---|
100 | // sig = sig/dsz - mean*mean;
|
---|
101 | // sig *= (dsz/(dsz-1));
|
---|
102 | // if (sig >= 0.) sig = sqrt(sig);
|
---|
103 | // }
|
---|
104 | // else sig = 0.;
|
---|
105 | // }
|
---|
106 |
|
---|
107 |
|
---|
108 | sa_size_t freqToChan(r_4 f){
|
---|
109 | return (sa_size_t)((f-LOWER_FREQUENCY)/TOTAL_BANDWIDTH*NUMBER_OF_FREQ);
|
---|
110 | }
|
---|
111 | //--------
|
---|
112 | //COMPUTE the mean value on a freq. range for all channels
|
---|
113 | //--------
|
---|
114 | void meanInRange(const TMatrix<r_4> mtx,
|
---|
115 | sa_size_t chLow,
|
---|
116 | sa_size_t chHigh,
|
---|
117 | TVector<r_4>& vec){
|
---|
118 |
|
---|
119 | sa_size_t nr = mtx.NRows();
|
---|
120 |
|
---|
121 | for (sa_size_t ir=0; ir<nr; ir++){
|
---|
122 | TVector<r_4> tmp(mtx(Range(ir),Range(chLow,chHigh)),false);
|
---|
123 | r_8 mean, sigma;
|
---|
124 | MeanSigma(tmp,mean,sigma);
|
---|
125 | vec(ir) = mean;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | //---------
|
---|
129 | class median_of_empty_list_exception:public std::exception{
|
---|
130 | virtual const char* what() const throw() {
|
---|
131 | return "Attempt to take the median of an empty list of numbers. "
|
---|
132 | "The median of an empty list is undefined.";
|
---|
133 | }
|
---|
134 | };
|
---|
135 | template<class RandAccessIter>
|
---|
136 | double median(RandAccessIter begin, RandAccessIter end)
|
---|
137 | throw(median_of_empty_list_exception){
|
---|
138 | if(begin == end){ throw median_of_empty_list_exception(); }
|
---|
139 | std::size_t size = end - begin;
|
---|
140 | std::size_t middleIdx = size/2;
|
---|
141 | RandAccessIter target = begin + middleIdx;
|
---|
142 | std::nth_element(begin, target, end);
|
---|
143 |
|
---|
144 | if(size % 2 != 0){ //Odd number of elements
|
---|
145 | return *target;
|
---|
146 | }else{ //Even number of elements
|
---|
147 | double a = *target;
|
---|
148 | RandAccessIter targetNeighbor= target-1;
|
---|
149 | std::nth_element(begin, targetNeighbor, end);
|
---|
150 | return (a+*targetNeighbor)/2.0;
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | //-------------
|
---|
155 | //JEC 25/10/11 Perform a median filtering with a sliding window of "halfwidth" half width
|
---|
156 | // It takes care of the edges and is based on the median function (above)
|
---|
157 | void medianFiltering(const TMatrix<r_4> mtx,
|
---|
158 | sa_size_t halfwidth,
|
---|
159 | TMatrix<r_4>& vec) {
|
---|
160 |
|
---|
161 | sa_size_t nr = mtx.NRows();
|
---|
162 | sa_size_t nc = mtx.NCols();
|
---|
163 | sa_size_t chMin = 0;
|
---|
164 | sa_size_t chMax = nc-1;
|
---|
165 |
|
---|
166 | for (sa_size_t ir=0; ir<nr; ir++){
|
---|
167 | for (sa_size_t ic=0; ic<nc; ic++) {
|
---|
168 | sa_size_t chLow = ic-halfwidth;
|
---|
169 | chLow = (chLow >= chMin) ? chLow : chMin;
|
---|
170 | sa_size_t chHigh = ic+halfwidth;
|
---|
171 | chHigh = ( chHigh <= chMax ) ? chHigh : chMax;
|
---|
172 | TVector<r_4> tmp(mtx(Range(ir),Range(chLow,chHigh)),false);
|
---|
173 | vector<r_4> val;
|
---|
174 | tmp.FillTo(val);
|
---|
175 | vec(ir,ic) = median(val.begin(),val.end());
|
---|
176 | }
|
---|
177 | }
|
---|
178 | }
|
---|
179 | //-------------
|
---|
180 | void split(const string& str, const string& delimiters , vector<string>& tokens) {
|
---|
181 | // Skip delimiters at beginning.
|
---|
182 | string::size_type lastPos = str.find_first_not_of(delimiters, 0);
|
---|
183 | // Find first "non-delimiter".
|
---|
184 | string::size_type pos = str.find_first_of(delimiters, lastPos);
|
---|
185 |
|
---|
186 | while (string::npos != pos || string::npos != lastPos)
|
---|
187 | {
|
---|
188 | // Found a token, add it to the vector.
|
---|
189 | tokens.push_back(str.substr(lastPos, pos - lastPos));
|
---|
190 | // Skip delimiters. Note the "not_of"
|
---|
191 | lastPos = str.find_first_not_of(delimiters, pos);
|
---|
192 | // Find next "non-delimiter"
|
---|
193 | pos = str.find_first_of(delimiters, lastPos);
|
---|
194 | }
|
---|
195 | }
|
---|
196 | //--------------------------------------------------------------
|
---|
197 | char *regexp (const char *string, const char *patrn, int *begin, int *end) {
|
---|
198 | int i, w=0, len;
|
---|
199 | char *word = NULL;
|
---|
200 | regex_t rgT;
|
---|
201 | regmatch_t match;
|
---|
202 | regcomp(&rgT,patrn,REG_EXTENDED);
|
---|
203 | if ((regexec(&rgT,string,1,&match,0)) == 0) {
|
---|
204 | *begin = (int)match.rm_so;
|
---|
205 | *end = (int)match.rm_eo;
|
---|
206 | len = *end-*begin;
|
---|
207 | word=(char*)malloc(len+1);
|
---|
208 | for (i=*begin; i<*end; i++) {
|
---|
209 | word[w] = string[i];
|
---|
210 | w++; }
|
---|
211 | word[w]=0;
|
---|
212 | }
|
---|
213 | regfree(&rgT);
|
---|
214 | return word;
|
---|
215 | }
|
---|
216 | //-------
|
---|
217 | sa_size_t round_sa(r_4 r) {
|
---|
218 | return static_cast<sa_size_t>((r > 0.0) ? (r + 0.5) : (r - 0.5));
|
---|
219 | }
|
---|
220 | //-----
|
---|
221 | string StringToLower(string strToConvert){
|
---|
222 | //change each element of the string to lower case
|
---|
223 | for(unsigned int i=0;i<strToConvert.length();i++) {
|
---|
224 | strToConvert[i] = tolower(strToConvert[i]);
|
---|
225 | }
|
---|
226 | return strToConvert;//return the converted string
|
---|
227 | }
|
---|
228 | //-----
|
---|
229 | bool stringCompare( const string &left, const string &right ){
|
---|
230 | if( left.size() < right.size() )
|
---|
231 | return true;
|
---|
232 | for( string::const_iterator lit = left.begin(), rit = right.begin(); lit != left.end() && rit != right.end(); ++lit, ++rit )
|
---|
233 | if( tolower( *lit ) < tolower( *rit ) )
|
---|
234 | return true;
|
---|
235 | else if( tolower( *lit ) > tolower( *rit ) )
|
---|
236 | return false;
|
---|
237 | return false;
|
---|
238 | }
|
---|
239 | //-----
|
---|
240 | list<string> ListOfFileInDir(string dir, string filePattern) throw(string) {
|
---|
241 | list<string> theList;
|
---|
242 |
|
---|
243 |
|
---|
244 | DIR *dip;
|
---|
245 | struct dirent *dit;
|
---|
246 | string msg; string fileName;
|
---|
247 | string fullFileName;
|
---|
248 | size_t found;
|
---|
249 |
|
---|
250 | if ((dip=opendir(dir.c_str())) == NULL ) {
|
---|
251 | msg = "opendir failed on directory "+dir;
|
---|
252 | throw msg;
|
---|
253 | }
|
---|
254 | while ( (dit = readdir(dip)) != NULL ) {
|
---|
255 | fileName = dit->d_name;
|
---|
256 | found=fileName.find(filePattern);
|
---|
257 | if (found != string::npos) {
|
---|
258 | fullFileName = dir + "/";
|
---|
259 | fullFileName += fileName;
|
---|
260 | theList.push_back(fullFileName);
|
---|
261 | }
|
---|
262 | }//eo while
|
---|
263 | if (closedir(dip) == -1) {
|
---|
264 | msg = "closedir failed on directory "+dir;
|
---|
265 | throw msg;
|
---|
266 | }
|
---|
267 |
|
---|
268 | theList.sort(stringCompare);
|
---|
269 |
|
---|
270 | return theList;
|
---|
271 |
|
---|
272 | }
|
---|
273 | //
|
---|
274 | class StringMatch : public unary_function<string,bool> {
|
---|
275 | public:
|
---|
276 | StringMatch(const string& pattern): pattern_(pattern){}
|
---|
277 | bool operator()(const string& aStr) const {
|
---|
278 |
|
---|
279 |
|
---|
280 | int b,e;
|
---|
281 | regexp(aStr.c_str(),pattern_.c_str(),&b,&e);
|
---|
282 |
|
---|
283 | // cout << "investigate " << aStr << " to find " << pattern_
|
---|
284 | // << "[" <<b<<","<<e<<"]"
|
---|
285 | // << endl;
|
---|
286 |
|
---|
287 |
|
---|
288 | if (b != 0) return false;
|
---|
289 | if (e != (int)aStr.size()) return false;
|
---|
290 | return true;
|
---|
291 |
|
---|
292 | }
|
---|
293 | private:
|
---|
294 | string pattern_;
|
---|
295 | };
|
---|
296 | //-------------------------------------------------------
|
---|
297 | //Rebin in frequence + compute mean and sigma
|
---|
298 | void reduceSpectra(const TMatrix<r_4>& specMtxInPut,
|
---|
299 | TMatrix<r_4>& meanMtx,
|
---|
300 | TMatrix<r_4>& sigmaMtx) {
|
---|
301 | sa_size_t nSliceFreq = para.nSliceInFreq_;
|
---|
302 | sa_size_t deltaFreq = NUMBER_OF_FREQ/nSliceFreq;
|
---|
303 | for (sa_size_t iSlice=0; iSlice<nSliceFreq; iSlice++){
|
---|
304 | sa_size_t freqLow= iSlice*deltaFreq;
|
---|
305 | sa_size_t freqHigh= freqLow + deltaFreq -1;
|
---|
306 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh){
|
---|
307 | TVector<r_4> reducedRow;
|
---|
308 | reducedRow = specMtxInPut.SubMatrix(Range(iCh),Range(freqLow,freqHigh)).CompactAllDimensions();
|
---|
309 | double mean;
|
---|
310 | double sigma;
|
---|
311 | MeanSigma(reducedRow,mean,sigma);
|
---|
312 | meanMtx(iCh,iSlice) = mean;
|
---|
313 | sigmaMtx(iCh,iSlice) = sigma;
|
---|
314 | }//eo loop on channels
|
---|
315 | }//eo loop on slices
|
---|
316 | }
|
---|
317 |
|
---|
318 | //AST 18/11/11
|
---|
319 | //-------------------------------------------------------
|
---|
320 | //Make n-tuple with calibration coefficients
|
---|
321 | //
|
---|
322 | void calibCoeffNtp() throw(string) {
|
---|
323 | list<string> listOfFiles;
|
---|
324 | string directoryName;
|
---|
325 | directoryName = para.inPath_ + "/" + para.sourceName_;
|
---|
326 |
|
---|
327 | //Make the listing of the directory
|
---|
328 | listOfFiles = ListOfFileInDir(directoryName,para.ppfFile_);
|
---|
329 |
|
---|
330 | list<string>::const_iterator iFile, iFileEnd, iSpec, iSpecEnd;
|
---|
331 | iFileEnd = listOfFiles.end();
|
---|
332 |
|
---|
333 | static const int NINFO=19;
|
---|
334 | char* calibTupleName[NINFO]={"date","run","cycle"
|
---|
335 | ,"meancoeffoff0","meancoeffoff1"
|
---|
336 | ,"meancoeffon0","meancoeffon1"
|
---|
337 | ,"coeffoff0","coeffoff1"
|
---|
338 | ,"coeffon0","coeffon1"
|
---|
339 | ,"invmeancoeffoff0","invmeancoeffoff1"
|
---|
340 | ,"invmeancoeffon0","invmeancoeffon1"
|
---|
341 | ,"invcoeffoff0","invcoeffoff1"
|
---|
342 | ,"invcoeffon0","invcoeffon1"
|
---|
343 | };
|
---|
344 | NTuple calibcoeffs(NINFO,calibTupleName);
|
---|
345 | r_4 xnt[NINFO];
|
---|
346 |
|
---|
347 | int totalNumberRuns=0; //total number of runs
|
---|
348 | int totalNumberCycles=0; //total number of cycles for normalisation
|
---|
349 | for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
|
---|
350 | if (para.debuglev_>90){
|
---|
351 | cout << "load file <" << *iFile << ">" << endl;
|
---|
352 | }
|
---|
353 |
|
---|
354 | vector<string> tokens;
|
---|
355 | split(*iFile,"_",tokens);
|
---|
356 | string dateOfRun = tokens[1];
|
---|
357 | r_4 rdateOfRun = atoi(dateOfRun.c_str()) - 2011*1.e4;
|
---|
358 |
|
---|
359 | if (para.debuglev_>90){
|
---|
360 | cout << "date <" << dateOfRun << ">" << endl;
|
---|
361 | cout << "rdate <" << rdateOfRun << ">" << endl;
|
---|
362 | }
|
---|
363 | vector<string> tokens2;
|
---|
364 | split(tokens[2],".",tokens2);
|
---|
365 | string srcLower = tokens2[0];
|
---|
366 |
|
---|
367 | PInPersist fin(*iFile);
|
---|
368 | vector<string> vec = fin.GetNameTags();
|
---|
369 |
|
---|
370 | vector<string> modeList;
|
---|
371 | modeList.push_back("On");
|
---|
372 | modeList.push_back("Off");
|
---|
373 | vector<string>::const_iterator iMode;
|
---|
374 |
|
---|
375 | map<string, list<int> > cycleModeCollect;
|
---|
376 |
|
---|
377 | for (iMode = modeList.begin(); iMode!=modeList.end(); ++iMode) {
|
---|
378 | list<string> listOfSpectra;
|
---|
379 | //Keep only required PPF objects
|
---|
380 | string matchstr = "specRaw"+(*iMode)+"[0-9]+";
|
---|
381 | std::remove_copy_if(
|
---|
382 | vec.begin(), vec.end(), back_inserter(listOfSpectra),
|
---|
383 | not1(StringMatch(matchstr))
|
---|
384 | );
|
---|
385 |
|
---|
386 | listOfSpectra.sort(stringCompare);
|
---|
387 | iSpecEnd = listOfSpectra.end();
|
---|
388 |
|
---|
389 | matchstr = "[0-9]+";
|
---|
390 | //Loop of spectra matrix
|
---|
391 | list<int> listOfCycles;
|
---|
392 | for (iSpec = listOfSpectra.begin(); iSpec!=iSpecEnd; ++iSpec){
|
---|
393 | int b,e;
|
---|
394 | regexp(iSpec->c_str(),matchstr.c_str(),&b,&e);
|
---|
395 | if (para.debuglev_>90){
|
---|
396 | cout << " spectra <" << *iSpec << ">" << endl;
|
---|
397 | cout << " cycle " << iSpec->substr(b) << endl;
|
---|
398 | }
|
---|
399 | listOfCycles.push_back(atoi((iSpec->substr(b)).c_str()));
|
---|
400 | }//end loop spectra
|
---|
401 | cycleModeCollect[*iMode] = listOfCycles;
|
---|
402 | }//end of mode
|
---|
403 |
|
---|
404 | //Take the Intersection of the list Of cycles in mode Off and On
|
---|
405 | list<int> commonCycles;
|
---|
406 | set_intersection(cycleModeCollect["On"].begin(),
|
---|
407 | cycleModeCollect["On"].end(),
|
---|
408 | cycleModeCollect["Off"].begin(),
|
---|
409 | cycleModeCollect["Off"].end(),
|
---|
410 | back_inserter(commonCycles)
|
---|
411 | );
|
---|
412 |
|
---|
413 | if (para.debuglev_>90){
|
---|
414 | cout << "Liste of cycles common to On & Off: <";
|
---|
415 | for (list<int>::iterator i=commonCycles.begin(); i!=commonCycles.end(); ++i){
|
---|
416 | cout << *i << " ";
|
---|
417 | }
|
---|
418 | cout << ">" << endl;
|
---|
419 | }
|
---|
420 |
|
---|
421 | //
|
---|
422 | //Load BAO Calibration factors "per Cycle and Channels"
|
---|
423 | //Compute the mean per Cycle to
|
---|
424 | // fill factors "per Run and Channels" with the same cycle list
|
---|
425 | //
|
---|
426 | //
|
---|
427 | //TODO improve the code....
|
---|
428 |
|
---|
429 | TMatrix<r_4> calibBAOfactors_Off_Cycle_Ch0;
|
---|
430 | TMatrix<r_4> calibBAOfactors_Off_Cycle_Ch1;
|
---|
431 | TMatrix<r_4> calibBAOfactors_On_Cycle_Ch0;
|
---|
432 | TMatrix<r_4> calibBAOfactors_On_Cycle_Ch1;
|
---|
433 |
|
---|
434 | string calibFileName;
|
---|
435 | ifstream ifs;
|
---|
436 | sa_size_t nr,nc; //values read
|
---|
437 |
|
---|
438 | //OFF Cycle per Channel
|
---|
439 | calibFileName = directoryName + "/"
|
---|
440 | + "calib_" + dateOfRun + "_" + srcLower + "_Off_"
|
---|
441 | + para.calibFreq_ +"MHz-Ch0Cycles.txt";
|
---|
442 | if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
|
---|
443 | ifs.open(calibFileName.c_str());
|
---|
444 | if ( ! ifs.is_open() ) {
|
---|
445 | throw calibFileName + " cannot be opened...";
|
---|
446 | }
|
---|
447 | calibBAOfactors_Off_Cycle_Ch0.ReadASCII(ifs,nr,nc);
|
---|
448 | if(para.debuglev_>9){
|
---|
449 | cout << "(nr,nc): "<< nr << "," << nc << endl;
|
---|
450 | calibBAOfactors_Off_Cycle_Ch0.Print(cout);
|
---|
451 | cout << endl;
|
---|
452 | }
|
---|
453 |
|
---|
454 | TMatrix<r_4> calibBAOfactors_Off_Run_Ch0(nr,nc);
|
---|
455 | calibBAOfactors_Off_Run_Ch0.Column(0) = calibBAOfactors_Off_Cycle_Ch0.Column(0);
|
---|
456 | {//Compute the mean
|
---|
457 | TVector<r_4> coef(calibBAOfactors_Off_Cycle_Ch0(Range::all(),Range::last()),false);
|
---|
458 | double mean,sigma;
|
---|
459 | MeanSigma(coef,mean,sigma);
|
---|
460 | calibBAOfactors_Off_Run_Ch0.Column(1).SetCst(mean);
|
---|
461 | }
|
---|
462 | if(para.debuglev_>9){
|
---|
463 | cout << "Fill calib. with mean value " << endl;
|
---|
464 | calibBAOfactors_Off_Run_Ch0.Print(cout);
|
---|
465 | cout << endl;
|
---|
466 | }
|
---|
467 |
|
---|
468 | TMatrix<r_4> invcalibBAOfactors_Off_Cycle_Ch0(nr,nc);
|
---|
469 | invcalibBAOfactors_Off_Cycle_Ch0.Column(0) = calibBAOfactors_Off_Cycle_Ch0.Column(0);
|
---|
470 | {//Compute the inverse value
|
---|
471 | TVector<r_4> coef(calibBAOfactors_Off_Cycle_Ch0(Range::all(),Range::last()),false);
|
---|
472 | invcalibBAOfactors_Off_Cycle_Ch0.Column(1).SetCst(1);
|
---|
473 | invcalibBAOfactors_Off_Cycle_Ch0.Column(1).Div(coef);
|
---|
474 | if(para.debuglev_>9){
|
---|
475 | cout << "Fill calib. with inverse value " << endl;
|
---|
476 | invcalibBAOfactors_Off_Cycle_Ch0.Print(cout);
|
---|
477 | cout << endl;
|
---|
478 | }
|
---|
479 | }
|
---|
480 | TMatrix<r_4> invcalibBAOfactors_Off_Run_Ch0(nr,nc);
|
---|
481 | invcalibBAOfactors_Off_Run_Ch0.Column(0) = calibBAOfactors_Off_Cycle_Ch0.Column(0);
|
---|
482 | {//Compute the inverse mean
|
---|
483 | TVector<r_4> coef(invcalibBAOfactors_Off_Cycle_Ch0(Range::all(),Range::last()),false);
|
---|
484 | double mean,sigma;
|
---|
485 | MeanSigma(coef,mean,sigma);
|
---|
486 | invcalibBAOfactors_Off_Run_Ch0.Column(1).SetCst(mean);
|
---|
487 | }
|
---|
488 | if(para.debuglev_>9){
|
---|
489 | cout << "Fill calib. with inverse mean value " << endl;
|
---|
490 | invcalibBAOfactors_Off_Run_Ch0.Print(cout);
|
---|
491 | cout << endl;
|
---|
492 | }
|
---|
493 | ifs.close();
|
---|
494 | //
|
---|
495 | calibFileName = directoryName + "/"
|
---|
496 | + "calib_" + dateOfRun + "_" + srcLower + "_Off_"
|
---|
497 | + para.calibFreq_ +"MHz-Ch1Cycles.txt";
|
---|
498 | if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
|
---|
499 | ifs.open(calibFileName.c_str());
|
---|
500 | if ( ! ifs.is_open() ) {
|
---|
501 |
|
---|
502 | throw calibFileName + " cannot be opened...";
|
---|
503 | }
|
---|
504 | calibBAOfactors_Off_Cycle_Ch1.ReadASCII(ifs,nr,nc);
|
---|
505 | if(para.debuglev_>9){
|
---|
506 | cout << "(nr,nc): "<< nr << "," << nc << endl;
|
---|
507 | calibBAOfactors_Off_Cycle_Ch1.Print(cout);
|
---|
508 | cout << endl;
|
---|
509 | }
|
---|
510 | TMatrix<r_4> calibBAOfactors_Off_Run_Ch1(nr,nc);
|
---|
511 | calibBAOfactors_Off_Run_Ch1.Column(0) = calibBAOfactors_Off_Cycle_Ch1.Column(0);
|
---|
512 | {//Compute the mean
|
---|
513 | TVector<r_4> coef(calibBAOfactors_Off_Cycle_Ch1(Range::all(),Range::last()),false);
|
---|
514 | double mean,sigma;
|
---|
515 | MeanSigma(coef,mean,sigma);
|
---|
516 | // cout << "Mean: " << mean << " sigma " << sigma << endl;
|
---|
517 | calibBAOfactors_Off_Run_Ch1.Column(1).SetCst(mean);
|
---|
518 | }
|
---|
519 | if(para.debuglev_>9){
|
---|
520 | cout << "Fill calib. with mean value " << endl;
|
---|
521 | calibBAOfactors_Off_Run_Ch1.Print(cout);
|
---|
522 | cout << endl;
|
---|
523 | }
|
---|
524 | TMatrix<r_4> invcalibBAOfactors_Off_Cycle_Ch1(nr,nc);
|
---|
525 | invcalibBAOfactors_Off_Cycle_Ch1.Column(0) = calibBAOfactors_Off_Cycle_Ch1.Column(0);
|
---|
526 | {//Compute the inverse value
|
---|
527 | TVector<r_4> coef(calibBAOfactors_Off_Cycle_Ch1(Range::all(),Range::last()),false);
|
---|
528 | invcalibBAOfactors_Off_Cycle_Ch1.Column(1).SetCst(1);
|
---|
529 | invcalibBAOfactors_Off_Cycle_Ch1.Column(1).Div(coef);
|
---|
530 | if(para.debuglev_>9){
|
---|
531 | cout << "Fill calib. with inverse value " << endl;
|
---|
532 | invcalibBAOfactors_Off_Cycle_Ch1.Print(cout);
|
---|
533 | cout << endl;
|
---|
534 | }
|
---|
535 | }
|
---|
536 | TMatrix<r_4> invcalibBAOfactors_Off_Run_Ch1(nr,nc);
|
---|
537 | invcalibBAOfactors_Off_Run_Ch1.Column(0) = calibBAOfactors_Off_Cycle_Ch1.Column(0);
|
---|
538 | {//Compute the inverse mean
|
---|
539 | TVector<r_4> coef(invcalibBAOfactors_Off_Cycle_Ch1(Range::all(),Range::last()),false);
|
---|
540 | double mean,sigma;
|
---|
541 | MeanSigma(coef,mean,sigma);
|
---|
542 | invcalibBAOfactors_Off_Run_Ch1.Column(1).SetCst(mean);
|
---|
543 | }
|
---|
544 | if(para.debuglev_>9){
|
---|
545 | cout << "Fill calib. with inverse mean value " << endl;
|
---|
546 | invcalibBAOfactors_Off_Run_Ch1.Print(cout);
|
---|
547 | cout << endl;
|
---|
548 | }
|
---|
549 | ifs.close();
|
---|
550 |
|
---|
551 | //ON Cycle per Channel
|
---|
552 | calibFileName = directoryName + "/"
|
---|
553 | + "calib_" + dateOfRun + "_" + srcLower + "_On_"
|
---|
554 | + para.calibFreq_ +"MHz-Ch0Cycles.txt";
|
---|
555 | if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
|
---|
556 | ifs.open(calibFileName.c_str());
|
---|
557 | if ( ! ifs.is_open() ) {
|
---|
558 |
|
---|
559 | throw calibFileName + " cannot be opened...";
|
---|
560 | }
|
---|
561 | calibBAOfactors_On_Cycle_Ch0.ReadASCII(ifs,nr,nc);
|
---|
562 | if(para.debuglev_>9){
|
---|
563 | cout << "(nr,nc): "<< nr << "," << nc << endl;
|
---|
564 | calibBAOfactors_On_Cycle_Ch0.Print(cout);
|
---|
565 | cout << endl;
|
---|
566 | }
|
---|
567 |
|
---|
568 | TMatrix<r_4> calibBAOfactors_On_Run_Ch0(nr,nc);
|
---|
569 | calibBAOfactors_On_Run_Ch0.Column(0) = calibBAOfactors_On_Cycle_Ch0.Column(0);
|
---|
570 | {//Compute the mean
|
---|
571 | TVector<r_4> coef(calibBAOfactors_On_Cycle_Ch0(Range::all(),Range::last()),false);
|
---|
572 | double mean,sigma;
|
---|
573 | MeanSigma(coef,mean,sigma);
|
---|
574 | // cout << "Mean: " << mean << " sigma " << sigma << endl;
|
---|
575 | calibBAOfactors_On_Run_Ch0.Column(1).SetCst(mean);
|
---|
576 | }
|
---|
577 | if(para.debuglev_>9){
|
---|
578 | cout << "Fill calib. with mean value " << endl;
|
---|
579 | calibBAOfactors_On_Run_Ch0.Print(cout);
|
---|
580 | cout << endl;
|
---|
581 | }
|
---|
582 |
|
---|
583 | TMatrix<r_4> invcalibBAOfactors_On_Cycle_Ch0(nr,nc);
|
---|
584 | invcalibBAOfactors_On_Cycle_Ch0.Column(0) = calibBAOfactors_On_Cycle_Ch0.Column(0);
|
---|
585 | {//Compute the inverse value
|
---|
586 | TVector<r_4> coef(calibBAOfactors_On_Cycle_Ch0(Range::all(),Range::last()),false);
|
---|
587 | invcalibBAOfactors_On_Cycle_Ch0.Column(1).SetCst(1);
|
---|
588 | invcalibBAOfactors_On_Cycle_Ch0.Column(1).Div(coef);
|
---|
589 | if(para.debuglev_>9){
|
---|
590 | cout << "Fill calib. with inverse value " << endl;
|
---|
591 | invcalibBAOfactors_On_Cycle_Ch0.Print(cout);
|
---|
592 | cout << endl;
|
---|
593 | }
|
---|
594 | }
|
---|
595 | TMatrix<r_4> invcalibBAOfactors_On_Run_Ch0(nr,nc);
|
---|
596 | invcalibBAOfactors_On_Run_Ch0.Column(0) = calibBAOfactors_On_Cycle_Ch0.Column(0);
|
---|
597 | {//Compute the inverse mean
|
---|
598 | TVector<r_4> coef(invcalibBAOfactors_On_Cycle_Ch0(Range::all(),Range::last()),false);
|
---|
599 | double mean,sigma;
|
---|
600 | MeanSigma(coef,mean,sigma);
|
---|
601 | invcalibBAOfactors_On_Run_Ch0.Column(1).SetCst(mean);
|
---|
602 | }
|
---|
603 | if(para.debuglev_>9){
|
---|
604 | cout << "Fill calib. with inverse mean value " << endl;
|
---|
605 | invcalibBAOfactors_On_Run_Ch0.Print(cout);
|
---|
606 | cout << endl;
|
---|
607 | }
|
---|
608 | ifs.close();
|
---|
609 |
|
---|
610 | calibFileName = directoryName + "/"
|
---|
611 | + "calib_" + dateOfRun + "_" + srcLower + "_On_"
|
---|
612 | + para.calibFreq_ +"MHz-Ch1Cycles.txt";
|
---|
613 | if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
|
---|
614 | ifs.open(calibFileName.c_str());
|
---|
615 | if ( ! ifs.is_open() ) {
|
---|
616 | throw calibFileName + " cannot be opened...";
|
---|
617 | }
|
---|
618 | calibBAOfactors_On_Cycle_Ch1.ReadASCII(ifs,nr,nc);
|
---|
619 | if(para.debuglev_>9){
|
---|
620 | cout << "(nr,nc): "<< nr << "," << nc << endl;
|
---|
621 | calibBAOfactors_On_Cycle_Ch1.Print(cout);
|
---|
622 | cout << endl;
|
---|
623 | }
|
---|
624 | TMatrix<r_4> calibBAOfactors_On_Run_Ch1(nr,nc);
|
---|
625 | calibBAOfactors_On_Run_Ch1.Column(0) = calibBAOfactors_On_Cycle_Ch1.Column(0);
|
---|
626 | {//Compute the mean
|
---|
627 | TVector<r_4> coef(calibBAOfactors_On_Cycle_Ch1(Range::all(),Range::last()),false);
|
---|
628 | double mean,sigma;
|
---|
629 | MeanSigma(coef,mean,sigma);
|
---|
630 | // cout << "Mean: " << mean << " sigma " << sigma << endl;
|
---|
631 | calibBAOfactors_On_Run_Ch1.Column(1).SetCst(mean);
|
---|
632 | }
|
---|
633 | if(para.debuglev_>9){
|
---|
634 | cout << "Fill calib. with mean value " << endl;
|
---|
635 | calibBAOfactors_On_Run_Ch1.Print(cout);
|
---|
636 | cout << endl;
|
---|
637 | }
|
---|
638 |
|
---|
639 | TMatrix<r_4> invcalibBAOfactors_On_Cycle_Ch1(nr,nc);
|
---|
640 | invcalibBAOfactors_On_Cycle_Ch1.Column(0) = calibBAOfactors_On_Cycle_Ch1.Column(0);
|
---|
641 | {//Compute the inverse value
|
---|
642 | TVector<r_4> coef(calibBAOfactors_On_Cycle_Ch1(Range::all(),Range::last()),false);
|
---|
643 | invcalibBAOfactors_On_Cycle_Ch1.Column(1).SetCst(1);
|
---|
644 | invcalibBAOfactors_On_Cycle_Ch1.Column(1).Div(coef);
|
---|
645 | if(para.debuglev_>9){
|
---|
646 | cout << "Fill calib. with inverse value " << endl;
|
---|
647 | invcalibBAOfactors_On_Cycle_Ch1.Print(cout);
|
---|
648 | cout << endl;
|
---|
649 | }
|
---|
650 | }
|
---|
651 | TMatrix<r_4> invcalibBAOfactors_On_Run_Ch1(nr,nc);
|
---|
652 | invcalibBAOfactors_On_Run_Ch1.Column(0) = calibBAOfactors_On_Cycle_Ch1.Column(0);
|
---|
653 | {//Compute the inverse mean
|
---|
654 | TVector<r_4> coef(invcalibBAOfactors_On_Cycle_Ch1(Range::all(),Range::last()),false);
|
---|
655 | double mean,sigma;
|
---|
656 | MeanSigma(coef,mean,sigma);
|
---|
657 | invcalibBAOfactors_On_Run_Ch1.Column(1).SetCst(mean);
|
---|
658 | }
|
---|
659 | if(para.debuglev_>9){
|
---|
660 | cout << "Fill calib. with inverse mean value " << endl;
|
---|
661 | invcalibBAOfactors_On_Run_Ch1.Print(cout);
|
---|
662 | cout << endl;
|
---|
663 | }
|
---|
664 | ifs.close();
|
---|
665 | //link <cycle> - <calibration coefficient>
|
---|
666 | //We cannot rely on identical cycle list of the OFF and ON calibration
|
---|
667 | map<int,r_4> calibBAO_Off_Run_Ch0;
|
---|
668 | map<int,r_4> calibBAO_Off_Run_Ch1;
|
---|
669 | map<int,r_4> calibBAO_On_Run_Ch0;
|
---|
670 | map<int,r_4> calibBAO_On_Run_Ch1;
|
---|
671 |
|
---|
672 | map<int,r_4> calibBAO_Off_Cycle_Ch0;
|
---|
673 | map<int,r_4> calibBAO_Off_Cycle_Ch1;
|
---|
674 | map<int,r_4> calibBAO_On_Cycle_Ch0;
|
---|
675 | map<int,r_4> calibBAO_On_Cycle_Ch1;
|
---|
676 |
|
---|
677 | map<int,r_4> invcalibBAO_Off_Run_Ch0;
|
---|
678 | map<int,r_4> invcalibBAO_Off_Run_Ch1;
|
---|
679 | map<int,r_4> invcalibBAO_On_Run_Ch0;
|
---|
680 | map<int,r_4> invcalibBAO_On_Run_Ch1;
|
---|
681 |
|
---|
682 | map<int,r_4> invcalibBAO_Off_Cycle_Ch0;
|
---|
683 | map<int,r_4> invcalibBAO_Off_Cycle_Ch1;
|
---|
684 | map<int,r_4> invcalibBAO_On_Cycle_Ch0;
|
---|
685 | map<int,r_4> invcalibBAO_On_Cycle_Ch1;
|
---|
686 |
|
---|
687 | //per Run based BAO coefficients
|
---|
688 | nr = calibBAOfactors_Off_Run_Ch0.NRows();
|
---|
689 | for (sa_size_t ir=0; ir<nr; ++ir){
|
---|
690 | // cout << "Calib. Off Run Ch0 cycle ["<< calibBAOfactors_Off_Run_Ch0(ir,0)<<"], val "
|
---|
691 | // << calibBAOfactors_Off_Run_Ch0(ir,1) << endl;
|
---|
692 |
|
---|
693 | calibBAO_Off_Run_Ch0[(int)calibBAOfactors_Off_Run_Ch0(ir,0)]
|
---|
694 | = calibBAOfactors_Off_Run_Ch0(ir,1);
|
---|
695 | calibBAO_Off_Cycle_Ch0[(int)calibBAOfactors_Off_Cycle_Ch0(ir,0)]
|
---|
696 | = calibBAOfactors_Off_Cycle_Ch0(ir,1);
|
---|
697 | calibBAO_Off_Run_Ch1[(int)calibBAOfactors_Off_Run_Ch1(ir,0)]
|
---|
698 | = calibBAOfactors_Off_Run_Ch1(ir,1);
|
---|
699 | calibBAO_Off_Cycle_Ch1[(int)calibBAOfactors_Off_Cycle_Ch1(ir,0)]
|
---|
700 | = calibBAOfactors_Off_Cycle_Ch1(ir,1);
|
---|
701 |
|
---|
702 | invcalibBAO_Off_Run_Ch0[(int)invcalibBAOfactors_Off_Run_Ch0(ir,0)]
|
---|
703 | = invcalibBAOfactors_Off_Run_Ch0(ir,1);
|
---|
704 | invcalibBAO_Off_Cycle_Ch0[(int)invcalibBAOfactors_Off_Cycle_Ch0(ir,0)]
|
---|
705 | = invcalibBAOfactors_Off_Cycle_Ch0(ir,1);
|
---|
706 | invcalibBAO_Off_Run_Ch1[(int)invcalibBAOfactors_Off_Run_Ch1(ir,0)]
|
---|
707 | = invcalibBAOfactors_Off_Run_Ch1(ir,1);
|
---|
708 | invcalibBAO_Off_Cycle_Ch1[(int)invcalibBAOfactors_Off_Cycle_Ch1(ir,0)]
|
---|
709 | = invcalibBAOfactors_Off_Cycle_Ch1(ir,1);
|
---|
710 | }//eo loop on coef Off
|
---|
711 |
|
---|
712 | nr = calibBAOfactors_On_Run_Ch0.NRows();
|
---|
713 | for (sa_size_t ir=0; ir<nr; ++ir){
|
---|
714 | calibBAO_On_Run_Ch0[(int)calibBAOfactors_On_Run_Ch0(ir,0)]
|
---|
715 | = calibBAOfactors_On_Run_Ch0(ir,1);
|
---|
716 | calibBAO_On_Cycle_Ch0[(int)calibBAOfactors_On_Cycle_Ch0(ir,0)]
|
---|
717 | = calibBAOfactors_On_Cycle_Ch0(ir,1);
|
---|
718 | calibBAO_On_Run_Ch1[(int)calibBAOfactors_On_Run_Ch1(ir,0)]
|
---|
719 | = calibBAOfactors_On_Run_Ch1(ir,1);
|
---|
720 | calibBAO_On_Cycle_Ch1[(int)calibBAOfactors_On_Cycle_Ch1(ir,0)]
|
---|
721 | = calibBAOfactors_On_Cycle_Ch1(ir,1);
|
---|
722 |
|
---|
723 | invcalibBAO_On_Run_Ch0[(int)invcalibBAOfactors_On_Run_Ch0(ir,0)]
|
---|
724 | = invcalibBAOfactors_On_Run_Ch0(ir,1);
|
---|
725 | invcalibBAO_On_Cycle_Ch0[(int)invcalibBAOfactors_On_Cycle_Ch0(ir,0)]
|
---|
726 | = invcalibBAOfactors_On_Cycle_Ch0(ir,1);
|
---|
727 | invcalibBAO_On_Run_Ch1[(int)invcalibBAOfactors_On_Run_Ch1(ir,0)]
|
---|
728 | = invcalibBAOfactors_On_Run_Ch1(ir,1);
|
---|
729 | invcalibBAO_On_Cycle_Ch1[(int)invcalibBAOfactors_On_Cycle_Ch1(ir,0)]
|
---|
730 | = invcalibBAOfactors_On_Cycle_Ch1(ir,1);
|
---|
731 | }//eo loop on coef On
|
---|
732 |
|
---|
733 | //Loop on cyles
|
---|
734 | for (list<int>::iterator ic=commonCycles.begin(); ic!=commonCycles.end(); ++ic){
|
---|
735 |
|
---|
736 | //Look if the cycle has been calibrated...
|
---|
737 | bool isCycleCalibrated =
|
---|
738 | ( calibBAO_On_Run_Ch0.count(*ic) *
|
---|
739 | calibBAO_On_Run_Ch1.count(*ic) *
|
---|
740 | calibBAO_Off_Run_Ch0.count(*ic) *
|
---|
741 | calibBAO_Off_Run_Ch1.count(*ic) *
|
---|
742 | calibBAO_On_Cycle_Ch0.count(*ic) *
|
---|
743 | calibBAO_On_Cycle_Ch1.count(*ic) *
|
---|
744 | calibBAO_Off_Cycle_Ch0.count(*ic) *
|
---|
745 | calibBAO_Off_Cycle_Ch1.count(*ic) ) != 0 ? true : false;
|
---|
746 |
|
---|
747 | if(para.debuglev_>9) {
|
---|
748 | cout << "Calibration coefficients for cycle "<<*ic << endl;
|
---|
749 | if (isCycleCalibrated) {
|
---|
750 | cout << "Cycle calibrated " << endl;
|
---|
751 | cout << "Off Run Ch0 " << calibBAO_Off_Run_Ch0[*ic] << " "
|
---|
752 | << "Ch1 " << calibBAO_Off_Run_Ch1[*ic] << "\n"
|
---|
753 | << "On Run Ch0 " << calibBAO_On_Run_Ch0[*ic] << " "
|
---|
754 | << "Ch1 " << calibBAO_On_Run_Ch1[*ic] << "\n"
|
---|
755 | << "Off Cycle Ch0 " << calibBAO_Off_Cycle_Ch0[*ic] << " "
|
---|
756 | << "Ch1 " << calibBAO_Off_Cycle_Ch1[*ic] << "\n"
|
---|
757 | << "On Cycle Ch0 " << calibBAO_On_Cycle_Ch0[*ic] << " "
|
---|
758 | << "Ch1 " << calibBAO_On_Cycle_Ch1[*ic] << endl;
|
---|
759 | } else {
|
---|
760 | cout << "Cycle NOT calibrated " << endl;
|
---|
761 | }
|
---|
762 | }//debug
|
---|
763 |
|
---|
764 | if ( ! isCycleCalibrated ) continue;
|
---|
765 |
|
---|
766 | totalNumberCycles++;
|
---|
767 | //Fill NTuple
|
---|
768 | xnt[0] = rdateOfRun;
|
---|
769 | xnt[1] = totalNumberRuns;
|
---|
770 | xnt[2] = totalNumberCycles;
|
---|
771 | xnt[3] = calibBAO_Off_Run_Ch0[*ic];
|
---|
772 | xnt[4] = calibBAO_Off_Run_Ch1[*ic];
|
---|
773 | xnt[5] = calibBAO_On_Run_Ch0[*ic];
|
---|
774 | xnt[6] = calibBAO_On_Run_Ch1[*ic];
|
---|
775 | xnt[7] = calibBAO_Off_Cycle_Ch0[*ic];
|
---|
776 | xnt[8] = calibBAO_Off_Cycle_Ch1[*ic];
|
---|
777 | xnt[9] = calibBAO_On_Cycle_Ch0[*ic];
|
---|
778 | xnt[10] = calibBAO_On_Cycle_Ch1[*ic];
|
---|
779 | xnt[11] = invcalibBAO_Off_Run_Ch0[*ic];
|
---|
780 | xnt[12] = invcalibBAO_Off_Run_Ch1[*ic];
|
---|
781 | xnt[13] = invcalibBAO_On_Run_Ch0[*ic];
|
---|
782 | xnt[14] = invcalibBAO_On_Run_Ch1[*ic];
|
---|
783 | xnt[15] = invcalibBAO_Off_Cycle_Ch0[*ic];
|
---|
784 | xnt[16] = invcalibBAO_Off_Cycle_Ch1[*ic];
|
---|
785 | xnt[17] = invcalibBAO_On_Cycle_Ch0[*ic];
|
---|
786 | xnt[18] = invcalibBAO_On_Cycle_Ch1[*ic];
|
---|
787 |
|
---|
788 | calibcoeffs.Fill(xnt);
|
---|
789 |
|
---|
790 | //Quit if enough
|
---|
791 | if (totalNumberCycles >= para.maxNumberCycles_) break;
|
---|
792 |
|
---|
793 | }//eo loop on cycles
|
---|
794 | if (totalNumberCycles >= para.maxNumberCycles_) break;
|
---|
795 | totalNumberRuns++;
|
---|
796 | }//eo loop on spectra in a file
|
---|
797 | cout << "End of jobs: we have treated " << totalNumberCycles << " cycles" << endl;
|
---|
798 |
|
---|
799 | {//save the results
|
---|
800 | stringstream tmp;
|
---|
801 | tmp << totalNumberCycles;
|
---|
802 | string fileName = para.outPath_+"/calibcoeffTuple_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
|
---|
803 |
|
---|
804 | POutPersist fos(fileName);
|
---|
805 | cout << "Save output in " << fileName << endl;
|
---|
806 |
|
---|
807 | string tag = "calib";
|
---|
808 | fos << PPFNameTag(tag) << calibcoeffs;
|
---|
809 |
|
---|
810 | }//end of save
|
---|
811 | }
|
---|
812 |
|
---|
813 | //-------------------------------------------------------
|
---|
814 | //Compute the mean of Diff ON-OFF BAO-calibrated spectra and also the mean/sigma of rebinned spectra
|
---|
815 | //
|
---|
816 | void meanCalibBAODiffOnOffCycles() throw(string) {
|
---|
817 |
|
---|
818 | list<string> listOfFiles;
|
---|
819 | string directoryName;
|
---|
820 | directoryName = para.inPath_ + "/" + para.sourceName_;
|
---|
821 |
|
---|
822 | //Make the listing of the directory
|
---|
823 | listOfFiles = ListOfFileInDir(directoryName,para.ppfFile_);
|
---|
824 |
|
---|
825 | list<string>::const_iterator iFile, iFileEnd, iSpec, iSpecEnd;
|
---|
826 | iFileEnd = listOfFiles.end();
|
---|
827 |
|
---|
828 | //mean ON-OFF over the list of cycles
|
---|
829 | TMatrix<r_4> meanDiffONOFFovOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //set to 0
|
---|
830 | TMatrix<r_4> meanDiffONOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //set to 0
|
---|
831 | TMatrix<r_4> meanDiffONOFF_perRunCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //set to 0
|
---|
832 | TMatrix<r_4> meanDiffONOFF_perCycleCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //set to 0
|
---|
833 | static const int NINFO=25;
|
---|
834 | char* onffTupleName[NINFO]={"cycle"
|
---|
835 | ,"onoffRaw0","onoffRaw1"
|
---|
836 | ,"onoffRun0","onoffRun1"
|
---|
837 | ,"onoffCycle0","onoffCycle1"
|
---|
838 | ,"onoffRaw01420","onoffRaw11420"
|
---|
839 | ,"onoffRun01420","onoffRun11420"
|
---|
840 | ,"onoffCycle01420","onoffCycle11420"
|
---|
841 | ,"onoffRaw01420side","onoffRaw11420side"
|
---|
842 | ,"onoffRun01420side","onoffRun11420side"
|
---|
843 | ,"onoffCycle01420side","onoffCycle11420side"
|
---|
844 | ,"onoffRaw0f14101415","onoffRaw1f14101415"
|
---|
845 | ,"offRaw0f14101415","offRaw1f14101415"
|
---|
846 | ,"onRaw0f14101415","onRaw1f14101415"
|
---|
847 | };
|
---|
848 | NTuple onoffevolution(NINFO,onffTupleName);
|
---|
849 | r_4 xnt[NINFO];
|
---|
850 |
|
---|
851 | //Lower and Higher freq. arround the Calibration Freq. bin to perform mean follow up
|
---|
852 | sa_size_t chCalibLow = freqToChan(para.rcalibFreq_ - (para.rcalibBandFreq_*0.5));
|
---|
853 | sa_size_t chCalibHigh = freqToChan(para.rcalibFreq_ + (para.rcalibBandFreq_*0.5));
|
---|
854 | //Lower and Higher freq. just around 1420.4MHz Freq. bin to perform mean follow up
|
---|
855 | sa_size_t ch1420Low;
|
---|
856 | sa_size_t ch1420High;
|
---|
857 | if (para.sourceName_ == "Abell85") {
|
---|
858 | ch1420Low = freqToChan(1420.4-0.2); // Abell85
|
---|
859 | ch1420High = freqToChan(1420.4+0.2);
|
---|
860 | } else if (para.sourceName_ == "Abell1205") {
|
---|
861 | ch1420Low = freqToChan(1420.4-0.3); // Abell1205
|
---|
862 | ch1420High = freqToChan(1420.4+0.2);
|
---|
863 | } else if (para.sourceName_ == "Abell2440") {
|
---|
864 | ch1420Low = freqToChan(1420.4); // Abell2440
|
---|
865 | ch1420High = freqToChan(1420.4+0.3);
|
---|
866 | } else {
|
---|
867 | ch1420Low = freqToChan(1420.4-0.2); // Abell85
|
---|
868 | ch1420High = freqToChan(1420.4+0.2);
|
---|
869 | }
|
---|
870 |
|
---|
871 | //Lower and Higher freq. on the sides of 1420.4Mhz Freq. bin to perform mean follow up
|
---|
872 | sa_size_t ch1420aLow = freqToChan(1418);
|
---|
873 | sa_size_t ch1420aHigh = freqToChan(1419);
|
---|
874 | sa_size_t ch1420bLow = freqToChan(1422);
|
---|
875 | sa_size_t ch1420bHigh = freqToChan(1423);
|
---|
876 |
|
---|
877 | //1400-1420Mhz
|
---|
878 | sa_size_t ch1400 = freqToChan(1400);
|
---|
879 | // sa_size_t ch1405 = freqToChan(1400);
|
---|
880 | sa_size_t ch1410 = freqToChan(1410);
|
---|
881 | sa_size_t ch1415 = freqToChan(1415);
|
---|
882 | sa_size_t ch1420 = freqToChan(1420);
|
---|
883 |
|
---|
884 | if (para.debuglev_>0){
|
---|
885 | cout << "freq. band for follow up [" << chCalibLow << ", "<< chCalibHigh << "]" << endl;
|
---|
886 | cout << "freq. band for follow up [" << ch1420Low << ", "<< ch1420High << "]" << endl;
|
---|
887 | cout << "freq. band for follow up [" << ch1420aLow << ", "<< ch1420aHigh << "]" << endl;
|
---|
888 | cout << "freq. band for follow up [" << ch1420bLow << ", "<< ch1420bHigh << "]" << endl;
|
---|
889 | }
|
---|
890 |
|
---|
891 | //Loop on files/run
|
---|
892 |
|
---|
893 | int totalNumberCycles=0; //total number of cycles for normalisation
|
---|
894 | for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
|
---|
895 | if (para.debuglev_>90){
|
---|
896 | cout << "load file <" << *iFile << ">" << endl;
|
---|
897 | }
|
---|
898 |
|
---|
899 | vector<string> tokens;
|
---|
900 | split(*iFile,"_",tokens);
|
---|
901 | string dateOfRun = tokens[1];
|
---|
902 | if (para.debuglev_>90){
|
---|
903 | cout << "date <" << dateOfRun << ">" << endl;
|
---|
904 | }
|
---|
905 | vector<string> tokens2;
|
---|
906 | split(tokens[2],".",tokens2);
|
---|
907 | string srcLower = tokens2[0];
|
---|
908 |
|
---|
909 | PInPersist fin(*iFile);
|
---|
910 | vector<string> vec = fin.GetNameTags();
|
---|
911 |
|
---|
912 | vector<string> modeList;
|
---|
913 | modeList.push_back("On");
|
---|
914 | modeList.push_back("Off");
|
---|
915 | vector<string>::const_iterator iMode;
|
---|
916 |
|
---|
917 | map<string, list<int> > cycleModeCollect;
|
---|
918 |
|
---|
919 | for (iMode = modeList.begin(); iMode!=modeList.end(); ++iMode) {
|
---|
920 | list<string> listOfSpectra;
|
---|
921 | //Keep only required PPF objects
|
---|
922 | string matchstr = "specRaw"+(*iMode)+"[0-9]+";
|
---|
923 | std::remove_copy_if(
|
---|
924 | vec.begin(), vec.end(), back_inserter(listOfSpectra),
|
---|
925 | not1(StringMatch(matchstr))
|
---|
926 | );
|
---|
927 |
|
---|
928 | listOfSpectra.sort(stringCompare);
|
---|
929 | iSpecEnd = listOfSpectra.end();
|
---|
930 |
|
---|
931 | matchstr = "[0-9]+";
|
---|
932 | //Loop of spectra matrix
|
---|
933 | list<int> listOfCycles;
|
---|
934 | for (iSpec = listOfSpectra.begin(); iSpec!=iSpecEnd; ++iSpec){
|
---|
935 | int b,e;
|
---|
936 | regexp(iSpec->c_str(),matchstr.c_str(),&b,&e);
|
---|
937 | if (para.debuglev_>90){
|
---|
938 | cout << " spactra <" << *iSpec << ">" << endl;
|
---|
939 | cout << " cycle " << iSpec->substr(b) << endl;
|
---|
940 | }
|
---|
941 | listOfCycles.push_back(atoi((iSpec->substr(b)).c_str()));
|
---|
942 | }//end loop spectra
|
---|
943 | cycleModeCollect[*iMode] = listOfCycles;
|
---|
944 | }//end of mode
|
---|
945 |
|
---|
946 | //Take the Intersection of the list Of cycles in mode Off and On
|
---|
947 | list<int> commonCycles;
|
---|
948 | set_intersection(cycleModeCollect["On"].begin(),
|
---|
949 | cycleModeCollect["On"].end(),
|
---|
950 | cycleModeCollect["Off"].begin(),
|
---|
951 | cycleModeCollect["Off"].end(),
|
---|
952 | back_inserter(commonCycles)
|
---|
953 | );
|
---|
954 |
|
---|
955 | if (para.debuglev_>90){
|
---|
956 | cout << "Liste of cycles common to On & Off: <";
|
---|
957 | for (list<int>::iterator i=commonCycles.begin(); i!=commonCycles.end(); ++i){
|
---|
958 | cout << *i << " ";
|
---|
959 | }
|
---|
960 | cout << ">" << endl;
|
---|
961 | }
|
---|
962 |
|
---|
963 | //
|
---|
964 | //Load BAO Calibration factors "per Cycle and Channels"
|
---|
965 | //Compute the mean per Cycle to
|
---|
966 | // fill factors "per Run and Channels" with the same cycle list
|
---|
967 | //
|
---|
968 | //
|
---|
969 | //TODO improve the code....
|
---|
970 |
|
---|
971 | TMatrix<r_4> calibBAOfactors_Off_Cycle_Ch0;
|
---|
972 | TMatrix<r_4> calibBAOfactors_Off_Cycle_Ch1;
|
---|
973 | TMatrix<r_4> calibBAOfactors_On_Cycle_Ch0;
|
---|
974 | TMatrix<r_4> calibBAOfactors_On_Cycle_Ch1;
|
---|
975 |
|
---|
976 | string calibFileName;
|
---|
977 | ifstream ifs;
|
---|
978 | sa_size_t nr,nc; //values read
|
---|
979 |
|
---|
980 | //OFF Cycle per Channel
|
---|
981 | calibFileName = directoryName + "/"
|
---|
982 | + "calib_" + dateOfRun + "_" + srcLower + "_Off_"
|
---|
983 | + para.calibFreq_ +"MHz-Ch0Cycles.txt";
|
---|
984 | if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
|
---|
985 | ifs.open(calibFileName.c_str());
|
---|
986 | if ( ! ifs.is_open() ) {
|
---|
987 |
|
---|
988 | throw calibFileName + " cannot be opened...";
|
---|
989 | }
|
---|
990 | calibBAOfactors_Off_Cycle_Ch0.ReadASCII(ifs,nr,nc);
|
---|
991 | if(para.debuglev_>9){
|
---|
992 | cout << "(nr,nc): "<< nr << "," << nc << endl;
|
---|
993 | calibBAOfactors_Off_Cycle_Ch0.Print(cout);
|
---|
994 | cout << endl;
|
---|
995 | }
|
---|
996 |
|
---|
997 | TMatrix<r_4> calibBAOfactors_Off_Run_Ch0(nr,nc);
|
---|
998 | calibBAOfactors_Off_Run_Ch0.Column(0) = calibBAOfactors_Off_Cycle_Ch0.Column(0);
|
---|
999 | {//Compute the mean
|
---|
1000 | TVector<r_4> coef(calibBAOfactors_Off_Cycle_Ch0(Range::all(),Range::last()),false);
|
---|
1001 | double mean,sigma;
|
---|
1002 | MeanSigma(coef,mean,sigma);
|
---|
1003 | calibBAOfactors_Off_Run_Ch0.Column(1).SetCst(mean);
|
---|
1004 | }
|
---|
1005 | if(para.debuglev_>9){
|
---|
1006 | cout << "Fill calib. with mean value " << endl;
|
---|
1007 | calibBAOfactors_Off_Run_Ch0.Print(cout);
|
---|
1008 | cout << endl;
|
---|
1009 | }
|
---|
1010 | ifs.close();
|
---|
1011 |
|
---|
1012 | //
|
---|
1013 | calibFileName = directoryName + "/"
|
---|
1014 | + "calib_" + dateOfRun + "_" + srcLower + "_Off_"
|
---|
1015 | + para.calibFreq_ +"MHz-Ch1Cycles.txt";
|
---|
1016 | if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
|
---|
1017 | ifs.open(calibFileName.c_str());
|
---|
1018 | if ( ! ifs.is_open() ) {
|
---|
1019 |
|
---|
1020 | throw calibFileName + " cannot be opened...";
|
---|
1021 | }
|
---|
1022 | calibBAOfactors_Off_Cycle_Ch1.ReadASCII(ifs,nr,nc);
|
---|
1023 | if(para.debuglev_>9){
|
---|
1024 | cout << "(nr,nc): "<< nr << "," << nc << endl;
|
---|
1025 | calibBAOfactors_Off_Cycle_Ch1.Print(cout);
|
---|
1026 | cout << endl;
|
---|
1027 | }
|
---|
1028 | TMatrix<r_4> calibBAOfactors_Off_Run_Ch1(nr,nc);
|
---|
1029 | calibBAOfactors_Off_Run_Ch1.Column(0) = calibBAOfactors_Off_Cycle_Ch1.Column(0);
|
---|
1030 | {//Compute the mean
|
---|
1031 | TVector<r_4> coef(calibBAOfactors_Off_Cycle_Ch1(Range::all(),Range::last()),false);
|
---|
1032 | double mean,sigma;
|
---|
1033 | MeanSigma(coef,mean,sigma);
|
---|
1034 | // cout << "Mean: " << mean << " sigma " << sigma << endl;
|
---|
1035 | calibBAOfactors_Off_Run_Ch1.Column(1).SetCst(mean);
|
---|
1036 | }
|
---|
1037 | if(para.debuglev_>9){
|
---|
1038 | cout << "Fill calib. with mean value " << endl;
|
---|
1039 | calibBAOfactors_Off_Run_Ch1.Print(cout);
|
---|
1040 | cout << endl;
|
---|
1041 | }
|
---|
1042 | ifs.close();
|
---|
1043 |
|
---|
1044 | //ON Cycle per Channel
|
---|
1045 | calibFileName = directoryName + "/"
|
---|
1046 | + "calib_" + dateOfRun + "_" + srcLower + "_On_"
|
---|
1047 | + para.calibFreq_ +"MHz-Ch0Cycles.txt";
|
---|
1048 | if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
|
---|
1049 | ifs.open(calibFileName.c_str());
|
---|
1050 | if ( ! ifs.is_open() ) {
|
---|
1051 |
|
---|
1052 | throw calibFileName + " cannot be opened...";
|
---|
1053 | }
|
---|
1054 | calibBAOfactors_On_Cycle_Ch0.ReadASCII(ifs,nr,nc);
|
---|
1055 | if(para.debuglev_>9){
|
---|
1056 | cout << "(nr,nc): "<< nr << "," << nc << endl;
|
---|
1057 | calibBAOfactors_On_Cycle_Ch0.Print(cout);
|
---|
1058 | cout << endl;
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | TMatrix<r_4> calibBAOfactors_On_Run_Ch0(nr,nc);
|
---|
1062 | calibBAOfactors_On_Run_Ch0.Column(0) = calibBAOfactors_On_Cycle_Ch0.Column(0);
|
---|
1063 | {//Compute the mean
|
---|
1064 | TVector<r_4> coef(calibBAOfactors_On_Cycle_Ch0(Range::all(),Range::last()),false);
|
---|
1065 | double mean,sigma;
|
---|
1066 | MeanSigma(coef,mean,sigma);
|
---|
1067 | // cout << "Mean: " << mean << " sigma " << sigma << endl;
|
---|
1068 | calibBAOfactors_On_Run_Ch0.Column(1).SetCst(mean);
|
---|
1069 | }
|
---|
1070 | if(para.debuglev_>9){
|
---|
1071 | cout << "Fill calib. with mean value " << endl;
|
---|
1072 | calibBAOfactors_On_Run_Ch0.Print(cout);
|
---|
1073 | cout << endl;
|
---|
1074 | }
|
---|
1075 | ifs.close();
|
---|
1076 |
|
---|
1077 |
|
---|
1078 | calibFileName = directoryName + "/"
|
---|
1079 | + "calib_" + dateOfRun + "_" + srcLower + "_On_"
|
---|
1080 | + para.calibFreq_ +"MHz-Ch1Cycles.txt";
|
---|
1081 | if(para.debuglev_>0) cout << "Read Calib file " << calibFileName << endl;
|
---|
1082 | ifs.open(calibFileName.c_str());
|
---|
1083 | if ( ! ifs.is_open() ) {
|
---|
1084 | throw calibFileName + " cannot be opened...";
|
---|
1085 | }
|
---|
1086 | calibBAOfactors_On_Cycle_Ch1.ReadASCII(ifs,nr,nc);
|
---|
1087 | if(para.debuglev_>9){
|
---|
1088 | cout << "(nr,nc): "<< nr << "," << nc << endl;
|
---|
1089 | calibBAOfactors_On_Cycle_Ch1.Print(cout);
|
---|
1090 | cout << endl;
|
---|
1091 | }
|
---|
1092 | TMatrix<r_4> calibBAOfactors_On_Run_Ch1(nr,nc);
|
---|
1093 | calibBAOfactors_On_Run_Ch1.Column(0) = calibBAOfactors_On_Cycle_Ch1.Column(0);
|
---|
1094 | {//Compute the mean
|
---|
1095 | TVector<r_4> coef(calibBAOfactors_On_Cycle_Ch1(Range::all(),Range::last()),false);
|
---|
1096 | double mean,sigma;
|
---|
1097 | MeanSigma(coef,mean,sigma);
|
---|
1098 | // cout << "Mean: " << mean << " sigma " << sigma << endl;
|
---|
1099 | calibBAOfactors_On_Run_Ch1.Column(1).SetCst(mean);
|
---|
1100 | }
|
---|
1101 | if(para.debuglev_>9){
|
---|
1102 | cout << "Fill calib. with mean value " << endl;
|
---|
1103 | calibBAOfactors_On_Run_Ch1.Print(cout);
|
---|
1104 | cout << endl;
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | ifs.close();
|
---|
1108 |
|
---|
1109 | //link <cycle> - <calibration coefficient>
|
---|
1110 | //We cannot rely on identical cycle list of the OFF and ON calibration
|
---|
1111 | map<int,r_4> calibBAO_Off_Run_Ch0;
|
---|
1112 | map<int,r_4> calibBAO_Off_Run_Ch1;
|
---|
1113 | map<int,r_4> calibBAO_On_Run_Ch0;
|
---|
1114 | map<int,r_4> calibBAO_On_Run_Ch1;
|
---|
1115 |
|
---|
1116 | map<int,r_4> calibBAO_Off_Cycle_Ch0;
|
---|
1117 | map<int,r_4> calibBAO_Off_Cycle_Ch1;
|
---|
1118 | map<int,r_4> calibBAO_On_Cycle_Ch0;
|
---|
1119 | map<int,r_4> calibBAO_On_Cycle_Ch1;
|
---|
1120 |
|
---|
1121 | //per Run based BAO coefficients
|
---|
1122 | nr = calibBAOfactors_Off_Run_Ch0.NRows();
|
---|
1123 | for (sa_size_t ir=0; ir<nr; ++ir){
|
---|
1124 | cout << "Calib. Off Run Ch0 cycle ["<< calibBAOfactors_Off_Run_Ch0(ir,0)<<"], val "
|
---|
1125 | << calibBAOfactors_Off_Run_Ch0(ir,1) << endl;
|
---|
1126 |
|
---|
1127 | calibBAO_Off_Run_Ch0[(int)calibBAOfactors_Off_Run_Ch0(ir,0)]
|
---|
1128 | = calibBAOfactors_Off_Run_Ch0(ir,1);
|
---|
1129 | calibBAO_Off_Cycle_Ch0[(int)calibBAOfactors_Off_Cycle_Ch0(ir,0)]
|
---|
1130 | = calibBAOfactors_Off_Cycle_Ch0(ir,1);
|
---|
1131 | calibBAO_Off_Run_Ch1[(int)calibBAOfactors_Off_Run_Ch1(ir,0)]
|
---|
1132 | = calibBAOfactors_Off_Run_Ch1(ir,1);
|
---|
1133 | calibBAO_Off_Cycle_Ch1[(int)calibBAOfactors_Off_Cycle_Ch1(ir,0)]
|
---|
1134 | = calibBAOfactors_Off_Cycle_Ch1(ir,1);
|
---|
1135 | }//eo loop on coef Off
|
---|
1136 |
|
---|
1137 | nr = calibBAOfactors_On_Run_Ch0.NRows();
|
---|
1138 | for (sa_size_t ir=0; ir<nr; ++ir){
|
---|
1139 | calibBAO_On_Run_Ch0[(int)calibBAOfactors_On_Run_Ch0(ir,0)]
|
---|
1140 | = calibBAOfactors_On_Run_Ch0(ir,1);
|
---|
1141 | calibBAO_On_Cycle_Ch0[(int)calibBAOfactors_On_Cycle_Ch0(ir,0)]
|
---|
1142 | = calibBAOfactors_On_Cycle_Ch0(ir,1);
|
---|
1143 | calibBAO_On_Run_Ch1[(int)calibBAOfactors_On_Run_Ch1(ir,0)]
|
---|
1144 | = calibBAOfactors_On_Run_Ch1(ir,1);
|
---|
1145 | calibBAO_On_Cycle_Ch1[(int)calibBAOfactors_On_Cycle_Ch1(ir,0)]
|
---|
1146 | = calibBAOfactors_On_Cycle_Ch1(ir,1);
|
---|
1147 | }//eo loop on coef On
|
---|
1148 |
|
---|
1149 | //Loop on cyles
|
---|
1150 | for (list<int>::iterator ic=commonCycles.begin(); ic!=commonCycles.end(); ++ic){
|
---|
1151 |
|
---|
1152 | //Look if the cycle has been calibrated...
|
---|
1153 | bool isCycleCalibrated =
|
---|
1154 | ( calibBAO_On_Run_Ch0.count(*ic) *
|
---|
1155 | calibBAO_On_Run_Ch1.count(*ic) *
|
---|
1156 | calibBAO_Off_Run_Ch0.count(*ic) *
|
---|
1157 | calibBAO_Off_Run_Ch1.count(*ic) *
|
---|
1158 | calibBAO_On_Cycle_Ch0.count(*ic) *
|
---|
1159 | calibBAO_On_Cycle_Ch1.count(*ic) *
|
---|
1160 | calibBAO_Off_Cycle_Ch0.count(*ic) *
|
---|
1161 | calibBAO_Off_Cycle_Ch1.count(*ic) ) != 0 ? true : false;
|
---|
1162 |
|
---|
1163 | if(para.debuglev_>9) {
|
---|
1164 | cout << "Calibration coefficients for cycle "<<*ic << endl;
|
---|
1165 | if (isCycleCalibrated) {
|
---|
1166 | cout << "Cycle calibrated " << endl;
|
---|
1167 | cout << "Off Run Ch0 " << calibBAO_Off_Run_Ch0[*ic] << " "
|
---|
1168 | << "Ch1 " << calibBAO_Off_Run_Ch1[*ic] << "\n"
|
---|
1169 | << "On Run Ch0 " << calibBAO_On_Run_Ch0[*ic] << " "
|
---|
1170 | << "Ch1 " << calibBAO_On_Run_Ch1[*ic] << "\n"
|
---|
1171 | << "Off Cycle Ch0 " << calibBAO_Off_Cycle_Ch0[*ic] << " "
|
---|
1172 | << "Ch1 " << calibBAO_Off_Cycle_Ch1[*ic] << "\n"
|
---|
1173 | << "On Cycle Ch0 " << calibBAO_On_Cycle_Ch0[*ic] << " "
|
---|
1174 | << "Ch1 " << calibBAO_On_Cycle_Ch1[*ic] << endl;
|
---|
1175 | } else {
|
---|
1176 | cout << "Cycle << " << *ic <<" NOT calibrated for file " << *iFile << endl;
|
---|
1177 | }
|
---|
1178 | }//debug
|
---|
1179 |
|
---|
1180 |
|
---|
1181 | if ( ! isCycleCalibrated ) continue;
|
---|
1182 |
|
---|
1183 | string ppftag;
|
---|
1184 | //load ON phase
|
---|
1185 | stringstream cycle;
|
---|
1186 | cycle << *ic;
|
---|
1187 |
|
---|
1188 | ppftag = "specRawOn"+cycle.str();
|
---|
1189 | TMatrix<r_4> aSpecOn(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
1190 | fin.GetObject(aSpecOn,ppftag);
|
---|
1191 |
|
---|
1192 | TMatrix<r_4> aSpecOn_BAOCalibRun(aSpecOn,false);
|
---|
1193 | aSpecOn_BAOCalibRun(Range(0),Range::all()) /= calibBAO_On_Run_Ch0[*ic];
|
---|
1194 | aSpecOn_BAOCalibRun(Range(1),Range::all()) /= calibBAO_On_Run_Ch1[*ic];
|
---|
1195 |
|
---|
1196 | TMatrix<r_4> aSpecOn_BAOCalibCycle(aSpecOn,false);
|
---|
1197 | aSpecOn_BAOCalibCycle(Range(0),Range::all()) /= calibBAO_On_Cycle_Ch0[*ic];
|
---|
1198 | aSpecOn_BAOCalibCycle(Range(1),Range::all()) /= calibBAO_On_Cycle_Ch1[*ic];
|
---|
1199 |
|
---|
1200 | //Load OFF phase
|
---|
1201 | ppftag = "specRawOff"+cycle.str();
|
---|
1202 | TMatrix<r_4> aSpecOff(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
1203 | fin.GetObject(aSpecOff,ppftag);
|
---|
1204 |
|
---|
1205 | TMatrix<r_4> aSpecOff_BAOCalibRun(aSpecOff,false);
|
---|
1206 | aSpecOff_BAOCalibRun(Range(0),Range::all()) /= calibBAO_Off_Run_Ch0[*ic];
|
---|
1207 | aSpecOff_BAOCalibRun(Range(1),Range::all()) /= calibBAO_Off_Run_Ch1[*ic];
|
---|
1208 |
|
---|
1209 | TMatrix<r_4> aSpecOff_BAOCalibCycle(aSpecOff,false);
|
---|
1210 | aSpecOff_BAOCalibCycle(Range(0),Range::all()) /= calibBAO_Off_Cycle_Ch0[*ic];
|
---|
1211 | aSpecOff_BAOCalibCycle(Range(1),Range::all()) /= calibBAO_Off_Cycle_Ch1[*ic];
|
---|
1212 |
|
---|
1213 |
|
---|
1214 | //Perform the difference ON-OFF with the different calibration options
|
---|
1215 | TMatrix<r_4> diffOnOff_noCalib = aSpecOn - aSpecOff;
|
---|
1216 | meanDiffONOFF_noCalib += diffOnOff_noCalib;
|
---|
1217 |
|
---|
1218 | //JEC 29/10/11 add ON-OFF/OFF
|
---|
1219 | TMatrix<r_4> diffOnOffOvOff_noCalib(diffOnOff_noCalib,false); //do not share data
|
---|
1220 | TMatrix<r_4> aSpecOffFiltered(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
1221 | sa_size_t halfWidth = 35; //number of freq. bin for the 1/2 width of the filtering window
|
---|
1222 | medianFiltering(aSpecOff,halfWidth,aSpecOffFiltered);
|
---|
1223 |
|
---|
1224 | diffOnOffOvOff_noCalib.Div(aSpecOffFiltered); //division in place
|
---|
1225 | meanDiffONOFFovOFF_noCalib += diffOnOffOvOff_noCalib;
|
---|
1226 |
|
---|
1227 | TMatrix<r_4> diffOnOff_perRunCalib = aSpecOn_BAOCalibRun - aSpecOff_BAOCalibRun;
|
---|
1228 | meanDiffONOFF_perRunCalib += diffOnOff_perRunCalib;
|
---|
1229 |
|
---|
1230 | TMatrix<r_4> diffOnOff_perCycleCalib = aSpecOn_BAOCalibCycle - aSpecOff_BAOCalibCycle;
|
---|
1231 | meanDiffONOFF_perCycleCalib += diffOnOff_perCycleCalib;
|
---|
1232 |
|
---|
1233 | totalNumberCycles++;
|
---|
1234 |
|
---|
1235 | //Fill NTuple
|
---|
1236 | xnt[0] = totalNumberCycles;
|
---|
1237 |
|
---|
1238 | //Follow up arround the Calibration Freq.
|
---|
1239 | TVector<r_4> meanInRange_CalibFreq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1240 | meanInRange(diffOnOff_noCalib,chCalibLow,chCalibHigh,meanInRange_CalibFreq_noCalib);
|
---|
1241 | xnt[1] = meanInRange_CalibFreq_noCalib(0);
|
---|
1242 | xnt[2] = meanInRange_CalibFreq_noCalib(1);
|
---|
1243 |
|
---|
1244 | TVector<r_4> meanInRange_CalibFreq_perRunCalib(NUMBER_OF_CHANNELS);
|
---|
1245 | meanInRange(diffOnOff_perRunCalib,chCalibLow,chCalibHigh,meanInRange_CalibFreq_perRunCalib);
|
---|
1246 | xnt[3] = meanInRange_CalibFreq_perRunCalib(0);
|
---|
1247 | xnt[4] = meanInRange_CalibFreq_perRunCalib(1);
|
---|
1248 |
|
---|
1249 | TVector<r_4> meanInRange_CalibFreq_perCycleCalib(NUMBER_OF_CHANNELS);
|
---|
1250 | meanInRange(diffOnOff_perCycleCalib,chCalibLow,chCalibHigh,meanInRange_CalibFreq_perCycleCalib);
|
---|
1251 | xnt[5] = meanInRange_CalibFreq_perCycleCalib(0);
|
---|
1252 | xnt[6] = meanInRange_CalibFreq_perCycleCalib(1);
|
---|
1253 |
|
---|
1254 |
|
---|
1255 | //Follow up arround the 1420.4MHz Freq.
|
---|
1256 | TVector<r_4> meanInRange_1420Freq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1257 | meanInRange(diffOnOff_noCalib,ch1420Low,ch1420High,meanInRange_1420Freq_noCalib);
|
---|
1258 | xnt[7] = meanInRange_1420Freq_noCalib(0);
|
---|
1259 | xnt[8] = meanInRange_1420Freq_noCalib(1);
|
---|
1260 |
|
---|
1261 | TVector<r_4> meanInRange_1420Freq_perRunCalib(NUMBER_OF_CHANNELS);
|
---|
1262 | meanInRange(diffOnOff_perRunCalib,ch1420Low,ch1420High,meanInRange_1420Freq_perRunCalib);
|
---|
1263 | xnt[9] = meanInRange_1420Freq_perRunCalib(0);
|
---|
1264 | xnt[10] = meanInRange_1420Freq_perRunCalib(1);
|
---|
1265 |
|
---|
1266 | TVector<r_4> meanInRange_1420Freq_perCycleCalib(NUMBER_OF_CHANNELS);
|
---|
1267 | meanInRange(diffOnOff_perCycleCalib,ch1420Low,ch1420High,meanInRange_1420Freq_perCycleCalib);
|
---|
1268 | xnt[11] = meanInRange_1420Freq_perCycleCalib(0);
|
---|
1269 | xnt[12] = meanInRange_1420Freq_perCycleCalib(1);
|
---|
1270 |
|
---|
1271 |
|
---|
1272 | //Follow up below the 1420.4MHz Freq.
|
---|
1273 | TVector<r_4> meanInRange_1420aFreq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1274 | meanInRange(diffOnOff_noCalib,ch1420aLow,ch1420aHigh,meanInRange_1420aFreq_noCalib);
|
---|
1275 | TVector<r_4> meanInRange_1420bFreq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1276 | meanInRange(diffOnOff_noCalib,ch1420bLow,ch1420bHigh,meanInRange_1420bFreq_noCalib);
|
---|
1277 |
|
---|
1278 | xnt[13] = (meanInRange_1420aFreq_noCalib(0) + meanInRange_1420bFreq_noCalib(0))/2.;
|
---|
1279 | xnt[14] = (meanInRange_1420aFreq_noCalib(1) + meanInRange_1420bFreq_noCalib(1))/2.;
|
---|
1280 |
|
---|
1281 |
|
---|
1282 | TVector<r_4> meanInRange_1420aFreq_perRun(NUMBER_OF_CHANNELS);
|
---|
1283 | meanInRange(diffOnOff_perRunCalib,ch1420aLow,ch1420aHigh,meanInRange_1420aFreq_perRun);
|
---|
1284 | TVector<r_4> meanInRange_1420bFreq_perRun(NUMBER_OF_CHANNELS);
|
---|
1285 | meanInRange(diffOnOff_perRunCalib,ch1420bLow,ch1420bHigh,meanInRange_1420bFreq_perRun);
|
---|
1286 |
|
---|
1287 | xnt[15] = (meanInRange_1420aFreq_perRun(0) + meanInRange_1420bFreq_perRun(0))/2.;
|
---|
1288 | xnt[16] = (meanInRange_1420aFreq_perRun(1) + meanInRange_1420bFreq_perRun(1))/2.;
|
---|
1289 |
|
---|
1290 |
|
---|
1291 | TVector<r_4> meanInRange_1420aFreq_perCycle(NUMBER_OF_CHANNELS);
|
---|
1292 | meanInRange(diffOnOff_perCycleCalib,ch1420aLow,ch1420aHigh,meanInRange_1420aFreq_perCycle);
|
---|
1293 | TVector<r_4> meanInRange_1420bFreq_perCycle(NUMBER_OF_CHANNELS);
|
---|
1294 | meanInRange(diffOnOff_perCycleCalib,ch1420bLow,ch1420bHigh,meanInRange_1420bFreq_perCycle);
|
---|
1295 |
|
---|
1296 | xnt[17] = (meanInRange_1420aFreq_perCycle(0) + meanInRange_1420bFreq_perCycle(0))/2.;
|
---|
1297 | xnt[18] = (meanInRange_1420aFreq_perCycle(1) + meanInRange_1420bFreq_perCycle(1))/2.;
|
---|
1298 |
|
---|
1299 |
|
---|
1300 | //JEC 25/10/11 follow 1400-1420 MHz bande protege et n'inclue pas le 1420.4Mhz de la Galaxie
|
---|
1301 | TVector<r_4> meanInRange_1400a1420Freq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1302 | meanInRange(diffOnOff_noCalib,ch1400,ch1420,meanInRange_1400a1420Freq_noCalib);
|
---|
1303 | xnt[19] = meanInRange_1400a1420Freq_noCalib(0);
|
---|
1304 | xnt[20] = meanInRange_1400a1420Freq_noCalib(1);
|
---|
1305 |
|
---|
1306 | //JEC 18/11/11 follow up the 1400-1420MHz OFF only
|
---|
1307 | TMatrix<r_4> aSpecOffovOff(aSpecOff,false);
|
---|
1308 | aSpecOffovOff.Div(aSpecOffFiltered);
|
---|
1309 |
|
---|
1310 | TVector<r_4> meanInRange_1410a1415Freq_OFF_noCalib(NUMBER_OF_CHANNELS);
|
---|
1311 | // meanInRange(aSpecOff,ch1410,ch1415,meanInRange_1410a1415Freq_OFF_noCalib);
|
---|
1312 | meanInRange(aSpecOffovOff,ch1410,ch1415,meanInRange_1410a1415Freq_OFF_noCalib);
|
---|
1313 |
|
---|
1314 | xnt[21] = meanInRange_1410a1415Freq_OFF_noCalib(0);
|
---|
1315 | xnt[22] = meanInRange_1410a1415Freq_OFF_noCalib(1);
|
---|
1316 |
|
---|
1317 | TMatrix<r_4> aSpecOnovOff(aSpecOn,false);
|
---|
1318 | aSpecOnovOff.Div(aSpecOffFiltered);
|
---|
1319 |
|
---|
1320 | TVector<r_4> meanInRange_1410a1415Freq_ON_noCalib(NUMBER_OF_CHANNELS);
|
---|
1321 | //meanInRange(aSpecOn,ch1410,ch1415,meanInRange_1410a1415Freq_ON_noCalib);
|
---|
1322 | meanInRange(aSpecOnovOff,ch1410,ch1415,meanInRange_1410a1415Freq_ON_noCalib);
|
---|
1323 |
|
---|
1324 | xnt[23] = meanInRange_1410a1415Freq_ON_noCalib(0);
|
---|
1325 | xnt[24] = meanInRange_1410a1415Freq_ON_noCalib(1);
|
---|
1326 |
|
---|
1327 | //store infos to Ntuple
|
---|
1328 | onoffevolution.Fill(xnt);
|
---|
1329 |
|
---|
1330 | //Quit if enough
|
---|
1331 | if (totalNumberCycles >= para.maxNumberCycles_) break;
|
---|
1332 |
|
---|
1333 | }//eo loop on cycles
|
---|
1334 | if (totalNumberCycles >= para.maxNumberCycles_) break;
|
---|
1335 |
|
---|
1336 | }//eo loop on spectra in a file
|
---|
1337 | cout << "End of jobs: we have treated " << totalNumberCycles << " cycles" << endl;
|
---|
1338 | //Normalisation
|
---|
1339 | if(totalNumberCycles > 0){
|
---|
1340 | //JEC 29/10 add ON-OFF/OFF
|
---|
1341 | meanDiffONOFFovOFF_noCalib /= (r_4)totalNumberCycles;
|
---|
1342 | meanDiffONOFF_noCalib /= (r_4)totalNumberCycles;
|
---|
1343 | meanDiffONOFF_perRunCalib /= (r_4)totalNumberCycles;
|
---|
1344 | meanDiffONOFF_perCycleCalib /= (r_4)totalNumberCycles;
|
---|
1345 | }
|
---|
1346 |
|
---|
1347 | //Compute the reduced version of the mean and sigma
|
---|
1348 | TMatrix<r_4> meanRedMtx_noCalib(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
|
---|
1349 | TMatrix<r_4> sigmaRedMtx_noCalib(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
|
---|
1350 | reduceSpectra(meanDiffONOFF_noCalib,meanRedMtx_noCalib,sigmaRedMtx_noCalib);
|
---|
1351 |
|
---|
1352 | TMatrix<r_4> meanRedMtx_perRunCalib(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
|
---|
1353 | TMatrix<r_4> sigmaRedMtx_perRunCalib(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
|
---|
1354 | reduceSpectra(meanDiffONOFF_perRunCalib,meanRedMtx_perRunCalib,sigmaRedMtx_perRunCalib);
|
---|
1355 |
|
---|
1356 | TMatrix<r_4> meanRedMtx_perCycleCalib(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
|
---|
1357 | TMatrix<r_4> sigmaRedMtx_perCycleCalib(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
|
---|
1358 | reduceSpectra(meanDiffONOFF_perCycleCalib,meanRedMtx_perCycleCalib,sigmaRedMtx_perCycleCalib);
|
---|
1359 |
|
---|
1360 | {//save the results
|
---|
1361 | stringstream tmp;
|
---|
1362 | tmp << totalNumberCycles;
|
---|
1363 | string fileName = para.outPath_+"/onoffsurvey_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
|
---|
1364 |
|
---|
1365 | POutPersist fos(fileName);
|
---|
1366 | cout << "Save output in " << fileName << endl;
|
---|
1367 |
|
---|
1368 | string tag = "meanNoCalib";
|
---|
1369 | fos << PPFNameTag(tag) << meanDiffONOFF_noCalib;
|
---|
1370 |
|
---|
1371 | //JEC 29/10/11
|
---|
1372 | tag = "meanOvOffNoCalib";
|
---|
1373 | fos << PPFNameTag(tag) << meanDiffONOFFovOFF_noCalib;
|
---|
1374 |
|
---|
1375 | tag = "meanPerRunCalib";
|
---|
1376 | fos << PPFNameTag(tag) << meanDiffONOFF_perRunCalib;
|
---|
1377 | tag = "meanPerCycleCalib";
|
---|
1378 | fos << PPFNameTag(tag) << meanDiffONOFF_perCycleCalib;
|
---|
1379 |
|
---|
1380 | tag = "redmeanNoCalib";
|
---|
1381 | fos << PPFNameTag(tag) << meanRedMtx_noCalib;
|
---|
1382 | tag = "redsigmaNoCalib";
|
---|
1383 | fos << PPFNameTag(tag) << sigmaRedMtx_noCalib;
|
---|
1384 |
|
---|
1385 | tag = "redmeanPerRunCalib";
|
---|
1386 | fos << PPFNameTag(tag) << meanRedMtx_perRunCalib;
|
---|
1387 | tag = "redsigmaPerRunCalib";
|
---|
1388 | fos << PPFNameTag(tag) << sigmaRedMtx_perRunCalib;
|
---|
1389 |
|
---|
1390 | tag = "redmeanPerCycleCalib";
|
---|
1391 | fos << PPFNameTag(tag) << meanRedMtx_perCycleCalib;
|
---|
1392 | tag = "redsigmaPerCycleCalib";
|
---|
1393 | fos << PPFNameTag(tag) << sigmaRedMtx_perCycleCalib;
|
---|
1394 |
|
---|
1395 | tag = "onoffevol";
|
---|
1396 | fos << PPFNameTag(tag) << onoffevolution;
|
---|
1397 |
|
---|
1398 | }//end of save
|
---|
1399 |
|
---|
1400 |
|
---|
1401 | }
|
---|
1402 | //JEC 14/11/11 New meanRawDiffOnOffCycles START
|
---|
1403 | //-------------------------------------------------------
|
---|
1404 | //Compute the mean of Diff ON-OFF/OFF from Raw spectra
|
---|
1405 | //Used like:
|
---|
1406 | //
|
---|
1407 | void meanRawDiffOnOffCycles() throw(string) {
|
---|
1408 | list<string> listOfFiles;
|
---|
1409 | string directoryName;
|
---|
1410 | directoryName = para.inPath_ + "/" + para.sourceName_;
|
---|
1411 |
|
---|
1412 | //Make the listing of the directory
|
---|
1413 | listOfFiles = ListOfFileInDir(directoryName,para.ppfFile_);
|
---|
1414 |
|
---|
1415 | list<string>::const_iterator iFile, iFileEnd, iSpec, iSpecEnd;
|
---|
1416 | iFileEnd = listOfFiles.end();
|
---|
1417 |
|
---|
1418 | //mean ON-OFF over the list of cycles
|
---|
1419 | TMatrix<r_4> meanDiffONOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //(ON-OFF)/GAIN
|
---|
1420 | TMatrix<r_4> meanDiffONOFFovOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //(ON-OFF)/Filtered_OFF
|
---|
1421 | TMatrix<r_4> meanONovOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); // ON/Filtered_OFF
|
---|
1422 | TMatrix<r_4> meanOFFovOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); // OFF/Filtered_OFF
|
---|
1423 | //Tuple only for RAW things to follow
|
---|
1424 | static const int NINFO=25;
|
---|
1425 | char* onffTupleName[NINFO]={"cycle"
|
---|
1426 | ,"onoffRaw01420","onoffRaw11420"
|
---|
1427 | ,"onoffRaw01420side","onoffRaw11420side"
|
---|
1428 | ,"onoffRaw0f14101415","onoffRaw1f14101415"
|
---|
1429 | ,"offovoffRaw0f14101415","offovoffRaw1f14101415"
|
---|
1430 | ,"onovoffRaw0f14101415","onovoffRaw1f14101415"
|
---|
1431 | ,"onoffRaw0f14051415","onoffRaw1f14051415"
|
---|
1432 | ,"onoffRaw0f14051410","onoffRaw1f14051410"
|
---|
1433 | ,"diffonoffRaw0f14051415","diffonoffRaw1f14051415"
|
---|
1434 | ,"diffonoffRaw0f14051410","diffonoffRaw1f14051410"
|
---|
1435 | ,"diffonoffRaw0f14101415","diffonoffRaw1f14101415"
|
---|
1436 | ,"onRaw0f14001415","onRaw1f14001415"
|
---|
1437 | ,"offRaw0f14001415","offRaw1f14001415"
|
---|
1438 | };
|
---|
1439 | NTuple onoffevolution(NINFO,onffTupleName);
|
---|
1440 | r_4 xnt[NINFO];
|
---|
1441 |
|
---|
1442 | //Lower and Higher freq. just arround 1420.4MHz Freq. bin to perform mean follow up
|
---|
1443 | sa_size_t ch1420Low = freqToChan(1420.4-0.2);
|
---|
1444 | sa_size_t ch1420High = freqToChan(1420.4+0.2);
|
---|
1445 |
|
---|
1446 | //Lower and Higher freq. on the sides of 1420.4Mhz Freq. bin to perform mean follow up
|
---|
1447 | sa_size_t ch1420aLow = freqToChan(1418);
|
---|
1448 | sa_size_t ch1420aHigh = freqToChan(1419);
|
---|
1449 | sa_size_t ch1420bLow = freqToChan(1422);
|
---|
1450 | sa_size_t ch1420bHigh = freqToChan(1423);
|
---|
1451 |
|
---|
1452 | //1400-1420Mhz
|
---|
1453 | sa_size_t ch1400 = freqToChan(1400);
|
---|
1454 | sa_size_t ch1405 = freqToChan(1405);
|
---|
1455 | sa_size_t ch1410 = freqToChan(1410);
|
---|
1456 | sa_size_t ch1415 = freqToChan(1415);
|
---|
1457 | // sa_size_t ch1420 = freqToChan(1420);
|
---|
1458 |
|
---|
1459 | if (para.debuglev_>0){
|
---|
1460 | cout << "freq. band for follow up [" << ch1420Low << ", "<< ch1420High << "]" << endl;
|
---|
1461 | cout << "freq. band for follow up [" << ch1420aLow << ", "<< ch1420aHigh << "]" << endl;
|
---|
1462 | cout << "freq. band for follow up [" << ch1420bLow << ", "<< ch1420bHigh << "]" << endl;
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 | int totalNumberCycles=0; //total number of cycles
|
---|
1466 |
|
---|
1467 | //Loop on files
|
---|
1468 | for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
|
---|
1469 | if (para.debuglev_>90){
|
---|
1470 | cout << "load file <" << *iFile << ">" << endl;
|
---|
1471 | }
|
---|
1472 |
|
---|
1473 | vector<string> tokens;
|
---|
1474 | split(*iFile,"_",tokens);
|
---|
1475 | string dateOfRun = tokens[1];
|
---|
1476 | if (para.debuglev_>90){
|
---|
1477 | cout << "date <" << dateOfRun << ">" << endl;
|
---|
1478 | }
|
---|
1479 | vector<string> tokens2;
|
---|
1480 | split(tokens[2],".",tokens2);
|
---|
1481 | string srcLower = tokens2[0];
|
---|
1482 |
|
---|
1483 | PInPersist fin(*iFile);
|
---|
1484 | vector<string> vec = fin.GetNameTags();
|
---|
1485 |
|
---|
1486 | vector<string> modeList;
|
---|
1487 | modeList.push_back("On");
|
---|
1488 | modeList.push_back("Off");
|
---|
1489 | vector<string>::const_iterator iMode;
|
---|
1490 |
|
---|
1491 | map<string, list<int> > cycleModeCollect;
|
---|
1492 |
|
---|
1493 | for (iMode = modeList.begin(); iMode!=modeList.end(); ++iMode) {
|
---|
1494 | list<string> listOfSpectra;
|
---|
1495 | //Keep only required PPF objects
|
---|
1496 | string matchstr = "specRaw"+(*iMode)+"[0-9]+";
|
---|
1497 | std::remove_copy_if(
|
---|
1498 | vec.begin(), vec.end(), back_inserter(listOfSpectra),
|
---|
1499 | not1(StringMatch(matchstr))
|
---|
1500 | );
|
---|
1501 |
|
---|
1502 | listOfSpectra.sort(stringCompare);
|
---|
1503 | iSpecEnd = listOfSpectra.end();
|
---|
1504 |
|
---|
1505 | matchstr = "[0-9]+";
|
---|
1506 | //Loop of spectra matrix
|
---|
1507 | list<int> listOfCycles;
|
---|
1508 | for (iSpec = listOfSpectra.begin(); iSpec!=iSpecEnd; ++iSpec){
|
---|
1509 | int b,e;
|
---|
1510 | regexp(iSpec->c_str(),matchstr.c_str(),&b,&e);
|
---|
1511 | if (para.debuglev_>90){
|
---|
1512 | cout << " spectra <" << *iSpec << ">" << endl;
|
---|
1513 | cout << " cycle " << iSpec->substr(b) << endl;
|
---|
1514 | }
|
---|
1515 | listOfCycles.push_back(atoi((iSpec->substr(b)).c_str()));
|
---|
1516 | }//end loop spectra
|
---|
1517 | cycleModeCollect[*iMode] = listOfCycles;
|
---|
1518 | }//end of mode
|
---|
1519 |
|
---|
1520 | //Take the Intersection of the list Of cycles in mode Off and On
|
---|
1521 | list<int> commonCycles;
|
---|
1522 | set_intersection(cycleModeCollect["On"].begin(),
|
---|
1523 | cycleModeCollect["On"].end(),
|
---|
1524 | cycleModeCollect["Off"].begin(),
|
---|
1525 | cycleModeCollect["Off"].end(),
|
---|
1526 | back_inserter(commonCycles)
|
---|
1527 | );
|
---|
1528 |
|
---|
1529 | if (para.debuglev_>90){
|
---|
1530 | cout << dateOfRun << ": Liste of cycles common to On & Off: <";
|
---|
1531 | for (list<int>::iterator i=commonCycles.begin(); i!=commonCycles.end(); ++i){
|
---|
1532 | cout << *i << " ";
|
---|
1533 | }
|
---|
1534 | cout << ">" << endl;
|
---|
1535 | }
|
---|
1536 |
|
---|
1537 | //Loop on cyles
|
---|
1538 | for (list<int>::iterator ic=commonCycles.begin(); ic!=commonCycles.end(); ++ic){
|
---|
1539 |
|
---|
1540 | // AST 28.11.11 remove non-calibrated cycles for Abell1205 and Abell2440
|
---|
1541 | if ( *ic == 1 && srcLower == "abell1205" ) {
|
---|
1542 | if ( dateOfRun == "20110502" || dateOfRun == "20110607" || dateOfRun == "20110818" ) {
|
---|
1543 | cout << "Skipping non-calibrated cycle " << *ic << endl;
|
---|
1544 | continue;
|
---|
1545 | }
|
---|
1546 | } else if ( *ic == 1 && srcLower == "abell2440" ) {
|
---|
1547 | if ( dateOfRun == "20110516" ) {
|
---|
1548 | cout << "Skipping non-calibrated cycle " << *ic << endl;
|
---|
1549 | continue;
|
---|
1550 | }
|
---|
1551 | } else if ( *ic == 3 && srcLower == "abell1205" ) {
|
---|
1552 | if ( dateOfRun == "20110810" ) {
|
---|
1553 | cout << "Skipping non-calibrated cycle " << *ic << endl;
|
---|
1554 | continue;
|
---|
1555 | }
|
---|
1556 | }
|
---|
1557 |
|
---|
1558 | string ppftag;
|
---|
1559 | //load ON phase
|
---|
1560 | stringstream cycle;
|
---|
1561 | cycle << *ic;
|
---|
1562 | ppftag = "specRawOn"+cycle.str();
|
---|
1563 | TMatrix<r_4> aSpecOn(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
1564 | fin.GetObject(aSpecOn,ppftag);
|
---|
1565 |
|
---|
1566 | //Load OFF phase
|
---|
1567 | ppftag = "specRawOff"+cycle.str();
|
---|
1568 | TMatrix<r_4> aSpecOff(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
1569 | fin.GetObject(aSpecOff,ppftag);
|
---|
1570 |
|
---|
1571 | //Perform the difference ON-OFF
|
---|
1572 | TMatrix<r_4> diffOnOff_noCalib = aSpecOn - aSpecOff;
|
---|
1573 |
|
---|
1574 | meanDiffONOFF_noCalib += diffOnOff_noCalib;
|
---|
1575 |
|
---|
1576 | //JEC 29/10/11 add ON-OFF/OFF
|
---|
1577 | TMatrix<r_4> diffOnOffOvOff_noCalib(diffOnOff_noCalib,false); //do not share data
|
---|
1578 | TMatrix<r_4> aSpecOffFiltered(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
1579 | sa_size_t halfWidth = 35; //number of freq. bin for the 1/2 width of the filtering window
|
---|
1580 | medianFiltering(aSpecOff,halfWidth,aSpecOffFiltered);
|
---|
1581 |
|
---|
1582 | diffOnOffOvOff_noCalib.Div(aSpecOffFiltered); //division in place
|
---|
1583 | meanDiffONOFFovOFF_noCalib += diffOnOffOvOff_noCalib;
|
---|
1584 |
|
---|
1585 | //JEC 15/11/11 add ON/OFF and OFF/OFF
|
---|
1586 | TMatrix<r_4> onOvOff(aSpecOn,false);
|
---|
1587 | onOvOff.Div(aSpecOffFiltered);
|
---|
1588 | meanONovOFF_noCalib += onOvOff;
|
---|
1589 |
|
---|
1590 | TMatrix<r_4> offOvOff(aSpecOff,false);
|
---|
1591 | offOvOff.Div(aSpecOffFiltered);
|
---|
1592 | meanOFFovOFF_noCalib += offOvOff;
|
---|
1593 |
|
---|
1594 |
|
---|
1595 | totalNumberCycles++;
|
---|
1596 |
|
---|
1597 | //Fill NTuple
|
---|
1598 | xnt[0] = totalNumberCycles;
|
---|
1599 |
|
---|
1600 | //Follow up arround the 1420.4MHz Freq.
|
---|
1601 | TVector<r_4> meanInRange_1420Freq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1602 | meanInRange(diffOnOffOvOff_noCalib,ch1420Low,ch1420High,meanInRange_1420Freq_noCalib);
|
---|
1603 | xnt[1] = meanInRange_1420Freq_noCalib(0);
|
---|
1604 | xnt[2] = meanInRange_1420Freq_noCalib(1);
|
---|
1605 |
|
---|
1606 | //Follow up below the 1420.4MHz Freq.
|
---|
1607 | TVector<r_4> meanInRange_1420aFreq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1608 | meanInRange(diffOnOffOvOff_noCalib,ch1420aLow,ch1420aHigh,meanInRange_1420aFreq_noCalib);
|
---|
1609 | TVector<r_4> meanInRange_1420bFreq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1610 | meanInRange(diffOnOffOvOff_noCalib,ch1420bLow,ch1420bHigh,meanInRange_1420bFreq_noCalib);
|
---|
1611 |
|
---|
1612 | xnt[3] = (meanInRange_1420aFreq_noCalib(0) + meanInRange_1420bFreq_noCalib(0))/2.;
|
---|
1613 | xnt[4] = (meanInRange_1420aFreq_noCalib(1) + meanInRange_1420bFreq_noCalib(1))/2.;
|
---|
1614 |
|
---|
1615 |
|
---|
1616 | //JEC 25/10/11 follow 1410-1415 MHz bande protege et n'inclue pas le 1420.4Mhz de la Galaxie
|
---|
1617 | TVector<r_4> meanInRange_1410a1415Freq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1618 | meanInRange(diffOnOffOvOff_noCalib,ch1410,ch1415,meanInRange_1410a1415Freq_noCalib);
|
---|
1619 | xnt[5] = meanInRange_1410a1415Freq_noCalib(0);
|
---|
1620 | xnt[6] = meanInRange_1410a1415Freq_noCalib(1);
|
---|
1621 |
|
---|
1622 | //JEC 18/11/11 follow up the 1410-1415MHz OFF only
|
---|
1623 | TMatrix<r_4> aSpecOffovOff(aSpecOff,false);
|
---|
1624 | aSpecOffovOff.Div(aSpecOffFiltered);
|
---|
1625 |
|
---|
1626 | TVector<r_4> meanInRange_1410a1415Freq_OFF_noCalib(NUMBER_OF_CHANNELS);
|
---|
1627 | meanInRange(aSpecOffovOff,ch1410,ch1415,meanInRange_1410a1415Freq_OFF_noCalib);
|
---|
1628 |
|
---|
1629 | xnt[7] = meanInRange_1410a1415Freq_OFF_noCalib(0);
|
---|
1630 | xnt[8] = meanInRange_1410a1415Freq_OFF_noCalib(1);
|
---|
1631 |
|
---|
1632 | TMatrix<r_4> aSpecOnovOff(aSpecOn,false);
|
---|
1633 | aSpecOnovOff.Div(aSpecOffFiltered);
|
---|
1634 |
|
---|
1635 | TVector<r_4> meanInRange_1410a1415Freq_ON_noCalib(NUMBER_OF_CHANNELS);
|
---|
1636 | meanInRange(aSpecOnovOff,ch1410,ch1415,meanInRange_1410a1415Freq_ON_noCalib);
|
---|
1637 |
|
---|
1638 | xnt[9] = meanInRange_1410a1415Freq_ON_noCalib(0);
|
---|
1639 | xnt[10] = meanInRange_1410a1415Freq_ON_noCalib(1);
|
---|
1640 |
|
---|
1641 | //AST 09/01/12 follow 1405-1415 and 1405-1410 MHz for (ON-OFF)/OFF_filt
|
---|
1642 | TVector<r_4> meanInRange_1405a1415Freq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1643 | meanInRange(diffOnOffOvOff_noCalib,ch1405,ch1415,meanInRange_1405a1415Freq_noCalib);
|
---|
1644 | xnt[11] = meanInRange_1405a1415Freq_noCalib(0);
|
---|
1645 | xnt[12] = meanInRange_1405a1415Freq_noCalib(1);
|
---|
1646 |
|
---|
1647 | TVector<r_4> meanInRange_1405a1410Freq_noCalib(NUMBER_OF_CHANNELS);
|
---|
1648 | meanInRange(diffOnOffOvOff_noCalib,ch1405,ch1410,meanInRange_1405a1410Freq_noCalib);
|
---|
1649 | xnt[13] = meanInRange_1405a1410Freq_noCalib(0);
|
---|
1650 | xnt[14] = meanInRange_1405a1410Freq_noCalib(1);
|
---|
1651 |
|
---|
1652 | //AST 09/01/12 follow 1405-1415, 1405-1410 and 1410-1415 MHz for (ON-OFF)
|
---|
1653 | TVector<r_4> meanInRange_1405a1415Freq_diffOnOff_noCalib(NUMBER_OF_CHANNELS);
|
---|
1654 | meanInRange(diffOnOff_noCalib,ch1405,ch1415,meanInRange_1405a1415Freq_diffOnOff_noCalib);
|
---|
1655 | xnt[15] = meanInRange_1405a1415Freq_diffOnOff_noCalib(0);
|
---|
1656 | xnt[16] = meanInRange_1405a1415Freq_diffOnOff_noCalib(1);
|
---|
1657 |
|
---|
1658 | TVector<r_4> meanInRange_1405a1410Freq_diffOnOff_noCalib(NUMBER_OF_CHANNELS);
|
---|
1659 | meanInRange(diffOnOff_noCalib,ch1405,ch1410,meanInRange_1405a1410Freq_diffOnOff_noCalib);
|
---|
1660 | xnt[17] = meanInRange_1405a1410Freq_diffOnOff_noCalib(0);
|
---|
1661 | xnt[18] = meanInRange_1405a1410Freq_diffOnOff_noCalib(1);
|
---|
1662 |
|
---|
1663 | TVector<r_4> meanInRange_1410a1415Freq_diffOnOff_noCalib(NUMBER_OF_CHANNELS);
|
---|
1664 | meanInRange(diffOnOff_noCalib,ch1410,ch1415,meanInRange_1410a1415Freq_diffOnOff_noCalib);
|
---|
1665 | xnt[19] = meanInRange_1410a1415Freq_diffOnOff_noCalib(0);
|
---|
1666 | xnt[20] = meanInRange_1410a1415Freq_diffOnOff_noCalib(1);
|
---|
1667 |
|
---|
1668 | //AST 10/01/12 follow 1400-1415 MHz ON, OFF (to continue plot on internal notes)
|
---|
1669 | TVector<r_4> meanInRange_1400a1415Freq_On_noCalib(NUMBER_OF_CHANNELS);
|
---|
1670 | meanInRange(aSpecOn,ch1400,ch1415,meanInRange_1400a1415Freq_On_noCalib);
|
---|
1671 | xnt[21] = meanInRange_1400a1415Freq_On_noCalib(0);
|
---|
1672 | xnt[22] = meanInRange_1400a1415Freq_On_noCalib(1);
|
---|
1673 | TVector<r_4> meanInRange_1400a1415Freq_Off_noCalib(NUMBER_OF_CHANNELS);
|
---|
1674 | meanInRange(aSpecOff,ch1400,ch1415,meanInRange_1400a1415Freq_Off_noCalib);
|
---|
1675 | xnt[23] = meanInRange_1400a1415Freq_Off_noCalib(0);
|
---|
1676 | xnt[24] = meanInRange_1400a1415Freq_Off_noCalib(1);
|
---|
1677 |
|
---|
1678 | //store infos to Ntuple
|
---|
1679 | onoffevolution.Fill(xnt);
|
---|
1680 |
|
---|
1681 | //Quit if enough
|
---|
1682 | if (totalNumberCycles >= para.maxNumberCycles_) break;
|
---|
1683 | }//end of cycles
|
---|
1684 |
|
---|
1685 | if (totalNumberCycles >= para.maxNumberCycles_) break;
|
---|
1686 |
|
---|
1687 | }//end files
|
---|
1688 | cout << "End of jobs: we have treated " << totalNumberCycles << " cycles" << endl;
|
---|
1689 | //Normalisation
|
---|
1690 | if(totalNumberCycles > 0){
|
---|
1691 | meanDiffONOFFovOFF_noCalib /= (r_4)totalNumberCycles;
|
---|
1692 | meanDiffONOFF_noCalib /= (r_4)totalNumberCycles;
|
---|
1693 | meanONovOFF_noCalib /= (r_4)totalNumberCycles;
|
---|
1694 | meanOFFovOFF_noCalib /= (r_4)totalNumberCycles;
|
---|
1695 | }
|
---|
1696 |
|
---|
1697 | {//save results
|
---|
1698 | stringstream tmp;
|
---|
1699 | tmp << totalNumberCycles;
|
---|
1700 | string fileName;
|
---|
1701 | if ( para.ppfFile_ == "dataRawNoGain" ) {
|
---|
1702 | fileName = para.outPath_+"/rawOnOffDiffNoGain_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
|
---|
1703 | } else {
|
---|
1704 | fileName = para.outPath_+"/rawOnOffDiff_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
|
---|
1705 | }
|
---|
1706 | POutPersist fos(fileName);
|
---|
1707 | cout << "Save output in " << fileName << endl;
|
---|
1708 |
|
---|
1709 | string tag = "meanNoCalib";
|
---|
1710 | fos << PPFNameTag(tag) << meanDiffONOFF_noCalib;
|
---|
1711 |
|
---|
1712 | tag = "meanOvOffNoCalib";
|
---|
1713 | fos << PPFNameTag(tag) << meanDiffONOFFovOFF_noCalib;
|
---|
1714 |
|
---|
1715 | tag = "meanOnovOffNoCalib";
|
---|
1716 | fos << PPFNameTag(tag) << meanONovOFF_noCalib;
|
---|
1717 |
|
---|
1718 | tag = "meanOffovOffNoCalib";
|
---|
1719 | fos << PPFNameTag(tag) << meanOFFovOFF_noCalib;
|
---|
1720 |
|
---|
1721 | tag = "onoffevol";
|
---|
1722 | fos << PPFNameTag(tag) << onoffevolution;
|
---|
1723 |
|
---|
1724 | }//end save
|
---|
1725 | }
|
---|
1726 | //JEC 14/11/11 New meanRawDiffOnOffCycles END
|
---|
1727 | //-------------------------------------------------------
|
---|
1728 | //Compute the median of Diff ON-OFF Raw spectra and also the mean/sigma of rebinned spectra
|
---|
1729 | //Used like:
|
---|
1730 | //
|
---|
1731 | void medianRawDiffOnOffCycles() throw(string) {
|
---|
1732 | list<string> listOfFiles;
|
---|
1733 | string directoryName;
|
---|
1734 | directoryName = para.inPath_ + "/" + para.sourceName_;
|
---|
1735 |
|
---|
1736 | //Make the listing of the directory
|
---|
1737 | listOfFiles = ListOfFileInDir(directoryName,para.ppfFile_);
|
---|
1738 |
|
---|
1739 | list<string>::const_iterator iFile, iFileEnd, iSpec, iSpecEnd;
|
---|
1740 | iFileEnd = listOfFiles.end();
|
---|
1741 |
|
---|
1742 |
|
---|
1743 | TArray<r_4> tableOfSpectra(NUMBER_OF_FREQ,NUMBER_OF_CHANNELS,para.maxNumberCycles_); //para.maxNumberCycles_ should be large enough...
|
---|
1744 |
|
---|
1745 | StringMatch match("specONOFFRaw[0-9]+"); //Tag of the PPF objects
|
---|
1746 | uint_4 nSpectra=0;
|
---|
1747 | //Loop on files
|
---|
1748 | for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
|
---|
1749 | if (para.debuglev_>90){
|
---|
1750 | cout << "load file <" << *iFile << ">" << endl;
|
---|
1751 | }
|
---|
1752 | PInPersist fin(*iFile);
|
---|
1753 | vector<string> vec = fin.GetNameTags();
|
---|
1754 | list<string> listOfSpectra;
|
---|
1755 | //Keep only required PPF objects
|
---|
1756 | std::remove_copy_if(
|
---|
1757 | vec.begin(), vec.end(), back_inserter(listOfSpectra),
|
---|
1758 | not1(match)
|
---|
1759 | );
|
---|
1760 |
|
---|
1761 | listOfSpectra.sort(stringCompare);
|
---|
1762 | iSpecEnd = listOfSpectra.end();
|
---|
1763 | //Loop of spectra matrix
|
---|
1764 | for (iSpec = listOfSpectra.begin(); iSpec !=iSpecEnd && (sa_size_t)nSpectra < para.maxNumberCycles_ ; ++iSpec){
|
---|
1765 | if (para.debuglev_>90){
|
---|
1766 | cout << " spactra <" << *iSpec << ">" << endl;
|
---|
1767 | }
|
---|
1768 | TMatrix<r_4> aSpec(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
1769 | fin.GetObject(aSpec,*iSpec);
|
---|
1770 |
|
---|
1771 | tableOfSpectra(Range::all(),Range::all(),Range(nSpectra)) = aSpec;
|
---|
1772 |
|
---|
1773 | nSpectra++;
|
---|
1774 | }//eo loop on spectra in a file
|
---|
1775 | }//eo loop on files
|
---|
1776 |
|
---|
1777 |
|
---|
1778 |
|
---|
1779 | TMatrix<r_4> medianOfSpectra(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
1780 | //Compute the median for each freq. and Channel
|
---|
1781 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; iCh++){
|
---|
1782 | for (sa_size_t freq =0; freq<NUMBER_OF_FREQ; freq++){
|
---|
1783 | TVector<r_4> tmp0(tableOfSpectra(Range(freq),Range(iCh),Range(0,nSpectra-1)).CompactAllDimensions());
|
---|
1784 | vector<r_4> tmp;
|
---|
1785 | tmp0.FillTo(tmp);
|
---|
1786 | medianOfSpectra(iCh,freq) = median(tmp.begin(),tmp.end());
|
---|
1787 | }
|
---|
1788 | }
|
---|
1789 |
|
---|
1790 |
|
---|
1791 | //Compute the reduced version of the mean and sigma
|
---|
1792 | TMatrix<r_4> meanRedMtx(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
|
---|
1793 | TMatrix<r_4> sigmaRedMtx(NUMBER_OF_CHANNELS,para.nSliceInFreq_);
|
---|
1794 | reduceSpectra(medianOfSpectra,meanRedMtx,sigmaRedMtx);
|
---|
1795 |
|
---|
1796 |
|
---|
1797 | sa_size_t f1320=freqToChan(1320.);
|
---|
1798 | sa_size_t f1345=freqToChan(1345.);
|
---|
1799 | sa_size_t f1355=freqToChan(1355.);
|
---|
1800 | sa_size_t f1380=freqToChan(1380.);
|
---|
1801 | //Compute baseline arround 1350Mhz on [1320-1345] U [1355-1380]
|
---|
1802 | if (para.debuglev_>9){
|
---|
1803 | cout << "Compute baseline arround 1350Mhz on [1320-1345] U [1355-1380]" << endl;
|
---|
1804 | }
|
---|
1805 | TVector<r_4>meanMed(NUMBER_OF_CHANNELS);
|
---|
1806 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh){
|
---|
1807 | double meanMed1;
|
---|
1808 | double sigmaMed1;
|
---|
1809 | TVector<r_4> band1;
|
---|
1810 | band1 = medianOfSpectra(Range(iCh),Range(f1320,f1345)).CompactAllDimensions();
|
---|
1811 | MeanSigma(band1,meanMed1,sigmaMed1);
|
---|
1812 | double meanMed2;
|
---|
1813 | double sigmaMed2;
|
---|
1814 | TVector<r_4> band2;
|
---|
1815 | band2 = medianOfSpectra(Range(iCh),Range(f1355,f1380)).CompactAllDimensions();
|
---|
1816 | MeanSigma(band2,meanMed2,sigmaMed2);
|
---|
1817 | meanMed(iCh) = (meanMed1+meanMed2)*0.5;
|
---|
1818 | }
|
---|
1819 | meanMed.Print(cout);
|
---|
1820 | cout << endl;
|
---|
1821 |
|
---|
1822 |
|
---|
1823 | //Compute the sigma in the range 1320MHz-1380MHz
|
---|
1824 | if (para.debuglev_>9){
|
---|
1825 | cout << "Compute the sigma in the range 1320MHz-1380MHz" << endl;
|
---|
1826 | }
|
---|
1827 | TVector<r_4>sigmaMed(NUMBER_OF_CHANNELS);
|
---|
1828 | sa_size_t redf1320=(sa_size_t)((1320.0-LOWER_FREQUENCY)/TOTAL_BANDWIDTH*para.nSliceInFreq_);
|
---|
1829 | sa_size_t redf1380=(sa_size_t)((1380.0-LOWER_FREQUENCY)/TOTAL_BANDWIDTH*para.nSliceInFreq_);
|
---|
1830 |
|
---|
1831 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh){
|
---|
1832 | double meanSigma;
|
---|
1833 | double sigmaSigma;
|
---|
1834 | TVector<r_4> band;
|
---|
1835 | band = sigmaRedMtx(Range(iCh),Range(redf1320,redf1380)).CompactAllDimensions();
|
---|
1836 | MeanSigma(band,meanSigma,sigmaSigma);
|
---|
1837 | meanSigma *= sqrt(para.nSliceInFreq_); //to scale to orignal spectra
|
---|
1838 | sigmaMed(iCh) = meanSigma;
|
---|
1839 | }
|
---|
1840 | sigmaMed.Print(cout);
|
---|
1841 | cout << endl;
|
---|
1842 |
|
---|
1843 |
|
---|
1844 |
|
---|
1845 | if (para.debuglev_>9){
|
---|
1846 | cout << "Compute medianOfSpectraNorm" << endl;
|
---|
1847 | }
|
---|
1848 | TMatrix<r_4> medianOfSpectraNorm(medianOfSpectra,false); //do not share the data...
|
---|
1849 | for (sa_size_t iCh=0; iCh<NUMBER_OF_CHANNELS; ++iCh){
|
---|
1850 | medianOfSpectraNorm.Row(iCh) -= meanMed(iCh);
|
---|
1851 | medianOfSpectraNorm.Row(iCh) /= sigmaMed(iCh);
|
---|
1852 | }
|
---|
1853 |
|
---|
1854 |
|
---|
1855 | {//Save the result
|
---|
1856 | stringstream tmp;
|
---|
1857 | tmp << nSpectra;
|
---|
1858 | string fileName = para.outPath_+"/medianDiffOnOffRaw_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
|
---|
1859 | cout << "Save median based on " << nSpectra << " cycles " << endl;
|
---|
1860 | POutPersist fos(fileName);
|
---|
1861 |
|
---|
1862 | string tag = "median";
|
---|
1863 | fos << PPFNameTag(tag) << medianOfSpectra;
|
---|
1864 |
|
---|
1865 | tag = "medianNorm";
|
---|
1866 | fos << PPFNameTag(tag) << medianOfSpectraNorm;
|
---|
1867 |
|
---|
1868 |
|
---|
1869 | tag = "meanmedred";
|
---|
1870 | fos << PPFNameTag(tag) << meanRedMtx;
|
---|
1871 | tag = "sigmamedred";
|
---|
1872 | fos << PPFNameTag(tag) << sigmaRedMtx;
|
---|
1873 | tag = "cycleVsfreq";
|
---|
1874 |
|
---|
1875 | TArray<r_4> tarr(tableOfSpectra(Range::all(),Range::all(),Range(0,nSpectra-1)));
|
---|
1876 | fos << PPFNameTag(tag) << tarr;
|
---|
1877 | }
|
---|
1878 | }
|
---|
1879 |
|
---|
1880 | // AST 5/12/2011
|
---|
1881 | //-------------------------------------------------------
|
---|
1882 | // Take all statistics from cluster data to compute Raw sensitivity vs. t_int
|
---|
1883 |
|
---|
1884 | void meanRawDiffOnOffAllClusters() throw(string) {
|
---|
1885 |
|
---|
1886 | // Sources names
|
---|
1887 | std::vector < std::string > sources; //we'll put all of the tokens in here
|
---|
1888 | std::string temp, insources = para.sourceName_;
|
---|
1889 | std::cout << insources << std::endl;
|
---|
1890 | while (insources.find("-", 0) != std::string::npos) { //does the string a comma in it?
|
---|
1891 | size_t pos = insources.find("-", 0); //store the position of the delimiter
|
---|
1892 | temp = insources.substr(0, pos); //get the token
|
---|
1893 | insources.erase(0, pos + 1); //erase it from the source
|
---|
1894 | sources.push_back(temp); //and put it into the array
|
---|
1895 | }
|
---|
1896 | sources.push_back(insources); //the last token is all alone
|
---|
1897 | std::cout << "Processing " << sources.size() << " sources" << std::endl;
|
---|
1898 |
|
---|
1899 | // Sources max number of cycles
|
---|
1900 | std::vector < std::string > cycles; //we'll put all of the tokens in here
|
---|
1901 | std::string temp1, incycles = para.maxNumberCyclesStr_;
|
---|
1902 | while (incycles.find("-", 0) != std::string::npos) { //does the string a hyphen in it?
|
---|
1903 | size_t pos = incycles.find("-", 0); //store the position of the delimiter
|
---|
1904 | temp1 = incycles.substr(0, pos); //get the token
|
---|
1905 | incycles.erase(0, pos + 1); //erase it from the source
|
---|
1906 | cycles.push_back(temp1); //and put it into the array
|
---|
1907 | }
|
---|
1908 | cycles.push_back(incycles); //the last token is all alone
|
---|
1909 |
|
---|
1910 | if ( sources.size() != cycles.size() ) {
|
---|
1911 | std::cout << "Problem: a max number of cycles for each source must be entered" << std::endl;
|
---|
1912 | exit (1);
|
---|
1913 | } else {
|
---|
1914 | for (uint j=0;j<cycles.size();j++) {
|
---|
1915 | cout<<"Source "<<sources.at(j)<<": max "<<cycles.at(j)<<" cycles"<< endl;
|
---|
1916 | }
|
---|
1917 | }
|
---|
1918 |
|
---|
1919 | // Begin analysis for each source
|
---|
1920 | list<string> listOfFiles,copylistOfFiles;
|
---|
1921 | string directoryName;
|
---|
1922 |
|
---|
1923 | //mean ON-OFF over the list of cycles
|
---|
1924 | TMatrix<r_4> meanDiffONOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //(ON-OFF)/GAIN
|
---|
1925 | TMatrix<r_4> meanDiffONOFFovOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); //(ON-OFF)/Filtered_OFF
|
---|
1926 | TMatrix<r_4> meanONovOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); // ON/Filtered_OFF
|
---|
1927 | TMatrix<r_4> meanOFFovOFF_noCalib(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ); // OFF/Filtered_OFF
|
---|
1928 | //Tuple only for RAW things to follow
|
---|
1929 | static const int NINFO=11;
|
---|
1930 | char* onffTupleName[NINFO]={"srcID","date","run","cycletot","cyclesource"
|
---|
1931 | ,"onoffRaw0f14101415","onoffRaw1f14101415"
|
---|
1932 | ,"onoffRaw0f141014125","onoffRaw1f141014125"
|
---|
1933 | ,"onoffRaw0f14101411","onoffRaw1f14101411"
|
---|
1934 | };
|
---|
1935 | NTuple onoffevolution(NINFO,onffTupleName);
|
---|
1936 | r_4 xnt[NINFO];
|
---|
1937 |
|
---|
1938 | //Loop on Sources
|
---|
1939 | int numberCyclesSource; // running number of cycles for each source
|
---|
1940 | int maxCyclesSource; // maximum number of cycles for each source
|
---|
1941 | int totalNumberRuns=0; //total number of runs (for all clusters)
|
---|
1942 | int totalNumberCycles=0; //total number of cycles (for all clusters)
|
---|
1943 | std::string dumm;
|
---|
1944 |
|
---|
1945 | for (uint iSource=0;iSource<sources.size();iSource++){
|
---|
1946 | directoryName = para.inPath_ + "/" + sources.at(iSource);
|
---|
1947 | maxCyclesSource = atoi(cycles.at(iSource).c_str());
|
---|
1948 | cout<<"Processing "<< maxCyclesSource<<" cycles for source "<<sources.at(iSource)<<endl;
|
---|
1949 |
|
---|
1950 | //Make the listing of the directory
|
---|
1951 | listOfFiles = ListOfFileInDir(directoryName,para.ppfFile_);
|
---|
1952 | cout << "Total number of files loaded..." << listOfFiles.size() << endl;
|
---|
1953 | // cout << endl;
|
---|
1954 |
|
---|
1955 | list<string>::const_iterator iFile, iFileEnd, iSpec, iSpecEnd;
|
---|
1956 | iFileEnd = listOfFiles.end();
|
---|
1957 |
|
---|
1958 | //1410-1415Mhz
|
---|
1959 | sa_size_t ch1410 = freqToChan(1410);
|
---|
1960 | sa_size_t ch1411 = freqToChan(1411);
|
---|
1961 | sa_size_t ch14125 = freqToChan(1412.5);
|
---|
1962 | sa_size_t ch1415 = freqToChan(1415);
|
---|
1963 |
|
---|
1964 | if (para.debuglev_>0){
|
---|
1965 | cout << "(1) freq. band for follow up [" << ch1410 << ", "<< ch1415 << "]" << endl;
|
---|
1966 | cout << "(2) freq. band for follow up [" << ch1410 << ", "<< ch14125 << "]" << endl;
|
---|
1967 | cout << "(3) freq. band for follow up [" << ch1410 << ", "<< ch1411 << "]" << endl;
|
---|
1968 | }
|
---|
1969 |
|
---|
1970 | numberCyclesSource=0; //total number of cycles in this source
|
---|
1971 | //Loop on files
|
---|
1972 | for (iFile = listOfFiles.begin(); iFile != iFileEnd; ++iFile) {
|
---|
1973 | if (para.debuglev_>90){
|
---|
1974 | cout << "load file <" << *iFile << ">" << endl;
|
---|
1975 | }
|
---|
1976 |
|
---|
1977 | vector<string> tokens;
|
---|
1978 | split(*iFile,"_",tokens);
|
---|
1979 | string dateOfRun = tokens[1];
|
---|
1980 | r_4 rdateOfRun = atoi(dateOfRun.c_str()) - 2011*1.e4;
|
---|
1981 | if (para.debuglev_>90){
|
---|
1982 | cout << "date <" << dateOfRun << ">" << endl;
|
---|
1983 | cout << "rdate <" << rdateOfRun << ">" << endl;
|
---|
1984 | }
|
---|
1985 | vector<string> tokens2;
|
---|
1986 | split(tokens[2],".",tokens2);
|
---|
1987 | string srcLower = tokens2[0], csrcID;
|
---|
1988 | size_t found;
|
---|
1989 | found=srcLower.find_first_of("0123456789");
|
---|
1990 | while (found!=string::npos){
|
---|
1991 | csrcID.push_back(srcLower[found]);
|
---|
1992 | found=srcLower.find_first_of("0123456789",found+1);
|
---|
1993 | }
|
---|
1994 | r_4 srcID = atoi(csrcID.c_str());
|
---|
1995 | if (para.debuglev_>1000){
|
---|
1996 | cout << "source <" << srcLower << ">" << endl;
|
---|
1997 | cout << "srcID <" << srcID << ">" << endl;
|
---|
1998 | }
|
---|
1999 |
|
---|
2000 | // AST remove bad data of Abell1205
|
---|
2001 | if ( (dateOfRun=="20110822"||dateOfRun=="20110903"||dateOfRun=="20110905"||dateOfRun=="20110912"||dateOfRun=="20110915") && srcLower == "abell1205" ) {
|
---|
2002 | cout << ">>> Skipping bad period " << dateOfRun << endl;
|
---|
2003 | continue;
|
---|
2004 | }
|
---|
2005 |
|
---|
2006 | PInPersist fin(*iFile);
|
---|
2007 | vector<string> vec = fin.GetNameTags();
|
---|
2008 |
|
---|
2009 | vector<string> modeList;
|
---|
2010 | modeList.push_back("On");
|
---|
2011 | modeList.push_back("Off");
|
---|
2012 | vector<string>::const_iterator iMode;
|
---|
2013 |
|
---|
2014 | map<string, list<int> > cycleModeCollect;
|
---|
2015 |
|
---|
2016 | for (iMode = modeList.begin(); iMode!=modeList.end(); ++iMode) {
|
---|
2017 | list<string> listOfSpectra;
|
---|
2018 | //Keep only required PPF objects
|
---|
2019 | string matchstr = "specRaw"+(*iMode)+"[0-9]+";
|
---|
2020 | std::remove_copy_if(
|
---|
2021 | vec.begin(), vec.end(), back_inserter(listOfSpectra),
|
---|
2022 | not1(StringMatch(matchstr))
|
---|
2023 | );
|
---|
2024 |
|
---|
2025 | listOfSpectra.sort(stringCompare);
|
---|
2026 | iSpecEnd = listOfSpectra.end();
|
---|
2027 |
|
---|
2028 | matchstr = "[0-9]+";
|
---|
2029 | //Loop of spectra matrix
|
---|
2030 | list<int> listOfCycles;
|
---|
2031 | for (iSpec = listOfSpectra.begin(); iSpec!=iSpecEnd; ++iSpec){
|
---|
2032 | int b,e;
|
---|
2033 | regexp(iSpec->c_str(),matchstr.c_str(),&b,&e);
|
---|
2034 | if (para.debuglev_>90){
|
---|
2035 | cout << " spectra <" << *iSpec << ">" << endl;
|
---|
2036 | cout << " cycle " << iSpec->substr(b) << endl;
|
---|
2037 | }
|
---|
2038 | listOfCycles.push_back(atoi((iSpec->substr(b)).c_str()));
|
---|
2039 | }//end loop spectra
|
---|
2040 | cycleModeCollect[*iMode] = listOfCycles;
|
---|
2041 | }//end of mode
|
---|
2042 |
|
---|
2043 | //Take the Intersection of the list Of cycles in mode Off and On
|
---|
2044 | list<int> commonCycles;
|
---|
2045 | set_intersection(cycleModeCollect["On"].begin(),
|
---|
2046 | cycleModeCollect["On"].end(),
|
---|
2047 | cycleModeCollect["Off"].begin(),
|
---|
2048 | cycleModeCollect["Off"].end(),
|
---|
2049 | back_inserter(commonCycles)
|
---|
2050 | );
|
---|
2051 |
|
---|
2052 | if (para.debuglev_>90){
|
---|
2053 | cout << "Liste of cycles common to On & Off: <";
|
---|
2054 | for (list<int>::iterator i=commonCycles.begin(); i!=commonCycles.end(); ++i){
|
---|
2055 | cout << *i << " ";
|
---|
2056 | }
|
---|
2057 | cout << ">" << endl;
|
---|
2058 | }
|
---|
2059 |
|
---|
2060 | //Loop on cycles
|
---|
2061 | for (list<int>::iterator ic=commonCycles.begin(); ic!=commonCycles.end(); ++ic){
|
---|
2062 |
|
---|
2063 | // AST 28.11.11 remove non-calibrated cycles for Abell1205 and Abell2440
|
---|
2064 | if ( *ic == 1 && srcLower == "abell1205" ) {
|
---|
2065 | if ( dateOfRun == "20110502" || dateOfRun == "20110607" || dateOfRun == "20110818" ) {
|
---|
2066 | cout << "Skipping non-calibrated cycle " << *ic << endl;
|
---|
2067 | continue;
|
---|
2068 | }
|
---|
2069 | } else if ( *ic == 1 && srcLower == "abell2440" ) {
|
---|
2070 | if ( dateOfRun == "20110516" ) {
|
---|
2071 | cout << "Skipping non-calibrated cycle " << *ic << endl;
|
---|
2072 | continue;
|
---|
2073 | }
|
---|
2074 | } else if ( *ic == 3 && srcLower == "abell1205" ) {
|
---|
2075 | if ( dateOfRun == "20110810" ) {
|
---|
2076 | cout << "Skipping non-calibrated cycle " << *ic << endl;
|
---|
2077 | continue;
|
---|
2078 | }
|
---|
2079 | }
|
---|
2080 |
|
---|
2081 | string ppftag;
|
---|
2082 | //load ON phase
|
---|
2083 | stringstream cycle;
|
---|
2084 | cycle << *ic;
|
---|
2085 | ppftag = "specRawOn"+cycle.str();
|
---|
2086 | TMatrix<r_4> aSpecOn(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
2087 | fin.GetObject(aSpecOn,ppftag);
|
---|
2088 |
|
---|
2089 | //Load OFF phase
|
---|
2090 | ppftag = "specRawOff"+cycle.str();
|
---|
2091 | TMatrix<r_4> aSpecOff(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
2092 | fin.GetObject(aSpecOff,ppftag);
|
---|
2093 |
|
---|
2094 | //Perform the difference ON-OFF
|
---|
2095 | TMatrix<r_4> diffOnOff_noCalib = aSpecOn - aSpecOff;
|
---|
2096 | meanDiffONOFF_noCalib += diffOnOff_noCalib;
|
---|
2097 |
|
---|
2098 | TMatrix<r_4> diffOnOffOvOff_noCalib(diffOnOff_noCalib,false); //do not share data
|
---|
2099 | TMatrix<r_4> aSpecOffFiltered(NUMBER_OF_CHANNELS,NUMBER_OF_FREQ);
|
---|
2100 | sa_size_t halfWidth = 35; //number of freq. bin for the 1/2 width of the filtering window
|
---|
2101 | medianFiltering(aSpecOff,halfWidth,aSpecOffFiltered);
|
---|
2102 | diffOnOffOvOff_noCalib.Div(aSpecOffFiltered); //division in place
|
---|
2103 | meanDiffONOFFovOFF_noCalib += diffOnOffOvOff_noCalib;
|
---|
2104 |
|
---|
2105 | numberCyclesSource++;
|
---|
2106 | totalNumberCycles++;
|
---|
2107 |
|
---|
2108 | //Fill NTuple
|
---|
2109 | xnt[0] = srcID;
|
---|
2110 | xnt[1] = rdateOfRun;
|
---|
2111 | xnt[2] = totalNumberRuns;
|
---|
2112 | xnt[3] = totalNumberCycles;
|
---|
2113 | xnt[4] = numberCyclesSource;
|
---|
2114 |
|
---|
2115 | TVector<r_4> meanInRange_1410a1415Freq_noCalib(NUMBER_OF_CHANNELS);
|
---|
2116 | meanInRange(diffOnOffOvOff_noCalib,ch1410,ch1415,meanInRange_1410a1415Freq_noCalib);
|
---|
2117 | TVector<r_4> meanInRange_1410a14125Freq_noCalib(NUMBER_OF_CHANNELS);
|
---|
2118 | meanInRange(diffOnOffOvOff_noCalib,ch1410,ch14125,meanInRange_1410a14125Freq_noCalib);
|
---|
2119 | TVector<r_4> meanInRange_1410a1411Freq_noCalib(NUMBER_OF_CHANNELS);
|
---|
2120 | meanInRange(diffOnOffOvOff_noCalib,ch1410,ch1411,meanInRange_1410a1411Freq_noCalib);
|
---|
2121 |
|
---|
2122 | xnt[5] = meanInRange_1410a1415Freq_noCalib(0);
|
---|
2123 | xnt[6] = meanInRange_1410a1415Freq_noCalib(1);
|
---|
2124 | xnt[7] = meanInRange_1410a14125Freq_noCalib(0);
|
---|
2125 | xnt[8] = meanInRange_1410a14125Freq_noCalib(1);
|
---|
2126 | xnt[9] = meanInRange_1410a1411Freq_noCalib(0);
|
---|
2127 | xnt[10] = meanInRange_1410a1411Freq_noCalib(1);
|
---|
2128 |
|
---|
2129 | onoffevolution.Fill(xnt);
|
---|
2130 |
|
---|
2131 | //Quit if enough
|
---|
2132 | if ( numberCyclesSource >= maxCyclesSource ) break;
|
---|
2133 | }//end loop on cycles
|
---|
2134 | if (numberCyclesSource >= maxCyclesSource) break;
|
---|
2135 | totalNumberRuns++;
|
---|
2136 | } // end loop on files
|
---|
2137 | cout << "End of job on source: we have treated " << numberCyclesSource << " cycles" << endl;
|
---|
2138 | } // end loop on sources
|
---|
2139 | cout << "End of jobs: we have treated " << totalNumberCycles << " cycles" << endl;
|
---|
2140 |
|
---|
2141 | //Normalisation
|
---|
2142 | if(totalNumberCycles > 0){
|
---|
2143 | meanDiffONOFF_noCalib /= (r_4)totalNumberCycles;
|
---|
2144 | meanDiffONOFFovOFF_noCalib /= (r_4)totalNumberCycles;
|
---|
2145 | }
|
---|
2146 |
|
---|
2147 | {//save results
|
---|
2148 | stringstream tmp;
|
---|
2149 | tmp << totalNumberCycles;
|
---|
2150 | string fileName = para.outPath_+"/rawOnOffDiff_"+StringToLower(para.sourceName_)+"-"+tmp.str()+"Cycles.ppf";
|
---|
2151 |
|
---|
2152 | POutPersist fos(fileName);
|
---|
2153 | cout << "Save output in " << fileName << endl;
|
---|
2154 |
|
---|
2155 | string tag = "meanNoCalib";
|
---|
2156 | fos << PPFNameTag(tag) << meanDiffONOFF_noCalib;
|
---|
2157 |
|
---|
2158 | tag = "meanOvOffNoCalib";
|
---|
2159 | fos << PPFNameTag(tag) << meanDiffONOFFovOFF_noCalib;
|
---|
2160 |
|
---|
2161 | tag = "onoffevol";
|
---|
2162 | fos << PPFNameTag(tag) << onoffevolution;
|
---|
2163 |
|
---|
2164 | }//end save
|
---|
2165 |
|
---|
2166 | }
|
---|
2167 |
|
---|
2168 | //-------------------------------------------------------
|
---|
2169 | int main(int narg, char* arg[]) {
|
---|
2170 |
|
---|
2171 | int rc = 0; //return code
|
---|
2172 | string msg; //message used in Exceptions
|
---|
2173 |
|
---|
2174 |
|
---|
2175 |
|
---|
2176 | //default value for initial parameters (see Para structure on top of the file)
|
---|
2177 | string debuglev = "0";
|
---|
2178 | string action = "meanDiffOnOff";
|
---|
2179 | string inputPath = ".";
|
---|
2180 | string outputPath = ".";
|
---|
2181 | string sourceName = "Abell85";
|
---|
2182 | string ppfFile;
|
---|
2183 | string nSliceInFreq = "32";
|
---|
2184 | string typeOfCalib="perRun";
|
---|
2185 | string calibFreq = "1346";
|
---|
2186 | string calibBandFreq="6.25";
|
---|
2187 | string mxcycles;
|
---|
2188 |
|
---|
2189 | // bool okarg=false;
|
---|
2190 | int ka=1;
|
---|
2191 | while (ka<narg) {
|
---|
2192 | if (strcmp(arg[ka],"-h")==0) {
|
---|
2193 | cout << "Usage: -act [meanRawDiffOnOff]|medianRawDiffOnOff|meanCalibBAODiffOnOff\n"
|
---|
2194 | << " -mxcycles <number> (max. number of cycles to be treated) or <list-of-numbers> if several sources are analysed \n"
|
---|
2195 | << " -calibfreq <number> (cf. freq. used by calibration operation)\n"
|
---|
2196 | << " -calibbandfreq <number> (cf. band of freq. used by calibration operation)\n"
|
---|
2197 | << " -src [Abell85] or list of sources [Abell85-Abell1205-Abell2440]\n"
|
---|
2198 | << " -inPath [.]|<top_root_dir of the ppf file>\n"
|
---|
2199 | << " (ex. /sps/baoradio/AmasNancay/JEC/\n "
|
---|
2200 | << " -outPath [.]|<dir of the output> \n"
|
---|
2201 | << " -nSliceInFreq [32]|<number of bin in freq. to cumulate>\n"
|
---|
2202 | << " -ppfFile <generic name of the input ppf files> (ex. diffOnOffRaw)\n"
|
---|
2203 | << " -debug <level> "
|
---|
2204 | << endl;
|
---|
2205 | return 0;
|
---|
2206 | }
|
---|
2207 | else if (strcmp(arg[ka],"-debug")==0) {
|
---|
2208 | debuglev=arg[ka+1];
|
---|
2209 | ka+=2;
|
---|
2210 | }
|
---|
2211 | else if (strcmp(arg[ka],"-act")==0) {
|
---|
2212 | action=arg[ka+1];
|
---|
2213 | ka+=2;
|
---|
2214 | }
|
---|
2215 | else if (strcmp(arg[ka],"-calibfreq")==0) {
|
---|
2216 | calibFreq=arg[ka+1];
|
---|
2217 | ka+=2;
|
---|
2218 | }
|
---|
2219 | else if (strcmp(arg[ka],"-calibbandfreq")==0) {
|
---|
2220 | calibBandFreq=arg[ka+1];
|
---|
2221 | ka+=2;
|
---|
2222 | }
|
---|
2223 | else if (strcmp(arg[ka],"-mxcycles")==0) {
|
---|
2224 | mxcycles=arg[ka+1];
|
---|
2225 | ka+=2;
|
---|
2226 | }
|
---|
2227 | else if (strcmp(arg[ka],"-inPath")==0) {
|
---|
2228 | inputPath=arg[ka+1];
|
---|
2229 | ka+=2;
|
---|
2230 | }
|
---|
2231 | else if (strcmp(arg[ka],"-outPath")==0) {
|
---|
2232 | outputPath=arg[ka+1];
|
---|
2233 | ka+=2;
|
---|
2234 | }
|
---|
2235 | else if (strcmp(arg[ka],"-src")==0) {
|
---|
2236 | sourceName=arg[ka+1];
|
---|
2237 | ka+=2;
|
---|
2238 | }
|
---|
2239 | else if (strcmp(arg[ka],"-ppfFile")==0) {
|
---|
2240 | ppfFile=arg[ka+1];
|
---|
2241 | ka+=2;
|
---|
2242 | }
|
---|
2243 | else if (strcmp(arg[ka],"-nSliceInFreq")==0) {
|
---|
2244 | nSliceInFreq=arg[ka+1];
|
---|
2245 | ka+=2;
|
---|
2246 | }
|
---|
2247 | else ka++;
|
---|
2248 | }//eo while
|
---|
2249 |
|
---|
2250 | para.debuglev_ = atoi(debuglev.c_str());
|
---|
2251 | para.inPath_ = inputPath;
|
---|
2252 | para.outPath_ = outputPath;
|
---|
2253 | para.sourceName_ = sourceName;
|
---|
2254 | para.ppfFile_ = ppfFile;
|
---|
2255 | para.nSliceInFreq_ = atoi(nSliceInFreq.c_str());
|
---|
2256 | para.calibFreq_ = calibFreq;
|
---|
2257 | para.calibBandFreq_ = calibBandFreq;
|
---|
2258 | para.rcalibFreq_ = atof(calibFreq.c_str());
|
---|
2259 | para.rcalibBandFreq_ = atof(calibBandFreq.c_str());
|
---|
2260 | if (mxcycles != "") {
|
---|
2261 | para.maxNumberCycles_ = atoi(mxcycles.c_str());
|
---|
2262 | para.maxNumberCyclesStr_ = mxcycles;
|
---|
2263 | } else {
|
---|
2264 | para.maxNumberCycles_ = std::numeric_limits<int>::max();
|
---|
2265 | para.maxNumberCyclesStr_ = "500";
|
---|
2266 | }
|
---|
2267 |
|
---|
2268 | cout << "Dump Initial parameters ............" << endl;
|
---|
2269 | cout << " action = " << action << "\n"
|
---|
2270 | << " maxNumberCycles = " << para.maxNumberCycles_ << "\n"
|
---|
2271 | << " inputPath = " << para.inPath_ << "\n"
|
---|
2272 | << " outputPath = " << para.outPath_ << "\n"
|
---|
2273 | << " sourceName = " << para.sourceName_ << "\n"
|
---|
2274 | << " ppfFile = " << para.ppfFile_ << "\n"
|
---|
2275 | << " nSliceInFreq = " << para.nSliceInFreq_ << "\n"
|
---|
2276 | << " calibFreq = " << para.calibFreq_ << "\n"
|
---|
2277 | << " calibBandFreq = " << para.calibBandFreq_ << "\n"
|
---|
2278 | << " debuglev = " << para.debuglev_ << "\n";
|
---|
2279 | cout << "...................................." << endl;
|
---|
2280 |
|
---|
2281 | if ( "" == ppfFile ) {
|
---|
2282 | cerr << "mergeAnaFiles.cc: you have forgotten ppfFile option"
|
---|
2283 | << endl;
|
---|
2284 | return 999;
|
---|
2285 | }
|
---|
2286 |
|
---|
2287 |
|
---|
2288 | try {
|
---|
2289 |
|
---|
2290 | // int b,e;
|
---|
2291 | // char *match=regexp("truc0machin","[a-z]+[0-9]*",&b,&e);
|
---|
2292 | // printf("->%s<-\n(b=%d e=%d)\n",match,b,e);
|
---|
2293 |
|
---|
2294 | if ( action == "meanRawDiffOnOff" ) {
|
---|
2295 | meanRawDiffOnOffCycles();
|
---|
2296 | } else if (action == "medianRawDiffOnOff") {
|
---|
2297 | medianRawDiffOnOffCycles();
|
---|
2298 | } else if (action == "meanCalibBAODiffOnOff") {
|
---|
2299 | meanCalibBAODiffOnOffCycles();
|
---|
2300 | } else if (action == "calibCoeffNtp") {
|
---|
2301 | calibCoeffNtp();
|
---|
2302 | } else if (action == "meanRawDiffOnOffAllClusters") {
|
---|
2303 | meanRawDiffOnOffAllClusters();
|
---|
2304 | } else {
|
---|
2305 | msg = "Unknown action " + action;
|
---|
2306 | throw msg;
|
---|
2307 | }
|
---|
2308 |
|
---|
2309 |
|
---|
2310 | } catch (std::exception& sex) {
|
---|
2311 | cerr << "mergeRawOnOff.cc std::exception :" << (string)typeid(sex).name()
|
---|
2312 | << "\n msg= " << sex.what() << endl;
|
---|
2313 | rc = 78;
|
---|
2314 | }
|
---|
2315 | catch ( string str ) {
|
---|
2316 | cerr << "mergeRawOnOff.cc Exception raised: " << str << endl;
|
---|
2317 | }
|
---|
2318 | catch (...) {
|
---|
2319 | cerr << "mergeRawOnOff.cc catched unknown (...) exception " << endl;
|
---|
2320 | rc = 79;
|
---|
2321 | }
|
---|
2322 |
|
---|
2323 | return 0;
|
---|
2324 |
|
---|
2325 | }
|
---|