Back to home page

EIC code displayed by LXR

 
 

    


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

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/B01/src/B01Run.cc
0027 /// \brief Implementation of the B01Run class
0028 //
0029 //
0030 //
0031 
0032 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0033 //
0034 //  (Description)
0035 //    B01Run 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 B01Run(const std::vector<G4String> mfdName)
0040 //  needs a vector filled with MultiFunctionalDetector names which
0041 //  was assigned at instantiation of MultiFunctionalDetector(MFD).
0042 //  Then B01Run 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 B01Run 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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0058 
0059 #include "B01Run.hh"
0060 
0061 #include "G4MultiFunctionalDetector.hh"
0062 #include "G4SDManager.hh"
0063 #include "G4VPrimitiveScorer.hh"
0064 
0065 //
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0067 //  Constructor.
0068 //   (The vector of MultiFunctionalDetector name has to given.)
0069 B01Run::B01Run(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 B01Run::~B01Run()
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 B01Run::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   //=======================================================
0143   // Sum up HitsMap of this Event  into HitsMap of this RUN
0144   //=======================================================
0145   G4int Ncol = fCollID.size();
0146   for (G4int i = 0; i < Ncol; i++) {  // Loop over HitsCollection
0147     G4THitsMap<G4double>* EvtMap = 0;
0148     if (fCollID[i] >= 0) {  // Collection is attached to HCE
0149       EvtMap = (G4THitsMap<G4double>*)(HCE->GetHC(fCollID[i]));
0150     }
0151     else {
0152       G4cout << " Error EvtMap Not Found " << i << G4endl;
0153     }
0154     if (EvtMap) {
0155       //=== Sum up HitsMap of this event to HitsMap of RUN.===
0156       *fRunMap[i] += *EvtMap;
0157       //======================================================
0158     }
0159   }
0160 }
0161 
0162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0163 //
0164 //  Access method for HitsMap of the RUN
0165 //
0166 //-----
0167 // Access HitsMap.
0168 //  By  MultiFunctionalDetector name and Collection Name.
0169 G4THitsMap<G4double>* B01Run::GetHitsMap(const G4String& detName, const G4String& colName)
0170 {
0171   G4String fullName = detName + "/" + colName;
0172   return GetHitsMap(fullName);
0173 }
0174 
0175 //-----
0176 // Access HitsMap.
0177 //  By full description of collection name, that is
0178 //    <MultiFunctional Detector Name>/<Primitive Scorer Name>
0179 G4THitsMap<G4double>* B01Run::GetHitsMap(const G4String& fullName)
0180 {
0181   G4int Ncol = fCollName.size();
0182   for (G4int i = 0; i < Ncol; i++) {
0183     if (fCollName[i] == fullName) {
0184       return fRunMap[i];
0185     }
0186   }
0187   return NULL;
0188 }
0189 
0190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0191 
0192 // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity).
0193 //   This method calls G4THisMap::PrintAll() for individual HitsMap.
0194 void B01Run::DumpAllScorer()
0195 {
0196   // - Number of HitsMap in this RUN.
0197   G4int n = GetNumberOfHitsMap();
0198   // - GetHitsMap and dump values.
0199   for (G4int i = 0; i < n; i++) {
0200     G4THitsMap<G4double>* RunMap = GetHitsMap(i);
0201     if (RunMap) {
0202       G4cout << " PrimitiveScorer RUN " << RunMap->GetSDname() << "," << RunMap->GetName()
0203              << G4endl;
0204       G4cout << " Number of entries " << RunMap->entries() << G4endl;
0205       std::map<G4int, G4double*>::iterator itr = RunMap->GetMap()->begin();
0206       for (; itr != RunMap->GetMap()->end(); itr++) {
0207         G4cout << "  copy no.: " << itr->first << "  Run Value : " << *(itr->second) << G4endl;
0208       }
0209     }
0210   }
0211 }
0212 
0213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0214 
0215 void B01Run::Merge(const G4Run* aRun)
0216 {
0217   const B01Run* localRun = static_cast<const B01Run*>(aRun);
0218   //=======================================================
0219   // Merge HitsMap of working threads
0220   //=======================================================
0221   G4int nCol = localRun->fCollID.size();
0222   for (G4int i = 0; i < nCol; i++) {  // Loop over HitsCollection
0223     if (localRun->fCollID[i] >= 0) {
0224       *fRunMap[i] += *localRun->fRunMap[i];
0225     }
0226   }
0227 
0228   G4Run::Merge(aRun);
0229 }
0230 
0231 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......