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

Common Output in GateToTree #680

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions source/digits_hits/include/GateToTree.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public:
static void SetOutputIDName(G4int id_system, const char * anOutputIDName, size_t depth);
G4bool getHitsEnabled() const;
void setHitsEnabled(G4bool mHitsEnabled);

G4bool getHitsCommonOutputEnabled() const;
void setHitsCommonOutputEnabled(G4bool mHitsCommonOutputEnabled);

void addCollection(const std::string &str); //called by messenger
//OK GND 2022
void setCCenabled(G4bool mCCenabled){m_cc_enabled=mCCenabled;};
Expand Down Expand Up @@ -135,6 +139,7 @@ private:
std::vector<std::string> m_listOfSinglesCollection;
std::vector<std::string> m_listOfCoincidencesCollection;
G4bool m_hits_enabled;
G4bool m_hitsCommonOutput_enabled;
G4String m_uselessFileName; //only for GiveNameOfFile which return a reference..

G4bool m_opticalData_enabled = false;
Expand Down
4 changes: 4 additions & 0 deletions source/digits_hits/include/GateToTreeMessenger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ private:
G4UIcmdWithoutParameter *m_enableHitsOutput;
G4UIcmdWithoutParameter *m_disableHitsOutput;

G4UIcmdWithoutParameter *m_enableHitsCommonOutput;
G4UIcmdWithoutParameter *m_disableHitsCommonOutput;


G4UIcmdWithoutParameter *m_enableOpticalDataOutput;
G4UIcmdWithoutParameter *m_disableOpticalDataOutput;

Expand Down
199 changes: 191 additions & 8 deletions source/digits_hits/src/GateToTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,179 @@ GateToTree::GateToTree(const G4String &name, GateOutputMgr *outputMgr, DigiMode

m_messenger = new GateToTreeMessenger(this);
m_hits_enabled = false;
m_hitsCommonOutput_enabled = false;




}

void GateToTree::RecordBeginOfAcquisition() {
if (m_hits_enabled && m_hitsCommonOutput_enabled)
GateError("Commands /hits/ and /hitsCommonOutput/ cannot be enabled at the same time");

if (!this->IsEnabled())
return;

/* if (m_hits_enabled) {
if (m_hitsCommonOutput_enabled) {
for (auto &&fileName: m_listOfFileName) {
auto extension = getExtension(fileName);
auto name = removeExtension(fileName);

G4String hits_filename = name + ".hits." + extension;
m_manager_hits.add_file(hits_filename, extension);
}
*/
if (m_hitsParams_to_write.at("PDGEncoding").toSave())
m_manager_hits.write_variable("PDGEncoding", &m_PDGEncoding);

if (m_hitsParams_to_write.at("trackID").toSave())
m_manager_hits.write_variable("trackID", &m_trackID);

if (m_hitsParams_to_write.at("parentID").toSave())
m_manager_hits.write_variable("parentID", &m_parentID);

if (m_hitsParams_to_write.at("trackLocalTime").toSave())
m_manager_hits.write_variable("trackLocalTime", &m_trackLocalTime);

if (m_hitsParams_to_write.at("time").toSave())
m_manager_hits.write_variable("time", &m_time[0]);

if (m_hitsParams_to_write.at("runID").toSave())
m_manager_hits.write_variable("runID", &m_runID);

if (m_hitsParams_to_write.at("eventID").toSave())
m_manager_hits.write_variable("eventID", &m_eventID[0]);

if (m_hitsParams_to_write.at("sourceID").toSave())
m_manager_hits.write_variable("sourceID", &m_sourceID[0]);

if (m_hitsParams_to_write.at("primaryID").toSave())
m_manager_hits.write_variable("primaryID", &m_primaryID);

if (m_hitsParams_to_write.at("posX").toSave())
m_manager_hits.write_variable("posX", &m_posX[0]);

if (m_hitsParams_to_write.at("posY").toSave())
m_manager_hits.write_variable("posY", &m_posY[0]);

if (m_hitsParams_to_write.at("posZ").toSave())
m_manager_hits.write_variable("posZ", &m_posZ[0]);

if (m_hitsParams_to_write.at("localPosX").toSave())
m_manager_hits.write_variable("localPosX", &m_localPosX);

if (m_hitsParams_to_write.at("localPosY").toSave())
m_manager_hits.write_variable("localPosY", &m_localPosY);

if (m_hitsParams_to_write.at("localPosZ").toSave())
m_manager_hits.write_variable("localPosZ", &m_localPosZ);

if (m_hitsParams_to_write.at("momDirX").toSave())
m_manager_hits.write_variable("momDirX", &m_momDirX);

if (m_hitsParams_to_write.at("momDirY").toSave())
m_manager_hits.write_variable("momDirY", &m_momDirY);

if (m_hitsParams_to_write.at("momDirZ").toSave())
m_manager_hits.write_variable("momDirZ", &m_momDirZ);

if (m_hitsParams_to_write.at("edep").toSave())
m_manager_hits.write_variable("edep", &m_edep[0]);

if (m_hitsParams_to_write.at("stepLength").toSave())
m_manager_hits.write_variable("stepLength", &m_stepLength);

if (m_hitsParams_to_write.at("trackLength").toSave())
m_manager_hits.write_variable("trackLength", &m_trackLength);

if (m_hitsParams_to_write.at("rotationAngle").toSave())
m_manager_hits.write_variable("rotationAngle", &m_rotationAngle);

if (m_hitsParams_to_write.at("axialPos").toSave())
m_manager_hits.write_variable("axialPos", &m_axialPos);

if (m_hitsParams_to_write.at("processName").toSave())
m_manager_hits.write_variable("processName", &m_processName, MAX_NB_CHARACTER);

if (m_hitsParams_to_write.at("comptVolName").toSave())
m_manager_hits.write_variable("comptVolName", &m_comptonVolumeName[0], MAX_NB_CHARACTER);

if (m_hitsParams_to_write.at("RayleighVolName").toSave())
m_manager_hits.write_variable("RayleighVolName", &m_RayleighVolumeName[0], MAX_NB_CHARACTER);

if (m_hitsParams_to_write.at("volumeIDs").toSave()) {
for (auto i = 0; i < VOLUMEID_SIZE; ++i) {
std::stringstream ss;
ss << "volumeID[" << i << "]";
m_manager_hits.write_variable(ss.str(), &m_volumeID[i]);
}
}

if (m_hitsParams_to_write.at("sourcePosX").toSave())
m_manager_hits.write_variable("sourcePosX", &m_sourcePosX[0]);
if (m_hitsParams_to_write.at("sourcePosY").toSave())
m_manager_hits.write_variable("sourcePosY", &m_sourcePosY[0]);
if (m_hitsParams_to_write.at("sourcePosZ").toSave())
m_manager_hits.write_variable("sourcePosZ", &m_sourcePosZ[0]);

if (m_hitsParams_to_write.at("nPhantomCompton").toSave())
m_manager_hits.write_variable("nPhantomCompton", &m_nPhantomCompton[0]);

if (m_hitsParams_to_write.at("nCrystalCompton").toSave())
m_manager_hits.write_variable("nCrystalCompton", &m_nCrystalCompton[0]);

if (m_hitsParams_to_write.at("nPhantomRayleigh").toSave())
m_manager_hits.write_variable("nPhantomRayleigh", &m_nPhantomRayleigh[0]);

if (m_hitsParams_to_write.at("nCrystalRayleigh").toSave())
m_manager_hits.write_variable("nCrystalRayleigh", &m_nCrystalRayleigh[0]);


if (m_hitsParams_to_write.at("componentsIDs").toSave()) {

if (GateSystemListManager::GetInstance()->size() == 1) {
int k = 0;
for (auto depth = 0; depth < m_max_depth_system[k]; ++depth) {
std::stringstream ss;
ss << m_outputIDName[k][depth];
m_manager_hits.write_variable(ss.str(), &m_outputID[0][k][depth]);
}
} else {
for (unsigned int k = 0; k < GateSystemListManager::GetInstance()->size(); ++k) {
auto system = GateSystemListManager::GetInstance()->GetSystem(k);

for (auto depth = 0; depth < m_max_depth_system[k]; ++depth) {
if (!m_outputIDHasName[k][depth])
continue;
std::stringstream ss;
ss << system->GetOwnName() << "/" << m_outputIDName[k][depth];
m_manager_hits.write_variable(ss.str(), &m_outputID[0][k][depth]);
}
}
}
}

if (m_hitsParams_to_write.at("photonID").toSave())
m_manager_hits.write_variable("photonID", &m_photonID);

if (m_hitsParams_to_write.at("systemID").toSave() && GateSystemListManager::GetInstance()->size() > 1)
m_manager_hits.write_variable("systemID", &m_systemID);

if (m_hitsParams_to_write.at("sourceType").toSave())
m_manager_hits.write_variable("sourceType", &m_sourceType);

if (m_hitsParams_to_write.at("decayType").toSave())
m_manager_hits.write_variable("decayType", &m_decayType);

if (m_hitsParams_to_write.at("gammaType").toSave())
m_manager_hits.write_variable("gammaType", &m_gammaType);


m_manager_hits.write_header();


}

//OK GND 2022
for (auto &&m: m_mmanager_hits)
{
Expand Down Expand Up @@ -691,9 +849,15 @@ void GateToTree::RecordEndOfAcquisition() {
//m_manager_optical.close();

//OK GND 2022

if(m_hitsCommonOutput_enabled)
{
m_manager_hits.close();
}
else
{
for (auto &&m: m_mmanager_hits)
m.second.close();
}

for (auto &&m: m_mmanager_optical)
m.second.close();
Expand All @@ -719,9 +883,10 @@ void GateToTree::RecordBeginOfEvent(const G4Event *event) {
}

void GateToTree::RecordEndOfEvent(const G4Event *event) {
auto fDM = G4DigiManager::GetDMpointer();

//OK GND 2022
auto fDM = G4DigiManager::GetDMpointer();


if (!m_hits_to_collectionID.size()) {
for (auto &&m: m_mmanager_hits) {
Expand Down Expand Up @@ -829,12 +994,19 @@ void GateToTree::RecordEndOfEvent(const G4Event *event) {
m_energyIniT=hit->GetEnergyIniTrack();
}

if(m_hitsCommonOutput_enabled)
{
m_manager_hits.fill();
}
else
{
m.second.fill();
//m_manager_hits.fill();
}

}
}
}
//auto fDM = G4DigiManager::GetDMpointer();

//}
if (!m_singles_to_collectionID.size()) {
for (auto &&m: m_mmanager_singles) {
// auto collectionID = fDM->GetDigiCollectionID(m.first);
Expand Down Expand Up @@ -1083,8 +1255,18 @@ void GateToTree::setHitsEnabled(G4bool mHitsEnabled) {

}

G4bool GateToTree::getHitsCommonOutputEnabled() const {
return m_hitsCommonOutput_enabled;
}

void GateToTree::setHitsCommonOutputEnabled(G4bool mHitsCommonOutputEnabled) {
m_hitsCommonOutput_enabled = mHitsCommonOutputEnabled;
}


//OK GND 2022
void GateToTree::addHitsCollection(const std::string &str) {

GateDigitizerMgr* digitizerMgr = GateDigitizerMgr::GetInstance();

G4String possibleValues = "";
Expand All @@ -1104,7 +1286,8 @@ void GateToTree::addHitsCollection(const std::string &str) {
n_fileName = name + ".hits." + extension;
else
n_fileName = name + ".hits_" + str + "." + extension;
m.add_file(n_fileName, extension);
if(m_hits_enabled)
m.add_file(n_fileName, extension);

}
m_mmanager_hits.emplace(str, std::move(m));
Expand Down
11 changes: 11 additions & 0 deletions source/digits_hits/src/GateToTreeMessenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ GateToTreeMessenger::GateToTreeMessenger(GateToTree *m) :
m_enableHitsOutput = new G4UIcmdWithoutParameter("/gate/output/tree/hits/enable", this);
m_disableHitsOutput = new G4UIcmdWithoutParameter("/gate/output/tree/hits/disable", this);

m_enableHitsCommonOutput = new G4UIcmdWithoutParameter("/gate/output/tree/hitsCommonOutput/enable", this);
m_disableHitsCommonOutput = new G4UIcmdWithoutParameter("/gate/output/tree/hitsCommonOutput/disable", this);


m_enableOpticalDataOutput = new G4UIcmdWithoutParameter("/gate/output/tree/optical/enable", this);
m_disableOpticalDataOutput = new G4UIcmdWithoutParameter("/gate/output/tree/optical/disable", this);

Expand Down Expand Up @@ -103,6 +107,8 @@ GateToTreeMessenger::~GateToTreeMessenger()
delete m_addOpticalCollectionCmd;
delete m_enableHitsOutput;
delete m_disableHitsOutput;
delete m_enableHitsCommonOutput;
delete m_disableHitsCommonOutput;

}

Expand All @@ -119,6 +125,11 @@ void GateToTreeMessenger::SetNewValue(G4UIcommand *icommand, G4String string)
if(icommand == m_disableHitsOutput)
m_gateToTree->setHitsEnabled(false);

if(icommand == m_enableHitsCommonOutput)
m_gateToTree->setHitsCommonOutputEnabled(true);
if(icommand == m_disableHitsCommonOutput)
m_gateToTree->setHitsCommonOutputEnabled(false);

if(icommand == m_enableOpticalDataOutput)
m_gateToTree->setOpticalDataEnabled(true);
if(icommand == m_disableOpticalDataOutput)
Expand Down
Loading