Changeset 3061 for trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc
- Timestamp:
- 02/08/04 22:17:27 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mcalib/MHCalibrationBlindPixel.cc
r3026 r3061 63 63 #include "MHCalibrationConfig.h" 64 64 65 65 66 #include <TStyle.h> 66 67 #include <TCanvas.h> 67 68 #include <TPaveText.h> 68 69 70 #include <TGraph.h> 69 71 #include <TF1.h> 70 72 #include <TH1.h> 71 73 #include <TRandom.h> 72 74 75 #include "MFFT.h" 73 76 #include "MLog.h" 74 77 #include "MLogManip.h" … … 80 83 const Int_t MHCalibrationBlindPixel::fgBlindPixelChargeNbins = 1000; 81 84 const Int_t MHCalibrationBlindPixel::fgBlindPixelTimeNbins = 22; 82 const Int_t MHCalibrationBlindPixel::fgBlindPixelChargevsNbins = 10000;83 85 const Axis_t MHCalibrationBlindPixel::fgBlindPixelTimeFirst = -9.00; 84 86 const Axis_t MHCalibrationBlindPixel::fgBlindPixelTimeLast = 12.00; 85 87 const Double_t MHCalibrationBlindPixel::fgBlindPixelElectronicAmp = 0.008; 86 88 const Double_t MHCalibrationBlindPixel::fgBlindPixelElectronicAmpError = 0.002; 89 90 const Axis_t MHCalibrationBlindPixel::fNyquistFreq = 1.0; 91 const Axis_t MHCalibrationBlindPixel::fMinFreq = 0.; 92 const Int_t MHCalibrationBlindPixel::fPSDNbins = 30; 87 93 88 94 // -------------------------------------------------------------------------- … … 95 101 fTimeGausFit(NULL), 96 102 fSinglePhePedFit(NULL), 103 fPSDHiGain(NULL), 104 fPSDLoGain(NULL), 105 fHPSD(NULL), 106 fPSDExpFit(NULL), 107 fChargeXaxis(NULL), 108 fPSDXaxis(NULL), 109 fCurrentSize(1024), 97 110 fFitLegend(NULL) 98 111 { … … 119 132 fHBlindPixelTime->SetDirectory(NULL); 120 133 121 fHBlindPixelChargevsN = new TH1I("HBlindPixelChargevsN","Sum of Charges vs. Event Number", 122 fgBlindPixelChargevsNbins,-0.5,(Axis_t)fgBlindPixelChargevsNbins-0.5); 123 fHBlindPixelChargevsN->SetXTitle("Event Nr."); 124 fHBlindPixelChargevsN->SetYTitle("Sum of FADC slices"); 125 fHBlindPixelChargevsN->SetDirectory(NULL); 134 fHiGains = new TArrayF(fCurrentSize); 135 fLoGains = new TArrayF(fCurrentSize); 126 136 127 137 Clear(); … … 136 146 delete fHBlindPixelCharge; 137 147 delete fHBlindPixelTime; 138 delete fHBlindPixelChargevsN; 148 149 delete fHiGains; 150 delete fLoGains; 139 151 140 152 if (fHBlindPixelPSD) … … 146 158 if(fSinglePhePedFit) 147 159 delete fSinglePhePedFit; 160 if (fPSDExpFit) 161 delete fPSDExpFit; 162 if (fHPSD) 163 delete fHPSD; 164 if (fChargeXaxis) 165 delete fChargeXaxis; 166 if (fPSDXaxis) 167 delete fPSDXaxis; 148 168 149 169 } … … 151 171 void MHCalibrationBlindPixel::Clear(Option_t *o) 152 172 { 173 174 fTotalEntries = 0; 175 fCurrentSize = 1024; 153 176 154 177 fBlindPixelChargefirst = -200.; … … 196 219 if(fSinglePhePedFit) 197 220 delete fSinglePhePedFit; 221 if (fPSDExpFit) 222 delete fPSDExpFit; 223 if (fHPSD) 224 delete fHPSD; 225 if (fChargeXaxis) 226 delete fChargeXaxis; 227 if (fPSDXaxis) 228 delete fPSDXaxis; 229 if (fPSDHiGain) 230 delete fPSDHiGain; 231 if (fPSDLoGain) 232 delete fPSDLoGain; 233 234 CLRBIT(fFlags,kFitOK); 235 CLRBIT(fFlags,kOscillating); 198 236 199 237 return; … … 207 245 fHBlindPixelCharge->Reset(); 208 246 fHBlindPixelTime->Reset(); 209 fHBlindPixelChargevsN->Reset(); 210 211 } 247 248 fHiGains->Set(1024); 249 fLoGains->Set(1024); 250 251 fHiGains->Reset(0.); 252 fLoGains->Reset(0.); 253 254 255 } 256 257 Bool_t MHCalibrationBlindPixel::CheckOscillations() 258 { 259 260 if (fPSDExpFit) 261 return IsOscillating(); 262 263 MFFT fourier; 264 265 fPSDLoGain = fourier.PowerSpectrumDensity(fLoGains); 266 fPSDHiGain = fourier.PowerSpectrumDensity(fHiGains); 267 268 Int_t entries; 269 TArrayF *array; 270 271 fHPSD = new TH1F("HBlindPixelPSD", 272 "Power Spectrum Density Projection Blind Pixel", 273 fPSDNbins,fMinFreq,fNyquistFreq); 274 275 array = fPSDHiGain; 276 entries = array->GetSize(); 277 278 for (Int_t i=0;i<entries;i++) 279 fHPSD->Fill(array->At(i)); 280 281 // 282 // First guesses for the fit (should be as close to reality as possible, 283 // 284 const Double_t area_guess = entries*10.; 285 286 fPSDExpFit = new TF1("PSDExpFit","[0]*exp(-[1]*x)",0.,1.); 287 288 fPSDExpFit->SetParameters(entries,10.); 289 fPSDExpFit->SetParNames("Area","slope"); 290 fPSDExpFit->SetParLimits(0,0.,3.*area_guess); 291 fPSDExpFit->SetParLimits(1,5.,20.); 292 fPSDExpFit->SetRange(fMinFreq,fNyquistFreq); 293 294 fHPSD->Fit(fPSDExpFit,"RQL0"); 295 296 fPSDProb = fPSDExpFit->GetProb(); 297 298 if (fPSDProb < gkProbLimit) 299 { 300 SETBIT(fFlags,kOscillating); 301 return kTRUE; 302 } 303 304 CLRBIT(fFlags,kOscillating); 305 306 return kFALSE; 307 } 308 309 void MHCalibrationBlindPixel::CreatePSDXaxis(Int_t n) 310 { 311 312 if (fPSDXaxis) 313 return; 314 315 fPSDXaxis = new TArrayF(n); 316 317 for (Int_t i=0;i<n;i++) 318 fPSDXaxis->AddAt((Float_t)i,i); 319 } 320 321 void MHCalibrationBlindPixel::CreateChargeXaxis(Int_t n) 322 { 323 324 if (!fChargeXaxis) 325 { 326 fChargeXaxis = new TArrayF(n); 327 for (Int_t i=0;i<n;i++) 328 fChargeXaxis->AddAt((Float_t)i,i); 329 return; 330 } 331 332 if (fChargeXaxis->GetSize() == n) 333 return; 334 335 const Int_t diff = fChargeXaxis->GetSize()-n; 336 fChargeXaxis->Set(n); 337 if (diff < 0) 338 for (Int_t i=n;i<n+diff;i++) 339 fChargeXaxis->AddAt((Float_t)i,i); 340 } 341 342 void MHCalibrationBlindPixel::CutArrayBorder(TArrayF *array) 343 { 344 345 Int_t i; 346 347 for (i=array->GetSize()-1;i>=0;i--) 348 if (array->At(i) != 0) 349 { 350 array->Set(i+1); 351 break; 352 } 353 } 354 355 const Bool_t MHCalibrationBlindPixel::IsFitOK() const 356 { 357 return TESTBIT(fFlags,kFitOK); 358 } 359 360 const Bool_t MHCalibrationBlindPixel::IsOscillating() 361 { 362 363 if (fPSDExpFit) 364 return TESTBIT(fFlags,kOscillating); 365 366 return CheckOscillations(); 367 368 } 369 370 Bool_t MHCalibrationBlindPixel::FillGraphs(Float_t qhi,Float_t qlo) 371 { 372 373 if (fTotalEntries >= fCurrentSize) 374 { 375 fCurrentSize *= 2; 376 377 fHiGains->Set(fCurrentSize); 378 fLoGains->Set(fCurrentSize); 379 } 380 381 fHiGains->AddAt(qhi,fTotalEntries); 382 fLoGains->AddAt(qlo,fTotalEntries); 383 384 fTotalEntries++; 385 386 return kTRUE; 387 388 } 389 390 212 391 213 392 Bool_t MHCalibrationBlindPixel::FillBlindPixelCharge(Float_t q) … … 221 400 } 222 401 223 Bool_t MHCalibrationBlindPixel::FillBlindPixelChargevsN(Stat_t rq, Int_t t)224 {225 return fHBlindPixelChargevsN->Fill(t,rq) > -1;226 }227 228 402 229 403 // ------------------------------------------------------------------------- … … 236 410 fFitLegend = new TPaveText(0.05,0.05,0.95,0.95); 237 411 238 if ( fFitOK)412 if (IsFitOK()) 239 413 fFitLegend->SetFillColor(80); 240 414 else … … 284 458 t8->SetBit(kCanDelete); 285 459 286 if ( fFitOK)460 if (IsFitOK()) 287 461 { 288 462 TText *t = fFitLegend->AddText(0.,0.,"Result of the Fit: OK"); … … 333 507 TCanvas *c = MakeDefCanvas(this,550,700); 334 508 335 c->Divide(2, 3);509 c->Divide(2,4); 336 510 337 511 gROOT->SetSelectedPad(NULL); … … 344 518 fHBlindPixelCharge->Draw(opt); 345 519 346 if ( fFitOK)520 if (IsFitOK()) 347 521 fSinglePheFit->SetLineColor(kGreen); 348 522 else … … 366 540 fHBlindPixelTime->Draw(opt); 367 541 368 c->cd(4); 369 370 fHBlindPixelChargevsN->Draw(opt); 371 542 CutArrayBorder(fHiGains); 543 CreateChargeXaxis(fHiGains->GetSize()); 544 545 c->cd(5); 546 gPad->SetTicks(); 547 TGraph *gr1 = new TGraph(fChargeXaxis->GetSize(), 548 fChargeXaxis->GetArray(), 549 fHiGains->GetArray()); 550 gr1->SetTitle("Evolution of HiGain charges with event number"); 551 gr1->SetBit(kCanDelete); 552 gr1->Draw("AL"); 553 554 CutArrayBorder(fLoGains); 555 CreateChargeXaxis(fHiGains->GetSize()); 556 557 c->cd(6); 558 gPad->SetTicks(); 559 TGraph *gr2 = new TGraph(fChargeXaxis->GetSize(), 560 fChargeXaxis->GetArray(), 561 fLoGains->GetArray()); 562 gr2->SetTitle("Evolution of HiGain charges with event number"); 563 gr2->SetBit(kCanDelete); 564 gr2->Draw("AL"); 565 372 566 c->Modified(); 373 567 c->Update(); 374 375 c->cd(5); 376 377 // fHBlindPixelPSD = (TH1F*)MFFT::PowerSpectrumDensity(fHBlindPixelChargevsN); 378 // TH1F *hist = MFFT::PowerSpectrumDensity((*this)->fHBlindPixelChargevsN); 379 380 // fHBlindPixelPSD->Draw(opt); 568 569 c->cd(7); 570 571 TArrayF *array; 572 573 if (!fPSDHiGain) 574 return; 575 array = fPSDHiGain; 576 577 if (!fPSDXaxis) 578 CreatePSDXaxis(array->GetSize()); 579 580 TGraph *gr3 = new TGraph(fPSDXaxis->GetSize(),fPSDXaxis->GetArray(),array->GetArray()); 581 gr3->SetTitle("Power Spectrum Density"); 582 gr3->SetBit(kCanDelete); 583 gr3->Draw("AL"); 584 381 585 c->Modified(); 382 586 c->Update(); 383 587 588 c->cd(8); 589 590 gStyle->SetOptStat(111111); 591 gPad->SetTicks(); 592 593 if (fHPSD->Integral() > 0) 594 gPad->SetLogy(); 595 596 fHPSD->Draw(opt); 597 598 if (fPSDExpFit) 599 { 600 fPSDExpFit->SetLineColor(IsOscillating() ? kRed : kGreen); 601 fPSDExpFit->Draw("same"); 602 } 603 604 c->Modified(); 605 c->Update(); 606 384 607 } 385 608 … … 653 876 *fLog << err << "ERROR: Fit Probability " << fProb 654 877 << " is smaller than the allowed value: " << gkProbLimit << endl; 655 fFitOK = kFALSE;878 CLRBIT(fFlags,kFitOK); 656 879 return kFALSE; 657 880 } … … 663 886 *fLog << err << "ERROR: Statistics is too low: Only " << contSinglePhe 664 887 << " in the Single Photo-Electron peak " << endl; 665 fFitOK = kFALSE;888 CLRBIT(fFlags,kFitOK); 666 889 return kFALSE; 667 890 } … … 669 892 *fLog << inf << contSinglePhe << " in Single Photo-Electron peak " << endl; 670 893 671 fFitOK = kTRUE;894 SETBIT(fFlags,kFitOK); 672 895 673 896 return kTRUE; … … 678 901 { 679 902 680 Int_t nbins = 30;903 Int_t nbins = 20; 681 904 682 905 CutEdges(fHBlindPixelCharge,nbins); … … 684 907 fBlindPixelChargefirst = fHBlindPixelCharge->GetBinLowEdge(fHBlindPixelCharge->GetXaxis()->GetFirst()); 685 908 fBlindPixelChargelast = fHBlindPixelCharge->GetBinLowEdge(fHBlindPixelCharge->GetXaxis()->GetLast())+fHBlindPixelCharge->GetBinWidth(0); 686 687 CutEdges(fHBlindPixelChargevsN,0);688 909 689 910 }
Note:
See TracChangeset
for help on using the changeset viewer.