source: trunk/source/digits_hits/utils/src/G4VScoringMesh.cc @ 814

Last change on this file since 814 was 814, checked in by garnier, 16 years ago

import all except CVS

File size: 7.5 KB
Line 
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//
27// $Id: G4VScoringMesh.cc,v 1.34 2007/11/07 04:12:07 akimura Exp $
28// GEANT4 tag $Name: geant4-09-01-patch-02 $
29//
30
31#include "G4VScoringMesh.hh"
32#include "G4VPhysicalVolume.hh"
33#include "G4MultiFunctionalDetector.hh"
34#include "G4VPrimitiveScorer.hh"
35#include "G4VSDFilter.hh"
36#include "G4SDManager.hh"
37
38G4VScoringMesh::G4VScoringMesh(G4String wName)
39  : fWorldName(wName),fConstructed(false),fActive(true),
40    fRotationMatrix(NULL), fMFD(new G4MultiFunctionalDetector(wName)),
41    verboseLevel(0),sizeIsSet(false),nMeshIsSet(false)
42{
43  G4SDManager::GetSDMpointer()->AddNewDetector(fMFD);
44
45  fSize[0] = fSize[1] = fSize[2] = 0.;
46  fNSegment[0] = fNSegment[1] = fNSegment[2] = 1;
47}
48
49G4VScoringMesh::~G4VScoringMesh()
50{
51  ;
52}
53
54void G4VScoringMesh::ResetScore() {
55  if(verboseLevel > 9) G4cout << "G4VScoringMesh::ResetScore() is called." << G4endl;
56  std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.begin();
57  for(; itr != fMap.end(); itr++) {
58    if(verboseLevel > 9) G4cout << "G4VScoringMesh::ResetScore()" << itr->first << G4endl;
59    itr->second->clear();
60  }
61}
62void G4VScoringMesh::SetSize(G4double size[3]) {
63  for(int i = 0; i < 3; i++) fSize[i] = size[i];
64  sizeIsSet = true;
65}
66void G4VScoringMesh::SetCenterPosition(G4double centerPosition[3]) {
67  fCenterPosition = G4ThreeVector(centerPosition[0], centerPosition[1], centerPosition[2]);
68}
69void G4VScoringMesh::SetNumberOfSegments(G4int nSegment[3]) {
70  for(int i = 0; i < 3; i++) fNSegment[i] = nSegment[i];
71  nMeshIsSet = true;
72}
73void G4VScoringMesh::GetNumberOfSegments(G4int nSegment[3]) {
74  for(int i = 0; i < 3; i++) nSegment[i] = fNSegment[i];
75}
76void G4VScoringMesh::RotateX(G4double delta) {
77  if(fRotationMatrix == NULL) fRotationMatrix = new G4RotationMatrix();
78  fRotationMatrix->rotateX(delta);
79}
80
81void G4VScoringMesh::RotateY(G4double delta) {
82  if(fRotationMatrix == NULL) fRotationMatrix = new G4RotationMatrix();
83  fRotationMatrix->rotateY(delta);
84}
85
86void G4VScoringMesh::RotateZ(G4double delta) {
87  if(fRotationMatrix == NULL) fRotationMatrix = new G4RotationMatrix();
88  fRotationMatrix->rotateZ(delta);
89}
90
91void G4VScoringMesh::SetPrimitiveScorer(G4VPrimitiveScorer * ps) {
92
93  if(!ReadyForQuantity())
94  {
95    G4cerr << "ERROR : G4VScoringMesh::SetPrimitiveScorer() : " << ps->GetName() 
96           << " does not yet have mesh size or number of bins. Set them first." << G4endl
97           << "This Method is ignored." << G4endl;
98    return;
99  }
100  if(verboseLevel > 0) G4cout << "G4VScoringMesh::SetPrimitiveScorer() : "
101                              << ps->GetName() << " is registered."
102                              << " 3D size: ("
103                              << fNSegment[0] << ", "
104                              << fNSegment[1] << ", "
105                              << fNSegment[2] << ")" << G4endl;
106
107  ps->SetNijk(fNSegment[0], fNSegment[1], fNSegment[2]);
108  fCurrentPS = ps;
109  fMFD->RegisterPrimitive(ps);
110  G4THitsMap<G4double> * map = new G4THitsMap<G4double>(fWorldName, ps->GetName());
111  fMap[ps->GetName()] = map;
112}
113
114void G4VScoringMesh::SetFilter(G4VSDFilter * filter) {
115
116  if(fCurrentPS == NULL) {
117    G4cerr << "ERROR : G4VScoringMesh::SetSDFilter() : a quantity must be defined first. This method is ignored." << G4endl;
118    return;
119  }
120  if(verboseLevel > 0) G4cout << "G4VScoringMesh::SetFilter() : "
121                              << filter->GetName()
122                              << " is set to "
123                              << fCurrentPS->GetName() << G4endl;
124
125  G4VSDFilter* oldFilter = fCurrentPS->GetFilter();
126  if(oldFilter)
127  {
128    G4cout << "WARNING : G4VScoringMesh::SetFilter() : " << oldFilter->GetName() 
129           << " is overwritten by " << filter->GetName() << G4endl;
130  }
131  fCurrentPS->SetFilter(filter);
132}
133
134void G4VScoringMesh::SetCurrentPrimitiveScorer(G4String & name) {
135  fCurrentPS = GetPrimitiveScorer(name);
136  if(fCurrentPS == NULL) {
137    G4cerr << "ERROR : G4VScoringMesh::SetCurrentPrimitiveScorer() : The primitive scorer <"
138           << name << "> does not found." << G4endl;
139  }
140}
141
142G4bool G4VScoringMesh::FindPrimitiveScorer(G4String & psname) {
143  std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.find(psname);;
144  if(itr == fMap.end()) return false;
145  return true;
146}
147
148G4VPrimitiveScorer * G4VScoringMesh::GetPrimitiveScorer(G4String & name) {
149  if(fMFD == NULL) return NULL;
150
151  G4int nps = fMFD->GetNumberOfPrimitives();
152  for(G4int i = 0; i < nps; i++) {
153    G4VPrimitiveScorer * ps = fMFD->GetPrimitive(i);
154    if(name == ps->GetName()) return ps;
155  }
156
157  return NULL;
158}
159void G4VScoringMesh::List() const {
160  G4cout << " Size: ("
161         << fSize[0]/cm << ", "
162         << fSize[1]/cm << ", "
163         << fSize[2]/cm << ") [cm]"
164         << G4endl;
165  G4cout << " # of segments: ("
166         << fNSegment[0] << ", "
167         << fNSegment[1] << ", "
168         << fNSegment[2] << ")"
169         << G4endl;
170  G4cout << " displacement: ("
171         << fCenterPosition.x()/cm << ", "
172         << fCenterPosition.y()/cm << ", "
173         << fCenterPosition.z()/cm << ") [cm]"
174         << G4endl;
175  if(fRotationMatrix != 0) {
176    G4cout << " rotation matrix: "
177           << fRotationMatrix->xx() << "  "
178           << fRotationMatrix->xy() << "  "
179           << fRotationMatrix->xz() << G4endl
180           << "                  "
181           << fRotationMatrix->yx() << "  "
182           << fRotationMatrix->yy() << "  "
183           << fRotationMatrix->yz() << G4endl
184           << "                  "
185           << fRotationMatrix->zx() << "  "
186           << fRotationMatrix->zy() << "  "
187           << fRotationMatrix->zz() << G4endl;
188  }
189
190
191  G4cout << " registered primitve scorers : " << G4endl;
192  G4int nps = fMFD->GetNumberOfPrimitives();
193  G4VPrimitiveScorer * ps;
194  for(int i = 0; i < nps; i++) {
195    ps = fMFD->GetPrimitive(i);
196    G4cout << "   " << i << "  " << ps->GetName();
197    if(ps->GetFilter() != NULL) G4cout << "     with  " << ps->GetFilter()->GetName();
198    G4cout << G4endl;
199  }
200
201
202}
203
204void G4VScoringMesh::Dump() {
205  G4cout << "scoring mesh name: " << fWorldName << G4endl;
206
207  G4cout << "# of G4THitsMap : " << fMap.size() << G4endl;
208  std::map<G4String, G4THitsMap<G4double>* >::iterator itr = fMap.begin();
209  for(; itr != fMap.end(); itr++) {
210    G4cout << "[" << itr->first << "]" << G4endl;
211    itr->second->PrintAllHits();
212  }
213  G4cout << G4endl;
214
215}
216
Note: See TracBrowser for help on using the repository browser.