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

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include "Identifier/TofID.h"
00004 #include "RawDataCnv/EventManagement/TofMcHitBuilder.h"
00005 using namespace std;
00006 
00007 TofMcHitBuilder::TofMcHitBuilder()
00008    :Builder()
00009 {
00010   initialize(Builder::m_confFile);
00011 }
00012 
00013 void TofMcHitBuilder::unPack(vector<uint32_t>::const_iterator& iter,
00014              vector<uint32_t>::const_iterator& eiter, TofTruth_t& tt)
00015 {
00016   uint32_t helpVal = *(iter++); assert(iter != eiter);
00017   tt.x          = *(iter++); assert(iter != eiter);
00018   tt.y          = *(iter++); assert(iter != eiter);
00019   tt.z          = *(iter++); assert(iter != eiter);
00020   tt.px         = *(iter++); assert(iter != eiter);
00021   tt.py         = *(iter++); assert(iter != eiter);
00022   tt.pz         = *(iter++); assert(iter != eiter);
00023   tt.trackLength= *(iter++); assert(iter != eiter);
00024   tt.time       = *(iter++);
00025 
00026   tt.trackIndex = (helpVal&m_trackIndexMask) >> m_trackIndexIndex;
00027   tt.partId     = (helpVal&m_partIdMask) >> m_partIdIndex; 
00028   tt.scinNb     = (helpVal&m_scinNbMask) >> m_scinNbIndex;
00029   tt.strip      = (helpVal&m_stripMask)  >> m_stripIndex;
00030 
00031   return;
00032 }
00033 
00034 
00035 StatusCode TofMcHitBuilder::pack(TofMcHitCol* tofMcHitCol, WriteRawEvent*& re)
00036 {
00037 /*
00038   if (tofMcHitCol == NULL) {
00039     cout << "TofMcHitBuilder::pack cant get TofMcHitCol" << endl;
00040     return StatusCode::FAILURE;
00041   }
00042 
00043   vector<uint32_t> *tofReMcHitVec = new vector<uint32_t>;
00044   TofTruth_t m_TofTruth;
00045 
00046   TofMcHitCol::const_iterator pTofMcHit = tofMcHitCol->begin();
00047   for ( ; pTofMcHit != tofMcHitCol->end(); pTofMcHit++) {
00048     // make TofTruth_t data
00049     makeTofTruth(pTofMcHit, m_TofTruth);
00050     //pack the int numbers
00051     uint32_t helpVal = (m_TofTruth.trackIndex<<m_trackIndexIndex) & m_trackIndexMask;
00052     helpVal |= ((m_TofTruth.partId<<m_partIdIndex) & m_partIdMask);
00053     helpVal |= ((m_TofTruth.scinNb<<m_scinNbIndex) & m_scinNbMask);
00054     //fill the McHit vector
00055     tofReMcHitVec->push_back(helpVal);
00056     tofReMcHitVec->push_back(m_TofTruth.x);
00057     tofReMcHitVec->push_back(m_TofTruth.y);
00058     tofReMcHitVec->push_back(m_TofTruth.z);
00059     tofReMcHitVec->push_back(m_TofTruth.px);
00060     tofReMcHitVec->push_back(m_TofTruth.py);
00061     tofReMcHitVec->push_back(m_TofTruth.pz);
00062     tofReMcHitVec->push_back(m_TofTruth.trackLength);
00063     tofReMcHitVec->push_back(m_TofTruth.time);
00064   }
00065 
00066   OfflineEventFormat::SubDetectorHeader sh(OfflineEventFormat::TOFTRUTH);
00067   SubRawEvent *sub = new SubRawEvent(sh, tofReMcHitVec);
00068   re->append(sub);
00069 */
00070 
00071   return StatusCode::SUCCESS;
00072 }
00073 
00074 // initialize re2te tables
00075 
00076 StatusCode  TofMcHitBuilder::initialize(string& initFile)
00077 {
00078   ifstream f;
00079 
00080   //read init file
00081   f.open(initFile.c_str());
00082 
00083   if ( f.bad() ) {
00084     cerr   << "Error: could not open file " << initFile << endl;
00085     return StatusCode::FAILURE;
00086   }
00087 
00088   if (!Builder::find( f, "##TofTruthConf", initFile)) {
00089     cerr << "Error: could not find '##TofTruthConf' in file " << initFile << endl;
00090     return StatusCode::FAILURE;
00091   }
00092 
00093   if ( !Builder::expect( f, "#TofTruthShift", initFile) ||
00094        !Builder::expectInt( f, "trackIndex", initFile, m_trackIndexIndex, m_trackIndexMask) ||
00095        !Builder::expectInt( f, "partId", initFile, m_partIdIndex, m_partIdMask) ||
00096        !Builder::expectInt( f, "scinNb", initFile, m_scinNbIndex, m_scinNbMask) ||
00097        !Builder::expectInt( f, "strip",  initFile, m_stripIndex,  m_stripMask) ||
00098        !Builder::expect( f, "#TofTruthCoeff", initFile) ||
00099        !Builder::expectLong( f, "x", initFile, m_xCoeff) ||
00100        !Builder::expectLong( f, "y", initFile, m_yCoeff) ||
00101        !Builder::expectLong( f, "z", initFile, m_zCoeff) ||
00102        !Builder::expectLong( f, "px", initFile, m_pxCoeff) ||
00103        !Builder::expectLong( f, "py", initFile, m_pyCoeff) ||
00104        !Builder::expectLong( f, "pz", initFile, m_pzCoeff) ||
00105        !Builder::expectLong( f, "trackLength", initFile, m_trackLengthCoeff) ||
00106        !Builder::expectLong( f, "time", initFile, m_timeCoeff)   )
00107     return StatusCode::FAILURE;
00108 
00109   f.close();
00110 
00111   return StatusCode::SUCCESS;
00112 }
00113 
00114 
00115 uint32_t TofMcHitBuilder::getTEID(uint32_t reid)
00116 {
00117   return 0;
00118 }
00119 
00120  
00121 uint32_t TofMcHitBuilder::getREID(uint32_t teid)
00122 {
00123   return 0;
00124 }
00125 
00126 void TofMcHitBuilder::makeTofTruth
00127 (TofMcHitCol::const_iterator& pTofMcHit, TofTruth_t& tt)
00128 {
00129   Identifier ident = (*pTofMcHit)->identify();
00130   uint32_t partId  = TofID::barrel_ec(ident);
00131   uint32_t scinNum = 0;
00132   uint32_t strip   = 0;
00133 
00134   if( TofID::is_scin(ident) ) {
00135     uint32_t layer = TofID::layer(ident);
00136     scinNum = TofID::phi_module(ident);
00137     if (TofID::is_barrel(layer)) scinNum += TofID::getPHI_BARREL_MAX() + 1;
00138   }
00139   else if( TofID::is_mrpc(ident) ) {
00140     uint32_t endcap = TofID::endcap(ident);
00141     scinNum = TofID::module(ident);
00142     if( TofID::is_barrel(endcap) ) partId = 4;
00143     strip = TofID::strip(ident);
00144   }
00145 
00146   tt.trackIndex = (*pTofMcHit)->getTrackIndex();
00147   tt.partId     = partId;
00148   tt.scinNb     = scinNum;
00149   tt.strip      = strip;
00150   tt.x          = int((*pTofMcHit)->getPositionX() * m_xCoeff);
00151   tt.y          = int((*pTofMcHit)->getPositionY() * m_yCoeff);
00152   tt.z          = int((*pTofMcHit)->getPositionZ() * m_zCoeff);
00153   tt.px         = int((*pTofMcHit)->getPx() * m_pxCoeff);
00154   tt.py         = int((*pTofMcHit)->getPy() * m_pyCoeff);
00155   tt.pz         = int((*pTofMcHit)->getPz() * m_pzCoeff);
00156   tt.trackLength= int((*pTofMcHit)->getTrackLength() * m_trackLengthCoeff);
00157   tt.time       = int((*pTofMcHit)->getFlightTime() * m_timeCoeff);
00158 
00159   return;
00160 }
00161 

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