Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 /// \file runAndEvent/RE01/src/RE01EventAction 26 /// \file runAndEvent/RE01/src/RE01EventAction.cc 27 /// \brief Implementation of the RE01EventActi 27 /// \brief Implementation of the RE01EventAction class 28 // 28 // >> 29 // $Id$ 29 // 30 // 30 31 31 #include "RE01EventAction.hh" 32 #include "RE01EventAction.hh" 32 << 33 #include "RE01CalorimeterHit.hh" << 34 #include "RE01TrackerHit.hh" 33 #include "RE01TrackerHit.hh" 35 #include "RE01Trajectory.hh" << 34 #include "RE01CalorimeterHit.hh" 36 35 37 #include "G4Event.hh" 36 #include "G4Event.hh" 38 #include "G4EventManager.hh" 37 #include "G4EventManager.hh" 39 #include "G4HCofThisEvent.hh" 38 #include "G4HCofThisEvent.hh" 40 #include "G4PrimaryParticle.hh" << 41 #include "G4PrimaryVertex.hh" << 42 #include "G4SDManager.hh" << 43 #include "G4SystemOfUnits.hh" << 44 #include "G4TrajectoryContainer.hh" << 45 #include "G4UImanager.hh" << 46 #include "G4VHitsCollection.hh" 39 #include "G4VHitsCollection.hh" >> 40 #include "G4TrajectoryContainer.hh" 47 #include "G4VVisManager.hh" 41 #include "G4VVisManager.hh" >> 42 #include "G4SDManager.hh" >> 43 #include "G4UImanager.hh" 48 #include "G4ios.hh" 44 #include "G4ios.hh" >> 45 #include "RE01Trajectory.hh" >> 46 #include "G4PrimaryVertex.hh" >> 47 #include "G4PrimaryParticle.hh" >> 48 #include "G4SystemOfUnits.hh" 49 49 50 //....oooOO0OOooo........oooOO0OOooo........oo << 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 RE01EventAction::RE01EventAction() : G4UserEve << 51 RE01EventAction::RE01EventAction() 52 { << 52 :G4UserEventAction(), 53 ; << 53 fTrackerCollID(-1),fCalorimeterCollID(-1),fMuonCollID(-1) 54 } << 54 {;} 55 55 56 //....oooOO0OOooo........oooOO0OOooo........oo << 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 RE01EventAction::~RE01EventAction() 57 RE01EventAction::~RE01EventAction() 58 { << 58 {;} 59 ; << 60 } << 61 59 62 //....oooOO0OOooo........oooOO0OOooo........oo << 60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 void RE01EventAction::BeginOfEventAction(const 61 void RE01EventAction::BeginOfEventAction(const G4Event*) 64 { 62 { 65 G4SDManager* SDman = G4SDManager::GetSDMpoin << 63 G4SDManager * SDman = G4SDManager::GetSDMpointer(); 66 if (fTrackerCollID < 0 || fCalorimeterCollID << 64 if(fTrackerCollID<0||fCalorimeterCollID<0||fMuonCollID<0) >> 65 { 67 G4String colNam; 66 G4String colNam; 68 fTrackerCollID = SDman->GetCollectionID(co << 67 fTrackerCollID = SDman->GetCollectionID(colNam="trackerCollection"); 69 fCalorimeterCollID = SDman->GetCollectionI << 68 fCalorimeterCollID = SDman->GetCollectionID(colNam="calCollection"); 70 } 69 } 71 } 70 } 72 71 73 //....oooOO0OOooo........oooOO0OOooo........oo << 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 74 void RE01EventAction::EndOfEventAction(const G 73 void RE01EventAction::EndOfEventAction(const G4Event* evt) 75 { 74 { 76 G4cout << ">>> Summary of Event " << evt->Ge 75 G4cout << ">>> Summary of Event " << evt->GetEventID() << G4endl; 77 if (evt->GetNumberOfPrimaryVertex() == 0) { << 76 78 G4cout << "Event is empty." << G4endl; << 77 if(fTrackerCollID<0||fCalorimeterCollID<0) return; 79 return; << 80 } << 81 << 82 if (fTrackerCollID < 0 || fCalorimeterCollID << 83 78 84 G4HCofThisEvent* HCE = evt->GetHCofThisEvent << 79 G4HCofThisEvent * HCE = evt->GetHCofThisEvent(); 85 RE01TrackerHitsCollection* THC = 0; 80 RE01TrackerHitsCollection* THC = 0; 86 RE01CalorimeterHitsCollection* CHC = 0; 81 RE01CalorimeterHitsCollection* CHC = 0; 87 if (HCE) { << 82 if(HCE) >> 83 { 88 THC = (RE01TrackerHitsCollection*)(HCE->Ge 84 THC = (RE01TrackerHitsCollection*)(HCE->GetHC(fTrackerCollID)); 89 CHC = (RE01CalorimeterHitsCollection*)(HCE 85 CHC = (RE01CalorimeterHitsCollection*)(HCE->GetHC(fCalorimeterCollID)); 90 } 86 } 91 87 92 if (THC) { << 88 if(THC) >> 89 { 93 int n_hit = THC->entries(); 90 int n_hit = THC->entries(); 94 G4cout << G4endl; 91 G4cout << G4endl; 95 G4cout << "Tracker hits " << 92 G4cout << "Tracker hits " << 96 << "------------------------------- << 93 "--------------------------------------------------------------" 97 G4cout << n_hit << " hits are stored in RE << 94 << G4endl; 98 if (fpEventManager->GetVerboseLevel() > 0) << 95 G4cout << n_hit << " hits are stored in RE01TrackerHitsCollection." 99 G4cout << "List of hits in tracker" << G << 96 << G4endl; 100 for (int i = 0; i < n_hit; i++) { << 97 G4cout << "List of hits in tracker" << G4endl; 101 (*THC)[i]->Print(); << 98 for(int i=0;i<n_hit;i++) 102 } << 99 { (*THC)[i]->Print(); } 103 } << 104 } 100 } 105 if (CHC) { << 101 if(CHC) >> 102 { 106 int n_hit = CHC->entries(); 103 int n_hit = CHC->entries(); 107 G4cout << G4endl; 104 G4cout << G4endl; 108 G4cout << "Calorimeter hits " << 105 G4cout << "Calorimeter hits "<< 109 << "------------------------------- << 106 "--------------------------------------------------------------" 110 G4cout << n_hit << " hits are stored in RE << 107 << G4endl; >> 108 G4cout << n_hit << " hits are stored in RE01CalorimeterHitsCollection." >> 109 << G4endl; 111 G4double totE = 0; 110 G4double totE = 0; 112 for (int i = 0; i < n_hit; i++) { << 111 for(int i=0;i<n_hit;i++) 113 totE += (*CHC)[i]->GetEdep(); << 112 { totE += (*CHC)[i]->GetEdep(); } 114 } << 113 G4cout << " Total energy deposition in calorimeter : " 115 G4cout << " Total energy deposition in << 114 << totE / GeV << " (GeV)" << G4endl; 116 } 115 } 117 116 118 // get number of stored trajectories 117 // get number of stored trajectories 119 G4TrajectoryContainer* trajectoryContainer = 118 G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer(); 120 G4int n_trajectories = 0; 119 G4int n_trajectories = 0; 121 if (trajectoryContainer) n_trajectories = tr 120 if (trajectoryContainer) n_trajectories = trajectoryContainer->entries(); 122 // extract the trajectories and print them o 121 // extract the trajectories and print them out 123 G4cout << G4endl; 122 G4cout << G4endl; 124 G4cout << "Trajectories in tracker " << 123 G4cout << "Trajectories in tracker "<< 125 << "--------------------------------- << 124 "--------------------------------------------------------------" 126 if (fpEventManager->GetVerboseLevel() > 0) { << 125 << G4endl; 127 for (G4int i = 0; i < n_trajectories; i++) << 126 for(G4int i=0; i<n_trajectories; i++) 128 RE01Trajectory* trj = (RE01Trajectory*)( << 127 { 129 trj->ShowTrajectory(); << 128 RE01Trajectory* trj = 130 } << 129 (RE01Trajectory*)((*(evt->GetTrajectoryContainer()))[i]); >> 130 trj->ShowTrajectory(); 131 } 131 } 132 << 132 133 G4cout << G4endl; 133 G4cout << G4endl; 134 G4cout << "Primary particles " << 134 G4cout << "Primary particles "<< 135 << "--------------------------------- << 135 "--------------------------------------------------------------" >> 136 << G4endl; 136 G4int n_vertex = evt->GetNumberOfPrimaryVert 137 G4int n_vertex = evt->GetNumberOfPrimaryVertex(); 137 for (G4int iv = 0; iv < n_vertex; iv++) { << 138 for(G4int iv=0;iv<n_vertex;iv++) >> 139 { 138 G4PrimaryVertex* pv = evt->GetPrimaryVerte 140 G4PrimaryVertex* pv = evt->GetPrimaryVertex(iv); 139 G4cout << G4endl; 141 G4cout << G4endl; 140 G4cout << "Primary vertex " << G4ThreeVect << 142 G4cout << "Primary vertex " 141 << " at t = " << (pv->GetT0()) / << 143 << G4ThreeVector(pv->GetX0(),pv->GetY0(),pv->GetZ0()) 142 if (fpEventManager->GetVerboseLevel() > 0) << 144 << " at t = " << (pv->GetT0())/ns << " [ns]" << G4endl; 143 G4PrimaryParticle* pp = pv->GetPrimary() << 145 G4PrimaryParticle* pp = pv->GetPrimary(); 144 while (pp) { << 146 while(pp) 145 PrintPrimary(pp, 0); << 147 { 146 pp = pp->GetNext(); << 148 PrintPrimary(pp,0); 147 } << 149 pp = pp->GetNext(); 148 } 150 } 149 } 151 } 150 } 152 } 151 153 152 //....oooOO0OOooo........oooOO0OOooo........oo << 154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 153 void RE01EventAction::PrintPrimary(G4PrimaryPa << 155 void RE01EventAction::PrintPrimary(G4PrimaryParticle* pp,G4int ind) 154 { 156 { 155 for (G4int ii = 0; ii <= ind; ii++) { << 157 for(G4int ii=0;ii<=ind;ii++) 156 G4cout << " "; << 158 { G4cout << " "; } 157 } << 158 G4cout << "==PDGcode " << pp->GetPDGcode() < 159 G4cout << "==PDGcode " << pp->GetPDGcode() << " "; 159 if (pp->GetG4code() != 0) { << 160 if(pp->GetG4code()!=0) 160 G4cout << "(" << pp->GetG4code()->GetParti << 161 { G4cout << "(" << pp->GetG4code()->GetParticleName() << ")"; } 161 } << 162 else 162 else { << 163 { G4cout << "is not defined in G4"; } 163 G4cout << "is not defined in G4"; << 164 G4cout << " " << pp->GetMomentum()/GeV << " [GeV] "; 164 } << 165 if(pp->GetTrackID()<0) 165 G4cout << " " << pp->GetMomentum() / GeV << << 166 { G4cout << G4endl; } 166 if (pp->GetTrackID() < 0) { << 167 else 167 G4cout << G4endl; << 168 { G4cout << ">>> G4Track ID " << pp->GetTrackID() << G4endl; } 168 } << 169 else { << 170 G4cout << ">>> G4Track ID " << pp->GetTrac << 171 } << 172 169 173 G4PrimaryParticle* daughter = pp->GetDaughte 170 G4PrimaryParticle* daughter = pp->GetDaughter(); 174 while (daughter) { << 171 while(daughter) 175 PrintPrimary(daughter, ind + 1); << 172 { >> 173 PrintPrimary(daughter,ind+1); 176 daughter = daughter->GetNext(); 174 daughter = daughter->GetNext(); 177 } 175 } 178 } 176 } >> 177 >> 178 179 179