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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 return StatusCode::SUCCESS;
00072 }
00073
00074
00075
00076 StatusCode TofMcHitBuilder::initialize(string& initFile)
00077 {
00078 ifstream f;
00079
00080
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