Changeset 5904 for trunk/MagicSoft/Mars/mtemp/mifae/library/MHDisp.cc
- Timestamp:
- 01/20/05 10:09:24 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mtemp/mifae/library/MHDisp.cc
r5671 r5904 29 29 // // 30 30 // container holding the histograms for Disp // 31 // also computes the Chi^2 of the Disp optimization//31 // also computes the minimization parameter of the Disp optimization // 32 32 // // 33 33 ///////////////////////////////////////////////////////////////////////////// … … 54 54 55 55 #include "MHMatrix.h" 56 #include "MParameters.h" 56 57 57 58 #include "MParList.h" … … 63 64 64 65 using namespace std; 66 67 enum dispVar_t {kX,kY,kMeanX,kMeanY,kDelta,kSize,kM3Long,kAsym, 68 kEnergy,kImpact,kLongitmax,kZd,kAz,kTotVar}; // enum variables for the 69 // matrix columns mapping 65 70 66 71 // -------------------------------------------------------------------------- … … 75 80 fTitle = title ? title : "Histograms for Disp"; 76 81 77 fSelectedPos = 1; // default MHDisp flag (selects Correct Disp s rcpos)82 fSelectedPos = 1; // default MHDisp flag (selects Correct Disp source position solution) 78 83 79 84 fMatrix = NULL; 85 86 // initialize mapping array dimension to the number of columns of fMatrix 87 fMap.Set(kTotVar); 80 88 81 89 //-------------------------------------------------- … … 110 118 fSkymapXY->SetYTitle("Y Disp source position [deg]"); 111 119 112 fHist Chi2 = new TH1F("fHistChi2" ,120 fHistMinPar = new TH1F("fHistMinPar" , 113 121 "Distance^2 between Disp and real srcpos", 100, 0., 2.); 114 fHist Chi2->SetDirectory(NULL);115 fHist Chi2->UseCurrentStyle();116 fHist Chi2->SetXTitle("Chi^2 = distance^2 Disp to real srcpos [deg^2]");117 fHist Chi2->SetYTitle("# events");122 fHistMinPar->SetDirectory(NULL); 123 fHistMinPar->UseCurrentStyle(); 124 fHistMinPar->SetXTitle("Minimization parameter = d^2 Disp to real srcpos [deg^2]"); 125 fHistMinPar->SetYTitle("# events"); 118 126 119 127 fHistDuDv = new TH2F("fHistDuDv", … … 125 133 fHistDuDv->SetYTitle("Du = longitudinal distance [deg]"); 126 134 127 fHist Chi2Energy = new TH2F("fHistChi2Energy",128 " Chi^2vs. Energy", 50, 1., 3., 100, 0., 2.);129 fHist Chi2Energy->SetDirectory(NULL);130 fHist Chi2Energy->UseCurrentStyle();131 fHist Chi2Energy->SetXTitle("log10(Energy) [GeV]");132 fHist Chi2Energy->SetYTitle("Chi^2 = distance^2 Disp to real srcpos [deg^2]");133 134 fHist Chi2Size = new TH2F("fHistChi2Size",135 " Chi^2vs. Size", 50, 2., 4., 100, 0., 2.);136 fHist Chi2Size->SetDirectory(NULL);137 fHist Chi2Size->UseCurrentStyle();138 fHist Chi2Size->SetXTitle("log10(Size) [#phot]");139 fHist Chi2Size->SetYTitle("Chi^2 = distance^2 Disp to real srcpos [deg^2]");135 fHistMinParEnergy = new TH2F("fHistMinParEnergy", 136 "Minimization parameter vs. Energy", 50, 1., 3., 100, 0., 2.); 137 fHistMinParEnergy->SetDirectory(NULL); 138 fHistMinParEnergy->UseCurrentStyle(); 139 fHistMinParEnergy->SetXTitle("log10(Energy) [GeV]"); 140 fHistMinParEnergy->SetYTitle("Minimization parameter = d^2 Disp to real srcpos [deg^2]"); 141 142 fHistMinParSize = new TH2F("fHistMinParSize", 143 "Minimization parameter vs. Size", 50, 2., 4., 100, 0., 2.); 144 fHistMinParSize->SetDirectory(NULL); 145 fHistMinParSize->UseCurrentStyle(); 146 fHistMinParSize->SetXTitle("log10(Size) [#phot]"); 147 fHistMinParSize->SetYTitle("Minimization parameter = d^2 Disp to real srcpos [deg^2]"); 140 148 141 149 fHistDuEnergy = new TH2F("fHistDuEnergy", … … 170 178 "Fraction events srcpos well assign vs. Size", 50, 2., 4., 0., 1.); 171 179 fEvCorrAssign->SetDirectory(NULL); 172 fEvCorrAssign-> UseCurrentStyle();180 fEvCorrAssign->SetStats(0); 173 181 fEvCorrAssign->SetXTitle("log10(Size) [#phot]"); 174 182 fEvCorrAssign->SetYTitle("Fraction of events with srcpos well assign"); … … 186 194 delete fHistcosZA; 187 195 delete fSkymapXY; 188 delete fHist Chi2;196 delete fHistMinPar; 189 197 delete fHistDuDv; 190 delete fHist Chi2Energy;191 delete fHist Chi2Size;198 delete fHistMinParEnergy; 199 delete fHistMinParSize; 192 200 delete fHistDuEnergy; 193 201 delete fHistDuSize; … … 204 212 Bool_t MHDisp::SetupFill(const MParList *pList) 205 213 { 206 // reset all histograms and Chi^2computing variables214 // reset all histograms and Minimization parameter computing variables 207 215 // before each new eventloop 208 216 fNumEv = 0; 209 fSumChi2 = 0.; 210 fChi2 = 0.; 217 fSumMinPar = 0.; 218 fMinPar = (MParameterD*)const_cast<MParList*>(pList)->FindCreateObj("MParameterD", "MinimizationParameter"); 219 if (!fMinPar) 220 { 221 *fLog << err << "MParameterD (MinimizationParameter) not found and could not be created... aborting." 222 << endl; 223 return kFALSE; 224 } 225 fMinPar->SetVal(0); 211 226 212 227 fHistEnergy->Reset(); … … 214 229 fHistcosZA->Reset(); 215 230 fSkymapXY->Reset(); 216 fHist Chi2->Reset();231 fHistMinPar->Reset(); 217 232 fHistDuDv->Reset(); 218 fHist Chi2Energy->Reset();219 fHist Chi2Size->Reset();233 fHistMinParEnergy->Reset(); 234 fHistMinParSize->Reset(); 220 235 fHistDuEnergy->Reset(); 221 236 fHistDuSize->Reset(); … … 250 265 // if fMatrix exists, skip preprocessing and just read events from matrix; 251 266 // if doesn't exist, read variables values from containers, so look for them 267 cout << "MHDisp::SetupFill: fMatrix = " << fMatrix << endl; 268 252 269 if (fMatrix) 253 270 return kTRUE; … … 291 308 if (!fPointing) 292 309 { 293 *fLog << err << "MPointingPos not found... " 294 << "MMcEvt is going to be used to get Theta and Phi." 295 << endl; 296 // return kFALSE; 310 *fLog << err << "MPointingPos not found... aborting." << endl; 311 return kFALSE; 297 312 } 298 313 … … 306 321 // 307 322 // Set which selection algorithm for the Disp estimated source position 308 // we want to follow when filling the histograms:323 // solutions we want to follow when filling the histograms: 309 324 // * iflag == 1 --> Correct source position, the closest to the real srcpos 310 325 // (only applicable to MC or well known source real data) … … 323 338 // 324 339 // Sets the Matrix and the array of mapped values for each Matrix column 325 // (see MDispCalc)326 340 // 327 341 void MHDisp::SetMatrixMap(MHMatrix *matrix, TArrayI &map) … … 334 348 // -------------------------------------------------------------------------- 335 349 // 350 // Returns the Matrix and the mapped value for each Matrix column 351 // 352 void MHDisp::GetMatrixMap(MHMatrix* &matrix, TArrayI &map) 353 { 354 map = fMap; 355 matrix = fMatrix; 356 } 357 358 359 // -------------------------------------------------------------------------- 360 // 361 // You can use this function if you want to use a MHMatrix instead of the 362 // given containers for the Disp optimization. This function adds all 363 // necessary columns to the given matrix. Afterwards, you should fill 364 // the matrix with the corresponding data (eg from a file by using 365 // MHMatrix::Fill). Then, if you loop through the matrix (eg using 366 // MMatrixLoop), MHDisp::Fill will take the values from the matrix 367 // instead of the containers. 368 // 369 void MHDisp::InitMapping(MHMatrix *mat) 370 { 371 if (fMatrix) 372 return; 373 374 fMatrix = mat; 375 376 fMap[kX] = fMatrix->AddColumn("MSrcPosCam.fX"); 377 fMap[kY] = fMatrix->AddColumn("MSrcPosCam.fY"); 378 fMap[kMeanX] = fMatrix->AddColumn("MHillas.fMeanX"); 379 fMap[kMeanY] = fMatrix->AddColumn("MHillas.fMeanY"); 380 fMap[kDelta] = fMatrix->AddColumn("MHillas.fDelta"); 381 382 fMap[kSize] = fMatrix->AddColumn("MHillas.fSize"); 383 384 fMap[kM3Long] = fMatrix->AddColumn("MHillasExt.fM3Long"); 385 fMap[kAsym] = fMatrix->AddColumn("MHillasExt.fAsym"); 386 387 fMap[kEnergy] = fMatrix->AddColumn("MMcEvt.fEnergy"); 388 fMap[kImpact] = fMatrix->AddColumn("MMcEvt.fImpact"); 389 fMap[kLongitmax] = fMatrix->AddColumn("MMcEvt.fLongitmax"); 390 391 fMap[kZd] = fMatrix->AddColumn("MPointingPos.fZd"); 392 fMap[kAz] = fMatrix->AddColumn("MPointingPos.fAz"); 393 } 394 395 396 // -------------------------------------------------------------------------- 397 // 336 398 // Returns a mapped value from the Matrix 337 399 // … … 349 411 // -------------------------------------------------------------------------- 350 412 // 351 // Fill the histograms and sum up the Chi^2 outcome of each processed event 413 // Fill the histograms and sum up the Minimization paramter outcome 414 // of each processed event 352 415 // 353 416 Bool_t MHDisp::Fill(const MParContainer *par, const Stat_t w) … … 356 419 Double_t impact = 0.; 357 420 Double_t xmax = 0.; 358 Double_t theta = 0.;359 Double_t phi = 0.;360 421 361 422 if ( fMatrix || (!fMatrix && fMcEvt) ) 362 423 { 363 energy = fMatrix ? GetVal(13) : fMcEvt->GetEnergy(); 364 impact = fMatrix ? GetVal(14) : fMcEvt->GetImpact(); 365 xmax = fMatrix ? GetVal(15) : fMcEvt->GetLongitmax(); 366 367 if (fPointing) 368 { 369 theta = fMatrix ? GetVal(16) : fPointing->GetZd(); 370 phi = fMatrix ? GetVal(17) : fPointing->GetAz(); 371 } 372 else 373 { 374 theta = fMatrix ? GetVal(16) : fMcEvt->GetTelescopeTheta()*kRad2Deg; 375 phi = fMatrix ? GetVal(17) : fMcEvt->GetTelescopePhi()*kRad2Deg; 376 } 424 energy = fMatrix ? GetVal(kEnergy) : fMcEvt->GetEnergy(); 425 impact = fMatrix ? GetVal(kImpact) : fMcEvt->GetImpact(); 426 xmax = fMatrix ? GetVal(kLongitmax) : fMcEvt->GetLongitmax(); 377 427 } 378 428 else 379 429 *fLog << "No MMcEvt container available (no Energy,ImpactPar or Xmax)" << endl; 380 430 381 Double_t xsrcpos0 = fMatrix ? GetVal(0) : fSrcPos->GetX(); 382 Double_t ysrcpos0 = fMatrix ? GetVal(1) : fSrcPos->GetY(); 383 Double_t xmean0 = fMatrix ? GetVal(2) : fHil->GetMeanX(); 384 Double_t ymean0 = fMatrix ? GetVal(3) : fHil->GetMeanY(); 385 Double_t delta = fMatrix ? GetVal(4) : fHil->GetDelta(); 386 387 Double_t size = fMatrix ? GetVal(5) : fHil->GetSize(); 388 // Double_t width0 = fMatrix ? GetVal(6) : fHil->GetWidth(); 389 // Double_t length0 = fMatrix ? GetVal(7) : fHil->GetLength(); 390 391 // Double_t conc = fMatrix ? GetVal(8) : fNewPar->GetConc(); 392 // Double_t leakage1 = fMatrix ? GetVal(9) : fNewPar->GetLeakage1(); 393 // Double_t leakage2 = fMatrix ? GetVal(10) : fNewPar->GetLeakage2(); 394 395 Double_t m3long = fMatrix ? GetVal(11) : fHilExt->GetM3Long(); 396 Double_t asym = fMatrix ? GetVal(12) : fHilExt->GetAsym(); 431 Double_t theta = fMatrix ? GetVal(kZd) : fPointing->GetZd(); 432 // Double_t phi = fMatrix ? GetVal(kAz) : fPointing->GetAz(); 433 434 Double_t xsrcpos0 = fMatrix ? GetVal(kX) : fSrcPos->GetX(); 435 Double_t ysrcpos0 = fMatrix ? GetVal(kY) : fSrcPos->GetY(); 436 Double_t xmean0 = fMatrix ? GetVal(kMeanX) : fHil->GetMeanX(); 437 Double_t ymean0 = fMatrix ? GetVal(kMeanY) : fHil->GetMeanY(); 438 Double_t delta = fMatrix ? GetVal(kDelta) : fHil->GetDelta(); 439 440 Double_t size = fMatrix ? GetVal(kSize) : fHil->GetSize(); 441 442 Double_t m3long = fMatrix ? GetVal(kM3Long) : fHilExt->GetM3Long(); 443 Double_t asym = fMatrix ? GetVal(kAsym) : fHilExt->GetAsym(); 397 444 398 445 //------------------------------------------ 399 446 // convert to deg 400 // Double_t width = width0 * fMm2Deg;401 // Double_t length = length0 * fMm2Deg;402 447 Double_t xsrcpos = xsrcpos0 * fMm2Deg; 403 448 Double_t ysrcpos = ysrcpos0 * fMm2Deg; … … 453 498 // Distance between estimated Disp and real source position 454 499 Double_t d2 = (xdisp-xsrcpos)*(xdisp-xsrcpos) + (ydisp-ysrcpos)*(ydisp-ysrcpos); 455 fHist Chi2->Fill(d2);500 fHistMinPar->Fill(d2); 456 501 457 502 // Longitudinal and transversal distances between Disp and real source positon … … 465 510 fHistcosZA->Fill(cos(theta/kRad2Deg)); 466 511 467 // to check the size dependence of the optimization468 fHist Chi2Energy->Fill(log10(energy),d2);469 fHist Chi2Size->Fill(log10(size),d2);512 // to check the size and energy dependence of the optimization 513 fHistMinParEnergy->Fill(log10(energy),d2); 514 fHistMinParSize->Fill(log10(size),d2); 470 515 fHistDuEnergy->Fill(log10(energy),Du); 471 516 fHistDuSize->Fill(log10(size),Du); … … 473 518 fHistDvSize->Fill(log10(size),Dv); 474 519 475 // variables for Chi^2calculation (= d^2)520 // variables for the Minimization parameter calculation (= d^2) 476 521 fNumEv += 1; 477 fSum Chi2+= d2;522 fSumMinPar += d2; 478 523 479 524 return kTRUE; … … 483 528 // -------------------------------------------------------------------------- 484 529 // 485 // Calculates the final Chi^2of the Disp optimization530 // Calculates the final Minimization parameter of the Disp optimization 486 531 // 487 532 Bool_t MHDisp::Finalize() 488 533 { 489 f Chi2 = fSumChi2/fNumEv;534 fMinPar->SetVal(fSumMinPar/fNumEv); 490 535 *fLog << endl; 491 *fLog << "MHDisp::Finalize: Sum Chi2, NumEv = " << fSumChi2<< ", " << fNumEv << endl;492 *fLog << "MHDisp::Finalize: Final Chi2 = " << fChi2<< endl;493 494 f Chi2 = fHistChi2->GetMean();495 *fLog << "MHDisp::Finalize: Final Chi2 = " << fChi2<< endl;536 *fLog << "MHDisp::Finalize: SumMinPar, NumEv = " << fSumMinPar << ", " << fNumEv << endl; 537 *fLog << "MHDisp::Finalize: Final MinPar = " << fMinPar->GetVal() << endl; 538 539 fMinPar->SetVal(fHistMinPar->GetMean()); 540 *fLog << "MHDisp::Finalize: Final MinPar = " << fMinPar->GetVal() << endl; 496 541 497 542 SetReadyToSave(); … … 542 587 pad->cd(4); 543 588 gPad->SetBorderMode(0); 544 fHist Chi2->SetTitleOffset(1.2,"Y");545 fHist Chi2->DrawClone(opt);546 fHist Chi2->SetBit(kCanDelete);547 gPad->Modified(); 548 549 TProfile *prof Chi2Energy = fHistChi2Energy->ProfileX("Chi^2vs. Energy",0,99999,"s");550 prof Chi2Energy->SetXTitle("log10(Energy) [GeV]");551 prof Chi2Energy->SetYTitle("Chi^2 = distance^2 Disp to real srcpos [deg^2]");589 fHistMinPar->SetTitleOffset(1.2,"Y"); 590 fHistMinPar->DrawClone(opt); 591 fHistMinPar->SetBit(kCanDelete); 592 gPad->Modified(); 593 594 TProfile *profMinParEnergy = fHistMinParEnergy->ProfileX("Minimization parameter vs. Energy",0,99999,"s"); 595 profMinParEnergy->SetXTitle("log10(Energy) [GeV]"); 596 profMinParEnergy->SetYTitle("Minimization parameter = d^2 Disp to real srcpos [deg^2]"); 552 597 pad->cd(5); 553 598 gPad->SetBorderMode(0); 554 profChi2Energy->SetTitleOffset(1.2,"Y"); 555 profChi2Energy->DrawClone(opt); 556 profChi2Energy->SetBit(kCanDelete); 557 gPad->Modified(); 558 559 TProfile *profChi2Size = fHistChi2Size->ProfileX("Chi^2 vs. Size",0,99999,"s"); 560 profChi2Size->SetXTitle("log10(Size) [#phot]"); 561 profChi2Size->SetYTitle("Chi^2 = distance^2 Disp to real srcpos [deg^2]"); 599 profMinParEnergy->SetTitleOffset(1.2,"Y"); 600 profMinParEnergy->SetStats(0); 601 profMinParEnergy->DrawClone(opt); 602 profMinParEnergy->SetBit(kCanDelete); 603 gPad->Modified(); 604 605 TProfile *profMinParSize = fHistMinParSize->ProfileX("Minimization parameter vs. Size",0,99999,"s"); 606 profMinParSize->SetXTitle("log10(Size) [#phot]"); 607 profMinParSize->SetYTitle("Minimization parameter = d^2 Disp to real srcpos [deg^2]"); 562 608 pad->cd(6); 563 609 gPad->SetBorderMode(0); 564 profChi2Size->SetTitleOffset(1.2,"Y"); 565 profChi2Size->DrawClone(opt); 566 profChi2Size->SetBit(kCanDelete); 610 profMinParSize->SetTitleOffset(1.2,"Y"); 611 profMinParSize->SetStats(0); 612 profMinParSize->DrawClone(opt); 613 profMinParSize->SetBit(kCanDelete); 567 614 gPad->Modified(); 568 615 … … 604 651 gPad->SetBorderMode(0); 605 652 profDuEnergy->SetTitleOffset(1.2,"Y"); 653 profDuEnergy->SetStats(0); 606 654 profDuEnergy->DrawClone(opt); 607 655 profDuEnergy->SetBit(kCanDelete); … … 614 662 gPad->SetBorderMode(0); 615 663 profDuSize->SetTitleOffset(1.2,"Y"); 664 profDuSize->SetStats(0); 616 665 profDuSize->DrawClone(opt); 617 666 profDuSize->SetBit(kCanDelete); … … 634 683 gPad->SetBorderMode(0); 635 684 profDvEnergy->SetTitleOffset(1.2,"Y"); 685 profDvEnergy->SetStats(0); 636 686 profDvEnergy->DrawClone(opt); 637 687 profDvEnergy->SetBit(kCanDelete); … … 644 694 gPad->SetBorderMode(0); 645 695 profDvSize->SetTitleOffset(1.2,"Y"); 696 profDvSize->SetStats(0); 646 697 profDvSize->DrawClone(opt); 647 698 profDvSize->SetBit(kCanDelete);
Note:
See TracChangeset
for help on using the changeset viewer.