- Timestamp:
- 03/18/08 17:47:37 (17 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r8882 r8883 45 45 * mpointing/MPointingDevCalc.cc: 46 46 - added some more comments 47 48 * mhflux/MMcSpectrumWeight.[h,cc]: 49 - added the possibility to extend a spectrum by "fake" statistics 47 50 48 51 -
trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.cc
r8746 r8883 428 428 // and fEnergyMax correctly describe the range. 429 429 // 430 // If scale is given the histogram statistics is further extended by the 431 // new spectrum according to the scale factor (eg. 1.2: by 20%) 432 // 430 433 // In the 1D case it is assumed that the x-axis is a zenith angle binning. 431 434 // In the 2D case the x-axis is assumed to be zenith angle, the y-axis 432 435 // to be energy. 433 436 // 434 void MMcSpectrumWeight::CompleteEnergySpectrum(TH1 &h, Double_t emin ) const437 void MMcSpectrumWeight::CompleteEnergySpectrum(TH1 &h, Double_t emin, Double_t scale) const 435 438 { 436 439 if (h.InheritsFrom(TH3::Class())) 437 440 { 438 *fLog << "ERROR - MMcSpctrumWeight::CompleteEnergySpectrum doesn't support TH3." << endl;439 441 return; 440 442 } 441 443 442 if (fEnergyMin <= emin) 444 if (fEnergyMin < emin) 445 { 446 *fLog << err << "ERROR - MMcSpctrumWeight::CompleteEnergySpectrum: fEnergyMin ("; 447 *fLog << fEnergyMin << ") smaller than emin (" << emin << ")." << endl; 443 448 return; 444 449 } 450 451 // Total number of events for the new spectrum in the same 452 // energy range as the current histogram is filled 445 453 const Double_t norm = GetSpecNewIntegral(); 446 454 455 // Check if it is only a histogram in ZA 447 456 if (!h.InheritsFrom(TH2::Class())) 448 457 { 449 h.Scale(GetSpecNewIntegral(emin, fEnergyMax)/norm); 458 // Warning: Simply scaling the zenith angle distribution might 459 // increase fluctuations for low statistics. 460 const Double_t f = GetSpecNewIntegral(emin, fEnergyMax)/norm; 461 h.Scale(f*scale); 450 462 return; 451 463 } … … 453 465 const TAxis &axey = *h.GetYaxis(); 454 466 467 // Find energy range between the minimum energy to be filles (emin) 468 // and the minimum energy corresponding to the data filled into 469 // this histogram (fEnergyMin) 455 470 const Int_t first = axey.FindFixBin(emin); 456 471 const Int_t last = axey.FindFixBin(fEnergyMin); 472 const Int_t max = axey.FindFixBin(fEnergyMax); 457 473 458 474 for (int x=1; x<=h.GetNbinsX(); x++) 459 475 { 460 const Double_t f = h.Integral(x, x, -1, 9999)/norm; 461 462 for (int y=first; y<=last; y++) 463 { 464 const Double_t lo = axey.GetBinLowEdge(y) <emin ? emin : axey.GetBinLowEdge(y); 465 const Double_t hi = axey.GetBinLowEdge(y+1)>fEnergyMin ? fEnergyMin : axey.GetBinLowEdge(y+1); 466 467 h.AddBinContent(h.GetBin(x, y), f*GetSpecNewIntegral(lo, hi)); 468 } 476 // Ratio between the number of events in the zenith angle 477 // bin corresponding to x and the new spectrum. 478 const Double_t f = h.Integral(x, x, -1, 9999)/norm; 479 480 // Fill histogram with the "new spectrum" between 481 // emin and fEnergyMin. 482 if (emin<fEnergyMin) 483 for (int y=first; y<=last; y++) 484 { 485 // Check if the bin is only partly filled by the energy range 486 const Double_t lo = axey.GetBinLowEdge(y) <emin ? emin : axey.GetBinLowEdge(y); 487 const Double_t hi = axey.GetBinLowEdge(y+1)>fEnergyMin ? fEnergyMin : axey.GetBinLowEdge(y+1); 488 489 // Add the new spectrum extending the existing spectrum 490 h.AddBinContent(h.GetBin(x, y), f*GetSpecNewIntegral(lo, hi)); 491 } 492 493 // If scale is >1 we also have to increse the statistics f the 494 // histogram according to scale. 495 if (scale>1) 496 for (int y=first; y<=max; y++) 497 { 498 // Check if the bin is only partly filled by the energy range 499 const Double_t lo = axey.GetBinLowEdge(y) <emin ? emin : axey.GetBinLowEdge(y); 500 const Double_t hi = axey.GetBinLowEdge(y+1)>fEnergyMax ? fEnergyMax : axey.GetBinLowEdge(y+1); 501 502 // Use the analytical solution to scale the histogram 503 h.AddBinContent(h.GetBin(x, y), f*GetSpecNewIntegral(lo, hi)*(scale-1)); 504 } 469 505 } 470 506 } -
trunk/MagicSoft/Mars/mhflux/MMcSpectrumWeight.h
r8680 r8883 101 101 102 102 // Functions 103 void CompleteEnergySpectrum(TH1 &h, Double_t emin ) const;103 void CompleteEnergySpectrum(TH1 &h, Double_t emin, Double_t scale=0) const; 104 104 105 105 // TObject
Note:
See TracChangeset
for help on using the changeset viewer.