195#include "TRestGeant4AnalysisProcess.h"
271 std::vector<string> fObservables;
272 fObservables = TRestEventProcess::ReadObservables();
274 if (fPerProcessSensitiveEnergy) {
275 fObservables.emplace_back(
"PerProcessPhotoelectric");
276 fObservables.emplace_back(
"PerProcessCompton");
277 fObservables.emplace_back(
"PerProcessElectronicIoni");
278 fObservables.emplace_back(
"PerProcessAlphaIoni");
279 fObservables.emplace_back(
"PerProcessIonIoni");
280 fObservables.emplace_back(
"PerProcessHadronicIoni");
281 fObservables.emplace_back(
"PerProcessProtonIoni");
282 fObservables.emplace_back(
"PerProcessMsc");
283 fObservables.emplace_back(
"PerProcessHadronElastic");
284 fObservables.emplace_back(
"PerProcessNeutronElastic");
286 for (
unsigned int i = 0; i < fObservables.size(); i++) {
287 if (fObservables[i].find(
"VolumeEDep") != string::npos) {
288 TString volName = fObservables[i].substr(0, fObservables[i].length() - 10).c_str();
294 fVolumeName.push_back(volName.Data());
299 cout <<
"??????????????????????????????????????????????????" << endl;
300 cout <<
"REST warning : TRestGeant4AnalysisProcess." << endl;
301 cout <<
"------------------------------------------" << endl;
303 cout <<
" Volume " << volName <<
" is not an active volume" << endl;
305 cout <<
"List of active volumes : " << endl;
306 cout <<
"------------------------ " << endl;
310 cout <<
"??????????????????????????????????????????????????" << endl;
315 if (fObservables[i].find(
"MeanPos") != string::npos) {
316 TString volName2 = fObservables[i].substr(0, fObservables[i].length() - 8).c_str();
317 std::string dirId = fObservables[i].substr(fObservables[i].length() - 1, 1);
328 cout <<
"??????????????????????????????????????????????????" << endl;
329 cout <<
"REST warning : TRestGeant4AnalysisProcess." << endl;
330 cout <<
"------------------------------------------" << endl;
332 cout <<
" Volume " << volName2 <<
" is not an active volume" << endl;
334 cout <<
"List of active volumes : " << endl;
335 cout <<
"------------------------ " << endl;
339 cout <<
"??????????????????????????????????????????????????" << endl;
343 if ((dirId !=
"X") && (dirId !=
"Y") && (dirId !=
"Z")) {
345 cout <<
"??????????????????????????????????????????????????" << endl;
346 cout <<
"REST warning : TRestGeant4AnalysisProcess." << endl;
347 cout <<
"------------------------------------------" << endl;
349 cout <<
" Direction " << dirId <<
" is not valid" << endl;
350 cout <<
" Only X, Y or Z accepted" << endl;
354 if (fObservables[i].find(
"Process") != string::npos) {
356 if (fObservables[i].find(
"RadiactiveDecay") != string::npos) ls = 15;
357 if (fObservables[i].find(
"Photoelectric") != string::npos) ls = 13;
358 if (fObservables[i].find(
"PhotonNuclear") != string::npos) ls = 13;
359 if (fObservables[i].find(
"Bremstralung") != string::npos) ls = 12;
360 if (fObservables[i].find(
"NInelastic") != string::npos) ls = 10;
361 if (fObservables[i].find(
"HadElastic") != string::npos) ls = 10;
362 if (fObservables[i].find(
"NCapture") != string::npos) ls = 8;
363 if (fObservables[i].find(
"Compton") != string::npos) ls = 7;
364 if (fObservables[i].find(
"Neutron") != string::npos) ls = 7;
365 if (fObservables[i].find(
"Alpha") != string::npos) ls = 5;
366 if (fObservables[i].find(
"Argon") != string::npos) ls = 5;
367 if (fObservables[i].find(
"Xenon") != string::npos) ls = 5;
368 if (fObservables[i].find(
"Neon") != string::npos) ls = 4;
370 TString processName = fObservables[i].substr(fObservables[i].length() - (ls + 7), ls).c_str();
371 TString volName3 = fObservables[i].substr(0, fObservables[i].length() - (ls + 7)).c_str();
380 if (fObservables[i].find(
"TracksCounter") != string::npos) {
381 TString particleName = fObservables[i].substr(0, fObservables[i].length() - 13).c_str();
386 if (fObservables[i].find(
"TracksEDep") != string::npos) {
387 TString particleName = fObservables[i].substr(0, fObservables[i].length() - 10).c_str();
403 Double_t sensitiveVolumeEnergy =
fOutputG4Event->GetEnergyInVolume(sensitiveVolumeName.Data());
405 double hitTime = std::numeric_limits<double>::infinity();
406 std::set<int> trackIdsInSensitiveVolume;
409 const auto& hits = track.GetHits();
410 for (
size_t hitIndex = 0; hitIndex < hits.GetNumberOfHits(); hitIndex++) {
411 const auto volumeName = hits.GetVolumeName(hitIndex);
412 if (volumeName != sensitiveVolumeName) {
415 const double energy = hits.GetEnergy(hitIndex);
420 const double time = hits.GetTime(hitIndex);
421 if (time < hitTime) {
425 trackIdsInSensitiveVolume.insert(track.GetTrackID());
431 std::set<int> trackParentsOfInterest;
432 for (
const auto& trackIdInSensitiveVolume : trackIdsInSensitiveVolume) {
433 const auto track =
fOutputG4Event->GetTrackByID(trackIdInSensitiveVolume);
436 while (parent !=
nullptr && !found) {
438 const auto& hits = parent->GetHits();
439 if (hits.GetVolumeName(0) != sensitiveVolumeName) {
440 for (
size_t hitIndex = 0; hitIndex < hits.GetNumberOfHits(); hitIndex++) {
441 const auto volumeName = hits.GetVolumeName(hitIndex);
442 if (volumeName != sensitiveVolumeName) {
444 trackParentsOfInterest.insert(parent->GetTrackID());
450 parent = parent->GetParentTrack();
454 if (!trackParentsOfInterest.empty()) {
455 const auto track =
fOutputG4Event->GetTrackByID(*trackParentsOfInterest.begin());
457 const auto position = track->GetInitialPosition();
462 const auto energy = track->GetInitialKineticEnergy();
465 const string particleName = track->GetParticleName().Data();
468 string parentParticleName;
469 if (track->GetParentTrack() !=
nullptr) {
470 parentParticleName = track->GetParentTrack()->GetParticleName().Data();
474 const string creatorProcess = track->GetCreatorProcess().Data();
477 const string volumeName = track->GetHits().GetVolumeName(0).Data();
484 cout <<
"----------------------------" << endl;
486 cout <<
"Sensitive volume Energy : " << sensitiveVolumeEnergy << endl;
487 cout <<
"Total energy : " <<
fOutputG4Event->GetTotalDepositedEnergy() << endl;
501 Double_t xDirection =
fOutputG4Event->GetPrimaryEventDirection(0).X();
504 Double_t yDirection =
fOutputG4Event->GetPrimaryEventDirection(0).Y();
507 Double_t zDirection =
fOutputG4Event->GetPrimaryEventDirection(0).Z();
511 string subEventPrimaryParticleName;
513 subEventPrimaryParticleName =
fOutputG4Event->GetSubEventPrimaryEventParticleName();
515 subEventPrimaryParticleName =
"generator";
519 TVector3 primaryDirection(xDirection, yDirection, zDirection);
520 primaryDirection = primaryDirection.Unit();
523 SetObservableValue(
"zenithYDegrees", TMath::ACos(-1 * yDirection) * TMath::RadToDeg());
525 sourceDirection = sourceDirection.Unit();
527 TMath::ACos(primaryDirection.Dot(sourceDirection)) * TMath::RadToDeg());
529 Double_t energyPrimary =
fOutputG4Event->GetPrimaryEventEnergy(0);
541 vector<string> processNames = {
"phot",
"compt"};
542 for (
auto& processName : processNames) {
543 Int_t containsProcess = 0;
548 if (!processName.empty()) {
549 processName[0] = toupper(processName[0]);
576 if (
fDirID[n] == (TString)
"X")
579 else if (
fDirID[n] == (TString)
"Y")
582 else if (
fDirID[n] == (TString)
"Z")
589 cout <<
"G4 Tracks : " <<
fOutputG4Event->GetNumberOfTracks() << endl;
590 cout <<
"----------------------------" << endl;
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
A base class for any REST event.
A pure analysis process to extract information from a TRestGeant4Event.
void Initialize() override
Function to initialize input/output event members and define the section name.
std::vector< std::string > fEnergyInObservables
It stores the name of observables xxxVolumeEDep related to the energy deposition in volume xxx.
std::vector< std::string > fDirID
void InitProcess() override
Process initialization. Observable names are interpreted and auxiliar observable members,...
TRestGeant4Event * fInputG4Event
A pointer to the specific TRestGeant4Event input.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
TRestGeant4Metadata * fG4Metadata
A pointer to the simulation metadata information accessible to TRestRun.
~TRestGeant4AnalysisProcess()
Default destructor.
std::vector< std::string > fTracksEDepObservables
A std::vector storing the observable name xxxTracksEDep for a given xxx particle.
std::vector< std::string > fParticleTrackCounter
A std::vector storing the xxx particle name extracted from xxxTracksCounter.
std::vector< std::string > fProcessObservables
A std::vector storing the name of observables related to processes in a particular active volume.
std::vector< Int_t > fVolumeID2
A std::vector storing the active volume ids corresponding mean position observable xxxMeanPosX,...
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
std::vector< Int_t > fVolumeID
A std::vector storing the active volume ids of observables xxxVolumeEDep.
TRestGeant4Event * fOutputG4Event
A pointer to the specific TRestGeant4Event output.
std::vector< std::string > fTrackCounterObservables
A std::vector storing the observable name xxxTracksCounter for a given xxx particle.
std::vector< Int_t > fVolumeID3
A std::vector storing the active volume ids corresponding process observable .
TRestGeant4AnalysisProcess()
Default constructor.
std::vector< std::string > fMeanPosObservables
A std::vector storing the name of active volumes.
std::vector< std::string > fProcessName
A std::vector storing the name of processes.
void EndProcess() override
Function to include required actions after all events have been processed.
std::vector< std::string > fParticleTrackEdep
A std::vector storing the xxx particle name extracted from xxxTracksEDep.
An event class to store geant4 generated event information.
Double_t GetBoundingBoxSize()
This method returns the event size as the size of the bounding box enclosing all hits.
@ REST_Debug
+show the defined debug messages