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"
33 theData = std::make_shared<MaterialBudgetData>();
39 std::vector<std::string> volList = m_Anal.
getParameter<std::vector<std::string> >(
"SelectedVolumes");
41 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: List of the selected volumes:";
42 for (
const auto& it : volList) {
51 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: running in Tracker Mode";
53 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: running in Ecal Mode";
55 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: running in Mtd Mode";
57 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: running in HGCal Mode";
59 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: running in General Mode";
68 if (saveToHistosFile !=
"None") {
70 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: saving histograms to " << saveToHistosFile;
104 edm::LogWarning(
"MaterialBudget") <<
"MaterialBudgetAction: No histograms file specified";
110 if (saveToTxtFile !=
"None") {
112 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: saving text info to " << saveToTxtFile;
113 theTxt = std::make_shared<MaterialBudgetTxt>(
theData, saveToTxtFile);
119 bool allSteps = m_Anal.
getParameter<
bool>(
"AllStepsToTree");
120 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: all steps are computed " << allSteps;
126 if (saveToTreeFile !=
"None") {
128 theTree = std::make_shared<MaterialBudgetTree>(
theData, saveToTreeFile);
132 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: saving ROOT TTree to " << saveToTreeFile;
139 <<
") if their kinetic energy is greater than " <<
Ekin <<
" MeV";
149 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
152 bool volFound =
false;
153 for (
const auto& lvcite : *lvs) {
154 if (lvcite->GetName() == volcite) {
160 edm::LogWarning(
"MaterialBudget") <<
"MaterialBudgetAction: selected volume not found in geometry " << volcite;
165 bool procFound =
false;
169 G4ParticleTable* partTable = G4ParticleTable::GetParticleTable();
170 int siz = partTable->size();
171 for (
int ii = 0;
ii < siz;
ii++) {
172 G4ParticleDefinition* particle = partTable->GetParticle(
ii);
175 G4ProcessManager* pmanager = particle->GetProcessManager();
176 G4ProcessVector* pvect = pmanager->GetProcessList();
177 int sizproc = pvect->size();
178 for (
int jj = 0;
jj < sizproc;
jj++) {
188 edm::LogWarning(
"MaterialBudget") <<
"MaterialBudgetAction: selected process to stop tracking not found "
195 const G4Track* aTrack = (*trk)();
200 LogDebug(
"MaterialBudget") <<
"MaterialBudgetAction: Track ID " << aTrack->GetTrackID() <<
"Track parent ID "
201 << aTrack->GetParentID() <<
"PDG Id. = " << aTrack->GetDefinition()->GetPDGEncoding()
202 <<
"Ekin = " << aTrack->GetKineticEnergy() <<
" MeV";
204 if (aTrack->GetCreatorProcess())
205 LogDebug(
"MaterialBudget") <<
"MaterialBudgetAction: produced through "
206 << aTrack->GetCreatorProcess()->GetProcessType();
208 if (aTrack->GetTrackID() == 1) {
215 if (aTrack->GetCreatorProcess()) {
216 if (aTrack->GetParentID() == 1 &&
219 aTrack->GetKineticEnergy() >
Ekin) {
222 G4Track* aTracknc = const_cast<G4Track*>(aTrack);
223 aTracknc->SetTrackStatus(fStopAndKill);
228 if (aTrack->GetParentID() != 0) {
229 G4Track* aTracknc = const_cast<G4Track*>(aTrack);
230 aTracknc->SetTrackStatus(fStopAndKill);
235 theData->dataStartTrack(aTrack);
264 G4Track*
track = aStep->GetTrack();
265 track->SetTrackStatus(fStopAndKill);
273 const G4TouchableHistory* theTouchable = (
const G4TouchableHistory*)(aStepPoint->GetTouchable());
274 G4int num_levels = theTouchable->GetHistoryDepth();
276 if (theTouchable->GetVolume()) {
277 return theTouchable->GetVolume(num_levels - 1)->GetName();
285 const G4TouchableHistory* theTouchable = (
const G4TouchableHistory*)(aStepPoint->GetTouchable());
286 G4int num_levels = theTouchable->GetHistoryDepth();
288 if (theTouchable->GetVolume()) {
289 return theTouchable->GetVolume(num_levels - 3)->GetName();
297 const G4Track* aTrack = (*trk)();
325 size_t volh = touch->GetHistoryDepth();
326 for (
int ii = volh;
ii >= 0;
ii--) {
338 if (aStep->GetPostStepPoint()->GetProcessDefinedStep() ==
nullptr)
340 if (aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() ==
theProcessToStop) {
341 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction :"
342 << aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();