36 #include <TVirtualMC.h>
37 #include <TVirtualMCStack.h>
53 std::set<int> trackset;
55 std::map<int, int> volumetosteps;
56 std::map<int, int> volumetostepsGlobal;
57 std::map<int, char const*> idtovolname;
65 auto stack = mc->GetStack();
67 trackset.insert(stack->GetCurrentTrackNumber());
68 pdgset.insert(mc->TrackPid());
70 auto id = mc->CurrentVolID(copyNo);
71 if (volumetosteps.find(
id) == volumetosteps.end()) {
72 volumetosteps.insert(std::pair<int, int>(
id, 0));
76 if (volumetostepsGlobal.find(
id) == volumetostepsGlobal.end()) {
77 volumetostepsGlobal.insert(std::pair<int, int>(
id, 0));
79 volumetostepsGlobal[id]++;
81 if (idtovolname.find(
id) == idtovolname.end()) {
82 idtovolname.insert(std::pair<int, char const*>(
id, mc->CurrentVolName()));
91 volumetosteps.clear();
96 std::cerr <<
"did " << stepcounter <<
" steps \n";
97 std::cerr <<
"transported " << trackset.size() <<
" different tracks \n";
98 std::cerr <<
"transported " << pdgset.size() <<
" different types \n";
100 for (
auto& p : volumetosteps) {
101 std::cout <<
" VolName " << idtovolname[p.first] <<
" COUNT " << p.second <<
"\n";
109 TFile* stepLoggerFile = TFile::Open(
"stepLogger.root",
"recreate");
110 TH1F* stepLoggerHistogram =
new TH1F(
"stepLoggerHistogram",
111 "Step logger results;volume number;number of steps",
112 volumetostepsGlobal.size(),
114 volumetostepsGlobal.size() + 0.5);
116 for (
auto& p : volumetostepsGlobal) {
117 std::cout <<
" VolName " << idtovolname[p.first] <<
" COUNT " << p.second <<
"\n";
118 stepLoggerHistogram->SetBinContent(++binNumber, p.second);
119 stepLoggerHistogram->GetXaxis()->SetBinLabel(binNumber, idtovolname[p.first]);
121 stepLoggerHistogram->DrawClone();
122 stepLoggerFile->Write();
123 stepLoggerFile->Close();
136 static StepMethodType origMethod =
nullptr;
137 if (origMethod ==
nullptr) {
138 auto libHandle = dlopen(libname, RTLD_NOW);
142 std::stringstream stream;
143 stream << libname <<
".so";
144 libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
148 std::stringstream stream;
149 stream << libname <<
".dylib";
150 libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
153 void* symbolAddress = dlsym(libHandle, origFunctionName);
154 assert(symbolAddress);
157 memcpy(&origMethod, &symbolAddress,
sizeof(symbolAddress));
159 (app->*origMethod)();
169 static StepMethodType origMethod =
nullptr;
170 if (origMethod ==
nullptr) {
171 auto libHandle = dlopen(libname, RTLD_NOW);
175 std::stringstream stream;
176 stream << libname <<
".so";
177 libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
181 std::stringstream stream;
182 stream << libname <<
".dylib";
183 libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
186 void* symbolAddress = dlsym(libHandle, origFunctionName);
187 assert(symbolAddress);
190 memcpy(&origMethod, &symbolAddress,
sizeof(symbolAddress));
192 (app->*origMethod)();
202 static StepMethodType origMethod =
nullptr;
203 if (origMethod ==
nullptr) {
204 auto libHandle = dlopen(libname, RTLD_NOW);
208 std::stringstream stream;
209 stream << libname <<
".so";
210 libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
214 std::stringstream stream;
215 stream << libname <<
".dylib";
216 libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
219 void* symbolAddress = dlsym(libHandle, origFunctionName);
220 assert(symbolAddress);
223 memcpy(&origMethod, &symbolAddress,
sizeof(symbolAddress));
225 (app->*origMethod)();
230 static TVirtualMC* mc = TVirtualMC::GetMC();
void addStep(TVirtualMC *mc)
void dispatchFinishEvent(FairMCApplication *, char const *libname, char const *)
void dispatchStepping(FairMCApplication *, char const *libname, char const *)
void dispatchFinishRun(FairMCApplication *, char const *libname, char const *)
void performLogging(FairMCApplication *)