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" 34 theData = std::make_shared<MaterialBudgetData>();
40 std::vector<std::string> volList = m_Anal.getParameter< std::vector<std::string> >(
"SelectedVolumes");
42 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: List of the selected volumes:";
43 for(
const auto& it : volList) {
51 if(theHistoList ==
"Tracker" ) {
52 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: running in Tracker Mode";
54 else if(theHistoList ==
"ECAL" ) {
55 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: running in Ecal Mode";
57 else if(theHistoList ==
"HGCal" ) {
58 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: running in HGCal Mode";
61 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: running in General Mode";
70 if( saveToHistosFile !=
"None" ) {
72 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: saving histograms to " << saveToHistosFile;
74 if(theHistoList ==
"Tracker" ) {
77 else if (theHistoList ==
"ECAL") {
80 else if (theHistoList ==
"HGCal") {
83 theData->setHGCalmode(
true);
89 edm::LogWarning(
"MaterialBudget") <<
"MaterialBudgetAction: No histograms file specified";
95 if( saveToTxtFile !=
"None" ) {
97 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: saving text info to " << saveToTxtFile;
98 theTxt = std::make_shared<MaterialBudgetTxt>(
theData, saveToTxtFile );
104 bool allSteps = m_Anal.getParameter<
bool>(
"AllStepsToTree");
105 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: all steps are computed " << allSteps;
106 if( allSteps )
theData->SetAllStepsToTree();
110 if( saveToTreeFile !=
"None" ) {
112 theTree = std::make_shared<MaterialBudgetTree>(
theData, saveToTreeFile );
116 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: saving ROOT TTree to " << saveToTreeFile;
120 storeDecay = m_Anal.getUntrackedParameter<
bool>(
"storeDecay",
false);
121 Ekin = m_Anal.getUntrackedParameter<
double>(
"EminDecayProd",1000.0);
122 edm::LogInfo(
"MaterialBudget") <<
"MaterialBudgetAction: decay products steps are stored (" 123 <<
storeDecay <<
") if their kinetic energy is greater than " 138 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
141 bool volFound =
false;
142 for(
const auto& lvcite: *lvs) {
143 if( lvcite->GetName() == volcite ) {
149 edm::LogWarning(
"MaterialBudget") <<
"MaterialBudgetAction: selected volume not found in geometry " << volcite;
155 bool procFound =
false;
159 G4ParticleTable * partTable = G4ParticleTable::GetParticleTable();
160 int siz = partTable->size();
161 for (
int ii= 0;
ii < siz;
ii++) {
162 G4ParticleDefinition * particle = partTable->GetParticle(
ii);
165 G4ProcessManager * pmanager = particle->GetProcessManager();
166 G4ProcessVector * pvect = pmanager->GetProcessList();
167 int sizproc = pvect->size();
168 for (
int jj = 0;
jj < sizproc;
jj++) {
185 const G4Track * aTrack = (*trk)();
190 LogDebug(
"MaterialBudget") <<
"MaterialBudgetAction: Track ID " << aTrack->GetTrackID()
191 <<
"Track parent ID " << aTrack->GetParentID()
192 <<
"PDG Id. = " << aTrack->GetDefinition()->GetPDGEncoding()
193 <<
"Ekin = " << aTrack->GetKineticEnergy() <<
" MeV";
195 if( aTrack->GetCreatorProcess() )
196 LogDebug(
"MaterialBudget") <<
"MaterialBudgetAction: produced through " << aTrack->GetCreatorProcess()->GetProcessType();
198 if(aTrack->GetTrackID() == 1) {
205 if( aTrack->GetCreatorProcess() ) {
207 aTrack->GetParentID() == 1
211 aTrack->GetKineticEnergy() >
Ekin 215 G4Track * aTracknc =
const_cast<G4Track*
>(aTrack);
216 aTracknc->SetTrackStatus(fStopAndKill);
221 if( aTrack->GetParentID() != 0) {
222 G4Track * aTracknc =
const_cast<G4Track*
>(aTrack);
223 aTracknc->SetTrackStatus(fStopAndKill);
228 theData->dataStartTrack( aTrack );
251 G4Track*
track = aStep->GetTrack();
252 track->SetTrackStatus( fStopAndKill );
261 const G4TouchableHistory* theTouchable
262 = (
const G4TouchableHistory*)(aStepPoint->GetTouchable());
263 G4int num_levels = theTouchable->GetHistoryDepth();
265 if( theTouchable->GetVolume() ) {
266 return theTouchable->GetVolume(num_levels-1)->GetName();
276 const G4TouchableHistory* theTouchable
277 = (
const G4TouchableHistory*)(aStepPoint->GetTouchable());
278 G4int num_levels = theTouchable->GetHistoryDepth();
280 if( theTouchable->GetVolume() ) {
281 return theTouchable->GetVolume(num_levels-3)->GetName();
290 const G4Track * aTrack = (*trk)();
291 theData->dataEndTrack( aTrack );
314 size_t volh = touch->GetHistoryDepth();
315 for(
int ii = volh;
ii >= 0;
ii-- ){
330 if( aStep->GetPostStepPoint()->GetProcessDefinedStep() ==
nullptr)
return false;
331 if( aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() ==
theProcessToStop ) {
332 edm::LogInfo(
"MaterialBudget" )<<
"MaterialBudgetAction :" 333 << aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
bool CheckTouchableInSelectedVolumes(const G4VTouchable *touch)
T getParameter(std::string const &) const
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
std::string getPartName(G4StepPoint *aStepPoint)
std::vector< G4String > theVolumeList
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.