Changeset 5692 for trunk/MagicSoft/Mars/mhflux
- Timestamp:
- 01/03/05 12:02:16 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mhflux
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhflux/MAlphaFitter.cc
r5114 r5692 41 41 #include <TF1.h> 42 42 #include <TH1.h> 43 #include <TH3.h> 44 45 #include <TRandom.h> 43 46 44 47 #include <TLatex.h> … … 51 54 52 55 using namespace std; 56 57 void MAlphaFitter::Clear(Option_t *o) 58 { 59 fSignificance=0; 60 fEventsExcess=0; 61 fEventsSignal=0; 62 fEventsBackground=0; 63 64 fChiSqSignal=0; 65 fChiSqBg=0; 66 fIntegralMax=0; 67 68 fCoefficients.Reset(); 69 } 53 70 54 71 // -------------------------------------------------------------------------- … … 84 101 Bool_t MAlphaFitter::Fit(TH1D &h, Bool_t paint) 85 102 { 103 Clear(); 104 if (h.GetEntries()==0) 105 return kFALSE; 106 86 107 Double_t sigmax=fSigMax; 87 108 Double_t bgmin =fBgMin; … … 175 196 //fSignificance = MMath::SignificanceLiMaSigned(s, b); 176 197 177 178 198 const Int_t bin = h.GetXaxis()->FindFixBin(fSigInt*0.999); 179 199 … … 190 210 } 191 211 212 Bool_t MAlphaFitter::Fit(TH1D &hon, TH1D &hof, Bool_t paint) 213 { 214 /* 215 Clear(); 216 if (hon.GetEntries()==0) 217 return kFALSE; 218 */ 219 220 TH1D h(hon); 221 h.Add(&hof, -1); 222 223 MAlphaFitter fit(*this); 224 fit.SetPolynomOrder(1); 225 226 if (!fit.Fit(h, paint)) 227 return kFALSE; 228 229 fChiSqSignal = fit.GetChiSqSignal(); 230 fChiSqBg = fit.GetChiSqBg(); 231 fCoefficients = fit.GetCoefficients(); 232 233 const Int_t bin = hon.GetXaxis()->FindFixBin(fSigInt*0.999); 234 235 fIntegralMax = hon.GetBinLowEdge(bin+1); 236 fEventsBackground = hof.Integral(0, bin); 237 fEventsSignal = hon.Integral(0, bin); 238 fEventsExcess = fEventsSignal-fEventsBackground; 239 fSignificance = MMath::SignificanceLiMaSigned(fEventsSignal, fEventsBackground); 240 241 if (fEventsExcess<0) 242 fEventsExcess=0; 243 /* 244 TF1 func("", "gaus(0)+pol0(3)", 0., 90.); 245 246 const Double_t A = fEventsSignal/bin; 247 const Double_t dA = TMath::Abs(A); 248 func.SetParLimits(0, -dA*4, dA*4); 249 func.SetParLimits(2, 0, 90); 250 func.SetParLimits(3, -dA, dA); 251 252 func.SetParameter(0, A); 253 func.FixParameter(1, 0); 254 func.SetParameter(2, fSigMax*0.75); 255 func.SetParameter(3, 0); 256 257 // options : N do not store the function, do not draw 258 // I use integral of function in bin rather than value at bin center 259 // R use the range specified in the function range 260 // Q quiet mode 261 TH1D h(hon); 262 h.Add(&hof, -1); 263 h.Fit(&func, "NQI", "", 0, 90); 264 265 fChiSqSignal = func.GetChisquare()/func.GetNDF(); 266 267 const Int_t bin1 = h.GetXaxis()->FindFixBin(func.GetParameter(2)*2); 268 269 fChiSqBg = 0; 270 for (int i=bin1; i<=h.GetNbinsX(); i++) 271 { 272 const Float_t val = h.GetBinContent(i); 273 fChiSqBg = val*val; 274 } 275 if (fChiSqBg>0) 276 fChiSqBg /= h.GetNbinsX()+1-bin1; 277 278 fCoefficients.Set(func.GetNpar(), func.GetParameters()); 279 280 // ------------------------------------ 281 if (paint) 282 { 283 func.SetLineColor(kBlue); 284 func.SetLineWidth(2); 285 func.Paint("same"); 286 } 287 // ------------------------------------ 288 */ 289 return kTRUE; 290 } 291 192 292 void MAlphaFitter::PaintResult(Float_t x, Float_t y, Float_t size) const 193 293 { 194 TLatex text(x, y, Form("\\sigma_{Li/Ma}=%.1f \\omega=%.1f\\circ E=%d (\\alpha<%.1f\\circ) (\\chi_{b}^{2} =%.1f \\chi_{s}^{2}=%.1f)",294 TLatex text(x, y, Form("\\sigma_{Li/Ma}=%.1f \\omega=%.1f\\circ E=%d (\\alpha<%.1f\\circ) (\\chi_{b}^{2}/ndf=%.1f \\chi_{s}^{2}/ndf=%.1f c_{0}=%.1f)", 195 295 fSignificance, GetGausSigma(), 196 296 (int)fEventsExcess, fIntegralMax, 197 fChiSqBg, fChiSqSignal ));297 fChiSqBg, fChiSqSignal, fCoefficients[3])); 198 298 199 299 text.SetBit(TLatex::kTextNDC); … … 210 310 f.fBgMin = fBgMin; 211 311 f.fBgMax = fBgMax; 312 f.fScaleMin = fScaleMin; 313 f.fScaleMax = fScaleMax; 212 314 f.fPolynomOrder = fPolynomOrder; 315 f.fScaleMode = fScaleMode; 316 f.fScaleUser = fScaleUser; 213 317 f.fCoefficients.Set(fCoefficients.GetSize()); 214 318 f.fCoefficients.Reset(); … … 227 331 *fLog << " ...signal to " << fSigMax << " (integrate into bin at " << fSigInt << ")" << endl; 228 332 *fLog << " ...polynom order " << fPolynomOrder << endl; 229 } 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."; break; 340 case kLeastSquare: *fLog << "least square."; break; 341 case kUserScale: *fLog << "user def (" << fScaleUser << ")"; break; 342 } 343 *fLog << endl; 344 345 if (TString(o).Contains("result")) 346 { 347 *fLog << "Result:" << endl; 348 *fLog << " - Significance " << fSignificance << endl; 349 *fLog << " - Excess Events " << fEventsExcess << endl; 350 *fLog << " - Signal Events " << fEventsSignal << endl; 351 *fLog << " - Background Events " << fEventsBackground << endl; 352 *fLog << " - Chi^2/ndf (Signal) " << fChiSqSignal << endl; 353 *fLog << " - Chi^2/ndf (Background) " << fChiSqBg << endl; 354 *fLog << " - Signal integrated " << fIntegralMax << "°" << endl; 355 } 356 } 357 358 Bool_t MAlphaFitter::FitEnergy(const TH3D &hon, UInt_t bin, Bool_t paint) 359 { 360 const TString name(Form("TempAlphaEnergy%06d", gRandom->Integer(1000000))); 361 TH1D *h = hon.ProjectionZ(name, -1, 9999, bin, bin, "E"); 362 h->SetDirectory(0); 363 364 const Bool_t rc = Fit(*h, paint); 365 delete h; 366 return rc; 367 } 368 369 Bool_t MAlphaFitter::FitTheta(const TH3D &hon, UInt_t bin, Bool_t paint) 370 { 371 const TString name(Form("TempAlphaTheta%06d", gRandom->Integer(1000000))); 372 TH1D *h = hon.ProjectionZ(name, bin, bin, -1, 9999, "E"); 373 h->SetDirectory(0); 374 375 const Bool_t rc = Fit(*h, paint); 376 delete h; 377 return rc; 378 } 379 380 Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, Bool_t paint) 381 { 382 const TString name(Form("TempAlpha%06d", gRandom->Integer(1000000))); 383 TH1D *h = hon.ProjectionZ(name, -1, 9999, -1, 9999, "E"); 384 h->SetDirectory(0); 385 386 const Bool_t rc = Fit(*h, paint); 387 delete h; 388 return rc; 389 } 390 391 Bool_t MAlphaFitter::FitEnergy(const TH3D &hon, const TH3D &hof, UInt_t bin, Bool_t paint) 392 { 393 const TString name1(Form("TempAlpha%06d_on", gRandom->Integer(1000000))); 394 const TString name0(Form("TempAlpha%06d_off", gRandom->Integer(1000000))); 395 TH1D *h1 = hon.ProjectionZ(name1, -1, 9999, bin, bin, "E"); 396 TH1D *h0 = hof.ProjectionZ(name0, -1, 9999, bin, bin, "E"); 397 h1->SetDirectory(0); 398 h0->SetDirectory(0); 399 400 Scale(*h0, *h1); 401 402 const Bool_t rc = Fit(*h1, *h0, paint); 403 404 delete h0; 405 delete h1; 406 407 return rc; 408 } 409 410 Bool_t MAlphaFitter::FitTheta(const TH3D &hon, const TH3D &hof, UInt_t bin, Bool_t paint) 411 { 412 const TString name1(Form("TempAlpha%06d_on", gRandom->Integer(1000000))); 413 const TString name0(Form("TempAlpha%06d_off", gRandom->Integer(1000000))); 414 415 TH1D *h1 = hon.ProjectionZ(name1, bin, bin, -1, 9999, "E"); 416 TH1D *h0 = hof.ProjectionZ(name0, bin, bin, -1, 9999, "E"); 417 h1->SetDirectory(0); 418 h0->SetDirectory(0); 419 420 Scale(*h0, *h1); 421 422 const Bool_t rc = Fit(*h1, *h0, paint); 423 424 delete h0; 425 delete h1; 426 427 return rc; 428 } 429 430 Bool_t MAlphaFitter::FitAlpha(const TH3D &hon, const TH3D &hof, Bool_t paint) 431 { 432 const TString name1(Form("TempAlpha%06d_on", gRandom->Integer(1000000))); 433 const TString name0(Form("TempAlpha%06d_off", gRandom->Integer(1000000))); 434 435 TH1D *h1 = hon.ProjectionZ(name1, -1, 9999, -1, 9999, "E"); 436 TH1D *h0 = hof.ProjectionZ(name0, -1, 9999, -1, 9999, "E"); 437 h1->SetDirectory(0); 438 h0->SetDirectory(0); 439 440 Scale(*h0, *h1); 441 442 const Bool_t rc = Fit(*h1, *h0, paint); 443 444 delete h0; 445 delete h1; 446 447 return rc; 448 } 449 450 void MAlphaFitter::Scale(TH1D &of, const TH1D &on) const 451 { 452 Float_t scaleon = 1; 453 Float_t scaleof = 1; 454 switch (fScaleMode) 455 { 456 case kNone: 457 return; 458 459 case kEntries: 460 scaleon = on.GetEntries(); 461 scaleof = of.GetEntries(); 462 break; 463 464 case kIntegral: 465 scaleon = on.Integral(); 466 scaleof = of.Integral(); 467 break; 468 469 case kOffRegion: 470 { 471 const Int_t min = on.GetXaxis()->FindFixBin(fScaleMin); 472 const Int_t max = on.GetXaxis()->FindFixBin(fScaleMax); 473 scaleon = on.Integral(min, max); 474 scaleof = of.Integral(min, max); 475 } 476 break; 477 478 case kUserScale: 479 scaleon = fScaleUser; 480 break; 481 482 default: 483 return; 484 } 485 486 if (scaleof!=0) 487 of.Scale(scaleon/scaleof); 488 } -
trunk/MagicSoft/Mars/mhflux/MAlphaFitter.h
r5114 r5692 15 15 16 16 class TH1D; 17 class TH3D; 17 18 18 19 class MAlphaFitter : public MParContainer 19 20 { 21 public: 22 enum ScaleMode_t { 23 kNone, 24 kEntries, 25 kIntegral, 26 kOffRegion, 27 kLeastSquare, 28 kUserScale 29 }; 20 30 private: 21 31 Float_t fSigInt; … … 23 33 Float_t fBgMin; 24 34 Float_t fBgMax; 35 Float_t fScaleMin; 36 Float_t fScaleMax; 25 37 Int_t fPolynomOrder; 26 38 … … 38 50 TF1 *fFunc; 39 51 52 ScaleMode_t fScaleMode; 53 Double_t fScaleUser; 54 40 55 public: 41 56 // Implementing the function yourself is only about 5% faster 42 MAlphaFitter(const char *name=0, const char *title=0) : fSigInt(15), fSigMax(75), fBgMin(45), fBgMax(85), f PolynomOrder(2), fCoefficients(3+fPolynomOrder+1), fFunc(new TF1("", Form("gaus(0) + pol%d(3)", fPolynomOrder), 0, 90))57 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(kEntries), fScaleUser(1) 43 58 { 44 59 fName = name ? name : "MAlphaFitter"; … … 58 73 } 59 74 60 void Print(Option_t *o=0) const; 75 void Clear(Option_t *o=""); 76 void Print(Option_t *o="") const; 61 77 void Copy(TObject &o) const; 62 78 /* … … 67 83 */ 68 84 85 void SetScaleUser(Float_t scale) { fScaleUser = scale; fScaleMode=kUserScale; } 86 void SetScaleMode(ScaleMode_t mode) { fScaleMode = mode; } 69 87 void SetSignalIntegralMax(Float_t s) { fSigInt = s; } 70 88 void SetSignalFitMax(Float_t s) { fSigMax = s; } 71 89 void SetBackgroundFitMin(Float_t s) { fBgMin = s; } 72 90 void SetBackgroundFitMax(Float_t s) { fBgMax = s; } 91 void SetScaleMin(Float_t s) { fScaleMin = s; } 92 void SetScaleMax(Float_t s) { fScaleMax = s; } 73 93 void SetPolynomOrder(Int_t s) { fPolynomOrder = s; delete fFunc; fFunc=new TF1 ("", Form("gaus(0) + pol%d(3)", s)); 74 94 gROOT->GetListOfFunctions()->Remove(fFunc); … … 93 113 94 114 Bool_t Fit(TH1D &h, Bool_t paint=kFALSE); 115 Bool_t Fit(TH1D &on, TH1D &off, Bool_t paint=kFALSE); 116 Bool_t Fit(TH1D &on, TH1D *off, Bool_t paint=kFALSE) 117 { 118 return off ? Fit(on, *off, paint) : Fit(on, paint); 119 } 120 121 Bool_t FitAlpha(const TH3D &h, Bool_t paint=kFALSE); 122 Bool_t FitEnergy(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE); 123 Bool_t FitTheta(const TH3D &h, UInt_t bin, Bool_t paint=kFALSE); 124 125 Bool_t FitAlpha(const TH3D &on, const TH3D &off, Bool_t paint=kFALSE); 126 Bool_t FitEnergy(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE); 127 Bool_t FitTheta(const TH3D &on, const TH3D &off, UInt_t bin, Bool_t paint=kFALSE); 128 129 Bool_t FitAlpha(const TH3D &on, const TH3D *off, Bool_t paint=kFALSE) 130 { 131 return off ? FitAlpha(on, *off, paint) : FitAlpha(on, paint); 132 } 133 Bool_t FitEnergy(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE) 134 { 135 return off ? FitEnergy(on, *off, bin, paint) : FitEnergy(on, bin, paint); 136 } 137 Bool_t FitTheta(const TH3D &on, const TH3D *off, UInt_t bin, Bool_t paint=kFALSE) 138 { 139 return off ? FitTheta(on, *off, bin, paint) : FitTheta(on, bin, paint); 140 } 141 142 void Scale(TH1D &off, const TH1D &on) const; 95 143 96 144 ClassDef(MAlphaFitter, 1) -
trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
r5300 r5692 75 75 // 76 76 MHAlpha::MHAlpha(const char *name, const char *title) 77 : fResult(0), /*fExcess(0),*/ fEnergy(0), fPointPos(0), fTimeEffOn(0), 78 fTime(0), fNameProjAlpha(Form("Alpha_%p", this)), fMatrix(0) 77 : fOffData(0), fResult(0), /*fExcess(0),*/ fEnergy(0), fHillas(0), 78 fPointPos(0), fTimeEffOn(0), fTime(0), 79 fSkipHistTime(kFALSE), fSkipHistTheta(kFALSE), fSkipHistEnergy(kFALSE), 80 //fEnergyMin(-1), fEnergyMax(-1), fSizeMin(-1), fSizeMax(-1), 81 fMatrix(0) 79 82 { 80 83 // … … 100 103 101 104 102 fHEnergy.SetName("Energy");103 fHEnergy.SetTitle(" N_{exc} vs. E_{est} ");104 fHEnergy.SetXTitle("E_{est} [GeV]");105 //fHEnergy.SetName("Energy"); 106 //fHEnergy.SetTitle(" N_{exc} vs. E_{est} "); 107 //fHEnergy.SetXTitle("E_{est} [GeV]"); 105 108 fHEnergy.SetYTitle("N_{exc}"); 106 109 fHEnergy.SetDirectory(NULL); … … 184 187 for (int i=1; i<=n; i++) 185 188 { 186 TH1D *h = fHAlpha.ProjectionZ("Alpha_EE", -1, 9999, i, i, i==1?"E":""); 187 if (fit.Fit(*h)) 189 if (fit.FitEnergy(fHAlpha, fOffData, i)) 188 190 { 189 191 fHEnergy.SetBinContent(i, fit.GetEventsExcess()); 190 192 fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2); 191 193 } 192 delete h;193 194 } 194 195 } … … 203 204 for (int i=1; i<=n; i++) 204 205 { 205 TH1D *h = fHAlpha.ProjectionZ("Alpha_EE", i, i, -1, 9999, i==1?"E":""); 206 if (fit.Fit(*h)) 206 if (fit.FitTheta(fHAlpha, fOffData, i)) 207 207 { 208 208 fHTheta.SetBinContent(i, fit.GetEventsExcess()); 209 209 fHTheta.SetBinError(i, fit.GetEventsExcess()*0.2); 210 210 } 211 delete h;212 211 } 213 212 } … … 219 218 fHTheta.Reset(); 220 219 220 if (fName!=(TString)"MHAlphaOff") 221 { 222 MHAlpha *hoff = (MHAlpha*)pl->FindObject("MHAlphaOff"); 223 if (!hoff) 224 *fLog << inf << "No MHAlphaOff [MHAlpha] found... using current data only!" << endl; 225 else 226 { 227 *fLog << inf << "MHAlphaOff [MHAlpha] found... using on-off mode!" << endl; 228 SetOffData(*hoff); 229 } 230 } 231 232 fHillas = 0; 233 /* 234 if (fSizeMin>=0 || fSizeMax>=0) 235 { 236 fHillas = (MHillas*)pl->FindObject("MHillas"); 237 if (!fHillas) 238 { 239 *fLog << warn << "Size cut set, but MHillas not found... abort." << endl; 240 return kFALSE; 241 } 242 } 243 */ 221 244 fEnergy = (MEnergyEst*)pl->FindObject("MEnergyEst"); 222 245 if (!fEnergy) 223 *fLog << warn << "MEnergyEst not found... ignored." << endl; 246 { /* 247 if (fEnergyMin>=0 || fEnergyMax>=0) 248 { 249 *fLog << warn << "Energy cut set, but MEnergyEst not found... abort." << endl; 250 return kFALSE; 251 } */ 252 253 *fLog << warn << "MEnergyEst not found... " << flush; 254 255 if (!fHillas) 256 fHillas = (MHillas*)pl->FindObject("MHillas"); 257 if (fHillas) 258 *fLog << "using SIZE instead!" << endl; 259 else 260 *fLog << "ignored." << endl; 261 262 fHEnergy.SetName("Size"); 263 fHEnergy.SetTitle(" N_{exc} vs. Size "); 264 fHEnergy.SetXTitle("Size [\\gamma]"); 265 } 266 else 267 { 268 fHEnergy.SetName("Energy"); 269 fHEnergy.SetTitle(" N_{exc} vs. E_{est} "); 270 fHEnergy.SetXTitle("E_{est} [GeV]"); 271 } 224 272 225 273 fPointPos = (MPointingPos*)pl->FindObject("MPointingPos"); … … 230 278 if (!fTimeEffOn) 231 279 *fLog << warn << "MTimeEffectiveOnTime [MTime] not found... ignored." << endl; 280 else 281 *fTimeEffOn = MTime(); // FIXME: How to do it different? 232 282 233 283 fTime = (MTime*)pl->FindObject("MTime"); … … 246 296 247 297 MBinning binst, binse, binsa; 248 binst.SetEdges(fHAlpha, 'x'); 249 binse.SetEdges(fHAlpha, 'y'); 250 binsa.SetEdges(fHAlpha, 'z'); 251 252 MBinning *bins = (MBinning*)pl->FindObject("BinningTheta", "MBinning"); 253 if (fPointPos && bins) 254 binst.SetEdges(*bins); 255 if (!fPointPos) 256 binst.SetEdges(1, 0, 90); 257 258 bins = (MBinning*)pl->FindObject("BinningEnergyEst", "MBinning"); 259 if (fEnergy && bins) 260 binse.SetEdges(*bins); 261 if (!fEnergy) 262 binse.SetEdges(1, 10, 100000); 263 264 bins = (MBinning*)pl->FindObject("BinningAlpha", "MBinning"); 265 if (bins) 266 binsa.SetEdges(*bins); 298 binst.SetEdges(fOffData ? *fOffData : fHAlpha, 'x'); 299 binse.SetEdges(fOffData ? *fOffData : fHAlpha, 'y'); 300 binsa.SetEdges(fOffData ? *fOffData : fHAlpha, 'z'); 301 302 if (!fOffData) 303 { 304 MBinning *bins = (MBinning*)pl->FindObject("BinningTheta", "MBinning"); 305 if (fPointPos && bins) 306 binst.SetEdges(*bins); 307 if (!fPointPos) 308 binst.SetEdges(1, 0, 60); 309 310 bins = (MBinning*)pl->FindObject("BinningEnergyEst", "MBinning"); 311 if ((fEnergy||fHillas) && bins) 312 binse.SetEdges(*bins); 313 if (!fEnergy && !fHillas) 314 binse.SetEdges(1, 10, 100000); 315 316 bins = (MBinning*)pl->FindObject("BinningAlpha", "MBinning"); 317 if (bins) 318 binsa.SetEdges(*bins); 319 } 267 320 268 321 binse.Apply(fHEnergy); … … 321 374 } 322 375 376 // Check new 'last time' 377 MTime *time = final ? fTime : fTimeEffOn; 378 379 if (time->GetAxisTime()<=fHTime.GetXaxis()->GetXmax()) 380 { 381 *fLog << warn << "WARNING - New time-stamp " << *time << " lower" << endl; 382 *fLog << "than upper edge of histogram... skipped." << endl; 383 *fLog << "This should not happen. Maybe you started you eventloop with" << endl; 384 *fLog << "an already initialized time stamp MTimeEffectiveOnTime?" << endl; 385 rebin++; 386 return; 387 } 388 389 // Fit time histogram 323 390 MAlphaFitter fit(fFit); 324 if (!fit.Fit(fHAlphaTime)) 391 392 TH1D *h = fOffData ? fOffData->ProjectionZ("ProjTimeTemp", -1, 9999, -1, 9999, "E") : 0; 393 const Bool_t rc = fit.Fit(fHAlphaTime, h); 394 if (h) 395 delete h; 396 397 if (!rc) 325 398 return; 326 399 … … 334 407 // Prepare Histogram 335 408 // 336 337 MTime *time = final ? fTime : fTimeEffOn;338 409 if (final) 339 410 time->Plus1ns(); … … 363 434 { 364 435 Double_t alpha, energy, theta; 436 Double_t size=-1; 365 437 366 438 if (fMatrix) 367 439 { 368 440 alpha = (*fMatrix)[fMap[0]]; 369 energy = 1000; 370 theta = 0; 441 energy = fMap[1]<0 ? -1 : (*fMatrix)[fMap[1]]; 442 size = fMap[2]<0 ? -1 : (*fMatrix)[fMap[2]]; 443 //<0 ? 1000 : (*fMatrix)[fMap[1]]; 444 theta = 0; 445 446 if (energy<0) 447 energy=size; 448 if (size<0) 449 size=energy; 450 451 if (energy<0 && size<0) 452 energy = size = 1000; 371 453 } 372 454 else … … 380 462 381 463 alpha = hil->GetAlpha(); 382 energy = fEnergy ? fEnergy->GetEnergy() : 1000; 464 if (fHillas) 465 size = fHillas->GetSize(); 466 energy = fEnergy ? fEnergy->GetEnergy() : (fHillas?fHillas->GetSize():1000); 383 467 theta = fPointPos ? fPointPos->GetZd() : 0; 384 468 } 385 469 470 // enhance histogram if necessary 386 471 UpdateAlphaTime(); 387 472 473 // Fill histograms 388 474 fHAlpha.Fill(theta, energy, TMath::Abs(alpha), w); 389 fHAlphaTime.Fill(TMath::Abs(alpha), w); 475 476 // Check cuts 477 /* 478 if ( (fEnergyMin>=0 && energy<fEnergyMin) || 479 (fEnergyMax>=0 && energy>fEnergyMax) || 480 (fSizeMin>=0 && size <fSizeMin) || 481 (fSizeMax>=0 && size >fSizeMin) ) 482 return kTRUE; 483 */ 484 485 if (!fSkipHistTime) 486 fHAlphaTime.Fill(TMath::Abs(alpha), w); 390 487 391 488 return kTRUE; … … 441 538 442 539 padsave->cd(1); 443 fHAlpha.ProjectionZ(fNameProjAlpha); 540 TH1D *hon = fHAlpha.ProjectionZ("ProjAlpha"); 541 if (fOffData) 542 { 543 TH1D *hoff = fOffData->ProjectionZ("ProjAlphaOff"); 544 fFit.Scale(*hoff, *hon); 545 546 hon->SetMaximum(); 547 hon->SetMaximum(TMath::Max(hon->GetMaximum(), hoff->GetMaximum())*1.05); 548 549 if ((h0=(TH1D*)gPad->FindObject("ProjAlphaOnOff"))) 550 { 551 h0->Reset(); 552 h0->Add(hoff, hon, -1); 553 const Float_t min = h0->GetMinimum()*1.05; 554 hon->SetMinimum(min<0 ? min : 0); 555 } 556 } 444 557 FitEnergyBins(); 445 558 FitThetaBins(); … … 447 560 448 561 if (o==(TString)"alpha") 449 if ((h0 = (TH1D*)gPad->FindObject( fNameProjAlpha)))562 if ((h0 = (TH1D*)gPad->FindObject("ProjAlpha"))) 450 563 { 451 564 // Do not store the 'final' result in fFit 452 565 MAlphaFitter fit(fFit); 453 fit.Fit(*h0, kTRUE); 566 TH1D *hoff = (TH1D*)gPad->FindObject("ProjAlphaOff"); 567 fit.Fit(*h0, hoff, kTRUE); 454 568 fit.PaintResult(); 455 569 } … … 459 573 460 574 if (o==(TString)"theta") 575 { 576 TH1 *h = (TH1*)gPad->FindObject("Alpha_x"); 577 if (h) 578 { 579 TH1D *h2 = (TH1D*)fHAlpha.Project3D("dum_x"); 580 h2->SetDirectory(0); 581 h2->Scale(fHTheta.Integral()/h2->Integral()); 582 h->Reset(); 583 h->Add(h2); 584 delete h2; 585 } 461 586 PaintText(fHTheta.Integral(), 0); 587 } 462 588 463 589 if (o==(TString)"energy") 464 590 { 591 TH1 *h = (TH1*)gPad->FindObject("Alpha_y"); 592 if (h) 593 { 594 TH1D *h2 = (TH1D*)fHAlpha.Project3D("dum_y"); 595 h2->SetDirectory(0); 596 h2->Scale(fHEnergy.Integral()/h2->Integral()); 597 h->Reset(); 598 h->Add(h2); 599 delete h2; 600 } 601 465 602 if (fHEnergy.GetMaximum()>1) 466 603 { … … 469 606 } 470 607 FitEnergySpec(kTRUE); 471 472 608 } 473 609 … … 494 630 pad->cd(1); 495 631 gPad->SetBorderMode(0); 496 h = fHAlpha.ProjectionZ(fNameProjAlpha, -1, 9999, -1, 9999, "E"); 632 633 h = fHAlpha.ProjectionZ("ProjAlpha", -1, 9999, -1, 9999, "E"); 497 634 h->SetBit(TH1::kNoTitle); 635 h->SetStats(kTRUE); 498 636 h->SetXTitle("\\alpha [\\circ]"); 499 637 h->SetYTitle("Counts"); … … 501 639 h->SetMarkerStyle(kFullDotMedium); 502 640 h->SetBit(kCanDelete); 503 h->Draw(); 641 h->Draw(""); 642 643 if (fOffData) 644 { 645 h->SetMarkerColor(kGreen); 646 647 h = fOffData->ProjectionZ("ProjAlphaOff", -1, 9999, -1, 9999, "E"); 648 h->SetBit(TH1::kNoTitle|TH1::kNoStats); 649 h->SetXTitle("\\alpha [\\circ]"); 650 h->SetYTitle("Counts"); 651 h->SetDirectory(NULL); 652 h->SetMarkerStyle(kFullDotMedium); 653 h->SetBit(kCanDelete); 654 h->SetMarkerColor(kRed); 655 h->Draw("same"); 656 657 h = (TH1D*)h->Clone("ProjAlphaOnOff"); 658 h->SetBit(TH1::kNoTitle); 659 h->SetXTitle("\\alpha [\\circ]"); 660 h->SetYTitle("Counts"); 661 h->SetDirectory(NULL); 662 h->SetMarkerStyle(kFullDotMedium); 663 h->SetBit(kCanDelete); 664 h->SetMarkerColor(kBlue); 665 h->Draw("same"); 666 667 TLine lin; 668 lin.SetLineStyle(kDashed); 669 lin.DrawLine(0, 0, 90, 0); 670 } 671 504 672 // After the Alpha-projection has been drawn. Fit the histogram 505 673 // and paint the result into this pad … … 511 679 gPad->SetBorderMode(0); 512 680 fHEnergy.Draw(); 681 513 682 AppendPad("energy"); 683 684 h = (TH1D*)fHAlpha.Project3D("y"); 685 h->SetBit(TH1::kNoTitle|TH1::kNoStats); 686 h->SetXTitle("E [GeV]"); 687 h->SetYTitle("Counts"); 688 h->SetDirectory(NULL); 689 h->SetMarkerStyle(kFullDotMedium); 690 h->SetBit(kCanDelete); 691 h->SetMarkerColor(kCyan); 692 h->SetLineColor(kCyan); 693 h->Draw("Psame"); 514 694 } 515 695 else … … 531 711 gPad->SetBorderMode(0); 532 712 fHTheta.Draw(); 713 533 714 AppendPad("theta"); 715 716 h = (TH1D*)fHAlpha.Project3D("x"); 717 h->SetBit(TH1::kNoTitle|TH1::kNoStats); 718 h->SetXTitle("\\theta [\\circ]"); 719 h->SetYTitle("Counts"); 720 h->SetDirectory(NULL); 721 h->SetMarkerStyle(kFullDotMedium); 722 h->SetBit(kCanDelete); 723 h->SetMarkerColor(kCyan); 724 h->SetLineColor(kCyan); 725 h->Draw("Psame"); 534 726 } 535 727 else 536 728 delete pad->GetPad(4); 537 538 } 729 } 730 731 void MHAlpha::DrawAll() 732 { 733 // FIXME: Do in Paint if special option given! 734 TCanvas *c = new TCanvas; 735 Int_t n = fHAlpha.GetNbinsY(); 736 Int_t nc = (Int_t)(TMath::Sqrt((Float_t)n-1)+1); 737 c->Divide(nc, nc, 0, 0); 738 739 // Do not store the 'final' result in fFit 740 MAlphaFitter fit(fFit); 741 742 for (int i=1; i<=fHAlpha.GetNbinsY(); i++) 743 { 744 c->cd(i); 745 746 TH1D *hon = fHAlpha.ProjectionZ("ProjAlpha", -1, 9999, i, i, "E"); 747 hon->SetBit(TH1::kNoTitle); 748 hon->SetStats(kTRUE); 749 hon->SetXTitle("\\alpha [\\circ]"); 750 hon->SetYTitle("Counts"); 751 hon->SetDirectory(NULL); 752 hon->SetMarkerStyle(kFullDotMedium); 753 hon->SetBit(kCanDelete); 754 hon->Draw(""); 755 756 TH1D *hof = 0; 757 758 if (fOffData) 759 { 760 hon->SetMarkerColor(kGreen); 761 762 hof = fOffData->ProjectionZ("ProjAlphaOff", -1, 9999, i, i, "E"); 763 hof->SetBit(TH1::kNoTitle|TH1::kNoStats); 764 hof->SetXTitle("\\alpha [\\circ]"); 765 hof->SetYTitle("Counts"); 766 hof->SetDirectory(NULL); 767 hof->SetMarkerStyle(kFullDotMedium); 768 hof->SetBit(kCanDelete); 769 hof->SetMarkerColor(kRed); 770 hof->Draw("same"); 771 772 fit.Scale(*hof, *hon); 773 774 hon->SetMaximum(); 775 hon->SetMaximum(TMath::Max(hon->GetMaximum(), hof->GetMaximum())*1.05); 776 777 TH1D *diff = new TH1D(*hon); 778 diff->Add(hof, -1); 779 diff->SetBit(TH1::kNoTitle); 780 diff->SetXTitle("\\alpha [\\circ]"); 781 diff->SetYTitle("Counts"); 782 diff->SetDirectory(NULL); 783 diff->SetMarkerStyle(kFullDotMedium); 784 diff->SetBit(kCanDelete); 785 diff->SetMarkerColor(kBlue); 786 diff->Draw("same"); 787 788 TLine lin; 789 lin.SetLineStyle(kDashed); 790 lin.DrawLine(0, 0, 90, 0); 791 792 const Float_t min = diff->GetMinimum()*1.05; 793 hon->SetMinimum(min<0 ? min : 0); 794 } 795 796 if (hof ? fit.Fit(*hon, *hof) : fit.Fit(*hon)) 797 *fLog << dbg << "Bin " << i << ": sigma=" << fit.GetSignificance() << " omega=" << fit.GetGausSigma() << " events=" << fit.GetEventsExcess() << endl; 798 /* 799 if (fit.FitEnergy(fHAlpha, fOffData, i, kTRUE)) 800 { 801 fHEnergy.SetBinContent(i, fit.GetEventsExcess()); 802 fHEnergy.SetBinError(i, fit.GetEventsExcess()*0.2); 803 }*/ 804 } 805 806 } 807 539 808 540 809 Bool_t MHAlpha::Finalize() 541 810 { 542 // Store the final result in fFit 543 TH1D *h = fHAlpha.ProjectionZ("AlphaExc_px", -1, 9999, -1, 9999, "E"); 544 h->SetDirectory(0); 545 fFit.Print(); 546 Bool_t rc = fFit.Fit(*h); 547 delete h; 548 if (!rc) 811 //TH1D *h = fHAlpha.ProjectionZ("AlphaExc_px", -1, 9999, -1, 9999, "E"); 812 //h->SetDirectory(0); 813 //Bool_t rc = fFit.Fit(*h); 814 //delete h; 815 if (!fFit.FitAlpha(fHAlpha, fOffData)) 549 816 { 550 817 *fLog << warn << "Histogram empty." << endl; … … 552 819 } 553 820 821 // Store the final result in fFit 822 fFit.Print("result"); 823 554 824 if (fResult) 555 825 fResult->SetVal(fFit.GetSignificance()); 556 826 557 FitEnergyBins(); 558 FitThetaBins(); 559 UpdateAlphaTime(kTRUE); 560 MH::RemoveFirstBin(fHTime); 827 if (!fSkipHistEnergy) 828 { 829 *fLog << inf << "Processing energy bins..." << endl; 830 FitEnergyBins(); 831 } 832 if (!fSkipHistTheta) 833 { 834 *fLog << inf << "Processing theta bins..." << endl; 835 FitThetaBins(); 836 } 837 if (!fSkipHistTime) 838 { 839 *fLog << inf << "Processing time bins..." << endl; 840 UpdateAlphaTime(kTRUE); 841 MH::RemoveFirstBin(fHTime); 842 } 561 843 562 844 return kTRUE; … … 572 854 // will take the values from the matrix instead of the containers. 573 855 // 574 void MHAlpha::InitMapping(MHMatrix *mat) 856 // It takes fSkipHist* into account! 857 // 858 void MHAlpha::InitMapping(MHMatrix *mat, Int_t type) 575 859 { 576 860 if (fMatrix) … … 580 864 581 865 fMap[0] = fMatrix->AddColumn("MHillasSrc.fAlpha"); 582 //fMap[1] = fMatrix->AddColumn("MEnergyEst.fEnergy"); 866 fMap[1] = -1; 867 fMap[2] = -1; 868 fMap[3] = -1; 869 fMap[4] = -1; 870 871 if (!fSkipHistEnergy) 872 if (type==0) 873 { 874 fMap[1] = fMatrix->AddColumn("MEnergyEst.fEnergy"); 875 fMap[2] = -1; 876 } 877 else 878 { 879 fMap[1] = -1; 880 fMap[2] = fMatrix->AddColumn("MHillas.fSize"); 881 } 882 883 if (!fSkipHistTheta) 884 fMap[3] = fMatrix->AddColumn("MPointingPos.fZd"); 885 886 // if (!fSkipHistTime) 887 // fMap[4] = fMatrix->AddColumn("MTime.GetAxisTime"); 583 888 } 584 889 -
trunk/MagicSoft/Mars/mhflux/MHAlpha.h
r5100 r5692 21 21 class MParameterD; 22 22 class MEnergyEst; 23 class MHillas; 23 24 class MHMatrix; 24 25 class MPointingPos; … … 84 85 { 85 86 private: 87 const TH3D *fOffData; 88 86 89 MAlphaFitter fFit; // SEEMS THAT STREAMER HAS SOME PROBLEMS... MAYBE IF FUNC IS USED AT THE SAME TIME FOR FITS (PAINT) 87 90 … … 94 97 MParameterD *fResult; //! 95 98 MEnergyEst *fEnergy; //! 99 MHillas *fHillas; //! 96 100 MPointingPos *fPointPos; //! 97 101 … … 100 104 MTime fLastTime; //! Last fTimeEffOn 101 105 102 const TString fNameProjAlpha; //! This should make sure, that gROOT doen't confuse the projection with something else 106 //Float_t fEnergyMin; 107 //Float_t fEnergyMax; 108 //Float_t fSizeMin; 109 //Float_t fSizeMax; 110 111 Bool_t fSkipHistTime; 112 Bool_t fSkipHistTheta; 113 Bool_t fSkipHistEnergy; 114 115 //const TString fNameProjAlpha; //! This should make sure, that gROOT doen't confuse the projection with something else 103 116 104 117 MHMatrix *fMatrix; //! 105 Int_t fMap[ 2]; //!118 Int_t fMap[5]; //! 106 119 107 120 void FitEnergySpec(Bool_t paint=kFALSE); … … 115 128 void PaintText(Double_t val, Double_t error) const; 116 129 130 Int_t DistancetoPrimitive(Int_t px, Int_t py) { return 0; } 131 117 132 public: 118 133 MHAlpha(const char *name=NULL, const char *title=NULL); … … 125 140 const MAlphaFitter &GetAlphaFitter() const { return fFit; } 126 141 142 void SetOffData(const MHAlpha &h) 143 { 144 fOffData = &h.fHAlpha; 145 } 146 /* 147 void SetSizeCuts(Float_t min, Float_t max) { fSizeMin=min; fSizeMax=max; } 148 void SetSizeMin(Float_t min) { fSizeMin=min; } 149 void SetSizeMax(Float_t max) { fSizeMax=max; } 150 void SetEnergyCuts(Float_t min, Float_t max) { fEnergyMin=min; fEnergyMax=max; } 151 void SetEnergyMin(Float_t min) { fEnergyMin=min; } 152 void SetEnergyMax(Float_t max) { fEnergyMax=max; } 153 154 void SetCuts(const MHAlpha &h) { 155 fSizeMin = h.fSizeMin; fEnergyMin = h.fEnergyMin; 156 fSizeMax = h.fSizeMax; fEnergyMax = h.fEnergyMax; 157 } 158 */ 159 160 void SkipHistTime(Bool_t b=kTRUE) { fSkipHistTime=b; } 161 void SkipHistTheta(Bool_t b=kTRUE) { fSkipHistTheta=b; } 162 void SkipHistEnergy(Bool_t b=kTRUE) { fSkipHistEnergy=b; } 163 127 164 void Paint(Option_t *opt=""); 128 165 void Draw(Option_t *option=""); 129 166 130 void InitMapping(MHMatrix *mat); 167 void DrawAll(); //*MENU* 168 169 void InitMapping(MHMatrix *mat, Int_t type=0); 131 170 void StopMapping(); 132 171
Note:
See TracChangeset
for help on using the changeset viewer.