- Timestamp:
- 12/15/19 15:32:25 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/spectrum.cc
r19900 r19903 147 147 ; 148 148 149 po::options_description queries(" Queries");149 po::options_description queries("Analysis Query"); 150 150 queries.add_options() 151 151 ("analysis", var<string>("analysis.sql"), "File with the analysis query. A default file is created automatically in the <prefix> directory it does not exist.") … … 172 172 ("print-queries", po_bool(), "Print all queries to the console. (For highlighting recompile with 'libsource-highlight-dev' installed)") 173 173 #endif 174 ("mc-only", po_bool(), "Do not run a n data realated queries (except observation times)")174 ("mc-only", po_bool(), "Do not run a data related queries (except observation times)") 175 175 ("verbose,v", var<uint16_t>(1), "Verbosity (0: quiet, 1: default, 2: more, 3, ...)") 176 176 ; … … 342 342 } 343 343 344 void CreateBinning(Database &connection, ostream &qlog, const Binning &bins, const string &name )344 void CreateBinning(Database &connection, ostream &qlog, const Binning &bins, const string &name, const string &comment) 345 345 { 346 346 mysqlpp::Query query0(&connection); … … 348 348 "CREATE TEMPORARY TABLE Binning" << name << "\n" 349 349 "(\n" 350 " bin SMALLINT UNSIGNED NOT NULL,\n"351 " lo DOUBLE NOT NULL,\n"352 " hi DOUBLE NOT NULL,\n"350 " bin INT NOT NULL COMMENT 'Bin index (" << name << ")',\n" 351 " lo DOUBLE NOT NULL COMMENT 'Lower bin edge (" << name << ")',\n" 352 " hi DOUBLE NOT NULL COMMENT 'Upper bin edge (" << name << ")',\n" 353 353 " PRIMARY KEY (bin) USING HASH\n" 354 ") ";354 ") COMMENT='" << comment << "'"; 355 355 356 356 qlog << query0 << ";\n" << endl; … … 747 747 cout << separator("Binnings") << '\n'; 748 748 749 CreateBinning(connection, qlog, binning_theta, "Theta" );750 CreateBinning(connection, qlog, binning_dense, "Energy_dense" );751 CreateBinning(connection, qlog, binning_sparse, "Energy_sparse" );749 CreateBinning(connection, qlog, binning_theta, "Theta", "Binning in zenith angle"); 750 CreateBinning(connection, qlog, binning_dense, "Energy_dense", "Dense binning in log10 Energy"); 751 CreateBinning(connection, qlog, binning_sparse, "Energy_sparse", "Sparse binning in log10 Energy"); 752 752 753 753 Dump(flog, connection, "BinningTheta"); … … 768 768 "CREATE TEMPORARY TABLE DataFiles\n" 769 769 "(\n" 770 " FileId INT UNSIGNED NOT NULL,\n"770 // " FileId INT UNSIGNED NOT NULL,\n" 771 771 " PRIMARY KEY (FileId) USING HASH\n" 772 772 ") ENGINE=MEMORY\n" … … 815 815 Time start2; 816 816 817 / * 02:get-observation-time.sql */817 // For some reason, the comments do not appear in the "EXPLAIN CREATE TABLE" query 818 818 mysqlpp::Query query2(&connection); 819 819 query2 << 820 820 "CREATE TEMPORARY TABLE ObservationTime\n" 821 821 "(\n" 822 " `.theta` SMALLINT UNSIGNED NOT NULL,\n"823 " OnTime DOUBLE NOT NULL,\n" 822 //" `.theta` INT COMMENT 'Zenith Angle bin index',\n" 823 " OnTime DOUBLE NOT NULL,\n"// COMMENT 'Effective on time in seconds per bin',\n" 824 824 " PRIMARY KEY (`.theta`) USING HASH\n" 825 ") ENGINE=MEMORY \n"825 ") ENGINE=MEMORY COMMENT='Effective on time of selected data files binning in zenith angle'\n" 826 826 "AS\n" 827 827 "(\n" … … 871 871 "CREATE TEMPORARY TABLE MonteCarloFiles\n" 872 872 "(\n" 873 " FileId INT UNSIGNED NOT NULL,\n"873 // " FileId INT UNSIGNED NOT NULL,\n" 874 874 " PRIMARY KEY (FileId) USING HASH\n" 875 ") ENGINE=MEMORY \n"875 ") ENGINE=MEMORY COMMENT='Monte Carlo files selected by data Zenith Angle range'\n" 876 876 "AS\n" 877 877 "(\n" … … 921 921 mysqlpp::Query query4(&connection); 922 922 query4 << 923 "CREATE TEMPORARY TABLE MonteCarloArea ENGINE=MEMORY \n"923 "CREATE TEMPORARY TABLE MonteCarloArea ENGINE=MEMORY COMMENT='Minimum and maximum impact radius of selected Monte Carlo files'" 924 924 "AS\n" 925 925 "(\n" … … 975 975 "CREATE TEMPORARY TABLE Summary%100:table\n" 976 976 "(\n" 977 " `.theta` SMALLINT UNSIGNED NOT NULL,\n"978 " `.sparse_sim` SMALLINT UNSIGNED NOT NULL,\n"979 " `.dense_sim` SMALLINT UNSIGNED NOT NULL,\n"980 " CountN DOUBLE NOT NULL,\n"981 " SumW DOUBLE NOT NULL,\n" 982 " SumW2 DOUBLE NOT NULL,\n" 977 // " `.theta` SMALLINT UNSIGNED NOT NULL COMMENT 'Zenith Angle bin index',\n" 978 // " `.sparse_sim` SMALLINT UNSIGNED NOT NULL COMMENT 'Energy bin index (sparse binning)',\n" 979 // " `.dense_sim` SMALLINT UNSIGNED NOT NULL COMMENT 'Energy bin index (dense binning)',\n" 980 " CountN INT UNSIGNED NOT NULL COMMENT 'Event count per bin',\n" 981 " SumW DOUBLE NOT NULL,\n"// COMMENT 'Sum of spectral weights',\n" 982 " SumW2 DOUBLE NOT NULL,\n"// COMMENT 'Sum of squared spectral weights',\n" 983 983 " INDEX (`.theta`) USING HASH,\n" 984 984 " INDEX (`.sparse_sim`) USING HASH,\n" 985 985 " INDEX (`.dense_sim`) USING HASH\n" 986 ") ENGINE=MEMORY \n"986 ") ENGINE=MEMORY COMMENT='Event counts and sums of (squared) spectral weights for selected Monte Carlo data binned in log10 energy'\n" 987 987 "AS\n" 988 988 "(\n" 989 " WITH Table0AS\n"989 " WITH BinnedData AS\n" 990 990 " (\n" 991 991 " SELECT\n" … … 1009 1009 " SUM(POW(SpectralWeight,2)) AS SumW2\n" 1010 1010 " FROM\n" 1011 " Table0\n"1011 " BinnedData\n" 1012 1012 " GROUP BY\n" 1013 1013 " `.theta`, `.sparse_sim`, `.dense_sim`\n" … … 1072 1072 query6 << 1073 1073 "CREATE TEMPORARY TABLE ThetaDist\n" 1074 "ENGINE=MEMORY\n" 1074 "(\n" 1075 " CountN INT UNSIGNED NOT NULL,\n" 1076 " ErrCountN DOUBLE NOT NULL,\n" 1077 " ZdWeight DOUBLE NOT NULL,\n" 1078 " ErrZdWeight DOUBLE NOT NULL,\n" 1079 " INDEX (`.theta`) USING HASH\n" 1080 ") ENGINE=MEMORY COMMENT='Event counts and sums of (squared) spectral weights for selected Monte Carlo data binned in theta'\n" 1075 1081 "AS\n" 1076 1082 "(\n" … … 1180 1186 mysqlpp::Query query7(&connection); 1181 1187 query7 << 1182 "CREATE TEMPORARY TABLE Weighted%100:table (\n" 1183 " `.theta` SMALLINT UNSIGNED NOT NULL,\n" 1184 " `.sparse_sim` SMALLINT UNSIGNED NOT NULL,\n" 1185 " `.dense_sim` SMALLINT UNSIGNED NOT NULL,\n" 1186 " CountN DOUBLE NOT NULL,\n" 1187 " SumW DOUBLE NOT NULL,\n" 1188 " SumW2 DOUBLE NOT NULL,\n" 1189 " INDEX (`.theta`) USING HASH,\n" 1190 " INDEX (`.sparse_sim`) USING HASH,\n" 1191 " INDEX (`.dense_sim`) USING HASH\n" 1188 "CREATE TEMPORARY TABLE Weighted%100:table\n" 1189 "(\n" 1190 " SumW2 DOUBLE NOT NULL,\n" 1191 " INDEX (`.theta`) USING HASH,\n" 1192 " INDEX (`.sparse_sim`) USING HASH,\n" 1193 " INDEX (`.dense_sim`) USING HASH\n" 1192 1194 ")\n" 1193 "ENGINE=MEMORY \n"1195 "ENGINE=MEMORY COMMENT='Table Summary%100:table but with theta-weights applied'\n" 1194 1196 "AS\n" 1195 1197 "(\n" … … 1282 1284 ") ENGINE=Memory\n" 1283 1285 */ 1284 "CREATE TEMPORARY TABLE AnalysisMC ENGINE=MEMORY\n" 1286 "CREATE TEMPORARY TABLE AnalysisMC\n" 1287 "(\n" 1288 " SignalN INT UNSIGNED NOT NULL,\n" 1289 " SignalW DOUBLE NOT NULL,\n" 1290 " SignalW2 DOUBLE NOT NULL,\n" 1291 " BackgroundN INT UNSIGNED NOT NULL,\n" 1292 " BackgroundW DOUBLE NOT NULL,\n" 1293 " BackgroundW2 DOUBLE NOT NULL,\n" 1294 " ResidualW DOUBLE NOT NULL,\n" 1295 " ResidualW2 DOUBLE NOT NULL,\n" 1296 " SumEnergySimW DOUBLE NOT NULL,\n" 1297 " SumEnergyEstW DOUBLE NOT NULL,\n" 1298 " INDEX (`.theta`) USING HASH,\n" 1299 " INDEX (`.sparse_est`) USING HASH,\n" 1300 " INDEX (`.sparse_sim`) USING HASH,\n" 1301 " INDEX (`.dense_est`) USING HASH,\n" 1302 " INDEX (`.dense_sim`) USING HASH,\n" 1303 " INDEX (`.sparse_est`, `.sparse_sim`) USING HASH,\n" 1304 " INDEX (`.dense_est`, `.dense_sim`) USING HASH\n" 1305 ") ENGINE=MEMORY COMMENT='Sum of counts and (squared) weightes of Monte Carlo Data after analysis'\n" 1285 1306 "AS\n" 1286 1307 "(\n" … … 1358 1379 sindent indent9(query9); 1359 1380 query9 << 1360 "CREATE TEMPORARY TABLE %100:table ENGINE=MEMORY " 1381 "CREATE TEMPORARY TABLE %100:table\n" 1382 "(\n" 1383 " SimCountN INT UNSIGNED NOT NULL,\n" 1384 " TrigCountN INT UNSIGNED NOT NULL,\n" 1385 " SignalN INT UNSIGNED NOT NULL,\n" 1386 " BackgroundN DOUBLE NOT NULL,\n" 1387 // 1388 " ErrSimCountN DOUBLE NOT NULL,\n" 1389 " ErrTrigCountN DOUBLE NOT NULL,\n" 1390 " ErrSignalN DOUBLE NOT NULL,\n" 1391 " ErrBackgroundN DOUBLE NOT NULL,\n" 1392 // 1393 " SimSumW DOUBLE NOT NULL,\n" 1394 " TrigSumW DOUBLE NOT NULL,\n" 1395 " SignalW DOUBLE NOT NULL,\n" 1396 " BackgroundW DOUBLE NOT NULL,\n" 1397 " ExcessW DOUBLE NOT NULL,\n" 1398 // 1399 " SimSumW2 DOUBLE NOT NULL,\n" 1400 " TrigSumW2 DOUBLE NOT NULL,\n" 1401 " SignalW2 DOUBLE NOT NULL,\n" 1402 " BackgroundW2 DOUBLE NOT NULL,\n" 1403 " ExcessW2 DOUBLE NOT NULL,\n" 1404 // 1405 " SimFluxW DOUBLE NOT NULL,\n" 1406 " TrigFluxW DOUBLE NOT NULL,\n" 1407 " SignalFluxW DOUBLE NOT NULL,\n" 1408 " BackgroundFluxW DOUBLE NOT NULL,\n" 1409 " ExcessFluxW DOUBLE NOT NULL,\n" 1410 // 1411 " ErrSimFluxW DOUBLE NOT NULL,\n" 1412 " ErrTrigFluxW DOUBLE NOT NULL,\n" 1413 " ErrSignalFluxW DOUBLE NOT NULL,\n" 1414 " ErrBackgroundFluxW DOUBLE NOT NULL,\n" 1415 " ErrExcessFluxW DOUBLE NOT NULL,\n" 1416 // 1417 " ResidualW DOUBLE NOT NULL,\n" 1418 " ResidualW2 DOUBLE NOT NULL,\n" 1419 " BiasW DOUBLE NOT NULL,\n" 1420 " ErrBiasW DOUBLE NOT NULL,\n" 1421 " ResolutionW DOUBLE,\n" 1422 // 1423 " SumEnergyEstW DOUBLE NOT NULL,\n" 1424 " SumEnergySimW DOUBLE NOT NULL,\n" 1425 // 1426 " AvgEnergyEstW DOUBLE NOT NULL,\n" 1427 " AvgEnergySimW DOUBLE NOT NULL,\n" 1428 // 1429 " CutEfficiencyN DOUBLE NOT NULL,\n" 1430 " CutEfficiencyW DOUBLE NOT NULL,\n" 1431 " TriggerEfficiencyN DOUBLE NOT NULL,\n" 1432 " TriggerEfficiencyW DOUBLE NOT NULL,\n" 1433 " EffectiveAreaN DOUBLE NOT NULL,\n" 1434 " EffectiveAreaW DOUBLE NOT NULL,\n" 1435 // 1436 " ErrCutEfficiencyN DOUBLE NOT NULL,\n" 1437 " ErrCutEfficiencyW DOUBLE NOT NULL,\n" 1438 " ErrEffectiveAreaN DOUBLE NOT NULL,\n" 1439 " ErrEffectiveAreaW DOUBLE NOT NULL,\n" 1440 " ErrTriggerEfficiencyN DOUBLE NOT NULL,\n" 1441 " ErrTriggerEfficiencyW DOUBLE NOT NULL,\n" 1442 // 1443 " IntegralSimFluxW DOUBLE NOT NULL,\n" 1444 " IntegralSimFluxW2 DOUBLE NOT NULL,\n" 1445 " IntegralSignalW DOUBLE NOT NULL,\n" 1446 " IntegralSignalFluxW DOUBLE NOT NULL,\n" 1447 " IntegralSignalFluxW2 DOUBLE NOT NULL,\n" 1448 " IntegralBackgroundFluxW DOUBLE NOT NULL,\n" 1449 " IntegralBackgroundFluxW2 DOUBLE NOT NULL,\n" 1450 " IntegralExcessFluxW DOUBLE NOT NULL,\n" 1451 // 1452 " ErrIntegralExcessFluxW DOUBLE NOT NULL,\n" 1453 " ErrIntegralSignalFluxW DOUBLE NOT NULL,\n" 1454 " ErrIntegralBackgroundFluxW DOUBLE NOT NULL,\n" 1455 " ErrIntegralSimFluxW DOUBLE NOT NULL,\n" 1456 // 1457 " IntegralEnergySimW DOUBLE NOT NULL,\n" 1458 " IntegralEnergyEstW DOUBLE NOT NULL,\n" 1459 // 1460 " AvgIntegralEnergyEstW DOUBLE NOT NULL,\n" 1461 " AvgIntegralEnergySimW DOUBLE NOT NULL,\n" 1462 // 1463 " ObsTime DOUBLE NOT NULL,\n" 1464 " Area DOUBLE NOT NULL,\n" 1465 " AreaTime DOUBLE NOT NULL,\n" 1466 " Width DOUBLE NOT NULL,\n" 1467 // 1468 " INDEX (%102:bin) USING HASH\n" 1469 ") ENGINE=MEMORY COMMENT='Summary of all Monte Carlo quantities, binned in true energy or zenith angle'\n" 1361 1470 "AS\n" 1362 1471 "(\n" … … 1530 1639 sindent indent10(query10); 1531 1640 query10 << 1532 "CREATE TEMPORARY TABLE SummaryEstimatedEnergy_%100:binning ENGINE=MEMORY " 1641 "CREATE TEMPORARY TABLE SummaryEstimatedEnergy_%100:binning\n" 1642 "(\n" 1643 " SignalN INT UNSIGNED NOT NULL,\n" 1644 " BackgroundN DOUBLE NOT NULL,\n" 1645 " ExcessN DOUBLE NOT NULL,\n" 1646 // 1647 " ErrSignalN DOUBLE NOT NULL,\n" 1648 " ErrBackgroundN DOUBLE NOT NULL,\n" 1649 " ErrExcessN DOUBLE NOT NULL,\n" 1650 // 1651 " SignalW DOUBLE NOT NULL,\n" 1652 " BackgroundW DOUBLE NOT NULL,\n" 1653 " ExcessW DOUBLE NOT NULL,\n" 1654 // 1655 " SignalW2 DOUBLE NOT NULL,\n" 1656 " BackgroundW2 DOUBLE NOT NULL,\n" 1657 // 1658 " ErrSignalW DOUBLE NOT NULL,\n" 1659 " ErrBackgroundW DOUBLE NOT NULL,\n" 1660 " ErrExcessW DOUBLE NOT NULL,\n" 1661 // 1662 " SignalFluxW DOUBLE NOT NULL,\n" 1663 " BackgroundFluxW DOUBLE NOT NULL,\n" 1664 " ExcessFluxW DOUBLE NOT NULL,\n" 1665 // 1666 " ErrSignalFluxW DOUBLE NOT NULL,\n" 1667 " ErrBackgroundFluxW DOUBLE NOT NULL,\n" 1668 " ErrExcessFluxW DOUBLE NOT NULL,\n" 1669 // 1670 " ResidualW DOUBLE NOT NULL,\n" 1671 " ResidualW2 DOUBLE NOT NULL,\n" 1672 " BiasW DOUBLE NOT NULL,\n" 1673 " ErrBiasW DOUBLE NOT NULL,\n" 1674 " ResolutionW DOUBLE,\n" 1675 // 1676 " SumEnergyEstW DOUBLE NOT NULL,\n" 1677 " SumEnergySimW DOUBLE NOT NULL,\n" 1678 // 1679 " AvgEnergyEstW DOUBLE NOT NULL,\n" 1680 " AvgEnergySimW DOUBLE NOT NULL,\n" 1681 // 1682 " IntegralSignalW DOUBLE NOT NULL,\n" 1683 " IntegralSignalFluxW DOUBLE NOT NULL,\n" 1684 " IntegralSignalFluxW2 DOUBLE NOT NULL,\n" 1685 " IntegralBackgroundFluxW DOUBLE NOT NULL,\n" 1686 " IntegralBackgroundFluxW2 DOUBLE NOT NULL,\n" 1687 " IntegralExcessFluxW DOUBLE NOT NULL,\n" 1688 // 1689 " ErrIntegralExcessFluxW DOUBLE NOT NULL,\n" 1690 " ErrIntegralSignalFluxW DOUBLE NOT NULL,\n" 1691 " ErrIntegralBackgroundFluxW DOUBLE NOT NULL,\n" 1692 // 1693 " IntegralEnergySimW DOUBLE NOT NULL,\n" 1694 " IntegralEnergyEstW DOUBLE NOT NULL,\n" 1695 // 1696 " AvgIntegralEnergyEstW DOUBLE NOT NULL,\n" 1697 " AvgIntegralEnergySimW DOUBLE NOT NULL,\n" 1698 // 1699 " ObsTime DOUBLE NOT NULL,\n" 1700 " Area DOUBLE NOT NULL,\n" 1701 " AreaTime DOUBLE NOT NULL,\n" 1702 " Width DOUBLE NOT NULL,\n" 1703 // 1704 " INDEX (`.%100:binning:_est`) USING HASH\n" 1705 ") ENGINE=MEMORY COMMENT='Summary of all Monte Carlo quantities binned in estimated energy'\n" 1533 1706 "AS\n" 1534 1707 "(\n" … … 1636 1809 mysqlpp::Query query11(&connection); 1637 1810 query11 << 1638 "CREATE TEMPORARY TABLE EnergyMigration_%100:binning ENGINE=MEMORY\n" 1811 "CREATE TEMPORARY TABLE EnergyMigration_%100:binning\n" 1812 "(\n" 1813 " SignalN INT UNSIGNED NOT NULL\n" 1814 ") ENGINE=MEMORY COMMENT='Energy Migration: Monte Carlo Event counts binned in true and estimated energy'\n" 1639 1815 "AS\n" 1640 1816 "(\n" … … 1699 1875 1700 1876 // ------------------------------------------------------------------- 1701 // --------------------------- SummaryData ---------------------------1702 // ------------------------------------------------------------------- 1703 1704 cout << separator(" SummaryData") << '\n';1877 // --------------------------- AnalysisData -------------------------- 1878 // ------------------------------------------------------------------- 1879 1880 cout << separator("AnalysisData") << '\n'; 1705 1881 1706 1882 Time start12; … … 1709 1885 sindent indent12(query12); 1710 1886 query12 << 1711 "CREATE TEMPORARY TABLE SummaryData ENGINE=MEMORY\n" 1712 /* "(\n" 1713 " `.theta` SMALLINT UNSIGNED NOT NULL,\n" 1714 " `.sparse_est` SMALLINT UNSIGNED NOT NULL,\n" 1715 " `Signal` DOUBLE NOT NULL,\n" 1716 " `ErrSignal` DOUBLE NOT NULL,\n" 1717 " `Background` DOUBLE NOT NULL,\n" 1718 " `ErrBackground` DOUBLE NOT NULL,\n" 1719 " `Excess` DOUBLE NOT NULL,\n" 1720 " `ErrExcess` DOUBLE NOT NULL,\n" 1721 " `Significance` DOUBLE NOT NULL,\n" 1722 " PRIMARY KEY (`.sparse_est`) USING HASH\n" 1723 ") ENGINE=Memory\n"*/ 1887 "CREATE TEMPORARY TABLE AnalysisData\n" 1888 "(\n" 1889 " `Signal` INT UNSIGNED NOT NULL,\n" 1890 " `Background` INT UNSIGNED NOT NULL,\n" 1891 " `SumEnergyEst` DOUBLE NOT NULL,\n" 1892 " `SumW` DOUBLE NOT NULL,\n" 1893 " INDEX (`.theta`) USING HASH,\n" 1894 " INDEX (`.sparse_est`) USING HASH\n" 1895 ") ENGINE=MEMORY COMMENT='Sum of counts and (squared) weightes of selected data after analysis'\n" 1724 1896 "AS\n" 1725 1897 "(\n" … … 1758 1930 cout << query12.execute().info() << endl; 1759 1931 ShowWarnings(connection); 1760 Dump(flog, connection, " SummaryData");1932 Dump(flog, connection, "AnalysisData"); 1761 1933 1762 1934 const auto sec12 = Time().UnixTime()-start12.UnixTime(); … … 1777 1949 1778 1950 Time start13; 1779 1780 1951 /* 1781 1952 "CREATE TEMPORARY TABLE Spectrum\n" … … 1817 1988 sindent indent13(query13); 1818 1989 query13 << 1819 "CREATE TEMPORARY TABLE %100:table ENGINE=MEMORY " 1820 "AS\n" 1990 "CREATE TEMPORARY TABLE %100:table ENGINE=MEMORY COMMENT='Combined information from different sources into final spectrum' AS\n" 1821 1991 "(\n" 1822 1992 << indent(3) << spectrum_sql << indent(0) <<
Note:
See TracChangeset
for help on using the changeset viewer.