REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestGeant4AnalysisProcess.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
284
285#include "TRestGeant4AnalysisProcess.h"
286
287#include <algorithm>
288#include <tuple>
289
290using namespace std;
291
293
298
312 Initialize();
313
314 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
315}
316
321
325void TRestGeant4AnalysisProcess::LoadDefaultConfig() { SetTitle("Default config"); }
326
332 fG4Metadata = nullptr;
333 SetSectionName(this->ClassName());
334 SetLibraryVersion(LIBRARY_VERSION);
335
336 fInputG4Event = nullptr;
338}
339
352void TRestGeant4AnalysisProcess::LoadConfig(const string& configFilename, const string& name) {
353 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
354}
355
356namespace {
357string CapitalizeFirst(string name) {
358 if (!name.empty()) {
359 name[0] = toupper(name[0]);
360 }
361 return name;
362}
363
364bool EndsWith(const string& text, const string& suffix) {
365 return text.size() >= suffix.size() &&
366 text.compare(text.size() - suffix.size(), suffix.size(), suffix) == 0;
367}
368
369bool StartsWith(const string& text, const string& prefix) { return text.rfind(prefix, 0) == 0; }
370} // namespace
371
377 static const map<string, string> processNameMap = {
378 // electromagnetic, photons
379 {"Photoelectric", "phot"},
380 {"Compton", "compt"},
381 {"Rayleigh", "Rayl"},
382 {"Conversion", "conv"},
383 {"PhotonNuclear", "photonNuclear"},
384 // electromagnetic, charged particles
385 {"Bremsstrahlung", "eBrem"},
386 {"Bremstralung", "eBrem"}, // legacy misspelling
387 {"Annihilation", "annihil"},
388 {"EIoni", "eIoni"},
389 {"HIoni", "hIoni"},
390 {"IonIoni", "ionIoni"},
391 {"MuIoni", "muIoni"},
392 {"Msc", "msc"},
393 {"CoulombScat", "CoulombScat"},
394 // hadronic
395 {"HadElastic", "hadElastic"},
396 {"NeutronInelastic", "neutronInelastic"},
397 {"NInelastic", "neutronInelastic"}, // legacy name
398 {"ProtonInelastic", "protonInelastic"},
399 {"NCapture", "nCapture"},
400 // decay
401 {"RadioactiveDecay", "RadioactiveDecay"},
402 {"RadiactiveDecay", "RadioactiveDecay"}, // legacy misspelling
403 {"Decay", "Decay"},
404 };
405 return processNameMap;
406}
407
415string TRestGeant4AnalysisProcess::GetGeant4ProcessName(const string& name) const {
416 if (name.empty()) {
417 return "";
418 }
419
420 const auto& processNameMap = GetRestToGeant4ProcessNameMap();
421 const auto it = processNameMap.find(name);
422 if (it != processNameMap.end()) {
423 return it->second;
424 }
425
426 for (const auto& [restName, geant4Name] : processNameMap) {
427 if (CapitalizeFirst(geant4Name) == name) {
428 return geant4Name;
429 }
430 }
431
432 if (fG4Metadata != nullptr) {
433 for (const auto& geant4Name : fG4Metadata->GetGeant4PhysicsInfo().GetAllProcesses()) {
434 if (CapitalizeFirst(geant4Name.Data()) == name) {
435 return geant4Name.Data();
436 }
437 }
438 }
439
440 return "";
441}
442
447 cout << endl;
448 cout << "??????????????????????????????????????????????????" << endl;
449 cout << "REST warning : TRestGeant4AnalysisProcess." << endl;
450 cout << "------------------------------------------" << endl;
451 cout << endl;
452 cout << " Volume " << volumeName << " is not an active volume" << endl;
453 cout << endl;
454 cout << "List of active volumes : " << endl;
455 cout << "------------------------ " << endl;
456
457 for (unsigned int n = 0; n < fG4Metadata->GetNumberOfActiveVolumes(); n++)
458 cout << "Volume " << n << " : " << fG4Metadata->GetActiveVolumeName(n) << endl;
459 cout << "??????????????????????????????????????????????????" << endl;
460 cout << endl;
461}
462
470 fG4Metadata = GetMetadata<TRestGeant4Metadata>();
471
472 // InitProcess may be called more than once
473 fEnergyInObservables.clear();
474 fVolumeID.clear();
475 fVolumeName.clear();
476 fMeanPosObservables.clear();
477 fVolumeID2.clear();
478 fDirID.clear();
479 fProcessObservables.clear();
480 fVolumeID3.clear();
481 fProcessVolumeName.clear();
482 fProcessName.clear();
484 fParticleTrackCounter.clear();
486 fParticleTrackEdep.clear();
490 fPerProcessG4Names.clear();
491 fPerProcessParticle.clear();
492
493 std::vector<string> fObservables;
494 fObservables = TRestEventProcess::ReadObservables();
495 std::map<std::string, std::string> aliasObsToVol = GetAliasObservableNameToVolume();
496
497 const auto& physicsInfo = fG4Metadata->GetGeant4PhysicsInfo();
498 const auto availableProcesses = physicsInfo.GetAllProcesses();
499
500 // containsProcessPhot and containsProcessCompt are always evaluated (historical behaviour)
501 fContainsProcessObservables = {"containsProcessPhot", "containsProcessCompt"};
502 fContainsProcessG4Name = {"phot", "compt"};
503
505 // {observable name, particle (empty for any), Geant4 processes}
506 const vector<tuple<string, string, vector<string>>> perProcessDefinitions = {
507 {"PerProcessPhotoelectric", "", {"phot"}},
508 {"PerProcessCompton", "", {"compt"}},
509 {"PerProcessElectronicIoni", "", {"eIoni"}},
510 {"PerProcessAlphaIoni", "alpha", {"ionIoni", "alphaIoni"}},
511 {"PerProcessIonIoni", "", {"ionIoni"}},
512 {"PerProcessHadronicIoni", "", {"hIoni"}},
513 {"PerProcessProtonIoni", "proton", {"hIoni"}},
514 {"PerProcessMsc", "", {"msc"}},
515 {"PerProcessHadronElastic", "", {"hadElastic"}},
516 {"PerProcessNeutronElastic", "neutron", {"hadElastic"}},
517 };
518 for (const auto& [obsName, particle, processes] : perProcessDefinitions) {
519 fPerProcessObservables.push_back(obsName);
520 fPerProcessParticle.push_back(particle);
521 fPerProcessG4Names.push_back(processes);
522 if (fAnalysisTree != nullptr) {
523 fAnalysisTree->AddObservable((string)GetName() + "_" + obsName, "double",
524 "Energy deposited in the sensitive volumes by a given process");
525 }
526 }
527 }
528
529 for (unsigned int i = 0; i < fObservables.size(); i++) {
530 if (fObservables[i].find("VolumeEDep") != string::npos) {
531 TString volName = fObservables[i].substr(0, fObservables[i].length() - 10).c_str();
532 if (aliasObsToVol.find(fObservables[i]) != aliasObsToVol.end()) {
533 volName = aliasObsToVol[fObservables[i]].c_str();
534 }
535
536 Int_t volId = fG4Metadata->GetActiveVolumeID(volName);
537 if (volId >= 0) {
538 fEnergyInObservables.push_back(fObservables[i]);
539 fVolumeID.push_back(volId);
540 fVolumeName.push_back(volName.Data());
541 }
542
543 if (volId == -1) {
545 }
546 }
547
548 if (fObservables[i].find("MeanPos") != string::npos) {
549 TString volName2 = fObservables[i].substr(0, fObservables[i].length() - 8).c_str();
550 if (aliasObsToVol.find(fObservables[i]) != aliasObsToVol.end()) {
551 volName2 = aliasObsToVol[fObservables[i]].c_str();
552 }
553 std::string dirId = fObservables[i].substr(fObservables[i].length() - 1, 1);
554
555 Int_t volId2 = fG4Metadata->GetActiveVolumeID(volName2);
556 if (volId2 >= 0) {
557 fMeanPosObservables.push_back(fObservables[i]);
558 fVolumeID2.push_back(volId2);
559 fDirID.push_back(dirId);
560 }
561
562 if (volId2 == -1) {
564 }
565
566 if ((dirId != "X") && (dirId != "Y") && (dirId != "Z")) {
567 cout << endl;
568 cout << "??????????????????????????????????????????????????" << endl;
569 cout << "REST warning : TRestGeant4AnalysisProcess." << endl;
570 cout << "------------------------------------------" << endl;
571 cout << endl;
572 cout << " Direction " << dirId << " is not valid" << endl;
573 cout << " Only X, Y or Z accepted" << endl;
574 cout << endl;
575 }
576 }
577
578 if (StartsWith(fObservables[i], "containsProcess")) {
579 const string processSuffix = fObservables[i].substr(string("containsProcess").length());
580 if (std::find(fContainsProcessObservables.begin(), fContainsProcessObservables.end(),
581 fObservables[i]) != fContainsProcessObservables.end()) {
582 continue;
583 }
584 const string geant4Name = GetGeant4ProcessName(processSuffix);
585 if (geant4Name.empty()) {
586 RESTWarning << "TRestGeant4AnalysisProcess: unknown process '" << processSuffix
587 << "' in observable '" << fObservables[i] << "'. It will not be filled."
588 << RESTendl;
589 continue;
590 }
591 if (availableProcesses.count(geant4Name) == 0) {
592 RESTWarning << "TRestGeant4AnalysisProcess: Geant4 process '" << geant4Name
593 << "' (observable '" << fObservables[i]
594 << "') is not registered in the physics info of this simulation. "
595 << "Its value will always be 0 (processes sharing type and subtype, e.g. "
596 << "eIoni and ionIoni, are registered only once)" << RESTendl;
597 }
598 fContainsProcessObservables.push_back(fObservables[i]);
599 fContainsProcessG4Name.push_back(geant4Name);
600 continue;
601 }
602
603 // <volume><Process>Process observables. Other observables ending in "Process" are excluded.
604 if (EndsWith(fObservables[i], "Process") && !StartsWith(fObservables[i], "firstTrackInSensitive")) {
605 const string nameWithoutSuffix =
606 fObservables[i].substr(0, fObservables[i].length() - string("Process").length());
607 const bool hasAlias = aliasObsToVol.find(fObservables[i]) != aliasObsToVol.end();
608
609 // find the longest trailing substring which is a known process name
610 string processName;
611 string geant4Name;
612 for (size_t length = 1; length <= nameWithoutSuffix.length(); length++) {
613 // the volume name may only be empty if it is given through the `volume` attribute
614 if (length == nameWithoutSuffix.length() && !hasAlias) {
615 break;
616 }
617 const string candidate = nameWithoutSuffix.substr(nameWithoutSuffix.length() - length);
618 const string candidateGeant4Name = GetGeant4ProcessName(candidate);
619 if (!candidateGeant4Name.empty()) {
620 processName = candidate;
621 geant4Name = candidateGeant4Name;
622 }
623 }
624
625 if (geant4Name.empty()) {
626 RESTWarning << "TRestGeant4AnalysisProcess: no known process name found in observable '"
627 << fObservables[i] << "'. It will not be filled." << RESTendl;
628 RESTWarning << "Valid process names are:";
629 for (const auto& [restName, g4Name] : GetRestToGeant4ProcessNameMap()) {
630 RESTWarning << " " << restName;
631 }
632 RESTWarning << " (or a Geant4 process name with the first letter capitalized)" << RESTendl;
633 continue;
634 }
635
636 TString volName3 = nameWithoutSuffix.substr(0, nameWithoutSuffix.length() - processName.length());
637 if (hasAlias) {
638 volName3 = aliasObsToVol[fObservables[i]].c_str();
639 }
640 Int_t volId3 = fG4Metadata->GetActiveVolumeID(volName3);
641
642 if (volId3 >= 0) {
643 fProcessObservables.push_back(fObservables[i]);
644 fVolumeID3.push_back(volId3);
645 fProcessVolumeName.emplace_back(volName3.Data());
646 fProcessName.push_back(geant4Name);
647 if (availableProcesses.count(geant4Name) == 0) {
648 RESTWarning << "TRestGeant4AnalysisProcess: Geant4 process '" << geant4Name
649 << "' (observable '" << fObservables[i]
650 << "') is not registered in the physics info of this simulation. "
651 << "It will be 0 unless energy is deposited under this process name "
652 << "(processes sharing type and subtype, e.g. eIoni and ionIoni, are "
653 << "registered only once)" << RESTendl;
654 }
655 } else {
657 }
658 }
659
660 if (fObservables[i].find("TracksCounter") != string::npos) {
661 TString particleName = fObservables[i].substr(0, fObservables[i].length() - 13).c_str();
662 fTrackCounterObservables.push_back(fObservables[i]);
663 fParticleTrackCounter.emplace_back(particleName.Data());
664 }
665
666 if (fObservables[i].find("TracksEDep") != string::npos) {
667 TString particleName = fObservables[i].substr(0, fObservables[i].length() - 10).c_str();
668 fTracksEDepObservables.push_back(fObservables[i]);
669 fParticleTrackEdep.emplace_back(particleName.Data());
670 }
671 }
672}
673
678 fInputG4Event = (TRestGeant4Event*)inputEvent;
679 *fOutputG4Event = *((TRestGeant4Event*)inputEvent);
680 // The event read by the process runner has no track/hit references, required to access the
681 // volume names of the hits or the parent tracks
683
684 // All the sensitive volumes are considered. Energies are summed over them.
685 const auto& sensitiveVolumes = fG4Metadata->GetSensitiveVolumes();
686 auto isSensitiveVolume = [&sensitiveVolumes](const TString& volumeName) {
687 return std::find(sensitiveVolumes.begin(), sensitiveVolumes.end(), volumeName) !=
688 sensitiveVolumes.end();
689 };
690
691 Double_t sensitiveVolumeEnergy = 0;
692 const auto energyInVolume = fOutputG4Event->GetEnergyInVolumeMap();
693 for (const auto& sensitiveVolume : sensitiveVolumes) {
694 const auto volume = energyInVolume.find(sensitiveVolume.Data());
695 if (volume != energyInVolume.end()) {
696 sensitiveVolumeEnergy += volume->second;
697 }
698 }
699
700 // Get time of the first hit in any sensitive volume
701 double hitTime = std::numeric_limits<double>::infinity();
702 std::set<int> trackIdsInSensitiveVolume;
703
704 for (const auto& track : fOutputG4Event->GetTracks()) {
705 const auto& hits = track.GetHits();
706 for (size_t hitIndex = 0; hitIndex < hits.GetNumberOfHits(); hitIndex++) {
707 const auto volumeName = hits.GetVolumeName(hitIndex);
708 if (!isSensitiveVolume(volumeName)) {
709 continue;
710 }
711 const double energy = hits.GetEnergy(hitIndex);
712 if (energy <= 0) {
713 continue;
714 }
715
716 const double time = hits.GetTime(hitIndex);
717 if (time < hitTime) {
718 hitTime = time;
719 }
720
721 trackIdsInSensitiveVolume.insert(track.GetTrackID());
722 }
723 }
724
725 SetObservableValue("sensitiveVolumeFirstHitTime", hitTime);
726
727 std::set<int> trackParentsOfInterest;
728 for (const auto& trackIdInSensitiveVolume : trackIdsInSensitiveVolume) {
729 const auto track = fOutputG4Event->GetTrackByID(trackIdInSensitiveVolume);
730 TRestGeant4Track* parent = track;
731 bool found = false;
732 while (parent != nullptr && !found) {
733 // iterate over hits
734 const auto& hits = parent->GetHits();
735 if (hits.GetNumberOfHits() > 0 && !isSensitiveVolume(hits.GetVolumeName(0))) {
736 for (size_t hitIndex = 0; hitIndex < hits.GetNumberOfHits(); hitIndex++) {
737 const auto volumeName = hits.GetVolumeName(hitIndex);
738 if (!isSensitiveVolume(volumeName)) {
739 found = true;
740 trackParentsOfInterest.insert(parent->GetTrackID());
741 break;
742 }
743 }
744 }
745
746 parent = parent->GetParentTrack();
747 }
748 }
749
750 const double missingValue = std::numeric_limits<double>::quiet_NaN();
751 TVector3 position(missingValue, missingValue, missingValue);
752 double energy = missingValue;
753 string particleName;
754 string parentParticleName;
755 string creatorProcess;
756 string volumeName;
757
758 if (!trackParentsOfInterest.empty()) {
759 const auto track = fOutputG4Event->GetTrackByID(*trackParentsOfInterest.begin());
760
761 position = track->GetInitialPosition();
762 energy = track->GetInitialKineticEnergy();
763 particleName = track->GetParticleName().Data();
764
765 if (track->GetParentTrack() != nullptr) {
766 parentParticleName = track->GetParentTrack()->GetParticleName().Data();
767 }
768 creatorProcess = track->GetCreatorProcess().Data();
769 volumeName = track->GetHits().GetVolumeName(0).Data();
770 }
771
772 SetObservableValue("firstTrackInSensitivePositionX", position.X());
773 SetObservableValue("firstTrackInSensitivePositionY", position.Y());
774 SetObservableValue("firstTrackInSensitivePositionZ", position.Z());
775 SetObservableValue("firstTrackInSensitiveEnergy", energy);
776 SetObservableValue("firstTrackInSensitiveParticle", particleName);
777 SetObservableValue("firstTrackInSensitiveParentParticle", parentParticleName);
778 SetObservableValue("firstTrackInSensitiveCreatorProcess", creatorProcess);
779 SetObservableValue("firstTrackInSensitiveVolumeName", volumeName);
780 SetObservableValue("firstTrackInSensitiveOk", trackParentsOfInterest.size() == 1);
781
783 cout << "----------------------------" << endl;
784 cout << "TRestGeant4Event : " << fOutputG4Event->GetID() << endl;
785 cout << "Sensitive volume Energy : " << sensitiveVolumeEnergy << endl;
786 cout << "Total energy : " << fOutputG4Event->GetTotalDepositedEnergy() << endl;
787 }
788
789 SetObservableValue("sensitiveVolumeEnergy", sensitiveVolumeEnergy);
790
791 Double_t xOrigin = fOutputG4Event->GetPrimaryEventOrigin().X();
792 SetObservableValue("xOriginPrimary", xOrigin);
793
794 Double_t yOrigin = fOutputG4Event->GetPrimaryEventOrigin().Y();
795 SetObservableValue("yOriginPrimary", yOrigin);
796
797 Double_t zOrigin = fOutputG4Event->GetPrimaryEventOrigin().Z();
798 SetObservableValue("zOriginPrimary", zOrigin);
799
800 Double_t xDirection = fOutputG4Event->GetPrimaryEventDirection(0).X();
801 SetObservableValue("xDirectionPrimary", xDirection);
802
803 Double_t yDirection = fOutputG4Event->GetPrimaryEventDirection(0).Y();
804 SetObservableValue("yDirectionPrimary", yDirection);
805
806 Double_t zDirection = fOutputG4Event->GetPrimaryEventDirection(0).Z();
807 SetObservableValue("zDirectionPrimary", zDirection);
808
809 SetObservableValue("eventPrimaryParticleName", fOutputG4Event->GetPrimaryEventParticleName(0));
810 string subEventPrimaryParticleName;
811 if (fOutputG4Event->GetSubID() != 0) {
812 subEventPrimaryParticleName = fOutputG4Event->GetSubEventPrimaryEventParticleName();
813 } else {
814 subEventPrimaryParticleName = "generator";
815 }
816 SetObservableValue("subEventPrimaryParticleName", subEventPrimaryParticleName);
817
818 TVector3 primaryDirection(xDirection, yDirection, zDirection);
819 primaryDirection = primaryDirection.Unit();
820 SetObservableValue("thetaPrimary", primaryDirection.Theta());
821 SetObservableValue("phiPrimary", primaryDirection.Phi());
822 SetObservableValue("zenithYDegrees", TMath::ACos(-1 * yDirection) * TMath::RadToDeg());
823 TVector3 sourceDirection = fG4Metadata->GetParticleSource(0)->GetDirection();
824 sourceDirection = sourceDirection.Unit();
825 SetObservableValue("zenithSourceDegrees",
826 TMath::ACos(primaryDirection.Dot(sourceDirection)) * TMath::RadToDeg());
827
828 Double_t energyPrimary = fOutputG4Event->GetPrimaryEventEnergy(0);
829 SetObservableValue("energyPrimary", energyPrimary);
830
831 Double_t energyTotal = fOutputG4Event->GetTotalDepositedEnergy();
832 SetObservableValue("totalEdep", energyTotal);
833
834 Double_t size = fOutputG4Event->GetBoundingBoxSize();
835 SetObservableValue("boundingSize", size);
836
837 // containsProcessXxx observables: 1 if the event contains the Geant4 process, 0 otherwise
838 const auto& physicsInfo = fG4Metadata->GetGeant4PhysicsInfo();
839 for (unsigned int n = 0; n < fContainsProcessObservables.size(); n++) {
840 const auto& processName = fContainsProcessG4Name[n];
841 const Int_t processID = physicsInfo.GetProcessID(processName);
842 // GetProcessID returns a default id (0) for unknown processes, which may be a valid id
843 const bool processIsRegistered = physicsInfo.GetProcessName(processID) == processName;
844 Int_t containsProcess = 0;
845 if (processIsRegistered && fOutputG4Event->ContainsProcess(processID)) {
846 containsProcess = 1;
847 }
849 }
850
851 if (!fProcessObservables.empty()) {
852 const auto energyInVolumePerProcess = fOutputG4Event->GetEnergyInVolumePerProcessMap();
853 for (unsigned int n = 0; n < fProcessObservables.size(); n++) {
854 Double_t energy = 0;
855 const auto volume = energyInVolumePerProcess.find(fProcessVolumeName[n]);
856 if (volume != energyInVolumePerProcess.end()) {
857 const auto process = volume->second.find(fProcessName[n]);
858 if (process != volume->second.end()) {
859 energy = process->second;
860 }
861 }
863 }
864 }
865
866 if (!fPerProcessObservables.empty()) {
867 const auto energyInVolumePerParticlePerProcess =
868 fOutputG4Event->GetEnergyInVolumePerParticlePerProcessMap();
869 for (unsigned int n = 0; n < fPerProcessObservables.size(); n++) {
870 Double_t energy = 0;
871 for (const auto& sensitiveVolumeName : sensitiveVolumes) {
872 const auto sensitiveVolume =
873 energyInVolumePerParticlePerProcess.find(sensitiveVolumeName.Data());
874 if (sensitiveVolume == energyInVolumePerParticlePerProcess.end()) {
875 continue;
876 }
877 for (const auto& [particle, energyPerProcess] : sensitiveVolume->second) {
878 if (!fPerProcessParticle[n].empty() && particle != fPerProcessParticle[n]) {
879 continue;
880 }
881 for (const auto& processName : fPerProcessG4Names[n]) {
882 const auto process = energyPerProcess.find(processName);
883 if (process != energyPerProcess.end()) {
884 energy += process->second;
885 }
886 }
887 }
888 }
890 energy = sensitiveVolumeEnergy > 0 ? energy / sensitiveVolumeEnergy : 0;
891 }
893 }
894 }
895
896 for (unsigned int n = 0; n < fParticleTrackCounter.size(); n++) {
897 Int_t nT = fOutputG4Event->GetNumberOfTracksForParticle(fParticleTrackCounter[n]);
898 string obsName = fTrackCounterObservables[n];
899 SetObservableValue(obsName, nT);
900 }
901
902 for (unsigned int n = 0; n < fTracksEDepObservables.size(); n++) {
903 Double_t energy = fOutputG4Event->GetEnergyDepositedByParticle(fParticleTrackEdep[n]);
904 string obsName = fTracksEDepObservables[n];
905 SetObservableValue(obsName, energy);
906 }
907
908 for (unsigned int n = 0; n < fEnergyInObservables.size(); n++) {
909 Double_t en = fOutputG4Event->GetEnergyInVolume(fVolumeName[n]);
910 string obsName = fEnergyInObservables[n];
911 SetObservableValue(obsName, en);
912 }
913
914 for (unsigned int n = 0; n < fMeanPosObservables.size(); n++) {
915 string obsName = fMeanPosObservables[n];
916
917 Double_t mpos = 0;
918 if (fDirID[n] == (TString) "X")
919 mpos = fOutputG4Event->GetMeanPositionInVolume(fVolumeID2[n]).X();
920
921 else if (fDirID[n] == (TString) "Y")
922 mpos = fOutputG4Event->GetMeanPositionInVolume(fVolumeID2[n]).Y();
923
924 else if (fDirID[n] == (TString) "Z")
925 mpos = fOutputG4Event->GetMeanPositionInVolume(fVolumeID2[n]).Z();
926
927 SetObservableValue(obsName, mpos);
928 }
929
931 cout << "G4 Tracks : " << fOutputG4Event->GetNumberOfTracks() << endl;
932 cout << "----------------------------" << endl;
933 }
934
935 return fOutputG4Event;
936}
937
938std::map<std::string, std::string> TRestGeant4AnalysisProcess::GetAliasObservableNameToVolume() {
939 TiXmlElement* e = GetElement("observable");
940 std::map<std::string, std::string> obsNamesToVolumes;
941
942 while (e != nullptr) {
943 const char* obschr = e->Attribute("name");
944 const char* _value = e->Attribute("value");
945 const char* _vol = e->Attribute("volume");
946
947 string value;
948 if (_value == nullptr)
949 value = "ON";
950 else
951 value = _value;
952
953 if (ToUpper(value) == "ON") {
954 if (obschr != nullptr) {
955 string volume;
956 if (_vol) {
957 volume = _vol;
958 obsNamesToVolumes[(string)obschr] = volume;
959 }
960 }
961 }
962
963 e = e->NextSiblingElement("observable");
964 }
965
966 return obsNamesToVolumes;
967}
968
TRestAnalysisTree * fAnalysisTree
TRestRun * GetRunInfo() const
Return the pointer of the hosting TRestRun object.
void SetObservableValue(const std::string &name, const T &value)
Set observable value for AnalysisTree.
A base class for any REST event.
Definition: TRestEvent.h:38
A pure analysis process to extract information from a TRestGeant4Event.
std::vector< std::string > fPerProcessParticle
The particle restriction of each PerProcessXxx observable (empty means any particle).
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
std::string GetGeant4ProcessName(const std::string &name) const
It returns the Geant4 process name corresponding to name.
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
std::vector< Int_t > fVolumeID2
A std::vector storing the active volume ids corresponding mean position observable xxxMeanPosX,...
Bool_t fPerProcessSensitiveEnergyNorm
If true, PerProcessXxx observables are normalized to the total energy in the sensitive volumes.
std::vector< std::string > fProcessVolumeName
A std::vector storing the volume name corresponding to each process observable.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
std::vector< std::string > fPerProcessObservables
A std::vector storing the observable names PerProcessXxx (only if fPerProcessSensitiveEnergy).
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
std::vector< std::string > fContainsProcessObservables
A std::vector storing the observable names containsProcessXxx.
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< std::vector< std::string > > fPerProcessG4Names
The Geant4 process names contributing to each PerProcessXxx observable.
std::vector< Int_t > fVolumeID3
A std::vector storing the active volume ids corresponding process observable .
static const std::map< std::string, std::string > & GetRestToGeant4ProcessNameMap()
It returns the map between the process names used in REST observables (<volume><Process>Process) and ...
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 Geant4 name of the process corresponding to each process observable.
void EndProcess() override
Function to include required actions after all events have been processed.
std::vector< std::string > fContainsProcessG4Name
A std::vector storing the Geant4 process name corresponding to each containsProcessXxx observable.
std::vector< std::string > fParticleTrackEdep
A std::vector storing the xxx particle name extracted from xxxTracksEDep.
void PrintNotActiveVolumeWarning(const TString &volumeName)
It prints a warning when the volume used by an observable is not an active volume.
An event class to store geant4 generated event information.
void InitializeReferences(TRestRun *run) override
Initialize dynamical references when loading the event from a root file.
Double_t GetBoundingBoxSize()
This method returns the event size as the size of the bounding box enclosing all hits.
const TRestGeant4PhysicsInfo & GetGeant4PhysicsInfo() const
Returns an immutable reference to the physics info.
Int_t GetActiveVolumeID(const TString &name)
Returns the id of an active volume giving as parameter its name.
unsigned int GetNumberOfActiveVolumes() const
Returns the number of active volumes, or geometry volumes that have been selected for data storage.
TString GetActiveVolumeName(Int_t n) const
Returns a std::string with the name of the active volume with index n.
TRestGeant4ParticleSource * GetParticleSource(size_t n=0) const
Returns the name of the particle source with index n (Geant4 based names).
endl_t RESTendl
Termination flag object for TRestStringOutput.
TiXmlElement * GetElement(std::string eleDeclare, TiXmlElement *e=nullptr)
Get an xml element from a given parent element, according to its declaration.
Int_t LoadConfigFromFile(const std::string &configFilename, const std::string &sectionName="")
Give the file name, find out the corresponding section. Then call the main starter.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
TRestStringOutput::REST_Verbose_Level GetVerboseLevel()
returns the verboselevel in type of REST_Verbose_Level enumerator
void SetSectionName(std::string sName)
set the section name, clear the section content
@ REST_Debug
+show the defined debug messages
std::string ToUpper(std::string in)
Convert string to its upper case. Alternative of TString::ToUpper.