diff --git a/source/digits_hits/include/GateToTree.hh b/source/digits_hits/include/GateToTree.hh index f4937d048..46de07d5c 100644 --- a/source/digits_hits/include/GateToTree.hh +++ b/source/digits_hits/include/GateToTree.hh @@ -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;}; @@ -135,6 +139,7 @@ private: std::vector m_listOfSinglesCollection; std::vector 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; diff --git a/source/digits_hits/include/GateToTreeMessenger.hh b/source/digits_hits/include/GateToTreeMessenger.hh index 27ece011e..2737d38d8 100644 --- a/source/digits_hits/include/GateToTreeMessenger.hh +++ b/source/digits_hits/include/GateToTreeMessenger.hh @@ -41,6 +41,10 @@ private: G4UIcmdWithoutParameter *m_enableHitsOutput; G4UIcmdWithoutParameter *m_disableHitsOutput; + G4UIcmdWithoutParameter *m_enableHitsCommonOutput; + G4UIcmdWithoutParameter *m_disableHitsCommonOutput; + + G4UIcmdWithoutParameter *m_enableOpticalDataOutput; G4UIcmdWithoutParameter *m_disableOpticalDataOutput; diff --git a/source/digits_hits/src/GateToTree.cc b/source/digits_hits/src/GateToTree.cc index 60e12700a..f85f06eaa 100644 --- a/source/digits_hits/src/GateToTree.cc +++ b/source/digits_hits/src/GateToTree.cc @@ -193,13 +193,21 @@ 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); @@ -207,7 +215,157 @@ void GateToTree::RecordBeginOfAcquisition() { 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) { @@ -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(); @@ -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) { @@ -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); @@ -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 = ""; @@ -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)); diff --git a/source/digits_hits/src/GateToTreeMessenger.cc b/source/digits_hits/src/GateToTreeMessenger.cc index 6a4a2ea6c..2e709fb69 100644 --- a/source/digits_hits/src/GateToTreeMessenger.cc +++ b/source/digits_hits/src/GateToTreeMessenger.cc @@ -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); @@ -103,6 +107,8 @@ GateToTreeMessenger::~GateToTreeMessenger() delete m_addOpticalCollectionCmd; delete m_enableHitsOutput; delete m_disableHitsOutput; + delete m_enableHitsCommonOutput; + delete m_disableHitsCommonOutput; } @@ -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)