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