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 // $Id: G4TrajectoryDrawByCharge.cc 66373 2012-12-18 09:41:34Z gcosmo $ 26 // 27 // 27 // Jane Tinslay, John Allison, Joseph Perl Nov 28 // Jane Tinslay, John Allison, Joseph Perl November 2005 28 #include "G4TrajectoryDrawByCharge.hh" 29 #include "G4TrajectoryDrawByCharge.hh" 29 #include "G4TrajectoryDrawerUtils.hh" 30 #include "G4TrajectoryDrawerUtils.hh" 30 #include "G4VisTrajContext.hh" 31 #include "G4VisTrajContext.hh" 31 #include "G4VTrajectory.hh" 32 #include "G4VTrajectory.hh" 32 #include <sstream> 33 #include <sstream> 33 34 34 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCh 35 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCharge(const G4String& name, G4VisTrajContext* context) 35 :G4VTrajectoryModel(name, context) 36 :G4VTrajectoryModel(name, context) 36 { 37 { 37 // Default configuration 38 // Default configuration 38 fMap[Positive] = G4Colour::Blue(); 39 fMap[Positive] = G4Colour::Blue(); 39 fMap[Negative] = G4Colour::Red(); 40 fMap[Negative] = G4Colour::Red(); 40 fMap[Neutral] = G4Colour::Green(); 41 fMap[Neutral] = G4Colour::Green(); 41 } 42 } 42 43 43 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCh 44 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCharge(const G4String& name, 44 const G4Colour& positive, 45 const G4Colour& positive, 45 const G4Colour& negative, 46 const G4Colour& negative, 46 const G4Colour& neutral) 47 const G4Colour& neutral) 47 :G4VTrajectoryModel(name) 48 :G4VTrajectoryModel(name) 48 { 49 { 49 fMap[Positive] = positive; 50 fMap[Positive] = positive; 50 fMap[Negative] = negative; 51 fMap[Negative] = negative; 51 fMap[Neutral] = neutral; 52 fMap[Neutral] = neutral; 52 } 53 } 53 54 54 G4TrajectoryDrawByCharge::~G4TrajectoryDrawByC 55 G4TrajectoryDrawByCharge::~G4TrajectoryDrawByCharge() {} 55 56 56 void 57 void 57 G4TrajectoryDrawByCharge::Draw(const G4VTrajec << 58 G4TrajectoryDrawByCharge::Draw(const G4VTrajectory& traj, const G4bool& visible) const 58 { 59 { 59 G4Colour colour; 60 G4Colour colour; 60 61 61 const G4double charge = traj.GetCharge(); 62 const G4double charge = traj.GetCharge(); 62 63 63 if(charge>0.) fMap.GetColour(Positive, 64 if(charge>0.) fMap.GetColour(Positive, colour); 64 else if(charge<0.) fMap.GetColour(Negative, 65 else if(charge<0.) fMap.GetColour(Negative, colour); 65 else fMap.GetColour(Neutral, c 66 else fMap.GetColour(Neutral, colour); 66 67 67 G4VisTrajContext myContext(GetContext()); 68 G4VisTrajContext myContext(GetContext()); 68 << 69 69 myContext.SetLineColour(colour); 70 myContext.SetLineColour(colour); 70 << 71 myContext.SetVisible(visible); >> 72 71 if (GetVerbose()) { 73 if (GetVerbose()) { 72 G4cout<<"G4TrajectoryDrawByCharge drawer n 74 G4cout<<"G4TrajectoryDrawByCharge drawer named "<<Name(); 73 G4cout<<", drawing trajectory with charge, 75 G4cout<<", drawing trajectory with charge, "<<charge<<G4endl; 74 G4cout<<", with configuration:"<<G4endl; 76 G4cout<<", with configuration:"<<G4endl; 75 myContext.Print(G4cout); 77 myContext.Print(G4cout); 76 } 78 } 77 79 78 G4TrajectoryDrawerUtils::DrawLineAndPoints(t 80 G4TrajectoryDrawerUtils::DrawLineAndPoints(traj, myContext); 79 } 81 } 80 82 81 void 83 void 82 G4TrajectoryDrawByCharge::Print(std::ostream& 84 G4TrajectoryDrawByCharge::Print(std::ostream& ostr) const 83 { 85 { 84 ostr<<"G4TrajectoryDrawByCharge model "<< Na 86 ostr<<"G4TrajectoryDrawByCharge model "<< Name() <<" colour scheme: "<<std::endl; 85 fMap.Print(ostr); 87 fMap.Print(ostr); 86 ostr<<"Default configuration:"<<G4endl; 88 ostr<<"Default configuration:"<<G4endl; 87 GetContext().Print(G4cout); 89 GetContext().Print(G4cout); 88 } 90 } 89 91 90 void 92 void 91 G4TrajectoryDrawByCharge::Set(const Charge& ch 93 G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4String& colour) 92 { 94 { 93 fMap.Set(charge, colour); 95 fMap.Set(charge, colour); 94 } 96 } 95 97 96 void 98 void 97 G4TrajectoryDrawByCharge::Set(const Charge& ch 99 G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4Colour& colour) 98 { 100 { 99 fMap[charge] = colour; 101 fMap[charge] = colour; 100 } 102 } 101 103 102 void 104 void 103 G4TrajectoryDrawByCharge::Set(const G4String& 105 G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4String& colour) 104 { 106 { 105 Charge myCharge; 107 Charge myCharge; 106 108 107 if (!ConvertToCharge(charge, myCharge)) { 109 if (!ConvertToCharge(charge, myCharge)) { 108 G4ExceptionDescription ed; 110 G4ExceptionDescription ed; 109 ed << "Invalid charge "<<charge; 111 ed << "Invalid charge "<<charge; 110 G4Exception 112 G4Exception 111 ("G4TrajectoryDrawByCharge::Set(const G4 113 ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4String& colour)", "modeling0121", JustWarning, ed); 112 return; 114 return; 113 } 115 } 114 116 115 return Set(myCharge, colour); 117 return Set(myCharge, colour); 116 } 118 } 117 119 118 void 120 void 119 G4TrajectoryDrawByCharge::Set(const G4String& 121 G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4Colour& colour) 120 { 122 { 121 Charge myCharge; 123 Charge myCharge; 122 124 123 if (!ConvertToCharge(charge, myCharge)) { 125 if (!ConvertToCharge(charge, myCharge)) { 124 G4ExceptionDescription ed; 126 G4ExceptionDescription ed; 125 ed << "Invalid charge "<<charge; 127 ed << "Invalid charge "<<charge; 126 G4Exception 128 G4Exception 127 ("G4TrajectoryDrawByCharge::Set(const G4 129 ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4Colour& colour)", "modeling0122", JustWarning, ed); 128 } 130 } 129 131 130 return Set(myCharge, colour); 132 return Set(myCharge, colour); 131 } 133 } 132 134 133 G4bool 135 G4bool 134 G4TrajectoryDrawByCharge::ConvertToCharge(cons 136 G4TrajectoryDrawByCharge::ConvertToCharge(const G4String& string, Charge& myCharge) 135 { 137 { 136 bool result(true); 138 bool result(true); 137 139 138 G4int charge; 140 G4int charge; 139 std::istringstream is(string.c_str()); 141 std::istringstream is(string.c_str()); 140 is >> charge; 142 is >> charge; 141 143 142 switch (charge) { 144 switch (charge) { 143 case 1: 145 case 1: 144 myCharge = G4TrajectoryDrawByCharge::Posit 146 myCharge = G4TrajectoryDrawByCharge::Positive; 145 break; 147 break; 146 case 0: 148 case 0: 147 myCharge = G4TrajectoryDrawByCharge::Neutr 149 myCharge = G4TrajectoryDrawByCharge::Neutral; 148 break; 150 break; 149 case -1: 151 case -1: 150 myCharge = G4TrajectoryDrawByCharge::Negat 152 myCharge = G4TrajectoryDrawByCharge::Negative; 151 break; 153 break; 152 default: 154 default: 153 result = false; 155 result = false; 154 } 156 } 155 157 156 return result; 158 return result; 157 } 159 } 158 160