BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
TofMcHitBuilder.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include "Identifier/TofID.h"
5using namespace std;
6
8 :Builder()
9{
11}
12
13void TofMcHitBuilder::unPack(vector<uint32_t>::const_iterator& iter,
14 vector<uint32_t>::const_iterator& eiter, TofTruth_t& tt)
15{
16 uint32_t helpVal = *(iter++); assert(iter != eiter);
17 tt.x = *(iter++); assert(iter != eiter);
18 tt.y = *(iter++); assert(iter != eiter);
19 tt.z = *(iter++); assert(iter != eiter);
20 tt.px = *(iter++); assert(iter != eiter);
21 tt.py = *(iter++); assert(iter != eiter);
22 tt.pz = *(iter++); assert(iter != eiter);
23 tt.trackLength= *(iter++); assert(iter != eiter);
24 tt.time = *(iter++);
25
26 tt.trackIndex = (helpVal&m_trackIndexMask) >> m_trackIndexIndex;
27 tt.partId = (helpVal&m_partIdMask) >> m_partIdIndex;
28 tt.scinNb = (helpVal&m_scinNbMask) >> m_scinNbIndex;
29
30 return;
31}
32
33
34StatusCode TofMcHitBuilder::pack(TofMcHitCol* tofMcHitCol, WriteRawEvent*& re)
35{
36/*
37 if (tofMcHitCol == NULL) {
38 cout << "TofMcHitBuilder::pack cant get TofMcHitCol" << endl;
39 return StatusCode::FAILURE;
40 }
41
42 vector<uint32_t> *tofReMcHitVec = new vector<uint32_t>;
43 TofTruth_t m_TofTruth;
44
45 TofMcHitCol::const_iterator pTofMcHit = tofMcHitCol->begin();
46 for ( ; pTofMcHit != tofMcHitCol->end(); pTofMcHit++) {
47 // make TofTruth_t data
48 makeTofTruth(pTofMcHit, m_TofTruth);
49 //pack the int numbers
50 uint32_t helpVal = (m_TofTruth.trackIndex<<m_trackIndexIndex) & m_trackIndexMask;
51 helpVal |= ((m_TofTruth.partId<<m_partIdIndex) & m_partIdMask);
52 helpVal |= ((m_TofTruth.scinNb<<m_scinNbIndex) & m_scinNbMask);
53 //fill the McHit vector
54 tofReMcHitVec->push_back(helpVal);
55 tofReMcHitVec->push_back(m_TofTruth.x);
56 tofReMcHitVec->push_back(m_TofTruth.y);
57 tofReMcHitVec->push_back(m_TofTruth.z);
58 tofReMcHitVec->push_back(m_TofTruth.px);
59 tofReMcHitVec->push_back(m_TofTruth.py);
60 tofReMcHitVec->push_back(m_TofTruth.pz);
61 tofReMcHitVec->push_back(m_TofTruth.trackLength);
62 tofReMcHitVec->push_back(m_TofTruth.time);
63 }
64
65 OfflineEventFormat::SubDetectorHeader sh(OfflineEventFormat::TOFTRUTH);
66 SubRawEvent *sub = new SubRawEvent(sh, tofReMcHitVec);
67 re->append(sub);
68*/
69
70 return StatusCode::SUCCESS;
71}
72
73// initialize re2te tables
74
75StatusCode TofMcHitBuilder::initialize(string& initFile)
76{
77 ifstream f;
78
79 //read init file
80 f.open(initFile.c_str());
81
82 if ( f.bad() ) {
83 cerr << "Error: could not open file " << initFile << endl;
84 return StatusCode::FAILURE;
85 }
86
87 if (!Builder::find( f, "##TofTruthConf", initFile)) {
88 cerr << "Error: could not find '##TofTruthConf' in file " << initFile << endl;
89 return StatusCode::FAILURE;
90 }
91
92 if ( !Builder::expect( f, "#TofTruthShift", initFile) ||
93 !Builder::expectInt( f, "trackIndex", initFile, m_trackIndexIndex, m_trackIndexMask) ||
94 !Builder::expectInt( f, "partId", initFile, m_partIdIndex, m_partIdMask) ||
95 !Builder::expectInt( f, "scinNb", initFile, m_scinNbIndex, m_scinNbMask) ||
96 !Builder::expect( f, "#TofTruthCoeff", initFile) ||
97 !Builder::expectLong( f, "x", initFile, m_xCoeff) ||
98 !Builder::expectLong( f, "y", initFile, m_yCoeff) ||
99 !Builder::expectLong( f, "z", initFile, m_zCoeff) ||
100 !Builder::expectLong( f, "px", initFile, m_pxCoeff) ||
101 !Builder::expectLong( f, "py", initFile, m_pyCoeff) ||
102 !Builder::expectLong( f, "pz", initFile, m_pzCoeff) ||
103 !Builder::expectLong( f, "trackLength", initFile, m_trackLengthCoeff) ||
104 !Builder::expectLong( f, "time", initFile, m_timeCoeff) )
105 return StatusCode::FAILURE;
106
107 f.close();
108
109 return StatusCode::SUCCESS;
110}
111
112
113uint32_t TofMcHitBuilder::getTEID(uint32_t reid)
114{
115 return 0;
116}
117
118
119uint32_t TofMcHitBuilder::getREID(uint32_t teid)
120{
121 return 0;
122}
123
124void TofMcHitBuilder::makeTofTruth
125(TofMcHitCol::const_iterator& pTofMcHit, TofTruth_t& tt)
126{
127 Identifier ident = (*pTofMcHit)->identify();
128
129 uint32_t layer = TofID::layer(ident);
130 uint32_t scinNum = TofID::phi_module(ident);
131 //if (layer == 1) scinNum += 88;
132 if (TofID::is_barrel(layer)) scinNum += TofID::getPHI_BARREL_MAX() + 1;
133
134 tt.trackIndex = (*pTofMcHit)->getTrackIndex();
135 tt.partId = TofID::barrel_ec(ident);
136 tt.scinNb = scinNum;
137 tt.x = int((*pTofMcHit)->getPositionX() * m_xCoeff);
138 tt.y = int((*pTofMcHit)->getPositionY() * m_yCoeff);
139 tt.z = int((*pTofMcHit)->getPositionZ() * m_zCoeff);
140 tt.px = int((*pTofMcHit)->getPx() * m_pxCoeff);
141 tt.py = int((*pTofMcHit)->getPy() * m_pyCoeff);
142 tt.pz = int((*pTofMcHit)->getPz() * m_pzCoeff);
143 tt.trackLength= int((*pTofMcHit)->getTrackLength() * m_trackLengthCoeff);
144 tt.time = int((*pTofMcHit)->getFlightTime() * m_timeCoeff);
145
146 return;
147}
148
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 value_type getPHI_BARREL_MAX()
Definition: TofID.cxx:237
static bool is_barrel(const Identifier &id)
Test for barrel.
Definition: TofID.cxx:78
static int phi_module(const Identifier &id)
Definition: TofID.cxx:117
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: TofID.cxx:95
static int layer(const Identifier &id)
Definition: TofID.cxx:109
virtual uint32_t getREID(uint32_t reid)
virtual StatusCode initialize(string &initFile)
virtual void unPack(vector< uint32_t >::const_iterator &, vector< uint32_t >::const_iterator &, TofTruth_t &)
uint64_t m_trackLengthCoeff
uint64_t m_timeCoeff
virtual StatusCode pack(TofMcHitCol *tofMcHitCol, WriteRawEvent *&re)
virtual uint32_t getTEID(uint32_t teid)