Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // Gorad (Geant4 Open-source Radiation Analysis and Design) 27 // 28 // Author : Makoto Asai (SLAC National Accelerator Laboratory) 29 // 30 // Development of Gorad is funded by NASA Johnson Space Center (JSC) 31 // under the contract NNJ15HK11B. 32 // 33 // ******************************************************************** 34 // 35 // GRRun.cc 36 // Gorad Run class that handles filling histograms and profile plots 37 // with scores accumulated by scoeres for each event. 38 // 39 // History 40 // September 8th, 2020 : first implementation 41 // 42 // ******************************************************************** 43 44 #include "GRRun.hh" 45 #include "GRRunAction.hh" 46 47 #include "G4AnalysisManager.hh" 48 #include "G4MultiFunctionalDetector.hh" 49 #include "G4VPrimitiveScorer.hh" 50 51 #include "G4PrimaryVertex.hh" 52 #include "G4PrimaryParticle.hh" 53 54 GRRun::GRRun(GRRunAction* ra) : G4Run(),pRA(ra) 55 { 56 ; 57 } 58 59 GRRun::~GRRun() 60 { 61 ; 62 } 63 64 void GRRun::RecordEvent(const G4Event* anEvent) 65 { 66 67 numberOfEvent++; // This is an original line. 68 69 G4HCofThisEvent* pHCE = anEvent->GetHCofThisEvent(); 70 71 auto analysisManager = G4AnalysisManager::Instance(); 72 auto map = pRA->IDMap; 73 for(auto itr : map) 74 { 75 if(itr.second->pplotter!=nullptr) continue; // directly plotted by the PrimitivePlotter 76 77 auto cID = itr.second->collID; 78 auto hID = itr.second->histID; 79 auto hTyp = itr.second->histType; 80 81 if(hTyp==1) // 1D histogram 82 { 83 if(cID>=0) // scorer 84 { 85 if(!pHCE) continue; 86 auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID)); 87 G4double val = 0.; 88 for(auto hItr : *score) 89 { 90 if(itr.second->idx==-1 || itr.second->idx==hItr.first) 91 { val += *(hItr.second); } 92 } 93 analysisManager->FillH1(hID,val); 94 } 95 else // primary particle 96 { 97 auto pv = anEvent->GetPrimaryVertex(); 98 while(pv) 99 { 100 auto pp = pv->GetPrimary(); 101 while(pp) 102 { 103 auto primE = pp->GetKineticEnergy(); 104 G4double weight = 1.0; 105 if(itr.second->biasf) weight = pp->GetWeight(); 106 analysisManager->FillH1(hID,primE,weight); 107 pp = pp->GetNext(); 108 } 109 pv = pv->GetNext(); 110 } 111 } 112 } 113 114 else if(hTyp==2) // 1D profile plot 115 { 116 if(!pHCE) continue; 117 auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID)); 118 for(auto hItr : *score) 119 { analysisManager->FillP1(hID,G4double(hItr.first),*(hItr.second)); } 120 } 121 122 } 123 124 auto ntmap = pRA->NTMap; 125 if(ntmap.size()>0) 126 { 127 for(auto ntitr : ntmap) 128 { 129 auto colID = ntitr.first; 130 auto cID = ntitr.second->collID; 131 G4double val = 0.; 132 if(cID>=0) 133 { 134 if(!pHCE) continue; 135 auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID)); 136 for(auto hItr : *score) 137 { 138 if(ntitr.second->idx==-1 || ntitr.second->idx==hItr.first) 139 { val += *(hItr.second); } 140 } 141 } 142 else 143 { 144 auto pv = anEvent->GetPrimaryVertex(); 145 auto pp = pv->GetPrimary(); 146 val = pp->GetKineticEnergy(); 147 } 148 analysisManager->FillNtupleDColumn(colID,val*(ntitr.second->fuct)); 149 } 150 analysisManager->AddNtupleRow(); 151 } 152 153 } 154 155 void GRRun::Merge(const G4Run * aRun) 156 { 157 G4Run::Merge(aRun); 158 } 159 160 161