Changeset 7151 for trunk/MagicSoft/Mars/mhflux
- Timestamp:
- 06/13/05 10:20:58 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mhflux
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
r7142 r7151 135 135 136 136 for (int i=5; i<fFunc->GetNpar(); i++) 137 fFunc->ReleaseParameter(i); 137 if (fFitBackground) 138 fFunc->ReleaseParameter(i); 139 else 140 fFunc->SetParameter(i, 0); 138 141 139 142 // options : N do not store the function, do not draw … … 142 145 // Q quiet mode 143 146 // E Perform better Errors estimation using Minos technique 144 h.Fit(fFunc, "NQI", "", bgmin, bgmax); 145 146 fChiSqBg = fFunc->GetChisquare()/fFunc->GetNDF(); 147 if (fFitBackground) 148 { 149 h.Fit(fFunc, "NQI", "", bgmin, bgmax); 150 fChiSqBg = fFunc->GetChisquare()/fFunc->GetNDF(); 151 } 152 147 153 148 154 // ------------------------------------ 149 if (paint )155 if (paint && fFitBackground) 150 156 { 151 157 fFunc->SetRange(0, 90); … … 209 215 fSignificance = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground); 210 216 217 if (TMath::IsNaN(fSignificance)) 218 fSignificance=0; 219 211 220 if (fEventsExcess<0) 212 221 fEventsExcess=0; … … 240 249 fSignificance = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground/alpha, alpha); 241 250 251 if (TMath::IsNaN(fSignificance)) 252 fSignificance=0; 242 253 if (fEventsExcess<0) 243 254 fEventsExcess=0; 244 /* 245 TF1 func("", "gaus(0)+pol0(3)", 0., 90.); 246 247 const Double_t A = fEventsSignal/bin; 248 const Double_t dA = TMath::Abs(A); 249 func.SetParLimits(0, -dA*4, dA*4); 250 func.SetParLimits(2, 0, 90); 251 func.SetParLimits(3, -dA, dA); 252 253 func.SetParameter(0, A); 254 func.FixParameter(1, 0); 255 func.SetParameter(2, fSigMax*0.75); 256 func.SetParameter(3, 0); 257 258 // options : N do not store the function, do not draw 259 // I use integral of function in bin rather than value at bin center 260 // R use the range specified in the function range 261 // Q quiet mode 262 // E Perform better Errors estimation using Minos technique 263 TH1D h(hon); 264 h.Add(&hof, -1); 265 h.Fit(&func, "NQI", "", 0, 90); 266 267 fChiSqSignal = func.GetChisquare()/func.GetNDF(); 268 269 const Int_t bin1 = h.GetXaxis()->FindFixBin(func.GetParameter(2)*2); 270 271 fChiSqBg = 0; 272 for (int i=bin1; i<=h.GetNbinsX(); i++) 273 { 274 const Float_t val = h.GetBinContent(i); 275 fChiSqBg = val*val; 276 } 277 if (fChiSqBg>0) 278 fChiSqBg /= h.GetNbinsX()+1-bin1; 279 280 fCoefficients.Set(func.GetNpar(), func.GetParameters()); 281 282 // ------------------------------------ 283 if (paint) 284 { 285 func.SetLineColor(kBlue); 286 func.SetLineWidth(2); 287 func.Paint("same"); 288 } 289 // ------------------------------------ 290 */ 255 291 256 return kTRUE; 292 257 } … … 323 288 f.fScaleMax = fScaleMax; 324 289 f.fPolynomOrder = fPolynomOrder; 290 f.fFitBackground= fFitBackground; 291 f.fSignalFunc = fSignalFunc; 325 292 f.fScaleMode = fScaleMode; 326 293 f.fScaleUser = fScaleUser; … … 350 317 { 351 318 *fLog << GetDescriptor() << ": Fitting..." << endl; 352 *fLog << " ...background from " << fBgMin << " to " << fBgMax << endl;353 319 *fLog << " ...signal to " << fSigMax << " (integrate into bin at " << fSigInt << ")" << endl; 354 *fLog << " ...polynom order " << fPolynomOrder << endl; 355 *fLog << " ...scale mode: "; 356 switch (fScaleMode) 357 { 358 case kNone: *fLog << "none."; break; 359 case kEntries: *fLog << "entries."; break; 360 case kIntegral: *fLog << "integral."; break; 361 case kOffRegion: *fLog << "off region (integral between " << fScaleMin << " and " << fScaleMax << ")"; break; 362 case kBackground: *fLog << "background (integral between " << fBgMin << " and " << fBgMax << ")"; break; 363 case kLeastSquare: *fLog << "least square (N/A)"; break; 364 case kUserScale: *fLog << "user def (" << fScaleUser << ")"; break; 320 *fLog << " ...signal function: "; 321 switch (fSignalFunc) 322 { 323 case kGauss: *fLog << "gauss(x)"; break; 324 case kThetaSq: *fLog << "gauss(sqrt(x))"; break; 365 325 } 366 326 *fLog << endl; 327 if (!fFitBackground) 328 *fLog << " ...no background." << endl; 329 else 330 { 331 *fLog << " ...background from " << fBgMin << " to " << fBgMax << endl; 332 *fLog << " ...polynom order " << fPolynomOrder << endl; 333 *fLog << " ...scale mode: "; 334 switch (fScaleMode) 335 { 336 case kNone: *fLog << "none."; break; 337 case kEntries: *fLog << "entries."; break; 338 case kIntegral: *fLog << "integral."; break; 339 case kOffRegion: *fLog << "off region (integral between " << fScaleMin << " and " << fScaleMax << ")"; break; 340 case kBackground: *fLog << "background (integral between " << fBgMin << " and " << fBgMax << ")"; break; 341 case kLeastSquare: *fLog << "least square (N/A)"; break; 342 case kUserScale: *fLog << "user def (" << fScaleUser << ")"; break; 343 } 344 *fLog << endl; 345 } 367 346 368 347 if (TString(o).Contains("result")) … … 402 381 } 403 382 383 Bool_t MAlphaFitter::FitTime(const TH3D &hon, UInt_t bin, Bool_t paint) 384 { 385 const TString name(Form("TempAlphaTime%06d", gRandom->Integer(1000000))); 386 387 hon.GetZaxis()->SetRange(bin,bin); 388 TH1D *h = (TH1D*)hon.Project3D("ye"); 389 hon.GetZaxis()->SetRange(-1,9999); 390 391 h->SetDirectory(0); 392 393 const Bool_t rc = Fit(*h, paint); 394 delete h; 395 return rc; 396 } 397 404 398 Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, Bool_t paint) 405 399 { … … 448 442 return rc; 449 443 } 450 444 /* 445 Bool_t MAlphaFitter::FitTime(const TH3D &hon, const TH3D &hof, UInt_t bin, Bool_t paint) 446 { 447 const TString name1(Form("TempAlphaTime%06d_on", gRandom->Integer(1000000))); 448 const TString name0(Form("TempAlphaTime%06d_off", gRandom->Integer(1000000))); 449 450 hon.GetZaxis()->SetRange(bin,bin); 451 TH1D *h1 = (TH1D*)hon.Project3D("ye"); 452 hon.GetZaxis()->SetRange(-1,9999); 453 h1->SetDirectory(0); 454 455 hof.GetZaxis()->SetRange(bin,bin); 456 TH1D *h0 = (TH1D*)hof.Project3D("ye"); 457 hof.GetZaxis()->SetRange(-1,9999); 458 h0->SetDirectory(0); 459 460 const Bool_t rc = ScaleAndFit(*h1, h0, paint); 461 462 delete h0; 463 delete h1; 464 465 return rc; 466 } 467 */ 451 468 Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, const TH3D &hof, Bool_t paint) 452 469 { … … 541 558 case kExcess: 542 559 return -GetEventsExcess(); 560 case kGaussSigma: 561 return GetGausSigma(); 543 562 } 544 563 return 0; … … 601 620 if (txt==(TString)"excess") 602 621 fStrategy = kExcess; 622 if (txt==(TString)"gausssigma" || txt==(TString)"gaussigma") 623 fStrategy = kGaussSigma; 603 624 rc = kTRUE; 604 625 } … … 625 646 rc = kTRUE; 626 647 } 648 if (IsEnvDefined(env, prefix, "Signalfunction", print)) 649 { 650 TString txt = GetEnvValue(env, prefix, "SignalFunction", ""); 651 txt = txt.Strip(TString::kBoth); 652 txt.ToLower(); 653 if (txt==(TString)"gauss" || txt==(TString)"gaus") 654 SetSignalFunction(kGauss); 655 if (txt==(TString)"thetasq") 656 SetSignalFunction(kThetaSq); 657 rc = kTRUE; 658 } 627 659 if (IsEnvDefined(env, prefix, "Scale", print)) 628 660 { -
trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h
r7066 r7151 34 34 kSignificanceLogExcess, 35 35 kSignificanceExcess, 36 kExcess 36 kExcess, 37 kGaussSigma 37 38 }; 39 enum SignalFunc_t { 40 kGauss, kThetaSq 41 }; 42 38 43 private: 39 Float_t fSigInt; 40 Float_t fSigMax; 41 Float_t fBgMin; 42 Float_t fBgMax; 43 Float_t fScaleMin; 44 Float_t fScaleMax; 45 Int_t fPolynomOrder; 46 47 Double_t fSignificance; 48 Double_t fEventsExcess; 49 Double_t fEventsSignal; 50 Double_t fEventsBackground; // fScaleFactor already applied 51 52 Double_t fChiSqSignal; 53 Double_t fChiSqBg; 54 Double_t fIntegralMax; 55 Double_t fScaleFactor; // Scale factor for off-data 56 57 TArrayD fCoefficients; 58 59 TF1 *fFunc; 60 61 ScaleMode_t fScaleMode; 62 Double_t fScaleUser; 63 64 Strategy_t fStrategy; 44 // Fitting Setup 45 Float_t fSigInt; // minimum of range to fit the signal 46 Float_t fSigMax; // maximum of range to fit the signal 47 Float_t fBgMin; // minimum of range to fit the background 48 Float_t fBgMax; // minimum of range to fit the background 49 Float_t fScaleMin; // minimum of range to determin the scale factor of the background 50 Float_t fScaleMax; // maximum of range to determin the scale factor of the background 51 Int_t fPolynomOrder; // order of polyom to be fitted to the background 52 Bool_t fFitBackground; // Backround fit: yes/no 53 SignalFunc_t fSignalFunc; // Type of signal function 54 // Result 55 Double_t fSignificance; // significance of signal 56 Double_t fEventsExcess; // calculated number of excess events (signal-bg) 57 Double_t fEventsSignal; // calculated number of signal events 58 Double_t fEventsBackground; // calculated number of bg events (fScaleFactor already applied) 59 60 Double_t fChiSqSignal; // Reduced (chi^2/NDF) chisq of signal fit 61 Double_t fChiSqBg; // Reduced (chi^2/NDF) chisq of bg fit 62 Double_t fIntegralMax; // Calculated bin border to which it was integrated 63 Double_t fScaleFactor; // Scale factor for off-data 64 65 TArrayD fCoefficients; // Fit result 66 67 // Function 68 TF1 *fFunc; // fit function (gauss + polynom) 69 70 // Scaling setup 71 ScaleMode_t fScaleMode; // scaling mode 72 Double_t fScaleUser; // user scale factor 73 74 // Minimization strategy 75 Strategy_t fStrategy; // How to calc minimization value 65 76 66 77 public: 67 78 // Implementing the function yourself is only about 5% faster 68 MAlphaFitter(const char *name=0, const char *title=0) : fSigInt(15), fSigMax(75), fBgMin(45), fBgMax(85), fScaleMin(40), fScaleMax(80), fPolynomOrder(2), fCoefficients(3+fPolynomOrder+1), fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90)), fScaleMode(kOffRegion), fScaleUser(1), fStrategy(kSignificance) 79 MAlphaFitter(const char *name=0, const char *title=0) : fSigInt(15), 80 fSigMax(75), fBgMin(45), fBgMax(85), fScaleMin(40), fScaleMax(80), 81 fPolynomOrder(2), fFitBackground(kTRUE), fSignalFunc(kGauss), 82 fCoefficients(3+fPolynomOrder+1), 83 fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90)), 84 fScaleMode(kOffRegion), fScaleUser(1), fStrategy(kSignificance) 69 85 { 70 86 fName = name ? name : "MAlphaFitter"; … … 86 102 } 87 103 104 // TObject 88 105 void Clear(Option_t *o=""); 89 106 void Print(Option_t *o="") const; //*MENU* 90 107 void Copy(TObject &o) const; 91 /* 92 TObject *Clone(const char *name) const 93 { 94 return new MAlphaFitter(*this); 95 } 96 */ 97 108 109 // Setter 98 110 void SetScaleUser(Float_t scale) { fScaleUser = scale; fScaleMode=kUserScale; } 99 111 void SetScaleMode(ScaleMode_t mode) { fScaleMode = mode; } … … 105 117 void SetScaleMin(Float_t s) { fScaleMin = s; } 106 118 void SetScaleMax(Float_t s) { fScaleMax = s; } 107 void SetPolynomOrder(Int_t s) { if (s==fPolynomOrder) return; fPolynomOrder = s; delete fFunc; fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", s)); 119 void SetPolynomOrder(Int_t s) 120 { 121 if (s==fPolynomOrder) 122 return; 123 124 fPolynomOrder = s; 125 126 SetSignalFunction(fSignalFunc); 127 } 128 void SetSignalFunction(SignalFunc_t func) 129 { 130 delete fFunc; 131 switch (func) 132 { 133 case kGauss: 134 fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", fPolynomOrder)); 135 break; 136 case kThetaSq: 137 fFunc=new TF1 ("", Form("[0]*exp(-((sqrt(x)-[1])/[2])^2) + pol%d(3)", fPolynomOrder)); 138 break; 139 } 140 fSignalFunc=func; 108 141 gROOT->GetListOfFunctions()->Remove(fFunc); 109 142 fFunc->SetName("Dummy"); 110 fCoefficients.Set(3+s+1); fCoefficients.Reset(); } 111 143 fCoefficients.Set(3+fPolynomOrder+1); 144 fCoefficients.Reset(); 145 } 146 void EnableBackgroundFit(Bool_t b=kTRUE) { fFitBackground=b; } 147 148 // Getter 112 149 Double_t GetSignalIntegralMax() const { return fSigInt; } 113 150 … … 127 164 Double_t GetCoefficient(Int_t i) const { return fCoefficients[i]; } 128 165 const TArrayD &GetCoefficients() const { return fCoefficients; } 129 130 void PaintResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035) const; 131 166 Double_t Eval(Double_t d) const { return fFunc ? fFunc->Eval(d) : 0; } 167 168 // Interface to fit 132 169 Bool_t Fit(TH1D &h, Bool_t paint=kFALSE); 133 170 Bool_t Fit(const TH1D &on, const TH1D &off, Double_t alpha, Bool_t paint=kFALSE); … … 149 186 Bool_t FitEnergy(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE); 150 187 Bool_t FitTheta(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE); 188 //Bool_t FitTime(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE); 151 189 152 190 Bool_t FitAlpha(const TH3D &on, const TH3D &off, Bool_t paint=kFALSE); 153 191 Bool_t FitEnergy(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE); 154 192 Bool_t FitTheta(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE); 193 //Bool_t FitTime(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE); 155 194 156 195 Bool_t FitAlpha(const TH3D &on, const TH3D *off, Bool_t paint=kFALSE) … … 165 204 { 166 205 return off ? FitTheta(on, *off, bin, paint) : FitTheta(on, bin, paint); 167 } 206 }/* 207 Bool_t FitTime(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE) 208 { 209 return off ? FitTime(on, *off, bin, paint) : FitTime(on, bin, paint); 210 }*/ 168 211 169 212 Double_t Scale(TH1D &off, const TH1D &on) const; 170 213 214 // Interface to result 215 void PaintResult(Float_t x=0.04, Float_t y=0.94, Float_t size=0.035) const; 216 217 // MTask 171 218 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE); 172 219 -
trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
r7142 r7151 292 292 if (!fResult) 293 293 return kFALSE; 294 fSigma = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "GaussSigma"); 295 if (!fSigma) 296 return kFALSE; 294 297 295 298 //fExcess = (MParameterD*)const_cast<MParList*>(pl)->FindCreateObj("MParameterD", "MExcess"); … … 469 472 size = fHillas->GetSize(); 470 473 energy = fEnergy ? fEnergy->GetVal() : (fHillas?fHillas->GetSize():1000); 471 theta = fPointPos ? fPointPos->GetZd() : 0; 472 } 473 474 //if (size>0) 475 // alpha /= (2.4 + 1.13*(log10((energy-14)/0.37)-5)*(log10((energy-14)/0.37)-5))/15; 474 theta = fPointPos ? fPointPos->GetZd() : 0; 475 } 476 476 477 477 // enhance histogram if necessary … … 480 480 // Fill histograms 481 481 fHist.Fill(theta, energy, TMath::Abs(alpha), w); 482 483 // Check cuts484 /*485 if ( (fEnergyMin>=0 && energy<fEnergyMin) ||486 (fEnergyMax>=0 && energy>fEnergyMax) ||487 (fSizeMin>=0 && size <fSizeMin) ||488 (fSizeMax>=0 && size >fSizeMin) )489 return kTRUE;490 */491 482 492 483 if (!fSkipHistTime) … … 851 842 852 843 fResult->SetVal(fFit.GetMinimizationValue()); 844 fSigma->SetVal(fFit.GetGausSigma()); 853 845 854 846 if (!fSkipHistEnergy) -
trunk/MagicSoft/Mars/mhflux/MHAlpha.h
r7122 r7151 44 44 45 45 MParameterD *fResult; //! 46 MParameterD *fSigma; //! 46 47 MParameterD *fEnergy; //! 47 48 MHillas *fHillas; //! -
trunk/MagicSoft/Mars/mhflux/MHThetaSq.h
r7147 r7151 24 24 25 25 Bool_t SetupFill(const MParList *pl); 26 void InitMapping(MHMatrix *mat, Int_t type=0);27 26 28 27 // MParContainer … … 31 30 public: 32 31 MHThetaSq(const char *name=NULL, const char *title=NULL); 32 33 void InitMapping(MHMatrix *mat, Int_t type=0); 33 34 34 35 void SetNumBinsSignal(UInt_t n) { fNumBinsSignal=TMath::Max(n, 1U); }
Note:
See TracChangeset
for help on using the changeset viewer.