/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Simulation/G4Svc/G4Svc-00-01-52/other_src/AthenaHepMCtoG4EventAction.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------
00002 //
00003 // ClassName:   AthenaHepMCtoG4EventAction
00004 //  
00005 // Description: PrimaryGeneratorAction to convert HepMC event to G4Event
00006 //
00007 // Author:      Charles Leggett
00008 // 
00009 // Date:        3-8-2001
00010 // 
00011 // $Id: AthenaHepMCtoG4EventAction.cpp,v 1.1 2005/08/17 06:45:46 dengzy Exp $
00012 // Simulation/G4Sim/G4Svc tag $Name: G4Svc-00-01-52 $
00013 //
00014 //------------------------------------------------------------------
00015 
00016 #include "G4Svc/AthenaHepMCtoG4EventAction.h"
00017 
00018 #include "HepMC/GenEvent.h"
00019 
00020 #include "G4Event.hh"
00021 #include "G4UImanager.hh"
00022 #include "globals.hh"
00023 
00024 #include "G4PrimaryParticle.hh"
00025 #include "G4PrimaryVertex.hh"
00026 #include "G4LorentzVector.hh"
00027 #include "G4Geantino.hh"
00028 
00029 #include "GaudiKernel/IMessageSvc.h"
00030 
00031 using namespace HepMC;
00032 
00033 AthenaHepMCtoG4EventAction::AthenaHepMCtoG4EventAction( int level):
00034   m_logLevel(level) {
00035 }
00036 
00037 AthenaHepMCtoG4EventAction::AthenaHepMCtoG4EventAction():
00038 m_logLevel( int(MSG::INFO) ) {
00039 }
00040 
00041 AthenaHepMCtoG4EventAction::~AthenaHepMCtoG4EventAction() {
00042 
00043 }
00044 
00045 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
00046 
00047 //void AthenaHepMCtoG4EventAction::SetHepMCEvent(const HepMC::GenEvent *p) { 
00048 void AthenaHepMCtoG4EventAction::SetHepMCEvent(McEventCol::iterator p) { 
00049   
00050   if ( m_logLevel <= int(MSG::DEBUG) ) {
00051     std::cout << "AthenaHepMCtoG4EventAction: - Setting HepMC Event ptr" 
00052               << std::endl;
00053   }
00054 
00055   //  p_evt = p;
00056   p_evtCollItr = p;
00057 
00058 }
00059 
00060 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
00061 
00062 //  void AthenaHepMCtoG4EventAction::GeneratePrimaries(G4Event* anEvent)
00063 //  {
00064 //    if ( m_logLevel <= int(MSG::DEBUG) ) {
00065 //      std::cout << "AthenaHepMCtoG4EventAction: - Generating Primaries" 
00066 //            << std::endl;
00067 //    }
00068 
00069 //    p_evt = (*p_evtCollItr)->pGenEvt();
00070 
00071 //    if (p_evt == 0) { 
00072 
00073 //      if ( m_logLevel <= int(MSG::WARNING) ) {
00074 //        std::cout << "AthenaHepMCtoG4EventAction: - HepMC ptr == null" 
00075 //              << std::endl;
00076 //      }
00077 
00078 //      return; 
00079 
00080 //    }
00081 
00082 //    int nv = 1;
00083 //    int mnv;
00084 
00085 //    std::cout << "how many vertices: ";
00086 //    std::cin >> mnv;
00087 
00088 //    for ( HepMC::GenEvent::vertex_const_iterator v = p_evt->vertices_begin();
00089 //          v != p_evt->vertices_end(); ++v ) {
00090 //      bool IsGood=false;
00091 //      for (HepMC::GenVertex::particle_iterator it=
00092 //         (*v)->particles_begin(HepMC::children);
00093 //       it!=(*v)->particles_end(HepMC::children);
00094 //       it++) {
00095       
00096 //        if (!(*it)->end_vertex() && (*it)->status()==1 ) { 
00097 //      IsGood=true;
00098 //      break;
00099 //        }
00100 //      }
00101 
00102 //      if (IsGood) {
00103 //        std::cout << "found a good vertex, barcode: " << (*v)->barcode() 
00104 //              << std::endl;
00105       
00106 //        G4LorentzVector lv=(*v)->position();
00107 //        G4PrimaryVertex *vert= new G4PrimaryVertex(lv.x(),lv.y(),lv.z(),lv.t());
00108 
00109 //        for (HepMC::GenVertex::particle_iterator it=
00110 //           (*v)->particles_begin(HepMC::children);
00111 //         it!=(*v)->particles_end(HepMC::children);
00112 //         it++) {
00113         
00114 //      //      if ( (*it)->status() != 1) continue;
00115 
00116 //      int pdgcode=(*it)->pdg_id();
00117 //      GenVertex *dcy = (*it)->end_vertex();
00118 //      std::cout << "found a good particle, barcode: " << (*it)->barcode()
00119 //                << "  pdg: " << pdgcode << "  status: " << (*it)->status()
00120 //                << "  end: ";
00121 //      if (dcy != 0) {
00122 //        std::cout << dcy->barcode();
00123 //      } else {
00124 //        std::cout << "nil";
00125 //      }
00126 //      std::cout << std::endl;
00127 
00128 //      const G4ThreeVector& p=(*it)->momentum();
00129 //      G4PrimaryParticle *part;
00130 //      if (pdgcode!=999) {
00131 //        part=new G4PrimaryParticle (pdgcode,p.x()*GeV,p.y()*GeV,p.z()*GeV);
00132 //      } else {
00133 //        G4ParticleDefinition *pdef = G4Geantino::GeantinoDefinition();
00134 //        part=new G4PrimaryParticle (pdef,p.x()*GeV,p.y()*GeV,p.z()*GeV);
00135 //      }
00136 //      vert->SetPrimary(part);
00137 //        }
00138 //        anEvent->AddPrimaryVertex(vert);
00139 //        if (nv > mnv) { break; }
00140 //        nv ++;
00141 //      }
00142 //    }       
00143 
00144 //    std::cout << "done generating event" << std::endl;
00145 
00146 //    p_evtCollItr++;
00147   
00148 //  }
00149 
00150 //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
00151 
00152 void AthenaHepMCtoG4EventAction::GeneratePrimaries(G4Event* anEvent)
00153 {
00154   if ( m_logLevel <= int(MSG::DEBUG) ) {
00155     std::cout << "AthenaHepMCtoG4EventAction: - Generating Primaries" 
00156               << std::endl;
00157   }
00158 
00159   
00160   p_evt = (const HepMC::GenEvent *)(*p_evtCollItr);
00161 
00162   
00163   if (p_evt == 0) { 
00164 
00165     if ( m_logLevel <= int(MSG::WARNING) ) {
00166       std::cout << "AthenaHepMCtoG4EventAction: - HepMC ptr == null" 
00167                 << std::endl;
00168     }
00169 
00170     return; 
00171 
00172   }
00173   
00174   G4PrimaryVertex* vertex = new G4PrimaryVertex(0.,0.,0.,0.);
00175   
00176   int n=0;
00177   for ( HepMC::GenEvent::vertex_const_iterator v = p_evt->vertices_begin();
00178         v != p_evt->vertices_end(); ++v ) {
00179     bool IsGood=false;
00180     for (HepMC::GenVertex::particle_iterator it=
00181            (*v)->particles_begin(HepMC::children);
00182          it!=(*v)->particles_end(HepMC::children);
00183          it++) {
00184       
00185       if (!(*it)->end_vertex() && (*it)->status()==1 ) { 
00186         IsGood=true;
00187         break;
00188       }
00189     }
00190 
00191     if (IsGood) {
00192 //        std::cout << "found a good vertex, barcode: " << (*v)->barcode() 
00193 //              << std::endl;
00194       
00195       for (HepMC::GenVertex::particle_iterator it=
00196              (*v)->particles_begin(HepMC::children);
00197            it!=(*v)->particles_end(HepMC::children);
00198            it++) {
00199         
00200         if ( (*it)->status() != 1) continue;
00201 
00202         int pdgcode=(*it)->pdg_id();
00203 //      GenVertex *dcy = (*it)->end_vertex();
00204 //      std::cout << "found a good particle, barcode: " << (*it)->barcode()
00205 //                << "  pdg: " << pdgcode << "  status: " << (*it)->status()
00206 //                << "  end: ";
00207 //      if (dcy != 0) {
00208 //        std::cout << dcy->barcode();
00209 //      } else {
00210 //        std::cout << "nil";
00211 //      }
00212 //      std::cout << std::endl;
00213 
00214         const G4ThreeVector& p=(*it)->momentum();
00215         G4PrimaryParticle *part;
00216         if (pdgcode!=999) {
00217           part=new G4PrimaryParticle (pdgcode,p.x()*GeV,p.y()*GeV,p.z()*GeV);
00218         } else {
00219           G4ParticleDefinition *pdef = G4Geantino::GeantinoDefinition();
00220           part=new G4PrimaryParticle (pdef,p.x()*GeV,p.y()*GeV,p.z()*GeV);
00221         }
00222 
00223       vertex->SetPosition((*v)->position().x(),
00224                           (*v)->position().y(),
00225                           (*v)->position().z());
00226       vertex->SetT0((*v)->position().t());
00227 
00228         vertex->SetPrimary(part);
00229 
00230         n++;
00231       }
00232     }
00233   }       
00234   anEvent->AddPrimaryVertex(vertex);
00235 
00236   if ( m_logLevel <= int(MSG::DEBUG) ) {
00237     std::cout << "AthenaHepMCtoG4EventAction: - done. G4Event has " 
00238               << n << "  particles. "
00239               << std::endl;
00240   }
00241 
00242   p_evtCollItr++;
00243   
00244 }

Generated on Tue Nov 29 23:14:33 2016 for BOSS_7.0.2 by  doxygen 1.4.7