| 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 | //
|
|---|
| 27 | // $Id: B01Run.cc,v 1.4 2007/06/21 15:03:37 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 |
|
|---|
| 31 | //=====================================================================
|
|---|
| 32 | //
|
|---|
| 33 | // (Description)
|
|---|
| 34 | // B01Run Class is for accumulating scored quantities which is
|
|---|
| 35 | // scored using G4MutiFunctionalDetector and G4VPrimitiveScorer.
|
|---|
| 36 | // Accumulation is done using G4THitsMap object.
|
|---|
| 37 | //
|
|---|
| 38 | // The constructor B01Run(const std::vector<G4String> mfdName)
|
|---|
| 39 | // needs a vector filled with MultiFunctionalDetector names which
|
|---|
| 40 | // was assigned at instantiation of MultiFunctionalDetector(MFD).
|
|---|
| 41 | // Then B01Run constructor automatically scans primitive scorers
|
|---|
| 42 | // in the MFD, and obtains collectionIDs of all collections associated
|
|---|
| 43 | // to those primitive scorers. Futhermore, the G4THitsMap objects
|
|---|
| 44 | // for accumulating during a RUN are automatically created too.
|
|---|
| 45 | // (*) Collection Name is same as primitive scorer name.
|
|---|
| 46 | //
|
|---|
| 47 | // The resultant information is kept inside B01Run objects as
|
|---|
| 48 | // data members.
|
|---|
| 49 | // std::vector<G4String> theCollName; // Collection Name,
|
|---|
| 50 | // std::vector<G4int> theCollID; // Collection ID,
|
|---|
| 51 | // std::vector<G4THitsMap<G4double>*> theRunMap; // HitsMap for RUN.
|
|---|
| 52 | //
|
|---|
| 53 | // The resualtant HitsMap objects are obtain using access method,
|
|---|
| 54 | // GetHitsMap(..).
|
|---|
| 55 | //
|
|---|
| 56 | //=====================================================================
|
|---|
| 57 |
|
|---|
| 58 | #include "B01Run.hh"
|
|---|
| 59 | #include "G4SDManager.hh"
|
|---|
| 60 |
|
|---|
| 61 | #include "G4MultiFunctionalDetector.hh"
|
|---|
| 62 | #include "G4VPrimitiveScorer.hh"
|
|---|
| 63 |
|
|---|
| 64 | //
|
|---|
| 65 | // Constructor.
|
|---|
| 66 | // (The vector of MultiFunctionalDetector name has to given.)
|
|---|
| 67 | B01Run::B01Run(const std::vector<G4String> mfdName): G4Run()
|
|---|
| 68 | {
|
|---|
| 69 | G4SDManager* SDman = G4SDManager::GetSDMpointer();
|
|---|
| 70 | //=================================================
|
|---|
| 71 | // Initalize RunMaps for accumulation.
|
|---|
| 72 | // Get CollectionIDs for HitCollections.
|
|---|
| 73 | //=================================================
|
|---|
| 74 | G4int Nmfd = mfdName.size();
|
|---|
| 75 | for ( G4int idet = 0; idet < Nmfd ; idet++){ // Loop for all MFD.
|
|---|
| 76 | G4String detName = mfdName[idet];
|
|---|
| 77 | //--- Seek and Obtain MFD objects from SDmanager.
|
|---|
| 78 | G4MultiFunctionalDetector* mfd =
|
|---|
| 79 | (G4MultiFunctionalDetector*)(SDman->FindSensitiveDetector(detName));
|
|---|
| 80 | //
|
|---|
| 81 | if ( mfd ){
|
|---|
| 82 | //--- Loop over the registered primitive scorers.
|
|---|
| 83 | for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
|
|---|
| 84 | // Get Primitive Scorer object.
|
|---|
| 85 | G4VPrimitiveScorer* scorer=mfd->GetPrimitive(icol);
|
|---|
| 86 | // collection name and collectionID for HitsCollection,
|
|---|
| 87 | // where type of HitsCollection is G4THitsMap in case of primitive scorer.
|
|---|
| 88 | // The collection name is given by <MFD name>/<Primitive Scorer name>.
|
|---|
| 89 | G4String collectionName = scorer->GetName();
|
|---|
| 90 | G4String fullCollectionName = detName+"/"+collectionName;
|
|---|
| 91 | G4int collectionID = SDman->GetCollectionID(fullCollectionName);
|
|---|
| 92 | //
|
|---|
| 93 | if ( collectionID >= 0 ){
|
|---|
| 94 | G4cout << "++ "<<fullCollectionName<< " id " << collectionID << G4endl;
|
|---|
| 95 | // Store obtained HitsCollection information into data members.
|
|---|
| 96 | // And, creates new G4THitsMap for accumulating quantities during RUN.
|
|---|
| 97 | theCollName.push_back(fullCollectionName);
|
|---|
| 98 | theCollID.push_back(collectionID);
|
|---|
| 99 | theRunMap.push_back(new G4THitsMap<G4double>(detName,collectionName));
|
|---|
| 100 | }else{
|
|---|
| 101 | G4cout << "** collection " << fullCollectionName << " not found. "<<G4endl;
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 | }
|
|---|
| 105 | }
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | //
|
|---|
| 109 | // Destructor
|
|---|
| 110 | // clear all data members.
|
|---|
| 111 | B01Run::~B01Run()
|
|---|
| 112 | {
|
|---|
| 113 | //--- Clear HitsMap for RUN
|
|---|
| 114 | G4int Nmap = theRunMap.size();
|
|---|
| 115 | for ( G4int i = 0; i < Nmap; i++){
|
|---|
| 116 | if(theRunMap[i] ) theRunMap[i]->clear();
|
|---|
| 117 | }
|
|---|
| 118 | theCollName.clear();
|
|---|
| 119 | theCollID.clear();
|
|---|
| 120 | theRunMap.clear();
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | //
|
|---|
| 124 | // RecordEvent is called at end of event.
|
|---|
| 125 | // For scoring purpose, the resultant quantity in a event,
|
|---|
| 126 | // is accumulated during a Run.
|
|---|
| 127 | void B01Run::RecordEvent(const G4Event* aEvent)
|
|---|
| 128 | {
|
|---|
| 129 | numberOfEvent++; // This is an original line.
|
|---|
| 130 |
|
|---|
| 131 | //=============================
|
|---|
| 132 | // HitsCollection of This Event
|
|---|
| 133 | //============================
|
|---|
| 134 | G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
|
|---|
| 135 | if (!HCE) return;
|
|---|
| 136 |
|
|---|
| 137 | //=======================================================
|
|---|
| 138 | // Sum up HitsMap of this Event into HitsMap of this RUN
|
|---|
| 139 | //=======================================================
|
|---|
| 140 | G4int Ncol = theCollID.size();
|
|---|
| 141 | for ( G4int i = 0; i < Ncol ; i++ ){ // Loop over HitsCollection
|
|---|
| 142 | G4THitsMap<G4double>* EvtMap=0;
|
|---|
| 143 | if ( theCollID[i] >= 0 ){ // Collection is attached to HCE
|
|---|
| 144 | EvtMap = (G4THitsMap<G4double>*)(HCE->GetHC(theCollID[i]));
|
|---|
| 145 | }else{
|
|---|
| 146 | G4cout <<" Error EvtMap Not Found "<< i << G4endl;
|
|---|
| 147 | }
|
|---|
| 148 | if ( EvtMap ) {
|
|---|
| 149 | //=== Sum up HitsMap of this event to HitsMap of RUN.===
|
|---|
| 150 | *theRunMap[i] += *EvtMap;
|
|---|
| 151 | //======================================================
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | //=================================================================
|
|---|
| 159 | // Access method for HitsMap of the RUN
|
|---|
| 160 | //
|
|---|
| 161 | //-----
|
|---|
| 162 | // Access HitsMap.
|
|---|
| 163 | // By MultiFunctionalDetector name and Collection Name.
|
|---|
| 164 | G4THitsMap<G4double>* B01Run::GetHitsMap(const G4String& detName,
|
|---|
| 165 | const G4String& colName){
|
|---|
| 166 | G4String fullName = detName+"/"+colName;
|
|---|
| 167 | return GetHitsMap(fullName);
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | //-----
|
|---|
| 171 | // Access HitsMap.
|
|---|
| 172 | // By full description of collection name, that is
|
|---|
| 173 | // <MultiFunctional Detector Name>/<Primitive Scorer Name>
|
|---|
| 174 | G4THitsMap<G4double>* B01Run::GetHitsMap(const G4String& fullName){
|
|---|
| 175 | G4int Ncol = theCollName.size();
|
|---|
| 176 | for ( G4int i = 0; i < Ncol; i++){
|
|---|
| 177 | if ( theCollName[i] == fullName ){
|
|---|
| 178 | return theRunMap[i];
|
|---|
| 179 | }
|
|---|
| 180 | }
|
|---|
| 181 | return NULL;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | //-----
|
|---|
| 185 | // - Dump All HitsMap of this RUN. (for debuging and monitoring of quantity).
|
|---|
| 186 | // This method calls G4THisMap::PrintAll() for individual HitsMap.
|
|---|
| 187 | void B01Run::DumpAllScorer(){
|
|---|
| 188 |
|
|---|
| 189 | // - Number of HitsMap in this RUN.
|
|---|
| 190 | G4int n = GetNumberOfHitsMap();
|
|---|
| 191 | // - GetHitsMap and dump values.
|
|---|
| 192 | for ( G4int i = 0; i < n ; i++ ){
|
|---|
| 193 | G4THitsMap<G4double>* RunMap =GetHitsMap(i);
|
|---|
| 194 | if ( RunMap ) {
|
|---|
| 195 | G4cout << " PrimitiveScorer RUN "
|
|---|
| 196 | << RunMap->GetSDname() <<","<< RunMap->GetName() << G4endl;
|
|---|
| 197 | G4cout << " Number of entries " << RunMap->entries() << G4endl;
|
|---|
| 198 | std::map<G4int,G4double*>::iterator itr = RunMap->GetMap()->begin();
|
|---|
| 199 | for(; itr != RunMap->GetMap()->end(); itr++) {
|
|---|
| 200 | G4cout << " copy no.: " << itr->first
|
|---|
| 201 | << " Run Value : " << *(itr->second)
|
|---|
| 202 | << G4endl;
|
|---|
| 203 | }
|
|---|
| 204 | }
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|