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) {
51 if (theHistoList ==
"Tracker") {
52 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: running in Tracker Mode";
53 }
else if (theHistoList ==
"ECAL") {
54 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: running in Ecal Mode";
55 }
else if (theHistoList ==
"Mtd") {
56 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetAction: running in Mtd Mode";
57 }
else if (theHistoList ==
"HGCal") {
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;
73 if (theHistoList ==
"Tracker") {
75 }
else if (theHistoList ==
"ECAL") {
77 }
else if (theHistoList ==
"Mtd") {
79 theData->setMtdmode(
true);
80 }
else if (theHistoList ==
"HGCal") {
84 m_Anal.getParameter<
double>(
"minZ"),
85 m_Anal.getParameter<
double>(
"maxZ"),
86 m_Anal.getParameter<
int>(
"nintZ"),
87 m_Anal.getParameter<
double>(
"rMin"),
88 m_Anal.getParameter<
double>(
"rMax"),
89 m_Anal.getParameter<
int>(
"nrbin"),
90 m_Anal.getParameter<
double>(
"etaMin"),
91 m_Anal.getParameter<
double>(
"etaMax"),
92 m_Anal.getParameter<
int>(
"netabin"),
93 m_Anal.getParameter<
double>(
"phiMin"),
94 m_Anal.getParameter<
double>(
"phiMax"),
95 m_Anal.getParameter<
int>(
"nphibin"),
96 m_Anal.getParameter<
double>(
"RMin"),
97 m_Anal.getParameter<
double>(
"RMax"),
98 m_Anal.getParameter<
int>(
"nRbin"));
100 theData->setHGCalmode(
true);
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;
137 storeDecay = m_Anal.getUntrackedParameter<
bool>(
"storeDecay",
false);
138 Ekin = m_Anal.getUntrackedParameter<
double>(
"EminDecayProd", 1000.0);
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();
bool CheckTouchableInSelectedVolumes(const G4VTouchable *touch)
Log< level::Info, true > LogVerbatim
std::shared_ptr< MaterialBudgetFormat > theHistos
MaterialBudgetAction(const edm::ParameterSet &)
std::shared_ptr< TestHistoMgr > theHistoMgr
std::shared_ptr< MaterialBudgetTxt > theTxt
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
G4String theProcessToStop
std::shared_ptr< MaterialBudgetTree > theTree
bool StopAfterProcess(const G4Step *aStep)
~MaterialBudgetAction() override
T getParameter(std::string const &) const
std::string getPartName(G4StepPoint *aStepPoint)
std::vector< G4String > theVolumeList
Log< level::Warning, false > LogWarning
std::string getSubDetectorName(G4StepPoint *aStepPoint)
std::shared_ptr< MaterialBudgetData > theData
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.