Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-25 09:22:34

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //  Gorad (Geant4 Open-source Radiation Analysis and Design)
0027 //
0028 //  Author : Makoto Asai (SLAC National Accelerator Laboratory)
0029 //
0030 //  Development of Gorad is funded by NASA Johnson Space Center (JSC)
0031 //  under the contract NNJ15HK11B.
0032 //
0033 // ********************************************************************
0034 //
0035 // GRRun.cc
0036 //   Gorad Run class that handles filling histograms and profile plots
0037 //   with scores accumulated by scoeres for each event.
0038 //
0039 // History
0040 //   September 8th, 2020 : first implementation
0041 //
0042 // ********************************************************************
0043 
0044 #include "GRRun.hh"
0045 #include "GRRunAction.hh"
0046 
0047 #include "G4AnalysisManager.hh"
0048 #include "G4MultiFunctionalDetector.hh"
0049 #include "G4VPrimitiveScorer.hh"
0050 
0051 #include "G4PrimaryVertex.hh"
0052 #include "G4PrimaryParticle.hh"
0053 
0054 GRRun::GRRun(GRRunAction* ra) : G4Run(),pRA(ra)
0055 {
0056   ;
0057 }
0058 
0059 GRRun::~GRRun()
0060 {
0061   ;
0062 }
0063 
0064 void GRRun::RecordEvent(const G4Event* anEvent)
0065 {
0066   
0067   numberOfEvent++;  // This is an original line.
0068 
0069   G4HCofThisEvent* pHCE = anEvent->GetHCofThisEvent();
0070 
0071   auto analysisManager = G4AnalysisManager::Instance();
0072   auto map = pRA->IDMap;
0073   for(auto itr : map)
0074   {
0075     if(itr.second->pplotter!=nullptr) continue; // directly plotted by the PrimitivePlotter
0076 
0077     auto cID = itr.second->collID;
0078     auto hID = itr.second->histID;
0079     auto hTyp = itr.second->histType;
0080 
0081     if(hTyp==1) // 1D histogram
0082     {
0083       if(cID>=0) // scorer
0084       {
0085         if(!pHCE) continue;
0086         auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID));
0087         G4double val = 0.;
0088         for(auto hItr : *score)
0089         {
0090           if(itr.second->idx==-1 || itr.second->idx==hItr.first)
0091           { val += *(hItr.second); }
0092         }
0093         analysisManager->FillH1(hID,val);
0094       }
0095       else // primary particle
0096       {
0097         auto pv = anEvent->GetPrimaryVertex();
0098         while(pv)
0099         {
0100           auto pp = pv->GetPrimary();
0101           while(pp)
0102           {
0103             auto primE = pp->GetKineticEnergy();
0104             G4double weight = 1.0;
0105             if(itr.second->biasf) weight = pp->GetWeight();
0106             analysisManager->FillH1(hID,primE,weight);
0107             pp = pp->GetNext();
0108           }
0109           pv = pv->GetNext();
0110         }
0111       }  
0112     }
0113 
0114     else if(hTyp==2) // 1D profile plot
0115     {
0116       if(!pHCE) continue;
0117       auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID));
0118       for(auto hItr : *score)
0119       { analysisManager->FillP1(hID,G4double(hItr.first),*(hItr.second)); }
0120     }
0121     
0122   }
0123 
0124   auto ntmap = pRA->NTMap;
0125   if(ntmap.size()>0) 
0126   {
0127     for(auto ntitr : ntmap)
0128     {
0129       auto colID = ntitr.first;
0130       auto cID = ntitr.second->collID;
0131       G4double val = 0.;
0132       if(cID>=0)
0133       {
0134         if(!pHCE) continue;
0135         auto score = (G4THitsMap<G4double>*)(pHCE->GetHC(cID));
0136         for(auto hItr : *score)
0137         {
0138           if(ntitr.second->idx==-1 || ntitr.second->idx==hItr.first)
0139           { val += *(hItr.second); }
0140         }
0141       }
0142       else
0143       {
0144         auto pv = anEvent->GetPrimaryVertex();
0145         auto pp = pv->GetPrimary();
0146         val = pp->GetKineticEnergy();
0147       }
0148       analysisManager->FillNtupleDColumn(colID,val*(ntitr.second->fuct));
0149     }
0150     analysisManager->AddNtupleRow();
0151   }
0152 
0153 }
0154 
0155 void GRRun::Merge(const G4Run * aRun) 
0156 {
0157   G4Run::Merge(aRun);
0158 }
0159 
0160