195 #include "TRestGeant4AnalysisProcess.h"
221 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
239 fG4Metadata =
nullptr;
240 SetSectionName(this->ClassName());
241 SetLibraryVersion(LIBRARY_VERSION);
243 fInputG4Event =
nullptr;
260 if (LoadConfigFromFile(configFilename, name)) LoadDefaultConfig();
269 fG4Metadata = GetMetadata<TRestGeant4Metadata>();
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();
290 Int_t volId = fG4Metadata->GetActiveVolumeID(volName);
292 fEnergyInObservables.push_back(fObservables[i]);
293 fVolumeID.push_back(volId);
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;
308 for (
unsigned int n = 0; n < fG4Metadata->GetNumberOfActiveVolumes(); n++)
309 cout <<
"Volume " << n <<
" : " << fG4Metadata->GetActiveVolumeName(n) << 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);
319 Int_t volId2 = fG4Metadata->GetActiveVolumeID(volName2);
321 fMeanPosObservables.push_back(fObservables[i]);
322 fVolumeID2.push_back(volId2);
323 fDirID.push_back(dirId);
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;
337 for (
unsigned int n = 0; n < fG4Metadata->GetNumberOfActiveVolumes(); n++)
338 cout <<
"Volume " << n <<
" : " << fG4Metadata->GetActiveVolumeName(n) << 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();
372 Int_t volId3 = fG4Metadata->GetActiveVolumeID(volName3);
375 fProcessObservables.push_back(fObservables[i]);
376 fVolumeID3.push_back(volId3);
377 fProcessName.emplace_back(processName.Data());
380 if (fObservables[i].find(
"TracksCounter") != string::npos) {
381 TString particleName = fObservables[i].substr(0, fObservables[i].length() - 13).c_str();
382 fTrackCounterObservables.push_back(fObservables[i]);
383 fParticleTrackCounter.emplace_back(particleName.Data());
386 if (fObservables[i].find(
"TracksEDep") != string::npos) {
387 TString particleName = fObservables[i].substr(0, fObservables[i].length() - 10).c_str();
388 fTracksEDepObservables.push_back(fObservables[i]);
389 fParticleTrackEdep.emplace_back(particleName.Data());
401 const auto sensitiveVolumeName = fG4Metadata->GetSensitiveVolume();
403 Double_t sensitiveVolumeEnergy = fOutputG4Event->GetEnergyInVolume(sensitiveVolumeName.Data());
405 double hitTime = std::numeric_limits<double>::infinity();
406 for (
const auto& track : fOutputG4Event->GetTracks()) {
407 const auto hits = track.GetHits();
408 for (
size_t hitIndex = 0; hitIndex < hits.GetNumberOfHits(); hitIndex++) {
409 const auto volumeName = hits.GetVolumeName(hitIndex);
410 if (volumeName != sensitiveVolumeName) {
413 const double energy = hits.GetEnergy(hitIndex);
418 const double time = hits.GetTime(hitIndex);
419 if (time < hitTime) {
424 SetObservableValue(
"sensitiveVolumeFirstHitTime", hitTime);
427 cout <<
"----------------------------" << endl;
428 cout <<
"TRestGeant4Event : " << fOutputG4Event->GetID() << endl;
429 cout <<
"Sensitive volume Energy : " << sensitiveVolumeEnergy << endl;
430 cout <<
"Total energy : " << fOutputG4Event->GetTotalDepositedEnergy() << endl;
433 SetObservableValue(
"sensitiveVolumeEnergy", sensitiveVolumeEnergy);
435 Double_t xOrigin = fOutputG4Event->GetPrimaryEventOrigin().X();
436 SetObservableValue(
"xOriginPrimary", xOrigin);
438 Double_t yOrigin = fOutputG4Event->GetPrimaryEventOrigin().Y();
439 SetObservableValue(
"yOriginPrimary", yOrigin);
441 Double_t zOrigin = fOutputG4Event->GetPrimaryEventOrigin().Z();
442 SetObservableValue(
"zOriginPrimary", zOrigin);
444 Double_t xDirection = fOutputG4Event->GetPrimaryEventDirection(0).X();
445 SetObservableValue(
"xDirectionPrimary", xDirection);
447 Double_t yDirection = fOutputG4Event->GetPrimaryEventDirection(0).Y();
448 SetObservableValue(
"yDirectionPrimary", yDirection);
450 Double_t zDirection = fOutputG4Event->GetPrimaryEventDirection(0).Z();
451 SetObservableValue(
"zDirectionPrimary", zDirection);
453 TVector3 v(xDirection, yDirection, zDirection);
454 SetObservableValue(
"thetaPrimary", v.Theta());
455 SetObservableValue(
"phiPrimary", v.Phi());
457 Double_t energyPrimary = fOutputG4Event->GetPrimaryEventEnergy(0);
458 SetObservableValue(
"energyPrimary", energyPrimary);
460 Double_t energyTotal = fOutputG4Event->GetTotalDepositedEnergy();
461 SetObservableValue(
"totalEdep", energyTotal);
463 Double_t size = fOutputG4Event->GetBoundingBoxSize();
464 SetObservableValue(
"boundingSize", size);
469 vector<string> processNames = {
"phot",
"compt"};
470 for (
auto& processName : processNames) {
471 Int_t containsProcess = 0;
472 if (fOutputG4Event->ContainsProcess(fG4Metadata->GetGeant4PhysicsInfo().GetProcessID(processName))) {
476 if (!processName.empty()) {
477 processName[0] = toupper(processName[0]);
478 SetObservableValue(
"containsProcess" + processName, containsProcess);
482 for (
unsigned int n = 0; n < fParticleTrackCounter.size(); n++) {
483 Int_t nT = fOutputG4Event->GetNumberOfTracksForParticle(fParticleTrackCounter[n]);
484 string obsName = fTrackCounterObservables[n];
485 SetObservableValue(obsName, nT);
488 for (
unsigned int n = 0; n < fTracksEDepObservables.size(); n++) {
489 Double_t energy = fOutputG4Event->GetEnergyDepositedByParticle(fParticleTrackEdep[n]);
490 string obsName = fTracksEDepObservables[n];
491 SetObservableValue(obsName, energy);
494 for (
unsigned int n = 0; n < fEnergyInObservables.size(); n++) {
495 Double_t en = fOutputG4Event->GetEnergyInVolume(fVolumeName[n]);
496 string obsName = fEnergyInObservables[n];
497 SetObservableValue(obsName, en);
500 for (
unsigned int n = 0; n < fMeanPosObservables.size(); n++) {
501 string obsName = fMeanPosObservables[n];
504 if (fDirID[n] == (TString)
"X")
505 mpos = fOutputG4Event->GetMeanPositionInVolume(fVolumeID2[n]).X();
507 else if (fDirID[n] == (TString)
"Y")
508 mpos = fOutputG4Event->GetMeanPositionInVolume(fVolumeID2[n]).Y();
510 else if (fDirID[n] == (TString)
"Z")
511 mpos = fOutputG4Event->GetMeanPositionInVolume(fVolumeID2[n]).Z();
513 SetObservableValue(obsName, mpos);
517 cout <<
"G4 Tracks : " << fOutputG4Event->GetNumberOfTracks() << endl;
518 cout <<
"----------------------------" << endl;
521 return fOutputG4Event;
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.
void InitProcess() override
Process initialization. Observable names are interpreted and auxiliar observable members,...
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
~TRestGeant4AnalysisProcess()
Default destructor.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
TRestGeant4AnalysisProcess()
Default constructor.
void EndProcess() override
Function to include required actions after all events have been processed.
An event class to store geant4 generated event information.
@ REST_Debug
+show the defined debug messages