CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
McParticleBuilder.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
4using namespace std;
5
7 :Builder()
8{
9 //initialize(Builder::m_confFile);
10}
11
12void McParticleBuilder::unPack(uint32_t* buf, double* vPointer, McParticle* mcPar)
13{
14 uint32_t trkIndex = (buf[0]>>16);
15 uint32_t vIndex0 = (buf[0]>>8) & 0xFF;
16 uint32_t vIndex1 = buf[0] & 0xFF;
17
18 double* ptmp = (double*)(buf+3);
19 double* v0Pointer = vPointer + 4*vIndex0;
20 HepLorentzVector initMomentum(ptmp[0], ptmp[1], ptmp[2], ptmp[3]);
21 HepLorentzVector initPosition(v0Pointer[0], v0Pointer[1], v0Pointer[2], v0Pointer[3]);
22
23 mcPar->initialize(buf[1], buf[2], initMomentum, initPosition, "");
24 mcPar->setTrackIndex(trkIndex);
25 mcPar->setVertexIndex0(vIndex0);
26
27 if (vIndex1 == 0xFF) {
28 mcPar->setVertexIndex1(-99);
29 }
30 else {
31 mcPar->setVertexIndex1(vIndex1);
32
33 double* v1Pointer = vPointer + 4*vIndex1;
34 HepLorentzVector finalPosition(v1Pointer[0], v1Pointer[1], v1Pointer[2], v1Pointer[3]);
35 mcPar->finalize(finalPosition);
36 }
37
38 return;
39}
40
41StatusCode McParticleBuilder::pack(McParticleCol* mcParticleCol, WriteRawEvent*& re)
42{
43 if (mcParticleCol == 0 ) {
44 cerr << "McParticleBuilder::pack can't get mcParticleCol" << endl;
45 return StatusCode::FAILURE;
46 }
47
48 uint32_t nParticle = mcParticleCol->size();
49 uint32_t nVertex = 0;
50 vector<bool> vFlag(nParticle+1, false);
51 double* vPointer = (double*)(m_buf + nParticle*11 + 1);
52
53 uint32_t index = 0;
54 int tIndex, vIndex0, vIndex1;
55 int parId;
56 uint32_t statusFlag;
57
58 m_buf[index++] = (nParticle<<16);
59
60 McParticleCol::const_iterator itPar = mcParticleCol->begin();
61 for( ; itPar != mcParticleCol->end(); itPar++) {
62 tIndex = (*itPar)->trackIndex();
63 vIndex0 = (*itPar)->vertexIndex0();
64 vIndex1 = (*itPar)->vertexIndex1();
65 if (vIndex1 == -99) vIndex1 = 0xFF;
66 parId = (*itPar)->particleProperty();
67 statusFlag = (*itPar)->statusFlags();
68 const HepLorentzVector& p4vec = (*itPar)->initialFourMomentum();
69 m_buf[index++] = ((tIndex<<16) | (vIndex0<<8) | (vIndex1));
70 m_buf[index++] = (uint32_t)parId;
71 m_buf[index++] = statusFlag;
72 double* ptmp = (double*)(m_buf+index);
73 ptmp[0] = p4vec.x();
74 ptmp[1] = p4vec.y();
75 ptmp[2] = p4vec.z();
76 ptmp[3] = p4vec.t();
77 index += 8;
78
79 if ( !vFlag[vIndex0] ) {
80 const HepLorentzVector& initPos = (*itPar)->initialPosition();
81 vPointer[vIndex0*4 + 0] = initPos.px();
82 vPointer[vIndex0*4 + 1] = initPos.py();
83 vPointer[vIndex0*4 + 2] = initPos.pz();
84 vPointer[vIndex0*4 + 3] = initPos.e();
85 vFlag[vIndex0] = true;
86 nVertex++;
87 }
88
89 if ( (vIndex1 != 0xFF) && (!vFlag[vIndex1]) ) {
90 const HepLorentzVector& finalPos = (*itPar)->finalPosition();
91 vPointer[vIndex1*4 + 0] = finalPos.px();
92 vPointer[vIndex1*4 + 1] = finalPos.py();
93 vPointer[vIndex1*4 + 2] = finalPos.pz();
94 vPointer[vIndex1*4 + 3] = finalPos.e();
95 vFlag[vIndex1] = true;
96 nVertex++;
97 }
98 }
99
100 m_buf[0] |= nVertex;
101
102 append2event(re, 0xf10000, (nParticle*11 + nVertex*8 + 1));
103
104 return StatusCode::SUCCESS;
105}
106
107// initialize re2te tables
108
109StatusCode McParticleBuilder::initialize(string& initFile)
110{
111 ifstream f;
112
113 //read init file
114 f.open(initFile.c_str());
115
116 if ( f.bad() ) {
117 cerr << "Error: could not open file " << initFile << endl;
118 return StatusCode::FAILURE;
119 }
120
121 if (!Builder::find( f, "##McParticleConf", initFile)) {
122 cerr << "Error: could not find '##McParticleConf' in file " << initFile << endl;
123 return StatusCode::FAILURE;
124 }
125
126 f.close();
127
128 return StatusCode::SUCCESS;
129}
130
131
132uint32_t McParticleBuilder::getTEID(uint32_t /*reid*/)
133{
134 return 0;
135}
136
137
138uint32_t McParticleBuilder::getREID(uint32_t /*teid*/)
139{
140 return 0;
141}
void append2event(WriteRawEvent *&re, uint32_t source_id, uint32_t size)
Definition Builder.cxx:76
static bool find(ifstream &f, string msg, string fname)
Definition Builder.cxx:60
void setVertexIndex0(int index0)
methods for setting and getting vertex indexes
Definition McParticle.h:119
void initialize(StdHepId id, unsigned int statusBits, const HepLorentzVector &initialMomentum, const HepLorentzVector &initialPosition, const std::string process="")
Set the initial attributes of the McParticle.
void finalize(const HepLorentzVector &finalPosition)
Set the final attributes of the McParticle.
void setVertexIndex1(int index1)
Definition McParticle.h:123
void setTrackIndex(int trackIndex)
Definition McParticle.h:128
virtual void unPack(uint32_t *buf, double *vPointer, McParticle *mcPar)
virtual uint32_t getREID(uint32_t reid)
virtual uint32_t getTEID(uint32_t teid)
virtual StatusCode initialize(string &initFile)
virtual StatusCode pack(McParticleCol *mcParticleCol, WriteRawEvent *&re)
ObjectList< McParticle > McParticleCol
Definition McParticle.h:205