00001
00002
00003
00004
00005
00006
00007 #include "AtlfastAlgs/HepMCEventWriter.h"
00008 #include "AtlfastEvent/MsgStreamDefs.h"
00009 #include "AtlfastEvent/MCparticleCollection.h"
00010 #include "AtlfastUtils/HeaderPrinter.h"
00011
00012 #include <cmath>
00013
00014 #include "GaudiKernel/DataSvc.h"
00015 #include "StoreGate/DataHandle.h"
00016
00017
00018 #include "GeneratorObjects/McEvent.h"
00019 #include "GeneratorObjects/McEventCollection.h"
00020 #include "HepMC/GenEvent.h"
00021 #include "HepMC/ParticleDataTable.h"
00022
00023
00024
00025 namespace Atlfast {
00026
00027 HepMCEventWriter::HepMCEventWriter
00028 ( const std::string& name, ISvcLocator* pSvcLocator )
00029 : Algorithm( name, pSvcLocator ){}
00030
00031 HepMCEventWriter::~HepMCEventWriter() {
00032 MsgStream log( messageService(), name() ) ;
00033 log << MSG::INFO << "destructor called" << endreq;
00034 }
00035
00036 StatusCode HepMCEventWriter::initialize()
00037 {
00038 MsgStream log( messageService(), name() ) ;
00039 log<<"Initialise...."<<endreq;
00040 HeaderPrinter hp("Atlfast HepMCEventWriter:", log);
00041 hp.print();
00042
00043 m_tesIO = new TesIO();
00044
00045 return StatusCode::SUCCESS;
00046 }
00047
00048 StatusCode HepMCEventWriter::finalize(){
00049
00050 MsgStream log( messageService(), name() ) ;
00051
00052 log << MSG::INFO << "Finalizing" << endreq;
00053
00054 return StatusCode::SUCCESS ;
00055 }
00056
00057 StatusCode HepMCEventWriter::execute( ){
00058 MsgStream log( messageService(), name() ) ;
00059 log << MSG::DEBUG << "Execute() " << endreq;
00060
00061 McEventCollection* mcCollection = new McEventCollection;
00062 McEvent* mcEvent = new McEvent("Test",20,1);
00063 HepMC::GenEvent* evt = mcEvent->pGenEvt();
00064 this->makeGenEvent(evt);
00065
00066 mcCollection->push_back(mcEvent);
00067 m_tesIO->store(mcCollection);
00068 return StatusCode::SUCCESS;
00069 }
00070
00071 StatusCode HepMCEventWriter::makeGenEvent(HepMC::GenEvent* evt){
00072
00073 MsgStream log( messageService(), name() ) ;
00074 log << MSG::DEBUG << "MakeGenEvent() " << endreq;
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 HepMC::ParticleDataTable pdt("my particle data table");
00090
00091
00092 pdt.insert( new HepMC::ParticleData( "p+", 2212, +1, 0.938, -1, .5 ) );
00093 pdt.insert( new HepMC::ParticleData( "d", 1, -2./3., 0, -1, .5 ) );
00094 pdt.insert( new HepMC::ParticleData( "u~", -2, -1./3., 0, -1, .5 ) );
00095 pdt.insert( new HepMC::ParticleData( "W-", -24, -1, 80.396,
00096 HepMC::clifetime_from_width(2.06), 1 ) );
00097 pdt.insert( new HepMC::ParticleData( "gamma", 22, 0, 0, -1, 1 ) );
00098
00099
00100 pdt.print();
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 HepMC::GenVertex* v1 = new HepMC::GenVertex();
00116 evt->add_vertex( v1 );
00117 v1->
00118 add_particle_in( new HepMC::GenParticle( HepLorentzVector(0,0,7000,7000),
00119 2212,
00120 3 )
00121 );
00122 HepMC::GenVertex* v2 = new HepMC::GenVertex();
00123 evt->add_vertex( v2 );
00124 v2->
00125 add_particle_in(
00126 new HepMC::GenParticle( HepLorentzVector(0,0,-7000,7000),
00127 2212,
00128 3 )
00129 );
00130
00131
00132 HepMC::GenParticle* p3 =
00133 new HepMC::GenParticle(
00134 HepLorentzVector(.750,-1.569,32.191,32.238),
00135 1,
00136 3 );
00137 v1->add_particle_out( p3 );
00138 HepMC::GenParticle* p4 =
00139 new HepMC::GenParticle( HepLorentzVector(-3.047,-19.,-54.629,57.920),
00140 -2,
00141 3 );
00142 v2->add_particle_out( p4 );
00143
00144
00145 HepMC::GenVertex* v3 = new HepMC::GenVertex();
00146 evt->add_vertex( v3 );
00147 v3->add_particle_in( p3 );
00148 v3->add_particle_in( p4 );
00149 v3->add_particle_out(
00150 new HepMC::GenParticle( HepLorentzVector(-3.813,0.113,-1.833,4.233 ),
00151 22,
00152 1 )
00153 );
00154 HepMC::GenParticle* p5 =
00155 new HepMC::GenParticle( HepLorentzVector(1.517,-20.68,-20.605,85.925),
00156 -24,
00157 3);
00158 v3->add_particle_out( p5 );
00159
00160
00161 HepMC::GenVertex* v4 = new HepMC::GenVertex();
00162 evt->add_vertex( v4 );
00163 v4->add_particle_in( p5 );
00164 v4->add_particle_out(
00165 new HepMC::GenParticle( HepLorentzVector(-2.445,28.816,6.082,29.552),
00166 1,
00167 1 )
00168 );
00169 v4->
00170 add_particle_out( new HepMC::GenParticle(
00171 HepLorentzVector(3.962,
00172 -49.498,
00173 -26.687,
00174 56.373),
00175 -2,
00176 1 )
00177 );
00178 int i, j, k;
00179 double delta = 2.5;
00180 double px, py, pz, e;
00181 int maxstep = 21;
00182 for(i=1;i<maxstep;++i){
00183 px = i*delta;
00184 for(j=1;j<maxstep;++j){
00185 py = j*delta;
00186 for(k=1;k<maxstep;++k){
00187 pz = k*delta;
00188 e=sqrt(px*px+py*py+pz*pz);
00189 log << MSG::INFO << "px,pypz,e"
00190 <<px<<" "<<py<<" "<<pz<<" "<<e<<" "<<endreq;
00191 HepMC::GenParticle* temp =
00192 new HepMC::GenParticle( HepLorentzVector(px,py,pz,e), 13, 1);
00193 v4->add_particle_out(temp);
00194 }
00195 }
00196 }
00197
00198
00199 evt->set_signal_process_vertex( v3 );
00200
00201 evt->print();
00202
00203
00204
00205
00206
00207
00208
00209
00210 pdt.delete_all();
00211 return StatusCode::SUCCESS;
00212
00213 }
00214 }
00215
00216
00217
00218
00219
00220
00221
00222