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: NTSTBabarEvtReadGenerator.cc,v 1.4 2006/06/29 18:26:03 gunter Exp $ |
---|
27 | // |
---|
28 | // -- Bogus -- BaBar Object-Oriented Geant-based Unified Simulation |
---|
29 | // |
---|
30 | // NTSTBabarEvtReadGenerator |
---|
31 | // |
---|
32 | // Description: |
---|
33 | // cloned from BabarEvtReadGenerator, it interpets the information in the |
---|
34 | // stdhep ascii files produced by GenFwkInt and passes it along to G4 |
---|
35 | // (both vertex and 4-vector information). |
---|
36 | // |
---|
37 | // This class is used in the Bogus standalone application. |
---|
38 | // |
---|
39 | // Author List: |
---|
40 | // Bill Lockman |
---|
41 | // |
---|
42 | // Modification History: |
---|
43 | // |
---|
44 | //----------------------------------------------------------------------------- |
---|
45 | |
---|
46 | // ====== C/C++ headers ====== |
---|
47 | #include <sstream> |
---|
48 | #include <iostream> |
---|
49 | #include <iomanip> |
---|
50 | |
---|
51 | // ====== This class header ====== |
---|
52 | #include "NTSTBabarEvtReadGenerator.hh" |
---|
53 | |
---|
54 | // ====== Collaborating classes ====== |
---|
55 | #include "G4ios.hh" |
---|
56 | #include "G4PrimaryVertex.hh" |
---|
57 | #include "G4PrimaryParticle.hh" |
---|
58 | #include "G4Event.hh" |
---|
59 | |
---|
60 | NTSTBabarEvtReadGenerator::NTSTBabarEvtReadGenerator(const char* evfile) |
---|
61 | : fileName(evfile){ |
---|
62 | inputFile.open(evfile); |
---|
63 | if (inputFile == 0){ |
---|
64 | G4cerr << "NTSTBabarEvtReadGenerator:: cannot open file " << fileName << G4endl; |
---|
65 | abort(); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | NTSTBabarEvtReadGenerator::~NTSTBabarEvtReadGenerator() |
---|
70 | { |
---|
71 | inputFile.close(); |
---|
72 | } |
---|
73 | |
---|
74 | void NTSTBabarEvtReadGenerator::GeneratePrimaryVertex(G4Event* anEvent){ |
---|
75 | G4int nevhep; // event number |
---|
76 | G4int nhep; // number of entries |
---|
77 | |
---|
78 | inputFile >> nevhep >> nhep; |
---|
79 | if( inputFile.eof() ) { |
---|
80 | G4cerr << "End-Of-File : BabarEvt input file" |
---|
81 | << fileName << G4endl; |
---|
82 | abort(); |
---|
83 | } |
---|
84 | |
---|
85 | for( G4int ihep=0; ihep<nhep; ihep++ ){ |
---|
86 | G4int isthep; // status code |
---|
87 | G4int idhep; // PDG code |
---|
88 | G4int moms[2] = {0,0}; // inital and final mother |
---|
89 | G4int daut[2] = {0,0}; // inital and final daughters |
---|
90 | G4double p[5] = {0,0,0,0,0}; // px, py, pz, E, m |
---|
91 | G4double v[4] = {0,0,0,0}; // x, y, z, t |
---|
92 | |
---|
93 | inputFile >> isthep >> idhep >> moms[0] >> daut[0] >> moms[1] >> daut[1]; |
---|
94 | inputFile >> p[0] >> p[1] >> p[2] >> p[3] >> p[4]; |
---|
95 | inputFile >> v[0] >> v[1] >> v[2] >> v[3]; |
---|
96 | |
---|
97 | if (isthep == 1) { // stable particle |
---|
98 | |
---|
99 | // create primary vertex - distance units are mm |
---|
100 | G4PrimaryVertex* primVtx = |
---|
101 | new G4PrimaryVertex(v[0]*mm, v[1]*mm, v[2]*mm, v[3]*ns); |
---|
102 | |
---|
103 | // create primary particle |
---|
104 | G4PrimaryParticle* primPart = |
---|
105 | new G4PrimaryParticle(idhep, p[0]*GeV, p[1]*GeV, p[2]*GeV); |
---|
106 | |
---|
107 | primPart->SetMass(p[4]*GeV); |
---|
108 | |
---|
109 | // no need to set daughter since we are keeping only the stable particles |
---|
110 | |
---|
111 | // add it to the primary vertex (ownership is passing to the vertex) |
---|
112 | primVtx->SetPrimary( primPart ); |
---|
113 | |
---|
114 | // add primary vertex to the event |
---|
115 | anEvent->AddPrimaryVertex( primVtx ); |
---|
116 | } |
---|
117 | } |
---|
118 | // for (G4int ivtx=0; ivtx < anEvent->GetNumberOfPrimaryVertex(); ivtx++){ |
---|
119 | // anEvent->GetPrimaryVertex(ivtx)->Print(); |
---|
120 | // } |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | |
---|