Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4TrajectoriesModel.cc,v 1.25 2010-05-11 11:21:52 allison Exp $ >> 28 // GEANT4 tag $Name: geant4-09-04-patch-01 $ 27 // 29 // 28 // 30 // 29 // John Allison 26th August 1998. 31 // John Allison 26th August 1998. 30 // Model which knows how to draw GEANT4 trajec 32 // Model which knows how to draw GEANT4 trajectories. 31 33 32 #include "G4TrajectoriesModel.hh" 34 #include "G4TrajectoriesModel.hh" 33 35 34 #include "G4ModelingParameters.hh" 36 #include "G4ModelingParameters.hh" 35 #include "G4VGraphicsScene.hh" 37 #include "G4VGraphicsScene.hh" 36 #include "G4RunManager.hh" << 37 #include "G4RunManagerFactory.hh" << 38 #include "G4Run.hh" << 39 #include "G4Event.hh" 38 #include "G4Event.hh" 40 #include "G4AttDefStore.hh" << 41 #include "G4AttValue.hh" 39 #include "G4AttValue.hh" 42 #include "G4AttDef.hh" 40 #include "G4AttDef.hh" 43 #include "G4AttCheck.hh" 41 #include "G4AttCheck.hh" 44 #include "G4UIcommand.hh" << 45 #include "G4VVisManager.hh" << 46 42 47 G4TrajectoriesModel::G4TrajectoriesModel () << 43 G4TrajectoriesModel::G4TrajectoriesModel (): 48 :fpCurrentTrajectory(0) << 44 fDrawingModeSet(false), 49 ,fRunID(-1) << 45 fDrawingMode(0), 50 ,fEventID(-1) << 46 fpCurrentTrajectory(0) 51 { 47 { 52 fType = "G4TrajectoriesModel"; << 48 fGlobalTag = "G4TrajectoriesModel for all trajectories."; 53 fGlobalTag = "G4TrajectoriesModel for any ty << 49 fGlobalDescription = fGlobalTag; >> 50 } >> 51 >> 52 G4TrajectoriesModel::G4TrajectoriesModel (G4int drawingMode): >> 53 fDrawingModeSet(true), >> 54 fDrawingMode(drawingMode), >> 55 fpCurrentTrajectory(0) { >> 56 fGlobalTag = "G4TrajectoriesModel for all trajectories."; 54 fGlobalDescription = fGlobalTag; 57 fGlobalDescription = fGlobalTag; 55 } 58 } 56 59 57 G4TrajectoriesModel::~G4TrajectoriesModel () { 60 G4TrajectoriesModel::~G4TrajectoriesModel () {} 58 61 59 void G4TrajectoriesModelDebugG4AttValues(const 62 void G4TrajectoriesModelDebugG4AttValues(const G4VTrajectory*); 60 63 61 void G4TrajectoriesModel::DescribeYourselfTo ( << 64 void G4TrajectoriesModel::DescribeYourselfTo (G4VGraphicsScene& sceneHandler) { 62 { << 63 G4RunManager* runManager = G4RunManagerFacto << 64 const G4Run* currentRun = runManager->GetCu << 65 if(currentRun) << 66 { << 67 fRunID = currentRun->GetRunID(); << 68 } << 69 else << 70 { << 71 fRunID = -1; << 72 return; << 73 } << 74 << 75 const G4Event* event = fpMP->GetEvent(); 65 const G4Event* event = fpMP->GetEvent(); 76 if (event) { 66 if (event) { 77 fEventID = event->GetEventID(); << 67 G4TrajectoryContainer* TC = event -> GetTrajectoryContainer (); 78 } else { << 68 if (TC) { 79 fEventID = -1; << 69 for (G4int iT = 0; iT < TC->entries(); iT++) { 80 return; << 70 fpCurrentTrajectory = (*TC) [iT]; >> 71 // Debug trajectory: >> 72 // fpCurrentTrajectory->ShowTrajectory(); G4cout << G4endl; >> 73 // Debug G4AttValues: >> 74 // G4TrajectoriesModelDebugG4AttValues(fpCurrentTrajectory); >> 75 if (fpCurrentTrajectory) >> 76 sceneHandler.AddCompound (*fpCurrentTrajectory); >> 77 } >> 78 } 81 } 79 } >> 80 } 82 81 83 G4TrajectoryContainer* TC = event -> GetTraj << 82 G4bool G4TrajectoriesModel::IsDrawingModeSet() const 84 if (!TC) return; << 83 { 85 << 84 return fDrawingModeSet; 86 G4VVisManager* pVVisManager = G4VVisManager: << 87 if (!pVVisManager) return; << 88 << 89 pVVisManager->BeginDraw(); << 90 // The use of Begin/EndDraw (optional method << 91 // speed) assumes all trajectories are drawn << 92 // transformation. If not, a fatal exceptio << 93 // G4VisManager::DrawT. << 94 for (std::size_t iT = 0; iT < TC->entries(); << 95 fpCurrentTrajectory = (*TC) [iT]; << 96 // Debug trajectory: << 97 // fpCurrentTrajectory->ShowTrajectory(); << 98 // Debug G4AttValues: << 99 // G4TrajectoriesModelDebugG4AttValues(fpC << 100 if (fpCurrentTrajectory) << 101 sceneHandler.AddCompound (*fpCurrentTraj << 102 } << 103 pVVisManager->EndDraw(); << 104 } 85 } 105 86 106 const std::map<G4String,G4AttDef>* G4Trajector << 87 G4int G4TrajectoriesModel::GetDrawingMode() const 107 { 88 { 108 G4bool isNew; << 89 if (fDrawingModeSet) return fDrawingMode; 109 std::map<G4String,G4AttDef>* store << 90 else { 110 = G4AttDefStore::GetInstance("G4Trajectories << 91 G4Exception 111 if (isNew) { << 92 ("G4TrajectoriesModel::GetDrawingMode", 112 (*store)["RunID"] = << 93 "", 113 G4AttDef("RunID","Run ID","Physics","","G4 << 94 FatalException, 114 (*store)["EventID"] = << 95 "Illegal attempt to obtain i_mode." 115 G4AttDef("EventID","Event ID","Physics","" << 96 "\n i_mode is an old trajectories parameter that is DEPRECATED" >> 97 "\n and will be removed at the next major release." >> 98 ); >> 99 return 0; 116 } 100 } 117 return store; << 118 } 101 } 119 102 120 std::vector<G4AttValue>* G4TrajectoriesModel:: << 103 void G4TrajectoriesModel::SetDrawingMode(G4int drawingMode) 121 { 104 { 122 std::vector<G4AttValue>* values = new std::v << 105 if (fDrawingModeSet) fDrawingMode = drawingMode; 123 values->push_back << 106 else { 124 (G4AttValue("RunID",G4UIcommand::ConvertToSt << 107 G4Exception 125 values->push_back << 108 ("G4TrajectoriesModel::SetDrawingMode", 126 (G4AttValue("EventID",G4UIcommand::ConvertTo << 109 "", 127 return values; << 110 FatalException, >> 111 "Illegal attempt to set i_mode." >> 112 "\n i_mode is an old trajectories parameter that is DEPRECATED" >> 113 "\n and will be removed at the next major release." >> 114 ); >> 115 } 128 } 116 } 129 117 130 // Debug material... 118 // Debug material... 131 119 132 #include "G4VTrajectoryPoint.hh" 120 #include "G4VTrajectoryPoint.hh" 133 121 134 void G4TrajectoriesModelDebugG4AttValues(const 122 void G4TrajectoriesModelDebugG4AttValues(const G4VTrajectory* pTraj) 135 { 123 { 136 // Trajectory attributes << 124 std::vector<G4AttValue>* attValues = pTraj->CreateAttValues(); 137 { // Scope bracket - allows re-use of names << 125 if (attValues) { 138 std::vector<G4AttValue>* attValues = pTraj << 126 G4AttCheck attCheck(attValues, pTraj->GetAttDefs()); 139 if (attValues) { << 127 G4cout << "\nProvided G4Atts:\n" << attCheck; 140 G4AttCheck attCheck(attValues, pTraj->Ge << 128 if (attCheck.Check()) G4cout << "Error" << G4endl; 141 G4cout << "\nProvided G4Atts:\n" << attC << 129 else { 142 if (attCheck.Check()) G4cout << "Error" << 130 std::vector<G4AttValue> standardValues; 143 else { << 131 std::map<G4String,G4AttDef> standardDefinitions; 144 std::vector<G4AttValue> standardValues; << 132 attCheck.Standard(&standardValues, &standardDefinitions); 145 std::map<G4String,G4AttDef> standardDefiniti << 133 G4cout << "\nStandard G4Atts:\n" 146 attCheck.Standard(&standardValues, &standard << 134 << G4AttCheck(&standardValues, &standardDefinitions); 147 G4cout << "\nStandard G4Atts:\n" << 148 << G4AttCheck(&standardValues, &stand << 149 } << 150 delete attValues; << 151 } 135 } >> 136 delete attValues; 152 } 137 } 153 // Trajectory point attributes << 138 for (G4int i = 0; i < pTraj->GetPointEntries(); i++) { 154 for (G4int i = 0; i < pTraj->GetPointEntries << 155 G4VTrajectoryPoint* aPoint = pTraj->GetPoi 139 G4VTrajectoryPoint* aPoint = pTraj->GetPoint(i); 156 std::vector<G4AttValue>* attValues = aPoin 140 std::vector<G4AttValue>* attValues = aPoint->CreateAttValues(); 157 if (attValues) { 141 if (attValues) { 158 G4AttCheck attCheck(attValues, aPoint->G 142 G4AttCheck attCheck(attValues, aPoint->GetAttDefs()); 159 G4cout << "\nProvided G4Atts:\n" << attC 143 G4cout << "\nProvided G4Atts:\n" << attCheck; 160 if (attCheck.Check()) G4cout << "Error" 144 if (attCheck.Check()) G4cout << "Error" << G4endl; 161 else { 145 else { 162 std::vector<G4AttValue> standardValues; 146 std::vector<G4AttValue> standardValues; 163 std::map<G4String,G4AttDef> standardDefiniti 147 std::map<G4String,G4AttDef> standardDefinitions; 164 attCheck.Standard(&standardValues, &standard 148 attCheck.Standard(&standardValues, &standardDefinitions); 165 G4cout << "\nStandard G4Atts:\n" 149 G4cout << "\nStandard G4Atts:\n" 166 << G4AttCheck(&standardValues, &stand 150 << G4AttCheck(&standardValues, &standardDefinitions); 167 } 151 } 168 delete attValues; 152 delete attValues; 169 } 153 } 170 } << 154 } 171 } 155 } 172 156