#include <Ntuple2HepMCFiller.h>
Public Member Functions | |
HepMC::GenParticle * | createParticle (int index) |
HepMC::GenEvent * | fillCurrentEventData () |
virtual void | initialize (const std::string &filename, int id) |
bool | isInitialized () |
virtual bool | printHepMcEvent () const |
virtual bool | readCurrentEvent () |
virtual bool | setEvent (unsigned int event) |
virtual bool | toGenEvent (int evtnum, HepMC::GenEvent *evt) |
virtual | ~Ntuple2HepMCFiller () |
Destructor. | |
Static Public Member Functions | |
static Ntuple2HepMCFiller * | instance () |
Protected Member Functions | |
Ntuple2HepMCFiller () | |
Constructor. | |
void | setInitialized (bool value) |
Private Member Functions | |
void | buildProductionVertex (int i, std::vector< HepMC::GenParticle * > &hepevt_particle, HepMC::GenEvent *evt, bool printInconsistencyErrors) |
int | find_in_map (const std::map< HepMC::GenParticle *, int > &m, HepMC::GenParticle *p) const |
int | number_children (int index) |
int | number_parents (int index) |
Private Attributes | |
HepMC::GenEvent * | evt |
int | evtid |
std::vector< HepMC::GenParticle * > | index_to_particle |
bool | initialized_ |
NtupleROOTFile * | input_ |
int | nParticles |
int | ntpl_id |
std::map< HepMC::GenParticle *, int > | particle_to_index |
Static Private Attributes | |
static Ntuple2HepMCFiller * | instance_ = 0 |
Fills information from a converted cmkin ntpl into an HepMC event; The "h2root" converted ntpl is read by the class NtupleROOTFile Joanna Weng 1/2006
Definition at line 19 of file Ntuple2HepMCFiller.h.
Ntuple2HepMCFiller::Ntuple2HepMCFiller | ( | ) | [protected] |
Constructor.
Definition at line 23 of file Ntuple2HepMCFiller.cc.
References gather_cfg::cout, and instance_.
: initialized_(false), input_(0), index_to_particle(3996),evtid(1),ntpl_id(1) { cout << "Constructing a new Ntuple2HepMCFiller" << endl; if(instance_ == 0) instance_ = this; }
Ntuple2HepMCFiller::~Ntuple2HepMCFiller | ( | ) | [virtual] |
Destructor.
Definition at line 31 of file Ntuple2HepMCFiller.cc.
References gather_cfg::cout, input_, and instance_.
void Ntuple2HepMCFiller::buildProductionVertex | ( | int | i, |
std::vector< HepMC::GenParticle * > & | hepevt_particle, | ||
HepMC::GenEvent * | evt, | ||
bool | printInconsistencyErrors | ||
) | [private] |
Definition at line 159 of file Ntuple2HepMCFiller.cc.
References benchmark_cfg::cerr, configurableAnalysis::GenParticle, NtupleROOTFile::getJmohep(), NtupleROOTFile::getNevhep(), NtupleROOTFile::getVhep(), i, input_, number_parents(), and L1TEmulatorMonitor_cff::p.
Referenced by toGenEvent().
{ // // for particle in HEPEVT with index i, build a production vertex // if appropriate, and add that vertex to the event HepMC::GenParticle* p = hepevt_particle[i]; // a. search to see if a production vertex already exists int mother = input_->getJmohep(i,0); // this is dangerous. Copying null pointer and attempting to fill // information in prod_vtx...... HepMC::GenVertex* prod_vtx = p->production_vertex(); // no production vertex and mother exist -> produce vertex while ( !prod_vtx && mother > 0 ) { prod_vtx = hepevt_particle[mother]->end_vertex(); if ( prod_vtx ) prod_vtx->add_particle_out( p ); // increment mother for next iteration if ( ++mother > input_->getJmohep(i,1) ) mother = 0; } // b. if no suitable production vertex exists - and the particle // has atleast one mother or position information to store - // make one@@@ FourVector prod_pos( input_->getVhep(i,0), input_->getVhep(i,1), input_->getVhep(i,2), input_->getVhep(i,3)); // orginal: if ( !prod_vtx && (number_parents(i)>0 || prod_pos!=FourVector(0,0,0,0) )){ prod_vtx = new HepMC::GenVertex(); prod_vtx->add_particle_out( p ); evt->add_vertex( prod_vtx ); } // c. if prod_vtx doesn't already have position specified, fill it if ( prod_vtx && prod_vtx->position()==FourVector(0,0,0,0) ) { prod_vtx->set_position( prod_pos ); } // d. loop over mothers to make sure their end_vertices are // consistent mother = input_->getJmohep(i,0); while ( prod_vtx && mother > 0 ) { if ( !hepevt_particle[mother]->end_vertex() ) { // if end vertex of the mother isn't specified, do it now prod_vtx->add_particle_in( hepevt_particle[mother] ); } else if (hepevt_particle[mother]->end_vertex() != prod_vtx ) { // problem scenario --- the mother already has a decay // vertex which differs from the daughter's produciton // vertex. This means there is internal // inconsistency in the HEPEVT event record. Print an // error // Note: we could provide a fix by joining the two // vertices with a dummy particle if the problem // arrises often with any particular generator. if ( printInconsistencyErrors ) std::cerr << "Ntuple2HepMCFiller:: inconsistent mother/daughter " << "information in HEPEVT event " << input_->getNevhep() << std::endl; } if ( ++mother > input_->getJmohep(i,1) ) mother = 0; } }
HepMC::GenParticle * Ntuple2HepMCFiller::createParticle | ( | int | index | ) |
Definition at line 143 of file Ntuple2HepMCFiller.cc.
References configurableAnalysis::GenParticle, NtupleROOTFile::getIdhep(), NtupleROOTFile::getIsthep(), NtupleROOTFile::getPhep(), input_, and L1TEmulatorMonitor_cff::p.
Referenced by toGenEvent().
{ // Builds a particle object corresponding to index in HEPEVT HepMC::GenParticle* p = new HepMC::GenParticle(FourVector( input_->getPhep(index,0), input_->getPhep(index,1), input_->getPhep(index,2), input_->getPhep(index,3)), input_->getIdhep(index), input_->getIsthep(index)); p->setGeneratedMass( input_->getPhep(index, 4) ); p->suggest_barcode( index ); return p; }
HepMC::GenEvent * Ntuple2HepMCFiller::fillCurrentEventData | ( | ) |
Definition at line 102 of file Ntuple2HepMCFiller.cc.
References evt, NULL, and readCurrentEvent().
Referenced by edm::H2RootNtplSource::produce().
{ if (readCurrentEvent())return evt; else return NULL; }
int Ntuple2HepMCFiller::find_in_map | ( | const std::map< HepMC::GenParticle *, int > & | m, |
HepMC::GenParticle * | p | ||
) | const [private] |
virtual void Ntuple2HepMCFiller::initialize | ( | const std::string & | filename, |
int | id | ||
) | [virtual] |
Referenced by edm::H2RootNtplSource::H2RootNtplSource().
Ntuple2HepMCFiller * Ntuple2HepMCFiller::instance | ( | ) | [static] |
Definition at line 14 of file Ntuple2HepMCFiller.cc.
{ if (instance_== 0) { instance_ = new Ntuple2HepMCFiller(); } return instance_; }
bool Ntuple2HepMCFiller::isInitialized | ( | ) |
Definition at line 60 of file Ntuple2HepMCFiller.cc.
References initialized_.
{ return initialized_; }
int Ntuple2HepMCFiller::number_children | ( | int | index | ) | [private] |
Definition at line 223 of file Ntuple2HepMCFiller.cc.
References NtupleROOTFile::getJdahep(), and input_.
int Ntuple2HepMCFiller::number_parents | ( | int | index | ) | [private] |
Definition at line 231 of file Ntuple2HepMCFiller.cc.
References NtupleROOTFile::getJmohep(), NtupleROOTFile::getNhep(), and input_.
Referenced by buildProductionVertex().
{ // Fix for cmkin single particle ntpls if (input_->getNhep()==1) return 1; // Fix for cmkindouble particle ntpls if (input_->getNhep()==2) return 1; int firstparent = input_->getJmohep(index,0); if( firstparent <= 0 ) return 0; int secondparent = input_->getJmohep(index,1); if( secondparent <= 0 ) return 1; return secondparent - firstparent + 1; }
bool Ntuple2HepMCFiller::printHepMcEvent | ( | ) | const [virtual] |
Definition at line 96 of file Ntuple2HepMCFiller.cc.
References evt.
bool Ntuple2HepMCFiller::readCurrentEvent | ( | ) | [virtual] |
Definition at line 66 of file Ntuple2HepMCFiller.cc.
References gather_cfg::cout, event(), evt, evtid, align_tpl::filter, NtupleROOTFile::getNevhep(), input_, NtupleROOTFile::setEvent(), and toGenEvent().
Referenced by fillCurrentEventData().
{ bool filter=false; // 1. create an empty event container HepMC::GenEvent* event = new HepMC::GenEvent(); input_ ->setEvent(evtid); // 2. fill the evt container - if the read is successful, set the pointer if ( this->toGenEvent( evtid, event ) ) evt=event; if (evt){ cout <<"| --- Ntuple2HepMCFiller: Event Nr. " <<evt->event_number() <<" with " <<evt->particles_size()<<" particles --- !" <<endl; // printHepMcEvent(); filter=true; } if (!evt) { cout << "Ntuple2HepMCFiller: Got no event :-(" <<endl; filter=false; delete evt; // @@@ } if (evtid > input_->getNevhep()) filter = false; evtid++; return filter; }
bool Ntuple2HepMCFiller::setEvent | ( | unsigned int | event | ) | [virtual] |
Definition at line 89 of file Ntuple2HepMCFiller.cc.
References event(), and evtid.
Referenced by edm::H2RootNtplSource::H2RootNtplSource().
void Ntuple2HepMCFiller::setInitialized | ( | bool | value | ) | [protected] |
Definition at line 40 of file Ntuple2HepMCFiller.cc.
References initialized_, and relativeConstraints::value.
bool Ntuple2HepMCFiller::toGenEvent | ( | int | evtnum, |
HepMC::GenEvent * | evt | ||
) | [virtual] |
sufficient to do one OR the other
Definition at line 110 of file Ntuple2HepMCFiller.cc.
References buildProductionVertex(), createParticle(), NtupleROOTFile::getNhep(), i, and input_.
Referenced by readCurrentEvent().
{ // Written according to HepMC /fio/ IO_HEPEVT.cc( hepmc-01-26 tag at Savannah) // 1. set event number // evt->set_event_number( input_->getNevhep()); evt->set_event_number( evtnum ) ; // these do not have the correct defaults if hepev4 is not filled //evt->set_event_scale( hepev4()->scalelh[1] ); //evt->set_alphaQCD( hepev4()->alphaqcdlh ); //evt->set_alphaQED( hepev4()->alphaqedlh ); std::vector<HepMC::GenParticle*> hepevt_particle(input_->getNhep()+1 ); //2. create a particle instance for each HEPEVT entry and fill a map // create a vector which maps from the HEPEVT particle index to the // GenParticle address // (+1 in size accounts for hepevt_particle[0] which is unfilled) hepevt_particle[0] = 0; for ( int i1 = 1; i1 <= input_->getNhep(); ++i1 ) { hepevt_particle[i1] = createParticle(i1); } std::set<HepMC::GenVertex*> new_vertices; // 3.+4. loop over HEPEVT particles AGAIN, this time creating vertices for ( int i = 1; i <= input_->getNhep(); ++i ) { // We go through and build EITHER the production or decay // vertex for each entry in hepevt // Note: since the HEPEVT pointers are bi-directional, it is buildProductionVertex( i, hepevt_particle, evt, 1 ); } // hepevt_particle.clear(); return true; }
HepMC::GenEvent* Ntuple2HepMCFiller::evt [private] |
Definition at line 44 of file Ntuple2HepMCFiller.h.
Referenced by fillCurrentEventData(), printHepMcEvent(), and readCurrentEvent().
int Ntuple2HepMCFiller::evtid [private] |
Definition at line 54 of file Ntuple2HepMCFiller.h.
Referenced by readCurrentEvent(), and setEvent().
std::vector<HepMC::GenParticle*> Ntuple2HepMCFiller::index_to_particle [private] |
Definition at line 52 of file Ntuple2HepMCFiller.h.
bool Ntuple2HepMCFiller::initialized_ [private] |
Definition at line 45 of file Ntuple2HepMCFiller.h.
Referenced by isInitialized(), and setInitialized().
NtupleROOTFile* Ntuple2HepMCFiller::input_ [private] |
Definition at line 46 of file Ntuple2HepMCFiller.h.
Referenced by buildProductionVertex(), createParticle(), number_children(), number_parents(), readCurrentEvent(), toGenEvent(), and ~Ntuple2HepMCFiller().
Ntuple2HepMCFiller * Ntuple2HepMCFiller::instance_ = 0 [static, private] |
Definition at line 42 of file Ntuple2HepMCFiller.h.
Referenced by Ntuple2HepMCFiller(), and ~Ntuple2HepMCFiller().
int Ntuple2HepMCFiller::nParticles [private] |
Definition at line 49 of file Ntuple2HepMCFiller.h.
int Ntuple2HepMCFiller::ntpl_id [private] |
Definition at line 55 of file Ntuple2HepMCFiller.h.
std::map<HepMC::GenParticle *,int> Ntuple2HepMCFiller::particle_to_index [private] |
Definition at line 53 of file Ntuple2HepMCFiller.h.