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
HepMCFileReader Class Reference

#include <HepMCFileReader.h>

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 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:
2009/12/01 19:23:11
Revision:
1.5
Author
G. Bruno - CERN, EP Division

Definition at line 31 of file HepMCFileReader.h.

Constructor & Destructor Documentation

HepMCFileReader::HepMCFileReader ( )
protected

Definition at line 45 of file HepMCFileReader.cc.

References instance_.

45  :
46  evt_(0), input_(0)
47 {
48  // Default constructor.
49  if (instance_ == 0) {
50  instance_ = this;
51  } else {
52  edm::LogError("HepMCFileReader") << "Constructing a new instance";
53  }
54 }
static HepMCFileReader * instance_
HepMC::IO_BaseClass * input_
HepMC::GenEvent * evt_
HepMCFileReader::~HepMCFileReader ( )
virtual

Definition at line 58 of file HepMCFileReader.cc.

References input_, and instance_.

59 {
60  edm::LogInfo("HepMCFileReader") << "Destructing HepMCFileReader";
61 
62  instance_=0;
63  delete input_;
64 }
static HepMCFileReader * instance_
HepMC::IO_BaseClass * input_

Member Function Documentation

HepMC::GenEvent * HepMCFileReader::fillCurrentEventData ( )

Definition at line 131 of file HepMCFileReader.cc.

References evt_, and readCurrentEvent().

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

132 {
134  return evt_;
135 }
virtual bool readCurrentEvent()
HepMC::GenEvent * evt_
int HepMCFileReader::find_in_map ( const std::map< HepMC::GenParticle *, int > &  m,
HepMC::GenParticle *  p 
) const
private

Definition at line 289 of file HepMCFileReader.cc.

Referenced by getStatsFromTuple().

291 {
292  std::map<HepMC::GenParticle*,int>::const_iterator iter = m.find(p);
293  return (iter == m.end()) ? 0 : iter->second;
294 }
void HepMCFileReader::getStatsFromTuple ( int &  mo1,
int &  mo2,
int &  da1,
int &  da2,
int &  status,
int &  pid,
int  j 
) const
virtual

Definition at line 238 of file HepMCFileReader.cc.

References gather_cfg::cout, evt_, find_in_map(), index_to_particle, j, and particle_to_index.

Referenced by printEvent().

240 {
241  if (!evt_) {
242  cout << "HepMCFileReader: Got no event :-( Game over already ?" <<endl;
243  } else {
244  status = index_to_particle[j]->status();
245  pid = index_to_particle[j]->pdg_id();
246  if ( index_to_particle[j]->production_vertex() ) {
247 
248  //HepLorentzVector p = index_to_particle[j]->
249  //production_vertex()->position();
250 
251  int num_mothers = index_to_particle[j]->production_vertex()->
252  particles_in_size();
253  int first_mother = find_in_map( particle_to_index,
254  *(index_to_particle[j]->
255  production_vertex()->
256  particles_in_const_begin()));
257  int last_mother = first_mother + num_mothers - 1;
258  if ( first_mother == 0 ) last_mother = 0;
259  mo1=first_mother;
260  mo2=last_mother;
261  } else {
262  mo1 =0;
263  mo2 =0;
264  }
265  if (!index_to_particle[j]->end_vertex()) {
266  //find # of 1. daughter
267  int first_daughter = find_in_map( particle_to_index,
268  *(index_to_particle[j]->end_vertex()->particles_begin(HepMC::children)));
269  //cout <<"first_daughter "<< first_daughter << "num_daughters " << num_daughters << endl;
270  HepMC::GenVertex::particle_iterator ic;
271  int last_daughter=0;
272  //find # of last daughter
273  for (ic = index_to_particle[j]->end_vertex()->particles_begin(HepMC::children);
274  ic != index_to_particle[j]->end_vertex()->particles_end(HepMC::children); ++ic)
275  last_daughter= find_in_map( particle_to_index,*ic);
276 
277  if (first_daughter== 0) last_daughter = 0;
278  da1=first_daughter;
279  da2=last_daughter;
280  } else {
281  da1=0;
282  da2=0;
283  }
284  }
285 }
std::map< HepMC::GenParticle *, int > particle_to_index
std::vector< HepMC::GenParticle * > index_to_particle
int find_in_map(const std::map< HepMC::GenParticle *, int > &m, HepMC::GenParticle *p) const
int j
Definition: DBlmapReader.cc:9
tuple cout
Definition: gather_cfg.py:121
tuple status
Definition: ntuplemaker.py:245
HepMC::GenEvent * evt_
void HepMCFileReader::initialize ( const std::string &  filename)
virtual

Definition at line 68 of file HepMCFileReader.cc.

References edm::hlt::Exception, recoMuon::in, input_, isInitialized(), and rdstate().

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

69 {
70  if (isInitialized()) {
71  edm::LogError("HepMCFileReader") << "Was already initialized... reinitializing";
72  delete input_;
73  }
74 
75  edm::LogInfo("HepMCFileReader") << "Opening file" << filename << "using HepMC::IO_GenEvent";
76  input_ = new HepMC::IO_GenEvent(filename.c_str(), std::ios::in);
77 
78  if (rdstate() == std::ios::failbit) {
79  throw cms::Exception("FileNotFound", "HepMCFileReader::initialize()")
80  << "File " << filename << " was not found.\n";
81  }
82 }
int rdstate() const
HepMC::IO_BaseClass * input_
bool isInitialized() const
tuple filename
Definition: lut2db_cfg.py:20
HepMCFileReader * HepMCFileReader::instance ( )
static

Definition at line 33 of file HepMCFileReader.cc.

34 {
35  // Implement a HepMCFileReader singleton.
36 
37  if (instance_== 0) {
38  instance_ = new HepMCFileReader();
39  }
40  return instance_;
41 }
static HepMCFileReader * instance_
bool HepMCFileReader::isInitialized ( ) const
inline

Definition at line 76 of file HepMCFileReader.h.

References input_.

Referenced by initialize().

77 {
78  return input_ != 0;
79 }
HepMC::IO_BaseClass * input_
void HepMCFileReader::printEvent ( ) const

Definition at line 140 of file HepMCFileReader.cc.

References gather_cfg::cout, evt_, g, configurableAnalysis::GenParticle, getStatsFromTuple(), index_to_particle, n, evf::utils::pid, mathSSE::sqrt(), and ntuplemaker::status.

140  {
141  int mo1=0,mo2=0,da1=0,da2=0,status=0,pid=0;
142  if (evt_ != 0) {
143  cout << "---#-------pid--st---Mo1---Mo2---Da1---Da2------px------py------pz-------E-";
144  cout << "------m---------x---------y---------z---------t-";
145  cout << endl;
146  cout.setf(ios::right, ios::adjustfield);
147  for(int n=1; n<=evt_->particles_size(); n++) {
149  getStatsFromTuple( mo1,mo2,da1,da2,status,pid,n);
150  cout << setw(4) << n
151  << setw(8) << pid
152  << setw(5) << status
153  << setw(6) << mo1
154  << setw(6) << mo2
155  << setw(6) << da1
156  << setw(6) << da2;
157  cout.setf(ios::fixed, ios::floatfield);
158  cout.setf(ios::right, ios::adjustfield);
159  cout << setw(10) << setprecision(2) << g->momentum().x();
160  cout << setw(8) << setprecision(2) << g->momentum().y();
161  cout << setw(10) << setprecision(2) << g->momentum().z();
162  cout << setw(8) << setprecision(2) << g->momentum().t();
163  cout << setw(8) << setprecision(2) << g->generatedMass();
164  // tau=L/(gamma*beta*c)
165  if (g->production_vertex() != 0 && g->end_vertex() != 0 && status == 2) {
166  cout << setw(10) << setprecision(2) <<g->production_vertex()->position().x();
167  cout << setw(10) << setprecision(2) <<g->production_vertex()->position().y();
168  cout << setw(10) << setprecision(2) <<g->production_vertex()->position().z();
169 
170  double xm = g->production_vertex()->position().x();
171  double ym = g->production_vertex()->position().y();
172  double zm = g->production_vertex()->position().z();
173  double xd = g->end_vertex()->position().x();
174  double yd = g->end_vertex()->position().y();
175  double zd = g->end_vertex()->position().z();
176  double decl = sqrt((xd-xm)*(xd-xm)+(yd-ym)*(yd-ym)+(zd-zm)*(zd-zm));
177  double labTime = decl/c_light;
178  // convert lab time to proper time
179  double properTime = labTime/g->momentum().rho()*(g->generatedMass() );
180  // set the proper time in nanoseconds
181  cout << setw(8) << setprecision(2) <<properTime;
182  }
183  else{
184  cout << setw(10) << setprecision(2) << 0.0;
185  cout << setw(10) << setprecision(2) << 0.0;
186  cout << setw(10) << setprecision(2) << 0.0;
187  cout << setw(8) << setprecision(2) << 0.0;
188  }
189  cout << endl;
190  }
191  } else {
192  cout << " HepMCFileReader: No event available !" << endl;
193  }
194 }
std::vector< HepMC::GenParticle * > index_to_particle
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
virtual void getStatsFromTuple(int &mo1, int &mo2, int &da1, int &da2, int &status, int &pid, int j) const
T sqrt(T t)
Definition: SSEVec.h:48
tuple cout
Definition: gather_cfg.py:121
tuple status
Definition: ntuplemaker.py:245
HepMC::GenEvent * evt_
bool HepMCFileReader::printHepMcEvent ( ) const
virtual

Definition at line 123 of file HepMCFileReader.cc.

References evt_.

124 {
125  if (evt_ != 0) evt_->print();
126  return true;
127 }
HepMC::GenEvent * evt_
int HepMCFileReader::rdstate ( ) const
private

Definition at line 86 of file HepMCFileReader.cc.

References input_, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by initialize().

87 {
88  // work around a HepMC IO_ inheritence shortfall
89 
90  HepMC::IO_GenEvent *p = dynamic_cast<HepMC::IO_GenEvent*>(input_);
91  if (p) return p->rdstate();
92 
93  return std::ios::failbit;
94 }
HepMC::IO_BaseClass * input_
bool HepMCFileReader::readCurrentEvent ( )
virtual

Definition at line 98 of file HepMCFileReader.cc.

References evt_, input_, and ReadStats().

Referenced by fillCurrentEventData().

99 {
100  evt_ = input_->read_next_event();
101  if (evt_) {
102  edm::LogInfo("HepMCFileReader") << "| --- Event Nr. " << evt_->event_number()
103  << " with " << evt_->particles_size() << " particles --- !";
104  ReadStats();
105  // printHepMcEvent();
106  // printEvent();
107  } else {
108  edm::LogInfo("HepMCFileReader") << "Got no event" <<endl;
109  }
110 
111  return evt_ != 0;
112 }
virtual void ReadStats()
HepMC::IO_BaseClass * input_
HepMC::GenEvent * evt_
void HepMCFileReader::ReadStats ( )
virtual

Definition at line 198 of file HepMCFileReader.cc.

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

Referenced by readCurrentEvent().

199 {
200  unsigned int particle_counter=0;
201  index_to_particle.reserve(evt_->particles_size()+1);
202  index_to_particle[0] = 0;
203  for (HepMC::GenEvent::vertex_const_iterator v = evt_->vertices_begin();
204  v != evt_->vertices_end(); ++v ) {
205  // making a list of incoming particles of the vertices
206  // so that the mother indices in HEPEVT can be filled properly
207  for (HepMC::GenVertex::particles_in_const_iterator p1 = (*v)->particles_in_const_begin();
208  p1 != (*v)->particles_in_const_end(); ++p1 ) {
209  ++particle_counter;
210  //particle_counter can be very large for heavy ions
211  if(particle_counter >= index_to_particle.size() ) {
212  //make it large enough to hold up to this index
213  index_to_particle.resize(particle_counter+1);
214  }
215  index_to_particle[particle_counter] = *p1;
216  particle_to_index[*p1] = particle_counter;
217  }
218  // daughters are entered only if they aren't a mother of
219  // another vertex
220  for (HepMC::GenVertex::particles_out_const_iterator p2 = (*v)->particles_out_const_begin();
221  p2 != (*v)->particles_out_const_end(); ++p2) {
222  if (!(*p2)->end_vertex()) {
223  ++particle_counter;
224  //particle_counter can be very large for heavy ions
225  if(particle_counter >= index_to_particle.size() ) {
226  //make it large enough to hold up to this index
227  index_to_particle.resize(particle_counter+1);
228  }
229  index_to_particle[particle_counter] = *p2;
230  particle_to_index[*p2] = particle_counter;
231  }
232  }
233  }
234 }
std::map< HepMC::GenParticle *, int > particle_to_index
std::vector< HepMC::GenParticle * > index_to_particle
double p2[4]
Definition: TauolaWrapper.h:90
double p1[4]
Definition: TauolaWrapper.h:89
HepMC::GenEvent * evt_
bool HepMCFileReader::setEvent ( int  event)
virtual

Definition at line 116 of file HepMCFileReader.cc.

117 {
118  return true;
119 }

Member Data Documentation

HepMC::GenEvent* HepMCFileReader::evt_
private
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
HepMCFileReader * HepMCFileReader::instance_ =0
staticprivate

Definition at line 63 of file HepMCFileReader.h.

Referenced by HepMCFileReader(), 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().