source: trunk/examples/extended/geometry/olap/src/OlapManager.cc@ 1314

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

update to geant4.9.3

File size: 9.9 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: OlapManager.cc,v 1.3 2006/06/29 17:23:00 gunter Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30//
31// --------------------------------------------------------------
32// OlapManager
33//
34// Author: Martin Liendl - Martin.Liendl@cern.ch
35//
36// --------------------------------------------------------------
37//
38#include <stdlib.h>
39
40#include <vector>
41
42#include "OlapManager.hh"
43#include "OlapDetConstr.hh"
44#include "OlapManagerMessenger.hh"
45#include "OlapGenerator.hh"
46#include "OlapEventAction.hh"
47#include "G4GeoNav.hh"
48#include "G4RunManager.hh"
49#include "globals.hh"
50
51OlapManager * OlapManager::theInstance = 0;
52
53OlapManager::OlapManager() :
54 olapGenerator(0), delta( kRadTolerance ),
55 eventsPerRun(27), lvPos(0), polyMode(false),
56 interrupt(false)
57{
58 theMessenger = new OlapManagerMessenger(this);
59 theLVStore = G4LogicalVolumeStore::GetInstance();
60 // for SUN
61 //std::vector<G4LogicalVolume*>::iterator aIt = theLVStore->begin();
62 //G4LogicalVolumeStore::iterator aIt = theLVStore->begin();
63
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 G4cerr << "OlapManger(): can't get the OlapDetConstr instance!" << G4endl;
72 G4cerr << " exiting ..." << G4endl;
73 G4Exception("ERROR - OlapManager::OlapManager()");
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
88OlapManager::~OlapManager()
89{
90 delete theMessenger;
91 delete theGeoNav;
92 delete olapGenerator;
93}
94
95
96OlapManager * OlapManager::GetOlapManager()
97{
98 if (!theInstance)
99 theInstance = new OlapManager();
100
101 return theInstance;
102}
103
104
105void OlapManager::SetRotation(G4double theta, G4double phi, G4double alpha)
106{
107 theDet->SetRotation(theta,phi,alpha);
108
109 // ?? set the current new-world again to activate the rotation??
110}
111
112
113
114void OlapManager::TriggerRun()
115{
116 const OlapGenerator * aGen = dynamic_cast<const OlapGenerator *>
117 (G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
118 OlapGenerator * aNonConstGen = 0;
119 if ( aGen )
120 {
121 aNonConstGen = const_cast<OlapGenerator*>(aGen);
122 }
123 else
124 {
125 G4cerr << "Warning: Primary generator is not OlapGenerator!" << G4endl
126 << "Overlap Detection will not work!" << G4endl;
127 return;
128 }
129 //while
130 aNonConstGen->SetAutoIncrement(true);
131 theRunManager->BeamOn(eventsPerRun);
132 aNonConstGen->SetAutoIncrement(false);
133}
134
135
136void OlapManager::TriggerFull(G4int trg)
137{
138 const OlapGenerator * aGen = dynamic_cast<const OlapGenerator *>
139 (G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
140 OlapGenerator * aNonConstGen = 0;
141 if ( aGen )
142 {
143 aNonConstGen = const_cast<OlapGenerator*>(aGen);
144 }
145 else
146 {
147 G4cerr << "Warning: Primary generator is not OlapGenerator!" << G4endl
148 << "Overlap Detection will not work!" << G4endl;
149 return;
150 }
151 //while
152 aNonConstGen->SetAutoIncrement(true);
153
154 interrupt = false; // can be changed to 'true' in the following loop
155 // by subclasses of OlapNotify. In that case,
156 // the triggerFull-command will be stopped.
157
158 while (Next() && trg)
159 {
160 if (theDet->GetNewWorld()->GetLogicalVolume()->GetDaughter(0)->
161 GetLogicalVolume()->GetNoDaughters())
162 {
163 theRunManager->BeamOn(eventsPerRun);
164 trg--;
165 if (interrupt)
166 {
167 break;
168 }
169 }
170 }
171 aNonConstGen->SetAutoIncrement(false);
172}
173
174G4VPhysicalVolume * OlapManager::GetNewWorld()
175{
176 return theDet->GetNewWorld();
177}
178
179
180G4VPhysicalVolume * OlapManager::GetFullWorld()
181{
182 return theDet->GetFullWorld();
183}
184
185G4bool OlapManager::Next()
186{
187 G4LogicalVolume * nextlv = theGeoNav->NextLV();
188 if(nextlv)
189 {
190 theDet->SetNewWorld(nextlv);
191 G4cout << nextlv->GetName() << G4endl;
192 return true;
193 }
194 return false;
195}
196
197/*
198G4bool OlapManager::SetNextWorld(G4int aOffs)
199{
200 if (aOffs >= theLVs.size())
201 {
202 G4cout << aOffs << ">" << theLVs.size() -1 << G4endl;
203 return false;
204 }
205 else
206 {
207 G4cout << "no daughters: " << (*theLVit)->GetNoDaughters() << G4endl;
208 theDet->SetNewWorld(theLVs[aOffs]);
209 lvPos=aOffs;
210 return true;
211 }
212
213}
214*/
215
216/*
217G4bool OlapManager::SetPrevWorld(G4int aOffs)
218{
219 //FIXME: OlapManager::SetPrevWorld(int) - remove this method!
220 G4cerr << "DON'T CALL OlapManager::SetPrevWorld(..)!" << G4endl;
221 G4Exception("ERROR - OlapManager::SetPrevWorld()");
222
223 for (G4int i=1; i<aOffs; i++)
224 {
225 if (theLVit == theLVs.begin())
226 {
227 theDet->SetNewWorld(*theLVit);
228 return true;
229 }
230 theLVit--;
231 }
232
233 if (theLVit != theLVs.begin())
234 {
235 theLVit--;
236 if ( *theLVit != 0)
237 {
238 theDet->SetNewWorld(*theLVit);
239 return true;
240 }
241 }
242
243 return false;
244}
245*/
246
247void OlapManager::ListLV(const G4String & aRegexStr)
248{
249 G4cout << "logical volumes matching " << aRegexStr << ":" <<G4endl;
250
251 std::vector<G4LogicalVolume *> aLVVec;
252 G4int c = theGeoNav->FilterLV(aRegexStr,aLVVec);
253
254 for(G4int i=0; i<c; i++)
255 {
256 G4cout << " " << (aLVVec[i])->GetName() << G4endl;
257 }
258}
259
260
261void OlapManager::LsLV()
262{
263 std::vector<G4LogicalVolume *> lvs;
264 G4int c = theGeoNav->LsLV(lvs);
265 for (G4int i = 0; i<c; i++)
266 G4cout << " " << (lvs[i])->GetName() << G4endl;
267}
268
269void OlapManager::PwdLV()
270{
271 std::vector<G4LogicalVolume *> lvs;
272 theGeoNav->PwdLV(lvs);
273 G4String temp;
274 G4cout << "/ = ";
275 for (G4int i=lvs.size()-1; i>=0; i--)
276 {
277 G4cout << temp << (lvs[i])->GetName() << G4endl;
278 temp = temp + G4String(" ");
279 }
280}
281
282
283G4int OlapManager::GetNrLVs()
284{
285 return theDet->GetNrLVs();
286}
287
288
289void OlapManager::ChangeLV(const G4String & aDir)
290{
291 G4LogicalVolume * aLv = theGeoNav->ChangeLV(aDir);
292 if (aLv)
293 {
294 G4cout << "new world: " << aLv->GetName() << G4endl;
295 theDet->SetNewWorld(aLv);
296 notifyNewWorld(theDet->GetNewWorld()->GetLogicalVolume());
297 }
298}
299
300void OlapManager::GotoLV(const G4String & aRegexStr)
301{
302 std::vector<G4LogicalVolume*> lvs;
303 if (theGeoNav->FilterLV(aRegexStr,lvs,true))
304 {
305 G4cout << "new world: " << (lvs[0])->GetName() << G4endl;
306 theDet->SetNewWorld((lvs[0]));
307 notifyNewWorld(theDet->GetNewWorld()->GetLogicalVolume());
308 }
309}
310
311
312void OlapManager::SetNewWorld(G4LogicalVolume * nw)
313{
314 if (nw)
315 {
316 theDet->SetNewWorld(nw);
317 notifyNewWorld(theDet->GetNewWorld()->GetLogicalVolume());
318 }
319}
320
321void OlapManager::SetGrid(G4int x, G4int y, G4int z)
322{
323 // try to find the OlapGenerator and set the new grid
324 const OlapGenerator * aGen = dynamic_cast<const OlapGenerator *>
325 (G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
326 OlapGenerator * aNonConstGen = 0;
327 if ( aGen )
328 {
329 aNonConstGen = const_cast<OlapGenerator*>(aGen);
330 aNonConstGen->SetGrid(x,y,z);
331 }
332 else
333 {
334 G4cerr << "Warning: Primary generator is not OlapGenerator!" << G4endl
335 << "Overlap Detection will not work!" << G4endl;
336 return;
337 }
338
339 eventsPerRun = x*y + y*z + x*z;
340 G4cout << "/olap/trigger will trigger "
341 << eventsPerRun
342 << " events." << G4endl;
343}
344
345
346void OlapManager::notifyNewWorld(G4LogicalVolume* nw)
347{
348 //G4cout << G4endl << "NewWorld-Notif: " << nw->GetName() << G4endl;
349 std::set<OlapNotify*>::iterator i = theNotifs.begin();
350 for(;i!=theNotifs.end();++i)
351 (*i)->worldChanged(nw);
352}
353
354
355void OlapManager::notifyOlaps(const std::vector<OlapInfo*> & ov)
356{
357 std::set<OlapNotify*>::iterator i = theNotifs.begin();
358 for(;i!=theNotifs.end();++i)
359 (*i)->overlaps(ov);
360}
361
362
363G4LogicalVolume* OlapManager::GetOriginalWorld()
364{
365 if (theDet)
366 {
367 return theDet->GetOriginalWorld();
368 }
369 return 0;
370}
Note: See TracBrowser for help on using the repository browser.