Changeset 5298 for trunk/MagicSoft/Mars
- Timestamp:
- 10/20/04 16:21:23 (20 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r5296 r5298 20 20 -*-*- END OF LINE -*-*- 21 21 22 2004/10/20: Markus Gaug22 2004/10/20: Thomas Bretz 23 23 24 24 * msignal/MExtractTimeFastSpline.cc: 25 25 - fixed a compiler warning: Unused variable 26 27 * mjob/MJPedestal.cc: 28 - added "DisableOutput" as a resource option 29 30 * mbase/MArrayF.h: 31 - added a new Reset(Float_t) member function 32 33 * msignal/MExtractTimeAndChargeDigitalFilter.[h,cc]: 34 - enrolled some if-else blocks 35 - fixed includes 36 - enhanced error handling when a file is read 37 - moved output from PostProcess to PreProcess 38 - fixed and enhanced ReadEnv 39 40 * mjob/MJCalibrateSignal.cc: 41 - enabled variance display for tabs showing signal 42 43 * mhist/MHCamera.cc: 44 - fixed returning GetBinError for kProfile mode switched on 26 45 27 46 … … 130 149 2004/10/08: R. DelosReyes 131 150 132 * mbase/M runIter.h151 * mbase/MRunIter.h 133 152 - changed the name of the Sort() function name by SortRuns() 134 153 to avoid conflicts with the Sort() function in the MDirIter class. -
trunk/MagicSoft/Mars/mbase/MArrayF.h
r5088 r5298 96 96 } 97 97 98 void Reset(Float_t f) 99 { 100 for (UInt_t i=0; i<fN; i++) 101 fArray[i] = f; 102 } 103 98 104 void Set(UInt_t n) 99 105 { -
trunk/MagicSoft/Mars/mhist/MHCamera.cc
r5156 r5298 1162 1162 } 1163 1163 else 1164 1164 { 1165 1165 rc = TH1D::GetBinError(bin); 1166 rc = Profile(rc); 1167 } 1168 1169 return rc; 1166 } 1167 1168 return Profile(rc); 1170 1169 } 1171 1170 -
trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc
r5167 r5298 332 332 MHCamEvent evt6(0, "Times", "Arrival Time;;T [slice]"); 333 333 evt0.EnableVariance(); 334 evt1.EnableVariance(); 334 335 evt2.EnableVariance(); 335 336 evt3.EnableVariance(); 337 evt4.EnableVariance(); 336 338 evt6.EnableVariance(); 337 339 -
trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
r5234 r5298 17 17 ! 18 18 ! Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de> 19 ! Markus Gaug ,04/2004 <mailto:markus@ifae.es>19 ! Author(s): Markus Gaug, 4/2004 <mailto:markus@ifae.es> 20 20 ! 21 21 ! Copyright: MAGIC Software Development, 2000-2004 … … 84 84 const Float_t MJPedestal::fgRefPedRmsExtraGalacticOuter = 3.35; 85 85 const Float_t MJPedestal::fgRefPedRmsGalacticOuter = 4.2; 86 86 87 // -------------------------------------------------------------------------- 87 88 // … … 99 100 fDataCheck(kFALSE), fUseData(kFALSE) 100 101 { 101 102 fName = name ? name : "MJPedestal"; 103 fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)"; 104 105 SetNormalStorage(); 106 102 fName = name ? name : "MJPedestal"; 103 fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)"; 104 105 SetNormalStorage(); 107 106 } 108 107 … … 128 127 Bool_t MJPedestal::ReadPedestalCam() 129 128 { 130 131 if (IsNoStorage()) 132 return kFALSE; 133 134 const TString fname = GetOutputFile(); 135 136 if (gSystem->AccessPathName(fname, kFileExists)) 137 { 138 *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl; 139 return kFALSE; 140 } 141 142 *fLog << inf << "Reading from file: " << fname << endl; 143 144 TFile file(fname, "READ"); 145 if (fPedestalCam.Read()<=0) 146 { 147 *fLog << err << "Unable to read MPedestalCam from " << fname << endl; 148 return kFALSE; 149 } 150 151 if (file.FindKey("MBadPixelsCam")) 152 { 153 MBadPixelsCam bad; 129 if (IsNoStorage()) 130 return kFALSE; 131 132 const TString fname = GetOutputFile(); 133 134 if (gSystem->AccessPathName(fname, kFileExists)) 135 { 136 *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl; 137 return kFALSE; 138 } 139 140 *fLog << inf << "Reading from file: " << fname << endl; 141 142 TFile file(fname, "READ"); 143 if (fPedestalCam.Read()<=0) 144 { 145 *fLog << err << "Unable to read MPedestalCam from " << fname << endl; 146 return kFALSE; 147 } 148 149 if (file.FindKey("MBadPixelsCam")) 150 { 151 MBadPixelsCam bad; 154 152 if (bad.Read()<=0) 155 153 { 156 154 *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl; 157 155 return kFALSE; 158 156 } 159 157 fBadPixels.Merge(bad); 160 158 } 161 159 162 if (fDisplay && !fDisplay->GetCanvas("Pedestals"))163 fDisplay->Read();164 165 return kTRUE;160 if (fDisplay && !fDisplay->GetCanvas("Pedestals")) 161 fDisplay->Read(); 162 163 return kTRUE; 166 164 } 167 165 … … 371 369 void MJPedestal::DisplayReferenceLines(MHCamera *cam, const Int_t what) const 372 370 { 373 374 371 Double_t x = cam->GetNbinsX(); 375 372 … … 441 438 void MJPedestal::FixDataCheckHist(TH1D *hist) const 442 439 { 443 444 440 hist->SetDirectory(NULL); 445 441 hist->SetStats(0); … … 459 455 xaxe->SetLabelSize(0.05); 460 456 yaxe->SetLabelSize(0.05); 461 462 } 457 } 458 463 459 /* 464 460 Bool_t MJPedestal::WriteEventloop(MEvtLoop &evtloop) const … … 494 490 // Prefix.DataCheck: Yes, No 495 491 // Prefix.UseData: Yes, No 492 // Prefix.DisableOutput: Yes, No 496 493 // 497 494 Bool_t MJPedestal::CheckEnvLocal() … … 502 499 SetDataCheck(GetEnv("DataCheck", fDataCheck)); 503 500 SetUseData(GetEnv("UseData", fUseData)); 501 SetNoStorage(GetEnv("DisableOutput", IsNoStorage())); 504 502 505 503 return kTRUE; … … 516 514 Bool_t MJPedestal::WriteResult() 517 515 { 518 519 if (IsNoStorage()) 516 if (IsNoStorage()) 517 return kTRUE; 518 519 if (fPathOut.IsNull()) 520 return kTRUE; 521 522 const TString oname(GetOutputFile()); 523 524 *fLog << inf << "Writing to file: " << oname << endl; 525 526 TFile file(oname, "UPDATE", "File created by MJPedestal", 9); 527 if (!file.IsOpen()) 528 { 529 *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl; 530 return kFALSE; 531 } 532 533 if (fDisplay && fDisplay->Write()<=0) 534 { 535 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl; 536 return kFALSE; 537 } 538 539 if (fPedestalCam.Write()<=0) 540 { 541 *fLog << err << "Unable to write MPedestalCam to " << oname << endl; 542 return kFALSE; 543 } 544 545 if (fBadPixels.Write()<=0) 546 { 547 *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl; 548 return kFALSE; 549 } 550 520 551 return kTRUE; 521 522 if (fPathOut.IsNull())523 return kTRUE;524 525 const TString oname(GetOutputFile());526 527 *fLog << inf << "Writing to file: " << oname << endl;528 529 TFile file(oname, "UPDATE", "File created by MJPedestal", 9);530 if (!file.IsOpen())531 {532 *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;533 return kFALSE;534 }535 536 if (fDisplay && fDisplay->Write()<=0)537 {538 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;539 return kFALSE;540 }541 542 if (fPedestalCam.Write()<=0)543 {544 *fLog << err << "Unable to write MPedestalCam to " << oname << endl;545 return kFALSE;546 }547 548 if (fBadPixels.Write()<=0)549 {550 *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;551 return kFALSE;552 }553 554 return kTRUE;555 552 } 556 553 -
trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc
r5203 r5298 51 51 #include "MExtractTimeAndChargeDigitalFilter.h" 52 52 53 #include <errno.h> 54 #include <fstream> 55 56 #include <TFile.h> 57 #include <TH1F.h> 58 #include <TH2F.h> 59 #include <TString.h> 60 #include <TMatrix.h> 61 53 62 #include "MLog.h" 54 63 #include "MLogManip.h" 55 64 56 65 #include "MPedestalPix.h" 57 58 #include "TFile.h"59 #include "TH1F.h"60 #include "TH2F.h"61 #include "TString.h"62 #include "TMatrix.h"63 64 #include <fstream>65 66 66 67 ClassImp(MExtractTimeAndChargeDigitalFilter); … … 78 79 const Int_t MExtractTimeAndChargeDigitalFilter::fgSignalStartBinHiGain = 4; 79 80 const Int_t MExtractTimeAndChargeDigitalFilter::fgSignalStartBinLoGain = 4; 81 80 82 // -------------------------------------------------------------------------- 81 83 // … … 91 93 MExtractTimeAndChargeDigitalFilter::MExtractTimeAndChargeDigitalFilter(const char *name, const char *title) 92 94 { 93 94 fName = name ? name : "MExtractTimeAndChargeDigitalFilter"; 95 fTitle = title ? title : "Digital Filter"; 96 97 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast); 98 SetWindowSize(); 99 SetBinningResolution(); 100 SetSignalStartBin(); 101 102 ReadWeightsFile(""); 95 fName = name ? name : "MExtractTimeAndChargeDigitalFilter"; 96 fTitle = title ? title : "Digital Filter"; 97 98 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast); 99 SetWindowSize(); 100 SetBinningResolution(); 101 SetSignalStartBin(); 102 103 ReadWeightsFile(""); 103 104 } 104 105 105 106 106 // --------------------------------------------------------------------------------------- … … 129 129 130 130 if (fWindowSizeHiGain > availhirange) 131 { 131 { 132 // Please simplify this! 132 133 *fLog << warn << GetDescriptor() 133 134 << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",fWindowSizeHiGain, … … 150 151 if (fWindowSizeLoGain > availlorange) 151 152 { 153 // Please simplify this! 152 154 *fLog << warn << GetDescriptor() 153 155 << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",fWindowSizeLoGain, … … 182 184 Bool_t MExtractTimeAndChargeDigitalFilter::ReInit(MParList *pList) 183 185 { 184 185 if (!MExtractTimeAndCharge::ReInit(pList)) 186 return kFALSE; 187 188 Int_t range = fHiGainLast - fHiGainFirst + 1 + fHiLoLast; 189 190 fHiGainSignal.Set(range); 191 192 range = fLoGainLast - fLoGainFirst + 1; 193 194 fLoGainSignal.Set(range); 195 196 fTimeShiftHiGain = (Float_t)fHiGainFirst + 0.5 + 1./fBinningResolutionHiGain; 197 fTimeShiftLoGain = (Float_t)fLoGainFirst + 0.5 + 1./fBinningResolutionLoGain; 198 199 return kTRUE; 186 if (!MExtractTimeAndCharge::ReInit(pList)) 187 return kFALSE; 188 189 fHiGainSignal.Set(fHiGainLast - fHiGainFirst + 1 + fHiLoLast); 190 fLoGainSignal.Set(fLoGainLast - fLoGainFirst + 1); 191 192 fTimeShiftHiGain = (Float_t)fHiGainFirst + 0.5 + 1./fBinningResolutionHiGain; 193 fTimeShiftLoGain = (Float_t)fLoGainFirst + 0.5 + 1./fBinningResolutionLoGain; 194 195 return kTRUE; 200 196 } 201 197 198 Int_t MExtractTimeAndChargeDigitalFilter::PreProcess(MParList *pList) 199 { 200 *fLog << endl; 201 *fLog << inf << "Using the following weights: " << endl; 202 *fLog << "Hi-Gain:" << endl; 203 204 for (Int_t i=0; i<fBinningResolutionHiGain*fWindowSizeHiGain; i++) 205 *fLog << " " << fAmpWeightsHiGain[i] << " \t " << fTimeWeightsHiGain[i] << endl; 206 207 *fLog << "Lo-Gain:" << endl; 208 209 for (Int_t i=0; i<fBinningResolutionLoGain*fWindowSizeLoGain; i++) 210 *fLog << " " << fAmpWeightsLoGain[i] << " \t " << fTimeWeightsLoGain[i] << endl; 211 212 return MExtractTimeAndCharge::PreProcess(pList); 213 } 202 214 203 215 void MExtractTimeAndChargeDigitalFilter::FindTimeAndChargeHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Float_t &dsum, … … 267 279 const Float_t ABoffs = ped.GetPedestalABoffset(); 268 280 269 Float_t PedMean[2];270 PedMean[0] = pedes + ABoffs;271 PedMean[1] = pedes - ABoffs;281 Float_t pedmean[2]; 282 pedmean[0] = pedes + ABoffs; 283 pedmean[1] = pedes - ABoffs; 272 284 273 285 // … … 286 298 { 287 299 const Int_t idx = fBinningResolutionHiGain*sample+fBinningResolutionHalfHiGain; 288 const Float_t pex = fHiGainSignal[sample+i]- PedMean[(sample+i+abflag) & 0x1];300 const Float_t pex = fHiGainSignal[sample+i]-pedmean[(sample+i+abflag) & 0x1]; 289 301 sum += fAmpWeightsHiGain [idx]*pex; 290 302 time_sum += fTimeWeightsHiGain[idx]*pex; … … 298 310 } 299 311 } /* for (Int_t i=0;i<range-fWindowSizeHiGain;i++) */ 300 301 if (fmax!=0) 302 { 303 ftime_max /= fmax; 304 Int_t t_iter = Int_t(ftime_max*fBinningResolutionHiGain); 305 Int_t sample_iter = 0; 306 307 while ( t_iter > fBinningResolutionHalfHiGain-1 || t_iter < -fBinningResolutionHalfHiGain ) 308 { 309 if (t_iter > fBinningResolutionHalfHiGain-1) 310 { 311 t_iter -= fBinningResolutionHiGain; 312 max_p--; 313 sample_iter--; 314 } 315 if (t_iter < -fBinningResolutionHalfHiGain) 316 { 317 t_iter += fBinningResolutionHiGain; 318 max_p++; 319 sample_iter++; 320 } 321 } 322 323 sum = 0.; 324 // 325 // Slide with a window of size fWindowSizeHiGain over the sample 326 // and multiply the entries with the corresponding weights 327 // 328 for (Int_t sample=0; sample < fWindowSizeHiGain; sample++) 329 { 330 const Int_t idx = fBinningResolutionHiGain*sample + fBinningResolutionHalfHiGain + t_iter; 331 const Int_t ids = max_p + sample; 332 const Float_t pex = ids < 0 ? 0. : 333 ( ids > range ? 0. : fHiGainSignal[ids]-PedMean[(ids+abflag) & 0x1]); 334 sum += fAmpWeightsHiGain [idx]*pex; 335 time_sum += fTimeWeightsHiGain[idx]*pex; 336 } 337 338 if (sum != 0.) 339 time = max_p + fTimeShiftHiGain /* this shifts the time to the start of the rising edge */ 340 - ((Float_t)t_iter)/fBinningResolutionHiGain - time_sum/sum; 341 else 342 time = 0.; 343 } /* if (max!=0) */ 344 else 345 time=0.; 346 347 return; 312 313 time = 0; 314 if (fmax==0) 315 return; 316 317 ftime_max /= fmax; 318 Int_t t_iter = Int_t(ftime_max*fBinningResolutionHiGain); 319 Int_t sample_iter = 0; 320 321 while ( t_iter > fBinningResolutionHalfHiGain-1 || t_iter < -fBinningResolutionHalfHiGain ) 322 { 323 if (t_iter > fBinningResolutionHalfHiGain-1) 324 { 325 t_iter -= fBinningResolutionHiGain; 326 max_p--; 327 sample_iter--; 328 } 329 if (t_iter < -fBinningResolutionHalfHiGain) 330 { 331 t_iter += fBinningResolutionHiGain; 332 max_p++; 333 sample_iter++; 334 } 335 } 336 337 sum = 0.; 338 // 339 // Slide with a window of size fWindowSizeHiGain over the sample 340 // and multiply the entries with the corresponding weights 341 // 342 for (Int_t sample=0; sample < fWindowSizeHiGain; sample++) 343 { 344 const Int_t idx = fBinningResolutionHiGain*sample + fBinningResolutionHalfHiGain + t_iter; 345 const Int_t ids = max_p + sample; 346 const Float_t pex = ids < 0 ? 0. : 347 ( ids > range ? 0. : fHiGainSignal[ids]-pedmean[(ids+abflag) & 0x1]); 348 sum += fAmpWeightsHiGain [idx]*pex; 349 time_sum += fTimeWeightsHiGain[idx]*pex; 350 } 351 352 if (sum == 0) 353 return; 354 355 time = max_p + fTimeShiftHiGain /* this shifts the time to the start of the rising edge */ 356 - ((Float_t)t_iter)/fBinningResolutionHiGain - time_sum/sum; 348 357 } 349 358 … … 386 395 const Float_t ABoffs = ped.GetPedestalABoffset(); 387 396 388 Float_t PedMean[2];389 PedMean[0] = pedes + ABoffs;390 PedMean[1] = pedes - ABoffs;397 Float_t pedmean[2]; 398 pedmean[0] = pedes + ABoffs; 399 pedmean[1] = pedes - ABoffs; 391 400 392 401 // … … 405 414 { 406 415 const Int_t idx = fBinningResolutionLoGain*sample+fBinningResolutionHalfLoGain; 407 const Float_t pex = fLoGainSignal[sample+i]- PedMean[(sample+i+abflag) & 0x1];416 const Float_t pex = fLoGainSignal[sample+i]-pedmean[(sample+i+abflag) & 0x1]; 408 417 sum += fAmpWeightsLoGain [idx]*pex; 409 418 time_sum += fTimeWeightsLoGain[idx]*pex; … … 417 426 } 418 427 } /* for (Int_t i=0;i<range-fWindowSizeLoGain;i++) */ 419 420 if (fmax!=0) 421 { 422 ftime_max /= fmax; 423 Int_t t_iter = Int_t(ftime_max*fBinningResolutionLoGain); 424 Int_t sample_iter = 0; 425 426 while ( t_iter > fBinningResolutionHalfLoGain-1 || t_iter < -fBinningResolutionHalfLoGain ) 427 { 428 if (t_iter > fBinningResolutionHalfLoGain-1) 429 { 430 t_iter -= fBinningResolutionLoGain; 431 max_p--; 432 sample_iter--; 433 } 434 if (t_iter < -fBinningResolutionHalfLoGain) 435 { 436 t_iter += fBinningResolutionLoGain; 437 max_p++; 438 sample_iter++; 439 } 440 } 441 442 sum = 0.; 443 // 444 // Slide with a window of size fWindowSizeLoGain over the sample 445 // and multiply the entries with the corresponding weights 446 // 447 for (Int_t sample=0; sample < fWindowSizeLoGain; sample++) 448 { 449 const Int_t idx = fBinningResolutionLoGain*sample + fBinningResolutionHalfLoGain + t_iter; 450 const Int_t ids = max_p + sample; 451 const Float_t pex = ids < 0 ? 0. : 452 ( ids > range ? 0. : fLoGainSignal[ids]-PedMean[(ids+abflag) & 0x1]); 453 sum += fAmpWeightsLoGain [idx]*pex; 454 time_sum += fTimeWeightsLoGain[idx]*pex; 455 } 456 457 if (sum != 0.) 458 time = max_p + fTimeShiftLoGain /* this shifts the time to the start of the rising edge */ 459 - ((Float_t)t_iter)/fBinningResolutionLoGain - time_sum/sum; 460 else 461 time = 0.; 462 } /* if (max!=0) */ 463 else 464 time=0.; 465 466 return; 428 429 time = 0; 430 if (fmax==0) 431 return; 432 433 ftime_max /= fmax; 434 Int_t t_iter = Int_t(ftime_max*fBinningResolutionLoGain); 435 Int_t sample_iter = 0; 436 437 while ( t_iter > fBinningResolutionHalfLoGain-1 || t_iter < -fBinningResolutionHalfLoGain ) 438 { 439 if (t_iter > fBinningResolutionHalfLoGain-1) 440 { 441 t_iter -= fBinningResolutionLoGain; 442 max_p--; 443 sample_iter--; 444 } 445 if (t_iter < -fBinningResolutionHalfLoGain) 446 { 447 t_iter += fBinningResolutionLoGain; 448 max_p++; 449 sample_iter++; 450 } 451 } 452 453 sum = 0.; 454 455 // 456 // Slide with a window of size fWindowSizeLoGain over the sample 457 // and multiply the entries with the corresponding weights 458 // 459 for (Int_t sample=0; sample < fWindowSizeLoGain; sample++) 460 { 461 const Int_t idx = fBinningResolutionLoGain*sample + fBinningResolutionHalfLoGain + t_iter; 462 const Int_t ids = max_p + sample; 463 const Float_t pex = ids < 0 ? 0. : 464 ( ids > range ? 0. : fLoGainSignal[ids]-pedmean[(ids+abflag) & 0x1]); 465 sum += fAmpWeightsLoGain [idx]*pex; 466 time_sum += fTimeWeightsLoGain[idx]*pex; 467 } 468 469 if (sum == 0) 470 return; 471 472 time = max_p + fTimeShiftLoGain /* this shifts the time to the start of the rising edge */ 473 - ((Float_t)t_iter)/fBinningResolutionLoGain - time_sum/sum; 467 474 } 468 475 476 // -------------------------------------------------------------------------- 477 // 478 // Read the setup from a TEnv, eg: 479 // MJPedestal.MExtractor.WindowSizeHiGain: 6 480 // MJPedestal.MExtractor.WindowSizeLoGain: 6 481 // MJPedestal.MExtractor.BinningResolutionHiGain: 10 482 // MJPedestal.MExtractor.BinningResolutionLoGain: 10 483 // MJPedestal.MExtractor.WeightsFile: filename 484 // 469 485 Int_t MExtractTimeAndChargeDigitalFilter::ReadEnv(const TEnv &env, TString prefix, Bool_t print) 470 486 { 471 472 Byte_t hw = fWindowSizeHiGain; 473 Byte_t lw = fWindowSizeLoGain; 474 Bool_t rc = kFALSE; 475 476 if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print)) 477 { 478 hw = GetEnvValue(env, prefix, "WindowSizeHiGain", hw); 479 rc = kTRUE; 480 } 481 if (IsEnvDefined(env, prefix, "WindowSizeLoGain", print)) 482 { 483 lw = GetEnvValue(env, prefix, "WindowSizeLoGain", lw); 484 rc = kTRUE; 485 } 486 487 if (rc) 488 SetWindowSize(hw, lw); 489 490 if (IsEnvDefined(env, prefix, "BinningResolution", print)) 491 { 492 SetBinningResolution(GetEnvValue(env, prefix, "BinningResolutionHiGain", fBinningResolutionHiGain), 493 GetEnvValue(env, prefix, "BinningResolutionLoGain", fBinningResolutionLoGain)); 494 rc = kTRUE; 495 } 496 497 rc = MExtractor::ReadEnv(env, prefix, print) ? kTRUE : rc; 498 499 return rc; 500 } 501 502 Int_t MExtractTimeAndChargeDigitalFilter::PostProcess() 503 { 504 505 *fLog << endl; 506 *fLog << inf << "Used High Gain weights in the extractor: " << endl; 507 508 for (Int_t i=0;i<fBinningResolutionHiGain*fWindowSizeHiGain; i++) 509 *fLog << inf << fAmpWeightsHiGain[i] << " " << fTimeWeightsHiGain[i] << endl; 510 511 *fLog << endl; 512 *fLog << inf << "Used Low Gain weights in the extractor: " << endl; 513 for (Int_t i=0;i<fBinningResolutionLoGain*fWindowSizeLoGain; i++) 514 *fLog << inf << fAmpWeightsLoGain[i] << " " << fTimeWeightsLoGain[i] << endl; 515 516 return kTRUE; 487 Byte_t hw = fWindowSizeHiGain; 488 Byte_t lw = fWindowSizeLoGain; 489 Bool_t rc = kFALSE; 490 491 if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print)) 492 { 493 hw = GetEnvValue(env, prefix, "WindowSizeHiGain", hw); 494 rc = kTRUE; 495 } 496 if (IsEnvDefined(env, prefix, "WindowSizeLoGain", print)) 497 { 498 lw = GetEnvValue(env, prefix, "WindowSizeLoGain", lw); 499 rc = kTRUE; 500 } 501 502 if (rc) 503 SetWindowSize(hw, lw); 504 505 Bool_t rc2 = kFALSE; 506 Int_t brh = fBinningResolutionHiGain; 507 Int_t brl = fBinningResolutionLoGain; 508 509 if (IsEnvDefined(env, prefix, "BinningResolutionHiGain", print)) 510 { 511 brh = GetEnvValue(env, prefix, brh); 512 rc2 = kTRUE; 513 } 514 if (IsEnvDefined(env, prefix, "BinningResolutionLoGain", print)) 515 { 516 brl = GetEnvValue(env, prefix, brl); 517 rc2 = kTRUE; 518 } 519 520 if (rc2) 521 { 522 SetBinningResolution(brh, brl); 523 rc = kTRUE; 524 } 525 526 if (IsEnvDefined(env, prefix, "WeightsFile", print)) 527 { 528 if (!ReadWeightsFile(GetEnvValue(env, prefix, "WeightsFile", ""))) 529 return kERROR; 530 rc = kTRUE; 531 } 532 533 return MExtractTimeAndCharge::ReadEnv(env, prefix, print) ? kTRUE : rc; 517 534 } 518 535 … … 526 543 Bool_t MExtractTimeAndChargeDigitalFilter::ReadWeightsFile(TString filename) 527 544 { 528 529 fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain); 530 fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain); 531 fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain); 532 fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain); 533 534 if (filename.IsNull()) 535 { 536 for (UInt_t i=0; i<fAmpWeightsHiGain.GetSize(); i++) 537 { 538 fAmpWeightsHiGain [i] = 1.; 539 fTimeWeightsHiGain[i] = 1.; 540 } 541 for (UInt_t i=0; i<fAmpWeightsLoGain.GetSize(); i++) 542 { 543 fAmpWeightsLoGain [i] = 1.; 544 fTimeWeightsLoGain[i] = 1.; 545 } 546 return kTRUE; 547 } 548 549 ifstream fin(filename.Data()); 550 551 if (!fin) 552 { 553 *fLog << err << GetDescriptor() 554 << ": No weights file found: " << filename << endl; 555 return kFALSE; 556 } 557 558 Int_t len = 0; 559 Int_t cnt = 0; 560 Bool_t hi = kFALSE; 561 Bool_t lo = kFALSE; 562 563 TString str; 564 565 while (1) 566 { 567 568 str.ReadLine(fin); 569 if (!fin) 570 break; 571 572 573 if (str.Contains("# High Gain Weights:")) 574 { 575 str.ReplaceAll("# High Gain Weights:",""); 576 sscanf(str.Data(),"%2i%2i",&fWindowSizeHiGain,&fBinningResolutionHiGain); 577 *fLog << inf << "Found number of High Gain slices: " << fWindowSizeHiGain 578 << " and High Gain resolution: " << fBinningResolutionHiGain << endl; 579 len = fBinningResolutionHiGain*fWindowSizeHiGain; 580 fAmpWeightsHiGain .Set(len); 581 fTimeWeightsHiGain.Set(len); 582 hi = kTRUE; 583 continue; 584 } 585 586 if (str.Contains("# Low Gain Weights:")) 587 { 588 str.ReplaceAll("# Low Gain Weights:",""); 589 sscanf(str.Data(),"%2i%2i",&fWindowSizeLoGain,&fBinningResolutionLoGain); 590 *fLog << inf << "Found number of Low Gain slices: " << fWindowSizeLoGain 591 << " and Low Gain resolution: " << fBinningResolutionLoGain << endl; 592 len = fBinningResolutionLoGain*fWindowSizeHiGain; 593 fAmpWeightsLoGain .Set(len); 594 fTimeWeightsLoGain.Set(len); 595 lo = kTRUE; 596 continue; 597 } 598 599 if (str.Contains("#")) 600 continue; 601 602 if (len == 0) 603 continue; 604 605 sscanf(str.Data(),"\t%f\t%f",lo ? &fAmpWeightsLoGain [cnt] : &fAmpWeightsHiGain [cnt], 606 lo ? &fTimeWeightsLoGain[cnt] : &fTimeWeightsHiGain[cnt]); 607 608 if (++cnt == len) 609 { 610 len = 0; 611 cnt = 0; 612 } 613 } 614 615 if (cnt != len) 616 { 617 *fLog << err << GetDescriptor() 618 << ": Size mismatch in weights file " << filename << endl; 619 return kFALSE; 620 } 621 622 if (!hi) 623 { 624 *fLog << err << GetDescriptor() 625 << ": No correct header found in weights file " << filename << endl; 626 return kFALSE; 627 } 628 629 return kTRUE; 545 fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain); 546 fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain); 547 fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain); 548 fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain); 549 550 if (filename.IsNull()) 551 { 552 fAmpWeightsHiGain.Reset(1); 553 fTimeWeightsHiGain.Reset(1); 554 fAmpWeightsLoGain.Reset(1); 555 fTimeWeightsLoGain.Reset(1); 556 return kTRUE; 557 } 558 559 ifstream fin(filename.Data()); 560 if (!fin) 561 { 562 *fLog << err << GetDescriptor() << ": ERROR - Cannot open file " << filename << ": "; 563 *fLog << strerror(errno) << endl; 564 return kFALSE; 565 } 566 567 *fLog << inf << "Reading weights file " << filename << "..." << flush; 568 569 Int_t len = 0; 570 Int_t cnt = 0; 571 Int_t line = 0; 572 Bool_t hi = kFALSE; 573 Bool_t lo = kFALSE; 574 575 TString str; 576 577 while (1) 578 { 579 str.ReadLine(fin); 580 if (!fin) 581 break; 582 583 line++; 584 585 if (str.Contains("# High Gain Weights:")) 586 { 587 if (hi) 588 { 589 *fLog << err << "ERROR - 'High Gain Weights' found twice in line #" << line << "." << endl; 590 return kFALSE; 591 } 592 593 if (2!=sscanf(str.Data(), "# High Gain Weights:%2i %2i", &fWindowSizeHiGain, &fBinningResolutionHiGain)) 594 { 595 *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl; 596 *fLog << str << endl; 597 return kFALSE; 598 } 599 600 len = fBinningResolutionHiGain*fWindowSizeHiGain; 601 fAmpWeightsHiGain .Set(len); 602 fTimeWeightsHiGain.Set(len); 603 hi = kTRUE; 604 continue; 605 } 606 607 if (str.Contains("# Low Gain Weights:")) 608 { 609 if (lo) 610 { 611 *fLog << err << "ERROR - 'Lo Gain Weights' found twice in line #" << line << "." << endl; 612 return kFALSE; 613 } 614 615 if (2!=sscanf(str.Data(),"# Low Gain Weights:%2i %2i", &fWindowSizeLoGain, &fBinningResolutionLoGain)) 616 { 617 *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl; 618 *fLog << str << endl; 619 return kFALSE; 620 } 621 622 len = fBinningResolutionLoGain*fWindowSizeHiGain; 623 fAmpWeightsLoGain .Set(len); 624 fTimeWeightsLoGain.Set(len); 625 lo = kTRUE; 626 continue; 627 } 628 629 // Handle lines with comments 630 if (str.Contains("#")) 631 continue; 632 633 // Nothing found so far 634 if (len == 0) 635 continue; 636 637 if (2!=sscanf(str.Data(), "%f %f", 638 lo ? &fAmpWeightsLoGain [cnt] : &fAmpWeightsHiGain [cnt], 639 lo ? &fTimeWeightsLoGain[cnt] : &fTimeWeightsHiGain[cnt])) 640 { 641 *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl; 642 *fLog << str << endl; 643 return kFALSE; 644 } 645 646 if (++cnt == len) 647 { 648 len = 0; 649 cnt = 0; 650 } 651 } 652 653 if (cnt != len) 654 { 655 *fLog << err << "Size mismatch in weights file " << filename << endl; 656 return kFALSE; 657 } 658 659 if (!hi) 660 { 661 *fLog << err << "No correct header found in weights file " << filename << endl; 662 return kFALSE; 663 } 664 665 *fLog << "done." << endl; 666 667 *fLog << inf << " File contains " << fWindowSizeHiGain << " hi-gain slices "; 668 *fLog << "and with a resolution of " << fBinningResolutionHiGain << endl; 669 670 *fLog << inf << " File contains " << fWindowSizeLoGain << " lo-gain slices "; 671 *fLog << "and with a resolution of " << fBinningResolutionLoGain << endl; 672 673 return kTRUE; 630 674 } 631 675 -
trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h
r5162 r5298 16 16 { 17 17 private: 18 19 18 static const Byte_t fgHiGainFirst; 20 19 static const Byte_t fgHiGainLast; … … 34 33 Float_t fTimeShiftLoGain; 35 34 36 Int_t fSignalStartBinHiGain; 37 Int_t fSignalStartBinLoGain; 35 Int_t fSignalStartBinHiGain; //! 36 Int_t fSignalStartBinLoGain; //! 38 37 39 Int_t fWindowSizeHiGain; 40 Int_t fWindowSizeLoGain; 38 Int_t fWindowSizeHiGain; 39 Int_t fWindowSizeLoGain; 41 40 42 41 Int_t fBinningResolutionHiGain; … … 45 44 Int_t fBinningResolutionHalfLoGain; 46 45 47 MArrayF fAmpWeightsHiGain; 48 MArrayF fTimeWeightsHiGain; 49 MArrayF fAmpWeightsLoGain; 50 MArrayF fTimeWeightsLoGain; 46 MArrayF fAmpWeightsHiGain; //! 47 MArrayF fTimeWeightsHiGain; //! 48 MArrayF fAmpWeightsLoGain; //! 49 MArrayF fTimeWeightsLoGain; //! 51 50 52 Bool_t ReInit( MParList *pList);53 Int_t P ostProcess();54 51 Bool_t ReInit(MParList *pList); 52 Int_t PreProcess(MParList *pList); 53 55 54 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); 56 55 57 56 protected: 58 59 57 virtual void FindTimeAndChargeHiGain(Byte_t *firstused, Byte_t *logain, Float_t &sum, Float_t &dsum, 60 58 Float_t &time, Float_t &dtime, … … 89 87 } 90 88 91 ClassDef(MExtractTimeAndChargeDigitalFilter, 0) // Hendrik's digital filter89 ClassDef(MExtractTimeAndChargeDigitalFilter, 1) // Hendrik's digital filter 92 90 }; 93 91 94 92 #endif 95 96 97
Note:
See TracChangeset
for help on using the changeset viewer.