Skip to content

Commit 8dc1d99

Browse files
Benedikt Volkelbenedikt-voelkel
authored andcommitted
Enable more cuts
* respect CUTGAM, CUTELE, CUTNEU, CUTHAD, CUTMUO * enable loading cut parameters form JSON for more complex setting * small fixes
1 parent 66bb9bb commit 8dc1d99

File tree

6 files changed

+157
-7
lines changed

6 files changed

+157
-7
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ configure_file(
109109
"${PROJECT_BINARY_DIR}/MCStepLoggerConfig.cmake" @ONLY)
110110
install(FILES
111111
"${PROJECT_BINARY_DIR}/MCStepLoggerConfig.cmake"
112-
DESTINATION ${INSTALL_CMAKE_DIR})
112+
DESTINATION ${INSTALL_CMAKE_DIR})

MCReplay/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(SRCS
3333
${CXX_SOURCE_DIR}/MCReplayGenericApplication.cxx
3434
${CXX_SOURCE_DIR}/MCReplayGenericStack.cxx
3535
${CXX_SOURCE_DIR}/MCReplayEvGen.cxx
36+
${CXX_SOURCE_DIR}/MCReplayPhysics.cxx
3637
)
3738
set(HEADERS
3839
${CXX_INCLUDE_DIR}/${MODULE_NAME}/MCReplayEngine.h
@@ -49,9 +50,9 @@ set(EXECUTABLE_SRCS
4950
mcsl_add_library(
5051
TARGETNAME Core
5152
BASENAME ${MODULE_NAME}
52-
DEPENDENCIES ROOT::Core ROOT::Hist ROOT::Graf ROOT::Gpad ROOT::Tree ROOT::VMC ROOT::RIO ROOT::Geom ROOT::EG MCStepLoggerCore MCStepLoggerAnalysis
53+
DEPENDENCIES ROOT::Core ROOT::Hist ROOT::Graf ROOT::Gpad ROOT::Tree ROOT::VMC ROOT::RIO ROOT::Geom ROOT::EG MCStepLoggerCore
5354
SOURCES ${SRCS}
54-
INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/include
55+
INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/include ${Boost_INCLUDE_DIR}
5556
LINKDEFDIR ${CMAKE_CURRENT_LIST_DIR}/src
5657
ROOT_DICTIONARY_HEADERS ${HEADERS})
5758

MCReplay/include/MCReplay/MCReplayEngine.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,13 @@ class MCReplayEngine : public TVirtualMC
11001100
mUserKeepStepMacroPath = path;
11011101
}
11021102

1103+
void blockSetProcessesCuts(bool value = true)
1104+
{
1105+
mUpdateProcessesCutsBlocked = value;
1106+
}
1107+
1108+
void cutsFromConfig(std::string const& path);
1109+
11031110
private:
11041111
// init the run, used to guarantee that both ProcessRun and ProcessEvent
11051112
// work just fine
@@ -1138,6 +1145,13 @@ class MCReplayEngine : public TVirtualMC
11381145
bool insertProcessOrCut(std::vector<std::vector<P>*>& insertInto, const std::array<T, N>& allParamsNames, const std::vector<P>& defaultParams, Int_t mediumId, const char* paramName, P parval)
11391146
{
11401147
auto paramIndex = physics::paramToIndex(allParamsNames, paramName);
1148+
return insertProcessOrCut(insertInto, allParamsNames, defaultParams, mediumId, paramIndex, parval);
1149+
}
1150+
1151+
// add process or cut values based on name and value
1152+
template <typename P, typename T, std::size_t N>
1153+
bool insertProcessOrCut(std::vector<std::vector<P>*>& insertInto, const std::array<T, N>& allParamsNames, const std::vector<P>& defaultParams, Int_t mediumId, int paramIndex, P parval)
1154+
{
11411155
if (paramIndex < 0) {
11421156
return false;
11431157
}
@@ -1158,6 +1172,12 @@ class MCReplayEngine : public TVirtualMC
11581172
bool insertProcessOrCut(std::vector<P>& insertInto, const std::array<T, N>& allParamsNames, const char* paramName, P parval)
11591173
{
11601174
auto paramIndex = physics::paramToIndex(allParamsNames, paramName);
1175+
return insertProcessOrCut(insertInto, allParamsNames, paramIndex, parval);
1176+
}
1177+
1178+
template <typename P, typename T, std::size_t N>
1179+
bool insertProcessOrCut(std::vector<P>& insertInto, const std::array<T, N>& allParamsNames, int paramIndex, P parval)
1180+
{
11611181
if (paramIndex < 0) {
11621182
return false;
11631183
}
@@ -1213,6 +1233,8 @@ class MCReplayEngine : public TVirtualMC
12131233
// increment the current track length
12141234
float mCurrentTrackLength = 0.;
12151235

1236+
// block in case framework should be prevented from setting cuts or processes
1237+
bool mUpdateProcessesCutsBlocked = false;
12161238
// Preliminary process structure
12171239
std::vector<std::vector<Int_t>*> mProcesses;
12181240
// Preliminary cut structure

MCReplay/include/MCReplay/MCReplayPhysics.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#define MC_REPLAY_PHYSICS_H
1414

1515
#include <array>
16+
#include <algorithm>
17+
#include <cstring>
1618

1719
// Fix process and cut names
1820
namespace mcreplay
@@ -23,8 +25,8 @@ namespace physics
2325
constexpr std::array<const char*, 15> namesProcesses = {"PAIR", "COMP", "PHOT", "PFIS", "DRAY", "ANNI", "BREM", "HADR", "MUNU", "DCAY", "LOSS", "MULS", "CKOV", "RAYL", "LABS"};
2426
// standard GEANT cut parameter names (1-11)
2527
// additional Replay cut parameter names (12-n):
26-
// CUTALLE: energy cut applying to all tracks independent of PDG
27-
constexpr std::array<const char*, 12> namesCuts = {"CUTGAM", "CUTELE", "CUTNEU", "CUTHAD", "CUTMUO", "NCUTE", "BCUTM", "DCUTE", "DCUTM", "PPCUTM", "TOFMAX", "CUTALLE"};
28+
// CUTALL: energy cut applying to all tracks independent of PDG
29+
constexpr std::array<const char*, 12> namesCuts = {"CUTGAM", "CUTELE", "CUTNEU", "CUTHAD", "CUTMUO", "BCUTE", "BCUTM", "DCUTE", "DCUTM", "PPCUTM", "TOFMAX", "CUTALL"};
2830
constexpr const char* unknownParam = "UNKNOWN";
2931

3032
template <typename T, std::size_t N>
@@ -46,6 +48,14 @@ const char* indexToParam(const std::array<T, N>& allParams, std::size_t index)
4648
return allParams[index];
4749
}
4850

51+
bool isPhoton(int pdg);
52+
53+
bool isElectronPositron(int pdg);
54+
55+
bool isMuonAntiMuon(int pdg);
56+
57+
bool isHadron(int pdg);
58+
4959
} // namespace physics
5060
} // end namespace mcreplay
5161

MCReplay/src/MCReplayEngine.cxx

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include <algorithm>
1313
#include <iostream>
1414

15+
#include <boost/program_options.hpp>
16+
#include <boost/property_tree/json_parser.hpp>
17+
#include <boost/property_tree/ptree_fwd.hpp>
18+
1519
// For now include all TGeo headers here
1620
#include <TROOT.h>
1721
#include <TInterpreter.h>
@@ -35,8 +39,7 @@
3539
#include <TGeoEltu.h>
3640
#include <TGeoHype.h>
3741
#include <TGeoArb8.h>
38-
39-
#include "TParticle.h"
42+
#include <TStopwatch.h>
4043

4144
#include "MCReplay/MCReplayEngine.h"
4245

@@ -739,11 +742,19 @@ int MCReplayEngine::getMediumId(int volId) const
739742

740743
Bool_t MCReplayEngine::SetProcess(const char* flagName, Int_t flagValue)
741744
{
745+
if (mUpdateProcessesCutsBlocked) {
746+
::Info("MCReplayEngine::Gstpar", "Parameter setting closed, nothing is changed.");
747+
return false;
748+
}
742749
return insertProcessOrCut(mProcessesGlobal, physics::namesCuts, flagName, flagValue);
743750
}
744751

745752
Bool_t MCReplayEngine::SetCut(const char* cutName, Double_t cutValue)
746753
{
754+
if (mUpdateProcessesCutsBlocked) {
755+
::Info("MCReplayEngine::Gstpar", "Parameter setting closed, nothing is changed.");
756+
return false;
757+
}
747758
return insertProcessOrCut(mCutsGlobal, physics::namesCuts, cutName, cutValue);
748759
}
749760

@@ -842,8 +853,46 @@ void MCReplayEngine::Gdtom(Float_t* xd, Float_t* xm, Int_t iflag)
842853
}
843854
}
844855

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+
845890
void MCReplayEngine::Gstpar(Int_t itmed, const char* param, Double_t parval)
846891
{
892+
if (mUpdateProcessesCutsBlocked) {
893+
::Info("MCReplayEngine::Gstpar", "Parameter setting closed, nothing is changed.");
894+
return;
895+
}
847896
if (insertProcessOrCut(mProcesses, physics::namesProcesses, mProcessesGlobal, itmed, param, (int)parval)) {
848897
return;
849898
}
@@ -878,6 +927,24 @@ bool MCReplayEngine::keepDueToCuts(const o2::StepInfo& step) const
878927
// check global energy cut
879928
return false;
880929
}
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+
}
881948
return true;
882949
}
883950

@@ -959,6 +1026,8 @@ void MCReplayEngine::ProcessEvent(Int_t eventId)
9591026
unsigned int nUserTracks{0};
9601027
unsigned int nStopTrack{0};
9611028

1029+
TStopwatch stopwatch{};
1030+
9621031
for (auto& step : *steps) {
9631032

9641033
// TODO This should not happen. (see comment in header file for these flags)
@@ -1068,10 +1137,13 @@ void MCReplayEngine::ProcessEvent(Int_t eventId)
10681137

10691138
fApplication->FinishEvent();
10701139

1140+
stopwatch.Stop();
1141+
10711142
auto nStepsSkipped = steps->size() - nStepsKept;
10721143
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";
10731144
std::cout << "In addition, " << nUserTracks << " tracks produced during hit creation were ignored\n";
10741145
std::cout << "TVirtualMC::StopTrack was ignored " << nStopTrack << " times\n";
1146+
std::cout << "Real time: " << stopwatch.RealTime() << ", CPU time: " << stopwatch.CpuTime() << "\n";
10751147

10761148
delete steps;
10771149
delete mCurrentLookups;

MCReplay/src/MCReplayPhysics.cxx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
3+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
4+
// All rights not expressly granted are reserved.
5+
//
6+
// This software is distributed under the terms of the GNU General Public
7+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
8+
//
9+
// In applying this license CERN does not waive the privileges and immunities
10+
// granted to it by virtue of its status as an Intergovernmental Organization
11+
// or submit itself to any jurisdiction.
12+
13+
#include <cmath>
14+
#include "MCReplay/MCReplayPhysics.h"
15+
16+
bool mcreplay::physics::isPhoton(int pdg)
17+
{
18+
return pdg == 22;
19+
}
20+
21+
bool mcreplay::physics::isElectronPositron(int pdg)
22+
{
23+
return std::abs(pdg) == 11;
24+
}
25+
26+
bool mcreplay::physics::isMuonAntiMuon(int pdg)
27+
{
28+
return std::abs(pdg) == 13;
29+
}
30+
31+
bool mcreplay::physics::isHadron(int pdg)
32+
{
33+
// Taken from Pythia8 ParticleDataEntry::isHadron
34+
35+
if (pdg <= 100 || (pdg >= 1000000 && pdg <= 9000000) || pdg >= 9900000) {
36+
return false;
37+
}
38+
if (pdg == 130 || pdg == 310) {
39+
return true;
40+
}
41+
if (pdg % 10 == 0 || (pdg / 10) % 10 == 0 || (pdg / 100) % 10 == 0) {
42+
return false;
43+
}
44+
return true;
45+
}

0 commit comments

Comments
 (0)