Skip to content
Snippets Groups Projects
GenAlgo.cpp 1.59 KiB
Newer Older
fangwx@ihep.ac.cn's avatar
V3
fangwx@ihep.ac.cn committed
#include "GenAlgo.h"

#include "GaudiKernel/IEventProcessor.h"
#include "GaudiKernel/IAppMgrUI.h"
#include "GaudiKernel/GaudiException.h"


#include "edm4hep/MCParticleCollection.h"//plico
fangwx@ihep.ac.cn's avatar
V3
fangwx@ihep.ac.cn committed

#include <iostream>
#include <vector>
#include <fstream>

#include "IGenTool.h"
#include "GenEvent.h"


DECLARE_COMPONENT(GenAlgo)

GenAlgo::GenAlgo(const std::string& name, ISvcLocator* pSvcLocator): GaudiAlgorithm(name, pSvcLocator) {
    declareProperty("MCParticleGen", m_hdl, "MCParticle collection (at Generator phase)");
    declareProperty("GenTools", m_genToolNames, "List of GenTools");
fangwx@ihep.ac.cn's avatar
V3
fangwx@ihep.ac.cn committed
    m_evtid = 0;

}

StatusCode
GenAlgo::initialize() {
    if (m_genToolNames.size()==0) {
        error() << "Please specify the gentools to be used in GenAlgo." << endmsg;
        return StatusCode::FAILURE;
    }

    for (auto gtname: m_genToolNames) {
        m_genTools.push_back(gtname);
fangwx@ihep.ac.cn's avatar
V3
fangwx@ihep.ac.cn committed
    }
fangwx@ihep.ac.cn's avatar
V3
fangwx@ihep.ac.cn committed
    return StatusCode::SUCCESS;

}

StatusCode
GenAlgo::execute() {
    m_evtid++;
    auto mcCol = m_hdl.createAndPut();
    MyHepMC::GenEvent m_event(*mcCol);

    for(auto gentool: m_genTools) {
        if (gentool->mutate(m_event)) {} 
fangwx@ihep.ac.cn's avatar
V3
fangwx@ihep.ac.cn committed
        else {
lintao@ihep.ac.cn's avatar
lintao@ihep.ac.cn committed
            warning() << "Have read all events, stop now." << endmsg; 
fangwx@ihep.ac.cn's avatar
V3
fangwx@ihep.ac.cn committed
            auto ep = serviceLocator()->as<IEventProcessor>();
            if ( !ep ) {
lintao@ihep.ac.cn's avatar
lintao@ihep.ac.cn committed
                error() << "Cannot get IEventProcessor" << endmsg;
                return StatusCode::FAILURE;
fangwx@ihep.ac.cn's avatar
V3
fangwx@ihep.ac.cn committed
            }
            ep->stopRun();
            return StatusCode::SUCCESS;
            
fangwx@ihep.ac.cn's avatar
V3
fangwx@ihep.ac.cn committed
    }

    return StatusCode::SUCCESS;

}

StatusCode
GenAlgo::finalize() {
    return StatusCode::SUCCESS;
}