CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
Ntuple2HepMCFiller Class Reference

#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. More...
 

Static Public Member Functions

static Ntuple2HepMCFillerinstance ()
 

Protected Member Functions

 Ntuple2HepMCFiller ()
 Constructor. More...
 
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_
 
NtupleROOTFileinput_
 
int nParticles
 
int ntpl_id
 
std::map< HepMC::GenParticle
*, int > 
particle_to_index
 

Static Private Attributes

static Ntuple2HepMCFillerinstance_ =0
 

Detailed Description

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.

Constructor & Destructor Documentation

Ntuple2HepMCFiller::Ntuple2HepMCFiller ( )
protected

Constructor.

Definition at line 23 of file Ntuple2HepMCFiller.cc.

References gather_cfg::cout, and instance_.

23  :
24  initialized_(false), input_(0),
25  index_to_particle(3996),evtid(1),ntpl_id(1) {
26  cout << "Constructing a new Ntuple2HepMCFiller" << endl;
27  if(instance_ == 0) instance_ = this;
28 }
NtupleROOTFile * input_
static Ntuple2HepMCFiller * instance_
tuple cout
Definition: gather_cfg.py:41
std::vector< HepMC::GenParticle * > index_to_particle
Ntuple2HepMCFiller::~Ntuple2HepMCFiller ( )
virtual

Destructor.

Definition at line 31 of file Ntuple2HepMCFiller.cc.

References gather_cfg::cout, input_, and instance_.

31  {
32  cout << "Destructing Ntuple2HepMCFiller" << endl;
33  if(input_) {
34  delete input_;
35  }
36  instance_=0;
37 }
NtupleROOTFile * input_
static Ntuple2HepMCFiller * instance_
tuple cout
Definition: gather_cfg.py:41

Member Function Documentation

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().

162 {
163  //
164  // for particle in HEPEVT with index i, build a production vertex
165  // if appropriate, and add that vertex to the event
166  HepMC::GenParticle* p = hepevt_particle[i];
167  // a. search to see if a production vertex already exists
168  int mother = input_->getJmohep(i,0);
169  // this is dangerous. Copying null pointer and attempting to fill
170  // information in prod_vtx......
171  HepMC::GenVertex* prod_vtx = p->production_vertex();
172  // no production vertex and mother exist -> produce vertex
173  while ( !prod_vtx && mother > 0 ) {
174  prod_vtx = hepevt_particle[mother]->end_vertex();
175  if ( prod_vtx ) prod_vtx->add_particle_out( p );
176  // increment mother for next iteration
177  if ( ++mother > input_->getJmohep(i,1) ) mother = 0;
178  }
179  // b. if no suitable production vertex exists - and the particle
180  // has atleast one mother or position information to store -
181  // make one@@@
182  FourVector prod_pos( input_->getVhep(i,0), input_->getVhep(i,1),
183  input_->getVhep(i,2), input_->getVhep(i,3));
184  // orginal:
185  if ( !prod_vtx && (number_parents(i)>0 || prod_pos!=FourVector(0,0,0,0) )){
186  prod_vtx = new HepMC::GenVertex();
187  prod_vtx->add_particle_out( p );
188  evt->add_vertex( prod_vtx );
189  }
190  // c. if prod_vtx doesn't already have position specified, fill it
191  if ( prod_vtx && prod_vtx->position()==FourVector(0,0,0,0) ) {
192  prod_vtx->set_position( prod_pos );
193  }
194  // d. loop over mothers to make sure their end_vertices are
195  // consistent
196  mother = input_->getJmohep(i,0);
197  while ( prod_vtx && mother > 0 ) {
198  if ( !hepevt_particle[mother]->end_vertex() ) {
199  // if end vertex of the mother isn't specified, do it now
200  prod_vtx->add_particle_in( hepevt_particle[mother] );
201  }
202  else if (hepevt_particle[mother]->end_vertex() != prod_vtx ) {
203  // problem scenario --- the mother already has a decay
204  // vertex which differs from the daughter's produciton
205  // vertex. This means there is internal
206  // inconsistency in the HEPEVT event record. Print an
207  // error
208  // Note: we could provide a fix by joining the two
209  // vertices with a dummy particle if the problem
210  // arrises often with any particular generator.
211  if ( printInconsistencyErrors ) std::cerr
212  << "Ntuple2HepMCFiller:: inconsistent mother/daughter "
213  << "information in HEPEVT event "
214  << input_->getNevhep()
215  << std::endl;
216  }
217  if ( ++mother > input_->getJmohep(i,1) ) mother = 0;
218  }
219 }
NtupleROOTFile * input_
int i
Definition: DBlmapReader.cc:9
virtual int getNevhep() const
HepMC::GenEvent * evt
virtual double getVhep(int j, int idx) const
int number_parents(int index)
virtual int getJmohep(int j, int idx) const
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().

143  {
144 
145  // Builds a particle object corresponding to index in HEPEVT
147  = new HepMC::GenParticle(FourVector( input_->getPhep(index,0),
148  input_->getPhep(index,1),
149  input_->getPhep(index,2),
150  input_->getPhep(index,3)),
151  input_->getIdhep(index),
153  p->setGeneratedMass( input_->getPhep(index, 4) );
154  p->suggest_barcode( index );
155  return p;
156 }
NtupleROOTFile * input_
virtual int getIsthep(int j) const
virtual int getIdhep(int j) const
virtual double getPhep(int j, int idx) const
HepMC::GenEvent * Ntuple2HepMCFiller::fillCurrentEventData ( )

Definition at line 102 of file Ntuple2HepMCFiller.cc.

References evt, NULL, and readCurrentEvent().

Referenced by edm::H2RootNtplSource::produce().

102  {
103  if (readCurrentEvent())return evt;
104  else return NULL;
105 
106 }
HepMC::GenEvent * evt
virtual bool readCurrentEvent()
#define NULL
Definition: scimark2.h:8
int Ntuple2HepMCFiller::find_in_map ( const std::map< HepMC::GenParticle *, int > &  m,
HepMC::GenParticle *  p 
) const
private
void Ntuple2HepMCFiller::initialize ( const std::string &  filename,
int  id 
)
virtual

Definition at line 43 of file Ntuple2HepMCFiller.cc.

References gather_cfg::cout, initialized_, input_, and ntpl_id.

Referenced by edm::H2RootNtplSource::H2RootNtplSource().

43  {
44 
45  if (initialized_) {
46  cout << "Ntuple2HepMCFiller was already initialized... reinitializing it " << endl;
47  if(input_) {
48  delete input_;
49  }
50  }
51 
52  cout<<"Ntuple2HepMCFiller::initialize : Opening file "<<filename<<endl;
53  ntpl_id=id;
54  input_ = new NtupleROOTFile( filename, id);
55  initialized_ = true;
56 }
NtupleROOTFile * input_
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:41
Ntuple2HepMCFiller * Ntuple2HepMCFiller::instance ( )
static

Definition at line 14 of file Ntuple2HepMCFiller.cc.

14  {
15 
16  if (instance_== 0) {
18  }
19  return instance_;
20 }
Ntuple2HepMCFiller()
Constructor.
static Ntuple2HepMCFiller * instance_
bool Ntuple2HepMCFiller::isInitialized ( )

Definition at line 60 of file Ntuple2HepMCFiller.cc.

References initialized_.

60  {
61 
62  return initialized_;
63 }
int Ntuple2HepMCFiller::number_children ( int  index)
private

Definition at line 223 of file Ntuple2HepMCFiller.cc.

References NtupleROOTFile::getJdahep(), and input_.

224 {
225  int firstchild = input_->getJdahep(index,0);
226  return ( firstchild>0 ) ?
227  ( 1+input_->getJdahep(index,1)-firstchild ) : 0;
228 }
NtupleROOTFile * input_
virtual int getJdahep(int j, int idx) const
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().

231  {
232 
233  // Fix for cmkin single particle ntpls
234  if (input_->getNhep()==1) return 1;
235  // Fix for cmkindouble particle ntpls
236  if (input_->getNhep()==2) return 1;
237  int firstparent = input_->getJmohep(index,0);
238  if( firstparent <= 0 ) return 0;
239  int secondparent = input_->getJmohep(index,1);
240  if( secondparent <= 0 ) return 1;
241  return secondparent - firstparent + 1;
242 
243 }
NtupleROOTFile * input_
virtual int getNhep() const
virtual int getJmohep(int j, int idx) const
bool Ntuple2HepMCFiller::printHepMcEvent ( ) const
virtual

Definition at line 96 of file Ntuple2HepMCFiller.cc.

References evt.

96  {
97  if (evt!=0) evt->print();
98  return true;
99 }
HepMC::GenEvent * 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().

66  {
67  bool filter=false;
68  // 1. create an empty event container
69  HepMC::GenEvent* event = new HepMC::GenEvent();
71  // 2. fill the evt container - if the read is successful, set the pointer
72  if ( this->toGenEvent( evtid, event ) ) evt=event;
73  if (evt){
74  cout <<"| --- Ntuple2HepMCFiller: Event Nr. " <<evt->event_number() <<" with " <<evt->particles_size()<<" particles --- !" <<endl;
75  // printHepMcEvent();
76  filter=true;
77  }
78  if (!evt) {
79  cout << "Ntuple2HepMCFiller: Got no event :-(" <<endl;
80  filter=false;
81  delete evt; // @@@
82  }
83  if (evtid > input_->getNevhep()) filter = false;
84  evtid++;
85  return filter;
86 }
NtupleROOTFile * input_
virtual int getNevhep() const
HepMC::GenEvent * evt
virtual bool toGenEvent(int evtnum, HepMC::GenEvent *evt)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual void setEvent(int event) const
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86
tuple cout
Definition: gather_cfg.py:41
bool Ntuple2HepMCFiller::setEvent ( unsigned int  event)
virtual

Definition at line 89 of file Ntuple2HepMCFiller.cc.

References event(), and evtid.

Referenced by edm::H2RootNtplSource::H2RootNtplSource().

89  {
90  evtid= event;
91  return true;
92 }
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void Ntuple2HepMCFiller::setInitialized ( bool  value)
protected
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().

110  {
111  // Written according to HepMC /fio/ IO_HEPEVT.cc( hepmc-01-26 tag at Savannah)
112  // 1. set event number
113  // evt->set_event_number( input_->getNevhep());
114  evt->set_event_number( evtnum ) ;
115  // these do not have the correct defaults if hepev4 is not filled
116  //evt->set_event_scale( hepev4()->scalelh[1] );
117  //evt->set_alphaQCD( hepev4()->alphaqcdlh );
118  //evt->set_alphaQED( hepev4()->alphaqedlh );
119  std::vector<HepMC::GenParticle*> hepevt_particle(input_->getNhep()+1 );
120  //2. create a particle instance for each HEPEVT entry and fill a map
121  // create a vector which maps from the HEPEVT particle index to the
122  // GenParticle address
123  // (+1 in size accounts for hepevt_particle[0] which is unfilled)
124  hepevt_particle[0] = 0;
125  for ( int i1 = 1; i1 <= input_->getNhep(); ++i1 ) {
126  hepevt_particle[i1] = createParticle(i1);
127  }
128  std::set<HepMC::GenVertex*> new_vertices;
129 
130  // 3.+4. loop over HEPEVT particles AGAIN, this time creating vertices
131  for ( int i = 1; i <= input_->getNhep(); ++i ) {
132  // We go through and build EITHER the production or decay
133  // vertex for each entry in hepevt
134  // Note: since the HEPEVT pointers are bi-directional, it is
136  buildProductionVertex( i, hepevt_particle, evt, 1 );
137  }
138  // hepevt_particle.clear();
139  return true;
140 }
NtupleROOTFile * input_
int i
Definition: DBlmapReader.cc:9
HepMC::GenEvent * evt
void buildProductionVertex(int i, std::vector< HepMC::GenParticle * > &hepevt_particle, HepMC::GenEvent *evt, bool printInconsistencyErrors)
HepMC::GenParticle * createParticle(int index)
virtual int getNhep() const

Member Data Documentation

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 initialize(), isInitialized(), and setInitialized().

NtupleROOTFile* Ntuple2HepMCFiller::input_
private
Ntuple2HepMCFiller * Ntuple2HepMCFiller::instance_ =0
staticprivate

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.

Referenced by initialize().

std::map<HepMC::GenParticle *,int> Ntuple2HepMCFiller::particle_to_index
private

Definition at line 53 of file Ntuple2HepMCFiller.h.