Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

HepMCEventWriter.cxx

Go to the documentation of this file.
00001 // ================================================
00002 // HepMCEventWriter class Implementation
00003 // Puts a HepMC event into the TES. For Atlfast Tests
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 // Gaudi includes
00014 #include "GaudiKernel/DataSvc.h"
00015 #include "StoreGate/DataHandle.h"
00016 
00017 // CLHEP,HepMC
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     //     name status pdg_id  parent Px       Py    Pz       Energy      Mass
00078     //  1  !p+!    3   2212    0,0    0.000    0.000 7000.000 7000.000    0.938
00079     //  2  !p+!    3   2212    0,0    0.000    0.000-7000.000 7000.000    0.938
00080     //=========================================================================
00081     //  3  !d!     3      1    1,1    0.750   -1.569   32.191   32.238    0.000
00082     //  4  !u~!    3     -2    2,2   -3.047  -19.000  -54.629   57.920    0.000
00083     //  5  !W-!    3    -24    1,2    1.517   -20.68  -20.605   85.925   80.799
00084     //  6  !gamma! 1     22    1,2   -3.813    0.113   -1.833    4.233    0.000
00085     //  7  !d!     1      1    5,5   -2.445   28.816    6.082   29.552    0.010
00086     //  8  !u~!    1     -2    5,5    3.962  -49.498  -26.687   56.373    0.006
00087 
00088     // first we construct a ParticleDataTable with all the particles we need
00089     HepMC::ParticleDataTable pdt("my particle data table");
00090     // create a particle data entry for the proton and add it to pdt at the
00091     // same time
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     // print out the GenParticle Data to the screen
00100     pdt.print();
00101 
00102     // now we build the graph, which will look like
00103     //                       p7
00104     // p1                   /
00105     //   \v1__p3      p5---v4
00106     //         \_v3_/       \ 
00107     //         /    \        p8
00108     //    v2__p4     \ 
00109     //   /            p6
00110     // p2
00111     //
00112 
00113     // First create the event container, with Signal Process 20, event number 1
00114     // create vertex 1 and vertex 2, together with their inparticles
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     // create the outgoing particles of v1 and v2
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     // create v3
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     // create v4
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     // tell the event which vertex is the signal process vertex
00199     evt->set_signal_process_vertex( v3 );
00200     // the event is complete, we now print it out to the screen
00201     evt->print();
00202     
00203     // now clean-up by deleteing all objects from memory
00204     //
00205     // deleting the event deletes all contained vertices, and all particles
00206     // contained in those vertices
00207     //    delete evt;
00208 
00209     // delete all particle data objects in the particle data table pdt
00210     pdt.delete_all();
00211     return StatusCode::SUCCESS;
00212 
00213   }
00214 } // Atlfast
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 

Generated on Tue Mar 18 11:18:23 2003 for AtlfastAlgs by doxygen1.3-rc1