00001
00002 #include "CPPFORT/HEPEVT.h"
00003
00004 #include <cstdlib>
00005 #include <cmath>
00006 #include <iostream>
00007 using namespace std ;
00008
00009 using namespace lcio ;
00010
00011 namespace HEPEVTIMPL{
00012
00013 void HEPEVT::fromHepEvt(LCEvent * evt){
00014
00015 float* p = new float[3] ;
00016
00017
00018 LCCollectionVec* mcVec = new LCCollectionVec( LCIO::MCPARTICLE ) ;
00019
00020
00021
00022 int* NMCPART = &FTNhep.nhep;
00023 for(int j=0;j < *NMCPART;j++)
00024 {
00025 MCParticleImpl* mcp = new MCParticleImpl ;
00026 mcp->setPDG( FTNhep.idhep[j] ) ;
00027 mcp->setGeneratorStatus( FTNhep.isthep[j] ) ;
00028 mcp->setSimulatorStatus( 0 ) ;
00029
00030
00031 for(int k=0;k<3;k++) p[k] = (float)FTNhep.phep[j][k];
00032 mcp->setMomentum( p );
00033 mcp->setMass( (float)FTNhep.phep[j][4] ) ;
00034 mcp->setVertex( FTNhep.vhep[j] ) ;
00035
00036
00037 mcp->setCharge( FTNhep1.mcchargev[j] ) ;
00038
00039 mcVec->push_back( mcp ) ;
00040 }
00041
00042
00043
00044
00045
00046 for(int j=0;j < *NMCPART;j++) {
00047 MCParticleImpl* mcp = dynamic_cast<MCParticleImpl*>( mcVec->getElementAt( j ) ) ;
00048
00049
00050 int parent1 = FTNhep.jmohep[j][0] ;
00051 int parent2 = FTNhep.jmohep[j][1] ;
00052
00053 if( parent1 > 0 ) {
00054 MCParticle* mom = dynamic_cast<MCParticle*>( mcVec->getElementAt( parent1-1 ) ) ;
00055 mcp->addParent( mom ) ;
00056 if( parent2 > 0 )
00057 for(int i = parent1 ; i < parent2 ; i++ ){
00058 MCParticle* mom = dynamic_cast<MCParticle*>( mcVec->getElementAt( i ) ) ;
00059 mcp->addParent( mom ) ;
00060 }
00061 }
00062 }
00063
00064
00065 evt->addCollection( (LCCollection*) mcVec , "MCParticle" ) ;
00066
00067
00068 LCEventImpl* evtimpl = reinterpret_cast<LCEventImpl*>(evt) ;
00069 LCCollection* getmcVec = evtimpl->getCollection( "MCParticle" ) ;
00070 int nelem = getmcVec->getNumberOfElements() ;
00071 for(int j=0;j < nelem; j++)
00072 {
00073 FTNhep1.mcpointerv[j] = reinterpret_cast<PTRTYPE>( getmcVec->getElementAt( j ) ) ;
00074 }
00075
00076 delete p ;
00077 }
00078
00079
00080
00081 void HEPEVT::toHepEvt(const LCEvent* evt){
00082
00083 int* kmax = new int ;
00084 double* maxxyz = new double;
00085
00086
00087
00088 FTNhep.nevhep = evt->getEventNumber() ;
00089
00090
00091 LCCollection* mcVec = evt->getCollection( LCIO::MCPARTICLE ) ;
00092 FTNhep.nhep = mcVec->getNumberOfElements() ;
00093 int* NMCPART = &FTNhep.nhep ;
00094
00095 for(int j=0;j < *NMCPART;j++)
00096 {
00097
00098
00099 const MCParticle* mcp =
00100 dynamic_cast<const MCParticle*>( mcVec->getElementAt( j ) ) ;
00101
00102 FTNhep.idhep[j] = mcp->getPDG() ;
00103 FTNhep.isthep[j] = mcp->getGeneratorStatus() ;
00104
00105
00106 FTNhep.jmohep[j][0] = 0 ;
00107 FTNhep.jmohep[j][1] = 0 ;
00108 const MCParticle* mcpp = 0 ;
00109 int nparents = mcp->getParents().size() ;
00110 if( nparents > 0 ) mcpp = mcp->getParents()[0] ;
00111
00112 try{
00113 for(int jjm=0;jjm < *NMCPART;jjm++)
00114 {
00115 if (mcpp == dynamic_cast<const MCParticle*>(mcVec->getElementAt( jjm )) ){
00116 FTNhep.jmohep[j][0] = jjm + 1 ;
00117 break ;
00118 }
00119 }
00120 }catch(exception& e){
00121 }
00122 if ( FTNhep.jmohep[j][0] > 0 )
00123 {
00124 try{
00125 const MCParticle* mcpsp = 0 ;
00126 if( mcp->getParents().size() > 1 ) mcpsp = mcp->getParents()[ nparents-1 ] ;
00127
00128 for(int jjj=0;jjj < *NMCPART;jjj++)
00129 {
00130
00131 if (mcpsp == dynamic_cast<const MCParticle*>(mcVec->getElementAt( jjj )) ){
00132 FTNhep.jmohep[j][1] = jjj + 1 ;
00133 break ;
00134 }
00135 }
00136 }catch(exception& e){
00137 FTNhep.jmohep[j][1] = 0 ;
00138 }
00139 }
00140
00141
00142
00143 FTNhep.jdahep[j][0] = 0 ;
00144 FTNhep.jdahep[j][1] = 0 ;
00145
00146 if ( FTNhep.isthep[j] != 3 )
00147 {
00148 int ndaugthers = mcp->getDaughters().size() ;
00149
00150 if (ndaugthers > 0)
00151 {
00152 const MCParticle* mcpd = mcp->getDaughters()[0] ;
00153 for (int jjj=0; jjj < *NMCPART; jjj++)
00154 {
00155 const MCParticle* mcpdtest = dynamic_cast<const MCParticle*>(mcVec->getElementAt( jjj )) ;
00156 if ( mcpd == mcpdtest )
00157 {
00158 FTNhep.jdahep[j][0] = jjj + 1 ;
00159 FTNhep.jdahep[j][1] = FTNhep.jdahep[j][0] + ndaugthers -1 ;
00160 break ;
00161 }
00162 }
00163 }
00164 }
00165
00166
00167 for(int k=0;k<3;k++) FTNhep.phep[j][k] = (double)mcp->getMomentum()[k] ;
00168 FTNhep.phep[j][3] = (double)mcp->getEnergy() ;
00169 FTNhep.phep[j][4] = (double)mcp->getMass() ;
00170
00171
00172 *kmax = 0 ;
00173 *maxxyz = 0. ;
00174 for(int k=0;k<3;k++){
00175 FTNhep.vhep[j][k] = mcp->getVertex()[k] ;
00176 if ( fabs( FTNhep.vhep[j][k] ) > *maxxyz ){
00177 *maxxyz = fabs( FTNhep.vhep[j][k] ) ;
00178 *kmax = k ;
00179 }
00180 }
00181 if ( mcpp != 0 && *maxxyz > 0. )
00182 {
00183 FTNhep.vhep[j][3] = FTNhep.vhep[FTNhep.jmohep[j][0]-1][3]
00184 + (mcp->getVertex()[*kmax] - mcpp->getVertex()[*kmax]) * mcpp->getEnergy()
00185 / mcpp->getMomentum()[*kmax] ;
00186 }
00187 else
00188 {
00189 FTNhep.vhep[j][3] = 0. ;
00190 }
00191
00192
00193 FTNhep1.mcpointerv[j] = reinterpret_cast<PTRTYPE>( (mcp) ) ;
00194 FTNhep1.mcchargev[j] = mcp->getCharge() ;
00195 }
00196
00197 delete kmax ;
00198 delete maxxyz ;
00199 }
00200
00201 }
00202