Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-23 07:55:05

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 /// \file RE02Run.cc
0027 /// \brief Implementation of the RE02Run class
0028 
0029 //=====================================================================
0030 //
0031 //  (Description)
0032 //    RE02Run Class is for accumulating scored quantities which is
0033 //  scored using G4MutiFunctionalDetector and G4VPrimitiveScorer.
0034 //  Accumulation is done using G4THitsMap object.
0035 //
0036 //    The constructor RE02Run(const std::vector<G4String> mfdName)
0037 //  needs a vector filled with MultiFunctionalDetector names which
0038 //  was assigned at instantiation of MultiFunctionalDetector(MFD).
0039 //  Then RE02Run constructor automatically scans primitive scorers
0040 //  in the MFD, and obtains collectionIDs of all collections associated
0041 //  to those primitive scorers. Futhermore, the G4THitsMap objects
0042 //  for accumulating during a RUN are automatically created too.
0043 //  (*) Collection Name is same as primitive scorer name.
0044 //
0045 //    The resultant information is kept inside RE02Run objects as
0046 //  data members.
0047 //  std::vector<G4String> fCollName;            // Collection Name,
0048 //  std::vector<G4int> fCollID;                 // Collection ID,
0049 //  std::vector<G4THitsMap<G4double>*> fRunMap; // HitsMap for RUN.
0050 //
0051 //  The resualtant HitsMap objects are obtain using access method,
0052 //  GetHitsMap(..).
0053 //
0054 //=====================================================================
0055 
0056 #include "RE02Run.hh"
0057 
0058 #include "G4MultiFunctionalDetector.hh"
0059 #include "G4SDManager.hh"
0060 #include "G4VPrimitiveScorer.hh"
0061 
0062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0063 //
0064 //  Constructor.
0065 //   (The vector of MultiFunctionalDetector name has to given.)
0066 RE02Run::RE02Run(const std::vector<G4String> mfdName) : G4Run()
0067 {
0068   G4SDManager* pSDman = G4SDManager::GetSDMpointer();
0069   //=================================================
0070   //  Initalize RunMaps for accumulation.
0071   //  Get CollectionIDs for HitCollections.
0072   //=================================================
0073   G4int nMfd = mfdName.size();
0074   for (G4int idet = 0; idet < nMfd; idet++) {  // Loop for all MFD.
0075     G4String detName = mfdName[idet];
0076     //--- Seek and Obtain MFD objects from SDmanager.
0077     G4MultiFunctionalDetector* mfd =
0078       (G4MultiFunctionalDetector*)(pSDman->FindSensitiveDetector(detName));
0079     //
0080     if (mfd) {
0081       //--- Loop over the registered primitive scorers.
0082       for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++) {
0083         // Get Primitive Scorer object.
0084         G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
0085         // collection name and collectionID for HitsCollection,
0086         // where type of HitsCollection is G4THitsMap in case of primitive
0087         // scorer.
0088         // The collection name is given by <MFD name>/<Primitive Scorer name>.
0089         G4String collectionName = scorer->GetName();
0090         G4String fullCollectionName = detName + "/" + collectionName;
0091         G4int collectionID = pSDman->GetCollectionID(fullCollectionName);
0092         //
0093         if (collectionID >= 0) {
0094           G4cout << "++ " << fullCollectionName << " id " << collectionID << G4endl;
0095           // Store obtained HitsCollection information into data members.
0096           // And, creates new G4THitsMap for accumulating quantities during RUN.
0097           fCollName.push_back(fullCollectionName);
0098           fCollID.push_back(collectionID);
0099           fRunMap.push_back(new G4THitsMap<G4double>(detName, collectionName));
0100         }
0101         else {
0102           G4cout << "** collection " << fullCollectionName << " not found. " << G4endl;
0103         }
0104       }
0105     }
0106   }
0107 }
0108 
0109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0110 //
0111 // Destructor
0112 //    clear all data members.
0113 RE02Run::~RE02Run()
0114 {
0115   //--- Clear HitsMap for RUN
0116   G4int nMap = fRunMap.size();
0117   for (G4int i = 0; i < nMap; i++) {
0118     if (fRunMap[i]) fRunMap[i]->clear();
0119   }
0120   fCollName.clear();
0121   fCollID.clear();
0122   fRunMap.clear();
0123 }
0124 
0125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0126 //
0127 //  RecordEvent is called at end of event.
0128 //  For scoring purpose, the resultant quantity in a event,
0129 //  is accumulated during a Run.
0130 void RE02Run::RecordEvent(const G4Event* aEvent)
0131 {
0132   numberOfEvent++;  // This is an original line.
0133 
0134   //=============================
0135   // HitsCollection of This Event
0136   //============================
0137   G4HCofThisEvent* pHCE = aEvent->GetHCofThisEvent();
0138   if (!pHCE) return;
0139 
0140   //=======================================================
0141   // Sum up HitsMap of this Event  into HitsMap of this RUN
0142   //=======================================================
0143   G4int nCol = fCollID.size();
0144   for (G4int i = 0; i < nCol; i++) {  // Loop over HitsCollection
0145     G4THitsMap<G4double>* evtMap = 0;
0146     if (fCollID[i] >= 0) {  // Collection is attached to pHCE
0147       evtMap = (G4THitsMap<G4double>*)(pHCE->GetHC(fCollID[i]));
0148     }
0149     else {
0150       G4cout << " Error evtMap Not Found " << i << G4endl;
0151     }
0152     if (evtMap) {
0153       //=== Sum up HitsMap of this event to HitsMap of RUN.===
0154       *fRunMap[i] += *evtMap;
0155       //======================================================
0156     }
0157   }
0158 }
0159 
0160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0161 void RE02Run::Merge(const G4Run* aRun)
0162 {
0163   const RE02Run* localRun = static_cast<const RE02Run*>(aRun);
0164 
0165   //=======================================================
0166   // Merge HitsMap of working threads
0167   //=======================================================
0168   G4int nCol = localRun->fCollID.size();
0169   for (G4int i = 0; i < nCol; i++) {  // Loop over HitsCollection
0170     if (localRun->fCollID[i] >= 0) {
0171       *fRunMap[i] += *localRun->fRunMap[i];
0172     }
0173   }
0174 
0175   G4Run::Merge(aRun);
0176 }
0177 
0178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0179 //
0180 //  Access method for HitsMap of the RUN
0181 //
0182 //-----
0183 // Access HitsMap.
0184 //  By  MultiFunctionalDetector name and Collection Name.
0185 G4THitsMap<G4double>* RE02Run::GetHitsMap(const G4String& detName, const G4String& colName)
0186 {
0187   G4String fullName = detName + "/" + colName;
0188   return GetHitsMap(fullName);
0189 }
0190 
0191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0192 //
0193 //-----
0194 // Access HitsMap.
0195 //  By full description of collection name, that is
0196 //    <MultiFunctional Detector Name>/<Primitive Scorer Name>
0197 G4THitsMap<G4double>* RE02Run::GetHitsMap(const G4String& fullName)
0198 {
0199   G4int nCol = fCollName.size();
0200   for (G4int i = 0; i < nCol; i++) {
0201     if (fCollName[i] == fullName) {
0202       return fRunMap[i];
0203     }
0204   }
0205   return NULL;
0206 }
0207 
0208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0209 //
0210 //-----
0211 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity).
0212 //   This method calls G4THisMap::PrintAll() for individual HitsMap.
0213 void RE02Run::DumpAllScorer()
0214 {
0215   // - Number of HitsMap in this RUN.
0216   G4int n = GetNumberOfHitsMap();
0217   // - GetHitsMap and dump values.
0218   for (G4int i = 0; i < n; i++) {
0219     G4THitsMap<G4double>* runMap = GetHitsMap(i);
0220     if (runMap) {
0221       G4cout << " PrimitiveScorer RUN " << runMap->GetSDname() << "," << runMap->GetName()
0222              << G4endl;
0223       G4cout << " Number of entries " << runMap->entries() << G4endl;
0224       ////      std::map<G4int,G4double*>::iterator itr = runMap->GetMap()->begin();
0225       ////      for(; itr != runMap->GetMap()->end(); itr++) {
0226       ////        G4cout << "  copy no.: " << itr->first
0227       ////               << "  Run Value : " << *(itr->second)
0228       ////               << G4endl;
0229       ////      }
0230     }
0231   }
0232 }