G4TrajectoryDrawByCharge.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // Jane Tinslay, John Allison, Joseph Perl November 2005
00029 #include "G4TrajectoryDrawByCharge.hh"
00030 #include "G4TrajectoryDrawerUtils.hh"
00031 #include "G4VisTrajContext.hh"
00032 #include "G4VTrajectory.hh"
00033 #include <sstream>
00034 
00035 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCharge(const G4String& name, G4VisTrajContext* context)
00036   :G4VTrajectoryModel(name, context)
00037 {
00038   // Default configuration
00039   fMap[Positive] = G4Colour::Blue();
00040   fMap[Negative] = G4Colour::Red();
00041   fMap[Neutral] = G4Colour::Green();
00042 }
00043 
00044 G4TrajectoryDrawByCharge::G4TrajectoryDrawByCharge(const G4String& name,
00045                                                    const G4Colour& positive,
00046                                                    const G4Colour& negative,
00047                                                    const G4Colour& neutral)
00048   :G4VTrajectoryModel(name)
00049 {
00050   fMap[Positive] = positive;
00051   fMap[Negative] = negative;
00052   fMap[Neutral] = neutral;
00053 }
00054 
00055 G4TrajectoryDrawByCharge::~G4TrajectoryDrawByCharge() {}
00056 
00057 void
00058 G4TrajectoryDrawByCharge::Draw(const G4VTrajectory& object,
00059                                const G4int&,
00060                                const G4bool& visible) const
00061 {
00062   Draw(object, visible);
00063 }
00064 
00065 void
00066 G4TrajectoryDrawByCharge::Draw(const G4VTrajectory& traj, const G4bool& visible) const
00067 {
00068   G4Colour colour;
00069 
00070   const G4double charge = traj.GetCharge();
00071 
00072   if(charge>0.)      fMap.GetColour(Positive, colour); 
00073   else if(charge<0.) fMap.GetColour(Negative, colour); 
00074   else               fMap.GetColour(Neutral, colour); 
00075 
00076   G4VisTrajContext myContext(GetContext());
00077   
00078   myContext.SetLineColour(colour);
00079   myContext.SetVisible(visible);
00080   
00081   if (GetVerbose()) {
00082     G4cout<<"G4TrajectoryDrawByCharge drawer named "<<Name();
00083     G4cout<<", drawing trajectory with charge, "<<charge<<G4endl;
00084     G4cout<<", with configuration:"<<G4endl;
00085     myContext.Print(G4cout);
00086   }
00087 
00088   G4TrajectoryDrawerUtils::DrawLineAndPoints(traj, myContext);
00089 }
00090 
00091 void
00092 G4TrajectoryDrawByCharge::Print(std::ostream& ostr) const
00093 {
00094   ostr<<"G4TrajectoryDrawByCharge model "<< Name() <<" colour scheme: "<<std::endl;
00095   fMap.Print(ostr);
00096   ostr<<"Default configuration:"<<G4endl;
00097   GetContext().Print(G4cout);
00098 }
00099 
00100 void
00101 G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4String& colour)
00102 {
00103   fMap.Set(charge, colour);
00104 }
00105 
00106 void
00107 G4TrajectoryDrawByCharge::Set(const Charge& charge, const G4Colour& colour)
00108 {
00109   fMap[charge] = colour;
00110 }
00111 
00112 void
00113 G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4String& colour)
00114 {  
00115   Charge myCharge;
00116   
00117   if (!ConvertToCharge(charge, myCharge)) {
00118     G4ExceptionDescription ed;
00119     ed << "Invalid charge "<<charge;
00120     G4Exception   
00121       ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4String& colour)", "modeling0121", JustWarning, ed);
00122     return;
00123   }
00124 
00125   return Set(myCharge, colour);
00126 }
00127 
00128 void
00129 G4TrajectoryDrawByCharge::Set(const G4String& charge, const G4Colour& colour)
00130 {  
00131   Charge myCharge;
00132   
00133   if (!ConvertToCharge(charge, myCharge)) {
00134     G4ExceptionDescription ed;
00135     ed << "Invalid charge "<<charge;
00136     G4Exception   
00137       ("G4TrajectoryDrawByCharge::Set(const G4int& charge, const G4Colour& colour)", "modeling0122", JustWarning, ed);
00138   }
00139 
00140   return Set(myCharge, colour);
00141 }
00142 
00143 G4bool
00144 G4TrajectoryDrawByCharge::ConvertToCharge(const G4String& string, Charge& myCharge)
00145 {
00146   bool result(true);
00147  
00148   G4int charge;
00149   std::istringstream is(string.c_str());
00150   is >> charge;
00151 
00152   switch (charge) {
00153   case 1:
00154     myCharge = G4TrajectoryDrawByCharge::Positive;
00155     break;
00156   case 0:
00157     myCharge = G4TrajectoryDrawByCharge::Neutral;  
00158     break;
00159   case -1:
00160     myCharge = G4TrajectoryDrawByCharge::Negative;   
00161     break;
00162   default:
00163     result = false;
00164   }
00165   
00166   return result;
00167 }

Generated on Mon May 27 17:50:01 2013 for Geant4 by  doxygen 1.4.7