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