Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4HEPEvtInterface class implementation << 27 // 26 // 28 // Author: Makoto Asai, 1997 << 27 // $Id: G4HEPEvtInterface.cc,v 1.11 2006/06/29 18:09:48 gunter Exp $ >> 28 // GEANT4 tag $Name: geant4-09-01 $ >> 29 // >> 30 // 29 // ------------------------------------------- 31 // -------------------------------------------------------------------- 30 32 31 #include "G4HEPEvtInterface.hh" << 32 << 33 #include "G4Types.hh" 33 #include "G4Types.hh" 34 #include "G4SystemOfUnits.hh" << 35 34 36 #include "G4ios.hh" 35 #include "G4ios.hh" >> 36 #include "G4HEPEvtInterface.hh" 37 #include "G4PrimaryVertex.hh" 37 #include "G4PrimaryVertex.hh" 38 #include "G4PrimaryParticle.hh" 38 #include "G4PrimaryParticle.hh" 39 #include "G4HEPEvtParticle.hh" 39 #include "G4HEPEvtParticle.hh" 40 #include "G4Event.hh" 40 #include "G4Event.hh" 41 41 42 G4HEPEvtInterface::G4HEPEvtInterface(const cha << 42 G4HEPEvtInterface::G4HEPEvtInterface(char* evfile) 43 : vLevel(vl) << 44 { 43 { 45 inputFile.open((char*)evfile); << 44 inputFile.open(evfile); 46 if (inputFile.is_open()) << 45 if (inputFile) { 47 { << 48 fileName = evfile; 46 fileName = evfile; 49 if(vl>0) << 50 G4cout << "G4HEPEvtInterface - " << file << 51 } 47 } 52 else << 48 else { 53 { << 49 G4Exception("G4HEPEvtInterface:: cannot open file."); 54 G4Exception("G4HEPEvtInterface::G4HEPEvtIn << 55 FatalException, "G4HEPEvtInter << 56 } 50 } 57 G4ThreeVector zero; 51 G4ThreeVector zero; 58 particle_position = zero; 52 particle_position = zero; 59 particle_time = 0.0; 53 particle_time = 0.0; >> 54 60 } 55 } 61 56 62 void G4HEPEvtInterface::GeneratePrimaryVertex( << 57 G4HEPEvtInterface::G4HEPEvtInterface(G4String evfile) 63 { 58 { 64 G4int NHEP = 0; // number of entries << 59 const char* fn = evfile.data(); 65 if (inputFile.is_open()) << 60 inputFile.open((char*)fn); 66 { << 61 if (inputFile) { 67 inputFile >> NHEP; << 62 fileName = evfile; 68 } 63 } 69 else << 64 else { 70 { << 65 G4Exception("G4HEPEvtInterface:: cannot open file."); 71 G4Exception("G4HEPEvtInterface::G4HEPEvtIn << 72 FatalException, "G4HEPEvtInter << 73 } 66 } >> 67 G4ThreeVector zero; >> 68 particle_position = zero; >> 69 particle_time = 0.0; >> 70 } >> 71 >> 72 G4HEPEvtInterface::~G4HEPEvtInterface() >> 73 {;} >> 74 >> 75 void G4HEPEvtInterface::GeneratePrimaryVertex(G4Event* evt) >> 76 { >> 77 G4int NHEP; // number of entries >> 78 inputFile >> NHEP; 74 if( inputFile.eof() ) 79 if( inputFile.eof() ) 75 { 80 { 76 G4Exception("G4HEPEvtInterface::GeneratePr << 81 G4Exception("End-Of-File : HEPEvt input file"); 77 RunMustBeAborted, << 78 "End-Of-File: HEPEvt input fil << 79 return; 82 return; 80 } 83 } 81 84 82 if(vLevel > 0) << 85 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 { 86 { 89 G4int ISTHEP; // status code 87 G4int ISTHEP; // status code 90 G4int IDHEP; // PDG code 88 G4int IDHEP; // PDG code 91 G4int JDAHEP1; // first daughter 89 G4int JDAHEP1; // first daughter 92 G4int JDAHEP2; // last daughter 90 G4int JDAHEP2; // last daughter 93 G4double PHEP1; // px in GeV 91 G4double PHEP1; // px in GeV 94 G4double PHEP2; // py in GeV 92 G4double PHEP2; // py in GeV 95 G4double PHEP3; // pz in GeV 93 G4double PHEP3; // pz in GeV 96 G4double PHEP5; // mass in GeV 94 G4double PHEP5; // mass in GeV 97 95 98 inputFile >> ISTHEP >> IDHEP >> JDAHEP1 >> 96 inputFile >> ISTHEP >> IDHEP >> JDAHEP1 >> JDAHEP2 99 >> PHEP1 >> PHEP2 >> PHEP3 >> PH << 97 >> 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 98 113 // Create G4PrimaryParticle object << 99 // create G4PrimaryParticle object 114 // << 100 G4PrimaryParticle* particle 115 auto* particle = new G4PrimaryParticle( ID << 101 = new G4PrimaryParticle( IDHEP, PHEP1*GeV, PHEP2*GeV, PHEP3*GeV ); 116 particle->SetMass( PHEP5*GeV ); 102 particle->SetMass( PHEP5*GeV ); 117 particle->SetMomentum(PHEP1*GeV, PHEP2*GeV << 118 103 119 // Create G4HEPEvtParticle object << 104 // create G4HEPEvtParticle object 120 // << 105 G4HEPEvtParticle* hepParticle 121 auto* hepParticle << 122 = new G4HEPEvtParticle( particle, ISTHEP 106 = new G4HEPEvtParticle( particle, ISTHEP, JDAHEP1, JDAHEP2 ); 123 107 124 // Store 108 // Store 125 // << 126 HPlist.push_back( hepParticle ); 109 HPlist.push_back( hepParticle ); 127 } 110 } 128 111 129 // Check if there is at least one particle << 112 // check if there is at least one particle 130 // << 113 if( HPlist.size() == 0 ) return; 131 if( HPlist.empty() ) return; << 114 132 << 115 // make connection between daughter particles decayed from 133 // Make connection between daughter particle << 116 // the same mother 134 // << 117 for( size_t i=0; i<HPlist.size(); i++ ) 135 for(auto & i : HPlist) << 136 { 118 { 137 if( i->GetJDAHEP1() > 0 ) // it has daugh << 119 if( HPlist[i]->GetJDAHEP1() > 0 ) // it has daughters 138 { 120 { 139 G4int jda1 = i->GetJDAHEP1()-1; // FORTR << 121 G4int jda1 = HPlist[i]->GetJDAHEP1()-1; // FORTRAN index starts from 1 140 G4int jda2 = i->GetJDAHEP2()-1; // but C << 122 G4int jda2 = HPlist[i]->GetJDAHEP2()-1; // but C++ starts from 0. 141 G4PrimaryParticle* mother = i->GetThePar << 123 G4PrimaryParticle* mother = HPlist[i]->GetTheParticle(); 142 for( G4int j=jda1; j<=jda2; ++j ) << 124 for( G4int j=jda1; j<=jda2; j++ ) 143 { 125 { 144 G4PrimaryParticle* daughter = HPlist[j 126 G4PrimaryParticle* daughter = HPlist[j]->GetTheParticle(); 145 if(HPlist[j]->GetISTHEP()>0) 127 if(HPlist[j]->GetISTHEP()>0) 146 { 128 { 147 mother->SetDaughter( daughter ); 129 mother->SetDaughter( daughter ); 148 HPlist[j]->Done(); 130 HPlist[j]->Done(); 149 } 131 } 150 } 132 } 151 } 133 } 152 } 134 } 153 135 154 // Create G4PrimaryVertex object << 136 // create G4PrimaryVertex object 155 // << 137 G4PrimaryVertex* vertex = new G4PrimaryVertex(particle_position,particle_time); 156 auto* vertex = new G4PrimaryVertex(particle_ << 138 157 << 139 // put initial particles to the vertex 158 // Put initial particles to the vertex << 140 for( size_t ii=0; ii<HPlist.size(); ii++ ) 159 // << 160 for(auto & ii : HPlist) << 161 { 141 { 162 if( ii->GetISTHEP() > 0 ) // ISTHEP of dau << 142 if( HPlist[ii]->GetISTHEP() > 0 ) // ISTHEP of daughters had been 163 // set t << 143 // set to negative 164 { 144 { 165 G4PrimaryParticle* initialParticle = ii- << 145 G4PrimaryParticle* initialParticle = HPlist[ii]->GetTheParticle(); 166 vertex->SetPrimary( initialParticle ); 146 vertex->SetPrimary( initialParticle ); 167 } 147 } 168 } 148 } 169 149 170 // Clear G4HEPEvtParticles << 150 // clear G4HEPEvtParticles 171 // << 151 //HPlist.clearAndDestroy(); 172 for(auto & iii : HPlist) << 152 for(size_t iii=0;iii<HPlist.size();iii++) 173 { << 153 { delete HPlist[iii]; } 174 delete iii; << 175 } << 176 HPlist.clear(); 154 HPlist.clear(); 177 155 178 // Put the vertex to G4Event object 156 // Put the vertex to G4Event object 179 // << 180 evt->AddPrimaryVertex( vertex ); 157 evt->AddPrimaryVertex( vertex ); 181 } 158 } >> 159 182 160