Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OlapManager.cc
Go to the documentation of this file.
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 //
28 //
29 //
30 // $Id$
31 //
32 //
33 // --------------------------------------------------------------
34 // OlapManager
35 //
36 // Author: Martin Liendl - Martin.Liendl@cern.ch
37 //
38 // --------------------------------------------------------------
39 //
40 #include <stdlib.h>
41 
42 #include <vector>
43 
44 #include "OlapManager.hh"
45 #include "OlapDetConstr.hh"
46 #include "OlapManagerMessenger.hh"
47 #include "OlapGenerator.hh"
48 #include "OlapEventAction.hh"
49 #include "G4GeoNav.hh"
50 #include "G4GeometryTolerance.hh"
51 #include "G4RunManager.hh"
52 #include "globals.hh"
53 
54 OlapManager * OlapManager::theInstance = 0;
55 
56 OlapManager::OlapManager()
57  : olapGenerator(0), eventsPerRun(27), lvPos(0),
58  polyMode(false), interrupt(false)
59 {
60  theMessenger = new OlapManagerMessenger(this);
61  theLVStore = G4LogicalVolumeStore::GetInstance();
62 
64  theRunManager = G4RunManager::GetRunManager();
65  const G4VUserDetectorConstruction * aTmp =
66  theRunManager->GetUserDetectorConstruction();
67 
68  const OlapDetConstr * aConstDetConstr =
69  dynamic_cast<const OlapDetConstr*>(aTmp);
70  if (!aConstDetConstr)
71  {
72  G4Exception("OlapManager::OlapManager()", "InvalidSetup", FatalException,
73  "Can't get the OlapDetConstr instance! Exiting...");
74  }
75 
76  // need a non-const instance for building NewWords!
77  theDet = const_cast<OlapDetConstr*>(aConstDetConstr);
78 
79  // instantiate the logical volume tree & add it to the Gui
80  theGeoNav = new G4GeoNav(theDet->GetFullWorld()->GetLogicalVolume());
81 
82  std::vector<G4LogicalVolume*>::iterator aIt2;
83  for (aIt2=theLVStore->begin(); aIt2 != theLVStore->end(); aIt2++)
84  NoOlapMap[*aIt2] = false;
85 }
86 
87 
89 {
90  delete theMessenger;
91  delete theGeoNav;
92  delete olapGenerator;
93 }
94 
95 
97 {
98  if (!theInstance)
99  theInstance = new OlapManager();
100 
101  return theInstance;
102 }
103 
104 
106 {
107  theDet->SetRotation(theta,phi,alpha);
108 }
109 
110 
111 
113 {
114  const OlapGenerator * aGen = dynamic_cast<const OlapGenerator *>
116  OlapGenerator * aNonConstGen = 0;
117  if ( aGen )
118  {
119  aNonConstGen = const_cast<OlapGenerator*>(aGen);
120  }
121  else
122  {
123  G4cout << "Warning: Primary generator is not OlapGenerator!" << G4endl
124  << " Overlap Detection will not work!" << G4endl;
125  return;
126  }
127  //while
128  aNonConstGen->SetAutoIncrement(true);
129  theRunManager->BeamOn(eventsPerRun);
130  aNonConstGen->SetAutoIncrement(false);
131 }
132 
133 
135 {
136  const OlapGenerator * aGen = dynamic_cast<const OlapGenerator *>
138  OlapGenerator * aNonConstGen = 0;
139  if ( aGen )
140  {
141  aNonConstGen = const_cast<OlapGenerator*>(aGen);
142  }
143  else
144  {
145  G4cout << "Warning: Primary generator is not OlapGenerator!" << G4endl
146  << " Overlap Detection will not work!" << G4endl;
147  return;
148  }
149  //while
150  aNonConstGen->SetAutoIncrement(true);
151 
152  interrupt = false; // can be changed to 'true' in the following loop
153  // by subclasses of OlapNotify. In that case,
154  // the triggerFull-command will be stopped.
155 
156  while (Next() && trg)
157  {
158  if (theDet->GetNewWorld()->GetLogicalVolume()->GetDaughter(0)->
159  GetLogicalVolume()->GetNoDaughters())
160  {
161  theRunManager->BeamOn(eventsPerRun);
162  trg--;
163  if (interrupt)
164  {
165  break;
166  }
167  }
168  }
169  aNonConstGen->SetAutoIncrement(false);
170 }
171 
173 {
174  return theDet->GetNewWorld();
175 }
176 
177 
179 {
180  return theDet->GetFullWorld();
181 }
182 
184 {
185  G4LogicalVolume * nextlv = theGeoNav->NextLV();
186  if(nextlv)
187  {
188  theDet->SetNewWorld(nextlv);
189  G4cout << nextlv->GetName() << G4endl;
190  return true;
191  }
192  return false;
193 }
194 
195 void OlapManager::ListLV(const G4String & aRegexStr)
196 {
197  G4cout << "Logical volumes matching " << aRegexStr << ":" <<G4endl;
198 
199  std::vector<G4LogicalVolume *> aLVVec;
200  G4int c = theGeoNav->FilterLV(aRegexStr,aLVVec);
201 
202  for(G4int i=0; i<c; i++)
203  {
204  G4cout << " " << (aLVVec[i])->GetName() << G4endl;
205  }
206 }
207 
208 
210 {
211  std::vector<G4LogicalVolume *> lvs;
212  G4int c = theGeoNav->LsLV(lvs);
213  for (G4int i = 0; i<c; i++)
214  G4cout << " " << (lvs[i])->GetName() << G4endl;
215 }
216 
218 {
219  std::vector<G4LogicalVolume *> lvs;
220  theGeoNav->PwdLV(lvs);
221  G4String temp;
222  G4cout << "/ = ";
223  for (G4int i=lvs.size()-1; i>=0; i--)
224  {
225  G4cout << temp << (lvs[i])->GetName() << G4endl;
226  temp = temp + G4String(" ");
227  }
228 }
229 
230 
232 {
233  return theDet->GetNrLVs();
234 }
235 
236 
237 void OlapManager::ChangeLV(const G4String & aDir)
238 {
239  G4LogicalVolume * aLv = theGeoNav->ChangeLV(aDir);
240  if (aLv)
241  {
242  G4cout << "New world: " << aLv->GetName() << G4endl;
243  theDet->SetNewWorld(aLv);
245  }
246 }
247 
248 void OlapManager::GotoLV(const G4String & aRegexStr)
249 {
250  std::vector<G4LogicalVolume*> lvs;
251  if (theGeoNav->FilterLV(aRegexStr,lvs,true))
252  {
253  G4cout << "New world: " << (lvs[0])->GetName() << G4endl;
254  theDet->SetNewWorld((lvs[0]));
256  }
257 }
258 
259 
261 {
262  if (nw)
263  {
264  theDet->SetNewWorld(nw);
266  }
267 }
268 
270 {
271  // try to find the OlapGenerator and set the new grid
272  const OlapGenerator * aGen = dynamic_cast<const OlapGenerator *>
274  OlapGenerator * aNonConstGen = 0;
275  if ( aGen )
276  {
277  aNonConstGen = const_cast<OlapGenerator*>(aGen);
278  aNonConstGen->SetGrid(x,y,z);
279  }
280  else
281  {
282  G4cout << "Warning: Primary generator is not OlapGenerator!" << G4endl
283  << " Overlap Detection will not work!" << G4endl;
284  return;
285  }
286 
287  eventsPerRun = x*y + y*z + x*z;
288  G4cout << "/olap/trigger will trigger "
289  << eventsPerRun
290  << " events." << G4endl;
291 }
292 
293 
295 {
296  std::set<OlapNotify*>::iterator i = theNotifs.begin();
297  for(;i!=theNotifs.end();++i)
298  (*i)->worldChanged(nw);
299 }
300 
301 
302 void OlapManager::notifyOlaps(const std::vector<OlapInfo*> & ov)
303 {
304  std::set<OlapNotify*>::iterator i = theNotifs.begin();
305  for(;i!=theNotifs.end();++i)
306  (*i)->overlaps(ov);
307 }
308 
309 
311 {
312  if (theDet)
313  {
314  return theDet->GetOriginalWorld();
315  }
316  return 0;
317 }