LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
readmcparticles.cc
Go to the documentation of this file.
1 #include "lcio.h"
2 
3 #include "IO/LCReader.h"
4 #include "EVENT/LCCollection.h"
5 #include "EVENT/MCParticle.h"
6 
7 #include <cstdlib>
8 #include <sstream>
9 
10 using namespace std ;
11 using namespace lcio ;
12 
16 int main(int argc, char** argv ){
17 
18  // read file names from command line (only argument)
19  if( argc < 2) {
20  cout << " usage: readmcparticles input-file" << endl << endl ;
21  exit(1) ;
22  }
23  std::string FILEN = argv[1] ;
24 
25  LCReader* lcReader = LCFactory::getInstance()->createLCReader() ;
26  lcReader->open( FILEN ) ;
27 
28 
29  LCEvent* evt ;
30  int nEvents = 0 ;
31 
32  double e_evt = 0. ;
33 
34  //----------- the event loop -----------
35  while( (evt = lcReader->readNextEvent()) != 0 ) {
36 
37 
38  LCCollection* col = evt->getCollection("MCParticle") ;
39 
40  double e_mcp = 0. ;
41 
42  for( unsigned i=0,N=col->getNumberOfElements() ; i< N ; ++i){
43 
44  MCParticle* p = (MCParticle*) col->getElementAt(i) ;
45 
46  if( p->getGeneratorStatus() == 1)
47  e_mcp += p->getEnergy() ;
48 
49  }
50 
51  e_evt += e_mcp ;
52 
53  nEvents ++ ;
54  }
55  // -------- end of event loop -----------
56 
57  std::cout << " read " << nEvents << " <Ecms> = " << e_evt/nEvents << std::endl ;
58 
59  lcReader->close() ;
60  delete lcReader ;
61  return 0 ;
62 }
63 
64 
T endl(T...args)
STL class.
T exit(T...args)
int main(int argc, char **argv)
Simple program that opens existing LCIO files and appends the records needed for direct access - if t...
LCReader * lcReader
Definition: lsh.cc:78
static std::vector< std::string > FILEN