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 | // $Id: G4CascadeMomentum.hh,v 1.5 2010/03/16 22:10:26 mkelsey Exp $ |
---|
27 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
28 | // |
---|
29 | // Class G4CascadeMomentum |
---|
30 | // |
---|
31 | // Class description: |
---|
32 | // |
---|
33 | // A simple wrapper class meant to replace the widespread use of |
---|
34 | // std::vector<double> in the cascade mode code, which causes |
---|
35 | // problems for performance due to excess memory allocations. |
---|
36 | // |
---|
37 | // NOTE: The Bertini code does not pass legitimate four-vectors when |
---|
38 | // creating new particles; the new getLV() function takes an |
---|
39 | // optional mass argument (in Bertini units [GeV]) so that a |
---|
40 | // valid G4LorentzVector can be returned. |
---|
41 | // |
---|
42 | // Author: Peter Elmer, Princeton University 7-Aug-2008 |
---|
43 | // Update: Michael Kelsey, SLAC (support G4LorentzVector) 8-Jan-2010 |
---|
44 | // -------------------------------------------------------------------- |
---|
45 | #ifndef G4CASCADE_MOMENTUM_HH |
---|
46 | #define G4CASCADE_MOMENTUM_HH |
---|
47 | |
---|
48 | #include <cassert> |
---|
49 | |
---|
50 | #include "G4Types.hh" |
---|
51 | #include "G4LorentzVector.hh" |
---|
52 | #include "G4ThreeVector.hh" |
---|
53 | |
---|
54 | class G4CascadeMomentum |
---|
55 | { |
---|
56 | public: |
---|
57 | G4CascadeMomentum() {for (int i=0; i<4; ++i) data_[i]=0.0;} |
---|
58 | |
---|
59 | // WARNING! This metric is (t,x,y,z), DIFFERENT FROM HepLV! |
---|
60 | G4CascadeMomentum(const G4LorentzVector& lv) { |
---|
61 | setLV(lv); |
---|
62 | } |
---|
63 | |
---|
64 | G4double& operator[](int i) { |
---|
65 | assert(i>=0 && i<4); |
---|
66 | return data_[i]; |
---|
67 | } |
---|
68 | const G4double& operator[](int i) const { |
---|
69 | assert(i>=0 && i<4); |
---|
70 | return data_[i]; |
---|
71 | } |
---|
72 | |
---|
73 | operator const G4LorentzVector&() const { |
---|
74 | return getLV(); // Casting can't do mass repairs |
---|
75 | } |
---|
76 | |
---|
77 | const G4LorentzVector& getLV(G4double mass=-1.) const { |
---|
78 | if (mass>=0.) lv.setVectM(get3V(),mass); // Force input mass! |
---|
79 | else lv.set(data_[1],data_[2],data_[3],data_[0]); |
---|
80 | |
---|
81 | return lv; |
---|
82 | } |
---|
83 | |
---|
84 | G4ThreeVector get3V() const { |
---|
85 | return getLV().vect(); |
---|
86 | } |
---|
87 | |
---|
88 | void setLV(const G4LorentzVector& lv) { |
---|
89 | data_[0] = lv.t(); // NOTE DIFFERENT METRIC CONVENTION! |
---|
90 | data_[1] = lv.x(); |
---|
91 | data_[2] = lv.y(); |
---|
92 | data_[3] = lv.z(); |
---|
93 | } |
---|
94 | |
---|
95 | G4CascadeMomentum& operator=(const G4LorentzVector& lv) { |
---|
96 | setLV(lv); |
---|
97 | return *this; |
---|
98 | } |
---|
99 | |
---|
100 | private: |
---|
101 | G4double data_[4]; |
---|
102 | mutable G4LorentzVector lv; // Buffer for conversion operations |
---|
103 | }; |
---|
104 | |
---|
105 | #endif |
---|
106 | |
---|