BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcMcHitBuilder.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include "Identifier/MdcID.h"
5using namespace std;
6
8 :Builder()
9{
11}
12
13void MdcMcHitBuilder::unPack(vector<uint32_t>::const_iterator& iter,
14 vector<uint32_t>::const_iterator& eiter, MdcTruth_t& mt)
15{
16 uint32_t helpVal = *(iter++); assert(iter != eiter);
17 mt.edep = *(iter++); assert(iter != eiter);
18 mt.driftD = *(iter++); assert(iter != eiter);
19 mt.x = *(iter++); assert(iter != eiter);
20 mt.y = *(iter++); assert(iter != eiter);
21 mt.z = *(iter++);
22
23 mt.trackIndex = (helpVal & m_trackIndexMask) >> m_trackIndexIndex;
24 mt.layerId = (helpVal & m_layerIdMask) >> m_layerIdIndex;
25 mt.cellId = (helpVal & m_cellIdMask) >> m_cellIdIndex;
26 mt.posFlag = (helpVal & m_posFlagMask) ? 1 : 0 ;
27
28 return;
29}
30
31StatusCode MdcMcHitBuilder::pack(MdcMcHitCol* mdcMcHitCol, WriteRawEvent*& re)
32{
33/*
34 if (mdcMcHitCol == NULL) {
35 cout << "MdcMcHitBuilder::pack cant get MdcMcHitCol" << endl;
36 return StatusCode::FAILURE;
37 }
38
39 MdcTruth_t m_MdcTruth;
40 vector<uint32_t> *mdcReMcHitVec = new vector<uint32_t>;
41
42 MdcMcHitCol::const_iterator pMdcMcHit = mdcMcHitCol->begin();
43 for ( ; pMdcMcHit != mdcMcHitCol->end(); pMdcMcHit++) {
44 // Make MdcTruth data
45 makeMdcTruth(pMdcMcHit, m_MdcTruth);
46 // pack the trackIndex, layerId and cellId.
47 uint32_t helpVal = (m_MdcTruth.trackIndex<<m_trackIndexIndex) & m_trackIndexMask;
48 helpVal |= ((m_MdcTruth.layerId<<m_layerIdIndex) & m_layerIdMask);
49 helpVal |= ((m_MdcTruth.cellId<<m_cellIdIndex) & m_cellIdMask);
50 if (m_MdcTruth.posFlag) helpVal |= ((0x1<<m_posFlagIndex) & m_posFlagMask);
51 //fill the McHit Vector
52 mdcReMcHitVec->push_back(helpVal);
53 mdcReMcHitVec->push_back(m_MdcTruth.edep);
54 mdcReMcHitVec->push_back(m_MdcTruth.driftD);
55 mdcReMcHitVec->push_back(m_MdcTruth.x);
56 mdcReMcHitVec->push_back(m_MdcTruth.y);
57 mdcReMcHitVec->push_back(m_MdcTruth.z);
58 }
59
60 OfflineEventFormat::SubDetectorHeader sh(OfflineEventFormat::MDCTRUTH);
61 SubRawEvent *sub = new SubRawEvent(sh, mdcReMcHitVec);
62 re->append(sub);
63 */
64
65 return StatusCode::SUCCESS;
66}
67
68// initialize re2te tables
69
70StatusCode MdcMcHitBuilder::initialize(string& initFile)
71{
72 ifstream f;
73
74 //read init file
75 f.open(initFile.c_str());
76
77 if ( f.bad() ) {
78 cerr << "Error: could not open file " << initFile << endl;
79 return StatusCode::FAILURE;
80 }
81
82 if (!Builder::find( f, "##MdcTruthConf", initFile)) {
83 cerr << "Error: could not find '##MdcTruthConf' in file " << initFile << endl;
84 return StatusCode::FAILURE;
85 }
86
87 if ( !Builder::expect( f, "#MdcTruthShift", initFile) ||
88 !Builder::expectInt( f, "trackIndex", initFile, m_trackIndexIndex, m_trackIndexMask) ||
89 !Builder::expectInt( f, "layerId", initFile, m_layerIdIndex, m_layerIdMask) ||
90 !Builder::expectInt( f, "cellId", initFile, m_cellIdIndex, m_cellIdMask) ||
91 !Builder::expectInt( f, "posFlag", initFile, m_posFlagIndex, m_posFlagMask) ||
92 !Builder::expect( f, "#MdcTruthCoeff", initFile) ||
93 !Builder::expectLong( f, "edep", initFile, m_edepCoeff) ||
94 !Builder::expectLong( f, "driftD", initFile, m_driftDCoeff) ||
95 !Builder::expectLong( f, "x", initFile, m_xCoeff) ||
96 !Builder::expectLong( f, "y", initFile, m_yCoeff) ||
97 !Builder::expectLong( f, "z", initFile, m_zCoeff) )
98 return StatusCode::FAILURE;
99
100 f.close();
101
102 return StatusCode::SUCCESS;
103}
104
105
106uint32_t MdcMcHitBuilder::getTEID(uint32_t reid)
107{
108 return 0;
109}
110
111
112uint32_t MdcMcHitBuilder::getREID(uint32_t teid)
113{
114 return 0;
115}
116
117void MdcMcHitBuilder::makeMdcTruth
118(MdcMcHitCol::const_iterator& iter, MdcTruth_t& mt)
119{
120 Identifier ident = (*iter)->identify();
121
122 mt.trackIndex = (*iter)->getTrackIndex();
123 mt.layerId = MdcID::layer(ident);
124 mt.cellId = MdcID::wire(ident);
125 mt.edep = int((*iter)->getDepositEnergy() * m_edepCoeff);
126 mt.driftD = int((*iter)->getDriftDistance() * m_driftDCoeff);
127 mt.x = int((*iter)->getPositionX() * m_xCoeff);
128 mt.y = int((*iter)->getPositionY() * m_yCoeff);
129 mt.z = int((*iter)->getPositionZ() * m_zCoeff);
130 mt.posFlag = (*iter)->getPositionFlag();
131
132 return;
133}
134
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
static bool find(ifstream &f, string msg, string fname)
Definition: Builder.cxx:60
static bool expect(ifstream &f, string msg, string fname)
Definition: Builder.cxx:28
static bool expectLong(ifstream &f, string msg, string fname, uint64_t &val)
Definition: Builder.cxx:52
static bool expectInt(ifstream &f, string msg, string fname, uint32_t &val1, uint32_t &val2)
Definition: Builder.cxx:44
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition: MdcID.cxx:49
static int wire(const Identifier &id)
Definition: MdcID.cxx:54
virtual StatusCode initialize(string &initFile)
virtual StatusCode pack(MdcMcHitCol *mdcMcHitCol, WriteRawEvent *&re)
virtual uint32_t getREID(uint32_t reid)
uint64_t m_driftDCoeff
virtual uint32_t getTEID(uint32_t teid)
uint64_t m_edepCoeff
virtual void unPack(vector< uint32_t >::const_iterator &, vector< uint32_t >::const_iterator &, MdcTruth_t &)