CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcMcHitCnv.cxx
Go to the documentation of this file.
1#ifndef MdcMcHitCnv_CXX
2#define MdcMcHitCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7
8#include "TClonesArray.h"
9
11#include "McTruth/McEvent.h" //TDS object
12#include "McTruth/MdcMcHit.h" //TDS object
13#include "RootEventData/TMdcMc.h" // standard root object
15#include "RootCnvSvc/Mc/McCnv.h"
18
19
20// Instantiation of a static factory class used by clients to create
21// instances of this service
22//static CnvFactory<MdcMcHitCnv> s_factory;
23//const ICnvFactory& MdcMcHitCnvFactory = s_factory;
24
25MdcMcHitCnv::MdcMcHitCnv(ISvcLocator* svc)
26: RootEventBaseCnv(classID(), svc)
27{
28 // Here we associate this converter with the /Event path on the TDS.
29 MsgStream log(msgSvc(), "MdcMcHitCnv");
30 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
31 m_rootBranchname ="m_mdcMcHitCol";
32 //declareObject(EventModel::MC::MdcMcHitCol, objType(), m_rootTreename, m_rootBranchname);
33 m_adresses.push_back(&m_mdcMcHitCol);
34 m_mdcMcHitCol=0;
35}
36
37StatusCode MdcMcHitCnv::TObjectToDataObject(DataObject*& refpObject) {
38 // creation of TDS object from root object
39
40 MsgStream log(msgSvc(), "MdcMcHitCnv");
41 log << MSG::DEBUG << "MdcMcHitCnv::TObjectToDataObject" << endreq;
42 StatusCode sc=StatusCode::SUCCESS;
43
44 // create the TDS location for the MdcMc Collection
45 MdcMcHitCol* mdcMcTdsCol = new MdcMcHitCol;
46 refpObject=mdcMcTdsCol;
47
48
49 // now convert
50 if (!m_mdcMcHitCol) return sc;
51 TIter mdcMcIter(m_mdcMcHitCol);
52 TMdcMc *mdcMcRoot = 0;
53 while ((mdcMcRoot = (TMdcMc*)mdcMcIter.Next())) {
54 unsigned int id = mdcMcRoot ->getId();
55 unsigned int trackIndex = mdcMcRoot ->getTrackIndex();
56 double xPosition = mdcMcRoot ->getPositionX() ;
57 double yPosition = mdcMcRoot ->getPositionY() ;
58 double zPosition = mdcMcRoot ->getPositionZ() ;
59 double driftDistance= mdcMcRoot ->getDriftDistance() ;
60 double depositEnergy = mdcMcRoot ->getDepositEnergy() ;
61 int positionFlag = mdcMcRoot->getPositionFlag();
62 double px = mdcMcRoot->getMomentumX();
63 double py = mdcMcRoot->getMomentumY();
64 double pz = mdcMcRoot->getMomentumZ();
65 double trkLen = mdcMcRoot->getFlightLength();
66 TString creatorProcess = mdcMcRoot->getCreatorProcess();
67 int digiIdx = mdcMcRoot->getDigiIdx();
68 int pdgCode = mdcMcRoot->getPDGCode();
69 int isSec = mdcMcRoot->getIsSecondary();
70
71 MdcMcHit *mdcMcTds = new MdcMcHit;
72 m_common.m_rootMdcMcHitMap[mdcMcRoot] = mdcMcTds;
73
74 mdcMcTds->setIdentifier(id);
75 mdcMcTds->setTrackIndex(trackIndex);
76 mdcMcTds->setPositionX(xPosition);
77 mdcMcTds->setPositionY(yPosition);
78 mdcMcTds->setPositionZ(zPosition);
79 mdcMcTds->setDriftDistance(driftDistance);
80 mdcMcTds->setDepositEnergy(depositEnergy);
81 mdcMcTds->setPositionFlag(positionFlag);
82 mdcMcTds->setMomentumX(px);
83 mdcMcTds->setMomentumY(py);
84 mdcMcTds->setMomentumZ(pz);
85 mdcMcTds->setFlightLength(trkLen);
86 mdcMcTds->setCreatorProcess(creatorProcess.Data());
87 mdcMcTds->setDigiIdx(digiIdx);
88 mdcMcTds->setCurrentTrackPID(pdgCode);
89 mdcMcTds->setIsSecondary(isSec);
90
91 mdcMcTdsCol->push_back(mdcMcTds);
92 }
93 //m_mdcMcHitCol->Delete(); // wensp add 2005/12/30
94 delete m_mdcMcHitCol;
95 m_mdcMcHitCol = 0;
96 return StatusCode::SUCCESS;
97}
98
99StatusCode MdcMcHitCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
100
101 MsgStream log(msgSvc(), "MdcMcHitCnv");
102 log << MSG::DEBUG << "MdcMcHitCnv::DataObjectToTObject" << endreq;
103 StatusCode sc=StatusCode::SUCCESS;
104
105 MdcMcHitCol * mdcMcHitCnvTds=dynamic_cast<MdcMcHitCol *> (obj);
106 if (!mdcMcHitCnvTds) {
107 log << MSG::ERROR << "Could not downcast to MdcMcHitCol" << endreq;
108 return StatusCode::FAILURE;
109 }
110
111 DataObject *evt;
112 m_eds->findObject(EventModel::MC::Event,evt);
113 if (evt==NULL) {
114 log << MSG::ERROR << "Could not get McEvent in TDS " << endreq;
115 return StatusCode::FAILURE;
116 }
117 McEvent * devtTds=dynamic_cast<McEvent *> (evt);
118 if (!devtTds) {
119 log << MSG::ERROR << "MdcMcHitCnv:Could not downcast to TDS McEvent" << endreq;
120 }
121 IOpaqueAddress *addr;
122
123 m_cnvSvc->getMcCnv()->createRep(evt,addr);
125
126 const TObjArray *m_mdcMcHitCol = McEvt->getMdcMcHitCol();
127 if (!m_mdcMcHitCol) return sc;
128 McEvt->clearMdcMcHitCol(); //necessary in case there is I/O at the same time since array is static
129 MdcMcHitCol::const_iterator mdcMcTds;
130
131 for (mdcMcTds = mdcMcHitCnvTds->begin(); mdcMcTds != mdcMcHitCnvTds->end(); mdcMcTds++) {
132 UInt_t id = ((*mdcMcTds)->identify()).get_value() ;
133 UInt_t trackIndex = (*mdcMcTds) ->getTrackIndex();
134 Double_t xPosition = (*mdcMcTds) ->getPositionX() ;
135 Double_t yPosition = (*mdcMcTds) ->getPositionY() ;
136 Double_t zPosition = (*mdcMcTds) ->getPositionZ() ;
137 Double_t driftDistance= (*mdcMcTds) ->getDriftDistance();
138 Double_t depositEnergy = (*mdcMcTds) ->getDepositEnergy() ;
139 Int_t positionFlag = (*mdcMcTds) ->getPositionFlag();
140 Double_t px = (*mdcMcTds)->getMomentumX();
141 Double_t py = (*mdcMcTds)->getMomentumY();
142 Double_t pz = (*mdcMcTds)->getMomentumZ();
143 Double_t trkLen = (*mdcMcTds)->getFlightLength();
144 TString creatorProcess = (*mdcMcTds)->getCreatorProcess();
145 Int_t trkIdx = (*mdcMcTds)->getDigiIdx();
146 Int_t pdgCode = (*mdcMcTds)->getCurrentTrackPID();
147 Int_t isSec = (*mdcMcTds)->getIsSecondary();
148
149 TMdcMc *mdcMcRoot = new TMdcMc();
150 //m_common.m_mdcMcHitMap[(*mdcMcTds)] = mdcMcRoot;
151
152 mdcMcRoot->setId(id);
153 mdcMcRoot->setTrackIndex(trackIndex);
154 mdcMcRoot->setPositionX(xPosition);
155 mdcMcRoot->setPositionY(yPosition);
156 mdcMcRoot->setPositionZ(zPosition);
157 mdcMcRoot->setDriftDistance(driftDistance);
158 mdcMcRoot->setDepositEnergy(depositEnergy);
159 mdcMcRoot->setPositionFlag(positionFlag);
160 mdcMcRoot->setMomentumX(px);
161 mdcMcRoot->setMomentumY(py);
162 mdcMcRoot->setMomentumZ(pz);
163 mdcMcRoot->setFlightLength(trkLen);
164 mdcMcRoot->setCreatorProcess(creatorProcess);
165 mdcMcRoot->setDigiIdx(trkIdx);
166 mdcMcRoot->setPDGCode(pdgCode);
167 mdcMcRoot->setIsSecondary(isSec);
168
169 McEvt->addMdcMc(mdcMcRoot);
170 }
171
172 return StatusCode::SUCCESS;
173}
174#endif
175
176
177
178
179
180
181
182
183
184
IMessageSvc * msgSvc()
void setMomentumZ(double momentumZ)
Definition MdcMcHit.h:101
void setCreatorProcess(string creatorProcess)
Definition MdcMcHit.h:106
void setMomentumY(double momentumY)
Definition MdcMcHit.h:100
void setPositionFlag(int posFlag)
Definition MdcMcHit.h:104
void setPositionZ(double positionZ)
Definition MdcMcHit.h:97
void setFlightLength(double flightLength)
Definition MdcMcHit.h:105
void setDepositEnergy(double depositEnergy)
Definition MdcMcHit.h:103
void setMomentumX(double momentumX)
Definition MdcMcHit.h:99
void setIdentifier(unsigned int id)
Definition MdcMcHit.h:88
void setPositionY(double positionY)
Definition MdcMcHit.h:96
void setDigiIdx(int id)
Definition MdcMcHit.h:107
void setIsSecondary(int isSec)
Definition MdcMcHit.h:94
void setTrackIndex(unsigned int trackIndex)
Definition MdcMcHit.h:89
void setCurrentTrackPID(int currentTrackPID)
Definition MdcMcHit.h:92
void setDriftDistance(double driftDistance)
Definition MdcMcHit.h:102
void setPositionX(double positionX)
Definition MdcMcHit.h:95
static TMcEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition McCnv.h:35
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
MdcMcHitCnv(ISvcLocator *svc)
Definition of a Root address, derived from IOpaqueAddress.
Definition RootAddress.h:21
McCnv * getMcCnv()
Definition RootCnvSvc.h:149
Base class for all Root Converters.
std::vector< void * > m_adresses
each converter knows the corresponding adresses
RootCnvSvc * m_cnvSvc
IDataProviderSvc * m_eds
pointer to eventdataservice
std::string m_rootBranchname
root branchname (may be concatenated of severals)
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Convert the transient object to the requested representation.
void addMdcMc(TMdcMc *mcHit)
Mdc.
Definition TMcEvent.cxx:114
void clearMdcMcHitCol()
Definition TMcEvent.h:36
const TObjArray * getMdcMcHitCol() const
Definition TMcEvent.h:33
Definition TMdcMc.h:9
void setMomentumX(Double_t momentumX)
Definition TMdcMc.h:77
UInt_t getId() const
Definition TMdcMc.h:17
Double_t getDepositEnergy() const
Definition TMdcMc.h:35
Int_t getDigiIdx() const
Definition TMdcMc.h:57
Double_t getPositionZ() const
Definition TMdcMc.h:29
void setPositionZ(Double_t positionZ)
Definition TMdcMc.h:70
TString getCreatorProcess() const
Definition TMdcMc.h:55
Double_t getDriftDistance() const
Definition TMdcMc.h:32
Int_t getPDGCode() const
Definition TMdcMc.h:40
void setDigiIdx(Int_t id)
Definition TMdcMc.h:82
Double_t getFlightLength() const
Definition TMdcMc.h:53
void setId(UInt_t id)
Definition TMdcMc.h:66
Double_t getMomentumX() const
Definition TMdcMc.h:44
void setMomentumY(Double_t momentumY)
Definition TMdcMc.h:78
void setPDGCode(Int_t code)
Definition TMdcMc.h:75
void setTrackIndex(UInt_t trackIndex)
Definition TMdcMc.h:67
void setFlightLength(Double_t flightLength)
Definition TMdcMc.h:80
UInt_t getTrackIndex() const
Definition TMdcMc.h:20
Double_t getMomentumZ() const
Definition TMdcMc.h:50
void setDepositEnergy(Double_t depositEnergy)
Definition TMdcMc.h:72
Int_t getPositionFlag() const
Definition TMdcMc.h:38
Double_t getPositionX() const
Definition TMdcMc.h:23
void setPositionX(Double_t positionX)
Definition TMdcMc.h:68
void setCreatorProcess(TString creatorProcess)
Definition TMdcMc.h:81
void setIsSecondary(Int_t isSec)
Definition TMdcMc.h:76
void setPositionFlag(Int_t posFlag)
Definition TMdcMc.h:73
Double_t getPositionY() const
Definition TMdcMc.h:26
void setPositionY(Double_t positionY)
Definition TMdcMc.h:69
void setDriftDistance(Double_t driftDistance)
Definition TMdcMc.h:71
Int_t getIsSecondary() const
Definition TMdcMc.h:41
Double_t getMomentumY() const
Definition TMdcMc.h:47
void setMomentumZ(Double_t momentumZ)
Definition TMdcMc.h:79
static std::map< const TObject *, const MdcMcHit * > m_rootMdcMcHitMap
Definition commonData.h:203
_EXTERN_ std::string Event
Definition EventModel.h:39
ObjectVector< MdcMcHit > MdcMcHitCol
Definition MdcMcHit.h:151