BOSS 7.0.2
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 ()
 
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
 
 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
 
destinationoperator (const source &) const
 

Static Public Member Functions

static const CLID & classID ()
 
static const CLID & classID ()
 
- Static Public Member Functions inherited from RootEventBaseCnv
static const unsigned char storageType ()
 Storage type and class ID.
 
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
 
 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
 
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
 
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 Event/RootCnvSvc/RootCnvSvc-02-01-12/RootCnvSvc/Mc/McParticleCnv.h.

Constructor & Destructor Documentation

◆ ~McParticleCnv() [1/2]

virtual McParticleCnv::~McParticleCnv ( )
inlinevirtual

◆ McParticleCnv() [1/2]

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}
std::vector< void * > m_adresses
each converter knows the corresponding adresses
std::string m_rootBranchname
root branchname (may be concatenated of severals)

◆ ~McParticleCnv() [2/2]

virtual McParticleCnv::~McParticleCnv ( )
inlinevirtual

◆ McParticleCnv() [2/2]

McParticleCnv::McParticleCnv ( ISvcLocator *  svc)
protected

Member Function Documentation

◆ classID() [1/2]

static const CLID & McParticleCnv::classID ( )
inlinestatic

Definition at line 24 of file Event/RootCnvSvc/RootCnvSvc-02-01-12/RootCnvSvc/Mc/McParticleCnv.h.

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

◆ classID() [2/2]

static const CLID & McParticleCnv::classID ( )
inlinestatic

◆ DataObjectToTObject() [1/2]

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)
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
ObjectList< McParticle > McParticleCol

◆ DataObjectToTObject() [2/2]

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

transformation to root

Implements RootEventBaseCnv.

◆ TObjectToDataObject() [1/2]

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)
The Monte Carlo particle kinematics information.
static std::map< const TObject *, const McParticle * > m_rootMcParticleMap

◆ TObjectToDataObject() [2/2]

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

transformation from root

Implements RootEventBaseCnv.

Friends And Related Function Documentation

◆ CnvFactory< McParticleCnv >


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