BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcMcHitBuilder.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include "Identifier/EmcID.h"
5using namespace std;
6
8 :Builder()
9{
11}
12
13void EmcMcHitBuilder::unPack(vector<uint32_t>::const_iterator& iter,
14 vector<uint32_t>::const_iterator& eiter, EmcTruth_t& et)
15{
16 uint32_t helpVal = *(iter++); assert(iter != eiter);
17 et.x = *(iter++); assert(iter != eiter);
18 et.y = *(iter++); assert(iter != eiter);
19 et.z = *(iter++); assert(iter != eiter);
20 et.px = *(iter++); assert(iter != eiter);
21 et.py = *(iter++); assert(iter != eiter);
22 et.pz = *(iter++); assert(iter != eiter);
23 et.totalEdep = *(iter++);
24
25 et.trackIndex = (helpVal&m_trackIndexMask) >> m_trackIndexIndex;
26 et.partId = (helpVal&m_partIdMask) >> m_partIdIndex;
27 et.numTheta = (helpVal&m_numThetaMask) >> m_numThetaIndex;
28 et.numPhi = (helpVal&m_numPhiMask) >> m_numPhiIndex;
29
30 return;
31}
32
33
34StatusCode EmcMcHitBuilder::pack(EmcMcHitCol* emcMcHitCol, WriteRawEvent*& re)
35{
36 /*
37 if (emcMcHitCol == NULL) {
38 cout << "EmcMcHitBuilder::pack cant get EmcMcHitCol" << endl;
39 return StatusCode::FAILURE;
40 }
41
42 vector<uint32_t> *emcReMcHitVec = new vector<uint32_t>;
43 EmcTruth_t m_EmcTruth;
44
45 EmcMcHitCol::const_iterator pEmcMcHit = emcMcHitCol->begin();
46 for ( ; pEmcMcHit != emcMcHitCol->end(); pEmcMcHit++) {
47 // Make the EmcTruth Data
48 makeEmcTruth(pEmcMcHit, m_EmcTruth);
49 // pack
50 uint32_t helpVal = (m_EmcTruth.trackIndex<<m_trackIndexIndex) & m_trackIndexMask;
51 helpVal |= ((m_EmcTruth.partId<<m_partIdIndex) & m_partIdMask);
52 helpVal |= ((m_EmcTruth.numTheta<<m_numThetaIndex) & m_numThetaMask);
53 helpVal |= ((m_EmcTruth.numPhi<<m_numPhiIndex) & m_numPhiMask);
54 // fill the McHit vector
55 emcReMcHitVec->push_back(helpVal);
56 emcReMcHitVec->push_back(m_EmcTruth.x);
57 emcReMcHitVec->push_back(m_EmcTruth.y);
58 emcReMcHitVec->push_back(m_EmcTruth.z);
59 emcReMcHitVec->push_back(m_EmcTruth.px);
60 emcReMcHitVec->push_back(m_EmcTruth.py);
61 emcReMcHitVec->push_back(m_EmcTruth.pz);
62 emcReMcHitVec->push_back(m_EmcTruth.totalEdep);
63 }
64
65 OfflineEventFormat::SubDetectorHeader sh(OfflineEventFormat::EMCTRUTH);
66 SubRawEvent *sub = new SubRawEvent(sh, emcReMcHitVec);
67 re->append(sub);
68 */
69
70 return StatusCode::SUCCESS;
71}
72
73// initialize re2te tables
74
75StatusCode EmcMcHitBuilder::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, "##EmcTruthConf", initFile)) {
88 cerr << "Error: could not find '##EmcTruthConf' in file " << initFile << endl;
89 return StatusCode::FAILURE;
90 }
91
92 if ( !Builder::expect( f, "#EmcTruthShift", 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, "numTheta", initFile, m_numThetaIndex, m_numThetaMask) ||
96 !Builder::expectInt( f, "numPhi", initFile, m_numPhiIndex, m_numPhiMask) ||
97 !Builder::expect( f, "#EmcTruthCoeff", initFile) ||
98 !Builder::expectLong( f, "x", initFile, m_xCoeff) ||
99 !Builder::expectLong( f, "y", initFile, m_yCoeff) ||
100 !Builder::expectLong( f, "z", initFile, m_zCoeff) ||
101 !Builder::expectLong( f, "px", initFile, m_pxCoeff) ||
102 !Builder::expectLong( f, "py", initFile, m_pyCoeff) ||
103 !Builder::expectLong( f, "pz", initFile, m_pzCoeff) ||
104 !Builder::expectLong( f, "totalEdep", initFile, m_totalEdepCoeff) )
105 return StatusCode::FAILURE;
106
107 f.close();
108
109 return StatusCode::SUCCESS;
110}
111
112
113uint32_t EmcMcHitBuilder::getTEID(uint32_t reid)
114{
115 return 0;
116}
117
118
119uint32_t EmcMcHitBuilder::getREID(uint32_t teid)
120{
121 return 0;
122}
123
124void EmcMcHitBuilder::makeEmcTruth
125(EmcMcHitCol::const_iterator& pEmcMcHit, EmcTruth_t& et)
126{
127 Identifier ident = (*pEmcMcHit)->identify();
128
129 et.trackIndex = (*pEmcMcHit)->getTrackIndex();
130 et.partId = EmcID::barrel_ec(ident);
131 et.numTheta = EmcID::theta_module(ident);
132 et.numPhi = EmcID::phi_module(ident);
133 et.x = int((*pEmcMcHit)->getPositionX() * m_xCoeff);
134 et.y = int((*pEmcMcHit)->getPositionY() * m_yCoeff);
135 et.z = int((*pEmcMcHit)->getPositionZ() * m_zCoeff);
136 et.px = int((*pEmcMcHit)->getPx() * m_pxCoeff);
137 et.py = int((*pEmcMcHit)->getPy() * m_pyCoeff);
138 et.pz = int((*pEmcMcHit)->getPz() * m_pzCoeff);
139 et.totalEdep = int((*pEmcMcHit)->getDepositEnergy() * m_totalEdepCoeff);
140
141 return;
142}
143
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
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 unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: EmcID.cxx:38
static unsigned int theta_module(const Identifier &id)
Definition: EmcID.cxx:43
static unsigned int phi_module(const Identifier &id)
Definition: EmcID.cxx:48
virtual StatusCode pack(EmcMcHitCol *emcMcHitCol, WriteRawEvent *&re)
virtual uint32_t getTEID(uint32_t teid)
virtual void unPack(vector< uint32_t >::const_iterator &, vector< uint32_t >::const_iterator &, EmcTruth_t &)
uint64_t m_totalEdepCoeff
virtual uint32_t getREID(uint32_t reid)
virtual StatusCode initialize(string &initFile)