G4PSNofSecondary.cc

Go to the documentation of this file.
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 // G4PSNofSecondary
00030 #include "G4PSNofSecondary.hh"
00031 
00032 // (Description)
00033 //   This is a primitive scorer class for scoring number of secondaries 
00034 // in the Cell.
00035 //
00036 // Created: 2005-11-14  Tsukasa ASO, Akinori Kimura.
00037 // Modify:  2011-09-09  T.Aso modify comment in PrintAll().
00038 //
00039 
00040 G4PSNofSecondary::G4PSNofSecondary(G4String name, G4int depth)
00041     :G4VPrimitiveScorer(name,depth),HCID(-1),particleDef(0),
00042      weighted(true)
00043 {;}
00044 
00045 G4PSNofSecondary::~G4PSNofSecondary()
00046 {;}
00047 
00048 G4bool G4PSNofSecondary::ProcessHits(G4Step* aStep,G4TouchableHistory*)
00049 {
00050   //- check for newly produced particle. e.g. first step.
00051   if ( aStep->GetTrack()->GetCurrentStepNumber() != 1) return FALSE;
00052   //- check for this is not a primary particle. e.g. ParentID > 0 .
00053   if ( aStep->GetTrack()->GetParentID() == 0 ) return FALSE;
00054   //- check the particle if the partifle definition is given.
00055   if ( particleDef && particleDef != aStep->GetTrack()->GetDefinition() )
00056       return FALSE;
00057   //
00058   //- This is a newly produced secondary particle.
00059   G4int  index = GetIndex(aStep);
00060   G4double weight = 1.0;
00061   if ( weighted ) weight *= aStep->GetPreStepPoint()->GetWeight();
00062   EvtMap->add(index,weight);  
00063   return TRUE;
00064 }
00065 
00066 void G4PSNofSecondary::SetParticle(const G4String& particleName){
00067   G4ParticleDefinition* pd =
00068       G4ParticleTable::GetParticleTable()->FindParticle(particleName);
00069   if(!pd) {
00070       G4String msg = "Particle <";
00071       msg += particleName;
00072       msg += "> not found.";
00073       G4Exception("G4PSNofSecondary::SetParticle",
00074                   "DetPS0101",FatalException,msg);
00075   }
00076   particleDef = pd;
00077 }
00078 
00079 void G4PSNofSecondary::Initialize(G4HCofThisEvent* HCE)
00080 {
00081   EvtMap = new G4THitsMap<G4double>(detector->GetName(),GetName());
00082   if(HCID < 0) {HCID = GetCollectionID(0);}
00083   HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
00084 }
00085 
00086 void G4PSNofSecondary::EndOfEvent(G4HCofThisEvent*)
00087 {;}
00088 
00089 void G4PSNofSecondary::clear(){
00090   EvtMap->clear();
00091 }
00092 
00093 void G4PSNofSecondary::DrawAll()
00094 {;}
00095 
00096 void G4PSNofSecondary::PrintAll()
00097 {
00098   G4cout << " PrimitiveScorer " << GetName() << G4endl;
00099   G4cout << " Number of entries " << EvtMap->entries() << G4endl;
00100   std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
00101   for(; itr != EvtMap->GetMap()->end(); itr++) {
00102     G4cout << "  copy no.: " << itr->first
00103            << "  num of secondaries: " << *(itr->second)/GetUnitValue()
00104            << G4endl;
00105   }
00106 }
00107 
00108 void G4PSNofSecondary::SetUnit(const G4String& unit)
00109 {
00110   if (unit == "" ){
00111     unitName = unit;
00112     unitValue = 1.0;
00113   }else{
00114       G4String msg = "Invalid unit ["+unit+"] (Current  unit is [" +GetUnit()+"] ) for " + GetName();
00115     G4Exception("G4PSNofSecondary::SetUnit","DetPS0010",JustWarning,msg);
00116   }
00117 }
00118 

Generated on Mon May 27 17:49:28 2013 for Geant4 by  doxygen 1.4.7