Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4VUserDetectorConstruction Class Referenceabstract

#include <G4VUserDetectorConstruction.hh>

Public Member Functions

 G4VUserDetectorConstruction ()
 
virtual ~G4VUserDetectorConstruction ()
 
virtual G4VPhysicalVolumeConstruct ()=0
 
virtual void ConstructSDandField ()
 
virtual void CloneSD ()
 
virtual void CloneF ()
 
void RegisterParallelWorld (G4VUserParallelWorld *)
 
G4int ConstructParallelGeometries ()
 
void ConstructParallelSD ()
 
G4int GetNumberOfParallelWorld () const
 
G4VUserParallelWorldGetParallelWorld (G4int i) const
 

Protected Member Functions

void SetSensitiveDetector (const G4String &logVolName, G4VSensitiveDetector *aSD, G4bool multi=false)
 
void SetSensitiveDetector (G4LogicalVolume *logVol, G4VSensitiveDetector *aSD)
 

Detailed Description

Definition at line 50 of file G4VUserDetectorConstruction.hh.

Constructor & Destructor Documentation

G4VUserDetectorConstruction::G4VUserDetectorConstruction ( )

Definition at line 42 of file G4VUserDetectorConstruction.cc.

43 {;}
G4VUserDetectorConstruction::~G4VUserDetectorConstruction ( )
virtual

Definition at line 45 of file G4VUserDetectorConstruction.cc.

46 {;}

Member Function Documentation

void G4VUserDetectorConstruction::CloneF ( )
virtual

Definition at line 109 of file G4VUserDetectorConstruction.cc.

110 {
111  typedef std::map<G4FieldManager*,G4FieldManager*> FMtoFMmap;
112  typedef std::pair<G4FieldManager*,G4FieldManager*> FMpair;
113  FMtoFMmap masterToWorker;
115  assert( logVolStore != NULL );
116  for ( G4LogicalVolumeStore::const_iterator it = logVolStore->begin() ; it != logVolStore->end() ; ++it )
117  {
118  G4LogicalVolume *g4LogicalVolume = *it;
119  //Use shadow of master to get instance of FM
120  G4FieldManager* masterFM = 0;//g4LogicalVolume->fFieldManager;
121  G4FieldManager* clonedFM = 0;
122  if ( masterFM )
123  {
124  FMtoFMmap::iterator fmFound = masterToWorker.find(masterFM);
125  if ( fmFound == masterToWorker.end() )
126  {
127  //First time we see this SD, let's clone and remember...
128  try {
129  std::pair<FMtoFMmap::iterator,bool> insertedEl = masterToWorker.insert( FMpair(masterFM, masterFM->Clone()) );
130  clonedFM = (insertedEl.first)->second;
131  }
132  catch (...)
133  {
135  msg << "Cloning of G4FieldManager failed."
136  << " But derived class does not implement cloning. Cannot continue.";
137  G4Exception("G4VUserDetectorConstruction::CloneSD", "Run0053", FatalException,msg);
138 
139  }
140  }
141  else
142  {
143  // We have already seen this SD attached to a fifferent LogicalVolume, let's re-use previous clone
144  clonedFM = (*fmFound).second;
145  }
146  }// masterFM != 0
147  //Note that we do not push FM to doughters (false argument), however, since we area looping on all
148  //logical volumes and we implemented the "trick" of the map master<->cloned the final
149  //effect is the same as using here the correct boolean flag: log-volumes that originally were sharing
150  //the same FM they will have cloned ones
151  g4LogicalVolume->SetFieldManager(clonedFM, false);
152  }
153 }
virtual G4FieldManager * Clone() const
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
static constexpr double second
Definition: G4SIunits.hh:157
void SetFieldManager(G4FieldManager *pFieldMgr, G4bool forceToAllDaughters)
static G4LogicalVolumeStore * GetInstance()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

void G4VUserDetectorConstruction::CloneSD ( )
virtual

Definition at line 155 of file G4VUserDetectorConstruction.cc.

156 {
157  //Loop on ALL logial volumes to search for attached SD
159  assert( logVolStore != NULL );
160 
161  typedef std::map<G4VSensitiveDetector*,G4VSensitiveDetector*> SDtoSDmap;
162  typedef std::pair<G4VSensitiveDetector*,G4VSensitiveDetector*> SDpair;
163  SDtoSDmap masterToWorker;
164 
165  for ( G4LogicalVolumeStore::const_iterator it = logVolStore->begin() ; it != logVolStore->end() ; ++it )
166  {
167  G4LogicalVolume *g4LogicalVolume = *it;
168  //Use shadow of master to get the instance of SD
169  G4VSensitiveDetector* masterSD = 0;//g4LogicalVolume->fSensitiveDetector;
170  G4VSensitiveDetector* clonedSD = 0;
171  if ( masterSD )
172  {
173  SDtoSDmap::iterator sdFound = masterToWorker.find(masterSD);
174  if ( sdFound == masterToWorker.end() )
175  {
176  //First time we see this SD, let's clone and remember...
177  try {
178  std::pair<SDtoSDmap::iterator,bool> insertedEl = masterToWorker.insert( SDpair(masterSD,masterSD->Clone()) );
179  clonedSD = (insertedEl.first)->second;
180  }
181  catch (...)
182  {
184  msg << "Cloning of G4VSensitiveDetector requested for:" << masterSD->GetName() << "\n"
185 #ifndef WIN32
186  << " (full path name: " << masterSD->GetFullPathName() << ").\n"
187 #endif
188  << " But derived class does not implement cloning. Cannot continue.";
189  G4Exception("G4VUserDetectorConstruction::CloneSD", "Run0053", FatalException,msg);
190  }
191 
192  }
193  else
194  {
195  // We have already seen this SD attached to a fifferent LogicalVolume, let's re-use previous clone
196  clonedSD = (*sdFound).second;
197 
198  }
199  }// masterSD!=0
200  g4LogicalVolume->SetSensitiveDetector(clonedSD);
201 
202  }
203 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
static constexpr double second
Definition: G4SIunits.hh:157
virtual G4VSensitiveDetector * Clone() const
static G4LogicalVolumeStore * GetInstance()
G4String GetFullPathName() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)

Here is the call graph for this function:

virtual G4VPhysicalVolume* G4VUserDetectorConstruction::Construct ( )
pure virtual

Here is the caller graph for this function:

G4int G4VUserDetectorConstruction::ConstructParallelGeometries ( )

Definition at line 65 of file G4VUserDetectorConstruction.cc.

66 {
67  G4int nP = 0;
68  std::vector<G4VUserParallelWorld*>::iterator pwItr;
69  for(pwItr=parallelWorld.begin();pwItr!=parallelWorld.end();pwItr++)
70  {
71  (*pwItr)->Construct();
72  nP++;
73  }
74  return nP;
75 }
int G4int
Definition: G4Types.hh:78

Here is the caller graph for this function:

void G4VUserDetectorConstruction::ConstructParallelSD ( )

Definition at line 77 of file G4VUserDetectorConstruction.cc.

78 {
79  std::vector<G4VUserParallelWorld*>::iterator pwItr;
80  for(pwItr=parallelWorld.begin();pwItr!=parallelWorld.end();pwItr++)
81  { (*pwItr)->ConstructSD(); }
82 }

Here is the caller graph for this function:

void G4VUserDetectorConstruction::ConstructSDandField ( )
virtual

Definition at line 95 of file G4VUserDetectorConstruction.cc.

96 {
97 // G4RunManager::RMType rmtype = G4RunManager::GetRunManager()->GetRunManagerType();
98 // if(rmtype != G4RunManager::sequentialRM)
99 // {
100 // G4cout
101 // << "User-derived detector construction class does not implement \n"
102 // << "ConstructSDandFiled method: i.e. workers will not have SD and fields!\n"
103 // << "The user can safely ignore this message if (s)he has no sensitive\n"
104 // << "detector or field in her/his application." << G4endl;
105 // }
106 }

Here is the caller graph for this function:

G4int G4VUserDetectorConstruction::GetNumberOfParallelWorld ( ) const

Definition at line 84 of file G4VUserDetectorConstruction.cc.

85 { return parallelWorld.size(); }

Here is the caller graph for this function:

G4VUserParallelWorld * G4VUserDetectorConstruction::GetParallelWorld ( G4int  i) const

Definition at line 87 of file G4VUserDetectorConstruction.cc.

88 {
89  if(i<0||i>=GetNumberOfParallelWorld()) return 0;
90  return parallelWorld[i];
91 }

Here is the call graph for this function:

void G4VUserDetectorConstruction::RegisterParallelWorld ( G4VUserParallelWorld aPW)

Definition at line 48 of file G4VUserDetectorConstruction.cc.

49 {
50  std::vector<G4VUserParallelWorld*>::iterator pwItr;
51  for(pwItr=parallelWorld.begin();pwItr!=parallelWorld.end();pwItr++)
52  {
53  if((*pwItr)->GetName()==aPW->GetName())
54  {
55  G4String eM = "A parallel world <";
56  eM += aPW->GetName();
57  eM += "> is already registered to the user detector construction.";
58  G4Exception("G4VUserDetectorConstruction::RegisterParallelWorld",
59  "Run0051",FatalErrorInArgument,eM);
60  }
61  }
62  parallelWorld.push_back(aPW);
63 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

void G4VUserDetectorConstruction::SetSensitiveDetector ( const G4String logVolName,
G4VSensitiveDetector aSD,
G4bool  multi = false 
)
protected

Definition at line 206 of file G4VUserDetectorConstruction.cc.

207 {
208  G4bool found = false;
210  for(G4LogicalVolumeStore::iterator pos=store->begin(); pos!=store->end(); pos++)
211  {
212  if((*pos)->GetName()==logVolName)
213  {
214  if(found && !multi)
215  {
216  G4String eM = "More than one logical volumes of the name <";
217  eM += (*pos)->GetName();
218  eM += "> are found and thus the sensitive detector <";
219  eM += aSD->GetName();
220  eM += "> cannot be uniquely assigned.";
221  G4Exception("G4VUserDetectorConstruction::SetSensitiveDetector",
222  "Run0052",FatalErrorInArgument,eM);
223  }
224  found = true;
226  }
227  }
228  if(!found)
229  {
230  G4String eM2 = "No logical volume of the name <";
231  eM2 += logVolName;
232  eM2 += "> is found. The specified sensitive detector <";
233  eM2 += aSD->GetName();
234  eM2 += "> couldn't be assigned to any volume.";
235  G4Exception("G4VUserDetectorConstruction::SetSensitiveDetector",
236  "Run0053",FatalErrorInArgument,eM2);
237  }
238 }
bool G4bool
Definition: G4Types.hh:79
static G4LogicalVolumeStore * GetInstance()
void SetSensitiveDetector(const G4String &logVolName, G4VSensitiveDetector *aSD, G4bool multi=false)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static const G4double pos

Here is the call graph for this function:

void G4VUserDetectorConstruction::SetSensitiveDetector ( G4LogicalVolume logVol,
G4VSensitiveDetector aSD 
)
protected

Definition at line 241 of file G4VUserDetectorConstruction.cc.

242 {
243  assert(logVol!=nullptr&&aSD!=nullptr);
244 
245  //The aSD has already been added by user to the manager if needed
246  //G4SDManager::GetSDMpointer()->AddNewDetector(aSD);
247 
248  //New Logic: allow for "multiple" SDs being attached to a single LV.
249  //To do that we use a special proxy SD called G4MultiSensitiveDetector
250 
251  //Get existing SD if already set and check if it is of the special type
252  G4VSensitiveDetector* originalSD = logVol->GetSensitiveDetector();
253  if ( originalSD == nullptr ) {
254  logVol->SetSensitiveDetector(aSD);
255  } else {
256  G4MultiSensitiveDetector* msd = dynamic_cast<G4MultiSensitiveDetector*>(originalSD);
257  if ( msd != nullptr ) {
258  msd->AddSD(aSD);
259  } else {
260  std::ostringstream mn;
261  mn<<"/MultiSD_"<<logVol->GetName()<<"_"<<logVol;
262  const G4String msdname = mn.str();
263  msd = new G4MultiSensitiveDetector(msdname);
264  //We need to register the proxy to have correct handling of IDs
266  msd->AddSD(originalSD);
267  msd->AddSD(aSD);
268  logVol->SetSensitiveDetector(msd);
269  }
270  }
271 }
void AddSD(G4VSensitiveDetector *sd)
void AddNewDetector(G4VSensitiveDetector *aSD)
Definition: G4SDManager.cc:71
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
const G4String & GetName() const
G4VSensitiveDetector * GetSensitiveDetector() const
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)

Here is the call graph for this function:


The documentation for this class was generated from the following files: