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 #include "Par03EventAction.hh" 26 #include "Par03EventAction.hh" 27 << 28 #include "Par03DetectorConstruction.hh" << 29 #include "Par03Hit.hh" 27 #include "Par03Hit.hh" >> 28 #include "Par03DetectorConstruction.hh" >> 29 #include "g4analysis.hh" 30 30 31 #include "G4AnalysisManager.hh" << 31 #include "G4SDManager.hh" >> 32 #include "G4HCofThisEvent.hh" 32 #include "G4Event.hh" 33 #include "G4Event.hh" 33 #include "G4EventManager.hh" 34 #include "G4EventManager.hh" 34 #include "G4HCofThisEvent.hh" << 35 #include "G4SDManager.hh" << 36 35 37 Par03EventAction::Par03EventAction(Par03Detect 36 Par03EventAction::Par03EventAction(Par03DetectorConstruction* aDetector) 38 : G4UserEventAction(), fHitCollectionID(-1), << 37 : G4UserEventAction() >> 38 , fHitCollectionID(-1) >> 39 , fTimer() >> 40 , fDetector(aDetector) 39 {} 41 {} 40 42 41 //....oooOO0OOooo........oooOO0OOooo........oo 43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 42 44 43 Par03EventAction::~Par03EventAction() = defaul << 45 Par03EventAction::~Par03EventAction() {} 44 46 45 //....oooOO0OOooo........oooOO0OOooo........oo 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 46 48 47 void Par03EventAction::BeginOfEventAction(cons << 49 void Par03EventAction::BeginOfEventAction(const G4Event*) { fTimer.Start(); } 48 { << 49 fTimer.Start(); << 50 } << 51 50 52 //....oooOO0OOooo........oooOO0OOooo........oo 51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 52 54 void Par03EventAction::EndOfEventAction(const 53 void Par03EventAction::EndOfEventAction(const G4Event* aEvent) 55 { 54 { 56 fTimer.Stop(); 55 fTimer.Stop(); 57 // Get hits collection ID (only once) 56 // Get hits collection ID (only once) 58 if (fHitCollectionID == -1) { << 57 if(fHitCollectionID == -1) >> 58 { 59 fHitCollectionID = G4SDManager::GetSDMpoin 59 fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID("hits"); 60 } 60 } 61 // Get hits collection 61 // Get hits collection 62 auto hitsCollection = << 62 auto hitsCollection = static_cast<Par03HitsCollection*>( 63 static_cast<Par03HitsCollection*>(aEvent-> << 63 aEvent->GetHCofThisEvent()->GetHC(fHitCollectionID)); 64 64 65 if (hitsCollection == nullptr) { << 65 if(hitsCollection == nullptr) >> 66 { 66 G4ExceptionDescription msg; 67 G4ExceptionDescription msg; 67 msg << "Cannot access hitsCollection ID " 68 msg << "Cannot access hitsCollection ID " << fHitCollectionID; 68 G4Exception("Par03EventAction::GetHitsColl << 69 G4Exception("Par03EventAction::GetHitsCollection()", "MyCode0001", >> 70 FatalException, msg); 69 } 71 } 70 // Get analysis manager 72 // Get analysis manager 71 auto analysisManager = G4AnalysisManager::In 73 auto analysisManager = G4AnalysisManager::Instance(); 72 // Retrieve only once detector dimensions 74 // Retrieve only once detector dimensions 73 if (fCellSizeZ == 0) { << 75 if(fCellSizeZ == 0) 74 fCellSizeZ = fDetector->GetLength() / fDet << 76 { >> 77 fCellSizeZ = fDetector->GetLength() / fDetector->GetNbOfLayers(); 75 fCellSizeRho = fDetector->GetRadius() / fD 78 fCellSizeRho = fDetector->GetRadius() / fDetector->GetNbOfRhoCells(); 76 } 79 } 77 80 78 // Retrieve information from primary vertex 81 // Retrieve information from primary vertex and primary particle 79 // To calculate shower axis and entry point 82 // To calculate shower axis and entry point to the detector 80 auto primaryVertex = << 83 auto primaryVertex = G4EventManager::GetEventManager() 81 G4EventManager::GetEventManager()->GetCons << 84 ->GetConstCurrentEvent() 82 auto primaryParticle = primaryVertex->GetPri << 85 ->GetPrimaryVertex(); >> 86 auto primaryParticle = primaryVertex->GetPrimary(0); 83 G4double primaryEnergy = primaryParticle->Ge 87 G4double primaryEnergy = primaryParticle->GetTotalEnergy(); 84 // Estimate from vertex and particle directi 88 // Estimate from vertex and particle direction the entry point to the detector 85 // Calculate entrance point to the detector 89 // Calculate entrance point to the detector located at z = 0 86 auto primaryDirection = primaryParticle->Get 90 auto primaryDirection = primaryParticle->GetMomentumDirection(); 87 auto primaryEntrance = << 91 auto primaryEntrance = primaryVertex->GetPosition() - 88 primaryVertex->GetPosition() - primaryVert << 92 primaryVertex->GetPosition().z() * primaryDirection; 89 G4double cosDirection = std::cos(primaryDire 93 G4double cosDirection = std::cos(primaryDirection.theta()); 90 G4double sinDirection = std::sin(primaryDire 94 G4double sinDirection = std::sin(primaryDirection.theta()); 91 95 92 // Fill histograms 96 // Fill histograms 93 Par03Hit* hit = nullptr; << 97 Par03Hit* hit = nullptr; 94 G4double hitEn = 0; << 98 G4double hitEn = 0; 95 G4double totalEnergy = 0; 99 G4double totalEnergy = 0; 96 G4int hitZ = -1; << 100 G4int hitZ = -1; 97 G4int hitRho = -1; << 101 G4int hitRho = -1; 98 G4int hitType = -1; << 102 G4int hitType = -1; 99 G4double tDistance = 0., rDistance = 0.; 103 G4double tDistance = 0., rDistance = 0.; 100 G4double tFirstMoment = 0., tSecondMoment = 104 G4double tFirstMoment = 0., tSecondMoment = 0.; 101 G4double rFirstMoment = 0., rSecondMoment = 105 G4double rFirstMoment = 0., rSecondMoment = 0.; 102 for (size_t iHit = 0; iHit < hitsCollection- << 106 for(size_t iHit = 0; iHit < hitsCollection->entries(); iHit++) 103 hit = static_cast<Par03Hit*>(hitsCollectio << 107 { 104 hitZ = hit->GetZid(); << 108 hit = static_cast<Par03Hit*>(hitsCollection->GetHit(iHit)); 105 hitRho = hit->GetRhoId(); << 109 hitZ = hit->GetZid(); 106 hitEn = hit->GetEdep(); << 110 hitRho = hit->GetRhoId(); >> 111 hitEn = hit->GetEdep(); 107 hitType = hit->GetType(); 112 hitType = hit->GetType(); 108 if (hitEn > 0) { << 113 if(hitEn > 0) >> 114 { 109 totalEnergy += hitEn; 115 totalEnergy += hitEn; 110 tDistance = hitZ * fCellSizeZ * cosDirec << 116 tDistance = 111 + (hitRho * fCellSizeRho - p << 117 hitZ * fCellSizeZ * cosDirection + 112 rDistance = hitZ * fCellSizeZ * (-sinDir << 118 (hitRho * fCellSizeRho - primaryEntrance.perp()) * sinDirection; 113 + (hitRho * fCellSizeRho - p << 119 rDistance = >> 120 hitZ * fCellSizeZ * (-sinDirection) + >> 121 (hitRho * fCellSizeRho - primaryEntrance.perp()) * cosDirection; 114 tFirstMoment += hitEn * tDistance; 122 tFirstMoment += hitEn * tDistance; 115 rFirstMoment += hitEn * rDistance; 123 rFirstMoment += hitEn * rDistance; 116 analysisManager->FillH1(4, tDistance, hi 124 analysisManager->FillH1(4, tDistance, hitEn); 117 analysisManager->FillH1(5, rDistance, hi 125 analysisManager->FillH1(5, rDistance, hitEn); 118 analysisManager->FillH1(10, hitType); 126 analysisManager->FillH1(10, hitType); 119 } 127 } 120 } 128 } 121 tFirstMoment /= totalEnergy; 129 tFirstMoment /= totalEnergy; 122 rFirstMoment /= totalEnergy; 130 rFirstMoment /= totalEnergy; 123 analysisManager->FillH1(0, primaryEnergy / G 131 analysisManager->FillH1(0, primaryEnergy / GeV); 124 analysisManager->FillH1(1, totalEnergy / GeV 132 analysisManager->FillH1(1, totalEnergy / GeV); 125 analysisManager->FillH1(2, totalEnergy / pri 133 analysisManager->FillH1(2, totalEnergy / primaryEnergy); 126 analysisManager->FillH1(3, fTimer.GetRealEla 134 analysisManager->FillH1(3, fTimer.GetRealElapsed()); 127 analysisManager->FillH1(6, tFirstMoment); 135 analysisManager->FillH1(6, tFirstMoment); 128 analysisManager->FillH1(7, rFirstMoment); 136 analysisManager->FillH1(7, rFirstMoment); 129 137 130 // Second loop over hits to calculate second 138 // Second loop over hits to calculate second moments 131 for (size_t iHit = 0; iHit < hitsCollection- << 139 for(size_t iHit = 0; iHit < hitsCollection->entries(); iHit++) 132 hit = static_cast<Par03Hit*>(hitsCollectio << 140 { 133 hitEn = hit->GetEdep(); << 141 hit = static_cast<Par03Hit*>(hitsCollection->GetHit(iHit)); 134 hitZ = hit->GetZid(); << 142 hitEn = hit->GetEdep(); >> 143 hitZ = hit->GetZid(); 135 hitRho = hit->GetRhoId(); 144 hitRho = hit->GetRhoId(); 136 if (hitEn > 0) { << 145 if(hitEn > 0) 137 tDistance = hitZ * fCellSizeZ * cosDirec << 146 { 138 + (hitRho * fCellSizeRho - p << 147 tDistance = hitZ * fCellSizeZ * cosDirection + 139 rDistance = hitZ * fCellSizeZ * (-sinDir << 148 (hitRho * fCellSizeRho - primaryEntrance.r()) * sinDirection; 140 + (hitRho * fCellSizeRho - p << 149 rDistance = hitZ * fCellSizeZ * (-sinDirection) + >> 150 (hitRho * fCellSizeRho - primaryEntrance.r()) * cosDirection; 141 tSecondMoment += hitEn * std::pow(tDista 151 tSecondMoment += hitEn * std::pow(tDistance - tFirstMoment, 2); 142 rSecondMoment += hitEn * std::pow(rDista 152 rSecondMoment += hitEn * std::pow(rDistance - rFirstMoment, 2); 143 } 153 } 144 } 154 } 145 tSecondMoment /= totalEnergy; 155 tSecondMoment /= totalEnergy; 146 rSecondMoment /= totalEnergy; 156 rSecondMoment /= totalEnergy; 147 analysisManager->FillH1(8, tSecondMoment); 157 analysisManager->FillH1(8, tSecondMoment); 148 analysisManager->FillH1(9, rSecondMoment); 158 analysisManager->FillH1(9, rSecondMoment); 149 } 159 }