- Timestamp:
- 08/19/03 10:59:28 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/macros/CT1Analysis.C
r2262 r2301 1 1 2 2 #include "CT1EgyEst.C" 3 4 #include "MBinning.h" 5 #include "MBlindPixelCalc.h" 6 #include "MContinue.h" 7 #include "MCT1PointingCorrCalc.h" 8 9 #include "MFCT1SelBasic.h" 10 #include "MFCT1SelStandard.h" 11 #include "MFCT1SelFinal.h" 12 #include "MFillH.h" 13 14 #include "MHillasCalc.h" 15 #include "MHillasSrcCalc.h" 16 #include "MImgCleanStd.h" 17 18 #include "MParList.h" 19 #include "MSigmabarCalc.h" 20 #include "MSrcPosCam.h" 21 #include "MTaskList.h" 22 #include "MWriteRootFile.h" 23 24 3 25 4 26 void InitBinnings(MParList *plist) … … 6 28 gLog << "InitBinnings" << endl; 7 29 30 //-------------------------------------------- 8 31 MBinning *binse = new MBinning("BinningE"); 9 32 //binse->SetEdgesLog(30, 1.0e2, 1.0e5); 10 binse->SetEdges(30, 2, 5); 33 34 //This is Daniel's binning in energy: 35 binse->SetEdgesLog(14, 296.296, 86497.6); 11 36 plist->AddToList(binse); 37 38 //-------------------------------------------- 12 39 13 40 MBinning *binssize = new MBinning("BinningSize"); … … 51 78 MBinning *binth = new MBinning("BinningTheta"); 52 79 Double_t yedge[9] = 53 { 7.5, 17.5, 23.5, 29.5, 35.5, 42., 50., 60., 70.};80 {0.0, 17.5, 23.5, 29.5, 35.5, 42., 50., 60., 70.}; 54 81 TArrayD yed(9,yedge); 55 82 binth->SetEdges(yed); … … 69 96 binsdiff->SetEdges(100, -5.0, 20.0); 70 97 plist->AddToList(binsdiff); 98 99 // robert ---------------------------------------------- 100 MBinning *binsalphaf = new MBinning("BinningAlphaFlux"); 101 binsalphaf->SetEdges(100, -100, 100); 102 plist->AddToList(binsalphaf); 103 104 MBinning *binsdifftime = new MBinning("BinningTimeDiff"); 105 binsdifftime->SetEdges(50, 0, 10); 106 plist->AddToList(binsdifftime); 107 108 MBinning *binstime = new MBinning("BinningTime"); 109 binstime->SetEdges(50, 44500, 61000); 110 plist->AddToList(binstime); 71 111 } 72 112 … … 112 152 113 153 bin = plist->FindObject("BinningDiffsigma2"); 154 if (bin) delete bin; 155 156 //robert 157 bin = plist->FindObject("BinningAlphaFlux"); 158 if (bin) delete bin; 159 160 bin = plist->FindObject("BinningTimeDiff"); 161 if (bin) delete bin; 162 163 bin = plist->FindObject("BinningTime"); 114 164 if (bin) delete bin; 115 165 } … … 173 223 Bool_t RLookNN = kFALSE; // read in look-alike events 174 224 Bool_t WNN = kFALSE; // update input root file ? 225 226 227 // Job B_SC_UP : read ON1.root (or MC1.root) file 228 // - depending on WParSC : create (or read in) supercuts parameter values 229 // - calculate hadroness for the SUPERCUTS 230 // - update the input files with the hadroness (ON1.root or MC1.root) 231 232 Bool_t JobB_SC_UP = kTRUE; 233 Bool_t RMatrix = kFALSE; // read matrices from file 234 Bool_t WParSC = kTRUE; // do optimization and write supercuts 235 // parameter values onto a file 236 Bool_t WSC = kFALSE; // update input root file ? 175 237 176 238 … … 209 271 210 272 211 212 273 // Job E_XX : 213 274 // - select g/h separation method XX 214 // - read MC _XX2.root file275 // - read MC root file 215 276 // - calculate eff. collection area 216 // - read ON_XX2.root file 277 // - optimize energy estimator 278 // - read ON root file 279 // - apply final cuts 280 // - write root file for ON data after final cuts 281 282 Bool_t JobE_XX = kFALSE; 283 Bool_t WXX = kFALSE; // write out root file ? 284 285 286 // Job F_XX : extended version of E_XX (including flux plots) 287 // - select g/h separation method XX 288 // - read MC root file 289 // - calculate eff. collection area 290 // - optimize energy estimator 291 // - read ON root file 217 292 // - apply final cuts 218 293 // - calculate flux 219 // - write root file for ON data after final cuts (ON3.root))220 221 Bool_t Job E_XX = kTRUE;222 Bool_t W XX = kFALSE; // write out root file ON3.root?294 // - write root file for ON data after final cuts 295 296 Bool_t JobF_XX = kFALSE; 297 Bool_t WFX = kFALSE; // write out root file ? 223 298 224 299 … … 344 419 contstandard.SetName("SelStandard"); 345 420 346 347 MWriteRootFile write(outNameImage); 421 if (WON1) 422 { 423 MWriteRootFile &write = *(new MWriteRootFile(outNameImage)); 348 424 349 425 write.AddContainer("MRawRunHeader", "RunHeaders"); … … 357 433 write.AddContainer("MHillasSrc", "Events"); 358 434 write.AddContainer("MNewImagePar", "Events"); 359 435 } 360 436 361 437 //$$$$$$$$$$$$$$$$$$$$$$$$$$$$ … … 677 753 678 754 679 680 MWriteRootFile write(outNameImage); 755 if (WMC1) 756 { 757 MWriteRootFile &write = *(new MWriteRootFile(outNameImage)); 681 758 682 759 write.AddContainer("MRawRunHeader", "RunHeaders"); … … 690 767 write.AddContainer("MHillasSrc", "Events"); 691 768 write.AddContainer("MNewImagePar", "Events"); 692 769 } 693 770 694 771 … … 1315 1392 1316 1393 //--------------------------------------------------------------------- 1394 // Job B_SC_UP 1395 //============ 1396 1397 // - create (or read in) optimum supercuts parameter values 1398 // 1399 // - calculate the hadroness for the supercuts 1400 // 1401 // - update input root file, including the hadroness 1402 1403 1404 if (JobB_SC_UP) 1405 { 1406 gLog << "=====================================================" << endl; 1407 gLog << "Macro CT1Analysis : Start of Job B_SC_UP" << endl; 1408 1409 gLog << "" << endl; 1410 gLog << "Macro CT1Analysis : JobB_SC_UP, WParSC, WSC = " 1411 << JobB_SC_UP << ", " << WParSC << ", " << WSC << endl; 1412 1413 1414 1415 //-------------------------------------------- 1416 // file to be updated (either ON or MC) 1417 1418 TString typeInput = "ON"; 1419 //TString typeInput = "MC"; 1420 gLog << "typeInput = " << typeInput << endl; 1421 1422 // name of input root file 1423 TString filenameData = outPath; 1424 filenameData += typeInput; 1425 filenameData += "2.root"; 1426 gLog << "filenameData = " << filenameData << endl; 1427 1428 // name of output root file 1429 TString outNameImage = outPath; 1430 outNameImage += typeInput; 1431 outNameImage += "3.root"; 1432 outNameImage += "xxxxx"; 1433 1434 1435 //TString outNameImage = filenameData; 1436 1437 gLog << "outNameImage = " << outNameImage << endl; 1438 1439 //-------------------------------------------- 1440 // files to be read for optimizing the supercuts 1441 // 1442 // for the training 1443 TString filenameTrain = outPath; 1444 filenameTrain += "ON"; 1445 filenameTrain += "2.root"; 1446 Int_t howManyTrain = 800000; 1447 gLog << "filenameTrain = " << filenameTrain << ", howManyTrain = " 1448 << howManyTrain << endl; 1449 1450 // for testing 1451 TString filenameTest = outPath; 1452 filenameTest += "ON"; 1453 filenameTest += "2.root"; 1454 Int_t howManyTest = 100000; 1455 1456 gLog << "filenameTest = " << filenameTest << ", howManyTest = " 1457 << howManyTest << endl; 1458 1459 1460 //-------------------------------------------- 1461 // files to contain the matrices (genertated from filenameTrain and 1462 // filenameTest) 1463 // 1464 // for the training 1465 TString fileMatrixTrain = outPath; 1466 fileMatrixTrain += "MatrixTrainSC"; 1467 fileMatrixTrain += ".root"; 1468 gLog << "fileMatrixTrain = " << fileMatrixTrain << endl; 1469 1470 // for testing 1471 TString fileMatrixTest = outPath; 1472 fileMatrixTest += "MatrixTestSC"; 1473 fileMatrixTest += ".root"; 1474 gLog << "fileMatrixTest = " << fileMatrixTest << endl; 1475 1476 1477 //-------------------------------------------- 1478 // file which contains the optimum parameter values for the supercuts 1479 1480 TString parSCfile = outPath; 1481 parSCfile += "parSC"; 1482 1483 gLog << "parSCfile = " << parSCfile << endl; 1484 1485 1486 //--------------------------------------------------------------------- 1487 // optimize supercuts using the training sample 1488 // and test them using the test sample 1489 1490 if (WParSC) 1491 { 1492 MCT1FindSupercuts findsuper; 1493 findsuper.SetFilenameParam(parSCfile); 1494 findsuper.SetHadronnessName("HadSC"); 1495 1496 1497 //-------------------------- 1498 // create matrices 1499 if (!RMatrix) 1500 { 1501 MH3 &mh3 = *(new MH3("MHillas.fSize")); 1502 mh3.SetName("Target distribution for SIZE"); 1503 1504 if (filenameTrain == filenameTest) 1505 { 1506 findsuper.DefineTrainTestMatrix(filenameTrain, 1507 howManyTrain, mh3, 1508 howManyTest, mh3); 1509 } 1510 else 1511 { 1512 findsuper.DefineTrainMatrix(filenameTrain, howManyTrain, mh3); 1513 findsuper.DefineTestMatrix( filenameTest, howManyTest, mh3); 1514 } 1515 1516 // writing doesn't work ??? 1517 //findsuper.WriteMatrix(fileMatrixTrain, fileMatrixTest); 1518 } 1519 1520 //-------------------------- 1521 // read matrices from files 1522 // NOT YET TESTED 1523 //if (RMatrix) 1524 // findsuper.ReadMatrix(fileMatrixTrain, fileMatrixTest); 1525 //-------------------------- 1526 1527 1528 //-------------------------- 1529 // optimize the supercuts 1530 Bool_t rf = findsuper.FindParams(); 1531 1532 if (!rf) 1533 { 1534 *fLog << "CT1Analysis.C : optimization of supercuts failed" << endl; 1535 return; 1536 } 1537 1538 //-------------------------------------- 1539 // test the supercuts on the test sample 1540 // 1541 Bool_t rt = findsuper.TestParams(); 1542 } 1543 1544 1545 //----------------------------------------------------------------- 1546 // Update the input files with the SC hadronness 1547 // 1548 1549 1550 gLog << "" << endl; 1551 gLog << "========================================================" << endl; 1552 gLog << "Update input file '" << filenameData 1553 << "' with the SC hadronness" << endl; 1554 1555 1556 //---------------------------------------------------- 1557 // read in optimum parameter values for the supercuts 1558 1559 TFile inparam(parSCfile); 1560 MCT1Supercuts scin; 1561 scin.Read("MCT1Supercuts"); 1562 inparam.Close(); 1563 1564 gLog << "Optimum parameter values for supercuts were read in from file '" 1565 << parSCfile << "'" << endl; 1566 1567 TArrayD supercutsPar(72); 1568 scin.GetParams(72, supercutsPar); 1569 1570 gLog << "Optimum parameter values for supercuts : " << endl; 1571 for (Int_t i=0; i<72; i++) 1572 { 1573 gLog << supercutsPar[i] << ", "; 1574 } 1575 gLog << endl; 1576 1577 1578 //---------------------------------------------------- 1579 MTaskList tliston; 1580 MParList pliston; 1581 1582 // set the parameters of the supercuts 1583 MCT1Supercuts supercuts; 1584 supercuts.SetParams(72, supercutsPar); 1585 gLog << "parameter values for the supercuts used for updating the input file ' " 1586 << filenameData << "'" << endl; 1587 supercuts.GetParams(72, supercutsPar); 1588 for (Int_t i=0; i<72; i++) 1589 { 1590 gLog << supercutsPar[i] << ", "; 1591 } 1592 gLog << endl; 1593 1594 1595 // geometry is needed in MHHillas... classes 1596 MGeomCam *fGeom = 1597 (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam"); 1598 1599 //------------------------------------------- 1600 // create the tasks which should be executed 1601 // 1602 1603 MReadMarsFile read("Events", filenameData); 1604 read.DisableAutoScheme(); 1605 1606 TString fHilName = "MHillas"; 1607 TString fHilNameExt = "MHillasExt"; 1608 TString fHilNameSrc = "MHillasSrc"; 1609 TString fImgParName = "MNewImagePar"; 1610 1611 1612 //....................................................................... 1613 // calculation of hadroness for the supercuts 1614 // (=0.25 if fullfilled, =0.75 otherwise) 1615 1616 TString hadSCName = "HadSC"; 1617 MCT1SupercutsCalc sccalc(fHilName, fHilNameSrc); 1618 sccalc.SetHadronnessName(hadSCName); 1619 1620 1621 //....................................................................... 1622 1623 1624 if (WSC) 1625 { 1626 //MWriteRootFile write(outNameImage, "UPDATE"); 1627 MWriteRootFile write = new MWriteRootFile(outNameImage, "RECREATE"); 1628 1629 write.AddContainer("MRawRunHeader", "RunHeaders"); 1630 write.AddContainer("MTime", "Events"); 1631 write.AddContainer("MMcEvt", "Events"); 1632 write.AddContainer("ThetaOrig", "Events"); 1633 write.AddContainer("MSrcPosCam", "Events"); 1634 write.AddContainer("MSigmabar", "Events"); 1635 write.AddContainer("MHillas", "Events"); 1636 write.AddContainer("MHillasExt", "Events"); 1637 write.AddContainer("MHillasSrc", "Events"); 1638 write.AddContainer("MNewImagePar", "Events"); 1639 1640 write.AddContainer("HadNN", "Events"); 1641 write.AddContainer("HadSC", "Events"); 1642 } 1643 1644 1645 //----------------------------------------------------------------- 1646 // geometry is needed in MHHillas... classes 1647 MGeomCam *fGeom = 1648 (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam"); 1649 1650 Float_t maxhadronness = 0.40; 1651 Float_t maxalpha = 20.0; 1652 Float_t maxdist = 10.0; 1653 1654 MFCT1SelFinal selfinalgh(fHilNameSrc); 1655 selfinalgh.SetCuts(maxhadronness, 100.0, maxdist); 1656 selfinalgh.SetHadronnessName(hadSCName); 1657 selfinalgh.SetName("SelFinalgh"); 1658 MContinue contfinalgh(&selfinalgh); 1659 contfinalgh.SetName("ContSelFinalgh"); 1660 1661 MFillH fillhadsc("hadSC[MHHadronness]", hadSCName); 1662 fillhadsc.SetName("HhadSC"); 1663 1664 MFCT1SelFinal selfinal(fHilNameSrc); 1665 selfinal.SetCuts(maxhadronness, maxalpha, maxdist); 1666 selfinal.SetHadronnessName(hadSCName); 1667 selfinal.SetName("SelFinal"); 1668 MContinue contfinal(&selfinal); 1669 contfinal.SetName("ContSelFinal"); 1670 1671 TString mh3name = "abs(Alpha)"; 1672 MBinning binsalphaabs("Binning"+mh3name); 1673 binsalphaabs.SetEdges(50, -2.0, 98.0); 1674 1675 MH3 alphaabs("abs(MHillasSrc.fAlpha)"); 1676 alphaabs.SetName(mh3name); 1677 MFillH alpha(&alphaabs); 1678 alpha.SetName("FillAlphaAbs"); 1679 1680 MFillH hfill1("MHHillas", fHilName); 1681 hfill1.SetName("HHillas"); 1682 1683 MFillH hfill2("MHStarMap", fHilName); 1684 hfill2.SetName("HStarMap"); 1685 1686 MFillH hfill3("MHHillasExt", fHilNameSrc); 1687 hfill3.SetName("HHillasExt"); 1688 1689 MFillH hfill4("MHHillasSrc", fHilNameSrc); 1690 hfill4.SetName("HHillasSrc"); 1691 1692 MFillH hfill5("MHNewImagePar", fImgParName); 1693 hfill5.SetName("HNewImagePar"); 1694 1695 //***************************** 1696 // entries in MParList 1697 1698 pliston.AddToList(&tliston); 1699 InitBinnings(&pliston); 1700 pliston.AddToList(&binsalphaabs); 1701 pliston.AddToList(&alphaabs); 1702 pliston.AddToList(&supercuts); 1703 1704 //***************************** 1705 // entries in MTaskList 1706 1707 tliston.AddToList(&read); 1708 1709 tliston.AddToList(&sccalc); 1710 tliston.AddToList(&fillhadsc); 1711 tliston.AddToList(&contfinalgh); 1712 1713 tliston.AddToList(&alpha); 1714 tliston.AddToList(&hfill1); 1715 tliston.AddToList(&hfill2); 1716 tliston.AddToList(&hfill3); 1717 tliston.AddToList(&hfill4); 1718 tliston.AddToList(&hfill5); 1719 1720 if (WSC) 1721 tliston.AddToList(&write); 1722 1723 tliston.AddToList(&contfinal); 1724 1725 //***************************** 1726 1727 //------------------------------------------- 1728 // Execute event loop 1729 // 1730 MProgressBar bar; 1731 MEvtLoop evtloop; 1732 evtloop.SetParList(&pliston); 1733 evtloop.SetProgressBar(&bar); 1734 1735 Int_t maxevents = -1; 1736 if ( !evtloop.Eventloop(maxevents) ) 1737 return; 1738 1739 tliston.PrintStatistics(0, kTRUE); 1740 1741 1742 //------------------------------------------- 1743 // Display the histograms 1744 // 1745 pliston.FindObject("hadSC", "MHHadronness")->DrawClone(); 1746 1747 pliston.FindObject("MHHillas")->DrawClone(); 1748 pliston.FindObject("MHHillasExt")->DrawClone(); 1749 pliston.FindObject("MHHillasSrc")->DrawClone(); 1750 pliston.FindObject("MHNewImagePar")->DrawClone(); 1751 pliston.FindObject("MHStarMap")->DrawClone(); 1752 1753 //------------------------------------------- 1754 // fit alpha distribution to get the number of excess events and 1755 // calculate significance of gamma signal in the alpha plot 1756 1757 MH3* absalpha = (MH3*)(pliston.FindObject(mh3name, "MH3")); 1758 TH1 &alphaHist = absalpha->GetHist(); 1759 alphaHist.SetXTitle("|alpha| [\\circ]"); 1760 1761 Double_t alphasig = 13.1; 1762 Double_t alphamin = 30.0; 1763 Double_t alphamax = 90.0; 1764 Int_t degree = 4; 1765 Double_t significance = -99.0; 1766 Bool_t drawpoly = kTRUE; 1767 Bool_t fitgauss = kTRUE; 1768 Bool_t print = kTRUE; 1769 1770 MHFindSignificance findsig; 1771 findsig.SetRebin(kTRUE); 1772 findsig.SetReduceDegree(kFALSE); 1773 1774 findsig.FindSigma(&alphaHist, alphamin, alphamax, degree, 1775 alphasig, drawpoly, fitgauss, print); 1776 significance = findsig.GetSignificance(); 1777 Float_t alphasi = findsig.GetAlphasi(); 1778 1779 gLog << "For file '" << filenameData << "' : " << endl; 1780 gLog << "Significance of gamma signal after supercuts : " 1781 << significance << " (for |alpha| < " << alphasi << " degrees)" 1782 << endl; 1783 1784 findsig.SigmaVsAlpha(&alphaHist, alphamin, alphamax, degree, print); 1785 1786 //------------------------------------------- 1787 1788 DeleteBinnings(&pliston); 1789 1790 gLog << "Macro CT1Analysis : End of Job B_SC_UP" << endl; 1791 gLog << "=======================================================" << endl; 1792 } 1793 //--------------------------------------------------------------------- 1794 1795 1796 //--------------------------------------------------------------------- 1317 1797 // Job B_RF_UP 1318 1798 //============ … … 2336 2816 2337 2817 MHOnSubtraction onsub; 2338 onsub.Calc(alphaHist, &pliston,kTRUE, 13.1);2818 onsub.Calc(alphaHist, kTRUE, 13.1); 2339 2819 //------------------------------------------- 2340 2820 … … 2387 2867 2388 2868 //TString XX("NN"); 2389 //TString XX("SC");2390 TString XX("RF");2869 TString XX("SC"); 2870 //TString XX("RF"); 2391 2871 TString fhadronnessName("Had"); 2392 2872 fhadronnessName += XX; … … 2412 2892 TString energyParName(outPath); 2413 2893 energyParName += "energyest_"; 2414 //energyParName += XX;2894 energyParName += XX; 2415 2895 energyParName += ".root"; 2416 2896 gLog << "energyParName = " << energyParName << endl; … … 2420 2900 TString filenameArea(outPath); 2421 2901 filenameArea += typeMC; 2422 //filenameArea += "_";2423 //filenameArea += XX;2424 2902 filenameArea += ext; 2425 2903 gLog << "filenameArea = " << filenameArea << endl; … … 2429 2907 TString collareaName(outPath); 2430 2908 collareaName += "area_"; 2431 //collareaName += XX;2909 collareaName += XX; 2432 2910 collareaName += ".root"; 2433 2911 gLog << "collareaName = " << collareaName << endl; … … 2437 2915 TString filenameData(outPath); 2438 2916 filenameData += typeData; 2439 //filenameData += "_";2440 //filenameData += XX;2441 2917 filenameData += ext; 2442 2918 gLog << "filenameData = " << filenameData << endl; … … 2446 2922 TString filenameDataout(outPath); 2447 2923 filenameDataout += typeData; 2448 //filenameDataout += "_";2449 //filenameDataout += XX;2924 filenameDataout += "_"; 2925 filenameDataout += XX; 2450 2926 filenameDataout += extout; 2451 2927 gLog << "filenameDataout = " << filenameDataout << endl; … … 2538 3014 f.Close(); 2539 3015 3016 gLog << "Collection area plots written onto file " << collareaName << endl; 2540 3017 2541 3018 gLog << "Calculation of effective collection areas done" << endl; … … 2554 3031 // Optimization of energy estimator 2555 3032 // 3033 gLog << "Macro CT1Analysis.C : calling CT1EEst" << endl; 2556 3034 2557 3035 TString inpath(""); … … 2562 3040 howMany, maxhadronness, maxalpha, maxdist, 2563 3041 binsE, binsTheta); 3042 gLog << "Macro CT1Analysis.C : returning from CT1EEst" << endl; 2564 3043 2565 3044 //----------------------------------------------------------- … … 2622 3101 //....................................................................... 2623 3102 2624 2625 MWriteRootFile write(filenameDataout); 3103 if (WXX) 3104 { 3105 MWriteRootFile &write = *(new MWriteRootFile(filenameDataout)); 2626 3106 2627 3107 write.AddContainer("MRawRunHeader", "RunHeaders"); … … 2641 3121 2642 3122 write.AddContainer("MEnergyEst", "Events"); 2643 3123 } 2644 3124 2645 3125 //----------------------------------------------------------------- … … 2670 3150 eeston.SetCoeffA(parA); 2671 3151 eeston.SetCoeffB(parB); 3152 3153 //--------------------------- 3154 // calculate estimated energy using Daniel's parameters 3155 3156 //MEnergyEstParam eeston(fHilName); 3157 //eeston.Add(fHilNameSrc); 3158 2672 3159 //--------------------------- 2673 3160 … … 2766 3253 //--------------------------------------------------------------------- 2767 3254 3255 3256 //--------------------------------------------------------------------- 3257 // Job F_XX 3258 //========= 3259 3260 // - select g/h separation method XX 3261 // - read MC_XX2.root file 3262 // - calculate eff. collection area 3263 // - read ON_XX2.root file 3264 // - apply final cuts 3265 // - calculate flux 3266 // - write root file for ON data after final cuts (ON_XX3.root)) 3267 3268 3269 if (JobF_XX) 3270 { 3271 gLog << "=====================================================" << endl; 3272 gLog << "Macro CT1Analysis : Start of Job F_XX" << endl; 3273 3274 gLog << "" << endl; 3275 gLog << "Macro CT1Analysis : JobF_XX, WXX = " 3276 << JobF_XX << ", " << WFX << endl; 3277 3278 // type of data to be analysed 3279 TString typeData = "ON"; 3280 //TString typeData = "OFF"; 3281 //TString typeData = "MC"; 3282 gLog << "typeData = " << typeData << endl; 3283 3284 TString typeMC = "MC"; 3285 TString ext = "3.root"; 3286 TString extout = "4.root"; 3287 3288 //------------------------------ 3289 // selection of g/h separation method 3290 // and definition of final selections 3291 3292 //TString XX("NN"); 3293 TString XX("SC"); 3294 //TString XX("RF"); 3295 TString fhadronnessName("Had"); 3296 fhadronnessName += XX; 3297 gLog << "fhadronnessName = " << fhadronnessName << endl; 3298 3299 // maximum values of the hadronness, |ALPHA| and DIST 3300 Float_t maxhadronness = 0.40; 3301 Float_t maxalpha = 20.0; 3302 Float_t maxdist = 10.0; 3303 gLog << "Maximum values of hadronness, |ALPHA| and DIST = " 3304 << maxhadronness << ", " << maxalpha << ", " 3305 << maxdist << endl; 3306 3307 //------------------------------ 3308 // name of MC file to be used for optimizing the energy estimator 3309 TString filenameOpt(outPath); 3310 filenameOpt += typeMC; 3311 filenameOpt += ext; 3312 gLog << "filenameOpt = " << filenameOpt << endl; 3313 3314 //------------------------------ 3315 // name of file containing the parameters of the energy estimator 3316 TString energyParName(outPath); 3317 energyParName += "energyest_"; 3318 energyParName += XX; 3319 energyParName += ".root"; 3320 gLog << "energyParName = " << energyParName << endl; 3321 3322 //------------------------------ 3323 // name of MC file to be used for calculating the eff. collection areas 3324 TString filenameArea(outPath); 3325 filenameArea += typeMC; 3326 filenameArea += ext; 3327 gLog << "filenameArea = " << filenameArea << endl; 3328 3329 //------------------------------ 3330 // name of file containing the eff. collection areas 3331 TString collareaName(outPath); 3332 collareaName += "area_"; 3333 collareaName += XX; 3334 collareaName += ".root"; 3335 gLog << "collareaName = " << collareaName << endl; 3336 3337 //------------------------------ 3338 // name of data file to be analysed 3339 TString filenameData(outPath); 3340 filenameData += typeData; 3341 filenameData += ext; 3342 gLog << "filenameData = " << filenameData << endl; 3343 3344 //------------------------------ 3345 // name of output data file (after the final cuts) 3346 TString filenameDataout(outPath); 3347 filenameDataout += typeData; 3348 filenameDataout += "_"; 3349 filenameDataout += XX; 3350 filenameDataout += extout; 3351 gLog << "filenameDataout = " << filenameDataout << endl; 3352 3353 //------------------------------ 3354 // name of file containing histograms for flux calculastion 3355 TString filenameResults(outPath); 3356 filenameResults += typeData; 3357 filenameResults += "Results_"; 3358 filenameResults += XX; 3359 filenameResults += extout; 3360 gLog << "filenameResults = " << filenameResults << endl; 3361 3362 3363 //==================================================================== 3364 gLog << "-----------------------------------------------" << endl; 3365 gLog << "Start calculation of effective collection areas" << endl; 3366 MParList parlist; 3367 MTaskList tasklist; 3368 3369 //--------------------------------------- 3370 // Setup the tasks to be executed 3371 // 3372 MReadMarsFile reader("Events", filenameArea); 3373 reader.DisableAutoScheme(); 3374 3375 MFCT1SelFinal cuthadrons; 3376 cuthadrons.SetHadronnessName(fhadronnessName); 3377 cuthadrons.SetCuts(maxhadronness, maxalpha, maxdist); 3378 3379 MContinue conthadrons(&cuthadrons); 3380 3381 MHMcCT1CollectionArea collarea; 3382 collarea.SetEaxis(MHMcCT1CollectionArea::kLinear); 3383 3384 MFillH filler("MHMcCT1CollectionArea", "MMcEvt"); 3385 filler.SetName("CollectionArea"); 3386 3387 //******************************** 3388 // entries in MParList 3389 3390 parlist.AddToList(&tasklist); 3391 InitBinnings(&parlist); 3392 parlist.AddToList(&collarea); 3393 3394 //******************************** 3395 // entries in MTaskList 3396 3397 tasklist.AddToList(&reader); 3398 tasklist.AddToList(&conthadrons); 3399 tasklist.AddToList(&filler); 3400 3401 //******************************** 3402 3403 //----------------------------------------- 3404 // Execute event loop 3405 // 3406 MEvtLoop magic; 3407 magic.SetParList(&parlist); 3408 3409 MProgressBar bar; 3410 magic.SetProgressBar(&bar); 3411 if (!magic.Eventloop()) 3412 return; 3413 3414 tasklist.PrintStatistics(0, kTRUE); 3415 3416 // Calculate effective collection areas 3417 // and display the histograms 3418 // 3419 //MHMcCT1CollectionArea *collarea = 3420 // (MHMcCT1CollectionArea*)parlist.FindObject("MHMcCT1CollectionArea"); 3421 collarea.CalcEfficiency(); 3422 collarea.DrawClone(); 3423 3424 // save binnings for call to CT1EEst 3425 MBinning *binsE = (MBinning*)parlist.FindObject("BinningE"); 3426 if (!binsE) 3427 { 3428 gLog << "Object 'BinningE' not found in MParList" << endl; 3429 return; 3430 } 3431 MBinning *binsTheta = (MBinning*)parlist.FindObject("BinningTheta"); 3432 if (!binsTheta) 3433 { 3434 gLog << "Object 'BinningTheta' not found in MParList" << endl; 3435 return; 3436 } 3437 3438 3439 //--------------------------------------------- 3440 // Write histograms to a file 3441 // 3442 3443 TFile f(collareaName, "RECREATE"); 3444 collarea.GetHist()->Write(); 3445 collarea.GetHAll()->Write(); 3446 collarea.GetHSel()->Write(); 3447 f.Close(); 3448 3449 gLog << "Collection area plots written onto file " << collareaName << endl; 3450 3451 gLog << "Calculation of effective collection areas done" << endl; 3452 gLog << "-----------------------------------------------" << endl; 3453 //------------------------------------------------------------------ 3454 3455 3456 TString fHilName = "MHillas"; 3457 TString fHilNameExt = "MHillasExt"; 3458 TString fHilNameSrc = "MHillasSrc"; 3459 TString fImgParName = "MNewImagePar"; 3460 3461 3462 //=========================================================== 3463 // 3464 // Optimization of energy estimator 3465 // 3466 gLog << "Macro CT1Analysis.C : calling CT1EEst" << endl; 3467 3468 TString inpath(""); 3469 TString outpath(""); 3470 Int_t howMany = 2000; 3471 CT1EEst(inpath, filenameOpt, outpath, energyParName, 3472 fHilName, fHilNameSrc, fhadronnessName, 3473 howMany, maxhadronness, maxalpha, maxdist, 3474 binsE, binsTheta); 3475 gLog << "Macro CT1Analysis.C : returning from CT1EEst" << endl; 3476 3477 //----------------------------------------------------------- 3478 // 3479 // Read in parameters of energy estimator ("MMcEnergyEst") 3480 // and migration matrix ("MHMcEnergyMigration") 3481 // 3482 gLog << "================================================================" 3483 << endl; 3484 gLog << "Macro CT1Analysis.C : read parameters of energy estimator and migration matrix from file '" 3485 << energyParName << "'" << endl; 3486 TFile enparam(energyParName); 3487 enparam.ls(); 3488 3489 //MMcEnergyEst mcest("MMcEnergyEst"); 3490 //mcest.Read("MMcEnergyEst"); 3491 MMcEnergyEst &mcest = *((MMcEnergyEst*)gROOT->FindObject("MMcEnergyEst")); 3492 3493 gLog << "Parameters of energy estimator were read in" << endl; 3494 3495 TArrayD parA(mcest.GetNumCoeffA()); 3496 TArrayD parB(mcest.GetNumCoeffB()); 3497 for (Int_t i=0; i<parA.GetSize(); i++) 3498 parA[i] = mcest.GetCoeff(i); 3499 for (Int_t i=0; i<parB.GetSize(); i++) 3500 parB[i] = mcest.GetCoeff( i+parA.GetSize() ); 3501 3502 gLog << "Read in Migration matrix" << endl; 3503 3504 //MHMcEnergyMigration mighiston("MHMcEnergyMigration"); 3505 //mighiston.Read("MHMcEnergyMigration"); 3506 MHMcEnergyMigration &mighiston = 3507 *((MHMcEnergyMigration*)gROOT->FindObject("MHMcEnergyMigration")); 3508 3509 gLog << "Migration matrix was read in" << endl; 3510 3511 //************************************************************************* 3512 // 3513 // Analyse the data 3514 // 3515 gLog << "============================================================" 3516 << endl; 3517 gLog << "Analyse the data" << endl; 3518 3519 MTaskList tliston; 3520 MParList pliston; 3521 3522 // geometry is needed in MHHillas... classes 3523 MGeomCam *fGeom = 3524 (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam"); 3525 3526 3527 //------------------------------------------- 3528 // create the tasks which should be executed 3529 // 3530 3531 MReadMarsFile read("Events", filenameData); 3532 read.DisableAutoScheme(); 3533 3534 //....................................................................... 3535 3536 if (WFX) 3537 { 3538 MWriteRootFile &write = *(new MWriteRootFile(filenameDataout)); 3539 3540 write.AddContainer("MRawRunHeader", "RunHeaders"); 3541 write.AddContainer("MTime", "Events"); 3542 write.AddContainer("MMcEvt", "Events"); 3543 write.AddContainer("ThetaOrig", "Events"); 3544 write.AddContainer("MSrcPosCam", "Events"); 3545 write.AddContainer("MSigmabar", "Events"); 3546 write.AddContainer("MHillas", "Events"); 3547 write.AddContainer("MHillasExt", "Events"); 3548 write.AddContainer("MHillasSrc", "Events"); 3549 write.AddContainer("MNewImagePar", "Events"); 3550 3551 write.AddContainer("HadNN", "Events"); 3552 write.AddContainer("HadSC", "Events"); 3553 write.AddContainer("HadRF", "Events"); 3554 3555 write.AddContainer("MEnergyEst", "Events"); 3556 } 3557 3558 //----------------------------------------------------------------- 3559 // geometry is needed in MHHillas... classes 3560 MGeomCam *fGeom = 3561 (MGeomCam*)pliston->FindCreateObj("MGeomCamCT1", "MGeomCam"); 3562 3563 MFCT1SelFinal selfinalgh(fHilNameSrc); 3564 selfinalgh.SetCuts(maxhadronness, 100.0, maxdist); 3565 selfinalgh.SetHadronnessName(fhadronnessName); 3566 selfinalgh.SetName("SelFinalgh"); 3567 MContinue contfinalgh(&selfinalgh); 3568 contfinalgh.SetName("ContSelFinalgh"); 3569 3570 MFillH fillhadnn("hadNN[MHHadronness]", "HadNN"); 3571 fillhadnn.SetName("HhadNN"); 3572 MFillH fillhadsc("hadSC[MHHadronness]", "HadSC"); 3573 fillhadsc.SetName("HhadSC"); 3574 MFillH fillhadrf("hadRF[MHHadronness]", "HadRF"); 3575 fillhadrf.SetName("HhadRF"); 3576 3577 //--------------------------- 3578 // calculate estimated energy 3579 3580 //MEnergyEstParam eeston(fHilName); 3581 //eeston.Add(fHilNameSrc); 3582 3583 //eeston.SetCoeffA(parA); 3584 //eeston.SetCoeffB(parB); 3585 3586 //--------------------------- 3587 // calculate estimated energy using Daniel's parameters 3588 3589 MEnergyEstParamDanielMkn421 eeston(fHilName); 3590 eeston.Add(fHilNameSrc); 3591 //eeston.SetCoeffA(parA); 3592 //eeston.SetCoeffB(parB); 3593 3594 3595 //--------------------------- 3596 3597 3598 MFillH hfill1("MHHillas", fHilName); 3599 hfill1.SetName("HHillas"); 3600 3601 MFillH hfill2("MHStarMap", fHilName); 3602 hfill2.SetName("HStarMap"); 3603 3604 MFillH hfill3("MHHillasExt", fHilNameSrc); 3605 hfill3.SetName("HHillasExt"); 3606 3607 MFillH hfill4("MHHillasSrc", fHilNameSrc); 3608 hfill4.SetName("HHillasSrc"); 3609 3610 MFillH hfill5("MHNewImagePar", fImgParName); 3611 hfill5.SetName("HNewImagePar"); 3612 3613 //--------------------------- 3614 // new from Robert 3615 3616 MFillH hfill6("MHTimeDiffTheta", "MMcEvt"); 3617 hfill6.SetName("HTimeDiffTheta"); 3618 3619 MFillH hfill6a("MHTimeDiffTime", "MMcEvt"); 3620 hfill6a.SetName("HTimeDiffTime"); 3621 3622 MFillH hfill7("MHAlphaEnergyTheta", fHilNameSrc); 3623 hfill7.SetName("HAlphaEnergyTheta"); 3624 3625 MFillH hfill7a("MHAlphaEnergyTime", fHilNameSrc); 3626 hfill7a.SetName("HAlphaEnergyTime"); 3627 3628 MFillH hfill7b("MHThetabarTime", fHilNameSrc); 3629 hfill7b.SetName("HThetabarTime"); 3630 3631 MFillH hfill7c("MHEnergyTime", "MMcEvt"); 3632 hfill7c.SetName("HEnergyTime"); 3633 3634 3635 //--------------------------- 3636 3637 MFCT1SelFinal selfinal(fHilNameSrc); 3638 selfinal.SetCuts(maxhadronness, maxalpha, maxdist); 3639 selfinal.SetHadronnessName(fhadronnessName); 3640 selfinal.SetName("SelFinal"); 3641 MContinue contfinal(&selfinal); 3642 contfinal.SetName("ContSelFinal"); 3643 3644 3645 //***************************** 3646 // entries in MParList 3647 3648 pliston.AddToList(&tliston); 3649 InitBinnings(&pliston); 3650 3651 3652 //***************************** 3653 // entries in MTaskList 3654 3655 tliston.AddToList(&read); 3656 3657 // robert 3658 tliston.AddToList(&hfill6); //timediff 3659 tliston.AddToList(&hfill6a); //timediff 3660 3661 tliston.AddToList(&contfinalgh); 3662 tliston.AddToList(&eeston); 3663 3664 if (WFX) 3665 tliston.AddToList(&write); 3666 3667 tliston.AddToList(&fillhadnn); 3668 tliston.AddToList(&fillhadsc); 3669 tliston.AddToList(&fillhadrf); 3670 3671 tliston.AddToList(&hfill1); 3672 tliston.AddToList(&hfill2); 3673 tliston.AddToList(&hfill3); 3674 tliston.AddToList(&hfill4); 3675 tliston.AddToList(&hfill5); 3676 3677 //robert 3678 tliston.AddToList(&hfill7); 3679 tliston.AddToList(&hfill7a); 3680 tliston.AddToList(&hfill7b); 3681 tliston.AddToList(&hfill7c); 3682 3683 tliston.AddToList(&contfinal); 3684 3685 //***************************** 3686 3687 //------------------------------------------- 3688 // Execute event loop 3689 // 3690 MProgressBar bar; 3691 MEvtLoop evtloop; 3692 evtloop.SetParList(&pliston); 3693 evtloop.SetProgressBar(&bar); 3694 3695 Int_t maxevents = -1; 3696 //Int_t maxevents = 10000; 3697 if ( !evtloop.Eventloop(maxevents) ) 3698 return; 3699 3700 tliston.PrintStatistics(0, kTRUE); 3701 3702 3703 //------------------------------------------- 3704 // Display the histograms 3705 // 3706 3707 pliston.FindObject("hadNN", "MHHadronness")->DrawClone(); 3708 pliston.FindObject("hadRF", "MHHadronness")->DrawClone(); 3709 pliston.FindObject("hadSC", "MHHadronness")->DrawClone(); 3710 3711 pliston.FindObject("MHHillas")->DrawClone(); 3712 pliston.FindObject("MHHillasExt")->DrawClone(); 3713 pliston.FindObject("MHHillasSrc")->DrawClone(); 3714 pliston.FindObject("MHNewImagePar")->DrawClone(); 3715 pliston.FindObject("MHStarMap")->DrawClone(); 3716 3717 DeleteBinnings(&pliston); 3718 3719 3720 //rwagner write all relevant histograms onto a file 3721 3722 gLog << "=======================================================" << endl; 3723 gLog << "Write results onto file '" << filenameResults << "'" << endl; 3724 3725 TFile outfile(filenameResults,"recreate"); 3726 3727 MHHillasSrc* hillasSrc = 3728 (MHHillasSrc*)(pliston->FindObject("MHHillasSrc")); 3729 TH1F* alphaHist = (TH1F*)(hillasSrc->GetHistAlpha()); 3730 alphaHist->Write(); 3731 3732 MHAlphaEnergyTheta* aetH = 3733 (MHAlphaEnergyTheta*)(pliston->FindObject("MHAlphaEnergyTheta")); 3734 TH3D* aetHist = (TH3D*)(aetH->GetHist()); 3735 aetHist->SetName("aetHist"); 3736 aetHist->Write(); 3737 3738 MHAlphaEnergyTime* aetH2 = 3739 (MHAlphaEnergyTime*)(pliston->FindObject("MHAlphaEnergyTime")); 3740 TH3D* aetHist2 = (TH3D*)(aetH2->GetHist()); 3741 aetHist2->SetName("aetimeHist"); 3742 // aetHist2->DrawClone(); 3743 aetHist2->Write(); 3744 3745 MHThetabarTime* tbt = 3746 (MHThetabarTime*)(pliston->FindObject("MHThetabarTime")); 3747 TProfile* tbtHist = (TProfile*)(tbt->GetHist()); 3748 tbtHist->SetName("tbtHist"); 3749 tbtHist->Write(); 3750 3751 MHEnergyTime* ent = 3752 (MHEnergyTime*)(pliston->FindObject("MHEnergyTime")); 3753 TH2D* entHist = (TH2D*)(ent->GetHist()); 3754 entHist->SetName("entHist"); 3755 entHist->Write(); 3756 3757 MHTimeDiffTheta *time = (MHTimeDiffTheta*)pliston.FindObject("MHTimeDiffTheta"); 3758 TH2D* timeHist = (TH2D*)(time->GetHist()); 3759 timeHist->SetName("MHTimeDiffTheta"); 3760 timeHist->SetTitle("Time diffs"); 3761 timeHist->Write(); 3762 3763 MHTimeDiffTime *time2 = (MHTimeDiffTime*)pliston.FindObject("MHTimeDiffTime"); 3764 TH2D* timeHist2 = (TH2D*)(time2->GetHist()); 3765 timeHist2->SetName("MHTimeDiffTime"); 3766 timeHist2->SetTitle("Time diffs"); 3767 timeHist2->Write(); 3768 3769 //rwagner write also collareas to same file 3770 collarea->GetHist()->Write(); 3771 collarea->GetHAll()->Write(); 3772 collarea->GetHSel()->Write(); 3773 3774 //rwagner todo: write alpha_cut, type of g/h sep (RF, SC, NN), type of data 3775 //rwagner (ON/OFF/MC), MJDmin, MJDmax to this file 3776 3777 outfile.Close(); 3778 3779 gLog << "=======================================================" << endl; 3780 3781 3782 gLog << "Macro CT1Analysis : End of Job F_XX" << endl; 3783 gLog << "=======================================================" << endl; 3784 } 3785 //--------------------------------------------------------------------- 3786 2768 3787 } 2769 3788 … … 2781 3800 2782 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814
Note:
See TracChangeset
for help on using the changeset viewer.