Changeset 7594 for trunk/MagicSoft/Mars/mhflux/MHPhi.cc
- Timestamp:
- 03/13/06 15:51:11 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhflux/MHPhi.cc
r7251 r7594 33 33 // http://www.astro.uni-wuerzburg.de/results/ringmethod/ 34 34 // 35 // Class Version 2: 36 // + TH1D fHPhi; // Phi plot of the signal w.r.t. source 37 // + TH1D fHPhiOff; // Phi plot of the signal w.r.t. source+180deg 38 // + TH1D fHTemplate; // Template how the background should look in the ideal case 39 // 40 // + TH1D fHInhom; // Phi plot off the signal w.r.t. source (out of the ring with the signal) 41 // + TH1D fHInhomOff; // Phi plot off the signal w.r.t. source+180deg (out of the ring with the signal) 42 // 43 // + Int_t fNumBinsSignal; // Number of bins for signal region 44 // + Float_t fThetaCut; // Theta cut 45 // + Float_t fDistSrc; // Nominal distance of source from center in wobble 46 // 47 // + Bool_t fUseAntiPhiCut; // Whether to use a anti-phi cut or not 48 // 35 49 //////////////////////////////////////////////////////////////////////////// 36 50 #include "MHPhi.h" … … 63 77 // 64 78 MHPhi::MHPhi(const char *name, const char *title) 65 : fHillas(0), fSrcPos(0), fDisp(0)//, fOnOffMode(kTRUE), fIsOffLoop(kFALSE) 79 : fHillas(0), fSrcPos(0), fDisp(0), 80 fNumBinsSignal(2), fThetaCut(0.23), fDistSrc(0.4), 81 fUseAntiPhiCut(kTRUE) 66 82 { 67 83 fName = name ? name : "MHPhi"; … … 70 86 // Init Graphs 71 87 fHPhi.SetNameTitle("Phi", "\\Delta\\Phi-Distribution"); 72 73 fHPhi.SetXTitle("\\Delta\\Phi [\\circ]"); 88 fHPhi.SetXTitle("\\Delta\\Phi' [\\circ]"); 74 89 fHPhi.SetYTitle("Counts"); 75 90 … … 79 94 fHPhi.SetBit(TH1::kNoStats); 80 95 fHPhi.SetMarkerStyle(kFullDotMedium); 81 82 fHPhi.GetYaxis()->SetTitleOffset(1.2); 83 84 /* 85 fNameParameter = "Disp"; 86 87 fHist.SetNameTitle("Phi", "\\Delta\\Phi-Distribution"); 88 fHist.SetZTitle("\\Delta\\Phi [\\circ]"); 89 fHist.SetDirectory(NULL); 90 91 // Main histogram 92 fHistTime.SetName("Phi"); 93 fHistTime.SetXTitle("\\Delta\\Phi [\\circ]"); 94 fHistTime.SetDirectory(NULL); 95 96 MBinning binsa, binse, binst; 97 //binsa.SetEdges(75, 0, 1.5); 98 //binsa.SetEdges(arr); 99 binse.SetEdgesLog(15, 10, 100000); 100 binst.SetEdgesASin(67, -0.005, 0.665); 101 //binsa.Apply(fHistTime); 102 103 MH::SetBinning(&fHist, &binst, &binse, &binsa); 104 */ 105 } 106 107 /* 108 Double_t MHPhi::GetVal() const 109 { 110 const Dopuble_t disp = static_cast<const MParameterD*>(fParameter)->GetVal(); 111 112 const TVector2 pos = fHillas->GetMean()*fConvMm2Deg + fHillas->GetNormAxis()*disp; 113 const TVector2 src = fSrcPos->GetXY()*fConvMm2Deg; 114 115 // Calculate radial distance. 116 const Double_t d = pos.Mod() - src.Mod(); 117 118 if (d<-fThetaCut*0.913 || d>fThetaCut) 119 return kTRUE; 120 121 const Double_t delta = src.DeltaPhi(pos)*TMath::RadToDeg(); 122 const Double_t absd = TMath::Abs(delta) 123 124 return fHistOff ? absd : 180-absd; 125 } 126 */ 96 fHPhi.SetLineColor(kBlue); 97 fHPhi.SetMarkerColor(kBlue); 98 fHPhi.GetYaxis()->SetTitleOffset(1.3); 99 100 fHPhiOff.SetMinimum(0); 101 fHPhiOff.SetDirectory(0); 102 fHPhiOff.Sumw2(); 103 fHPhiOff.SetBit(TH1::kNoStats); 104 fHPhiOff.SetLineColor(kRed); 105 fHPhiOff.SetMarkerColor(kRed); 106 107 fHTemplate.SetMinimum(0); 108 fHTemplate.SetDirectory(0); 109 fHTemplate.SetBit(TH1::kNoStats); 110 fHTemplate.SetLineColor(kGreen); 111 112 fHInhom.SetNameTitle("Inhomogeneity", "\\Delta\\Phi-Distribution"); 113 fHInhom.SetXTitle("\\Delta\\Phi' [\\circ]"); 114 fHInhom.SetYTitle("Counts"); 115 fHInhom.Sumw2(); 116 fHInhom.SetMinimum(0); 117 fHInhom.SetDirectory(0); 118 fHInhom.SetBit(TH1::kNoStats); 119 fHInhom.GetYaxis()->SetTitleOffset(1.3); 120 121 fHInhomOff.Sumw2(); 122 fHInhomOff.SetMinimum(0); 123 fHInhomOff.SetDirectory(0); 124 fHInhomOff.SetBit(TH1::kNoStats); 125 fHInhomOff.SetLineColor(kRed); 126 fHInhomOff.SetMarkerColor(kRed); 127 } 127 128 128 129 // -------------------------------------------------------------------------- … … 161 162 fConvMm2Deg = geom->GetConvMm2Deg(); 162 163 163 fNumBinsSignal = 2; 164 fThetaCut = 0.21/1.2; 165 fDistSrc = 0.4; 166 //fIsOffLoop = !fIsOffLoop; 164 MParameterD *cut = (MParameterD*)plist->FindObject("ThetaSquaredCut", "MParameterD"); 165 if (!cut) 166 *fLog << warn << "ThetaSquareCut [MParameterD] not found... using default theta<" << fThetaCut << "." << endl; 167 else 168 fThetaCut = TMath::Sqrt(cut->GetVal()); 167 169 168 170 const Double_t w = TMath::ATan(fThetaCut/fDistSrc); … … 170 172 const Int_t n = TMath::Nint(TMath::Ceil(180/sz)); 171 173 172 MBinning(n, 0, n*sz).Apply(fHPhi); 173 /* 174 175 // Get Histogram binnings 176 MBinning binst, binse; 177 binst.SetEdges(fHist, 'x'); 178 binse.SetEdges(fHist, 'y'); 179 180 MBinning binsa(n, 0, n*sz); 181 182 // Apply binning 183 binsa.Apply(fHistTime); 184 MH::SetBinning(&fHist, &binst, &binse, &binsa); 185 186 // Remark: Binnings might be overwritten in MHAlpha::SetupFill 187 return MHAlpha::SetupFill(pl); 188 */ 174 MBinning(n+3, 0, (n+3)*sz).Apply(fHPhi); 175 MBinning(n+3, 0, (n+3)*sz).Apply(fHPhiOff); 176 MBinning(n+3, 0, (n+3)*sz).Apply(fHTemplate); 177 MBinning(n+3, 0, (n+3)*sz).Apply(fHInhom); 178 MBinning(n+3, 0, (n+3)*sz).Apply(fHInhomOff); 179 189 180 return kTRUE; 190 181 } … … 197 188 Bool_t MHPhi::Fill(const MParContainer *par, const Stat_t weight) 198 189 { 190 // Here we calculate an upper phi cut to take a 191 // possible anti-theta cut into account 192 const Double_t ulim = fUseAntiPhiCut ? 180-fHPhi.GetBinLowEdge(fNumBinsSignal+1)*1.1 : 180; 193 194 // Calculate the shower origin and the source position in units of deg 199 195 const TVector2 pos = fHillas->GetMean()*fConvMm2Deg + fHillas->GetNormAxis()*fDisp->GetVal(); 200 196 const TVector2 src = fSrcPos->GetXY()*fConvMm2Deg; 201 197 202 // Calculate radial distance .198 // Calculate radial distance between shower origin and source 203 199 const Double_t d = pos.Mod() - src.Mod(); 204 200 205 if (d<-fThetaCut*0.913 || d>fThetaCut) 201 // define an upper and lower cut for the radial distance between both 202 const Double_t dR = fThetaCut; 203 const Double_t dr = fThetaCut*0.913; 204 205 // calculate the phi-angle of the shower origin w.r.t. the source position 206 const Double_t delta = src.DeltaPhi(pos)*TMath::RadToDeg(); 207 208 // Define the radii of the upper and lower ring border 209 const Double_t R = src.Mod()+dR; 210 const Double_t r = src.Mod()-dr; 211 212 // Calculate a scale to scale all source positions to the 213 // nominal distance to center 214 const Double_t scale = src.Mod()/fDistSrc; 215 216 // Fill a phi-histograms with all events outside the ring 217 // Take the upper phi cut into account 218 if ((d<-dr || d>dR)/*TMath::Abs(d)>fThetaCut*1.2*/ && TMath::Abs(delta)<ulim) 219 { 220 fHInhom.Fill(TMath::Abs(delta)*scale, weight); 221 fHInhomOff.Fill((ulim-TMath::Abs(delta))*scale, weight); 222 } 223 224 // Now forget about all events which are not inside the ring 225 if (d<-dr || d>dR) 206 226 return kTRUE; 207 227 208 const Double_t delta = src.DeltaPhi(pos)*TMath::RadToDeg(); 209 210 fHPhi.Fill(TMath::Abs(delta), weight); 211 212 // const Double_t absd = TMath::Abs(delta) 213 // fHPhi.Fill(fHistOff ? absd : 180-absd, weight); 228 // Fill the histograms for on and off with the scaled phi 229 // only if we are below the upper phi cut 230 if (TMath::Abs(delta)<ulim) 231 { 232 fHPhi.Fill( TMath::Abs(delta)*scale, weight); 233 fHPhiOff.Fill((ulim-TMath::Abs(delta))*scale, weight); 234 } 235 236 // Calculate the maximum scaled phi taking the upper phi cut into account 237 const Double_t max = scale*ulim; 238 239 // Fill a template, this is how the phi-plot would look like 240 // without a signal and for an ideal camera. 241 const Int_t n = fHTemplate.GetNbinsX(); 242 TArrayD arr(n); 243 for (int i=1; i<=n; i++) 244 { 245 const Double_t hi = fHTemplate.GetBinLowEdge(i+1); 246 const Double_t lo = fHTemplate.GetBinLowEdge(i); 247 248 // Decide whether the bin is fully contained in the upper phi-cut or 249 // the maximum possible phi is inside the bin 250 if (hi<max) 251 arr[i-1] = 1; 252 else 253 if (lo<max) // if its inside calculate the ratio 254 arr[i-1] = (max-lo)/fHTemplate.GetBinWidth(i+1); 255 else 256 break; 257 } 258 259 // The template is scaled with the current ring width. The upper phi- 260 // cut must not be taken into account because it is just a constant 261 // for all events. 262 const Double_t sum = arr.GetSum(); 263 for (int i=1; i<=n; i++) 264 fHTemplate.AddBinContent(i, (R*R-r*r)*arr[i-1]/sum); 214 265 215 266 return kTRUE; … … 227 278 pad->SetBorderMode(0); 228 279 229 AppendPad("combine"); 280 AppendPad("update"); 281 282 pad->Divide(2,2); 283 284 // -------------------------- 285 286 pad->cd(1); 287 gPad->SetBorderMode(0); 288 gPad->SetFrameBorderMode(0); 230 289 231 290 fHPhi.Draw(); 232 233 AppendPad(opt); 234 } 235 236 void MHPhi::Paint(Option_t *o) 237 { 238 //TString opt(o); 239 //opt.ToLower(); 240 241 // if (opt=="combine" && fHistOff) 242 // { 243 // fHPhi.Add(fHist, fHistOff); 244 // return; 245 // } 246 247 const Bool_t wobble = TString(o).Contains("anticut", TString::kIgnoreCase); 248 249 const Double_t cut = fHPhi.GetBinLowEdge(fNumBinsSignal+1); 250 251 const Int_t maxbin = wobble ? fHPhi.GetXaxis()->FindFixBin(180-cut)-1 : fHPhi.GetNbinsX(); 252 const Double_t cut2 = wobble ? fHPhi.GetBinLowEdge(maxbin+1) : 180; 253 254 const Double_t sig = fHPhi.Integral(1, fNumBinsSignal); 255 const Double_t bg = fHPhi.Integral(1+fNumBinsSignal, maxbin); 256 257 const Double_t f = cut/(cut2-cut); 258 259 const Double_t S0 = MMath::SignificanceLiMaSigned(sig, bg*f); 260 const Double_t S = MMath::SignificanceLiMaSigned(sig, bg, f); 261 262 const TString fmt = Form("\\sigma_{L/M}=%.1f (\\sigma_{0}=%.1f) \\Delta\\Phi_{on}<%.1f\\circ \\Delta\\Phi_{off}<%.1f\\circ E=%.0f B=%.0f f=%.2f", 263 S, S0, cut, cut2, sig-bg*f, bg*f, f); 291 fHPhiOff.Draw("same"); 292 293 TH1D *h1 = new TH1D(fHTemplate); 294 h1->SetName("Template"); 295 h1->SetBit(kCanDelete); 296 h1->SetDirectory(0); 297 h1->Draw("same"); 298 299 // -------------------------- 300 301 pad->cd(2); 302 gPad->SetBorderMode(0); 303 gPad->SetFrameBorderMode(0); 304 305 fHInhom.Draw(); 306 fHInhomOff.Draw("same"); 307 308 TH1D *h2 = new TH1D(fHTemplate); 309 h2->SetName("Template"); 310 h2->SetBit(kCanDelete); 311 h2->SetDirectory(0); 312 h2->Draw("same"); 313 314 // -------------------------- 315 316 pad->cd(3); 317 gPad->SetBorderMode(0); 318 gPad->SetFrameBorderMode(0); 319 320 fHPhi.Draw(); 321 TH1D *h4 = new TH1D(fHInhom); 322 h4->SetName("Inhomogeneity"); 323 h4->SetBit(kCanDelete); 324 h4->SetDirectory(0); 325 h4->Draw("same"); 326 327 h1->Draw("same"); 328 329 // -------------------------- 330 331 pad->cd(4); 332 gPad->SetBorderMode(0); 333 gPad->SetFrameBorderMode(0); 334 335 TH1D *h3 = new TH1D(fHPhi); 336 h3->SetName("Result"); 337 h3->SetBit(kCanDelete); 338 h3->SetDirectory(0); 339 h3->Draw(); 340 341 h1->Draw("same"); 342 343 // -------------------------- 344 345 pad->cd(); 346 AppendPad("result"); 347 } 348 349 void MHPhi::PaintUpdate() const 350 { 351 TVirtualPad *pad1 = gPad->GetPad(1); 352 TVirtualPad *pad2 = gPad->GetPad(2); 353 TVirtualPad *pad3 = gPad->GetPad(3); 354 TVirtualPad *pad4 = gPad->GetPad(4); 355 356 Double_t sig2 = 0; 357 Double_t bg2 = 0; 358 Double_t f2 = 1; 359 TH1D *htemp = pad1 ? dynamic_cast<TH1D*>(pad1->FindObject("Template")) : NULL; 360 if (htemp) 361 { 362 fHTemplate.Copy(*htemp); 363 htemp->SetName("Template"); 364 htemp->SetDirectory(0); 365 366 Double_t sc1 = 1; 367 Double_t sc2 = 1; 368 369 TH1D *res = pad4 ? dynamic_cast<TH1D*>(pad4->FindObject("Result")) : NULL; 370 if (res) 371 { 372 fHPhi.Copy(*res); 373 374 // Scale inhomogeneity to match the phi-plot in the off-region 375 sc1 = res->Integral(fNumBinsSignal+1, 9999)/fHInhom.Integral(fNumBinsSignal+1, 9999); 376 // Scale inhomogeneity to match the phi-plot in the off-region 377 sc2 = fHInhom.Integral()/htemp->Integral(); 378 379 res->Add(&fHInhom, -sc1); 380 res->Add(htemp, sc1*sc2); 381 res->SetName("Result"); 382 res->SetDirectory(0); 383 384 htemp->Scale(res->Integral(fNumBinsSignal+1, 9999)/htemp->Integral(fNumBinsSignal+1, 9999)); 385 386 sig2 = res->Integral(1, fNumBinsSignal); 387 bg2 = fHPhi.Integral(fNumBinsSignal+1, 9999); 388 f2 = htemp->Integral(1, fNumBinsSignal)/htemp->Integral(fNumBinsSignal+1, 9999); 389 } 390 391 TH1D *hinhom = pad3 ? dynamic_cast<TH1D*>(pad3->FindObject("Inhomogeneity")) : NULL; 392 if (hinhom) 393 { 394 fHInhom.Copy(*hinhom); 395 hinhom->SetName("Inhomogeneity"); 396 hinhom->SetDirectory(0); 397 hinhom->Scale(sc1); 398 } 399 } 400 401 htemp = pad2 ? dynamic_cast<TH1D*>(pad2->FindObject("Template")) : NULL; 402 if (htemp) 403 { 404 fHTemplate.Copy(*htemp); 405 htemp->Scale(fHInhom.Integral()/htemp->Integral()); 406 htemp->SetName("Template"); 407 htemp->SetDirectory(0); 408 } 409 } 410 411 void MHPhi::PaintText(const TH1D &res) const 412 { 413 const Double_t cut = res.GetBinLowEdge(fNumBinsSignal+1); 414 415 const Double_t sig = res.Integral(1, fNumBinsSignal); 416 const Double_t bg = res.Integral(fNumBinsSignal+1, 9999); 417 418 const Double_t f = fHTemplate.Integral(1, fNumBinsSignal)/fHTemplate.Integral(fNumBinsSignal+1, 9999); 419 420 const Double_t S0 = MMath::SignificanceLiMaSigned(sig, bg*f); 421 const Double_t S = MMath::SignificanceLiMaSigned(sig, bg, f); 422 423 const TString fmt = Form("\\sigma_{L/M}=%.1f (\\sigma_{0}=%.1f) \\Delta\\Phi_{on}<%.1f\\circ E=%.0f B=%.0f f=%.2f", 424 S, S0, cut, sig-bg*f, bg*f, f); 264 425 265 426 const Double_t b = bg *f/fNumBinsSignal; 266 427 const Double_t e = TMath::Sqrt(bg)*f/fNumBinsSignal; 267 428 268 TLatex text(0.27 , 0.94, fmt);429 TLatex text(0.275, 0.95, fmt); 269 430 text.SetBit(TLatex::kTextNDC); 270 text.SetTextSize(0.0 35);431 text.SetTextSize(0.042); 271 432 text.Paint(); 272 433 … … 274 435 line.SetLineColor(14); 275 436 line.PaintLine(cut, gPad->GetUymin(), cut, gPad->GetUymax()); 276 if (maxbin<fHPhi.GetNbinsX()) 277 line.PaintLine(cut2, gPad->GetUymin(), cut2, gPad->GetUymax()); 278 line.SetLineColor(kBlue); 437 438 // Here we calculate an upper phi cut to take a 439 // possible anti-theta cut into account 440 const Double_t ulim = fUseAntiPhiCut ? 180-fHPhi.GetBinLowEdge(fNumBinsSignal+1)*1.1 : 180; 441 line.SetLineStyle(kDotted); 442 line.PaintLine(ulim, gPad->GetUymin(), ulim, gPad->GetUymax()); 443 444 line.SetLineStyle(kSolid); 445 line.SetLineColor(kBlack); 279 446 line.PaintLine(0, b, cut, b); 280 447 line.PaintLine(cut/2, b-e, cut/2, b+e); … … 283 450 284 451 TMarker m; 285 m.SetMarkerColor(kBlue);286 452 m.SetMarkerStyle(kFullDotMedium); 287 453 m.PaintMarker(cut/2, b); 288 454 } 455 456 void MHPhi::PaintResult() const 457 { 458 TVirtualPad *pad = gPad; 459 460 pad->cd(1); 461 PaintText(fHPhi); 462 463 pad->cd(4); 464 TH1D *res = gPad ? dynamic_cast<TH1D*>(gPad->FindObject("Result")) : NULL; 465 if (res) 466 PaintText(*res); 467 } 468 469 void MHPhi::Paint(Option_t *o) 470 { 471 TString opt(o); 472 if (opt=="update") 473 PaintUpdate(); 474 if (opt=="result") 475 PaintResult(); 476 } 477 478 Int_t MHPhi::ReadEnv(const TEnv &env, TString prefix, Bool_t print) 479 { 480 Bool_t rc = kFALSE; 481 if (IsEnvDefined(env, prefix, "NumBinsSignal", print)) 482 { 483 SetNumBinsSignal(GetEnvValue(env, prefix, "NumBinsSignal", (Int_t)fNumBinsSignal)); 484 rc = kTRUE; 485 } 486 if (IsEnvDefined(env, prefix, "UseAntiPhiCut", print)) 487 { 488 SetUseAntiPhiCut(GetEnvValue(env, prefix, "UseAntiPhiCut", (Int_t)fUseAntiPhiCut)); 489 rc = kTRUE; 490 } 491 492 return rc; 493 }
Note:
See TracChangeset
for help on using the changeset viewer.