Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4VTrajectory class implementation << 23 // >> 24 // $Id: G4VTrajectory.cc,v 1.3 2002/12/12 13:13:27 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-05-01-patch-01 $ >> 26 // >> 27 // >> 28 // --------------------------------------------------------------- >> 29 // >> 30 // G4VTrajectory.cc 27 // 31 // 28 // Contact: 32 // Contact: 29 // Questions and comments to this code shoul 33 // Questions and comments to this code should be sent to 30 // Katsuya Amako (e-mail: Katsuya.Amako@k 34 // Katsuya Amako (e-mail: Katsuya.Amako@kek.jp) 31 // Makoto Asai (e-mail: asai@slac.stanf << 35 // Makoto Asai (e-mail: asai@kekvax.kek.jp) 32 // Takashi Sasaki (e-mail: Takashi.Sasaki@ 36 // Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp) 33 // ------------------------------------------- << 37 // >> 38 // --------------------------------------------------------------- 34 39 35 #include "G4VTrajectory.hh" 40 #include "G4VTrajectory.hh" 36 << 41 #include "G4VTrajectoryPoint.hh" 37 #include "G4AttCheck.hh" << 38 #include "G4AttDef.hh" << 39 #include "G4AttDefStore.hh" 42 #include "G4AttDefStore.hh" >> 43 #include "G4AttDef.hh" 40 #include "G4AttValue.hh" 44 #include "G4AttValue.hh" 41 #include "G4Colour.hh" << 42 #include "G4Polyline.hh" << 43 #include "G4Polymarker.hh" << 44 #include "G4VTrajectoryPoint.hh" << 45 #include "G4VVisManager.hh" 45 #include "G4VVisManager.hh" 46 #include "G4VisAttributes.hh" 46 #include "G4VisAttributes.hh" >> 47 #include "G4Polyline.hh" >> 48 #include "G4Polymarker.hh" >> 49 #include "G4Colour.hh" 47 50 48 G4bool G4VTrajectory::operator==(const G4VTraj << 51 void G4VTrajectory::ShowTrajectory(G4std::ostream& os) const 49 << 50 G4VTrajectory* G4VTrajectory::CloneForMaster() << 51 { << 52 // Base-class method must not be invoked. << 53 // Each concrete class should implement its << 54 G4Exception("G4VTrajectory::CloneForMaster( << 55 "CloneForMaster() of G4VTrajectory base-c << 56 return nullptr; << 57 } << 58 << 59 void G4VTrajectory::ShowTrajectory(std::ostrea << 60 { 52 { 61 // Makes use of attribute values implemented 53 // Makes use of attribute values implemented in the concrete class. 62 // Note: the user needs to follow with new-l 54 // Note: the user needs to follow with new-line or end-of-string, 63 // depending on the nature of os << 55 // depending on the nature of os. 64 56 65 std::vector<G4AttValue>* attValues = CreateA << 57 G4std::vector<G4AttValue>* attValues = CreateAttValues(); 66 const std::map<G4String, G4AttDef>* attDefs << 67 58 68 // Ensure validity... << 59 if (!attValues) { 69 // << 60 os << "G4VTrajectory::ShowTrajectory: no attribute values defined."; 70 if (G4AttCheck(attValues, attDefs).Check("G4 << 61 return; >> 62 } >> 63 >> 64 const G4std::map<G4String,G4AttDef>* attDefs = GetAttDefs(); >> 65 if (!attDefs) { >> 66 os << "G4VTrajectory::ShowTrajectory:" >> 67 "\n ERROR: no attribute definitions for attribute values."; 71 return; 68 return; 72 } 69 } 73 70 74 os << "Trajectory:"; 71 os << "Trajectory:"; 75 72 76 for (const auto& attValue : *attValues) { << 73 G4std::vector<G4AttValue>::iterator iAttVal; 77 auto iAttDef = attDefs->find(attValue.GetN << 74 for (iAttVal = attValues->begin(); 78 os << "\n " << iAttDef->second.GetDesc() << 75 iAttVal != attValues->end(); ++iAttVal) { 79 << "): " << attValue.GetValue(); << 76 G4std::map<G4String,G4AttDef>::const_iterator iAttDef = >> 77 attDefs->find(iAttVal->GetName()); >> 78 if (iAttDef == attDefs->end()) { >> 79 os << "G4VTrajectory::ShowTrajectory:" >> 80 "\n WARNING: no matching definition for attribute \"" >> 81 << iAttVal->GetName() << "\", value: " >> 82 << iAttVal->GetValue(); >> 83 } >> 84 else { >> 85 os << "\n " << iAttDef->second.GetDesc() << ": " >> 86 << iAttVal->GetValue(); >> 87 } 80 } 88 } 81 89 82 delete attValues; // AttValues must be dele 90 delete attValues; // AttValues must be deleted after use. 83 91 84 // Now do trajectory points... << 92 //Now do trajectory points... 85 << 93 for (G4int i = 0; i < GetPointEntries(); i++) { 86 for (G4int i = 0; i < GetPointEntries(); ++i << 87 G4VTrajectoryPoint* aTrajectoryPoint = Get 94 G4VTrajectoryPoint* aTrajectoryPoint = GetPoint(i); 88 attValues = aTrajectoryPoint->CreateAttVal << 95 G4std::vector<G4AttValue>* attValues 89 attDefs = aTrajectoryPoint->GetAttDefs(); << 96 = aTrajectoryPoint->CreateAttValues(); 90 << 97 if (!attValues) { 91 // Ensure validity... << 98 os << 92 // << 99 "\nG4VTrajectory::ShowTrajectory: no attribute values" 93 if (G4AttCheck(attValues, attDefs).Check(" << 100 " for trajectory point defined."; 94 return; << 95 } 101 } 96 << 102 else { 97 for (const auto& attValue : *attValues) { << 103 const G4std::map<G4String,G4AttDef>* attDefs 98 const auto iAttDef = attDefs->find(attVa << 104 = aTrajectoryPoint->GetAttDefs(); 99 os << "\n " << iAttDef->second.GetDes << 105 if (!attDefs) { 100 << "): " << attValue.GetValue(); << 106 os << "\nG4VTrajectory::ShowTrajectory:" >> 107 "\n ERROR: no attribute definitions for attribute values" >> 108 " for trajectory point defined."; >> 109 } >> 110 else { >> 111 G4std::vector<G4AttValue>::iterator iAttVal; >> 112 for (iAttVal = attValues->begin(); >> 113 iAttVal != attValues->end(); ++iAttVal) { >> 114 G4std::map<G4String,G4AttDef>::const_iterator iAttDef = >> 115 attDefs->find(iAttVal->GetName()); >> 116 if (iAttDef == attDefs->end()) { >> 117 os << "\nG4VTrajectory::ShowTrajectory:" >> 118 "\n WARNING: no matching definition for trajectory" >> 119 " point attribute \"" >> 120 << iAttVal->GetName() << "\", value: " >> 121 << iAttVal->GetValue(); >> 122 } >> 123 else { >> 124 os << "\n " << iAttDef->second.GetDesc() << ": " >> 125 << iAttVal->GetValue(); >> 126 } >> 127 } >> 128 } >> 129 delete attValues; // AttValues must be deleted after use. 101 } 130 } 102 << 103 delete attValues; // AttValues must be de << 104 } 131 } 105 os << std::endl; << 106 } 132 } 107 133 108 void G4VTrajectory::DrawTrajectory() const << 134 void G4VTrajectory::DrawTrajectory(G4int i_mode) const 109 { 135 { >> 136 // If i_mode>=0, draws a trajectory as a polyline (blue for >> 137 // positive, red for negative, green for neutral) and, if i_mode!=0, >> 138 // adds markers - yellow circles for step points and magenta squares >> 139 // for auxiliary points, if any - whose screen size in pixels is >> 140 // given by abs(i_mode)/1000. E.g: i_mode = 5000 gives easily >> 141 // visible markers. >> 142 110 G4VVisManager* pVVisManager = G4VVisManager: 143 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); >> 144 if (!pVVisManager) return; 111 145 112 if (pVVisManager != nullptr) { << 146 const G4double markerSize = abs(i_mode)/1000; 113 pVVisManager->DispatchToModel(*this); << 147 G4bool lineRequired (i_mode >= 0); >> 148 G4bool markersRequired (markerSize > 0.); >> 149 >> 150 G4Polyline trajectoryLine; >> 151 G4Polymarker stepPoints; >> 152 G4Polymarker auxiliaryPoints; >> 153 >> 154 for (G4int i = 0; i < GetPointEntries() ; i++) { >> 155 G4VTrajectoryPoint* aTrajectoryPoint = GetPoint(i); >> 156 const G4std::vector<G4ThreeVector>* auxiliaries >> 157 = aTrajectoryPoint->GetAuxiliaryPoints(); >> 158 if (auxiliaries) { >> 159 for (size_t iAux = 0; iAux < auxiliaries->size(); ++iAux) { >> 160 const G4ThreeVector pos((*auxiliaries)[iAux]); >> 161 if (lineRequired) { >> 162 trajectoryLine.push_back(pos); >> 163 } >> 164 if (markersRequired) { >> 165 auxiliaryPoints.push_back(pos); >> 166 } >> 167 } >> 168 } >> 169 const G4ThreeVector pos(aTrajectoryPoint->GetPosition()); >> 170 if (lineRequired) { >> 171 trajectoryLine.push_back(pos); >> 172 } >> 173 if (markersRequired) { >> 174 stepPoints.push_back(pos); >> 175 } >> 176 } >> 177 >> 178 if (lineRequired) { >> 179 G4Colour colour; >> 180 const G4double charge = GetCharge(); >> 181 if(charge>0.) colour = G4Colour(0.,0.,1.); // Blue = positive. >> 182 else if(charge<0.) colour = G4Colour(1.,0.,0.); // Red = negative. >> 183 else colour = G4Colour(0.,1.,0.); // Green = neutral. >> 184 G4VisAttributes trajectoryLineAttribs(colour); >> 185 trajectoryLine.SetVisAttributes(&trajectoryLineAttribs); >> 186 pVVisManager->Draw(trajectoryLine); >> 187 } >> 188 if (markersRequired) { >> 189 auxiliaryPoints.SetMarkerType(G4Polymarker::squares); >> 190 auxiliaryPoints.SetScreenSize(markerSize); >> 191 auxiliaryPoints.SetFillStyle(G4VMarker::filled); >> 192 G4VisAttributes auxiliaryPointsAttribs(G4Colour(0.,1.,1.)); // Magenta >> 193 auxiliaryPoints.SetVisAttributes(&auxiliaryPointsAttribs); >> 194 pVVisManager->Draw(auxiliaryPoints); >> 195 >> 196 stepPoints.SetMarkerType(G4Polymarker::circles); >> 197 stepPoints.SetScreenSize(markerSize); >> 198 stepPoints.SetFillStyle(G4VMarker::filled); >> 199 G4VisAttributes stepPointsAttribs(G4Colour(1.,1.,0.)); // Yellow. >> 200 stepPoints.SetVisAttributes(&stepPointsAttribs); >> 201 pVVisManager->Draw(stepPoints); 114 } 202 } 115 } 203 } 116 204