G4PSFlatSurfaceCurrent.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 // G4PSFlatSurfaceCurrent
00030 #include "G4PSFlatSurfaceCurrent.hh"
00031 
00032 #include "G4SystemOfUnits.hh"
00033 #include "G4StepStatus.hh"
00034 #include "G4Track.hh"
00035 #include "G4VSolid.hh"
00036 #include "G4VPhysicalVolume.hh"
00037 #include "G4VPVParameterisation.hh"
00038 #include "G4UnitsTable.hh"
00039 #include "G4GeometryTolerance.hh"
00041 // (Description)
00042 //   This is a primitive scorer class for scoring only Surface Flux.
00043 //  Current version assumes only for G4Box shape. 
00044 //
00045 // Surface is defined at the -Z surface.
00046 // Direction                  -Z   +Z
00047 //   0  IN || OUT            ->|<-  |
00048 //   1  IN                   ->|    |
00049 //   2  OUT                    |<-  |
00050 //
00051 // Created: 2005-11-14  Tsukasa ASO, Akinori Kimura.
00052 // 17-Nov-2005 T.Aso, Bug fix for area definition.
00053 // 31-Mar-2007 T.Aso, Add option for normalizing by the area.
00054 // 2010-07-22   Introduce Unit specification.
00055 // 
00057 
00058 
00059 G4PSFlatSurfaceCurrent::G4PSFlatSurfaceCurrent(G4String name, 
00060                                          G4int direction, G4int depth)
00061     :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction),
00062      weighted(true),divideByArea(true)
00063 {
00064     DefineUnitAndCategory();
00065     SetUnit("percm2");
00066 }
00067 
00068 G4PSFlatSurfaceCurrent::G4PSFlatSurfaceCurrent(G4String name, 
00069                                                G4int direction, 
00070                                                const G4String& unit, 
00071                                                G4int depth)
00072     :G4VPrimitiveScorer(name,depth),HCID(-1),fDirection(direction),
00073      weighted(true),divideByArea(true)
00074 {
00075     DefineUnitAndCategory();
00076     SetUnit(unit);
00077 }
00078 
00079 G4PSFlatSurfaceCurrent::~G4PSFlatSurfaceCurrent()
00080 {;}
00081 
00082 G4bool G4PSFlatSurfaceCurrent::ProcessHits(G4Step* aStep,G4TouchableHistory*)
00083 {
00084   G4StepPoint* preStep = aStep->GetPreStepPoint();
00085   G4VPhysicalVolume* physVol = preStep->GetPhysicalVolume();
00086   G4VPVParameterisation* physParam = physVol->GetParameterisation();
00087   G4VSolid * solid = 0;
00088   if(physParam)
00089   { // for parameterized volume
00090     G4int idx = ((G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable()))
00091                 ->GetReplicaNumber(indexDepth);
00092     solid = physParam->ComputeSolid(idx, physVol);
00093     solid->ComputeDimensions(physParam,idx,physVol);
00094   }
00095   else
00096   { // for ordinary volume
00097     solid = physVol->GetLogicalVolume()->GetSolid();
00098   }
00099 
00100   G4Box* boxSolid = (G4Box*)(solid);
00101 
00102   G4int dirFlag =IsSelectedSurface(aStep,boxSolid);
00103   if ( dirFlag > 0 ) {
00104    if ( fDirection == fCurrent_InOut || fDirection == dirFlag ){
00105        G4int index = GetIndex(aStep);
00106        G4TouchableHandle theTouchable = preStep->GetTouchableHandle();
00107        G4double current = 1.0;
00108        if ( weighted ) current=preStep->GetWeight(); // Current (Particle Weight)
00109        if ( divideByArea ){
00110            G4double square = 4.*boxSolid->GetXHalfLength()*boxSolid->GetYHalfLength();
00111            current = current/square;  // Normalized by Area
00112        }
00113        EvtMap->add(index,current);
00114    }
00115   }
00116 
00117   return TRUE;
00118 }
00119 
00120 G4int G4PSFlatSurfaceCurrent::IsSelectedSurface(G4Step* aStep, G4Box* boxSolid){
00121 
00122   G4TouchableHandle theTouchable = 
00123     aStep->GetPreStepPoint()->GetTouchableHandle();
00124   G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
00125 
00126   if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary ){
00127     // Entering Geometry
00128     G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition();
00129     G4ThreeVector localpos1 = 
00130       theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1);
00131     if(std::fabs( localpos1.z() + boxSolid->GetZHalfLength())<kCarTolerance ){
00132       return fCurrent_In;
00133     }
00134   }
00135 
00136   if (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary ){
00137     // Exiting Geometry
00138     G4ThreeVector stppos2= aStep->GetPostStepPoint()->GetPosition();
00139     G4ThreeVector localpos2 = 
00140       theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos2);
00141     if(std::fabs( localpos2.z() + boxSolid->GetZHalfLength())<kCarTolerance ){
00142       return fCurrent_Out;
00143     }
00144   }
00145 
00146   return -1;
00147 }
00148 
00149 void G4PSFlatSurfaceCurrent::Initialize(G4HCofThisEvent* HCE)
00150 {
00151   EvtMap = new G4THitsMap<G4double>(detector->GetName(), GetName());
00152   if ( HCID < 0 ) HCID = GetCollectionID(0);
00153   HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap);
00154 }
00155 
00156 void G4PSFlatSurfaceCurrent::EndOfEvent(G4HCofThisEvent*)
00157 {;}
00158 
00159 void G4PSFlatSurfaceCurrent::clear(){
00160   EvtMap->clear();
00161 }
00162 
00163 void G4PSFlatSurfaceCurrent::DrawAll()
00164 {;}
00165 
00166 void G4PSFlatSurfaceCurrent::PrintAll()
00167 {
00168   G4cout << " MultiFunctionalDet  " << detector->GetName() << G4endl;
00169   G4cout << " PrimitiveScorer " << GetName() <<G4endl; 
00170   G4cout << " Number of entries " << EvtMap->entries() << G4endl;
00171   std::map<G4int,G4double*>::iterator itr = EvtMap->GetMap()->begin();
00172   for(; itr != EvtMap->GetMap()->end(); itr++) {
00173       G4cout << "  copy no.: " << itr->first << " current : " ;
00174       if ( divideByArea ) {
00175           G4cout << *(itr->second)/GetUnitValue() 
00176                  << " ["<<GetUnit()<<"]";
00177       }else {
00178           G4cout <<  *(itr->second)/GetUnitValue() << " [tracks]";
00179       }
00180       G4cout << G4endl;
00181   }
00182 }
00183 
00184 void G4PSFlatSurfaceCurrent::SetUnit(const G4String& unit)
00185 {
00186     if ( divideByArea ) {
00187         CheckAndSetUnit(unit,"Per Unit Surface");
00188     } else {
00189         if (unit == "" ){
00190             unitName = unit;
00191             unitValue = 1.0;
00192         }else{
00193             G4String msg = "Invalid unit ["+unit+"] (Current  unit is [" +GetUnit()+"] ) for " + GetName();
00194             G4Exception("G4PSFlatSurfaceCurrent::SetUnit","DetPS0007",JustWarning,msg);
00195         }
00196     }
00197 }
00198 
00199 void G4PSFlatSurfaceCurrent::DefineUnitAndCategory(){
00200    // Per Unit Surface
00201    new G4UnitDefinition("percentimeter2","percm2","Per Unit Surface",(1./cm2));
00202    new G4UnitDefinition("permillimeter2","permm2","Per Unit Surface",(1./mm2));
00203    new G4UnitDefinition("permeter2","perm2","Per Unit Surface",(1./m2));
00204 }
00205 

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