CMS 3D CMS Logo

HepMCProduct.cc

Go to the documentation of this file.
00001 /*************************
00002  *
00003  *  Date: 2005/08 $
00004  *  \author J Weng - F. Moortgat'
00005  */
00006 
00007 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00008 #include <iostream>
00009 #include <algorithm> // because we use std::swap
00010 
00011 //#include "CLHEP/Vector/ThreeVector.h"
00012 
00013 using namespace edm;
00014 using namespace std;
00015 
00016 HepMCProduct::HepMCProduct( HepMC::GenEvent * evt ) {
00017     evt_ = evt;
00018     cout << "Contructing HepMCProduct" << endl;
00019     
00020     //note: this is not quite safe, because GenEvent does NOT
00021     //      know if vertex smearing applied or nor - only the
00022     //      HepMCProduct itself knows !
00023     // isVtxGenApplied_ = 0 ;  // ???
00024 }
00025 
00026 HepMCProduct::~HepMCProduct(){
00027 
00028         delete evt_; evt_ = 0; isVtxGenApplied_ = false;
00029         isVtxBoostApplied_ = false;
00030         isPBoostApplied_ = false;
00031 }
00032 
00033 
00034 void HepMCProduct::addHepMCData( HepMC::GenEvent  *evt){
00035   //  evt->print();
00036   // cout <<sizeof (evt)  <<"  " << sizeof ( HepMC::GenEvent)   << endl;
00037   evt_ = evt;
00038   
00039   // same story about vertex smearing - GenEvent won't know it...
00040   // in fact, would be better to implement CmsGenEvent...
00041   
00042 }
00043 
00044 void HepMCProduct::applyVtxGen( HepMC::FourVector* vtxShift ) const
00045 {
00046         //std::cout<< " applyVtxGen called " << isVtxGenApplied_ << endl;
00047 
00048    if ( isVtxGenApplied() ) return ;
00049       
00050    for ( HepMC::GenEvent::vertex_iterator vt=evt_->vertices_begin();
00051                                           vt!=evt_->vertices_end(); ++vt )
00052    {
00053             
00054       double x = (*vt)->position().x() + vtxShift->x() ;
00055       double y = (*vt)->position().y() + vtxShift->y() ;
00056       double z = (*vt)->position().z() + vtxShift->z() ;
00057       // for now, (re)set time exactly as it comes from the generator
00058       double t = (*vt)->position().t() ;
00059       //std::cout << " vertex (x,y,z)= " << x <<" " << y << " " << z << std::endl;
00060       (*vt)->set_position( HepMC::FourVector(x,y,z,t) ) ;      
00061    }
00062       
00063    isVtxGenApplied_ = true ;
00064    
00065    return ;
00066 
00067 } 
00068 
00069 void HepMCProduct::boostToLab( TMatrixD* lorentz, std::string type ) const {
00070 
00071         //std::cout << "from boostToLab:" << std::endl;
00072         
00073   
00074   
00075         if ( lorentz == 0 ) {
00076 
00077                 //std::cout << " lorentz = 0 " << std::endl;
00078                 return;
00079         }
00080 
00081         //lorentz->Print();
00082 
00083   TMatrixD tmplorentz(*lorentz);
00084   //tmplorentz.Print();
00085   
00086         if ( type == "vertex") {
00087 
00088                 if ( isVtxBoostApplied() ) {
00089                         //std::cout << " isVtxBoostApplied true " << std::endl;
00090                         return ;
00091                 }
00092                 
00093                 for ( HepMC::GenEvent::vertex_iterator vt=evt_->vertices_begin();
00094                           vt!=evt_->vertices_end(); ++vt ) {
00095 
00096                         // change basis to lorentz boost definition: (t,x,z,y)
00097                         TMatrixD p4(4,1);
00098                         p4(0,0) = (*vt)->position().t();
00099                         p4(1,0) = (*vt)->position().x();
00100                         p4(2,0) = (*vt)->position().z();
00101                         p4(3,0) = (*vt)->position().y();
00102 
00103                         TMatrixD p4lab(4,1);
00104                         p4lab = tmplorentz * p4;
00105                         //std::cout << " vertex lorentz: " << p4lab(1,0) << " " << p4lab(3,0) << " " << p4lab(2,0) << std::endl;
00106                         (*vt)->set_position( HepMC::FourVector(p4lab(1,0),p4lab(3,0),p4lab(2,0), p4lab(0,0) ) ) ;      
00107                 }
00108       
00109                 isVtxBoostApplied_ = true ;
00110         }
00111         else if ( type == "momentum") {
00112                 
00113                 if ( isPBoostApplied() ) {
00114                         //std::cout << " isPBoostApplied true " << std::endl;
00115                         return ;
00116                 }
00117                 
00118                 for ( HepMC::GenEvent::particle_iterator part=evt_->particles_begin();
00119                           part!=evt_->particles_end(); ++part ) {
00120 
00121                         // change basis to lorentz boost definition: (E,Px,Pz,Py)
00122                         TMatrixD p4(4,1);
00123                         p4(0,0) = (*part)->momentum().e();
00124                         p4(1,0) = (*part)->momentum().x();
00125                         p4(2,0) = (*part)->momentum().z();
00126                         p4(3,0) = (*part)->momentum().y();
00127 
00128                         TMatrixD p4lab(4,1);
00129                         p4lab = tmplorentz * p4;
00130                         //std::cout << " momentum lorentz: " << p4lab(1,0) << " " << p4lab(3,0) << " " << p4lab(2,0) << std::endl;
00131                         (*part)->set_momentum( HepMC::FourVector(p4lab(1,0),p4lab(3,0),p4lab(2,0),p4lab(0,0) ) ) ;      
00132                 }
00133       
00134                 isPBoostApplied_ = true ;
00135         }
00136         else {
00137                 std::cout << " no type found for boostToLab(std::string), options are vertex or momentum" << std::endl;
00138         }
00139                 
00140                  
00141         return ;
00142 }
00143 
00144 
00145 const HepMC::GenEvent&  
00146 HepMCProduct::getHepMCData()const   {
00147 
00148   return  * evt_;
00149 }
00150 
00151 // copy constructor
00152 HepMCProduct::HepMCProduct(HepMCProduct const& other) :
00153   evt_(0) {
00154   
00155    if (other.evt_) evt_=new HepMC::GenEvent(*other.evt_);
00156    isVtxGenApplied_ = other.isVtxGenApplied_ ;
00157    isVtxBoostApplied_ = other.isVtxBoostApplied_;
00158    isPBoostApplied_ = other.isPBoostApplied_;
00159 }
00160 
00161 // swap
00162 void
00163 HepMCProduct::swap(HepMCProduct& other) {
00164   std::swap(evt_, other.evt_);
00165   std::swap(isVtxGenApplied_, other.isVtxGenApplied_);
00166   std::swap(isVtxBoostApplied_, other.isVtxBoostApplied_);
00167   std::swap(isPBoostApplied_, other.isPBoostApplied_);
00168   
00169 }
00170 
00171 // assignment: use copy/swap idiom for exception safety.
00172 HepMCProduct&
00173 HepMCProduct::operator=(HepMCProduct const& other) {
00174   HepMCProduct temp(other);
00175   swap(temp);
00176   return *this;
00177 } 

Generated on Tue Jun 9 17:46:46 2009 for CMSSW by  doxygen 1.5.4