/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 #include "GtTimeratorTool.h" 00002 00003 #include "GaudiKernel/IssueSeverity.h" 00004 #include "GaudiKernel/IRndmGenSvc.h" 00005 #include "HepMC/GenEvent.h" 00006 #include "HepMC/GenVertex.h" 00007 #include "CLHEP/Units/SystemOfUnits.h" 00008 00009 #include <cmath> 00010 00011 GtTimeratorTool::GtTimeratorTool(const std::string& type, 00012 const std::string& name, 00013 const IInterface* parent) 00014 : GaudiTool(type,name,parent) 00015 { 00016 declareInterface<IHepMCEventMutator>(this); 00017 00018 declareProperty("Mode",m_mode="Absolut","Mode for time calculation method."); 00019 declareProperty("Distribution",m_distrib="Exponential","Event timing distribution"); 00020 declareProperty("LifeTime",m_lifetime=0,"Life time for distribution."); 00021 } 00022 00023 GtTimeratorTool::~GtTimeratorTool() 00024 { 00025 } 00026 00027 StatusCode GtTimeratorTool::initialize() 00028 { 00029 info () << "initialize timer tool with mean delta time of " 00030 << m_lifetime/CLHEP::second << endreq; 00031 00032 // Non-positive lifetimes are meaningless and cause problems, particularly for 00033 // the Sim15 method 00034 if ( m_lifetime <= 0 ) 00035 { 00036 fatal() << "Non-positive lifetime specified. This is meaningless." << endreq; 00037 return StatusCode::FAILURE; 00038 } 00039 00040 // Unfortunately GaudiTool doesn't provide a short cut for us 00041 IRndmGenSvc *rgs = 0; 00042 if (service("RndmGenSvc",rgs,true).isFailure()) { 00043 fatal() << "Failed to get random service" << endreq; 00044 return StatusCode::FAILURE; 00045 } 00046 00047 StatusCode sc; 00048 if (m_rand.initialize(rgs, Rndm::Flat(0,1)).isFailure()) { 00049 fatal() << "Failed to initialize flat random numbers" << endreq; 00050 return StatusCode::FAILURE; 00051 } 00052 00053 return StatusCode::SUCCESS; 00054 } 00055 00056 StatusCode GtTimeratorTool::finalize() 00057 { 00058 return StatusCode::SUCCESS; 00059 } 00060 00061 StatusCode GtTimeratorTool::mutate(HepMC::GenEvent& event) 00062 { 00063 // Exponential Distribution: t(n) = t(n-1) * exp(-t/tL) 00064 // random t(n) = -ln(U)*tL + t(n-1) 00065 00066 double u = m_rand(); 00067 double dt = 0; 00068 00069 if (m_distrib == "Exponential") dt = ((-1.0 * log(u)) * m_lifetime); 00070 else if (m_distrib == "Uniform") dt = m_lifetime; 00071 else { 00072 fatal() << "Not a recognized event timing distribution option" << endreq; 00073 return StatusCode::FAILURE; 00074 } 00075 00076 debug() << "Incrementing current time of by " 00077 << dt/CLHEP::second << " seconds" 00078 << endreq; 00079 00080 double event_time = dt; 00081 00082 HepMC::GenEvent::vertex_iterator vtx, done = event.vertices_end(); 00083 for (vtx = event.vertices_begin(); vtx != done; ++vtx) { 00084 HepMC::FourVector position = (*vtx)->position(); 00085 double vertex_time = event_time; 00086 if (m_mode == "Relative") 00087 vertex_time += position.t(); 00088 position.setT(vertex_time); 00089 (*vtx)->set_position(position); 00090 } 00091 return StatusCode::SUCCESS; 00092 } 00093