00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 // G4MultiFunctionalDetector 00030 // 00031 // 2010-07-23 T.Aso Call PS if the step length or energy deposit is not zero. 00032 // 00033 // 00034 #include "G4MultiFunctionalDetector.hh" 00035 #include "G4SDManager.hh" 00036 #include "G4VPrimitiveScorer.hh" 00037 00038 G4MultiFunctionalDetector::G4MultiFunctionalDetector(G4String name) 00039 :G4VSensitiveDetector(name) 00040 {;} 00041 00042 G4MultiFunctionalDetector::~G4MultiFunctionalDetector() 00043 {;} 00044 00045 G4bool G4MultiFunctionalDetector::ProcessHits(G4Step* aStep,G4TouchableHistory* aTH) 00046 { 00047 if(aStep->GetStepLength()>0. || aStep->GetTotalEnergyDeposit()>0.){ 00048 G4int nPrim = primitives.size(); 00049 for(G4int iPrim=0;iPrim<nPrim;iPrim++) 00050 { 00051 primitives[iPrim]->HitPrimitive(aStep,aTH); 00052 } 00053 } 00054 return true; 00055 } 00056 00057 G4bool G4MultiFunctionalDetector::RegisterPrimitive(G4VPrimitiveScorer* aPS) 00058 { 00059 G4int nPrim = primitives.size(); 00060 for(G4int iPrim=0;iPrim<nPrim;iPrim++) 00061 { 00062 if(primitives[iPrim]==aPS) 00063 { 00064 G4ExceptionDescription ED; 00065 ED << "Primitive <" << aPS->GetName() << "> is already defined in <" << SensitiveDetectorName 00066 << ">." << G4endl << "Method RegisterPrimitive() is ignored." << G4endl; 00067 G4Exception("G4MultiFunctionalDetector::RegisterPrimitive","Det0101", 00068 JustWarning,ED); 00069 return false; 00070 } 00071 } 00072 primitives.push_back(aPS); 00073 aPS->SetMultiFunctionalDetector(this); 00074 collectionName.insert(aPS->GetName()); 00075 if(G4SDManager::GetSDMpointer()->FindSensitiveDetector(SensitiveDetectorName,false)) 00076 { 00077 // This G4MultiFunctionalDetector has already been registered to G4SDManager. 00078 // Make sure this new primitive is registered as well. 00079 G4SDManager::GetSDMpointer()->AddNewCollection(SensitiveDetectorName,aPS->GetName()); 00080 } 00081 return true; 00082 } 00083 00084 G4bool G4MultiFunctionalDetector::RemovePrimitive(G4VPrimitiveScorer* aPS) 00085 { 00086 std::vector<G4VPrimitiveScorer*>::iterator iterPS; 00087 std::vector<G4String>::iterator iterName = collectionName.begin(); 00088 for(iterPS=primitives.begin();iterPS!=primitives.end();iterPS++) 00089 { 00090 if(*iterPS==aPS) 00091 { 00092 primitives.erase(iterPS); 00093 aPS->SetMultiFunctionalDetector(0); 00094 return true; 00095 } 00096 iterName++; 00097 } 00098 G4cerr << "Primitive <" << aPS->GetName() << "> is not defined in <" << SensitiveDetectorName 00099 << ">." << G4endl << "Method RemovePrimitive() is ignored." << G4endl; 00100 return false; 00101 } 00102 00103 void G4MultiFunctionalDetector::Initialize(G4HCofThisEvent* HC) 00104 { 00105 G4int nPrim = primitives.size(); 00106 for(G4int iPrim=0;iPrim<nPrim;iPrim++) 00107 { primitives[iPrim]->Initialize(HC); } 00108 } 00109 00110 void G4MultiFunctionalDetector::EndOfEvent(G4HCofThisEvent* HC) 00111 { 00112 G4int nPrim = primitives.size(); 00113 for(G4int iPrim=0;iPrim<nPrim;iPrim++) 00114 { primitives[iPrim]->EndOfEvent(HC); } 00115 } 00116 00117 void G4MultiFunctionalDetector::clear() 00118 { 00119 G4int nPrim = primitives.size(); 00120 for(G4int iPrim=0;iPrim<nPrim;iPrim++) 00121 { primitives[iPrim]->clear(); } 00122 } 00123 00124 void G4MultiFunctionalDetector::DrawAll() 00125 { 00126 G4int nPrim = primitives.size(); 00127 for(G4int iPrim=0;iPrim<nPrim;iPrim++) 00128 { primitives[iPrim]->DrawAll(); } 00129 } 00130 00131 void G4MultiFunctionalDetector::PrintAll() 00132 { 00133 G4int nPrim = primitives.size(); 00134 for(G4int iPrim=0;iPrim<nPrim;iPrim++) 00135 { primitives[iPrim]->PrintAll(); } 00136 } 00137