BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
McParticleCnv Class Reference

Concrete converter for the McParticle collection. More...

#include <McParticleCnv.h>

+ Inheritance diagram for McParticleCnv:

Public Member Functions

virtual ~McParticleCnv ()
 
- Public Member Functions inherited from RootEventBaseCnv
 RootEventBaseCnv (const CLID &clid, ISvcLocator *svc)
 
virtual ~RootEventBaseCnv ()
 
virtual long repSvcType () const
 
virtual StatusCode initialize ()
 
virtual StatusCode finalize ()
 
void declareObject (const std::string &fullPath, const CLID &clid, const std::string &treename, const std::string &branchname)
 Store TDS path to link a particular converter to an object on the TDS.
 
virtual StatusCode createObj (IOpaqueAddress *addr, DataObject *&dat)
 Convert the persistent object to transient.
 
virtual StatusCode createRep (DataObject *pObject, IOpaqueAddress *&refpAddress)
 Convert the transient object to the requested representation.
 
virtual StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Resolve the references of the converted object.
 
virtual StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Resolve the references of the converted object.
 
virtual StatusCode DataObjectToTObject (DataObject *dat, RootAddress *addr)=0
 Do the concrete conversion from TDS to ROOT.
 
virtual StatusCode TObjectToDataObject (DataObject *&dat)=0
 Do the concrete conversion from ROOT to TDS.
 
TObject * getReadObject () const
 get the object to be read
 
- Public Member Functions inherited from Converter< Ty1, Ty2 >
destinationoperator (const source &) const
 

Static Public Member Functions

static const CLID & classID ()
 
- Static Public Member Functions inherited from RootEventBaseCnv
static const unsigned char storageType ()
 Storage type and class ID.
 

Protected Member Functions

 McParticleCnv (ISvcLocator *svc)
 
virtual StatusCode DataObjectToTObject (DataObject *obj, RootAddress *addr)
 transformation to root
 
virtual StatusCode TObjectToDataObject (DataObject *&obj)
 transformation from root
 
- Protected Member Functions inherited from Converter< Ty1, Ty2 >
virtual destinationconvert (const source &) const =0
 

Friends

class CnvFactory< McParticleCnv >
 

Additional Inherited Members

- Public Types inherited from Converter< Ty1, Ty2 >
typedef Ty1 source
 
typedef Ty2 destination
 
- Protected Attributes inherited from RootEventBaseCnv
RootCnvSvcm_cnvSvc
 
std::vector< RootCnvSvc::Leafm_leaves
 
RootInterfacem_rootInterface
 pointer to the RootInterface
 
IDataProviderSvc * m_eds
 pointer to eventdataservice
 
int m_branchNr
 the branchNr of this converter for writing
 
int m_branchNrDst
 
int m_branchNrMc
 
int m_branchNrRecon
 
int m_branchNrEvtRec
 
int m_branchNrEvtHeader
 
int m_branchNrEvtNavigator
 
TObject * m_objRead
 the object that was read
 
CLID CLID_top
 the CLID of the upper converter if any
 
TArrayS * m_branchNumbers
 array with number of branches for reading
 
std::string m_rootBranchname
 root branchname (may be concatenated of severals)
 
std::string m_rootTreename
 each converter knows it's treename
 
std::string m_currentFileName
 
std::vector< void * > m_adresses
 each converter knows the corresponding adresses
 
RootEvtSelectorm_evtsel
 

Detailed Description

Concrete converter for the McParticle collection.

Definition at line 19 of file McParticleCnv.h.

Constructor & Destructor Documentation

◆ ~McParticleCnv()

virtual McParticleCnv::~McParticleCnv ( )
inlinevirtual

Definition at line 29 of file McParticleCnv.h.

29{ };

◆ McParticleCnv()

McParticleCnv::McParticleCnv ( ISvcLocator *  svc)
protected

Definition at line 25 of file McParticleCnv.cxx.

27{
28 // Here we associate this converter with the /Event path on the TDS.
29 MsgStream log(msgSvc(), "McParticleCnv");
30 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
31 m_rootBranchname ="m_mcParticleCol";
32 //declareObject(EventModel::MC::McParticleCol, objType(), m_rootTreename, m_rootBranchname);
33 m_adresses.push_back(&m_mcParticleCol);
34 m_mcParticleCol=0;
35}
IMessageSvc * msgSvc()
static const CLID & classID()
Definition: McParticleCnv.h:24
Base class for all Root Converters.
std::vector< void * > m_adresses
each converter knows the corresponding adresses
std::string m_rootBranchname
root branchname (may be concatenated of severals)

Member Function Documentation

◆ classID()

static const CLID & McParticleCnv::classID ( )
inlinestatic

Definition at line 24 of file McParticleCnv.h.

25 {
26 return CLID_McParticleCol;
27 }
const CLID & CLID_McParticleCol
Definition: EventModel.cxx:207

◆ DataObjectToTObject()

StatusCode McParticleCnv::DataObjectToTObject ( DataObject *  obj,
RootAddress addr 
)
protectedvirtual

transformation to root

Implements RootEventBaseCnv.

Definition at line 139 of file McParticleCnv.cxx.

139 {
140
141 MsgStream log(msgSvc(), "McParticleCnv");
142 log << MSG::DEBUG << "McParticleCnv::DataObjectToTObject" << endreq;
143 StatusCode sc=StatusCode::SUCCESS;
144
145 McParticleCol *mcParticleCnvTds=dynamic_cast<McParticleCol *> (obj);
146 if (!mcParticleCnvTds) {
147 log << MSG::ERROR << "Could not downcast to McParticleCol" << endreq;
148 return StatusCode::FAILURE;
149 }
150
151 DataObject *evt;
152 m_eds->findObject(EventModel::MC::Event,evt);
153 if (evt==NULL) {
154 log << MSG::ERROR << "Could not get McEvent in TDS " << endreq;
155 return StatusCode::FAILURE;
156 }
157 McEvent * devtTds=dynamic_cast<McEvent *> (evt);
158 if (!devtTds) {
159 log << MSG::ERROR << "McParticleCnv:Could not downcast to TDS McEvent" << endreq;
160 }
161 IOpaqueAddress *addr;
162
163 m_cnvSvc->getMcCnv()->createRep(evt,addr);
165
166 const TObjArray *m_mcParticleCol = McEvt->getMcParticleCol();
167 if (!m_mcParticleCol) { return sc; }
168 McEvt->clearMcParticleCol(); //necessary in case there is I/O at the same time since array is static
169
170 McParticleCol::const_iterator mcParticleTds;
171
172 for (mcParticleTds = mcParticleCnvTds->begin(); mcParticleTds != mcParticleCnvTds->end(); mcParticleTds++) {
173 Int_t particleID = (*mcParticleTds)->particleProperty();
174 Int_t trackIndex = (*mcParticleTds)->trackIndex();
175
176 Int_t vertexIndex0 = (*mcParticleTds)->vertexIndex0();
177 Int_t vertexIndex1 = (*mcParticleTds)->vertexIndex1();
178 Int_t statusFlags = (*mcParticleTds)->statusFlags();
179
180 HepLorentzVector initialPosition = (*mcParticleTds)->initialPosition();
181 HepLorentzVector finalPosition = (*mcParticleTds)->finalPosition();
182 HepLorentzVector initialFourMomentum = (*mcParticleTds)->initialFourMomentum();
183 //HepLorentzVector finalFourMomentum = (*mcParticleTds)->finalFourMomentum();
184
185 //cout << " HepID " << (*mcParticleTds)->particleProperty() << endl;
186 //cout << " init pos " << initialPosition.x() << " " << initialPosition.y() << " " << initialPosition.z() << endl;
187 Int_t mother = -99;
188 if(!(*mcParticleTds)->primaryParticle()) mother = ((*mcParticleTds)->mother()).trackIndex();
189
190 vector<Int_t> daughters;
191 SmartRefVector<McParticle> daughterList = (*mcParticleTds)->daughterList();
192 //SmartRefVector<McParticle>::iterator iter;
193 for (int iPar = 0; iPar < daughterList.size(); iPar++) {
194 //cout <<"daughter Index " <<daughterList[iPar]->getTrackIndex()<<endl;
195 daughters.push_back(daughterList[iPar]->trackIndex());
196 }
197 /*
198 for (int idau = 0; idau<daughters.size();idau++){
199 cout <<"daughter Index " <<daughters[idau]<<endl;
200 }
201
202 cout<<"###############################"<<endl;
203 */
204 TMcParticle *mcParticleRoot = new TMcParticle();
205 //m_common.m_mcParticleMap[(*mcParticleTds)] = mcParticleRoot;
206
207 mcParticleRoot->setParticleID(particleID);
208 mcParticleRoot->setTrackIndex(trackIndex);
209
210 mcParticleRoot->setVertexIndex0(vertexIndex0);
211 mcParticleRoot->setVertexIndex1(vertexIndex1);
212
213 mcParticleRoot->setStatusFlags(statusFlags);
214
215 mcParticleRoot->setInitialPositionX(initialPosition.x());
216 mcParticleRoot->setInitialPositionY(initialPosition.y());
217 mcParticleRoot->setInitialPositionZ(initialPosition.z());
218 mcParticleRoot->setInitialPositionT(initialPosition.t());
219
220 mcParticleRoot->setFinalPositionX(finalPosition.x());
221 mcParticleRoot->setFinalPositionY(finalPosition.y());
222 mcParticleRoot->setFinalPositionZ(finalPosition.z());
223 mcParticleRoot->setFinalPositionT(finalPosition.t());
224
225 mcParticleRoot->setInitialMomentumX(initialFourMomentum.x());
226 mcParticleRoot->setInitialMomentumY(initialFourMomentum.y());
227 mcParticleRoot->setInitialMomentumZ(initialFourMomentum.z());
228 mcParticleRoot->setInitialMomentumE(initialFourMomentum.e());
229
230 //mcParticleRoot->setFinalMomentumX(finalFourMomentum.x());
231 //mcParticleRoot->setFinalMomentumY(finalFourMomentum.y());
232 //mcParticleRoot->setFinalMomentumZ(finalFourMomentum.z());
233 //mcParticleRoot->setFinalMomentumE(finalFourMomentum.e());
234
235 mcParticleRoot->setMother(mother);
236 mcParticleRoot->setDaughters(daughters);
237 /*
238 vector<int> dau = mcParticleRoot->getDaughters();
239
240 for (int idau = 0; idau<daughters.size();idau++){
241 cout <<"daughter Index root " <<dau[idau]<<endl;
242 }
243 */
244
245 McEvt->addMcParticle(mcParticleRoot);
246 }
247 return StatusCode::SUCCESS;
248}
static TMcEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: McCnv.h:35
Definition: McEvent.h:8
McCnv * getMcCnv()
Definition: RootCnvSvc.h:156
RootCnvSvc * m_cnvSvc
IDataProviderSvc * m_eds
pointer to eventdataservice
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Convert the transient object to the requested representation.
void addMcParticle(TMcParticle *mcHit)
McParticle.
Definition: TMcEvent.cxx:148
const TObjArray * getMcParticleCol() const
Definition: TMcEvent.h:54
void clearMcParticleCol()
Definition: TMcEvent.h:57
void setInitialPositionT(Double_t positionT)
Definition: TMcParticle.h:131
void setFinalPositionZ(Double_t positionZ)
Definition: TMcParticle.h:135
void setStatusFlags(UInt_t statusFlags)
Definition: TMcParticle.h:126
void setInitialPositionX(Double_t positionX)
Definition: TMcParticle.h:128
void setFinalPositionY(Double_t positionY)
Definition: TMcParticle.h:134
void setInitialPositionY(Double_t positionY)
Definition: TMcParticle.h:129
void setMother(Int_t mother)
Definition: TMcParticle.h:149
void setInitialMomentumZ(Double_t momentumZ)
Definition: TMcParticle.h:140
void setInitialPositionZ(Double_t positionZ)
Definition: TMcParticle.h:130
void setVertexIndex1(Int_t vertexIndex1)
Definition: TMcParticle.h:125
void setInitialMomentumX(Double_t momentumX)
Definition: TMcParticle.h:138
void setTrackIndex(Int_t trackIndex)
Definition: TMcParticle.h:122
void setFinalPositionT(Double_t positionT)
Definition: TMcParticle.h:136
void setInitialMomentumE(Double_t momentumE)
Definition: TMcParticle.h:141
void setVertexIndex0(Int_t vertexIndex0)
Definition: TMcParticle.h:124
void setParticleID(Int_t particleID)
Definition: TMcParticle.h:121
void setFinalPositionX(Double_t positionX)
Definition: TMcParticle.h:133
void setInitialMomentumY(Double_t momentumY)
Definition: TMcParticle.h:139
void setDaughters(vector< Int_t > &daughters)
Definition: TMcParticle.h:150
_EXTERN_ std::string Event
Definition: EventModel.h:39
ObjectList< McParticle > McParticleCol
Definition: McParticle.h:205

◆ TObjectToDataObject()

StatusCode McParticleCnv::TObjectToDataObject ( DataObject *&  obj)
protectedvirtual

transformation from root

Implements RootEventBaseCnv.

Definition at line 37 of file McParticleCnv.cxx.

37 {
38 // creation of TDS object from root object
39
40 MsgStream log(msgSvc(), "McParticleCnv");
41 log << MSG::DEBUG << "McParticleCnv::TObjectToDataObject" << endreq;
42 StatusCode sc=StatusCode::SUCCESS;
43
44 // create the TDS location for the MdcMc Collection
45 McParticleCol* mcParticleTdsCol = new McParticleCol;
46 refpObject=mcParticleTdsCol;
47
48
49 // now convert
50 if (!m_mcParticleCol) return sc;
51 TIter mcParticleIter(m_mcParticleCol);
52 TMcParticle *mcParticleRoot = 0;
53
54 vector<int> mothers;
55 // vector<vector<int> > daughtList;
56
57 while ((mcParticleRoot = (TMcParticle*)mcParticleIter.Next())) {
58 unsigned int particleID = mcParticleRoot ->getParticleID();
59 unsigned int trackIndex = mcParticleRoot ->getTrackIndex();
60
61 int vertexIndex0 = mcParticleRoot ->getVertexIndex0();
62 int vertexIndex1 = mcParticleRoot ->getVertexIndex1();
63 unsigned int statusFlags = mcParticleRoot ->getStatusFlags();
64
65 double xInitialPosition = mcParticleRoot->getInitialPositionX();
66 double yInitialPosition = mcParticleRoot->getInitialPositionY();
67 double zInitialPosition = mcParticleRoot->getInitialPositionZ();
68 double tInitialPosition = mcParticleRoot->getInitialPositionT();
69
70 double xFinalPosition = mcParticleRoot->getFinalPositionX();
71 double yFinalPosition = mcParticleRoot->getFinalPositionY();
72 double zFinalPosition = mcParticleRoot->getFinalPositionZ();
73 double tFinalPosition = mcParticleRoot->getFinalPositionT();
74
75 double xInitialMomentum = mcParticleRoot->getInitialMomentumX();
76 double yInitialMomentum = mcParticleRoot->getInitialMomentumY();
77 double zInitialMomentum = mcParticleRoot->getInitialMomentumZ();
78 double eInitialMomentum = mcParticleRoot->getInitialMomentumE();
79
80 //double xFinalMomentum = mcParticleRoot->getFinalMomentumX();
81 //double yFinalMomentum = mcParticleRoot->getFinalMomentumY();
82 //double zFinalMomentum = mcParticleRoot->getFinalMomentumZ();
83 //double eFinalMomentum = mcParticleRoot->getFinalMomentumE();
84
85 HepLorentzVector initialMomentum(xInitialMomentum, yInitialMomentum, zInitialMomentum, eInitialMomentum);
86 HepLorentzVector initialPosition(xInitialPosition, yInitialPosition, zInitialPosition, tInitialPosition);
87 //HepLorentzVector finalMomentum(xFinalMomentum, yFinalMomentum, zFinalMomentum, eFinalMomentum);
88 HepLorentzVector finalPosition(xFinalPosition, yFinalPosition, zFinalPosition, tFinalPosition);
89
90
91 int mother = mcParticleRoot->getMother();
92 vector<int> daughters = mcParticleRoot->getDaughters();
93
94 mothers.push_back(mother);
95 //daughtList.push_back(daughters);
96
97 McParticle *mcParticleTds = new McParticle;
98 m_common.m_rootMcParticleMap[mcParticleRoot] = mcParticleTds;
99
100
101 mcParticleTds->initialize(particleID, statusFlags, initialMomentum, initialPosition);
102 mcParticleTds->setTrackIndex(trackIndex);
103 mcParticleTds->addStatusFlag(statusFlags);
104
105 mcParticleTds->setVertexIndex0(vertexIndex0);
106 mcParticleTds->setVertexIndex1(vertexIndex1);
107 //mcParticleTds->finalize(finalMomentum, finalPosition);
108 mcParticleTds->finalize(finalPosition);
109
110 mcParticleTdsCol->push_back(mcParticleTds);
111 }
112
113 //Set Mother and DaughterList
114 McParticleCol::iterator iter;
115 int i =0;
116 for (iter = mcParticleTdsCol->begin(); iter != mcParticleTdsCol->end(); iter++,i++){
117 //cout<<" ***** mothers[ "<<i<<"] = "<<mothers[i]<<endl;
118 if(mothers[i] != -99 ){
119 McParticleCol::iterator mcParticleTds;
120 for (mcParticleTds = mcParticleTdsCol->begin(); mcParticleTds != mcParticleTdsCol->end(); mcParticleTds++) {
121 int trackIndex = (*mcParticleTds)->trackIndex();
122 if( trackIndex == mothers[i] ){
123 (*iter)->setMother(*mcParticleTds);
124 (*mcParticleTds)->addDaughter(*iter);
125 break;
126 }
127 }
128 }
129 else{
130 (*iter)->setMother(*iter);
131 }
132 }
133 //m_mcParticleCol->Delete(); // wensp add 2005/12/30
134 delete m_mcParticleCol;
135 m_mcParticleCol = 0;
136 return StatusCode::SUCCESS;
137}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
void setVertexIndex0(int index0)
methods for setting and getting vertex indexes
Definition: McParticle.h:119
int trackIndex() const
Definition: McParticle.h:131
void initialize(StdHepId id, unsigned int statusBits, const HepLorentzVector &initialMomentum, const HepLorentzVector &initialPosition, const std::string process="")
Set the initial attributes of the McParticle.
Definition: McParticle.cxx:50
void addStatusFlag(unsigned int flag)
add a new flag to the status flags
Definition: McParticle.h:103
void finalize(const HepLorentzVector &finalPosition)
Set the final attributes of the McParticle.
Definition: McParticle.cxx:85
void setVertexIndex1(int index1)
Definition: McParticle.h:123
void setTrackIndex(int trackIndex)
Definition: McParticle.h:128
Double_t getInitialMomentumX() const
Definition: TMcParticle.h:56
Double_t getFinalPositionT() const
Definition: TMcParticle.h:53
Double_t getFinalPositionX() const
Definition: TMcParticle.h:44
Int_t getVertexIndex0() const
Definition: TMcParticle.h:23
Double_t getInitialPositionX() const
Definition: TMcParticle.h:32
Int_t getParticleID() const
Definition: TMcParticle.h:17
Double_t getInitialMomentumZ() const
Definition: TMcParticle.h:62
Double_t getInitialMomentumY() const
Definition: TMcParticle.h:59
UInt_t getStatusFlags() const
Definition: TMcParticle.h:29
Int_t getMother() const
Definition: TMcParticle.h:82
vector< Int_t > getDaughters() const
Definition: TMcParticle.h:85
Double_t getInitialPositionZ() const
Definition: TMcParticle.h:38
Double_t getInitialPositionT() const
Definition: TMcParticle.h:41
Double_t getFinalPositionY() const
Definition: TMcParticle.h:47
Int_t getVertexIndex1() const
Definition: TMcParticle.h:26
Int_t getTrackIndex() const
Definition: TMcParticle.h:20
Double_t getFinalPositionZ() const
Definition: TMcParticle.h:50
Double_t getInitialPositionY() const
Definition: TMcParticle.h:35
Double_t getInitialMomentumE() const
Definition: TMcParticle.h:65
static std::map< const TObject *, const McParticle * > m_rootMcParticleMap
Definition: commonData.h:179

Friends And Related Function Documentation

◆ CnvFactory< McParticleCnv >

friend class CnvFactory< McParticleCnv >
friend

Definition at line 9 of file McParticleCnv.h.


The documentation for this class was generated from the following files: