/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RawDataCnv/RawDataCnv-00-04-35/src/EventManagement/McParticleBuilder.cxx

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include "RawDataCnv/EventManagement/McParticleBuilder.h"
00004 using namespace std;
00005 
00006 McParticleBuilder::McParticleBuilder()
00007    :Builder()
00008 {
00009   //initialize(Builder::m_confFile);
00010 }
00011 
00012 void McParticleBuilder::unPack(uint32_t* buf, double* vPointer, McParticle* mcPar)
00013 {
00014   uint32_t trkIndex = (buf[0]>>16);
00015   uint32_t vIndex0  = (buf[0]>>8) & 0xFF;
00016   uint32_t vIndex1  = buf[0] & 0xFF;
00017 
00018   double*  ptmp      = (double*)(buf+3);
00019   double*  v0Pointer = vPointer + 4*vIndex0;
00020   HepLorentzVector initMomentum(ptmp[0], ptmp[1], ptmp[2], ptmp[3]);
00021   HepLorentzVector initPosition(v0Pointer[0], v0Pointer[1], v0Pointer[2], v0Pointer[3]);
00022 
00023   mcPar->initialize(buf[1], buf[2], initMomentum, initPosition, "");
00024   mcPar->setTrackIndex(trkIndex);
00025   mcPar->setVertexIndex0(vIndex0);
00026 
00027   if (vIndex1 == 0xFF) {
00028     mcPar->setVertexIndex1(-99);
00029   }
00030   else {
00031     mcPar->setVertexIndex1(vIndex1);
00032 
00033     double* v1Pointer = vPointer + 4*vIndex1;
00034     HepLorentzVector finalPosition(v1Pointer[0], v1Pointer[1], v1Pointer[2], v1Pointer[3]);
00035     mcPar->finalize(finalPosition);
00036   }
00037 
00038   return;
00039 }
00040 
00041 StatusCode McParticleBuilder::pack(McParticleCol* mcParticleCol, WriteRawEvent*& re)
00042 {
00043   if (mcParticleCol == 0 ) {
00044     cerr << "McParticleBuilder::pack can't get mcParticleCol" << endl;
00045     return StatusCode::FAILURE;
00046   }
00047 
00048   uint32_t nParticle = mcParticleCol->size();
00049   uint32_t nVertex = 0;
00050   vector<bool> vFlag(nParticle+1, false);
00051   double*  vPointer = (double*)(m_buf + nParticle*11 + 1);
00052 
00053   uint32_t index = 0;
00054   int tIndex, vIndex0, vIndex1;
00055   int parId;
00056   uint32_t statusFlag;
00057 
00058   m_buf[index++] = (nParticle<<16);
00059 
00060   McParticleCol::const_iterator itPar = mcParticleCol->begin();
00061   for( ; itPar != mcParticleCol->end(); itPar++) {
00062     tIndex  = (*itPar)->trackIndex();
00063     vIndex0 = (*itPar)->vertexIndex0();
00064     vIndex1 = (*itPar)->vertexIndex1();
00065     if (vIndex1 == -99) vIndex1 = 0xFF;
00066     parId   = (*itPar)->particleProperty();
00067     statusFlag = (*itPar)->statusFlags();
00068     const HepLorentzVector& p4vec    = (*itPar)->initialFourMomentum();
00069     m_buf[index++] = ((tIndex<<16) | (vIndex0<<8) | (vIndex1));
00070     m_buf[index++] = (uint32_t)parId;
00071     m_buf[index++] = statusFlag;
00072     double* ptmp = (double*)(m_buf+index);
00073     ptmp[0] = p4vec.x();
00074     ptmp[1] = p4vec.y();
00075     ptmp[2] = p4vec.z();
00076     ptmp[3] = p4vec.t();
00077     index += 8;
00078 
00079     if ( !vFlag[vIndex0] ) {
00080       const HepLorentzVector& initPos  = (*itPar)->initialPosition();
00081       vPointer[vIndex0*4 + 0] = initPos.px();
00082       vPointer[vIndex0*4 + 1] = initPos.py();
00083       vPointer[vIndex0*4 + 2] = initPos.pz();
00084       vPointer[vIndex0*4 + 3] = initPos.e();
00085       vFlag[vIndex0] = true;
00086       nVertex++;
00087     }
00088 
00089     if ( (vIndex1 != 0xFF) && (!vFlag[vIndex1]) ) {
00090       const HepLorentzVector& finalPos = (*itPar)->finalPosition();
00091       vPointer[vIndex1*4 + 0] = finalPos.px();
00092       vPointer[vIndex1*4 + 1] = finalPos.py();
00093       vPointer[vIndex1*4 + 2] = finalPos.pz();
00094       vPointer[vIndex1*4 + 3] = finalPos.e();
00095       vFlag[vIndex1] = true;
00096       nVertex++;
00097     }
00098   }
00099 
00100   m_buf[0] |= nVertex;
00101 
00102   append2event(re, 0xf10000, (nParticle*11 + nVertex*8 + 1));
00103 
00104   return StatusCode::SUCCESS;
00105 }
00106 
00107 // initialize re2te tables
00108 
00109 StatusCode  McParticleBuilder::initialize(string& initFile)
00110 {
00111   ifstream f;
00112 
00113   //read init file
00114   f.open(initFile.c_str());
00115 
00116   if ( f.bad() ) {
00117     cerr   << "Error: could not open file " << initFile << endl;
00118     return StatusCode::FAILURE;
00119   }
00120 
00121   if (!Builder::find( f, "##McParticleConf", initFile)) {
00122     cerr << "Error: could not find '##McParticleConf' in file " << initFile << endl;
00123     return StatusCode::FAILURE;
00124   }
00125 
00126   f.close();                    
00127                                   
00128   return StatusCode::SUCCESS;     
00129 }
00130                                   
00131                                 
00132 uint32_t McParticleBuilder::getTEID(uint32_t /*reid*/)
00133 {
00134   return 0;
00135 }
00136 
00137  
00138 uint32_t McParticleBuilder::getREID(uint32_t /*teid*/)
00139 {
00140   return 0;
00141 }

Generated on Tue Nov 29 22:58:32 2016 for BOSS_7.0.2 by  doxygen 1.4.7