[814] | 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 | // |
---|
[850] | 27 | // $Id: G4MultiFunctionalDetector.cc,v 1.5 2008/03/06 23:31:12 asaim Exp $ |
---|
[1012] | 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
[814] | 29 | // |
---|
| 30 | // G4MultiFunctionalDetector |
---|
| 31 | #include "G4MultiFunctionalDetector.hh" |
---|
| 32 | #include "G4SDManager.hh" |
---|
| 33 | #include "G4VPrimitiveScorer.hh" |
---|
| 34 | |
---|
| 35 | G4MultiFunctionalDetector::G4MultiFunctionalDetector(G4String name) |
---|
| 36 | :G4VSensitiveDetector(name) |
---|
| 37 | {;} |
---|
| 38 | |
---|
| 39 | G4MultiFunctionalDetector::~G4MultiFunctionalDetector() |
---|
| 40 | {;} |
---|
| 41 | |
---|
| 42 | G4bool G4MultiFunctionalDetector::ProcessHits(G4Step* aStep,G4TouchableHistory* aTH) |
---|
| 43 | { |
---|
| 44 | G4int nPrim = primitives.size(); |
---|
| 45 | for(G4int iPrim=0;iPrim<nPrim;iPrim++) |
---|
[850] | 46 | { if(aStep->GetStepLength()>0.) primitives[iPrim]->HitPrimitive(aStep,aTH); } |
---|
[814] | 47 | return true; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | G4bool G4MultiFunctionalDetector::RegisterPrimitive(G4VPrimitiveScorer* aPS) |
---|
| 51 | { |
---|
| 52 | G4int nPrim = primitives.size(); |
---|
| 53 | for(G4int iPrim=0;iPrim<nPrim;iPrim++) |
---|
| 54 | { |
---|
| 55 | if(primitives[iPrim]==aPS) |
---|
| 56 | { |
---|
| 57 | G4cerr << "Primitive <" << aPS->GetName() << "> is already defined in <" << SensitiveDetectorName |
---|
| 58 | << ">." << G4endl << "Method RegisterPrimitive() is ignored." << G4endl; |
---|
| 59 | return false; |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | primitives.push_back(aPS); |
---|
| 63 | aPS->SetMultiFunctionalDetector(this); |
---|
| 64 | collectionName.insert(aPS->GetName()); |
---|
| 65 | if(G4SDManager::GetSDMpointer()->FindSensitiveDetector(SensitiveDetectorName,false)) |
---|
| 66 | { |
---|
| 67 | // This G4MultiFunctionalDetector has already been registered to G4SDManager. |
---|
| 68 | // Make sure this new primitive is registered as well. |
---|
| 69 | G4SDManager::GetSDMpointer()->AddNewCollection(SensitiveDetectorName,aPS->GetName()); |
---|
| 70 | } |
---|
| 71 | return true; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | G4bool G4MultiFunctionalDetector::RemovePrimitive(G4VPrimitiveScorer* aPS) |
---|
| 75 | { |
---|
| 76 | std::vector<G4VPrimitiveScorer*>::iterator iterPS; |
---|
| 77 | std::vector<G4String>::iterator iterName = collectionName.begin(); |
---|
| 78 | for(iterPS=primitives.begin();iterPS!=primitives.end();iterPS++) |
---|
| 79 | { |
---|
| 80 | if(*iterPS==aPS) |
---|
| 81 | { |
---|
| 82 | primitives.erase(iterPS); |
---|
| 83 | aPS->SetMultiFunctionalDetector(0); |
---|
| 84 | return true; |
---|
| 85 | } |
---|
| 86 | iterName++; |
---|
| 87 | } |
---|
| 88 | G4cerr << "Primitive <" << aPS->GetName() << "> is not defined in <" << SensitiveDetectorName |
---|
| 89 | << ">." << G4endl << "Method RemovePrimitive() is ignored." << G4endl; |
---|
| 90 | return false; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | void G4MultiFunctionalDetector::Initialize(G4HCofThisEvent* HC) |
---|
| 94 | { |
---|
| 95 | G4int nPrim = primitives.size(); |
---|
| 96 | for(G4int iPrim=0;iPrim<nPrim;iPrim++) |
---|
| 97 | { primitives[iPrim]->Initialize(HC); } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | void G4MultiFunctionalDetector::EndOfEvent(G4HCofThisEvent* HC) |
---|
| 101 | { |
---|
| 102 | G4int nPrim = primitives.size(); |
---|
| 103 | for(G4int iPrim=0;iPrim<nPrim;iPrim++) |
---|
| 104 | { primitives[iPrim]->EndOfEvent(HC); } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void G4MultiFunctionalDetector::clear() |
---|
| 108 | { |
---|
| 109 | G4int nPrim = primitives.size(); |
---|
| 110 | for(G4int iPrim=0;iPrim<nPrim;iPrim++) |
---|
| 111 | { primitives[iPrim]->clear(); } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | void G4MultiFunctionalDetector::DrawAll() |
---|
| 115 | { |
---|
| 116 | G4int nPrim = primitives.size(); |
---|
| 117 | for(G4int iPrim=0;iPrim<nPrim;iPrim++) |
---|
| 118 | { primitives[iPrim]->DrawAll(); } |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | void G4MultiFunctionalDetector::PrintAll() |
---|
| 122 | { |
---|
| 123 | G4int nPrim = primitives.size(); |
---|
| 124 | for(G4int iPrim=0;iPrim<nPrim;iPrim++) |
---|
| 125 | { primitives[iPrim]->PrintAll(); } |
---|
| 126 | } |
---|
| 127 | |
---|