CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

GenParticles2HepMCConverter Class Reference

Inheritance diagram for GenParticles2HepMCConverter:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

void beginRun (edm::Run &run, const edm::EventSetup &eventSetup)
 GenParticles2HepMCConverter (const edm::ParameterSet &pset)
void produce (edm::Event &event, const edm::EventSetup &eventSetup)
 ~GenParticles2HepMCConverter ()

Private Member Functions

HepMC::FourVector FourVector (const reco::Candidate::Point &point)
HepMC::FourVector FourVector (const reco::Candidate::LorentzVector &lvec)

Private Attributes

edm::InputTag genEventInfoLabel_
edm::InputTag genParticlesLabel_
edm::ESHandle< ParticleDataTablepTable_

Detailed Description

Definition at line 28 of file GenParticles2HepMCConverter.cc.


Constructor & Destructor Documentation

GenParticles2HepMCConverter::GenParticles2HepMCConverter ( const edm::ParameterSet pset) [explicit]

Definition at line 59 of file GenParticles2HepMCConverter.cc.

References edm::ParameterSet::getParameter().

{
//  lheEventLabel_ = pset.getParameter<edm::InputTag>("lheEvent");
  genParticlesLabel_ = pset.getParameter<edm::InputTag>("genParticles");
  //genRunInfoLabel_ = pset.getParameter<edm::InputTag>("genRunInfo");
  genEventInfoLabel_ = pset.getParameter<edm::InputTag>("genEventInfo");

  produces<edm::HepMCProduct>();
}
GenParticles2HepMCConverter::~GenParticles2HepMCConverter ( ) [inline]

Definition at line 32 of file GenParticles2HepMCConverter.cc.

{};

Member Function Documentation

void GenParticles2HepMCConverter::beginRun ( edm::Run run,
const edm::EventSetup eventSetup 
) [virtual]

Reimplemented from edm::EDProducer.

Definition at line 69 of file GenParticles2HepMCConverter.cc.

{
  //edm::Handle<GenRunInfoProduct> genRunInfoHandle;
  //event.getByLabel(genRunInfoLabel_, genRunInfoHandle);
  // const double xsecIn = genRunInfoHandle->internalXSec().value();
  // const double xsecInErr = genRunInfoHandle->internalXSec().error();
  // const double xsecLO = genRunInfoHandle->externalXSecLO().value();
  // const double xsecLOErr = genRunInfoHandle->externalXSecLO().error();
  // const double xsecNLO = genRunInfoHandle->externalXSecNLO().value();
  // const double xsecNLOErr = genRunInfoHandle->externalXSecNLO().error();
}
HepMC::FourVector GenParticles2HepMCConverter::FourVector ( const reco::Candidate::LorentzVector lvec) [inline, private]

Definition at line 50 of file GenParticles2HepMCConverter.cc.

References max().

  {
    // Avoid negative mass, set minimum m^2 = 0
    return HepMC::FourVector(lvec.px(), lvec.py(), lvec.pz(), std::hypot(lvec.P(), std::max(0., lvec.mass())));
  };
HepMC::FourVector GenParticles2HepMCConverter::FourVector ( const reco::Candidate::Point point) [inline, private]

Definition at line 45 of file GenParticles2HepMCConverter.cc.

  {
    return HepMC::FourVector(10*point.x(), 10*point.y(), 10*point.z(), 0);
  };
void GenParticles2HepMCConverter::produce ( edm::Event event,
const edm::EventSetup eventSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 81 of file GenParticles2HepMCConverter.cc.

References edm::EventID::event(), configurableAnalysis::GenParticle, edm::EventSetup::getData(), i, gen::PdfInfo::id, edm::EventBase::id(), j, scaleCards::mass, reco::Candidate::mother(), n, reco::Candidate::numberOfMothers(), AlCaHLTBitMon_ParallelJobs::p, reco::Candidate::p4(), reco::Candidate::pdgId(), gen::PdfInfo::scalePDF, reco::Candidate::status(), reco::Candidate::vertex(), gen::PdfInfo::x, and gen::PdfInfo::xPDF.

{
//  edm::Handle<LHEEventProduct> lheEventHandle;
//  event.getByLabel(lheEventLabel_, lheEventHandle);

  edm::Handle<reco::CandidateView> genParticlesHandle;
  event.getByLabel(genParticlesLabel_, genParticlesHandle);

  edm::Handle<GenEventInfoProduct> genEventInfoHandle;
  event.getByLabel(genEventInfoLabel_, genEventInfoHandle);

  eventSetup.getData(pTable_);

  HepMC::GenEvent* hepmc_event = new HepMC::GenEvent();
  hepmc_event->set_event_number(event.id().event());
  hepmc_event->set_signal_process_id(genEventInfoHandle->signalProcessID());
  hepmc_event->set_event_scale(genEventInfoHandle->qScale());
  hepmc_event->set_alphaQED(genEventInfoHandle->alphaQED());
  hepmc_event->set_alphaQCD(genEventInfoHandle->alphaQCD());

  hepmc_event->weights() = genEventInfoHandle->weights();

  // Set PDF
  const gen::PdfInfo* pdf = genEventInfoHandle->pdf();
  const int pdf_id1 = pdf->id.first, pdf_id2 = pdf->id.second;
  const double pdf_x1 = pdf->x.first, pdf_x2 = pdf->x.second;
  const double pdf_scalePDF = pdf->scalePDF;
  const double pdf_xPDF1 = pdf->xPDF.first, pdf_xPDF2 = pdf->xPDF.second;
  HepMC::PdfInfo hepmc_pdfInfo(pdf_id1, pdf_id2, pdf_x1, pdf_x2, pdf_scalePDF, pdf_xPDF1, pdf_xPDF2);
  hepmc_event->set_pdf_info(hepmc_pdfInfo);

  // Load LHE
//  const lhef::HEPEUP& lheEvent = lheEventHandle->hepeup();
//  std::vector<int> lhe_meIndex; // Particle indices with preserved mass, status=2
//  for ( int i=0, n=lheEvent.ISTUP.size(); i<n; ++i )
//  {
//    if ( lheEvent.ISTUP[i] == 2 ) lhe_meIndex.push_back(i);
//  }

  // Prepare list of HepMC::GenParticles
  std::map<const reco::Candidate*, HepMC::GenParticle*> genCandToHepMCMap;
  std::vector<HepMC::GenParticle*> hepmc_particles;
  for ( unsigned int i=0, n=genParticlesHandle->size(); i<n; ++i )
  {
    const reco::Candidate* p = &genParticlesHandle->at(i);
    HepMC::GenParticle* hepmc_particle = new HepMC::GenParticle(FourVector(p->p4()), p->pdgId(), p->status());
    hepmc_particle->suggest_barcode(i+1);

    // Assign particle's generated mass from the standard particle data table
    double particleMass = pTable_->particle(p->pdgId())->mass();
//    // Re-assign generated mass from LHE, find particle among the LHE
//    for ( unsigned int j=0, m=lhe_meIndex.size(); j<m; ++j )
//    {
//      const unsigned int lheIndex = lhe_meIndex[j];
//      if ( p->pdgId() != lheEvent.IDUP[lheIndex] ) continue;
//
//      const lhef::HEPEUP::FiveVector& vp = lheEvent.PUP[lheIndex];
//      if ( std::abs(vp[0] - p->px()) > 1e-7 or std::abs(vp[1] - p->py()) > 1e-7 ) continue;
//      if ( std::abs(vp[2] - p->pz()) > 1e-7 or std::abs(vp[3] - p->energy()) > 1e-7 ) continue;
//
//      particleMass = vp[4];
//      break;
//    }
    hepmc_particle->set_generated_mass(particleMass);

    hepmc_particles.push_back(hepmc_particle);
    genCandToHepMCMap[p] = hepmc_particle;
  }

  // Put incident beam particles : proton -> parton vertex
  const reco::Candidate* parton1 = genParticlesHandle->at(0).daughter(0);
  const reco::Candidate* parton2 = genParticlesHandle->at(1).daughter(0);
  HepMC::GenVertex* vertex1 = new HepMC::GenVertex(FourVector(parton1->vertex()));
  HepMC::GenVertex* vertex2 = new HepMC::GenVertex(FourVector(parton2->vertex()));
  hepmc_event->add_vertex(vertex1);
  hepmc_event->add_vertex(vertex2);
  //hepmc_particles[0]->set_status(4);
  //hepmc_particles[1]->set_status(4);
  vertex1->add_particle_in(hepmc_particles[0]);
  vertex2->add_particle_in(hepmc_particles[1]);
  hepmc_event->set_beam_particles(hepmc_particles[0], hepmc_particles[1]);

  // Prepare vertex list
  typedef std::map<const reco::Candidate*, HepMC::GenVertex*> ParticleToVertexMap;
  ParticleToVertexMap particleToVertexMap;
  particleToVertexMap[parton1] = vertex1;
  particleToVertexMap[parton2] = vertex2;
  for ( unsigned int i=2, n=genParticlesHandle->size(); i<n; ++i )
  {
    const reco::Candidate* p = &genParticlesHandle->at(i);

    // Connect mother-daughters for the other cases
    for ( unsigned int j=0, nMothers=p->numberOfMothers(); j<nMothers; ++j )
    {
      // Mother-daughter hierarchy defines vertex
      const reco::Candidate* elder = p->mother(j)->daughter(0);
      HepMC::GenVertex* vertex;
      if ( particleToVertexMap.find(elder) == particleToVertexMap.end() )
      {
        vertex = new HepMC::GenVertex(FourVector(elder->vertex()));
        hepmc_event->add_vertex(vertex);
        particleToVertexMap[elder] = vertex;
      }
      else
      {
        vertex = particleToVertexMap[elder];
      }

      // Vertex is found. Now connect each other
      const reco::Candidate* mother = p->mother(j);
      vertex->add_particle_in(genCandToHepMCMap[mother]);
      vertex->add_particle_out(hepmc_particles[i]);
    }
  }

  // Finalize HepMC event record
  hepmc_event->set_signal_process_vertex(*(vertex1->vertices_begin()));

  std::auto_ptr<edm::HepMCProduct> hepmc_product(new edm::HepMCProduct());
  hepmc_product->addHepMCData(hepmc_event);
  event.put(hepmc_product);

}

Member Data Documentation

Definition at line 41 of file GenParticles2HepMCConverter.cc.

Definition at line 39 of file GenParticles2HepMCConverter.cc.

Definition at line 42 of file GenParticles2HepMCConverter.cc.