|
12 | 12 | #include <algorithm> |
13 | 13 | #include <iostream> |
14 | 14 |
|
| 15 | +#include <boost/program_options.hpp> |
| 16 | +#include <boost/property_tree/json_parser.hpp> |
| 17 | +#include <boost/property_tree/ptree_fwd.hpp> |
| 18 | + |
15 | 19 | // For now include all TGeo headers here |
16 | 20 | #include <TROOT.h> |
17 | 21 | #include <TInterpreter.h> |
|
35 | 39 | #include <TGeoEltu.h> |
36 | 40 | #include <TGeoHype.h> |
37 | 41 | #include <TGeoArb8.h> |
38 | | - |
39 | | -#include "TParticle.h" |
| 42 | +#include <TStopwatch.h> |
40 | 43 |
|
41 | 44 | #include "MCReplay/MCReplayEngine.h" |
42 | 45 |
|
@@ -739,11 +742,19 @@ int MCReplayEngine::getMediumId(int volId) const |
739 | 742 |
|
740 | 743 | Bool_t MCReplayEngine::SetProcess(const char* flagName, Int_t flagValue) |
741 | 744 | { |
| 745 | + if (mUpdateProcessesCutsBlocked) { |
| 746 | + ::Info("MCReplayEngine::Gstpar", "Parameter setting closed, nothing is changed."); |
| 747 | + return false; |
| 748 | + } |
742 | 749 | return insertProcessOrCut(mProcessesGlobal, physics::namesCuts, flagName, flagValue); |
743 | 750 | } |
744 | 751 |
|
745 | 752 | Bool_t MCReplayEngine::SetCut(const char* cutName, Double_t cutValue) |
746 | 753 | { |
| 754 | + if (mUpdateProcessesCutsBlocked) { |
| 755 | + ::Info("MCReplayEngine::Gstpar", "Parameter setting closed, nothing is changed."); |
| 756 | + return false; |
| 757 | + } |
747 | 758 | return insertProcessOrCut(mCutsGlobal, physics::namesCuts, cutName, cutValue); |
748 | 759 | } |
749 | 760 |
|
@@ -842,8 +853,46 @@ void MCReplayEngine::Gdtom(Float_t* xd, Float_t* xm, Int_t iflag) |
842 | 853 | } |
843 | 854 | } |
844 | 855 |
|
| 856 | +void MCReplayEngine::cutsFromConfig(std::string const& path) |
| 857 | +{ |
| 858 | + if (mUpdateProcessesCutsBlocked) { |
| 859 | + ::Info("MCReplayEngine::paramsFromConfig", "Parameter setting closed, nothing is changed."); |
| 860 | + return; |
| 861 | + } |
| 862 | + |
| 863 | + ::Info("MCReplayEngine::paramsFromConfig", "Read Params from %s", path.c_str()); |
| 864 | + if (path.empty()) { |
| 865 | + return; |
| 866 | + } |
| 867 | + boost::property_tree::ptree pt; |
| 868 | + boost::property_tree::json_parser::read_json(path, pt); |
| 869 | + |
| 870 | + for (auto& it : pt) { |
| 871 | + auto mediumID = std::stoi(it.first); |
| 872 | + int i = 0; |
| 873 | + for (auto& v : it.second) { |
| 874 | + auto value = v.second.get_value<double>(); |
| 875 | + if (value < 0.) { |
| 876 | + continue; |
| 877 | + } |
| 878 | + // TODO Going back and forth between parameter name and index. Implement so that we use the index directly |
| 879 | + auto param = physics::indexToParam(physics::namesCuts, i); |
| 880 | + if (mediumID < 0) { |
| 881 | + insertProcessOrCut(mCutsGlobal, physics::namesCuts, i, value); |
| 882 | + } else { |
| 883 | + insertProcessOrCut(mCuts, physics::namesCuts, mCutsGlobal, mediumID, i, value); |
| 884 | + } |
| 885 | + i++; |
| 886 | + } |
| 887 | + } |
| 888 | +} |
| 889 | + |
845 | 890 | void MCReplayEngine::Gstpar(Int_t itmed, const char* param, Double_t parval) |
846 | 891 | { |
| 892 | + if (mUpdateProcessesCutsBlocked) { |
| 893 | + ::Info("MCReplayEngine::Gstpar", "Parameter setting closed, nothing is changed."); |
| 894 | + return; |
| 895 | + } |
847 | 896 | if (insertProcessOrCut(mProcesses, physics::namesProcesses, mProcessesGlobal, itmed, param, (int)parval)) { |
848 | 897 | return; |
849 | 898 | } |
@@ -878,6 +927,24 @@ bool MCReplayEngine::keepDueToCuts(const o2::StepInfo& step) const |
878 | 927 | // check global energy cut |
879 | 928 | return false; |
880 | 929 | } |
| 930 | + auto pdg = mCurrentLookups->tracktopdg[step.trackID]; |
| 931 | + if ((*mCurrentCuts)[0] > 0. && physics::isPhoton(pdg) && step.E < (*mCurrentCuts)[0]) { |
| 932 | + return false; |
| 933 | + } |
| 934 | + if ((*mCurrentCuts)[1] > 0. && physics::isElectronPositron(pdg) && step.E < (*mCurrentCuts)[1]) { |
| 935 | + return false; |
| 936 | + } |
| 937 | + if (physics::isHadron(pdg)) { |
| 938 | + if (mCurrentLookups->tracktocharge[step.trackID] && (*mCurrentCuts)[3] > 0. && step.E < (*mCurrentCuts)[3]) { |
| 939 | + return false; |
| 940 | + } |
| 941 | + if ((*mCurrentCuts)[2] > 0. && step.E < (*mCurrentCuts)[2]) { |
| 942 | + return false; |
| 943 | + } |
| 944 | + } |
| 945 | + if ((*mCurrentCuts)[4] > 0. && physics::isMuonAntiMuon(pdg) && step.E < (*mCurrentCuts)[4]) { |
| 946 | + return false; |
| 947 | + } |
881 | 948 | return true; |
882 | 949 | } |
883 | 950 |
|
@@ -959,6 +1026,8 @@ void MCReplayEngine::ProcessEvent(Int_t eventId) |
959 | 1026 | unsigned int nUserTracks{0}; |
960 | 1027 | unsigned int nStopTrack{0}; |
961 | 1028 |
|
| 1029 | + TStopwatch stopwatch{}; |
| 1030 | + |
962 | 1031 | for (auto& step : *steps) { |
963 | 1032 |
|
964 | 1033 | // TODO This should not happen. (see comment in header file for these flags) |
@@ -1068,10 +1137,13 @@ void MCReplayEngine::ProcessEvent(Int_t eventId) |
1068 | 1137 |
|
1069 | 1138 | fApplication->FinishEvent(); |
1070 | 1139 |
|
| 1140 | + stopwatch.Stop(); |
| 1141 | + |
1071 | 1142 | auto nStepsSkipped = steps->size() - nStepsKept; |
1072 | 1143 | std::cout << "Original number, skipped, kept, skipped fraction and kept fraction of steps: " << steps->size() << " " << nStepsSkipped << " " << nStepsKept << " " << static_cast<float>(nStepsSkipped) / steps->size() << " " << static_cast<float>(nStepsKept) / steps->size() << "\n"; |
1073 | 1144 | std::cout << "In addition, " << nUserTracks << " tracks produced during hit creation were ignored\n"; |
1074 | 1145 | std::cout << "TVirtualMC::StopTrack was ignored " << nStopTrack << " times\n"; |
| 1146 | + std::cout << "Real time: " << stopwatch.RealTime() << ", CPU time: " << stopwatch.CpuTime() << "\n"; |
1075 | 1147 |
|
1076 | 1148 | delete steps; |
1077 | 1149 | delete mCurrentLookups; |
|
0 commit comments