62 #include "TRestGeant4ToDetectorHitsProcess.h"
88 if (LoadConfigFromFile(configFilename)) {
102 SetTitle(
"Default config");
104 cout <<
"Geant4 to hits metadata not found. Loading default values" << endl;
112 SetSectionName(this->ClassName());
113 SetLibraryVersion(LIBRARY_VERSION);
115 fGeant4Event =
nullptr;
132 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
140 fGeant4Metadata = GetMetadata<TRestGeant4Metadata>();
142 for (
const auto& userVolume : fVolumeSelection) {
143 if (fGeant4Metadata->GetActiveVolumeID(userVolume) >= 0) {
144 fVolumeId.push_back(fGeant4Metadata->GetActiveVolumeID(userVolume));
145 }
else if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Warning)
146 cout <<
"TRestGeant4ToDetectorHitsProcess. volume name : " << userVolume
147 <<
" not found and will not be added." << endl;
150 sort(fVolumeId.begin(), fVolumeId.end());
151 fVolumeId.erase(unique(fVolumeId.begin(), fVolumeId.end()), fVolumeId.end());
153 for (
size_t i = 0; i < fVolumeId.size(); i++) {
154 RESTDebug <<
"TRestGeant4ToDetectorHitsProcess. Volume id : " << fVolumeId[i]
155 <<
" name : " << fGeant4Metadata->GetActiveVolumeName(fVolumeId[i]) << RESTendl;
158 RESTDebug <<
"Active volumes available in TRestGeant4Metadata" << RESTendl;
159 RESTDebug <<
"-------------------------------------------" << RESTendl;
160 for (
unsigned int n = 0; n < fGeant4Metadata->GetNumberOfActiveVolumes(); n++) {
161 RESTDebug <<
"Volume id : " << n <<
" name : " << fGeant4Metadata->GetActiveVolumeName(n) << RESTendl;
163 RESTDebug << RESTendl;
165 RESTDebug <<
"TRestGeant4HitsProcess volumes enabled in RML : ";
166 RESTDebug <<
"-------------------------------------------" << RESTendl;
167 if (fVolumeSelection.empty())
168 RESTDebug <<
"all" << RESTendl;
170 for (
const auto& volume : fVolumeSelection) {
171 RESTDebug <<
"" << RESTendl;
172 RESTDebug <<
" - " << volume << RESTendl;
174 RESTDebug <<
" " << RESTendl;
177 if (!fVolumeSelection.empty() && fVolumeSelection.size() != fVolumeId.size())
178 RESTWarning <<
"TRestGeant4ToDetectorHitsProcess. Not all volumes were properly identified!"
181 if (!fVolumeId.empty()) {
182 RESTDebug <<
"TRestGeant4HitsProcess volumes identified : ";
183 RESTDebug <<
"---------------------------------------" << RESTendl;
184 if (fVolumeSelection.empty())
185 RESTDebug <<
"all" << RESTendl;
187 for (
const auto& volume : fVolumeSelection) {
188 RESTDebug <<
"" << RESTendl;
189 RESTDebug <<
" - " << volume << RESTendl;
191 RESTDebug <<
" " << RESTendl;
204 cout <<
"------ TRestGeant4ToDetectorHitsProcess --- Printing Input Event --- START ----" << endl;
205 fGeant4Event->PrintEvent();
206 cout <<
"------ TRestGeant4ToDetectorHitsProcess --- Printing Input Event ---- END ----" << endl;
210 fHitsEvent->SetRunOrigin(fGeant4Event->GetRunOrigin());
211 fHitsEvent->SetSubRunOrigin(fGeant4Event->GetSubRunOrigin());
212 fHitsEvent->SetID(fGeant4Event->GetID());
213 fHitsEvent->SetSubID(fGeant4Event->GetSubID());
214 fHitsEvent->SetSubEventTag(fGeant4Event->GetSubEventTag());
215 fHitsEvent->SetTimeStamp(fGeant4Event->GetTimeStamp());
216 fHitsEvent->SetState(fGeant4Event->isOk());
218 for (
const auto& track : fGeant4Event->GetTracks()) {
219 const auto& hits = track.GetHits();
220 for (
unsigned int i = 0; i < track.GetNumberOfHits(); i++) {
221 const auto energy = hits.GetEnergy(i);
225 const TVector3& position = hits.GetPosition(i);
226 const double time = hits.GetTime(i);
229 cerr <<
"TRestGeant4ToDetectorHitsProcess. Negative time found. This should never happen"
233 if (fVolumeId.empty()) {
235 fHitsEvent->AddHit(position.X(), position.Y(), position.Z(), energy, time);
237 const string volumeName = hits.GetVolumeName(i).Data();
238 const auto volumeId = fGeant4Metadata->GetActiveVolumeID(volumeName);
241 if (find(fVolumeId.begin(), fVolumeId.end(), volumeId) != fVolumeId.end()) {
242 const REST_HitType type = fHitTypes.at(volumeName);
244 fHitsEvent->AddHit(position, energy, time, type);
251 cout <<
"TRestGeant4ToDetectorHitsProcess. Hits added : " << fHitsEvent->GetNumberOfHits() << endl;
252 cout <<
"TRestGeant4ToDetectorHitsProcess. Hits total energy : " << fHitsEvent->GetTotalEnergy()
265 fGeant4Metadata = GetMetadata<TRestGeant4Metadata>();
266 if (fGeant4Metadata ==
nullptr) {
267 RESTWarning <<
"TRestGeant4ToDetectorHitsProcess. No TRestGeant4Metadata found in the input file"
271 set<string> volumesToAdd;
272 TiXmlElement* volumeDefinition = GetElement(
"volume");
273 if (volumeDefinition ==
nullptr) {
274 volumeDefinition = GetElement(
"addVolume");
275 if (volumeDefinition !=
nullptr) {
276 RESTWarning <<
"TRestGeant4ToDetectorHitsProcess. 'addVolume' tag is deprecated. Please use "
281 while (volumeDefinition !=
nullptr) {
282 const auto userVolume = GetFieldValue(
"name", volumeDefinition);
283 const auto typeName = GetFieldValue(
"type", volumeDefinition);
284 REST_HitType type = XYZ;
285 if (typeName ==
"veto") {
289 if (userVolume ==
"Not defined") {
290 RESTError <<
"TRestGeant4ToDetectorHitsProcess. No name defined for volume" << RESTendl;
292 if (fGeant4Metadata !=
nullptr) {
293 const auto& geometryInfo = fGeant4Metadata->GetGeant4GeometryInfo();
295 auto physicalVolumes = geometryInfo.GetAllPhysicalVolumesMatchingExpression(userVolume);
296 if (physicalVolumes.empty()) {
297 const auto logicalVolumes = geometryInfo.GetAllLogicalVolumesMatchingExpression(userVolume);
298 for (
const auto& logicalVolume : logicalVolumes) {
299 for (
const auto& physicalVolume :
300 geometryInfo.GetAllPhysicalVolumesFromLogical(logicalVolume)) {
301 physicalVolumes.push_back(
302 geometryInfo.GetAlternativeNameFromGeant4PhysicalName(physicalVolume));
306 for (
const auto& physicalVolume : physicalVolumes) {
307 volumesToAdd.insert(physicalVolume.Data());
308 fHitTypes[physicalVolume.Data()] = type;
311 volumesToAdd.insert(userVolume);
312 fHitTypes[userVolume] = type;
315 volumeDefinition = GetNextElement(volumeDefinition);
318 for (
const auto& volume : volumesToAdd) {
319 if (find(fVolumeSelection.begin(), fVolumeSelection.end(), volume) == fVolumeSelection.end()) {
320 fVolumeSelection.emplace_back(volume);
331 for (
const auto& volume : fVolumeSelection) {
332 RESTMetadata <<
"Volume added : " << volume << RESTendl;
A base class for any REST event.
virtual void InitializeReferences(TRestRun *run)
Initialize dynamical references when loading the event from a root file.
An event class to store geant4 generated event information.
A process to transform a TRestGeant4Event into a TRestDetectorHitsEvent.
void Initialize() override
Function to initialize input/output event members and define the section name.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
TRestGeant4ToDetectorHitsProcess()
Default constructor.
~TRestGeant4ToDetectorHitsProcess() override
Default destructor.
void InitProcess() override
Process initialization. This process accesses the information inside TRestGeant4Metadata to identify ...
void InitFromConfigFile() override
Function to read input parameters from the RML TRestGeant4ToDetectorHitsProcess metadata section.
void PrintMetadata() override
It prints on screen relevant data members from this class.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
@ REST_Extreme
show everything
@ REST_Debug
+show the defined debug messages
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.