17 #include "G4UImanager.hh"
18 #include "G4UIterminal.hh"
19 #include "G4UItcsh.hh"
20 #include "G4LogicalVolumeStore.hh"
21 #include "G4TouchableHistory.hh"
22 #include "G4VPhysicalVolume.hh"
23 #include "G4VProcess.hh"
24 #include "G4ParticleTable.hh"
25 #include "G4ParticleDefinition.hh"
26 #include "G4ProcessManager.hh"
27 #include "G4TransportationManager.hh"
28 #include "DD4hep/Filter.h"
34 theData = std::make_shared<MaterialBudgetData>();
40 std::vector<std::string> volList = m_Anal.
getParameter<std::vector<std::string> >(
"SelectedVolumes");
42 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: List of the selected volumes:";
43 for (
const auto& it : volList) {
52 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: running in Tracker Mode";
54 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: running in Ecal Mode";
56 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: running in Mtd Mode";
58 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: running in HGCal Mode";
60 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: running in General Mode";
69 if (saveToHistosFile !=
"None") {
71 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: saving histograms to " << saveToHistosFile;
105 edm::LogWarning(
"MaterialBudget") <<
"MaterialBudgetAction: No histograms file specified";
111 if (saveToTxtFile !=
"None") {
113 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: saving text info to " << saveToTxtFile;
114 theTxt = std::make_shared<MaterialBudgetTxt>(
theData, saveToTxtFile);
120 bool allSteps = m_Anal.
getParameter<
bool>(
"AllStepsToTree");
121 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: all steps are computed " << allSteps;
127 if (saveToTreeFile !=
"None") {
129 theTree = std::make_shared<MaterialBudgetTree>(
theData, saveToTreeFile);
133 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: saving ROOT TTree to " << saveToTreeFile;
140 <<
") if their kinetic energy is greater than " <<
Ekin <<
" MeV";
150 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
153 bool volFound =
false;
154 for (
const auto& lvcite : *lvs) {
155 if (static_cast<std::string>(dd4hep::dd::noNamespace(lvcite->GetName())) == static_cast<std::string>(volcite)) {
161 edm::LogWarning(
"MaterialBudget") <<
"MaterialBudgetAction: selected volume not found in geometry " << volcite;
166 bool procFound =
false;
170 G4ParticleTable* partTable = G4ParticleTable::GetParticleTable();
171 int siz = partTable->size();
172 for (
int ii = 0;
ii < siz;
ii++) {
173 G4ParticleDefinition* particle = partTable->GetParticle(
ii);
176 G4ProcessManager* pmanager = particle->GetProcessManager();
177 G4ProcessVector* pvect = pmanager->GetProcessList();
178 int sizproc = pvect->size();
179 for (
int jj = 0;
jj < sizproc;
jj++) {
189 edm::LogWarning(
"MaterialBudget") <<
"MaterialBudgetAction: selected process to stop tracking not found "
196 const G4Track* aTrack = (*trk)();
201 LogDebug(
"MaterialBudget") <<
"MaterialBudgetAction: Track ID " << aTrack->GetTrackID() <<
"Track parent ID "
202 << aTrack->GetParentID() <<
"PDG Id. = " << aTrack->GetDefinition()->GetPDGEncoding()
203 <<
"Ekin = " << aTrack->GetKineticEnergy() <<
" MeV";
205 if (aTrack->GetCreatorProcess())
206 LogDebug(
"MaterialBudget") <<
"MaterialBudgetAction: produced through "
207 << aTrack->GetCreatorProcess()->GetProcessType();
209 if (aTrack->GetTrackID() == 1) {
216 if (aTrack->GetCreatorProcess()) {
217 if (aTrack->GetParentID() == 1 &&
220 aTrack->GetKineticEnergy() >
Ekin) {
223 G4Track* aTracknc = const_cast<G4Track*>(aTrack);
224 aTracknc->SetTrackStatus(fStopAndKill);
229 if (aTrack->GetParentID() != 0) {
230 G4Track* aTracknc = const_cast<G4Track*>(aTrack);
231 aTracknc->SetTrackStatus(fStopAndKill);
236 theData->dataStartTrack(aTrack);
265 G4Track*
track = aStep->GetTrack();
266 track->SetTrackStatus(fStopAndKill);
274 const G4TouchableHistory* theTouchable = (
const G4TouchableHistory*)(aStepPoint->GetTouchable());
275 G4int num_levels = theTouchable->GetHistoryDepth();
277 if (theTouchable->GetVolume()) {
278 return static_cast<std::string>(dd4hep::dd::noNamespace(theTouchable->GetVolume(num_levels - 1)->GetName()));
286 const G4TouchableHistory* theTouchable = (
const G4TouchableHistory*)(aStepPoint->GetTouchable());
287 G4int num_levels = theTouchable->GetHistoryDepth();
289 if (theTouchable->GetVolume()) {
290 return static_cast<std::string>(dd4hep::dd::noNamespace(theTouchable->GetVolume(num_levels - 3)->GetName()));
298 const G4Track* aTrack = (*trk)();
326 size_t volh = touch->GetHistoryDepth();
327 for (
int ii = volh;
ii >= 0;
ii--) {
328 G4String
name = static_cast<std::string>(dd4hep::dd::noNamespace(touch->GetVolume(
ii)->GetName()));
340 if (aStep->GetPostStepPoint()->GetProcessDefinedStep() ==
nullptr)
342 if (aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() ==
theProcessToStop) {
344 << aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();