CMS 3D CMS Logo

HepMCFileReader Class Reference

This class is used by the implementation of DaqEventFactory present in this package to read in the full event raw data from a flat binary file. More...

#include <IOMC/Input/interface/HepMCFileReader.h>

List of all members.

Public Member Functions

HepMC::GenEvent * fillCurrentEventData ()
virtual void getStatsFromTuple (int &mo1, int &mo2, int &da1, int &da2, int &status, int &pid, int j) const
virtual void initialize (const std::string &filename, bool useExtendedAscii)
bool isInitialized () const
void printEvent () const
virtual bool printHepMcEvent () const
virtual bool readCurrentEvent ()
virtual void ReadStats ()
virtual bool setEvent (int event)
virtual ~HepMCFileReader ()

Static Public Member Functions

static HepMCFileReaderinstance ()

Protected Member Functions

 HepMCFileReader ()

Private Member Functions

int find_in_map (const std::map< HepMC::GenParticle *, int > &m, HepMC::GenParticle *p) const
int rdstate () const

Private Attributes

HepMC::GenEvent * evt_
std::vector< HepMC::GenParticle * > index_to_particle
HepMC::IO_BaseClass * input_
std::map< HepMC::GenParticle *,
int
particle_to_index

Static Private Attributes

static HepMCFileReaderinstance_ = 0


Detailed Description

This class is used by the implementation of DaqEventFactory present in this package to read in the full event raw data from a flat binary file.

WARNING: If you want to use this class for other purposes you must always invoke the method initialize before starting using the interface it exposes.

Date
2007/05/29 21:00:22
Revision
1.3
Author:
G. Bruno - CERN, EP Division

Definition at line 31 of file HepMCFileReader.h.


Constructor & Destructor Documentation

HepMCFileReader::HepMCFileReader (  )  [protected]

Definition at line 46 of file HepMCFileReader.cc.

References instance_.

Referenced by instance().

00046                                  :
00047   evt_(0), input_(0)
00048 { 
00049   // Default constructor.
00050   if (instance_ == 0) {
00051     instance_ = this;  
00052   } else {
00053     edm::LogError("HepMCFileReader") << "Constructing a new instance";
00054   }
00055 } 

HepMCFileReader::~HepMCFileReader (  )  [virtual]

Definition at line 59 of file HepMCFileReader.cc.

References input_, and instance_.

00060 {
00061   edm::LogInfo("HepMCFileReader") << "Destructing HepMCFileReader";
00062   
00063   instance_=0;    
00064   delete input_;
00065 }


Member Function Documentation

HepMC::GenEvent * HepMCFileReader::fillCurrentEventData (  ) 

Definition at line 140 of file HepMCFileReader.cc.

References evt_, and readCurrentEvent().

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

00141 {
00142   readCurrentEvent();
00143   return evt_;
00144 }

int HepMCFileReader::find_in_map ( const std::map< HepMC::GenParticle *, int > &  m,
HepMC::GenParticle *  p 
) const [private]

Definition at line 298 of file HepMCFileReader.cc.

References iter.

Referenced by getStatsFromTuple().

00300 {
00301   std::map<HepMC::GenParticle*,int>::const_iterator iter = m.find(p);
00302   return (iter == m.end()) ? 0 : iter->second;
00303 }

void HepMCFileReader::getStatsFromTuple ( int mo1,
int mo2,
int da1,
int da2,
int status,
int pid,
int  j 
) const [virtual]

Definition at line 247 of file HepMCFileReader.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), evt_, find_in_map(), index_to_particle, and particle_to_index.

Referenced by printEvent().

00249 {
00250   if (!evt_) {
00251     cout <<  "HepMCFileReader: Got no event :-(  Game over already  ?" <<endl; 
00252   } else {
00253     status =  index_to_particle[j]->status();
00254     pid = index_to_particle[j]->pdg_id();
00255     if ( index_to_particle[j]->production_vertex() ) {
00256       
00257           //HepLorentzVector p = index_to_particle[j]->
00258           //production_vertex()->position();
00259       
00260       int num_mothers = index_to_particle[j]->production_vertex()->
00261       particles_in_size();
00262       int first_mother = find_in_map( particle_to_index,
00263       *(index_to_particle[j]->
00264       production_vertex()->
00265       particles_in_const_begin()));
00266       int last_mother = first_mother + num_mothers - 1;
00267       if ( first_mother == 0 ) last_mother = 0;
00268       mo1=first_mother;
00269       mo2=last_mother;
00270     } else {
00271       mo1 =0;
00272       mo2 =0;
00273     }   
00274     if (!index_to_particle[j]->end_vertex()) {
00275       //find # of 1. daughter
00276       int first_daughter = find_in_map( particle_to_index,
00277       *(index_to_particle[j]->end_vertex()->particles_begin(HepMC::children)));
00278       //cout <<"first_daughter "<< first_daughter <<  "num_daughters " << num_daughters << endl; 
00279       HepMC::GenVertex::particle_iterator ic;
00280       int last_daughter=0;
00281       //find # of last daughter
00282       for (ic = index_to_particle[j]->end_vertex()->particles_begin(HepMC::children);
00283       ic != index_to_particle[j]->end_vertex()->particles_end(HepMC::children); ++ic) 
00284       last_daughter= find_in_map( particle_to_index,*ic);       
00285       
00286       if (first_daughter== 0) last_daughter = 0;
00287       da1=first_daughter;
00288       da2=last_daughter;
00289     } else {
00290       da1=0;
00291       da2=0;
00292     }
00293   } 
00294 } 

virtual void HepMCFileReader::initialize ( const std::string &  filename,
bool  useExtendedAscii 
) [virtual]

Referenced by edm::MCFileSource::MCFileSource().

HepMCFileReader * HepMCFileReader::instance ( void   )  [static]

Definition at line 34 of file HepMCFileReader.cc.

References HepMCFileReader(), and instance_.

00035 {
00036   // Implement a HepMCFileReader singleton.
00037 
00038   if (instance_== 0) {
00039     instance_ = new HepMCFileReader();
00040   }
00041   return instance_;
00042 }

bool HepMCFileReader::isInitialized (  )  const [inline]

Definition at line 76 of file HepMCFileReader.h.

References input_.

00077 {
00078   return input_ != 0;
00079 }

void HepMCFileReader::printEvent (  )  const

Definition at line 149 of file HepMCFileReader.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), evt_, g, getStatsFromTuple(), index_to_particle, mo1, mo2, n, funct::sqrt(), and StDecayID::status.

00149                                        {
00150   int mo1=0,mo2=0,da1=0,da2=0,status=0,pid=0;   
00151   if (evt_ != 0) {   
00152     cout << "---#-------pid--st---Mo1---Mo2---Da1---Da2------px------py------pz-------E-";
00153     cout << "------m---------x---------y---------z---------t-";
00154     cout << endl;
00155     cout.setf(ios::right, ios::adjustfield);
00156     for(int n=1; n<=evt_->particles_size(); n++) {  
00157       HepMC::GenParticle *g = index_to_particle[n];  
00158       getStatsFromTuple( mo1,mo2,da1,da2,status,pid,n);
00159       cout << setw(4) << n
00160       << setw(8) << pid
00161       << setw(5) << status
00162       << setw(6) << mo1    
00163       << setw(6) << mo2
00164       << setw(6) << da1
00165       << setw(6) << da2;
00166       cout.setf(ios::fixed, ios::floatfield);
00167       cout.setf(ios::right, ios::adjustfield);
00168       cout << setw(10) << setprecision(2) << g->momentum().x();
00169       cout << setw(8) << setprecision(2) << g->momentum().y();
00170       cout << setw(10) << setprecision(2) << g->momentum().z();
00171       cout << setw(8) << setprecision(2) << g->momentum().t();
00172       cout << setw(8) << setprecision(2) << g->generatedMass();       
00173       // tau=L/(gamma*beta*c) 
00174       if (g->production_vertex() != 0 && g->end_vertex() != 0 && status == 2) {
00175         cout << setw(10) << setprecision(2) <<g->production_vertex()->position().x();
00176         cout << setw(10) << setprecision(2) <<g->production_vertex()->position().y();
00177         cout << setw(10) << setprecision(2) <<g->production_vertex()->position().z();
00178         
00179         double xm = g->production_vertex()->position().x();
00180         double ym = g->production_vertex()->position().y();
00181         double zm = g->production_vertex()->position().z();
00182         double xd = g->end_vertex()->position().x();
00183         double yd = g->end_vertex()->position().y();
00184         double zd = g->end_vertex()->position().z();
00185         double decl = sqrt((xd-xm)*(xd-xm)+(yd-ym)*(yd-ym)+(zd-zm)*(zd-zm));
00186         double labTime = decl/c_light;
00187         // convert lab time to proper time
00188         double properTime =  labTime/g->momentum().rho()*(g->generatedMass() );
00189         // set the proper time in nanoseconds
00190         cout << setw(8) << setprecision(2) <<properTime;
00191       }
00192       else{
00193         cout << setw(10) << setprecision(2) << 0.0;
00194         cout << setw(10) << setprecision(2) << 0.0;
00195         cout << setw(10) << setprecision(2) << 0.0;
00196         cout << setw(8) << setprecision(2) << 0.0;  
00197       }
00198       cout << endl; 
00199     }
00200   } else {
00201     cout << " HepMCFileReader: No event available !" << endl;
00202   }
00203 }

bool HepMCFileReader::printHepMcEvent (  )  const [virtual]

Definition at line 132 of file HepMCFileReader.cc.

References evt_.

00133 {
00134   if (evt_ != 0) evt_->print(); 
00135   return true;
00136 }

int HepMCFileReader::rdstate (  )  const [private]

Definition at line 92 of file HepMCFileReader.cc.

References e, input_, and p.

00093 {
00094   // work around a HepMC IO_ inheritence shortfall
00095 
00096   HepMC::IO_ExtendedAscii *e = dynamic_cast<HepMC::IO_ExtendedAscii*>(input_);
00097   if (e) return e->rdstate();
00098 
00099   HepMC::IO_Ascii *p = dynamic_cast<HepMC::IO_Ascii*>(input_);
00100   if (p) return p->rdstate();
00101 
00102   return std::ios::failbit;
00103 }

bool HepMCFileReader::readCurrentEvent (  )  [virtual]

Definition at line 107 of file HepMCFileReader.cc.

References lat::endl(), evt_, input_, and ReadStats().

Referenced by fillCurrentEventData().

00108 {
00109   evt_ = input_->read_next_event();
00110   if (evt_) { 
00111     edm::LogInfo("HepMCFileReader") << "| --- Event Nr. "  << evt_->event_number()
00112          << " with " << evt_->particles_size() << " particles --- !";  
00113     ReadStats();
00114     //  printHepMcEvent();
00115     //          printEvent();
00116   } else {
00117     edm::LogInfo("HepMCFileReader") << "Got no event" <<endl;
00118   }
00119 
00120   return evt_ != 0;
00121 }

void HepMCFileReader::ReadStats (  )  [virtual]

Definition at line 207 of file HepMCFileReader.cc.

References evt_, index_to_particle, p1, p2, particle_to_index, and v.

Referenced by readCurrentEvent().

00208 {
00209   unsigned int particle_counter=0;
00210   index_to_particle.reserve(evt_->particles_size()+1); 
00211   index_to_particle[0] = 0; 
00212   for (HepMC::GenEvent::vertex_const_iterator v = evt_->vertices_begin();
00213        v != evt_->vertices_end(); ++v ) {
00214     // making a list of incoming particles of the vertices
00215     // so that the mother indices in HEPEVT can be filled properly
00216     for (HepMC::GenVertex::particles_in_const_iterator p1 = (*v)->particles_in_const_begin();
00217          p1 != (*v)->particles_in_const_end(); ++p1 ) {
00218       ++particle_counter;
00219       //particle_counter can be very large for heavy ions
00220       if(particle_counter >= index_to_particle.size() ) {
00221         //make it large enough to hold up to this index
00222          index_to_particle.resize(particle_counter+1);
00223       }                 
00224       index_to_particle[particle_counter] = *p1;
00225       particle_to_index[*p1] = particle_counter;
00226     }   
00227     // daughters are entered only if they aren't a mother of
00228     // another vertex
00229     for (HepMC::GenVertex::particles_out_const_iterator p2 = (*v)->particles_out_const_begin();
00230          p2 != (*v)->particles_out_const_end(); ++p2) {
00231       if (!(*p2)->end_vertex()) {
00232         ++particle_counter;
00233         //particle_counter can be very large for heavy ions
00234         if(particle_counter  >= index_to_particle.size() ) {        
00235           //make it large enough to hold up to this index
00236           index_to_particle.resize(particle_counter+1);
00237         }                   
00238         index_to_particle[particle_counter] = *p2;
00239         particle_to_index[*p2] = particle_counter;
00240       }
00241     }
00242   } 
00243 }

bool HepMCFileReader::setEvent ( int  event  )  [virtual]

Definition at line 125 of file HepMCFileReader.cc.

00126 {
00127   return true;
00128 }


Member Data Documentation

HepMC::GenEvent* HepMCFileReader::evt_ [private]

Definition at line 60 of file HepMCFileReader.h.

Referenced by fillCurrentEventData(), getStatsFromTuple(), printEvent(), printHepMcEvent(), readCurrentEvent(), and ReadStats().

std::vector<HepMC::GenParticle*> HepMCFileReader::index_to_particle [private]

Definition at line 68 of file HepMCFileReader.h.

Referenced by getStatsFromTuple(), printEvent(), and ReadStats().

HepMC::IO_BaseClass* HepMCFileReader::input_ [private]

Definition at line 61 of file HepMCFileReader.h.

Referenced by isInitialized(), rdstate(), readCurrentEvent(), and ~HepMCFileReader().

HepMCFileReader * HepMCFileReader::instance_ = 0 [static, private]

Definition at line 63 of file HepMCFileReader.h.

Referenced by HepMCFileReader(), instance(), and ~HepMCFileReader().

std::map<HepMC::GenParticle*,int> HepMCFileReader::particle_to_index [private]

Definition at line 69 of file HepMCFileReader.h.

Referenced by getStatsFromTuple(), and ReadStats().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:24:10 2009 for CMSSW by  doxygen 1.5.4