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 // Gorad (Geant4 Open-source Radiation Analys 26 // Gorad (Geant4 Open-source Radiation Analysis and Design) 27 // 27 // 28 // Author : Makoto Asai (SLAC National Accele 28 // Author : Makoto Asai (SLAC National Accelerator Laboratory) 29 // 29 // 30 // Development of Gorad is funded by NASA Joh 30 // Development of Gorad is funded by NASA Johnson Space Center (JSC) 31 // under the contract NNJ15HK11B. 31 // under the contract NNJ15HK11B. 32 // 32 // 33 // ******************************************* 33 // ******************************************************************** 34 // 34 // 35 // GRRun.cc 35 // GRRun.cc 36 // Gorad Run class that handles filling hist 36 // Gorad Run class that handles filling histograms and profile plots 37 // with scores accumulated by scoeres for ea 37 // with scores accumulated by scoeres for each event. 38 // 38 // 39 // History 39 // History 40 // September 8th, 2020 : first implementatio 40 // September 8th, 2020 : first implementation 41 // 41 // 42 // ******************************************* 42 // ******************************************************************** 43 43 44 #include "GRRun.hh" 44 #include "GRRun.hh" 45 #include "GRRunAction.hh" 45 #include "GRRunAction.hh" 46 46 47 #include "G4AnalysisManager.hh" 47 #include "G4AnalysisManager.hh" 48 #include "G4MultiFunctionalDetector.hh" 48 #include "G4MultiFunctionalDetector.hh" 49 #include "G4VPrimitiveScorer.hh" 49 #include "G4VPrimitiveScorer.hh" 50 50 51 #include "G4PrimaryVertex.hh" 51 #include "G4PrimaryVertex.hh" 52 #include "G4PrimaryParticle.hh" 52 #include "G4PrimaryParticle.hh" 53 53 54 GRRun::GRRun(GRRunAction* ra) : G4Run(),pRA(ra 54 GRRun::GRRun(GRRunAction* ra) : G4Run(),pRA(ra) 55 { 55 { 56 ; 56 ; 57 } 57 } 58 58 59 GRRun::~GRRun() 59 GRRun::~GRRun() 60 { 60 { 61 ; 61 ; 62 } 62 } 63 63 64 void GRRun::RecordEvent(const G4Event* anEvent 64 void GRRun::RecordEvent(const G4Event* anEvent) 65 { 65 { 66 66 67 numberOfEvent++; // This is an original lin 67 numberOfEvent++; // This is an original line. 68 68 69 G4HCofThisEvent* pHCE = anEvent->GetHCofThis 69 G4HCofThisEvent* pHCE = anEvent->GetHCofThisEvent(); 70 70 71 auto analysisManager = G4AnalysisManager::In 71 auto analysisManager = G4AnalysisManager::Instance(); 72 auto map = pRA->IDMap; 72 auto map = pRA->IDMap; 73 for(auto itr : map) 73 for(auto itr : map) 74 { 74 { 75 if(itr.second->pplotter!=nullptr) continue 75 if(itr.second->pplotter!=nullptr) continue; // directly plotted by the PrimitivePlotter 76 76 77 auto cID = itr.second->collID; 77 auto cID = itr.second->collID; 78 auto hID = itr.second->histID; 78 auto hID = itr.second->histID; 79 auto hTyp = itr.second->histType; 79 auto hTyp = itr.second->histType; 80 80 81 if(hTyp==1) // 1D histogram 81 if(hTyp==1) // 1D histogram 82 { 82 { 83 if(cID>=0) // scorer 83 if(cID>=0) // scorer 84 { 84 { 85 if(!pHCE) continue; 85 if(!pHCE) continue; 86 auto score = (G4THitsMap<G4double>*)(p 86 auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID)); 87 G4double val = 0.; 87 G4double val = 0.; 88 for(auto hItr : *score) 88 for(auto hItr : *score) 89 { 89 { 90 if(itr.second->idx==-1 || itr.second 90 if(itr.second->idx==-1 || itr.second->idx==hItr.first) 91 { val += *(hItr.second); } 91 { val += *(hItr.second); } 92 } 92 } 93 analysisManager->FillH1(hID,val); 93 analysisManager->FillH1(hID,val); 94 } 94 } 95 else // primary particle 95 else // primary particle 96 { 96 { 97 auto pv = anEvent->GetPrimaryVertex(); 97 auto pv = anEvent->GetPrimaryVertex(); 98 while(pv) 98 while(pv) 99 { 99 { 100 auto pp = pv->GetPrimary(); 100 auto pp = pv->GetPrimary(); 101 while(pp) 101 while(pp) 102 { 102 { 103 auto primE = pp->GetKineticEnergy( 103 auto primE = pp->GetKineticEnergy(); 104 G4double weight = 1.0; 104 G4double weight = 1.0; 105 if(itr.second->biasf) weight = pp- 105 if(itr.second->biasf) weight = pp->GetWeight(); 106 analysisManager->FillH1(hID,primE, 106 analysisManager->FillH1(hID,primE,weight); 107 pp = pp->GetNext(); 107 pp = pp->GetNext(); 108 } 108 } 109 pv = pv->GetNext(); 109 pv = pv->GetNext(); 110 } 110 } 111 } 111 } 112 } 112 } 113 113 114 else if(hTyp==2) // 1D profile plot 114 else if(hTyp==2) // 1D profile plot 115 { 115 { 116 if(!pHCE) continue; 116 if(!pHCE) continue; 117 auto score = (G4THitsMap<G4double>*)(pHC 117 auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID)); 118 for(auto hItr : *score) 118 for(auto hItr : *score) 119 { analysisManager->FillP1(hID,G4double(h 119 { analysisManager->FillP1(hID,G4double(hItr.first),*(hItr.second)); } 120 } 120 } 121 121 122 } 122 } 123 123 124 auto ntmap = pRA->NTMap; 124 auto ntmap = pRA->NTMap; 125 if(ntmap.size()>0) 125 if(ntmap.size()>0) 126 { 126 { 127 for(auto ntitr : ntmap) 127 for(auto ntitr : ntmap) 128 { 128 { 129 auto colID = ntitr.first; 129 auto colID = ntitr.first; 130 auto cID = ntitr.second->collID; 130 auto cID = ntitr.second->collID; 131 G4double val = 0.; 131 G4double val = 0.; 132 if(cID>=0) 132 if(cID>=0) 133 { 133 { 134 if(!pHCE) continue; 134 if(!pHCE) continue; 135 auto score = (G4THitsMap<G4double>*)(p 135 auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID)); 136 for(auto hItr : *score) 136 for(auto hItr : *score) 137 { 137 { 138 if(ntitr.second->idx==-1 || ntitr.se 138 if(ntitr.second->idx==-1 || ntitr.second->idx==hItr.first) 139 { val += *(hItr.second); } 139 { val += *(hItr.second); } 140 } 140 } 141 } 141 } 142 else 142 else 143 { 143 { 144 auto pv = anEvent->GetPrimaryVertex(); 144 auto pv = anEvent->GetPrimaryVertex(); 145 auto pp = pv->GetPrimary(); 145 auto pp = pv->GetPrimary(); 146 val = pp->GetKineticEnergy(); 146 val = pp->GetKineticEnergy(); 147 } 147 } 148 analysisManager->FillNtupleDColumn(colID 148 analysisManager->FillNtupleDColumn(colID,val*(ntitr.second->fuct)); 149 } 149 } 150 analysisManager->AddNtupleRow(); 150 analysisManager->AddNtupleRow(); 151 } 151 } 152 152 153 } 153 } 154 154 155 void GRRun::Merge(const G4Run * aRun) 155 void GRRun::Merge(const G4Run * aRun) 156 { 156 { 157 G4Run::Merge(aRun); 157 G4Run::Merge(aRun); 158 } 158 } 159 159 160 160 161 161