Geant4 Cross Reference |
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 #include "Par04Hit.hh" 27 28 #include "G4AttDef.hh" // for G4AttDef 29 #include "G4AttDefStore.hh" // for GetInstance 30 #include "G4AttValue.hh" // for G4AttValue 31 #include "G4Colour.hh" // for G4Colour 32 #include "G4SystemOfUnits.hh" // for mm, MeV, cm, rad 33 #include "G4Tubs.hh" // for G4Tubs 34 #include "G4UnitsTable.hh" // for G4BestUnit 35 #include "G4VVisManager.hh" // for G4VVisManager 36 #include "G4VisAttributes.hh" // for G4VisAttributes 37 38 #include <CLHEP/Units/SystemOfUnits.h> // for mm, pi, MeV, cm, rad 39 #include <CLHEP/Vector/ThreeVector.h> // for operator/, operator<<, Hep... 40 #include <G4RotationMatrix.hh> // for G4RotationMatrix 41 #include <G4String.hh> // for G4String 42 #include <G4ThreeVector.hh> // for G4ThreeVector 43 #include <G4Transform3D.hh> // for G4Transform3D 44 #include <G4VHit.hh> // for G4VHit 45 #include <algorithm> // for max 46 #include <cmath> // for log10 47 #include <iostream> // for operator<<, basic_ostream:... 48 #include <string> // for operator< 49 template<class Type> 50 class G4Allocator; 51 52 G4ThreadLocal G4Allocator<Par04Hit>* Par04HitAllocator; 53 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 55 56 Par04Hit::Par04Hit() : G4VHit() {} 57 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 60 Par04Hit::~Par04Hit() = default; 61 62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 64 Par04Hit::Par04Hit(const Par04Hit& aRight) : G4VHit() 65 { 66 fEdep = aRight.fEdep; 67 fNdep = aRight.fNdep; 68 fZId = aRight.fZId; 69 fRhoId = aRight.fRhoId; 70 fPhiId = aRight.fPhiId; 71 fTime = aRight.fTime; 72 fPos = aRight.fPos; 73 fRot = aRight.fRot; 74 fType = aRight.fType; 75 fLogVol = aRight.fLogVol; 76 } 77 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 80 const Par04Hit& Par04Hit::operator=(const Par04Hit& aRight) 81 { 82 fEdep = aRight.fEdep; 83 fNdep = aRight.fNdep; 84 fZId = aRight.fZId; 85 fRhoId = aRight.fRhoId; 86 fPhiId = aRight.fPhiId; 87 fTime = aRight.fTime; 88 fPos = aRight.fPos; 89 fRot = aRight.fRot; 90 fType = aRight.fType; 91 fLogVol = aRight.fLogVol; 92 return *this; 93 } 94 95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 96 97 int Par04Hit::operator==(const Par04Hit& aRight) const 98 { 99 return (fRhoId == aRight.fRhoId && fPhiId == aRight.fPhiId && fZId == aRight.fZId); 100 } 101 102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 103 104 void Par04Hit::Draw() 105 { 106 /// Arbitrary size corresponds to the example macros 107 G4ThreeVector meshSize(2.325 * mm, 2 * CLHEP::pi / 50. * CLHEP::rad, 3.4 * mm); 108 G4int numPhiCells = CLHEP::pi * 2. / meshSize.y(); 109 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 110 // Hits can be filtered out in visualisation 111 if (!pVVisManager->FilterHit(*this)) return; 112 // Do not plot hits from parallel world 113 if (fType >= 2) return; 114 // Do not draw empty hits 115 if (fEdep <= 0) return; 116 // Do not plot if default values were not changed 117 if (fRhoId == -1 && fZId == -1 && fPhiId == -1) return; 118 if (pVVisManager) { 119 G4Transform3D trans(fRot, fPos); 120 G4VisAttributes attribs; 121 G4Tubs solid("draw", fRhoId * meshSize.x(), (fRhoId + 1) * meshSize.x(), meshSize.z() / 2., 122 (-numPhiCells / 2. + fPhiId) * meshSize.y(), meshSize.y()); 123 // Set colours depending on type of hit (full/fast sim) 124 G4double colR = fType == 0 ? 0 : 1; 125 G4double colG = fType == 0 ? 1 : 0; 126 G4double colB = 0; 127 // Set transparency depending on the energy 128 // Arbitrary formula 129 G4double alpha = 2 * std::log10(fEdep + 1); 130 G4Colour colour(colR, colG, colB, alpha); 131 attribs.SetColour(colour); 132 attribs.SetForceSolid(true); 133 pVVisManager->Draw(solid, attribs, trans); 134 } 135 } 136 137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 138 139 const std::map<G4String, G4AttDef>* Par04Hit::GetAttDefs() const 140 { 141 G4bool isNew; 142 std::map<G4String, G4AttDef>* store = G4AttDefStore::GetInstance("Par04Hit", isNew); 143 if (isNew) { 144 (*store)["HitType"] = G4AttDef("HitType", "Hit Type", "Physics", "", "G4String"); 145 (*store)["Energy"] = 146 G4AttDef("Energy", "Energy Deposited", "Physics", "G4BestUnit", "G4double"); 147 (*store)["Time"] = G4AttDef("Time", "Time", "Physics", "G4BestUnit", "G4double"); 148 (*store)["Pos"] = G4AttDef("Pos", "Position", "Physics", "G4BestUnit", "G4ThreeVector"); 149 } 150 return store; 151 } 152 153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 154 155 std::vector<G4AttValue>* Par04Hit::CreateAttValues() const 156 { 157 std::vector<G4AttValue>* values = new std::vector<G4AttValue>; 158 values->push_back(G4AttValue("HitType", "HadPar04Hit", "")); 159 values->push_back(G4AttValue("Energy", G4BestUnit(fEdep, "Energy"), "")); 160 values->push_back(G4AttValue("Time", G4BestUnit(fTime, "Time"), "")); 161 values->push_back(G4AttValue("Pos", G4BestUnit(fPos, "Length"), "")); 162 return values; 163 } 164 165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 166 167 void Par04Hit::Print() 168 { 169 std::cout << "\tHit " << fEdep / MeV << " MeV from " << fNdep << " deposits at " << fPos / cm 170 << " cm rotation " << fRot << " (R,phi,z)= (" << fRhoId << ", " << fPhiId << ", " 171 << fZId << "), " << fTime << " ns" << std::endl; 172 } 173