16 #include "G4UImanager.hh" 17 #include "G4UIterminal.hh" 18 #include "G4UItcsh.hh" 19 #include "G4LogicalVolumeStore.hh" 20 #include "G4TouchableHistory.hh" 21 #include "G4VPhysicalVolume.hh" 22 #include "G4VProcess.hh" 23 #include "G4ParticleTable.hh" 24 #include "G4ParticleDefinition.hh" 25 #include "G4ProcessManager.hh" 26 #include "G4TransportationManager.hh" 33 theData = std::make_shared<MaterialBudgetData>();
39 std::vector<std::string> volList = m_Anal.getParameter< std::vector<std::string> >(
"SelectedVolumes");
40 std::vector<std::string>::const_iterator ite;
41 std::cout <<
"TestGeometry: List of the selected volumes: " << std::endl;
42 for( ite = volList.begin(); ite != volList.end(); ite++ ){
43 if( (*ite) !=
"None" ) {
49 if(theHistoList ==
"Tracker" ) {
50 std::cout <<
"TestGeometry: MaterialBudgetAction running in Tracker Mode" << std::endl;
52 else if(theHistoList ==
"ECAL" ) {
53 std::cout <<
"TestGeometry: MaterialBudgetAction running in Ecal Mode" << std::endl;
55 else if(theHistoList ==
"HGCal" ) {
56 std::cout <<
"TestGeometry: MaterialBudgetAction running in HGCal Mode" << std::endl;
59 std::cout <<
"TestGeometry: MaterialBudgetAction running in General Mode" << std::endl;
69 if( saveToHistosFile !=
"None" ) {
71 std::cout <<
"TestGeometry: saving histograms to " << saveToHistosFile << std::endl;
74 if(theHistoList ==
"Tracker" ) {
77 else if (theHistoList ==
"ECAL") {
80 else if (theHistoList ==
"HGCal") {
83 theData->setHGCalmode(
true);
95 if( saveToTxtFile !=
"None" ) {
97 std::cout <<
"TestGeometry: saving text info to " << saveToTxtFile << std::endl;
98 theTxt = std::make_shared<MaterialBudgetTxt>(
theData, saveToTxtFile );
104 bool allSteps = m_Anal.getParameter<
bool>(
"AllStepsToTree");
105 std::cout <<
"TestGeometry: all steps are computed " << allSteps << std::endl;
106 if( allSteps )
theData->SetAllStepsToTree();
111 if( saveToTreeFile !=
"None" ) {
113 theTree = std::make_shared<MaterialBudgetTree>(
theData, saveToTreeFile );
117 std::cout <<
"TestGeometry: saving ROOT TREE to " << saveToTreeFile << std::endl;
121 storeDecay = m_Anal.getUntrackedParameter<
bool>(
"storeDecay",
false);
122 Ekin = m_Anal.getUntrackedParameter<
double>(
"EminDecayProd",1000.0);
124 if(storeDecay)
std::cout <<
" if their kinetic energy is greater than " << Ekin <<
" MeV";
139 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
140 std::vector<G4LogicalVolume*>::const_iterator lvcite;
141 std::vector<G4String>::const_iterator volcite;
144 bool volFound =
false;
145 for( lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++ ) {
146 if( (*lvcite)->GetName() == *volcite ) {
152 std::cerr <<
" @@@@@@@ WARNING at MaterialBudgetAction: selected volume not found in geometry " << *volcite << std::endl;
158 bool procFound =
false;
162 G4ParticleTable * partTable = G4ParticleTable::GetParticleTable();
163 int siz = partTable->size();
164 for (
int ii= 0;
ii < siz;
ii++) {
165 G4ParticleDefinition * particle = partTable->GetParticle(
ii);
168 G4ProcessManager * pmanager = particle->GetProcessManager();
169 G4ProcessVector * pvect = pmanager->GetProcessList();
170 int sizproc = pvect->size();
171 for (
int jj = 0;
jj < sizproc;
jj++) {
181 std::cerr <<
" @@@@@@@ WARNING at MaterialBudgetAction: selected process to stop tracking not found " <<
theProcessToStop << std::endl;
190 const G4Track * aTrack = (*trk)();
195 std::cout <<
"Track ID " << aTrack->GetTrackID() <<
" Track parent ID " << aTrack->GetParentID()
196 <<
" PDG Id. = " << aTrack->GetDefinition()->GetPDGEncoding()
197 <<
" Ekin = " << aTrack->GetKineticEnergy() <<
" MeV" << std::endl;
198 if( aTrack->GetCreatorProcess() )
std::cout <<
" produced through " << aTrack->GetCreatorProcess()->GetProcessType() << std::endl;
200 if(aTrack->GetTrackID() == 1) {
207 if( aTrack->GetCreatorProcess() ) {
209 aTrack->GetParentID() == 1
213 aTrack->GetKineticEnergy() >
Ekin 217 G4Track * aTracknc =
const_cast<G4Track*
>(aTrack);
218 aTracknc->SetTrackStatus(fStopAndKill);
223 if( aTrack->GetParentID() != 0) {
224 G4Track * aTracknc =
const_cast<G4Track*
>(aTrack);
225 aTracknc->SetTrackStatus(fStopAndKill);
234 theData->dataStartTrack( aTrack );
260 G4Track*
track = aStep->GetTrack();
261 track->SetTrackStatus( fStopAndKill );
272 const G4TouchableHistory* theTouchable
273 = (
const G4TouchableHistory*)(aStepPoint->GetTouchable());
274 G4int num_levels = theTouchable->GetHistoryDepth();
276 if( theTouchable->GetVolume() ) {
277 return theTouchable->GetVolume(num_levels-1)->GetName();
287 const G4TouchableHistory* theTouchable
288 = (
const G4TouchableHistory*)(aStepPoint->GetTouchable());
289 G4int num_levels = theTouchable->GetHistoryDepth();
292 if( theTouchable->GetVolume() ) {
293 return theTouchable->GetVolume(num_levels-3)->GetName();
302 const G4Track * aTrack = (*trk)();
307 theData->dataEndTrack( aTrack );
325 size_t volh = touch->GetHistoryDepth();
328 for(
int ii = volh;
ii >= 0;
ii-- ){
346 if(aStep->GetPostStepPoint()->GetProcessDefinedStep() ==
nullptr)
return false;
347 if( aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() ==
theProcessToStop ) {
348 std::cout <<
" MaterialBudgetAction::StopAfterProcess " << aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() << std::endl;
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.