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