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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /event/src/G4HEPEvtInterface.cc (Version 11.3.0) and /event/src/G4HEPEvtInterface.cc (Version 10.5)


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