Changeset 572 in svn
- Timestamp:
- Nov 2, 2011, 5:39:26 PM (13 years ago)
- Location:
- trunk/Utilities/HepMC/interface
- Files:
-
- 5 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/HepMC/interface/Flow.h
r349 r572 179 179 inline void Flow::clear() { m_icode.clear(); } 180 180 inline bool Flow::erase( int code_index ) { 181 return (bool)m_icode.erase( code_index ); 181 // this will return true if the number of elements removed is nonzero 182 return m_icode.erase( code_index )==0 ? false : true ; 182 183 } 183 184 inline Flow::iterator Flow::begin() { return m_icode.begin(); } -
trunk/Utilities/HepMC/interface/GenEvent.h
r349 r572 119 119 // parent_event() return value will return a pointer to the event which owns 120 120 // it (or null if its an orphan). 121 // - Please note that the barcodes are intended for internal use within HepMC 122 // as a unique identifier for the particles and vertices. 123 // Using the barcode to encode extra information is an abuse of 124 // the barcode data member and causes confusion among users. 121 125 // 122 126 … … 124 128 #include "GenParticle.h" 125 129 #include "WeightContainer.h" 130 #include "GenCrossSection.h" 126 131 #include "HeavyIon.h" 127 132 #include "PdfInfo.h" 128 133 #include "Units.h" 134 #include "HepMCDefs.h" 129 135 #include <map> 130 136 #include <string> … … 134 140 135 141 namespace HepMC { 142 143 class GenEventVertexRange; 144 class ConstGenEventVertexRange; 145 class GenEventParticleRange; 146 class ConstGenEventParticleRange; 136 147 137 148 //! The GenEvent class is the core of HepMC … … 146 157 friend class GenVertex; 147 158 public: 148 /// default constructor creates null pointers to HeavyIon and PdfInfo159 /// default constructor creates null pointers to HeavyIon, PdfInfo, and GenCrossSection 149 160 GenEvent( int signal_process_id = 0, int event_number = 0, 150 161 GenVertex* signal_vertex = 0, … … 202 213 /// pair of pointers to the two incoming beam particles 203 214 std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beam_particles() const; 215 /// check GenEvent for validity 216 /// A GenEvent is presumed valid if it has particles and/or vertices. 217 bool is_valid() const; 204 218 205 219 /// direct access to the weights container is allowed. … … 211 225 const WeightContainer& weights() const; //!< direct access to WeightContainer 212 226 227 /// access the GenCrossSection container if it exists 228 GenCrossSection const * cross_section() const; 229 GenCrossSection* cross_section(); 213 230 /// access the HeavyIon container if it exists 214 HeavyIon const * 231 HeavyIon const * heavy_ion() const; 215 232 HeavyIon* heavy_ion(); 216 233 /// access the PdfInfo container if it exists 217 PdfInfo const * 234 PdfInfo const * pdf_info() const; 218 235 PdfInfo* pdf_info(); 219 236 … … 230 247 bool vertices_empty() const; 231 248 249 /// Write the unit information to an output stream. 250 /// If the output stream is not defined, use std::cout. 232 251 void write_units( std::ostream & os = std::cout ) const; 252 /// If the cross section is defined, 253 /// write the cross section information to an output stream. 254 /// If the output stream is not defined, use std::cout. 255 void write_cross_section( std::ostream& ostr = std::cout ) const; 233 256 234 257 /// Units used by the GenParticle momentum FourVector. … … 236 259 /// Units used by the GenVertex position FourVector. 237 260 Units::LengthUnit length_unit() const; 261 262 std::ostream& write(std::ostream&); 263 std::istream& read(std::istream&); 238 264 239 265 ///////////////////// … … 261 287 void set_random_states( const std::vector<long>& randomstates ); 262 288 289 /// provide a pointer to the GenCrossSection container 290 void set_cross_section( const GenCrossSection& ); 263 291 /// provide a pointer to the HeavyIon container 264 292 void set_heavy_ion( const HeavyIon& ion ); … … 271 299 /// the string must match the enum exactly 272 300 void use_units( std::string&, std::string& ); 301 302 /// vertex range 303 GenEventVertexRange vertex_range(); 304 /// vertex range 305 ConstGenEventVertexRange vertex_range() const; 306 /// particle range 307 GenEventParticleRange particle_range(); 308 /// particle range 309 ConstGenEventParticleRange particle_range() const; 273 310 274 311 public: … … 320 357 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator 321 358 m_map_iterator; 359 private: 360 /// Pre-fix increment -- is not allowed 361 vertex_const_iterator& operator--(void); 362 /// Post-fix increment -- is not allowed 363 vertex_const_iterator operator--(int); 322 364 }; 323 365 friend class vertex_const_iterator; … … 377 419 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator 378 420 m_map_iterator; 421 private: 422 /// Pre-fix increment 423 vertex_iterator& operator--(void); 424 /// Post-fix increment 425 vertex_iterator operator--(int); 426 379 427 }; 380 428 friend class vertex_iterator; … … 439 487 /// const iterator to the GenParticle map 440 488 std::map<int,HepMC::GenParticle*>::const_iterator m_map_iterator; 489 private: 490 /// Pre-fix increment 491 particle_const_iterator& operator--(void); 492 /// Post-fix increment 493 particle_const_iterator operator--(int); 441 494 }; 442 495 friend class particle_const_iterator; … … 492 545 /// iterator for GenParticle map 493 546 std::map<int,HepMC::GenParticle*>::iterator m_map_iterator; 547 private: 548 /// Pre-fix increment 549 particle_iterator& operator--(void); 550 /// Post-fix increment 551 particle_iterator operator--(int); 494 552 }; 495 553 friend class particle_iterator; … … 526 584 bool use_length_unit( Units::LengthUnit ); 527 585 bool use_length_unit( std::string& ); 586 587 // the following internal methods are used by read() and write() 588 589 /// send the beam particles to ASCII output 590 std::ostream & write_beam_particles( std::ostream &, 591 std::pair<HepMC::GenParticle *,HepMC::GenParticle *> ); 592 /// send a GenVertex to ASCII output 593 std::ostream & write_vertex( std::ostream &, GenVertex const * ); 594 /// send a GenParticle to ASCII output 595 std::ostream & write_particle( std::ostream&, GenParticle const * ); 596 /// find the file type 597 std::istream & find_file_type( std::istream & ); 598 /// find the key at the end of the block 599 std::istream & find_end_key( std::istream &, int & ); 600 /// get unit information from ASCII input 601 std::istream & read_units( std::istream & ); 602 /// get weight names from ASCII input 603 std::istream & read_weight_names( std::istream & ); 604 /// read the event header line 605 std::istream & process_event_line( std::istream &, int &, int &, int &, int & ); 528 606 529 607 private: // data members … … 544 622 std::map< int,HepMC::GenVertex*,std::greater<int> > m_vertex_barcodes; 545 623 std::map< int,HepMC::GenParticle*,std::less<int> > m_particle_barcodes; 624 GenCrossSection* m_cross_section; // undefined by default 546 625 HeavyIon* m_heavy_ion; // undefined by default 547 626 PdfInfo* m_pdf_info; // undefined by default … … 549 628 Units::LengthUnit m_position_unit; // default value set by configure switch 550 629 551 //static unsigned int s_counter;552 630 }; 631 632 633 /////////////////////////// 634 // IO Free Functions // 635 /////////////////////////// 636 637 /// standard streaming IO output operator 638 std::ostream & operator << (std::ostream &, GenEvent &); 639 /// standard streaming IO input operator 640 std::istream & operator >> (std::istream &, GenEvent &); 641 /// set the units for this input stream 642 std::istream & set_input_units(std::istream &, 643 Units::MomentumUnit, Units::LengthUnit); 644 /// Explicitly write the begin block lines that IO_GenEvent uses 645 std::ostream & write_HepMC_IO_block_begin(std::ostream & ); 646 /// Explicitly write the end block line that IO_GenEvent uses 647 std::ostream & write_HepMC_IO_block_end(std::ostream & ); 553 648 554 649 … … 596 691 inline const WeightContainer& GenEvent::weights() const 597 692 { return m_weights; } 693 694 inline GenCrossSection const * GenEvent::cross_section() const 695 { return m_cross_section; } 696 697 inline GenCrossSection* GenEvent::cross_section() 698 { return m_cross_section; } 598 699 599 700 inline HeavyIon const * GenEvent::heavy_ion() const … … 639 740 } 640 741 742 inline void GenEvent::set_cross_section( const GenCrossSection& xs ) 743 { 744 delete m_cross_section; 745 m_cross_section = new GenCrossSection(xs); 746 } 747 641 748 inline void GenEvent::set_heavy_ion( const HeavyIon& ion ) 642 { m_heavy_ion = new HeavyIon(ion); } 749 { 750 delete m_heavy_ion; 751 m_heavy_ion = new HeavyIon(ion); 752 } 643 753 644 754 inline void GenEvent::set_pdf_info( const PdfInfo& p ) 645 { m_pdf_info = new PdfInfo(p); } 755 { 756 delete m_pdf_info; 757 m_pdf_info = new PdfInfo(p); 758 } 646 759 647 760 inline void GenEvent::set_random_states( const std::vector<long>& … … 649 762 { m_random_states = randomstates; } 650 763 651 inline void GenEvent::remove_barcode( HepMC::GenParticle* p )764 inline void GenEvent::remove_barcode( GenParticle* p ) 652 765 { m_particle_barcodes.erase( p->barcode() ); } 653 766 … … 668 781 /// The barcodes are chosen and set automatically when a vertex or particle 669 782 /// comes under the ownership of an event (i.e. it is contained in an event). 783 /// 784 /// Please note that the barcodes are intended for internal use within 785 /// HepMC as a unique identifier for the particles and vertices. 786 /// Using the barcode to encode extra information is an abuse of 787 /// the barcode data member and causes confusion among users. 670 788 inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const 671 789 { … … 688 806 /// The barcodes are chosen and set automatically when a vertex or particle 689 807 /// comes under the ownership of an event (i.e. it is contained in an event). 808 /// 809 /// Please note that the barcodes are intended for internal use within 810 /// HepMC as a unique identifier for the particles and vertices. 811 /// Using the barcode to encode extra information is an abuse of 812 /// the barcode data member and causes confusion among users. 690 813 inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const 691 814 { … … 709 832 710 833 // beam particles 711 inline std::pair<HepMC::GenParticle *,HepMC::GenParticle*> GenEvent::beam_particles() const {712 return std::pair<GenParticle *,GenParticle*> (m_beam_particle_1, m_beam_particle_2);834 inline std::pair<HepMC::GenParticle *,HepMC::GenParticle *> GenEvent::beam_particles() const { 835 return std::pair<GenParticle *,GenParticle *> (m_beam_particle_1, m_beam_particle_2); 713 836 } 714 837 -
trunk/Utilities/HepMC/interface/GenParticle.h
r349 r572 30 30 #include "Polarization.h" 31 31 #include "SimpleVector.h" 32 #include "IteratorRange.h" 32 33 #include <iostream> 33 34 #ifdef _WIN32 … … 43 44 class GenEvent; 44 45 46 class GenParticleProductionRange; 47 class ConstGenParticleProductionRange; 48 class GenParticleEndRange; 49 class ConstGenParticleEndRange; 45 50 46 51 //! The GenParticle class contains information about generated particles … … 119 124 /// 120 125 /// The barcode is the particle's reference number, every vertex in the 121 /// event has a unique barcode. Particle barcodes are positive numbers, 122 /// vertex barcodes are negative numbers. 126 /// event has a unique barcode. Particle barcodes are positive numbers, 127 /// vertex barcodes are negative numbers. 128 /// 129 /// Please note that the barcodes are intended for internal use within 130 /// HepMC as a unique identifier for the particles and vertices. 131 /// Using the barcode to encode extra information is an abuse of 132 /// the barcode data member and causes confusion among users. 133 /// 123 134 int barcode() const; //!< particle barcode 135 136 /// Convenience method. Returns true if status==1 137 bool is_undecayed() const; 138 /// Convenience method. Returns true if status==2 139 bool has_decayed() const; 140 /// Convenience method. Returns true if status==4 141 /// Note that using status 4 for beam particles is a new convention which 142 /// may not have been implemented by the code originating this GenEvent. 143 bool is_beam() const; 144 145 /// incoming particle range 146 GenParticleProductionRange particles_in( IteratorRange range = relatives ); 147 /// incoming particle range 148 ConstGenParticleProductionRange particles_in( IteratorRange range = relatives ) const; 149 /// outgoing particle range 150 GenParticleEndRange particles_out( IteratorRange range = relatives ); 151 /// outgoing particle range 152 ConstGenParticleEndRange particles_out( IteratorRange range = relatives ) const; 124 153 125 154 ///////////////////// … … 225 254 inline void GenParticle::set_barcode_( int bc ) { m_barcode = bc; } 226 255 256 inline bool GenParticle::is_undecayed() const { 257 return ( m_status==1 ) ? true : false; 258 } 259 inline bool GenParticle::has_decayed() const { 260 return ( m_status==2 ) ? true : false; 261 } 262 inline bool GenParticle::is_beam() const { 263 return ( m_status==4 ) ? true : false; 264 } 265 227 266 } // HepMC 228 267 -
trunk/Utilities/HepMC/interface/GenVertex.h
r349 r572 24 24 #include "WeightContainer.h" 25 25 #include "SimpleVector.h" 26 #include "IteratorRange.h" 26 27 #include <iostream> 27 28 #include <iterator> … … 29 30 #include <set> 30 31 #include <algorithm> 32 #include <cstddef> 31 33 32 34 namespace HepMC { 33 35 34 /// type of iteration 35 enum IteratorRange { parents, children, family, 36 ancestors, descendants, relatives }; 36 class GenVertexParticleRange; 37 class GenParticleProductionRange; 38 class ConstGenParticleProductionRange; 39 class GenParticleEndRange; 40 class ConstGenParticleEndRange; 41 37 42 class GenParticle; 38 43 class GenEvent; … … 110 115 /// 111 116 /// The barcode is the vertex's reference number, every vertex in the 112 /// event has a unique barcode. Vertex barcodes are negative numbers, 113 /// particle barcodes are positive numbers. 117 /// event has a unique barcode. Vertex barcodes are negative numbers, 118 /// particle barcodes are positive numbers. 119 /// 120 /// Please note that the barcodes are intended for internal use within 121 /// HepMC as a unique identifier for the particles and vertices. 122 /// Using the barcode to encode extra information is an abuse of 123 /// the barcode data member and causes confusion among users. 124 /// 114 125 int barcode() const; //!< unique identifier 115 126 … … 121 132 /// const direct access to the weights container 122 133 const WeightContainer& weights() const; 134 135 /// particle range 136 GenVertexParticleRange particles( IteratorRange range = relatives ); 137 /// incoming particle range 138 GenParticleProductionRange particles_in( GenParticle&, IteratorRange range = relatives ); 139 /// incoming particle range 140 ConstGenParticleProductionRange particles_in( GenParticle const &, IteratorRange range = relatives ) const; 141 /// outgoing particle range 142 GenParticleEndRange particles_out( GenParticle&, IteratorRange range = relatives ); 143 /// outgoing particle range 144 ConstGenParticleEndRange particles_out( GenParticle const &, IteratorRange range = relatives ) const; 123 145 124 146 //////////////////// … … 197 219 /// root vertex of this iteration 198 220 const GenVertex* vertex_root() const; 221 private: 222 /// Pre-fix increment -- is not allowed 223 edge_iterator& operator--(void); 224 /// Post-fix increment -- is not allowed 225 edge_iterator operator--(int); 199 226 private: 200 227 const GenVertex* m_vertex; … … 275 302 recursive_v_iter ); 276 303 private: 304 /// Pre-fix increment -- is not allowed 305 vertex_iterator& operator--(void); 306 /// Post-fix increment -- is not allowed 307 vertex_iterator operator--(int); 308 309 private: 277 310 GenVertex* m_vertex; // the vertex associated to this iter 278 311 IteratorRange m_range; -
trunk/Utilities/HepMC/interface/HeavyIon.h
r349 r572 112 112 float sigma_inel_NN() const { return m_sigma_inel_NN; } 113 113 114 /// verify that the instance contains non-zero information 115 bool is_valid() const; 116 114 117 // --- mutators: 115 118 /// set number of hard scatterings … … 158 161 }; 159 162 163 // Free Functions 164 165 /// Write the contents of HeavyIon to an output stream. 166 std::ostream & operator << (std::ostream &, HeavyIon const *); 167 /// Read the contents of HeavyIon from an input stream. 168 std::istream & operator >> (std::istream &, HeavyIon *); 169 160 170 // inline operators 161 171 /// Required members are … … 248 258 } 249 259 260 inline bool HeavyIon::is_valid() const 261 { 262 if( m_Ncoll_hard != 0 ) return true; 263 if( m_Npart_proj != 0 ) return true; 264 if( m_Npart_targ != 0 ) return true; 265 if( m_Ncoll != 0 ) return true; 266 if( m_spectator_neutrons != 0 ) return true; 267 if( m_spectator_protons != 0 ) return true; 268 if( m_N_Nwounded_collisions != 0 ) return true; 269 if( m_Nwounded_N_collisions != 0 ) return true; 270 if( m_Nwounded_Nwounded_collisions != 0 ) return true; 271 if( m_impact_parameter != 0 ) return true; 272 if( m_event_plane_angle != 0 ) return true; 273 if( m_eccentricity != 0 ) return true; 274 if( m_sigma_inel_NN != 0 ) return true; 275 return false; 276 } 277 250 278 } // HepMC 251 279 -
trunk/Utilities/HepMC/interface/IO_AsciiParticles.h
r349 r572 8 8 ////////////////////////////////////////////////////////////////////////// 9 9 // 10 // Strategy for reading or writing events /particleDataas machine readable10 // Strategy for reading or writing events as machine readable 11 11 // ascii to a file. When instantiating, the mode of file to be created 12 12 // must be specified. Options are: … … 48 48 /// 49 49 /// \class IO_AsciiParticles 50 /// Strategy for reading or writing events /particleDataas machine readable50 /// Strategy for reading or writing events as machine readable 51 51 /// ascii to a file. When instantiating, the mode of file to be created 52 52 /// must be specified. … … 63 63 /// get the next event 64 64 bool fill_next_event( GenEvent* evt ); 65 inline void write_particle_data_table(const ParticleDataTable*);66 inline bool fill_particle_data_table( ParticleDataTable* );67 65 /// insert a comment directly into the output file --- normally you 68 66 /// only want to do this at the beginning or end of the file. All … … 100 98 inline void IO_AsciiParticles::setPrecision(int iprec) { m_precision=iprec; } 101 99 102 /////////////////////103 // Inline dummies //104 /////////////////////105 106 void IO_AsciiParticles::write_particle_data_table(const ParticleDataTable*) {;}107 bool IO_AsciiParticles::fill_particle_data_table( ParticleDataTable* ) {return false;}108 109 100 } // HepMC 110 101 -
trunk/Utilities/HepMC/interface/IO_BaseClass.h
r349 r572 20 20 21 21 #include <iostream> 22 #include "ParticleDataTable.h"23 22 #include "GenEvent.h" 24 23 … … 41 40 /// fill this GenEvent 42 41 virtual bool fill_next_event( GenEvent* ) =0; 43 /// write this ParticleDataTable44 virtual void write_particle_data_table( const ParticleDataTable* ) =0;45 /// fill this ParticleDataTable46 virtual bool fill_particle_data_table( ParticleDataTable* ) =0;47 42 /// write output to ostr 48 43 virtual void print( std::ostream& ostr = std::cout ) const; 49 44 // 50 // the read_next_event() and read_particle_data_table() differfrom51 // the fill_***() methods in that they create a new event or pdt45 // the read_next_event() differs from 46 // the fill_***() methods in that it creates a new event 52 47 // before calling the corresponding fill_*** method 53 48 // (they are not intended to be over-ridden) 54 49 GenEvent* read_next_event(); //!< do not over-ride 55 ParticleDataTable* read_particle_data_table(); //!< do not over-ride56 50 // 57 51 // The overloaded stream operators >>,<< are identical to … … 72 66 /// the same as write_event 73 67 virtual GenEvent*& operator<<( GenEvent*& ); 74 /// the same as read_particle_data_table75 virtual ParticleDataTable*& operator>>( ParticleDataTable*& );76 /// the same as write_particle_data_table77 virtual const ParticleDataTable*& operator<<( const78 ParticleDataTable*& );79 /// the same as write_particle_data_table80 virtual ParticleDataTable*& operator<<( ParticleDataTable*& );81 68 }; 82 69 … … 98 85 // since this statement is rarely reached 99 86 delete evt; 100 return 0;101 }102 103 inline ParticleDataTable* IO_BaseClass::read_particle_data_table() {104 /// creates a new particle data table and fills it by calling105 /// the sister method read_particle_data_table( ParticleDataTable* )106 //107 // 1. create an empty pdt108 ParticleDataTable* pdt = new ParticleDataTable();109 // 2. fill the pdt container - if the read is successful, return the110 // pointer, otherwise return null and delete the evt111 if ( fill_particle_data_table( pdt ) ) return pdt;112 // next statement is only reached if read fails113 delete pdt;114 87 return 0; 115 88 } … … 135 108 } 136 109 137 inline ParticleDataTable*& IO_BaseClass::operator>>(138 ParticleDataTable*& pdt ){139 pdt = read_particle_data_table();140 return pdt;141 }142 143 inline const ParticleDataTable*& IO_BaseClass::operator<<(144 const ParticleDataTable*& pdt ) {145 write_particle_data_table( pdt );146 return pdt;147 }148 149 inline ParticleDataTable*& IO_BaseClass::operator<<(150 ParticleDataTable*& pdt ) {151 write_particle_data_table( pdt );152 return pdt;153 }154 155 110 } // HepMC 156 111 -
trunk/Utilities/HepMC/interface/IO_GenEvent.h
r349 r572 16 16 #include <vector> 17 17 #include "IO_BaseClass.h" 18 #include "TempParticleMap.h" 19 #include "CommonIO.h" 18 #include "IO_Exception.h" 20 19 #include "Units.h" 21 20 22 21 namespace HepMC { 23 22 24 class GenEvent; 25 class GenVertex; 26 class GenParticle; 27 class ParticleData; 28 class HeavyIon; 29 class PdfInfo; 23 class GenEvent; 24 class GenVertex; 25 class GenParticle; 26 class HeavyIon; 27 class PdfInfo; 30 28 31 29 //! IO_GenEvent also deals with HeavyIon and PdfInfo 32 30 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 31 /// 32 /// \class IO_GenEvent 33 /// event input/output in ascii format for machine reading 34 /// extended format contains HeavyIon and PdfInfo classes 35 /// 36 /// Strategy for reading or writing events using iostreams 37 /// When instantiating with a file name, the mode of file to be created 38 /// must be specified. Options are: 39 /// std::ios::in open file for input 40 /// std::ios::out open file for output 41 /// std::ios::trunc erase old file when opening (i.e. ios::out|ios::trunc 42 /// removes oldfile, and creates a new one for output ) 43 /// std::ios::app append output to end of file 44 /// for the purposes of this class, simultaneous input and output mode 45 /// ( std::ios::in | std::ios::out ) is not allowed. 46 /// 47 /// Event listings are preceded by the key: 48 /// "HepMC::IO_GenEvent-START_EVENT_LISTING\n" 49 /// and terminated by the key: 50 /// "HepMC::IO_GenEvent-END_EVENT_LISTING\n" 51 /// GenParticle Data tables are preceded by the key: 52 /// "HepMC::IO_GenEvent-START_PARTICLE_DATA\n" 53 /// and terminated by the key: 54 /// "HepMC::IO_GenEvent-END_PARTICLE_DATA\n" 55 /// Comments are allowed. They need not be preceded by anything, though if 56 /// a comment is written using write_comment( const string ) then it will be 57 /// preceded by "HepMC::IO_GenEvent-COMMENT\n" 58 /// Each event, vertex, particle, particle data, heavy ion, or pdf info line 59 /// is preceded by "E ","V ","P ","D ","H ","F " respectively. 60 /// Comments may appear anywhere in the file -- so long as they do not contain 61 /// any of the start/stop keys. 62 /// 63 class IO_GenEvent : public IO_BaseClass { 64 public: 65 /// constructor requiring a file name and std::ios mode 66 IO_GenEvent( const std::string& filename="IO_GenEvent.dat", 67 std::ios::openmode mode=std::ios::out ); 68 /// constructor requiring an input stream 69 IO_GenEvent( std::istream & ); 70 /// constructor requiring an output stream 71 IO_GenEvent( std::ostream & ); 72 virtual ~IO_GenEvent(); 75 73 76 /// write this event 77 void write_event( const GenEvent* evt ); 78 /// get the next event 79 bool fill_next_event( GenEvent* evt ); 80 void write_particle_data_table(const ParticleDataTable*); 81 bool fill_particle_data_table( ParticleDataTable* ); 82 /// insert a comment directly into the output file --- normally you 83 /// only want to do this at the beginning or end of the file. All 84 /// comments are preceded with "HepMC::IO_GenEvent-COMMENT\n" 85 void write_comment( const std::string comment ); 74 /// write this event 75 void write_event( const GenEvent* evt ); 76 /// get the next event 77 bool fill_next_event( GenEvent* evt ); 78 /// insert a comment directly into the output file --- normally you 79 /// only want to do this at the beginning or end of the file. All 80 /// comments are preceded with "HepMC::IO_GenEvent-COMMENT\n" 81 void write_comment( const std::string comment ); 86 82 87 88 83 int rdstate() const; //!< check the state of the IO stream 84 void clear(); //!< clear the IO stream 89 85 90 91 86 /// write to ostr 87 void print( std::ostream& ostr = std::cout ) const; 92 88 93 94 95 96 97 89 /// needed when reading a file without units if those units are 90 /// different than the declared default units 91 /// (e.g., the default units are MeV, but the file was written with GeV) 92 /// This method is not necessary if the units are written in the file 93 void use_input_units( Units::MomentumUnit, Units::LengthUnit ); 98 94 99 protected: // for internal use only 100 /// write vertex information 101 void write_vertex( GenVertex* ); 102 /// write beam particle information 103 void write_beam_particles( std::pair<HepMC::GenParticle *,HepMC::GenParticle *> ); 104 /// write heavy ion information 105 void write_heavy_ion( HeavyIon const * ); 106 /// write PDF information 107 void write_pdf_info( PdfInfo const * ); 108 /// write units 109 void write_unit_info( const GenEvent* evt ); 110 /// write particle information 111 void write_particle( GenParticle* p ); 112 /// write particle data information 113 void write_particle_data( const ParticleData* d ); 114 /// read vertex information 115 GenVertex* read_vertex( TempParticleMap& particle_to_end_vertex ); 116 /// read GenParticle information 117 GenParticle* read_particle( TempParticleMap& particle_to_end_vertex ); 118 /// read particle data table information 119 ParticleData* read_particle_data( ParticleDataTable* ); 120 /// read heavy ion information 121 HeavyIon* read_heavy_ion( ); 122 /// read units 123 void read_unit_info( GenEvent* evt ); 124 /// write end tag 125 bool write_end_listing(); 95 /// set output precision 96 /// The default precision is 16. 97 void precision( int ); 98 99 /// integer (enum) associated with read error 100 int error_type() const; 101 /// the read error message string 102 const std::string & error_message() const; 126 103 127 void output( const double& ); //!< write double 128 void output( const float& ); //!< write float 129 void output( const int& ); //!< write int 130 void output( const long& ); //!< write long 131 void output( const char& ); //!< write a single character 132 private: // use of copy constructor is not allowed 133 IO_GenEvent( const IO_GenEvent& ) : IO_BaseClass() {} 134 private: // data members 135 std::ios::openmode m_mode; 136 std::fstream m_file; 137 std::ostream * m_ostr; 138 std::istream * m_istr; 139 std::ios * m_iostr; 140 bool m_finished_first_event_io; 141 bool m_have_file; 142 CommonIO m_common_io; 143 144 }; 104 private: // use of copy constructor is not allowed 105 IO_GenEvent( const IO_GenEvent& ) : IO_BaseClass() {} 145 106 146 ////////////// 147 // Inlines // 148 ////////////// 107 private: // data members 108 std::ios::openmode m_mode; 109 std::fstream m_file; 110 std::ostream * m_ostr; 111 std::istream * m_istr; 112 std::ios * m_iostr; 113 bool m_have_file; 114 IO_Exception::ErrorType m_error_type; 115 std::string m_error_message; 149 116 150 inline void IO_GenEvent::output( const double& d ) { 151 if( m_ostr ) { 152 if ( d == 0. ) { 153 *m_ostr << ' ' << (int)0; 154 } else { 155 *m_ostr << ' ' << d; 156 } 157 } 117 }; 118 119 ////////////// 120 // Inlines // 121 ////////////// 122 123 inline int IO_GenEvent::rdstate() const { 124 int state; 125 if( m_istr ) { 126 state = (int)m_istr->rdstate(); 127 } else { 128 state = (int)m_ostr->rdstate(); 158 129 } 159 inline void IO_GenEvent::output( const float& d ) {160 if( m_ostr ) { 161 if ( d == 0. ) { 162 *m_ostr << ' ' << (int)0; 163 } else{164 *m_ostr << ' ' << d;165 } 166 }130 return state; 131 } 132 133 inline void IO_GenEvent::clear() { 134 if( m_istr ) { 135 m_istr->clear(); 136 } else { 137 m_ostr->clear(); 167 138 } 168 inline void IO_GenEvent::output( const int& i ) { 169 if( m_ostr ) { 170 if ( i == 0. ) { 171 *m_ostr << ' ' << (int)0; 172 } else { 173 *m_ostr << ' ' << i; 174 } 175 } 176 } 177 inline void IO_GenEvent::output( const long& i ) { 178 if( m_ostr ) { 179 if ( i == 0. ) { 180 *m_ostr << ' ' << (int)0; 181 } else { 182 *m_ostr << ' ' << i; 183 } 184 } 185 } 186 inline void IO_GenEvent::output( const char& c ) { 187 if( m_ostr ) { 188 if ( c ) { 189 *m_ostr << c; 190 } else { 191 *m_ostr << ' ' ; 192 } 193 } 194 } 195 inline int IO_GenEvent::rdstate() const { 196 int state; 197 if( m_istr ) { 198 state = (int)m_istr->rdstate(); 199 } else { 200 state = (int)m_ostr->rdstate(); 201 } 202 return state; 203 } 204 inline void IO_GenEvent::clear() { 205 if( m_istr ) { 206 m_istr->clear(); 207 } else { 208 m_ostr->clear(); 209 } 210 } 211 // these are required by IO_BaseClass, but not used here 212 inline void IO_GenEvent::write_particle_data_table(const ParticleDataTable*) {;} 213 inline bool IO_GenEvent::fill_particle_data_table( ParticleDataTable* ) 214 { return false;} 139 } 140 141 inline int IO_GenEvent::error_type() const { 142 return m_error_type; 143 } 144 145 inline const std::string & IO_GenEvent::error_message() const { 146 return m_error_message; 147 } 215 148 216 149 } // HepMC -
trunk/Utilities/HepMC/interface/PdfInfo.h
r349 r572 91 91 double pdf2() const { return m_pdf2; } 92 92 93 /// verify that the instance contains non-zero information 94 bool is_valid() const; 95 93 96 // --- mutators: 94 97 /// set flavour code of first parton … … 124 127 }; 125 128 129 // Free Functions 130 131 // IO 132 std::ostream & operator << (std::ostream &, PdfInfo const *); 133 std::istream & operator >> (std::istream &, PdfInfo *); 134 126 135 // inline operators 127 136 inline PdfInfo::PdfInfo( int i1, int i2, double x1, double x2, … … 191 200 } 192 201 202 inline bool PdfInfo::is_valid() const 203 { 204 if( m_id1 != 0 ) return true; 205 if( m_id2 != 0 ) return true; 206 if( m_pdf_id1 != 0 ) return true; 207 if( m_pdf_id2 != 0 ) return true; 208 if( m_x1 != 0 ) return true; 209 if( m_x2 != 0 ) return true; 210 if( m_scalePDF != 0 ) return true; 211 if( m_pdf1 != 0 ) return true; 212 if( m_pdf2 != 0 ) return true; 213 return false; 214 } 215 193 216 } // HepMC 194 217 -
trunk/Utilities/HepMC/interface/Polarization.h
r349 r572 34 34 public: 35 35 /// default constructor 36 Polarization( double theta = 0, double phi = 0 ); 36 Polarization( ); 37 /// constructor requiring at least one value 38 Polarization( double theta, double phi = 0 ); 37 39 /// construct from another polarization object 38 40 Polarization( const Polarization& inpolar ); … … 59 61 double phi() const; //!< returns azimuthal angle in radians 60 62 ThreeVector normal3d() const; //!< unit 3 vector for easy manipulation 63 bool is_defined() const; //!< returns true if the Polarization has been defined 61 64 62 65 /// set polar angle in radians … … 68 71 /// sets polarization according to direction of 3 vec 69 72 ThreeVector set_normal3d( const ThreeVector& vec3in ); 73 /// declares the Polarization as undefined and zeros the values 74 void set_undefined(); 70 75 71 76 private: … … 78 83 double m_theta; //polar angle of polarization in radians 0< theta <pi 79 84 double m_phi; //azimuthal angle of polarization in rad. 0< phi <2pi 85 bool m_defined; //used to flag if the Polarization has been defined 80 86 }; 81 87 … … 93 99 inline bool Polarization::operator==( const Polarization& a ) const 94 100 { 95 return ( a.theta() == this->theta() && a.phi() == this->phi() );101 return ( a.theta() == this->theta() && a.phi() == this->phi() && a.is_defined() == this->is_defined() ); 96 102 } 97 103 -
trunk/Utilities/HepMC/interface/SimpleVector.h
r349 r572 83 83 double perp2() const; //!< Transverse component of the spatial vector squared. 84 84 double perp() const; //!< Transverse component of the spatial vector (R in cylindrical system). 85 double mag() const; //!< Magnitude of the spatial vector86 85 87 86 // Get spatial vector components in spherical coordinate system. … … 167 166 double r() const; //!< The magnitude 168 167 169 double mag() const; //!< The magnitude (r in spherical coordinate system). 170 171 void setPhi(double); //!< Set phi keeping mag and theta constant (BaBar). 172 void setTheta(double); //!< Set theta keeping mag and phi constant (BaBar). 168 void setPhi(double); //!< Set phi keeping magnitude and theta constant (BaBar). 169 void setTheta(double); //!< Set theta keeping magnitude and phi constant (BaBar). 173 170 174 171 double perp2() const; //!< The transverse component squared (rho^2 in cylindrical coordinate system). -
trunk/Utilities/HepMC/interface/SimpleVector.icc
r349 r572 49 49 } 50 50 51 inline double FourVector::mag() const {52 return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );53 }54 55 51 inline double FourVector::perp2() const { return m_x*m_x + m_y*m_y; } 56 52 … … 78 74 79 75 inline double FourVector::pseudoRapidity() const { 80 double m = mag();76 double m = std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z ); 81 77 if ( m== 0 ) return 0.0; 82 78 if ( m== z() ) return 1.0E72; … … 106 102 } 107 103 108 inline double ThreeVector::mag()const {104 inline double ThreeVector::r() const { 109 105 return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z ); 110 106 } 111 112 inline double ThreeVector::r() const { return mag(); }113 107 114 108 inline void ThreeVector::set(double x, double y, double z) { … … 125 119 126 120 inline void ThreeVector::setTheta(double th) { 127 double ma = mag();121 double ma = r(); 128 122 double ph = phi(); 129 123 setX(ma*std::sin(th)*std::cos(ph)); -
trunk/Utilities/HepMC/interface/TempParticleMap.h
r349 r572 60 60 m_particle_order[p->barcode()] = p; 61 61 m_particle_to_end_vertex[p] = end_vtx_code; 62 } 62 } 63 63 64 64 } // HepMC -
trunk/Utilities/HepMC/interface/Version.h
r349 r572 12 12 #include <string> 13 13 #include <iostream> 14 #include "HepMCDefs.h" 14 15 15 16 namespace HepMC { 16 17 17 void version( ); //!< print HepMC version18 void version( std::ostream & os = std::cout ); //!< print HepMC version 18 19 void writeVersion( std::ostream & os ); //!< write HepMC version to os 19 20 std::string versionName( ); //!< return HepMC version … … 21 22 inline std::string versionName( ) 22 23 { 23 return "2.04.01";24 return HEPMC_VERSION; 24 25 } 25 26 26 inline void version( )27 inline void version( std::ostream & os ) 27 28 { 28 std::cout<< " --------------- HepMC Version " << versionName()29 29 os << " --------------- HepMC Version " << versionName() 30 << " --------------- " << std::endl; 30 31 } 31 32 -
trunk/Utilities/HepMC/interface/WeightContainer.h
r349 r572 9 9 // 10 10 // Container for the Weights associated with an event or vertex. 11 // Basically just an interface to STL vector. 11 // 12 // This implementation adds a map-like interface in addition to the 13 // vector-like interface. 12 14 ////////////////////////////////////////////////////////////////////////// 13 15 14 16 #include <iostream> 15 17 #include <vector> 18 #include <string> 19 #include <map> 16 20 17 21 namespace HepMC { … … 21 25 /// 22 26 /// \class WeightContainer 23 /// Basically just an interface to STL vector. 27 /// This class has both map-like and vector-like functionality. 28 /// Named weights are now supported. 24 29 class WeightContainer { 30 friend class GenEvent; 25 31 26 32 public: 33 /// defining the size type used by vector and map 34 typedef std::size_t size_type; 35 /// iterator for the weight container 36 typedef std::vector<double>::iterator iterator; 37 /// const iterator for the weight container 38 typedef std::vector<double>::const_iterator const_iterator; 39 27 40 /// default constructor 28 WeightContainer( unsigned int n = 0, const double&value = 0. );41 explicit WeightContainer( size_type n = 0, double value = 0. ); 29 42 /// construct from a vector of weights 30 43 WeightContainer( const std::vector<double>& weights ); 31 44 /// copy 32 45 WeightContainer( const WeightContainer& in ); 33 virtual~WeightContainer();46 ~WeightContainer(); 34 47 35 48 /// swap 36 49 void swap( WeightContainer & other); 37 /// copy 50 /// copy assignment 38 51 WeightContainer& operator=( const WeightContainer& ); 39 /// copy52 /// alternate assignment using a vector of doubles 40 53 WeightContainer& operator=( const std::vector<double>& in ); 41 54 42 55 /// print weights 43 56 void print( std::ostream& ostr = std::cout ) const; 57 /// write weights in a readable table 58 void write( std::ostream& ostr = std::cout ) const; 44 59 45 60 /// size of weight container 46 intsize() const;61 size_type size() const; 47 62 /// return true if weight container is empty 48 63 bool empty() const; … … 54 69 void clear(); 55 70 56 /// access the weight container 57 double& operator[]( unsigned int n ); // unchecked access 58 /// access the weight container 59 const double& operator[]( unsigned int n ) const; 60 71 /// check to see if a name exists in the map 72 bool has_key( const std::string& s ) const; 73 74 /// access the weight container 75 double& operator[]( size_type n ); // unchecked access 76 /// access the weight container 77 const double& operator[]( size_type n ) const; 78 /// access the weight container 79 double& operator[]( const std::string& s ); // unchecked access 80 /// access the weight container 81 const double& operator[]( const std::string& s ) const; 82 83 /// equality 84 bool operator==( const WeightContainer & ) const; 85 /// inequality 86 bool operator!=( const WeightContainer & ) const; 87 61 88 /// returns the first element 62 89 double& front(); … … 68 95 const double& back() const; 69 96 70 /// iterator for the weight container 71 typedef std::vector<double>::iterator iterator; 97 /// begining of the weight container 98 iterator begin(); 99 /// end of the weight container 100 iterator end(); 101 /// begining of the weight container 102 const_iterator begin() const; 103 /// end of the weight container 104 const_iterator end() const; 105 106 private: 107 // for internal use only 108 109 /// maplike iterator for the weight container 110 /// for internal use only 111 typedef std::map<std::string,size_type>::iterator map_iterator; 72 112 /// const iterator for the weight container 73 typedef std::vector<double>::const_iterator const_iterator; 74 /// begining of the weight container 75 iterator begin(); 76 /// end of the weight container 77 iterator end(); 78 /// begining of the weight container 79 const_iterator begin() const; 80 /// end of the weight container 81 const_iterator end() const; 113 /// for internal use only 114 typedef std::map<std::string,size_type>::const_iterator const_map_iterator; 115 /// begining of the weight container 116 /// for internal use only 117 map_iterator map_begin(); 118 /// end of the weight container 119 /// for internal use only 120 map_iterator map_end(); 121 /// begining of the weight container 122 /// for internal use only 123 const_map_iterator map_begin() const; 124 /// end of the weight container 125 /// for internal use only 126 const_map_iterator map_end() const; 127 128 /// used by the constructors to set initial names 129 /// for internal use only 130 void set_default_names( size_type n ); 82 131 83 132 private: 84 std::vector<double> m_weights; 133 std::vector<double> m_weights; 134 std::map<std::string,size_type> m_names; 85 135 }; 86 136 … … 89 139 /////////////////////////// 90 140 91 inline WeightContainer::WeightContainer( unsigned int n, 92 const double& value ) 93 : m_weights(n,value) 141 inline WeightContainer::WeightContainer( const WeightContainer& in ) 142 : m_weights(in.m_weights), m_names(in.m_names) 94 143 {} 95 144 96 inline WeightContainer::WeightContainer( const std::vector<double>& wgts )97 : m_weights(wgts)98 {}99 100 inline WeightContainer::WeightContainer( const WeightContainer& in )101 : m_weights(in.m_weights)102 {}103 104 145 inline WeightContainer::~WeightContainer() {} 105 146 106 147 inline void WeightContainer::swap( WeightContainer & other) 107 { m_weights.swap( other.m_weights ); } 148 { 149 m_weights.swap( other.m_weights ); 150 m_names.swap( other.m_names ); 151 } 108 152 109 153 inline WeightContainer& WeightContainer::operator= … … 123 167 } 124 168 125 inline void WeightContainer::print( std::ostream& ostr ) const 169 inline WeightContainer::size_type WeightContainer::size() const { return m_weights.size(); } 170 171 inline bool WeightContainer::empty() const { return m_weights.empty(); } 172 173 inline void WeightContainer::clear() 126 174 { 127 for ( const_iterator w = begin(); w != end(); ++w ) 128 { 129 ostr << *w << " "; 130 } 131 ostr << std::endl; 132 } 133 134 inline int WeightContainer::size() const { return m_weights.size(); } 135 136 inline bool WeightContainer::empty() const { return m_weights.empty(); } 137 138 inline void WeightContainer::push_back( const double& value) 139 { m_weights.push_back(value); } 140 141 inline void WeightContainer::pop_back() { m_weights.pop_back(); } 142 143 inline void WeightContainer::clear() { m_weights.clear(); } 144 145 inline double& WeightContainer::operator[]( unsigned int n ) 146 { return m_weights[(int)n]; } 147 148 inline const double& WeightContainer::operator[]( unsigned int n ) const 149 { return m_weights[(int)n]; } 175 m_weights.clear(); 176 m_names.clear(); 177 } 178 179 inline double& WeightContainer::operator[]( size_type n ) 180 { return m_weights[n]; } 181 182 inline const double& WeightContainer::operator[]( size_type n ) const 183 { return m_weights[n]; } 150 184 151 185 inline double& WeightContainer::front() { return m_weights.front(); } … … 171 205 { return m_weights.end(); } 172 206 207 inline WeightContainer::map_iterator WeightContainer::map_begin() 208 { return m_names.begin(); } 209 210 inline WeightContainer::map_iterator WeightContainer::map_end() 211 { return m_names.end(); } 212 213 inline WeightContainer::const_map_iterator WeightContainer::map_begin() const 214 { return m_names.begin(); } 215 216 inline WeightContainer::const_map_iterator WeightContainer::map_end() const 217 { return m_names.end(); } 218 173 219 } // HepMC 174 220
Note:
See TracChangeset
for help on using the changeset viewer.