Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:44

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