[827] | 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 | // |
---|
[1228] | 27 | // $Id: G4RichTrajectory.cc,v 1.8 2009/11/24 10:04:14 perl Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
[827] | 29 | // |
---|
| 30 | // --------------------------------------------------------------- |
---|
| 31 | // |
---|
| 32 | // G4RichTrajectory.cc |
---|
| 33 | // |
---|
| 34 | // Contact: |
---|
| 35 | // Questions and comments on G4Trajectory, on which this is based, |
---|
| 36 | // should be sent to |
---|
| 37 | // Katsuya Amako (e-mail: Katsuya.Amako@kek.jp) |
---|
| 38 | // Makoto Asai (e-mail: asai@kekvax.kek.jp) |
---|
| 39 | // Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp) |
---|
| 40 | // and on the extended code to: |
---|
| 41 | // John Allison (e-mail: John.Allison@manchester.ac.uk) |
---|
| 42 | // Joseph Perl (e-mail: perl@slac.stanford.edu) |
---|
| 43 | // |
---|
| 44 | // --------------------------------------------------------------- |
---|
| 45 | |
---|
| 46 | #include "G4RichTrajectory.hh" |
---|
| 47 | #include "G4RichTrajectoryPoint.hh" |
---|
| 48 | #include "G4AttDefStore.hh" |
---|
| 49 | #include "G4AttDef.hh" |
---|
| 50 | #include "G4AttValue.hh" |
---|
[1196] | 51 | #include "G4UnitsTable.hh" |
---|
[827] | 52 | #include "G4VProcess.hh" |
---|
| 53 | |
---|
| 54 | //#define G4ATTDEBUG |
---|
| 55 | #ifdef G4ATTDEBUG |
---|
| 56 | #include "G4AttCheck.hh" |
---|
| 57 | #endif |
---|
| 58 | |
---|
[1228] | 59 | #include <sstream> |
---|
| 60 | |
---|
[827] | 61 | G4Allocator<G4RichTrajectory> aRichTrajectoryAllocator; |
---|
| 62 | |
---|
| 63 | G4RichTrajectory::G4RichTrajectory(): |
---|
| 64 | fpRichPointsContainer(0), |
---|
[1196] | 65 | fpCreatorProcess(0), |
---|
[1228] | 66 | fpEndingProcess(0), |
---|
[1196] | 67 | fFinalKineticEnergy(0.) |
---|
[827] | 68 | {} |
---|
| 69 | |
---|
| 70 | G4RichTrajectory::G4RichTrajectory(const G4Track* aTrack): |
---|
| 71 | G4Trajectory(aTrack) // Note: this initialises the base class data |
---|
| 72 | // members and, unfortunately but never mind, |
---|
| 73 | // creates a G4TrajectoryPoint in |
---|
| 74 | // TrajectoryPointContainer that we cannot |
---|
| 75 | // access because it's private. We store the |
---|
| 76 | // same information (plus more) in a |
---|
| 77 | // G4RichTrajectoryPoint in the |
---|
| 78 | // RichTrajectoryPointsContainer |
---|
| 79 | { |
---|
[1228] | 80 | fpInitialVolume = aTrack->GetTouchableHandle(); |
---|
| 81 | fpInitialNextVolume = aTrack->GetNextTouchableHandle(); |
---|
[827] | 82 | fpCreatorProcess = aTrack->GetCreatorProcess(); |
---|
[1228] | 83 | // On construction, set final values to initial values. |
---|
| 84 | // Final values are updated at the addition of every step - see AppendStep. |
---|
| 85 | fpFinalVolume = aTrack->GetTouchableHandle(); |
---|
| 86 | fpFinalNextVolume = aTrack->GetNextTouchableHandle(); |
---|
| 87 | fpEndingProcess = aTrack->GetCreatorProcess(); |
---|
| 88 | fFinalKineticEnergy = aTrack->GetKineticEnergy(); |
---|
| 89 | // Insert the first rich trajectory point (see note above)... |
---|
[827] | 90 | fpRichPointsContainer = new RichTrajectoryPointsContainer; |
---|
| 91 | fpRichPointsContainer->push_back(new G4RichTrajectoryPoint(aTrack)); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | G4RichTrajectory::G4RichTrajectory(G4RichTrajectory & right): |
---|
| 95 | G4Trajectory(right) |
---|
| 96 | { |
---|
| 97 | fpInitialVolume = right.fpInitialVolume; |
---|
| 98 | fpInitialNextVolume = right.fpInitialNextVolume; |
---|
| 99 | fpCreatorProcess = right.fpCreatorProcess; |
---|
[1228] | 100 | fpFinalVolume = right.fpFinalVolume; |
---|
| 101 | fpFinalNextVolume = right.fpFinalNextVolume; |
---|
| 102 | fpEndingProcess = right.fpEndingProcess; |
---|
| 103 | fFinalKineticEnergy = right.fFinalKineticEnergy; |
---|
[827] | 104 | fpRichPointsContainer = new RichTrajectoryPointsContainer; |
---|
| 105 | for(size_t i=0;i<right.fpRichPointsContainer->size();i++) |
---|
| 106 | { |
---|
| 107 | G4RichTrajectoryPoint* rightPoint = |
---|
| 108 | (G4RichTrajectoryPoint*)((*(right.fpRichPointsContainer))[i]); |
---|
| 109 | fpRichPointsContainer->push_back(new G4RichTrajectoryPoint(*rightPoint)); |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | G4RichTrajectory::~G4RichTrajectory() |
---|
| 114 | { |
---|
| 115 | if (fpRichPointsContainer) { |
---|
| 116 | // fpRichPointsContainer->clearAndDestroy(); |
---|
| 117 | size_t i; |
---|
| 118 | for(i=0;i<fpRichPointsContainer->size();i++){ |
---|
| 119 | delete (*fpRichPointsContainer)[i]; |
---|
| 120 | } |
---|
| 121 | fpRichPointsContainer->clear(); |
---|
| 122 | delete fpRichPointsContainer; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | void G4RichTrajectory::AppendStep(const G4Step* aStep) |
---|
| 127 | { |
---|
| 128 | fpRichPointsContainer->push_back(new G4RichTrajectoryPoint(aStep)); |
---|
[1196] | 129 | // Except for first step, which is a sort of virtual step to start |
---|
[1228] | 130 | // the track, compute the final values... |
---|
| 131 | const G4Track* track = aStep->GetTrack(); |
---|
| 132 | const G4StepPoint* postStepPoint = aStep->GetPostStepPoint(); |
---|
| 133 | if (track->GetCurrentStepNumber() > 0) { |
---|
| 134 | fpFinalVolume = track->GetTouchableHandle(); |
---|
| 135 | fpFinalNextVolume = track->GetNextTouchableHandle(); |
---|
| 136 | fpEndingProcess = postStepPoint->GetProcessDefinedStep(); |
---|
[1196] | 137 | fFinalKineticEnergy = |
---|
| 138 | aStep->GetPreStepPoint()->GetKineticEnergy() - |
---|
| 139 | aStep->GetTotalEnergyDeposit(); |
---|
| 140 | } |
---|
[827] | 141 | } |
---|
| 142 | |
---|
| 143 | void G4RichTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory) |
---|
| 144 | { |
---|
| 145 | if(!secondTrajectory) return; |
---|
| 146 | |
---|
| 147 | G4Trajectory::MergeTrajectory(secondTrajectory); |
---|
| 148 | |
---|
| 149 | G4RichTrajectory* seco = (G4RichTrajectory*)secondTrajectory; |
---|
| 150 | G4int ent = seco->GetPointEntries(); |
---|
| 151 | for(G4int i=1;i<ent;i++) { |
---|
| 152 | // initial point of the second trajectory should not be merged |
---|
| 153 | fpRichPointsContainer->push_back((*(seco->fpRichPointsContainer))[i]); |
---|
| 154 | // fpRichPointsContainer->push_back(seco->fpRichPointsContainer->removeAt(1)); |
---|
| 155 | } |
---|
| 156 | delete (*seco->fpRichPointsContainer)[0]; |
---|
| 157 | seco->fpRichPointsContainer->clear(); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | const std::map<G4String,G4AttDef>* G4RichTrajectory::GetAttDefs() const |
---|
| 161 | { |
---|
| 162 | G4bool isNew; |
---|
| 163 | std::map<G4String,G4AttDef>* store |
---|
| 164 | = G4AttDefStore::GetInstance("G4RichTrajectory",isNew); |
---|
| 165 | if (isNew) { |
---|
| 166 | |
---|
| 167 | // Get att defs from base class... |
---|
| 168 | *store = *(G4Trajectory::GetAttDefs()); |
---|
| 169 | |
---|
| 170 | G4String ID; |
---|
| 171 | |
---|
[1228] | 172 | ID = "IVPath"; |
---|
| 173 | (*store)[ID] = G4AttDef(ID,"Initial Volume Path", |
---|
[827] | 174 | "Physics","","G4String"); |
---|
| 175 | |
---|
[1228] | 176 | ID = "INVPath"; |
---|
| 177 | (*store)[ID] = G4AttDef(ID,"Initial Next Volume Path", |
---|
[827] | 178 | "Physics","","G4String"); |
---|
| 179 | |
---|
| 180 | ID = "CPN"; |
---|
| 181 | (*store)[ID] = G4AttDef(ID,"Creator Process Name", |
---|
| 182 | "Physics","","G4String"); |
---|
| 183 | |
---|
| 184 | ID = "CPTN"; |
---|
| 185 | (*store)[ID] = G4AttDef(ID,"Creator Process Type Name", |
---|
| 186 | "Physics","","G4String"); |
---|
| 187 | |
---|
[1228] | 188 | ID = "FVPath"; |
---|
| 189 | (*store)[ID] = G4AttDef(ID,"Final Volume Path", |
---|
| 190 | "Physics","","G4String"); |
---|
| 191 | |
---|
| 192 | ID = "FNVPath"; |
---|
| 193 | (*store)[ID] = G4AttDef(ID,"Final Next Volume Path", |
---|
| 194 | "Physics","","G4String"); |
---|
| 195 | |
---|
| 196 | ID = "EPN"; |
---|
| 197 | (*store)[ID] = G4AttDef(ID,"Ending Process Name", |
---|
| 198 | "Physics","","G4String"); |
---|
| 199 | |
---|
| 200 | ID = "EPTN"; |
---|
| 201 | (*store)[ID] = G4AttDef(ID,"Ending Process Type Name", |
---|
| 202 | "Physics","","G4String"); |
---|
| 203 | |
---|
[1196] | 204 | ID = "FKE"; |
---|
| 205 | (*store)[ID] = G4AttDef(ID,"Final kinetic energy", |
---|
| 206 | "Physics","G4BestUnit","G4double"); |
---|
| 207 | |
---|
[827] | 208 | } |
---|
| 209 | |
---|
| 210 | return store; |
---|
| 211 | } |
---|
| 212 | |
---|
[1228] | 213 | static G4String Path(const G4TouchableHandle& th) |
---|
| 214 | { |
---|
| 215 | std::ostringstream oss; |
---|
| 216 | G4int depth = th->GetHistoryDepth(); |
---|
| 217 | for (G4int i = depth; i >= 0; --i) { |
---|
| 218 | oss << th->GetVolume(i)->GetName() |
---|
| 219 | << ':' << th->GetCopyNumber(i); |
---|
| 220 | if (i != 0) oss << '/'; |
---|
| 221 | } |
---|
| 222 | return oss.str(); |
---|
| 223 | } |
---|
| 224 | |
---|
[827] | 225 | std::vector<G4AttValue>* G4RichTrajectory::CreateAttValues() const |
---|
| 226 | { |
---|
| 227 | // Create base class att values... |
---|
| 228 | std::vector<G4AttValue>* values = G4Trajectory::CreateAttValues(); |
---|
| 229 | |
---|
[1228] | 230 | if (fpInitialVolume && fpInitialVolume->GetVolume()) { |
---|
| 231 | values->push_back(G4AttValue("IVPath",Path(fpInitialVolume),"")); |
---|
| 232 | } else { |
---|
| 233 | values->push_back(G4AttValue("IVPath","None","")); |
---|
| 234 | } |
---|
[827] | 235 | |
---|
[1228] | 236 | if (fpInitialNextVolume && fpInitialNextVolume->GetVolume()) { |
---|
| 237 | values->push_back(G4AttValue("INVPath",Path(fpInitialNextVolume),"")); |
---|
| 238 | } else { |
---|
| 239 | values->push_back(G4AttValue("INVPath","None","")); |
---|
| 240 | } |
---|
[827] | 241 | |
---|
| 242 | if (fpCreatorProcess) { |
---|
| 243 | values->push_back(G4AttValue("CPN",fpCreatorProcess->GetProcessName(),"")); |
---|
| 244 | G4ProcessType type = fpCreatorProcess->GetProcessType(); |
---|
| 245 | values->push_back(G4AttValue("CPTN",G4VProcess::GetProcessTypeName(type),"")); |
---|
| 246 | } else { |
---|
| 247 | values->push_back(G4AttValue("CPN","User Defined","")); |
---|
| 248 | values->push_back(G4AttValue("CPTN","User","")); |
---|
| 249 | } |
---|
| 250 | |
---|
[1228] | 251 | if (fpFinalVolume && fpFinalVolume->GetVolume()) { |
---|
| 252 | values->push_back(G4AttValue("FVPath",Path(fpFinalVolume),"")); |
---|
| 253 | } else { |
---|
| 254 | values->push_back(G4AttValue("FVPath","None","")); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | if (fpFinalNextVolume && fpFinalNextVolume->GetVolume()) { |
---|
| 258 | values->push_back(G4AttValue("FNVPath",Path(fpFinalNextVolume),"")); |
---|
| 259 | } else { |
---|
| 260 | values->push_back(G4AttValue("FNVPath","None","")); |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | if (fpEndingProcess) { |
---|
| 264 | values->push_back(G4AttValue("EPN",fpEndingProcess->GetProcessName(),"")); |
---|
| 265 | G4ProcessType type = fpEndingProcess->GetProcessType(); |
---|
| 266 | values->push_back(G4AttValue("EPTN",G4VProcess::GetProcessTypeName(type),"")); |
---|
| 267 | } else { |
---|
| 268 | values->push_back(G4AttValue("EPN","User Defined","")); |
---|
| 269 | values->push_back(G4AttValue("EPTN","User","")); |
---|
| 270 | } |
---|
| 271 | |
---|
[1196] | 272 | values->push_back |
---|
| 273 | (G4AttValue("FKE",G4BestUnit(fFinalKineticEnergy,"Energy"),"")); |
---|
| 274 | |
---|
[827] | 275 | #ifdef G4ATTDEBUG |
---|
| 276 | G4cout << G4AttCheck(values,GetAttDefs()); |
---|
| 277 | #endif |
---|
| 278 | |
---|
| 279 | return values; |
---|
| 280 | } |
---|