Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small changes necessary for https://github.com/rest-for-physics/geant4lib/pull/41 #10

Merged
merged 4 commits into from
Apr 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions src/TRestGeant4ToDetectorHitsProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
/// <hr>
///
#include "TRestGeant4ToDetectorHitsProcess.h"

using namespace std;

ClassImp(TRestGeant4ToDetectorHitsProcess);
Expand Down Expand Up @@ -187,7 +188,7 @@ void TRestGeant4ToDetectorHitsProcess::InitProcess() {
TRestEvent* TRestGeant4ToDetectorHitsProcess::ProcessEvent(TRestEvent* evInput) {
fG4Event = (TRestGeant4Event*)evInput;

if (this->GetVerboseLevel() >= REST_Extreme) {
if (GetVerboseLevel() >= REST_Extreme) {
cout << "------ TRestGeant4ToDetectorHitsProcess --- Printing Input Event --- START ----" << endl;
fG4Event->PrintEvent();
cout << "------ TRestGeant4ToDetectorHitsProcess --- Printing Input Event ---- END ----" << endl;
Expand All @@ -202,30 +203,23 @@ TRestEvent* TRestGeant4ToDetectorHitsProcess::ProcessEvent(TRestEvent* evInput)
fHitsEvent->SetTimeStamp(fG4Event->GetTimeStamp());
fHitsEvent->SetState(fG4Event->isOk());

Int_t i, j;
Double_t x, y, z, E;

for (i = 0; i < fG4Event->GetNumberOfTracks(); i++) {
for (j = 0; j < fG4Event->GetTrack(i)->GetNumberOfHits(); j++) {
// read x,y,z and E of every hit in the G4 event
x = fG4Event->GetTrack(i)->GetHits()->fX[j];
y = fG4Event->GetTrack(i)->GetHits()->fY[j];
z = fG4Event->GetTrack(i)->GetHits()->fZ[j];
E = fG4Event->GetTrack(i)->GetHits()->fEnergy[j];

Bool_t addHit = true;
Copy link
Member

@juanangp juanangp Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, we change the behaviour, by default addHit = true unless the number of volume hits is higher than zero

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, we change the behaviour, by default addHit = true unless the number of volume hits is higher than zero

I am not sure if this refers to the current code (77c74c1), I think the behaviour right now is the same, right?

Copy link
Member

@juanangp juanangp Apr 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not the same, before we had addHit = true if fVolumeId.size() == 0 now we just check hits.GetVolumeId(j) == volumeID). So, in case fVolumeId.size() == 0 (which I would suggest fVolumeId.empty()) we assume addHit = false. Therefore, the logic has been changed.

Bug was indroduced in 4a29a1b

Copy link
Member

@jgalan jgalan Apr 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, however if fVolumeId.size() == 0, then we would have no hits inside the event. In normal conditions, the loop will always go inside, setting addHit=false. Because, if there are hits it means that there was at least one activeVolume and fVolumeId should contain at least 1 volume id.

Except that fVolumeId behaviour would have been changed in restG4.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 53d73ec restores previous logic, perhaps now pipeline passes 🤞🏻

if (fVolumeId.size() > 0) {
addHit = false;
for (unsigned int n = 0; n < fVolumeId.size(); n++)
if (fG4Event->GetTrack(i)->GetHits()->GetVolumeId(j) == fVolumeId[n]) addHit = true;
for (int i = 0; i < fG4Event->GetNumberOfTracks(); i++) {
const auto& track = fG4Event->GetTrack(i);
const auto& hits = track.GetHits();
for (int j = 0; j < track.GetNumberOfHits(); j++) {
const auto energy = hits.GetEnergy(j);
for (const auto& volumeID : fVolumeId) {
if (hits.GetVolumeId(j) == volumeID && energy > 0) {
fHitsEvent->AddHit(hits.GetX(j), hits.GetY(j), hits.GetZ(j), energy);
}
}
if (fVolumeId.empty() && energy > 0) {
lobis marked this conversation as resolved.
Show resolved Hide resolved
fHitsEvent->AddHit(hits.GetX(j), hits.GetY(j), hits.GetZ(j), energy);
}

// and write them in the output hits event:
if (addHit && E > 0) fHitsEvent->AddHit(x, y, z, E);
}
}

if (this->GetVerboseLevel() >= REST_Debug) {
if (GetVerboseLevel() >= REST_Debug) {
cout << "TRestGeant4ToDetectorHitsProcess. Hits added : " << fHitsEvent->GetNumberOfHits() << endl;
cout << "TRestGeant4ToDetectorHitsProcess. Hits total energy : " << fHitsEvent->GetEnergy() << endl;
}
Expand Down