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 // G4HEPEvtInterface class implementation << 27 // 23 // 28 // Author: Makoto Asai, 1997 << 24 // $Id: G4HEPEvtInterface.cc,v 1.9 2003/06/16 16:50:33 gunter Exp $ >> 25 // GEANT4 tag $Name: geant4-07-00-patch-01 $ >> 26 // >> 27 // 29 // ------------------------------------------- 28 // -------------------------------------------------------------------- 30 29 31 #include "G4HEPEvtInterface.hh" << 32 << 33 #include "G4Types.hh" 30 #include "G4Types.hh" 34 #include "G4SystemOfUnits.hh" << 31 #include <strstream> 35 32 36 #include "G4ios.hh" 33 #include "G4ios.hh" >> 34 #include "G4HEPEvtInterface.hh" 37 #include "G4PrimaryVertex.hh" 35 #include "G4PrimaryVertex.hh" 38 #include "G4PrimaryParticle.hh" 36 #include "G4PrimaryParticle.hh" 39 #include "G4HEPEvtParticle.hh" 37 #include "G4HEPEvtParticle.hh" 40 #include "G4Event.hh" 38 #include "G4Event.hh" 41 39 42 G4HEPEvtInterface::G4HEPEvtInterface(const cha << 40 G4HEPEvtInterface::G4HEPEvtInterface(char* evfile) 43 : vLevel(vl) << 44 { 41 { 45 inputFile.open((char*)evfile); << 42 inputFile.open(evfile); 46 if (inputFile.is_open()) << 43 if (inputFile) { 47 { << 48 fileName = evfile; 44 fileName = evfile; 49 if(vl>0) << 50 G4cout << "G4HEPEvtInterface - " << file << 51 } 45 } 52 else << 46 else { 53 { << 47 G4Exception("G4HEPEvtInterface:: cannot open file."); 54 G4Exception("G4HEPEvtInterface::G4HEPEvtIn << 55 FatalException, "G4HEPEvtInter << 56 } 48 } 57 G4ThreeVector zero; 49 G4ThreeVector zero; 58 particle_position = zero; 50 particle_position = zero; 59 particle_time = 0.0; 51 particle_time = 0.0; >> 52 60 } 53 } 61 54 62 void G4HEPEvtInterface::GeneratePrimaryVertex( << 55 G4HEPEvtInterface::G4HEPEvtInterface(G4String evfile) 63 { 56 { 64 G4int NHEP = 0; // number of entries << 57 const char* fn = evfile.data(); 65 if (inputFile.is_open()) << 58 inputFile.open((char*)fn); 66 { << 59 if (inputFile) { 67 inputFile >> NHEP; << 60 fileName = evfile; 68 } 61 } 69 else << 62 else { 70 { << 63 G4Exception("G4HEPEvtInterface:: cannot open file."); 71 G4Exception("G4HEPEvtInterface::G4HEPEvtIn << 72 FatalException, "G4HEPEvtInter << 73 } 64 } >> 65 G4ThreeVector zero; >> 66 particle_position = zero; >> 67 particle_time = 0.0; >> 68 } >> 69 >> 70 G4HEPEvtInterface::~G4HEPEvtInterface() >> 71 {;} >> 72 >> 73 void G4HEPEvtInterface::GeneratePrimaryVertex(G4Event* evt) >> 74 { >> 75 G4int NHEP; // number of entries >> 76 inputFile >> NHEP; 74 if( inputFile.eof() ) 77 if( inputFile.eof() ) 75 { 78 { 76 G4Exception("G4HEPEvtInterface::GeneratePr << 79 G4Exception("End-Of-File : HEPEvt input file"); 77 RunMustBeAborted, << 78 "End-Of-File: HEPEvt input fil << 79 return; 80 return; 80 } 81 } 81 82 82 if(vLevel > 0) << 83 for( G4int IHEP=0; IHEP<NHEP; IHEP++ ) 83 { << 84 G4cout << "G4HEPEvtInterface - reading " < << 85 << " HEPEvt particles from " << fil << 86 } << 87 for( G4int IHEP=0; IHEP<NHEP; ++IHEP ) << 88 { 84 { 89 G4int ISTHEP; // status code 85 G4int ISTHEP; // status code 90 G4int IDHEP; // PDG code 86 G4int IDHEP; // PDG code 91 G4int JDAHEP1; // first daughter 87 G4int JDAHEP1; // first daughter 92 G4int JDAHEP2; // last daughter 88 G4int JDAHEP2; // last daughter 93 G4double PHEP1; // px in GeV 89 G4double PHEP1; // px in GeV 94 G4double PHEP2; // py in GeV 90 G4double PHEP2; // py in GeV 95 G4double PHEP3; // pz in GeV 91 G4double PHEP3; // pz in GeV 96 G4double PHEP5; // mass in GeV 92 G4double PHEP5; // mass in GeV 97 93 98 inputFile >> ISTHEP >> IDHEP >> JDAHEP1 >> 94 inputFile >> ISTHEP >> IDHEP >> JDAHEP1 >> JDAHEP2 99 >> PHEP1 >> PHEP2 >> PHEP3 >> PH << 95 >> PHEP1 >> PHEP2 >> PHEP3 >> PHEP5; 100 if( inputFile.eof() ) << 101 { << 102 G4Exception("G4HEPEvtInterface::Generate << 103 FatalException, << 104 "Unexpected End-Of-File in t << 105 } << 106 if(vLevel > 1) << 107 { << 108 G4cout << " " << ISTHEP << " " << IDHEP << 109 << " " << JDAHEP2 << " " << PHEP1 << 110 << " " << PHEP3 << " " << PHEP5 < << 111 } << 112 96 113 // Create G4PrimaryParticle object << 97 // create G4PrimaryParticle object 114 // << 98 G4PrimaryParticle* particle 115 auto* particle = new G4PrimaryParticle( ID << 99 = new G4PrimaryParticle( IDHEP, PHEP1*GeV, PHEP2*GeV, PHEP3*GeV ); 116 particle->SetMass( PHEP5*GeV ); 100 particle->SetMass( PHEP5*GeV ); 117 particle->SetMomentum(PHEP1*GeV, PHEP2*GeV << 118 101 119 // Create G4HEPEvtParticle object << 102 // create G4HEPEvtParticle object 120 // << 103 G4HEPEvtParticle* hepParticle 121 auto* hepParticle << 122 = new G4HEPEvtParticle( particle, ISTHEP 104 = new G4HEPEvtParticle( particle, ISTHEP, JDAHEP1, JDAHEP2 ); 123 105 124 // Store 106 // Store 125 // << 126 HPlist.push_back( hepParticle ); 107 HPlist.push_back( hepParticle ); 127 } 108 } 128 109 129 // Check if there is at least one particle << 110 // check if there is at least one particle 130 // << 111 if( HPlist.size() == 0 ) return; 131 if( HPlist.empty() ) return; << 112 132 << 113 // make connection between daughter particles decayed from 133 // Make connection between daughter particle << 114 // the same mother 134 // << 115 for( size_t i=0; i<HPlist.size(); i++ ) 135 for(auto & i : HPlist) << 136 { 116 { 137 if( i->GetJDAHEP1() > 0 ) // it has daugh << 117 if( HPlist[i]->GetJDAHEP1() > 0 ) // it has daughters 138 { 118 { 139 G4int jda1 = i->GetJDAHEP1()-1; // FORTR << 119 G4int jda1 = HPlist[i]->GetJDAHEP1()-1; // FORTRAN index starts from 1 140 G4int jda2 = i->GetJDAHEP2()-1; // but C << 120 G4int jda2 = HPlist[i]->GetJDAHEP2()-1; // but C++ starts from 0. 141 G4PrimaryParticle* mother = i->GetThePar << 121 G4PrimaryParticle* mother = HPlist[i]->GetTheParticle(); 142 for( G4int j=jda1; j<=jda2; ++j ) << 122 for( G4int j=jda1; j<=jda2; j++ ) 143 { 123 { 144 G4PrimaryParticle* daughter = HPlist[j 124 G4PrimaryParticle* daughter = HPlist[j]->GetTheParticle(); 145 if(HPlist[j]->GetISTHEP()>0) 125 if(HPlist[j]->GetISTHEP()>0) 146 { 126 { 147 mother->SetDaughter( daughter ); 127 mother->SetDaughter( daughter ); 148 HPlist[j]->Done(); 128 HPlist[j]->Done(); 149 } 129 } 150 } 130 } 151 } 131 } 152 } 132 } 153 133 154 // Create G4PrimaryVertex object << 134 // create G4PrimaryVertex object 155 // << 135 G4PrimaryVertex* vertex = new G4PrimaryVertex(particle_position,particle_time); 156 auto* vertex = new G4PrimaryVertex(particle_ << 136 157 << 137 // put initial particles to the vertex 158 // Put initial particles to the vertex << 138 for( size_t ii=0; ii<HPlist.size(); ii++ ) 159 // << 160 for(auto & ii : HPlist) << 161 { 139 { 162 if( ii->GetISTHEP() > 0 ) // ISTHEP of dau << 140 if( HPlist[ii]->GetISTHEP() > 0 ) // ISTHEP of daughters had been 163 // set t << 141 // set to negative 164 { 142 { 165 G4PrimaryParticle* initialParticle = ii- << 143 G4PrimaryParticle* initialParticle = HPlist[ii]->GetTheParticle(); 166 vertex->SetPrimary( initialParticle ); 144 vertex->SetPrimary( initialParticle ); 167 } 145 } 168 } 146 } 169 147 170 // Clear G4HEPEvtParticles << 148 // clear G4HEPEvtParticles 171 // << 149 //HPlist.clearAndDestroy(); 172 for(auto & iii : HPlist) << 150 for(size_t iii=0;iii<HPlist.size();iii++) 173 { << 151 { delete HPlist[iii]; } 174 delete iii; << 175 } << 176 HPlist.clear(); 152 HPlist.clear(); 177 153 178 // Put the vertex to G4Event object 154 // Put the vertex to G4Event object 179 // << 180 evt->AddPrimaryVertex( vertex ); 155 evt->AddPrimaryVertex( vertex ); 181 } 156 } >> 157 182 158