G4PSTrackLength.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 // G4PSTrackLength
00030 #include "G4PSTrackLength.hh"
00031 #include "G4SystemOfUnits.hh"
00032 #include "G4UnitsTable.hh"
00034 // (Description)
00035 //   This is a primitive scorer class for scoring sum of track length.
00036 // 
00037 //
00038 // Created: 2007-02-02  Tsukasa ASO, Akinori Kimura.
00039 //          2010-07-22  Introduce Unit specification.
00040 //          2011-09-09  Modify comment in PrintAll().
00041 // 
00043 
00044 G4PSTrackLength::G4PSTrackLength(G4String name, G4int depth)
00045     :G4VPrimitiveScorer(name,depth),HCID(-1),weighted(false),multiplyKinE(false),
00046      divideByVelocity(false)
00047 {
00048     DefineUnitAndCategory();
00049     SetUnit("mm");
00050 }
00051 
00052 G4PSTrackLength::G4PSTrackLength(G4String name, const G4String& unit, 
00053                                  G4int depth)
00054     :G4VPrimitiveScorer(name,depth),HCID(-1),weighted(false),multiplyKinE(false),
00055      divideByVelocity(false)
00056 {
00057     DefineUnitAndCategory();
00058     SetUnit(unit);
00059 }
00060 
00061 G4PSTrackLength::~G4PSTrackLength()
00062 {;}
00063 
00064 void G4PSTrackLength::MultiplyKineticEnergy(G4bool flg)
00065 { 
00066     multiplyKinE = flg; 
00067     // Default unit is set according to flags.
00068     SetUnit(""); 
00069 }
00070 
00071 void G4PSTrackLength::DivideByVelocity(G4bool flg) 
00072 { 
00073     divideByVelocity = flg; 
00074     // Default unit is set according to flags.
00075     SetUnit(""); 
00076 }
00077 
00078 G4bool G4PSTrackLength::ProcessHits(G4Step* aStep,G4TouchableHistory*)
00079 {
00080   G4double trklength  = aStep->GetStepLength();
00081   if ( trklength == 0. ) return FALSE;
00082   if(weighted) trklength *= aStep->GetPreStepPoint()->GetWeight();
00083   if(multiplyKinE) trklength *= aStep->GetPreStepPoint()->GetKineticEnergy();
00084   if(divideByVelocity) trklength /= aStep->GetPreStepPoint()->GetVelocity();
00085   G4int  index = GetIndex(aStep);
00086   EvtMap->add(index,trklength);  
00087   return TRUE;
00088 }
00089 
00090 void G4PSTrackLength::Initialize(G4HCofThisEvent* HCE)
00091 {
00092   EvtMap = new G4THitsMap<G4double>(detector->GetName(),GetName());
00093   if(HCID < 0) {HCID = GetCollectionID(0);}
00094   HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
00095 }
00096 
00097 void G4PSTrackLength::EndOfEvent(G4HCofThisEvent*)
00098 {;}
00099 
00100 void G4PSTrackLength::clear(){
00101   EvtMap->clear();
00102 }
00103 
00104 void G4PSTrackLength::DrawAll()
00105 {;}
00106 
00107 void G4PSTrackLength::PrintAll()
00108 {
00109   G4cout << " MultiFunctionalDet  " << detector->GetName() << G4endl;
00110   G4cout << " PrimitiveScorer " << GetName() << G4endl;
00111   G4cout << " Number of entries " << EvtMap->entries() << G4endl;
00112   std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
00113   for(; itr != EvtMap->GetMap()->end(); itr++) {
00114       G4cout << "  copy no.: " << itr->first ;
00115       if ( multiplyKinE ){
00116         if ( divideByVelocity ) G4cout << " EnergyFlux: ";
00117         else                    G4cout << " EnergyFlow: ";
00118       }else{
00119         if ( divideByVelocity ) G4cout << " Time: ";
00120         else                    G4cout << " Length: ";
00121       }
00122       G4cout << *(itr->second)/GetUnitValue()
00123              << " ["<< GetUnit() << "]";
00124       G4cout << G4endl;
00125   }
00126 }
00127 
00128 void G4PSTrackLength::SetUnit(const G4String& unit)
00129 {
00130     if ( multiplyKinE ){
00131         if ( divideByVelocity ){
00132             if ( unit == "" ) {
00133                 CheckAndSetUnit("MeV_second","EnergyFlux");
00134             } else {
00135                 CheckAndSetUnit(unit,"EnergyFlux");
00136             }
00137         }else {
00138             if ( unit == "" ) {
00139                 CheckAndSetUnit("MeV_mm","EnergyFlow");
00140             } else {
00141                 CheckAndSetUnit(unit,"EnergyFlow");
00142             }
00143         }
00144     }else {
00145         if ( divideByVelocity ){
00146             if ( unit == "" ) {
00147                 CheckAndSetUnit("second","Time");
00148             } else {
00149                 CheckAndSetUnit(unit,"Time");
00150             }
00151         }else {
00152             if ( unit == "") {
00153                 CheckAndSetUnit("mm","Length");
00154             } else {
00155                 CheckAndSetUnit(unit,"Length");
00156             }
00157         }
00158     } 
00159 }
00160 
00161 void G4PSTrackLength::DefineUnitAndCategory(){
00162     // EnergyFlux
00163     new G4UnitDefinition("eV_second","eV_s","EnergyFlux",(eV*second));
00164     new G4UnitDefinition("keV_second","keV_s","EnergyFlux",(keV*second));
00165     new G4UnitDefinition("MeV_second","MeV_s","EnergyFlux",(MeV*second));
00166     new G4UnitDefinition("eV_millisecond","eV_ms","EnergyFlux",(eV*ms));
00167     new G4UnitDefinition("keV_millisecond","keV_ms","EnergyFlux",(keV*ms));
00168     new G4UnitDefinition("MeV_millisecond","MeV_ms","EnergyFlux",(MeV*ms));
00169     //EnergyFlow
00170     new G4UnitDefinition("eV_millimeter","eV_mm","EnergyFlow",(eV*mm));
00171     new G4UnitDefinition("keV_millimeter","keV_mm","EnergyFlow",(keV*mm));
00172     new G4UnitDefinition("MeV_millimeter","MeV_mm","EnergyFlow",(MeV*mm));
00173     new G4UnitDefinition("eV_centimeter","eV_cm","EnergyFlow",(eV*cm));
00174     new G4UnitDefinition("keV_centimeter","keV_cm","EnergyFlow",(keV*cm));
00175     new G4UnitDefinition("MeV_centimeter","MeV_cm","EnergyFlow",(MeV*cm));
00176     new G4UnitDefinition("eV_meter","eV_m","EnergyFlow",(eV*m));
00177     new G4UnitDefinition("keV_meter","keV_m","EnergyFlow",(keV*m));
00178     new G4UnitDefinition("MeV_meter","MeV_m","EnergyFlow",(MeV*m));
00179 }
00180 
00181 
00182 

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