/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

GtGenerator.cc
Go to the documentation of this file.
00001 #include "GtGenerator.h"
00002 #include "GenTools/IHepMCEventMutator.h"
00003 
00004 #include "Event/GenHeader.h"
00005 
00006 #include "Context/TimeStamp.h"
00007 
00008 #include "GaudiKernel/ISvcLocator.h"
00009 #include "GaudiKernel/IDataProviderSvc.h"
00010 #include "GaudiKernel/IDataManagerSvc.h"
00011 #include "GaudiKernel/IRndmEngine.h"
00012 
00013 #include "GaudiKernel/IssueSeverity.h"
00014 
00015 #include "CLHEP/Units/SystemOfUnits.h"
00016 #include "HepMC/GenEvent.h"
00017 
00018 #include <vector>
00019 #include <limits>
00020 
00021 GtGenerator::GtGenerator(const std::string& name, ISvcLocator* pSvcLocator)
00022     : DybAlgorithm<DayaBay::GenHeader>(name,pSvcLocator)
00023 {
00024     declareProperty("TimeStamp",m_tsseconds = 0,
00025                     "Absolute start time in seconds from the unix epoch. "
00026                     "Caution: this is a bare integer, do not multiply by CLHEP seconds.");
00027     declareProperty("GenTools",m_genToolNames,
00028                     "Tools to generate HepMC::GenEvents");
00029     declareProperty("GenName", m_genName = "GtGenerator",
00030                     "Name of this generator for book keeping purposes.");
00031 }
00032 
00033 GtGenerator::~GtGenerator()
00034 {
00035 }
00036 
00037 StatusCode GtGenerator::initialize()
00038 {
00039     for (size_t ind=0; ind < m_genToolNames.size(); ++ind) {
00040         std::string gtn = m_genToolNames[ind];
00041         try {
00042             m_genTools.push_back(tool<IHepMCEventMutator>(gtn));
00043         }
00044         catch(const GaudiException& exg) {
00045             fatal() << "Failed to get generator: \"" << gtn << "\"" << endreq;
00046             return StatusCode::FAILURE;
00047         }
00048         info () << "Added gen tool " << gtn << endreq;
00049     }
00050 
00051     // Set the generator start time
00052     m_now = TimeStamp(m_tsseconds);
00053 
00054     return StatusCode::SUCCESS;
00055 }
00056 
00057 StatusCode GtGenerator::execute()
00058 {
00059     // Look for pre-existing header object or make new one
00060     DayaBay::GenHeader* gen_header = MakeHeaderObject();
00061 
00062 
00063     HepMC::GenEvent* event = new HepMC::GenEvent;
00064     event->set_event_number(this->getExecNum());
00065 
00066     // Let each tool do its thing on the event
00067     for (size_t ind = 0; ind< m_genTools.size(); ++ind) {
00068         debug () << "Running gen tool #" << ind << " " << m_genToolNames[ind] << endreq;
00069         if (m_genTools[ind]->mutate(*event).isFailure()) {
00070             fatal() << "Generator Tool " << m_genToolNames[ind]
00071                     << " failed" << endreq;
00072             return StatusCode::FAILURE;
00073         }
00074     }
00075 
00076     // Find the smallest time
00077     double dt = std::numeric_limits<double>::max();
00078     {
00079         HepMC::GenEvent::vertex_const_iterator it, done = event->vertices_end();
00080         for (it = event->vertices_begin(); it != done; ++it) {
00081             double t = (*it)->position().t();
00082             if (t < dt) dt = t;
00083         }
00084     }
00085     debug () << "Smallest time of "
00086              << event->vertices_size() << " vertices = " << dt << endreq;
00087 
00088     // Slurp away seconds and ns and leave the rest
00089     dt = dt/CLHEP::second;      // bring into explicit units of seconds
00090     time_t seconds = (time_t)dt;
00091     double fractional = dt - seconds;
00092     int ns = (int)(1e9*fractional);
00093     double rest = fractional - (1e-9*ns);
00094 
00095     // how much we steal away from each vertex time
00096     double toffset = (dt - rest)*CLHEP::second; // put back into system of units
00097 
00098     // Increment our notion of now
00099     m_now.Add(TimeStamp(seconds,ns));
00100     gen_header->setTimeStamp(m_now);
00101 
00102     debug() << "Offset time is " << toffset
00103             << ", now is " << m_now << endreq;
00104 
00105     // Loop over vertices to set reduce time we stole and set time extent
00106     {
00107         double earliest = -1, latest = -1;
00108         HepMC::GenEvent::vertex_iterator it, done = event->vertices_end();
00109         for (it = event->vertices_begin(); it != done; ++it) {
00110             HepMC::FourVector vtx = (*it)->position();
00111             double t = vtx.t() - toffset;
00112             vtx.setT(t);
00113             (*it)->set_position(vtx);
00114 
00115             if (earliest < 0 || earliest > t) earliest = t;
00116             if (latest   < 0 || latest   < t)   latest = t;
00117         }
00118 
00119         TimeStamp ts_earliest(m_now);
00120         if (earliest > 0)
00121             ts_earliest.Add(earliest/CLHEP::second);
00122         gen_header->setEarliest(ts_earliest);
00123 
00124         TimeStamp ts_latest(m_now);
00125         if (latest > 0)
00126             ts_latest.Add(latest/CLHEP::second);
00127         gen_header->setLatest(ts_latest);
00128     }
00129 
00130     // GenHeader subclass
00131     gen_header->setEvent(event);
00132     gen_header->setGeneratorName(m_genName);
00133 
00134     return StatusCode::SUCCESS;
00135 }
00136 
00137 StatusCode GtGenerator::finalize()
00138 {
00139     // Do NOT release the tools.  This is handled implicitly
00140     m_genTools.clear();
00141 
00142     return this->GaudiAlgorithm::finalize();
00143 }
00144 
00145 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:18:50 for GenTools by doxygen 1.7.4