CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcTrackCnv.cxx
Go to the documentation of this file.
1#ifndef MdcTrackCnv_CXX
2#define MdcTrackCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7#include "TClonesArray.h"
9#include "DstEvent/DstEvent.h" //TDS object
10#include "DstEvent/DstMdcTrack.h" //TDS object
11#include "RootEventData/TMdcTrack.h" // standard root object
16#include <vector>
17#include "CLHEP/Matrix/Vector.h"
18#include "CLHEP/Matrix/SymMatrix.h"
19#include "CLHEP/Geometry/Point3D.h"
20
21using namespace std;
22
23
24MdcTrackCnv::MdcTrackCnv(ISvcLocator* svc)
25: RootEventBaseCnv(classID(), svc)
26{
27 // Here we associate this converter with the /Event path on the TDS.
28 MsgStream log(msgSvc(), "MdcTrackCnv");
29 m_rootBranchname ="m_mdcTrackCol";
30 m_adresses.push_back(&m_mdcTrackCol);
31 m_mdcTrackCol=0;
32}
33
34StatusCode MdcTrackCnv::TObjectToDataObject(DataObject*& refpObject) {
35 // creation of TDS object from root object
36 MsgStream log(msgSvc(), "MdcTrackCnv");
37 log << MSG::DEBUG << "MdcTrackCnv::TObjectToDataObject" << endreq;
38 StatusCode sc=StatusCode::SUCCESS;
39
40 // create the TDS location for the MdcTrack Collection
41 DstMdcTrackCol* mdcTrackTdsCol = new DstMdcTrackCol;
42 refpObject=mdcTrackTdsCol;
43
44 // now convert
45 if (!m_mdcTrackCol) return sc;
46 TIter mdcTrackIter(m_mdcTrackCol);
47 TMdcTrack *mdcTrackRoot = 0;
48 while ((mdcTrackRoot = (TMdcTrack*)mdcTrackIter.Next())) {
49
50 int trackId = mdcTrackRoot->trackId();
51 int charge = mdcTrackRoot->charge();
52 double helix[5];
53 for(int i=0; i<5; i++){
54 helix[i] = mdcTrackRoot->helix(i);
55 log<<MSG::INFO<<"in MdcTrackCnv, helix["<<i<<"]: "<<helix[i]<<endreq;
56 }
57 double pxy = mdcTrackRoot->pxy();
58 double px = mdcTrackRoot->px();
59 double py = mdcTrackRoot->py();
60 double pz = mdcTrackRoot->pz();
61 double p = mdcTrackRoot->p();
62 double theta = mdcTrackRoot->theta();
63 double phi = mdcTrackRoot->phi();
64 double x = mdcTrackRoot->x();
65 double y = mdcTrackRoot->y();
66 double z = mdcTrackRoot->z();
67 double r = mdcTrackRoot->r();
68 int stat = mdcTrackRoot->stat();
69 double chi = mdcTrackRoot->chi2();
70 int ndof = mdcTrackRoot->ndof();
71 int ns = mdcTrackRoot->nster();
72 int nlayer = mdcTrackRoot->nlayer();
73 int nCgemXClusters=mdcTrackRoot->nCgemXClusters();
74 int nCgemVClusters=mdcTrackRoot->nCgemVClusters();
75
76 double err[15];
77 for (int i=0; i<15; i++){
78 err[i] = mdcTrackRoot->err(i);
79 }
80
81 double poca[3];
82 poca[0] = x;
83 poca[1] = y;
84 poca[2] = z;
85
86 log<<MSG::INFO<<"in MdcTrackCnv, mdcTrackRoot.nster "<<ns<<endreq;
87
88 DstMdcTrack *mdcTrackTds = new DstMdcTrack();
89 m_common.m_rootMdcTrackMap[mdcTrackRoot] = mdcTrackTds;
90
91 mdcTrackTds->setTrackId( trackId );
92 log<<MSG::INFO<<" dstMdcTrack trkid: "<<mdcTrackTds->trackId()<<endreq;
93
94 mdcTrackTds->setCharge( charge );
95 mdcTrackTds->setHelix(helix);
96 mdcTrackTds->setPoca(poca);
97
98 log<<MSG::INFO<<"dstMdcTrack helix: "<<mdcTrackTds->helix()<<endreq;
99
100 mdcTrackTds->setPxy( pxy );
101 mdcTrackTds->setPx( px );
102 mdcTrackTds->setPy( py );
103 mdcTrackTds->setPz( pz );
104 mdcTrackTds->setP( p );
105 mdcTrackTds->setTheta( theta );
106 mdcTrackTds->setPhi( phi );
107 mdcTrackTds->setX( x );
108 mdcTrackTds->setY( y );
109 mdcTrackTds->setZ( z );
110 mdcTrackTds->setR( r );
111 mdcTrackTds->setStat( stat );
112 mdcTrackTds->setChi2( chi );
113 mdcTrackTds->setNdof( ndof );
114 mdcTrackTds->setError( err );
115 mdcTrackTds->setNster( ns );
116 mdcTrackTds->setNlayer( nlayer );
117 mdcTrackTds->setNCgemXCluster( nCgemXClusters );
118 mdcTrackTds->setNCgemVCluster( nCgemVClusters );
119
120 log<<MSG::INFO<<" dstMdcTrack nster: "<<mdcTrackTds->nster()<<endreq;
121
122 mdcTrackTdsCol->push_back(mdcTrackTds);
123
124 }
125 delete m_mdcTrackCol;
126 m_mdcTrackCol = 0;
127 return StatusCode::SUCCESS;
128}
129
130StatusCode MdcTrackCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
131
132 MsgStream log(msgSvc(), "MdcTrackCnv");
133 log << MSG::DEBUG << "MdcTrackCnv::DataObjectToTObject" << endreq;
134 StatusCode sc=StatusCode::SUCCESS;
135
136 DstMdcTrackCol * mdcTrackColTds=dynamic_cast<DstMdcTrackCol *> (obj);
137 if (!mdcTrackColTds) {
138 log << MSG::ERROR << "Could not downcast to MdcTrackCol" << endreq;
139 return StatusCode::FAILURE;
140 }
141
142 DataObject *evt;
143 m_eds->findObject(EventModel::Dst::Event,evt);
144 if (evt==NULL) {
145 log << MSG::ERROR << "Could not get DstEvent in TDS " << endreq;
146 return StatusCode::FAILURE;
147 }
148 DstEvent * devtTds=dynamic_cast<DstEvent *> (evt);
149 if (!devtTds) {
150 log << MSG::ERROR << "MdcTrackCnv:Could not downcast to TDS DstEvent" << endreq;
151 }
152 IOpaqueAddress *addr;
153
154 m_cnvSvc->getDstCnv()->createRep(evt,addr);
156
157 const TObjArray *m_mdcTrackCol = recEvt->getMdcTrackCol();
158 if (!m_mdcTrackCol) return sc;
159 recEvt->clearMdcTrackCol(); //necessary in case there is I/O at the same time since array is static
160 DstMdcTrackCol::const_iterator mdcTrackTds;
161
162 for (mdcTrackTds = mdcTrackColTds->begin(); mdcTrackTds != mdcTrackColTds->end(); mdcTrackTds++) {
163 Int_t trackId =(*mdcTrackTds)->trackId();
164 Double_t helix[5];
165 for(int i=0;i<5;i++){
166 helix[i] = (*mdcTrackTds)->helix(i) ;
167 }
168 Int_t stat = (*mdcTrackTds)->stat();
169 Double_t chi = (*mdcTrackTds)->chi2();
170 Int_t ndof = (*mdcTrackTds)->ndof();
171 Double_t err[15];
172 for (Int_t i=0; i<15; i++){
173 err[i] = (*mdcTrackTds)->err(i);
174 }
175 Int_t ns = (*mdcTrackTds)->nster();
176 Int_t fL = (*mdcTrackTds)->firstLayer();
177 Int_t lL = (*mdcTrackTds)->lastLayer();
178 Int_t nlayer = (*mdcTrackTds)->nlayer();
179 Int_t nCgemXCluster = (*mdcTrackTds)->nCgemXCluster();
180 Int_t nCgemVCluster = (*mdcTrackTds)->nCgemVCluster();
181
182 TMdcTrack *mdcTrackRoot = new TMdcTrack();
183 //m_common.m_mdcTrackMap[(*mdcTrackTds)] = mdcTrackRoot;
184 mdcTrackRoot->setTrackId( trackId );
185
186 mdcTrackRoot->setHelix(helix);
187 log<<MSG::INFO<<"test,trackId: "<<mdcTrackRoot->trackId()<<endreq;
188 log<<MSG::INFO<<"test,px: "<<mdcTrackRoot->px()
189 <<"test,py: "<<mdcTrackRoot->py()
190 <<"test,pz: "<<mdcTrackRoot->pz()<<endreq;
191
192 mdcTrackRoot->setStat( stat );
193 mdcTrackRoot->setChi2( chi );
194 mdcTrackRoot->setNdof( ndof );
195 mdcTrackRoot->setErr( err );
196 mdcTrackRoot->setNster( ns );
197 mdcTrackRoot->setFirstLayer(fL);
198 mdcTrackRoot->setLastLayer(lL);
199 mdcTrackRoot->setNlayer(nlayer);
200 mdcTrackRoot->setNCgemXClusters(nCgemXCluster);
201 mdcTrackRoot->setNCgemVClusters(nCgemVCluster);
202
203 recEvt->addMdcTrack(mdcTrackRoot);
204 }
205
206 return StatusCode::SUCCESS;
207}
208#endif
Double_t x[10]
ObjectVector< DstMdcTrack > DstMdcTrackCol
Definition: DstMdcTrack.h:139
IMessageSvc * msgSvc()
static TDstEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: DstCnv.h:36
void setPxy(const double pxy)
Definition: DstMdcTrack.h:86
void setTrackId(const int trackId)
Definition: DstMdcTrack.h:84
void setPy(const double py)
Definition: DstMdcTrack.h:88
void setZ(const double z)
Definition: DstMdcTrack.h:95
void setNster(const int ns)
Definition: DstMdcTrack.h:100
void setX(const double x)
Definition: DstMdcTrack.h:93
void setError(double err[15])
void setNCgemXCluster(const int n)
Definition: DstMdcTrack.h:104
void setNdof(const int ndof)
Definition: DstMdcTrack.h:99
void setTheta(const double theta)
Definition: DstMdcTrack.h:91
void setStat(const int stat)
Definition: DstMdcTrack.h:97
const int trackId() const
Definition: DstMdcTrack.h:52
void setNlayer(const int nlayer)
Definition: DstMdcTrack.h:103
void setP(const double p)
Definition: DstMdcTrack.h:90
void setHelix(double helix[5])
void setPoca(double poca[3])
void setR(const double r)
Definition: DstMdcTrack.h:96
void setCharge(const int charge)
Definition: DstMdcTrack.h:85
const HepVector helix() const
......
void setY(const double y)
Definition: DstMdcTrack.h:94
void setChi2(const double chi)
Definition: DstMdcTrack.h:98
void setPhi(const double phi)
Definition: DstMdcTrack.h:92
void setNCgemVCluster(const int n)
Definition: DstMdcTrack.h:105
void setPz(const double pz)
Definition: DstMdcTrack.h:89
const int nster() const
Definition: DstMdcTrack.h:68
void setPx(const double px)
Definition: DstMdcTrack.h:87
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition: MdcTrackCnv.cxx:34
MdcTrackCnv(ISvcLocator *svc)
Definition: MdcTrackCnv.cxx:24
Definition of a Root address, derived from IOpaqueAddress.
Definition: RootAddress.h:21
DstCnv * getDstCnv()
Definition: RootCnvSvc.h:148
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 addMdcTrack(TMdcTrack *Track)
Add a Tkrtrack into the Mdc data collection.
Definition: TDstEvent.cxx:164
void clearMdcTrackCol()
clear the whole array (necessary because of the consts-s)
Definition: TDstEvent.h:49
const TObjArray * getMdcTrackCol() const
retrieve the whole TObjArray of MdcTrack Data
Definition: TDstEvent.h:40
const Double_t py() const
Definition: TMdcTrack.cxx:57
const Int_t charge() const
Definition: TMdcTrack.cxx:18
void setNCgemVClusters(const Int_t n)
Definition: TMdcTrack.h:52
const Double_t pz() const
Definition: TMdcTrack.cxx:61
const Double_t helix(Int_t i) const
Definition: TMdcTrack.h:14
const Double_t chi2() const
Definition: TMdcTrack.h:16
const Double_t phi() const
Definition: TMdcTrack.cxx:74
void setLastLayer(const Int_t lL)
Definition: TMdcTrack.h:50
Int_t nCgemVClusters() const
Definition: TMdcTrack.h:24
const Int_t stat() const
Definition: TMdcTrack.h:15
const Double_t px() const
Definition: TMdcTrack.cxx:53
const Double_t y() const
Definition: TMdcTrack.cxx:34
void setNster(const Int_t ns)
Definition: TMdcTrack.h:47
void setChi2(const Double_t chi)
Definition: TMdcTrack.h:45
Int_t nCgemXClusters() const
Definition: TMdcTrack.h:23
const Double_t theta() const
Definition: TMdcTrack.cxx:70
const Double_t pxy() const
Definition: TMdcTrack.cxx:47
void setNlayer(const Int_t nlayer)
Definition: TMdcTrack.h:48
const Int_t nster() const
Definition: TMdcTrack.h:19
const Double_t x() const
Definition: TMdcTrack.cxx:30
const Double_t r() const
Definition: TMdcTrack.cxx:42
const Double_t err(Int_t i) const
Definition: TMdcTrack.h:18
const Double_t p() const
Definition: TMdcTrack.cxx:65
const Int_t trackId() const
Definition: TMdcTrack.h:13
void setNdof(const Int_t ndof)
Definition: TMdcTrack.h:46
void setTrackId(const Int_t trackId)
Definition: TMdcTrack.h:43
const Double_t z() const
Definition: TMdcTrack.cxx:38
void setFirstLayer(const Int_t fL)
Definition: TMdcTrack.h:49
const Int_t ndof() const
Definition: TMdcTrack.h:17
const Int_t nlayer() const
Definition: TMdcTrack.h:20
void setErr(const Double_t err[15])
Definition: TMdcTrack.cxx:84
void setStat(const Int_t stat)
Definition: TMdcTrack.h:44
void setNCgemXClusters(const Int_t n)
Definition: TMdcTrack.h:51
void setHelix(const Double_t helix[5])
Definition: TMdcTrack.cxx:78
static std::map< const TObject *, const DstMdcTrack * > m_rootMdcTrackMap
Definition: commonData.h:170
_EXTERN_ std::string Event
Definition: EventModel.h:146
#define ns(x)
Definition: xmltok.c:1504