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